Decompiled source of AdvancedDealing v1.3.0

Mods/AdvancedDealing.Il2Cpp.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using AdvancedDealing;
using AdvancedDealing.Economy;
using AdvancedDealing.Messaging;
using AdvancedDealing.Messaging.Messages;
using AdvancedDealing.NPCs.Behaviour;
using AdvancedDealing.Persistence;
using AdvancedDealing.Persistence.Datas;
using AdvancedDealing.Persistence.IO;
using AdvancedDealing.UI;
using AdvancedDealing.Utils;
using HarmonyLib;
using Il2CppFishNet;
using Il2CppGameKit.Utilities;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.Dialogue;
using Il2CppScheduleOne.Economy;
using Il2CppScheduleOne.GameTime;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.Map;
using Il2CppScheduleOne.Messaging;
using Il2CppScheduleOne.Money;
using Il2CppScheduleOne.NPCs;
using Il2CppScheduleOne.NPCs.Behaviour;
using Il2CppScheduleOne.Networking;
using Il2CppScheduleOne.Persistence;
using Il2CppScheduleOne.PlayerScripts;
using Il2CppScheduleOne.Product;
using Il2CppScheduleOne.Storage;
using Il2CppScheduleOne.UI;
using Il2CppScheduleOne.UI.Phone;
using Il2CppScheduleOne.UI.Phone.Messages;
using Il2CppSteamworks;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppSystem.Text;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(global::AdvancedDealing.AdvancedDealing), "AdvancedDealing", "1.3.0", "ManZune", "https://github.com/manzune/AdvancedDealing")]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: MelonColor(255, 113, 195, 230)]
[assembly: MelonPlatformDomain(/*Could not decode attribute arguments.*/)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ManZune")]
[assembly: AssemblyConfiguration("Il2Cpp")]
[assembly: AssemblyDescription("A Schedule I Dealer Enhancement MelonLoader Mod")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyInformationalVersion("1.3.0+5259f34a0663f528d9c5e6903b35fd2ecb71250b")]
[assembly: AssemblyProduct("AdvancedDealing")]
[assembly: AssemblyTitle("AdvancedDealing")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/manzune/AdvancedDealing")]
[assembly: AssemblyVersion("1.3.0.0")]
[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 AdvancedDealing
{
	public class AdvancedDealing : MelonMod
	{
		public bool IsInitialized { get; private set; }

		public SaveModifier SaveModifier { get; private set; }

		public NetworkSynchronizer NetworkSynchronizer { get; private set; }

		public override void OnSceneWasInitialized(int buildIndex, string sceneName)
		{
			if (sceneName == "Menu")
			{
				if (!IsInitialized)
				{
					ModConfig.Initialize();
					ConflictChecker.CheckForConflicts();
					SaveModifier = new SaveModifier();
					NetworkSynchronizer = new NetworkSynchronizer();
					Logger.Msg("AdvancedDealing v1.3.0 initialized");
					IsInitialized = true;
				}
				if (SaveModifier.SavegameLoaded)
				{
					SaveModifier.ClearModifications();
				}
			}
			else if (sceneName == "Main")
			{
				SaveModifier.LoadModifications();
			}
		}
	}
	public static class ModConfig
	{
		private static MelonPreferences_Category generalCategory;

		private static bool isInitialized;

		public static bool Debug
		{
			get
			{
				return generalCategory.GetEntry<bool>("Debug").Value;
			}
			set
			{
				generalCategory.GetEntry<bool>("Debug").Value = value;
			}
		}

		public static bool SkipMovement
		{
			get
			{
				return generalCategory.GetEntry<bool>("SkipMovement").Value;
			}
			set
			{
				generalCategory.GetEntry<bool>("SkipMovement").Value = value;
			}
		}

		public static bool NotifyOnAction
		{
			get
			{
				return generalCategory.GetEntry<bool>("NotifyOnAction").Value;
			}
			set
			{
				generalCategory.GetEntry<bool>("NotifyOnAction").Value = value;
			}
		}

		public static bool CustomersSearchAndSort
		{
			get
			{
				return generalCategory.GetEntry<bool>("CustomersSearchAndSort").Value;
			}
			set
			{
				generalCategory.GetEntry<bool>("CustomersSearchAndSort").Value = value;
			}
		}

		public static bool AccessInventory
		{
			get
			{
				if (NetworkSynchronizer.IsSyncing && NetworkSynchronizer.Instance.SessionData != null)
				{
					return NetworkSynchronizer.Instance.SessionData.AccessInventory;
				}
				return generalCategory.GetEntry<bool>("AccessInventory").Value;
			}
			set
			{
				generalCategory.GetEntry<bool>("AccessInventory").Value = value;
			}
		}

		public static bool SettingsMenu
		{
			get
			{
				if (NetworkSynchronizer.IsSyncing && NetworkSynchronizer.Instance.SessionData != null)
				{
					return NetworkSynchronizer.Instance.SessionData.SettingsMenu;
				}
				return generalCategory.GetEntry<bool>("SettingsMenu").Value;
			}
			set
			{
				generalCategory.GetEntry<bool>("SettingsMenu").Value = value;
			}
		}

		public static float NegotiationModifier
		{
			get
			{
				if (NetworkSynchronizer.IsSyncing && NetworkSynchronizer.Instance.SessionData != null)
				{
					return NetworkSynchronizer.Instance.SessionData.NegotiationModifier;
				}
				return generalCategory.GetEntry<float>("NegotiationModifier").Value;
			}
			set
			{
				generalCategory.GetEntry<float>("NegotiationModifier").Value = value;
			}
		}

		public static void Initialize()
		{
			if (isInitialized)
			{
				return;
			}
			generalCategory = MelonPreferences.CreateCategory("AdvancedDealing_01_General", "AdvancedDealing - General Settings", false, true);
			string text = Path.Combine(MelonEnvironment.UserDataDirectory, "AdvancedDealing.cfg");
			generalCategory.SetFilePath(text, true, false);
			CreateEntries();
			if (!File.Exists(text))
			{
				foreach (MelonPreferences_Entry entry in generalCategory.Entries)
				{
					entry.ResetToDefault();
				}
				generalCategory.SaveToFile(false);
			}
			isInitialized = true;
		}

		private static void CreateEntries()
		{
			generalCategory.CreateEntry<bool>("Debug", false, "Enable Debug Mode", "Enables debugging for this mod", false, false, (ValueValidator)null, (string)null);
			generalCategory.CreateEntry<bool>("SkipMovement", false, "Skip Movement (Instant Delivery)", "Skips all movement actions for dealers", false, false, (ValueValidator)null, (string)null);
			generalCategory.CreateEntry<bool>("NotifyOnAction", true, "Notify On Actions", "Sends notifications after some actions got triggered", false, false, (ValueValidator)null, (string)null);
			generalCategory.CreateEntry<bool>("CustomersSearchAndSort", true, "Search And Sort Customers (Needs Reload)", "Enable customers searching and sorting by region and alphabetical", false, false, (ValueValidator)null, (string)null);
			generalCategory.CreateEntry<bool>("AccessInventory", false, "Access Dealer Inventories Remotely", "Enables the option to access the dealer inventory via text message", false, false, (ValueValidator)null, (string)null);
			generalCategory.CreateEntry<bool>("SettingsMenu", false, "Enable Dealer Settings Menu", "Allows access to the dealer settings menu via text message", false, false, (ValueValidator)null, (string)null);
			generalCategory.CreateEntry<float>("NegotiationModifier", 0.5f, "Negotiation Modifier (Higher = Better Chance)", "Modifier used to calculate the negotiation success.", false, false, (ValueValidator)(object)new ValueRange<float>(0f, 1f), (string)null);
		}
	}
	public static class ModInfo
	{
		public const string NAME = "AdvancedDealing";

		public const string VERSION = "1.3.0";

		public const string AUTHOR = "ManZune";

		public const string DOWNLOAD_LINK = "https://github.com/manzune/AdvancedDealing";
	}
}
namespace AdvancedDealing.Utils
{
	public static class ConflictChecker
	{
		public static bool DisableMoreItemSlots { get; private set; }

		public static void CheckForConflicts()
		{
			bool flag = false;
			if (MelonBase.FindMelon("Bread's Storage Tweak Mod", "BreadCh4n") != null)
			{
				flag = true;
				DisableMoreItemSlots = true;
				Logger.Msg("ConflictChecker", "Bread's Storage Tweaks found: More item slots feature disabled.");
			}
			if (!flag)
			{
				Logger.Msg("ConflictChecker", "No known conflicting mods found.");
			}
		}
	}
	public static class Logger
	{
		public static void Msg(string msg)
		{
			Msg(null, msg);
		}

		public static void Msg(string prefix, string msg)
		{
			if (prefix != null)
			{
				msg = "[" + prefix + "] " + msg;
			}
			MelonLogger.Msg(msg);
		}

		public static void Error(string msg)
		{
			Error(null, msg, null);
		}

		public static void Error(string prefix, string msg)
		{
			Error(prefix, msg, null);
		}

		public static void Error(string msg, Exception ex)
		{
			Error(null, msg, ex);
		}

		public static void Error(string prefix, string msg, Exception ex)
		{
			if (prefix != null)
			{
				msg = "[" + prefix + "] " + msg;
			}
			if (ex != null)
			{
				MelonLogger.Error(msg, ex);
			}
			else
			{
				MelonLogger.Error(msg);
			}
		}

		public static void Debug(string msg)
		{
			Debug(null, msg);
		}

		public static void Debug(string prefix, string msg)
		{
			if (ModConfig.Debug)
			{
				if (prefix != null)
				{
					msg = "[" + prefix + "] " + msg;
				}
				MelonLogger.Msg(ConsoleColor.Cyan, msg);
			}
		}
	}
}
namespace AdvancedDealing.UI
{
	public class CustomerSelector
	{
		public RectTransform Content;

		public InputField Searchbar;

		private Dictionary<EMapRegion, (GameObject gameObject, List<RectTransform> entries)> _categories = new Dictionary<EMapRegion, (GameObject, List<RectTransform>)>();

		public bool UICreated { get; private set; }

		public void BuildUI()
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			if (UICreated)
			{
				return;
			}
			Transform transform = ((Component)PlayerSingleton<DealerManagementApp>.Instance.CustomerSelector).transform;
			Content = PlayerSingleton<DealerManagementApp>.Instance.CustomerSelector.EntriesContainer;
			Transform obj = transform.Find("Shade/Content/Scroll View");
			RectTransform val = ((obj != null) ? ((Component)obj).GetComponent<RectTransform>() : null);
			val.sizeDelta = new Vector2(val.sizeDelta.x, val.sizeDelta.y - 100f);
			GameObject val2 = Object.Instantiate<GameObject>(((Component)((Component)PlayerSingleton<MessagesApp>.Instance.CounterofferInterface).transform.Find("Shade/Content/Selection/SearchInput")).gameObject, ((Transform)val).parent);
			val2.SetActive(true);
			((Object)val2).name = "Searchbar";
			Searchbar = val2.GetComponent<InputField>();
			((UnityEventBase)Searchbar.onEndEdit).RemoveAllListeners();
			((UnityEventBase)Searchbar.onValueChanged).RemoveAllListeners();
			((UnityEvent<string>)(object)Searchbar.onValueChanged).AddListener(UnityAction<string>.op_Implicit((Action<string>)OnSearchValueChanged));
			Searchbar.contentType = (ContentType)0;
			RectTransform component = ((Component)Searchbar).GetComponent<RectTransform>();
			component.offsetMax = new Vector2(-25f, -80f);
			component.offsetMin = new Vector2(25f, -130f);
			Text component2 = ((Component)((Transform)component).Find("Text Area/Placeholder")).GetComponent<Text>();
			component2.text = "Search customers...";
			GameObject gameObject = ((Component)((Transform)Content).GetChild(0).Find("Name")).gameObject;
			foreach (EMapRegion value in Enum.GetValues(typeof(EMapRegion)))
			{
				GameObject val4 = Object.Instantiate<GameObject>(gameObject, (Transform)(object)Content);
				((Object)val4).name = "Region";
				RectTransform component3 = val4.GetComponent<RectTransform>();
				component3.offsetMax = new Vector2(0f, 0f);
				component3.offsetMin = new Vector2(0f, 0f);
				component3.sizeDelta = new Vector2(495f, 60f);
				Text component4 = val4.GetComponent<Text>();
				component4.text = Enum.GetName(typeof(EMapRegion), (object)value);
				component4.fontStyle = (FontStyle)1;
				component4.alignment = (TextAnchor)4;
				_categories.Add(value, (val4, new List<RectTransform>()));
			}
			UICreated = true;
		}

		public void SortCustomers()
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < PlayerSingleton<DealerManagementApp>.Instance.CustomerSelector.customerEntries.Count; i++)
			{
				RectTransform val = PlayerSingleton<DealerManagementApp>.Instance.CustomerSelector.customerEntries[i];
				Customer val2 = PlayerSingleton<DealerManagementApp>.Instance.CustomerSelector.entryToCustomer[val];
				if ((Object)(object)val2.AssignedDealer != (Object)null)
				{
					_categories[val2.NPC.Region].entries.Remove(val);
				}
				else
				{
					_categories[val2.NPC.Region].entries.Add(val);
				}
			}
			foreach (KeyValuePair<EMapRegion, (GameObject, List<RectTransform>)> category in _categories)
			{
				category.Value.Item1.transform.SetAsLastSibling();
				List<RectTransform> collection = category.Value.Item2.OrderBy((RectTransform e) => ((Component)((Transform)e).Find("Name")).GetComponent<Text>().text).ToList();
				category.Value.Item2.Clear();
				category.Value.Item2.AddRange(collection);
				int num = 0;
				for (int j = 0; j < category.Value.Item2.Count; j++)
				{
					RectTransform val3 = category.Value.Item2[j];
					((Transform)val3).SetAsLastSibling();
					if (((Component)val3).gameObject.activeSelf)
					{
						num++;
					}
				}
				if (num == 0)
				{
					category.Value.Item1.SetActive(false);
				}
				else
				{
					category.Value.Item1.SetActive(true);
				}
			}
		}

		private void OnSearchValueChanged(string value)
		{
			foreach (KeyValuePair<EMapRegion, (GameObject, List<RectTransform>)> category in _categories)
			{
				int num = 0;
				for (int i = 0; i < category.Value.Item2.Count; i++)
				{
					RectTransform val = category.Value.Item2[i];
					Text component = ((Component)((Transform)val).Find("Name")).GetComponent<Text>();
					if (component.text.Contains(value, StringComparison.OrdinalIgnoreCase) || value == null || value == string.Empty)
					{
						((Component)val).gameObject.SetActive(true);
						num++;
					}
					else
					{
						((Component)val).gameObject.SetActive(false);
					}
				}
				if (num == 0)
				{
					category.Value.Item1.SetActive(false);
				}
				else
				{
					category.Value.Item1.SetActive(true);
				}
			}
		}
	}
	public class CustomersScrollView
	{
		public const int MAX_ENTRIES = 24;

		public GameObject Container;

		public GameObject Viewport;

		public GameObject AssignButton;

		public RectTransform CustomerTitle;

		public List<GameObject> CustomerEntries = new List<GameObject>();

		public Text TitleLabel;

		public bool UICreated { get; private set; }

		public void BuildUI()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Expected O, but got Unknown
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Expected O, but got Unknown
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			Container = ((Component)((Component)PlayerSingleton<DealerManagementApp>.Instance).transform.Find("Container/Background/Content")).gameObject;
			float num = 620f;
			GameObject val = new GameObject("Scroll");
			RectTransform val2 = val.AddComponent<RectTransform>();
			((Transform)val2).SetParent(Container.transform, false);
			val2.anchorMin = new Vector2(0f, 0f);
			val2.anchorMax = new Vector2(1f, 0f);
			val2.pivot = new Vector2(0.5f, 0f);
			val2.anchoredPosition = Vector2.zero;
			val2.sizeDelta = new Vector2(0f, num);
			Viewport = new GameObject("Viewport");
			RectTransform val3 = Viewport.AddComponent<RectTransform>();
			((Transform)val3).SetParent((Transform)(object)val2, false);
			val3.anchorMin = new Vector2(0f, 0f);
			val3.anchorMax = new Vector2(1f, 0f);
			val3.pivot = new Vector2(0.5f, 0f);
			val3.anchoredPosition = Vector2.zero;
			val3.sizeDelta = new Vector2(0f, num);
			Viewport.AddComponent<Mask>().showMaskGraphic = false;
			Viewport.AddComponent<Image>();
			GameObject gameObject = ((Component)((Transform)((IEnumerable<RectTransform>)PlayerSingleton<DealerManagementApp>.Instance.CustomerEntries).Last()).parent).gameObject;
			RectTransform component = gameObject.GetComponent<RectTransform>();
			((Transform)component).SetParent((Transform)(object)val3, true);
			component.pivot = new Vector2(0.5f, 1f);
			ContentSizeFitter val4 = gameObject.AddComponent<ContentSizeFitter>();
			val4.horizontalFit = (FitMode)0;
			val4.verticalFit = (FitMode)2;
			((LayoutGroup)gameObject.GetComponent<VerticalLayoutGroup>()).padding = new RectOffset(0, 0, 20, 20);
			ScrollRect val5 = val.AddComponent<ScrollRect>();
			val5.viewport = val3;
			val5.content = component;
			val5.horizontal = false;
			val5.vertical = true;
			val5.movementType = (MovementType)1;
			val5.inertia = true;
			val5.elasticity = 0.1f;
			val5.verticalNormalizedPosition = 1f;
			val5.scrollSensitivity = 8f;
			CustomerTitle = ((Component)Container.transform.Find("CustomerTitle")).GetComponent<RectTransform>();
			CustomerTitle.sizeDelta = new Vector2(CustomerTitle.sizeDelta.x, CustomerTitle.sizeDelta.y - 15f);
			CustomerTitle.offsetMax = new Vector2(CustomerTitle.offsetMax.x, CustomerTitle.offsetMax.y - 15f);
			TitleLabel = ((Component)CustomerTitle).GetComponent<Text>();
			AssignButton = ((Component)PlayerSingleton<DealerManagementApp>.Instance.AssignCustomerButton).gameObject;
			CreateCustomerEntries();
			Logger.Debug("CustomersScrollView", "Customers scroll view UI created");
			UICreated = true;
		}

		private void CreateCustomerEntries()
		{
			Il2CppReferenceArray<RectTransform> customerEntries = PlayerSingleton<DealerManagementApp>.Instance.CustomerEntries;
			Il2CppReferenceArray<RectTransform> val = new Il2CppReferenceArray<RectTransform>(24L);
			int length = ((Il2CppArrayBase<RectTransform>)(object)customerEntries).Length;
			if (length == 24)
			{
				return;
			}
			for (int i = 0; i < 24; i++)
			{
				if (i < length)
				{
					((Il2CppArrayBase<RectTransform>)(object)val)[i] = ((Il2CppArrayBase<RectTransform>)(object)customerEntries)[i];
					CustomerEntries.Add(((Component)((Il2CppArrayBase<RectTransform>)(object)customerEntries)[i]).gameObject);
					continue;
				}
				RectTransform val2 = ((IEnumerable<RectTransform>)customerEntries).Last();
				RectTransform val3 = Object.Instantiate<RectTransform>(val2, ((Transform)val2).parent);
				((Object)val3).name = $"CustomerEntry ({i})";
				((Component)val3).gameObject.SetActive(false);
				((Il2CppArrayBase<RectTransform>)(object)val)[i] = val3;
				CustomerEntries.Add(((Component)val3).gameObject);
			}
			PlayerSingleton<DealerManagementApp>.Instance.CustomerEntries = val;
			((Component)PlayerSingleton<DealerManagementApp>.Instance.AssignCustomerButton).transform.SetAsLastSibling();
		}
	}
	public class DeadDropSelector
	{
		public GameObject Container;

		public Text TitleLabel;

		public Transform Content;

		public GameObject Button;

		public Text ButtonLabel;

		private readonly List<GameObject> _selectables = new List<GameObject>();

		private DealerExtension _dealer;

		private GameObject _selectableTemplate;

		public bool UICreated { get; private set; }

		public bool IsOpen { get; private set; }

		public void Open(DealerExtension dealerExtension)
		{
			IsOpen = true;
			_dealer = dealerExtension;
			foreach (DeadDrop deadDrop in DeadDropExtension.GetDeadDropsByDistance(((Component)Player.Local).transform))
			{
				GameObject val = _selectables.Find((GameObject x) => ((Component)x.transform.Find("Name")).GetComponent<Text>().text == deadDrop.DeadDropName);
				val.transform.SetAsLastSibling();
			}
			Container.SetActive(true);
		}

		public void Close()
		{
			IsOpen = false;
			Container.SetActive(false);
		}

		private void OnSelected(string guid, string name)
		{
			_dealer.DeadDrop = guid;
			ButtonLabel.text = name;
			Logger.Debug("DeadDropSelector", "Dead drop for " + ((NPC)_dealer.Dealer).fullName + " selected: " + guid);
			if (NetworkSynchronizer.IsSyncing)
			{
				NetworkSynchronizer.Instance.SendData(_dealer.FetchData());
			}
			Close();
		}

		public void BuildUI()
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			if (!UICreated)
			{
				GameObject gameObject = ((Component)PlayerSingleton<DealerManagementApp>.Instance.CustomerSelector).gameObject;
				Container = Object.Instantiate<GameObject>(gameObject, gameObject.transform.parent);
				((Object)Container).name = "DeadDropSelector";
				Container.SetActive(true);
				CreateSelectableTemplate();
				RectTransform component = ((Component)Container.transform.Find("Shade/Content/Scroll View/Viewport/Content")).gameObject.GetComponent<RectTransform>();
				GameObject val = new GameObject("Content");
				RectTransform val2 = val.AddComponent<RectTransform>();
				((Transform)val2).SetParent(((Transform)component).parent, false);
				val2.anchorMin = component.anchorMin;
				val2.anchorMax = component.anchorMax;
				val2.pivot = component.pivot;
				val2.anchoredPosition = component.anchoredPosition;
				val2.sizeDelta = component.sizeDelta;
				TitleLabel = ((Component)Container.transform.Find("Shade/Content/Title")).GetComponent<Text>();
				TitleLabel.text = "Select Dead Drop";
				Content = (Transform)(object)val2;
				Object.Destroy((Object)(object)((Component)component).gameObject);
				((Component)Container.transform.Find("Shade/Content/Scroll View")).gameObject.GetComponent<ScrollRect>().content = val2;
				ContentSizeFitter val3 = val.AddComponent<ContentSizeFitter>();
				val3.horizontalFit = (FitMode)0;
				val3.verticalFit = (FitMode)2;
				VerticalLayoutGroup val4 = val.AddComponent<VerticalLayoutGroup>();
				((HorizontalOrVerticalLayoutGroup)val4).childControlHeight = false;
				((HorizontalOrVerticalLayoutGroup)val4).childControlWidth = true;
				((HorizontalOrVerticalLayoutGroup)val4).childForceExpandHeight = false;
				((HorizontalOrVerticalLayoutGroup)val4).childForceExpandWidth = true;
				((HorizontalOrVerticalLayoutGroup)val4).childScaleHeight = false;
				((HorizontalOrVerticalLayoutGroup)val4).childScaleWidth = false;
				CreateSelectable(null, "None");
				for (int i = 0; i <= DeadDrop.DeadDrops.Count - 1; i++)
				{
					Guid gUID = DeadDrop.DeadDrops[i].GUID;
					CreateSelectable(((object)(Guid)(ref gUID)).ToString(), DeadDrop.DeadDrops[i].DeadDropName);
				}
				CreateButton();
				Logger.Debug("DeadDropSelector", "Dead drop selector UI created");
				UICreated = true;
			}
		}

		private void CreateButton()
		{
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			GameObject gameObject = ((Component)((Component)PlayerSingleton<DealerManagementApp>.Instance).transform.Find("Container/Background/Content/Home")).gameObject;
			Button = Object.Instantiate<GameObject>(gameObject, gameObject.transform.parent);
			Button.SetActive(true);
			((Object)Button).name = "DeadDropSelectorButton";
			((Component)Button.transform.Find("Title")).GetComponent<Text>().text = "Dead Drop";
			RectTransform component = ((Component)Button.transform.Find("Value")).GetComponent<RectTransform>();
			component.offsetMax = new Vector2(component.offsetMax.x, 60f);
			component.offsetMin = new Vector2(component.offsetMin.x, 15f);
			component.sizeDelta = new Vector2(component.sizeDelta.x, 40f);
			ButtonLabel = ((Component)component).GetComponent<Text>();
			ButtonLabel.text = "None";
			((Graphic)ButtonLabel).color = new Color(0.6f, 1f, 1f, 1f);
			((UnityEvent)Button.AddComponent<Button>().onClick).AddListener(UnityAction.op_Implicit((Action)OpenSelector));
			void OpenSelector()
			{
				Open(DealerExtension.GetDealer(PlayerSingleton<DealerManagementApp>.Instance.SelectedDealer));
			}
		}

		private void CreateSelectableTemplate()
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(((Component)Container.transform.Find("Shade/Content/Scroll View/Viewport/Content").GetChild(0)).gameObject);
			val.SetActive(false);
			((Object)val).name = "SelectableTemplate";
			Object.Destroy((Object)(object)((Component)val.transform.Find("Mugshot")).gameObject);
			((Component)val.transform.Find("Name")).GetComponent<RectTransform>().sizeDelta = new Vector2(0f, 0f);
			_selectableTemplate = val;
		}

		private void CreateSelectable(string deadDropGuid, string name)
		{
			GameObject val = Object.Instantiate<GameObject>(_selectableTemplate, Content);
			val.SetActive(true);
			((Object)val).name = "Selectable";
			((Component)val.transform.Find("Name")).GetComponent<Text>().text = name;
			((UnityEvent)val.GetComponent<Button>().onClick).AddListener(UnityAction.op_Implicit((Action)Selected));
			_selectables.Add(val);
			void Selected()
			{
				OnSelected(deadDropGuid, name);
			}
		}
	}
	public class SettingsPopup
	{
		public GameObject Container;

		public Text TitleLabel;

		public Button ApplyButton;

		public Transform Content;

		private readonly List<GameObject> _inputFields = new List<GameObject>();

		private DealerExtension _dealer;

		private GameObject _inputFieldTemplate;

		public bool UICreated { get; private set; }

		public bool IsOpen { get; private set; }

		public SettingsPopup()
		{
			GameInput.RegisterExitListener(ExitDelegate.op_Implicit((Action<ExitAction>)RightClick), 4);
		}

		private void RightClick(ExitAction action)
		{
			if (!action.Used && IsOpen)
			{
				action.Used = true;
				Close();
			}
		}

		public void Open(DealerExtension dealerExtension)
		{
			IsOpen = true;
			_dealer = dealerExtension;
			Container.SetActive(true);
			TitleLabel.text = "Adjust Settings (" + ((Object)_dealer.Dealer).name + ")";
			foreach (GameObject inputField in _inputFields)
			{
				inputField.GetComponent<InputField>().text = GetDataValue(((Object)inputField).name);
				inputField.SetActive(true);
			}
		}

		public void Close()
		{
			IsOpen = false;
			Container.SetActive(false);
		}

		private void OnApply()
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Invalid comparison between Unknown and I4
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Invalid comparison between Unknown and I4
			if (!IsOpen)
			{
				return;
			}
			bool flag = false;
			foreach (GameObject inputField in _inputFields)
			{
				InputField component = inputField.GetComponent<InputField>();
				string dataValue = GetDataValue(((Object)inputField).name);
				string text = component.text;
				if (text != dataValue)
				{
					if ((int)component.contentType == 2)
					{
						typeof(DealerExtension).GetField(((Object)inputField).name).SetValue(_dealer, int.Parse(text));
					}
					else if ((int)component.contentType == 3)
					{
						typeof(DealerExtension).GetField(((Object)inputField).name).SetValue(_dealer, float.Parse(text));
					}
					flag = true;
				}
			}
			if (flag)
			{
				if (NetworkSynchronizer.IsSyncing)
				{
					NetworkSynchronizer.Instance.SendData(_dealer.FetchData());
				}
				_dealer.HasChanged = true;
				_dealer.SendPlayerMessage("Damn.. please change your behavior!");
				_dealer.SendMessage("Hmkay .. i'm sorry", notify: false, network: true, 2f);
			}
			Close();
		}

		private void OnCancel()
		{
			Close();
		}

		public void BuildUI()
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: 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)
			if (!UICreated)
			{
				GameObject gameObject = ((Component)PlayerSingleton<MessagesApp>.Instance.ConfirmationPopup).gameObject;
				Container = Object.Instantiate<GameObject>(gameObject, gameObject.transform.parent);
				((Object)Container).name = "SettingsPopup";
				Container.SetActive(true);
				CreateInputFieldTemplate();
				Content = Container.transform.Find("Shade/Content");
				((Component)Content).GetComponent<RectTransform>().sizeDelta = new Vector2(-160f, 100f);
				Object.Destroy((Object)(object)((Component)Content.Find("Subtitle")).gameObject);
				TitleLabel = ((Component)Content.Find("Title")).GetComponent<Text>();
				TitleLabel.text = "Adjust Settings";
				Button[] array = Il2CppArrayBase<Button>.op_Implicit(((Component)Content).GetComponentsInChildren<Button>());
				((UnityEventBase)array[0].onClick).RemoveAllListeners();
				((UnityEvent)array[0].onClick).AddListener(UnityAction.op_Implicit((Action)OnCancel));
				ApplyButton = array[2];
				((Object)((Component)ApplyButton).gameObject).name = "Apply";
				((Component)ApplyButton).GetComponentInChildren<Text>().text = "Apply";
				Button applyButton = ApplyButton;
				ColorBlock colors = default(ColorBlock);
				((ColorBlock)(ref colors)).normalColor = new Color(0.2941f, 0.6863f, 0.8824f, 1f);
				((ColorBlock)(ref colors)).highlightedColor = new Color(0.4532f, 0.7611f, 0.9151f, 1f);
				((ColorBlock)(ref colors)).pressedColor = new Color(0.5674f, 0.8306f, 0.9623f, 1f);
				((ColorBlock)(ref colors)).selectedColor = new Color(0.9608f, 0.9608f, 0.9608f, 1f);
				((ColorBlock)(ref colors)).disabledColor = new Color(0.2941f, 0.6863f, 0.8824f, 1f);
				((ColorBlock)(ref colors)).colorMultiplier = 1f;
				((ColorBlock)(ref colors)).fadeDuration = 0f;
				((Selectable)applyButton).colors = colors;
				((UnityEventBase)ApplyButton.onClick).RemoveAllListeners();
				((UnityEvent)ApplyButton.onClick).AddListener(UnityAction.op_Implicit((Action)OnApply));
				((Graphic)((Component)ApplyButton).GetComponent<Image>()).color = Color.white;
				Object.Destroy((Object)(object)((Component)array[1]).gameObject);
				CreateInputField((ContentType)2, "MaxCustomers", "Max Customers", 0f, 24f);
				CreateInputField((ContentType)3, "Cut", "Cut %", 0f, 1f);
				CreateInputField((ContentType)3, "SpeedMultiplier", "Speed Multiplier");
				if (!ConflictChecker.DisableMoreItemSlots)
				{
					CreateInputField((ContentType)2, "ItemSlots", "Item Slots", 0f, 20f);
				}
				Logger.Debug("SettingsPopup", "Settings popup UI created");
				UICreated = true;
			}
		}

		private void CreateInputFieldTemplate()
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(((Component)((Component)PlayerSingleton<MessagesApp>.Instance.CounterofferInterface).transform.Find("Shade/Content/Selection/SearchInput")).gameObject);
			val.SetActive(false);
			((Object)val).name = "InputFieldUITemplate";
			((UnityEventBase)val.GetComponent<InputField>().onEndEdit).RemoveAllListeners();
			RectTransform component = val.GetComponent<RectTransform>();
			component.offsetMax = new Vector2(-20f, -100f);
			component.offsetMin = new Vector2(20f, -160f);
			RectTransform component2 = ((Component)((Transform)component).Find("Image")).GetComponent<RectTransform>();
			component2.offsetMin = new Vector2(350f, component2.offsetMin.y);
			RectTransform component3 = ((Component)((Transform)component).Find("Text Area")).GetComponent<RectTransform>();
			component3.offsetMin = new Vector2(350f, component3.offsetMin.y);
			Text component4 = ((Component)((Transform)component3).Find("Placeholder")).GetComponent<Text>();
			component4.text = "Set value...";
			RectTransform val2 = new GameObject("Title").AddComponent<RectTransform>();
			((Transform)val2).SetParent((Transform)(object)component);
			((Transform)val2).SetAsFirstSibling();
			val2.sizeDelta = new Vector2(-358f, -13f);
			val2.offsetMax = new Vector2(-150f, -10f);
			val2.offsetMin = new Vector2(10f, 8f);
			val2.anchorMax = new Vector2(1f, 1f);
			val2.anchorMin = new Vector2(0f, 0f);
			Text val3 = ((Component)val2).gameObject.AddComponent<Text>();
			val3.font = component4.font;
			val3.alignment = (TextAnchor)3;
			val3.text = "Title";
			((Graphic)val3).color = Color.black;
			val3.fontSize = 20;
			_inputFieldTemplate = val;
		}

		private void CreateInputField(ContentType type, string key, string description, float rangeMin = 0f, float rangeMax = 0f)
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(_inputFieldTemplate, Content);
			val.SetActive(true);
			((Object)val).name = key;
			float num = 0f;
			if (_inputFields.Count > 0)
			{
				num = 80f * (float)_inputFields.Count;
			}
			RectTransform component = val.GetComponent<RectTransform>();
			component.offsetMax = new Vector2(component.offsetMax.x, component.offsetMax.y - num);
			component.offsetMin = new Vector2(component.offsetMin.x, component.offsetMin.y - num);
			((Component)((Transform)component).Find("Title")).GetComponent<Text>().text = description;
			InputField input = val.GetComponent<InputField>();
			input.contentType = type;
			if (rangeMin != 0f || rangeMax != 0f)
			{
				((UnityEvent<string>)(object)input.onEndEdit).AddListener(UnityAction<string>.op_Implicit((Action<string>)ValidateRange));
			}
			_inputFields.Add(val);
			void ValidateRange(string text)
			{
				if (text.Length > 0)
				{
					float num2 = float.Parse(text);
					if (!(rangeMin <= num2) || !(num2 <= rangeMax))
					{
						input.text = GetDataValue(key);
					}
				}
			}
		}

		private string GetDataValue(string key)
		{
			if (_dealer == null)
			{
				return null;
			}
			return typeof(DealerExtension).GetField(key).GetValue(_dealer).ToString();
		}
	}
	public class SliderPopup
	{
		public GameObject Container;

		public Text TitleLabel;

		public Text SubtitleLabel;

		public Text ValueLabel;

		public Button SendButton;

		public Transform Content;

		public Slider Slider;

		public Action<float> OnSend;

		public Action OnCancel;

		private int _digits;

		private float _stepSize;

		private string _format;

		public bool UICreated { get; private set; }

		public bool IsOpen { get; private set; }

		public SliderPopup()
		{
			GameInput.RegisterExitListener(ExitDelegate.op_Implicit((Action<ExitAction>)RightClick), 4);
		}

		private void RightClick(ExitAction action)
		{
			if (!action.Used && IsOpen)
			{
				action.Used = true;
				Close();
			}
		}

		public void Open(string title, string subtitle, float startValue, float minValue, float maxValue, float stepSize = 0.05f, int digits = 2, Action<float> onSendCallback = null, Action onCancelCallback = null, string format = "")
		{
			IsOpen = true;
			Container.SetActive(true);
			OnSend = onSendCallback;
			OnCancel = onCancelCallback;
			_digits = digits;
			_stepSize = stepSize;
			_format = format;
			TitleLabel.text = title;
			SubtitleLabel.text = subtitle;
			ValueLabel.text = string.Format(_format, GetSteppedValue(startValue));
			Slider.value = startValue;
			Slider.minValue = minValue;
			Slider.maxValue = maxValue;
		}

		public void Close()
		{
			IsOpen = false;
			Container.SetActive(false);
		}

		private void Send()
		{
			if (IsOpen)
			{
				OnSend?.Invoke(GetSteppedValue(Slider.value));
				Close();
			}
		}

		private void Cancel()
		{
			OnCancel?.Invoke();
			Close();
		}

		private void OnValueChanged(float value)
		{
			ValueLabel.text = string.Format(_format, GetSteppedValue(value));
		}

		private float GetSteppedValue(float value)
		{
			return (float)Math.Round(Mathf.Round(value / _stepSize) * _stepSize, _digits);
		}

		public void BuildUI()
		{
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: 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_033c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0373: Unknown result type (might be due to invalid IL or missing references)
			//IL_038a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0433: Unknown result type (might be due to invalid IL or missing references)
			//IL_044a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0474: Unknown result type (might be due to invalid IL or missing references)
			//IL_048b: Unknown result type (might be due to invalid IL or missing references)
			if (!UICreated)
			{
				GameObject gameObject = ((Component)PlayerSingleton<MessagesApp>.Instance.ConfirmationPopup).gameObject;
				Container = Object.Instantiate<GameObject>(gameObject, gameObject.transform.parent);
				((Object)Container).name = "NegotiationPopup";
				Container.SetActive(true);
				Content = Container.transform.Find("Shade/Content");
				((Component)Content).GetComponent<RectTransform>().sizeDelta = new Vector2(-160f, 40f);
				SubtitleLabel = ((Component)Content.Find("Subtitle")).GetComponent<Text>();
				SubtitleLabel.text = "Current: 0.2%\n\nLast offer: 0%";
				ValueLabel = Object.Instantiate<GameObject>(((Component)SubtitleLabel).gameObject, ((Component)SubtitleLabel).transform.parent).GetComponent<Text>();
				((Object)ValueLabel).name = "Value";
				ValueLabel.text = "0%";
				ValueLabel.fontSize = 30;
				ValueLabel.fontStyle = (FontStyle)1;
				RectTransform component = ((Component)ValueLabel).GetComponent<RectTransform>();
				component.anchorMax = new Vector2(1f, 1f);
				component.anchorMin = new Vector2(0f, 0f);
				component.offsetMax = new Vector2(-30f, 200f);
				component.offsetMin = new Vector2(30f, -280f);
				TitleLabel = ((Component)Content.Find("Title")).GetComponent<Text>();
				TitleLabel.text = "Negotiate Cut %";
				Button[] array = Il2CppArrayBase<Button>.op_Implicit(((Component)Content).GetComponentsInChildren<Button>());
				((UnityEventBase)array[0].onClick).RemoveAllListeners();
				((UnityEvent)array[0].onClick).AddListener(UnityAction.op_Implicit((Action)Cancel));
				SendButton = array[2];
				((Object)((Component)SendButton).gameObject).name = "Send";
				((Component)SendButton).GetComponentInChildren<Text>().text = "Send";
				Button sendButton = SendButton;
				ColorBlock colors = default(ColorBlock);
				((ColorBlock)(ref colors)).normalColor = new Color(0.2941f, 0.6863f, 0.8824f, 1f);
				((ColorBlock)(ref colors)).highlightedColor = new Color(0.4532f, 0.7611f, 0.9151f, 1f);
				((ColorBlock)(ref colors)).pressedColor = new Color(0.5674f, 0.8306f, 0.9623f, 1f);
				((ColorBlock)(ref colors)).selectedColor = new Color(0.9608f, 0.9608f, 0.9608f, 1f);
				((ColorBlock)(ref colors)).disabledColor = new Color(0.2941f, 0.6863f, 0.8824f, 1f);
				((ColorBlock)(ref colors)).colorMultiplier = 1f;
				((ColorBlock)(ref colors)).fadeDuration = 0f;
				((Selectable)sendButton).colors = colors;
				((UnityEventBase)SendButton.onClick).RemoveAllListeners();
				((UnityEvent)SendButton.onClick).AddListener(UnityAction.op_Implicit((Action)Send));
				((Graphic)((Component)SendButton).GetComponent<Image>()).color = Color.white;
				GameObject val = Object.Instantiate<GameObject>(GameObject.Find("UI/ItemUIManager/AmountSelector/Slider"), Content);
				((Object)val).name = "Slider";
				RectTransform component2 = val.GetComponent<RectTransform>();
				component2.anchoredPosition = Vector2.zero;
				component2.sizeDelta = new Vector2(280f, 40f);
				Slider = val.GetComponent<Slider>();
				Slider.maxValue = 1f;
				Slider.minValue = 0f;
				Slider.wholeNumbers = false;
				Slider.normalizedValue = 0.5f;
				((UnityEventBase)Slider.onValueChanged).RemoveAllListeners();
				((UnityEvent<float>)(object)Slider.onValueChanged).AddListener(UnityAction<float>.op_Implicit((Action<float>)OnValueChanged));
				RectTransform component3 = ((Component)((Transform)component2).Find("Handle Slide Area/Handle")).GetComponent<RectTransform>();
				component3.anchoredPosition = new Vector2(0f, 0f);
				component3.sizeDelta = new Vector2(40f, 0f);
				RectTransform component4 = ((Component)((Transform)component2).Find("Fill Area/Fill")).GetComponent<RectTransform>();
				component4.anchoredPosition = new Vector2(0f, 0f);
				component4.sizeDelta = new Vector2(40f, 0f);
				val.SetActive(true);
				Object.Destroy((Object)(object)((Component)array[1]).gameObject);
				Logger.Debug("NegotiationPopup", "Negotiation popup UI created");
				UICreated = true;
			}
		}
	}
	public static class UIBuilder
	{
		[CompilerGenerated]
		private sealed class <<Build>g__CreateUI|24_0>d : IEnumerator<object>, IEnumerator, IDisposable
		{
			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 <<Build>g__CreateUI|24_0>d(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

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

			private bool MoveNext()
			{
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitUntil(Func<bool>.op_Implicit((Func<bool>)(() => !Singleton<LoadManager>.Instance.IsLoading && Singleton<LoadManager>.Instance.IsGameLoaded)));
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					SettingsPopup.BuildUI();
					SliderPopup.BuildUI();
					DeadDropSelector.BuildUI();
					CustomersScrollView.BuildUI();
					if (ModConfig.CustomersSearchAndSort)
					{
						CustomerSelector.BuildUI();
					}
					Logger.Msg("UI elements created");
					HasBuild = true;
					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 bool HasBuild { get; private set; }

		public static SettingsPopup SettingsPopup { get; private set; }

		public static SliderPopup SliderPopup { get; private set; }

		public static DeadDropSelector DeadDropSelector { get; private set; }

		public static CustomersScrollView CustomersScrollView { get; private set; }

		public static CustomerSelector CustomerSelector { get; private set; }

		public static void Build()
		{
			if (!HasBuild)
			{
				if (SettingsPopup == null)
				{
					SettingsPopup = new SettingsPopup();
				}
				if (SliderPopup == null)
				{
					SliderPopup = new SliderPopup();
				}
				if (DeadDropSelector == null)
				{
					DeadDropSelector = new DeadDropSelector();
				}
				if (CustomersScrollView == null)
				{
					CustomersScrollView = new CustomersScrollView();
				}
				if (CustomerSelector == null)
				{
					CustomerSelector = new CustomerSelector();
				}
				MelonCoroutines.Start(CreateUI());
			}
			[IteratorStateMachine(typeof(<<Build>g__CreateUI|24_0>d))]
			static IEnumerator CreateUI()
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <<Build>g__CreateUI|24_0>d(0);
			}
		}

		public static void Reset()
		{
			SettingsPopup = null;
			SliderPopup = null;
			DeadDropSelector = null;
			CustomersScrollView = null;
			CustomerSelector = null;
			HasBuild = false;
		}
	}
}
namespace AdvancedDealing.Persistence
{
	public struct DataWrapper
	{
		public string SaveName;

		public List<DealerData> Dealers;

		public List<DeadDropData> DeadDrops;
	}
	public class NetworkSynchronizer
	{
		public SessionData SessionData;

		protected Callback<LobbyChatMsg_t> LobbyChatMsgCallback;

		protected Callback<LobbyDataUpdate_t> LobbyDataUpdateCallback;

		private readonly string _prefix = Hashing.GetStableHashU16("AdvancedDealing").ToString();

		private CSteamID _lobbySteamID;

		private bool _isSyncing;

		private bool _isHost;

		public static NetworkSynchronizer Instance { get; private set; }

		public static bool IsSyncing => Instance._isSyncing;

		public static bool IsNoSyncOrHost => !IsSyncing || (IsSyncing && Instance._isHost);

		public static bool IsHost => Instance._isHost;

		public static CSteamID LocalSteamID => Singleton<Lobby>.Instance.LocalPlayerID;

		public NetworkSynchronizer()
		{
			if (Instance == null)
			{
				Lobby instance = Singleton<Lobby>.Instance;
				instance.onLobbyChange += Action.op_Implicit((Action)OnLobbyChange);
				LobbyChatMsgCallback = Callback<LobbyChatMsg_t>.Create(DispatchDelegate<LobbyChatMsg_t>.op_Implicit((Action<LobbyChatMsg_t>)OnLobbyMessage));
				Instance = this;
			}
		}

		private void StartSyncing()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			_isHost = false;
			_lobbySteamID = Singleton<Lobby>.Instance.LobbySteamID;
			_isSyncing = true;
			Logger.Msg("NetworkSynchronizer", "Synchronization started");
		}

		private void StopSyncing()
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			_isHost = false;
			_lobbySteamID = CSteamID.Nil;
			_isSyncing = false;
			SessionData = null;
			Logger.Msg("NetworkSynchronizer", "Synchronization stopped");
		}

		public void SetAsHost()
		{
			_isHost = true;
			Logger.Debug("NetworkSynchronizer", "Set as host");
		}

		public void SendData(DataBase data)
		{
			SendData(data.DataType, data.Identifier, JsonConvert.SerializeObject((object)data, FileSerializer.JsonSerializerSettings));
		}

		public void SendData(string dataType, string identifier, string dataString)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			if (IsSyncing)
			{
				string text = $"{_prefix}_{dataType}_{identifier}";
				SteamMatchmaking.SetLobbyMemberData(_lobbySteamID, text, dataString);
				SendMessage(text);
				Logger.Debug("NetworkSynchronizer", "Data synced with lobby: " + text);
			}
		}

		public void SendMessage(string text, string identifier = null)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			text = _prefix + "__" + text;
			if (identifier != null)
			{
				text = text + "__" + identifier;
			}
			Il2CppStructArray<byte> bytes = Encoding.UTF8.GetBytes(text);
			SteamMatchmaking.SendLobbyChatMsg(_lobbySteamID, bytes, ((Il2CppArrayBase<byte>)(object)bytes).Length);
		}

		public void FetchData(CSteamID steamId, string key)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			string lobbyMemberData = SteamMatchmaking.GetLobbyMemberData(_lobbySteamID, steamId, key);
			bool flag = false;
			if (lobbyMemberData != null)
			{
				string[] array = key.Split("_");
				if (array[1] != null && array[2] != null)
				{
					string text = array[1];
					string guid = array[2];
					if (text == "DealerData")
					{
						DealerExtension dealer = DealerExtension.GetDealer(guid);
						if (dealer != null)
						{
							DealerData data = JsonConvert.DeserializeObject<DealerData>(lobbyMemberData);
							dealer.PatchData(data);
							flag = true;
						}
					}
					else if (text == "SessionData" && !_isHost)
					{
						SessionData = JsonConvert.DeserializeObject<SessionData>(lobbyMemberData);
						flag = true;
					}
				}
			}
			if (flag)
			{
				Logger.Debug("NetworkSynchronizer", "Data from lobby fetched: " + key);
			}
			else
			{
				Logger.Debug("NetworkSynchronizer", "Could not fetch data from lobby: " + key);
			}
		}

		private void OnLobbyMessage(LobbyChatMsg_t res)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			if (!IsSyncing)
			{
				return;
			}
			Il2CppStructArray<byte> val = Il2CppStructArray<byte>.op_Implicit(new byte[4096]);
			CSteamID val2 = default(CSteamID);
			EChatEntryType val3 = default(EChatEntryType);
			SteamMatchmaking.GetLobbyChatEntry(_lobbySteamID, (int)res.m_iChatID, ref val2, val, ((Il2CppArrayBase<byte>)(object)val).Length, ref val3);
			if (val2 == LocalSteamID)
			{
				return;
			}
			string @string = Encoding.UTF8.GetString(val);
			@string = @string.TrimEnd(new char[1]);
			string[] array = @string.Split("__");
			if (!(array[0] == _prefix))
			{
				return;
			}
			Logger.Debug("NetworkSynchronizer", "Received msg: " + array[1]);
			string text = array[1];
			string text2 = text;
			if (!(text2 == "data_request"))
			{
				if (text2 == "dealer_fired")
				{
					DealerExtension.GetDealer(array[2])?.Fire();
				}
				else
				{
					FetchData(val2, array[1]);
				}
			}
			else
			{
				if (!_isHost)
				{
					return;
				}
				SendData(SessionData);
				foreach (DealerData item in DealerExtension.FetchAllDealerDatas())
				{
					SendData(item);
				}
			}
		}

		private void OnLobbyChange()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			if (Singleton<Lobby>.Instance.IsInLobby && _isSyncing && Singleton<Lobby>.Instance.LobbySteamID != _lobbySteamID)
			{
				_lobbySteamID = Singleton<Lobby>.Instance.LobbySteamID;
			}
			else if (Singleton<Lobby>.Instance.IsInLobby && !_isSyncing)
			{
				StartSyncing();
			}
			else if (!Singleton<Lobby>.Instance.IsInLobby && _isSyncing)
			{
				StopSyncing();
			}
		}
	}
	public class SaveModifier
	{
		[CompilerGenerated]
		private sealed class <<LoadModifications>g__LoadRoutine|15_0>d : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public SaveModifier <>4__this;

			private DataWrapper <data>5__1;

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

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

			[DebuggerHidden]
			public <<LoadModifications>g__LoadRoutine|15_0>d(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<data>5__1 = default(DataWrapper);
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b0: Expected O, but got Unknown
				//IL_0160: Unknown result type (might be due to invalid IL or missing references)
				//IL_0165: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					if (!FileSerializer.LoadFromFile<DataWrapper>(FilePath, out <data>5__1))
					{
						<>4__this.SaveData = new DataWrapper
						{
							SaveName = $"SaveGame_{Singleton<LoadManager>.Instance.ActiveSaveInfo.SaveSlotNumber}",
							Dealers = new List<DealerData>(),
							DeadDrops = new List<DeadDropData>()
						};
					}
					else
					{
						<>4__this.SaveData = new DataWrapper
						{
							SaveName = $"SaveGame_{Singleton<LoadManager>.Instance.ActiveSaveInfo.SaveSlotNumber}",
							Dealers = (<data>5__1.Dealers ?? new List<DealerData>()),
							DeadDrops = (<data>5__1.DeadDrops ?? new List<DeadDropData>())
						};
					}
					DeadDropExtension.Initialize();
					DealerExtension.Initialize();
					if (NetworkSynchronizer.IsSyncing)
					{
						NetworkSynchronizer.Instance.SetAsHost();
						NetworkSynchronizer instance = NetworkSynchronizer.Instance;
						CSteamID lobbySteamID = Singleton<Lobby>.Instance.LobbySteamID;
						instance.SessionData = new SessionData(((object)(CSteamID)(ref lobbySteamID)).ToString())
						{
							AccessInventory = ModConfig.AccessInventory,
							SettingsMenu = ModConfig.SettingsMenu,
							NegotiationModifier = ModConfig.NegotiationModifier
						};
					}
					<>2__current = (object)new WaitForSecondsRealtime(2f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>4__this.SavegameLoaded = true;
					UIBuilder.Build();
					Logger.Msg("Savegame modifications successfully injected");
					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 <<LoadModificationsAsClient>g__ClientLoadRoutine|16_0>d : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public SaveModifier <>4__this;

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

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

			[DebuggerHidden]
			public <<LoadModificationsAsClient>g__ClientLoadRoutine|16_0>d(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

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

			private bool MoveNext()
			{
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0069: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>4__this.SaveData = new DataWrapper
					{
						SaveName = "temporary",
						Dealers = new List<DealerData>()
					};
					DeadDropExtension.Initialize();
					DealerExtension.Initialize();
					<>2__current = (object)new WaitForSecondsRealtime(2f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>4__this.SavegameLoaded = true;
					NetworkSynchronizer.Instance.SendMessage("data_request");
					UIBuilder.Build();
					Logger.Msg("Savegame modifications successfully injected");
					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 SaveModifier Instance { get; private set; }

		public DataWrapper SaveData { get; private set; }

		public bool SavegameLoaded { get; private set; }

		private static string FilePath => Path.Combine(Singleton<LoadManager>.Instance.ActiveSaveInfo.SavePath, "AdvancedDealing.json");

		public SaveModifier()
		{
			if (Instance == null)
			{
				Singleton<SaveManager>.Instance.onSaveComplete.AddListener(UnityAction.op_Implicit((Action)OnSaveComplete));
				Instance = this;
			}
		}

		public void LoadModifications()
		{
			Logger.Msg("Preparing savegame modifications...");
			if (Singleton<Lobby>.Instance.IsInLobby && !Singleton<Lobby>.Instance.IsHost)
			{
				LoadModificationsAsClient();
			}
			else
			{
				MelonCoroutines.Start(LoadRoutine());
			}
			[IteratorStateMachine(typeof(<<LoadModifications>g__LoadRoutine|15_0>d))]
			IEnumerator LoadRoutine()
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <<LoadModifications>g__LoadRoutine|15_0>d(0)
				{
					<>4__this = this
				};
			}
		}

		private void LoadModificationsAsClient()
		{
			MelonCoroutines.Start(ClientLoadRoutine());
			[IteratorStateMachine(typeof(<<LoadModificationsAsClient>g__ClientLoadRoutine|16_0>d))]
			IEnumerator ClientLoadRoutine()
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <<LoadModificationsAsClient>g__ClientLoadRoutine|16_0>d(0)
				{
					<>4__this = this
				};
			}
		}

		public void ClearModifications()
		{
			UIBuilder.Reset();
			List<DealerExtension> allDealers = DealerExtension.GetAllDealers();
			for (int num = allDealers.Count - 1; num >= 0; num--)
			{
				allDealers[num].Destroy();
			}
			SavegameLoaded = false;
			Logger.Msg("Savegame modifications cleared");
		}

		private void OnSaveComplete()
		{
			if (NetworkSynchronizer.IsNoSyncOrHost)
			{
				DataWrapper dataWrapper = default(DataWrapper);
				dataWrapper.SaveName = $"SaveGame_{Singleton<LoadManager>.Instance.ActiveSaveInfo.SaveSlotNumber}";
				dataWrapper.Dealers = DealerExtension.FetchAllDealerDatas();
				dataWrapper.DeadDrops = DeadDropExtension.FetchAllDeadDropDatas();
				DataWrapper data = dataWrapper;
				Logger.Msg("Data for " + data.SaveName + " saved");
				FileSerializer.SaveToFile(FilePath, data);
			}
		}
	}
}
namespace AdvancedDealing.Persistence.IO
{
	public static class FileSerializer
	{
		public static readonly JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings
		{
			NullValueHandling = (NullValueHandling)0,
			MissingMemberHandling = (MissingMemberHandling)0,
			Formatting = (Formatting)1
		};

		public static Type LastLoadedDataType { get; private set; }

		public static string LastLoadedDataString { get; private set; }

		public static bool LoadFromFile<T>(string filePath, out T data) where T : struct
		{
			if (File.Exists(filePath))
			{
				string text = File.ReadAllText(filePath);
				data = JsonConvert.DeserializeObject<T>(text, JsonSerializerSettings);
				LastLoadedDataType = data.GetType();
				LastLoadedDataString = text;
				Logger.Debug("Loaded from file: " + filePath);
				return true;
			}
			data = default(T);
			return false;
		}

		public static void SaveToFile<T>(string filePath, T data) where T : struct
		{
			string contents = JsonConvert.SerializeObject((object)data, JsonSerializerSettings);
			File.WriteAllText(filePath, contents);
			Logger.Debug("Saved to file: " + filePath);
		}
	}
}
namespace AdvancedDealing.Persistence.Datas
{
	public abstract class DataBase
	{
		public string DataType;

		public string ModVersion;

		public string Identifier;

		public DataBase(string identifier)
		{
			DataType = GetType().Name;
			ModVersion = "1.3.0";
			Identifier = identifier;
		}

		public virtual bool IsEqual(object other)
		{
			if (!GetType().Equals(other.GetType()))
			{
				throw new Exception($"Tried to compare {GetType()} with {other.GetType()}");
			}
			bool result = true;
			FieldInfo[] fields = GetType().GetFields();
			FieldInfo[] array = fields;
			foreach (FieldInfo fieldInfo in array)
			{
				if (fieldInfo.GetValue(this) != fieldInfo.GetValue(other))
				{
					result = false;
					break;
				}
			}
			return result;
		}

		public virtual void Merge(DataBase other)
		{
			FieldInfo[] fields = GetType().GetFields();
			FieldInfo[] array = fields;
			foreach (FieldInfo fieldInfo in array)
			{
				if (fieldInfo.GetValue(other) == null || fieldInfo.GetValue(this) != fieldInfo.GetValue(other))
				{
					fieldInfo.SetValue(this, fieldInfo.GetValue(other));
				}
			}
		}
	}
	public class DeadDropData : DataBase
	{
		public string CashCollectionQuest;

		public string RefillProductsQuest;

		public DeadDropData(string identifier, bool loadDefaults = false)
			: base(identifier)
		{
			if (loadDefaults)
			{
				LoadDefaults();
			}
		}

		public void LoadDefaults()
		{
		}
	}
	public class DealerData : DataBase
	{
		public string DeadDrop;

		public int MaxCustomers;

		public int ItemSlots;

		public float Cut;

		public float SpeedMultiplier;

		public bool DeliverCash;

		public bool PickupProducts;

		public float CashThreshold;

		public int ProductThreshold;

		public int DaysUntilNextNegotiation;

		public DealerData(string identifier, bool loadDefaults = false)
			: base(identifier)
		{
			if (loadDefaults)
			{
				LoadDefaults();
			}
		}

		public void LoadDefaults()
		{
			DeadDrop = null;
			MaxCustomers = 8;
			ItemSlots = 5;
			Cut = 0.2f;
			SpeedMultiplier = 1f;
			DeliverCash = false;
			PickupProducts = false;
			CashThreshold = 1500f;
			ProductThreshold = 20;
			DaysUntilNextNegotiation = 0;
		}
	}
	public class SessionData : DataBase
	{
		public bool AccessInventory;

		public bool SettingsMenu;

		public float NegotiationModifier;

		public SessionData(string identifier)
			: base(identifier)
		{
		}
	}
}
namespace AdvancedDealing.Patches
{
	[HarmonyPatch(typeof(CustomerSelector))]
	public class CustomerSelectorPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Open")]
		public static void OpenPostfix()
		{
			if (UIBuilder.CustomerSelector.UICreated)
			{
				UIBuilder.CustomerSelector.SortCustomers();
				UIBuilder.CustomerSelector.Searchbar.text = string.Empty;
			}
		}
	}
	[HarmonyPatch(typeof(DealerManagementApp))]
	public class DealerManagementAppPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("SetDisplayedDealer")]
		public static void SetDisplayedDealerPostfix(DealerManagementApp __instance, Dealer dealer)
		{
			if (!SaveModifier.Instance.SavegameLoaded || !UIBuilder.HasBuild)
			{
				return;
			}
			DealerExtension dealer2 = DealerExtension.GetDealer(dealer);
			if (dealer2 != null)
			{
				string text = "None";
				string deadDrop = dealer2.DeadDrop;
				if (deadDrop != null)
				{
					DeadDropExtension deadDrop2 = DeadDropExtension.GetDeadDrop(dealer2.DeadDrop);
					text = deadDrop2.DeadDrop.DeadDropName;
				}
				UIBuilder.DeadDropSelector.ButtonLabel.text = text;
				UIBuilder.CustomersScrollView.TitleLabel.text = $"Assigned Customers ({dealer2.Dealer.AssignedCustomers.Count}/{dealer2.MaxCustomers})";
				if (dealer2.Dealer.AssignedCustomers.Count < dealer2.MaxCustomers)
				{
					UIBuilder.CustomersScrollView.AssignButton.SetActive(true);
				}
				else
				{
					UIBuilder.CustomersScrollView.AssignButton.SetActive(false);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Dealer))]
	public class DealerPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("OnTick")]
		public static bool OnTickPrefix(Dealer __instance)
		{
			if (DealerExtension.DealerExists(__instance))
			{
				DealerExtension dealer = DealerExtension.GetDealer(__instance);
				if (dealer.HasActiveBehaviour)
				{
					dealer.Dealer.UpdatePotentialDealerPoI();
					return false;
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(App<MessagesApp>))]
	public class MessagesAppPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("SetOpen")]
		public static void SetOpenPostfix()
		{
			if (!SaveModifier.Instance.SavegameLoaded)
			{
				return;
			}
			foreach (Conversation allConversation in Conversation.GetAllConversations())
			{
				allConversation.PatchSendableMessages();
			}
		}
	}
	[HarmonyPatch(typeof(NPCBehaviour))]
	public class NPCBehaviourPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("Update")]
		public static bool UpdatePrefix(NPCBehaviour __instance)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			Guid gUID = __instance.Npc.GUID;
			if (DealerExtension.DealerExists(((object)(Guid)(ref gUID)).ToString()))
			{
				gUID = __instance.Npc.GUID;
				DealerExtension dealer = DealerExtension.GetDealer(((object)(Guid)(ref gUID)).ToString());
				if (dealer.HasActiveBehaviour)
				{
					return false;
				}
			}
			return true;
		}
	}
}
namespace AdvancedDealing.NPCs.Behaviour
{
	public abstract class DealerBehaviour
	{
		public const int MAX_CONSECUTIVE_PATHING_FAILURES = 5;

