Decompiled source of DealerDropBoxSuite v1.0.2

DealerDropBoxSuite/DealerDropBoxSuite.dll

Decompiled 6 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.Security;
using System.Security.Permissions;
using AdvancedDealing;
using AdvancedDealing.Economy;
using AdvancedDealing.Messaging;
using AdvancedDealing.Messaging.Messages;
using AdvancedDealing.NPCs;
using AdvancedDealing.NPCs.Actions;
using AdvancedDealing.Persistence;
using AdvancedDealing.Persistence.Datas;
using AdvancedDealing.Persistence.IO;
using AdvancedDealing.UI;
using AdvancedDealing.Utils;
using Bread_Storage_Tweaks;
using Bread_Storage_Tweaks.Preferences;
using Bread_Storage_Tweaks.Preferences.Classes;
using DealerDropBoxSuite.Compat;
using HarmonyLib;
using Il2CppFishNet.Object;
using Il2CppGameKit.Utilities;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne;
using Il2CppScheduleOne.Delivery;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.Dialogue;
using Il2CppScheduleOne.Economy;
using Il2CppScheduleOne.Employees;
using Il2CppScheduleOne.GameTime;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.Map;
using Il2CppScheduleOne.Messaging;
using Il2CppScheduleOne.Money;
using Il2CppScheduleOne.NPCs;
using Il2CppScheduleOne.Networking;
using Il2CppScheduleOne.Persistence;
using Il2CppScheduleOne.PlayerScripts;
using Il2CppScheduleOne.Product;
using Il2CppScheduleOne.Quests;
using Il2CppScheduleOne.Storage;
using Il2CppScheduleOne.UI;
using Il2CppScheduleOne.UI.Phone.Delivery;
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.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), "Dealer Drop Box Suite", "1.0.0", "brobb + ManZune + Bread", null)]
[assembly: MelonInfo(typeof(AdvancedDealingConfigMod), "AdvancedDealing", "1.0.0", "brobb + ManZune + Bread", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: AssemblyMetadata("NexusModID", "0")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("DealerDropBoxSuite")]
[assembly: AssemblyConfiguration("IL2CPP")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DealerDropBoxSuite")]
[assembly: AssemblyTitle("DealerDropBoxSuite")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 DealerDropBoxSuite.Compat
{
	internal static class LegacyDropBoxConfig
	{
		private static bool _initialized;

		private static bool _hasConfig;

		private static int _slotCount;

		public static bool TryGetSlotCount(out int slotCount)
		{
			EnsureLoaded();
			slotCount = _slotCount;
			return _hasConfig;
		}

		private static void EnsureLoaded()
		{
			if (!_initialized)
			{
				_initialized = true;
				string text = Path.Combine(MelonEnvironment.UserDataDirectory, "MoreDropBoxSlots.cfg");
				if (File.Exists(text))
				{
					MelonPreferences_Category val = MelonPreferences.CreateCategory("MoreDropBoxSlots");
					val.SetFilePath(text, false);
					MelonPreferences_Entry<int> val2 = val.CreateEntry<int>("SlotCount", 8, "Number of slots in dead drop boxes", (string)null, false, false, (ValueValidator)null, (string)null);
					MelonPreferences.Load();
					_slotCount = ClampSlots(val2.Value);
					_hasConfig = true;
				}
			}
		}

		private static int ClampSlots(int value)
		{
			int mAX_SLOTS = StorageEntity.MAX_SLOTS;
			if (value < 1)
			{
				return 1;
			}
			return (value > mAX_SLOTS) ? mAX_SLOTS : value;
		}
	}
}
namespace Bread_Storage_Tweaks
{
	internal static class DeadDropSlotApplier
	{
		public static void ApplyDeadDropSlots(int slotCount, int rowCount)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			if (DeadDrop.DeadDrops == null)
			{
				return;
			}
			int slotCount2 = ClampSlots(slotCount);
			int displayRowCount = Math.Max(1, rowCount);
			Enumerator<DeadDrop> enumerator = DeadDrop.DeadDrops.GetEnumerator();
			while (enumerator.MoveNext())
			{
				DeadDrop current = enumerator.Current;
				if (!((Object)current == (Object)null))
				{
					StorageEntity storage = (StorageEntity)(object)current.Storage;
					if (!((Object)storage == (Object)null))
					{
						storage.SlotCount = slotCount2;
						storage.DisplayRowCount = displayRowCount;
						StorageSlotHelper.EnsureSlotListSize(storage);
						storage.ContentsChanged();
					}
				}
			}
		}

		private static int ClampSlots(int value)
		{
			int mAX_SLOTS = StorageEntity.MAX_SLOTS;
			if (value < 1)
			{
				return 1;
			}
			return (value > mAX_SLOTS) ? mAX_SLOTS : value;
		}
	}
	public static class Main
	{
		private class StoragePatches
		{
			[HarmonyPatch(typeof(StorageEntity), "Awake")]
			[HarmonyPrefix]
			private static void StoragePatch(StorageEntity __instance)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: Expected O, but got Unknown
				if ((Object)__instance == (Object)null)
				{
					return;
				}
				string storageEntityName = __instance.StorageEntityName;
				if (!string.IsNullOrEmpty(storageEntityName))
				{
					StorageEntity val = __instance;
					StorageEntity val2 = val;
					if (1 == 0)
					{
					}
					int slotCount = storageEntityName switch
					{
						"Briefcase" => Extra.BriefcaseSlotAmount.Value, 
						"Coffee Table" => Extra.CoffeeTableSlotAmount.Value, 
						"Dead Drop" => Extra.DeadDropSlotAmount.Value, 
						"Delivery Bay" => Extra.DeliveryBaySlotAmount.Value, 
						"Display Cabinet" => Extra.DisplayCabinetSlotAmount.Value, 
						"Large Storage Rack" => StorageRacks.LargeRackSlotAmount.Value, 
						"Locker" => Extra.LockerSlotAmount.Value, 
						"Medium Storage Rack" => StorageRacks.MediumRackSlotAmount.Value, 
						"Safe" => Extra.SafeSlotAmount.Value, 
						"Shitbox Trunk" => Cars.ShitBoxSlotAmount.Value, 
						"Small Storage Rack" => StorageRacks.SmallRackSlotAmount.Value, 
						"Table" => Extra.TableSlotAmount.Value, 
						"Trunk" => Cars.GetSA(__instance), 
						"Wall-Mounted Shelf" => Extra.WallMountedShelfSlotAmount.Value, 
						_ => __instance.SlotCount, 
					};
					if (1 == 0)
					{
					}
					val2.SlotCount = slotCount;
					val = __instance;
					StorageEntity val3 = val;
					if (1 == 0)
					{
					}
					slotCount = storageEntityName switch
					{
						"Briefcase" => Extra.BriefcaseRowAmount.Value, 
						"Coffee Table" => Extra.CoffeeRowAmount.Value, 
						"Dead Drop" => Extra.DeadDropRowAmount.Value, 
						"Delivery Bay" => Extra.DeliveryBayRowAmount.Value, 
						"Display Cabinet" => Extra.DisplayCabinetRowAmount.Value, 
						"Large Storage Rack" => StorageRacks.LargeRackRowAmount.Value, 
						"Locker" => Extra.LockerRowAmount.Value, 
						"Medium Storage Rack" => StorageRacks.MediumRackRowAmount.Value, 
						"Safe" => Extra.SafeRowAmount.Value, 
						"Shitbox Trunk" => Cars.ShitBoxRowAmount.Value, 
						"Small Storage Rack" => StorageRacks.SmallRackRowAmount.Value, 
						"Table" => Extra.TableRowAmount.Value, 
						"Trunk" => Cars.GetRA(__instance), 
						"Wall-Mounted Shelf" => Extra.WallMountedShelfRowAmount.Value, 
						_ => __instance.DisplayRowCount, 
					};
					if (1 == 0)
					{
					}
					val3.DisplayRowCount = slotCount;
				}
			}

			[HarmonyPatch(typeof(StorageEntity), "Awake")]
			[HarmonyPostfix]
			private static void StorageSlotsPostfix(StorageEntity __instance)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: Expected O, but got Unknown
				if (!((Object)__instance == (Object)null))
				{
					StorageSlotHelper.EnsureSlotListSize(__instance);
				}
			}

			[HarmonyPatch(typeof(NPCInventory), "Awake")]
			[HarmonyPrefix]
			private static void NPCSlotPatch(NPCInventory __instance)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: Expected O, but got Unknown
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Expected O, but got Unknown
				//IL_004b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0056: Expected O, but got Unknown
				//IL_0078: Unknown result type (might be due to invalid IL or missing references)
				//IL_0083: Expected O, but got Unknown
				//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ad: Expected O, but got Unknown
				//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d9: Expected O, but got Unknown
				if (!((Object)__instance == (Object)null))
				{
					if ((Object)((Component)__instance).GetComponentInParent<Botanist>() != (Object)null)
					{
						__instance.SlotCount = Employees.BotanistSlotAmount.Value;
					}
					else if ((Object)((Component)__instance).GetComponentInParent<Chemist>() != (Object)null)
					{
						__instance.SlotCount = Employees.ChemistSlotAmount.Value;
					}
					else if ((Object)((Component)__instance).GetComponentInParent<Cleaner>() != (Object)null)
					{
						__instance.SlotCount = Employees.CleanerSlotAmount.Value;
					}
					else if ((Object)((Component)__instance).GetComponentInParent<Dealer>() != (Object)null)
					{
						__instance.SlotCount = Extra.DealerSlotAmount.Value;
					}
					else if ((Object)((Component)__instance).GetComponentInParent<Packager>() != (Object)null)
					{
						__instance.SlotCount = Employees.HandlerSlotAmount.Value;
					}
				}
			}

			[HarmonyPatch(typeof(StorageMenu), "Open", new Type[]
			{
				typeof(IItemSlotOwner),
				typeof(string),
				typeof(string)
			})]
			[HarmonyPrefix]
			private static bool NPCInvRowPatch(StorageMenu __instance, IItemSlotOwner owner, string title, string subtitle)
			{
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Expected O, but got Unknown
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_0041: Expected O, but got Unknown
				//IL_0068: Unknown result type (might be due to invalid IL or missing references)
				//IL_0073: Expected O, but got Unknown
				//IL_009c: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a7: Expected O, but got Unknown
				//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d8: Expected O, but got Unknown
				//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
				//IL_0109: Expected O, but got Unknown
				NPCInventory val = ((Il2CppObjectBase)owner).TryCast<NPCInventory>();
				if ((Object)val == (Object)null)
				{
					return true;
				}
				__instance.IsOpen = true;
				__instance.OpenedStorageEntity = null;
				if ((Object)((Component)val).GetComponentInParent<Botanist>() != (Object)null)
				{
					__instance.SlotGridLayout.constraintCount = Employees.BotanistRowAmount.Value;
				}
				else if ((Object)((Component)val).GetComponentInParent<Chemist>() != (Object)null)
				{
					__instance.SlotGridLayout.constraintCount = Employees.ChemistRowAmount.Value;
				}
				else if ((Object)((Component)val).GetComponentInParent<Cleaner>() != (Object)null)
				{
					__instance.SlotGridLayout.constraintCount = Employees.CleanerRowAmount.Value;
				}
				else if ((Object)((Component)val).GetComponentInParent<Dealer>() != (Object)null)
				{
					__instance.SlotGridLayout.constraintCount = Extra.DealerRowAmount.Value;
				}
				else if ((Object)((Component)val).GetComponentInParent<Packager>() != (Object)null)
				{
					__instance.SlotGridLayout.constraintCount = Employees.HandlerRowAmount.Value;
				}
				else
				{
					__instance.SlotGridLayout.constraintCount = __instance.SlotGridLayout.constraintCount;
				}
				__instance.Open(title, subtitle, owner);
				return false;
			}

			[HarmonyPatch(typeof(StorageMenu), "Awake")]
			[HarmonyPrefix]
			private static void StorageEntityPatch(StorageMenu __instance)
			{
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Expected O, but got Unknown
				//IL_011b: Unknown result type (might be due to invalid IL or missing references)
				if (Utils.MaxSlotAmount <= 20)
				{
					return;
				}
				Transform val = ((Component)__instance.Container).gameObject.transform.Find("Slots");
				if ((Object)val == (Object)null)
				{
					return;
				}
				List<ItemSlotUI> list = new List<ItemSlotUI>();
				if (__instance.SlotsUIs != null)
				{
					Il2CppArrayBase<ItemSlotUI> val2 = (Il2CppArrayBase<ItemSlotUI>)(object)__instance.SlotsUIs;
					for (int i = 0; i < val2.Length; i++)
					{
						list.Add(val2[i]);
					}
				}
				while (val.childCount < Utils.MaxSlotAmount)
				{
					try
					{
						GameObject val3 = Object.Instantiate<GameObject>(((Component)val.GetChild(0)).gameObject, val, true);
						((Object)val3).name = ((Object)val3).name.Replace("Clone", $"Extra-[{val.childCount - 1}]");
						val3.SetActive(true);
						val3.transform.localScale = Vector3.one;
						list.Add(val3.GetComponent<ItemSlotUI>() ?? val3.AddComponent<ItemSlotUI>());
					}
					catch (Exception ex)
					{
						MelonLogger.Error((object)ex);
					}
				}
				Il2CppReferenceArray<ItemSlotUI> val4 = new Il2CppReferenceArray<ItemSlotUI>((long)list.Count);
				for (int j = 0; j < list.Count; j++)
				{
					((Il2CppArrayBase<ItemSlotUI>)(object)val4)[j] = list[j];
				}
				__instance.SlotsUIs = val4;
			}

			[HarmonyPatch(typeof(DeliveryShop), "WillCartFitInVehicle")]
			[HarmonyPrefix]
			private static bool DeliveryVanPatch(DeliveryShop __instance, ref bool __result)
			{
				int num = 0;
				Enumerator<ListingEntry> enumerator = __instance.listingEntries.GetEnumerator();
				while (enumerator.MoveNext())
				{
					ListingEntry current = enumerator.Current;
					if (current.SelectedQuantity != 0)
					{
						int selectedQuantity = current.SelectedQuantity;
						int stackLimit = ((ItemDefinition)current.MatchingListing.Item).StackLimit;
						num += (selectedQuantity + stackLimit - 1) / stackLimit;
					}
				}
				__result = num <= Extra.DeliveryVehicleSlotAmount.Value;
				return false;
			}
		}

		public static void Initialize()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			PreferenceManager.Init();
			if (LegacyDropBoxConfig.TryGetSlotCount(out var slotCount))
			{
				Extra.DeadDropSlotAmount.Value = slotCount;
				Utils.MaxSlotAmount = Math.Max(Utils.MaxSlotAmount, slotCount);
			}
			new Harmony("Bread_Storage_Tweaks").PatchAll(typeof(StoragePatches));
		}
	}
	internal static class StorageSlotHelper
	{
		public static void EnsureSlotListSize(StorageEntity storage)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			if ((Object)storage == (Object)null)
			{
				return;
			}
			List<ItemSlot> itemSlots = storage.ItemSlots;
			if (itemSlots == null)
			{
				return;
			}
			int slotCount = storage.SlotCount;
			if (itemSlots.Count < slotCount)
			{
				for (int i = itemSlots.Count; i < slotCount; i++)
				{
					ItemSlot val = new ItemSlot();
					if ((Delegate)(object)val.onItemDataChanged == (Delegate)null)
					{
						val.onItemDataChanged = Action.op_Implicit((Action)storage.ContentsChanged);
					}
					else
					{
						((Delegate)val.onItemDataChanged).CombineImpl((Delegate)(object)Action.op_Implicit((Action)storage.ContentsChanged));
					}
					val.SetSlotOwner(((Il2CppObjectBase)storage).Cast<IItemSlotOwner>());
					itemSlots.Add(val);
				}
			}
			else
			{
				if (itemSlots.Count <= slotCount)
				{
					return;
				}
				bool flag = true;
				for (int j = slotCount; j < itemSlots.Count; j++)
				{
					ItemSlot val2 = itemSlots[j];
					if (val2 != null && val2.ItemInstance != null)
					{
						flag = false;
						break;
					}
				}
				if (flag)
				{
					itemSlots.RemoveRange(slotCount, itemSlots.Count - slotCount);
				}
				else
				{
					storage.SlotCount = itemSlots.Count;
				}
			}
		}
	}
	public static class Utils
	{
		public static readonly string PreferencePath = Path.Combine(MelonEnvironment.UserDataDirectory, "Bread_Storage_Tweaks");

		public static int MaxSlotAmount;
	}
}
namespace Bread_Storage_Tweaks.Preferences
{
	public static class PreferenceManager
	{
		public static void Init()
		{
			Directory.CreateDirectory(Utils.PreferencePath);
			Cars.Init();
			Employees.Init();
			Extra.Init();
			StorageRacks.Init();
		}
	}
}
namespace Bread_Storage_Tweaks.Preferences.Classes
{
	public static class Cars
	{
		private static MelonPreferences_Category? _carSlotAmountCategory;

