Decompiled source of VoiceChatRange v1.0.2

VoiceChatRange\VoiceChatRange.dll

Decompiled 18 hours 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 UnityEngine;

[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-CSharp")]
[assembly: AssemblyCompany("VoiceChatRange")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+ca9f25bd2366f85288e318ea5f5d8fb8269af0ac")]
[assembly: AssemblyProduct("VoiceChatRange")]
[assembly: AssemblyTitle("VoiceChatRange")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.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 VoiceChatRange
{
	[BepInPlugin("com.riggola.voicechatrange", "VoiceChatRange", "1.0.2")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "com.riggola.voicechatrange";

		public const string Name = "VoiceChatRange";

		public const string Version = "1.0.2";

		internal static ManualLogSource Log;

		internal static ConfigEntry<float> RangeMultiplier;

		private void Awake()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			RangeMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Range", "RangeMultiplier", 2.5f, new ConfigDescription("Multiplies how far away you can hear other players' voice chat (and TTS), including the distance at which it becomes muffled through walls. 1 = vanilla range. This only changes how far YOU can hear others, so each player can set their own value independently and it works correctly in multiplayer without anyone else needing the mod.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 20f), Array.Empty<object>()));
			try
			{
				new Harmony("com.riggola.voicechatrange").PatchAll(typeof(Hooks));
				Log.LogInfo((object)"VoiceChatRange 1.0.2 loaded.");
			}
			catch (Exception arg)
			{
				Log.LogError((object)string.Format("{0} failed to patch voice chat range hooks: {1}", "VoiceChatRange", arg));
			}
		}
	}
	[HarmonyPatch]
	internal static class Hooks
	{
		private static readonly Dictionary<AudioLowPassLogic, float> BaselineFalloff = new Dictionary<AudioLowPassLogic, float>();

		[HarmonyPatch(typeof(PlayerVoiceChat), "Update")]
		[HarmonyPostfix]
		private static void RegisterChannels(PlayerVoiceChat __instance)
		{
			TryCaptureBaseline(__instance.lowPassLogic);
			TryCaptureBaseline(__instance.lowPassLogicTTS);
		}

		[HarmonyPatch(typeof(AudioLowPassLogic), "Update")]
		[HarmonyPrefix]
		private static void ApplyRangeBeforeUpdate(AudioLowPassLogic __instance)
		{
			ApplyRange(__instance);
		}

		[HarmonyPatch(typeof(AudioLowPassLogic), "CheckLogic")]
		[HarmonyPrefix]
		private static void ApplyRangeBeforeCheck(AudioLowPassLogic __instance)
		{
			ApplyRange(__instance);
		}

		private static void TryCaptureBaseline(AudioLowPassLogic instance)
		{
			if (!((Object)(object)instance == (Object)null) && !(instance.Falloff <= 0f) && !BaselineFalloff.ContainsKey(instance))
			{
				BaselineFalloff[instance] = instance.Falloff;
			}
		}

		private static void ApplyRange(AudioLowPassLogic instance)
		{
			if (BaselineFalloff.TryGetValue(instance, out var value))
			{
				instance.Falloff = value * Plugin.RangeMultiplier.Value;
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}