		public int Priority;

		protected int ConsecutivePathingFailures;

		protected DealerExtension Dealer;

		private Vector3 _lastDestination;

		private bool _enableScheduleOnEnd = false;

		public virtual string Name => "Behaviour";

		public virtual bool IsEnabled { get; protected set; }

		public bool IsActive { get; protected set; }

		public bool HasStarted { get; protected set; }

		protected NPCMovement Movement => ((NPC)Dealer.Dealer).Movement;

		private Behaviour activeBehaviour
		{
			get
			{
				NPCBehaviour behaviour = ((NPC)Dealer.Dealer).Behaviour;
				return (behaviour != null) ? behaviour.activeBehaviour : null;
			}
		}

		private NPCScheduleManager schedule => ((Component)Dealer.Dealer).GetComponentInChildren<NPCScheduleManager>();

		public DealerBehaviour(DealerExtension dealer)
		{
			Dealer = dealer;
			((NPC)dealer.Dealer).Health.onKnockedOut.AddListener(UnityAction.op_Implicit((Action)OnKnockOutOrDie));
			((NPC)dealer.Dealer).Health.onDie.AddListener(UnityAction.op_Implicit((Action)OnKnockOutOrDie));
			((NPC)dealer.Dealer).Health.onRevive.AddListener(UnityAction.op_Implicit((Action)OnRevive));
		}

