Decompiled source of LC TitleVideos v1.3.0

BepInEx/plugins/LC_TitleVideos.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LC_TitleVideos")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+3e05845dd589b22dca99cbff360fd1851c0f32f1")]
[assembly: AssemblyProduct("LC_TitleVideos")]
[assembly: AssemblyTitle("LC_TitleVideos")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LC_TitleVideos
{
	[BepInPlugin("LC_TitleVideos", "LC_TitleVideos", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private ConfigEntry<bool> configPlayAudio;

		private ConfigEntry<bool> configPlayDefaultVideos;

		private ConfigEntry<int> configLoopCount;

		private bool hasMultipleClips = false;

		private int loopCount = 0;

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			SceneManager.sceneLoaded += OnSceneLoaded;
			configPlayAudio = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "PlayAudio", false, "Plays the audio of the background videos.");
			configPlayDefaultVideos = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "PlayDefaultVideos", true, "Plays any built-in videos in 'DefaultTitleVideos' folders.");
			configLoopCount = ((BaseUnityPlugin)this).Config.Bind<int>("General", "LoopCount", -1, "Amount of times to loop videos before changing to a different one, set to -1 to disable alternating videos.");
			Logger.LogInfo((object)"Plugin LC_TitleVideos is loaded!");
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Expected O, but got Unknown
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			if (!((Scene)(ref scene)).name.StartsWith("MainMenu"))
			{
				return;
			}
			loopCount = 0;
			hasMultipleClips = false;
			GameObject val = GameObject.Find("MenuContainer");
			if ((Object)(object)val != (Object)null)
			{
				GameObject val2 = new GameObject("TitleVideo");
				val2.transform.parent = val.transform;
				RenderTexture val3 = new RenderTexture(Screen.width, Screen.height, 16);
				AudioSource val4 = val2.AddComponent<AudioSource>();
				VideoPlayer val5 = val2.AddComponent<VideoPlayer>();
				val5.url = PickRandomVideo();
				val5.targetTexture = val3;
				val5.isLooping = configLoopCount.Value <= -1;
				val5.audioOutputMode = (VideoAudioOutputMode)1;
				val5.SetTargetAudioSource((ushort)0, val4);
				val5.aspectRatio = (VideoAspectRatio)3;
				val5.loopPointReached += new EventHandler(OnLoopPointReached);
				val5.Play();
				val2.transform.localPosition = new Vector3(0f, 0f, 0f);
				val2.transform.localScale = new Vector3(1f, 1f, 1f);
				val2.transform.localEulerAngles = new Vector3(0f, 0f, 0f);
				val2.transform.SetSiblingIndex(0);
				RectTransform val6 = val2.AddComponent<RectTransform>();
				val6.anchorMin = new Vector2(0f, 0f);
				val6.anchorMax = new Vector2(1f, 1f);
				val6.sizeDelta = new Vector2(1f, 1f);
				RawImage val7 = val2.AddComponent<RawImage>();
				val7.texture = (Texture)(object)val3;
				((Graphic)val7).color = new Color(1f, 1f, 1f, 0.25f);
				if (!configPlayAudio.Value)
				{
					((Behaviour)val4).enabled = false;
				}
			}
		}

		private void OnLoopPointReached(VideoPlayer vp)
		{
			if (configLoopCount.Value <= -1)
			{
				return;
			}
			loopCount++;
			if (loopCount <= configLoopCount.Value)
			{
				vp.Play();
				return;
			}
			string text = vp.url;
			while (text == vp.url && hasMultipleClips)
			{
				text = PickRandomVideo();
			}
			loopCount = 0;
			vp.url = text;
			vp.Play();
		}

		private string PickRandomVideo()
		{
			string[] array = Directory.GetDirectories(Paths.BepInExRootPath, "TitleVideos", SearchOption.AllDirectories);
			if (configPlayDefaultVideos.Value)
			{
				array = Directory.GetDirectories(Paths.BepInExRootPath, "DefaultTitleVideos", SearchOption.AllDirectories).Concat(array).ToArray();
			}
			List<FileInfo> list = new List<FileInfo>();
			string[] array2 = array;
			foreach (string path in array2)
			{
				DirectoryInfo directoryInfo = new DirectoryInfo(path);
				FileInfo[] files = directoryInfo.GetFiles();
				foreach (FileInfo item in files)
				{
					list.Add(item);
				}
			}
			hasMultipleClips = list.Count > 1;
			if (list.Count > 0)
			{
				return list[Random.Range(0, list.Count)].FullName;
			}
			return "";
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "LC_TitleVideos";

		public const string PLUGIN_NAME = "LC_TitleVideos";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}