Decompiled source of SpectateVoiceVolume v1.0.1

BepInEx/plugins/SpectateVoiceVolume.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
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 HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("RED")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("SpectateVoiceVolume")]
[assembly: AssemblyTitle("SpectateVoiceVolume")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 SpectateVoiceVolume
{
	[BepInPlugin("redos.spectatevoicevolume", "SpectateVoiceVolume", "1.0.1")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public static ConfigEntry<bool> Enabled;

		public static ConfigEntry<float> Balance;

		public static ConfigEntry<bool> ShowSliderAlways;

		public static float LiveBalance;

		private Harmony _harmony;

		public static Plugin Instance { get; private set; }

		public ManualLogSource Log => ((BaseUnityPlugin)this).Logger;

		private void Awake()
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Expected O, but got Unknown
			Instance = this;
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Turn the mod off (voice stays vanilla).");
			Balance = ((BaseUnityPlugin)this).Config.Bind<float>("Spectator Voice", "Balance", 0.5f, new ConfigDescription("Voice balance while you're spectating. 0 = only dead chat, 1 = only alive players, 0.5 = both normal. Set it with the in-game slider.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			ShowSliderAlways = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "ShowSliderAlways", false, "Show the slider in the pause menu even while alive (for setting it up). Off = only while spectating.");
			LiveBalance = Balance.Value;
			_harmony = new Harmony("redos.spectatevoicevolume");
			_harmony.PatchAll(typeof(Plugin).Assembly);
			((BaseUnityPlugin)this).Logger.LogMessage((object)"SpectateVoiceVolume 1.0.1 loaded");
		}
	}
	internal static class SpectateState
	{
		internal static bool IsLocalSpectating()
		{
			PlayerController instance = PlayerController.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return false;
			}
			PlayerAvatar playerAvatarScript = instance.playerAvatarScript;
			if (!((Object)(object)playerAvatarScript == (Object)null))
			{
				return playerAvatarScript.isDisabled;
			}
			return true;
		}
	}
	public static class SpectatorBalance
	{
		public static (float spectator, float alive) Factors(float balance)
		{
			balance = Clamp01(balance);
			float item = Clamp01(2f * (1f - balance));
			float item2 = Clamp01(2f * balance);
			return (spectator: item, alive: item2);
		}

		private static float Clamp01(float v)
		{
			if (!(v < 0f))
			{
				if (!(v > 1f))
				{
					return v;
				}
				return 1f;
			}
			return 0f;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "redos.spectatevoicevolume";

		public const string PLUGIN_NAME = "SpectateVoiceVolume";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}
namespace SpectateVoiceVolume.UI
{
	internal sealed class BalanceSliderBinding : MonoBehaviour
	{
		private const float ValueEpsilon = 0.0005f;

		private const float NoValue = -2f;

		internal MenuPageEsc page;

		internal MenuSlider slider;

		internal TextMeshProUGUI deadWord;

		internal TextMeshProUGUI aliveWord;

		internal RectTransform handle;

		internal RectTransform barSize;

		internal RawImage handleFill;

		private CanvasGroup _cg;

		private bool _inited;

		private bool _fault;

		private float _last = -2f;

		private float _lastWidth = -2f;

		private void Awake()
		{
			_cg = ((Component)this).GetComponent<CanvasGroup>();
			if ((Object)(object)_cg == (Object)null)
			{
				_cg = ((Component)this).gameObject.AddComponent<CanvasGroup>();
			}
			_cg.alpha = 0f;
			_cg.interactable = false;
			_cg.blocksRaycasts = false;
		}

		private void LateUpdate()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)slider == (Object)null)
			{
				return;
			}
			try
			{
				if (!_inited)
				{
					slider.SetBar(Plugin.Balance.Value);
					slider.SetBarScaleInstant();
					_inited = true;
				}
				Vector3 val = SliderUi.RowSlot(page);
				if (((Component)this).transform.localPosition != val)
				{
					((Component)this).transform.localPosition = val;
				}
				float settingsValue = slider.settingsValue;
				float num;
				if (!((Object)(object)barSize != (Object)null))
				{
					num = 0f;
				}
				else
				{
					Rect rect = barSize.rect;
					num = ((Rect)(ref rect)).width;
				}
				float num2 = num;
				if (Mathf.Abs(settingsValue - _last) > 0.0005f || num2 != _lastWidth)
				{
					_last = settingsValue;
					_lastWidth = num2;
					Plugin.LiveBalance = Mathf.Clamp01(settingsValue);
					var (num3, num4) = SpectatorBalance.Factors(settingsValue);
					if ((Object)(object)deadWord != (Object)null)
					{
						((TMP_Text)deadWord).text = $"DEAD {Mathf.RoundToInt(num3 * 100f)}%";
						((Graphic)deadWord).color = SliderUi.Alpha(SliderUi.Cool, 0.35f + 0.65f * num3);
					}
					if ((Object)(object)aliveWord != (Object)null)
					{
						((TMP_Text)aliveWord).text = $"ALIVE {Mathf.RoundToInt(num4 * 100f)}%";
						((Graphic)aliveWord).color = SliderUi.Alpha(SliderUi.Warm, 0.35f + 0.65f * num4);
					}
					if ((Object)(object)handle != (Object)null)
					{
						Vector2 anchoredPosition = handle.anchoredPosition;
						anchoredPosition.x = settingsValue * num2;
						handle.anchoredPosition = anchoredPosition;
					}
				}
				bool flag = Plugin.ShowSliderAlways.Value || SpectateState.IsLocalSpectating();
				if (flag)
				{
					HoverEffect();
				}
				if (((Behaviour)slider).enabled != flag)
				{
					((Behaviour)slider).enabled = flag;
				}
				float num5 = (flag ? 1f : 0f);
				if (_cg.alpha != num5)
				{
					_cg.alpha = num5;
					_cg.interactable = flag;
					_cg.blocksRaycasts = flag;
				}
			}
			catch (Exception arg)
			{
				if (!_fault)
				{
					_fault = true;
					Plugin instance = Plugin.Instance;
					if (instance != null)
					{
						instance.Log.LogError((object)$"[BalanceSliderBinding] {arg}");
					}
				}
			}
		}

		private void HoverEffect()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: 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)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)handle == (Object)null)
			{
				return;
			}
			bool hovering = slider.hovering;
			float num = Time.deltaTime * 12f;
			float num2 = (hovering ? 1.18f : 1f);
			float num3 = Mathf.Lerp(((Transform)handle).localScale.x, num2, num);
			if (Mathf.Abs(num3 - num2) < 0.005f)
			{
				num3 = num2;
			}
			if (((Transform)handle).localScale.x != num3)
			{
				((Transform)handle).localScale = new Vector3(num3, num3, 1f);
			}
			if ((Object)(object)handleFill != (Object)null)
			{
				Color val = (hovering ? SliderUi.HandleHoverCol : SliderUi.HandleCol);
				Color val2 = Color.Lerp(((Graphic)handleFill).color, val, num);
				if (Mathf.Abs(val2.r - val.r) + Mathf.Abs(val2.g - val.g) + Mathf.Abs(val2.b - val.b) < 0.01f)
				{
					val2 = val;
				}
				if (((Graphic)handleFill).color != val2)
				{
					((Graphic)handleFill).color = val2;
				}
			}
		}

		private void OnDisable()
		{
			if (Plugin.Balance == null || Plugin.Balance.Value == Plugin.LiveBalance)
			{
				return;
			}
			try
			{
				Plugin.Balance.Value = Mathf.Clamp01(Plugin.LiveBalance);
				Plugin instance = Plugin.Instance;
				if (instance != null)
				{
					((BaseUnityPlugin)instance).Config.Save();
				}
			}
			catch (Exception ex)
			{
				Plugin instance2 = Plugin.Instance;
				if (instance2 != null)
				{
					instance2.Log.LogWarning((object)("[BalanceSliderBinding] save failed: " + ex.Message));
				}
			}
		}
	}
	[HarmonyPatch(typeof(MenuPageEsc), "Start")]
	internal static class BalanceSliderInjector
	{
		private static void Postfix(MenuPageEsc __instance)
		{
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)__instance.playerMicrophoneVolumeSliderPrefab == (Object)null || (Object)(object)((Component)__instance).GetComponentInChildren<BalanceSliderBinding>(true) != (Object)null)
				{
					return;
				}
				GameObject val = CloneStrippedSlider(__instance);
				MenuSlider component = val.GetComponent<MenuSlider>();
				if ((Object)(object)component == (Object)null)
				{
					Object.Destroy((Object)(object)val);
					return;
				}
				RectTransform barSizeRectTransform = component.barSizeRectTransform;
				HideNativeVisuals(val.transform, barSizeRectTransform);
				TextMeshProUGUI deadWord = null;
				TextMeshProUGUI aliveWord = null;
				RectTransform val2 = null;
				RawImage handleFill = null;
				if ((Object)(object)barSizeRectTransform != (Object)null)
				{
					StretchBarToRowWidth(barSizeRectTransform, val.transform);
					BuildTrack(barSizeRectTransform);
					BuildLabels(component, barSizeRectTransform, out deadWord, out aliveWord);
					val2 = ((Graphic)SliderUi.MakeRaw("BalHandle", (Transform)(object)barSizeRectTransform, SliderUi.HandleEdgeCol, SliderUi.HandleRect())).rectTransform;
					handleFill = SliderUi.MakeRaw("BalHandleFill", (Transform)(object)val2, SliderUi.HandleCol, SliderUi.InsetFill(2f));
				}
				val.transform.localPosition = SliderUi.RowSlot(__instance);
				BalanceSliderBinding balanceSliderBinding = val.AddComponent<BalanceSliderBinding>();
				balanceSliderBinding.page = __instance;
				balanceSliderBinding.slider = component;
				balanceSliderBinding.deadWord = deadWord;
				balanceSliderBinding.aliveWord = aliveWord;
				balanceSliderBinding.handle = val2;
				balanceSliderBinding.handleFill = handleFill;
				balanceSliderBinding.barSize = barSizeRectTransform;
			}
			catch (Exception arg)
			{
				Plugin instance = Plugin.Instance;
				if (instance != null)
				{
					instance.Log.LogError((object)$"[BalanceSliderInjector] {arg}");
				}
			}
		}

		private static GameObject CloneStrippedSlider(MenuPageEsc page)
		{
			GameObject val = Object.Instantiate<GameObject>(page.playerMicrophoneVolumeSliderPrefab, ((Component)page).transform);
			((Object)val).name = "SpectatorVoiceBalanceSlider";
			MenuSliderPlayerMicGain component = val.GetComponent<MenuSliderPlayerMicGain>();
			if ((Object)(object)component != (Object)null)
			{
				((Behaviour)component).enabled = false;
				Object.Destroy((Object)(object)component);
			}
			SliderUi.DestroyChild(val.transform, "Menu Kick Button");
			SliderUi.DestroyChild(val.transform, "Steam Button");
			return val;
		}

		private static void HideNativeVisuals(Transform root, RectTransform barSize)
		{
			SliderUi.HideObject(root, "SliderBG");
			SliderUi.HideObject(root, "Bar");
			SliderUi.HideObject(root, "Bar Text");
			SliderUi.HideObject(root, "MaskedText");
			SliderUi.HideObject(root, "Menu Button - <");
			SliderUi.HideObject(root, "Menu Button - >");
			SliderUi.HideGraphic(root, "Bar Pointer");
			SliderUi.HideGraphic((Transform)(object)barSize);
		}

		private static void StretchBarToRowWidth(RectTransform barSize, Transform root)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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_0045: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			if (TryGetRowBoxSpan(root, out var left, out var right))
			{
				Rect rect = barSize.rect;
				float x = root.InverseTransformPoint(((Transform)barSize).TransformPoint(new Vector3(((Rect)(ref rect)).xMin, 0f, 0f))).x;
				rect = barSize.rect;
				float x2 = root.InverseTransformPoint(((Transform)barSize).TransformPoint(new Vector3(((Rect)(ref rect)).xMax, 0f, 0f))).x;
				float num = x - left;
				float num2 = right - x2;
				float num3 = num + num2;
				if (!(Mathf.Abs(num3) < 0.01f))
				{
					barSize.sizeDelta = new Vector2(barSize.sizeDelta.x + num3, barSize.sizeDelta.y);
					float num4 = barSize.pivot.x * num3 - num;
					((Transform)barSize).localPosition = ((Transform)barSize).localPosition + new Vector3(num4, 0f, 0f);
				}
			}
		}

		private static bool TryGetRowBoxSpan(Transform root, out float left, out float right)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			left = float.MaxValue;
			right = float.MinValue;
			Transform obj = root.Find("SliderBG");
			RectTransform val = (RectTransform)(object)((obj is RectTransform) ? obj : null);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			Graphic[] componentsInChildren = ((Component)val).GetComponentsInChildren<Graphic>(true);
			foreach (Graphic val2 in componentsInChildren)
			{
				val2.rectTransform.GetWorldCorners(array);
				float x = root.InverseTransformPoint(array[0]).x;
				float x2 = root.InverseTransformPoint(array[2]).x;
				if (x < left)
				{
					left = x;
				}
				if (x2 > right)
				{
					right = x2;
				}
			}
			if (left > right)
			{
				Rect rect = val.rect;
				left = root.InverseTransformPoint(((Transform)val).TransformPoint(new Vector3(((Rect)(ref rect)).xMin, 0f, 0f))).x;
				rect = val.rect;
				right = root.InverseTransformPoint(((Transform)val).TransformPoint(new Vector3(((Rect)(ref rect)).xMax, 0f, 0f))).x;
			}
			return true;
		}

		private static void BuildTrack(RectTransform barSize)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			SliderUi.MakeRaw("BalGrooveEdge", (Transform)(object)barSize, SliderUi.GrooveEdgeCol, SliderUi.FullWidth(16f));
			SliderUi.MakeRaw("BalGroove", (Transform)(object)barSize, SliderUi.GrooveCol, SliderUi.FullWidth(12f));
			SliderUi.MakeRaw("BalTintL", (Transform)(object)barSize, SliderUi.Alpha(SliderUi.Cool, 0.2f), SliderUi.HalfWidth(left: true, 12f));
			SliderUi.MakeRaw("BalTintR", (Transform)(object)barSize, SliderUi.Alpha(SliderUi.Warm, 0.2f), SliderUi.HalfWidth(left: false, 12f));
			SliderUi.MakeRaw("BalTick", (Transform)(object)barSize, SliderUi.TickCol, SliderUi.TickRect());
		}

		private static void BuildLabels(MenuSlider slider, RectTransform barSize, out TextMeshProUGUI deadWord, out TextMeshProUGUI aliveWord)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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_00a9: Unknown result type (might be due to invalid IL or missing references)
			deadWord = null;
			aliveWord = null;
			TextMeshProUGUI elementNameText = slider.elementNameText;
			if (!((Object)(object)elementNameText == (Object)null))
			{
				float fontSize = ((TMP_Text)elementNameText).fontSize;
				deadWord = elementNameText;
				aliveWord = SliderUi.CloneLabel(elementNameText, "AliveWord");
				TextMeshProUGUI val = SliderUi.CloneLabel(elementNameText, "Caption");
				SliderUi.PlaceAtBarEdge(deadWord, barSize, leftEdge: true, 12f, fontSize * 0.55f, SliderUi.Cool);
				SliderUi.PlaceAtBarEdge(aliveWord, barSize, leftEdge: false, -12f, fontSize * 0.55f, SliderUi.Warm);
				SliderUi.PlaceLabel(val, barSize, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, 18f), (TextAlignmentOptions)514, fontSize * 0.5f, SliderUi.CaptionCol);
				((TMP_Text)val).text = "VOICE BALANCE";
			}
		}
	}
	internal static class SliderUi
	{
		internal struct Rec
		{
			public Vector2 min;

			public Vector2 max;

			public Vector2 pivot;

			public Vector2 size;

			public Vector2 pos;
		}

		internal static readonly Color Cool = new Color(0.31f, 0.71f, 0.88f);

		internal static readonly Color Warm = new Color(0.96f, 0.65f, 0.14f);

		internal static readonly Color GrooveCol = new Color(0.1f, 0.11f, 0.15f, 0.95f);

		internal static readonly Color GrooveEdgeCol = new Color(0.02f, 0.03f, 0.05f, 0.9f);

		internal static readonly Color TickCol = new Color(0.8f, 0.84f, 0.92f, 0.45f);

		internal static readonly Color HandleCol = new Color(1f, 0.76f, 0.32f);

		internal static readonly Color HandleEdgeCol = new Color(0.48f, 0.31f, 0.04f);

		internal static readonly Color HandleHoverCol = new Color(1f, 0.88f, 0.55f);

		internal static readonly Color CaptionCol = new Color(0.58f, 0.58f, 0.66f);

		internal const float BarHeight = 12f;

		internal const float EdgeThickness = 2f;

		internal const float TintAlpha = 0.2f;

		internal const float WordInset = 12f;

		internal const float CaptionRise = 18f;

		internal const float WordFontScale = 0.55f;

		internal const float CaptionFontScale = 0.5f;

		internal const float MutedDim = 0.35f;

		internal const float HandleHoverScale = 1.18f;

		internal const float HoverLerpSpeed = 12f;

		internal const float RowX = 375f;

		internal const float MasterClientRowX = 400f;

		internal const float RowBaseY = 21f;

		internal const float RowHeight = 25f;

		internal static Vector3 RowSlot(MenuPageEsc page)
		{
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			float num = (SemiFunc.IsMasterClient() ? 400f : 375f);
			float num2 = 21f;
			Dictionary<PlayerAvatar, MenuSliderPlayerMicGain> dictionary = (((Object)(object)page != (Object)null) ? page.playerMicGainSliders : null);
			if (dictionary != null)
			{
				float num3 = float.MinValue;
				foreach (KeyValuePair<PlayerAvatar, MenuSliderPlayerMicGain> item in dictionary)
				{
					MenuSliderPlayerMicGain value = item.Value;
					if (!((Object)(object)value == (Object)null))
					{
						Vector3 val = ((Component)page).transform.InverseTransformPoint(((Component)value).transform.position);
						if (val.y > num3 + 0.5f)
						{
							num3 = val.y;
							num = val.x;
						}
						else if (val.y > num3 - 0.5f)
						{
							num = Mathf.Min(num, val.x);
						}
					}
				}
				if (num3 > float.MinValue)
				{
					num2 = num3 + 25f;
				}
			}
			return new Vector3(num, num2, 0f);
		}

		internal static Rec FullWidth(float h)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_002f: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			return new Rec
			{
				min = new Vector2(0f, 0.5f),
				max = new Vector2(1f, 0.5f),
				pivot = new Vector2(0.5f, 0.5f),
				size = new Vector2(0f, h),
				pos = Vector2.zero
			};
		}

		internal static Rec HalfWidth(bool left, float h)
		{
			//IL_001e: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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)
			return new Rec
			{
				min = new Vector2(left ? 0f : 0.5f, 0.5f),
				max = new Vector2(left ? 0.5f : 1f, 0.5f),
				pivot = new Vector2(0.5f, 0.5f),
				size = new Vector2(0f, h),
				pos = Vector2.zero
			};
		}

		internal static Rec TickRect()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_002f: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			return new Rec
			{
				min = new Vector2(0.5f, 0.5f),
				max = new Vector2(0.5f, 0.5f),
				pivot = new Vector2(0.5f, 0.5f),
				size = new Vector2(2f, 20f),
				pos = Vector2.zero
			};
		}

		internal static Rec HandleRect()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_002f: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			return new Rec
			{
				min = new Vector2(0f, 0.5f),
				max = new Vector2(0f, 0.5f),
				pivot = new Vector2(0.5f, 0.5f),
				size = new Vector2(14f, 26f),
				pos = Vector2.zero
			};
		}

		internal static Rec InsetFill(float inset)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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_001b: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			return new Rec
			{
				min = Vector2.zero,
				max = Vector2.one,
				pivot = new Vector2(0.5f, 0.5f),
				size = new Vector2((0f - inset) * 2f, (0f - inset) * 2f),
				pos = Vector2.zero
			};
		}

		internal static Color Alpha(Color c, float a)
		{
			//IL_0000: 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_000c: 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)
			return new Color(c.r, c.g, c.b, a);
		}

		internal static RawImage MakeRaw(string name, Transform parent, Color color, Rec r)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name, new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(RawImage)
			});
			RectTransform component = val.GetComponent<RectTransform>();
			((Transform)component).SetParent(parent, false);
			component.anchorMin = r.min;
			component.anchorMax = r.max;
			component.pivot = r.pivot;
			component.sizeDelta = r.size;
			component.anchoredPosition = r.pos;
			RawImage component2 = val.GetComponent<RawImage>();
			((Graphic)component2).color = color;
			((Graphic)component2).raycastTarget = false;
			return component2;
		}

		internal static TextMeshProUGUI CloneLabel(TextMeshProUGUI src, string name)
		{
			GameObject val = Object.Instantiate<GameObject>(((Component)src).gameObject, ((TMP_Text)src).transform.parent, false);
			((Object)val).name = name;
			return val.GetComponent<TextMeshProUGUI>();
		}

		internal static void PlaceLabel(TextMeshProUGUI tmp, RectTransform bar, Vector2 anchor, Vector2 pivot, Vector2 pos, TextAlignmentOptions align, float font, Color color)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			RectTransform rectTransform = ((TMP_Text)tmp).rectTransform;
			((Transform)rectTransform).SetParent((Transform)(object)bar, false);
			Vector2 anchorMin = (rectTransform.anchorMax = anchor);
			rectTransform.anchorMin = anchorMin;
			rectTransform.pivot = pivot;
			rectTransform.anchoredPosition = pos;
			((TMP_Text)tmp).alignment = align;
			((TMP_Text)tmp).enableAutoSizing = false;
			((TMP_Text)tmp).fontSize = font;
			((Graphic)tmp).color = color;
		}

		internal static void PlaceAtBarEdge(TextMeshProUGUI tmp, RectTransform bar, bool leftEdge, float x, float font, Color color)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			bool flag = x < 0f;
			PlaceLabel(tmp, bar, new Vector2(leftEdge ? 0f : 1f, 0.5f), new Vector2(flag ? 1f : 0f, 0.5f), new Vector2(x, 0f), (TextAlignmentOptions)(flag ? 516 : 513), font, color);
		}

		internal static void DestroyChild(Transform root, string name)
		{
			Transform val = root.Find(name);
			if (!((Object)(object)val == (Object)null))
			{
				((Component)val).gameObject.SetActive(false);
				Object.Destroy((Object)(object)((Component)val).gameObject);
			}
		}

		internal static void HideObject(Transform root, string name)
		{
			Transform val = root.Find(name);
			if ((Object)(object)val != (Object)null)
			{
				((Component)val).gameObject.SetActive(false);
			}
		}

		internal static void HideGraphic(Transform target)
		{
			if (!((Object)(object)target == (Object)null))
			{
				Graphic component = ((Component)target).GetComponent<Graphic>();
				if ((Object)(object)component != (Object)null)
				{
					((Behaviour)component).enabled = false;
				}
			}
		}

		internal static void HideGraphic(Transform root, string name)
		{
			HideGraphic(root.Find(name));
		}
	}
}
namespace SpectateVoiceVolume.Patches
{
	[HarmonyPatch(typeof(PlayerVoiceChat), "Update")]
	internal static class VoiceVolumePatch
	{
		private static bool _faultLogged;