		public virtual void Enable()
		{
			IsEnabled = true;
			Logger.Debug("DealerBehaviour", "Behaviour for " + ((NPC)Dealer.Dealer).fullName + " enabled: " + Name);
		}

		public void Disable()
		{
			IsEnabled = false;
			if (HasStarted)
			{
				End();
			}
			Logger.Debug("DealerBehaviour", "Behaviour for " + ((NPC)Dealer.Dealer).fullName + " disabled: " + Name);
		}

		public virtual void Start()
		{
			HasStarted = true;
			IsActive = true;
			Dealer.SetActiveBehaviour(this);
			Behaviour obj = activeBehaviour;
			if (obj != null)
			{
				obj.Pause();
			}
			if ((Object)(object)schedule != (Object)null && schedule.ScheduleEnabled)
			{
				schedule.DisableSchedule();
				_enableScheduleOnEnd = true;
			}
			Logger.Debug("DealerBehaviour", "Behaviour for " + ((NPC)Dealer.Dealer).fullName + " started: " + Name);
		}

		public virtual void End()
		{
			HasStarted = false;
			IsActive = false;
			Disable();
			Dealer.SetActiveBehaviour(null);
			if (_enableScheduleOnEnd && (Object)(object)schedule != (Object)null)
			{
				schedule.EnableSchedule();
			}
			Logger.Debug("DealerBehaviour", "Behaviour for " + ((NPC)Dealer.Dealer).fullName + " ended: " + Name);
		}

		public virtual void Pause()
		{
			IsActive = false;
			if (_enableScheduleOnEnd && (Object)(object)schedule != (Object)null)
			{
				schedule.EnableSchedule();
			}
			Logger.Debug("DealerBehaviour", "Behaviour for " + ((NPC)Dealer.Dealer).fullName + " paused: " + Name);
		}

		public virtual void Resume()
		{
			IsActive = true;
			if ((Object)(object)schedule != (Object)null && schedule.ScheduleEnabled)
			{
				schedule.DisableSchedule();
				_enableScheduleOnEnd = true;
			}
			Logger.Debug("DealerBehaviour", "Behaviour for " + ((NPC)Dealer.Dealer).fullName + " resumed: " + Name);
		}

		public virtual void OnActiveTick()
		{
			Behaviour obj = activeBehaviour;
			if (obj != null)
			{
				obj.Pause();
			}
		}

		protected virtual void SetDestination(Vector3 position, bool teleportIfFail = true, float successThreshold = 1f)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: 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_007c: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			if (InstanceFinder.IsServer)
			{
				if (teleportIfFail && ConsecutivePathingFailures >= 5 && !Movement.CanGetTo(position, 1f))
				{
					Logger.Debug("DealerBehaviour", $"Too many pathing failures for {((NPC)Dealer.Dealer).fullName}. Warping to {position}.");
					NavMeshHit val = default(NavMeshHit);
					NavMeshUtility.SamplePosition(position, ref val, 5f, -1, true);
					position = ((NavMeshHit)(ref val)).position;
					Movement.Warp(position);
					WalkCallback((WalkResult)4);
				}
				else
				{
					_lastDestination = position;
					Movement.SetDestination(position, Action<WalkResult>.op_Implicit((Action<WalkResult>)WalkCallback), successThreshold, 0.1f);
				}
			}
		}

