Decompiled source of BlowsUpFilthWithMind v1.0.2

doomahreal.ultrakill.BlowsUpFilthWithMind/BlowsUpFilthWithMind.dll

Decompiled 3 months ago
using System;
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 Configgy;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("BlowsUpFilthWithMind")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("My first Mod")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BlowsUpFilthWithMind")]
[assembly: AssemblyTitle("BlowsUpFilthWithMind")]
[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;
		}
	}
}
public static class embload
{
	public static Sprite loadsprite(string fileName)
	{
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Expected O, but got Unknown
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		Assembly executingAssembly = Assembly.GetExecutingAssembly();
		string[] manifestResourceNames = executingAssembly.GetManifestResourceNames();
		Debug.Log((object)"Embedded resource names:");
		string[] array = manifestResourceNames;
		for (int i = 0; i < array.Length; i++)
		{
			Debug.Log((object)array[i]);
		}
		string text = manifestResourceNames.FirstOrDefault((string r) => r.EndsWith(fileName));
		if (string.IsNullOrEmpty(text))
		{
			Debug.LogError((object)("Embedded resource " + fileName + " not found in the assembly."));
			return null;
		}
		using Stream stream = executingAssembly.GetManifestResourceStream(text);
		if (stream == null)
		{
			Debug.LogError((object)("Failed to load embedded resource stream for " + fileName + "."));
			return null;
		}
		byte[] array2 = new byte[stream.Length];
		stream.Read(array2, 0, array2.Length);
		Texture2D val = new Texture2D(2, 2);
		ImageConversion.LoadImage(val, array2);
		((Texture)val).filterMode = (FilterMode)0;
		val.Apply();
		return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
	}
}
namespace BlowsUpFilthWithMind
{
	public static class MAHORAGAHELP
	{
		public class DetectionTrigger : MonoBehaviour
		{
			private void OnTriggerStay(Collider other)
			{
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0053: Unknown result type (might be due to invalid IL or missing references)
				if (Plugin.loudenough && ((ConfigValueElement<bool>)(object)Plugin.funmode).Value)
				{
					EnemyIdentifier componentInParent = ((Component)other).gameObject.GetComponentInParent<EnemyIdentifier>();
					if ((Object)(object)componentInParent != (Object)null && !componentInParent.dead && (Object)(object)((Component)componentInParent).gameObject.GetComponent<Exploded>() == (Object)null)
					{
						Object.Instantiate<GameObject>(Plugin.funThing, ((Component)componentInParent).transform.position, Quaternion.identity);
						((Component)componentInParent).gameObject.AddComponent<Exploded>();
					}
				}
			}
		}

		public class Exploded : MonoBehaviour
		{
			private void Awake()
			{
				Object.Destroy((Object)(object)this, 0.125f);
			}
		}

		public static GameObject CreateCanvas()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			GameObject val = new GameObject("LoudnessCanvas");
			val.AddComponent<Canvas>().renderMode = (RenderMode)0;
			val.AddComponent<CanvasScaler>().uiScaleMode = (ScaleMode)1;
			val.AddComponent<GraphicRaycaster>();
			return val;
		}

		public static GameObject CreateIcon(string fileName, GameObject parent)
		{
			//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)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			GameObject val = new GameObject(fileName);
			val.transform.SetParent(parent.transform);
			Image obj = val.AddComponent<Image>();
			Sprite sprite = embload.loadsprite(fileName);
			obj.sprite = sprite;
			val.GetComponent<RectTransform>().sizeDelta = new Vector2(25f, 25f);
			return val;
		}

