Decompiled source of Bulk Purchase Plus v1.0.3

BulkPurchasePlus.dll

Decompiled 4 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BulkPurchasePlus;
using HarmonyLib;
using MonoMod.RuntimeDetour;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
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: AssemblyTitle("BulkPurchasePlus")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BulkPurchasePlus")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a15a3d6a-6ae9-46e1-99bc-007f149c9fc0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace BulkPurchasePlus
{
	[BepInPlugin("com.Kalkune.BulkPurchasePlus", "BulkPurchasePlus", "1.0.3")]
	public class BulkPurchasePlus : BaseUnityPlugin
	{
		internal static Harmony Harmony;

		public static int threshold;

		public static int currentMode = 1;

		public static bool notificationSent = false;

		public static string notificationMessage;

		public static string productToggled;

		public static bool productToggledBlacklist;

		public static string productToggledInternalName;

		public static bool buyMaxToggle;

		public static int buyMaxCycleCount;

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

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

		public static ConfigEntry<int> HardThreshold { get; set; }

		public static ConfigEntry<int> StorageThreshold { get; set; }

		public static ConfigEntry<int> StorageBoxThreshold { get; set; }

		public static ConfigEntry<KeyboardShortcut> KeyboardShortcutDoublePrice { get; set; }

		public static ConfigEntry<KeyboardShortcut> KeyboardShortcutBlacklist { get; set; }

		public static ConfigEntry<string> Help { get; set; }

		public void Awake()
		{
			//IL_007d: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Expected O, but got Unknown
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Expected O, but got Unknown
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Expected O, but got Unknown
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Expected O, but got Unknown
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Expected O, but got Unknown
			HardThreshold = ((BaseUnityPlugin)this).Config.Bind<int>("Threshold", "Hard Threshold Cap", 50, "Products with quantity above this number won't be ordered with Needs Only if on alternate modes.");
			StorageThreshold = ((BaseUnityPlugin)this).Config.Bind<int>("Threshold", "Storage Threshold Cap", 30, "Products with quantity above this number won't be ordered with Product Storage Mode.");
			StorageBoxThreshold = ((BaseUnityPlugin)this).Config.Bind<int>("Threshold", "Storage Box Threshold Cap", 4, "Products with box quantity above this number won't be ordered with Box Storage Mode.");
			KeyboardShortcutDoublePrice = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Threshold", "Toggle Threshold Keybind", new KeyboardShortcut((KeyCode)114, Array.Empty<KeyCode>()), "Keybind to toggle through modes");
			Help = ((BaseUnityPlugin)this).Config.Bind<string>("Blacklist", "Blacklist List", "", "Current list of product blacklisted");
			KeyboardShortcutBlacklist = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Blacklist", "Toggle Blacklist Keybind", new KeyboardShortcut((KeyCode)105, Array.Empty<KeyCode>()), "Keybind to toggle products blacklist status");
			threshold = HardThreshold.Value;
			Harmony = new Harmony("com.Kalkune.BulkPurchasePlus");
			Harmony.PatchAll();
			productBlacklist = Help.Value.Split(new char[1] { ',' }).ToList();
			Hook val = new Hook((MethodBase)typeof(ManagerBlackboard).GetMethod("AddShoppingListProduct", BindingFlags.Instance | BindingFlags.Public), typeof(BulkPurchasePlus).GetMethod("ManagerBlackboardAddShoppingListProduct"));
			Hook val2 = new Hook((MethodBase)typeof(ManagerBlackboard).GetMethod("RemoveShoppingListProduct", BindingFlags.Instance | BindingFlags.Public), typeof(BulkPurchasePlus).GetMethod("ManagerBlackboardRemoveShoppingListProduct"));
			Hook val3 = new Hook((MethodBase)typeof(ManagerBlackboard).GetMethod("RemoveAllShoppingList", BindingFlags.Instance | BindingFlags.Public), typeof(BulkPurchasePlus).GetMethod("ManagerBlackboardRemoveAllShoppingList"));
			Hook val4 = new Hook((MethodBase)typeof(ManagerBlackboard).GetMethod("BuyCargo", BindingFlags.Instance | BindingFlags.Public), typeof(BulkPurchasePlus).GetMethod("ManagerBlackboardBuyCargo"));
		}

		public static void ManagerBlackboardAddShoppingListProduct(Action<ManagerBlackboard, int, float> orig, ManagerBlackboard self, int productID, float boxPrice)
		{
			orig(self, productID, boxPrice);
			ProductListing val = Object.FindFirstObjectByType<ProductListing>();
			GameObject val2 = val.productPrefabs[productID];
			currentShoppingList.Add(((Object)val2).name);
		}

		public static void ManagerBlackboardRemoveShoppingListProduct(Action<ManagerBlackboard, int> orig, ManagerBlackboard self, int indexToRemove)
		{
			currentShoppingList.RemoveAt(indexToRemove);
			orig(self, indexToRemove);
		}

		public static void ManagerBlackboardRemoveAllShoppingList(Action<ManagerBlackboard> orig, ManagerBlackboard self)
		{
			currentShoppingList.Clear();
			orig(self);
		}

		public static void ManagerBlackboardBuyCargo(Action<ManagerBlackboard> orig, ManagerBlackboard self)
		{
			ManagerBlackboard val = Object.FindFirstObjectByType<ManagerBlackboard>();
			GameData val2 = Object.FindFirstObjectByType<GameData>();
			if (val.shoppingListParent.transform.childCount != 0 && val.shoppingTotalCharge != 0f && !(val2.gameFunds < val.shoppingTotalCharge))
			{
				currentShoppingList.Clear();
				orig(self);
			}
		}

		public void Update()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			KeyboardShortcut value = KeyboardShortcutDoublePrice.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				if (currentMode >= 7)
				{
					currentMode = 1;
				}
				else
				{
					currentMode++;
				}
				notificationMessage = "ThresholdToggle";
				notificationSent = true;
				return;
			}
			PlayerNetwork val = Object.FindFirstObjectByType<PlayerNetwork>();
			if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val.gameCanvasProductOBJ) || !val.gameCanvasProductOBJ.activeSelf)
			{
				return;
			}
			KeyboardShortcut value2 = KeyboardShortcutBlacklist.Value;
			if (((KeyboardShortcut)(ref value2)).IsDown())
			{
				productToggled = ((TMP_Text)((Component)val.gameCanvasProductOBJ.transform.Find("Container/ProductName")).GetComponent<TextMeshProUGUI>()).text;
				productToggledInternalName = ((Object)((Graphic)((Component)val.gameCanvasProductOBJ.transform.Find("Container/ProductImage")).GetComponent<Image>()).mainTexture).name;
				if (!productBlacklist.Contains(productToggledInternalName))
				{
					productBlacklist.Add(productToggledInternalName);
					productToggledBlacklist = true;
				}
				else if (productBlacklist.Contains(productToggledInternalName))
				{
					productBlacklist.Remove(productToggledInternalName);
					productToggledBlacklist = false;
				}
				notificationMessage = "ProductBlacklist";
				notificationSent = true;
				Help.Value = string.Join(",", productBlacklist);
			}
		}

		public static int somethingsomething(NPC_Manager __instance, int productId, Data_Product productComponent, bool includeStorage)
		{
			//IL_00c0: 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_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.shelvesOBJ.transform.childCount == 0)
			{
				return 0;
			}
			int num = 0;
			int num2 = 0;
			for (int i = 0; i < __instance.shelvesOBJ.transform.childCount; i++)
			{
				int[] productInfoArray = ((Component)__instance.shelvesOBJ.transform.GetChild(i)).GetComponent<Data_Container>().productInfoArray;
				int num3 = productInfoArray.Length / 2;
				for (int j = 0; j < num3; j++)
				{
					int num4 = productInfoArray[j * 2];
					if (num4 == productId)
					{
						num++;
					}
					Data_Container component = ((Component)__instance.shelvesOBJ.transform.GetChild(i)).GetComponent<Data_Container>();
					if (!Object.op_Implicit((Object)(object)component.productlistComponent))
					{
						break;
					}
					GameObject val = component.productlistComponent.productPrefabs[productId];
					Vector3 size = val.GetComponent<BoxCollider>().size;
					bool isStackable = val.GetComponent<Data_Product>().isStackable;
					int num5 = Mathf.FloorToInt(component.shelfLength / (size.x * 1.1f));
					num5 = Mathf.Clamp(num5, 1, 100);
					int num6 = Mathf.FloorToInt(component.shelfWidth / (size.z * 1.1f));
					num6 = Mathf.Clamp(num6, 1, 100);
					int num7 = num5 * num6;
					if (isStackable)
					{
						int num8 = Mathf.FloorToInt(component.shelfHeight / (size.y * 1.1f));
						num8 = Mathf.Clamp(num8, 1, 100);
						num7 = num5 * num6 * num8;
					}
					num2 += num7 * num;
					num = 0;
				}
			}
			if (__instance.storageOBJ.transform.childCount == 0)
			{
				Debug.LogWarning((object)"Stopped cause some reason I don't really know");
				return num2;
			}
			if (!includeStorage)
			{
				for (int k = 0; k < __instance.storageOBJ.transform.childCount && !(((Object)((Component)__instance.storageOBJ.transform.GetChild(k)).GetComponent<Data_Container>()).name != "5_StorageShelf(Clone)"); k++)
				{
					int[] productInfoArray2 = ((Component)__instance.storageOBJ.transform.GetChild(k)).GetComponent<Data_Container>().productInfoArray;
					int num9 = productInfoArray2.Length / 2;
					for (int l = 0; l < num9; l++)
					{
						int num10 = productInfoArray2[l * 2];
						if (num10 == productId)
						{
							num++;
						}
						num2 += productComponent.maxItemsPerBox * num;
						num = 0;
					}
				}
			}
			return num2;
		}
	}
}
namespace BuyAllButton.Patches
{
	[HarmonyPatch(typeof(GameCanvas))]
	internal class NotificationHandler
	{
		[HarmonyPatch(typeof(LocalizationManager))]
		internal class LocalizationHandler
		{
			[HarmonyPatch("GetLocalizationString")]
			[HarmonyPrefix]
			public static bool noLocalization_Prefix(ref string key, ref string __result)
			{
				if (key[0] == '`')
				{
					__result = key.Substring(1);
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		public static void NotificationHandler_Postfix(GameCanvas __instance, ref bool ___inCooldown)
		{
			if (!global::BulkPurchasePlus.BulkPurchasePlus.notificationSent)
			{
				return;
			}
			___inCooldown = false;
			global::BulkPurchasePlus.BulkPurchasePlus.notificationSent = false;
			string text = "`";
			switch (global::BulkPurchasePlus.BulkPurchasePlus.notificationMessage)
			{
			case "ThresholdToggle":
				switch (global::BulkPurchasePlus.BulkPurchasePlus.currentMode)
				{
				case 1:
					text += "Threshold: Shelves Filled";
					break;
				case 2:
					text = text + "Threshold: " + global::BulkPurchasePlus.BulkPurchasePlus.HardThreshold.Value + " On Shelf";
					break;
				case 3:
					text += "Threshold: Shelf Mixed";
					break;
				case 4:
					text = text + "Threshold: " + global::BulkPurchasePlus.BulkPurchasePlus.StorageThreshold.Value + " Product In Storage";
					break;
				case 5:
					text = text + "Threshold: " + global::BulkPurchasePlus.BulkPurchasePlus.StorageBoxThreshold.Value + " Boxes In Storage";
					break;
				case 6:
					text += "Threshold: Storage Mixed";
					break;
				case 7:
					text += "Threshold: Storage Filled";
					break;
				}
				break;
			case "ProductBlacklist":
				if (global::BulkPurchasePlus.BulkPurchasePlus.productToggledBlacklist)
				{
					text = text + "Blacklisted: " + global::BulkPurchasePlus.BulkPurchasePlus.productToggled;
				}
				else if (!global::BulkPurchasePlus.BulkPurchasePlus.productToggledBlacklist)
				{
					text = text + "Un-Blacklisted: " + global::BulkPurchasePlus.BulkPurchasePlus.productToggled;
				}
				break;
			case "BuyMaxToggle":
				if (global::BulkPurchasePlus.BulkPurchasePlus.buyMaxToggle)
				{
					text += "Buy Max Enabled";
				}
				else if (!global::BulkPurchasePlus.BulkPurchasePlus.buyMaxToggle)
				{
					text += "Buy Max Disabled";
				}
				break;
			}
			__instance.CreateCanvasNotification(text);
		}
	}
	[HarmonyPatch(typeof(PlayerNetwork), "OnStartClient")]
	public class AddButton
	{
		public static bool Prefix()
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Expected O, but got Unknown
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Expected O, but got Unknown
			GameObject val = GameObject.Find("Buttons_Bar");
			if ((Object)(object)val == (Object)null)
			{
				return true;
			}
			if ((Object)(object)val.transform.Find("AddAllToCartButton") == (Object)null)
			{
				GameObject val2 = CreateButton(val, "AddAllToCartButton", -450f, 110f);
				AddButtonEvents(val2.GetComponent<Button>(), val2.GetComponent<Image>(), new UnityAction(OnAddAllToCartButtonClick));
			}
			if ((Object)(object)val.transform.Find("BuyMaxButton") == (Object)null)
			{
				GameObject val3 = CreateButton(val, "BuyMaxButton", 425f, 110f);
				AddButtonEvents(val3.GetComponent<Button>(), val3.GetComponent<Image>(), new UnityAction(OnBuyMaxButtonClick));
			}
			if ((Object)(object)val.transform.Find("NeedsOnlyButton") == (Object)null)
			{
				GameObject val4 = CreateButton(val, "NeedsOnlyButton", -325f, 55f);
				AddButtonEvents(val4.GetComponent<Button>(), val4.GetComponent<Image>(), new UnityAction(OnNeedsOnlyButtonClick));
			}
			return true;
		}

		private static GameObject CreateButton(GameObject parent, string name, float xOffset, float width)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_00a2: Expected O, but got Unknown
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			RectTransform val2 = val.AddComponent<RectTransform>();
			Button val3 = val.AddComponent<Button>();
			Image val4 = val.AddComponent<Image>();
			val.transform.SetParent(parent.transform, false);
			val2.sizeDelta = new Vector2(width, 35f);
			val2.anchoredPosition = new Vector2(xOffset, 612f);
			val2.anchorMin = new Vector2(0.5f, 0.5f);
			val2.anchorMax = new Vector2(0.5f, 0.5f);
			val2.pivot = new Vector2(0.5f, 0.5f);
			GameObject val5 = new GameObject("ButtonText");
			val5.transform.SetParent(val.transform, false);
			RectTransform val6 = val5.AddComponent<RectTransform>();
			Text val7 = val5.AddComponent<Text>();
			val6.sizeDelta = val2.sizeDelta;
			val6.anchoredPosition = Vector2.zero;
			val7.text = ((name == "AddAllToCartButton") ? "Add All to Cart" : ((name == "BuyMaxButton") ? "Toggle Buy Max" : "Needs Only Button"));
			val7.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
			val7.alignment = (TextAnchor)4;
			((Graphic)val7).color = Color.black;
			val7.fontStyle = (FontStyle)1;
			return val;
		}