		protected bool IsAtDestination()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			return Vector3.Distance(Movement.FootPosition, _lastDestination) < 2f;
		}

		protected virtual void WalkCallback(WalkResult res)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Invalid comparison between Unknown and I4
			if (IsActive)
			{
				if ((int)res == 0)
				{
					ConsecutivePathingFailures++;
				}
				else
				{
					ConsecutivePathingFailures = 0;
				}
			}
		}

		private void OnKnockOutOrDie()
		{
			if (IsEnabled && HasStarted)
			{
				Pause();
			}
		}

		private void OnRevive()
		{
			if (IsEnabled && HasStarted)
			{
				Resume();
			}
		}
	}
	public class DeliverCashDealerBehaviour : DealerBehaviour
	{
		[CompilerGenerated]
		private sealed class <<BeginDelivery>g__DeliveryRoutine|10_0>d : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public DeliverCashDealerBehaviour <>4__this;

			private float <cash>5__1;

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

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

			[DebuggerHidden]
			public <<BeginDelivery>g__DeliveryRoutine|10_0>d(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

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

			private bool MoveNext()
			{
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0075: Unknown result type (might be due to invalid IL or missing references)
				//IL_007f: Expected O, but got Unknown
				//IL_025a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0264: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<cash>5__1 = <>4__this.Dealer.Dealer.Cash;
					<>4__this.Movement.FaceDirection(<>4__this._deadDrop.GetPosition(), 0.5f);
					<>2__current = (object)new WaitForSeconds(2f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					((NPC)<>4__this.Dealer.Dealer).SetAnimationTrigger("GrabItem");
					if (<>4__this._deadDrop.IsFull())
					{
						<>4__this._deadDropIsFull = true;
						<>4__this.Dealer.SendMessage("Could not deliver cash to dead drop " + <>4__this._deadDrop.DeadDrop.DeadDropName + ". There is no space inside!", ModConfig.NotifyOnAction);
						Logger.Debug("Cash delivery for " + ((NPC)<>4__this.Dealer.Dealer).fullName + " failed: Dead drop is full");
						break;
					}
					((StorageEntity)<>4__this._deadDrop.DeadDrop.Storage).InsertItem((ItemInstance)(object)NetworkSingleton<MoneyManager>.Instance.GetCashInstance(<cash>5__1), true);
					<>4__this.Dealer.SendMessage($"I've put ${<cash>5__1:F0} inside the dead drop {((Object)<>4__this._deadDrop.DeadDrop).name}.", ModConfig.NotifyOnAction);
					if (ModConfig.NotifyOnAction)
					{
					}
					<>4__this.Dealer.Dealer.ChangeCash(0f - <cash>5__1);
					Logger.Debug("Cash from " + ((NPC)<>4__this.Dealer.Dealer).fullName + " delivered successfully");
					<>2__current = (object)new WaitUntil(Func<bool>.op_Implicit((Func<bool>)(() => <>4__this.Dealer.Dealer.Cash < <>4__this.Dealer.CashThreshold)));
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -1;
					break;
				}
				<>4__this.End();
				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 <<BeginInstantDelivery>g__InstantDeliveryRoutine|11_0>d : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public DeliverCashDealerBehaviour <>4__this;

			private float <cash>5__1;

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

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

			[DebuggerHidden]
			public <<BeginInstantDelivery>g__InstantDeliveryRoutine|11_0>d(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

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

			private bool MoveNext()
			{
				//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ee: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<cash>5__1 = <>4__this.Dealer.Dealer.Cash;
					NetworkSingleton<MoneyManager>.Instance.ChangeCashBalance(<cash>5__1, true, true);
					<>4__this.Dealer.SendMessage($"Sent you ${<cash>5__1:F0} from my earnings.", ModConfig.NotifyOnAction);
					<>4__this.Dealer.Dealer.ChangeCash(0f - <cash>5__1);
					<>2__current = (object)new WaitUntil(Func<bool>.op_Implicit((Func<bool>)(() => <>4__this.Dealer.Dealer.Cash < <>4__this.Dealer.CashThreshold)));
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>4__this.End();
					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();
			}
		}

		private DeadDropExtension _deadDrop;

		private object _deliveryRoutine;

		private object _instantDeliveryRoutine;

		private bool _deadDropIsFull = false;

		public override string Name => "Deliver cash";

		public DeliverCashDealerBehaviour(DealerExtension dealer)
			: base(dealer)
		{
			Priority = 1;
		}

		public override void Start()
		{
			_deadDrop = DeadDropExtension.GetDeadDrop(Dealer.DeadDrop);
			if (!_deadDropIsFull || _deadDrop == null || !_deadDrop.IsFull())
			{
				_deadDropIsFull = false;
				base.Start();
			}
		}

		public override void End()
		{
			base.End();
			StopRoutines();
		}

		public override void OnActiveTick()
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			if (!base.IsActive || _instantDeliveryRoutine != null)
			{
				return;
			}
			base.OnActiveTick();
			if (_deadDrop == null)
			{
				BeginInstantDelivery();
				return;
			}
			if (ModConfig.SkipMovement)
			{
				BeginDelivery();
				return;
			}
			if (!(Dealer.Dealer.Cash < Dealer.CashThreshold))
			{
				if (_deadDrop != null)
				{
					Guid gUID = _deadDrop.DeadDrop.GUID;
					if (((object)(Guid)(ref gUID)).ToString() != Dealer.DeadDrop)
					{
						goto IL_00c3;
					}
				}
				if (Dealer.DeliverCash)
				{
					if (_deliveryRoutine == null && !base.Movement.IsMoving)
					{
						if (IsAtDestination())
						{
							BeginDelivery();
						}
						else
						{
							SetDestination(_deadDrop.GetPosition(), teleportIfFail: true, 2f);
						}
					}
					return;
				}
			}
			goto IL_00c3;
			IL_00c3:
			End();
		}

		private void BeginDelivery()
		{
			if (_deliveryRoutine == null)
			{
				_deliveryRoutine = MelonCoroutines.Start(DeliveryRoutine());
			}
			[IteratorStateMachine(typeof(<<BeginDelivery>g__DeliveryRoutine|10_0>d))]
			IEnumerator DeliveryRoutine()
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <<BeginDelivery>g__DeliveryRoutine|10_0>d(0)
				{
					<>4__this = this
				};
			}
		}

		private void BeginInstantDelivery()
		{
			if (_instantDeliveryRoutine == null)
			{
				_instantDeliveryRoutine = MelonCoroutines.Start(InstantDeliveryRoutine());
			}
			[IteratorStateMachine(typeof(<<BeginInstantDelivery>g__InstantDeliveryRoutine|11_0>d))]
			IEnumerator InstantDeliveryRoutine()
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <<BeginInstantDelivery>g__InstantDeliveryRoutine|11_0>d(0)
				{
					<>4__this = this
				};
			}
		}

		private void StopRoutines()
		{
			if (_deliveryRoutine != null)
			{
				MelonCoroutines.Stop(_deliveryRoutine);
				_deliveryRoutine = null;
			}
			if (_instantDeliveryRoutine != null)
			{
				MelonCoroutines.Stop(_instantDeliveryRoutine);
				_instantDeliveryRoutine = null;
			}
		}
	}
	public class PickupProductsDealerBehaviour : DealerBehaviour
	{
		[CompilerGenerated]
		private sealed class <<BeginPickup>g__PickupRoutine|9_0>d : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public PickupProductsDealerBehaviour <>4__this;

			private bool <shouldNotify>5__1;

			private Dictionary<ProductItemInstance, ItemSlot> <products>5__2;

			private int <totalAmount>5__3;

			private int <freeSlots2>5__4;

			private Dictionary<ProductItemInstance, ItemSlot>.Enumerator <>s__5;

			private KeyValuePair<ProductItemInstance, ItemSlot> <product>5__6;

			private int <freeSlots>5__7;

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

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

			[DebuggerHidden]
			public <<BeginPickup>g__PickupRoutine|9_0>d(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<products>5__2 = null;
				<>s__5 = default(Dictionary<ProductItemInstance, ItemSlot>.Enumerator);
				<product>5__6 = default(KeyValuePair<ProductItemInstance, ItemSlot>);
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_005a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0064: Expected O, but got Unknown
				//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ed: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>4__this.Movement.FaceDirection(<>4__this._deadDrop.GetPosition(), 0.5f);
					<>2__current = (object)new WaitForSeconds(2f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					((NPC)<>4__this.Dealer.Dealer).SetAnimationTrigger("GrabItem");
					<shouldNotify>5__1 = true;
					if (<>4__this._deadDrop.GetAllProducts().Count > 0)
					{
						<products>5__2 = <>4__this._deadDrop.GetAllProducts();
						<>s__5 = <products>5__2.GetEnumerator();
						try
						{
							while (<>s__5.MoveNext())
							{
								<product>5__6 = <>s__5.Current;
								if (<>4__this.Dealer.IsInventoryFull(out <freeSlots>5__7) || <freeSlots>5__7 <= 1)
								{
									break;
								}
								((NPC)<>4__this.Dealer.Dealer).Inventory.InsertItem((ItemInstance)(object)<product>5__6.Key, true);
								<product>5__6.Value.ChangeQuantity(-((ItemInstance)<product>5__6.Key).Quantity, false);
								<product>5__6 = default(KeyValuePair<ProductItemInstance, ItemSlot>);
							}
						}
						finally
						{
							((IDisposable)<>s__5).Dispose();
						}
						<>s__5 = default(Dictionary<ProductItemInstance, ItemSlot>.Enumerator);
						<>4__this.Dealer.GetAllProducts(out <totalAmount>5__3);
						if (<totalAmount>5__3 <= <>4__this.Dealer.ProductThreshold && !<>4__this.Dealer.IsInventoryFull(out <freeSlots2>5__4) && <freeSlots2>5__4 > 1)
						{
							<shouldNotify>5__1 = true;
						}
						else
						{
							<shouldNotify>5__1 = false;
							Logger.Debug("Product pickup for " + ((NPC)<>4__this.Dealer.Dealer).fullName + " was successfull");
						}
						<products>5__2 = null;
					}
					if (<shouldNotify>5__1)
					{
						<>4__this.Dealer.SendMessage("Could not pickup products at dead drop " + <>4__this._deadDrop.DeadDrop.DeadDropName + ". There are no products inside!", ModConfig.NotifyOnAction);
						<>4__this._deadDropIsEmpty = true;
						if (ModConfig.NotifyOnAction)
						{
						}
						Logger.Debug("Product pickup for " + ((NPC)<>4__this.Dealer.Dealer).fullName + " failed: Dead drop is empty");
					}
					<>2__current = (object)new WaitForSeconds(2f);
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -1;
					<>4__this.End();
					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();
			}
		}

		private DeadDropExtension _deadDrop;

		private object _pickupRoutine;

		private bool _deadDropIsEmpty = false;

		public override string Name => "Pickup products";

		public PickupProductsDealerBehaviour(DealerExtension dealer)
			: base(dealer)
		{
			Priority = 2;
		}

		public override void Start()
		{
			_deadDrop = DeadDropExtension.GetDeadDrop(Dealer.DeadDrop);
			if (!_deadDropIsEmpty || _deadDrop == null || _deadDrop.GetAllProducts().Count > 0)
			{
				_deadDropIsEmpty = false;
				base.Start();
			}
		}

		public override void End()
		{
			base.End();
			StopRoutines();
		}

		public override void OnActiveTick()
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			if (!base.IsActive)
			{
				return;
			}
			base.OnActiveTick();
			if (_deadDrop == null)
			{
				End();
				return;
			}
			if (ModConfig.SkipMovement)
			{
				BeginPickup();
				return;
			}
			if (_deadDrop != null)
			{
				Guid gUID = _deadDrop.DeadDrop.GUID;
				if (((object)(Guid)(ref gUID)).ToString() != Dealer.DeadDrop)
				{
					goto IL_009a;
				}
			}
			if (Dealer.PickupProducts)
			{
				if (_pickupRoutine == null && !base.Movement.IsMoving)
				{
					if (IsAtDestination())
					{
						BeginPickup();
					}
					else
					{
						SetDestination(_deadDrop.GetPosition(), teleportIfFail: true, 2f);
					}
				}
				return;
			}
			goto IL_009a;
			IL_009a:
			End();
		}

		private void BeginPickup()
		{
			if (_pickupRoutine == null)
			{
				_pickupRoutine = MelonCoroutines.Start(PickupRoutine());
			}
			[IteratorStateMachine(typeof(<<BeginPickup>g__PickupRoutine|9_0>d))]
			IEnumerator PickupRoutine()
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <<BeginPickup>g__PickupRoutine|9_0>d(0)
				{
					<>4__this = this
				};
			}
		}

		private void StopRoutines()
		{
			if (_pickupRoutine != null)
			{
				MelonCoroutines.Stop(_pickupRoutine);
				_pickupRoutine = null;
			}
		}
	}
}
namespace AdvancedDealing.Messaging
{
	public class Conversation
	{
		public readonly NPC NPC;

		public bool UIPatched;

		private static readonly List<Conversation> cache = new List<Conversation>();

		private readonly List<MessageBase> _sendableMessages = new List<MessageBase>();

		private readonly List<MessageBase> _patchedMessages = new List<MessageBase>();

		public MSGConversation S1Conversation => NPC.MSGConversation;

		public Conversation(NPC npc)
		{
			NPC = npc;
			Logger.Debug("Conversation", "Conversation created: " + npc.fullName);
			cache.Add(this);
		}

		public void PatchSendableMessages()
		{
			if ((Object)(object)NPC == (Object)null || S1Conversation == null)
			{
				return;
			}
			foreach (MessageBase msg in _sendableMessages)
			{
				bool flag = S1Conversation.Sendables.Exists(Predicate<SendableMessage>.op_Implicit((Func<SendableMessage, bool>)((SendableMessage x) => x.Text == msg.Text)));
				if (!_patchedMessages.Contains(msg) && !flag)
				{
					SendableMessage val = S1Conversation.CreateSendableMessage(msg.Text);
					val.ShouldShowCheck = BoolCheck.op_Implicit((Func<SendableMessage, bool>)msg.ShouldShowCheck);
					val.disableDefaultSendBehaviour = msg.DisableDefaultSendBehaviour;
					val.onSelected = Action.op_Implicit((Action)msg.OnSelected);
					val.onSent = Action.op_Implicit((Action)msg.OnSent);
					_patchedMessages.Add(msg);
				}
			}
			if (!UIPatched)
			{
				NPC.ConversationCanBeHidden = false;
				S1Conversation.EnsureUIExists();
				S1Conversation.SetEntryVisibility(true);
				UIPatched = true;
			}
		}

		public void Destroy()
		{
			if ((Object)(object)NPC != (Object)null)
			{
				NPC.ConversationCanBeHidden = true;
			}
			UIPatched = false;
			cache.Remove(this);
		}

		public void AddSendableMessage(MessageBase message)
		{
			Type type = message.GetType();
			if (!_sendableMessages.Exists((MessageBase a) => a.GetType() == type))
			{
				message.SetReferences(NPC, this);
				_sendableMessages.Add(message);
			}
		}

		public static Conversation GetConversation(string npcGuid)
		{
			Conversation conversation = cache.Find(delegate(Conversation x)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				Guid gUID = x.NPC.GUID;
				return ((object)(Guid)(ref gUID)).ToString().Contains(npcGuid);
			});
			if (conversation == null)
			{
				Logger.Error("Conversation", "Could not find conversation for: " + npcGuid);
				return null;
			}
			return conversation;
		}

		public static List<Conversation> GetAllConversations()
		{
			return cache;
		}

		public static void ClearAll()
		{
			cache.Clear();
			Logger.Debug("Conversation", "Conversations deinitialized");
		}

		public static bool ConversationExists(string npcName)
		{
			Conversation conversation = cache.Find((Conversation x) => ((Object)x.NPC).name.Contains(npcName));
			return conversation != null;
		}
	}
}
namespace AdvancedDealing.Messaging.Messages
{
	public class AccessInventoryMessage : MessageBase
	{
		private readonly DealerExtension _dealer;

		public override string Text => "Access inventory";

		public override bool DisableDefaultSendBehaviour => true;

		public AccessInventoryMessage(DealerExtension dealerExtension)
		{
			_dealer = dealerExtension;
			base..ctor();
		}

		public override bool ShouldShowCheck(SendableMessage sMsg)
		{
			if (_dealer.Dealer.IsRecruited && ModConfig.AccessInventory)
			{
				return true;
			}
			return false;
		}

		public override void OnSelected()
		{
			Singleton<GameplayMenu>.Instance.SetIsOpen(false);
			_dealer.Dealer.TradeItems();
		}
	}
	public class AdjustSettingsMessage : MessageBase
	{
		private readonly DealerExtension _dealer;

		public override string Text => "Need to adjust settings";

		public override bool DisableDefaultSendBehaviour => true;

		public AdjustSettingsMessage(DealerExtension dealerExtension)
		{
			_dealer = dealerExtension;
			base..ctor();
		}

		public override bool ShouldShowCheck(SendableMessage sMsg)
		{
			if (_dealer.Dealer.IsRecruited && ModConfig.SettingsMenu)
			{
				return true;
			}
			return false;
		}

		public override void OnSelected()
		{
			UIBuilder.SettingsPopup.Open(_dealer);
		}
	}
	public class DisableDeliverCashMessage : MessageBase
	{
		private readonly DealerExtension _dealer;

		public override string Text => "Stop delivering cash";

		public override bool DisableDefaultSendBehaviour => true;

		public DisableDeliverCashMessage(DealerExtension dealerExtension)
		{
			_dealer = dealerExtension;
			base..ctor();
		}

		public override bool ShouldShowCheck(SendableMessage sMsg)
		{
			if (_dealer.Dealer.IsRecruited && _dealer.DeliverCash)
			{
				return true;
			}
			return false;
		}

		public override void OnSelected()
		{
			_dealer.DeliverCash = false;
			_dealer.SendPlayerMessage("The dead drops are not safe atm... I will meet you to take the cash!");
			_dealer.SendMessage("Okay", notify: false, network: true, 2f);
		}
	}
	internal class DisableProductPickupMessage : MessageBase
	{
		private readonly DealerExtension _dealer;

		public override string Text => "Stop picking up products";

		public override bool DisableDefaultSendBehaviour => true;

		public DisableProductPickupMessage(DealerExtension dealerExtension)
		{
			_dealer = dealerExtension;
			base..ctor();
		}

		public override bool ShouldShowCheck(SendableMessage sMsg)
		{
			if (_dealer.Dealer.IsRecruited && _dealer.PickupProducts)
			{
				return true;
			}
			return false;
		}

		public override void OnSelected()
		{
			_dealer.PickupProducts = false;
			_dealer.SendPlayerMessage("We can't use the dead drops for some time. I will meet you to bring new products!");
			_dealer.SendMessage("Waiting for you", notify: false, network: true, 2f);
		}
	}
	public class EnableDeliverCashMessage : MessageBase
	{
		private readonly DealerExtension _dealer;

		public override string Text => "Please deliver cash";

		public override bool DisableDefaultSendBehaviour => true;

		public EnableDeliverCashMessage(DealerExtension dealerExtension)
		{
			_dealer = dealerExtension;
			base..ctor();
		}

		public override bool ShouldShowCheck(SendableMessage sMsg)
		{
			if (_dealer.Dealer.IsRecruited && !_dealer.DeliverCash)
			{
				return true;
			}
			return false;
		}

		public override void OnSelected()
		{
			UIBuilder.SliderPopup.Open("Cash Threshold (" + ((Object)_dealer.Dealer).name + ")", null, _dealer.CashThreshold, 100f, 10000f, 50f, 0, OnSend, null, "${0:0}");
		}

		private void OnSend(float value)
		{
			_dealer.DeliverCash = true;
			_dealer.CashThreshold = value;
			_dealer.SendPlayerMessage($"Yoo, could you deliver your cash to the dead drop? Deliver after collecting ${value}.");
			_dealer.SendMessage("Sure thing boss!", notify: false, network: true, 2f);
		}
	}
	public class EnableProductPickupMessage : MessageBase
	{
		private readonly DealerExtension _dealer;

		public override string Text => "Pickup products";

		public override bool DisableDefaultSendBehaviour => true;

		public EnableProductPickupMessage(DealerExtension dealerExtension)
		{
			_dealer = dealerExtension;
			base..ctor();
		}

		public override bool ShouldShowCheck(SendableMessage sMsg)
		{
			if (_dealer.Dealer.IsRecruited && !_dealer.PickupProducts)
			{
				return true;
			}
			return false;
		}

		public override void OnSelected()
		{
			UIBuilder.SliderPopup.Open("Product Threshold (" + ((Object)_dealer.Dealer).name + ")", null, _dealer.ProductThreshold, 0f, 1000f, 10f, 0, OnSend, null, "{0:0} pcs");
		}

		private void OnSend(float value)
		{
			_dealer.PickupProducts = true;
			_dealer.ProductThreshold = (int)value;
			_dealer.SendPlayerMessage($"I will deposit products at the dead drop. Come there if you got less than {value}pcs left.");
			_dealer.SendMessage("Ok. Will pick them up soon!", notify: false, network: true, 2f);
		}
	}
	public class FiredMessage : MessageBase
	{
		private readonly DealerExtension _dealer;

		public override string Text => "You are fired";

		public override bool DisableDefaultSendBehaviour => true;

		public FiredMessage(DealerExtension dealerExtension)
		{
			_dealer = dealerExtension;
			base..ctor();
		}

		public override bool ShouldShowCheck(SendableMessage sMsg)
		{
			if (_dealer.Dealer.IsRecruited)
			{
				return true;
			}
			return false;
		}

		public override void OnSelected()
		{
			PlayerSingleton<MessagesApp>.Instance.ConfirmationPopup.Open("Are you sure?", "Calling off the cooperation could make a dealer really mad.\n\nHe maybe will become hostile.\n(In future updates)", base.S1Conversation, Action<EResponse>.op_Implicit((Action<EResponse>)OnConfirmationResponse));
		}

