Decompiled source of Television Controller v1.0.3

BepInEx/plugins/Television_Controller.dll

Decompiled 11 months ago
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Video;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("MonoGame Team")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Television Controller")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Television_Controller")]
[assembly: AssemblyTitle("Television_Controller")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/MonoGame/MonoGame")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[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 Television_Controller
{
	[BepInPlugin("KoderTech.TelevisionController", "TelevisionController", "1.0.3")]
	public class Plugin : BaseUnityPlugin
	{
		public static Plugin instance;

		private static Harmony HarmonyLib;

		public static Configs config;

		private void Awake()
		{
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Expected O, but got Unknown
			instance = this;
			config = new Configs();
			config.GetConfig();
			string text = config.languages.Value.ToLower();
			string text2 = text;
			if (!(text2 == "ru"))
			{
				if (text2 == "en")
				{
					config.GetLang().GetConfigEN();
				}
			}
			else
			{
				config.GetLang().GetConfigRU();
			}
			WriteLogo();
			if (!Directory.Exists("TelevisionController\\lang"))
			{
				Directory.CreateDirectory("TelevisionController\\lang");
			}
			if (!Directory.Exists("TelevisionController\\other"))
			{
				Directory.CreateDirectory("TelevisionController\\other");
			}
			if (File.Exists("TelevisionController\\other\\test.mp4"))
			{
				File.Delete("TelevisionController\\other\\test.mp4");
			}
			if (!File.Exists("TelevisionController\\cache"))
			{
				using StreamWriter streamWriter = File.CreateText("TelevisionController\\cache");
				streamWriter.WriteLine(0.5f);
			}
			if (!File.Exists("TelevisionController\\other\\yt-dlp.exe"))
			{
				Thread thread = new Thread((ThreadStart)delegate
				{
					DownloadFiles(new Uri("https://github.com/yt-dlp/yt-dlp/releases/download/2023.11.16/yt-dlp.exe"), "TelevisionController\\other\\yt-dlp.exe");
				});
				thread.Start();
			}
			HarmonyLib = new Harmony("com.kodertech.TelevisionController");
			HarmonyLib.PatchAll(typeof(TelevisionController));
		}

		public void WriteLogo()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)" /$$$$$$$$        /$$                      /$$           /$$                            /$$$$$$                        /$$                         /$$ /$$                    ");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"|__  $$__/       | $$                     |__/          |__/                           /$$__  $$                      | $$                        | $$| $$                    ");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"   | $$  /$$$$$$ | $$  /$$$$$$  /$$    /$$ /$$  /$$$$$$$ /$$  /$$$$$$  /$$$$$$$       | $$  \\__/  /$$$$$$  /$$$$$$$  /$$$$$$    /$$$$$$   /$$$$$$ | $$| $$  /$$$$$$   /$$$$$$ ");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"   | $$ /$$__  $$| $$ /$$__  $$|  $$  /$$/| $$ /$$_____/| $$ /$$__  $$| $$__  $$      | $$       /$$__  $$| $$__  $$|_  $$_/   /$$__  $$ /$$__  $$| $$| $$ /$$__  $$ /$$__  $$");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"   | $$| $$$$$$$$| $$| $$$$$$$$ \\  $$/$$/ | $$|  $$$$$$ | $$| $$  \\ $$| $$  \\ $$      | $$      | $$  \\ $$| $$  \\ $$  | $$    | $$  \\__/| $$  \\ $$| $$| $$| $$$$$$$$| $$  \\__/");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"   | $$| $$_____/| $$| $$_____/  \\  $$$/  | $$ \\____  $$| $$| $$  | $$| $$  | $$      | $$    $$| $$  | $$| $$  | $$  | $$ /$$| $$      | $$  | $$| $$| $$| $$_____/| $$      ");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"   | $$|  $$$$$$$| $$|  $$$$$$$   \\  $/   | $$ /$$$$$$$/| $$|  $$$$$$/| $$  | $$      |  $$$$$$/|  $$$$$$/| $$  | $$  |  $$$$/| $$      |  $$$$$$/| $$| $$|  $$$$$$$| $$      ");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"   |__/ \\_______/|__/ \\_______/    \\_/    |__/|_______/ |__/ \\______/ |__/  |__/       \\______/  \\______/ |__/  |__/   \\___/  |__/       \\______/ |__/|__/ \\_______/|__/      ");
		}

		public static void DownloadFiles(Uri uri, string filename)
		{
			WebClient webClient = new WebClient();
			webClient.DownloadFileCompleted += Web_DownloadFileCompleted;
			webClient.DownloadFileAsync(uri, filename);
		}

		private static void Web_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
		{
			Thread.CurrentThread.Abort();
		}

		public void Log(object message)
		{
			((BaseUnityPlugin)this).Logger.LogInfo(message);
		}
	}
	public class Configs
	{
		public class Lang
		{
			public ConfigEntry<string> main_1;

			public ConfigEntry<string> main_2;

			public ConfigEntry<string> main_3;

			public ConfigEntry<string> main_4;

			public ConfigEntry<string> main_5;

			public ConfigEntry<string> main_6;

			public ConfigEntry<string> main_7;

			public ConfigEntry<string> main_8;

			public ConfigEntry<string> main_9;

			public ConfigEntry<string> main_10;

			public ConfigEntry<string> main_11;

			public ConfigEntry<string> main_12;

			public ConfigEntry<string> main_13;

			public void GetConfigRU()
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: Expected O, but got Unknown
				ConfigFile val = new ConfigFile("TelevisionController\\lang\\television_ru.cfg", true);
				main_1 = val.Bind<string>("General", "Main_1", "Пожалуйста, подождите, загружаются дополнительные библиотеки, чтобы модификация заработала.", (ConfigDescription)null);
				main_2 = val.Bind<string>("General", "Main_2", "Включить/Выключить Телевизор : [E]\n@2 - @3\n@1 громкость\nУвеличить громкость [PU]\nУменьшить громкость [PG]", (ConfigDescription)null);
				main_3 = val.Bind<string>("General", "Main_3", "Все дополнительные библиотеки загружены, теперь вы можете использовать команды для телевизора.", (ConfigDescription)null);
				main_4 = val.Bind<string>("General", "Main_4", "Подождите, видео еще загружается!", (ConfigDescription)null);
				main_5 = val.Bind<string>("General", "Main_5", "Команды:\n/tplay - Проиграть видео\n/ttime - Поставить позицию видео\n/treset - Сбросить позцию видео вначало\n/tposition - Включить/Выключить запоминания позиции после выключение телевизора\n/tvolume - Изменить громкость видео", (ConfigDescription)null);
				main_6 = val.Bind<string>("General", "Main_6", "Введите правильный URL-адрес!", (ConfigDescription)null);
				main_7 = val.Bind<string>("General", "Main_7", "Пожалуйста подождите...", (ConfigDescription)null);
				main_8 = val.Bind<string>("General", "Main_8", "Видео был загружен в телевизор", (ConfigDescription)null);
				main_9 = val.Bind<string>("General", "Main_9", "@1 изменил громкость видео @2", (ConfigDescription)null);
				main_10 = val.Bind<string>("General", "Main_10", "Введите правильную громкость видео (пример: 0, 10, 20, 30...)!", (ConfigDescription)null);
				main_11 = val.Bind<string>("General", "Main_11", "Ссылка недействительная!", (ConfigDescription)null);
				main_12 = val.Bind<string>("General", "Main_12", "Позиция видео изменена на @1!", (ConfigDescription)null);
				main_13 = val.Bind<string>("General", "Main_13", "Запоминание позиции @1!", (ConfigDescription)null);
			}

			public void GetConfigEN()
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: Expected O, but got Unknown
				ConfigFile val = new ConfigFile("TelevisionController\\lang\\television_en.cfg", true);
				main_1 = val.Bind<string>("General", "Main_1", "Please wait, additional libraries are being loaded for the modification to work.", (ConfigDescription)null);
				main_2 = val.Bind<string>("General", "Main_2", "Enable/Disable Television : [E]\n@2 - @3\n@1 volume\nIncrease volume [PU]\nDecrease volume [PG]", (ConfigDescription)null);
				main_3 = val.Bind<string>("General", "Main_3", "All libraries have loaded, now you can use the television commands.", (ConfigDescription)null);
				main_4 = val.Bind<string>("General", "Main_4", "Another video is being uploaded to the television!", (ConfigDescription)null);
				main_5 = val.Bind<string>("General", "Main_5", "Commands:\n/tplay - Play video\n/ttime - Place video position\n/treset - Reset the video position to the beginning\n/tposition - Turn on/off position memorization after turning off the TV\n/tvolume - Change video volume", (ConfigDescription)null);
				main_6 = val.Bind<string>("General", "Main_6", "Enter the correct URL!", (ConfigDescription)null);
				main_7 = val.Bind<string>("General", "Main_7", "Please wait...", (ConfigDescription)null);
				main_8 = val.Bind<string>("General", "Main_8", "The video was uploaded to the television", (ConfigDescription)null);
				main_9 = val.Bind<string>("General", "Main_9", "@1 changed the volume @2 of the television.", (ConfigDescription)null);
				main_10 = val.Bind<string>("General", "Main_10", "Enter the correct Volume (example: 0, 10, 20, 30...)!", (ConfigDescription)null);
				main_11 = val.Bind<string>("General", "Main_11", "Link is invalid!", (ConfigDescription)null);
				main_12 = val.Bind<string>("General", "Main_12", "Video position changed to @1!", (ConfigDescription)null);
				main_13 = val.Bind<string>("General", "Main_13", "Position memorization is @1!", (ConfigDescription)null);
			}
		}

		public ConfigEntry<bool> requstbattery;

		public ConfigEntry<string> languages;

		public static Lang lang = new Lang();

		public void GetConfig()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			ConfigFile val = new ConfigFile("TelevisionController\\television_controller.cfg", true);
			languages = val.Bind<string>("General", "Languages", "en", "EN/RU/AR");
		}

		public Lang GetLang()
		{
			return lang;
		}
	}
	public class TelevisionController
	{
		public static TVScript tvScript = new TVScript();

		public static InteractTrigger tigger = new InteractTrigger();

		public static string LastMessage;

		public static bool LoadingVideo = false;

		public static bool LoadingLibrary = false;

		public static string LastnameOfUserWhoTyped;

		public static string Lastname;

		public static double curretTime = 0.0;

		public static double totalTime = 0.0;

		public static bool positonSafe = true;

		public static double positonTime = 0.0;

		public static bool isPlayTelevision = false;

		public static double volumeMain = 0.0;

		[HarmonyPatch(typeof(PlayerControllerB), "SetHoverTipAndCurrentInteractTrigger")]
		[HarmonyPrefix]
		public static bool SetHoverTipAndCurrentInteractTrigger(PlayerControllerB __instance, ref RaycastHit ___hit, ref Ray ___interactRay, ref int ___playerMask, ref int ___interactableObjectsMask)
		{
			//IL_001e: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e9: Unknown result type (might be due to invalid IL or missing references)
			if (!__instance.isGrabbingObjectAnimation)
			{
				___interactRay = new Ray(((Component)__instance.gameplayCamera).transform.position, ((Component)__instance.gameplayCamera).transform.forward);
				if (Physics.Raycast(___interactRay, ref ___hit, __instance.grabDistance, ___interactableObjectsMask) && ((Component)((RaycastHit)(ref ___hit)).collider).gameObject.layer != 8)
				{
					string tag = ((Component)((RaycastHit)(ref ___hit)).collider).tag;
					if (!(tag == "PhysicsProp"))
					{
						if ((Object)(object)((Component)((RaycastHit)(ref ___hit)).transform).gameObject.GetComponent<InteractTrigger>() != (Object)null)
						{
							InteractTrigger component = ((Component)((RaycastHit)(ref ___hit)).transform).gameObject.GetComponent<InteractTrigger>();
							if (component.hoverTip == "Switch TV: [LMB]")
							{
								tigger = component;
							}
							if ((Object)(object)tigger != (Object)null)
							{
								if (!File.Exists("TelevisionController\\other\\yt-dlp.exe"))
								{
									tigger.hoverTip = Plugin.config.GetLang().main_1.Value;
								}
								else
								{
									float volume = tvScript.tvSFX.volume;
									int num = (int)curretTime % 3600;
									string text = Mathf.Floor((float)((int)curretTime / 3600)).ToString("00");
									string text2 = Mathf.Floor((float)(num / 60)).ToString("00");
									string text3 = Mathf.Floor((float)(num % 60)).ToString("00");
									int num2 = (int)totalTime % 3600;
									string text4 = Mathf.Floor((float)((int)totalTime / 3600)).ToString("00");
									string text5 = Mathf.Floor((float)(num2 / 60)).ToString("00");
									string text6 = Mathf.Floor((float)(num2 % 60)).ToString("00");
									tigger.hoverTip = Plugin.config.GetLang().main_2.Value.Replace("@1", $"{Math.Round(volume * 100f)}%").Replace("@2", text + ":" + text2 + ":" + text3).Replace("@3", text4 + ":" + text5 + ":" + text6);
									if (((ButtonControl)Keyboard.current.pageDownKey).wasPressedThisFrame && volume > 0f)
									{
										float num3 = volume - 0.1f;
										tvScript.tvSFX.volume = num3;
										volumeMain = num3;
										ChangeVolume();
									}
									if (((ButtonControl)Keyboard.current.pageUpKey).wasPressedThisFrame && volume < 1f)
									{
										float num4 = volume + 0.1f;
										tvScript.tvSFX.volume = num4;
										volumeMain = num4;
										ChangeVolume();
									}
								}
							}
						}
						if (tag == "InteractTrigger")
						{
							InteractTrigger component2 = ((Component)((RaycastHit)(ref ___hit)).transform).gameObject.GetComponent<InteractTrigger>();
							if ((Object)(object)component2 != (Object)(object)__instance.previousHoveringOverTrigger && (Object)(object)__instance.previousHoveringOverTrigger != (Object)null)
							{
								__instance.previousHoveringOverTrigger.isBeingHeldByPlayer = false;
							}
							if (!((Object)(object)component2 == (Object)null))
							{
								__instance.hoveringOverTrigger = component2;
								if (!component2.interactable)
								{
									__instance.cursorIcon.sprite = component2.disabledHoverIcon;
									((Behaviour)__instance.cursorIcon).enabled = (Object)(object)component2.disabledHoverIcon != (Object)null;
									((TMP_Text)__instance.cursorTip).text = component2.disabledHoverTip;
								}
								else if (component2.isPlayingSpecialAnimation)
								{
									((Behaviour)__instance.cursorIcon).enabled = false;
									((TMP_Text)__instance.cursorTip).text = "";
								}
								else if (__instance.isHoldingInteract)
								{
									if (__instance.twoHanded)
									{
										((TMP_Text)__instance.cursorTip).text = "[Hands full]";
									}
									else if (!string.IsNullOrEmpty(component2.holdTip))
									{
										((TMP_Text)__instance.cursorTip).text = component2.holdTip;
									}
								}
								else
								{
									((Behaviour)__instance.cursorIcon).enabled = true;
									__instance.cursorIcon.sprite = component2.hoverIcon;
									((TMP_Text)__instance.cursorTip).text = component2.hoverTip;
								}
							}
						}
					}
					else
					{
						if (FirstEmptyItemSlot(__instance) == -1)
						{
							((TMP_Text)__instance.cursorTip).text = "Inventory full!";
						}
						else
						{
							GrabbableObject component3 = ((Component)((RaycastHit)(ref ___hit)).collider).gameObject.GetComponent<GrabbableObject>();
							if (!GameNetworkManager.Instance.gameHasStarted && !component3.itemProperties.canBeGrabbedBeforeGameStart && (Object)(object)StartOfRound.Instance.testRoom == (Object)null)
							{
								((TMP_Text)__instance.cursorTip).text = "(Cannot pickup until ship is landed)";
							}
							if ((Object)(object)component3 != (Object)null && !string.IsNullOrEmpty(component3.customGrabTooltip))
							{
								((TMP_Text)__instance.cursorTip).text = component3.customGrabTooltip;
							}
						}
						((Behaviour)__instance.cursorIcon).enabled = true;
						__instance.cursorIcon.sprite = __instance.grabItemIcon;
					}
				}
				else
				{
					((Behaviour)__instance.cursorIcon).enabled = false;
					((TMP_Text)__instance.cursorTip).text = "";
					if ((Object)(object)__instance.hoveringOverTrigger != (Object)null)
					{
						__instance.previousHoveringOverTrigger = __instance.hoveringOverTrigger;
					}
					__instance.hoveringOverTrigger = null;
				}
			}
			if (StartOfRound.Instance.localPlayerUsingController)
			{
				StringBuilder stringBuilder = new StringBuilder(((TMP_Text)__instance.cursorTip).text);
				stringBuilder.Replace("[E]", "[X]");
				stringBuilder.Replace("[LMB]", "[X]");
				stringBuilder.Replace("[RMB]", "[R-Trigger]");
				stringBuilder.Replace("[F]", "[R-Shoulder]");
				stringBuilder.Replace("[Z]", "[L-Shoulder]");
				((TMP_Text)__instance.cursorTip).text = stringBuilder.ToString();
			}
			else
			{
				((TMP_Text)__instance.cursorTip).text = ((TMP_Text)__instance.cursorTip).text.Replace("[LMB]", "[E]");
			}
			if (!__instance.isFreeCamera && Physics.Raycast(___interactRay, ref ___hit, 5f, ___playerMask))
			{
				PlayerControllerB component4 = ((Component)((RaycastHit)(ref ___hit)).collider).gameObject.GetComponent<PlayerControllerB>();
				if ((Object)(object)component4 != (Object)null)
				{
					component4.ShowNameBillboard();
				}
			}
			return false;
		}

		public static void ChangeVolume()
		{
			using StreamWriter streamWriter = new StreamWriter("TelevisionController\\cache");
			streamWriter.WriteLine(volumeMain.ToString());
		}

		public static int FirstEmptyItemSlot(PlayerControllerB __instance)
		{
			int result = -1;
			if ((Object)(object)__instance.ItemSlots[__instance.currentItemSlot] == (Object)null)
			{
				result = __instance.currentItemSlot;
			}
			else
			{
				for (int i = 0; i < __instance.ItemSlots.Length; i++)
				{
					if ((Object)(object)__instance.ItemSlots[i] == (Object)null)
					{
						result = i;
						break;
					}
				}
			}
			return result;
		}

		[HarmonyPatch(typeof(HUDManager), "AddPlayerChatMessageServerRpc")]
		[HarmonyPostfix]
		[ServerRpc(RequireOwnership = false)]
		private static void AddPlayerChatMessageServerRpc(HUDManager __instance, string chatMessage, int playerId)
		{
			if (chatMessage.Length > 50)
			{
				MethodInfo method = ((object)__instance).GetType().GetMethod("AddPlayerChatMessageClientRpc", BindingFlags.Instance | BindingFlags.NonPublic);
				method.Invoke(__instance, new object[2] { chatMessage, playerId });
			}
		}

		[HarmonyPatch(typeof(HUDManager), "AddChatMessage")]
		[HarmonyPrefix]
		private static bool AddChatMessage(HUDManager __instance, string chatMessage, string nameOfUserWhoTyped)
		{
			if (!(__instance.lastChatMessage == chatMessage))
			{
				__instance.lastChatMessage = chatMessage;
				__instance.PingHUDElement(__instance.Chat, 4f, 1f, 0.2f);
				if (__instance.ChatMessageHistory.Count >= 4)
				{
					((TMP_Text)__instance.chatText).text.Remove(0, __instance.ChatMessageHistory[0].Length);
					__instance.ChatMessageHistory.Remove(__instance.ChatMessageHistory[0]);
				}
				StringBuilder stringBuilder = new StringBuilder(chatMessage);
				stringBuilder.Replace("[playerNum0]", StartOfRound.Instance.allPlayerScripts[0].playerUsername);
				stringBuilder.Replace("[playerNum1]", StartOfRound.Instance.allPlayerScripts[1].playerUsername);
				stringBuilder.Replace("[playerNum2]", StartOfRound.Instance.allPlayerScripts[2].playerUsername);
				stringBuilder.Replace("[playerNum3]", StartOfRound.Instance.allPlayerScripts[3].playerUsername);
				chatMessage = stringBuilder.ToString();
				string item = ((!string.IsNullOrEmpty(nameOfUserWhoTyped)) ? ("<color=#FF0000>" + nameOfUserWhoTyped + "</color>: <color=#FFFF00>'" + chatMessage + "'</color>") : ("<color=#7069ff>" + chatMessage + "</color>"));
				__instance.ChatMessageHistory.Add(item);
				((TMP_Text)__instance.chatText).text = "";
				for (int i = 0; i < __instance.ChatMessageHistory.Count; i++)
				{
					TextMeshProUGUI chatText = __instance.chatText;
					((TMP_Text)chatText).text = ((TMP_Text)chatText).text + "\n" + __instance.ChatMessageHistory[i];
				}
			}
			AddChatMessageMain(__instance, chatMessage, nameOfUserWhoTyped);
			return false;
		}

		[HarmonyPatch(typeof(HUDManager), "Update")]
		[HarmonyPrefix]
		private static void Updat(HUDManager __instance)
		{
			if (File.Exists("TelevisionController\\other\\yt-dlp.exe") && LoadingLibrary)
			{
				DrawString(__instance, Plugin.config.GetLang().main_3.Value, "Television", "Television");
				LoadingLibrary = false;
			}
		}

		public static async void AddChatMessageMain(HUDManager __instance, string chatMessage, string nameOfUserWhoTyped)
		{
			if (!File.Exists("TelevisionController\\other\\yt-dlp.exe"))
			{
				DrawString(__instance, Plugin.config.GetLang().main_1.Value, "Television", nameOfUserWhoTyped);
				LoadingLibrary = true;
				return;
			}
			string[] vs = chatMessage.Split(new char[1] { ' ' });
			switch (vs[0].Replace("/", ""))
			{
			case "thelp":
				if (Plugin.config.languages.Value.ToLower().Equals("en"))
				{
					DrawString(__instance, Plugin.config.GetLang().main_5.Value + "\nThe creator of the mod is KoderTech.\nWith love from Russia", "Television", nameOfUserWhoTyped);
				}
				if (Plugin.config.languages.Value.ToLower().Equals("ru"))
				{
					DrawString(__instance, Plugin.config.GetLang().main_5.Value + "\nСоздатель мода KoderTech.\nСпасибо что вы скачали именно этот мод)))", "Television", nameOfUserWhoTyped);
				}
				break;
			case "tplay":
			{
				Regex regex = new Regex("^https?:\\/\\/(?:www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b(?:[-a-zA-Z0-9()@:%_\\+.~#?&\\/=]*)$");
				if (regex.IsMatch(vs[1]))
				{
					string url = vs[1].Remove(0, 8);
					string text = url.Substring(0, url.IndexOf('/'));
					string text2 = text;
					if (!(text2 == "www.youtube.com"))
					{
						break;
					}
					if (vs[1].Contains("list"))
					{
						DrawString(__instance, Plugin.config.GetLang().main_6.Value, "Television", nameOfUserWhoTyped);
						break;
					}
					LoadingVideo = true;
					if (File.Exists("TelevisionController\\other\\test.mp4"))
					{
						File.Delete("TelevisionController\\other\\test.mp4");
					}
					DrawString(__instance, Plugin.config.GetLang().main_7.Value, "Television", nameOfUserWhoTyped);
					if (isPlayTelevision)
					{
						break;
					}
					isPlayTelevision = true;
					await Task.Run(delegate
					{
						bool flag = false;
						bool flag2 = false;
						Process process = new Process();
						process.StartInfo.FileName = "TelevisionController\\other\\yt-dlp.exe";
						process.StartInfo.UseShellExecute = false;
						process.StartInfo.Arguments = "-f mp4 " + vs[1] + " -o \\test.%(ext)s";
						process.StartInfo.WorkingDirectory = "TelevisionController\\other";
						process.StartInfo.CreateNoWindow = true;
						process.Start();
						while (!flag)
						{
							if (flag2)
							{
								if (File.Exists("TelevisionController\\other\\test.mp4"))
								{
									flag = true;
									break;
								}
							}
							else if (Process.GetProcessById(process.Id).HasExited)
							{
								if (File.Exists("TelevisionController\\other\\test.mp4.part") || File.Exists("TelevisionController\\other\\test.mp4"))
								{
									flag2 = true;
								}
								else if (!File.Exists("TelevisionController\\other\\test.mp4"))
								{
									DrawString(__instance, Plugin.config.GetLang().main_11.Value, "Television", nameOfUserWhoTyped);
									break;
								}
							}
							Thread.Sleep(1000);
						}
					});
					if (!File.Exists("TelevisionController\\other\\test.mp4"))
					{
						LoadingVideo = false;
						break;
					}
					if (tvScript.tvOn)
					{
						tvScript.tvOn = false;
						SetTVScreenMaterial(tvScript, on: false);
						tvScript.tvSFX.Stop();
						tvScript.video.Stop();
						tvScript.tvSFX.PlayOneShot(tvScript.switchTVOff);
						WalkieTalkie.TransmitOneShotAudio(tvScript.tvSFX, tvScript.switchTVOff, 1f);
					}
					tvScript.video.url = "file:///" + Paths.GameRootPath + "\\TelevisionController\\other\\test.mp4";
					tvScript.video.controlledAudioTrackCount = 1;
					tvScript.video.audioOutputMode = (VideoAudioOutputMode)1;
					tvScript.video.SetTargetAudioSource((ushort)0, tvScript.tvSFX);
					tvScript.video.Stop();
					tvScript.tvSFX.Stop();
					LoadingVideo = false;
					isPlayTelevision = false;
					positonTime = 0.0;
					DrawString(__instance, Plugin.config.GetLang().main_8.Value, "Television", nameOfUserWhoTyped);
				}
				else
				{
					DrawString(__instance, Plugin.config.GetLang().main_6.Value, "Television", nameOfUserWhoTyped);
				}
				break;
			}
			case "ttime":
			{
				string[] arg = vs[1].Split(new char[1] { ':' });
				switch (arg.Length)
				{
				case 2:
				{
					if (!tvScript.tvOn)
					{
						break;
					}
					int arg2 = Convert.ToInt32(arg[0]);
					int arg4 = Convert.ToInt32(arg[1]);
					switch (arg2)
					{
					case 0:
						switch (arg4)
						{
						case 0:
							tvScript.video.time = 0.0;
							DrawString(__instance, Plugin.config.GetLang().main_12.Value.Replace("@1", "00:00:00"), "Television", nameOfUserWhoTyped);
							break;
						case 1:
						case 2:
						case 3:
						case 4:
						case 5:
						case 6:
						case 7:
						case 8:
						case 9:
						case 10:
						case 11:
						case 12:
						case 13:
						case 14:
						case 15:
						case 16:
						case 17:
						case 18:
						case 19:
						case 20:
						case 21:
						case 22:
						case 23:
						case 24:
						case 25:
						case 26:
						case 27:
						case 28:
						case 29:
						case 30:
						case 31:
						case 32:
						case 33:
						case 34:
						case 35:
						case 36:
						case 37:
						case 38:
						case 39:
						case 40:
						case 41:
						case 42:
						case 43:
						case 44:
						case 45:
						case 46:
						case 47:
						case 48:
						case 49:
						case 50:
						case 51:
						case 52:
						case 53:
						case 54:
						case 55:
						case 56:
						case 57:
						case 58:
						case 59:
							tvScript.video.time = arg4;
							DrawString(__instance, Plugin.config.GetLang().main_12.Value.Replace("@1", "00:00:" + arg4.ToString("00")), "Television", nameOfUserWhoTyped);
							break;
						}
						break;
					case 1:
					case 2:
					case 3:
					case 4:
					case 5:
					case 6:
					case 7:
					case 8:
					case 9:
					case 10:
					case 11:
					case 12:
					case 13:
					case 14:
					case 15:
					case 16:
					case 17:
					case 18:
					case 19:
					case 20:
					case 21:
					case 22:
					case 23:
					case 24:
					case 25:
					case 26:
					case 27:
					case 28:
					case 29:
					case 30:
					case 31:
					case 32:
					case 33:
					case 34:
					case 35:
					case 36:
					case 37:
					case 38:
					case 39:
					case 40:
					case 41:
					case 42:
					case 43:
					case 44:
					case 45:
					case 46:
					case 47:
					case 48:
					case 49:
					case 50:
					case 51:
					case 52:
					case 53:
					case 54:
					case 55:
					case 56:
					case 57:
					case 58:
					case 59:
					{
						int correct = arg2 * 60;
						if (arg4 > 0 && arg4 < 60)
						{
							int correct_sec = correct + arg4;
							tvScript.video.time = correct_sec;
							DrawString(__instance, Plugin.config.GetLang().main_12.Value.Replace("@1", "00:" + arg2.ToString("00") + ":" + arg4.ToString("00")), "Television", nameOfUserWhoTyped);
						}
						else
						{
							tvScript.video.time = correct;
							DrawString(__instance, Plugin.config.GetLang().main_12.Value.Replace("@1", "00:" + arg2.ToString("00") + ":00"), "Television", nameOfUserWhoTyped);
						}
						break;
					}
					}
					break;
				}
				case 3:
				{
					if (!tvScript.tvOn)
					{
						break;
					}
					int arg3 = Convert.ToInt32(arg[0]);
					int arg5 = Convert.ToInt32(arg[1]);
					int arg6 = Convert.ToInt32(arg[2]);
					switch (arg3)
					{
					case 0:
						if (arg5 == 0 && arg6 == 0)
						{
							tvScript.video.time = 0.0;
							DrawString(__instance, Plugin.config.GetLang().main_12.Value.Replace("@1", "00:00:00"), "Television", nameOfUserWhoTyped);
						}
						else if (arg5 > 0 && arg5 < 60)
						{
							int correct2 = arg5 * 60;
							if (arg6 > 0 && arg6 < 60)
							{
								int correct_sec2 = correct2 + arg6;
								tvScript.video.time = correct_sec2;
								DrawString(__instance, Plugin.config.GetLang().main_12.Value.Replace("@1", "00:" + arg5.ToString("00") + ":" + arg6.ToString("00")), "Television", nameOfUserWhoTyped);
							}
							else
							{
								tvScript.video.time = correct2;
								DrawString(__instance, Plugin.config.GetLang().main_12.Value.Replace("@1", "00:" + arg5.ToString("00") + ":00"), "Television", nameOfUserWhoTyped);
							}
						}
						break;
					case 1:
					case 2:
					{
						int correct3 = arg3 * 3600;
						if (arg5 > 0 && arg5 < 60)
						{
							int correct_minutes = correct3 + arg5 * 60;
							if (arg6 > 0 && arg6 < 60)
							{
								int correct_sec3 = correct_minutes + arg6;
								tvScript.video.time = correct_sec3;
								DrawString(__instance, Plugin.config.GetLang().main_12.Value.Replace("@1", arg3.ToString("00") + ":" + arg5.ToString("00") + ":" + arg6.ToString("00")), "Television", nameOfUserWhoTyped);
							}
							else
							{
								tvScript.video.time = correct_minutes;
								DrawString(__instance, Plugin.config.GetLang().main_12.Value.Replace("@1", arg3.ToString("00") + ":" + arg5.ToString("00") + ":00"), "Television", nameOfUserWhoTyped);
							}
						}
						else
						{
							tvScript.video.time = correct3;
							DrawString(__instance, Plugin.config.GetLang().main_12.Value.Replace("@1", arg3.ToString("00") + ":00:00"), "Television", nameOfUserWhoTyped);
						}
						break;
					}
					}
					break;
				}
				}
				break;
			}
			case "tposition":
			{
				string text3 = Plugin.config.languages.Value.ToLower();
				string text4 = text3;
				string text5 = text4;
				if (!(text5 == "ru"))
				{
					if (text5 == "en")
					{
						if (vs[1].ToLower() == "true")
						{
							positonSafe = true;
						}
						if (vs[1].ToLower() == "false")
						{
							positonSafe = false;
						}
						string mess_en_correct = (positonSafe ? "enabled" : "disabled");
						DrawString(__instance, Plugin.config.GetLang().main_13.Value.Replace("@1", mess_en_correct ?? ""), "Television", nameOfUserWhoTyped);
					}
				}
				else
				{
					if (vs[1].ToLower() == "true")
					{
						positonSafe = true;
					}
					if (vs[1].ToLower() == "false")
					{
						positonSafe = false;
					}
					string mess_ru_correct = (positonSafe ? "включено" : "выключено");
					DrawString(__instance, Plugin.config.GetLang().main_13.Value.Replace("@1", mess_ru_correct ?? ""), "Television", nameOfUserWhoTyped);
				}
				break;
			}
			case "treset":
				if (tvScript.tvOn)
				{
					tvScript.video.time = 0.0;
					DrawString(__instance, Plugin.config.GetLang().main_12.Value.Replace("@1", "00:00:00"), "Television", nameOfUserWhoTyped);
				}
				break;
			case "tvolume":
			{
				float volume = tvScript.tvSFX.volume;
				float correct_volume = (float)(Convert.ToInt32(vs[1]) / 10) * 0.1f;
				if (volume != correct_volume && (volume < correct_volume || volume > correct_volume))
				{
					tvScript.tvSFX.volume = correct_volume;
					volumeMain = correct_volume;
					ChangeVolume();
					DrawString(__instance, Plugin.config.GetLang().main_9.Value.Replace("@1", nameOfUserWhoTyped ?? "").Replace("@2", vs[1] + "%"), "Television", nameOfUserWhoTyped);
				}
				break;
			}
			}
		}

		[HarmonyPatch(typeof(HUDManager), "SubmitChat_performed")]
		[HarmonyPrefix]
		private static bool SubmitChat_performed(HUDManager __instance, ref CallbackContext context)
		{
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			if (!LoadingVideo)
			{
				__instance.localPlayer = GameNetworkManager.Instance.localPlayerController;
				if (((CallbackContext)(ref context)).performed && !((Object)(object)__instance.localPlayer == (Object)null) && __instance.localPlayer.isTypingChat && ((((NetworkBehaviour)__instance.localPlayer).IsOwner && (!((NetworkBehaviour)__instance).IsServer || __instance.localPlayer.isHostPlayerObject)) || __instance.localPlayer.isTestingPlayer) && !__instance.localPlayer.isPlayerDead)
				{
					if (!string.IsNullOrEmpty(__instance.chatTextField.text) && __instance.chatTextField.text.Length < 200)
					{
						__instance.AddTextToChatOnServer(__instance.chatTextField.text, (int)__instance.localPlayer.playerClientId);
					}
					for (int i = 0; i < StartOfRound.Instance.allPlayerScripts.Length; i++)
					{
						if (StartOfRound.Instance.allPlayerScripts[i].isPlayerControlled && Vector3.Distance(((Component)GameNetworkManager.Instance.localPlayerController).transform.position, ((Component)StartOfRound.Instance.allPlayerScripts[i]).transform.position) > 24.4f && (!GameNetworkManager.Instance.localPlayerController.holdingWalkieTalkie || !StartOfRound.Instance.allPlayerScripts[i].holdingWalkieTalkie))
						{
							__instance.playerCouldRecieveTextChatAnimator.SetTrigger("ping");
							break;
						}
					}
					__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 false;
		}

		public static void DrawString(HUDManager __instance, string chatMessage, string nameOfUserWhoTyped, string? name)
		{
			if (!(LastMessage == chatMessage))
			{
				LastMessage = chatMessage;
				LastnameOfUserWhoTyped = name;
				__instance.PingHUDElement(__instance.Chat, 4f, 1f, 0.2f);
				if (__instance.ChatMessageHistory.Count >= 4)
				{
					((TMP_Text)__instance.chatText).text.Remove(0, __instance.ChatMessageHistory[0].Length);
					__instance.ChatMessageHistory.Remove(__instance.ChatMessageHistory[0]);
				}
				StringBuilder stringBuilder = new StringBuilder(chatMessage);
				stringBuilder.Replace("[playerNum0]", StartOfRound.Instance.allPlayerScripts[0].playerUsername);
				stringBuilder.Replace("[playerNum1]", StartOfRound.Instance.allPlayerScripts[1].playerUsername);
				stringBuilder.Replace("[playerNum2]", StartOfRound.Instance.allPlayerScripts[2].playerUsername);
				stringBuilder.Replace("[playerNum3]", StartOfRound.Instance.allPlayerScripts[3].playerUsername);
				chatMessage = stringBuilder.ToString();
				string item = ((!string.IsNullOrEmpty(nameOfUserWhoTyped)) ? ("<color=#FF0000>" + nameOfUserWhoTyped + "</color>: <color=#FFFF00>'" + chatMessage + "'</color>") : ("<color=#7069ff>" + chatMessage + "</color>"));
				__instance.ChatMessageHistory.Add(item);
				((TMP_Text)__instance.chatText).text = "";
				for (int i = 0; i < __instance.ChatMessageHistory.Count; i++)
				{
					TextMeshProUGUI chatText = __instance.chatText;
					((TMP_Text)chatText).text = ((TMP_Text)chatText).text + "\n" + __instance.ChatMessageHistory[i];
				}
			}
		}

		[HarmonyPatch(typeof(HUDManager), "Update")]
		[HarmonyPostfix]
		private static void StartPostfixs(HUDManager __instance)
		{
		}

		[HarmonyPatch(typeof(HUDManager), "Start")]
		[HarmonyPostfix]
		private static void StartPostfix(HUDManager __instance)
		{
			__instance.chatTextField.characterLimit = 200;
		}

		[HarmonyPatch(typeof(TVScript), "TurnTVOnOff")]
		[HarmonyPrefix]
		public static bool TurnTVOnOff(TVScript __instance, bool on)
		{
			__instance.tvOn = on;
			if (on)
			{
				if (positonSafe)
				{
					tvScript.video.time = positonTime;
				}
				SetTVScreenMaterial(__instance, on: true);
				__instance.video.Play();
				__instance.tvSFX.Play();
				__instance.tvSFX.PlayOneShot(__instance.switchTVOn);
				WalkieTalkie.TransmitOneShotAudio(__instance.tvSFX, __instance.switchTVOn, 1f);
			}
			else
			{
				if (positonSafe)
				{
					positonTime = tvScript.video.time;
				}
				SetTVScreenMaterial(__instance, on: false);
				__instance.tvSFX.Stop();
				__instance.video.Stop();
				__instance.tvSFX.PlayOneShot(__instance.switchTVOff);
				WalkieTalkie.TransmitOneShotAudio(__instance.tvSFX, __instance.switchTVOff, 1f);
			}
			return false;
		}

		public static void SetTVScreenMaterial(TVScript __instance, bool on)
		{
			Material[] sharedMaterials = ((Renderer)__instance.tvMesh).sharedMaterials;
			if (on)
			{
				sharedMaterials[1] = __instance.tvOnMaterial;
			}
			else
			{
				sharedMaterials[1] = __instance.tvOffMaterial;
			}
			((Renderer)__instance.tvMesh).sharedMaterials = sharedMaterials;
			((Behaviour)__instance.tvLight).enabled = on;
		}

		[HarmonyPatch(typeof(TVScript), "TVFinishedClip")]
		[HarmonyPrefix]
		public static bool TVFinishedClip()
		{
			return false;
		}

		[HarmonyPatch(typeof(TVScript), "Update")]
		[HarmonyPrefix]
		public static bool Update()
		{
			curretTime = tvScript.video.time;
			totalTime = tvScript.video.length;
			return false;
		}

		[HarmonyPatch(typeof(TVScript), "OnEnable")]
		[HarmonyPrefix]
		public static bool Start(TVScript __instance)
		{
			tvScript = __instance;
			__instance.video.clip = null;
			__instance.tvSFX.clip = null;
			if (File.Exists("TelevisionController\\cache"))
			{
				using StreamReader streamReader = new StreamReader("TelevisionController\\cache");
				string value;
				while ((value = streamReader.ReadLine()) != null)
				{
					__instance.tvSFX.volume = Convert.ToSingle(value);
				}
			}
			else
			{
				__instance.tvSFX.volume = 0.5f;
			}
			__instance.video.Stop();
			__instance.tvSFX.Stop();
			return false;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "Television_Controller";

		public const string PLUGIN_NAME = "Television_Controller";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}