Decompiled source of LCDuels v1.2.0

LCDuels.dll

Decompiled 3 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net.WebSockets;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Logging;
using DunGen;
using GameNetcodeStuff;
using HarmonyLib;
using LCDuels.Patches;
using Newtonsoft.Json;
using Steamworks;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LCDuels")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LCDuels")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("acf0b1d5-4fb6-473d-9539-84c1197bcf38")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LCDuels
{
	[BepInPlugin("onty.duels", "LCDuels", "1.2.0.0")]
	public class LCDuelsModBase : BaseUnityPlugin
	{
		private const string modGUID = "onty.duels";

		private const string modName = "LCDuels";

		private const string modVersion = "1.2.0.0";

		private readonly Harmony harmony = new Harmony("onty.duels");

		public static LCDuelsModBase Instance;

		internal ManualLogSource mls;

		public int seedFromServer = 64;

		public static TextMeshPro inGameStatusText;

		public static bool playing = true;

		public string enemyPlayerName = "Waiting";

		public string enemyPlayerScrap = "0";

		public string enemyPlayerLocation = "in ship";

		public bool gameReady = false;

		public bool isInShip = true;

		public bool wsTerminated = false;

		public string endOfGameResult = "";

		public int currentValue = 0;

		public bool gameStarted = false;

		public bool DisconnectDone = false;

		public bool waitingForResult = false;

		public bool death = false;

		public string versionString = "";

		public bool gameEndedWithError = false;

		public string queueName = "";

		public static bool debug = true;

		public bool isPublicQueue = false;

		public ClientWebSocket localWS = null;

		public Terminal terminal = null;

		public StartMatchLever matchLever = null;

		public MenuManager menuManager = null;

		public TextMeshProUGUI publicText;

		public TextMeshProUGUI friendsText;

		public TextMeshProUGUI serverName;

		public int gameMode = 0;

		public int yourScore = 0;

		public int enemyScore = 0;

		public int curDay = 1;

		public bool ejected = false;

		public List<SaveFileUISlot> saveFileUISlots = new List<SaveFileUISlot>();

		public TextMeshProUGUI specialTipText;

		public int foundMapID = 0;

		public void ResetValues(bool isEnabled)
		{
			endOfGameResult = "";
			seedFromServer = 64;
			playing = isEnabled;
			enemyPlayerName = "Unknown";
			enemyPlayerScrap = "0";
			enemyPlayerLocation = "in ship";
			gameReady = false;
			isInShip = true;
			wsTerminated = false;
			currentValue = 0;
			gameStarted = false;
			waitingForResult = false;
			death = false;
			gameEndedWithError = false;
			yourScore = 0;
			enemyScore = 0;
			curDay = 1;
			ejected = false;
			foundMapID = 0;
		}

		public int getRandomMapID(Random ra)
		{
			SelectableLevel[] levels = StartOfRound.Instance.levels;
			foreach (SelectableLevel val in levels)
			{
				Console.WriteLine(val.levelID + "-" + ((Object)val).name);
			}
			int num = ra.Next(0, StartOfRound.Instance.levels.Length - 1);
			if (num < 3)
			{
				return num;
			}
			if (num < 10)
			{
				return num + 1;
			}
			return num + 2;
		}

		public int getRandomMapIDByTier(int tier, Random ra)
		{
			List<int> list = new List<int>();
			switch (tier)
			{
			case 1:
				list.Add(0);
				list.Add(1);
				list.Add(2);
				break;
			case 2:
				list.Add(4);
				list.Add(5);
				list.Add(8);
				list.Add(12);
				break;
			default:
				list.Add(6);
				list.Add(7);
				list.Add(9);
				list.Add(10);
				break;
			}
			int index = ra.Next(0, list.Count - 1);
			mls.LogInfo((object)("!!!!!!!!!!!!!!!!!!!!!!!!found output" + index));
			return list[index];
		}

		public void UpdateInGameStatusText()
		{
			switch (gameMode)
			{
			case 1:
				((TMP_Text)HUDManager.Instance.controlTipLines[0]).text = "Join dc: dc.ontro.cz";
				((TMP_Text)HUDManager.Instance.controlTipLines[1]).text = ((enemyPlayerName == "Unknown") ? "Waiting for player" : (enemyPlayerName + " is " + enemyPlayerLocation));
				((TMP_Text)HUDManager.Instance.controlTipLines[2]).text = "VS: " + enemyPlayerName;
				((TMP_Text)HUDManager.Instance.controlTipLines[3]).text = "Your loot " + currentValue;
				break;
			case 2:
			case 3:
				((TMP_Text)HUDManager.Instance.controlTipLines[0]).text = "Join dc: dc.ontro.cz";
				((TMP_Text)HUDManager.Instance.controlTipLines[1]).text = ((enemyPlayerName == "Unknown") ? "Waiting for player" : (enemyPlayerName + " is " + enemyPlayerLocation));
				((TMP_Text)HUDManager.Instance.controlTipLines[2]).text = "You " + yourScore + ":" + enemyScore + " " + enemyPlayerName;
				((TMP_Text)HUDManager.Instance.controlTipLines[3]).text = "Your loot from this day " + currentValue;
				break;
			default:
				((TMP_Text)HUDManager.Instance.controlTipLines[0]).text = "error";
				((TMP_Text)HUDManager.Instance.controlTipLines[1]).text = "error";
				((TMP_Text)HUDManager.Instance.controlTipLines[2]).text = "error";
				((TMP_Text)HUDManager.Instance.controlTipLines[3]).text = "error";
				break;
			}
		}

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("onty.duels");
			mls.LogInfo((object)"LC Duels has been awaken");
			harmony.PatchAll(typeof(LCDuelsModBase));
			harmony.PatchAll(typeof(PlayerControllerBPatch));
			harmony.PatchAll(typeof(StartOfRoundPatch));
			harmony.PatchAll(typeof(RoundManagerPatch));
			harmony.PatchAll(typeof(TerminalPatch));
			harmony.PatchAll(typeof(HUDManagerPatch));
			harmony.PatchAll(typeof(StartMatchLeverPatch));
			harmony.PatchAll(typeof(RuntimeDungeonStartPatch));
			harmony.PatchAll(typeof(GameNetworkManagerPatch));
			harmony.PatchAll(typeof(MenuManagerPatch));
			harmony.PatchAll(typeof(EntranceTeleportPatch));
			harmony.PatchAll(typeof(ItemDropShipPatch));
			harmony.PatchAll(typeof(SaveFileUISlotPatch));
			harmony.PatchAll(typeof(TimeOfDayPatch));
		}

		public async Task InitWS()
		{
			mls.LogInfo((object)"InitWebSocket");
			if (localWS == null)
			{
				Uri serverUri = new Uri("ws://130.61.35.90:8080");
				using ClientWebSocket webSocket = new ClientWebSocket();
				localWS = webSocket;
				await webSocket.ConnectAsync(serverUri, CancellationToken.None);
				mls.LogInfo((object)"Connected to server");
				await ReceiveMessages(webSocket, shouldRegister: true);
			}
			else
			{
				Register(localWS);
			}
		}

		private async Task ReceiveMessages(ClientWebSocket webSocket, bool shouldRegister)
		{
			byte[] buffer = new byte[1024];
			try
			{
				while (webSocket.State == WebSocketState.Open)
				{
					mls.LogInfo((object)"Starting while loop");
					if (shouldRegister)
					{
						mls.LogInfo((object)"Registering");
						shouldRegister = false;
						Register(localWS);
					}
					WebSocketReceiveResult result = await webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);
					string message = Encoding.UTF8.GetString(buffer, 0, result.Count);
					HandleMessage(message);
				}
			}
			catch (WebSocketException ex2)
			{
				WebSocketException ex = ex2;
				Console.WriteLine("WebSocketException: " + ex.Message);
			}
			finally
			{
				if (webSocket.State != WebSocketState.Closed)
				{
					await webSocket.CloseAsync(WebSocketCloseStatus.InternalServerError, "Error occurred", CancellationToken.None);
				}
				webSocket.Dispose();
				mls.LogInfo((object)"Socket closed");
				localWS = null;
				if (GameNetworkManager.Instance.isHostingGame && !wsTerminated)
				{
					gameEndedWithError = true;
					waitingForResult = true;
					endOfGameResult = "Lost connection to server";
				}
			}
		}

		private void HandleMessage(string message)
		{
			Dictionary<string, object> dictionary = JsonConvert.DeserializeObject<Dictionary<string, object>>(message);
			if (dictionary == null || !dictionary.ContainsKey("type"))
			{
				mls.LogInfo((object)"Invalid message received");
				return;
			}
			string text = dictionary["type"].ToString();
			switch (text)
			{
			case "match_found":
			{
				string text2 = dictionary["opponentId"].ToString();
				enemyPlayerName = dictionary["opponentUsername"].ToString();
				seedFromServer = int.Parse(dictionary["seed"].ToString());
				gameMode = int.Parse(dictionary["gameMode"].ToString());
				mls.LogInfo((object)("Match found! Opponent: " + enemyPlayerName + " (ID: " + text2 + ")"));
				matchFound();
				break;
			}
			case "game_start":
				mls.LogInfo((object)"Game started!");
				gameReady = true;
				break;
			case "reroll":
				if (!gameReady)
				{
					seedFromServer = int.Parse(dictionary["seed"].ToString());
					HUDManager.Instance.DisplayTip("Info", "Rerolled", false, false, "LC_Tip1");
					matchFound();
				}
				break;
			case "position":
				switch (dictionary["value"].ToString())
				{
				case "0":
					enemyPlayerLocation = (waitingForResult ? "in ship" : "outside");
					break;
				case "1":
					enemyPlayerLocation = "outside";
					break;
				case "2":
					enemyPlayerLocation = "inside";
					break;
				default:
					enemyPlayerLocation = "data error";
					break;
				}
				if (debug)
				{
					mls.LogInfo((object)("Opponent position: " + enemyPlayerLocation));
				}
				UpdateInGameStatusText();
				if (waitingForResult)
				{
					UpdateDisplayWaitingForResult();
				}
				break;
			case "score":
				enemyPlayerScrap = dictionary["value"].ToString();
				if (debug)
				{
					mls.LogInfo((object)("Opponent score is " + enemyPlayerScrap));
				}
				UpdateInGameStatusText();
				if (waitingForResult)
				{
					UpdateDisplayWaitingForResult();
				}
				break;
			case "error":
				gameEndedWithError = true;
				waitingForResult = true;
				endOfGameResult = dictionary["value"].ToString();
				break;
			case "opponent_left":
				mls.LogInfo((object)"Your opponent has left the game.");
				HUDManager.Instance.DisplayTip("You won!", "You can leave or finish the day. Your opponent has left the game!", false, false, "LC_Tip1");
				endOfGameResult = "Won, opponent left";
				break;
			case "won":
			{
				if (gameMode != 1 && (string)dictionary["value"] != "15")
				{
					HUDManager.Instance.DisplayTip("Won the day", "You can pull the lever now", false, false, "LC_Tip1");
					yourScore = int.Parse(dictionary["yourScore"].ToString());
					enemyScore = int.Parse(dictionary["enemyScore"].ToString());
					gameReady = false;
					death = false;
					yourScore = int.Parse(dictionary["yourScore"].ToString());
					enemyScore = int.Parse(dictionary["enemyScore"].ToString());
					GameNetworkManager.Instance.SetLobbyJoinable(false);
					GameNetworkManager.Instance.disallowConnection = true;
					((TMP_Text)StartOfRound.Instance.screenLevelDescription).text = "Waiting for other player\nYou can join our discord (dc.ontro.cz) to find people to play with.";
					if ((Object)(object)matchLever != (Object)null)
					{
						matchLever.triggerScript.disabledHoverTip = "[Wait for the other player]";
						matchLever.triggerScript.interactable = false;
					}
					Instance.UpdateInGameStatusText();
					((MonoBehaviour)terminal).StartCoroutine(Instance.waitUntilEndOfGame());
					break;
				}
				HUDManager.Instance.DisplayTip("You won!", "You can leave or finish the day", false, false, "LC_Tip1");
				object obj3 = dictionary["value"];
				object obj4 = obj3;
				switch (obj4 as string)
				{
				case "1":
					endOfGameResult = "Won, because other player died";
					break;
				case "3":
					endOfGameResult = "Won, because you had more loot";
					break;
				case "5":
					endOfGameResult = "Won, because you had the same amount of loot but you were faster";
					break;
				case "7":
					endOfGameResult = "Won, because other player had no balls";
					break;
				case "9":
					endOfGameResult = "Won, because you had the same amount of loot but you survived longer";
					break;
				case "11":
					endOfGameResult = "Won, because you survived more days";
					break;
				case "13":
					endOfGameResult = "Won, because you survived the same amount of days but you had more loot on ship";
					break;
				case "15":
					endOfGameResult = "Won, because you got 2 points first";
					break;
				default:
					endOfGameResult = "Won, reason unknown";
					break;
				}
				break;
			}
			case "lost":
			{
				if (gameMode != 1 && (string)dictionary["value"] != "16")
				{
					HUDManager.Instance.DisplayTip("Lost the day", "You can pull the lever now", false, false, "LC_Tip1");
					yourScore = int.Parse(dictionary["yourScore"].ToString());
					enemyScore = int.Parse(dictionary["enemyScore"].ToString());
					gameReady = false;
					death = false;
					GameNetworkManager.Instance.SetLobbyJoinable(false);
					GameNetworkManager.Instance.disallowConnection = true;
					((TMP_Text)StartOfRound.Instance.screenLevelDescription).text = "Waiting for other player\nYou can join our discord (dc.ontro.cz) to find people to play with.";
					if ((Object)(object)matchLever != (Object)null)
					{
						matchLever.triggerScript.disabledHoverTip = "[Wait for the other player]";
						matchLever.triggerScript.interactable = false;
					}
					Instance.UpdateInGameStatusText();
					((MonoBehaviour)terminal).StartCoroutine(Instance.waitUntilEndOfGame());
					break;
				}
				HUDManager.Instance.DisplayTip("You lost!", "You can leave or finish the day", false, false, "LC_Tip1");
				object obj = dictionary["value"];
				object obj2 = obj;
				switch (obj2 as string)
				{
				case "2":
					endOfGameResult = "Lost, because other player survived";
					break;
				case "4":
					endOfGameResult = "Lost, because you had less loot";
					break;
				case "6":
					endOfGameResult = "Lost, because you had the same amount of loot but you were slower";
					break;
				case "8":
					endOfGameResult = "Lost, because you had no balls";
					break;
				case "10":
					endOfGameResult = "Lost, because you had the same amount of loot but you died sooner";
					break;
				case "12":
					endOfGameResult = "Lost, because you survived less days";
					break;
				case "14":
					endOfGameResult = "Lost, because you survived the same amount of days but you had less loot on ship";
					break;
				case "16":
					endOfGameResult = "Lost, because the enemy got 2 points first";
					break;
				default:
					endOfGameResult = "Lost, reason unknown";
					break;
				}
				break;
			}
			case "in_game_error":
				gameEndedWithError = true;
				waitingForResult = true;
				endOfGameResult = "Something went wrong, please restart the game!";
				break;
			case "chat":
			{
				MethodInfo method = typeof(HUDManager).GetMethod("AddChatMessage", BindingFlags.Instance | BindingFlags.NonPublic);
				method.Invoke(HUDManager.Instance, new object[2]
				{
					dictionary["value"],
					enemyPlayerName
				});
				HUDManager.Instance.PingHUDElement(HUDManager.Instance.Chat, 2f, 1f, 0.2f);
				break;
			}
			case "new_seed":
				seedFromServer = int.Parse(dictionary["seed"].ToString());
				StartOfRound.Instance.randomMapSeed = seedFromServer;
				break;
			default:
				if (debug)
				{
					mls.LogInfo((object)("Unknown message type: " + text));
				}
				else
				{
					mls.LogInfo((object)"Unknown message received");
				}
				break;
			}
			if (debug)
			{
				mls.LogInfo((object)("Received: " + message));
			}
			else
			{
				mls.LogInfo((object)"Received message");
			}
		}

		public void UpdateDisplayWaitingForResult()
		{
			((TMP_Text)StartOfRound.Instance.screenLevelDescription).text = "Waiting for other player to die or get more then you or lift off\nEnemy loot: " + enemyPlayerScrap + "\nHe is: " + enemyPlayerLocation;
		}

		private async Task Register(ClientWebSocket webSocket)
		{
			mls.LogInfo((object)(versionString + "version"));
			if (string.IsNullOrEmpty(menuManager.lobbyNameInputField.text))
			{
				queueName = "";
			}
			SteamId steamId = SteamClient.SteamId;
			var message = new
			{
				type = "register",
				steamId = ((object)(SteamId)(ref steamId)).ToString(),
				steamUsername = SteamClient.Name.ToString(),
				queueName = queueName,
				version = versionString,
				modVersion = "1.2.0.0",
				gameMode = gameMode
			};
			mls.LogInfo((object)("Registering with username: " + message.steamUsername + "-" + queueName));
			await SendMessage(message);
		}

		public void WaitingForResult()
		{
			waitingForResult = true;
			if ((gameMode == 2 && curDay < 3) || gameMode == 3)
			{
				matchLever.triggerScript.disabledHoverTip = "[ Waiting for end of day ]";
			}
			else
			{
				matchLever.triggerScript.disabledHoverTip = "[ Waiting for end of game ]";
			}
			matchLever.triggerScript.interactable = false;
			UpdateDisplayWaitingForResult();
		}

		public async Task SendMessage(object message)
		{
			string jsonMessage = JsonConvert.SerializeObject(message);
			byte[] bytes = Encoding.UTF8.GetBytes(jsonMessage);
			await localWS.SendAsync(new ArraySegment<byte>(bytes), WebSocketMessageType.Text, endOfMessage: true, CancellationToken.None);
			mls.LogInfo((object)"Sent message");
			if (debug)
			{
				mls.LogInfo((object)("message" + jsonMessage));
			}
		}

		public IEnumerator waitUntilGameIsReady()
		{
			mls.LogInfo((object)"Waiting until game is ready");
			yield return (object)new WaitUntil((Func<bool>)(() => gameReady));
			mls.LogInfo((object)"Starting game");
			matchLever.StartGame();
			gameStarted = true;
		}

		public IEnumerator waitUntilEndOfGame()
		{
			mls.LogInfo((object)"Wait until end of game");
			yield return (object)new WaitUntil((Func<bool>)(() => endOfGameResult != "" && waitingForResult));
			mls.LogInfo((object)"Ending game");
			yield return (object)new WaitForSeconds(3f);
			GameNetworkManager.Instance.Disconnect();
		}

		private async Task matchFound()
		{
			matchLever = Object.FindFirstObjectByType<StartMatchLever>();
			matchLever.triggerScript.interactable = true;
			StartOfRound.Instance.randomMapSeed = seedFromServer;
			matchLever.triggerScript.hoverTip = "[Pull to get ready]";
			mls.LogInfo((object)("match found using seed from server: " + seedFromServer));
			Random lmfao = new Random(seedFromServer);
			int[] startingCash = new int[20]
			{
				0, 0, 0, 0, 0, 30, 30, 30, 60, 60,
				60, 60, 300, 300, 300, 900, 900, 900, 1500, 1500
			};
			if (gameMode == 1)
			{
				Terminal obj = terminal;
				obj.groupCredits += startingCash[lmfao.Next(0, startingCash.Length)];
			}
			else if (curDay == 1)
			{
				terminal.groupCredits = startingCash[lmfao.Next(0, startingCash.Length)];
			}
			if (lmfao.Next(0, 10000) == 6942)
			{
				terminal.groupCredits = int.MaxValue;
			}
			if (gameMode == 1 || gameMode == 3)
			{
				foundMapID = getRandomMapID(lmfao);
				StartOfRound.Instance.ChangeLevel(foundMapID);
				StartOfRound.Instance.SetPlanetsWeather(0);
				gameReady = false;
				gameStarted = false;
				waitingForResult = false;
			}
			else if (gameMode == 2)
			{
				foundMapID = getRandomMapIDByTier(1 + enemyScore + yourScore, lmfao);
				StartOfRound.Instance.ChangeLevel(foundMapID);
				StartOfRound.Instance.SetPlanetsWeather(0);
				gameReady = false;
				gameStarted = false;
				waitingForResult = false;
			}
			UpdateInGameStatusText();
			string text = "";
			if (gameMode == 1)
			{
				text = "Best of 1\n";
			}
			else if (gameMode == 2)
			{
				text = "Best of 3\n";
			}
			else if (gameMode == 3)
			{
				text = "Endless\n";
			}
			if ((int)StartOfRound.Instance.currentLevel.currentWeather != -1)
			{
				text = text + "Weather: " + ((object)(LevelWeatherType)(ref StartOfRound.Instance.currentLevel.currentWeather)).ToString();
			}
			((TMP_Text)StartOfRound.Instance.screenLevelDescription).text = string.Concat(new string[4]
			{
				"Pull the lever to get ready\nOrbiting: ",
				StartOfRound.Instance.currentLevel.PlanetName,
				"\n",
				text
			});
			if (enemyScore == 0 && yourScore == 0)
			{
				HUDManager.Instance.DisplayTip("Match found", "Pull the lever to get ready", false, false, "LC_Tip1");
			}
			if (gameMode != 1)
			{
				GrabbableObject[] grabbableObjects = Object.FindObjectsOfType<GrabbableObject>();
				GrabbableObject[] array = grabbableObjects;
				foreach (GrabbableObject grabbableObject in array)
				{
					Terminal obj2 = terminal;
					obj2.groupCredits += grabbableObject.scrapValue;
					grabbableObject.SetScrapValue(0);
				}
			}
		}

		public void preventSaveLoading()
		{
			Instance.mls.LogInfo((object)"Preventing loading a save");
			GameNetworkManager.Instance.currentSaveFileName = "PleaseDontCheatThx";
			GameNetworkManager.Instance.saveFileNum = 69;
		}

		public void allowSaveLoading()
		{
			Instance.mls.LogInfo((object)"Allowing loading a save");
			GameNetworkManager.Instance.currentSaveFileName = "LCSaveFile1";
			GameNetworkManager.Instance.saveFileNum = 1;
		}
	}
}
namespace LCDuels.Patches
{
	[HarmonyPatch(typeof(HUDManager))]
	internal class HUDManagerPatch
	{
		[HarmonyPatch("ChangeControlTip")]
		[HarmonyPrefix]
		private static bool changeControlTipPatch()
		{
			return !LCDuelsModBase.playing;
		}