		private void OnConfirmationResponse(EResponse response)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			if ((int)response == 0)
			{
				_dealer.Fire();
				_dealer.SendPlayerMessage("I don't need your service anymore. You are out!");
				_dealer.SendMessage("Hmpf okay, get in touch if you need me", notify: false, network: true, 0.5f);
			}
		}
	}
	public abstract class MessageBase
	{
		protected NPC NPC;

		protected Conversation Conversation;

		public virtual string Text => "Text";

		protected MSGConversation S1Conversation => NPC.MSGConversation;

		public virtual bool DisableDefaultSendBehaviour => false;

		public virtual void SetReferences(NPC npc, Conversation conversation)
		{
			NPC = npc;
			Conversation = conversation;
		}

		public virtual bool ShouldShowCheck(SendableMessage sMsg)
		{
			return true;
		}

		public virtual void OnSelected()
		{
		}

		public virtual void OnSent()
		{
		}
	}
	public class NegotiateCutMessage : MessageBase
	{
		private readonly DealerExtension _dealer;

		public override string Text => "Let's talk about your cut";

		public override bool DisableDefaultSendBehaviour => true;

		public NegotiateCutMessage(DealerExtension dealerExtension)
		{
			_dealer = dealerExtension;
			base..ctor();
		}

		public override bool ShouldShowCheck(SendableMessage sMsg)
		{
			if (_dealer.Dealer.IsRecruited && _dealer.DaysUntilNextNegotiation <= 0)
			{
				return true;
			}
			return false;
		}

		public override void OnSelected()
		{
			float num = (float)Math.Round(_dealer.Cut, 2);
			UIBuilder.SliderPopup.Open("Negotiate Cut % (" + ((Object)_dealer.Dealer).name + ")", $"Current: {num:P0}", num, 0f, 1f, 0.01f, 2, OnSend, null, "{0:P0}");
		}

		private void OnSend(float value)
		{
			_dealer.SendPlayerMessage($"Joo! We need to talk about your cut.. How about {value:P0}?");
			if (value == _dealer.Cut)
			{
				_dealer.SendMessage("Bro that's the same amount i get atm!", notify: false, network: true, 2f);
				return;
			}
			if (value > _dealer.Cut)
			{
				_dealer.SendMessage("Haha.. you idiot! Yeah 

Mods/AdvancedDealing.Mono.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using AdvancedDealing;
using AdvancedDealing.Economy;
using AdvancedDealing.Messaging;
using AdvancedDealing.Messaging.Messages;
using AdvancedDealing.NPCs.Behaviour;
using AdvancedDealing.Persistence;
using AdvancedDealing.Persistence.Datas;
using AdvancedDealing.Persistence.IO;
using AdvancedDealing.UI;
using AdvancedDealing.Utils;
using FishNet;
using GameKit.Utilities;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using ScheduleOne;
using ScheduleOne.DevUtilities;
using ScheduleOne.Dialogue;
using ScheduleOne.Economy;
using ScheduleOne.GameTime;
using ScheduleOne.ItemFramework;
using ScheduleOne.Map;
using ScheduleOne.Messaging;
using ScheduleOne.Money;
using ScheduleOne.NPCs;
using ScheduleOne.NPCs.Behaviour;
using ScheduleOne.Networking;
using ScheduleOne.Persistence;
using ScheduleOne.PlayerScripts;
using ScheduleOne.Product;
using ScheduleOne.Storage;
using ScheduleOne.UI;
using ScheduleOne.UI.Phone;
using ScheduleOne.UI.Phone.Messages;
using Steamworks;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(global::AdvancedDealing.AdvancedDealing), "AdvancedDealing", "1.3.0", "ManZune", "https://github.com/manzune/AdvancedDealing")]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: MelonColor(255, 113, 195, 230)]
[assembly: MelonPlatformDomain(/*Could not decode attribute arguments.*/)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ManZune")]
[assembly: AssemblyConfiguration("Mono")]
[assembly: AssemblyDescription("A Schedule I Dealer Enhancement MelonLoader Mod")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyInformationalVersion("1.3.0+5259f34a0663f528d9c5e6903b35fd2ecb71250b")]
[assembly: AssemblyProduct("AdvancedDealing")]
[assembly: AssemblyTitle("AdvancedDealing")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/manzune/AdvancedDealing")]
[assembly: AssemblyVersion("1.3.0.0")]
[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 AdvancedDealing
{
	public class AdvancedDealing : MelonMod
	{
		public bool IsInitialized { get; private set; }

		public SaveModifier SaveModifier { get; private set; }

		public NetworkSynchronizer NetworkSynchronizer { get; private set; }

		public override void OnSceneWasInitialized(int buildIndex, string sceneName)
		{
			if (sceneName == "Menu")
			{
				if (!IsInitialized)
				{
					ModConfig.Initialize();
					ConflictChecker.CheckForConflicts();
					SaveModifier = new SaveModifier();
					NetworkSynchronizer = new NetworkSynchronizer();
					Logger.Msg("AdvancedDealing v1.3.0 initialized");
					IsInitialized = true;
				}
				if (SaveModifier.SavegameLoaded)
				{
					SaveModifier.ClearModifications();
				}
			}
			else if (sceneName == "Main")
			{
				SaveModifier.LoadModifications();
			}
		}
	}
	public static class ModConfig
	{
		private static MelonPreferences_Category generalCategory;

		private static bool isInitialized;

		public static bool Debug
		{
			get
			{
				return generalCategory.GetEntry<bool>("Debug").Value;
			}
			set
			{
				generalCategory.GetEntry<bool>("Debug").Value = value;
			}
		}

		public static bool SkipMovement
		{
			get
			{
				return generalCategory.GetEntry<bool>("SkipMovement").Value;
			}
			set
			{
				generalCategory.GetEntry<bool>("SkipMovement").Value = value;
			}
		}

		public static bool NotifyOnAction
		{
			get
			{
				return generalCategory.GetEntry<bool>("NotifyOnAction").Value;
			}
			set
			{
				generalCategory.GetEntry<bool>("NotifyOnAction").Value = value;
			}
		}

		public static bool CustomersSearchAndSort
		{
			get
			{
				return generalCategory.GetEntry<bool>("CustomersSearchAndSort").Value;
			}
			set
			{
				generalCategory.GetEntry<bool>("CustomersSearchAndSort").Value = value;
			}
		}

		public static bool AccessInventory
		{
			get
			{
				if (NetworkSynchronizer.IsSyncing && NetworkSynchronizer.Instance.SessionData != null)
				{
					return NetworkSynchronizer.Instance.SessionData.AccessInventory;
				}
				return generalCategory.GetEntry<bool>("AccessInventory").Value;
			}
			set
			{
				generalCategory.GetEntry<bool>("AccessInventory").Value = value;
			}
		}

		public static bool SettingsMenu
		{
			get
			{
				if (NetworkSynchronizer.IsSyncing && NetworkSynchronizer.Instance.SessionData != null)
				{
					return NetworkSynchronizer.Instance.SessionData.SettingsMenu;
				}
				return generalCategory.GetEntry<bool>("SettingsMenu").Value;
			}
			set
			{
				generalCategory.GetEntry<bool>("SettingsMenu").Value = value;
			}
		}

		public static float NegotiationModifier
		{
			get
			{
				if (NetworkSynchronizer.IsSyncing && NetworkSynchronizer.Instance.SessionData != null)
				{
					return NetworkSynchronizer.Instance.SessionData.NegotiationModifier;
				}
				return generalCategory.GetEntry<float>("NegotiationModifier").Value;
			}
			set
			{
				generalCategory.GetEntry<float>("NegotiationModifier").Value = value;
			}
		}

		public static void Initialize()
		{
			if (isInitialized)
			{
				return;
			}
			generalCategory = MelonPreferences.CreateCategory("AdvancedDealing_01_General", "AdvancedDealing - General Settings", false, true);
			string text = Path.Combine(MelonEnvironment.UserDataDirectory, "AdvancedDealing.cfg");
			generalCategory.SetFilePath(text, true, false);
			CreateEntries();
			if (!File.Exists(text))
			{
				foreach (MelonPreferences_Entry entry in generalCategory.Entries)
				{
					entry.ResetToDefault();
				}
				generalCategory.SaveToFile(false);
			}
			isInitialized = true;
		}

		private static void CreateEntries()
		{
			generalCategory.CreateEntry<bool>("Debug", false, "Enable Debug Mode", "Enables debugging for this mod", false, false, (ValueValidator)null, (string)null);
			generalCategory.CreateEntry<bool>("SkipMovement", false, "Skip Movement (Instant Delivery)", "Skips all movement actions for dealers", false, false, (ValueValidator)null, (string)null);
			generalCategory.CreateEntry<bool>("NotifyOnAction", true, "Notify On Actions", "Sends notifications after some actions got triggered", false, false, (ValueValidator)null, (string)null);
			generalCategory.CreateEntry<bool>("CustomersSearchAndSort", true, "Search And Sort Customers (Needs Reload)", "Enable customers searching and sorting by region and alphabetical", false, false, (ValueValidator)null, (string)null);
			generalCategory.CreateEntry<bool>("AccessInventory", false, "Access Dealer Inventories Remotely", "Enables the option to access the dealer inventory via text message", false, false, (ValueValidator)null, (string)null);
			generalCategory.CreateEntry<bool>("SettingsMenu", false, "Enable Dealer Settings Menu", "Allows access to the dealer settings menu via text message", false, false, (ValueValidator)null, (string)null);
			generalCategory.CreateEntry<float>("NegotiationModifier", 0.5f, "Negotiation Modifier (Higher = Better Chance)", "Modifier used to calculate the negotiation success.", false, false, (ValueValidator)(object)new ValueRange<float>(0f, 1f), (string)null);
		}
	}
	public static class ModInfo
	{
		public const string NAME = "AdvancedDealing";

		public const string VERSION = "1.3.0";

		public const string AUTHOR = "ManZune";

		public const string DOWNLOAD_LINK = "https://github.com/manzune/AdvancedDealing";
	}
}
namespace AdvancedDealing.Utils
{
	public static class ConflictChecker
	{
		public static bool DisableMoreItemSlots { get; private set; }

		public static void CheckForConflicts()
		{
			bool flag = false;
			if (MelonBase.FindMelon("Bread's Storage Tweak Mod", "BreadCh4n") != null)
			{
				flag = true;
				DisableMoreItemSlots = true;
				Logger.Msg("ConflictChecker", "Bread's Storage Tweaks found: More item slots feature disabled.");
			}
			if (!flag)
			{
				Logger.Msg("ConflictChecker", "No known conflicting mods found.");
			}
		}
	}
	public static class Logger
	{
		public static void Msg(string msg)
		{
			Msg(null, msg);
		}

		public static void Msg(string prefix, string msg)
		{
			if (prefix != null)
			{
				msg = "[" + prefix + "] " + msg;
			}
			MelonLogger.Msg(msg);
		}

		public static void Error(string msg)
		{
			Error(null, msg, null);
		}

		public static void Error(string prefix, string msg)
		{
			Error(prefix, msg, null);
		}

		public static void Error(string msg, Exception ex)
		{
			Error(null, msg, ex);
		}

		public static void Error(string prefix, string msg, Exception ex)
		{
			if (prefix != null)
			{
				msg = "[" + prefix + "] " + msg;
			}
			if (ex != null)
			{
				MelonLogger.Error(msg, ex);
			}
			else
			{
				MelonLogger.Error(msg);
			}
		}

		public static void Debug(string msg)
		{
			Debug(null, msg);
		}

		public static void Debug(string prefix, string msg)
		{
			if (ModConfig.Debug)
			{
				if (prefix != null)
				{
					msg = "[" + prefix + "] " + msg;
				}
				MelonLogger.Msg(ConsoleColor.Cyan, msg);
			}
		}
	}
}
namespace AdvancedDealing.UI
{
	public class CustomerSelector
	{
		public RectTransform Content;

		public InputField Searchbar;

		private Dictionary<EMapRegion, (GameObject gameObject, List<RectTransform> entries)> _categories = new Dictionary<EMapRegion, (GameObject, List<RectTransform>)>();

		public bool UICreated { get; private set; }

		public void BuildUI()
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			if (UICreated)
			{
				return;
			}
			Transform transform = ((Component)PlayerSingleton<DealerManagementApp>.Instance.CustomerSelector).transform;
			Content = PlayerSingleton<DealerManagementApp>.Instance.CustomerSelector.EntriesContainer;
			Transform obj = transform.Find("Shade/Content/Scroll View");
			RectTransform val = ((obj != null) ? ((Component)obj).GetComponent<RectTransform>() : null);
			val.sizeDelta = new Vector2(val.sizeDelta.x, val.sizeDelta.y - 100f);
			GameObject val2 = Object.Instantiate<GameObject>(((Component)((Component)PlayerSingleton<MessagesApp>.Instance.CounterofferInterface).transform.Find("Shade/Content/Selection/SearchInput")).gameObject, ((Transform)val).parent);
			val2.SetActive(true);
			((Object)val2).name = "Searchbar";
			Searchbar = val2.GetComponent<InputField>();
			((UnityEventBase)Searchbar.onEndEdit).RemoveAllListeners();
			((UnityEventBase)Searchbar.onValueChanged).RemoveAllListeners();
			((UnityEvent<string>)(object)Searchbar.onValueChanged).AddListener((UnityAction<string>)OnSearchValueChanged);
			Searchbar.contentType = (ContentType)0;
			RectTransform component = ((Component)Searchbar).GetComponent<RectTransform>();
			component.offsetMax = new Vector2(-25f, -80f);
			component.offsetMin = new Vector2(25f, -130f);
			Text component2 = ((Component)((Transform)component).Find("Text Area/Placeholder")).GetComponent<Text>();
			component2.text = "Search customers...";
			GameObject gameObject = ((Component)((Transform)Content).GetChild(0).Find("Name")).gameObject;
			foreach (EMapRegion value in Enum.GetValues(typeof(EMapRegion)))
			{
				GameObject val4 = Object.Instantiate<GameObject>(gameObject, (Transform)(object)Content);
				((Object)val4).name = "Region";
				RectTransform component3 = val4.GetComponent<RectTransform>();
				component3.offsetMax = new Vector2(0f, 0f);
				component3.offsetMin = new Vector2(0f, 0f);
				component3.sizeDelta = new Vector2(495f, 60f);
				Text component4 = val4.GetComponent<Text>();
				component4.text = Enum.GetName(typeof(EMapRegion), (object)value);
				component4.fontStyle = (FontStyle)1;
				component4.alignment = (TextAnchor)4;
				_categories.Add(value, (val4, new List<RectTransform>()));
			}
			UICreated = true;
		}

		public void SortCustomers()
		{
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			List<RectTransform> list = (List<RectTransform>)typeof(CustomerSelector).GetField("customerEntries", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(PlayerSingleton<DealerManagementApp>.Instance.CustomerSelector);
			Dictionary<RectTransform, Customer> dictionary = (Dictionary<RectTransform, Customer>)typeof(CustomerSelector).GetField("entryToCustomer", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(PlayerSingleton<DealerManagementApp>.Instance.CustomerSelector);
			for (int i = 0; i < list.Count; i++)
			{
				RectTransform val = list[i];
				Customer val2 = dictionary[val];
				if ((Object)(object)val2.AssignedDealer != (Object)null)
				{
					_categories[val2.NPC.Region].entries.Remove(val);
				}
				else
				{
					_categories[val2.NPC.Region].entries.Add(val);
				}
			}
			foreach (KeyValuePair<EMapRegion, (GameObject, List<RectTransform>)> category in _categories)
			{
				category.Value.Item1.transform.SetAsLastSibling();
				List<RectTransform> collection = category.Value.Item2.OrderBy((RectTransform e) => ((Component)((Transform)e).Find("Name")).GetComponent<Text>().text).ToList();
				category.Value.Item2.Clear();
				category.Value.Item2.AddRange(collection);
				int num = 0;
				for (int j = 0; j < category.Value.Item2.Count; j++)
				{
					RectTransform val3 = category.Value.Item2[j];
					((Transform)val3).SetAsLastSibling();
					if (((Component)val3).gameObject.activeSelf)
					{
						num++;
					}
				}
				if (num == 0)
				{
					category.Value.Item1.SetActive(false);
				}
				else
				{
					category.Value.Item1.SetActive(true);
				}
			}
		}

		private void OnSearchValueChanged(string value)
		{
			foreach (KeyValuePair<EMapRegion, (GameObject, List<RectTransform>)> category in _categories)
			{
				int num = 0;
				for (int i = 0; i < category.Value.Item2.Count; i++)
				{
					RectTransform val = category.Value.Item2[i];
					Text component = ((Component)((Transform)val).Find("Name")).GetComponent<Text>();
					if (component.text.Contains(value, StringComparison.OrdinalIgnoreCase) || value == null || value == string.Empty)
					{
						((Component)val).gameObject.SetActive(true);
						num++;
					}
					else
					{
						((Component)val).gameObject.SetActive(false);
					}
				}
				if (num == 0)
				{
					category.Value.Item1.SetActive(false);
				}
				else
				{
					category.Value.Item1.SetActive(true);
				}
			}
		}
	}
	public class CustomersScrollView
	{
		public const int MAX_ENTRIES = 24;

		public GameObject Container;

		public GameObject Viewport;

		public GameObject AssignButton;

		public RectTransform CustomerTitle;

		public List<GameObject> CustomerEntries = new List<GameObject>();

		public Text TitleLabel;

		public bool UICreated { get; private set; }

		public void BuildUI()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Expected O, but got Unknown
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Expected O, but got Unknown
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			Container = ((Component)((Component)PlayerSingleton<DealerManagementApp>.Instance).transform.Find("Container/Background/Content")).gameObject;
			float num = 620f;
			GameObject val = new GameObject("Scroll");
			RectTransform val2 = val.AddComponent<RectTransform>();
			((Transform)val2).SetParent(Container.transform, false);
			val2.anchorMin = new Vector2(0f, 0f);
			val2.anchorMax = new Vector2(1f, 0f);
			val2.pivot = new Vector2(0.5f, 0f);
			val2.anchoredPosition = Vector2.zero;
			val2.sizeDelta = new Vector2(0f, num);
			Viewport = new GameObject("Viewport");
			RectTransform val3 = Viewport.AddComponent<RectTransform>();
			((Transform)val3).SetParent((Transform)(object)val2, false);
			val3.anchorMin = new Vector2(0f, 0f);
			val3.anchorMax = new Vector2(1f, 0f);
			val3.pivot = new Vector2(0.5f, 0f);
			val3.anchoredPosition = Vector2.zero;
			val3.sizeDelta = new Vector2(0f, num);
			Viewport.AddComponent<Mask>().showMaskGraphic = false;
			Viewport.AddComponent<Image>();
			GameObject gameObject = ((Component)((Transform)PlayerSingleton<DealerManagementApp>.Instance.CustomerEntries.Last()).parent).gameObject;
			RectTransform component = gameObject.GetComponent<RectTransform>();
			((Transform)component).SetParent((Transform)(object)val3, true);
			component.pivot = new Vector2(0.5f, 1f);
			ContentSizeFitter val4 = gameObject.AddComponent<ContentSizeFitter>();
			val4.horizontalFit = (FitMode)0;
			val4.verticalFit = (FitMode)2;
			((LayoutGroup)gameObject.GetComponent<VerticalLayoutGroup>()).padding = new RectOffset(0, 0, 20, 20);
			ScrollRect val5 = val.AddComponent<ScrollRect>();
			val5.viewport = val3;
			val5.content = component;
			val5.horizontal = false;
			val5.vertical = true;
			val5.movementType = (MovementType)1;
			val5.inertia = true;
			val5.elasticity = 0.1f;
			val5.verticalNormalizedPosition = 1f;
			val5.scrollSensitivity = 8f;
			CustomerTitle = ((Component)Container.transform.Find("CustomerTitle")).GetComponent<RectTransform>();
			CustomerTitle.sizeDelta = new Vector2(CustomerTitle.sizeDelta.x, CustomerTitle.sizeDelta.y - 15f);
			CustomerTitle.offsetMax = new Vector2(CustomerTitle.offsetMax.x, CustomerTitle.offsetMax.y - 15f);
			TitleLabel = ((Component)CustomerTitle).GetComponent<Text>();
			AssignButton = ((Component)PlayerSingleton<DealerManagementApp>.Instance.AssignCustomerButton).gameObject;
			CreateCustomerEntries();
			Logger.Debug("CustomersScrollView", "Customers scroll view UI created");
			UICreated = true;
		}

		private void CreateCustomerEntries()
		{
			RectTransform[] customerEntries = PlayerSingleton<DealerManagementApp>.Instance.CustomerEntries;
			RectTransform[] array = (RectTransform[])(object)new RectTransform[24];
			int num = customerEntries.Length;
			if (num == 24)
			{
				return;
			}
			for (int i = 0; i < 24; i++)
			{
				if (i < num)
				{
					array[i] = customerEntries[i];
					CustomerEntries.Add(((Component)customerEntries[i]).gameObject);
					continue;
				}
				RectTransform val = customerEntries.Last();
				RectTransform val2 = Object.Instantiate<RectTransform>(val, ((Transform)val).parent);
				((Object)val2).name = $"CustomerEntry ({i})";
				((Component)val2).gameObject.SetActive(false);
				array[i] = val2;
				CustomerEntries.Add(((Component)val2).gameObject);
			}
			PlayerSingleton<DealerManagementApp>.Instance.CustomerEntries = array;
			((Component)PlayerSingleton<DealerManagementApp>.Instance.AssignCustomerButton).transform.SetAsLastSibling();
		}
	}
	public class DeadDropSelector
	{
		public GameObject Container;

		public Text TitleLabel;

		public Transform Content;

		public GameObject Button;

		public Text ButtonLabel;

		private readonly List<GameObject> _selectables = new List<GameObject>();

		private DealerExtension _dealer;

		private GameObject _selectableTemplate;

		public bool UICreated { get; private set; }

		public bool IsOpen { get; private set; }

		public void Open(DealerExtension dealerExtension)
		{
			IsOpen = true;
			_dealer = dealerExtension;
			foreach (DeadDrop deadDrop in DeadDropExtension.GetDeadDropsByDistance(((Component)Player.Local).transform))
			{
				GameObject val = _selectables.Find((GameObject x) => ((Component)x.transform.Find("Name")).GetComponent<Text>().text == deadDrop.DeadDropName);
				val.transform.SetAsLastSibling();
			}
			Container.SetActive(true);
		}

		public void Close()
		{
			IsOpen = false;
			Container.SetActive(false);
		}

		private void OnSelected(string guid, string name)
		{
			_dealer.DeadDrop = guid;
			ButtonLabel.text = name;
			Logger.Debug("DeadDropSelector", "Dead drop for " + ((NPC)_dealer.Dealer).fullName + " selected: " + guid);
			if (NetworkSynchronizer.IsSyncing)
			{
				NetworkSynchronizer.Instance.SendData(_dealer.FetchData());
			}
			Close();
		}

		public void BuildUI()
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			if (!UICreated)
			{
				GameObject gameObject = ((Component)PlayerSingleton<DealerManagementApp>.Instance.CustomerSelector).gameObject;
				Container = Object.Instantiate<GameObject>(gameObject, gameObject.transform.parent);
				((Object)Container).name = "DeadDropSelector";
				Container.SetActive(true);
				CreateSelectableTemplate();
				RectTransform component = ((Component)Container.transform.Find("Shade/Content/Scroll View/Viewport/Content")).gameObject.GetComponent<RectTransform>();
				GameObject val = new GameObject("Content");
				RectTransform val2 = val.AddComponent<RectTransform>();
				((Transform)val2).SetParent(((Transform)component).parent, false);
				val2.anchorMin = component.anchorMin;
				val2.anchorMax = component.anchorMax;
				val2.pivot = component.pivot;
				val2.anchoredPosition = component.anchoredPosition;
				val2.sizeDelta = component.sizeDelta;
				TitleLabel = ((Component)Container.transform.Find("Shade/Content/Title")).GetComponent<Text>();
				TitleLabel.text = "Select Dead Drop";
				Content = (Transform)(object)val2;
				Object.Destroy((Object)(object)((Component)component).gameObject);
				((Component)Container.transform.Find("Shade/Content/Scroll View")).gameObject.GetComponent<ScrollRect>().content = val2;
				ContentSizeFitter val3 = val.AddComponent<ContentSizeFitter>();
				val3.horizontalFit = (FitMode)0;
				val3.verticalFit = (FitMode)2;
				VerticalLayoutGroup val4 = val.AddComponent<VerticalLayoutGroup>();
				((HorizontalOrVerticalLayoutGroup)val4).childControlHeight = false;
				((HorizontalOrVerticalLayoutGroup)val4).childControlWidth = true;
				((HorizontalOrVerticalLayoutGroup)val4).childForceExpandHeight = false;
				((HorizontalOrVerticalLayoutGroup)val4).childForceExpandWidth = true;
				((HorizontalOrVerticalLayoutGroup)val4).childScaleHeight = false;
				((HorizontalOrVerticalLayoutGroup)val4).childScaleWidth = false;
				CreateSelectable(null, "None");
				for (int i = 0; i <= DeadDrop.DeadDrops.Count - 1; i++)
				{
					CreateSelectable(DeadDrop.DeadDrops[i].GUID.ToString(), DeadDrop.DeadDrops[i].DeadDropName);
				}
				CreateButton();
				Logger.Debug("DeadDropSelector", "Dead drop selector UI created");
				UICreated = true;
			}
		}

		private void CreateButton()
		{
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Expected O, but got Unknown
			GameObject gameObject = ((Component)((Component)PlayerSingleton<DealerManagementApp>.Instance).transform.Find("Container/Background/Content/Home")).gameObject;
			Button = Object.Instantiate<GameObject>(gameObject, gameObject.transform.parent);
			Button.SetActive(true);
			((Object)Button).name = "DeadDropSelectorButton";
			((Component)Button.transform.Find("Title")).GetComponent<Text>().text = "Dead Drop";
			RectTransform component = ((Component)Button.transform.Find("Value")).GetComponent<RectTransform>();
			component.offsetMax = new Vector2(component.offsetMax.x, 60f);
			component.offsetMin = new Vector2(component.offsetMin.x, 15f);
			component.sizeDelta = new Vector2(component.sizeDelta.x, 40f);
			ButtonLabel = ((Component)component).GetComponent<Text>();
			ButtonLabel.text = "None";
			((Graphic)ButtonLabel).color = new Color(0.6f, 1f, 1f, 1f);
			((UnityEvent)Button.AddComponent<Button>().onClick).AddListener(new UnityAction(OpenSelector));
			void OpenSelector()
			{
				Open(DealerExtension.GetDealer(PlayerSingleton<DealerManagementApp>.Instance.SelectedDealer));
			}
		}

		private void CreateSelectableTemplate()
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(((Component)Container.transform.Find("Shade/Content/Scroll View/Viewport/Content").GetChild(0)).gameObject);
			val.SetActive(false);
			((Object)val).name = "SelectableTemplate";
			Object.Destroy((Object)(object)((Component)val.transform.Find("Mugshot")).gameObject);
			((Component)val.transform.Find("Name")).GetComponent<RectTransform>().sizeDelta = new Vector2(0f, 0f);
			_selectableTemplate = val;
		}

		private void CreateSelectable(string deadDropGuid, string name)
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			GameObject val = Object.Instantiate<GameObject>(_selectableTemplate, Content);
			val.SetActive(true);
			((Object)val).name = "Selectable";
			((Component)val.transform.Find("Name")).GetComponent<Text>().text = name;
			((UnityEvent)val.GetComponent<Button>().onClick).AddListener(new UnityAction(Selected));
			_selectables.Add(val);
			void Selected()
			{
				OnSelected(deadDropGuid, name);
			}
		}
	}
	public class SettingsPopup
	{
		public GameObject Container;

		public Text TitleLabel;

		public Button ApplyButton;

		public Transform Content;

		private readonly List<GameObject> _inputFields = new List<GameObject>();

		private DealerExtension _dealer;

		private GameObject _inputFieldTemplate;

		public bool UICreated { get; private set; }

		public bool IsOpen { get; private set; }

		public SettingsPopup()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			GameInput.RegisterExitListener(new ExitDelegate(RightClick), 4);
		}

		private void RightClick(ExitAction action)
		{
			if (!action.Used && IsOpen)
			{
				action.Used = true;
				Close();
			}
		}

		public void Open(DealerExtension dealerExtension)
		{
			IsOpen = true;
			_dealer = dealerExtension;
			Container.SetActive(true);
			TitleLabel.text = "Adjust Settings (" + ((Object)_dealer.Dealer).name + ")";
			foreach (GameObject inputField in _inputFields)
			{
				inputField.GetComponent<InputField>().text = GetDataValue(((Object)inputField).name);
				inputField.SetActive(true);
			}
		}

		public void Close()
		{
			IsOpen = false;
			Container.SetActive(false);
		}

		private void OnApply()
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Invalid comparison between Unknown and I4
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Invalid comparison between Unknown and I4
			if (!IsOpen)
			{
				return;
			}
			bool flag = false;
			foreach (GameObject inputField in _inputFields)
			{
				InputField component = inputField.GetComponent<InputField>();
				string dataValue = GetDataValue(((Object)inputField).name);
				string text = component.text;
				if (text != dataValue)
				{
					if ((int)component.contentType == 2)
					{
						typeof(DealerExtension).GetField(((Object)inputField).name).SetValue(_dealer, int.Parse(text));
					}
					else if ((int)component.contentType == 3)
					{
						typeof(DealerExtension).GetField(((Object)inputField).name).SetValue(_dealer, float.Parse(text));
					}
					flag = true;
				}
			}
			if (flag)
			{
				if (NetworkSynchronizer.IsSyncing)
				{
					NetworkSynchronizer.Instance.SendData(_dealer.FetchData());
				}
				_dealer.HasChanged = true;
				_dealer.SendPlayerMessage("Damn.. please change your behavior!");
				_dealer.SendMessage("Hmkay .. i'm sorry", notify: false, network: true, 2f);
			}
			Close();
		}

		private void OnCancel()
		{
			Close();
		}

		public void BuildUI()
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Expected O, but got Unknown
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Expected O, but got Unknown
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			if (!UICreated)
			{
				GameObject gameObject = ((Component)PlayerSingleton<MessagesApp>.Instance.ConfirmationPopup).gameObject;
				Container = Object.Instantiate<GameObject>(gameObject, gameObject.transform.parent);
				((Object)Container).name = "SettingsPopup";
				Container.SetActive(true);
				CreateInputFieldTemplate();
				Content = Container.transform.Find("Shade/Content");
				((Component)Content).GetComponent<RectTransform>().sizeDelta = new Vector2(-160f, 100f);
				Object.Destroy((Object)(object)((Component)Content.Find("Subtitle")).gameObject);
				TitleLabel = ((Component)Content.Find("Title")).GetComponent<Text>();
				TitleLabel.text = "Adjust Settings";
				Button[] componentsInChildren = ((Component)Content).GetComponentsInChildren<Button>();
				((UnityEventBase)componentsInChildren[0].onClick).RemoveAllListeners();
				((UnityEvent)componentsInChildren[0].onClick).AddListener(new UnityAction(OnCancel));
				ApplyButton = componentsInChildren[2];
				((Object)((Component)ApplyButton).gameObject).name = "Apply";
				((Component)ApplyButton).GetComponentInChildren<Text>().text = "Apply";
				Button applyButton = ApplyButton;
				ColorBlock colors = default(ColorBlock);
				((ColorBlock)(ref colors)).normalColor = new Color(0.2941f, 0.6863f, 0.8824f, 1f);
				((ColorBlock)(ref colors)).highlightedColor = new Color(0.4532f, 0.7611f, 0.9151f, 1f);
				((ColorBlock)(ref colors)).pressedColor = new Color(0.5674f, 0.8306f, 0.9623f, 1f);
				((ColorBlock)(ref colors)).selectedColor = new Color(0.9608f, 0.9608f, 0.9608f, 1f);
				((ColorBlock)(ref colors)).disabledColor = new Color(0.2941f, 0.6863f, 0.8824f, 1f);
				((ColorBlock)(ref colors)).colorMultiplier = 1f;
				((ColorBlock)(ref colors)).fadeDuration = 0f;
				((Selectable)applyButton).colors = colors;
				((UnityEventBase)ApplyButton.onClick).RemoveAllListeners();
				((UnityEvent)ApplyButton.onClick).AddListener(new UnityAction(OnApply));
				((Graphic)((Component)ApplyButton).GetComponent<Image>()).color = Color.white;
				Object.Destroy((Object)(object)((Component)componentsInChildren[1]).gameObject);
				CreateInputField((ContentType)2, "MaxCustomers", "Max Customers", 0f, 24f);
				CreateInputField((ContentType)3, "Cut", "Cut %", 0f, 1f);
				CreateInputField((ContentType)3, "SpeedMultiplier", "Speed Multiplier");
				if (!ConflictChecker.DisableMoreItemSlots)
				{
					CreateInputField((ContentType)2, "ItemSlots", "Item Slots", 0f, 20f);
				}
				Logger.Debug("SettingsPopup", "Settings popup UI created");
				UICreated = true;
			}
		}

		private void CreateInputFieldTemplate()
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(((Component)((Component)PlayerSingleton<MessagesApp>.Instance.CounterofferInterface).transform.Find("Shade/Content/Selection/SearchInput")).gameObject);
			val.SetActive(false);
			((Object)val).name = "InputFieldUITemplate";
			((UnityEventBase)val.GetComponent<InputField>().onEndEdit).RemoveAllListeners();
			RectTransform component = val.GetComponent<RectTransform>();
			component.offsetMax = new Vector2(-20f, -100f);
			component.offsetMin = new Vector2(20f, -160f);
			RectTransform component2 = ((Component)((Transform)component).Find("Image")).GetComponent<RectTransform>();
			component2.offsetMin = new Vector2(350f, component2.offsetMin.y);
			RectTransform component3 = ((Component)((Transform)component).Find("Text Area")).GetComponent<RectTransform>();
			component3.offsetMin = new Vector2(350f, component3.offsetMin.y);
			Text component4 = ((Component)((Transform)component3).Find("Placeholder")).GetComponent<Text>();
			component4.text = "Set value...";
			RectTransform val2 = new GameObject("Title").AddComponent<RectTransform>();
			((Transform)val2).SetParent((Transform)(object)component);
			((Transform)val2).SetAsFirstSibling();
			val2.sizeDelta = new Vector2(-358f, -13f);
			val2.offsetMax = new Vector2(-150f, -10f);
			val2.offsetMin = new Vector2(10f, 8f);
			val2.anchorMax = new Vector2(1f, 1f);
			val2.anchorMin = new Vector2(0f, 0f);
			Text val3 = ((Component)val2).gameObject.AddComponent<Text>();
			val3.font = component4.font;
			val3.alignment = (TextAnchor)3;
			val3.text = "Title";
			((Graphic)val3).color = Color.black;
			val3.fontSize = 20;
			_inputFieldTemplate = val;
		}

		private void CreateInputField(ContentType type, string key, string description, float rangeMin = 0f, float rangeMax = 0f)
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(_inputFieldTemplate, Content);
			val.SetActive(true);
			((Object)val).name = key;
			float num = 0f;
			if (_inputFields.Count > 0)
			{
				num = 80f * (float)_inputFields.Count;
			}
			RectTransform component = val.GetComponent<RectTransform>();
			component.offsetMax = new Vector2(component.offsetMax.x, component.offsetMax.y - num);
			component.offsetMin = new Vector2(component.offsetMin.x, component.offsetMin.y - num);
			((Component)((Transform)component).Find("Title")).GetComponent<Text>().text = description;
			InputField input = val.GetComponent<InputField>();
			input.contentType = type;
			if (rangeMin != 0f || rangeMax != 0f)
			{
				((UnityEvent<string>)(object)input.onEndEdit).AddListener((UnityAction<string>)ValidateRange);
			}
			_inputFields.Add(val);
			void ValidateRange(string text)
			{
				if (text.Length > 0)
				{
					float num2 = float.Parse(text);
					if (!(rangeMin <= num2) || !(num2 <= rangeMax))
					{
						input.text = GetDataValue(key);
					}
				}
			}
		}

		private string GetDataValue(string key)
		{
			if (_dealer == null)
			{
				return null;
			}
			return typeof(DealerExtension).GetField(key).GetValue(_dealer).ToString();
		}
	}
	public class SliderPopup
	{
		public GameObject Container;

		public Text TitleLabel;

		public Text SubtitleLabel;

		public Text ValueLabel;

		public Button SendButton;

		public Transform Content;

		public Slider Slider;

		public Action<float> OnSend;

		public Action OnCancel;

		private int _digits;

		private float _stepSize;

		private string _format;

		public bool UICreated { get; private set; }

		public bool IsOpen { get; private set; }

		public SliderPopup()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			GameInput.RegisterExitListener(new ExitDelegate(RightClick), 4);
		}

		private void RightClick(ExitAction action)
		{
			if (!action.Used && IsOpen)
			{
				action.Used = true;
				Close();
			}
		}

		public void Open(string title, string subtitle, float startValue, float minValue, float maxValue, float stepSize = 0.05f, int digits = 2, Action<float> onSendCallback = null, Action onCancelCallback = null, string format = "")
		{
			IsOpen = true;
			Container.SetActive(true);
			OnSend = onSendCallback;
			OnCancel = onCancelCallback;
			_digits = digits;
			_stepSize = stepSize;
			_format = format;
			TitleLabel.text = title;
			SubtitleLabel.text = subtitle;
			ValueLabel.text = string.Format(_format, GetSteppedValue(startValue));
			Slider.value = startValue;
			Slider.minValue = minValue;
			Slider.maxValue = maxValue;
		}

		public void Close()
		{
			IsOpen = false;
			Container.SetActive(false);
		}

		private void Send()
		{
			if (IsOpen)
			{
				OnSend?.Invoke(GetSteppedValue(Slider.value));
				Close();
			}
		}

		private void Cancel()
		{
			OnCancel?.Invoke();
			Close();
		}

		private void OnValueChanged(float value)
		{
			ValueLabel.text = string.Format(_format, GetSteppedValue(value));
		}

		private float GetSteppedValue(float value)
		{
			return (float)Math.Round(Mathf.Round(value / _stepSize) * _stepSize, _digits);
		}

		public void BuildUI()
		{
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Expected O, but got Unknown
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Expected O, but got Unknown
			//IL_032d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0364: Unknown result type (might be due to invalid IL or missing references)
			//IL_037b: Unknown result type (might be due to invalid IL or missing references)
			//IL_041f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0436: Unknown result type (might be due to invalid IL or missing references)
			//IL_0460: Unknown result type (might be due to invalid IL or missing references)
			//IL_0477: Unknown result type (might be due to invalid IL or missing references)
			if (!UICreated)
			{
				GameObject gameObject = ((Component)PlayerSingleton<MessagesApp>.Instance.ConfirmationPopup).gameObject;
				Container = Object.Instantiate<GameObject>(gameObject, gameObject.transform.parent);
				((Object)Container).name = "NegotiationPopup";
				Container.SetActive(true);
				Content = Container.transform.Find("Shade/Content");
				((Component)Content).GetComponent<RectTransform>().sizeDelta = new Vector2(-160f, 40f);
				SubtitleLabel = ((Component)Content.Find("Subtitle")).GetComponent<Text>();
				SubtitleLabel.text = "Current: 0.2%\n\nLast offer: 0%";
				ValueLabel = Object.Instantiate<GameObject>(((Component)SubtitleLabel).gameObject, ((Component)SubtitleLabel).transform.parent).GetComponent<Text>();
				((Object)ValueLabel).name = "Value";
				ValueLabel.text = "0%";
				ValueLabel.fontSize = 30;
				ValueLabel.fontStyle = (FontStyle)1;
				RectTransform component = ((Component)ValueLabel).GetComponent<RectTransform>();
				component.anchorMax = new Vector2(1f, 1f);
				component.anchorMin = new Vector2(0f, 0f);
				component.offsetMax = new Vector2(-30f, 200f);
				component.offsetMin = new Vector2(30f, -280f);
				TitleLabel = ((Component)Content.Find("Title")).GetComponent<Text>();
				TitleLabel.text = "Negotiate Cut %";
				Button[] componentsInChildren = ((Component)Content).GetComponentsInChildren<Button>();
				((UnityEventBase)componentsInChildren[0].onClick).RemoveAllListeners();
				((UnityEvent)componentsInChildren[0].onClick).AddListener(new UnityAction(Cancel));
				SendButton = componentsInChildren[2];
				((Object)((Component)SendButton).gameObject).name = "Send";
				((Component)SendButton).GetComponentInChildren<Text>().text = "Send";
				Button sendButton = SendButton;
				ColorBlock colors = default(ColorBlock);
				((ColorBlock)(ref colors)).normalColor = new Color(0.2941f, 0.6863f, 0.8824f, 1f);
				((ColorBlock)(ref colors)).highlightedColor = new Color(0.4532f, 0.7611f, 0.9151f, 1f);
				((ColorBlock)(ref colors)).pressedColor = new Color(0.5674f, 0.8306f, 0.9623f, 1f);
				((ColorBlock)(ref colors)).selectedColor = new Color(0.9608f, 0.9608f, 0.9608f, 1f);
				((ColorBlock)(ref colors)).disabledColor = new Color(0.2941f, 0.6863f, 0.8824f, 1f);
				((ColorBlock)(ref colors)).colorMultiplier = 1f;
				((ColorBlock)(ref colors)).fadeDuration = 0f;
				((Selectable)sendButton).colors = colors;
				((UnityEventBase)SendButton.onClick).RemoveAllListeners();
				((UnityEvent)SendButton.onClick).AddListener(new UnityAction(Send));
				((Graphic)((Component)SendButton).GetComponent<Image>()).color = Color.white;
				GameObject val = Object.Instantiate<GameObject>(GameObject.Find("UI/ItemUIManager/AmountSelector/Slider"), Content);
				((Object)val).name = "Slider";
				RectTransform component2 = val.GetComponent<RectTransform>();
				component2.anchoredPosition = Vector2.zero;
				component2.sizeDelta = new Vector2(280f, 40f);
				Slider = val.GetComponent<Slider>();
				Slider.maxValue = 1f;
				Slider.minValue = 0f;
				Slider.wholeNumbers = false;
				Slider.normalizedValue = 0.5f;
				((UnityEventBase)Slider.onValueChanged).RemoveAllListeners();
				((UnityEvent<float>)(object)Slider.onValueChanged).AddListener((UnityAction<float>)OnValueChanged);
				RectTransform component3 = ((Component)((Transform)component2).Find("Handle Slide Area/Handle")).GetComponent<RectTransform>();
				component3.anchoredPosition = new Vector2(0f, 0f);
				component3.sizeDelta = new Vector2(40f, 0f);
				RectTransform component4 = ((Component)((Transform)component2).Find("Fill Area/Fill")).GetComponent<RectTransform>();
				component4.anchoredPosition = new Vector2(0f, 0f);
				component4.sizeDelta = new Vector2(40f, 0f);
				val.SetActive(true);
				Object.Destroy((Object)(object)((Component)componentsInChildren[1]).gameObject);
				Logger.Debug("NegotiationPopup", "Negotiation popup UI created");
				UICreated = true;
			}
		}
	}
	public static class UIBuilder
	{
		[CompilerGenerated]
		private sealed class <<Build>g__CreateUI|24_0>d : IEnumerator<object>, IEnumerator, IDisposable
		{
			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 <<Build>g__CreateUI|24_0>d(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

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

			private bool MoveNext()
			{
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_004a: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitUntil((Func<bool>)(() => !Singleton<LoadManager>.Instance.IsLoading && Singleton<LoadManager>.Instance.IsGameLoaded));
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					SettingsPopup.BuildUI();
					SliderPopup.BuildUI();
					DeadDropSelector.BuildUI();
					CustomersScrollView.BuildUI();
					if (ModConfig.CustomersSearchAndSort)
					{
						CustomerSelector.BuildUI();
					}
					Logger.Msg("UI elements created");
					HasBuild = true;
					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 bool HasBuild { get; private set; }

		public static SettingsPopup SettingsPopup { get; private set; }

		public static SliderPopup SliderPopup { get; private set; }

		public static DeadDropSelector DeadDropSelector { get; private set; }

		public static CustomersScrollView CustomersScrollView { get; private set; }

		public static CustomerSelector CustomerSelector { get; private set; }

		public static void Build()
		{
			if (!HasBuild)
			{
				if (SettingsPopup == null)
				{
					SettingsPopup = new SettingsPopup();
				}
				if (SliderPopup == null)
				{
					SliderPopup = new SliderPopup();
				}
				if (DeadDropSelector == null)
				{
					DeadDropSelector = new DeadDropSelector();
				}
				if (CustomersScrollView == null)
				{
					CustomersScrollView = new CustomersScrollView();
				}
				if (CustomerSelector == null)
				{
					CustomerSelector = new CustomerSelector();
				}
				MelonCoroutines.Start(CreateUI());
			}
			[IteratorStateMachine(typeof(<<Build>g__CreateUI|24_0>d))]
			static IEnumerator CreateUI()
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <<Build>g__CreateUI|24_0>d(0);
			}
		}

		public static void Reset()
		{
			SettingsPopup = null;
			SliderPopup = null;
			DeadDropSelector = null;
			CustomersScrollView = null;
			CustomerSelector = null;
			HasBuild = false;
		}
	}
}
namespace AdvancedDealing.Persistence
{
	public struct DataWrapper
	{
		public string SaveName;

		public List<DealerData> Dealers;

		public List<DeadDropData> DeadDrops;
	}
	public class NetworkSynchronizer
	{
		public SessionData SessionData;

		protected Callback<LobbyChatMsg_t> LobbyChatMsgCallback;

		protected Callback<LobbyDataUpdate_t> LobbyDataUpdateCallback;

		private readonly string _prefix = Hashing.GetStableHashU16("AdvancedDealing").ToString();

		private CSteamID _lobbySteamID;

		private bool _isSyncing;

		private bool _isHost;

		public static NetworkSynchronizer Instance { get; private set; }

		public static bool IsSyncing => Instance._isSyncing;

		public static bool IsNoSyncOrHost => !IsSyncing || (IsSyncing && Instance._isHost);

		public static bool IsHost => Instance._isHost;

		public static CSteamID LocalSteamID => Singleton<Lobby>.Instance.LocalPlayerID;

		public NetworkSynchronizer()
		{
			if (Instance == null)
			{
				Lobby instance = Singleton<Lobby>.Instance;
				instance.onLobbyChange = (Action)Delegate.Combine(instance.onLobbyChange, new Action(OnLobbyChange));
				LobbyChatMsgCallback = Callback<LobbyChatMsg_t>.Create((DispatchDelegate<LobbyChatMsg_t>)OnLobbyMessage);
				Instance = this;
			}
		}

		private void StartSyncing()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			_isHost = false;
			_lobbySteamID = Singleton<Lobby>.Instance.LobbySteamID;
			_isSyncing = true;
			Logger.Msg("NetworkSynchronizer", "Synchronization started");
		}

		private void StopSyncing()
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			_isHost = false;
			_lobbySteamID = CSteamID.Nil;
			_isSyncing = false;
			SessionData = null;
			Logger.Msg("NetworkSynchronizer", "Synchronization stopped");
		}

		public void SetAsHost()
		{
			_isHost = true;
			Logger.Debug("NetworkSynchronizer", "Set as host");
		}

		public void SendData(DataBase data)
		{
			SendData(data.DataType, data.Identifier, JsonConvert.SerializeObject((object)data, FileSerializer.JsonSerializerSettings));
		}

		public void SendData(string dataType, string identifier, string dataString)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			if (IsSyncing)
			{
				string text = _prefix + "_" + dataType + "_" + identifier;
				SteamMatchmaking.SetLobbyMemberData(_lobbySteamID, text, dataString);
				SendMessage(text);
				Logger.Debug("NetworkSynchronizer", "Data synced with lobby: " + text);
			}
		}

		public void SendMessage(string text, string identifier = null)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			text = _prefix + "__" + text;
			if (identifier != null)
			{
				text = text + "__" + identifier;
			}
			byte[] bytes = Encoding.UTF8.GetBytes(text);
			SteamMatchmaking.SendLobbyChatMsg(_lobbySteamID, bytes, bytes.Length);
		}

		public void FetchData(CSteamID steamId, string key)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			string lobbyMemberData = SteamMatchmaking.GetLobbyMemberData(_lobbySteamID, steamId, key);
			bool flag = false;
			if (lobbyMemberData != null)
			{
				string[] array = key.Split("_");
				if (array[1] != null && array[2] != null)
				{
					string text = array[1];
					string guid = array[2];
					if (text == "DealerData")
					{
						DealerExtension dealer = DealerExtension.GetDealer(guid);
						if (dealer != null)
						{
							DealerData data = JsonConvert.DeserializeObject<DealerData>(lobbyMemberData);
							dealer.PatchData(data);
							flag = true;
						}
					}
					else if (text == "SessionData" && !_isHost)
					{
						SessionData = JsonConvert.DeserializeObject<SessionData>(lobbyMemberData);
						flag = true;
					}
				}
			}
			if (flag)
			{
				Logger.Debug("NetworkSynchronizer", "Data from lobby fetched: " + key);
			}
			else
			{
				Logger.Debug("NetworkSynchronizer", "Could not fetch data from lobby: " + key);
			}
		}

		private void OnLobbyMessage(LobbyChatMsg_t res)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			if (!IsSyncing)
			{
				return;
			}
			byte[] array = new byte[4096];
			CSteamID val = default(CSteamID);
			EChatEntryType val2 = default(EChatEntryType);
			SteamMatchmaking.GetLobbyChatEntry(_lobbySteamID, (int)res.m_iChatID, ref val, array, array.Length, ref val2);
			if (val == LocalSteamID)
			{
				return;
			}
			string @string = Encoding.UTF8.GetString(array);
			@string = @string.TrimEnd(new char[1]);
			string[] array2 = @string.Split("__");
			if (!(array2[0] == _prefix))
			{
				return;
			}
			Logger.Debug("NetworkSynchronizer", "Received msg: " + array2[1]);
			string text = array2[1];
			string text2 = text;
			if (!(text2 == "data_request"))
			{
				if (text2 == "dealer_fired")
				{
					DealerExtension.GetDealer(array2[2])?.Fire();
				}
				else
				{
					FetchData(val, array2[1]);
				}
			}
			else
			{
				if (!_isHost)
				{
					return;
				}
				SendData(SessionData);
				foreach (DealerData item in DealerExtension.FetchAllDealerDatas())
				{
					SendData(item);
				}
			}
		}

		private void OnLobbyChange()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			if (Singleton<Lobby>.Instance.IsInLobby && _isSyncing && Singleton<Lobby>.Instance.LobbySteamID != _lobbySteamID)
			{
				_lobbySteamID = Singleton<Lobby>.Instance.LobbySteamID;
			}
			else if (Singleton<Lobby>.Instance.IsInLobby && !_isSyncing)
			{
				StartSyncing();
			}
			else if (!Singleton<Lobby>.Instance.IsInLobby && _isSyncing)
			{
				StopSyncing();
			}
		}
	}
	public class SaveModifier
	{
		[CompilerGenerated]
		private sealed class <<LoadModifications>g__LoadRoutine|15_0>d : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public SaveModifier <>4__this;

			private DataWrapper <data>5__1;

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

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

			[DebuggerHidden]
			public <<LoadModifications>g__LoadRoutine|15_0>d(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<data>5__1 = default(DataWrapper);
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0173: Unknown result type (might be due to invalid IL or missing references)
				//IL_017d: Expected O, but got Unknown
				//IL_012d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0132: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					if (!FileSerializer.LoadFromFile<DataWrapper>(FilePath, out <data>5__1))
					{
						<>4__this.SaveData = new DataWrapper
						{
							SaveName = $"SaveGame_{Singleton<LoadManager>.Instance.ActiveSaveInfo.SaveSlotNumber}",
							Dealers = new List<DealerData>(),
							DeadDrops = new List<DeadDropData>()
						};
					}
					else
					{
						<>4__this.SaveData = new DataWrapper
						{
							SaveName = $"SaveGame_{Singleton<LoadManager>.Instance.ActiveSaveInfo.SaveSlotNumber}",
							Dealers = (<data>5__1.Dealers ?? new List<DealerData>()),
							DeadDrops = (<data>5__1.DeadDrops ?? new List<DeadDropData>())
						};
					}
					DeadDropExtension.Initialize();
					DealerExtension.Initialize();
					if (NetworkSynchronizer.IsSyncing)
					{
						NetworkSynchronizer.Instance.SetAsHost();
						NetworkSynchronizer instance = NetworkSynchronizer.Instance;
						CSteamID lobbySteamID = Singleton<Lobby>.Instance.LobbySteamID;
						instance.SessionData = new SessionData(((object)(CSteamID)(ref lobbySteamID)).ToString())
						{
							AccessInventory = ModConfig.AccessInventory,
							SettingsMenu = ModConfig.SettingsMenu,
							NegotiationModifier = ModConfig.NegotiationModifier
						};
					}
					<>2__current = (object)new WaitForSecondsRealtime(2f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>4__this.SavegameLoaded = true;
					UIBuilder.Build();
					Logger.Msg("Savegame modifications successfully injected");
					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 <<LoadModificationsAsClient>g__ClientLoadRoutine|16_0>d : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public SaveModifier <>4__this;

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

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

			[DebuggerHidden]
			public <<LoadModificationsAsClient>g__ClientLoadRoutine|16_0>d(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

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

			private bool MoveNext()
			{
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0069: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>4__this.SaveData = new DataWrapper
					{
						SaveName = "temporary",
						Dealers = new List<DealerData>()
					};
					DeadDropExtension.Initialize();
					DealerExtension.Initialize();
					<>2__current = (object)new WaitForSecondsRealtime(2f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>4__this.SavegameLoaded = true;
					NetworkSynchronizer.Instance.SendMessage("data_request");
					UIBuilder.Build();
					Logger.Msg("Savegame modifications successfully injected");
					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 SaveModifier Instance { get; private set; }

		public DataWrapper SaveData { get; private set; }

		public bool SavegameLoaded { get; private set; }

		private static string FilePath => Path.Combine(Singleton<LoadManager>.Instance.ActiveSaveInfo.SavePath, "AdvancedDealing.json");

		public SaveModifier()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			if (Instance == null)
			{
				Singleton<SaveManager>.Instance.onSaveComplete.AddListener(new UnityAction(OnSaveComplete));
				Instance = this;
			}
		}

		public void LoadModifications()
		{
			Logger.Msg("Preparing savegame modifications...");
			if (Singleton<Lobby>.Instance.IsInLobby && !Singleton<Lobby>.Instance.IsHost)
			{
				LoadModificationsAsClient();
			}
			else
			{
				MelonCoroutines.Start(LoadRoutine());
			}
			[IteratorStateMachine(typeof(<<LoadModifications>g__LoadRoutine|15_0>d))]
			IEnumerator LoadRoutine()
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <<LoadModifications>g__LoadRoutine|15_0>d(0)
				{
					<>4__this = this
				};
			}
		}

		private void LoadModificationsAsClient()
		{
			MelonCoroutines.Start(ClientLoadRoutine());
			[IteratorStateMachine(typeof(<<LoadModificationsAsClient>g__ClientLoadRoutine|16_0>d))]
			IEnumerator ClientLoadRoutine()
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <<LoadModificationsAsClient>g__ClientLoadRoutine|16_0>d(0)
				{
					<>4__this = this
				};
			}
		}

		public void ClearModifications()
		{
			UIBuilder.Reset();
			List<DealerExtension> allDealers = DealerExtension.GetAllDealers();
			for (int num = allDealers.Count - 1; num >= 0; num--)
			{
				allDealers[num].Destroy();
			}
			SavegameLoaded = false;
			Logger.Msg("Savegame modifications cleared");
		}

		private void OnSaveComplete()
		{
			if (NetworkSynchronizer.IsNoSyncOrHost)
			{
				DataWrapper dataWrapper = default(DataWrapper);
				dataWrapper.SaveName = $"SaveGame_{Singleton<LoadManager>.Instance.ActiveSaveInfo.SaveSlotNumber}";
				dataWrapper.Dealers = DealerExtension.FetchAllDealerDatas();
				dataWrapper.DeadDrops = DeadDropExtension.FetchAllDeadDropDatas();
				DataWrapper data = dataWrapper;
				Logger.Msg("Data for " + data.SaveName + " saved");
				FileSerializer.SaveToFile(FilePath, data);
			}
		}
	}
}
namespace AdvancedDealing.Persistence.IO
{
	public static class FileSerializer
	{
		public static readonly JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings
		{
			NullValueHandling = (NullValueHandling)0,
			MissingMemberHandling = (MissingMemberHandling)0,
			Formatting = (Formatting)1
		};

		public static Type LastLoadedDataType { get; private set; }

		public static string LastLoadedDataString { get; private set; }

		public static bool LoadFromFile<T>(string filePath, out T data) where T : struct
		{
			if (File.Exists(filePath))
			{
				string text = File.ReadAllText(filePath);
				data = JsonConvert.DeserializeObject<T>(text, JsonSerializerSettings);
				LastLoadedDataType = data.GetType();
				LastLoadedDataString = text;
				Logger.Debug("Loaded from file: " + filePath);
				return true;
			}
			data = default(T);
			return false;
		}

		public static void SaveToFile<T>(string filePath, T data) where T : struct
		{
			string contents = JsonConvert.SerializeObject((object)data, JsonSerializerSettings);
			File.WriteAllText(filePath, contents);
			Logger.Debug("Saved to file: " + filePath);
		}
	}
}
namespace AdvancedDealing.Persistence.Datas
{
	public abstract class DataBase
	{
		public string DataType;

		public string ModVersion;

		public string Identifier;

		public DataBase(string identifier)
		{
			DataType = GetType().Name;
			ModVersion = "1.3.0";
			Identifier = identifier;
		}

		public virtual bool IsEqual(object other)
		{
			if (!GetType().Equals(other.GetType()))
			{
				throw new Exception($"Tried to compare {GetType()} with {other.GetType()}");
			}
			bool result = true;
			FieldInfo[] fields = GetType().GetFields();
			FieldInfo[] array = fields;
			foreach (FieldInfo fieldInfo in array)
			{
				if (fieldInfo.GetValue(this) != fieldInfo.GetValue(other))
				{
					result = false;
					break;
				}
			}
			return result;
		}

		public virtual void Merge(DataBase other)
		{
			FieldInfo[] fields = GetType().GetFields();
			FieldInfo[] array = fields;
			foreach (FieldInfo fieldInfo in array)
			{
				if (fieldInfo.GetValue(other) == null || fieldInfo.GetValue(this) != fieldInfo.GetValue(other))
				{
					fieldInfo.SetValue(this, fieldInfo.GetValue(other));
				}
			}
		}
	}
	public class DeadDropData : DataBase
	{
		public string CashCollectionQuest;

		public string RefillProductsQuest;

		public DeadDropData(string identifier, bool loadDefaults = false)
			: base(identifier)
		{
			if (loadDefaults)
			{
				LoadDefaults();
			}
		}

		public void LoadDefaults()
		{
		}
	}
	public class DealerData : DataBase
	{
		public string DeadDrop;

		public int MaxCustomers;

		public int ItemSlots;

		public float Cut;

		public float SpeedMultiplier;

		public bool DeliverCash;

		public bool PickupProducts;

		public float CashThreshold;

		public int ProductThreshold;

		public int DaysUntilNextNegotiation;

		public DealerData(string identifier, bool loadDefaults = false)
			: base(identifier)
		{
			if (loadDefaults)
			{
				LoadDefaults();
			}
		}

		public void LoadDefaults()
		{
			DeadDrop = null;
			MaxCustomers = 8;
			ItemSlots = 5;
			Cut = 0.2f;
			SpeedMultiplier = 1f;
			DeliverCash = false;
			PickupProducts = false;
			CashThreshold = 1500f;
			ProductThreshold = 20;
			DaysUntilNextNegotiation = 0;
		}
	}
	public class SessionData : DataBase
	{
		public bool AccessInventory;

		public bool SettingsMenu;

		public float NegotiationModifier;

		public SessionData(string identifier)
			: base(identifier)
		{
		}
	}
}
namespace AdvancedDealing.Patches
{
	[HarmonyPatch(typeof(CustomerSelector))]
	public class CustomerSelectorPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Open")]
		public static void OpenPostfix()
		{
			if (UIBuilder.CustomerSelector.UICreated)
			{
				UIBuilder.CustomerSelector.SortCustomers();
				UIBuilder.CustomerSelector.Searchbar.text = string.Empty;
			}
		}
	}
	[HarmonyPatch(typeof(DealerManagementApp))]
	public class DealerManagementAppPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("SetDisplayedDealer")]
		public static void SetDisplayedDealerPostfix(DealerManagementApp __instance, Dealer dealer)
		{
			if (!SaveModifier.Instance.SavegameLoaded || !UIBuilder.HasBuild)
			{
				return;
			}
			DealerExtension dealer2 = DealerExtension.GetDealer(dealer);
			if (dealer2 != null)
			{
				string text = "None";
				string deadDrop = dealer2.DeadDrop;
				if (deadDrop != null)
				{
					DeadDropExtension deadDrop2 = DeadDropExtension.GetDeadDrop(dealer2.DeadDrop);
					text = deadDrop2.DeadDrop.DeadDropName;
				}
				UIBuilder.DeadDropSelector.ButtonLabel.text = text;
				UIBuilder.CustomersScrollView.TitleLabel.text = $"Assigned Customers ({dealer2.Dealer.AssignedCustomers.Count}/{dealer2.MaxCustomers})";
				if (dealer2.Dealer.AssignedCustomers.Count < dealer2.MaxCustomers)
				{
					UIBuilder.CustomersScrollView.AssignButton.SetActive(true);
				}
				else
				{
					UIBuilder.CustomersScrollView.AssignButton.SetActive(false);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Dealer))]
	public class DealerPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("OnTick")]
		public static bool OnTickPrefix(Dealer __instance)
		{
			if (DealerExtension.DealerExists(__instance))
			{
				DealerExtension dealer = DealerExtension.GetDealer(__instance);
				if (dealer.HasActiveBehaviour)
				{
					typeof(Dealer).GetMethod("UpdatePotentialDealerPoI", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, Array.Empty<object>());
					return false;
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(App<MessagesApp>))]
	public class MessagesAppPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("SetOpen")]
		public static void SetOpenPostfix()
		{
			if (!SaveModifier.Instance.SavegameLoaded)
			{
				return;
			}
			foreach (Conversation allConversation in Conversation.GetAllConversations())
			{
				allConversation.PatchSendableMessages();
			}
		}
	}
	[HarmonyPatch(typeof(NPCBehaviour))]
	public class NPCBehaviourPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("Update")]
		public static bool UpdatePrefix(NPCBehaviour __instance)
		{
			if (DealerExtension.DealerExists(__instance.Npc.GUID.ToString()))
			{
				DealerExtension dealer = DealerExtension.GetDealer(__instance.Npc.GUID.ToString());
				if (dealer.HasActiveBehaviour)
				{
					return false;
				}
			}
			return true;
		}
	}
}
namespace AdvancedDealing.NPCs.Behaviour
{
	public abstract class DealerBehaviour
	{
		public const int MAX_CONSECUTIVE_PATHING_FAILURES = 5;

