Decompiled source of SellMyScrap v1.1.4

SellMyScrap.dll

Decompiled 2 years 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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Newtonsoft.Json;
using SellMyScrap.Patches;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("SellMyScrap")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SellMyScrap")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("91c95eff-85f3-4a95-b208-2c4de804980b")]
[assembly: AssemblyFileVersion("1.1.4.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.1.4.0")]
namespace SellMyScrap
{
	internal class ConfigurationController
	{
		private ConfigEntry<bool> SellGiftsCfg;

		private ConfigEntry<bool> SellShotgunsCfg;

		private ConfigEntry<bool> SellAmmoCfg;

		private ConfigEntry<bool> SellHomemadeFlashbangCfg;

		private ConfigEntry<bool> SellPicklesCfg;

		private ConfigEntry<string> DontSellListJsonCfg;

		private ConfigEntry<bool> ShowFoundItemsCfg;

		private ConfigEntry<int> ShowFoundItemsLimitCfg;

		private ConfigEntry<bool> AlignFoundItemsPriceCfg;

		internal bool SellGifts
		{
			get
			{
				return SellGiftsCfg.Value;
			}
			set
			{
				SellGiftsCfg.Value = value;
			}
		}

		internal bool SellShotguns
		{
			get
			{
				return SellShotgunsCfg.Value;
			}
			set
			{
				SellShotgunsCfg.Value = value;
			}
		}

		internal bool SellAmmo
		{
			get
			{
				return SellAmmoCfg.Value;
			}
			set
			{
				SellAmmoCfg.Value = value;
			}
		}

		internal bool SellHomemadeFlashbang
		{
			get
			{
				return SellHomemadeFlashbangCfg.Value;
			}
			set
			{
				SellHomemadeFlashbangCfg.Value = value;
			}
		}

		internal bool SellPickles
		{
			get
			{
				return SellPicklesCfg.Value;
			}
			set
			{
				SellPicklesCfg.Value = value;
			}
		}

		internal string[] DontSellListJson
		{
			get
			{
				return JsonConvert.DeserializeObject<string[]>(DontSellListJsonCfg.Value);
			}
			set
			{
				DontSellListJsonCfg.Value = JsonConvert.SerializeObject((object)value);
			}
		}

		internal bool ShowFoundItems
		{
			get
			{
				return ShowFoundItemsCfg.Value;
			}
			set
			{
				ShowFoundItemsCfg.Value = value;
			}
		}

		internal int ShowFoundItemsLimit
		{
			get
			{
				return ShowFoundItemsLimitCfg.Value;
			}
			set
			{
				ShowFoundItemsLimitCfg.Value = value;
			}
		}

		internal bool AlignFoundItemsPrice
		{
			get
			{
				return AlignFoundItemsPriceCfg.Value;
			}
			set
			{
				AlignFoundItemsPriceCfg.Value = value;
			}
		}

