Decompiled source of VoiceHUD v1.0.4

BepInEx/plugins/VoiceHUD.dll

Decompiled a year 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 BepInEx.Configuration;
using BepInEx.Logging;
using Dissonance;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;
using VoiceHUD.Configuration;

[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("VoiceHUD")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Displays push-to-talk icon on voice activation")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+f1e0a0cfa0a629002418c9e0aa3a753676e33192")]
[assembly: AssemblyProduct("VoiceHUD")]
[assembly: AssemblyTitle("VoiceHUD")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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 VoiceHUD
{
	[BepInPlugin("5Bit.VoiceHUD", "VoiceHUD", "1.0.4")]
	public class VoiceHUD : BaseUnityPlugin
	{
		private const string modGUID = "5Bit.VoiceHUD";

		private const string modName = "VoiceHUD";

		private const string modVersion = "1.0.4";

		private readonly Harmony harmony = new Harmony("5Bit.VoiceHUD");

		private static VoiceHUD Instance;

		internal static ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("5Bit.VoiceHUD");
			Config.Init();
			harmony.PatchAll();
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "VoiceHUD";

		public const string PLUGIN_NAME = "VoiceHUD";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}
namespace VoiceHUD.Patches
{
	[HarmonyPatch(typeof(HUDManager))]
	internal class VoiceHUDPatch
	{
		private static Color Start = new Color(0f, 255f, 0f, 255f);

		private static Color Center = new Color(165f, 255f, 0f, 255f);

		private static Color End = new Color(255f, 0f, 0f, 255f);

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void Update()
		{
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			if (!IngamePlayerSettings.Instance.settings.micEnabled || IngamePlayerSettings.Instance.settings.pushToTalk || (Object)(object)StartOfRound.Instance.voiceChatModule == (Object)null)
			{
				return;
			}
			VoicePlayerState val = StartOfRound.Instance.voiceChatModule.FindPlayer(StartOfRound.Instance.voiceChatModule.LocalPlayerName);
			if (val.IsSpeaking)
			{
				float num = Mathf.Clamp(val.Amplitude * 35f, 0f, 1f);
				if (Config.ColorsEnabled)
				{
					((Graphic)HUDManager.Instance.PTTIcon).color = GetColorByVolume(num * 100f);
				}
				((Behaviour)HUDManager.Instance.PTTIcon).enabled = num > 0.01f;
			}
		}

		public static Color GetColorByVolume(float volume)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			if (volume < 20f)
			{
				return Start;
			}
			if (volume > 70f)
			{
				return End;
			}
			return Center;
		}
	}
}
namespace VoiceHUD.Configuration
{
	internal static class Config
	{
		private const string CONFIG_FILE_NAME = "VoiceHUD.cfg";

		private static ConfigFile config;

		private static ConfigEntry<bool> colorsEnabled;

		public static bool ColorsEnabled => colorsEnabled.Value;

		public static void Init()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			string text = Path.Combine(Paths.ConfigPath, "VoiceHUD.cfg");
			config = new ConfigFile(text, true);
			colorsEnabled = config.Bind<bool>("Config", "Colors enabled", false, "Change icon color based on volume.");
		}
	}
}