Decompiled source of SpectateVoiceVolume v1.0.0

BepInEx/plugins/SpectateVoiceVolume.dll

Decompiled 6 hours ago
using System;
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.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SpectateVoiceVolume")]
[assembly: AssemblyTitle("SpectateVoiceVolume")]
[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;
		}
	}
}
namespace SpectateVoiceVolume
{
	[BepInPlugin("redos.spectatevoicevolume", "SpectateVoiceVolume", "1.0.0")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string GUID = "redos.spectatevoicevolume";

		public const string Name = "SpectateVoiceVolume";

		public const string Version = "1.0.0";

		public static ConfigEntry<bool> Enabled;

		public static ConfigEntry<float> Balance;

		public static ConfigEntry<bool> ShowSliderAlways;

		public static ConfigEntry<bool> VerboseLogging;

		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_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: 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.");
			VerboseLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "VerboseLogging", false, "Extra logging.");
			LiveBalance = Balance.Value;
			_harmony = new Harmony("redos.spectatevoicevolume");
			_harmony.PatchAll(typeof(Plugin).Assembly);
			((BaseUnityPlugin)this).Logger.LogMessage((object)"SpectateVoiceVolume 1.0.0 loaded");
		}

		public static void Vlog(string msg)
		{
			if ((Object)(object)Instance != (Object)null && VerboseLogging != null && VerboseLogging.Value)
			{
				((BaseUnityPlugin)Instance).Logger.LogInfo((object)("[SpectateVoiceVolume] " + msg));
			}
		}
	}
	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 (item, item2);
		}

		private static float Clamp01(float v)
		{
			if (!(v < 0f))
			{
				if (!(v > 1f))
				{
					return v;
				}
				return 1f;
			}
			return 0f;
		}
	}
}
namespace SpectateVoiceVolume.UI
{
	[HarmonyPatch(typeof(MenuPageEsc), "Start")]
	internal static class BalanceSliderInjector
	{
		private static void Postfix(MenuPageEsc __instance)
		{
			//IL_0166: 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_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: 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_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: Unknown result type (might be due to invalid IL or missing references)
			//IL_033e: Unknown result type (might be due to invalid IL or missing references)
			//IL_033f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_0359: Unknown result type (might be due to invalid IL or missing references)
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_042b: 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 = Object.Instantiate<GameObject>(__instance.playerMicrophoneVolumeSliderPrefab, ((Component)__instance).transform);
				((Object)val).name = "SpectatorVoiceBalanceSlider";
				Transform transform = val.transform;
				SliderUi.StripComponent<MenuSliderPlayerMicGain>(val);
				SliderUi.DestroyChild(transform, "Menu Kick Button");
				SliderUi.DestroyChild(transform, "Steam Button");
				MenuSlider component = val.GetComponent<MenuSlider>();
				if ((Object)(object)component == (Object)null)
				{
					Object.Destroy((Object)(object)val);
					return;
				}
				SliderUi.HideObject(transform, "SliderBG");
				SliderUi.HideObject(transform, "Bar");
				SliderUi.HideObject(transform, "Bar Text");
				SliderUi.HideObject(transform, "MaskedText");
				SliderUi.HideObject(transform, "Menu Button - <");
				SliderUi.HideObject(transform, "Menu Button - >");
				SliderUi.HideGraphic(transform, "Bar Pointer");
				RectTransform barSizeRectTransform = component.barSizeRectTransform;
				if ((Object)(object)barSizeRectTransform != (Object)null)
				{
					Graphic component2 = ((Component)barSizeRectTransform).GetComponent<Graphic>();
					if ((Object)(object)component2 != (Object)null)
					{
						((Behaviour)component2).enabled = false;
					}
					((Transform)barSizeRectTransform).localPosition = ((Transform)barSizeRectTransform).localPosition - new Vector3((1f - barSizeRectTransform.pivot.x) * 100f, 0f, 0f);
					barSizeRectTransform.sizeDelta = new Vector2(barSizeRectTransform.sizeDelta.x + 100f, barSizeRectTransform.sizeDelta.y);
				}
				if ((Object)(object)barSizeRectTransform != (Object)null)
				{
					SliderUi.MakeRaw("BalGroove", (Transform)(object)barSizeRectTransform, SliderUi.Groove, SliderUi.StretchH(12f));
					SliderUi.MakeRaw("BalTintL", (Transform)(object)barSizeRectTransform, SliderUi.Alpha(SliderUi.Cool, 0.16f), SliderUi.Half(left: true, 12f));
					SliderUi.MakeRaw("BalTintR", (Transform)(object)barSizeRectTransform, SliderUi.Alpha(SliderUi.Warm, 0.16f), SliderUi.Half(left: false, 12f));
					SliderUi.MakeRaw("BalTick", (Transform)(object)barSizeRectTransform, SliderUi.Tick, SliderUi.Tick2());
				}
				TextMeshProUGUI val2 = null;
				TextMeshProUGUI val3 = null;
				TextMeshProUGUI elementNameText = component.elementNameText;
				if ((Object)(object)elementNameText != (Object)null && (Object)(object)barSizeRectTransform != (Object)null)
				{
					float fontSize = ((TMP_Text)elementNameText).fontSize;
					TextMeshProUGUI val4 = SliderUi.CloneLabel(elementNameText, "AliveWord");
					val2 = SliderUi.CloneLabel(elementNameText, "DeadPct");
					val3 = SliderUi.CloneLabel(elementNameText, "AlivePct");
					TextMeshProUGUI val5 = SliderUi.CloneLabel(elementNameText, "Caption");
					SliderUi.OnBarEdge(elementNameText, barSizeRectTransform, leftEdge: true, 12f, new Vector2(0f, 0.5f), (TextAlignmentOptions)513, fontSize * 0.55f, SliderUi.Cool);
					SliderUi.OnBarEdge(val4, barSizeRectTransform, leftEdge: false, -12f, new Vector2(1f, 0.5f), (TextAlignmentOptions)516, fontSize * 0.55f, SliderUi.Warm);
					((TMP_Text)elementNameText).text = "DEAD";
					((TMP_Text)val4).text = "ALIVE";
					SliderUi.OnBarEdge(val2, barSizeRectTransform, leftEdge: true, -8f, new Vector2(1f, 0.5f), (TextAlignmentOptions)516, fontSize * 0.7f, SliderUi.Cool);
					SliderUi.OnBarEdge(val3, barSizeRectTransform, leftEdge: false, 8f, new Vector2(0f, 0.5f), (TextAlignmentOptions)513, fontSize * 0.7f, SliderUi.Warm);
					RectTransform rectTransform = ((TMP_Text)val5).rectTransform;
					((Transform)rectTransform).SetParent((Transform)(object)barSizeRectTransform, false);
					Vector2 anchorMin = (rectTransform.anchorMax = new Vector2(0.5f, 1f));
					rectTransform.anchorMin = anchorMin;
					rectTransform.pivot = new Vector2(0.5f, 0f);
					rectTransform.anchoredPosition = new Vector2(0f, 6f);
					((TMP_Text)val5).alignment = (TextAlignmentOptions)514;
					((TMP_Text)val5).enableAutoSizing = false;
					((TMP_Text)val5).fontSize = fontSize * 0.5f;
					((Graphic)val5).color = new Color(0.58f, 0.58f, 0.66f);
					((TMP_Text)val5).text = "VOICE BALANCE";
				}
				RectTransform handle = (((Object)(object)barSizeRectTransform != (Object)null) ? ((Graphic)SliderUi.MakeRaw("BalHandle", (Transform)(object)barSizeRectTransform, SliderUi.HandleCol, SliderUi.HandleRect())).rectTransform : null);
				float num = (SemiFunc.IsMasterClient() ? 400f : 375f);
				int count = __instance.playerMicGainSliders.Count;
				val.transform.localPosition = new Vector3(num, 21f + 25f * (float)(count + 1), 0f);
				val.AddComponent<BalanceSliderBinding>().Init(component, val2, val3, handle, barSizeRectTransform);
			}
			catch (Exception arg)
			{
				Plugin instance = Plugin.Instance;
				if (instance != null)
				{
					instance.Log.LogError((object)$"[BalanceSliderInjector] {arg}");
				}
			}
		}
	}
	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 Groove = new Color(0.1f, 0.11f, 0.15f, 0.95f);

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

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

		internal static Rec StretchH(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)
			Rec result = default(Rec);
			result.min = new Vector2(0f, 0.5f);
			result.max = new Vector2(1f, 0.5f);
			result.pivot = new Vector2(0.5f, 0.5f);
			result.size = new Vector2(0f, h);
			result.pos = Vector2.zero;
			return result;
		}

		internal static Rec Half(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)
			Rec result = default(Rec);
			result.min = new Vector2(left ? 0f : 0.5f, 0.5f);
			result.max = new Vector2(left ? 0.5f : 1f, 0.5f);
			result.pivot = new Vector2(0.5f, 0.5f);
			result.size = new Vector2(0f, h);
			result.pos = Vector2.zero;
			return result;
		}

		internal static Rec Tick2()
		{
			//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)
			Rec result = default(Rec);
			result.min = new Vector2(0.5f, 0.5f);
			result.max = new Vector2(0.5f, 0.5f);
			result.pivot = new Vector2(0.5f, 0.5f);
			result.size = new Vector2(2f, 20f);
			result.pos = Vector2.zero;
			return result;
		}

		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)
			Rec result = default(Rec);
			result.min = new Vector2(0f, 0.5f);
			result.max = new Vector2(0f, 0.5f);
			result.pivot = new Vector2(0.5f, 0.5f);
			result.size = new Vector2(14f, 26f);
			result.pos = Vector2.zero;
			return result;
		}

		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 OnBarEdge(TextMeshProUGUI tmp, RectTransform bar, bool leftEdge, float x, Vector2 pivot, TextAlignmentOptions align, float font, Color color)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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_005b: 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)
			RectTransform rectTransform = ((TMP_Text)tmp).rectTransform;
			((Transform)rectTransform).SetParent((Transform)(object)bar, false);
			float num = (leftEdge ? 0f : 1f);
			rectTransform.anchorMin = new Vector2(num, 0.5f);
			rectTransform.anchorMax = new Vector2(num, 0.5f);
			rectTransform.pivot = pivot;
			rectTransform.anchoredPosition = new Vector2(x, 0f);
			((TMP_Text)tmp).alignment = align;
			((TMP_Text)tmp).enableAutoSizing = false;
			((TMP_Text)tmp).fontSize = font;
			((Graphic)tmp).color = color;
		}

		internal static void StripComponent<T>(GameObject go) where T : Component
		{
			T component = go.GetComponent<T>();
			if ((Object)(object)component != (Object)null)
			{
				Object.Destroy((Object)(object)component);
			}
		}

		internal static Transform FindChild(Transform root, string name)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			foreach (Transform item in root)
			{
				Transform val = item;
				if (((Object)val).name == name)
				{
					return val;
				}
			}
			return null;
		}

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

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

		internal static void HideGraphic(Transform root, string name)
		{
			Transform val = FindChild(root, name);
			if (!((Object)(object)val == (Object)null))
			{
				Graphic component = ((Component)val).GetComponent<Graphic>();
				if ((Object)(object)component != (Object)null)
				{
					((Behaviour)component).enabled = false;
				}
			}
		}
	}
	internal sealed class BalanceSliderBinding : MonoBehaviour
	{
		private MenuSlider _slider;

		private TextMeshProUGUI _deadPct;

		private TextMeshProUGUI _alivePct;

		private RectTransform _handle;

		private RectTransform _barSize;

		private CanvasGroup _cg;

		private bool _inited;

		private bool _dirty;

		private bool _fault;

		private float _last = -2f;

		public void Init(MenuSlider slider, TextMeshProUGUI deadPct, TextMeshProUGUI alivePct, RectTransform handle, RectTransform barSize)
		{
			_slider = slider;
			_deadPct = deadPct;
			_alivePct = alivePct;
			_handle = handle;
			_barSize = barSize;
			_cg = ((Component)this).GetComponent<CanvasGroup>();
			if ((Object)(object)_cg == (Object)null)
			{
				_cg = ((Component)this).gameObject.AddComponent<CanvasGroup>();
			}
		}

		private void LateUpdate()
		{
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: 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;
				}
				float settingsValue = _slider.settingsValue;
				if (Mathf.Abs(settingsValue - _last) > 0.0005f)
				{
					_last = settingsValue;
					Plugin.LiveBalance = Mathf.Clamp01(settingsValue);
					_dirty = true;
					var (num, num2) = SpectatorBalance.Factors(settingsValue);
					if ((Object)(object)_deadPct != (Object)null)
					{
						((TMP_Text)_deadPct).text = $"{Mathf.RoundToInt(num * 100f)}%";
					}
					if ((Object)(object)_alivePct != (Object)null)
					{
						((TMP_Text)_alivePct).text = $"{Mathf.RoundToInt(num2 * 100f)}%";
					}
				}
				if ((Object)(object)_handle != (Object)null && (Object)(object)_barSize != (Object)null)
				{
					Vector2 anchoredPosition = _handle.anchoredPosition;
					Rect rect = _barSize.rect;
					anchoredPosition.x = settingsValue * ((Rect)(ref rect)).width;
					_handle.anchoredPosition = anchoredPosition;
				}
				bool flag = Plugin.ShowSliderAlways.Value || SpectateState.IsLocalSpectating();
				float num3 = (flag ? 1f : 0f);
				if (_cg.alpha != num3)
				{
					_cg.alpha = num3;
					_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 OnDisable()
		{
			if (!_dirty)
			{
				return;
			}
			_dirty = false;
			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));
				}
			}
		}
	}
}
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}");
					}
				}
			}
		}
	}
}