		private static void Postfix(PlayerVoiceChat __instance)
		{
			try
			{
				if (!Plugin.Enabled.Value || (Object)(object)__instance == (Object)(object)PlayerVoiceChat.instance || !SpectateState.IsLocalSpectating())
				{
					return;
				}
				PlayerAvatar playerAvatar = __instance.playerAvatar;
				if ((Object)(object)playerAvatar == (Object)null)
				{
					return;
				}
				(float spectator, float alive) tuple = SpectatorBalance.Factors(Plugin.LiveBalance);
				float item = tuple.spectator;
				float item2 = tuple.alive;
				float num = (playerAvatar.isDisabled ? item : item2);
				if (!(num >= 1f))
				{
					if ((Object)(object)__instance.lowPassLogic != (Object)null)
					{
						AudioLowPassLogic lowPassLogic = __instance.lowPassLogic;
						lowPassLogic.Volume *= num;
					}
					if ((Object)(object)__instance.lowPassLogicTTS != (Object)null)
					{
						AudioLowPassLogic lowPassLogicTTS = __instance.lowPassLogicTTS;
						lowPassLogicTTS.Volume *= num;
					}
				}
			}
			catch (Exception arg)
			{
				if (!_faultLogged)
				{
					_faultLogged = true;
					Plugin instance = Plugin.Instance;
					if (instance != null)
					{
						instance.Log.LogError((object)$"[VoiceVolumePatch] {arg}");
					}
				}
			}
		}
	}
}