Decompiled source of SBG VoiceOverlay v1.0.2

SBG-VoiceOverlay.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 HarmonyLib;
using Microsoft.CodeAnalysis;
using Mirror;
using ProximityChat;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("GameAssembly")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SBG-VoiceOverlay")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+c4116cae25dd57ca92bdc8edd61d9fbb2b8cd331")]
[assembly: AssemblyProduct("Voice Overlay")]
[assembly: AssemblyTitle("SBG-VoiceOverlay")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.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 VoiceOverlay
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "SBG-VoiceOverlay";

		public const string PLUGIN_NAME = "Voice Overlay";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}
namespace VoiceActivityOverlay
{
	[BepInPlugin("com.kingcox22.sbg.voiceoverlay", "SBG-Voice Overlay", "1.0.2")]
	public class VoiceOverlayPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(VoiceNetworker), "OnStartClient")]
		public static class VoiceNetworker_Patch
		{
			private static void Postfix(VoiceNetworker __instance)
			{
				if (!_allNetworkers.Contains(__instance))
				{
					_allNetworkers.Add(__instance);
				}
			}
		}

		private static List<VoiceNetworker> _allNetworkers = new List<VoiceNetworker>();

		private static GUIStyle _labelStyle;

		private static MemberInfo _volumeMember;

		private static bool _searched = false;

		private ConfigEntry<float> _offsetX;

		private ConfigEntry<float> _offsetY;

		private ConfigEntry<int> _fontSize;

		private void Awake()
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			_offsetX = ((BaseUnityPlugin)this).Config.Bind<float>("General", "X Offset", 20f, "Horizontal position.");
			_offsetY = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Y Offset", 20f, "Vertical starting position.");
			_fontSize = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Font Size", 18, "Size of the text.");
			new Harmony("com.kingcox22.sbg.voiceoverlay").PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Voice Overlay 1.9.0: Using Proven Name Discovery");
		}

		private void OnGUI()
		{
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Expected O, but got Unknown
			if (!NetworkClient.active || _allNetworkers.Count == 0)
			{
				return;
			}
			if (!_searched)
			{
				_searched = true;
				Type typeFromHandle = typeof(VoiceNetworker);
				_volumeMember = (MemberInfo)(((object)typeFromHandle.GetProperty("SlowSmoothedNormalizedVolume", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) ?? ((object)typeFromHandle.GetField("normalizedVolume", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)));
			}
			if (_labelStyle == null)
			{
				_labelStyle = new GUIStyle(GUI.skin.label)
				{
					fontStyle = (FontStyle)1,
					richText = true
				};
			}
			_labelStyle.fontSize = _fontSize.Value;
			float value = _offsetX.Value;
			float num = _offsetY.Value;
			_allNetworkers.RemoveAll((VoiceNetworker v) => (Object)(object)v == (Object)null);
			foreach (VoiceNetworker allNetworker in _allNetworkers)
			{
				if (!allNetworker.IsTalking)
				{
					continue;
				}
				PlayerGolfer componentInParent = ((Component)allNetworker).GetComponentInParent<PlayerGolfer>();
				string text = "Connecting...";
				if ((Object)(object)componentInParent != (Object)null && (Object)(object)componentInParent.PlayerInfo != (Object)null)
				{
					text = GetPlayerName(componentInParent.PlayerInfo);
				}
				float num2 = 0f;
				try
				{
					if (_volumeMember is PropertyInfo propertyInfo)
					{
						num2 = (float)propertyInfo.GetValue(allNetworker);
					}
					else if (_volumeMember is FieldInfo fieldInfo)
					{
						num2 = (float)fieldInfo.GetValue(allNetworker);
					}
				}
				catch
				{
				}
				int count = Mathf.Clamp((int)(num2 * 35f), 1, 40);
				string text2 = new string('|', count);
				GUI.color = Color.black;
				GUI.Label(new Rect(value + 2f, num + 2f, 800f, 50f), "[VOICE] " + text + " " + text2, _labelStyle);
				GUI.color = Color.white;
				GUI.Label(new Rect(value, num, 800f, 50f), "<color=#00FF00>[VOICE]</color> " + text + " <color=#FFFFFF>" + text2 + "</color>", _labelStyle);
				num += (float)(_fontSize.Value + 10);
			}
		}

		private string GetPlayerName(PlayerInfo info)
		{
			if ((Object)(object)info == (Object)null)
			{
				return "Unknown";
			}
			try
			{
				Component component = ((Component)info).GetComponent("PlayerId");
				if ((Object)(object)component != (Object)null)
				{
					Type type = ((object)component).GetType();
					PropertyInfo property = type.GetProperty("PlayerName", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (property != null)
					{
						return property.GetValue(component)?.ToString() ?? "Unknown";
					}
					FieldInfo field = type.GetField("playerName", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (field != null)
					{
						return field.GetValue(component)?.ToString() ?? "Unknown";
					}
				}
				Type type2 = ((object)info).GetType();
				FieldInfo field2 = type2.GetField("playerName", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field2 != null)
				{
					return field2.GetValue(info)?.ToString() ?? "Unknown";
				}
			}
			catch (Exception)
			{
			}
			return "Golfer";
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}