		private static void AddButtonEvents(Button button, Image buttonImage, UnityAction onClickAction)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_0053: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			EventTrigger val = ((Component)button).gameObject.AddComponent<EventTrigger>();
			Entry val2 = new Entry
			{
				eventID = (EventTriggerType)0
			};
			((UnityEvent<BaseEventData>)(object)val2.callback).AddListener((UnityAction<BaseEventData>)delegate
			{
				OnHoverEnter(buttonImage);
			});
			val.triggers.Add(val2);
			Entry val3 = new Entry
			{
				eventID = (EventTriggerType)1
			};
			((UnityEvent<BaseEventData>)(object)val3.callback).AddListener((UnityAction<BaseEventData>)delegate
			{
				OnHoverExit(buttonImage);
			});
			val.triggers.Add(val3);
			((UnityEvent)button.onClick).AddListener((UnityAction)delegate
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				if (((Graphic)buttonImage).color != Color.white)
				{
					onClickAction.Invoke();
				}
			});
		}

		private static void OnHoverEnter(Image buttonImage)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			((Graphic)buttonImage).color = new Color(1f / 51f, 0.52156866f, 0.8156863f);
		}

		private static void OnHoverExit(Image buttonImage)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			((Graphic)buttonImage).color = Color.white;
		}

		private static void OnAddAllToCartButtonClick()
		{
			ProductListing val = Object.FindFirstObjectByType<ProductListing>();
			ManagerBlackboard val2 = Object.FindFirstObjectByType<ManagerBlackboard>();
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				return;
			}
			GameObject[] productPrefabs = val.productPrefabs;
			foreach (GameObject val3 in productPrefabs)
			{
				Data_Product component = val3.GetComponent<Data_Product>();
				if ((Object)(object)component != (Object)null && val.unlockedProductTiers[component.productTier])
				{
					float num = component.basePricePerUnit * (float)component.maxItemsPerBox;
					num *= val.tierInflation[component.productTier];
					float num2 = Mathf.Round(num * 100f) / 100f;
					val2.AddShoppingListProduct(component.productID, num2);
				}
			}
		}

		private static void OnBuyMaxButtonClick()
		{
			ManagerBlackboard val = Object.FindFirstObjectByType<ManagerBlackboard>();
			if (!((Object)(object)val == (Object)null))
			{
				global::BulkPurchasePlus.BulkPurchasePlus.buyMaxToggle = !global::BulkPurchasePlus.BulkPurchasePlus.buyMaxToggle;
				global::BulkPurchasePlus.BulkPurchasePlus.notificationMessage = "BuyMaxToggle";
				global::BulkPurchasePlus.BulkPurchasePlus.notificationSent = true;
			}
		}

		private static void OnNeedsOnlyButtonClick()
		{
			ProductListing val = Object.FindFirstObjectByType<ProductListing>();
			ManagerBlackboard val2 = Object.FindFirstObjectByType<ManagerBlackboard>();
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				return;
			}
			GameObject[] productPrefabs = val.productPrefabs;
			foreach (GameObject val3 in productPrefabs)
			{
				Data_Product productComponent = val3.GetComponent<Data_Product>();
				if (!((Object)(object)productComponent != (Object)null) || !val.unlockedProductTiers[productComponent.productTier])
				{
					continue;
				}
				int productID = productComponent.productID;
				bool flag = false;
				int[] productsExistences = val2.GetProductsExistences(productID);
				int num = 0;
				int[] array = productsExistences;
				foreach (int num2 in array)
				{
					num += num2;
				}
				if (global::BulkPurchasePlus.BulkPurchasePlus.currentShoppingList.Contains(((Object)productComponent).name))
				{
					num += global::BulkPurchasePlus.BulkPurchasePlus.currentShoppingList.FindAll((string s) => s.Equals(((Object)productComponent).name)).Count * productComponent.maxItemsPerBox;
				}
				flag = CheckOrderAviablility(num, productID, global::BulkPurchasePlus.BulkPurchasePlus.currentMode, productComponent);
				if (global::BulkPurchasePlus.BulkPurchasePlus.buyMaxToggle && flag)
				{
					int num3 = 0;
					if (global::BulkPurchasePlus.BulkPurchasePlus.currentMode < 7)
					{
						num3 = global::BulkPurchasePlus.BulkPurchasePlus.somethingsomething(NPC_Manager.Instance, productID, productComponent, includeStorage: false);
					}
					else if (global::BulkPurchasePlus.BulkPurchasePlus.currentMode == 7)
					{
						num3 = global::BulkPurchasePlus.BulkPurchasePlus.somethingsomething(NPC_Manager.Instance, productID, productComponent, includeStorage: true);
					}
					else
					{
						Debug.LogError((object)"Couldn't choose a mode");
					}
					num3 -= num;
					float num4 = productComponent.basePricePerUnit * (float)productComponent.maxItemsPerBox;
					num4 *= val.tierInflation[productComponent.productTier];
					float num5 = Mathf.Round(num4 * 100f) / 100f;
					for (int k = 0; (double)k < Math.Ceiling((float)num3 / (float)productComponent.maxItemsPerBox); k++)
					{
						val2.AddShoppingListProduct(productID, num5);
					}
				}
				else if (flag)
				{
					float num6 = productComponent.basePricePerUnit * (float)productComponent.maxItemsPerBox;
					num6 *= val.tierInflation[productComponent.productTier];
					float num7 = Mathf.Round(num6 * 100f) / 100f;
					val2.AddShoppingListProduct(productID, num7);
				}
			}
		}

		public static bool CheckOrderAviablility(int totalExistence, int productID, int orderNumber, Data_Product productComponent)
		{
			bool result = false;
			if (global::BulkPurchasePlus.BulkPurchasePlus.productBlacklist.Contains(((Object)productComponent).name))
			{
				return result;
			}
			switch (orderNumber)
			{
			case 1:
				if (totalExistence < global::BulkPurchasePlus.BulkPurchasePlus.somethingsomething(NPC_Manager.Instance, productID, productComponent, includeStorage: false))
				{
					result = true;
				}
				break;
			case 2:
				if (totalExistence < global::BulkPurchasePlus.BulkPurchasePlus.threshold)
				{
					result = true;
				}
				break;
			case 3:
				if (CheckOrderAviablility(totalExistence, productID, 1, productComponent) && CheckOrderAviablility(totalExistence, productID, 2, productComponent))
				{
					result = true;
				}
				break;
			case 4:
				if (totalExistence < global::BulkPurchasePlus.BulkPurchasePlus.somethingsomething(NPC_Manager.Instance, productID, productComponent, includeStorage: false) + global::BulkPurchasePlus.BulkPurchasePlus.StorageThreshold.Value)
				{
					result = true;
				}
				break;
			case 5:
				if (totalExistence < global::BulkPurchasePlus.BulkPurchasePlus.somethingsomething(NPC_Manager.Instance, productID, productComponent, includeStorage: false) + (global::BulkPurchasePlus.BulkPurchasePlus.StorageBoxThreshold.Value * productComponent.maxItemsPerBox - productComponent.maxItemsPerBox + 1))
				{
					result = true;
				}
				break;
			case 6:
				if (CheckOrderAviablility(totalExistence, productID, 4, productComponent) && CheckOrderAviablility(totalExistence, productID, 5, productComponent))
				{
					result = true;
				}
				break;
			case 7:
				if (totalExistence < global::BulkPurchasePlus.BulkPurchasePlus.somethingsomething(NPC_Manager.Instance, productID, productComponent, includeStorage: true) - productComponent.maxItemsPerBox + 1)
				{
					result = true;
				}
				break;
			}
			return result;
		}
	}
}