Decompiled source of Enhanced Workbench v2.0.1

plugins/EnhancedWorkbenches.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using EnhancedPrefabLoader;
using EnhancedWorkbenches.Models;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("EnhancedWorkbenches")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("2.0.1.0")]
[assembly: AssemblyInformationalVersion("2.0.1+87be79b7578d1481b460e37404ff22f7852a1f0c")]
[assembly: AssemblyProduct("Enhanced Workbenches")]
[assembly: AssemblyTitle("EnhancedWorkbenches")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
public sealed class ConfigurationManagerAttributes
{
	public delegate void CustomHotkeyDrawerFunc(ConfigEntryBase setting, ref bool isCurrentlyAcceptingInput);

	public bool? ShowRangeAsPercent;

	public Action<ConfigEntryBase> CustomDrawer;

	public CustomHotkeyDrawerFunc CustomHotkeyDrawer;

	public bool? Browsable;

	public string Category;

	public object DefaultValue;

	public bool? HideDefaultButton;

	public bool? HideSettingName;

	public string Description;

	public string DispName;

	public int? Order;

	public bool? ReadOnly;

	public bool? IsAdvanced;

	public Func<object, string> ObjToStr;

	public Func<string, object> StrToObj;
}
namespace EnhancedPrefabLoader
{
	public class ModConfigManager
	{
		private static ModConfigManager instance;

		private ConfigFile config;

		private readonly Dictionary<string, ConfigEntryBase> entries = new Dictionary<string, ConfigEntryBase>();

		public static ModConfigManager Instance => instance ?? (instance = new ModConfigManager());

		private ModConfigManager()
		{
		}

		public void Initialize(ConfigFile config)
		{
			this.config = config;
		}

		public ConfigEntry<T> BindSetting<T>(string category, string key, T value, string description = "", AcceptableValueBase acceptableValueBase = null, ConfigurationManagerAttributes configurationManagerAttributes = null)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			ConfigDescription val = new ConfigDescription(description, acceptableValueBase, new object[1] { configurationManagerAttributes });
			ConfigEntry<T> val2 = config.Bind<T>(category, key, value, val);
			string key2 = category + "." + key;
			entries[key2] = (ConfigEntryBase)(object)val2;
			return val2;
		}

		public T GetValue<T>(string category, string key)
		{
			string key2 = category + "." + key;
			if (!entries.TryGetValue(key2, out var value) || !(value is ConfigEntry<T> val))
			{
				return default(T);
			}
			return val.Value;
		}

		public void SetValue<T>(string category, string key, T value)
		{
			string key2 = category + "." + key;
			if (entries.TryGetValue(key2, out var value2) && value2 is ConfigEntry<T> val)
			{
				val.Value = value;
			}
		}

		public ConfigEntry<T> GetEntry<T>(string category, string key)
		{
			string key2 = category + "." + key;
			if (!entries.TryGetValue(key2, out var value) || !(value is ConfigEntry<T> result))
			{
				return null;
			}
			return result;
		}

		public void OnSettingChanged<T>(string category, string key, Action<T> callback)
		{
			ConfigEntry<T> entry = GetEntry<T>(category, key);
			if (entry != null)
			{
				entry.SettingChanged += delegate
				{
					callback(entry.Value);
				};
			}
		}
	}
}
namespace EnhancedWorkbenches
{
	public enum EBulkBoxGrade
	{
		WhiteBox,
		YellowBox,
		PinkBox,
		RedBox,
		GreenBox
	}
	public class EnhancedWorkbench : MonoBehaviour
	{
		private float emptyBoxCost;

		private Transform ejectBoxTransform;

		private Transform fillBoxTransform;

		private KeyboardShortcut buyBoxShortcut;

		public ShelfCompartment ShelfCompartment { get; private set; }

		public InteractablePackagingBox_Item CurrentFillBox { get; set; }

		public bool IsRaycasted { get; set; }

		public int WorkbenchNumber { get; set; }

		public EnhancedWorkbenchSaveData SaveData
		{
			get
			{
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				PackagingBoxSaveData packagingBox = ((CurrentFillBox == null) ? null : new PackagingBoxSaveData
				{
					ItemType = CurrentFillBox.m_ItemType,
					ItemCount = CurrentFillBox.m_ItemCompartment.GetItemCount()
				});
				return new EnhancedWorkbenchSaveData
				{
					PackagingBox = packagingBox,
					EmptyBoxCount = ShelfCompartment.GetItemCount()
				};
			}
		}

