Decompiled source of SellFromTerminal v1.1.2

SellFromTerminal.dll

Decompiled 11 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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 System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using SellFromTerminal.NetcodePatcher;
using SellFromTerminal.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("SellFromTerminal")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SellFromTerminal")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("36aed39a-dd38-40b0-80d7-1eb3e1b6681b")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
namespace SellFromTerminal
{
	[HarmonyPatch]
	public class NetworkHandler : NetworkBehaviour
	{
		public static NetworkHandler Instance { get; private set; }

		private int SellScrap(GrabbableObject scrap)
		{
			int num = scrap.ActualSellValue();
			Terminal terminalScript = HUDManager.Instance.terminalScript;
			terminalScript.groupCredits += num;
			EndOfGameStats gameStats = StartOfRound.Instance.gameStats;
			gameStats.scrapValueCollected += num;
			TimeOfDay instance = TimeOfDay.Instance;
			instance.quotaFulfilled += num;
			TimeOfDay.Instance.UpdateProfitQuotaCurrentTime();
			if (NetworkManager.Singleton.IsServer)
			{
				((Component)scrap).GetComponent<NetworkObject>().Despawn(true);
			}
			if ((Object)(object)scrap.radarIcon != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)scrap.radarIcon).gameObject);
			}
			return num;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "SetPlanetsWeather")]
		public static void Test()
		{
			SellFromTerminalBase.Log.LogInfo((object)"SET WEATHER!!!!");
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(TimeOfDay), "OnDayChanged")]
		public static void Test2()
		{
			SellFromTerminalBase.Log.LogInfo((object)"SET WEATHER2222!!!!");
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "PassTimeToNextDay")]
		public static void Test3()
		{
			SellFromTerminalBase.Log.LogInfo((object)"SET WEATHER333333333333!!!!");
			SellFromTerminalBase.Log.LogInfo((object)StartOfRound.Instance.isChallengeFile);
		}

		[ClientRpc]
		public void SellAllScrapClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: 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_006d: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3498428421u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3498428421u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage != 2 || (!networkManager.IsClient && !networkManager.IsHost))
			{
				return;
			}
			int num = 0;
			int num2 = 0;
			foreach (GrabbableObject item in ScrapHelpers.GetAllScrapInShip())
			{
				int num3 = SellScrap(item);
				num2 += num3;
				num++;
			}
			HUDManager.Instance.DisplayGlobalNotification($"Sold {num} pieces of scrap for {num2}!");
			TerminalPatch.numScrapSold = num;
			TerminalPatch.sellScrapFor = num2;
		}

		[ClientRpc]
		public void SellAmountClientRpc(int amount)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: 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_006d: 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)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(419213531u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, amount);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 419213531u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage != 2 || (!networkManager.IsClient && !networkManager.IsHost))
			{
				return;
			}
			int num = 0;
			int num2 = 0;
			foreach (GrabbableObject item in ScrapHelpers.GetScrapForAmount(amount))
			{
				int num3 = SellScrap(item);
				num2 += num3;
				num++;
			}
			HUDManager.Instance.DisplayGlobalNotification($"Sold {num} pieces of scrap for {num2}!");
			TerminalPatch.numScrapSold = num;
			TerminalPatch.sellScrapFor = num2;
		}

		[ServerRpc(RequireOwnership = false)]
		public void SellAllScrapServerRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: 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_006d: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(402788919u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 402788919u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					SellAllScrapClientRpc();
				}
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void SellAmountServerRpc(int amount)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: 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_006d: 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)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(3641963246u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, amount);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 3641963246u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					SellAmountClientRpc(amount);
				}
			}
		}

		public override void OnNetworkSpawn()
		{
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				NetworkHandler instance = Instance;
				if (instance != null)
				{
					((Component)instance).gameObject.GetComponent<NetworkObject>().Despawn(true);
				}
			}
			Instance = this;
			((NetworkBehaviour)this).OnNetworkSpawn();
		}

		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_NetworkHandler()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(3498428421u, new RpcReceiveHandler(__rpc_handler_3498428421));
			NetworkManager.__rpc_func_table.Add(419213531u, new RpcReceiveHandler(__rpc_handler_419213531));
			NetworkManager.__rpc_func_table.Add(402788919u, new RpcReceiveHandler(__rpc_handler_402788919));
			NetworkManager.__rpc_func_table.Add(3641963246u, new RpcReceiveHandler(__rpc_handler_3641963246));
		}

		private static void __rpc_handler_3498428421(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((NetworkHandler)(object)target).SellAllScrapClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_419213531(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int amount = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref amount);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((NetworkHandler)(object)target).SellAmountClientRpc(amount);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_402788919(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((NetworkHandler)(object)target).SellAllScrapServerRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3641963246(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int amount = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref amount);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((NetworkHandler)(object)target).SellAmountServerRpc(amount);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "NetworkHandler";
		}
	}
	[BepInPlugin("stormytuna.SellFromTerminal", "SellFromTerminal", "1.1.2")]
	public class SellFromTerminalBase : BaseUnityPlugin
	{
		public const string ModGUID = "stormytuna.SellFromTerminal";

		public const string ModName = "SellFromTerminal";

		public const string ModVersion = "1.1.2";

		public static ManualLogSource Log = Logger.CreateLogSource("stormytuna.SellFromTerminal");

		public static SellFromTerminalBase Instance;

		public static AssetBundle CustomAssets;

		private readonly Harmony harmony = new Harmony("stormytuna.SellFromTerminal");

		public static ConfigEntry<bool> ConfigCanSellShotgunAndShells;

		public static ConfigEntry<bool> ConfigCanSellGifts;

		public static ConfigEntry<bool> ConfigCanSellPickles;

		public static ConfigEntry<int> ConfigExactAmountAllowance;

		private void Awake()
		{
			if (Instance == null)
			{
				Instance = this;
			}
			Log.LogInfo((object)"Sell From Terminal has awoken!");
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			foreach (Type type in types)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo in methods)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			CustomAssets = AssetBundle.LoadFromFile(Path.Combine(directoryName, "sellfromterminalbundle"));
			if (CustomAssets == null)
			{
				Log.LogError((object)"Failed to load custom assets!");
			}
			LoadConfigs();
			harmony.PatchAll();
		}

		private void LoadConfigs()
		{
			ConfigCanSellShotgunAndShells = ((BaseUnityPlugin)this).Config.Bind<bool>("Can Sell", "CanSellShotgunAndShells", false, "Whether or not to allow the 'Shotgun' and 'Ammo' scrap to be sold");
			ConfigCanSellGifts = ((BaseUnityPlugin)this).Config.Bind<bool>("Can Sell", "CanSellGifts", false, "Whether or not to allow the 'Gift' item to be sold");
			ConfigCanSellPickles = ((BaseUnityPlugin)this).Config.Bind<bool>("Can Sell", "CanSellPickles", true, "Whether or not to allow the 'Jar of Pickles' item to be sold");
			ConfigExactAmountAllowance = ((BaseUnityPlugin)this).Config.Bind<int>("Misc", "ExactAmountAllowance", 0, "The amount of allowance over the specified amount to grant. Ex: Setting this to 5 will make 'sell 50' also sell at 51, 52, 53, 54 and 55");
		}
	}
	public static class ScrapHelpers
	{
		public static IEnumerable<GrabbableObject> GetAllScrapInShip()
		{
			GameObject val = GameObject.Find("Environment/HangarShip");
			GrabbableObject[] componentsInChildren = val.GetComponentsInChildren<GrabbableObject>();
			return componentsInChildren.Where((GrabbableObject go) => go.CanSellItem());
		}

		public static IEnumerable<GrabbableObject> GetScrapForAmount(int amount)
		{
			int totalScrapValueInShip = GetTotalScrapValueInShip();
			if (totalScrapValueInShip < amount)
			{
				SellFromTerminalBase.Log.LogInfo((object)$"Cannot reach required amount of {amount}! Total value: {totalScrapValueInShip}, total num scrap: {CountAllScrapInShip()}");
				return Enumerable.Empty<GrabbableObject>();
			}
			int count = 0;
			List<GrabbableObject> list = (from scrap in GetAllScrapInShip()
				orderby scrap.scrapValue descending, ((NetworkBehaviour)scrap).NetworkObjectId
				select scrap).ToList();
			List<GrabbableObject> list2 = new List<GrabbableObject>();
			int amountNeeded;
			GrabbableObject val;
			for (amountNeeded = amount; amountNeeded > 420; amountNeeded -= val.ActualSellValue())
			{
				val = list[count++];
				list2.Add(val);
			}
			list = (from scrap in list.Skip(count)
				orderby scrap.scrapValue, ((NetworkBehaviour)scrap).NetworkObjectId
				select scrap).ToList();
			count = 0;
			GrabbableObject val4;
			for (; amountNeeded > 0; amountNeeded -= val4.ActualSellValue())
			{
				List<(GrabbableObject, GrabbableObject, int)> list3 = new List<(GrabbableObject, GrabbableObject, int)>();
				for (int i = count; i < list.Count; i++)
				{
					for (int j = i + 1; j < list.Count; j++)
					{
						list3.Add((list[i], list[j], list[i].ActualSellValue() + list[j].ActualSellValue()));
					}
				}
				(GrabbableObject, GrabbableObject, int) tuple = list3.FirstOrDefault<(GrabbableObject, GrabbableObject, int)>(((GrabbableObject first, GrabbableObject second, int sum) sum) => sum.sum >= amountNeeded && sum.sum <= amountNeeded + SellFromTerminalBase.ConfigExactAmountAllowance.Value);
				var (val2, val3, num) = tuple;
				if ((Object)(object)val2 != (Object)null || (Object)(object)val3 != (Object)null || num != 0)
				{
					list2.Add(tuple.Item1);
					list2.Add(tuple.Item2);
					return list2;
				}
				val4 = list[count++];
				list2.Add(val4);
			}
			SellFromTerminalBase.Log.LogInfo((object)"Couldn't find a way to perfectly meet quota :(");
			return list2;
		}

		public static int CountAllScrapInShip()
		{
			return GetAllScrapInShip().Count();
		}

		public static int GetTotalScrapValueInShip()
		{
			return GetAllScrapInShip().Sum((GrabbableObject scrap) => scrap.ActualSellValue());
		}

		public static bool CanSellItem(this GrabbableObject item)
		{
			bool flag = item.itemProperties.isScrap && item.scrapValue > 0 && !item.isHeld;
			bool flag2 = ((Object)item.itemProperties).name != "Shotgun" || SellFromTerminalBase.ConfigCanSellShotgunAndShells.Value;
			bool flag3 = ((Object)item.itemProperties).name != "GunAmmo" || SellFromTerminalBase.ConfigCanSellShotgunAndShells.Value;
			bool flag4 = ((Object)item.itemProperties).name != "GiftBox" || SellFromTerminalBase.ConfigCanSellGifts.Value;
			bool flag5 = ((Object)item.itemProperties).name != "PickleJar" || SellFromTerminalBase.ConfigCanSellPickles.Value;
			return flag && flag2 && flag3 && flag4 && flag5;
		}

		public static int ActualSellValue(this GrabbableObject scrap)
		{
			float num = (float)scrap.scrapValue * StartOfRound.Instance.companyBuyingRate;
			return (int)Math.Round(num);
		}
	}
}
namespace SellFromTerminal.Patches
{
	[HarmonyPatch]
	public class NetworkObjectManager
	{
		private static GameObject networkPrefab;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameNetworkManager), "Start")]
		public static void LoadNetworkPrefab()
		{
			if (!((Object)(object)networkPrefab != (Object)null))
			{
				networkPrefab = SellFromTerminalBase.CustomAssets.LoadAsset<GameObject>("SellFromTerminalNetworkHandler");
				networkPrefab.AddComponent<NetworkHandler>();
				NetworkManager.Singleton.AddNetworkPrefab(networkPrefab);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		public static void SpawnNetworkHandlerObject()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				GameObject val = Object.Instantiate<GameObject>(networkPrefab, Vector3.zero, Quaternion.identity);
				val.GetComponent<NetworkObject>().Spawn(false);
			}
		}
	}
	[HarmonyPatch(typeof(Terminal))]
	public class TerminalPatch
	{
		public static int sellScrapFor;

		public static int numScrapSold;

		private static TerminalNode sellAmountNode;

		private static TerminalNode specialQuotaAlreadyMetNode;

		private static TerminalNode specialNotEnoughScrapNode;

		private static TerminalNode specialCanOnlySellAtCompanyNode;

		private static bool patchedTerminal;

		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		public static void AddTerminalNodes(Terminal __instance)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Expected O, but got Unknown
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Expected O, but got Unknown
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Expected O, but got Unknown
			//IL_017f: 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_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Expected O, but got Unknown
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Expected O, but got Unknown
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Expected O, but got Unknown
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: 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_0207: Expected O, but got Unknown
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Expected O, but got Unknown
			//IL_0249: 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_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Expected O, but got Unknown
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Expected O, but got Unknown
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Expected O, but got Unknown
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Expected O, but got Unknown
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Expected O, but got Unknown
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Expected O, but got Unknown
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Expected O, but got Unknown
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_036b: Expected O, but got Unknown
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0370: Unknown result type (might be due to invalid IL or missing references)
			//IL_037c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0389: Expected O, but got Unknown
			//IL_0389: Unknown result type (might be due to invalid IL or missing references)
			//IL_0390: Expected O, but got Unknown
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d1: Expected O, but got Unknown
			//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e9: Expected O, but got Unknown
			if (!patchedTerminal)
			{
				specialQuotaAlreadyMetNode = new TerminalNode
				{
					name = "quotaAlreadyMet",
					displayText = "Quota already met.\n\n\n",
					clearPreviousText = true
				};
				specialNotEnoughScrapNode = new TerminalNode
				{
					name = "notEnoughScrap",
					displayText = "Not enough scrap to meet [sellScrapFor] credits.\nTotal value: [totalScrapValue]\n\n\n",
					clearPreviousText = true
				};
				specialCanOnlySellAtCompanyNode = new TerminalNode
				{
					name = "onlySellAtCompany",
					displayText = "ERR: Usage of this feature is only permitted within Company bounds\n\nPlease land at 71-Gordion and repeat command\n\n\n",
					clearPreviousText = true
				};
				TerminalKeyword noun = __instance.terminalNodes.allKeywords.First((TerminalKeyword kw) => ((Object)kw).name == "Confirm");
				TerminalKeyword noun2 = __instance.terminalNodes.allKeywords.First((TerminalKeyword kw) => ((Object)kw).name == "Deny");
				TerminalNode result = new TerminalNode
				{
					name = "sellQuotaConfirm",
					displayText = "Transaction complete.\nSold [numScrapSold] scrap for [sellScrapFor] credits.\n\nThe company is not responsible for any calculation errors.\n\n\n",
					clearPreviousText = true,
					terminalEvent = "sellQuota"
				};
				TerminalNode result2 = new TerminalNode
				{
					name = "sellQuotaDeny",
					displayText = "Transaction cancelled.\n\n\n",
					clearPreviousText = true
				};
				TerminalNode val = new TerminalNode();
				((Object)val).name = "sellQuota";
				val.displayText = "Beginning transaction.\nRequesting to sell scrap as close to [sellScrapFor] credits as possible.[companyBuyingRateWarning]\n\nPlease CONFIRM or DENY.\n\n\n";
				val.isConfirmationNode = true;
				val.clearPreviousText = true;
				val.overrideOptions = true;
				val.terminalOptions = (CompatibleNoun[])(object)new CompatibleNoun[2]
				{
					new CompatibleNoun
					{
						noun = noun,
						result = result
					},
					new CompatibleNoun
					{
						noun = noun2,
						result = result2
					}
				};
				TerminalNode result3 = val;
				TerminalNode result4 = new TerminalNode
				{
					name = "sellAllConfirm",
					displayText = "Transaction complete. Sold all scrap for [sellScrapFor] credits.\n\nThe company is not responsible for any calculation errors.\n\n\n",
					clearPreviousText = true,
					terminalEvent = "sellAll"
				};
				TerminalNode result5 = new TerminalNode
				{
					name = "sellAllConfirm",
					displayText = "Transaction cancelled.\n\n\n",
					clearPreviousText = true
				};
				val = new TerminalNode();
				((Object)val).name = "sellAll";
				val.displayText = "Beginning transaction.\nRequesting to sell ALL scrap ([numScrap]) for [totalScrapValue] credits.[companyBuyingRateWarning]\n\nPlease CONFIRM or DENY.\n\n\n";
				val.isConfirmationNode = true;
				val.clearPreviousText = true;
				val.overrideOptions = true;
				val.terminalOptions = (CompatibleNoun[])(object)new CompatibleNoun[2]
				{
					new CompatibleNoun
					{
						noun = noun,
						result = result4
					},
					new CompatibleNoun
					{
						noun = noun2,
						result = result5
					}
				};
				TerminalNode result6 = val;
				TerminalNode result7 = new TerminalNode
				{
					name = "sellAmountConfirm",
					displayText = "Transaction complete.\nSold [numScrapSold] scrap for [sellScrapFor].\n\nThe company is not responsible for any calculation errors.\n\n\n",
					clearPreviousText = true,
					terminalEvent = "sellAmount"
				};
				TerminalNode result8 = new TerminalNode
				{
					name = "sellAllConfirm",
					displayText = "Transaction cancelled.\n\n\n",
					clearPreviousText = true
				};
				val = new TerminalNode();
				((Object)val).name = "sellAmount";
				val.displayText = "Beginning transaction.\nRequesting to sell scrap as close to [sellScrapFor] credits as possible.[companyBuyingRateWarning]\n\nPlease CONFIRM or DENY.\n\n\n";
				val.isConfirmationNode = true;
				val.clearPreviousText = true;
				val.overrideOptions = true;
				val.terminalOptions = (CompatibleNoun[])(object)new CompatibleNoun[2]
				{
					new CompatibleNoun
					{
						noun = noun,
						result = result7
					},
					new CompatibleNoun
					{
						noun = noun2,
						result = result8
					}
				};
				sellAmountNode = val;
				TerminalKeyword val2 = new TerminalKeyword
				{
					name = "All",
					word = "all"
				};
				TerminalKeyword val3 = new TerminalKeyword
				{
					name = "Quota",
					word = "quota"
				};
				TerminalKeyword val4 = new TerminalKeyword();
				((Object)val4).name = "Sell";
				val4.word = "sell";
				val4.isVerb = true;
				val4.compatibleNouns = (CompatibleNoun[])(object)new CompatibleNoun[2]
				{
					new CompatibleNoun
					{
						noun = val2,
						result = result6
					},
					new CompatibleNoun
					{
						noun = val3,
						result = result3
					}
				};
				TerminalKeyword val5 = (val3.defaultVerb = (val2.defaultVerb = val4));
				__instance.terminalNodes.allKeywords = CollectionExtensions.AddRangeToArray<TerminalKeyword>(__instance.terminalNodes.allKeywords, (TerminalKeyword[])(object)new TerminalKeyword[3] { val5, val2, val3 });
				TerminalNode specialKeywordResult = __instance.terminalNodes.allKeywords.First((TerminalKeyword node) => ((Object)node).name == "Other").specialKeywordResult;
				specialKeywordResult.displayText = specialKeywordResult.displayText.Substring(0, specialKeywordResult.displayText.Length - 1) + ">SELL [ALL|QUOTA|<AMOUNT>]\nTo sell items on the ship.\n\n\n";
				patchedTerminal = true;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("TextPostProcess")]
		public static string ProcessCustomText(string __result)
		{
			__result = __result.Replace("[numScrap]", ScrapHelpers.CountAllScrapInShip().ToString());
			__result = __result.Replace("[sellScrapFor]", sellScrapFor.ToString());
			__result = __result.Replace("[numScrapSold]", numScrapSold.ToString());
			__result = __result.Replace("[totalScrapValue]", ScrapHelpers.GetTotalScrapValueInShip().ToString());
			string newValue = ((StartOfRound.Instance.companyBuyingRate == 1f) ? "" : $"\n\nWARNING: Company buying rate is currently at {StartOfRound.Instance.companyBuyingRate:P0}\n\n");
			__result = __result.Replace("[companyBuyingRateWarning]", newValue);
			return __result;
		}

		[HarmonyPostfix]
		[HarmonyPatch("ParsePlayerSentence")]
		public static void SetSellScrapForHack(TerminalNode __result, Terminal __instance)
		{
			if (!((Object)(object)__result == (Object)null))
			{
				if (((Object)__result).name == "sellAll")
				{
					sellScrapFor = ScrapHelpers.GetTotalScrapValueInShip();
				}
				if (((Object)__result).name == "sellQuota")
				{
					sellScrapFor = TimeOfDay.Instance.profitQuota - TimeOfDay.Instance.quotaFulfilled;
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("ParsePlayerSentence")]
		public static TerminalNode TryParseSellAmount(TerminalNode __result, Terminal __instance)
		{
			string text = __instance.screenText.text.Substring(__instance.screenText.text.Length - __instance.textAdded);
			Regex regex = new Regex("^sell (\\d+$)$");
			Match match = regex.Match(text.ToLower());
			if (match.Success)
			{
				sellScrapFor = Convert.ToInt32(match.Groups[1].Value);
				if (sellScrapFor > 0)
				{
					return sellAmountNode;
				}
			}
			return __result;
		}

		[HarmonyPostfix]
		[HarmonyPatch("ParsePlayerSentence")]
		public static TerminalNode TryReturnSpecialNodes(TerminalNode __result, Terminal __instance)
		{
			if (((Object)__result).name == "sellQuota" && TimeOfDay.Instance.profitQuota - TimeOfDay.Instance.quotaFulfilled <= 0)
			{
				return specialQuotaAlreadyMetNode;
			}
			if ((((Object)__result).name == "sellQuota" || ((Object)__result).name == "sellAmount") && sellScrapFor > ScrapHelpers.GetTotalScrapValueInShip())
			{
				return specialNotEnoughScrapNode;
			}
			if ((((Object)__result).name == "sellQuota" || ((Object)__result).name == "sellAmount" || ((Object)__result).name == "sellAll") && (StartOfRound.Instance.currentLevel.levelID != 3 || StartOfRound.Instance.inShipPhase))
			{
				return specialCanOnlySellAtCompanyNode;
			}
			return __result;
		}

		[HarmonyPostfix]
		[HarmonyPatch("RunTerminalEvents")]
		public static void RunTerminalEvents(TerminalNode node)
		{
			if (node.terminalEvent == "sellAll")
			{
				NetworkHandler.Instance.SellAllScrapServerRpc();
			}
			if (node.terminalEvent == "sellQuota" || node.terminalEvent == "sellAmount")
			{
				NetworkHandler.Instance.SellAmountServerRpc(sellScrapFor);
			}
		}
	}
}
namespace SellFromTerminal.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}