		public int Priority;

		protected int ConsecutivePathingFailures;

		protected DealerExtension Dealer;

		private Vector3 _lastDestination;

		private bool _enableScheduleOnEnd = false;

		public virtual string Name => "Behaviour";

		public virtual bool IsEnabled { get; protected set; }

		public bool IsActive { get; protected set; }

		public bool HasStarted { get; protected set; }

		protected NPCMovement Movement => ((NPC)Dealer.Dealer).Movement;

		private Behaviour activeBehaviour
		{
			get
			{
				NPCBehaviour behaviour = ((NPC)Dealer.Dealer).Behaviour;
				return (behaviour != null) ? behaviour.activeBehaviour : null;
			}
		}

		private NPCScheduleManager schedule => ((Component)Dealer.Dealer).GetComponentInChildren<NPCScheduleManager>();

		public DealerBehaviour(DealerExtension dealer)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			Dealer = dealer;
			((NPC)dealer.Dealer).Health.onKnockedOut.AddListener(new UnityAction(OnKnockOutOrDie));
			((NPC)dealer.Dealer).Health.onDie.AddListener(new UnityAction(OnKnockOutOrDie));
			((NPC)dealer.Dealer).Health.onRevive.AddListener(new UnityAction(OnRevive));
		}

		public virtual void Enable()
		{
			IsEnabled = true;
			Logger.Debug("DealerBehaviour", "Behaviour for " + ((NPC)Dealer.Dealer).fullName + " enabled: " + Name);
		}

