Decompiled source of Resonix v1.0.0

Mods/Resonix.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BoneLib;
using BoneLib.BoneMenu;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using Resonix;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Main), "Resonix", "2.0.0", "Clifnite", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Resonix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Resonix")]
[assembly: AssemblyTitle("Resonix")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 Resonix
{
	public static class Classifier
	{
		public static SoundKind Classify(string source, string clip)
		{
			string n = (source + "|" + clip).ToLowerInvariant();
			if (Has(n, "fusion", "voicechat", "voice chat", "voip", "microphone", "remoteplayer"))
			{
				return SoundKind.FusionVoice;
			}
			if (Has(n, "npc", "voice", "dialog", "speech", "talk", "ford", "nullbody"))
			{
				return SoundKind.NpcVoice;
			}
			if (Has(n, "gun", "shot", "firearm", "rifle", "pistol", "smg", "shotgun", "revolver"))
			{
				return SoundKind.Gunshot;
			}
			if (Has(n, "explosion", "explode", "blast", "grenade"))
			{
				return SoundKind.Explosion;
			}
			if (Has(n, "impact", "hit", "collision", "ricochet", "thud"))
			{
				return SoundKind.Impact;
			}
			if (Has(n, "foot", "step", "walk", "run"))
			{
				return SoundKind.Footstep;
			}
			if (Has(n, "reload", "slide", "bolt", "mechan", "mag"))
			{
				return SoundKind.Mechanical;
			}
			if (Has(n, "music", "song", "radio"))
			{
				return SoundKind.Music;
			}
			if (Has(n, "ambient", "ambience", "wind", "hum"))
			{
				return SoundKind.Ambient;
			}
			return SoundKind.Unknown;
		}

		private static bool Has(string n, params string[] terms)
		{
			foreach (string value in terms)
			{
				if (n.Contains(value))
				{
					return true;
				}
			}
			return false;
		}
	}
	public static class Config
	{
		public static MelonPreferences_Category Category;

		public static MelonPreferences_Entry<bool> Enabled;

		public static MelonPreferences_Entry<bool> GunVariation;

		public static MelonPreferences_Entry<bool> ImpactVariation;

		public static MelonPreferences_Entry<bool> VoiceOverhaul;

		public static MelonPreferences_Entry<bool> NpcVoices;

		public static MelonPreferences_Entry<bool> FusionVoices;

		public static MelonPreferences_Entry<bool> Occlusion;

		public static MelonPreferences_Entry<bool> HearingResponse;

		public static MelonPreferences_Entry<bool> DistanceAudio;

		public static MelonPreferences_Entry<bool> EnvironmentAudio;

		public static MelonPreferences_Entry<bool> FusionSafeMode;

		public static MelonPreferences_Entry<float> GunPitchVariation;

		public static MelonPreferences_Entry<float> GunVolumeVariation;

		public static MelonPreferences_Entry<float> GunLoudness;

		public static MelonPreferences_Entry<float> GunRange;

		public static MelonPreferences_Entry<float> VoiceOcclusion;

		public static MelonPreferences_Entry<float> WorldOcclusion;

		public static MelonPreferences_Entry<float> HearingStrength;

		public static MelonPreferences_Entry<float> HearingRecovery;

		public static void Initialize()
		{
			Category = MelonPreferences.CreateCategory("Resonix2");
			Enabled = Category.CreateEntry<bool>("Enabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			GunVariation = Category.CreateEntry<bool>("GunVariation", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			ImpactVariation = Category.CreateEntry<bool>("ImpactVariation", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			VoiceOverhaul = Category.CreateEntry<bool>("VoiceOverhaul", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			NpcVoices = Category.CreateEntry<bool>("NpcVoices", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			FusionVoices = Category.CreateEntry<bool>("FusionVoices", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			Occlusion = Category.CreateEntry<bool>("Occlusion", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			HearingResponse = Category.CreateEntry<bool>("HearingResponse", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			DistanceAudio = Category.CreateEntry<bool>("DistanceAudio", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			EnvironmentAudio = Category.CreateEntry<bool>("EnvironmentAudio", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			FusionSafeMode = Category.CreateEntry<bool>("FusionSafeMode", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			GunPitchVariation = Category.CreateEntry<float>("GunPitchVariation", 0.085f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			GunVolumeVariation = Category.CreateEntry<float>("GunVolumeVariation", 0.05f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			GunLoudness = Category.CreateEntry<float>("GunLoudness", 0.92f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			GunRange = Category.CreateEntry<float>("GunRange", 95f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			VoiceOcclusion = Category.CreateEntry<float>("VoiceOcclusion", 0.72f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			WorldOcclusion = Category.CreateEntry<float>("WorldOcclusion", 0.55f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			HearingStrength = Category.CreateEntry<float>("HearingStrength", 0.68f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			HearingRecovery = Category.CreateEntry<float>("HearingRecovery", 3.5f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			MelonPreferences.Save();
		}
	}
	public static class FusionBridge
	{
		public static bool Loaded { get; private set; }

		public static void Refresh()
		{
			try
			{
				Loaded = AppDomain.CurrentDomain.GetAssemblies().Any((Assembly a) => (a.GetName().Name ?? "").IndexOf("Fusion", StringComparison.OrdinalIgnoreCase) >= 0);
			}
			catch
			{
				Loaded = false;
			}
		}
	}
	public static class GunSoundSystem
	{
		public static int ShotChanges { get; private set; }

		public static void Process(AudioSource source, SourceState state, SoundKind kind)
		{
			if (!Config.GunVariation.Value || (Object)(object)source == (Object)null || state == null || kind != SoundKind.Gunshot)
			{
				return;
			}
			int num = (((Object)(object)source.clip != (Object)null) ? ((Object)source.clip).GetInstanceID() : 0);
			int num2 = 0;
			try
			{
				num2 = source.timeSamples;
			}
			catch
			{
			}
			if (source.isPlaying && (!state.LastPlaying || state.LastClipId != num || num2 + 256 < state.LastTimeSamples))
			{
				float num3 = Mathf.Clamp(Config.GunPitchVariation.Value, 0f, 0.18f);
				float num4 = Mathf.Clamp(Config.GunVolumeVariation.Value, 0f, 0.12f);
				float num5 = Mathf.Clamp01(Config.GunLoudness.Value);
				source.pitch = Mathf.Clamp(state.OriginalPitch + Random.Range(0f - num3, num3), 0.78f, 1.22f);
				float num6 = Mathf.Clamp01(state.OriginalVolume + Random.Range(0f - num4, num4));
				source.volume = Mathf.Lerp(num6, 1f, num5);
				if (source.spatialBlend > 0.1f && Config.DistanceAudio.Value)
				{
					source.maxDistance = Mathf.Max(state.OriginalMaxDistance, Mathf.Clamp(Config.GunRange.Value, 20f, 150f));
					source.minDistance = Mathf.Max(state.OriginalMinDistance, Mathf.Lerp(1f, 3.2f, num5));
				}
				ShotChanges++;
			}
			state.LastPlaying = source.isPlaying;
			state.LastClipId = num;
			state.LastTimeSamples = num2;
		}

		public static void Reset()
		{
			ShotChanges = 0;
		}
	}
	public static class HearingSystem
	{
		private static float _shock;

		private static float _baseVolume = 1f;

		public static float Shock => _shock;

		public static void Initialize()
		{
			try
			{
				_baseVolume = AudioListener.volume;
			}
			catch
			{
				_baseVolume = 1f;
			}
		}

		public static void Observe(AudioSource source, SoundKind kind, float distance)
		{
			if (Config.HearingResponse.Value && !((Object)(object)source == (Object)null))
			{
				float num = ((kind == SoundKind.Explosion) ? 0.95f : ((kind == SoundKind.Gunshot) ? 0.78f : ((kind == SoundKind.Impact && source.volume > 0.75f) ? 0.12f : 0f)));
				if (!(num <= 0f))
				{
					float num2 = ((kind == SoundKind.Gunshot) ? Mathf.Clamp(Config.GunRange.Value * 0.25f, 10f, 30f) : 14f);
					num *= Mathf.Clamp01(1f - distance / num2) * Mathf.Clamp01(Config.HearingStrength.Value);
					_shock = Mathf.Max(_shock, num);
				}
			}
		}

		public static void Tick()
		{
			float num = Mathf.Max(0.5f, Config.HearingRecovery.Value);
			_shock = Mathf.MoveTowards(_shock, 0f, Time.deltaTime / num);
			try
			{
				AudioListener.volume = Mathf.Lerp(_baseVolume, _baseVolume * 0.3f, _shock);
			}
			catch
			{
			}
		}

		public static void Test()
		{
			_shock = Mathf.Max(_shock, 0.75f);
		}

		public static void Reset()
		{
			_shock = 0f;
			try
			{
				AudioListener.volume = _baseVolume;
			}
			catch
			{
			}
		}
	}
	public static class ImpactSystem
	{
		public static void Process(AudioSource source, SourceState state, SoundKind kind)
		{
			if (Config.ImpactVariation.Value && !((Object)(object)source == (Object)null) && state != null && kind == SoundKind.Impact && source.isPlaying && !state.LastPlaying)
			{
				source.pitch = Mathf.Clamp(state.OriginalPitch + Random.Range(-0.035f, 0.035f), 0.85f, 1.15f);
			}
		}
	}
	public sealed class Main : MelonMod
	{
		public override void OnInitializeMelon()
		{
			Config.Initialize();
			Runtime.Initialize();
			Menu.Build();
			MelonLogger.Msg("[Resonix] 2.0 full BONELAB audio overhaul initialized.");
		}

		public override void OnUpdate()
		{
			if (Config.Enabled.Value)
			{
				Runtime.Tick();
			}
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			Runtime.Reset();
		}
	}
	public static class Menu
	{
		public static void Build()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: 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_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0328: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_039c: 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_041e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0430: Unknown result type (might be due to invalid IL or missing references)
			//IL_046a: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0526: Unknown result type (might be due to invalid IL or missing references)
			//IL_0538: Unknown result type (might be due to invalid IL or missing references)
			//IL_0571: Unknown result type (might be due to invalid IL or missing references)
			Page obj = Page.Root.CreatePage("Resonix", new Color(0.55f, 0.85f, 1f), 0, true);
			obj.CreateBool("Enabled", Color.green, Config.Enabled.Value, (Action<bool>)delegate(bool v)
			{
				Save(Config.Enabled, v);
			});
			Page obj2 = obj.CreatePage("Gun Audio", Color.white, 0, true);
			obj2.CreateBool("Per-Shot Variation", Color.white, Config.GunVariation.Value, (Action<bool>)delegate(bool v)
			{
				Save(Config.GunVariation, v);
			});
			obj2.CreateFloat("Pitch Variation", Color.white, Config.GunPitchVariation.Value, 0.005f, 0f, 0.18f, (Action<float>)delegate(float v)
			{
				Save(Config.GunPitchVariation, v);
			});
			obj2.CreateFloat("Volume Variation", Color.white, Config.GunVolumeVariation.Value, 0.005f, 0f, 0.12f, (Action<float>)delegate(float v)
			{
				Save(Config.GunVolumeVariation, v);
			});
			obj2.CreateFloat("Gun Loudness", Color.white, Config.GunLoudness.Value, 0.05f, 0.25f, 1f, (Action<float>)delegate(float v)
			{
				Save(Config.GunLoudness, v);
			});
			obj2.CreateFloat("Gun Range", Color.white, Config.GunRange.Value, 5f, 20f, 150f, (Action<float>)delegate(float v)
			{
				Save(Config.GunRange, v);
			});
			Page obj3 = obj.CreatePage("Voices", Color.cyan, 0, true);
			obj3.CreateBool("Voice Overhaul", Color.white, Config.VoiceOverhaul.Value, (Action<bool>)delegate(bool v)
			{
				Save(Config.VoiceOverhaul, v);
			});
			obj3.CreateBool("NPC Voices", Color.white, Config.NpcVoices.Value, (Action<bool>)delegate(bool v)
			{
				Save(Config.NpcVoices, v);
			});
			obj3.CreateBool("Fusion Player Voices", Color.white, Config.FusionVoices.Value, (Action<bool>)delegate(bool v)
			{
				Save(Config.FusionVoices, v);
			});
			obj3.CreateFloat("Voice Occlusion", Color.white, Config.VoiceOcclusion.Value, 0.05f, 0f, 1f, (Action<float>)delegate(float v)
			{
				Save(Config.VoiceOcclusion, v);
			});
			Page obj4 = obj.CreatePage("World Acoustics", Color.green, 0, true);
			obj4.CreateBool("Door / Wall Muffling", Color.white, Config.Occlusion.Value, (Action<bool>)delegate(bool v)
			{
				Save(Config.Occlusion, v);
			});
			obj4.CreateBool("Distance Audio", Color.white, Config.DistanceAudio.Value, (Action<bool>)delegate(bool v)
			{
				Save(Config.DistanceAudio, v);
			});
			obj4.CreateBool("Environment Audio", Color.white, Config.EnvironmentAudio.Value, (Action<bool>)delegate(bool v)
			{
				Save(Config.EnvironmentAudio, v);
			});
			obj4.CreateBool("Impact Variation", Color.white, Config.ImpactVariation.Value, (Action<bool>)delegate(bool v)
			{
				Save(Config.ImpactVariation, v);
			});
			obj4.CreateFloat("World Occlusion", Color.white, Config.WorldOcclusion.Value, 0.05f, 0f, 1f, (Action<float>)delegate(float v)
			{
				Save(Config.WorldOcclusion, v);
			});
			Page obj5 = obj.CreatePage("Hearing", Color.yellow, 0, true);
			obj5.CreateBool("Hearing Response", Color.white, Config.HearingResponse.Value, (Action<bool>)delegate(bool v)
			{
				Save(Config.HearingResponse, v);
			});
			obj5.CreateFloat("Hearing Strength", Color.white, Config.HearingStrength.Value, 0.05f, 0f, 1f, (Action<float>)delegate(float v)
			{
				Save(Config.HearingStrength, v);
			});
			obj5.CreateFloat("Recovery Time", Color.white, Config.HearingRecovery.Value, 0.25f, 0.5f, 10f, (Action<float>)delegate(float v)
			{
				Save(Config.HearingRecovery, v);
			});
			obj5.CreateFunction("Test Hearing Effect", Color.white, (Action)HearingSystem.Test);
			Page obj6 = obj.CreatePage("Compatibility", Color.magenta, 0, true);
			obj6.CreateBool("Fusion Safe Mode", Color.white, Config.FusionSafeMode.Value, (Action<bool>)delegate(bool v)
			{
				Save(Config.FusionSafeMode, v);
			});
			obj6.CreateFunction("Print Audio Report", Color.white, (Action)Report.Print);
		}

		private static void Save(MelonPreferences_Entry<bool> e, bool v)
		{
			e.Value = v;
			MelonPreferences.Save();
		}

		private static void Save(MelonPreferences_Entry<float> e, float v)
		{
			e.Value = v;
			MelonPreferences.Save();
		}
	}
	public static class OcclusionSystem
	{
		public static void Process(AudioSource source, SourceState state, SoundKind kind, Transform listener)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_006e: 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)
			if (!Config.Occlusion.Value || (Object)(object)source == (Object)null || state == null || (Object)(object)listener == (Object)null || kind == SoundKind.Music)
			{
				return;
			}
			Vector3 val = ((Component)source).transform.position - listener.position;
			float magnitude = ((Vector3)(ref val)).magnitude;
			if (magnitude < 0.35f)
			{
				state.Occlusion = Mathf.MoveTowards(state.Occlusion, 0f, 0.2f);
				return;
			}
			bool flag = false;
			try
			{
				RaycastHit val2 = default(RaycastHit);
				flag = Physics.Raycast(listener.position, ((Vector3)(ref val)).normalized, ref val2, magnitude, -1, (QueryTriggerInteraction)1);
			}
			catch
			{
			}
			float num = (flag ? 1f : 0f);
			state.Occlusion = Mathf.MoveTowards(state.Occlusion, num, 0.18f);
			if (!(state.Occlusion <= 0.01f))
			{
				bool flag2 = kind == SoundKind.NpcVoice || kind == SoundKind.FusionVoice;
				float num2 = (flag2 ? Mathf.Clamp01(Config.VoiceOcclusion.Value) : Mathf.Clamp01(Config.WorldOcclusion.Value));
				float num3 = Mathf.Lerp(1f, flag2 ? 0.36f : 0.55f, state.Occlusion * num2);
				source.volume *= num3;
				if (flag2)
				{
					source.pitch = Mathf.Lerp(source.pitch, Mathf.Clamp(state.OriginalPitch * 0.985f, 0.8f, 1.2f), state.Occlusion * num2 * 0.25f);
				}
			}
		}
	}
	public static class Report
	{
		public static void Print()
		{
			MelonLogger.Msg("[Resonix] ===== AUDIO REPORT =====");
			MelonLogger.Msg($"Playing sources: {Runtime.PlayingSources}");
			MelonLogger.Msg($"Tracked sources: {SourceRegistry.Count}");
			MelonLogger.Msg($"Per-shot pitch changes: {GunSoundSystem.ShotChanges}");
			MelonLogger.Msg($"Hearing effect: {HearingSystem.Shock:0.00}");
			MelonLogger.Msg($"Fusion detected: {FusionBridge.Loaded}");
			MelonLogger.Msg("[Resonix] ========================");
		}
	}
	public static class Runtime
	{
		private static float _nextScan;

		private static float _nextFusion;

		public static int PlayingSources { get; private set; }

		public static void Initialize()
		{
			HearingSystem.Initialize();
			FusionBridge.Refresh();
		}

		public static void Tick()
		{
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			HearingSystem.Tick();
			if (Time.time >= _nextFusion)
			{
				_nextFusion = Time.time + 5f;
				FusionBridge.Refresh();
			}
			float num = ((FusionBridge.Loaded && Config.FusionSafeMode.Value) ? 0.14f : 0.08f);
			if (Time.time < _nextScan)
			{
				return;
			}
			_nextScan = Time.time + num;
			Transform val = null;
			try
			{
				val = Player.Head;
			}
			catch
			{
			}
			AudioSource[] array;
			try
			{
				array = Il2CppArrayBase<AudioSource>.op_Implicit(Object.FindObjectsOfType<AudioSource>());
			}
			catch
			{
				return;
			}
			PlayingSources = 0;
			AudioSource[] array2 = array;
			foreach (AudioSource val2 in array2)
			{
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				SourceState sourceState = SourceRegistry.Get(val2);
				if (sourceState != null)
				{
					string clip = (((Object)(object)val2.clip != (Object)null) ? ((Object)val2.clip).name : "");
					SoundKind kind = Classifier.Classify(((Object)val2).name, clip);
					if (val2.isPlaying)
					{
						PlayingSources++;
						float distance = (((Object)(object)val != (Object)null) ? Vector3.Distance(val.position, ((Component)val2).transform.position) : 999f);
						GunSoundSystem.Process(val2, sourceState, kind);
						ImpactSystem.Process(val2, sourceState, kind);
						VoiceSystem.Process(val2, sourceState, kind, val);
						OcclusionSystem.Process(val2, sourceState, kind, val);
						HearingSystem.Observe(val2, kind, distance);
					}
					else
					{
						sourceState.LastPlaying = false;
						val2.pitch = Mathf.Lerp(val2.pitch, sourceState.OriginalPitch, 0.2f);
						val2.volume = Mathf.Lerp(val2.volume, sourceState.OriginalVolume, 0.2f);
					}
				}
			}
		}

		public static void Reset()
		{
			_nextScan = 0f;
			PlayingSources = 0;
			GunSoundSystem.Reset();
			SourceRegistry.Reset();
			HearingSystem.Reset();
		}
	}
	public enum SoundKind
	{
		Unknown,
		Gunshot,
		Explosion,
		Impact,
		Footstep,
		Mechanical,
		NpcVoice,
		FusionVoice,
		Ambient,
		Music
	}
	public static class SourceRegistry
	{
		private static readonly Dictionary<int, SourceState> States = new Dictionary<int, SourceState>();

		public static int Count => States.Count;

		public static SourceState Get(AudioSource source)
		{
			if ((Object)(object)source == (Object)null)
			{
				return null;
			}
			int instanceID = ((Object)source).GetInstanceID();
			if (!States.TryGetValue(instanceID, out var value))
			{
				value = new SourceState
				{
					Source = source,
					OriginalPitch = source.pitch,
					OriginalVolume = source.volume,
					OriginalMinDistance = source.minDistance,
					OriginalMaxDistance = source.maxDistance
				};
				States[instanceID] = value;
			}
			return value;
		}

		public static void Reset()
		{
			foreach (SourceState value in States.Values)
			{
				if (!((Object)(object)value?.Source == (Object)null))
				{
					try
					{
						value.Source.pitch = value.OriginalPitch;
						value.Source.volume = value.OriginalVolume;
						value.Source.minDistance = value.OriginalMinDistance;
						value.Source.maxDistance = value.OriginalMaxDistance;
					}
					catch
					{
					}
				}
			}
			States.Clear();
		}
	}
	public sealed class SourceState
	{
		public AudioSource Source;

		public float OriginalPitch;

		public float OriginalVolume;

		public float OriginalMinDistance;

		public float OriginalMaxDistance;

		public float LastTime;

		public int LastTimeSamples;

		public bool LastPlaying;

		public int LastClipId;

		public float Occlusion;
	}
	public static class VoiceSystem
	{
		public static void Process(AudioSource source, SourceState state, SoundKind kind, Transform listener)
		{
			//IL_004c: 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)
			if (!Config.VoiceOverhaul.Value || (Object)(object)source == (Object)null || state == null || (Object)(object)listener == (Object)null)
			{
				return;
			}
			bool num = kind == SoundKind.NpcVoice && Config.NpcVoices.Value;
			bool flag = kind == SoundKind.FusionVoice && Config.FusionVoices.Value;
			if (num || flag)
			{
				float num2 = Vector3.Distance(listener.position, ((Component)source).transform.position);
				if (source.spatialBlend > 0.1f)
				{
					float num3 = Mathf.Clamp01(num2 / 22f);
					float num4 = state.OriginalVolume * Mathf.Lerp(1f, 0.72f, num3);
					source.volume = Mathf.Lerp(source.volume, num4, 0.2f);
				}
			}
		}
	}
}