Decompiled source of AudibleDistanceLib v0.0.0

AudibleDistanceLib.dll

Decompiled a year 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.Logging;
using GameNetcodeStuff;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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("AudibleDistanceLib")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A small library for audible distance determination.")]
[assembly: AssemblyFileVersion("0.0.0.0")]
[assembly: AssemblyInformationalVersion("0.0.0+290b0a6020c40397f2827f7e300a3a1bab3f47c8")]
[assembly: AssemblyProduct("AudibleDistanceLib")]
[assembly: AssemblyTitle("AudibleDistanceLib")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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 AudibleDistanceLib
{
	[BepInPlugin("JustJelly.AudibleDistanceLib", "AudibleDistanceLib", "0.0.0")]
	public class AudibleDistanceLib : BaseUnityPlugin
	{
		private const string pluginGuid = "JustJelly.AudibleDistanceLib";

		private const string pluginName = "AudibleDistanceLib";

		private const string pluginVersion = "0.0.0";

		public static ManualLogSource ManualLogSource;

		private void Awake()
		{
			ManualLogSource = Logger.CreateLogSource("JustJelly.AudibleDistanceLib");
			ManualLogSource.LogInfo((object)"AudibleDistanceLib 0.0.0 loaded!");
		}

		public static bool IsInWithinAudiableDistance(GameNetworkManager gameNetworkManager, AudioSource source, float volume, float minimumAudibleVolume = 12f)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_006d: 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)
			if (volume == 0f || source == null || gameNetworkManager?.localPlayerController == null)
			{
				return false;
			}
			bool isPlayerDead = gameNetworkManager.localPlayerController.isPlayerDead;
			bool flag = (Object)gameNetworkManager.localPlayerController.spectatedPlayerScript != (Object)null;
			PlayerControllerB val = ((!isPlayerDead || !flag) ? gameNetworkManager.localPlayerController : gameNetworkManager.localPlayerController.spectatedPlayerScript);
			float distance = Vector3.Distance(((Component)val).transform.position, ((Component)source).transform.position);
			float num = EvaluateVolumeAt(source, distance) * volume;
			return num >= minimumAudibleVolume / 100f;
		}

		private static float EvaluateVolumeAt(AudioSource source, float distance)
		{
			//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_004f: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected I4, but got Unknown
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Expected O, but got Unknown
			AnimationCurve val = null;
			float num = source.maxDistance - source.minDistance;
			if (distance < source.minDistance)
			{
				return 1f;
			}
			if (distance > source.maxDistance)
			{
				return 0f;
			}
			AudioRolloffMode rolloffMode = source.rolloffMode;
			AudioRolloffMode val2 = rolloffMode;
			switch ((int)val2)
			{
			case 1:
				val = AnimationCurve.Linear(0f, 1f, 1f, 0f);
				break;
			case 0:
				val = new AnimationCurve((Keyframe[])(object)new Keyframe[5]
				{
					new Keyframe(0f, 1f),
					new Keyframe(num / 4f, 1f / (source.minDistance + num / 4f)),
					new Keyframe(num / 2f, 1f / (source.minDistance + num / 2f)),
					new Keyframe(3f * num / 4f, 1f / (source.minDistance + 3f * num / 4f)),
					new Keyframe(1f, 0f)
				});
				break;
			case 2:
				val = source.GetCustomCurve((AudioSourceCurveType)0);
				break;
			}
			if (val == null)
			{
				return 1f;
			}
			float num2 = (distance - source.minDistance) / num;
			return val.Evaluate(num2);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "AudibleDistanceLib";

		public const string PLUGIN_NAME = "AudibleDistanceLib";

		public const string PLUGIN_VERSION = "0.0.0";
	}
}