		[HarmonyPatch("ChangeControlTipMultiple")]
		[HarmonyPrefix]
		private static bool changeControlTipMultiplePatch()
		{
			return !LCDuelsModBase.playing;
		}

		[HarmonyPatch("ClearControlTips")]
		[HarmonyPrefix]
		private static bool clearControlTipPatch()
		{
			return !LCDuelsModBase.playing;
		}

		[HarmonyPatch("SubmitChat_performed")]
		[HarmonyPrefix]
		private static bool submitChatPatch()
		{
			if (LCDuelsModBase.playing)
			{
				if ((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null || !GameNetworkManager.Instance.localPlayerController.isTypingChat)
				{
					return true;
				}
				HUDManager instance = HUDManager.Instance;
				if (!string.IsNullOrEmpty(instance.chatTextField.text) && instance.chatTextField.text.Length < 50)
				{
					instance.AddTextToChatOnServer(instance.chatTextField.text, (int)instance.localPlayer.playerClientId);
				}
				LCDuelsModBase.Instance.SendMessage(new
				{
					type = "chat",
					value = instance.chatTextField.text
				});
				instance.localPlayer.isTypingChat = false;
				instance.chatTextField.text = "";
				EventSystem.current.SetSelectedGameObject((GameObject)null);
				instance.PingHUDElement(instance.Chat, 2f, 1f, 0.2f);
				((Behaviour)instance.typingIndicator).enabled = false;
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(TimeOfDay))]
	internal class TimeOfDayPatch
	{
		[HarmonyPatch("SetBuyingRateForDay")]
		[HarmonyPostfix]
		private static void SetBuyingRateForDayPatch()
		{
			if (LCDuelsModBase.Instance.gameMode == 3)
			{
				TimeOfDay.Instance.timeUntilDeadline = TimeOfDay.Instance.totalTime;
				LCDuelsModBase.Instance.mls.LogInfo((object)"!!!!!!!!!!!!!!Setting to 3");
				TimeOfDay.Instance.daysUntilDeadline = 3;
				((TMP_Text)StartOfRound.Instance.deadlineMonitorText).text = "DEADLINE:\n3 days";
			}
		}

		[HarmonyPatch("UpdateProfitQuotaCurrentTime")]
		[HarmonyPostfix]
		private static void UpdateProfitQuotaCurrentTimePatch()
		{
			if (LCDuelsModBase.Instance.gameMode == 3)
			{
				TimeOfDay.Instance.timeUntilDeadline = TimeOfDay.Instance.totalTime;
				LCDuelsModBase.Instance.mls.LogInfo((object)"!!!!!!!!!!!!!!Setting to 3");
				TimeOfDay.Instance.daysUntilDeadline = 3;
				((TMP_Text)StartOfRound.Instance.deadlineMonitorText).text = "DEADLINE:\n3 days";
			}
		}
	}
	[HarmonyPatch(typeof(SaveFileUISlot))]
	internal class SaveFileUISlotPatch
	{
		[HarmonyPatch("OnEnable")]
		[HarmonyPostfix]
		private static void OnEnablePatch(SaveFileUISlot __instance)
		{
			LCDuelsModBase.Instance.saveFileUISlots.Add(__instance);
			if (!LCDuelsModBase.playing)
			{
				return;
			}
			if (__instance.fileNum == -1)
			{
				((Behaviour)__instance).enabled = false;
				LCDuelsModBase.Instance.specialTipText = __instance.specialTipText;
				return;
			}
			Transform val = ((Component)__instance).gameObject.transform.Find("Text (TMP)");
			Debug.Log((object)val);
			TextMeshProUGUI component = ((Component)val).GetComponent<TextMeshProUGUI>();
			((TMP_Text)__instance.fileStatsText).text = "";
			((Behaviour)__instance.fileNotCompatibleAlert).enabled = false;
			switch (__instance.fileNum)
			{
			case -1:
				((Behaviour)__instance).enabled = false;
				break;
			case 0:
				((TMP_Text)component).text = "Best of 1";
				((TMP_Text)((Component)((Component)__instance).transform.parent.Find("EnterAName")).GetComponent<TextMeshProUGUI>()).text = "Game modes";
				break;
			case 1:
				((TMP_Text)component).text = "Best of 3";
				break;
			case 2:
				((TMP_Text)component).text = "Endless";
				break;
			}
		}

		[HarmonyPatch("SetFileToThis")]
		[HarmonyPostfix]
		private static void patchSetFileToThis(SaveFileUISlot __instance)
		{
			if (!LCDuelsModBase.playing)
			{
				return;
			}
			if (LCDuelsModBase.Instance.isPublicQueue)
			{
				((TMP_Text)LCDuelsModBase.Instance.specialTipText).text = "Try to get as much loot as possible in 1 day without dying.";
				GameNetworkManager.Instance.currentSaveFileName = "LCSaveFile1";
				GameNetworkManager.Instance.saveFileNum = 1;
				LCDuelsModBase.Instance.gameMode = 1;
			}
			else
			{
				switch (__instance.fileNum)
				{
				case 0:
					LCDuelsModBase.Instance.gameMode = 1;
					((TMP_Text)LCDuelsModBase.Instance.specialTipText).text = "Try to get as much loot as possible in 1 day without dying.";
					break;
				case 1:
					LCDuelsModBase.Instance.gameMode = 2;
					((TMP_Text)LCDuelsModBase.Instance.specialTipText).text = "You get a point for getting more loot in a day (Bo1 evaluation). You have 3 days to win.";
					break;
				case 2:
					LCDuelsModBase.Instance.gameMode = 3;
					((TMP_Text)LCDuelsModBase.Instance.specialTipText).text = "You get a point for getting more loot in a day (Bo1 evaluation). You can play as long as you want.";
					break;
				}
			}
			__instance.SetButtonColorForAllFileSlots();
			((Behaviour)LCDuelsModBase.Instance.specialTipText).enabled = true;
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	internal class RoundManagerPatch
	{
		[HarmonyPatch("YRotationThatFacesTheFarthestFromPosition")]
		[HarmonyPrefix]
		private static void prefixYRotationThatFacesTheFarthestFromPosition(ref bool ___hasInitializedLevelRandomSeed)
		{
			if (LCDuelsModBase.playing)
			{
				___hasInitializedLevelRandomSeed = false;
			}
		}

		[HarmonyPatch("YRotationThatFacesTheFarthestFromPosition")]
		[HarmonyPostfix]
		private static void postfixYRotationThatFacesTheFarthestFromPosition(ref bool ___hasInitializedLevelRandomSeed)
		{
			if (LCDuelsModBase.playing)
			{
				___hasInitializedLevelRandomSeed = true;
			}
		}

		[HarmonyPatch("YRotationThatFacesTheNearestFromPosition")]
		[HarmonyPrefix]
		private static void prefixYRotationThatFacesTheNearestFromPosition(ref bool ___hasInitializedLevelRandomSeed)
		{
			if (LCDuelsModBase.playing)
			{
				___hasInitializedLevelRandomSeed = false;
			}
		}

		[HarmonyPatch("YRotationThatFacesTheNearestFromPosition")]
		[HarmonyPostfix]
		private static void postfixYRotationThatFacesTheNearestFromPosition(ref bool ___hasInitializedLevelRandomSeed)
		{
			if (LCDuelsModBase.playing)
			{
				___hasInitializedLevelRandomSeed = true;
			}
		}
	}
	[HarmonyPatch(typeof(GameNetworkManager))]
	internal class GameNetworkManagerPatch
	{
		[HarmonyPatch("SaveGame")]
		[HarmonyPrefix]
		private static bool SaveGamePatch()
		{
			if (LCDuelsModBase.Instance.waitingForResult && LCDuelsModBase.Instance.gameMode == 1)
			{
				LCDuelsModBase.Instance.WaitingForResult();
			}
			return !LCDuelsModBase.playing;
		}

		[HarmonyPatch("JoinLobby")]
		[HarmonyPrefix]
		private static void PatchJoinLobby()
		{
			LCDuelsModBase.Instance.ResetValues(isEnabled: false);
		}

		[HarmonyPatch("DisconnectProcess")]
		[HarmonyPostfix]
		private static void PatchDisconnectProcess()
		{
			LCDuelsModBase.Instance.DisconnectDone = true;
		}

		[HarmonyPatch("Disconnect")]
		[HarmonyPrefix]
		private static void PatchDisconnect()
		{
			if (LCDuelsModBase.playing)
			{
				LCDuelsModBase.Instance.SendMessage(new
				{
					type = "leave"
				});
			}
		}

		[HarmonyPatch("Disconnect")]
		[HarmonyPostfix]
		private static void PatchDisconnectPost()
		{
			if (LCDuelsModBase.playing)
			{
				LCDuelsModBase.Instance.wsTerminated = true;
				LCDuelsModBase.Instance.localWS.CloseAsync(WebSocketCloseStatus.NormalClosure, "Closing the connection normally", CancellationToken.None);
			}
		}

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void PatchStart(GameNetworkManager __instance)
		{
			if (LCDuelsModBase.playing)
			{
				LCDuelsModBase.Instance.preventSaveLoading();
			}
		}
	}
	[HarmonyPatch(typeof(ItemDropship))]
	internal class ItemDropShipPatch
	{
		[HarmonyPatch("LandShipOnServer")]
		[HarmonyPrefix]
		private static bool StartPatch()
		{
			return !LCDuelsModBase.playing;
		}
	}
	[HarmonyPatch(typeof(RuntimeDungeon))]
	internal class RuntimeDungeonStartPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void StartPatch()
		{
			LCDuelsModBase.Instance.mls.LogInfo((object)"Runtime dungeon start!!!!!!!!!!!!!!!!!!!!!!!!!!");
		}
	}
	[HarmonyPatch(typeof(StartMatchLever))]
	internal class StartMatchLeverPatch
	{
		[HarmonyPatch("PullLever")]
		[HarmonyPrefix]
		private static bool patchPullLever(StartMatchLever __instance)
		{
			if (LCDuelsModBase.playing)
			{
				if (LCDuelsModBase.Instance.waitingForResult)
				{
					return false;
				}
				if (LCDuelsModBase.Instance.gameStarted)
				{
					return true;
				}
				if (LCDuelsModBase.Instance.gameReady)
				{
					return true;
				}
				LCDuelsModBase.Instance.mls.LogInfo((object)"Sending ready");
				LCDuelsModBase.Instance.SendMessage(new
				{
					type = "ready"
				});
				LCDuelsModBase.Instance.matchLever = __instance;
				((MonoBehaviour)__instance).StartCoroutine(LCDuelsModBase.Instance.waitUntilGameIsReady());
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch("ChooseNewRandomMapSeed")]
		[HarmonyPostfix]
		private static void patchChooseNewRandomMapSeed(ref float ___randomMapSeed)
		{
			if (LCDuelsModBase.playing)
			{
				LCDuelsModBase.Instance.mls.LogInfo((object)"patchChooseNewRandomMapSeed called");
				StartOfRound.Instance.ChangeLevel(LCDuelsModBase.Instance.foundMapID);
				___randomMapSeed = LCDuelsModBase.Instance.seedFromServer;
				StartOfRound.Instance.SetMapScreenInfoToCurrentLevel();
			}
		}

		[HarmonyPatch("StartGame")]
		[HarmonyPrefix]
		private static void patchtest1()
		{
			LCDuelsModBase.Instance.mls.LogInfo((object)"startgame called");
		}

		[HarmonyPatch("StartGame")]
		[HarmonyPostfix]
		private static void patchtest2()
		{
			LCDuelsModBase.Instance.mls.LogInfo((object)"startgame finished");
		}

		[HarmonyPatch("PlayFirstDayShipAnimation")]
		[HarmonyPrefix]
		private static bool patchPlayFirstDayShipAnimation()
		{
			return !LCDuelsModBase.playing;
		}

		[HarmonyPatch("FirePlayersAfterDeadlineClientRpc")]
		[HarmonyPostfix]
		private static void patchEject()
		{
			if (LCDuelsModBase.playing)
			{
				LCDuelsModBase.Instance.ejected = true;
				LCDuelsModBase.Instance.waitingForResult = true;
				LCDuelsModBase.Instance.SendMessage(new
				{
					type = "eject",
					curDay = LCDuelsModBase.Instance.curDay
				});
			}
		}

		[HarmonyPatch("PassTimeToNextDay")]
		[HarmonyPostfix]
		private static void patchPassTimeToNextDay()
		{
			if (LCDuelsModBase.playing)
			{
				LCDuelsModBase.Instance.mls.LogInfo((object)"Sending liftoff");
				LCDuelsModBase.Instance.WaitingForResult();
				LCDuelsModBase.Instance.curDay++;
				LCDuelsModBase.Instance.UpdateInGameStatusText();
				LCDuelsModBase.Instance.SendMessage(new
				{
					type = "liftoff",
					curDay = LCDuelsModBase.Instance.curDay
				});
				if (LCDuelsModBase.Instance.gameMode == 3)
				{
					TimeOfDay.Instance.daysUntilDeadline = 3;
				}
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch
	{
		[HarmonyPatch("SetItemInElevator")]
		[HarmonyPostfix]
		private static void patchSetItemInElevatorPatch()
		{
			if (!LCDuelsModBase.playing)
			{
				return;
			}
			GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>();
			LCDuelsModBase.Instance.currentValue = 0;
			GrabbableObject[] array2 = array;
			foreach (GrabbableObject val in array2)
			{
				if (val.isInShipRoom)
				{
					LCDuelsModBase.Instance.currentValue += val.scrapValue;
				}
			}
			LCDuelsModBase.Instance.mls.LogInfo((object)("Sending score " + LCDuelsModBase.Instance.currentValue));
			LCDuelsModBase.Instance.SendMessage(new
			{
				type = "score",
				value = LCDuelsModBase.Instance.currentValue.ToString()
			});
			LCDuelsModBase.Instance.UpdateInGameStatusText();
		}

		[HarmonyPatch("UpdatePlayerPositionClientRpc")]
		[HarmonyPostfix]
		private static void patchUpate(PlayerControllerB __instance)
		{
			if (__instance.isInHangarShipRoom != LCDuelsModBase.Instance.isInShip && LCDuelsModBase.playing && !__instance.playersManager.hangarDoorsClosed)
			{
				LCDuelsModBase.Instance.isInShip = __instance.isInHangarShipRoom;
				if (__instance.isInHangarShipRoom)
				{
					LCDuelsModBase.Instance.SendMessage(new
					{
						type = "position",
						value = "0"
					});
				}
				else
				{
					LCDuelsModBase.Instance.SendMessage(new
					{
						type = "position",
						value = "1"
					});
				}
			}
		}

		[HarmonyPatch("KillPlayer")]
		[HarmonyPostfix]
		private static void patchKillPlayer()
		{
			LCDuelsModBase.Instance.mls.LogInfo((object)"Sending death info");
			LCDuelsModBase.Instance.death = true;
			LCDuelsModBase.Instance.WaitingForResult();
			LCDuelsModBase.Instance.SendMessage(new
			{
				type = "death"
			});
		}
	}
	[HarmonyPatch(typeof(MenuManager))]
	internal class MenuManagerPatch
	{
		private static Button LCDbuttonbutton;

		[HarmonyPatch("OnEnable")]
		[HarmonyPostfix]
		private static void patchOnEnable(MenuManager __instance)
		{
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Expected O, but got Unknown
			if (GameNetworkManager.Instance.disableSteam || !((Object)(object)LCDbuttonbutton == (Object)null))
			{
				return;
			}
			TextMeshProUGUI[] componentsInChildren = __instance.HostSettingsOptionsNormal.GetComponentsInChildren<TextMeshProUGUI>();
			foreach (TextMeshProUGUI val in componentsInChildren)
			{
				if (((TMP_Text)val).text == "Public")
				{
					LCDuelsModBase.Instance.publicText = val;
				}
				else if (((TMP_Text)val).text == "Friends-only")
				{
					LCDuelsModBase.Instance.friendsText = val;
				}
				else if (((TMP_Text)val).text == "Server name:")
				{
					LCDuelsModBase.Instance.serverName = val;
				}
			}
			LCDuelsModBase.Instance.versionString = ((TMP_Text)__instance.versionNumberText).text;
			object value = Traverse.Create((object)__instance).Field("startHostButton").GetValue();
			Button val2 = (Button)((value is Button) ? value : null);
			LCDuelsModBase.Instance.menuManager = __instance;
			GameObject val3 = Object.Instantiate<GameObject>(((Component)val2).gameObject);
			val3.transform.SetParent((Transform)(object)((Component)((Component)val2).transform.parent).GetComponent<RectTransform>(), false);
			val3.transform.localPosition = ((Component)val2).transform.localPosition + (((Component)val2).transform.localPosition - __instance.joinCrewButtonContainer.transform.localPosition);
			val3.transform.localRotation = ((Component)val2).transform.localRotation;
			val3.transform.localScale = ((Component)val2).transform.localScale;
			((TMP_Text)val3.GetComponentInChildren<TextMeshProUGUI>()).text = "> Play LC Duels";
			LCDbuttonbutton = val3.GetComponent<Button>();
			((UnityEventBase)LCDbuttonbutton.onClick).RemoveAllListeners();
			((UnityEvent)LCDbuttonbutton.onClick).AddListener(new UnityAction(OnPlayLCDuelsMenuOpen));
		}

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void patchOnStart(MenuManager __instance)
		{
			if (LCDuelsModBase.Instance.endOfGameResult != "")
			{
				LCDuelsModBase.Instance.mls.LogInfo((object)"Setting reason for leaving game");
				__instance.SetLoadingScreen(false, (RoomEnter)5, LCDuelsModBase.Instance.endOfGameResult + ((!LCDuelsModBase.Instance.gameEndedWithError) ? ("\nLoot values:\n" + LCDuelsModBase.Instance.currentValue + " vs " + LCDuelsModBase.Instance.enemyPlayerScrap) : ""));
				LCDuelsModBase.Instance.endOfGameResult = "";
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void patchOnUpdate(MenuManager __instance)
		{
			if (LCDuelsModBase.playing && (Object)(object)((Component)__instance.lobbyTagInputField).gameObject != (Object)null)
			{
				((Component)__instance.lobbyTagInputField).gameObject.SetActive(false);
			}
		}

		[HarmonyPatch("ClickHostButton")]
		[HarmonyPrefix]
		private static void patchClickHostButton()
		{
			LCDuelsModBase.playing = false;
			LCDuelsModBase.Instance.allowSaveLoading();
			LCDuelsModBase.Instance.saveFileUISlots.Clear();
			ResetHostMenuValues();
			TextMeshProUGUI componentInChildren = ((Component)LCDuelsModBase.Instance.menuManager.lobbyNameInputField).GetComponentInChildren<TextMeshProUGUI>();
			((TMP_Text)componentInChildren).text = "Name your server...";
		}

		[HarmonyPatch("ConfirmHostButton")]
		[HarmonyPrefix]
		private static bool patchConfirm()
		{
			LCDuelsModBase.Instance.queueName = LCDuelsModBase.Instance.menuManager.lobbyNameInputField.text;
			if (LCDuelsModBase.playing)
			{
				OnHostLCDuels();
				return false;
			}
			return true;
		}

		private static void ResetHostMenuValues()
		{
			((TMP_Text)LCDuelsModBase.Instance.publicText).text = "Public";
			((TMP_Text)LCDuelsModBase.Instance.friendsText).text = "Friends-only";
			((TMP_Text)LCDuelsModBase.Instance.serverName).text = "Server name:";
		}

		[HarmonyPatch("HostSetLobbyPublic")]
		[HarmonyPostfix]
		private static void patchHostSetLobbyPublic(bool setPublic)
		{
			if (LCDuelsModBase.playing)
			{
				LCDuelsModBase.Instance.isPublicQueue = setPublic;
				if (setPublic)
				{
					((TMP_Text)LCDuelsModBase.Instance.menuManager.privatePublicDescription).text = "For public queue you have to follow the rules and play on the current version and its only Bo1 game mode.";
					LCDuelsModBase.Instance.menuManager.lobbyNameInputField.text = "";
					((Behaviour)LCDuelsModBase.Instance.menuManager.lobbyNameInputField).enabled = false;
					TextMeshProUGUI componentInChildren = ((Component)LCDuelsModBase.Instance.menuManager.lobbyNameInputField).GetComponentInChildren<TextMeshProUGUI>();
					((TMP_Text)componentInChildren).text = "Leave empty";
					SelectFileByFileNum(1);
				}
				else
				{
					((TMP_Text)LCDuelsModBase.Instance.menuManager.privatePublicDescription).text = "For private queue select the same queue name as the players you want to queue up with and make sure you have matching game mode, mods and version. Game mode is based on the first player that joins.";
					((Behaviour)LCDuelsModBase.Instance.menuManager.lobbyNameInputField).enabled = true;
					TextMeshProUGUI componentInChildren2 = ((Component)LCDuelsModBase.Instance.menuManager.lobbyNameInputField).GetComponentInChildren<TextMeshProUGUI>();
					((TMP_Text)componentInChildren2).text = "Name your queue...";
				}
			}
		}

		public static void OnHostLCDuels()
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			if (!LCDuelsModBase.Instance.isPublicQueue && LCDuelsModBase.Instance.menuManager.lobbyNameInputField.text == "")
			{
				LCDuelsModBase.Instance.menuManager.SetLoadingScreen(false, (RoomEnter)5, "Please enter private queue name");
				return;
			}
			LCDuelsModBase.Instance.mls.LogInfo((object)"OnHostClicked");
			LCDuelsModBase.Instance.ResetValues(isEnabled: true);
			LCDuelsModBase.Instance.preventSaveLoading();
			GameNetworkManager.Instance.lobbyHostSettings = new HostSettings("LCDuels game", false, "");
			GameNetworkManager.Instance.StartHost();
		}

		public static void SelectFileByFileNum(int fileNum)
		{
			foreach (SaveFileUISlot saveFileUISlot in LCDuelsModBase.Instance.saveFileUISlots)
			{
				if (saveFileUISlot.fileNum == fileNum)
				{
					saveFileUISlot.SetFileToThis();
				}
			}
		}

		public static void OnPlayLCDuelsMenuOpen()
		{
			LCDuelsModBase.Instance.saveFileUISlots.Clear();
			LCDuelsModBase.Instance.menuManager.HostSettingsScreen.SetActive(true);
			LCDuelsModBase.playing = true;
			((TMP_Text)LCDuelsModBase.Instance.publicText).text = "Public Queue";
			((TMP_Text)LCDuelsModBase.Instance.friendsText).text = "Private Queue";
			((TMP_Text)LCDuelsModBase.Instance.serverName).text = "Queue name:";
			if (GameNetworkManager.Instance.disableSteam)
			{
				string text = "Unnamed";
			}
			else if (!SteamClient.IsLoggedOn)
			{
				LCDuelsModBase.Instance.menuManager.DisplayMenuNotification("Could not connect to Steam servers! (If you just want to play on your local network, choose LAN on launch.)", "Continue");
				string text = "Unnamed";
			}
			else
			{
				string text = SteamClient.Name.ToString() + "'s Crew";
			}
			LCDuelsModBase.Instance.menuManager.lobbyNameInputField.text = "";
			LCDuelsModBase.Instance.menuManager.HostSetLobbyPublic(true);
			LCDuelsModBase.Instance.menuManager.EnableLeaderboardDisplay(false);
		}

		public static void PrintChildren(GameObject parent)
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			if (parent.transform.childCount == 0)
			{
				Component[] components = parent.GetComponents<Component>();
				Debug.Log((object)("Leaf Node: " + ((Object)parent).name));
				Component[] array = components;
				foreach (Component val in array)
				{
					Debug.Log((object)("Component: " + ((object)val).GetType()));
				}
				return;
			}
			foreach (Transform item in parent.transform)
			{
				Transform val2 = item;
				Debug.Log((object)("Name: " + ((Object)((Component)val2).gameObject).name + ", Type: " + ((object)((Component)val2).gameObject).GetType()));
				PrintChildren(((Component)val2).gameObject);
			}
		}
	}
	[HarmonyPatch(typeof(EntranceTeleport))]
	internal class EntranceTeleportPatch
	{
		[HarmonyPatch("TeleportPlayer")]
		[HarmonyPostfix]
		private static void patchStart(EntranceTeleport __instance)
		{
			if (LCDuelsModBase.playing)
			{
				if (__instance.isEntranceToBuilding)
				{
					LCDuelsModBase.Instance.SendMessage(new
					{
						type = "position",
						value = "2"
					});
				}
				else
				{
					LCDuelsModBase.Instance.SendMessage(new
					{
						type = "position",
						value = "1"
					});
				}
			}
		}
	}
	[HarmonyPatch(typeof(Terminal))]
	internal class TerminalPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void patchStart(Terminal __instance)
		{
			LCDuelsModBase.Instance.mls.LogInfo((object)("Is LCDuels enabled: " + LCDuelsModBase.playing));
			if (LCDuelsModBase.playing)
			{
				__instance.groupCredits = 0;
				GameNetworkManager.Instance.SetLobbyJoinable(false);
				GameNetworkManager.Instance.disallowConnection = true;
				LCDuelsModBase.Instance.terminal = __instance;
				((TMP_Text)StartOfRound.Instance.screenLevelDescription).text = "Waiting for other player\nYou can join our discord (dc.ontro.cz) to find people to play with.";
				StartMatchLever val = Object.FindFirstObjectByType<StartMatchLever>();
				val.triggerScript.disabledHoverTip = "[Wait for the other player]";
				val.triggerScript.interactable = false;
				LCDuelsModBase.Instance.UpdateInGameStatusText();
				Task.Run((Func<Task?>)LCDuelsModBase.Instance.InitWS);
				((MonoBehaviour)__instance).StartCoroutine(LCDuelsModBase.Instance.waitUntilEndOfGame());
				StartOfRound.Instance.DisableShipSpeaker();
			}
		}

		[HarmonyPatch("SyncGroupCreditsClientRpc")]
		[HarmonyPostfix]
		private static void patchSyncBoughItemsWithServer(Terminal __instance)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			if (!LCDuelsModBase.playing)
			{
				return;
			}
			foreach (int item in __instance.orderedItemsFromTerminal)
			{
				LCDuelsModBase.Instance.mls.LogInfo((object)("Spawing item" + item));
				GameObject val = Object.Instantiate<GameObject>(__instance.buyableItemsList[item].spawnPrefab, ((Component)GameNetworkManager.Instance.localPlayerController).transform.position, Quaternion.identity, StartOfRound.Instance.propsContainer);
				GrabbableObject component = val.GetComponent<GrabbableObject>();
				if ((Object)(object)component != (Object)null)
				{
					val.GetComponent<NetworkObject>().Spawn(false);
					component.itemProperties.canBeGrabbedBeforeGameStart = true;
					component.isInElevator = true;
					component.isInShipRoom = true;
					component.fallTime = 0f;
					component.parentObject = null;
					((Component)component).transform.SetParent(StartOfRound.Instance.elevatorTransform, true);
					StartOfRound instance = StartOfRound.Instance;
					instance.currentShipItemCount++;
				}
			}
			__instance.orderedItemsFromTerminal.Clear();
		}
	}
}