Decompiled source of Whistle Josh Hutcherson v1.0.0

CustomTelevisionVideo.dll

Decompiled a year ago
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
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("CustomTelevisionVideo")]
[assembly: AssemblyDescription("Mod made by flipf17")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CustomTelevisionVideo")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("bf8ba009-dc9e-4448-a9c0-9ea880f19ee6")]
[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 CustomTelevisionVideo
{
	public static class ConfigSettings
	{
		public static ConfigEntry<string> videoPath;

		public static void BindConfigSettings()
		{
			Plugin.Log("BindingConfigs");
			videoPath = ((BaseUnityPlugin)Plugin.instance).Config.Bind<string>("CustomTelevisionVideo", "CustomVideoPath", "FlipMods-CustomTelevisionVideo/television_video.mp4", "Absolute or local video path. Use forward slashes in your path. Local paths are local to the BepInEx/plugins folder, and should not begin with a slash.");
		}
	}
	[BepInPlugin("FlipMods.CustomTelevisionVideo", "CustomTelevisionVideo", "1.1.3")]
	public class Plugin : BaseUnityPlugin
	{
		private Harmony _harmony;

		public static Plugin instance;

		public static string filePath;

		private void Awake()
		{
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			instance = this;
			ConfigSettings.BindConfigSettings();
			filePath = ConfigSettings.videoPath.Value;
			if (filePath.Length <= 0 || Enumerable.Contains(filePath, ' '))
			{
				filePath = ((ConfigEntryBase)ConfigSettings.videoPath).DefaultValue.ToString();
			}
			filePath = filePath.Replace('/', Path.DirectorySeparatorChar);
			if (!Path.IsPathRooted(filePath))
			{
				filePath = Path.Combine(Paths.PluginPath, filePath.TrimStart(new char[1] { '/' }));
			}
			Log("Using path from config: " + filePath);
			_harmony = new Harmony("CustomTelevisionVideo");
			_harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"CustomTelevisionVideo mod loaded");
		}

		public static void Log(string message)
		{
			((BaseUnityPlugin)instance).Logger.LogInfo((object)message);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "FlipMods.CustomTelevisionVideo";

		public const string PLUGIN_NAME = "CustomTelevisionVideo";

		public const string PLUGIN_VERSION = "1.1.3";
	}
}
namespace CustomTelevisionVideo.Patches
{
	[HarmonyPatch]
	internal class CustomTelevisionVideoPatcher
	{
		[HarmonyPatch(typeof(TVScript), "TVFinishedClip")]
		[HarmonyPrefix]
		public static bool TVFinishedClip()
		{
			return false;
		}

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

		[HarmonyPatch(typeof(TVScript), "TurnTVOnOff")]
		[HarmonyPrefix]
		public static bool TurnTVOnOff(bool on, TVScript __instance)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Invalid comparison between Unknown and I4
			__instance.tvOn = on;
			if ((int)__instance.video.source != 1 || __instance.video.url == "")
			{
				__instance.video.clip = null;
				__instance.tvSFX.clip = null;
				__instance.video.url = $"file://{Plugin.filePath}";
				__instance.video.source = (VideoSource)1;
				__instance.video.controlledAudioTrackCount = 1;
				__instance.video.audioOutputMode = (VideoAudioOutputMode)1;
				__instance.video.SetTargetAudioSource((ushort)0, __instance.tvSFX);
				__instance.video.Prepare();
				__instance.video.Stop();
				__instance.tvSFX.Stop();
			}
			if (on)
			{
				Plugin.Log("Turning on TV");
				SetTVScreenMaterial(__instance, b: true);
				__instance.video.Play();
				__instance.tvSFX.Play();
				__instance.tvSFX.PlayOneShot(__instance.switchTVOn);
				WalkieTalkie.TransmitOneShotAudio(__instance.tvSFX, __instance.switchTVOn, 1f);
			}
			else
			{
				Plugin.Log("Turning off TV");
				SetTVScreenMaterial(__instance, b: false);
				__instance.tvSFX.Stop();
				__instance.tvSFX.PlayOneShot(__instance.switchTVOff);
				__instance.video.Stop();
				WalkieTalkie.TransmitOneShotAudio(__instance.tvSFX, __instance.switchTVOff, 1f);
			}
			return false;
		}

		public static void SetTVScreenMaterial(TVScript instance, bool b)
		{
			MethodInfo method = ((object)instance).GetType().GetMethod("SetTVScreenMaterial", BindingFlags.Instance | BindingFlags.NonPublic);
			method.Invoke(instance, new object[1] { b });
		}
	}
}