		public ConfigurationController(ConfigFile Config)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Expected O, but got Unknown
			//IL_00ea: Expected O, but got Unknown
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Expected O, but got Unknown
			//IL_0116: Expected O, but got Unknown
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Expected O, but got Unknown
			//IL_0143: Expected O, but got Unknown
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Expected O, but got Unknown
			//IL_016f: Expected O, but got Unknown
			SellGiftsCfg = Config.Bind<bool>(new ConfigDefinition("Sell Settings", "sellGifts"), false, (ConfigDescription)null);
			SellShotgunsCfg = Config.Bind<bool>(new ConfigDefinition("Sell Settings", "sellShotguns"), false, (ConfigDescription)null);
			SellAmmoCfg = Config.Bind<bool>(new ConfigDefinition("Sell Settings", "sellAmmo"), false, (ConfigDescription)null);
			SellHomemadeFlashbangCfg = Config.Bind<bool>(new ConfigDefinition("Sell Settings", "sellHomemadeFlashbang"), false, (ConfigDescription)null);
			SellPicklesCfg = Config.Bind<bool>(new ConfigDefinition("Sell Settings", "sellPickles"), true, (ConfigDescription)null);
			string text = "JSON array of item names to not sell.\n";
			text += "Item names are not case-sensitive.\n";
			text += "https://www.w3schools.com/js/js_json_arrays.asp\n\n";
			text += "Example: [\"Gift\", \"Shotgun\", \"Ammo\"]\n";
			DontSellListJsonCfg = Config.Bind<string>(new ConfigDefinition("Advanced Sell Settings", "dontSellListJson"), "[]", new ConfigDescription(text, (AcceptableValueBase)null, Array.Empty<object>()));
			ShowFoundItemsCfg = Config.Bind<bool>(new ConfigDefinition("Confirmation Settings", "showFoundItems"), true, new ConfigDescription("Show found items on the confirmation screen.", (AcceptableValueBase)null, Array.Empty<object>()));
			ShowFoundItemsLimitCfg = Config.Bind<int>(new ConfigDefinition("Confirmation Settings", "showFoundItemsLimit"), 100, new ConfigDescription("Won't show founds items if the total item count is over the limit.", (AcceptableValueBase)null, Array.Empty<object>()));
			AlignFoundItemsPriceCfg = Config.Bind<bool>(new ConfigDefinition("Confirmation Settings", "alignFoundItemsPrice"), true, new ConfigDescription("Align all prices of found items on the confirmation screen. This might cost more performance.", (AcceptableValueBase)null, Array.Empty<object>()));
		}
	}
	[BepInPlugin("Zehs.SellMyScrap", "Sell My Scrap", "1.1.4")]
	public class SellMyScrapBase : BaseUnityPlugin
	{
		private const string modGUID = "Zehs.SellMyScrap";

		private const string modName = "Sell My Scrap";

		private const string modVersion = "1.1.4";

		private readonly Harmony harmony = new Harmony("Zehs.SellMyScrap");

		internal static SellMyScrapBase Instance;

		internal static ManualLogSource mls;

		internal ConfigurationController ConfigManager;

		public SellRequest sellRequest;

		public ScrapToSell scrapToSell;

		public string[] dontSellList;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Zehs.SellMyScrap");
			mls.LogInfo((object)"Sell My Scrap has awoken!");
			harmony.PatchAll(typeof(TerminalPatch));
			ConfigManager = new ConfigurationController(((BaseUnityPlugin)this).Config);
			dontSellList = Instance.ConfigManager.DontSellListJson;
		}

		public ScrapToSell GetScrapToSell(int amount, GameObject ship)
		{
			if (amount == -1)
			{
				scrapToSell = new ScrapToSell(GetScrapFromShip(ship));
				return scrapToSell;
			}
			scrapToSell = ScrapCalculator.GetScrapToSell(GetScrapFromShip(ship), amount, StartOfRound.Instance.companyBuyingRate);
			return scrapToSell;
		}

		public void RequestSell(int amount, GameObject ship, DepositItemsDesk depositItemsDesk)
		{
			if (scrapToSell == null || scrapToSell.value != amount)
			{
				GetScrapToSell(amount, ship);
			}
			PerformSell(scrapToSell.scrap, depositItemsDesk);
			scrapToSell = null;
		}

		public void RequestSellAll(GameObject ship, DepositItemsDesk depositItemsDesk)
		{
			PerformSell(GetScrapFromShip(ship), depositItemsDesk);
		}

		public static List<GrabbableObject> GetScrapFromShip(GameObject ship)
		{
			GrabbableObject[] componentsInChildren = ship.GetComponentsInChildren<GrabbableObject>();
			List<GrabbableObject> list = new List<GrabbableObject>();
			foreach (GrabbableObject item in componentsInChildren)
			{
				if (IsItemAllowedScrap(item))
				{
					list.Add(item);
				}
			}
			return list;
		}

		public static bool IsItemAllowedScrap(GrabbableObject item)
		{
			if (!item.itemProperties.isScrap)
			{
				return false;
			}
			if (item.isPocketed)
			{
				return false;
			}
			if (item.isHeld)
			{
				return false;
			}
			string itemName = item.itemProperties.itemName;
			if (itemName == "Gift" && !Instance.ConfigManager.SellGifts)
			{
				return false;
			}
			if (itemName == "Shotgun" && !Instance.ConfigManager.SellShotguns)
			{
				return false;
			}
			if (itemName == "Ammo" && !Instance.ConfigManager.SellAmmo)
			{
				return false;
			}
			if (itemName == "Homemade flashbang" && !Instance.ConfigManager.SellHomemadeFlashbang)
			{
				return false;
			}
			if (itemName == "Jar of pickles" && !Instance.ConfigManager.SellPickles)
			{
				return false;
			}
			for (int i = 0; i < Instance.dontSellList.Length; i++)
			{
				if (itemName.ToLower().Contains(Instance.dontSellList[i].ToLower()))
				{
					return false;
				}
			}
			return true;
		}

		public static void PerformSell(List<GrabbableObject> scrap, DepositItemsDesk depositItemsDesk)
		{
			Instance.scrapToSell = null;
			scrap.ForEach(delegate(GrabbableObject item)
			{
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				((Component)item).transform.parent = ((Component)depositItemsDesk.deskObjectsContainer).transform;
				depositItemsDesk.AddObjectToDeskServerRpc(NetworkObjectReference.op_Implicit(((Component)item).gameObject.GetComponent<NetworkObject>()));
			});
			depositItemsDesk.SellItemsOnServer();
		}
	}
	internal class ScrapCalculator
	{
		public static ScrapToSell GetScrapToSell(List<GrabbableObject> scrap, int quota, float rate)
		{
			int num = (int)((float)quota / rate);
			int num2 = 0;
			List<GrabbableObject> list = new List<GrabbableObject>();
			while (true)
			{
				GrabbableObject highestItem = GetHighestItem(scrap, num - num2);
				if ((Object)(object)highestItem == (Object)null)
				{
					break;
				}
				list.Add(highestItem);
				scrap.Remove(highestItem);
				num2 += highestItem.scrapValue;
			}
			if (num - num2 > 0)
			{
				GrabbableObject lowestItem = GetLowestItem(scrap);
				if ((Object)(object)lowestItem != (Object)null)
				{
					list.Add(lowestItem);
					scrap.Remove(lowestItem);
					num2 += lowestItem.scrapValue;
				}
			}
			if (num2 == 0 || scrap.Count == 0)
			{
				return new ScrapToSell(list);
			}
			int difference = num2 - num;
			GrabbableObject replacement = null;
			GrabbableObject previous = null;
			list.ForEach(delegate(GrabbableObject item)
			{
				if (!((Object)(object)replacement != (Object)null))
				{
					GrabbableObject exactItem = GetExactItem(scrap, item.scrapValue - difference);
					if ((Object)(object)exactItem != (Object)null)
					{
						previous = item;
						replacement = exactItem;
					}
				}
			});
			if ((Object)(object)replacement != (Object)null)
			{
				list.Add(replacement);
				list.Remove(previous);
				scrap.Remove(replacement);
				return new ScrapToSell(list);
			}
			return new ScrapToSell(list);
		}

		public static GrabbableObject GetExactItem(List<GrabbableObject> scrap, int target)
		{
			GrabbableObject selected = null;
			scrap.ForEach(delegate(GrabbableObject item)
			{
				if (!((Object)(object)selected != (Object)null) && item.scrapValue == target)
				{
					selected = item;
				}
			});
			return selected;
		}

		public static GrabbableObject GetHighestItem(List<GrabbableObject> scrap, int target)
		{
			bool search = true;
			GrabbableObject selected = null;
			scrap.ForEach(delegate(GrabbableObject item)
			{
				if (search)
				{
					if ((Object)(object)selected == (Object)null)
					{
						if (item.scrapValue <= target)
						{
							selected = item;
						}
					}
					else if (item.scrapValue > selected.scrapValue && item.scrapValue <= target)
					{
						selected = item;
					}
					else if (selected.scrapValue == target)
					{
						search = false;
					}
				}
			});
			return selected;
		}

		public static GrabbableObject GetLowestItem(List<GrabbableObject> scrap)
		{
			GrabbableObject selected = null;
			scrap.ForEach(delegate(GrabbableObject item)
			{
				if ((Object)(object)selected == (Object)null)
				{
					selected = item;
				}
				else if (item.scrapValue < selected.scrapValue)
				{
					selected = item;
				}
			});
			return selected;
		}
	}
	public class ScrapToSell
	{
		public List<GrabbableObject> scrap;

		public int value;

		public ScrapToSell(List<GrabbableObject> scrap)
		{
			this.scrap = scrap;
			value = 0;
			scrap.ForEach(delegate(GrabbableObject item)
			{
				value += item.scrapValue;
			});
		}

		public string GetListAsString()
		{
			ScrapItemStackManager itemStackManager = new ScrapItemStackManager();
			scrap.ForEach(delegate(GrabbableObject item)
			{
				itemStackManager.AddItem(item.itemProperties.itemName, item.scrapValue);
			});
			List<ScrapItemStack> sortedItemStackList = itemStackManager.GetSortedItemStackList();
			if (SellMyScrapBase.Instance.ConfigManager.AlignFoundItemsPrice)
			{
				return GetAlignedSortedListAsString(sortedItemStackList);
			}
			return GetNormalSortedListAsString(sortedItemStackList);
		}

		private string GetNormalSortedListAsString(List<ScrapItemStack> sortedItemStacks)
		{
			string result = string.Empty;
			sortedItemStacks.ForEach(delegate(ScrapItemStack item)
			{
				result += $"{item.name} (x{item.amount}) : ${item.value}\n";
			});
			return result.Trim();
		}

		private string GetAlignedSortedListAsString(List<ScrapItemStack> sortedItemStacks)
		{
			PricedLogMessageManager logMessageManager = new PricedLogMessageManager();
			sortedItemStacks.ForEach(delegate(ScrapItemStack item)
			{
				logMessageManager.Add($"{item.name} (x{item.amount}) :", item.value);
			});
			List<PricedLogMessage> sortedLogMessages = logMessageManager.GetSortedLogMessages();
			string result = string.Empty;
			sortedLogMessages.ForEach(delegate(PricedLogMessage item)
			{
				result = result + item.GetMessage() + "\n";
			});
			return result.Trim();
		}
	}
	public class ScrapItemStackManager
	{
		public List<ScrapItemStack> itemStacks = new List<ScrapItemStack>();

		public void AddItem(string name, int value)
		{
			int num = -1;
			for (int i = 0; i < itemStacks.Count; i++)
			{
				if (name == itemStacks[i].name)
				{
					num = i;
				}
			}
			if (num == -1)
			{
				itemStacks.Add(new ScrapItemStack(name, 1, value));
			}
			else
			{
				itemStacks[num].AddItem(value);
			}
		}

		public List<ScrapItemStack> GetSortedItemStackList()
		{
			List<ScrapItemStack> list = new List<ScrapItemStack>(itemStacks);
			List<ScrapItemStack> list2 = new List<ScrapItemStack>();
			while (list.Count != 0)
			{
				ScrapItemStack highestItemStack = GetHighestItemStack(list);
				list2.Add(highestItemStack);
				list.Remove(highestItemStack);
			}
			return list2;
		}

		public ScrapItemStack GetHighestItemStack(List<ScrapItemStack> _itemStacks)
		{
			ScrapItemStack highestItemStack = null;
			_itemStacks.ForEach(delegate(ScrapItemStack itemStack)
			{
				if (highestItemStack == null)
				{
					highestItemStack = itemStack;
				}
				else if (itemStack.value > highestItemStack.value)
				{
					highestItemStack = itemStack;
				}
			});
			return highestItemStack;
		}
	}
	public class ScrapItemStack
	{
		public string name;

		public int amount;

		public int value;

		public ScrapItemStack(string name, int amount, int value)
		{
			this.name = name;
			this.amount = amount;
			this.value = value;
		}

		public void AddItem(int value)
		{
			amount++;
			this.value += value;
		}
	}
	public class PricedLogMessageManager
	{
		private List<PricedLogMessage> logMessages = new List<PricedLogMessage>();

		public void Add(string message, int price)
		{
			logMessages.Add(new PricedLogMessage(message, price));
		}

		public List<PricedLogMessage> GetSortedLogMessages()
		{
			PricedLogMessage longestLogMessage = GetLongestLogMessage(logMessages);
			List<PricedLogMessage> list = new List<PricedLogMessage>(logMessages);
			list.ForEach(delegate(PricedLogMessage logMessage)
			{
				if (logMessage != longestLogMessage)
				{
					logMessage.SetOffset(longestLogMessage.message.Length);
				}
			});
			return list;
		}

		public PricedLogMessage GetLongestLogMessage(List<PricedLogMessage> _logMessages)
		{
			PricedLogMessage longestLogMessage = null;
			_logMessages.ForEach(delegate(PricedLogMessage logMessage)
			{
				if (longestLogMessage == null)
				{
					longestLogMessage = logMessage;
				}
				else if (logMessage.message.Length > longestLogMessage.message.Length)
				{
					longestLogMessage = logMessage;
				}
			});
			return longestLogMessage;
		}
	}
	public class PricedLogMessage
	{
		public string message;

		public int price;

		public int offset;

		public PricedLogMessage(string message, int price)
		{
			this.message = message;
			this.price = price;
			offset = 0;
		}

		public void SetOffset(int maxLength)
		{
			offset = maxLength - message.Length;
		}

		public string GetMessage()
		{
			string text = message;
			for (int i = 0; i < offset; i++)
			{
				text += " ";
			}
			return text + $" ${price}";
		}
	}
	public enum SellType
	{
		None = -1,
		SellAmount,
		SellQuota,
		SellAll
	}
	public class SellRequest
	{
		public SellType type;

		public int amount;

		public int requestedAmount;

		public bool awaitingConfirmation;

		public SellRequest(SellType type, int amount, int requestedAmount, bool awaitingConfirmation)
		{
			this.type = type;
			this.amount = amount;
			this.requestedAmount = requestedAmount;
			this.awaitingConfirmation = awaitingConfirmation;
		}
	}
}
namespace SellMyScrap.Patches
{
	[HarmonyPatch(typeof(Terminal))]
	internal class TerminalPatch
	{
		[HarmonyPatch("ParsePlayerSentence")]
		[HarmonyPrefix]
		private static bool ParsePlayerSentencePatch(Terminal __instance, ref TerminalNode __result)
		{
			string[] array = __instance.screenText.text.Split(new char[1] { '\n' });
			if (array.Length == 0)
			{
				return true;
			}
			string[] array2 = array.Last().Trim().ToLower()
				.Split(new char[1] { ' ' });
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			if ((Object)(object)localPlayerController == (Object)null)
			{
				return true;
			}
			StartOfRound playersManager = localPlayerController.playersManager;
			if ((Object)(object)playersManager == (Object)null)
			{
				return true;
			}
			SellType sellType = SellType.None;
			if (array2[0] == "sell")
			{
				sellType = SellType.SellAmount;
			}
			if (array2[0] == "sell-quota")
			{
				sellType = SellType.SellQuota;
			}
			if (array2[0] == "sell-all")
			{
				sellType = SellType.SellAll;
			}
			if (sellType != SellType.None)
			{
				if (!GameNetworkManager.Instance.isHostingGame)
				{
					__result = CreateTerminalNode("Only the host can sell!\n\n");
					return false;
				}
				if (!IsAtTheCompany(playersManager) || playersManager.inShipPhase || playersManager.travellingToNewLevel)
				{
					__result = CreateTerminalNode("You must be at The Company building to sell your scrap!\n\n");
					return false;
				}
			}
			switch (sellType)
			{
			case SellType.SellAmount:
			{
				if (array2.Length < 2)
				{
					__result = CreateTerminalNode("Please specify an amount to sell.\n\nUsage: sell <amount>\n\n");
					return false;
				}
				int result = 0;
				int.TryParse(array2[1], out result);
				if (result <= 0)
				{
					__result = CreateTerminalNode("ERROR! Sell amount is invalid.\n\nUsage: sell <amount>\n\n");
					return false;
				}
				GameObject ship3 = GameObject.Find("/Environment/HangarShip");
				ScrapToSell scrapToSell2 = SellMyScrapBase.Instance.GetScrapToSell(result, ship3);
				int num2 = (int)(100f * playersManager.companyBuyingRate);
				if (scrapToSell2.scrap.Count == 0)
				{
					__result = CreateTerminalNode("No items found to sell.\n\n");
					return false;
				}
				string text2 = $"Found {scrapToSell2.scrap.Count} items with a total of ${scrapToSell2.value} / ${result} selling at %{num2}\n\n";
				if (SellMyScrapBase.Instance.ConfigManager.ShowFoundItems)
				{
					text2 = ((scrapToSell2.scrap.Count > SellMyScrapBase.Instance.ConfigManager.ShowFoundItemsLimit) ? (text2 + "[Too many items to show]\n\n") : (text2 + scrapToSell2.GetListAsString() + "\n\n"));
				}
				text2 += "Please CONFIRM or DENY.\n\n";
				__result = CreateTerminalNode(text2);
				SellMyScrapBase.Instance.sellRequest = new SellRequest(SellType.SellAmount, scrapToSell2.value, result, awaitingConfirmation: true);
				return false;
			}
			case SellType.SellQuota:
			{
				int num3 = TimeOfDay.Instance.profitQuota - TimeOfDay.Instance.quotaFulfilled;
				if (num3 <= 0)
				{
					__result = CreateTerminalNode("Quota has already been fulfilled.\n\n");
					return false;
				}
				GameObject ship4 = GameObject.Find("/Environment/HangarShip");
				ScrapToSell scrapToSell3 = SellMyScrapBase.Instance.GetScrapToSell(num3, ship4);
				int num4 = (int)(100f * playersManager.companyBuyingRate);
				if (scrapToSell3.scrap.Count == 0)
				{
					__result = CreateTerminalNode("No items found to sell.\n\n");
					return false;
				}
				string text3 = $"Found {scrapToSell3.scrap.Count} items with a total of ${scrapToSell3.value} / ${num3} selling at %{num4}\n\n";
				if (SellMyScrapBase.Instance.ConfigManager.ShowFoundItems)
				{
					text3 = ((scrapToSell3.scrap.Count > SellMyScrapBase.Instance.ConfigManager.ShowFoundItemsLimit) ? (text3 + "[Too many items to show]\n\n") : (text3 + scrapToSell3.GetListAsString() + "\n\n"));
				}
				text3 += "Please CONFIRM or DENY.\n\n";
				__result = CreateTerminalNode(text3);
				SellMyScrapBase.Instance.sellRequest = new SellRequest(SellType.SellQuota, scrapToSell3.value, num3, awaitingConfirmation: true);
				return false;
			}
			case SellType.SellAll:
			{
				GameObject ship2 = GameObject.Find("/Environment/HangarShip");
				ScrapToSell scrapToSell = SellMyScrapBase.Instance.GetScrapToSell(-1, ship2);
				int num = (int)(100f * playersManager.companyBuyingRate);
				if (scrapToSell.scrap.Count == 0)
				{
					__result = CreateTerminalNode("No items found to sell.\n\n");
					return false;
				}
				string text = $"Found {scrapToSell.scrap.Count} items with a total of ${scrapToSell.value} selling at %{num}\n\n";
				if (SellMyScrapBase.Instance.ConfigManager.ShowFoundItems)
				{
					text = ((scrapToSell.scrap.Count > SellMyScrapBase.Instance.ConfigManager.ShowFoundItemsLimit) ? (text + "[Too many items to show]\n\n") : (text + scrapToSell.GetListAsString() + "\n\n"));
				}
				text += "Please CONFIRM or DENY.\n\n";
				__result = CreateTerminalNode(text);
				SellMyScrapBase.Instance.sellRequest = new SellRequest(SellType.SellAll, scrapToSell.value, -1, awaitingConfirmation: true);
				return false;
			}
			case SellType.None:
			{
				if (SellMyScrapBase.Instance.sellRequest == null || !SellMyScrapBase.Instance.sellRequest.awaitingConfirmation)
				{
					break;
				}
				DepositItemsDesk val = Object.FindObjectOfType<DepositItemsDesk>();
				if ((Object)(object)val == (Object)null)
				{
					SellMyScrapBase.Instance.sellRequest = null;
					SellMyScrapBase.Instance.scrapToSell = null;
					__result = CreateTerminalNode("ERROR! Cannot find DepositItemsDesk. Sell aborted.\n\n");
					return false;
				}
				if ("confirm".Contains(array2[0].ToLower()))
				{
					SellRequest sellRequest = SellMyScrapBase.Instance.sellRequest;
					GameObject ship = GameObject.Find("/Environment/HangarShip");
					if (sellRequest.type == SellType.SellAmount)
					{
						__result = CreateTerminalNode($"Sell confirmed. Processing ${sellRequest.amount}...\n\n");
						SellMyScrapBase.Instance.RequestSell(sellRequest.amount, ship, val);
					}
					if (sellRequest.type == SellType.SellQuota)
					{
						__result = CreateTerminalNode($"Sell confirmed. Processing ${sellRequest.amount}...\n\n");
						SellMyScrapBase.Instance.RequestSell(sellRequest.amount, ship, val);
					}
					if (sellRequest.type == SellType.SellAll)
					{
						__result = CreateTerminalNode($"Sell confirmed. Processing ${sellRequest.amount}...\n\n");
						SellMyScrapBase.Instance.RequestSellAll(ship, val);
					}
					return false;
				}
				if ("deny".Contains(array2[0].ToLower()))
				{
					__result = CreateTerminalNode("Sell aborted.\n\n");
					return false;
				}
				SellMyScrapBase.Instance.sellRequest = null;
				break;
			}
			}
			return true;
		}

		private static bool IsAtTheCompany(StartOfRound playersManager)
		{
			int num = 3;
			return playersManager.currentLevel.levelID == num;
		}

		private static TerminalNode CreateTerminalNode(string message)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			return new TerminalNode
			{
				displayText = message,
				clearPreviousText = true
			};
		}
	}
}