Decompiled source of ShelfSenseAutoOrder v1.4.2

ShelfSenseAutoOrder.dll

Decompiled 14 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using Mirror;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 ShelfSenseAutoOrder
{
	[BepInPlugin("com.shelfsense.supermarkettogether.autoorder", "ShelfSense Auto Order", "1.4.2")]
	public sealed class ShelfSenseAutoOrder : BaseUnityPlugin
	{
		private ConfigEntry<float> moneyFloor;

		private ConfigEntry<float> scanInterval;

		private ConfigEntry<bool> includeNew;

		private ConfigEntry<int> newDelay;

		private ConfigEntry<bool> notificationsEnabled;

		private ConfigEntry<bool> chatSummaryEnabled;

		private ConfigEntry<string> unlockHistory;

		private ConfigEntry<string> baselineHistory;

		private readonly Dictionary<int, int> firstSeenDay = new Dictionary<int, int>();

		private readonly HashSet<int> startingProducts = new HashSet<int>();

		private readonly Dictionary<int, float> pendingOrders = new Dictionary<int, float>();

		private readonly List<string> lastOrderNames = new List<string>();

		private static readonly MethodInfo GetStockMethod = typeof(ManagerBlackboard).GetMethod("GetProductsExistences", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly MethodInfo ChatRpcMethod = typeof(PlayerObjectController).GetMethod("RpcReceiveChatMsg", BindingFlags.Instance | BindingFlags.NonPublic);

		private Rect window = new Rect(35f, 110f, 530f, 620f);

		private Vector2 settingsScroll;

		private GameData activeGame;

		private bool enabledThisRun;

		private bool menuOpen;

		private bool shopReady;

		private bool sawManualActivity;

		private bool manualOrdering;

		private bool initializedStore;

		private float nextScan;

		private float nextManualCheck;

		private float nextUnlockCheck;

		private List<int> scanIds;

		private List<int> chosen;

		private int scanCursor;

		private float scanTotal;

		private float notificationStart;

		private GUIStyle titleStyle;

		private GUIStyle headingStyle;

		private GUIStyle labelStyle;

		private GUIStyle buttonStyle;

		private GUIStyle toggleStyle;

		private GUIStyle sliderStyle;

		private GUIStyle thumbStyle;

		private GUIStyle windowStyle;

		private Texture2D windowTexture;

		private GUIStyle noticeTitleStyle;

		private GUIStyle noticeItemStyle;

		private GUIStyle noticeShadowStyle;

		private string status = "Off. Press F8 to enable.";

		private void Awake()
		{
			moneyFloor = ((BaseUnityPlugin)this).Config.Bind<float>("Ordering", "MoneyFloorV3", 5000f, "Never spend below this amount. Default $5,000.");
			scanInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Ordering", "ScanIntervalSeconds", 10f, "Seconds between scans (5 to 60 in the menu).");
			includeNew = ((BaseUnityPlugin)this).Config.Bind<bool>("New stock", "IncludeNewlyUnlocked", false, "Allow products unlocked after the initial store snapshot.");
			newDelay = ((BaseUnityPlugin)this).Config.Bind<int>("New stock", "WaitStoreDays", 1, "Wait 1, 2, or 3 store days after a new product unlocks.");
			notificationsEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Notifications", "ShowOrderNotifications", true, "Show ordered product names below the day and time HUD.");
			chatSummaryEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Notifications", "SendChatOrderSummaries", true, "Send a short order summary to all players using the game's chat.");
			unlockHistory = ((BaseUnityPlugin)this).Config.Bind<string>("New stock", "UnlockHistory", "", "Internal day tracking for newly unlocked products.");
			baselineHistory = ((BaseUnityPlugin)this).Config.Bind<string>("New stock", "BaselineProducts", "", "Products available when this mod first sees the store.");
			LoadHistory();
			SceneManager.activeSceneChanged += OnActiveSceneChanged;
		}

		private void Update()
		{
			GameData instance = GameData.Instance;
			if (instance != activeGame)
			{
				if (activeGame != null)
				{
					ResetForMarketChange();
				}
				activeGame = instance;
			}
			ProductListing instance2 = ProductListing.Instance;
			if ((Object)(object)instance == (Object)null || !((Behaviour)instance).isActiveAndEnabled || (Object)(object)instance2 == (Object)null || !((Behaviour)instance2).isActiveAndEnabled || instance2.availableProducts == null || (!NetworkServer.active && !NetworkClient.active))
			{
				if (shopReady || menuOpen || enabledThisRun)
				{
					ResetForMarketChange();
				}
				return;
			}
			ManagerBlackboard component = ((Component)instance).GetComponent<ManagerBlackboard>();
			if ((Object)(object)component == (Object)null || !((Behaviour)component).isActiveAndEnabled)
			{
				if (shopReady || menuOpen || enabledThisRun)
				{
					ResetForMarketChange();
				}
				return;
			}
			if (!NetworkServer.active)
			{
				if (shopReady || menuOpen || enabledThisRun)
				{
					ResetForMarketChange();
				}
				return;
			}
			shopReady = true;
			if (Input.GetKeyDown((KeyCode)288))
			{
				menuOpen = !menuOpen;
			}
			if (Input.GetKeyDown((KeyCode)289))
			{
				ToggleOrdering();
			}
			if (Time.unscaledTime >= nextUnlockCheck)
			{
				nextUnlockCheck = Time.unscaledTime + 1f;
				ObserveUnlocks(instance2, instance.gameDay);
			}
			if (!enabledThisRun)
			{
				return;
			}
			if (Time.unscaledTime >= nextManualCheck)
			{
				nextManualCheck = Time.unscaledTime + 0.25f;
				manualOrdering = IsManualOrdering(component);
			}
			if (manualOrdering)
			{
				sawManualActivity = true;
			}
			else if (sawManualActivity)
			{
				sawManualActivity = false;
				nextScan = Time.unscaledTime + 0.25f;
			}
			if (!NetworkServer.active)
			{
				ResetScan();
				status = "Host only: enable on the host.";
				return;
			}
			if (manualOrdering)
			{
				ResetScan();
				status = "Paused while manual ordering is open or listed.";
				return;
			}
			if (scanIds == null)
			{
				if (Time.unscaledTime < nextScan || !initializedStore)
				{
					return;
				}
				if (instance.gameFunds <= moneyFloor.Value)
				{
					status = "Waiting for money above the limit.";
					nextScan = Time.unscaledTime + Mathf.Clamp(scanInterval.Value, 5f, 60f);
					return;
				}
				scanIds = new List<int>(instance2.availableProducts);
				chosen = new List<int>();
				scanCursor = 0;
				scanTotal = 0f;
				status = "Checking stock...";
			}
			try
			{
				ScanBatch(component, instance2, instance);
			}
			catch (Exception ex)
			{
				ResetScan();
				nextScan = Time.unscaledTime + Mathf.Clamp(scanInterval.Value, 5f, 60f);
				status = "Scan failed; see BepInEx log.";
				((BaseUnityPlugin)this).Logger.LogError((object)ex);
			}
		}

		private void ToggleOrdering()
		{
			if (NetworkServer.active)
			{
				enabledThisRun = !enabledThisRun;
				ResetScan();
				nextScan = Time.unscaledTime;
				nextManualCheck = 0f;
				status = (enabledThisRun ? "On. Waiting for scan." : "Off. Press F8 to enable.");
			}
		}

		private void OnActiveSceneChanged(Scene previous, Scene next)
		{
			ResetForMarketChange();
			activeGame = null;
		}

		private void ResetForMarketChange()
		{
			enabledThisRun = false;
			menuOpen = false;
			shopReady = false;
			ResetScan();
			pendingOrders.Clear();
			lastOrderNames.Clear();
			manualOrdering = false;
			sawManualActivity = false;
			initializedStore = false;
			nextManualCheck = 0f;
			nextUnlockCheck = 0f;
			nextScan = 0f;
			status = "Off. Press F8 to enable.";
		}

		private void ResetScan()
		{
			scanIds = null;
			chosen = null;
			scanCursor = 0;
			scanTotal = 0f;
		}

		private bool IsManualOrdering(ManagerBlackboard board)
		{
			if ((Object)(object)board.shoppingListParent != (Object)null && board.shoppingListParent.transform.childCount > 0)
			{
				return true;
			}
			if ((Object)(object)board.tabsOBJ != (Object)null && board.tabsOBJ.activeInHierarchy)
			{
				return true;
			}
			OrderingDevice[] array = Object.FindObjectsOfType<OrderingDevice>();
			foreach (OrderingDevice val in array)
			{
				if (((Behaviour)val).isActiveAndEnabled || ((Object)(object)val.listParentOBJ != (Object)null && val.listParentOBJ.transform.childCount > 0))
				{
					return true;
				}
			}
			return false;
		}

		private void ScanBatch(ManagerBlackboard board, ProductListing listing, GameData game)
		{
			float num = game.gameFunds - Mathf.Max(0f, moneyFloor.Value);
			if (num <= 0f)
			{
				ResetScan();
				nextScan = Time.unscaledTime + Mathf.Clamp(scanInterval.Value, 5f, 60f);
				status = "Waiting for money above the limit.";
				return;
			}
			int num2 = Math.Min(scanCursor + 1, scanIds.Count);
			while (scanCursor < num2)
			{
				int num3 = scanIds[scanCursor];
				if (num3 >= 0 && num3 < listing.productsData.Length && listing.productsData[num3] != null && (startingProducts.Contains(num3) || (includeNew.Value && firstSeenDay.TryGetValue(num3, out var value) && game.gameDay - value >= Mathf.Clamp(newDelay.Value, 1, 3))) && GetStockMethod?.Invoke(board, new object[1] { num3 }) is int[] array && array.Length >= 3)
				{
					float value2;
					if (array[1] != 0 || array[2] != 0)
					{
						pendingOrders.Remove(num3);
					}
					else if (!pendingOrders.TryGetValue(num3, out value2) || !(Time.unscaledTime - value2 < 120f))
					{
						float num4 = PricePerBox(listing, num3);
						if (!(num4 <= 0f) && !float.IsNaN(num4) && !float.IsInfinity(num4) && !(scanTotal + num4 > num + 0.001f))
						{
							chosen.Add(num3);
							scanTotal += num4;
						}
					}
				}
				scanCursor++;
			}
			if (scanCursor >= scanIds.Count)
			{
				FinishScan(board, listing, game);
			}
		}

		private void FinishScan(ManagerBlackboard board, ProductListing listing, GameData game)
		{
			if (IsManualOrdering(board))
			{
				ResetScan();
				manualOrdering = true;
				sawManualActivity = true;
				status = "Paused for a manual order.";
				return;
			}
			float num = game.gameFunds - Mathf.Max(0f, moneyFloor.Value);
			List<int> list = new List<int>();
			float num2 = 0f;
			foreach (int item in chosen)
			{
				float num3 = PricePerBox(listing, item);
				if (num3 > 0f && num2 + num3 <= num + 0.001f)
				{
					list.Add(item);
					num2 += num3;
				}
			}
			ResetScan();
			nextScan = Time.unscaledTime + Mathf.Clamp(scanInterval.Value, 5f, 60f);
			if (list.Count == 0)
			{
				status = "No eligible boxes within the money limit.";
				return;
			}
			foreach (int item2 in list)
			{
				board.AddShoppingListProduct(item2, PricePerBox(listing, item2));
				pendingOrders[item2] = Time.unscaledTime;
			}
			board.shoppingTotalCharge = num2;
			board.BuyCargo();
			RecordOrder(list);
			SendChatSummary(list.Count, num2);
			status = "Ordered " + list.Count + " box" + ((list.Count == 1) ? "" : "es") + " for $" + num2.ToString("0.00") + ".";
		}

		private void SendChatSummary(int boxCount, float total)
		{
			if (!chatSummaryEnabled.Value || !NetworkServer.active || ChatRpcMethod == null)
			{
				return;
			}
			NetworkManager singleton = NetworkManager.singleton;
			CustomNetworkManager val = (CustomNetworkManager)(object)((singleton is CustomNetworkManager) ? singleton : null);
			if ((Object)(object)val == (Object)null || val.GamePlayers == null)
			{
				return;
			}
			PlayerObjectController val2 = null;
			foreach (PlayerObjectController gamePlayer in val.GamePlayers)
			{
				if ((Object)(object)gamePlayer != (Object)null && ((NetworkBehaviour)gamePlayer).isServer)
				{
					val2 = gamePlayer;
					break;
				}
			}
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			int num = Math.Min(4, lastOrderNames.Count);
			List<string> list = new List<string>();
			for (int i = 0; i < num; i++)
			{
				list.Add(lastOrderNames[i]);
			}
			string text = "Ordered " + boxCount + " box" + ((boxCount == 1) ? "" : "es") + " ($" + total.ToString("0.00") + "): " + string.Join(", ", list.ToArray());
			if (lastOrderNames.Count > num)
			{
				text = text + " +" + (lastOrderNames.Count - num) + " more";
			}
			try
			{
				ChatRpcMethod.Invoke(val2, new object[2] { "ShelfSense", text });
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not send order chat summary: " + ex.Message));
			}
		}

		private void RecordOrder(List<int> productIds)
		{
			lastOrderNames.Clear();
			foreach (int productId in productIds)
			{
				string text = null;
				try
				{
					if ((Object)(object)LocalizationManager.instance != (Object)null)
					{
						text = LocalizationManager.instance.GetLocalizationString("product" + productId);
					}
				}
				catch (Exception ex)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not localize product " + productId + ": " + ex.Message));
				}
				if (string.IsNullOrWhiteSpace(text))
				{
					text = "Product #" + productId;
				}
				lastOrderNames.Add(text);
			}
			notificationStart = Time.unscaledTime;
		}

		private static float PricePerBox(ProductListing listing, int id)
		{
			ProductData val = listing.productsData[id];
			if (val.productTier < 0 || val.productTier >= listing.tierInflation.Length)
			{
				return 0f;
			}
			return Mathf.Round(Mathf.Round(val.basePricePerUnit * listing.tierInflation[val.productTier] * 100f) / 100f * (float)val.maxItemsPerBox * 100f) / 100f;
		}

		private void ObserveUnlocks(ProductListing listing, int currentDay)
		{
			if (listing.availableProducts.Count == 0)
			{
				return;
			}
			if (!initializedStore)
			{
				if (string.IsNullOrEmpty(baselineHistory.Value))
				{
					foreach (int availableProduct in listing.availableProducts)
					{
						startingProducts.Add(availableProduct);
					}
					baselineHistory.Value = string.Join(",", listing.availableProducts.ConvertAll((int id) => id.ToString()).ToArray());
				}
				else
				{
					string[] array = baselineHistory.Value.Split(',');
					for (int num = 0; num < array.Length; num++)
					{
						if (int.TryParse(array[num], out var result))
						{
							startingProducts.Add(result);
						}
					}
				}
				initializedStore = true;
			}
			bool flag = false;
			foreach (int availableProduct2 in listing.availableProducts)
			{
				if (!firstSeenDay.ContainsKey(availableProduct2))
				{
					firstSeenDay[availableProduct2] = currentDay;
					flag = true;
				}
			}
			if (flag)
			{
				SaveHistory();
			}
		}

		private void LoadHistory()
		{
			string[] array = unlockHistory.Value.Split(';');
			for (int i = 0; i < array.Length; i++)
			{
				string[] array2 = array[i].Split(':');
				if (array2.Length == 2 && int.TryParse(array2[0], out var result) && int.TryParse(array2[1], out var result2))
				{
					firstSeenDay[result] = result2;
				}
			}
		}

		private void SaveHistory()
		{
			List<string> list = new List<string>();
			foreach (KeyValuePair<int, int> item in firstSeenDay)
			{
				list.Add(item.Key + ":" + item.Value);
			}
			unlockHistory.Value = string.Join(";", list.ToArray());
		}

		private void OnGUI()
		{
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Expected O, but got Unknown
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			if (shopReady && (menuOpen || (notificationsEnabled.Value && lastOrderNames.Count != 0)))
			{
				EnsureStyles();
				if (notificationsEnabled.Value && lastOrderNames.Count > 0)
				{
					DrawNotification();
				}
				if (menuOpen)
				{
					((Rect)(ref window)).width = Mathf.Min(530f, (float)Screen.width - 16f);
					((Rect)(ref window)).height = Mathf.Min(690f, (float)Screen.height - 16f);
					((Rect)(ref window)).x = Mathf.Clamp(((Rect)(ref window)).x, 0f, Mathf.Max(0f, (float)Screen.width - ((Rect)(ref window)).width));
					((Rect)(ref window)).y = Mathf.Clamp(((Rect)(ref window)).y, 0f, Mathf.Max(0f, (float)Screen.height - ((Rect)(ref window)).height));
					window = GUI.Window(773421, window, new WindowFunction(DrawWindow), GUIContent.none, windowStyle);
					((Rect)(ref window)).x = Mathf.Clamp(((Rect)(ref window)).x, 0f, Mathf.Max(0f, (float)Screen.width - ((Rect)(ref window)).width));
					((Rect)(ref window)).y = Mathf.Clamp(((Rect)(ref window)).y, 0f, Mathf.Max(0f, (float)Screen.height - ((Rect)(ref window)).height));
				}
			}
		}

		private void EnsureStyles()
		{
			//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_0021: 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_0034: Expected O, but got Unknown
			//IL_003f: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Expected O, but got Unknown
			//IL_00ab: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Expected O, but got Unknown
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			//IL_00ef: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Expected O, but got Unknown
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Expected O, but got Unknown
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Expected O, but got Unknown
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Expected O, but got Unknown
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Expected O, but got Unknown
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Expected O, but got Unknown
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			if (labelStyle == null)
			{
				titleStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 22,
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)4
				};
				headingStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 19,
					fontStyle = (FontStyle)1
				};
				labelStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 17,
					wordWrap = true
				};
				buttonStyle = new GUIStyle(GUI.skin.button)
				{
					fontSize = 19,
					fontStyle = (FontStyle)1
				};
				toggleStyle = new GUIStyle(GUI.skin.toggle)
				{
					fontSize = 18,
					wordWrap = true
				};
				sliderStyle = new GUIStyle(GUI.skin.horizontalSlider)
				{
					fixedHeight = 22f
				};
				thumbStyle = new GUIStyle(GUI.skin.horizontalSliderThumb)
				{
					fixedWidth = 24f,
					fixedHeight = 24f
				};
				titleStyle.normal.textColor = new Color(0.56f, 0.91f, 0.68f);
				headingStyle.normal.textColor = Color.white;
				labelStyle.normal.textColor = Color.white;
				windowTexture = new Texture2D(1, 1);
				windowTexture.SetPixel(0, 0, new Color(0.07f, 0.1f, 0.12f, 0.55f));
				windowTexture.Apply();
				windowStyle = new GUIStyle(GUI.skin.window);
				windowStyle.normal.background = windowTexture;
				noticeTitleStyle = new GUIStyle(labelStyle)
				{
					fontSize = 18,
					fontStyle = (FontStyle)1
				};
				noticeTitleStyle.normal.textColor = new Color(0.65f, 1f, 0.75f);
				noticeItemStyle = new GUIStyle(labelStyle)
				{
					fontSize = 17,
					wordWrap = false
				};
				noticeShadowStyle = new GUIStyle(noticeItemStyle);
				noticeShadowStyle.normal.textColor = Color.black;
			}
		}

		private void DrawNotification()
		{
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			float num = Time.unscaledTime - notificationStart;
			if (num >= 10f)
			{
				lastOrderNames.Clear();
				return;
			}
			int num2 = Mathf.Min(7, lastOrderNames.Count);
			float num3 = Mathf.Min(390f, (float)Screen.width - 16f);
			string text = "AUTO ORDER  •  " + lastOrderNames.Count + " box" + ((lastOrderNames.Count == 1) ? "" : "es");
			GUI.Label(new Rect(20f, 105f, num3 - 24f, 26f), text, noticeTitleStyle);
			float num4 = (float)Mathf.Max(0, lastOrderNames.Count - 7) * Mathf.Clamp01(num / 8f) * 26f;
			GUI.BeginGroup(new Rect(20f, 132f, num3 - 24f, (float)num2 * 26f));
			Rect val = default(Rect);
			for (int i = 0; i < lastOrderNames.Count; i++)
			{
				float num5 = (float)i * 26f - num4;
				if (!(num5 < -26f) && !(num5 > (float)num2 * 26f))
				{
					string text2 = "• " + lastOrderNames[i];
					((Rect)(ref val))..ctor(0f, num5, num3 - 24f, 25f);
					GUI.Label(new Rect(((Rect)(ref val)).x + 1f, ((Rect)(ref val)).y + 1f, ((Rect)(ref val)).width, ((Rect)(ref val)).height), text2, noticeShadowStyle);
					GUI.Label(val, text2, noticeItemStyle);
				}
			}
			GUI.EndGroup();
		}

		private void OnDestroy()
		{
			if ((Object)(object)windowTexture != (Object)null)
			{
				Object.Destroy((Object)(object)windowTexture);
			}
			SceneManager.activeSceneChanged -= OnActiveSceneChanged;
		}

		private void DrawWindow(int id)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_050d: Unknown result type (might be due to invalid IL or missing references)
			//IL_053d: Unknown result type (might be due to invalid IL or missing references)
			GUI.Label(new Rect(18f, 8f, ((Rect)(ref window)).width - 36f, 34f), "ShelfSense Auto Order", titleStyle);
			float num = Mathf.Max(180f, ((Rect)(ref window)).height - 120f);
			GUILayout.BeginArea(new Rect(22f, 48f, ((Rect)(ref window)).width - 44f, num));
			settingsScroll = GUILayout.BeginScrollView(settingsScroll, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(num) });
			if (GUILayout.Button(enabledThisRun ? "AUTO ORDERING  ON" : "AUTO ORDERING  OFF", buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(42f) }))
			{
				ToggleOrdering();
			}
			GUILayout.Space(12f);
			GUILayout.Label("MONEY TO KEEP", headingStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) });
			GUILayout.Label("Keep at least $" + moneyFloor.Value.ToString("0") + " after an order", labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(27f) });
			float num2 = GUILayout.HorizontalSlider(Mathf.Pow(Mathf.Clamp01(moneyFloor.Value / 100000f), 1f / 3f), 0f, 1f, sliderStyle, thumbStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) });
			float num3 = 100000f * num2 * num2 * num2;
			float num4 = ((num3 < 100f) ? Mathf.Round(num3) : (Mathf.Round(num3 / 10f) * 10f));
			if (num4 != moneyFloor.Value)
			{
				moneyFloor.Value = num4;
			}
			GUILayout.Space(12f);
			GUILayout.Label("SCAN INTERVAL", headingStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) });
			GUILayout.Label("Every " + scanInterval.Value.ToString("0") + " seconds (default 10)", labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(27f) });
			float num5 = Mathf.Round(GUILayout.HorizontalSlider(scanInterval.Value, 5f, 60f, sliderStyle, thumbStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) }));
			if (num5 != scanInterval.Value)
			{
				scanInterval.Value = num5;
			}
			GUILayout.Space(12f);
			GUILayout.Label("NEW STOCK", headingStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) });
			if (GUILayout.Button(includeNew.Value ? "NEW STOCK  ON" : "NEW STOCK  OFF", buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(36f) }))
			{
				includeNew.Value = !includeNew.Value;
			}
			GUILayout.Label("Wait " + newDelay.Value + " store day" + ((newDelay.Value == 1) ? "" : "s") + " after unlocking", labelStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(27f) });
			int num6 = Mathf.RoundToInt(GUILayout.HorizontalSlider((float)newDelay.Value, 1f, 3f, sliderStyle, thumbStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) }));
			if (num6 != newDelay.Value)
			{
				newDelay.Value = num6;
			}
			GUILayout.Space(13f);
			GUILayout.Label("ORDER NOTIFICATIONS", headingStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) });
			if (GUILayout.Button(notificationsEnabled.Value ? "SCREEN OVERLAY  ON" : "SCREEN OVERLAY  OFF", buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(36f) }))
			{
				notificationsEnabled.Value = !notificationsEnabled.Value;
			}
			GUILayout.Space(6f);
			if (GUILayout.Button(chatSummaryEnabled.Value ? "GAME CHAT  ON" : "GAME CHAT  OFF", buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(36f) }))
			{
				chatSummaryEnabled.Value = !chatSummaryEnabled.Value;
			}
			GUILayout.EndScrollView();
			GUILayout.EndArea();
			GUI.Label(new Rect(22f, ((Rect)(ref window)).height - 57f, ((Rect)(ref window)).width - 44f, 46f), status, labelStyle);
			GUI.DragWindow(new Rect(0f, 0f, ((Rect)(ref window)).width, 43f));
		}
	}
}