		public void Disable()
		{
			IsEnabled = false;
			if (HasStarted)
			{
				End();
			}
			Logger.Debug("DealerBehaviour", "Behaviour for " + ((NPC)Dealer.Dealer).fullName + " disabled: " + Name);
		}

		public virtual void Start()
		{
			HasStarted = true;
			IsActive = true;
			Dealer.SetActiveBehaviour(this);
			Behaviour obj = activeBehaviour;
			if (obj != null)
			{
				obj.Pause();
			}
			if ((Object)(object)schedule != (Object)null && schedule.ScheduleEnabled)
			{
				schedule.DisableSchedule();
				_enableScheduleOnEnd = true;
			}
			Logger.Debug("DealerBehaviour", "Behaviour for " + ((NPC)Dealer.Dealer).fullName + " started: " + Name);
		}

		public virtual void End()
		{
			HasStarted = false;
			IsActive = false;
			Disable();
			Dealer.SetActiveBehaviour(null);
			if (_enableScheduleOnEnd && (Object)(object)schedule != (Object)null)
			{
				schedule.EnableSchedule();
			}
			Logger.Debug("DealerBehaviour", "Behaviour for " + ((NPC)Dealer.Dealer).fullName + " ended: " + Name);
		}

		public virtual void Pause()
		{
			IsActive = false;
			if (_enableScheduleOnEnd && (Object)(object)schedule != (Object)null)
			{
				schedule.EnableSchedule();
			}
			Logger.Debug("DealerBehaviour", "Behaviour for " + ((NPC)Dealer.Dealer).fullName + " paused: " + Name);
		}

		public virtual void Resume()
		{
			IsActive = true;
			if ((Object)(object)schedule != (Object)null && schedule.ScheduleEnabled)
			{
				schedule.DisableSchedule();
				_enableScheduleOnEnd = true;
			}
			Logger.Debug("DealerBehaviour", "Behaviour for " + ((NPC)Dealer.Dealer).fullName + " resumed: " + Name);
		}

		public virtual void OnActiveTick()
		{
			Behaviour obj = activeBehaviour;
			if (obj != null)
			{
				obj.Pause();
			}
		}

