Decompiled source of A Coffin For William v1.0.0

ACoffinForWilliam.dll

Decompiled 14 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using Microsoft.CodeAnalysis;
using PluginConfig.API;
using PluginConfig.API.Fields;
using PluginConfig.API.Functionals;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ACoffinForWilliam")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d2848df53f0cdafc18a645af2853ac799e90943b")]
[assembly: AssemblyProduct("ACoffinForWilliam")]
[assembly: AssemblyTitle("ACoffinForWilliam")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
		}
	}
}
namespace ACoffinForWilliam
{
	[BepInPlugin("triggeredidiot.ACoffinForWilliam", "A Coffin For William", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static OnClick <>9__11_0;

			public static ColorValueChangeEventDelegate <>9__11_1;

			public static FloatValueChangeEventDelegate <>9__11_2;

			public static IntValueChangeEventDelegate <>9__11_3;

			internal void <Awake>b__11_0()
			{
				Application.OpenURL("file://" + SoundsDirectory.Replace("\\", "/"));
			}

			internal void <Awake>b__11_1(ColorValueChangeEvent @event)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				FireColor = @event.value;
			}

			internal void <Awake>b__11_2(FloatValueChangeEvent @event)
			{
				Chance = @event.value;
			}

			internal void <Awake>b__11_3(IntValueChangeEvent @event)
			{
				WilliamAmount = @event.value;
			}
		}

		public const string Guid = "triggeredidiot.ACoffinForWilliam";

		public static Color FireColor = Color.magenta;

		public static float Chance = 5f;

		public static int WilliamAmount = 4;

		public static List<AudioClip> WilliamSounds = new List<AudioClip>();

		private PluginConfigurator? _config;

		public static string SoundsDirectory => Path.Combine(Path.GetDirectoryName(Uri.UnescapeDataString(new UriBuilder(Assembly.GetExecutingAssembly().CodeBase).Path)) ?? Environment.CurrentDirectory, "sounds");

		public static string IconPath => Path.Combine(Path.GetDirectoryName(Uri.UnescapeDataString(new UriBuilder(Assembly.GetExecutingAssembly().CodeBase).Path)) ?? Environment.CurrentDirectory, "icon.png");

		public void LoadSounds()
		{
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			if (!Directory.Exists(SoundsDirectory))
			{
				Debug.LogError((object)"Sounds directory doesn't exist!");
				Debug.LogWarning((object)"Making missing sounds directory...");
				Directory.CreateDirectory(SoundsDirectory);
			}
			Debug.Log((object)("Loading sounds in " + SoundsDirectory));
			WilliamSounds = new List<AudioClip>();
			string[] files = Directory.GetFiles(SoundsDirectory);
			foreach (string text in files)
			{
				string text2 = Path.GetExtension(text).ToLower();
				if (!(text2 != ".ogg") || !(text2 != ".mp3") || !(text2 != ".wav"))
				{
					AudioType val = (AudioType)0;
					switch (text2)
					{
					case ".ogg":
						val = (AudioType)14;
						break;
					case ".mp3":
						val = (AudioType)13;
						break;
					case ".wav":
						val = (AudioType)20;
						break;
					}
					UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(text, val);
					((AsyncOperation)www.SendWebRequest()).completed += delegate
					{
						AudioClip content = DownloadHandlerAudioClip.GetContent(www);
						WilliamSounds.Add(content);
					};
				}
			}
		}

