Decompiled source of LethalLoudnessMeter v1.0.2

LethalLoudnessMeter.dll

Decompiled 10 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLoudnessMeter.Patches;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("LoudnessMeter")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LoudnessMeter")]
[assembly: AssemblyCopyright("Copyright © extraes 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("368a271e-98d6-48f8-981e-60df5875ea73")]
[assembly: AssemblyFileVersion("1.0.2")]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyVersion("1.0.2.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 LethalLoudnessMeter
{
	internal static class BuildInfo
	{
		public const string GUID = "xyz.extraes.lethalLoudness";

		public const string NAME = "LoudnessMeter";

		public const string SHORT_NAME = "LoudMeter";

		public const string VERSION = "1.0.2";

		public const string AUTHOR = "extraes";
	}
	internal static class LMUtils
	{
		public static MethodInfo AsInfo<T>(T dele) where T : Delegate
		{
			return dele.Method;
		}

		public static HarmonyMethod ToHarmony<T>(T dele) where T : Delegate
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			return new HarmonyMethod(AsInfo(dele));
		}
	}
	[BepInPlugin("xyz.extraes.lethalLoudness", "LoudMeter", "1.0.2")]
	public sealed class LoudnessMeterPlugin : BaseUnityPlugin
	{
		private Image volumeImg;

		private Collider playersCollider;

		private float accumulatedVolume;

		public static LoudnessMeterPlugin Instance { get; private set; }

		public static ManualLogSource Log
		{
			get
			{
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				LoudnessMeterPlugin instance = Instance;
				return (ManualLogSource)(((object)((instance != null) ? ((BaseUnityPlugin)instance).Logger : null)) ?? ((object)new ManualLogSource("LoudMeter")));
			}
		}

		public bool NeedsSnatchedImage => (Object)(object)volumeImg == (Object)null;

		internal static Harmony Harmony { get; private set; }

		static LoudnessMeterPlugin()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			Log.LogMessage((object)"Initializing Lethal Loudness Meter...");
			Stopwatch stopwatch = Stopwatch.StartNew();
			Harmony = new Harmony("xyz.extraes.lethalLoudness");
			Harmony.PatchAll();
			FootstepPatches.Init();
			ItemPatches.Init();
			Log.LogInfo((object)("Initialized LethalLoudness in " + stopwatch.ElapsedMilliseconds + "ms"));
		}

		private void Awake()
		{
			Instance = this;
			Object.DontDestroyOnLoad((Object)(object)this);
			PlayAudibleNoisePatch.noisePlayed = (Action<Vector3, float, float>)Delegate.Combine(PlayAudibleNoisePatch.noisePlayed, new Action<Vector3, float, float>(NoisePlayed));
		}

		private void NoisePlayed(Vector3 pos, float range, float vol)
		{
			//IL_0057: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)GameNetworkManager.Instance == (Object)null || (Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null)
			{
				return;
			}
			if ((Object)(object)playersCollider == (Object)null)
			{
				playersCollider = ((Component)GameNetworkManager.Instance.localPlayerController).GetComponent<Collider>();
			}
			if (playersCollider.enabled)
			{
				Vector3 val = playersCollider.ClosestPoint(pos);
				if (!(Vector3.Distance(pos, val) > 0.8f))
				{
					accumulatedVolume += vol;
				}
			}
		}

		private void Update()
		{
			if ((Object)(object)GameNetworkManager.Instance == (Object)null || (Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null)
			{
				return;
			}
			if ((Object)(object)volumeImg == (Object)null && accumulatedVolume != 0f)
			{
				Log.LogError((object)"Volume image wasn't found! Wha?");
				return;
			}
			if (volumeImg.fillAmount < accumulatedVolume)
			{
				volumeImg.fillAmount = Mathf.Clamp(accumulatedVolume, 0.05f, 1f);
			}
			else
			{
				float fillAmount = volumeImg.fillAmount;
				float num = Mathf.Clamp(accumulatedVolume, 0.01f, 1f);
				float num2 = Mathf.Clamp(Time.deltaTime * 3f, 0f, 1f);
				volumeImg.fillAmount = Mathf.Lerp(fillAmount, num, num2);
			}
			accumulatedVolume = 0f;
		}

		private void OnDestroy()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			Log.LogError((object)"Creating new GameObject to host LoudnessMeter...");
			new GameObject("LMP").AddComponent<LoudnessMeterPlugin>();
		}

		public void SetVolumeImage(Image img)
		{
			if ((Object)(object)volumeImg != (Object)null)
			{
				Log.LogWarning((object)"Volume img isn't null but you're replacing it? Whar?");
			}
			volumeImg = img;
		}
	}
}
namespace LethalLoudnessMeter.Patches
{
	internal static class FootstepPatches
	{
		public static void Init()
		{
			MethodInfo methodInfo = AccessTools.DeclaredMethod(typeof(PlayerControllerB), "PlayFootstepServer", (Type[])null, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.DeclaredMethod(typeof(PlayerControllerB), "PlayFootstepLocal", (Type[])null, (Type[])null);
			HarmonyMethod val = LMUtils.ToHarmony<Action<PlayerControllerB>>(FootstepServer);
			HarmonyMethod val2 = LMUtils.ToHarmony<Action<PlayerControllerB>>(FootstepLocal);
			LoudnessMeterPlugin.Harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			LoudnessMeterPlugin.Harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		private static void FootstepServer(PlayerControllerB __instance)
		{
		}

		private static void FootstepLocal(PlayerControllerB __instance)
		{
		}
	}
	internal static class ItemPatches
	{
		public static void Init()
		{
		}
	}
	[HarmonyPatch(typeof(DisplayPlayerMicVolume), "Awake")]
	internal static class MicVolumeSnatcher
	{
		public static void Postfix(DisplayPlayerMicVolume __instance)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = Object.Instantiate<GameObject>(((Component)__instance.volumeMeterImage).gameObject);
			Image component = obj.GetComponent<Image>();
			RectTransform val = (RectTransform)obj.transform;
			CanvasRenderer canvasRenderer = ((Graphic)component).canvasRenderer;
			GameObject val2 = GameObject.Find("Systems/UI/Canvas/IngamePlayerHUD/BottomLeftCorner");
			((Transform)val).SetParent(val2.transform, true);
			val.anchoredPosition3D = new Vector3(-10f, 40f, 0f);
			((Transform)val).localScale = new Vector3(15f, 15f, 15f);
			canvasRenderer.SetAlpha(4f);
			component.fillAmount = 1f;
			LoudnessMeterPlugin.Log.LogMessage((object)"Snatched mic volume!");
			LoudnessMeterPlugin.Instance.SetVolumeImage(component);
		}
	}
	[HarmonyPatch(typeof(RoundManager), "PlayAudibleNoise")]
	internal static class PlayAudibleNoisePatch
	{
		public static Action<Vector3, float, float> noisePlayed;

		public static void Postfix(Vector3 noisePosition, float noiseRange, float noiseLoudness)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			noisePlayed?.Invoke(noisePosition, noiseRange, noiseLoudness);
		}
	}
	[HarmonyPatch(typeof(HUDManager), "Awake")]
	internal static class SettingsPanelActivator
	{
		public static void Postfix()
		{
			Transform obj = GameObject.Find("Systems/UI/Canvas").transform.Find("QuickMenu");
			Transform val = obj.Find("SettingsPanel");
			((Component)obj).gameObject.SetActive(true);
			((Component)val).gameObject.SetActive(true);
			((Component)val).gameObject.SetActive(false);
			((Component)obj).gameObject.SetActive(false);
			LoudnessMeterPlugin.Log.LogMessage((object)"Toggled QuickMenu -> SettingsPanel successfully");
		}
	}
}