Decompiled source of LBY Mod v1.0.0

plugins/LethalCompanyTemplate.dll

Decompiled 8 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
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("LethalCompanyTemplate")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A template for Lethal Company")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LethalCompanyTemplate")]
[assembly: AssemblyTitle("LethalCompanyTemplate")]
[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 LethalCompanyTemplate
{
	[BepInPlugin("com.noiseminded.plugins.testplugin", "Test Plug-in", "1.0.0.0")]
	[BepInProcess("Lethal Company.exe")]
	public class Plugin : BaseUnityPlugin
	{
		private void Awake()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin LethalCompanyTemplate is loaded!");
			Harmony val = new Harmony("com.noiseminded.plugins.testplugin");
			val.PatchAll(typeof(TexturePatcher));
			val.PatchAll(typeof(TVVideoPatcher));
		}
	}
	public class TexturePatcher
	{
		public static string TextureFolder;

		[HarmonyPatch(typeof(TimeOfDay), "Start")]
		[HarmonyPostfix]
		public static void PostFix_TextureChanger()
		{
			TextureFolder = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "CustomTextures");
			ChangeTexture("Environment/HangarShip/Plane.001", "posters1.png");
			ChangeTexture("Environment/HangarShip/Plane.001", "posters2.png", 1);
		}

		private static void ChangeTexture(string objectPath, string textureName, int materialSlot = 0)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			string path = Path.Combine(TextureFolder, textureName);
			byte[] array = File.ReadAllBytes(path);
			Texture2D val = new Texture2D(2, 2);
			ImageConversion.LoadImage(val, array);
			GameObject.Find(objectPath).GetComponent<Renderer>().materials[materialSlot].mainTexture = (Texture)val;
		}
	}
	public class TVVideoPatcher
	{
		public static string TextureFolder;

		public static string filePath = "BepInEx/plugins/CustomVideoFiles/";

		public static string videoFilename = "television_video.mp4";

		public static string fullPath => filePath + videoFilename;

		[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:///" + fullPath;
				__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)
			{
				SetTVScreenMaterial(__instance, b: true);
				__instance.video.Play();
				__instance.tvSFX.Play();
				__instance.tvSFX.PlayOneShot(__instance.switchTVOn);
			}
			else
			{
				SetTVScreenMaterial(__instance, b: false);
				__instance.tvSFX.Stop();
				__instance.tvSFX.PlayOneShot(__instance.switchTVOff);
				__instance.video.Stop();
			}
			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 });
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "LethalCompanyTemplate";

		public const string PLUGIN_NAME = "LethalCompanyTemplate";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}