Decompiled source of LCModTest v0.0.2

BepInEx/plugins/HahaRiku.LCModTest.dll

Decompiled 5 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.Logging;
using HarmonyLib;
using LobbyCompatibility.Attributes;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Video;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("HahaRiku.LCModTest")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.0.2.0")]
[assembly: AssemblyInformationalVersion("0.0.2+4e5cc5b9159d8f29091855f8089c941a371c3aec")]
[assembly: AssemblyProduct("LCModTest")]
[assembly: AssemblyTitle("HahaRiku.LCModTest")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.2.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.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = 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 LCModTest
{
	[BepInPlugin("HahaRiku.LCModTest", "LCModTest", "0.0.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[LobbyCompatibility(/*Could not decode attribute arguments.*/)]
	public class LCModTest : BaseUnityPlugin
	{
		public static LCModTest Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Patch();
			Logger.LogInfo((object)"HahaRiku.LCModTest v0.0.2 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("HahaRiku.LCModTest");
			}
			Logger.LogDebug((object)"in LCModTest by HahaRiku, Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"in LCModTest by HahaRiku, Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "HahaRiku.LCModTest";

		public const string PLUGIN_NAME = "LCModTest";

		public const string PLUGIN_VERSION = "0.0.2";
	}
}
namespace LCModTest.Patches
{
	[HarmonyPatch(typeof(Terminal))]
	public class ShowAllUnlockableItemsPatch
	{
		[HarmonyPatch("RotateShipDecorSelection")]
		[HarmonyPrefix]
		private static bool RotateShipDecorSelectionPrefix(Terminal __instance)
		{
			__instance.ShipDecorSelection.Clear();
			for (int i = 0; i < StartOfRound.Instance.unlockablesList.unlockables.Count; i++)
			{
				if ((Object)(object)StartOfRound.Instance.unlockablesList.unlockables[i].shopSelectionNode != (Object)null && !StartOfRound.Instance.unlockablesList.unlockables[i].alwaysInStock)
				{
					__instance.ShipDecorSelection.Add(StartOfRound.Instance.unlockablesList.unlockables[i].shopSelectionNode);
				}
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(TVScript))]
	public class TVMoreVideos
	{
		private static bool isVideosLoaded = false;

		private static VideoClip[] finalTvClips = Array.Empty<VideoClip>();

		private static AudioClip[] finalAudioClips = Array.Empty<AudioClip>();

		private static AudioSource? audioSourceForVideo = null;

		[HarmonyPatch("OnEnable")]
		[HarmonyPrefix]
		private static bool TVScriptOnEnablePrefix(TVScript __instance)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Expected O, but got Unknown
			audioSourceForVideo = Object.Instantiate<AudioSource>(__instance.tvSFX, ((Component)__instance.tvSFX).transform.position, ((Component)__instance).transform.rotation, ((Component)__instance.tvSFX).transform.parent);
			__instance.video.audioOutputMode = (VideoAudioOutputMode)1;
			__instance.video.SetTargetAudioSource((ushort)0, audioSourceForVideo);
			__instance.video.playOnAwake = false;
			if (!isVideosLoaded)
			{
				finalTvClips = __instance.tvClips;
				finalAudioClips = __instance.tvAudioClips;
				List<string> list = Directory.GetDirectories(Paths.PluginPath, "moreTvVideos", SearchOption.AllDirectories).ToList();
				List<string> list2 = new List<string>();
				for (int i = 0; i < list.Count(); i++)
				{
					if (list[i] != "")
					{
						string[] files = Directory.GetFiles(list[i], "*.videobundle");
						list2.AddRange(files);
					}
				}
				for (int j = 0; j < list2.Count; j++)
				{
					string text = list2[j];
					Object[] array = AssetBundle.LoadFromFile(text).LoadAllAssets();
					for (int k = 0; k < array.Length; k++)
					{
						if (array[k] is VideoClip)
						{
							VideoClip val = (VideoClip)array[k];
							finalTvClips = CollectionExtensions.AddToArray<VideoClip>(finalTvClips, val);
							AudioClip val2 = AudioClip.Create("temp", 88200, 1, 44100, true);
							finalAudioClips = CollectionExtensions.AddToArray<AudioClip>(finalAudioClips, val2);
						}
					}
				}
				isVideosLoaded = true;
			}
			__instance.tvClips = finalTvClips;
			__instance.tvAudioClips = finalAudioClips;
			return true;
		}

		[HarmonyPatch("OnDisable")]
		[HarmonyPrefix]
		private static bool TVScriptOnDisablePrefix(TVScript __instance)
		{
			if ((Object)(object)audioSourceForVideo != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)audioSourceForVideo).gameObject);
				audioSourceForVideo = null;
			}
			return true;
		}

		[HarmonyPatch("TVFinishedClip")]
		[HarmonyPrefix]
		private static bool TVScriptTVFinishedClipPrefix(TVScript __instance)
		{
			__instance.video.Stop();
			__instance.tvSFX.Stop();
			__instance.video.SetTargetAudioSource((ushort)0, audioSourceForVideo);
			return true;
		}

		[HarmonyPatch("TurnTVOnOff")]
		[HarmonyPrefix]
		private static bool TVScriptTurnTVOnOff(TVScript __instance, bool on)
		{
			__instance.tvOn = on;
			if (on)
			{
				Traverse val = Traverse.Create((object)__instance);
				float num = (float)val.Field("currentClipTime").GetValue();
				int num2 = (int)val.Field("currentClip").GetValue();
				float time = num;
				if (num > __instance.tvAudioClips[num2].length)
				{
					time = 0f;
				}
				__instance.tvSFX.clip = __instance.tvAudioClips[num2];
				__instance.tvSFX.time = time;
				__instance.tvSFX.Play();
				__instance.tvSFX.PlayOneShot(__instance.switchTVOn);
				WalkieTalkie.TransmitOneShotAudio(__instance.tvSFX, __instance.switchTVOn, 1f);
			}
			else
			{
				__instance.tvSFX.Stop();
				__instance.tvSFX.PlayOneShot(__instance.switchTVOff);
				WalkieTalkie.TransmitOneShotAudio(__instance.tvSFX, __instance.switchTVOff, 1f);
			}
			return false;
		}
	}
}