		private void Awake()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Expected O, but got Unknown
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			//IL_0115: 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)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Expected O, but got Unknown
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Expected O, but got Unknown
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Expected O, but got Unknown
			LoadSounds();
			_config = PluginConfigurator.Create("A Coffin For William", "triggeredidiot.ACoffinForWilliam");
			_config.SetIconWithURL("file://" + IconPath.Replace("\\", "/"));
			ButtonField val = new ButtonField(_config.rootPanel, "Open sounds folder", "triggeredidiot.ACoffinForWilliam.openfolder");
			object obj = <>c.<>9__11_0;
			if (obj == null)
			{
				OnClick val2 = delegate
				{
					Application.OpenURL("file://" + SoundsDirectory.Replace("\\", "/"));
				};
				<>c.<>9__11_0 = val2;
				obj = (object)val2;
			}
			val.onClick += (OnClick)obj;
			new ButtonField(_config.rootPanel, "Reload sounds", "triggeredidiot.ACoffinForWilliam.reloadsounds").onClick += new OnClick(LoadSounds);
			ColorField val3 = new ColorField(_config.rootPanel, "Fire color", "triggeredidiot.ACoffinForWilliam.color", Color.magenta);
			FireColor = val3.value;
			object obj2 = <>c.<>9__11_1;
			if (obj2 == null)
			{
				ColorValueChangeEventDelegate val4 = delegate(ColorValueChangeEvent @event)
				{
					//IL_0001: Unknown result type (might be due to invalid IL or missing references)
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					FireColor = @event.value;
				};
				<>c.<>9__11_1 = val4;
				obj2 = (object)val4;
			}
			val3.onValueChange += (ColorValueChangeEventDelegate)obj2;
			FloatField val5 = new FloatField(_config.rootPanel, "Chance (x/100)", "triggeredidiot.ACoffinForWilliam.randchance", 5f);
			Chance = val5.value;
			object obj3 = <>c.<>9__11_2;
			if (obj3 == null)
			{
				FloatValueChangeEventDelegate val6 = delegate(FloatValueChangeEvent @event)
				{
					Chance = @event.value;
				};
				<>c.<>9__11_2 = val6;
				obj3 = (object)val6;
			}
			val5.onValueChange += (FloatValueChangeEventDelegate)obj3;
			IntField val7 = new IntField(_config.rootPanel, "Amount of williams", "triggeredidiot.ACoffinForWilliam.williamcount", 4);
			WilliamAmount = val7.value;
			object obj4 = <>c.<>9__11_3;
			if (obj4 == null)
			{
				IntValueChangeEventDelegate val8 = delegate(IntValueChangeEvent @event)
				{
					WilliamAmount = @event.value;
				};
				<>c.<>9__11_3 = val8;
				obj4 = (object)val8;
			}
			val7.onValueChange += (IntValueChangeEventDelegate)obj4;
			SceneManager.sceneLoaded += delegate(Scene s, LoadSceneMode lcm)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				((MonoBehaviour)this).StartCoroutine(_loadCoffin(s));
			};
		}

		private IEnumerator _loadCoffin(Scene newScene)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			yield return (object)new WaitForFixedUpdate();
			AnimatedTexture[] animatedTextures = Resources.FindObjectsOfTypeAll<AnimatedTexture>();
			Debug.Log((object)("Adding williams... (" + animatedTextures.Length + "/" + WilliamAmount + ")"));
			int localAmnt = WilliamAmount;
			int tries = 32;
			while (localAmnt > 0 && tries > 0)
			{
				tries--;
				for (int i = 0; i < animatedTextures.Length; i++)
				{
					if (localAmnt <= 0)
					{
						break;
					}
					AnimatedTexture val = animatedTextures[i];
					if (((Object)((Component)val).gameObject).name.ToLower().Contains("furnacecoffin") && ((Component)val).gameObject.scene == newScene && !(Random.Range(0f, 100f) > Chance))
					{
						localAmnt--;
						((Component)val).gameObject.AddComponent<WilliamCoffin>().meshRenderer = ((Component)val).gameObject.GetComponent<MeshRenderer>();
					}
				}
				yield return (object)new WaitForFixedUpdate();
			}
		}
	}
	public class WilliamCoffin : MonoBehaviour
	{
		private static readonly int EmissionColor = Shader.PropertyToID("_EmissiveColor");

		public MeshRenderer? meshRenderer;

		public AudioSource? target;

		private void Start()
		{
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			if (!((Behaviour)this).enabled)
			{
				return;
			}
			if ((Object)(object)meshRenderer == (Object)null)
			{
				meshRenderer = ((Component)this).GetComponent<MeshRenderer>();
			}
			Material material = ((Renderer)meshRenderer).material;
			try
			{
				material.SetVector(EmissionColor, new Vector4(Plugin.FireColor.r, Plugin.FireColor.g, Plugin.FireColor.b, 1f));
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("William fire color patch failed.\n" + ex.Message));
			}
			Transform parent = ((Component)meshRenderer).transform.parent;
			Transform val = parent.Find("Light");
			Transform val2 = parent.Find("LightShaft (Upper)");
			Transform val3 = parent.Find("LightShaft (Lower)");
			try
			{
				((Renderer)((Component)val2).gameObject.GetComponent<MeshRenderer>()).material.color = new Color(Plugin.FireColor.r, Plugin.FireColor.g, Plugin.FireColor.b, 0.502f);
				((Renderer)((Component)val3).gameObject.GetComponent<MeshRenderer>()).material.color = new Color(Plugin.FireColor.r, Plugin.FireColor.g, Plugin.FireColor.b, 0.502f);
			}
			catch (Exception ex2)
			{
				Debug.LogWarning((object)("William light shaft patch failed.\n" + ex2.Message));
			}
			try
			{
				((Component)val).gameObject.GetComponent<Light>().color = Plugin.FireColor;
			}
			catch (Exception ex3)
			{
				Debug.LogWarning((object)("William light patch failed.\n" + ex3.Message));
			}
			try
			{
				RandomAudioclip componentInChildren = ((Component)parent).gameObject.GetComponentInChildren<RandomAudioclip>();
				((Component)componentInChildren).gameObject.SetActive(false);
				target = new GameObject("fixed screaming").AddComponent<AudioSource>();
				((Component)target).gameObject.transform.SetParent(((Component)parent).transform);
				((Component)target).gameObject.transform.localPosition = Vector3.zero;
				((Component)target).gameObject.transform.position = (val2 ?? ((Component)meshRenderer).transform).position;
				target.spatialBlend = 1f;
				target.spatialize = true;
				target.rolloffMode = (AudioRolloffMode)1;
				target.minDistance = 10f;
				target.maxDistance = 20f;
				((Component)target).gameObject.AddComponent<AudioLowPassFilter>().cutoffFrequency = 4000f;
				target.outputAudioMixerGroup = ((Component)componentInChildren).GetComponentInChildren<AudioSource>().outputAudioMixerGroup;
			}
			catch (Exception ex4)
			{
				Debug.LogWarning((object)("William voice patch failed.\n" + ex4.Message));
			}
		}

		private void Update()
		{
			if (!((Object)(object)target == (Object)null) && !target.isPlaying && Plugin.WilliamSounds.Count > 0)
			{
				target.clip = Plugin.WilliamSounds[Random.Range(0, Plugin.WilliamSounds.Count)];
				target.Play();
			}
		}
	}
}