		public static void CreateDetectionSphere(GameObject player, bool isFunMode, out GameObject detectionSphereObject)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			detectionSphereObject = new GameObject("DetectionSphere");
			detectionSphereObject.transform.SetParent(player.transform);
			detectionSphereObject.transform.localPosition = Vector3.zero;
			SphereCollider obj = detectionSphereObject.AddComponent<SphereCollider>();
			((Collider)obj).isTrigger = true;
			obj.radius = 2048f;
			detectionSphereObject.AddComponent<DetectionTrigger>();
			detectionSphereObject.SetActive(isFunMode);
		}
	}
	[BepInPlugin("doomahreal.ultrakill.BlowsUpFilthWithMind", "BlowsUpFilthWithMind", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static Plugin Instance;

		private const string modGUID = "doomahreal.ultrakill.BlowsUpFilthWithMind";

		private const string modName = "BlowsUpFilthWithMind";

		private const string modVersion = "1.0.0";

		private static readonly Harmony Harmony = new Harmony("doomahreal.ultrakill.BlowsUpFilthWithMind");

		private const int sampleWindow = 128;

		private ConfigBuilder config;

		private string[] availableMics;

		private AudioClip microphoneClip;

		private static GameObject loudindicator;

		private static GameObject quietindicator;

		public static bool loudenough;

		public static GameObject funThing;

		private GameObject detectionSphereObject;

		[Configgable("", "Available Microphones", 0, null)]
		public static ConfigDropdown<string> currentMic;

		[Configgable("", "Decibel Activation (lower is quieter)", 0, null)]
		public static ConfigInputField<int> decibelThreshold = new ConfigInputField<int>(-10, (Func<int, bool>)null, (Func<string, ValueTuple<bool, int>>)null);

		[Configgable("", "Enable Mod", 0, null)]
		public static ConfigToggle enabled = new ConfigToggle(true);

		[Configgable("", "\"Fun\" mode", 0, null)]
		public static ConfigToggle funmode = new ConfigToggle(false);

		private void Awake()
		{
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			availableMics = Microphone.devices;
			if (availableMics.Length == 0)
			{
				Debug.LogWarning((object)"No microphones detected.");
				return;
			}
			currentMic = new ConfigDropdown<string>(availableMics, (string[])null, 0);
			ConfigDropdown<string> obj = currentMic;
			((ConfigValueElement<string>)(object)obj).OnValueChanged = (Action<string>)Delegate.Combine(((ConfigValueElement<string>)(object)obj).OnValueChanged, new Action<string>(OnMicrophoneChanged));
			ConfigToggle obj2 = enabled;
			((ConfigValueElement<bool>)(object)obj2).OnValueChanged = (Action<bool>)Delegate.Combine(((ConfigValueElement<bool>)(object)obj2).OnValueChanged, new Action<bool>(OnEnableOrDisable));
			ConfigToggle obj3 = funmode;
			((ConfigValueElement<bool>)(object)obj3).OnValueChanged = (Action<bool>)Delegate.Combine(((ConfigValueElement<bool>)(object)obj3).OnValueChanged, new Action<bool>(OnFunModeChanged));
			AsyncOperationHandle<GameObject> val = Addressables.LoadAssetAsync<GameObject>((object)"Assets/Prefabs/Attacks and Projectiles/Explosions/Explosion Super.prefab");
			val.Completed += delegate(AsyncOperationHandle<GameObject> handle)
			{
				funThing = handle.Result;
			};
			Harmony.PatchAll();
		}

		private void Start()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			config = new ConfigBuilder("doomahreal.ultrakill.BlowsUpFilthWithMind", "BlowsUpFilthWithMind");
			config.BuildAll();
			OnMicrophoneChanged(((ConfigValueElement<string>)(object)currentMic).Value);
		}

		private void Update()
		{
			if ((Object)(object)microphoneClip == (Object)null || !((ConfigValueElement<bool>)(object)enabled).Value)
			{
				return;
			}
			float averageVolume = GetAverageVolume();
			bool flag = 20f * Mathf.Log10(Mathf.Max(averageVolume, 0.0001f)) > (float)((ConfigValueElement<int>)(object)decibelThreshold).Value;
			if (flag == loudenough)
			{
				return;
			}
			loudenough = flag;
			if (!((Object)(object)loudindicator == (Object)null) && !((Object)(object)quietindicator == (Object)null))
			{
				loudindicator.SetActive(loudenough);
				quietindicator.SetActive(!loudenough);
			}
			if (!((ConfigValueElement<bool>)(object)funmode).Value)
			{
				if (loudenough)
				{
					MonoSingleton<InputManager>.Instance.InputSource.Fire1.IsPressed = true;
				}
				else
				{
					MonoSingleton<InputManager>.Instance.InputSource.Fire1.IsPressed = false;
				}
			}
		}

		private void OnEnableOrDisable(bool yayornay)
		{
			if (!yayornay)
			{
				if ((Object)(object)loudindicator != (Object)null)
				{
					loudindicator.SetActive(false);
				}
				if ((Object)(object)quietindicator != (Object)null)
				{
					quietindicator.SetActive(false);
				}
				if ((Object)(object)detectionSphereObject != (Object)null)
				{
					detectionSphereObject.SetActive(false);
				}
				Microphone.End((string)null);
				microphoneClip = null;
			}
			else
			{
				if ((Object)(object)loudindicator != (Object)null)
				{
					loudindicator.SetActive(true);
				}
				if ((Object)(object)quietindicator != (Object)null)
				{
					quietindicator.SetActive(true);
				}
				if ((Object)(object)detectionSphereObject != (Object)null)
				{
					detectionSphereObject.SetActive(((ConfigValueElement<bool>)(object)funmode).Value);
				}
			}
		}

		private void OnMicrophoneChanged(string newMicName)
		{
			if (!((ConfigValueElement<bool>)(object)enabled).Value)
			{
				return;
			}
			if (string.IsNullOrEmpty(newMicName) || Array.IndexOf(availableMics, newMicName) == -1)
			{
				Debug.LogWarning((object)"Selected microphone is invalid.");
				return;
			}
			Debug.Log((object)("Microphone changed to: " + newMicName));
			if ((Object)(object)microphoneClip != (Object)null)
			{
				Microphone.End((string)null);
				microphoneClip = null;
			}
			microphoneClip = Microphone.Start(newMicName, true, 1, 44100);
		}

		private float GetAverageVolume()
		{
			if ((Object)(object)microphoneClip == (Object)null)
			{
				return 0f;
			}
			float[] array = new float[128];
			int num = Microphone.GetPosition((string)null) - 129;
			if (num < 0)
			{
				return 0f;
			}
			microphoneClip.GetData(array, num);
			float num2 = 0f;
			for (int i = 0; i < 128; i++)
			{
				num2 += Mathf.Abs(array[i]);
			}
			return num2 / 128f;
		}

		public static void CreateIcons()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			GameObject parent = MAHORAGAHELP.CreateCanvas();
			quietindicator = MAHORAGAHELP.CreateIcon("quiet.png", parent);
			RectTransform component = quietindicator.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(1f, 0f);
			component.anchorMax = new Vector2(1f, 0f);
			component.anchoredPosition = new Vector2(-100f, 50f);
			loudindicator = MAHORAGAHELP.CreateIcon("loud.png", parent);
			RectTransform component2 = loudindicator.GetComponent<RectTransform>();
			component2.anchorMin = new Vector2(1f, 0f);
			component2.anchorMax = new Vector2(1f, 0f);
			component2.anchoredPosition = new Vector2(-100f, 50f);
			loudindicator.SetActive(false);
		}

		private void OnFunModeChanged(bool isEnabled)
		{
			if ((Object)(object)detectionSphereObject != (Object)null)
			{
				detectionSphereObject.SetActive(isEnabled);
			}
		}

		public void CreateDetectionSphere(GameObject player, bool isfunmode)
		{
			MAHORAGAHELP.CreateDetectionSphere(player, isfunmode, out detectionSphereObject);
		}
	}
	[HarmonyPatch(typeof(NewMovement))]
	[HarmonyPatch("Awake")]
	internal class PatchNewMovementAwake
	{
		private static void Postfix(NewMovement __instance)
		{
			if (!(SceneHelper.CurrentScene == "Main Menu") && !(SceneHelper.CurrentScene == "Intro") && !(SceneHelper.CurrentScene == "Bootstrap"))
			{
				Plugin.CreateIcons();
				Plugin.Instance.CreateDetectionSphere(((Component)__instance).gameObject, ((ConfigValueElement<bool>)(object)Plugin.funmode).Value);
			}
		}
	}
	[HarmonyPatch(typeof(InputActionState))]
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal class PatchInputActionStateIsPressed
	{
		private static bool Prefix(InputActionState __instance, ref bool __result)
		{
			if (SceneHelper.CurrentScene == "Main Menu" || SceneHelper.CurrentScene == "Intro" || SceneHelper.CurrentScene == "Bootstrap")
			{
				return true;
			}
			if (!((ConfigValueElement<bool>)(object)Plugin.enabled).Value || ((ConfigValueElement<bool>)(object)Plugin.funmode).Value)
			{
				return true;
			}
			if (__instance.Action == MonoSingleton<InputManager>.Instance.InputSource.Fire1.Action)
			{
				__result = Plugin.loudenough;
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(InputActionState))]
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal class PatchInputActionStateWasPerformedThisFrame
	{
		private static bool Prefix(InputActionState __instance, ref bool __result)
		{
			if (SceneHelper.CurrentScene == "Main Menu" || SceneHelper.CurrentScene == "Intro" || SceneHelper.CurrentScene == "Bootstrap")
			{
				return true;
			}
			if (!((ConfigValueElement<bool>)(object)Plugin.enabled).Value || ((ConfigValueElement<bool>)(object)Plugin.funmode).Value)
			{
				return true;
			}
			if (__instance.Action == MonoSingleton<InputManager>.Instance.InputSource.Fire1.Action)
			{
				__result = Plugin.loudenough;
				return false;
			}
			return true;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}