		private static MelonPreferences_Entry<int>? _coupeSlotAmount;

		private static MelonPreferences_Entry<int>? _hotBoxSlotAmount;

		private static MelonPreferences_Entry<int>? _pickupSlotAmount;

		private static MelonPreferences_Entry<int>? _sedanSlotAmount;

		public static MelonPreferences_Entry<int>? ShitBoxSlotAmount;

		private static MelonPreferences_Entry<int>? _suvSlotAmount;

		private static MelonPreferences_Entry<int>? _vanSlotAmount;

		private static MelonPreferences_Category? _carRowAmountCategory;

		private static MelonPreferences_Entry<int>? _coupeRowAmount;

		private static MelonPreferences_Entry<int>? _hotBoxRowAmount;

		private static MelonPreferences_Entry<int>? _pickupRowAmount;

		private static MelonPreferences_Entry<int>? _sedanRowAmount;

		public static MelonPreferences_Entry<int>? ShitBoxRowAmount;

		private static MelonPreferences_Entry<int>? _suvRowAmount;

		private static MelonPreferences_Entry<int>? _vanRowAmount;

		public static void Init()
		{
			_carSlotAmountCategory = MelonPreferences.CreateCategory("Car Slots");
			_carSlotAmountCategory.SetFilePath(Path.Combine(Utils.PreferencePath, "Cars.cfg"));
			_coupeSlotAmount = _carSlotAmountCategory.CreateEntry<int>("Coupe Slot Amount", 4, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_hotBoxSlotAmount = _carSlotAmountCategory.CreateEntry<int>("Hotbox Slot Amount", 5, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_pickupSlotAmount = _carSlotAmountCategory.CreateEntry<int>("Pickup Slot Amount", 8, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_sedanSlotAmount = _carSlotAmountCategory.CreateEntry<int>("Sedan Slot Amount", 5, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			ShitBoxSlotAmount = _carSlotAmountCategory.CreateEntry<int>("Shitbox Slot Amount", 5, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_suvSlotAmount = _carSlotAmountCategory.CreateEntry<int>("SUV Slot Amount", 5, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_vanSlotAmount = _carSlotAmountCategory.CreateEntry<int>("Van Slot Amount", 16, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_carRowAmountCategory = MelonPreferences.CreateCategory("Car Rows");
			_carRowAmountCategory.SetFilePath(Path.Combine(Utils.PreferencePath, "Cars.cfg"));
			_coupeRowAmount = _carRowAmountCategory.CreateEntry<int>("Coupe Row Amount", 1, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_hotBoxRowAmount = _carRowAmountCategory.CreateEntry<int>("Hotbox Row Amount", 1, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_pickupRowAmount = _carRowAmountCategory.CreateEntry<int>("Pickup Row Amount", 2, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_sedanRowAmount = _carRowAmountCategory.CreateEntry<int>("Sedan Amount", 1, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			ShitBoxRowAmount = _carRowAmountCategory.CreateEntry<int>("Shitbox Row Amount", 1, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_suvRowAmount = _carRowAmountCategory.CreateEntry<int>("SUV Row Amount", 1, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_vanRowAmount = _carRowAmountCategory.CreateEntry<int>("Van Row Amount", 2, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			Utils.MaxSlotAmount = Math.Max(Utils.MaxSlotAmount, new List<MelonPreferences_Entry<int>>(7) { ShitBoxSlotAmount, _hotBoxSlotAmount, _coupeSlotAmount, _pickupSlotAmount, _sedanSlotAmount, _suvSlotAmount, _vanSlotAmount }.Max((MelonPreferences_Entry<int> x) => x.Value));
		}

		public static int GetSA(StorageEntity storageEntity)
		{
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Expected O, but got Unknown
			_ = ((Object)storageEntity).name;
			if (((Object)storageEntity).name.Contains("Shitbox"))
			{
				return ShitBoxSlotAmount.Value;
			}
			if (((Object)storageEntity).name.Contains("BoxSUV"))
			{
				return _hotBoxSlotAmount.Value;
			}
			if (((Object)storageEntity).name.Contains("SUV"))
			{
				return _suvSlotAmount.Value;
			}
			if (((Object)storageEntity).name.Contains("Sedan"))
			{
				return _sedanSlotAmount.Value;
			}
			if (((Object)storageEntity).name.Contains("Pickup"))
			{
				return _pickupSlotAmount.Value;
			}
			if (((Object)storageEntity).name.Contains("Coupe"))
			{
				return _coupeSlotAmount.Value;
			}
			if (((Object)storageEntity).name.Contains("Van"))
			{
				return _vanSlotAmount.Value;
			}
			if ((Object)((Component)storageEntity).GetComponentInParent<DeliveryVehicle>() != (Object)null)
			{
				return Extra.DeliveryVehicleSlotAmount.Value;
			}
			return storageEntity.SlotCount;
		}

		public static int GetRA(StorageEntity storageEntity)
		{
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Expected O, but got Unknown
			_ = ((Object)storageEntity).name;
			if (((Object)storageEntity).name.Contains("Shitbox"))
			{
				return ShitBoxRowAmount.Value;
			}
			if (((Object)storageEntity).name.Contains("BoxSUV"))
			{
				return _hotBoxRowAmount.Value;
			}
			if (((Object)storageEntity).name.Contains("SUV"))
			{
				return _suvRowAmount.Value;
			}
			if (((Object)storageEntity).name.Contains("Sedan"))
			{
				return _sedanRowAmount.Value;
			}
			if (((Object)storageEntity).name.Contains("Pickup"))
			{
				return _pickupRowAmount.Value;
			}
			if (((Object)storageEntity).name.Contains("Coupe"))
			{
				return _coupeRowAmount.Value;
			}
			if (((Object)storageEntity).name.Contains("Van"))
			{
				return _vanRowAmount.Value;
			}
			if ((Object)((Component)storageEntity).GetComponentInParent<DeliveryVehicle>() != (Object)null)
			{
				return Extra.DeliveryVehicleRowAmount.Value;
			}
			return storageEntity.DisplayRowCount;
		}
	}
	public static class Employees
	{
		private static MelonPreferences_Category? _employeesSlotAmountCategory;

		public static MelonPreferences_Entry<int>? BotanistSlotAmount;

		public static MelonPreferences_Entry<int>? ChemistSlotAmount;

		public static MelonPreferences_Entry<int>? CleanerSlotAmount;

		public static MelonPreferences_Entry<int>? HandlerSlotAmount;

		private static MelonPreferences_Category? _employeesRowAmountCategory;

		public static MelonPreferences_Entry<int>? BotanistRowAmount;

		public static MelonPreferences_Entry<int>? ChemistRowAmount;

		public static MelonPreferences_Entry<int>? CleanerRowAmount;

		public static MelonPreferences_Entry<int>? HandlerRowAmount;

		public static void Init()
		{
			_employeesSlotAmountCategory = MelonPreferences.CreateCategory("Employee Slots");
			_employeesSlotAmountCategory.SetFilePath(Path.Combine(Utils.PreferencePath, "Employees.cfg"));
			BotanistSlotAmount = _employeesSlotAmountCategory.CreateEntry<int>("Botanist Slot Amount", 5, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			ChemistSlotAmount = _employeesSlotAmountCategory.CreateEntry<int>("Chemist Slot Amount", 5, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			CleanerSlotAmount = _employeesSlotAmountCategory.CreateEntry<int>("Cleaner Slot Amount", 5, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			HandlerSlotAmount = _employeesSlotAmountCategory.CreateEntry<int>("Handler Slot Amount", 5, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_employeesRowAmountCategory = MelonPreferences.CreateCategory("Employee Rows");
			_employeesRowAmountCategory.SetFilePath(Path.Combine(Utils.PreferencePath, "Employees.cfg"));
			BotanistRowAmount = _employeesRowAmountCategory.CreateEntry<int>("Botanist Amount", 1, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			ChemistRowAmount = _employeesRowAmountCategory.CreateEntry<int>("Chemist Row Amount", 1, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			CleanerRowAmount = _employeesRowAmountCategory.CreateEntry<int>("Cleaner Row Amount", 1, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			HandlerRowAmount = _employeesRowAmountCategory.CreateEntry<int>("Handler Row Amount", 1, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			Utils.MaxSlotAmount = Math.Max(Utils.MaxSlotAmount, new List<MelonPreferences_Entry<int>>(4) { BotanistSlotAmount, ChemistSlotAmount, CleanerSlotAmount, HandlerSlotAmount }.Max((MelonPreferences_Entry<int> x) => x.Value));
		}
	}
	public static class Extra
	{
		private static MelonPreferences_Category? _extraSlotAmountCategory;

		public static MelonPreferences_Entry<int>? BriefcaseSlotAmount;

		public static MelonPreferences_Entry<int>? LockerSlotAmount;

		public static MelonPreferences_Entry<int>? CoffeeTableSlotAmount;

		public static MelonPreferences_Entry<int>? DeadDropSlotAmount;

		public static MelonPreferences_Entry<int>? DealerSlotAmount;

		public static MelonPreferences_Entry<int>? DeliveryBaySlotAmount;

		public static MelonPreferences_Entry<int>? DeliveryVehicleSlotAmount;

		public static MelonPreferences_Entry<int>? DisplayCabinetSlotAmount;

		public static MelonPreferences_Entry<int>? SafeSlotAmount;

		public static MelonPreferences_Entry<int>? TableSlotAmount;

		public static MelonPreferences_Entry<int>? WallMountedShelfSlotAmount;

		private static MelonPreferences_Category? _extraRowAmountCategory;

		public static MelonPreferences_Entry<int>? BriefcaseRowAmount;

		public static MelonPreferences_Entry<int>? LockerRowAmount;

		public static MelonPreferences_Entry<int>? CoffeeRowAmount;

		public static MelonPreferences_Entry<int>? DeadDropRowAmount;

		public static MelonPreferences_Entry<int>? DealerRowAmount;

		public static MelonPreferences_Entry<int>? DeliveryBayRowAmount;

		public static MelonPreferences_Entry<int>? DeliveryVehicleRowAmount;

		public static MelonPreferences_Entry<int>? DisplayCabinetRowAmount;

		public static MelonPreferences_Entry<int>? SafeRowAmount;

		public static MelonPreferences_Entry<int>? TableRowAmount;

		public static MelonPreferences_Entry<int>? WallMountedShelfRowAmount;

		public static void Init()
		{
			_extraSlotAmountCategory = MelonPreferences.CreateCategory("Extra Slots");
			_extraSlotAmountCategory.SetFilePath(Path.Combine(Utils.PreferencePath, "Extra.cfg"));
			BriefcaseSlotAmount = _extraSlotAmountCategory.CreateEntry<int>("Briefcase Slot Amount", 4, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			LockerSlotAmount = _extraSlotAmountCategory.CreateEntry<int>("Locker Slot Amount", 6, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			CoffeeTableSlotAmount = _extraSlotAmountCategory.CreateEntry<int>("Coffee Table Slot Amount", 3, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			DeadDropSlotAmount = _extraSlotAmountCategory.CreateEntry<int>("Dead Drop Slot Amount", 5, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			DealerSlotAmount = _extraSlotAmountCategory.CreateEntry<int>("Dealer Inventory Slot Amount", 5, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			DeliveryBaySlotAmount = _extraSlotAmountCategory.CreateEntry<int>("Delivery Bay Slot Amount", 5, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			DeliveryVehicleSlotAmount = _extraSlotAmountCategory.CreateEntry<int>("Delivery Vehicle Slot Amount", 16, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			DisplayCabinetSlotAmount = _extraSlotAmountCategory.CreateEntry<int>("Display Cabinet Slot Amount", 4, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			SafeSlotAmount = _extraSlotAmountCategory.CreateEntry<int>("Safe Slot Amount", 10, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			TableSlotAmount = _extraSlotAmountCategory.CreateEntry<int>("Table Slot Amount", 3, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			WallMountedShelfSlotAmount = _extraSlotAmountCategory.CreateEntry<int>("Wall-Mounted Shelf Slot Amount", 4, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_extraRowAmountCategory = MelonPreferences.CreateCategory("Extra Rows");
			_extraRowAmountCategory.SetFilePath(Path.Combine(Utils.PreferencePath, "Extra.cfg"));
			BriefcaseRowAmount = _extraRowAmountCategory.CreateEntry<int>("Briefcase Row Amount", 1, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			LockerRowAmount = _extraRowAmountCategory.CreateEntry<int>("Locker Row Amount", 1, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			CoffeeRowAmount = _extraRowAmountCategory.CreateEntry<int>("Coffee Table Row Amount", 1, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			DeadDropRowAmount = _extraRowAmountCategory.CreateEntry<int>("Dead Drop Row Amount", 1, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			DealerRowAmount = _extraRowAmountCategory.CreateEntry<int>("Dealer Inventory Row Amount", 1, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			DeliveryBayRowAmount = _extraRowAmountCategory.CreateEntry<int>("Delivery Bay Row Amount", 1, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			DeliveryVehicleRowAmount = _extraRowAmountCategory.CreateEntry<int>("Delivery Vehicle Row Amount", 2, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			DisplayCabinetRowAmount = _extraRowAmountCategory.CreateEntry<int>("Display Cabinet Row Amount", 1, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			SafeRowAmount = _extraRowAmountCategory.CreateEntry<int>("Safe Row Amount", 1, (string)null, (string)null, false, false, (ValueValidator)null, "Safe Slot Row Amount");
			TableRowAmount = _extraRowAmountCategory.CreateEntry<int>("Table Row Amount", 1, (string)null, (string)null, false, false, (ValueValidator)null, "Table Slot Row Amount");
			WallMountedShelfRowAmount = _extraRowAmountCategory.CreateEntry<int>("Wall-Mounted Shelf Row Amount", 1, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			Utils.MaxSlotAmount = Math.Max(Utils.MaxSlotAmount, new List<MelonPreferences_Entry<int>>(10) { BriefcaseSlotAmount, CoffeeTableSlotAmount, DeadDropSlotAmount, DealerSlotAmount, DeliveryBaySlotAmount, DeliveryVehicleSlotAmount, DisplayCabinetSlotAmount, SafeSlotAmount, TableSlotAmount, WallMountedShelfSlotAmount }.Max((MelonPreferences_Entry<int> x) => x.Value));
		}
	}
	public static class StorageRacks
	{
		private static MelonPreferences_Category? _storageRackSlotAmountCategory;

		public static MelonPreferences_Entry<int>? LargeRackSlotAmount;

		public static MelonPreferences_Entry<int>? MediumRackSlotAmount;

		public static MelonPreferences_Entry<int>? SmallRackSlotAmount;

		private static MelonPreferences_Category? _storageRackRowAmountCategory;

		public static MelonPreferences_Entry<int>? LargeRackRowAmount;

		public static MelonPreferences_Entry<int>? MediumRackRowAmount;

		public static MelonPreferences_Entry<int>? SmallRackRowAmount;

		public static void Init()
		{
			_storageRackSlotAmountCategory = MelonPreferences.CreateCategory("Storage Rack Slots");
			_storageRackSlotAmountCategory.SetFilePath(Path.Combine(Utils.PreferencePath, "Storage_Racks.cfg"));
			LargeRackSlotAmount = _storageRackSlotAmountCategory.CreateEntry<int>("Large Storage Rack Slot Amount", 8, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			MediumRackSlotAmount = _storageRackSlotAmountCategory.CreateEntry<int>("Medium Storage Rack Slot Amount", 6, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			SmallRackSlotAmount = _storageRackSlotAmountCategory.CreateEntry<int>("Small Storage Rack Slot Amount", 4, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_storageRackRowAmountCategory = MelonPreferences.CreateCategory("Storage Rack Rows");
			_storageRackRowAmountCategory.SetFilePath(Path.Combine(Utils.PreferencePath, "Storage_Racks.cfg"));
			LargeRackRowAmount = _storageRackRowAmountCategory.CreateEntry<int>("Large Storage Rack Row Amount", 2, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			MediumRackRowAmount = _storageRackRowAmountCategory.CreateEntry<int>("Medium Storage Rack Row Amount", 2, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			SmallRackRowAmount = _storageRackRowAmountCategory.CreateEntry<int>("Small Storage Rack Row Amount", 2, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			Utils.MaxSlotAmount = Math.Max(Utils.MaxSlotAmount, new List<MelonPreferences_Entry<int>>(3) { LargeRackSlotAmount, MediumRackSlotAmount, SmallRackSlotAmount }.Max((MelonPreferences_Entry<int> x) => x.Value));
		}
	}
}
namespace AdvancedDealing
{
	public class AdvancedDealing : MelonMod
	{
		private bool _storageTweaksInitialized;

		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();
					SaveModifier = new SaveModifier();
					NetworkSynchronizer = new NetworkSynchronizer();
					Logger.Msg("Dealer Drop Box Suite initialized");
					IsInitialized = true;
				}
				if (!_storageTweaksInitialized)
				{
					Main.Initialize();
					_storageTweaksInitialized = true;
				}
				if (SaveModifier.SavegameLoaded)
				{
					SaveModifier.ClearModifications();
				}
			}
			else if (sceneName == "Main")
			{
				SaveModifier.LoadModifications();
			}
		}
	}
	public class AdvancedDealingConfigMod : MelonMod
	{
	}
	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 LoyalityMode
		{
			get
			{
				if (NetworkSynchronizer.IsSyncing && NetworkSynchronizer.Instance.SessionData != null)
				{
					return NetworkSynchronizer.Instance.SessionData.LoyalityMode;
				}
				return generalCategory.GetEntry<bool>("LoyalityMode").Value;
			}
			set
			{
				generalCategory.GetEntry<bool>("LoyalityMode").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 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()
		{
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Expected O, but got Unknown
			generalCategory.CreateEntry<bool>("Debug", false, "Enable Debug Mode", "Enables debugging for this mod", false, false, (ValueValidator)null, (string)null);
			generalCategory.CreateEntry<bool>("LoyalityMode", false, "Loyality Mode (WIP)", "Makes the mod less feel like a cheat", 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>("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)new ValueRange<float>(0f, 1f), (string)null);
		}
	}
	public static class ModInfo
	{
		public const string Name = "AdvancedDealing";

		public const string Version = "1.1.0";

		public const string Author = "ManZune";

		public const string DownloadLink = "https://github.com/manzune/AdvancedDealing";
	}
}
namespace AdvancedDealing.Utils
{
	public static class CashDropQuestHelper
	{
		public static void EnsureCashDropQuest(string deadDropGuid)
		{
			if (!string.IsNullOrEmpty(deadDropGuid))
			{
				DeadDropExtension deadDrop = DeadDropExtension.GetDeadDrop(deadDropGuid);
				if (deadDrop == null)
				{
					Logger.Debug("CashDropQuestHelper", "Dead drop not found for quest: " + deadDropGuid);
				}
				else
				{
					EnsureCashDropQuest(deadDrop);
				}
			}
		}

		public static void EnsureCashDropQuest(DeadDropExtension deadDrop)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			if (deadDrop == null)
			{
				return;
			}
			string text = ((object)deadDrop.DeadDrop.GUID).ToString();
			DeaddropQuest val = FindQuestForDrop(text);
			if ((Object)val == (Object)null)
			{
				val = NetworkSingleton<QuestManager>.Instance.CreateDeaddropCollectionQuest(text, "");
			}
			if (!((Object)val == (Object)null))
			{
				((Quest)val).Description = "Collect cash at " + deadDrop.DeadDrop.DeadDropDescription;
				string entryTitle = "Cash delivery " + deadDrop.DeadDrop.DeadDropName;
				if (((Quest)val).Entries.Count > 0)
				{
					((Quest)val).Entries[0].SetEntryTitle(entryTitle);
				}
			}
		}

		private static DeaddropQuest FindQuestForDrop(string deadDropGuid)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrEmpty(deadDropGuid))
			{
				return null;
			}
			List<DeaddropQuest> deaddropQuests = DeaddropQuest.DeaddropQuests;
			for (int i = 0; i < deaddropQuests.Count; i++)
			{
				DeaddropQuest val = deaddropQuests[i];
				if (!((Object)val == (Object)null))
				{
					DeadDrop drop = val.Drop;
					if (!((Object)drop == (Object)null) && ((object)drop.GUID).ToString().Contains(deadDropGuid))
					{
						return val;
					}
				}
			}
			return null;
		}
	}
	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 CustomersScrollView
	{
		public const int MaxEntries = 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_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Expected O, but got Unknown
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Expected O, but got Unknown
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: 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)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)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
	{
		private enum DeadDropSelectMode
		{
			Cash,
			Pickup
		}

		public GameObject Container;

		public Text TitleLabel;

		public Transform Content;

		public GameObject CashButton;

		public Text CashButtonLabel;

		public GameObject PickupButton;

		public Text PickupButtonLabel;

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

		private DealerExtension _dealer;

		private GameObject _selectableTemplate;

		private DeadDropSelectMode _mode;

		public bool UICreated { get; private set; }

		public bool IsOpen { get; private set; }

		private void Open(DealerExtension dealerExtension, DeadDropSelectMode mode)
		{
			IsOpen = true;
			_dealer = dealerExtension;
			_mode = mode;
			TitleLabel.text = ((mode == DeadDropSelectMode.Cash) ? "Select Cash Dead Drop" : "Select Pickup Dead Drop");
			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)
		{
			if (_mode == DeadDropSelectMode.Cash)
			{
				_dealer.SetCashDeadDropGuid(guid);
				CashButtonLabel.text = name;
			}
			else
			{
				_dealer.SetPickupDeadDropGuid(guid);
				PickupButtonLabel.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_00a3: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Expected O, but got Unknown
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Expected O, but got Unknown
			//IL_01d4: 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)val2;
				Object.Destroy((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(((object)DeadDrop.DeadDrops[i].GUID).ToString(), DeadDrop.DeadDrops[i].DeadDropName);
				}
				CreateButtons();
				Logger.Debug("DeadDropSelector", "Dead drop selector UI created");
				UICreated = true;
			}
		}

		private void CreateButtons()
		{
			Transform transform = ((Component)PlayerSingleton<DealerManagementApp>.Instance).transform;
			Transform val = transform.Find("Container/Background/Content/Home");
			GameObject val2 = (((Object)(object)val != (Object)null) ? ((Component)val).gameObject : null);
			GameObject val3 = (((Object)(object)val != (Object)null) ? FindTileByTitle(val, "Cut") : null);
			if ((Object)(object)val3 == (Object)null)
			{
				val3 = FindTileByTitle(transform, "Cut");
			}
			if ((Object)(object)val2 == (Object)null)
			{
				Logger.Debug("DeadDropSelector", "Could not find home template for dead drop buttons");
				return;
			}
			CreateButton(val2, "Pickup", DeadDropSelectMode.Pickup, out PickupButton, out PickupButtonLabel);
			if ((Object)(object)val3 != (Object)null)
			{
				CashButton = val3;
				ConfigureButton(CashButton, "Cash Drop", DeadDropSelectMode.Cash, out CashButtonLabel, rename: false, adjustValueLayout: false);
			}
			else
			{
				CreateButton(val2, "Cash Drop", DeadDropSelectMode.Cash, out CashButton, out CashButtonLabel);
			}
			LayoutButtons(val2, val3);
		}

		private void LayoutButtons(GameObject pickupTemplate, GameObject cashTarget)
		{
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: 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_012a: Unknown result type (might be due to invalid IL or missing references)
			RectTransform component = pickupTemplate.GetComponent<RectTransform>();
			RectTransform component2 = PickupButton.GetComponent<RectTransform>();
			CopyRectTransform(component, component2);
			if ((Object)(object)CashButton != (Object)null && (Object)(object)cashTarget != (Object)null && (Object)(object)CashButton != (Object)(object)cashTarget)
			{
				RectTransform component3 = cashTarget.GetComponent<RectTransform>();
				RectTransform component4 = CashButton.GetComponent<RectTransform>();
				CopyRectTransform(component3, component4);
			}
			else if ((Object)(object)CashButton != (Object)null && (Object)(object)cashTarget == (Object)null && (Object)(object)CashButton != (Object)(object)PickupButton)
			{
				RectTransform component5 = CashButton.GetComponent<RectTransform>();
				Rect rect = component5.rect;
				float num = ((Rect)(ref rect)).height;
				if (num <= 0f)
				{
					num = component5.sizeDelta.y;
				}
				if (num <= 0f)
				{
					num = 60f;
				}
				float num2 = 8f;
				float num3 = num * 0.6f + num2;
				Vector2 anchoredPosition = component2.anchoredPosition;
				component5.anchoredPosition = anchoredPosition + new Vector2(0f, 0f - num3);
			}
		}

		private void CreateButton(GameObject template, string title, DeadDropSelectMode mode, out GameObject button, out Text label)
		{
			button = Object.Instantiate<GameObject>(template, template.transform.parent);
			ConfigureButton(button, title, mode, out label, rename: true, adjustValueLayout: false);
		}

		private void ConfigureButton(GameObject button, string title, DeadDropSelectMode mode, out Text label, bool rename, bool adjustValueLayout)
		{
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: 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)
			button.SetActive(true);
			if (rename)
			{
				((Object)button).name = "DeadDropSelectorButton_" + title.Replace(" ", string.Empty);
			}
			Transform val = button.transform.Find("Title");
			if ((Object)(object)val != (Object)null)
			{
				((Component)val).GetComponent<Text>().text = title;
			}
			label = null;
			Transform val2 = button.transform.Find("Value");
			if ((Object)(object)val2 != (Object)null)
			{
				RectTransform component = ((Component)val2).GetComponent<RectTransform>();
				if (adjustValueLayout)
				{
					component.offsetMax = new Vector2(component.offsetMax.x, 60f);
					component.offsetMin = new Vector2(component.offsetMin.x, 15f);
					component.sizeDelta = new Vector2(component.sizeDelta.x, 40f);
				}
				label = ((Component)val2).GetComponent<Text>();
				label.text = "None";
				((Graphic)label).color = new Color(0.6f, 1f, 1f, 1f);
			}
			Button val3 = button.GetComponent<Button>();
			if ((Object)(object)val3 == (Object)null)
			{
				val3 = button.AddComponent<Button>();
			}
			((UnityEventBase)val3.onClick).RemoveAllListeners();
			((UnityEvent)val3.onClick).AddListener(UnityAction.op_Implicit((Action)OpenSelector));
			void OpenSelector()
			{
				Open(DealerExtension.GetDealer(PlayerSingleton<DealerManagementApp>.Instance.SelectedDealer), mode);
			}
		}

		private GameObject FindTileByTitle(Transform root, string title)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			Text[] array = Il2CppArrayBase<Text>.op_Implicit(((Component)root).GetComponentsInChildren<Text>(true));
			foreach (Text val in array)
			{
				if ((Object)val == (Object)null)
				{
					continue;
				}
				string text = val.text;
				if (string.IsNullOrWhiteSpace(text))
				{
					continue;
				}
				string text2 = text.Trim();
				bool flag = string.Equals(text2, title, StringComparison.OrdinalIgnoreCase);
				if (!flag && title == "Cut")
				{
					flag = text2.StartsWith("Cut", StringComparison.OrdinalIgnoreCase);
				}
				else if (!flag && title == "Cash")
				{
					flag = text2.StartsWith("Cash", StringComparison.OrdinalIgnoreCase);
				}
				if (flag)
				{
					Transform parent = ((Component)val).transform.parent;
					if ((Object)(object)parent != (Object)null && (Object)(object)parent.Find("Title") != (Object)null && (Object)(object)parent.Find("Value") != (Object)null)
					{
						return ((Component)parent).gameObject;
					}
					if ((Object)(object)((parent != null) ? parent.parent : null) != (Object)null && (Object)(object)parent.parent.Find("Title") != (Object)null && (Object)(object)parent.parent.Find("Value") != (Object)null)
					{
						return ((Component)parent.parent).gameObject;
					}
				}
			}
			return null;
		}

		private void CopyRectTransform(RectTransform source, RectTransform target)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			target.anchorMin = source.anchorMin;
			target.anchorMax = source.anchorMax;
			target.pivot = source.pivot;
			target.anchoredPosition = source.anchoredPosition;
			target.sizeDelta = source.sizeDelta;
			target.offsetMin = source.offsetMin;
			target.offsetMax = source.offsetMax;
		}

		private void CreateSelectableTemplate()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			//IL_007a: 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)((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 LoyalityDisplay
	{
		public GameObject Container;

		public Text ValueLabel;

		public void BuildUI()
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: 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_0104: 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;
			Container = Object.Instantiate<GameObject>(gameObject, gameObject.transform.parent);
			Container.SetActive(true);
			((Object)Container).name = "Loyality";
			((Component)Container.transform.Find("Title")).GetComponent<Text>().text = "Loyality";
			RectTransform component = Container.GetComponent<RectTransform>();
			component.offsetMax = new Vector2(component.offsetMax.x, -550f);
			component.offsetMin = new Vector2(component.offsetMin.x, -650f);
			ValueLabel = ((Component)Container.transform.Find("Value")).GetComponent<Text>();
			ValueLabel.text = "None";
			((Graphic)ValueLabel).color = new Color(0.3f, 0.6f, 0.5f, 1f);
		}
	}
	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);
			}
			if (ModConfig.LoyalityMode)
			{
				GameObject val = _inputFields.Find((GameObject x) => ((Object)x).name == "SpeedMultiplier");
				if ((Object)(object)val != (Object)null)
				{
					val.SetActive(false);
				}
				GameObject val2 = _inputFields.Find((GameObject x) => ((Object)x).name == "MaxCustomers");
				if ((Object)(object)val2 != (Object)null)
				{
					val2.SetActive(false);
				}
			}
		}

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

		private void OnApply()
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: 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_008e: 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_00b8: Expected O, but got Unknown
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Expected O, but got Unknown
			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)((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)((Component)array[1]).gameObject);
				CreateInputField((ContentType)2, "MaxCustomers", "Max Customers", 0f, 24f);
				CreateInputField((ContentType)2, "ItemSlots", "Item Slots", 0f, 20f);
				CreateInputField((ContentType)3, "Cut", "Cut %", 0f, 1f);
				CreateInputField((ContentType)3, "SpeedMultiplier", "Speed Multiplier");
				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_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Expected O, but got Unknown
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: 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)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_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0391: Unknown result type (might be due to invalid IL or missing references)
			//IL_0440: Unknown result type (might be due to invalid IL or missing references)
			//IL_0457: Unknown result type (might be due to invalid IL or missing references)
			//IL_0481: Unknown result type (might be due to invalid IL or missing references)
			//IL_0498: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04be: Expected O, but got Unknown
			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)((Component)array[1]).gameObject);
				Logger.Debug("NegotiationPopup", "Negotiation popup UI created");
				UICreated = true;
			}
		}
	}
	public static class UIBuilder
	{
		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 LoyalityDisplay LoyalityDisplay { 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 (LoyalityDisplay == null)
				{
					LoyalityDisplay = new LoyalityDisplay();
				}
				MelonCoroutines.Start(CreateUI());
			}
			static IEnumerator CreateUI()
			{
				yield return (object)new WaitUntil(Func<bool>.op_Implicit((Func<bool>)(() => !Singleton<LoadManager>.Instance.IsLoading && Singleton<LoadManager>.Instance.IsGameLoaded)));
				SettingsPopup.BuildUI();
				SliderPopup.BuildUI();
				DeadDropSelector.BuildUI();
				CustomersScrollView.BuildUI();
				LoyalityDisplay.BuildUI();
				ChangeLoyalityModeUI();
				Logger.Msg("UI elements created");
				HasBuild = true;
			}
		}

		public static void ChangeLoyalityModeUI()
		{
			//IL_0099: 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_00c5: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			RectTransform component = CustomersScrollView.Viewport.GetComponent<RectTransform>();
			RectTransform customerTitle = CustomersScrollView.CustomerTitle;
			if (ModConfig.LoyalityMode)
			{
				LoyalityDisplay.Container.SetActive(true);
				component.offsetMax = new Vector2(0f, 490f);
				customerTitle.offsetMax = new Vector2(-50f, -662.3004f);
				customerTitle.offsetMin = new Vector2(65f, -712.3004f);
			}
			else
			{
				LoyalityDisplay.Container.SetActive(false);
				component.offsetMax = new Vector2(0f, 620f);
				customerTitle.offsetMax = new Vector2(-50f, -542.3004f);
				customerTitle.offsetMin = new Vector2(65f, -592.3004f);
			}
		}

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

		public List<DealerData> Dealers;
	}
	public class NetworkSynchronizer
	{
		private const string DealerDataType = "DealerData";

		private const string DataRequestMessage = "data_request";

		private const string DealerFiredMessage = "dealer_fired";

		private const string CashDropQuestMessage = "cash_drop_quest";

		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_0087: Unknown result type (might be due to invalid IL or missing references)
			if (IsSyncing)
			{
				if (!_isHost && dataType != "DealerData")
				{
					Logger.Debug("NetworkSynchronizer", "Ignoring data sync from client");
					return;
				}
				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);
						ApplySessionStorage(SessionData);
						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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: 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 = (EChatEntryType)0;
			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) || array.Length < 2)
			{
				return;
			}
			bool flag = IsSenderHost(val2);
			if (_isHost && array[1] != "data_request" && array[1] != "dealer_fired" && !IsDealerDataKey(array[1]))
			{
				Logger.Debug("NetworkSynchronizer", "Ignored non-host message from client");
				return;
			}
			if (!_isHost && !flag)
			{
				Logger.Debug("NetworkSynchronizer", "Ignored message from non-host client");
				return;
			}
			Logger.Debug("NetworkSynchronizer", "Received msg: " + array[1]);
			switch (array[1])
			{
			case "dealer_fired":
				DealerExtension.GetDealer(array[2])?.Fire();
				return;
			case "cash_drop_quest":
				if (!_isHost && array.Length > 2)
				{
					CashDropQuestHelper.EnsureCashDropQuest(array[2]);
				}
				return;
			case "data_request":
				if (!_isHost)
				{
					return;
				}
				SendData(SessionData);
				{
					foreach (DealerData item in DealerExtension.FetchAllDealerDatas())
					{
						SendData(item);
					}
					return;
				}
			}
			FetchData(val2, array[1]);
			if (_isHost && IsDealerDataKey(array[1], out var identifier))
			{
				DealerExtension dealer = DealerExtension.GetDealer(identifier, includeFired: true);
				if (dealer != null)
				{
					SendData(dealer.FetchData());
				}
			}
		}

		private bool IsDealerDataKey(string key)
		{
			string identifier;
			return IsDealerDataKey(key, out identifier);
		}

		private bool IsDealerDataKey(string key, out string identifier)
		{
			identifier = null;
			string[] array = key.Split("_");
			if (array.Length < 3)
			{
				return false;
			}
			if (array[0] != _prefix)
			{
				return false;
			}
			if (array[1] != "DealerData")
			{
				return false;
			}
			identifier = array[2];
			return true;
		}

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

		private bool IsSenderHost(CSteamID sender)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if (!_isSyncing)
			{
				return false;
			}
			CSteamID lobbyOwner = SteamMatchmaking.GetLobbyOwner(_lobbySteamID);
			return ((CSteamID)(ref sender)).Equals(lobbyOwner);
		}

		private void ApplySessionStorage(SessionData data)
		{
			if (data == null)
			{
				return;
			}
			int num = data.DeadDropSlotAmount;
			int num2 = data.DeadDropRowAmount;
			if (num <= 0 && Extra.DeadDropSlotAmount != null)
			{
				num = Extra.DeadDropSlotAmount.Value;
			}
			if (num2 <= 0 && Extra.DeadDropRowAmount != null)
			{
				num2 = Extra.DeadDropRowAmount.Value;
			}
			if (num > 0)
			{
				if (Extra.DeadDropSlotAmount != null)
				{
					Extra.DeadDropSlotAmount.Value = num;
				}
				if (Extra.DeadDropRowAmount != null)
				{
					Extra.DeadDropRowAmount.Value = num2;
				}
				Bread_Storage_Tweaks.Utils.MaxSlotAmount = Math.Max(Bread_Storage_Tweaks.Utils.MaxSlotAmount, num);
				DeadDropSlotApplier.ApplyDeadDropSlots(num, num2);
			}
		}
	}
	public class SaveModifier
	{
		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());
			}
			IEnumerator LoadRoutine()
			{
				if (!FileSerializer.LoadFromFile<DataWrapper>(FilePath, out var data))
				{
					SaveData = new DataWrapper
					{
						SaveName = $"SaveGame_{Singleton<LoadManager>.Instance.ActiveSaveInfo.SaveSlotNumber}",
						Dealers = new List<DealerData>()
					};
				}
				else
				{
					SaveData = data;
				}
				DeadDropExtension.Initialize();
				DealerExtension.Initialize();
				if (NetworkSynchronizer.IsSyncing)
				{
					NetworkSynchronizer.Instance.SetAsHost();
					NetworkSynchronizer.Instance.SessionData = new SessionData(((object)Singleton<Lobby>.Instance.LobbySteamID).ToString())
					{
						LoyalityMode = ModConfig.LoyalityMode,
						AccessInventory = ModConfig.AccessInventory,
						SettingsMenu = ModConfig.SettingsMenu,
						NegotiationModifier = ModConfig.NegotiationModifier,
						DeadDropSlotAmount = Extra.DeadDropSlotAmount.Value,
						DeadDropRowAmount = Extra.DeadDropRowAmount.Value
					};
				}
				yield return (object)new WaitForSecondsRealtime(2f);
				SavegameLoaded = true;
				if (NetworkSynchronizer.IsNoSyncOrHost)
				{
					DeadDropSlotApplier.ApplyDeadDropSlots(Extra.DeadDropSlotAmount.Value, Extra.DeadDropRowAmount.Value);
				}
				UIBuilder.Build();
				Logger.Msg("Savegame modifications successfully injected");
			}
		}

		private void LoadModificationsAsClient()
		{
			MelonCoroutines.Start(ClientLoadRoutine());
			IEnumerator ClientLoadRoutine()
			{
				SaveData = new DataWrapper
				{
					SaveName = "temporary",
					Dealers = new List<DealerData>()
				};
				DeadDropExtension.Initialize();
				DealerExtension.Initialize();
				yield return (object)new WaitForSecondsRealtime(2f);
				SavegameLoaded = true;
				NetworkSynchronizer.Instance.SendMessage("data_request");
				UIBuilder.Build();
				Logger.Msg("Savegame modifications successfully injected");
			}
		}

		public void ClearModifications()
		{
			UIBuilder.Reset();
			Schedule.ClearAllSchedules();
			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.IsNoSyncOrH