		protected virtual void SetDestination(Vector3 position, bool teleportIfFail = true, float successThreshold = 1f)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			if (InstanceFinder.IsServer)
			{
				if (teleportIfFail && ConsecutivePathingFailures >= 5 && !Movement.CanGetTo(position, 1f))
				{
					Logger.Debug("DealerBehaviour", $"Too many pathing failures for {((NPC)Dealer.Dealer).fullName}. Warping to {position}.");
					NavMeshHit val = default(NavMeshHit);
					NavMeshUtility.SamplePosition(position, ref val, 5f, -1, true);
					position = ((NavMeshHit)(ref val)).position;
					Movement.Warp(position);
					WalkCallback((WalkResult)4);
				}
				else
				{
					_lastDestination = position;
					Movement.SetDestination(position, (Action<WalkResult>)WalkCallback, successThreshold, 0.1f);
				}
			}
		}

		protected bool IsAtDestination()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			return Vector3.Distance(Movement.FootPosition, _lastDestination) < 2f;
		}

		protected virtual void WalkCallback(WalkResult res)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Invalid comparison between Unknown and I4
			if (IsActive)
			{
				if ((int)res == 0)
				{
					ConsecutivePathingFailures++;
				}
				else
				{
					ConsecutivePathingFailures = 0;
				}
			}
		}

		private void OnKnockOutOrDie()
		{
			if (IsEnabled && HasStarted)
			{
				Pause();
			}
		}

		private void OnRevive()
		{
			if (IsEnabled && HasStarted)
			{
				Resume();
			}
		}
	}
	public class DeliverCashDealerBehaviour : DealerBehaviour
	{
		[CompilerGenerated]
		private sealed class <<BeginDelivery>g__DeliveryRoutine|10_0>d : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public DeliverCashDealerBehaviour <>4__this;

			private float <cash>5__1;

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

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

			[DebuggerHidden]
			public <<BeginDelivery>g__DeliveryRoutine|10_0>d(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

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

			private bool MoveNext()
			{
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0075: Unknown result type (might be due to invalid IL or missing references)
				//IL_007f: Expected O, but got Unknown
				//IL_0217: Unknown result type (might be due to invalid IL or missing references)
				//IL_0221: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<cash>5__1 = <>4__this.Dealer.Dealer.Cash;
					<>4__this.Movement.FaceDirection(<>4__this._deadDrop.GetPosition(), 0.5f);
					<>2__current = (object)new WaitForSeconds(2f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					((NPC)<>4__this.Dealer.Dealer).SetAnimationTrigger("GrabItem");
					if (<>4__this._deadDrop.IsFull())
					{
						<>4__this._deadDropIsFull = true;
						<>4__this.Dealer.SendMessage("Could not deliver cash to dead drop " + <>4__this._deadDrop.DeadDrop.DeadDropName + ". There is no space inside!", ModConfig.NotifyOnAction);
						Logger.Debug("Cash delivery for " + ((NPC)<>4__this.Dealer.Dealer).fullName + " failed: Dead drop is full");
						break;
					}
					((StorageEntity)<>4__this._deadDrop.DeadDrop.Storage).InsertItem((ItemInstance)(object)NetworkSingleton<MoneyManager>.Instance.GetCashInstance(<cash>5__1), true);
					<>4__this.Dealer.SendMessage($"I've put ${<cash>5__1:F0} inside the dead drop {((Object)<>4__this._deadDrop.DeadDrop).name}.", ModConfig.NotifyOnAction);
					if (ModConfig.NotifyOnAction)
					{
					}
					<>4__this.Dealer.Dealer.ChangeCash(0f - <cash>5__1);
					Logger.Debug("Cash from " + ((NPC)<>4__this.Dealer.Dealer).fullName + " delivered successfully");
					<>2__current = (object)new WaitUntil((Func<bool>)(() => <>4__this.Dealer.Dealer.Cash < <>4__this.Dealer.CashThreshold));
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -1;
					break;
				}
				<>4__this.End();
				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 <<BeginInstantDelivery>g__InstantDeliveryRoutine|11_0>d : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public DeliverCashDealerBehaviour <>4__this;

			private float <cash>5__1;

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

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

			[DebuggerHidden]
			public <<BeginInstantDelivery>g__InstantDeliveryRoutine|11_0>d(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

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

			private bool MoveNext()
			{
				//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c0: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<cash>5__1 = <>4__this.Dealer.Dealer.Cash;
					NetworkSingleton<MoneyManager>.Instance.ChangeCashBalance(<cash>5__1, true, true);
					<>4__this.Dealer.SendMessage($"Sent you ${<cash>5__1:F0} from my earnings.", ModConfig.NotifyOnAction);
					<>4__this.Dealer.Dealer.ChangeCash(0f - <cash>5__1);
					<>2__current = (object)new WaitUntil((Func<bool>)(() => <>4__this.Dealer.Dealer.Cash < <>4__this.Dealer.CashThreshold));
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>4__this.End();
					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();
			}
		}

		private DeadDropExtension _deadDrop;

		private object _deliveryRoutine;

		private object _instantDeliveryRoutine;

		private bool _deadDropIsFull = false;

		public override string Name => "Deliver cash";

		public DeliverCashDealerBehaviour(DealerExtension dealer)
			: base(dealer)
		{
			Priority = 1;
		}

		public override void Start()
		{
			_deadDrop = DeadDropExtension.GetDeadDrop(Dealer.DeadDrop);
			if (!_deadDropIsFull || _deadDrop == null || !_deadDrop.IsFull())
			{
				_deadDropIsFull = false;
				base.Start();
			}
		}

		public override void End()
		{
			base.End();
			StopRoutines();
		}

		public override void OnActiveTick()
		{
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			if (!base.IsActive || _instantDeliveryRoutine != null)
			{
				return;
			}
			base.OnActiveTick();
			if (_deadDrop == null)
			{
				BeginInstantDelivery();
			}
			else if (ModConfig.SkipMovement)
			{
				BeginDelivery();
			}
			else if (Dealer.Dealer.Cash < Dealer.CashThreshold || (_deadDrop != null && _deadDrop.DeadDrop.GUID.ToString() != Dealer.DeadDrop) || !Dealer.DeliverCash)
			{
				End();
			}
			else if (_deliveryRoutine == null && !base.Movement.IsMoving)
			{
				if (IsAtDestination())
				{
					BeginDelivery();
				}
				else
				{
					SetDestination(_deadDrop.GetPosition(), teleportIfFail: true, 2f);
				}
			}
		}

		private void BeginDelivery()
		{
			if (_deliveryRoutine == null)
			{
				_deliveryRoutine = MelonCoroutines.Start(DeliveryRoutine());
			}
			[IteratorStateMachine(typeof(<<BeginDelivery>g__DeliveryRoutine|10_0>d))]
			IEnumerator DeliveryRoutine()
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <<BeginDelivery>g__DeliveryRoutine|10_0>d(0)
				{
					<>4__this = this
				};
			}
		}

		private void BeginInstantDelivery()
		{
			if (_instantDeliveryRoutine == null)
			{
				_instantDeliveryRoutine = MelonCoroutines.Start(InstantDeliveryRoutine());
			}
			[IteratorStateMachine(typeof(<<BeginInstantDelivery>g__InstantDeliveryRoutine|11_0>d))]
			IEnumerator InstantDeliveryRoutine()
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <<BeginInstantDelivery>g__InstantDeliveryRoutine|11_0>d(0)
				{
					<>4__this = this
				};
			}
		}

		private void StopRoutines()
		{
			if (_deliveryRoutine != null)
			{
				MelonCoroutines.Stop(_deliveryRoutine);
				_deliveryRoutine = null;
			}
			if (_instantDeliveryRoutine != null)
			{
				MelonCoroutines.Stop(_instantDeliveryRoutine);
				_instantDeliveryRoutine = null;
			}
		}
	}
	public class PickupProductsDealerBehaviour : DealerBehaviour
	{
		[CompilerGenerated]
		private sealed class <<BeginPickup>g__PickupRoutine|9_0>d : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public PickupProductsDealerBehaviour <>4__this;

			private bool <shouldNotify>5__1;

			private Dictionary<ProductItemInstance, ItemSlot> <products>5__2;

			private int <totalAmount>5__3;

			private int <freeSlots2>5__4;

			private Dictionary<ProductItemInstance, ItemSlot>.Enumerator <>s__5;

			private KeyValuePair<ProductItemInstance, ItemSlot> <product>5__6;

			private int <freeSlots>5__7;

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

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

			[DebuggerHidden]
			public <<BeginPickup>g__PickupRoutine|9_0>d(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<products>5__2 = null;
				<>s__5 = default(Dictionary<ProductItemInstance, ItemSlot>.Enumerator);
				<product>5__6 = default(KeyValuePair<ProductItemInstance, ItemSlot>);
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_005a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0064: Expected O, but got Unknown
				//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ed: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>4__this.Movement.FaceDirection(<>4__this._deadDrop.GetPosition(), 0.5f);
					<>2__current = (object)new WaitForSeconds(2f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					((NPC)<>4__this.Dealer.Dealer).SetAnimationTrigger("GrabItem");
					<shouldNotify>5__1 = true;
					if (<>4__this._deadDrop.GetAllProducts().Count > 0)
					{
						<products>5__2 = <>4__this._deadDrop.GetAllProducts();
						<>s__5 = <products>5__2.GetEnumerator();
						try
						{
							while (<>s__5.MoveNext())
							{
								<product>5__6 = <>s__5.Current;
								if (<>4__this.Dealer.IsInventoryFull(out <freeSlots>5__7) || <freeSlots>5__7 <= 1)
								{
									break;
								}
								((NPC)<>4__this.Dealer.Dealer).Inventory.InsertItem((ItemInstance)(object)<product>5__6.Key, true);
								<product>5__6.Value.ChangeQuantity(-((ItemInstance)<product>5__6.Key).Quantity, false);
								<product>5__6 = default(KeyValuePair<ProductItemInstance, ItemSlot>);
							}
						}
						finally
						{
							((IDisposable)<>s__5).Dispose();
						}
						<>s__5 = default(Dictionary<ProductItemInstance, ItemSlot>.Enumerator);
						<>4__this.Dealer.GetAllProducts(out <totalAmount>5__3);
						if (<totalAmount>5__3 <= <>4__this.Dealer.ProductThreshold && !<>4__this.Dealer.IsInventoryFull(out <freeSlots2>5__4) && <freeSlots2>5__4 > 1)
						{
							<shouldNotify>5__1 = true;
						}
						else
						{
							<shouldNotify>5__1 = false;
							Logger.Debug("Product pickup for " + ((NPC)<>4__this.Dealer.Dealer).fullName + " was successfull");
						}
						<products>5__2 = null;
					}
					if (<shouldNotify>5__1)
					{
						<>4__this.Dealer.SendMessage("Could not pickup products at dead drop " + <>4__this._deadDrop.DeadDrop.DeadDropName + ". There are no products inside!", ModConfig.NotifyOnAction);
						<>4__this._deadDropIsEmpty = true;
						if (ModConfig.NotifyOnAction)
						{
						}
						Logger.Debug("Product pickup for " + ((NPC)<>4__this.Dealer.Dealer).fullName + " failed: Dead drop is empty");
					}
					<>2__current = (object)new WaitForSeconds(2f);
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -1;
					<>4__this.End();
					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();
			}
		}

		private DeadDropExtension _deadDrop;

		private object _pickupRoutine;

		private bool _deadDropIsEmpty = false;

		public override string Name => "Pickup products";

		public PickupProductsDealerBehaviour(DealerExtension dealer)
			: base(dealer)
		{
			Priority = 2;
		}

		public override void Start()
		{
			_deadDrop = DeadDropExtension.GetDeadDrop(Dealer.DeadDrop);
			if (!_deadDropIsEmpty || _deadDrop == null || _deadDrop.GetAllProducts().Count > 0)
			{
				_deadDropIsEmpty = false;
				base.Start();
			}
		}

		public override void End()
		{
			base.End();
			StopRoutines();
		}

		public override void OnActiveTick()
		{
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			if (!base.IsActive)
			{
				return;
			}
			base.OnActiveTick();
			if (_deadDrop == null)
			{
				End();
			}
			else if (ModConfig.SkipMovement)
			{
				BeginPickup();
			}
			else if ((_deadDrop != null && _deadDrop.DeadDrop.GUID.ToString() != Dealer.DeadDrop) || !Dealer.PickupProducts)
			{
				End();
			}
			else if (_pickupRoutine == null && !base.Movement.IsMoving)
			{
				if (IsAtDestination())
				{
					BeginPickup();
				}
				else
				{
					SetDestination(_deadDrop.GetPosition(), teleportIfFail: true, 2f);
				}
			}
		}

		private void BeginPickup()
		{
			if (_pickupRoutine == null)
			{
				_pickupRoutine = MelonCoroutines.Start(PickupRoutine());
			}
			[IteratorStateMachine(typeof(<<BeginPickup>g__PickupRoutine|9_0>d))]
			IEnumerator PickupRoutine()
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <<BeginPickup>g__PickupRoutine|9_0>d(0)
				{
					<>4__this = this
				};
			}
		}

		private void StopRoutines()
		{
			if (_pickupRoutine != null)
			{
				MelonCoroutines.Stop(_pickupRoutine);
				_pickupRoutine = null;
			}
		}
	}
}
namespace AdvancedDealing.Messaging
{
	public class Conversation
	{
		public readonly NPC NPC;

		public bool UIPatched;

		private static readonly List<Conversation> cache = new List<Conversation>();

		private readonly List<MessageBase> _sendableMessages = new List<MessageBase>();

		private readonly List<MessageBase> _patchedMessages = new List<MessageBase>();

		public MSGConversation S1Conversation => NPC.MSGConversation;

		public Conversation(NPC npc)
		{
			NPC = npc;
			Logger.Debug("Conversation", "Conversation created: " + npc.fullName);
			cache.Add(this);
		}

		public void PatchSendableMessages()
		{
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Expected O, but got Unknown
			if ((Object)(object)NPC == (Object)null || S1Conversation == null)
			{
				return;
			}
			foreach (MessageBase msg in _sendableMessages)
			{
				bool flag = S1Conversation.Sendables.Exists((SendableMessage x) => x.Text == msg.Text);
				if (!_patchedMessages.Contains(msg) && !flag)
				{
					SendableMessage val = S1Conversation.CreateSendableMessage(msg.Text);
					MessageBase messageBase = msg;
					val.ShouldShowCheck = new BoolCheck(messageBase.ShouldShowCheck);
					val.disableDefaultSendBehaviour = msg.DisableDefaultSendBehaviour;
					val.onSelected = msg.OnSelected;
					val.onSent = msg.OnSent;
					_patchedMessages.Add(msg);
				}
			}
			if (!UIPatched)
			{
				NPC.ConversationCanBeHidden = false;
				S1Conversation.EnsureUIExists();
				S1Conversation.SetEntryVisibility(true);
				UIPatched = true;
			}
		}

		public void Destroy()
		{
			if ((Object)(object)NPC != (Object)null)
			{
				NPC.ConversationCanBeHidden = true;
			}
			UIPatched = false;
			cache.Remove(this);
		}

		public void AddSendableMessage(MessageBase message)
		{
			Type type = message.GetType();
			if (!_sendableMessages.Exists((MessageBase a) => a.GetType() == type))
			{
				message.SetReferences(NPC, this);
				_sendableMessages.Add(message);
			}
		}

		public static Conversation GetConversation(string npcGuid)
		{
			Conversation conversation = cache.Find((Conversation x) => x.NPC.GUID.ToString().Contains(npcGuid));
			if (conversation == null)
			{
				Logger.Error("Conversation", "Could not find conversation for: " + npcGuid);
				return null;
			}
			return conversation;
		}

		public static List<Conversation> GetAllConversations()
		{
			return cache;
		}

		public static void ClearAll()
		{
			cache.Clear();
			Logger.Debug("Conversation", "Conversations deinitialized");
		}

		public static bool ConversationExists(string npcName)
		{
			Conversation conversation = cache.Find((Conversation x) => ((Object)x.NPC).name.Contains(npcName));
			return conversation != null;
		}
	}
}
namespace AdvancedDealing.Messaging.Messages
{
	public class AccessInventoryMessage : MessageBase
	{
		private readonly DealerExtension _dealer;

		public override string Text => "Access inventory";

		public override bool DisableDefaultSendBehaviour => true;

		public AccessInventoryMessage(DealerExtension dealerExtension)
		{
			_dealer = dealerExtension;
			base..ctor();
		}

		public override bool ShouldShowCheck(SendableMessage sMsg)
		{
			if (_dealer.Dealer.IsRecruited && ModConfig.AccessInventory)
			{
				return true;
			}
			return false;
		}

		public override void OnSelected()
		{
			Singleton<GameplayMenu>.Instance.SetIsOpen(false);
			typeof(Dealer).GetMethod("TradeItems", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(_dealer.Dealer, Array.Empty<object>());
		}
	}
	public class AdjustSettingsMessage : MessageBase
	{
		private readonly DealerExtension _dealer;

		public override string Text => "Need to adjust settings";

		public override bool DisableDefaultSendBehaviour => true;

		public AdjustSettingsMessage(DealerExtension dealerExtension)
		{
			_dealer = dealerExtension;
			base..ctor();
		}

		public override bool ShouldShowCheck(SendableMessage sMsg)
		{
			if (_dealer.Dealer.IsRecruited && ModConfig.SettingsMenu)
			{
				return true;
			}
			return false;
		}

		public override void OnSelected()
		{
			UIBuilder.SettingsPopup.Open(_dealer);
		}
	}
	public class DisableDeliverCashMessage : MessageBase
	{
		private readonly DealerExtension _dealer;

		public override string Text => "Stop delivering cash";

		public override bool DisableDefaultSendBehaviour => true;

		public DisableDeliverCashMessage(DealerExtension dealerExtension)
		{
			_dealer = dealerExtension;
			base..ctor();
		}

		public override bool ShouldShowCheck(SendableMessage sMsg)
		{
			if (_dealer.Dealer.IsRecruited && _dealer.DeliverCash)
			{
				return true;
			}
			return false;
		}

		public override void OnSelected()
		{
			_dealer.DeliverCash = false;
			_dealer.SendPlayerMessage("The dead drops are not safe atm... I will meet you to take the cash!");
			_dealer.SendMessage("Okay", notify: false, network: true, 2f);
		}
	}
	internal class DisableProductPickupMessage : MessageBase
	{
		private readonly DealerExtension _dealer;

		public override string Text => "Stop picking up products";

		public override bool DisableDefaultSendBehaviour => true;

		public DisableProductPickupMessage(DealerExtension dealerExtension)
		{
			_dealer = dealerExtension;
			base..ctor();
		}

		public override bool ShouldShowCheck(SendableMessage sMsg)
		{
			if (_dealer.Dealer.IsRecruited && _dealer.PickupProducts)
			{
				return true;
			}
			return false;
		}

		public override void OnSelected()
		{
			_dealer.PickupProducts = false;
			_dealer.SendPlayerMessage("We can't use the dead drops for some time. I will meet you to bring new products!");
			_dealer.SendMessage("Waiting for you", notify: false, network: true, 2f);
		}
	}
	public class EnableDeliverCashMessage : MessageBase
	{
		private readonly DealerExtension _dealer;

		public override string Text => "Please deliver cash";

		public override bool DisableDefaultSendBehaviour => true;

		public EnableDeliverCashMessage(DealerExtension dealerExtension)
		{
			_dealer = dealerExtension;
			base..ctor();
		}

		public override bool ShouldShowCheck(SendableMessage sMsg)
		{
			if (_dealer.Dealer.IsRecruited && !_dealer.DeliverCash)
			{
				return true;
			}
			return false;
		}

		public override void OnSelected()
		{
			UIBuilder.SliderPopup.Open("Cash Threshold (" + ((Object)_dealer.Dealer).name + ")", null, _dealer.CashThreshold, 100f, 10000f, 50f, 0, OnSend, null, "${0:0}");
		}

		private void OnSend(float value)
		{
			_dealer.DeliverCash = true;
			_dealer.CashThreshold = value;
			_dealer.SendPlayerMessage($"Yoo, could you deliver your cash to the dead drop? Deliver after collecting ${value}.");
			_dealer.SendMessage("Sure thing boss!", notify: false, network: true, 2f);
		}
	}
	public class EnableProductPickupMessage : MessageBase
	{
		private readonly DealerExtension _dealer;

		public override string Text => "Pickup products";

		public override bool DisableDefaultSendBehaviour => true;

		public EnableProductPickupMessage(DealerExtension dealerExtension)
		{
			_dealer = dealerExtension;
			base..ctor();
		}

		public override bool ShouldShowCheck(SendableMessage sMsg)
		{
			if (_dealer.Dealer.IsRecruited && !_dealer.PickupProducts)
			{
				return true;
			}
			return false;
		}

		public override void OnSelected()
		{
			UIBuilder.SliderPopup.Open("Product Threshold (" + ((Object)_dealer.Dealer).name + ")", null, _dealer.ProductThreshold, 0f, 1000f, 10f, 0, OnSend, null, "{0:0} pcs");
		}

		private void OnSend(float value)
		{
			_dealer.PickupProducts = true;
			_dealer.ProductThreshold = (int)value;
			_dealer.SendPlayerMessage($"I will deposit products at the dead drop. Come there if you got less than {value}pcs left.");
			_dealer.SendMessage("Ok. Will pick them up soon!", notify: false, network: true, 2f);
		}
	}
	public class FiredMessage : MessageBase
	{
		private readonly DealerExtension _dealer;

		public override string Text => "You are fired";

		public override bool DisableDefaultSendBehaviour => true;

		public FiredMessage(DealerExtension dealerExtension)
		{
			_dealer = dealerExtension;
			base..ctor();
		}

		public override bool ShouldShowCheck(SendableMessage sMsg)
		{
			if (_dealer.Dealer.IsRecruited)
			{
				return true;
			}
			return false;
		}

		public override void OnSelected()
		{
			PlayerSingleton<MessagesApp>.Instance.ConfirmationPopup.Open("Are you sure?", "Calling off the cooperation could make a dealer really mad.\n\nHe maybe will become hostile.\n(In future updates)", base.S1Conversation, (Action<EResponse>)OnConfirmationResponse);
		}

		private void OnConfirmationResponse(EResponse response)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			if ((int)response == 0)
			{
				_dealer.Fire();
				_dealer.SendPlayerMessage("I don't need your service anymore. You are out!");
				_dealer.SendMessage("Hmpf okay, get in touch if you need me", notify: false, network: true, 0.5f);
			}
		}
	}
	public abstract class MessageBase
	{
		protected NPC NPC;

		protected Conversation Conversation;

		public virtual string Text => "Text";

		protected MSGConversation S1Conversation => NPC.MSGConversation;

		public virtual bool DisableDefaultSendBehaviour => false;

		public virtual void SetReferences(NPC npc, Conversation conversation)
		{
			NPC = npc;
			Conversation = conversation;
		}

		public virtual bool ShouldShowCheck(SendableMessage sMsg)
		{
			return true;
		}

		public virtual void OnSelected()
		{
		}

		public virtual void OnSent()
		{
		}
	}
	public class NegotiateCutMessage : MessageBase
	{
		private readonly DealerExtension _dealer;

		public override string Text => "Let's talk about your cut";

		public override bool DisableDefaultSendBehaviour => true;

		public NegotiateCutMessage(DealerExtension dealerExtension)
		{
			_dealer = dealerExtension;
			base..ctor();
		}

		public override bool ShouldShowCheck(SendableMessage sMsg)
		{
			if (_dealer.Dealer.IsRecruited && _dealer.DaysUntilNextNegotiation <= 0)
			{
				return true;
			}
			return false;
		}

		public override void OnSelected()
		{
			float num = (float)Math.Round(_dealer.Cut, 2);
			UIBuilder.SliderPopup.Open("Negotiate Cut % (" + ((Object)_dealer.Dealer).name + ")", $"Current: {num:P0}", num, 0f, 1f, 0.01f, 2, OnSend, null, "{0:P0}");
		}

		private void OnSend(float value)
		{
			_dealer.SendPlayerMessage($"Joo! We need to talk about your cut.. How about {value:P0}?");
			if (value == _dealer.Cut)
			{
				_dealer.SendMessage("Bro that's the same amount i get atm!", notify: false, network: true, 2f);
				return;
			}
			if (value > _dealer.Cut)
			{
				_dealer.SendMessage("Haha.. you idiot! Yeah sure", notify: false, network: true, 2f);
			}
			else
			{
				if (!CalculateResponse(_dealer.Cut, value))
				{
					_dealer.SendMessage("Naah.. no chance!", notify: false, network: true, 2f);
					_dealer.DaysUntilNextNegotiation = 3;
					if (NetworkSynchronizer.IsSyncing)
					{
						NetworkSynchronizer.Instance.SendData(_dealer.FetchData());
					}
					return;
				}
				_dealer.SendMessage("Okay i'm fine with that. We got a deal!", notify: false, network: true, 2f);
			}
			_dealer.Cut = value;
			_dealer.DaysUntilNextNegotiation = 7;
			_dealer.HasChanged = true;
			if (NetworkSynchronizer.IsSyncing)
			{
				Net