Decompiled source of CozyFurniture v1.0.8

CozyFurniture.dll

Decompiled 5 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.Serialization.Formatters.Binary;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using CozyFurniture.NetcodePatcher;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CozyFurniture")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A furniture for Lethal Company")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CozyFurniture")]
[assembly: AssemblyTitle("CozyFurniture")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CozyFurniture
{
	[Serializable]
	[HarmonyPatch]
	public class ConfigSync
	{
		public static bool isSynced;

		public static ConfigSync defaultConfig;

		public static ConfigSync instance;

		public bool syncUnlockEverything;

		public bool syncShareEverything;

		public bool syncSyncUnsharedEmotes;

		public bool syncEnableMovingWhileEmoting;

		public bool syncDisableRaritySystem;

		public int syncStartingEmoteCredits;

		public float syncAddEmoteCreditsMultiplier;

		public bool syncPurchaseEmotesWithDefaultCurrency;

		public float syncPriceMultiplierEmotesStore;

		public int syncBasePriceEmoteTier0;

		public int syncBasePriceEmoteTier1;

		public int syncBasePriceEmoteTier2;

		public int syncBasePriceEmoteTier3;

		public int syncNumEmotesStoreRotation;

		public float syncRotationChanceEmoteTier0;

		public float syncRotationChanceEmoteTier1;

		public float syncRotationChanceEmoteTier2;

		public float syncRotationChanceEmoteTier3;

		public bool syncEnableMaskedEnemiesEmoting;

		public float syncMaskedEnemiesEmoteChanceOnEncounter;

		public bool syncMaskedEnemiesAlwaysEmoteOnFirstEncounter;

		public bool syncOverrideStopAndStareDuration;

		public float syncMaskedEnemyEmoteRandomDelayMin;

		public float syncMaskedEnemyEmoteRandomDelayMax;

		public float syncMaskedEnemyEmoteRandomDurationMin;

		public float syncMaskedEnemyEmoteRandomDurationMax;

		public static Vector2 syncMaskedEnemyEmoteRandomDelay;

		public static Vector2 syncMaskedEnemyEmoteRandomDuration;

		public static HashSet<ulong> syncedClients;

		public ConfigSync()
		{
			if (syncUnlockEverything)
			{
				syncShareEverything = true;
			}
		}

		public Vector2 ParseVector2FromString(string str)
		{
			//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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			Vector2 result = Vector2.zero;
			try
			{
				string[] array = str.Split(',');
				if (float.TryParse(array[0].Trim(' '), out var result2) && float.TryParse(array[1].Trim(' '), out var result3))
				{
					result = new Vector2(Mathf.Min(Mathf.Abs(result2), Mathf.Abs(result3)), Mathf.Max(Mathf.Abs(result2), Mathf.Abs(result3)));
				}
				return result;
			}
			catch
			{
			}
			return Vector2.zero;
		}

		public static void BuildDefaultConfigSync()
		{
			defaultConfig = new ConfigSync();
			instance = new ConfigSync();
		}

		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		[HarmonyPostfix]
		public static void ResetValues()
		{
			isSynced = false;
		}

		private static void OnRequestConfigSyncClientRpc(ulong clientId, FastBufferReader reader)
		{
			//IL_001d: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkManager.Singleton.IsClient)
			{
				return;
			}
			int num = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			if (((FastBufferReader)(ref reader)).TryBeginRead(num))
			{
				byte[] data = new byte[num];
				((FastBufferReader)(ref reader)).ReadBytesSafe(ref data, num, 0);
				instance = DeserializeFromByteArray(data);
				if (instance.syncUnlockEverything)
				{
					instance.syncShareEverything = true;
				}
				syncMaskedEnemyEmoteRandomDelay = new Vector2(instance.syncMaskedEnemyEmoteRandomDelayMin, instance.syncMaskedEnemyEmoteRandomDelayMax);
				syncMaskedEnemyEmoteRandomDuration = new Vector2(instance.syncMaskedEnemyEmoteRandomDurationMin, instance.syncMaskedEnemyEmoteRandomDurationMax);
				isSynced = true;
			}
		}

		public static byte[] SerializeConfigToByteArray(ConfigSync config)
		{
			BinaryFormatter binaryFormatter = new BinaryFormatter();
			MemoryStream memoryStream = new MemoryStream();
			binaryFormatter.Serialize(memoryStream, config);
			return memoryStream.ToArray();
		}

		public static ConfigSync DeserializeFromByteArray(byte[] data)
		{
			MemoryStream serializationStream = new MemoryStream(data);
			BinaryFormatter binaryFormatter = new BinaryFormatter();
			return (ConfigSync)binaryFormatter.Deserialize(serializationStream);
		}
	}
	public class NetworkHandler : NetworkBehaviour
	{
		public static NetworkHandler Instance { get; private set; }

		public static event Action<string> LevelEvent;

		public override void OnNetworkSpawn()
		{
			NetworkHandler.LevelEvent = null;
			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();
		}

		[ClientRpc]
		public void EventClientRpc(string eventName)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: 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(506852059u, val, (RpcDelivery)0);
				bool flag = eventName != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(eventName, false);
				}
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 506852059u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				NetworkHandler.LevelEvent?.Invoke(eventName);
			}
		}

		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
			NetworkManager.__rpc_func_table.Add(506852059u, new RpcReceiveHandler(__rpc_handler_506852059));
		}

		private static void __rpc_handler_506852059(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string eventName = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref eventName, false);
				}
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((NetworkHandler)(object)target).EventClientRpc(eventName);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "NetworkHandler";
		}
	}
	[HarmonyPatch]
	public class NetworkObjectManager
	{
		private static GameObject networkPrefab;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameNetworkManager), "Start")]
		public static void Init()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			if (!((Object)(object)networkPrefab != (Object)null))
			{
				networkPrefab = (GameObject)Plugin.networkBundle.LoadAsset("ExampleNetworkHandler");
				networkPrefab.AddComponent<NetworkHandler>();
				NetworkManager.Singleton.AddNetworkPrefab(networkPrefab);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		private static void SpawnNetworkHandler()
		{
			//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);
			}
		}
	}
	[BepInPlugin("CozyFurniture", "CozyFurniture", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private static Plugin instance;

		public static AssetBundle bundle;

		public static AssetBundle networkBundle;

		public static GameObject shipObject;

		private readonly Harmony harmony = new Harmony("CozyFurniture");

		internal ManualLogSource mls;

		private void Awake()
		{
			NetcodePatcher();
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			bundle = AssetBundle.LoadFromFile(Path.Combine(directoryName, "ship"));
			shipObject = bundle.LoadAsset<GameObject>("Assets/ShipInside (1).prefab");
			NetworkPrefabs.RegisterNetworkPrefab(shipObject);
			Utilities.FixMixerGroups(shipObject);
			SpawnNetworkManager();
			if ((Object)(object)bundle == (Object)null)
			{
				mls.LogError((object)"Failed to load custom assets.");
				return;
			}
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			mls = Logger.CreateLogSource("CozyFurniture");
			mls.LogInfo((object)"CozyFurniture initalized");
			mls.LogInfo((object)("Mothership Asset: " + (object)bundle));
			harmony.PatchAll(typeof(Plugin));
			harmony.PatchAll(typeof(TerminalPatch));
			harmony.PatchAll(typeof(SpacePatcher));
			[ServerRpc]
			void SpawnNetworkManager()
			{
				string directoryName2 = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
				string fileName = Path.GetFileName(directoryName2);
				networkBundle = AssetBundle.LoadFromFile(fileName);
			}
		}

		private static void NetcodePatcher()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}

		private void Update()
		{
		}
	}
	[HarmonyPatch]
	public static class SpacePatcher
	{
		public static ManualLogSource mls;

		public static bool inSpace = false;

		public static Plugin pluginInstance;

		public static GameObject shipInstantiation;

		public static AutoParentToShip[] furnitureArray;

		public static HashSet<string> blacklistedFurnitureObjects = new HashSet<string>();

		public static HashSet<AutoParentToShip> toggledFurniture = new HashSet<AutoParentToShip>();

		public static GameObject shipRails;

		public static GameObject shipRailsPost;

		[HarmonyPatch(typeof(StartOfRound), "TeleportPlayerInShipIfOutOfRoomBounds")]
		[HarmonyPrefix]
		public static bool TeleportPlayerInShipIfOutOfRoomBounds()
		{
			if (inSpace)
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		[HarmonyPostfix]
		public static void SpawnShip()
		{
		}

		[HarmonyPatch(typeof(ShipBuildModeManager), "PlayerMeetsConditionsToBuild")]
		[HarmonyPostfix]
		public static void PlayerMeetsConditionsToBuild(ref bool __result)
		{
			PlayerControllerB val = Object.FindObjectOfType<PlayerControllerB>();
			__result = inSpace;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(RoundManager), "Awake")]
		private static void AwakeServerRpc()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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_00ee: Unknown result type (might be due to invalid IL or missing references)
			NetworkHandler.LevelEvent += ReceivedEventFromServer;
			mls = Logger.CreateLogSource("CozyFurniture");
			shipInstantiation = Object.Instantiate<GameObject>(Plugin.shipObject, new Vector3(-13.7527f, 0.96f, -15.52f), Quaternion.identity);
			NetworkPrefabs.RegisterNetworkPrefab(shipInstantiation);
			toggledFurniture = new HashSet<AutoParentToShip>();
			mls.LogInfo((object)"Server side Starting game");
			shipRails = GameObject.Find("ShipRails");
			shipRailsPost = GameObject.Find("ShipRailPosts");
			if ((Object)(object)shipInstantiation != (Object)null)
			{
				shipInstantiation.transform.Rotate(new Vector3(0f, 1f, 0f), 180f);
				shipInstantiation.transform.Rotate(new Vector3(1f, 0f, 0f), 270f);
			}
			blacklistedFurnitureObjects.Add("FileCabinet");
			blacklistedFurnitureObjects.Add("Terminal");
			blacklistedFurnitureObjects.Add("Bunkbeds");
			blacklistedFurnitureObjects.Add("StorageCloset");
			blacklistedFurnitureObjects.Add("Teleporter(Clone)");
			blacklistedFurnitureObjects.Add("ShipHorn(Clone)");
			blacklistedFurnitureObjects.Add("InverseTeleporter(Clone)");
			blacklistedFurnitureObjects.Add("SignalTranslator(Clone)");
			GameObject.Find("ShipRails").SetActive(true);
			GameObject.Find("ShipRailPosts").SetActive(true);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(RoundManager), "InitializeRandomNumberGenerators")]
		private static void SubscribeToHandler()
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			NetworkHandler.LevelEvent += ReceivedEventFromServer;
			inSpace = false;
			shipInstantiation.SetActive(false);
			furnitureArray = Object.FindObjectsOfType<AutoParentToShip>();
			RoundManager.Instance.playersManager.shipDoorsAnimator.SetBool("Closed", true);
			shipRails.SetActive(true);
			shipRailsPost.SetActive(true);
			BoxCollider component = GameObject.Find("ShipInnerRoomBoundsTrigger").GetComponent<BoxCollider>();
			component.center = new Vector3(0f, 0f, 0f);
			component.size = new Vector3(1f, 0f, 0.9999999f);
			mls.LogInfo((object)"Server side Starting game");
			if (furnitureArray == null)
			{
				return;
			}
			mls.LogInfo((object)furnitureArray);
			mls.LogInfo((object)"Found furniture array");
			AutoParentToShip[] array = furnitureArray;
			foreach (AutoParentToShip val in array)
			{
				if (!blacklistedFurnitureObjects.Contains(((Object)((Component)val).gameObject).name))
				{
					((Component)val).gameObject.SetActive(false);
					toggledFurniture.Add(val);
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(RoundManager), "DespawnPropsAtEndOfRound")]
		private static void UnsubscribeFromHandler()
		{
			//IL_0063: 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)
			NetworkHandler.LevelEvent -= ReceivedEventFromServer;
			inSpace = true;
			mls = Logger.CreateLogSource("CozyFurniture");
			Object.FindObjectOfType<HangarShipDoor>().SetDoorButtonsEnabled(true);
			BoxCollider component = GameObject.Find("ShipInnerRoomBoundsTrigger").GetComponent<BoxCollider>();
			component.center = new Vector3(-0.487964f, 0f, 0f);
			component.size = new Vector3(1.975929f, 1f, 1f);
			furnitureArray = Object.FindObjectsOfType<AutoParentToShip>();
			shipInstantiation.SetActive(true);
			shipRails.SetActive(false);
			shipRailsPost.SetActive(false);
			if (toggledFurniture == null || furnitureArray == null)
			{
				return;
			}
			mls.LogInfo((object)furnitureArray);
			mls.LogInfo((object)"Found furniture array");
			foreach (AutoParentToShip item in toggledFurniture.ToList())
			{
				if (!blacklistedFurnitureObjects.Contains(((Object)((Component)item).gameObject).name))
				{
					((Component)item).gameObject.SetActive(true);
					toggledFurniture.Remove(item);
				}
			}
		}

		private static void ReceivedEventFromServer(string eventName)
		{
		}

		private static void SendEventToClients(string eventName)
		{
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				NetworkHandler.Instance.EventClientRpc(eventName);
			}
		}
	}
	[HarmonyPatch]
	public static class TerminalPatch
	{
		public static ManualLogSource mls;

		public static Terminal terminalInstance;

		public static int currentFurnitureCredits;

		public static Dictionary<string, int> currentFurnitureCreditsByPlayer;

		public static List<TerminalNode> ShipFurnitureSelection = new List<TerminalNode>();

		public static bool initializedTerminalNodes = false;

		private static string confirmFurnitureOpeningText = "You have requested to order a new piece of furniture.";

		[HarmonyPatch(typeof(Terminal), "Awake")]
		[HarmonyPostfix]
		public static void InitializeTerminal(Terminal __instance)
		{
			terminalInstance = __instance;
			currentFurnitureCreditsByPlayer = new Dictionary<string, int>();
			if (!initializedTerminalNodes)
			{
				EditExistingTerminalNodesForFurniture();
			}
		}

		[HarmonyPatch(typeof(Terminal), "RotateShipDecorSelection")]
		[HarmonyPrefix]
		public static bool HijackDecor()
		{
			NetworkHandler.LevelEvent += ReceivedEventFromServer;
			Random random = new Random(StartOfRound.Instance.randomMapSeed + 65);
			terminalInstance.ShipDecorSelection.Clear();
			List<TerminalNode> list = new List<TerminalNode>();
			List<TerminalNode> list2 = new List<TerminalNode>();
			for (int i = 0; i < StartOfRound.Instance.unlockablesList.unlockables.Count; i++)
			{
				if (StartOfRound.Instance.unlockablesList.unlockables[i].IsPlaceable || (Object)(object)StartOfRound.Instance.unlockablesList.unlockables[i].suitMaterial == (Object)null)
				{
					if ((Object)(object)StartOfRound.Instance.unlockablesList.unlockables[i].shopSelectionNode != (Object)null && !StartOfRound.Instance.unlockablesList.unlockables[i].alwaysInStock)
					{
						list2.Add(StartOfRound.Instance.unlockablesList.unlockables[i].shopSelectionNode);
						StartOfRound.Instance.unlockablesList.unlockables[i].alwaysInStock = true;
					}
				}
				else if ((Object)(object)StartOfRound.Instance.unlockablesList.unlockables[i].shopSelectionNode != (Object)null && !StartOfRound.Instance.unlockablesList.unlockables[i].alwaysInStock)
				{
					list.Add(StartOfRound.Instance.unlockablesList.unlockables[i].shopSelectionNode);
				}
			}
			int num = random.Next(4, 6);
			for (int j = 0; j < num; j++)
			{
				if (list.Count <= 0)
				{
					break;
				}
				TerminalNode item = list2[random.Next(0, list2.Count)];
				ShipFurnitureSelection.Add(item);
				list2.Remove(item);
				TerminalNode item2 = list[random.Next(0, list.Count)];
				terminalInstance.ShipDecorSelection.Add(item2);
				list.Remove(item2);
			}
			return false;
		}

		private static void ReceivedEventFromServer(string eventName)
		{
		}

		[HarmonyPatch(typeof(Terminal), "LoadNewNodeIfAffordable")]
		[HarmonyPostfix]
		public static void GenerateFurniture(ref TerminalNode node)
		{
			//IL_0055: 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)
			if (node.shipUnlockableID == -1)
			{
				return;
			}
			UnlockableItem val = StartOfRound.Instance.unlockablesList.unlockables[node.shipUnlockableID];
			if (StartOfRound.Instance.inShipPhase || StartOfRound.Instance.shipHasLanded)
			{
				AnimatorStateInfo currentAnimatorStateInfo = StartOfRound.Instance.shipAnimator.GetCurrentAnimatorStateInfo(0);
				if (((AnimatorStateInfo)(ref currentAnimatorStateInfo)).tagHash == Animator.StringToHash("ShipIdle"))
				{
					if (!ShipFurnitureSelection.Contains(node) && !val.alwaysInStock && (!node.buyUnlockable || (Object)(object)val.shopSelectionNode == (Object)null))
					{
						Debug.Log((object)("Not in stock, node: " + ((Object)node).name));
						terminalInstance.LoadNewNode(terminalInstance.terminalNodes.specialNodes[16]);
					}
					return;
				}
			}
			terminalInstance.LoadNewNode(terminalInstance.terminalNodes.specialNodes[15]);
		}

		public static void EditExistingTerminalNodesForFurniture()
		{
			initializedTerminalNodes = true;
			foreach (TerminalNode specialNode in terminalInstance.terminalNodes.specialNodes)
			{
				if (((Object)specialNode).name == "Start")
				{
					string text = "Type \"Help\" for a list of commands.";
					int num = specialNode.displayText.IndexOf(text);
					if (num != -1)
					{
						num += text.Length;
						string value = "\n\n[CozyFurniture]\nType \"Furniture\" for a list of commands.";
						specialNode.displayText = specialNode.displayText.Insert(num, value);
					}
					else
					{
						Debug.LogError((object)"Failed to add furniture tip to terminal. Maybe an update broke it?");
					}
				}
				else if (((Object)specialNode).name == "HelpCommands")
				{
					string value2 = "[numberOfItemsOnRoute]";
					int num2 = specialNode.displayText.IndexOf(value2);
					if (num2 != -1)
					{
						string value3 = ">FURNITURE\nFor a list of Furniture commands.\n\n";
						specialNode.displayText = specialNode.displayText.Insert(num2, value3);
					}
				}
			}
		}

		[HarmonyPatch(typeof(Terminal), "TextPostProcess")]
		[HarmonyPrefix]
		public static void TextPostProcessFurniture(ref string modifiedDisplayText, TerminalNode node)
		{
			if (modifiedDisplayText.Length > 0 && (modifiedDisplayText.Contains("[[[[furnitureUnlockablesSelectionList]]]]") || (modifiedDisplayText.Contains("[[[[") && modifiedDisplayText.Contains("]]]]"))))
			{
				int num = modifiedDisplayText.IndexOf("[[[[");
				int num2 = modifiedDisplayText.IndexOf("]]]]") + 3;
				string oldValue = modifiedDisplayText.Substring(num, num2 - num);
				string text = "";
				text = text + "Remaining furniture credit balance: $" + currentFurnitureCredits + ".\n";
				text += "\n";
				StringBuilder stringBuilder = new StringBuilder();
				for (int i = 0; i < ShipFurnitureSelection.Count; i++)
				{
					stringBuilder.Append($"\n{ShipFurnitureSelection[i].creatureName}  //  ${ShipFurnitureSelection[i].itemCost}");
				}
				text += stringBuilder.ToString();
				if (ShipFurnitureSelection == null || ShipFurnitureSelection.Count <= 0)
				{
					modifiedDisplayText = modifiedDisplayText.Replace("[[[[furnitureUnlockablesSelectionList]]]]", "[No items available]");
				}
				modifiedDisplayText = modifiedDisplayText.Replace(oldValue, text);
			}
		}

		[HarmonyPatch(typeof(Terminal), "ParsePlayerSentence")]
		[HarmonyPrefix]
		public static bool ParsePlayerSentence(ref TerminalNode __result, Terminal __instance)
		{
			if (__instance.screenText.text.Length <= 0)
			{
				return true;
			}
			string text = __instance.screenText.text.Substring(__instance.screenText.text.Length - __instance.textAdded);
			string[] array = text.Split(' ');
			if (array.Length == 0)
			{
				return true;
			}
			if (!ConfigSync.isSynced)
			{
				if (text.StartsWith("furniture"))
				{
					__result = BuildTerminalNodeHomeFurniture();
					return false;
				}
				return true;
			}
			if (text.StartsWith("furnitures"))
			{
				text = text.Replace("furnitures", "furniture");
			}
			if (text.StartsWith("furniture"))
			{
				if (text == "furniture")
				{
					__result = BuildTerminalNodeHomeFurniture();
					return false;
				}
				text = text.Substring(6);
				return true;
			}
			return true;
		}

		private static TerminalNode BuildTerminalNodeHomeFurniture()
		{
			//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_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			return new TerminalNode
			{
				displayText = "[CozyFurniture]\n\nStore\n------------------------------\n[[[[furnitureUnlockablesSelectionList]]]]\n\n",
				clearPreviousText = true,
				acceptAnything = false
			};
		}

		private static TerminalNode BuildCustomTerminalNode(string displayText, bool clearPreviousText = false, bool acceptAnything = false, bool isConfirmationNode = false)
		{
			//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_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			return new TerminalNode
			{
				displayText = displayText,
				clearPreviousText = clearPreviousText,
				acceptAnything = false,
				isConfirmationNode = isConfirmationNode
			};
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "CozyFurniture";

		public const string PLUGIN_NAME = "CozyFurniture";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace CozyFurniture.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}