using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
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 MushTV;
using TMPro;
using Television_Controller;
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: AssemblyTitle("MoreTV")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MoreTV")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("db36653d-24e2-474b-8240-93018150a1d9")]
[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 Television_Controller
{
[BepInPlugin("MushTV", "TVControls", "1.0.3")]
public class Plugin : BaseUnityPlugin
{
public static Plugin instance;
private static Harmony HarmonyLib;
public static Configs config;
public static Key volumeUpKey = (Key)14;
public static Key volumeDownKey = (Key)13;
public static string volumeHoverTip = "Volume up: [+]\nVolume down: [-]";
public static float volumeIncrement = 0.1f;
public static float maxDisplayedVolume = 1.5f;
public static float defaultVolume = 1f;
public static string volumeTip;
public static string filePath = "TVControls\\other\\yt-dlp.exe";
public static string downloadUrl = "https://github.com/yt-dlp/yt-dlp/releases/download/2024.07.25/yt-dlp.exe";
public static string expectedMD5 = "c9c729f678ba8afbc6007abaec159522";
private void Awake()
{
//IL_012f: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: Expected O, but got Unknown
instance = this;
config = new Configs();
config.GetConfig();
string text = config.languages.Value.ToLower();
string text2 = text;
if (text2 == "en")
{
config.GetLang().GetConfigEN();
}
WriteLogo();
if (!Directory.Exists("TVControls\\lang"))
{
Directory.CreateDirectory("TVControls\\lang");
}
if (!Directory.Exists("TVControls\\other"))
{
Directory.CreateDirectory("TVControls\\other");
}
if (File.Exists("TVControls\\other\\test.mp4"))
{
File.Delete("TVControls\\other\\test.mp4");
}
if (!File.Exists("TVControls\\cache"))
{
using StreamWriter streamWriter = File.CreateText("TVControls\\cache");
streamWriter.WriteLine(0.5f);
}
if (!File.Exists(filePath))
{
new Thread((ThreadStart)delegate
{
DownloadFileWithMD5(downloadUrl, filePath, expectedMD5);
}).Start();
}
HarmonyLib = new Harmony("MushTV");
HarmonyLib.PatchAll(typeof(TVControls));
HarmonyLib.PatchAll();
}
public void WriteLogo()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)" MUSH TV ");
}
private static void DownloadFileWithMD5(string downloadUrl, string filePath, string expectedMD5)
{
string text = "";
using WebClient client = new WebClient();
try
{
Console.WriteLine("Downloading file...");
DownloadFiles(new Uri(downloadUrl), filePath, client);
Console.WriteLine("Download complete.");
text = CalculateMD5(filePath);
if (text == expectedMD5)
{
Console.WriteLine("MD5 checksum verified. File is valid.");
return;
}
Console.WriteLine("MD5 checksum does not match. Deleting the file.");
File.Delete(filePath);
}
catch (Exception)
{
throw new Exception("Invalid file checksum at " + downloadUrl + " - expected " + expectedMD5 + ", got " + text);
}
}
private static string CalculateMD5(string filePath)
{
using MD5 mD = MD5.Create();
using FileStream inputStream = File.OpenRead(filePath);
byte[] array = mD.ComputeHash(inputStream);
return BitConverter.ToString(array).Replace("-", "").ToLower();
}
public static void DownloadFiles(Uri uri, string filename, WebClient client)
{
client.DownloadFileCompleted += Web_DownloadFileCompleted;
client.DownloadFileAsync(uri, filename);
}
private static void Web_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
Thread.CurrentThread.Abort();
}
public void Log(object message)
{
}
}
}
namespace MushTV
{
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 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("TVControls\\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\nVolume up [ + ]\nVolume down: [ - ]", (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)
languages = new ConfigFile("TVControls\\tv_controls.cfg", true).Bind<string>("General", "Languages", "en", "EN");
}
public Lang GetLang()
{
return lang;
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "MushTV";
public const string PLUGIN_NAME = "MushTV";
public const string PLUGIN_VERSION = "1.0.0";
}
public class TVControls
{
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 double positonTime = 0.0;
public static bool isPlayTelevision = false;
public static double volumeMain = 0.0;
public static bool startVolume = false;
[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_06cb: 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("TVControls\\other\\yt-dlp.exe"))
{
tigger.hoverTip = Plugin.config.GetLang().main_1.Value;
}
else
{
if (!startVolume)
{
tvScript.tvSFX.volume = 1f;
startVolume = true;
}
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 = "Enable/Disable Television : [E]\n@2 - @3\n@1\n".Replace("@1", Plugin.volumeTip).Replace("@2", text + ":" + text2 + ":" + text3).Replace("@3", text4 + ":" + text5 + ":" + text6);
if (((ButtonControl)Keyboard.current.minusKey).wasPressedThisFrame && volume > 0f)
{
float num3 = volume - 0.1f;
tvScript.tvSFX.volume = num3;
volumeMain = num3;
}
if (((ButtonControl)Keyboard.current.equalsKey).wasPressedThisFrame && volume < 1.5f)
{
float num4 = volume + 0.1f;
tvScript.tvSFX.volume = num4;
volumeMain = num4;
}
}
}
}
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 Pause()
{
if (!tvScript.video.isPaused)
{
if (!tvScript.tvOn)
{
tvScript.tvOn = true;
tvScript.video.time = positonTime;
SetTVScreenMaterial(tvScript, on: true);
tvScript.video.Play();
tvScript.tvSFX.Play();
tvScript.tvSFX.PlayOneShot(tvScript.switchTVOn);
WalkieTalkie.TransmitOneShotAudio(tvScript.tvSFX, tvScript.switchTVOn, 1f);
}
else
{
positonTime = tvScript.video.time;
tvScript.tvSFX.Pause();
tvScript.video.Pause();
tvScript.tvSFX.Pause();
WalkieTalkie.TransmitOneShotAudio(tvScript.tvSFX, tvScript.switchTVOff, 1f);
}
}
}
public static void Play()
{
if (tvScript.video.isPaused)
{
if (!tvScript.tvOn)
{
tvScript.tvOn = true;
tvScript.video.time = positonTime;
SetTVScreenMaterial(tvScript, on: true);
tvScript.video.Play();
tvScript.tvSFX.Play();
tvScript.tvSFX.PlayOneShot(tvScript.switchTVOn);
WalkieTalkie.TransmitOneShotAudio(tvScript.tvSFX, tvScript.switchTVOn, 1f);
}
else
{
tvScript.video.time = positonTime;
tvScript.tvOn = true;
SetTVScreenMaterial(tvScript, on: true);
tvScript.video.Play();
tvScript.tvSFX.UnPause();
tvScript.tvSFX.UnPause();
tvScript.tvSFX.Play();
tvScript.tvSFX.PlayOneShot(tvScript.switchTVOn);
WalkieTalkie.TransmitOneShotAudio(tvScript.tvSFX, tvScript.switchTVOn, 1f);
}
}
}
public static int FirstEmptyItemSlot(PlayerControllerB __instance)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Expected O, but got Unknown
int result = -1;
if ((Object)__instance.ItemSlots[__instance.currentItemSlot] == (Object)null)
{
result = __instance.currentItemSlot;
}
else
{
for (int i = 0; i < __instance.ItemSlots.Length; i++)
{
if ((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("TVControls\\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("TVControls\\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 "/help":
if (Plugin.config.languages.Value.ToLower().Equals("en"))
{
DrawString(__instance, "Commands:\n/yt [link] - Play video from YouTube \n/time [time] - Skips video to set time \n/pause - Pause the video \n/play - Play the video \n/restart - Restarts video", "Television", nameOfUserWhoTyped);
}
break;
case "/yt":
try
{
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("TVControls\\other\\test.mp4"))
{
File.Delete("TVControls\\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 = "TVControls\\other\\yt-dlp.exe";
process.StartInfo.UseShellExecute = false;
process.StartInfo.Arguments = "-f mp4 " + vs[1] + " -o \\test.%(ext)s";
process.StartInfo.WorkingDirectory = "TVControls\\other";
process.StartInfo.CreateNoWindow = true;
process.Start();
while (!flag)
{
if (flag2)
{
if (File.Exists("TVControls\\other\\test.mp4"))
{
flag = true;
break;
}
}
else if (Process.GetProcessById(process.Id).HasExited)
{
if (File.Exists("TVControls\\other\\test.mp4.part") || File.Exists("TVControls\\other\\test.mp4"))
{
flag2 = true;
}
else if (!File.Exists("TVControls\\other\\test.mp4"))
{
DrawString(__instance, Plugin.config.GetLang().main_11.Value, "Television", nameOfUserWhoTyped);
break;
}
}
Thread.Sleep(1000);
}
});
if (!File.Exists("TVControls\\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 + "\\TVControls\\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);
tvScript.tvOn = true;
tvScript.video.time = positonTime;
SetTVScreenMaterial(tvScript, on: true);
tvScript.video.Play();
tvScript.tvSFX.Play();
tvScript.tvSFX.PlayOneShot(tvScript.switchTVOn);
WalkieTalkie.TransmitOneShotAudio(tvScript.tvSFX, tvScript.switchTVOn, 1f);
break;
}
DrawString(__instance, Plugin.config.GetLang().main_6.Value, "Television", nameOfUserWhoTyped);
}
catch (Exception)
{
DrawString(__instance, "You must include a link to play.", "Television", nameOfUserWhoTyped);
break;
}
break;
case "/pause":
Pause();
DrawString(__instance, "\nPausing video.", "Television", nameOfUserWhoTyped);
break;
case "/play":
Play();
DrawString(__instance, "\nPlaying video.", "Television", nameOfUserWhoTyped);
break;
case "/time":
{
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;
positonTime = 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;
positonTime = 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;
positonTime = 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;
positonTime = 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;
positonTime = 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;
positonTime = 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;
positonTime = 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;
positonTime = 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;
positonTime = 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;
positonTime = correct3;
DrawString(__instance, Plugin.config.GetLang().main_12.Value.Replace("@1", arg3.ToString("00") + ":00:00"), "Television", nameOfUserWhoTyped);
}
break;
}
}
break;
}
}
break;
}
case "/restart":
if (tvScript.tvOn)
{
tvScript.video.time = 0.0;
DrawString(__instance, Plugin.config.GetLang().main_12.Value.Replace("@1", "00:00:00"), "Television", nameOfUserWhoTyped);
tvScript.tvOn = true;
if (tvScript.video.isPaused)
{
positonTime = 0.0;
SetTVScreenMaterial(tvScript, on: true);
tvScript.video.Play();
tvScript.tvSFX.UnPause();
tvScript.tvSFX.UnPause();
WalkieTalkie.TransmitOneShotAudio(tvScript.tvSFX, tvScript.switchTVOn, 1f);
}
SetTVScreenMaterial(tvScript, on: true);
tvScript.video.Play();
tvScript.tvSFX.Play();
tvScript.tvSFX.PlayOneShot(tvScript.switchTVOn);
WalkieTalkie.TransmitOneShotAudio(tvScript.tvSFX, tvScript.switchTVOn, 1f);
positonTime = 0.0;
}
break;
}
}
[HarmonyPatch(typeof(HUDManager), "SubmitChat_performed")]
[HarmonyPrefix]
private static bool SubmitChat_performed(HUDManager __instance, ref CallbackContext context)
{
//IL_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: 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 && (double)Vector3.Distance(((Component)GameNetworkManager.Instance.localPlayerController).transform.position, ((Component)StartOfRound.Instance.allPlayerScripts[i]).transform.position) > 24.399999618530273 && (!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 text = ((!string.IsNullOrEmpty(nameOfUserWhoTyped)) ? ("<color=#FF0000>" + nameOfUserWhoTyped + "</color>: <color=#FFFF00>'" + chatMessage + "'</color>") : ("<color=#7069ff>" + chatMessage + "</color>"));
string item = text;
__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)
{
positonTime = 0.0;
SetTVScreenMaterial(__instance, on: true);
__instance.video.Play();
__instance.tvSFX.UnPause();
__instance.tvSFX.UnPause();
__instance.tvSFX.Play();
__instance.tvSFX.PlayOneShot(__instance.switchTVOn);
WalkieTalkie.TransmitOneShotAudio(__instance.tvSFX, __instance.switchTVOn, 1f);
}
else
{
positonTime = 0.0;
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("TVControls\\cache"))
{
StreamReader streamReader = new StreamReader("TVControls\\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;
}
}
[HarmonyPatch]
internal class ChangeVolumePatcher
{
private static AudioPlayerItemType boomboxItems = new AudioPlayerItemType("Boomboxes", "Grab boombox: [E]");
private static AudioPlayerPlaceableType televisions = new AudioPlayerPlaceableType("Televisions");
[HarmonyPatch(typeof(PlayerControllerB), "Update")]
[HarmonyPrefix]
public static void GetObjectLookingAt(PlayerControllerB __instance)
{
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Expected O, but got Unknown
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Expected O, but got Unknown
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Expected O, but got Unknown
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Expected O, but got Unknown
boomboxItems.lookingAtDeviceType = false;
televisions.lookingAtDeviceType = false;
if (!((NetworkBehaviour)__instance).IsOwner || !__instance.isPlayerControlled || __instance.inTerminalMenu || __instance.isTypingChat || __instance.isPlayerDead)
{
return;
}
InteractTrigger hoveringOverTrigger = __instance.hoveringOverTrigger;
object obj;
if ((Object)(object)hoveringOverTrigger == (Object)null)
{
obj = null;
}
else
{
Transform parent = ((Component)hoveringOverTrigger).transform.parent;
obj = (((Object)(object)parent != (Object)null) ? ((Component)parent).gameObject : null);
}
GameObject val = (GameObject)obj;
if ((Object)val != (Object)null && ((Object)val).name.Contains("Television"))
{
televisions.lookingAtDeviceType = true;
}
if (!televisions.lookingAtDeviceType)
{
if ((Object)__instance.cursorTip != (Object)null && ((TMP_Text)__instance.cursorTip).text.Contains(boomboxItems.originalHoverTip))
{
boomboxItems.lookingAtDeviceType = true;
}
else if ((Object)__instance.currentlyHeldObjectServer != (Object)null && __instance.currentlyHeldObjectServer is BoomboxItem)
{
boomboxItems.lookingAtDeviceType = true;
}
}
}
[HarmonyPatch(typeof(PlayerControllerB), "Update")]
[HarmonyPostfix]
public static void GetVolumeInput(PlayerControllerB __instance)
{
if (!((NetworkBehaviour)__instance).IsOwner || !__instance.isPlayerControlled || __instance.inTerminalMenu || __instance.isTypingChat || __instance.isPlayerDead || (!boomboxItems.lookingAtDeviceType && !televisions.lookingAtDeviceType))
{
return;
}
float num = 0f;
if (((ButtonControl)Keyboard.current.minusKey).wasPressedThisFrame)
{
num = 0f - Plugin.volumeIncrement;
}
if (((ButtonControl)Keyboard.current.equalsKey).wasPressedThisFrame)
{
num = Plugin.volumeIncrement;
}
if (num != 0f)
{
AudioPlayerTypeBase audioPlayerTypeBase = null;
if (boomboxItems.lookingAtDeviceType)
{
audioPlayerTypeBase = boomboxItems;
}
else if (televisions.lookingAtDeviceType)
{
audioPlayerTypeBase = televisions;
}
if (audioPlayerTypeBase != null)
{
audioPlayerTypeBase.currentVolume = Mathf.Clamp(audioPlayerTypeBase.currentVolume + num, 0f, Plugin.maxDisplayedVolume);
audioPlayerTypeBase.UpdateVolumes();
audioPlayerTypeBase.UpdateTooltips();
}
}
}
[HarmonyPatch(typeof(BoomboxItem), "Start")]
[HarmonyPostfix]
public static void SetBoomboxHoverTip(BoomboxItem __instance)
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Expected O, but got Unknown
boomboxItems.audioSources.Add(__instance.boomboxAudio);
boomboxItems.items.Add((GrabbableObject)__instance);
((GrabbableObject)__instance).itemProperties.canBeGrabbedBeforeGameStart = true;
if (boomboxItems.defaultVolume == 0f)
{
boomboxItems.defaultVolume = __instance.boomboxAudio.volume;
}
if (boomboxItems.controlTooltips == null)
{
boomboxItems.controlTooltips = new List<string>(((GrabbableObject)__instance).itemProperties.toolTips);
boomboxItems.controlTooltips.Add("");
}
boomboxItems.UpdateTooltips();
boomboxItems.UpdateVolumes();
}
[HarmonyPatch(typeof(TVScript), "__initializeVariables")]
[HarmonyPostfix]
public static void SetTelevisionHoverTip(TVScript __instance)
{
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Expected O, but got Unknown
televisions.audioSources.Add(__instance.tvSFX);
Transform parent = ((Component)__instance).transform.parent;
InteractTrigger val = (((Object)(object)parent != (Object)null) ? ((Component)parent).GetComponentInChildren<InteractTrigger>() : null);
if (televisions.defaultVolume == 0f)
{
televisions.defaultVolume = __instance.tvSFX.volume;
}
if (!((Object)val == (Object)null))
{
televisions.triggers.Add(val);
televisions.UpdateTooltips();
televisions.UpdateVolumes();
}
}
}
internal abstract class AudioPlayerTypeBase
{
public string name;
public List<AudioSource> audioSources;
public string originalHoverTip;
public float defaultVolume;
public float currentVolume;
public bool lookingAtDeviceType;
public Type objectType;
public AudioPlayerTypeBase(string name, string originalHoverTip = "", float defaultVolume = 0f)
{
this.name = name;
audioSources = new List<AudioSource>();
this.originalHoverTip = originalHoverTip;
this.defaultVolume = defaultVolume;
currentVolume = Plugin.defaultVolume;
lookingAtDeviceType = false;
}
public void UpdateVolumes()
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Expected O, but got Unknown
for (int i = 0; i < audioSources.Count; i++)
{
if ((Object)audioSources[i] != (Object)null)
{
audioSources[i].volume = currentVolume / Plugin.maxDisplayedVolume;
}
}
}
public abstract void UpdateTooltips();
}
internal class AudioPlayerItemType : AudioPlayerTypeBase
{
public List<GrabbableObject> items;
public List<string> controlTooltips;
public AudioPlayerItemType(string name, string originalHoverTip = "", float defaultVolume = 0f)
: base(name, originalHoverTip, defaultVolume)
{
items = new List<GrabbableObject>();
}
public override void UpdateTooltips()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Expected O, but got Unknown
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Expected O, but got Unknown
//IL_0106: Unknown result type (might be due to invalid IL or missing references)
//IL_0111: Expected O, but got Unknown
for (int i = 0; i < items.Count; i++)
{
if ((Object)items[i] != (Object)null)
{
items[i].customGrabTooltip = $"{originalHoverTip}\n{Mathf.RoundToInt(currentVolume * 10f) * 10}% volume\n{Plugin.volumeHoverTip}";
controlTooltips[controlTooltips.Count - 1] = items[i].customGrabTooltip.Replace(originalHoverTip + "\n", "");
items[i].itemProperties.toolTips = controlTooltips.ToArray();
}
}
PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
if ((Object)localPlayerController != (Object)null && (Object)localPlayerController.currentlyHeldObjectServer != (Object)null && items.Contains(localPlayerController.currentlyHeldObjectServer))
{
localPlayerController.currentlyHeldObjectServer.EquipItem();
}
}
}
internal class AudioPlayerPlaceableType : AudioPlayerTypeBase
{
public List<InteractTrigger> triggers;
public AudioPlayerPlaceableType(string name, string originalHoverTip = "", float defaultVolume = 0f)
: base(name, originalHoverTip, defaultVolume)
{
triggers = new List<InteractTrigger>();
}
public override void UpdateTooltips()
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Expected O, but got Unknown
for (int i = 0; i < triggers.Count; i++)
{
if ((Object)triggers[i] != (Object)null)
{
Plugin.volumeTip = $"{originalHoverTip}\n{Mathf.RoundToInt(currentVolume * 10f) * 10}% volume\n{Plugin.volumeHoverTip}";
}
}
}
}
}
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 Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}