Decompiled source of GranularSoundControl v1.5.2

GranularSoundControl.dll

Decompiled an hour 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 System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using LethalSettings.UI;
using LethalSettings.UI.Components;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
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: AssemblyCompany("kryptosynth")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Volume tuning mod for Lethal Company")]
[assembly: AssemblyFileVersion("1.5.2.0")]
[assembly: AssemblyInformationalVersion("1.5.2+a487cd40639a7bd13751e08d26e1c290c79d5eb0")]
[assembly: AssemblyProduct("GranularSoundControl")]
[assembly: AssemblyTitle("GranularSoundControl")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.5.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 GranularSoundControl
{
	internal static class AudioPatches
	{
		private static string GetFormattedName(Object gameObject)
		{
			return gameObject.name.Replace("(Clone)", "").Replace("Item", "");
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(NoisemakerProp), "Start")]
		private static void NoiseMakerProp_Start_Postfix(NoisemakerProp __instance)
		{
			GameObject gameObject = ((Component)__instance).gameObject;
			string formattedName = GetFormattedName((Object)(object)gameObject);
			GranularSoundControlPlugin.Instance.Bind(formattedName, gameObject, __instance.maxLoudness, delegate(float v)
			{
				__instance.maxLoudness = v;
			});
			GranularSoundControlPlugin.Instance.Bind(formattedName, gameObject, __instance.minLoudness, delegate(float v)
			{
				__instance.minLoudness = v;
			});
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(AnimatedItem), "Start")]
		private static void AnimatedItem_Start_Postfix(AnimatedItem __instance)
		{
			string formattedName = GetFormattedName((Object)(object)((Component)__instance).gameObject);
			GranularSoundControlPlugin.Instance.BindAudioSource(formattedName, __instance.itemAudio);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(RadarBoosterItem), "Start")]
		private static void RadarBoosterItem_Start_Postfix(RadarBoosterItem __instance)
		{
			GranularSoundControlPlugin.Instance.BindAudioSource("RadarBoosterPing", __instance.pingAudio);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(ShipAlarmCord), "Start")]
		private static void ShipAlarmCord_Start_Postfix(ShipAlarmCord __instance)
		{
			GranularSoundControlPlugin.Instance.BindAudioSources("ShipAlarm", __instance.hornClose, __instance.hornFar);
			GranularSoundControlPlugin.Instance.BindAudioSource("ShipAlarmCord", __instance.cordAudio);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(BoomboxItem), "Start")]
		private static void BoomboxItem_Start_Postfix(BoomboxItem __instance)
		{
			GranularSoundControlPlugin.Instance.BindAudioSource("Boombox", __instance.boomboxAudio);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(WalkieTalkie), "Start")]
		private static void WalkieTalkie_Start_Postfix(WalkieTalkie __instance)
		{
			GranularSoundControlPlugin.Instance.BindAudioSource("Walkie-talkie", __instance.thisAudio);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(FlashlightItem), "Start")]
		private static void FlashlightItem_Start_Postfix(FlashlightItem __instance)
		{
			GranularSoundControlPlugin.Instance.BindAudioSource("Flashlight", __instance.flashlightAudio);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(SprayPaintItem), "Start")]
		private static void SprayPaintItem_Start_Postfix(SprayPaintItem __instance)
		{
			GranularSoundControlPlugin.Instance.BindAudioSource("Spraycan", __instance.sprayAudio);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Landmine), "Start")]
		private static void Landmine_Start_Postfix(Landmine __instance)
		{
			GranularSoundControlPlugin.Instance.BindAudioSource("Landmine", __instance.mineAudio);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(SteamValveHazard), "Start")]
		private static void SteamValveHazard_Start_Postfix(SteamValveHazard __instance)
		{
			GranularSoundControlPlugin.Instance.BindAudioSource("SteamLeak", __instance.valveAudio);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(SpikeRoofTrap), "Start")]
		private static void SpikeRoofTrap_Start_Postfix(SpikeRoofTrap __instance)
		{
			GranularSoundControlPlugin.Instance.BindAudioSource("SpikeTrap", __instance.spikeTrapAudio);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Turret), "Start")]
		private static void Turret_Start_Postfix(Turret __instance)
		{
			GranularSoundControlPlugin.Instance.BindAudioSources("Turret", __instance.mainAudio, __instance.berserkAudio, __instance.farAudio);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(VehicleController), "Start")]
		private static void VehicleController_Start_Postfix(VehicleController __instance)
		{
			GranularSoundControlPlugin.Instance.BindAudioSource("Horn", __instance.hornAudio);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(VehicleController), "SetRadioValues")]
		private static void VehicleControllerRadio_Start_Postfix(VehicleController __instance)
		{
			GranularSoundControlPlugin.Instance.BindAudioSources("Radio", __instance.radioAudio, __instance.radioInterference);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(VehicleController), "SetCarEffects")]
		private static void VehicleControllerEngine_Start_Postfix(VehicleController __instance)
		{
			GranularSoundControlPlugin.Instance.BindAudioSources("Skidding", __instance.tireAudio, __instance.skiddingAudio);
			GranularSoundControlPlugin.Instance.BindAudioSources("Engine", __instance.vehicleEngineAudio, __instance.engineAudio1, __instance.engineAudio2);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(JesterAI), "Start")]
		private static void JesterAI_Start_Postfix(JesterAI __instance)
		{
			GranularSoundControlPlugin.Instance.BindAudioSource("Jester", __instance.farAudio);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(SandSpiderAI), "Start")]
		private static void SandSpider_Start_Postfix(SandSpiderAI __instance)
		{
			GranularSoundControlPlugin.Instance.BindAudioSource("Spider", __instance.footstepAudio);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(CentipedeAI), "Start")]
		private static void CentipedeAI_Start_Postfix(CentipedeAI __instance)
		{
			GranularSoundControlPlugin.Instance.BindAudioSource("SnareFlea", __instance.clingingToPlayer2DAudio);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(RadMechAI), "Start")]
		private static void RedMechAI_Start_Postfix(RadMechAI __instance)
		{
			GranularSoundControlPlugin.Instance.BindAudioSources("OldBird", __instance.blowtorchAudio, __instance.explosionAudio, __instance.LocalLRADAudio, __instance.LocalLRADAudio2, __instance.chargeForwardAudio, __instance.flyingDistantAudio, __instance.spotlightOnAudio);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(TVScript), "OnEnable")]
		private static void TVScript_OnEnable_Postfix(TVScript __instance)
		{
			GranularSoundControlPlugin.Instance.BindAudioSource("TV", __instance.tvSFX);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(TVScript), "OnDisable")]
		private static void TVScript_OnDisable_Postfix(TVScript __instance)
		{
			GranularSoundControlPlugin.Instance.RemoveBindings("TV", ((Component)__instance.tvSFX).gameObject);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "OnEnable")]
		private static void StartOfRound_OnEnable_Postfix(StartOfRound __instance)
		{
			GranularSoundControlPlugin.Instance.BindAudioSource("ShipDoor", __instance.shipDoorAudioSource);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "OnDisable")]
		private static void StartOfRound_OnDisable_Postfix(StartOfRound __instance)
		{
			GranularSoundControlPlugin.Instance.RemoveBindings("ShipDoor", ((Component)__instance).gameObject);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StormyWeather), "OnEnable")]
		private static void StormyWeather_OnEnable_Postfix(StormyWeather __instance)
		{
			GranularSoundControlPlugin.Instance.BindAudioSources("Thunder", __instance.randomStrikeAudio, __instance.randomStrikeAudioB, __instance.targetedStrikeAudio);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StormyWeather), "OnDisable")]
		private static void StormyWeather_OnDisable_Postfix(StormyWeather __instance)
		{
			GranularSoundControlPlugin.Instance.RemoveBindings("Thunder", ((Component)__instance).gameObject);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(EnemyAI), "PlayAudioOfCurrentState")]
		private static void EnemyAI_Start_Postfix(EnemyAI __instance)
		{
			CaveDwellerAI val = (CaveDwellerAI)(object)((__instance is CaveDwellerAI) ? __instance : null);
			if (val == null)
			{
				CentipedeAI val2 = (CentipedeAI)(object)((__instance is CentipedeAI) ? __instance : null);
				if (val2 == null)
				{
					SandSpiderAI val3 = (SandSpiderAI)(object)((__instance is SandSpiderAI) ? __instance : null);
					if (val3 != null)
					{
						GranularSoundControlPlugin.Instance.BindAudioSource("Spider", ((EnemyAI)val3).creatureSFX);
					}
				}
				else
				{
					GranularSoundControlPlugin.Instance.BindAudioSource("SnareFlea", ((EnemyAI)val2).creatureSFX);
				}
			}
			else
			{
				GranularSoundControlPlugin.Instance.BindAudioSource("ManeaterScream", val.screamAudio);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GrabbableObject), "Start")]
		private static void GrabbableObject_Start_Postfix(GrabbableObject __instance)
		{
			RemoteProp val = (RemoteProp)(object)((__instance is RemoteProp) ? __instance : null);
			if (val == null)
			{
				JetpackItem val2 = (JetpackItem)(object)((__instance is JetpackItem) ? __instance : null);
				if (val2 == null)
				{
					Shovel val3 = (Shovel)(object)((__instance is Shovel) ? __instance : null);
					if (val3 == null)
					{
						ShotgunItem val4 = (ShotgunItem)(object)((__instance is ShotgunItem) ? __instance : null);
						if (val4 == null)
						{
							KnifeItem val5 = (KnifeItem)(object)((__instance is KnifeItem) ? __instance : null);
							if (val5 == null)
							{
								ClockProp val6 = (ClockProp)(object)((__instance is ClockProp) ? __instance : null);
								if (val6 == null)
								{
									SoccerBallProp val7 = (SoccerBallProp)(object)((__instance is SoccerBallProp) ? __instance : null);
									if (val7 == null)
									{
										WhoopieCushionItem val8 = (WhoopieCushionItem)(object)((__instance is WhoopieCushionItem) ? __instance : null);
										if (val8 == null)
										{
											ExtensionLadderItem val9 = (ExtensionLadderItem)(object)((__instance is ExtensionLadderItem) ? __instance : null);
											if (val9 == null)
											{
												StunGrenadeItem val10 = (StunGrenadeItem)(object)((__instance is StunGrenadeItem) ? __instance : null);
												if (val10 != null)
												{
													string key = (((Object)val10).name.Contains("Egg") ? "EasterEgg" : "StunGrenade");
													GranularSoundControlPlugin.Instance.BindAudioSource(key, val10.itemAudio);
												}
											}
											else
											{
												GranularSoundControlPlugin.Instance.BindAudioSource("ExtensionLadder", val9.ladderAudio);
											}
										}
										else
										{
											GranularSoundControlPlugin.Instance.BindAudioSource("WhoopieCushion", val8.whoopieCushionAudio);
										}
									}
									else
									{
										GranularSoundControlPlugin.Instance.BindAudioSource("SoccerBall", val7.soccerBallAudio);
									}
								}
								else
								{
									GranularSoundControlPlugin.Instance.BindAudioSource("Clock", val6.tickAudio);
								}
							}
							else
							{
								GranularSoundControlPlugin.Instance.BindAudioSource("Knife", val5.knifeAudio);
							}
						}
						else
						{
							GranularSoundControlPlugin.Instance.BindAudioSources("Shotgun", val4.gunShootAudio, val4.gunBulletsRicochetAudio);
						}
					}
					else
					{
						GranularSoundControlPlugin.Instance.BindAudioSource("Shovel", val3.shovelAudio);
					}
				}
				else
				{
					GranularSoundControlPlugin.Instance.BindAudioSource("Jetpack", val2.jetpackAudio);
				}
			}
			else
			{
				GranularSoundControlPlugin.Instance.BindAudioSource("Remote", val.remoteAudio);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(NetworkBehaviour), "OnNetworkSpawn")]
		private static void NetworkBehaviour_OnNetworkSpawn_Postfix(NetworkBehaviour __instance)
		{
			ItemCharger val = (ItemCharger)(object)((__instance is ItemCharger) ? __instance : null);
			if (val != null)
			{
				GranularSoundControlPlugin.Instance.BindAudioSource("ItemCharger", val.zapAudio);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(HUDManager), "OnEnable")]
		private static void HUDManager_OnEnable_Postfix(HUDManager __instance)
		{
			GranularSoundControlPlugin.Instance.BindAudioSource("Scan", __instance.UIAudio);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(HUDManager), "OnDisable")]
		private static void HUDManager_OnDisable_Postfix(HUDManager __instance)
		{
			GranularSoundControlPlugin.Instance.RemoveBindings("Scan", ((Component)__instance.UIAudio).gameObject);
		}
	}
	public class GranularSoundControlConfig
	{
		private readonly Dictionary<string, VolumeConfig> _volumes = new Dictionary<string, VolumeConfig>();

		private readonly ConfigFile _mainCfg;

		public IReadOnlyDictionary<string, VolumeConfig> Volumes => _volumes;

		internal GranularSoundControlConfig(ConfigFile mainCfg)
		{
			_mainCfg = mainCfg;
		}

		private static VolumeConfig CreateVolumeConfig(ConfigFile cfg, string key, string section)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			return new VolumeConfig(key, cfg.Bind<float>(section, key + "Volume", 50f, new ConfigDescription("Volume of " + key, (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())));
		}

		public bool AddVolumeConfig(string key, string section, ConfigFile cfg = null)
		{
			if (_volumes.ContainsKey(key))
			{
				GranularSoundControlPlugin.Instance.Log.LogWarning((object)("Volume config for " + key + " already exists!"));
				return false;
			}
			_volumes[key] = CreateVolumeConfig(cfg ?? _mainCfg, key, section);
			GranularSoundControlPlugin.Instance.Log.LogDebug((object)("Registered " + key));
			return true;
		}

		public bool AddVolumeConfigs(IEnumerable<string> keys, string section, ConfigFile cfg = null)
		{
			return keys.Select((string key) => AddVolumeConfig(key, section, cfg)).All((bool x) => x);
		}
	}
	public class VolumeConfig : IDisposable
	{
		public delegate void ChangedEventHandler(VolumeConfig config, float rawValue, float normalizedValue);

		public struct Binding
		{
			public GameObject GameObject { get; }

			public float BaseVolume { get; }

			public Action<float> Setter { get; }

			public Binding(GameObject gameObject, float baseVolume, Action<float> setter)
			{
				GameObject = gameObject;
				BaseVolume = baseVolume;
				Setter = setter;
			}
		}

		private readonly List<Binding> _bindings = new List<Binding>();

		private bool _isDisposed;

		public ConfigEntry<float> ConfigEntry { get; }

		public float NormalizedValue
		{
			get
			{
				return RawValue / 100f * 2f;
			}
			set
			{
				RawValue = value * 100f / 2f;
			}
		}

		public float RawValue
		{
			get
			{
				return ConfigEntry.Value;
			}
			set
			{
				ConfigEntry.Value = value;
			}
		}

		public string Key { get; }

		public string Section => ((ConfigEntryBase)ConfigEntry).Definition.Section;

		public event ChangedEventHandler OnChanged;

		internal VolumeConfig(string key, ConfigEntry<float> configEntry)
		{
			Key = key;
			ConfigEntry = configEntry;
			ConfigEntry.SettingChanged += SettingChangedEventHandler;
		}

		~VolumeConfig()
		{
			Dispose();
		}

		public void Dispose()
		{
			if (!_isDisposed)
			{
				_isDisposed = true;
				ConfigEntry.SettingChanged -= SettingChangedEventHandler;
			}
		}

		private void SettingChangedEventHandler(object sender, EventArgs e)
		{
			for (int i = 0; i < _bindings.Count; i++)
			{
				Binding binding = _bindings[i];
				if ((Object)(object)binding.GameObject == (Object)null)
				{
					_bindings.RemoveAt(i--);
				}
				else
				{
					ActivateBinding(in binding);
				}
			}
			this.OnChanged?.Invoke(this, RawValue, NormalizedValue);
		}

		public void AddBinding(Binding binding)
		{
			_bindings.Add(binding);
			ActivateBinding(in binding);
		}

		public void RemoveBindings(GameObject gameObject)
		{
			for (int i = 0; i < _bindings.Count; i++)
			{
				if ((Object)(object)_bindings[i].GameObject == (Object)(object)gameObject)
				{
					_bindings.RemoveAt(i--);
				}
			}
		}

		private void ActivateBinding(in Binding binding)
		{
			binding.Setter(NormalizedValue * binding.BaseVolume);
		}
	}
	public static class GranularSoundControlInfo
	{
		public const string Guid = "GranularSoundControl";

		public const string Name = "GranularSoundControl";

		public const string Version = "1.5.2";
	}
	[BepInPlugin("GranularSoundControl", "GranularSoundControl", "1.5.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class GranularSoundControlPlugin : BaseUnityPlugin
	{
		private const string LethalSettingsGuid = "com.willis.lc.lethalsettings";

		private const string LethalConfigGuid = "ainavt.lc.lethalconfig";

		public static GranularSoundControlPlugin Instance { get; private set; }

		internal ManualLogSource Log => ((BaseUnityPlugin)this).Logger;

		internal GranularSoundControlConfig Config { get; private set; }

		private void Awake()
		{
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Config = new GranularSoundControlConfig(((BaseUnityPlugin)this).Config);
			AddConfigs(new string[15]
			{
				"Airhorn", "CashRegister", "Remote", "Dentures", "RobotToy", "Hairdryer", "RubberDucky", "WhoopieCushion", "Clownhorn", "OldPhone",
				"Shotgun", "EasterEgg", "Knife", "Clock", "SoccerBall"
			}, "Scrap");
			AddConfigs(new string[9] { "Boombox", "Flashlight", "Walkie-talkie", "Spraycan", "Jetpack", "RadarBoosterPing", "Shovel", "ExtensionLadder", "StunGrenade" }, "Tools");
			AddConfigs(new string[5] { "Landmine", "Thunder", "Turret", "SteamLeak", "SpikeTrap" }, "Hazards");
			AddConfigs(new string[5] { "Jester", "SnareFlea", "Spider", "OldBird", "ManeaterScream" }, "Entities");
			AddConfigs(new string[4] { "Horn", "Radio", "Skidding", "Engine" }, "Cruiser");
			AddConfigs(new string[6] { "Scan", "ShipAlarm", "ShipAlarmCord", "ItemCharger", "TV", "ShipDoor" }, "Miscellaneous");
			new Harmony("GranularSoundControl").PatchAll(typeof(AudioPatches));
			bool num = Chainloader.PluginInfos.ContainsKey("com.willis.lc.lethalsettings");
			if (num)
			{
				Log.LogInfo((object)"LethalSettings found, initializing UI...");
				LethalSettingsUI.Init();
			}
			bool flag = Chainloader.PluginInfos.ContainsKey("ainavt.lc.lethalconfig");
			if (flag)
			{
				Log.LogInfo((object)"LethalConfig found, initializing UI...");
				LethalConfigUI.Init();
			}
			if (!num && !flag)
			{
				Log.LogWarning((object)"Neither LethalSettings nor LethalConfig found, no UI will be available");
			}
			Log.LogInfo((object)"GranularSoundControl is loaded!");
		}

		internal bool AddConfig(string key, string section, ConfigFile cfg = null)
		{
			return Config.AddVolumeConfig(key, section, cfg);
		}

		internal bool AddConfigs(IEnumerable<string> keys, string section, ConfigFile cfg = null)
		{
			return Config.AddVolumeConfigs(keys, section, cfg);
		}

		internal bool TryGetConfig(string key, out VolumeConfig config)
		{
			return Config.Volumes.TryGetValue(key, out config);
		}

		internal bool Bind(string key, GameObject gameObject, float baseVolume, Action<float> volumeSetter)
		{
			if (!TryGetConfig(key, out var config))
			{
				Log.LogWarning((object)("Trying to bind volume config for " + key + ", but it doesn't exist"));
				return false;
			}
			config.AddBinding(new VolumeConfig.Binding(gameObject, baseVolume, volumeSetter));
			return true;
		}

		internal bool BindAudioSource(string key, AudioSource audioSource)
		{
			return Bind(key, ((Component)audioSource).gameObject, audioSource.volume, delegate(float v)
			{
				audioSource.volume = v;
			});
		}

		internal bool BindAudioSources(string key, params AudioSource[] audioSources)
		{
			return audioSources.All((AudioSource audioSource) => BindAudioSource(key, audioSource));
		}

		internal bool RemoveBindings(string key, GameObject gameObject)
		{
			if (!TryGetConfig(key, out var config))
			{
				Log.LogWarning((object)("Trying to remove volume config bindings for " + key + ", but it doesn't exist"));
				return false;
			}
			config.RemoveBindings(gameObject);
			return true;
		}
	}
	internal static class LethalConfigUI
	{
		internal static void Init()
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			//IL_0098: Expected O, but got Unknown
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected O, but got Unknown
			LethalConfigManager.SkipAutoGen();
			LethalConfigManager.SetModDescription("Volume control for various sounds in the game.");
			foreach (KeyValuePair<string, VolumeConfig> item in GranularSoundControlPlugin.Instance.Config.Volumes.OrderBy((KeyValuePair<string, VolumeConfig> kvp) => kvp.Key))
			{
				item.Deconstruct(out var _, out var value);
				VolumeConfig volumeConfig = value;
				ConfigEntry<float> configEntry = volumeConfig.ConfigEntry;
				FloatStepSliderOptions val = new FloatStepSliderOptions
				{
					Name = SharedUI.GetDisplayName(volumeConfig),
					RequiresRestart = false
				};
				((BaseRangeOptions<float>)val).Min = 0f;
				((BaseRangeOptions<float>)val).Max = 100f;
				LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatSliderConfigItem(configEntry, (FloatSliderOptions)val));
			}
		}
	}
	internal static class LethalSettingsUI
	{
		internal static void Init()
		{
			//IL_004c: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected O, but got Unknown
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: 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_0092: Expected O, but got Unknown
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Expected O, but got Unknown
			SliderComponent[] _sliders = null;
			Dictionary<SliderComponent, string> _sliderToConfigKey = new Dictionary<SliderComponent, string>();
			GranularSoundControlConfig config2 = GranularSoundControlPlugin.Instance.Config;
			_sliders = ((IEnumerable<KeyValuePair<string, VolumeConfig>>)config2.Volumes).Select((Func<KeyValuePair<string, VolumeConfig>, SliderComponent>)delegate(KeyValuePair<string, VolumeConfig> kvp)
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: Expected O, but got Unknown
				kvp.Value.OnChanged += OnConfigChangedHandler;
				return new SliderComponent
				{
					MinValue = 0f,
					MaxValue = 100f,
					OnValueChanged = OnSliderValueChanged
				};
			}).ToArray();
			RefreshOrder();
			ButtonComponent item = new ButtonComponent
			{
				Text = "Reset",
				OnClick = OnResetClicked
			};
			InputComponent item2 = new InputComponent
			{
				Placeholder = "Search...",
				OnValueChanged = delegate(InputComponent _, string text)
				{
					RefreshOrder(text);
				}
			};
			List<MenuComponent> list = new List<MenuComponent>
			{
				(MenuComponent)(object)item,
				(MenuComponent)(object)item2
			};
			list.AddRange((IEnumerable<MenuComponent>)(object)_sliders);
			ModMenu.RegisterMod(new ModSettingsConfig
			{
				Name = "GranularSoundControl",
				Id = "GranularSoundControl",
				Version = "1.5.2",
				Description = "Volume control for various sounds in the game.",
				MenuComponents = list.ToArray()
			}, true, true);
			void OnConfigChangedHandler(VolumeConfig config, float rawValue, float normalizedValue)
			{
				SliderComponent val2 = ((IEnumerable<SliderComponent>)_sliders).FirstOrDefault((Func<SliderComponent, bool>)((SliderComponent s) => _sliderToConfigKey[s] == config.Key));
				if (val2 != null && !Mathf.Approximately(val2.Value, rawValue))
				{
					val2.Value = rawValue;
				}
			}
			static void OnResetClicked(ButtonComponent instance)
			{
				SharedUI.ResetAllVolumes();
			}
			void OnSliderValueChanged(SliderComponent slider, float value)
			{
				if (_sliderToConfigKey.TryGetValue(slider, out var value2) && GranularSoundControlPlugin.Instance.TryGetConfig(value2, out var config4))
				{
					config4.RawValue = value;
				}
			}
			void RefreshOrder(string searchTerm = null)
			{
				GranularSoundControlConfig config3 = GranularSoundControlPlugin.Instance.Config;
				IEnumerable<string> enumerable;
				if (searchTerm == null)
				{
					enumerable = config3.Volumes.Keys.OrderBy((string k) => k);
				}
				else
				{
					string lowerSearchTerm = searchTerm.ToLower();
					enumerable = config3.Volumes.Keys.OrderBy((string k) => (!k.ToLower().Contains(lowerSearchTerm)) ? 1 : 0);
				}
				_sliderToConfigKey.Clear();
				int num = 0;
				foreach (string item3 in enumerable)
				{
					SliderComponent val = _sliders[num++];
					VolumeConfig volumeConfig = config3.Volumes[item3];
					val.Text = SharedUI.GetDisplayName(volumeConfig);
					val.Value = volumeConfig.RawValue;
					_sliderToConfigKey[val] = item3;
				}
			}
		}
	}
	public static class SharedUI
	{
		public const string Name = "GranularSoundControl";

		public const string Guid = "GranularSoundControl";

		public const string Version = "1.5.2";

		public const string Description = "Volume control for various sounds in the game.";

		private static readonly Regex _nicifyRegex = new Regex("(?<=[a-z])([A-Z])", RegexOptions.Compiled);

		public static string GetDisplayName(VolumeConfig volumeConfig)
		{
			string text = _nicifyRegex.Replace(volumeConfig.Key, " $1");
			if (volumeConfig.Section != "Vanilla")
			{
				text = text + " (" + volumeConfig.Section + ")";
			}
			return text;
		}

		public static void ResetAllVolumes()
		{
			foreach (VolumeConfig value in GranularSoundControlPlugin.Instance.Config.Volumes.Values)
			{
				value.NormalizedValue = 1f;
			}
		}
	}
}