		private void Awake()
		{
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			InteractableWorkbench interactableWorkbench = ((Component)this).GetComponent<InteractableWorkbench>();
			ModConfigManager.Instance.BindSetting("Workbench", "Animation Speed Multiplier", 1f, "", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 10f));
			interactableWorkbench.m_JankBoxAnim.speed = ModConfigManager.Instance.GetValue<float>("Workbench", "Animation Speed Multiplier");
			foreach (Animation cardEnterBoxAnim in interactableWorkbench.m_CardEnterBoxAnimList)
			{
				foreach (AnimationState item in cardEnterBoxAnim)
				{
					item.speed = ModConfigManager.Instance.GetValue<float>("Workbench", "Animation Speed Multiplier");
				}
			}
			ModConfigManager.Instance.OnSettingChanged("Workbench", "Animation Speed Multiplier", delegate(float value)
			{
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				interactableWorkbench.m_JankBoxAnim.speed = value;
				foreach (Animation cardEnterBoxAnim2 in interactableWorkbench.m_CardEnterBoxAnimList)
				{
					foreach (AnimationState item2 in cardEnterBoxAnim2)
					{
						item2.speed = value;
					}
				}
			});
			ModConfigManager.Instance.BindSetting("Workbench", "Empty Box Cost", 50f, "", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, float.MaxValue));
			emptyBoxCost = ModConfigManager.Instance.GetValue<float>("Workbench", "Empty Box Cost");
			ModConfigManager.Instance.OnSettingChanged("Workbench", "Empty Box Cost", delegate(float value)
			{
				emptyBoxCost = value;
			});
			ModConfigManager.Instance.BindSetting<KeyboardShortcut>("Workbench", "Buy Empty Box", new KeyboardShortcut((KeyCode)98, Array.Empty<KeyCode>()));
			buyBoxShortcut = ModConfigManager.Instance.GetValue<KeyboardShortcut>("Workbench", "Buy Empty Box");
			ModConfigManager.Instance.OnSettingChanged("Workbench", "Buy Empty Box", delegate(KeyboardShortcut value)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				buyBoxShortcut = value;
			});
			ModConfigManager.Instance.BindSetting<Vector3>("Workbench", "Empties Storage Location", new Vector3(1.25f, 0.13f, -0.5f));
			ModConfigManager.Instance.OnSettingChanged("Workbench", "Empties Storage Location", delegate(Vector3 value)
			{
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				ShelfCompartment shelfCompartment = ShelfCompartment;
				if (shelfCompartment != null)
				{
					((Component)shelfCompartment).transform.localPosition = value;
				}
			});
			CreateEmptyBoxStorage();
			ejectBoxTransform = new GameObject().transform;
			ejectBoxTransform.SetParent(((Component)this).gameObject.transform);
			ejectBoxTransform.localPosition = new Vector3(-0.6f, 0.9f, 0.15f);
			((Object)ejectBoxTransform).name = "EjectBoxesTransform";
			fillBoxTransform = new GameObject().transform;
			fillBoxTransform.SetParent(((Component)this).gameObject.transform);
			fillBoxTransform.localPosition = new Vector3(-0.35f, 0.91f, -0.25f);
			((Object)fillBoxTransform).name = "FillBoxTransform";
		}

		private void Update()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			if (!IsRaycasted)
			{
				return;
			}
			if (UnityInput.Current.GetMouseButtonDown(0))
			{
				InteractablePackagingBox_Item currentHoldingItemBox = CSingleton<InteractionPlayerController>.Instance.m_CurrentHoldingItemBox;
				if (currentHoldingItemBox != null)
				{
					AttemptStoreBox(currentHoldingItemBox);
				}
			}
			if (Input.GetKeyDown(((KeyboardShortcut)(ref buyBoxShortcut)).MainKey) && ShelfCompartment.HasEnoughSlot() && CPlayerData.m_CoinAmountDouble >= (double)emptyBoxCost)
			{
				CreateNewBoxInShelf();
				CEventManager.QueueEvent((CEvent)new CEventPlayer_ReduceCoin(emptyBoxCost, false));
				SoundManager.PlayAudio("SFX_CustomerBuy", 0.6f, 1f);
			}
		}

		public void InitFromSaveData(EnhancedWorkbenchSaveData saveData)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			if (saveData.PackagingBox != null && fillBoxTransform != null)
			{
				InteractablePackagingBox_Item val = RestockManager.SpawnPackageBoxItem(saveData.PackagingBox.ItemType, saveData.PackagingBox.ItemCount, true);
				RestockManager.RemoveItemPackageBox(val);
				((Component)val).transform.SetParent(fillBoxTransform.parent);
				((Component)val).transform.localPosition = fillBoxTransform.localPosition;
				((Component)val).transform.localRotation = fillBoxTransform.localRotation;
				((InteractablePackagingBox)val).SetPhysicsEnabled(false);
				val.SetOpenCloseBox(true, false);
				((InteractablePackagingBox)val).m_Collider.enabled = true;
				((InteractablePackagingBox)val).m_Collider.isTrigger = true;
				CurrentFillBox = val;
			}
			if (ShelfCompartment != null)
			{
				for (int i = 0; i < saveData.EmptyBoxCount; i++)
				{
					CreateNewBoxInShelf();
				}
			}
		}

		public int GetOpenSpaceCount()
		{
			InteractableWorkbench component = ((Component)this).GetComponent<InteractableWorkbench>();
			int num = ShelfCompartment.GetItemCount() * 8;
			num += component.m_PosList.Count - component.m_ItemAmount;
			if (CurrentFillBox != null)
			{
				num += 8 - CurrentFillBox.m_ItemCount;
			}
			return num;
		}

		public void TryPrepareNextEmpty(InteractablePackagingBox_Item box = null)
		{
			if (CurrentFillBox == null && ShelfCompartment.GetItemCount() > 0)
			{
				if (box == null)
				{
					box = ShelfCompartment.GetLastInteractablePackagingBox();
				}
				ShelfCompartment.RemoveBox(box);
				((InteractableObject)box).LerpToTransform(fillBoxTransform, fillBoxTransform.parent, 3f);
				box.SetOpenCloseBox(true, true);
				CurrentFillBox = box;
			}
		}

		public bool OnTaskComplete()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			InteractableWorkbench component = ((Component)this).GetComponent<InteractableWorkbench>();
			((Component)component.m_JankBoxAnim).gameObject.SetActive(false);
			ItemMeshData itemMeshData = InventoryBase.GetItemMeshData(component.m_CurrentItemTypeSpawn);
			Item item = ItemSpawnManager.GetItem(component.m_SpawnItemPos);
			item.SetMesh(itemMeshData.mesh, itemMeshData.material, component.m_CurrentItemTypeSpawn, itemMeshData.meshSecondary, itemMeshData.materialSecondary, itemMeshData.materialList);
			((Component)item).transform.position = component.m_SpawnItemPos.position;
			((Component)item).transform.rotation = component.m_SpawnItemPos.rotation;
			((Component)item).gameObject.SetActive(true);
			foreach (InteractableCard3d interactableCard3d in component.m_InteractableCard3dList)
			{
				interactableCard3d.m_Card3dUI.SetVisibility(false);
			}
			if (CurrentFillBox != null)
			{
				EItemType val = CurrentFillBox.m_ItemCompartment.CheckItemType(item.GetItemType());
				if (CurrentFillBox.GetItemType() != val && CurrentFillBox.m_ItemCount <= 0)
				{
					CurrentFillBox.SetItemType(val);
				}
				if (CurrentFillBox.m_ItemCompartment.HasEnoughSlot() && val == item.GetItemType())
				{
					item.LerpToTransform(CurrentFillBox.m_ItemCompartment.GetLastEmptySlotTransform(), CurrentFillBox.m_ItemCompartment.GetEmptySlotParent(), false);
					CurrentFillBox.m_ItemCompartment.AddItem(item, true);
					CurrentFillBox.m_ItemCompartment.SetPriceTagVisibility(false);
					if (!CurrentFillBox.m_ItemCompartment.HasEnoughSlot())
					{
						CSingleton<RestockManager>.Instance.m_ItemPackagingBoxList.Add(CurrentFillBox);
						CurrentFillBox.SetOpenCloseBox(false, true);
						((InteractableObject)CurrentFillBox).LerpToTransform(ejectBoxTransform, ((InteractableObject)CurrentFillBox).m_OriginalParent, 3f);
						((InteractablePackagingBox)CurrentFillBox).SetPhysicsEnabled(true);
						((Collider)((InteractableObject)CurrentFillBox).m_BoxCollider).isTrigger = false;
						CurrentFillBox = null;
						TryPrepareNextEmpty();
					}
					return false;
				}
			}
			if (component.HasEnoughSlot())
			{
				component.AddItem(item, true);
				return false;
			}
			CSingleton<InteractionPlayerController>.Instance.AddHoldItemToFront(item);
			return true;
		}

		private void AttemptStoreBox(InteractablePackagingBox_Item currentBox)
		{
			if (!((InteractableObject)currentBox).m_IsLerpingToPos && currentBox.m_IsBigBox && currentBox.m_ItemCompartment.GetItemCount() == 0 && ShelfCompartment.HasEnoughSlot())
			{
				if (((InteractablePackagingBox)currentBox).IsBoxOpened())
				{
					currentBox.SetOpenCloseBox(false, true);
				}
				((InteractableObject)currentBox).LerpToTransform(ShelfCompartment.GetEmptySlotTransform(), ShelfCompartment.GetEmptySlotParent(), 3f);
				ShelfCompartment.AddBox(currentBox);
				((Component)((InteractableObject)currentBox).m_MoveStateValidArea).gameObject.SetActive(false);
				((InteractableObject)currentBox).m_IsBeingHold = false;
				((InteractablePackagingBox)currentBox).SetPhysicsEnabled(false);
				CSingleton<InteractionPlayerController>.Instance.OnExitHoldBoxMode();
				RestockManager.RemoveItemPackageBox(currentBox);
				SoundManager.GenericPop(1f, 1f);
			}
		}

		private void CreateNewBoxInShelf()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			InteractablePackagingBox_Item val = RestockManager.SpawnPackageBoxItem((EItemType)(-1), 0, true);
			RestockManager.RemoveItemPackageBox(val);
			Transform emptySlotTransform = ShelfCompartment.GetEmptySlotTransform();
			((InteractablePackagingBox)val).SetPhysicsEnabled(false);
			((Component)val).transform.SetParent(emptySlotTransform.parent);
			((Component)val).transform.localPosition = emptySlotTransform.localPosition;
			((Component)val).transform.localRotation = emptySlotTransform.localRotation;
			ShelfCompartment.AddBox(val);
		}

		private void CreateEmptyBoxStorage()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: 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_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(((Object)((Component)this).GetComponent<InteractableWorkbench>()).name + "-empties");
			val.SetActive(false);
			ShelfCompartment = val.AddComponent<ShelfCompartment>();
			((Component)ShelfCompartment).transform.SetParent(((Component)this).transform);
			((Component)ShelfCompartment).transform.localPosition = ModConfigManager.Instance.GetValue<Vector3>("Workbench", "Empties Storage Location");
			((Component)ShelfCompartment).transform.localRotation = Quaternion.identity;
			ShelfCompartment.SetCompartmentBoxType(true);
			ShelfCompartment.m_StartLoc = new GameObject().GetComponent<Transform>();
			ShelfCompartment.m_StartLoc.SetParent(((Component)ShelfCompartment).transform);
			ShelfCompartment.m_StartLoc.localPosition = new Vector3(0f, -0.1f, -0.25f);
			((Object)ShelfCompartment.m_StartLoc).name = "StartLoc";
			ShelfCompartment.m_EndWidthLoc = new GameObject().GetComponent<Transform>();
			ShelfCompartment.m_EndWidthLoc.SetParent(((Component)ShelfCompartment).transform);
			ShelfCompartment.m_EndWidthLoc.localPosition = new Vector3(0.75f, -0.1f, -0.25f);
			((Object)ShelfCompartment.m_EndWidthLoc).name = "EndWidthLoc";
			ShelfCompartment.m_EndDepthLoc = new GameObject().GetComponent<Transform>();
			ShelfCompartment.m_EndDepthLoc.SetParent(((Component)ShelfCompartment).transform);
			ShelfCompartment.m_EndDepthLoc.localPosition = new Vector3(0f, -0.1f, 0.5f);
			((Object)ShelfCompartment.m_EndDepthLoc).name = "EndDepthLoc";
			ShelfCompartment.m_EndHeightLoc = new GameObject().GetComponent<Transform>();
			ShelfCompartment.m_EndHeightLoc.SetParent(((Component)ShelfCompartment).transform);
			ShelfCompartment.m_EndHeightLoc.localPosition = new Vector3(0f, 1.68f, -0.25f);
			((Object)ShelfCompartment.m_EndHeightLoc).name = "EndHeightLoc";
			ShelfCompartment.m_PosListGrp = new GameObject().GetComponent<Transform>();
			ShelfCompartment.m_PosListGrp.SetParent(((Component)ShelfCompartment).transform);
			ShelfCompartment.m_PosListGrp.localPosition = Vector3.zero;
			((Object)ShelfCompartment.m_PosListGrp).name = "PosListGrp";
			ShelfCompartment.m_StoredItemListGrp = new GameObject().GetComponent<Transform>();
			ShelfCompartment.m_StoredItemListGrp.SetParent(((Component)ShelfCompartment).transform);
			ShelfCompartment.m_StoredItemListGrp.localPosition = Vector3.zero;
			((Object)ShelfCompartment.m_StoredItemListGrp).name = "StoredItemListGrp";
			for (int i = 0; i < 12; i++)
			{
				Transform component = new GameObject().GetComponent<Transform>();
				component.SetParent(ShelfCompartment.m_PosListGrp);
				((Component)component).gameObject.SetActive(false);
				((Object)component).name = $"postListGrpItem_{i}";
			}
			ShelfCompartment.m_CanPutItem = false;
			ShelfCompartment.m_CanPutBox = true;
			ShelfCompartment.m_ItemNotForSale = true;
			ShelfCompartment.m_SizeX = 4;
			ShelfCompartment.m_SizeY = 8;
			ShelfCompartment.m_SizeZ = 12;
			ShelfCompartment.m_HeightGoesUp = true;
			val.SetActive(true);
			ShelfCompartment.CalculatePositionList();
		}
	}
	public class EnhancedWorkbenchUI : MonoBehaviour
	{
		private EnhancedWorkbench currentWorkbench;

		private WorkbenchUIScreen workbenchUIScreen;

		private Slider maxBoxCreateSlider;

		private Transform boxCountSliderGrp;

		private TextMeshProUGUI boxCountSliderCurrentText;

		private TextMeshProUGUI boxCountSliderMaxText;

		private ControllerButton startBundleButton;

		private ControllerButton whiteBoxButton;

		private ControllerButton yellowBoxButton;

		private ControllerButton pinkBoxButton;

		private ControllerButton redBoxButton;

		private ControllerButton greenBoxButton;

		public EnhancedWorkbench CurrentWorkbench
		{
			get
			{
				return currentWorkbench;
			}
			set
			{
				currentWorkbench = value;
				if (currentWorkbench != null)
				{
					CalculateMaxBoxCount();
				}
			}
		}

		private void Awake()
		{
			workbenchUIScreen = ((Component)this).GetComponent<WorkbenchUIScreen>();
			RegisterConfigs();
			Initialize();
		}

		private void RegisterConfigs()
		{
			//IL_001e: 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)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_033e: Unknown result type (might be due to invalid IL or missing references)
			//IL_038e: Unknown result type (might be due to invalid IL or missing references)
			ModConfigManager.Instance.BindSetting<Vector3>("UI", "White Box Button Position", new Vector3(550f, 90f, 0f));
			ModConfigManager.Instance.OnSettingChanged("UI", "White Box Button Position", delegate(Vector3 value)
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				ControllerButton obj12 = whiteBoxButton;
				if (obj12 != null)
				{
					((Component)obj12).transform.localPosition = value;
				}
			});
			ModConfigManager.Instance.BindSetting<Vector3>("UI", "White Box Button Scale", new Vector3(0.25f, 0.25f, 0.25f));
			ModConfigManager.Instance.OnSettingChanged("UI", "White Box Button Scale", delegate(Vector3 value)
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				ControllerButton obj11 = whiteBoxButton;
				if (obj11 != null)
				{
					((Component)obj11).transform.localScale = value;
				}
			});
			ModConfigManager.Instance.BindSetting<Vector3>("UI", "Yellow Box Button Position", new Vector3(700f, 90f, 0f));
			ModConfigManager.Instance.OnSettingChanged("UI", "Yellow Box Button Position", delegate(Vector3 value)
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				ControllerButton obj10 = yellowBoxButton;
				if (obj10 != null)
				{
					((Component)obj10).transform.localPosition = value;
				}
			});
			ModConfigManager.Instance.BindSetting<Vector3>("UI", "Yellow Box Button Scale", new Vector3(0.25f, 0.25f, 0.25f));
			ModConfigManager.Instance.OnSettingChanged("UI", "Yellow Box Button Scale", delegate(Vector3 value)
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				ControllerButton obj9 = yellowBoxButton;
				if (obj9 != null)
				{
					((Component)obj9).transform.localScale = value;
				}
			});
			ModConfigManager.Instance.BindSetting<Vector3>("UI", "Pink Box Button Position", new Vector3(400f, 30f, 0f));
			ModConfigManager.Instance.OnSettingChanged("UI", "Pink Box Button Position", delegate(Vector3 value)
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				ControllerButton obj8 = pinkBoxButton;
				if (obj8 != null)
				{
					((Component)obj8).transform.localPosition = value;
				}
			});
			ModConfigManager.Instance.BindSetting<Vector3>("UI", "Pink Box Button Scale", new Vector3(0.25f, 0.25f, 0.25f));
			ModConfigManager.Instance.OnSettingChanged("UI", "Pink Box Button Scale", delegate(Vector3 value)
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				ControllerButton obj7 = pinkBoxButton;
				if (obj7 != null)
				{
					((Component)obj7).transform.localScale = value;
				}
			});
			ModConfigManager.Instance.BindSetting<Vector3>("UI", "Red Box Button Position", new Vector3(550f, 30f, 0f));
			ModConfigManager.Instance.OnSettingChanged("UI", "Red Box Button Position", delegate(Vector3 value)
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				ControllerButton obj6 = redBoxButton;
				if (obj6 != null)
				{
					((Component)obj6).transform.localPosition = value;
				}
			});
			ModConfigManager.Instance.BindSetting<Vector3>("UI", "Red Box Button Scale", new Vector3(0.25f, 0.25f, 0.25f));
			ModConfigManager.Instance.OnSettingChanged("UI", "Red Box Button Scale", delegate(Vector3 value)
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				ControllerButton obj5 = redBoxButton;
				if (obj5 != null)
				{
					((Component)obj5).transform.localScale = value;
				}
			});
			ModConfigManager.Instance.BindSetting<Vector3>("UI", "Green Box Button Position", new Vector3(700f, 30f, 0f));
			ModConfigManager.Instance.OnSettingChanged("UI", "Green Box Button Position", delegate(Vector3 value)
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				ControllerButton obj4 = greenBoxButton;
				if (obj4 != null)
				{
					((Component)obj4).transform.localPosition = value;
				}
			});
			ModConfigManager.Instance.BindSetting<Vector3>("UI", "Green Box Button Scale", new Vector3(0.25f, 0.25f, 0.25f));
			ModConfigManager.Instance.OnSettingChanged("UI", "Green Box Button Scale", delegate(Vector3 value)
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				ControllerButton obj3 = greenBoxButton;
				if (obj3 != null)
				{
					((Component)obj3).transform.localScale = value;
				}
			});
			ModConfigManager.Instance.BindSetting<Vector3>("UI", "Box Count Slider Position", new Vector3(500f, -65f, 0f));
			ModConfigManager.Instance.OnSettingChanged("UI", "Box Count Slider Position", delegate(Vector3 value)
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				Slider obj2 = maxBoxCreateSlider;
				if (obj2 != null)
				{
					((Component)obj2).transform.localPosition = value;
				}
			});
			ModConfigManager.Instance.BindSetting<Vector3>("UI", "Box Count Slider Scale", new Vector3(0.75f, 0.75f, 0.75f));
			ModConfigManager.Instance.OnSettingChanged("UI", "Box Count Slider Scale", delegate(Vector3 value)
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				Slider obj = maxBoxCreateSlider;
				if (obj != null)
				{
					((Component)obj).transform.localScale = value;
				}
			});
			ModConfigManager.Instance.BindSetting("UI", "White Box Min", 0.01f);
			ModConfigManager.Instance.BindSetting("UI", "White Box Max", 1f);
			ModConfigManager.Instance.BindSetting("UI", "Yellow Box Min", 1f);
			ModConfigManager.Instance.BindSetting("UI", "Yellow Box Max", 2f);
			ModConfigManager.Instance.BindSetting("UI", "Pink Box Min", 2f);
			ModConfigManager.Instance.BindSetting("UI", "Pink Box Max", 4f);
			ModConfigManager.Instance.BindSetting("UI", "Red Box Min", 4f);
			ModConfigManager.Instance.BindSetting("UI", "Red Box Max", 12f);
			ModConfigManager.Instance.BindSetting("UI", "Green Box Min", 12f);
			ModConfigManager.Instance.BindSetting("UI", "Green Box Max", 20f);
		}

		private void Initialize()
		{
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Expected O, but got Unknown
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Expected O, but got Unknown
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Expected O, but got Unknown
			//IL_036d: 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_03a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b3: Expected O, but got Unknown
			//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0407: Unknown result type (might be due to invalid IL or missing references)
			//IL_041f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0429: Expected O, but got Unknown
			//IL_0459: Unknown result type (might be due to invalid IL or missing references)
			//IL_047d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0490: Unknown result type (might be due to invalid IL or missing references)
			//IL_04df: Unknown result type (might be due to invalid IL or missing references)
			Transform val = workbenchUIScreen.m_ScreenGrp.transform.Find("AnimGrp");
			startBundleButton = ((Component)val.Find("StartBundleCardBtn")).GetComponent<ControllerButton>();
			boxCountSliderGrp = Object.Instantiate<GameObject>(((Component)((TMP_Text)workbenchUIScreen.m_MinimumCardText).transform.parent).gameObject).transform;
			((Object)((Component)boxCountSliderGrp).gameObject).name = "boxCountSlider";
			ControllerScreenUIExtension component = ((Component)this).GetComponent<ControllerScreenUIExtension>();
			maxBoxCreateSlider = ((Component)boxCountSliderGrp.Find("Slider")).GetComponent<Slider>();
			int persistentEventCount = ((UnityEventBase)maxBoxCreateSlider.onValueChanged).GetPersistentEventCount();
			for (int i = 0; i < persistentEventCount; i++)
			{
				((UnityEventBase)maxBoxCreateSlider.onValueChanged).SetPersistentListenerState(i, (UnityEventCallState)0);
			}
			((UnityEventBase)maxBoxCreateSlider.onValueChanged).RemoveAllListeners();
			maxBoxCreateSlider.minValue = 1f;
			maxBoxCreateSlider.value = 1f;
			maxBoxCreateSlider.wholeNumbers = true;
			((UnityEvent<float>)(object)maxBoxCreateSlider.onValueChanged).AddListener((UnityAction<float>)OnSliderValueChanged);
			component.m_ControllerBtnColumnList.Insert(0, new ControllerBtnList
			{
				rowList = new List<ControllerButton>(1) { ((Component)maxBoxCreateSlider).GetComponent<ControllerButton>() }
			});
			((TMP_Text)((Component)((Component)boxCountSliderGrp).transform.Find("MinText")).GetComponent<TextMeshProUGUI>()).text = "1";
			((TMP_Text)((Component)((Component)boxCountSliderGrp).transform.Find("TitleText")).GetComponent<TextMeshProUGUI>()).text = "Number of Boxes";
			boxCountSliderCurrentText = ((Component)((Component)boxCountSliderGrp).transform.Find("CurrentText")).GetComponent<TextMeshProUGUI>();
			((TMP_Text)boxCountSliderCurrentText).text = "1";
			boxCountSliderMaxText = ((Component)((Component)boxCountSliderGrp).transform.Find("MaxText")).GetComponent<TextMeshProUGUI>();
			boxCountSliderGrp.SetParent(val);
			((Component)boxCountSliderGrp).transform.localPosition = ModConfigManager.Instance.GetValue<Vector3>("UI", "Box Count Slider Position");
			((Component)boxCountSliderGrp).transform.localScale = ModConfigManager.Instance.GetValue<Vector3>("UI", "Box Count Slider Scale");
			whiteBoxButton = AddButton("White Box", (UnityAction)delegate
			{
				OnButtonPress(EBulkBoxGrade.WhiteBox);
			});
			((Component)whiteBoxButton).transform.SetParent(val);
			((Component)whiteBoxButton).transform.localPosition = ModConfigManager.Instance.GetValue<Vector3>("UI", "White Box Button Position");
			((Component)whiteBoxButton).transform.localScale = ModConfigManager.Instance.GetValue<Vector3>("UI", "White Box Button Scale");
			yellowBoxButton = AddButton("Yellow Box", (UnityAction)delegate
			{
				OnButtonPress(EBulkBoxGrade.YellowBox);
			});
			((Component)yellowBoxButton).transform.SetParent(val);
			((Component)yellowBoxButton).transform.localPosition = ModConfigManager.Instance.GetValue<Vector3>("UI", "Yellow Box Button Position");
			((Component)yellowBoxButton).transform.localScale = ModConfigManager.Instance.GetValue<Vector3>("UI", "Yellow Box Button Scale");
			pinkBoxButton = AddButton("Pink Box", (UnityAction)delegate
			{
				OnButtonPress(EBulkBoxGrade.PinkBox);
			});
			((Component)pinkBoxButton).transform.SetParent(val);
			((Component)pinkBoxButton).transform.localPosition = ModConfigManager.Instance.GetValue<Vector3>("UI", "Pink Box Button Position");
			((Component)pinkBoxButton).transform.localScale = ModConfigManager.Instance.GetValue<Vector3>("UI", "Pink Box Button Scale");
			redBoxButton = AddButton("Red Box", (UnityAction)delegate
			{
				OnButtonPress(EBulkBoxGrade.RedBox);
			});
			((Component)redBoxButton).transform.SetParent(val);
			((Component)redBoxButton).transform.localPosition = ModConfigManager.Instance.GetValue<Vector3>("UI", "Red Box Button Position");
			((Component)redBoxButton).transform.localScale = ModConfigManager.Instance.GetValue<Vector3>("UI", "Red Box Button Scale");
			greenBoxButton = AddButton("Green Box", (UnityAction)delegate
			{
				OnButtonPress(EBulkBoxGrade.GreenBox);
			});
			((Component)greenBoxButton).transform.SetParent(val);
			((Component)greenBoxButton).transform.localPosition = ModConfigManager.Instance.GetValue<Vector3>("UI", "Green Box Button Position");
			((Component)greenBoxButton).transform.localScale = ModConfigManager.Instance.GetValue<Vector3>("UI", "Green Box Button Scale");
			component.m_ControllerBtnColumnList.Insert(0, new ControllerBtnList
			{
				rowList = new List<ControllerButton>(5) { whiteBoxButton, yellowBoxButton, pinkBoxButton, redBoxButton, greenBoxButton }
			});
		}

		private void OnSliderValueChanged(float value)
		{
			((TMP_Text)boxCountSliderCurrentText).text = $"{value}";
		}

		private void CalculateMaxBoxCount()
		{
			int num = 1 + CurrentWorkbench.GetOpenSpaceCount();
			((TMP_Text)boxCountSliderMaxText).text = $"{num}";
			maxBoxCreateSlider.maxValue = num;
		}

		private ControllerButton AddButton(string name, UnityAction onClick = null)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			ControllerButton val = Object.Instantiate<ControllerButton>(startBundleButton);
			((Component)val).gameObject.SetActive(true);
			((Object)val).name = name ?? "";
			Button componentInChildren = ((Component)val).GetComponentInChildren<Button>(true);
			if (componentInChildren != null)
			{
				int persistentEventCount = ((UnityEventBase)componentInChildren.onClick).GetPersistentEventCount();
				for (int i = 0; i < persistentEventCount; i++)
				{
					((UnityEventBase)componentInChildren.onClick).SetPersistentListenerState(i, (UnityEventCallState)0);
				}
				((UnityEventBase)componentInChildren.onClick).RemoveAllListeners();
				if (onClick != null)
				{
					((UnityEvent)componentInChildren.onClick).AddListener(onClick);
				}
				((Selectable)componentInChildren).navigation = Navigation.defaultNavigation;
			}
			((TMP_Text)((Component)val).GetComponentInChildren<TextMeshProUGUI>(true)).text = name;
			return ((Component)val).GetComponent<ControllerButton>();
		}

		private void OnButtonPress(EBulkBoxGrade boxGrade)
		{
			switch (boxGrade)
			{
			case EBulkBoxGrade.WhiteBox:
				workbenchUIScreen.m_SliderPriceMinimum.value = ModConfigManager.Instance.GetValue<float>("UI", "White Box Min") * 100f;
				workbenchUIScreen.m_SliderPriceLimit.value = ModConfigManager.Instance.GetValue<float>("UI", "White Box Max") * 100f;
				break;
			case EBulkBoxGrade.YellowBox:
				workbenchUIScreen.m_SliderPriceMinimum.value = ModConfigManager.Instance.GetValue<float>("UI", "Yellow Box Min") * 100f;
				workbenchUIScreen.m_SliderPriceLimit.value = ModConfigManager.Instance.GetValue<float>("UI", "Yellow Box Max") * 100f;
				break;
			case EBulkBoxGrade.PinkBox:
				workbenchUIScreen.m_SliderPriceMinimum.value = ModConfigManager.Instance.GetValue<float>("UI", "Pink Box Min") * 100f;
				workbenchUIScreen.m_SliderPriceLimit.value = ModConfigManager.Instance.GetValue<float>("UI", "Pink Box Max") * 100f;
				break;
			case EBulkBoxGrade.RedBox:
				workbenchUIScreen.m_SliderPriceMinimum.value = ModConfigManager.Instance.GetValue<float>("UI", "Red Box Min") * 100f;
				workbenchUIScreen.m_SliderPriceLimit.value = ModConfigManager.Instance.GetValue<float>("UI", "Red Box Max") * 100f;
				break;
			case EBulkBoxGrade.GreenBox:
				workbenchUIScreen.m_SliderPriceMinimum.value = ModConfigManager.Instance.GetValue<float>("UI", "Green Box Min") * 100f;
				workbenchUIScreen.m_SliderPriceLimit.value = ModConfigManager.Instance.GetValue<float>("UI", "Green Box Max") * 100f;
				break;
			}
			workbenchUIScreen.m_PriceMinimum = Mathf.RoundToInt(workbenchUIScreen.m_SliderPriceMinimum.value / 100f);
			workbenchUIScreen.m_PriceLimit = Mathf.RoundToInt(workbenchUIScreen.m_SliderPriceLimit.value / 100f);
			((TMP_Text)workbenchUIScreen.m_PriceLimitText).text = GameInstance.GetPriceString(workbenchUIScreen.m_PriceLimit, false, true, false, "F2");
			((TMP_Text)workbenchUIScreen.m_PriceMinimumText).text = GameInstance.GetPriceString(workbenchUIScreen.m_PriceMinimum, false, true, false, "F2");
			CPlayerData.m_WorkbenchPriceLimit = workbenchUIScreen.m_PriceLimit;
			CPlayerData.m_WorkbenchPriceMinimum = workbenchUIScreen.m_PriceMinimum;
		}

		public void OnTaskComplete()
		{
			bool num = CurrentWorkbench.OnTaskComplete();
			((Selectable)workbenchUIScreen.m_SliderMinCard).interactable = true;
			((Selectable)workbenchUIScreen.m_SliderPriceLimit).interactable = true;
			((Selectable)workbenchUIScreen.m_SliderPriceMinimum).interactable = true;
			workbenchUIScreen.m_TaskFinishCirlceGrp.SetActive(false);
			if (num)
			{
				workbenchUIScreen.CloseScreen(false);
			}
			else if (maxBoxCreateSlider.value - 1f >= 1f)
			{
				Slider obj = maxBoxCreateSlider;
				float value = obj.value;
				obj.value = value - 1f;
				startBundleButton.OnPressConfirm();
			}
			else
			{
				CalculateMaxBoxCount();
			}
		}
	}
	public class ModCoroutineRunner : MonoBehaviour
	{
		private static ModCoroutineRunner instance;

		public static ModCoroutineRunner Instance => instance ?? Initialize();

		private static ModCoroutineRunner Initialize()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			GameObject val = new GameObject("ModCoroutineRunner", new Type[1] { typeof(ModCoroutineRunner) });
			instance = val.GetComponent<ModCoroutineRunner>();
			Object.DontDestroyOnLoad((Object)val);
			return instance;
		}
	}
	[BepInPlugin("EnhancedWorkbenches", "Enhanced Workbenches", "2.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony m_Harmony = new Harmony("EnhancedWorkbenches");

		public static WorkbenchManager WorkbenchManager { get; private set; } = new WorkbenchManager();


		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			ModConfigManager.Instance.Initialize(((BaseUnityPlugin)this).Config);
			SceneManager.sceneLoaded += OnSceneLoad;
			m_Harmony.PatchAll();
			Logger.LogInfo((object)"Plugin Enhanced Workbenches v:2.0.1 by GhostNarwhal is loaded!");
		}

		private void OnSceneLoad(Scene scene, LoadSceneMode _)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			WorkbenchManager.HandleSceneChange(scene);
		}

		private void OnDestroy()
		{
			m_Harmony.UnpatchSelf();
			Logger.LogInfo((object)"Plugin Enhanced Workbenches is unloaded!");
		}
	}
	public class SaveFileManager
	{
		private static SaveFileManager instance;

		public static SaveFileManager Instance => instance ?? (instance = new SaveFileManager());

		public List<EnhancedWorkbenchSaveData> OnLoad(int savefileIndex)
		{
			List<EnhancedWorkbenchSaveData> result = new List<EnhancedWorkbenchSaveData>();
			if (File.Exists(string.Format("{0}/EnhancedWorkbench/{1}_{2}.json", Paths.PluginPath, "EnhancedWorkbenches", savefileIndex)))
			{
				if (File.Exists(string.Format("{0}/EnhancedWorkbench/{1}_{2}.json", Application.persistentDataPath, "EnhancedWorkbenches", savefileIndex)))
				{
					File.Delete(string.Format("{0}/EnhancedWorkbench/{1}_{2}.json", Paths.PluginPath, "EnhancedWorkbenches", savefileIndex));
				}
				else
				{
					if (!Directory.Exists(Application.persistentDataPath + "/EnhancedWorkbench"))
					{
						Directory.CreateDirectory(Application.persistentDataPath + "/EnhancedWorkbench");
					}
					File.Copy(string.Format("{0}/EnhancedWorkbench/{1}_{2}.json", Paths.PluginPath, "EnhancedWorkbenches", savefileIndex), string.Format("{0}/EnhancedWorkbench/{1}_{2}.json", Application.persistentDataPath, "EnhancedWorkbenches", savefileIndex));
					File.Delete(string.Format("{0}/EnhancedWorkbench/{1}_{2}.json", Paths.PluginPath, "EnhancedWorkbenches", savefileIndex));
				}
			}
			if (File.Exists(string.Format("{0}/EnhancedWorkbench/{1}_{2}.json", Application.persistentDataPath, "EnhancedWorkbenches", savefileIndex)))
			{
				result = JsonConvert.DeserializeObject<List<EnhancedWorkbenchSaveData>>(File.ReadAllText(string.Format("{0}/EnhancedWorkbench/{1}_{2}.json", Application.persistentDataPath, "EnhancedWorkbenches", savefileIndex)));
			}
			return result;
		}

		public void OnSave(int savefileIndex, List<EnhancedWorkbenchSaveData> workbenchSaveData)
		{
			if (!Directory.Exists(Application.persistentDataPath + "/EnhancedWorkbench"))
			{
				Directory.CreateDirectory(Application.persistentDataPath + "/EnhancedWorkbench");
			}
			string contents = JsonConvert.SerializeObject((object)workbenchSaveData, (Formatting)1);
			File.WriteAllText(string.Format("{0}/EnhancedWorkbench/{1}_{2}.json", Application.persistentDataPath, "EnhancedWorkbenches", savefileIndex), contents);
		}
	}
	public class WorkbenchManager
	{
		public readonly ConditionalWeakTable<InteractableWorkbench, EnhancedWorkbench> WorkbenchCache = new ConditionalWeakTable<InteractableWorkbench, EnhancedWorkbench>();

		public List<EnhancedWorkbenchSaveData> tempSaveData = new List<EnhancedWorkbenchSaveData>();

		private EnhancedWorkbenchUI enhancedWorkbenchUI;

		private int nextWorkbenchNumber;

		public bool IsLoaded { get; set; }

		public void HandleSceneChange(Scene scene)
		{
			if (((Scene)(ref scene)).name == "Title")
			{
				IsLoaded = false;
				WorkbenchCache.Clear();
				enhancedWorkbenchUI = null;
				nextWorkbenchNumber = 0;
			}
		}

		public void OnWorkbenchAwake(InteractableWorkbench workbench)
		{
			if (IsLoaded)
			{
				InitializeWorkbench(workbench, nextWorkbenchNumber);
				nextWorkbenchNumber++;
			}
		}

		public void OnEnterWorkBenchMode(InteractableWorkbench workbench)
		{
			if (WorkbenchCache.TryGetValue(workbench, out var value))
			{
				enhancedWorkbenchUI.CurrentWorkbench = value;
			}
		}

		public void OnExitWorkBenchMode(InteractableWorkbench workbench)
		{
			enhancedWorkbenchUI.CurrentWorkbench = null;
			if (WorkbenchCache.TryGetValue(workbench, out var value) && value.CurrentFillBox != null)
			{
				((InteractablePackagingBox)value.CurrentFillBox).m_Collider.enabled = true;
				((InteractablePackagingBox)value.CurrentFillBox).m_Collider.isTrigger = true;
			}
		}

		public void OnStartHoldingBox(InteractablePackagingBox_Item packagingBox)
		{
			foreach (InteractableWorkbench workbench in CSingleton<ShelfManager>.Instance.m_WorkbenchList)
			{
				if (WorkbenchCache.TryGetValue(workbench, out var value) && (Object)(object)value.CurrentFillBox == (Object)(object)packagingBox)
				{
					CSingleton<RestockManager>.Instance.m_ItemPackagingBoxList.Add(packagingBox);
					((InteractablePackagingBox)packagingBox).m_Collider.isTrigger = false;
					value.CurrentFillBox = null;
					break;
				}
			}
		}

		public void OnRaycasted(InteractableWorkbench workbench)
		{
			if (WorkbenchCache.TryGetValue(workbench, out var value))
			{
				value.IsRaycasted = true;
			}
		}

		public void OnRaycastEnded(InteractableWorkbench workbench)
		{
			if (WorkbenchCache.TryGetValue(workbench, out var value))
			{
				value.IsRaycasted = false;
			}
		}

		public bool OnLeftMouseButtonUp(InteractableWorkbench workbench)
		{
			if (WorkbenchCache.TryGetValue(workbench, out var value) && value.ShelfCompartment.GetItemCount() > 0)
			{
				InteractablePackagingBox_Item lastInteractablePackagingBox = value.ShelfCompartment.GetLastInteractablePackagingBox();
				if (lastInteractablePackagingBox != null && (((InteractableObject)lastInteractablePackagingBox).m_IsLerpingToPos || lastInteractablePackagingBox.m_IsTogglingOpenClose))
				{
					return false;
				}
				value.TryPrepareNextEmpty(lastInteractablePackagingBox);
			}
			return true;
		}

		public bool OnTaskComplete()
		{
			if (enhancedWorkbenchUI == null || enhancedWorkbenchUI.CurrentWorkbench == null)
			{
				return true;
			}
			enhancedWorkbenchUI.OnTaskComplete();
			return false;
		}

		public void OnLoadComplete(List<EnhancedWorkbenchSaveData> saveData)
		{
			if (!IsLoaded)
			{
				tempSaveData = saveData;
				enhancedWorkbenchUI = ((Component)CSingleton<WorkbenchUIScreen>.Instance).gameObject.AddComponent<EnhancedWorkbenchUI>();
				IsLoaded = true;
			}
		}

		private void InitializeWorkbench(InteractableWorkbench workbench, int workbenchNumber)
		{
			if (!WorkbenchCache.TryGetValue(workbench, out var value))
			{
				value = ((Component)workbench).gameObject.AddComponent<EnhancedWorkbench>();
				value.WorkbenchNumber = workbenchNumber;
				if (workbenchNumber < tempSaveData.Count)
				{
					value.InitFromSaveData(tempSaveData[workbenchNumber]);
					tempSaveData.RemoveAt(workbenchNumber);
				}
				WorkbenchCache.Add(workbench, value);
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "EnhancedWorkbenches";

		public const string PLUGIN_NAME = "Enhanced Workbenches";

		public const string PLUGIN_VERSION = "2.0.1";
	}
}
namespace EnhancedWorkbenches.Patches
{
	[HarmonyPatch(typeof(CSaveLoad))]
	public class CSaveLoadPatches
	{
		[HarmonyPatch("Save")]
		[HarmonyPrefix]
		private static void SavePrefix(int saveSlotIndex, bool skipJSONSave)
		{
			List<EnhancedWorkbenchSaveData> workbenchSaveData = (from kvp in Plugin.WorkbenchManager.WorkbenchCache
				orderby kvp.Value.WorkbenchNumber
				select kvp.Value.SaveData).ToList();
			SaveFileManager.Instance.OnSave(saveSlotIndex, workbenchSaveData);
		}

		[HarmonyPatch("Load")]
		[HarmonyPrefix]
		private static void LoadPrefix(int slotIndex)
		{
			List<EnhancedWorkbenchSaveData> saveData = SaveFileManager.Instance.OnLoad(slotIndex);
			Plugin.WorkbenchManager.OnLoadComplete(saveData);
		}
	}
	[HarmonyPatch(typeof(InteractableObject))]
	public class InteractableObjectPatch
	{
		[HarmonyPatch("OnRaycasted")]
		[HarmonyPostfix]
		private static void OnRaycastedPostfix(InteractableWorkbench __instance)
		{
			Plugin.WorkbenchManager.OnRaycasted(__instance);
		}

		[HarmonyPatch("OnRaycastEnded")]
		[HarmonyPostfix]
		private static void OnRaycastEndedPostfix(InteractableWorkbench __instance)
		{
			Plugin.WorkbenchManager.OnRaycastEnded(__instance);
		}
	}
	[HarmonyPatch(typeof(InteractablePackagingBox_Item))]
	public class InteractablePackagingBox_ItemPatch
	{
		[HarmonyPatch("StartHoldBox")]
		[HarmonyPostfix]
		private static void OnStartHoldBoxPostfix(bool isPlayer, Transform holdItemPos, InteractablePackagingBox_Item __instance)
		{
			Plugin.WorkbenchManager.OnStartHoldingBox(__instance);
		}
	}
	[HarmonyPatch(typeof(InteractableWorkbench))]
	public class InteractableWorkbenchPatch
	{
		[HarmonyPatch("OnMouseButtonUp")]
		[HarmonyPrefix]
		private static bool OnMouseButtonUpPrefix(InteractableWorkbench __instance)
		{
			return Plugin.WorkbenchManager.OnLeftMouseButtonUp(__instance);
		}

		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void OnAwakePostfix(InteractableWorkbench __instance)
		{
			Plugin.WorkbenchManager.OnWorkbenchAwake(__instance);
		}

		[HarmonyPatch("Update")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> UpdateTranspiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Expected O, but got Unknown
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Expected O, but got Unknown
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Expected O, but got Unknown
			MethodInfo getMethod = AccessTools.Property(typeof(Time), "deltaTime").GetGetMethod();
			MethodInfo methodInfo = AccessTools.Method(typeof(ModConfigManager), "GetValue", (Type[])null, (Type[])null).MakeGenericMethod(typeof(float));
			MethodInfo getMethod2 = AccessTools.Property(typeof(ModConfigManager), "Instance").GetGetMethod();
			CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
			val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Call, (object)getMethod, (string)null)
			});
			if (val.IsValid)
			{
				val.Advance(1).Insert((CodeInstruction[])(object)new CodeInstruction[5]
				{
					new CodeInstruction(OpCodes.Call, (object)getMethod2),
					new CodeInstruction(OpCodes.Ldstr, (object)"Workbench"),
					new CodeInstruction(OpCodes.Ldstr, (object)"Animation Speed Multiplier"),
					new CodeInstruction(OpCodes.Callvirt, (object)methodInfo),
					new CodeInstruction(OpCodes.Mul, (object)null)
				});
			}
			return val.InstructionEnumeration();
		}
	}
	[HarmonyPatch(typeof(InteractionPlayerController))]
	public class InteractionPlayerControllerPatch
	{
		[HarmonyPatch("OnExitWorkbenchMode")]
		[HarmonyPostfix]
		private static void OnExitWorkbenchModePostfix(InteractableWorkbench ___m_CurrentWorkbench)
		{
			Plugin.WorkbenchManager.OnExitWorkBenchMode(___m_CurrentWorkbench);
		}

		[HarmonyPatch("OnEnterWorkbenchMode")]
		[HarmonyPostfix]
		private static void OnEnterWorkbenchModePostfix(InteractableWorkbench ___m_CurrentWorkbench)
		{
			Plugin.WorkbenchManager.OnEnterWorkBenchMode(___m_CurrentWorkbench);
		}
	}
	[HarmonyPatch(typeof(WorkbenchUIScreen))]
	public class WorkbenchUIScreenPatch
	{
		[HarmonyPatch("OnTaskCompleted")]
		[HarmonyPrefix]
		private static bool OnTaskCompletedPrefix()
		{
			return Plugin.WorkbenchManager.OnTaskComplete();
		}

		[HarmonyPatch("Update")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> UpdateTranspiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Expected O, but got Unknown
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Expected O, but got Unknown
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Expected O, but got Unknown
			MethodInfo getMethod = AccessTools.Property(typeof(Time), "deltaTime").GetGetMethod();
			MethodInfo methodInfo = AccessTools.Method(typeof(ModConfigManager), "GetValue", (Type[])null, (Type[])null).MakeGenericMethod(typeof(float));
			MethodInfo getMethod2 = AccessTools.Property(typeof(ModConfigManager), "Instance").GetGetMethod();
			CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
			val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Call, (object)getMethod, (string)null)
			});
			if (val.IsValid)
			{
				val.Advance(1).Insert((CodeInstruction[])(object)new CodeInstruction[5]
				{
					new CodeInstruction(OpCodes.Call, (object)getMethod2),
					new CodeInstruction(OpCodes.Ldstr, (object)"Workbench"),
					new CodeInstruction(OpCodes.Ldstr, (object)"Animation Speed Multiplier"),
					new CodeInstruction(OpCodes.Callvirt, (object)methodInfo),
					new CodeInstruction(OpCodes.Mul, (object)null)
				});
			}
			return val.InstructionEnumeration();
		}
	}
}
namespace EnhancedWorkbenches.Models
{
	public class EnhancedWorkbenchSaveData
	{
		public int EmptyBoxCount { get; set; }

		public PackagingBoxSaveData PackagingBox { get; set; }
	}
	public class PackagingBoxSaveData
	{
		public EItemType ItemType { get; set; }

		public int ItemCount { get; set; }
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}