Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of GranularSoundControl v1.6.0
GranularSoundControl.dll
Decompiled a year agousing 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.6.0.0")] [assembly: AssemblyInformationalVersion("1.6.0+da44967978db2de1d30326e009cbadb0b82514f2")] [assembly: AssemblyProduct("GranularSoundControl")] [assembly: AssemblyTitle("GranularSoundControl")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.6.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.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 KeepItDown { 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); KeepItDownPlugin.Instance.Bind(formattedName, gameObject, __instance.maxLoudness, delegate(float v) { __instance.maxLoudness = v; }); KeepItDownPlugin.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); KeepItDownPlugin.Instance.BindAudioSource(formattedName, __instance.itemAudio); } [HarmonyPostfix] [HarmonyPatch(typeof(ShipAlarmCord), "HoldCordDown")] private static void ShipAlarmCord_HoldCordDown_Postfix(ShipAlarmCord __instance) { KeepItDownPlugin.Instance.BindAudioSourcesClampRange("LoudHorn", __instance.hornClose, __instance.hornFar); } [HarmonyPostfix] [HarmonyPatch(typeof(Landmine), "Start")] private static void Landmine_Start_Postfix(Landmine __instance) { KeepItDownPlugin.Instance.BindAudioSource("Landmine", __instance.mineAudio); } [HarmonyPostfix] [HarmonyPatch(typeof(SteamValveHazard), "Start")] private static void SteamValveHazard_Start_Postfix(SteamValveHazard __instance) { KeepItDownPlugin.Instance.BindAudioSource("SteamLeak", __instance.valveAudio); } [HarmonyPostfix] [HarmonyPatch(typeof(SpikeRoofTrap), "Start")] private static void SpikeRoofTrap_Start_Postfix(SpikeRoofTrap __instance) { KeepItDownPlugin.Instance.BindAudioSource("SpikeTrap", __instance.spikeTrapAudio); } [HarmonyPostfix] [HarmonyPatch(typeof(Turret), "SetTargetToPlayerBody")] private static void Turret_SetTargetToPlayerBody_Postfix(Turret __instance) { KeepItDownPlugin.Instance.BindAudioSources("Turret", __instance.mainAudio, __instance.berserkAudio, __instance.farAudio, __instance.bulletCollisionAudio); } [HarmonyPostfix] [HarmonyPatch(typeof(VehicleController), "Start")] private static void VehicleController_Start_Postfix(VehicleController __instance) { KeepItDownPlugin.Instance.BindAudioSource("Horn", __instance.hornAudio); } [HarmonyPostfix] [HarmonyPatch(typeof(VehicleController), "SetRadioValues")] private static void VehicleController_SetRadioValues_Postfix(VehicleController __instance) { KeepItDownPlugin.Instance.BindAudioSourcesClampRange("Radio", __instance.radioAudio, __instance.radioInterference); } [HarmonyPostfix] [HarmonyPatch(typeof(VehicleController), "SetCarEffects")] private static void VehicleController_SetCarEffects_Postfix(VehicleController __instance) { KeepItDownPlugin.Instance.BindAudioSources("Skidding", __instance.tireAudio, __instance.rollingAudio, __instance.skiddingAudio); KeepItDownPlugin.Instance.BindAudioSources("Engine", __instance.vehicleEngineAudio, __instance.engineAudio1, __instance.engineAudio2); } [HarmonyPostfix] [HarmonyPatch(typeof(NutcrackerEnemyAI), "TurnTorsoToTargetDegrees")] private static void NutcrackerEnemyAI_TurnTorsoToTargetDegrees_Postfix(NutcrackerEnemyAI __instance) { KeepItDownPlugin.Instance.BindAudioSourceClampRange("Nutcracker", __instance.torsoTurnAudio); } [HarmonyPostfix] [HarmonyPatch(typeof(NutcrackerEnemyAI), "StartInspectionTurn")] private static void NutcrackerEnemyAI_StartInspectionTurn_Postfix(NutcrackerEnemyAI __instance) { KeepItDownPlugin.Instance.BindAudioSourceClampRange("Nutcracker", __instance.longRangeAudio); } [HarmonyPostfix] [HarmonyPatch(typeof(RadMechAI), "MoveTowardsThreat")] private static void RedMechAI_MoveTowardsThreat_Postfix(RadMechAI __instance) { KeepItDownPlugin.Instance.BindAudioSources("OldBird", __instance.chargeForwardAudio); } [HarmonyPostfix] [HarmonyPatch(typeof(ClaySurgeonAI), "SetMusicVolume")] private static void ClaySurgeonAI_SetMusicVolume_Postfix(ClaySurgeonAI __instance) { KeepItDownPlugin.Instance.BindAudioSource("Barber", __instance.musicAudio2); } [HarmonyPostfix] [HarmonyPatch(typeof(StartOfRound), "Start")] private static void StartOfRound_Start_Postfix(StartOfRound __instance) { KeepItDownPlugin.Instance.BindAudioSource("CompanySpeaker", __instance.speakerAudioSource); KeepItDownPlugin.Instance.BindAudioSource("ShipDoor", __instance.shipDoorAudioSource); } [HarmonyPostfix] [HarmonyPatch(typeof(TVScript), "OnEnable")] private static void TVScript_OnEnable_Postfix(TVScript __instance) { KeepItDownPlugin.Instance.BindAudioSource("TV", __instance.tvSFX); } [HarmonyPostfix] [HarmonyPatch(typeof(TVScript), "OnDisable")] private static void TVScript_OnDisable_Postfix(TVScript __instance) { KeepItDownPlugin.Instance.RemoveBindings("TV", ((Component)__instance.tvSFX).gameObject); } [HarmonyPostfix] [HarmonyPatch(typeof(StormyWeather), "OnEnable")] private static void StormyWeather_OnEnable_Postfix(StormyWeather __instance) { KeepItDownPlugin.Instance.BindAudioSources("Thunder", __instance.randomStrikeAudio, __instance.randomStrikeAudioB, __instance.targetedStrikeAudio); } [HarmonyPostfix] [HarmonyPatch(typeof(StormyWeather), "OnDisable")] private static void StormyWeather_OnDisable_Postfix(StormyWeather __instance) { KeepItDownPlugin.Instance.RemoveBindings("Thunder", ((Component)__instance).gameObject); } [HarmonyPostfix] [HarmonyPatch(typeof(EnemyAI), "Start")] private static void EnemyAI_Start_Postfix(EnemyAI __instance) { JesterAI val = (JesterAI)(object)((__instance is JesterAI) ? __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) { CrawlerAI val4 = (CrawlerAI)(object)((__instance is CrawlerAI) ? __instance : null); if (val4 == null) { MouthDogAI val5 = (MouthDogAI)(object)((__instance is MouthDogAI) ? __instance : null); if (val5 == null) { SpringManAI val6 = (SpringManAI)(object)((__instance is SpringManAI) ? __instance : null); if (val6 == null) { DressGirlAI val7 = (DressGirlAI)(object)((__instance is DressGirlAI) ? __instance : null); if (val7 == null) { NutcrackerEnemyAI val8 = (NutcrackerEnemyAI)(object)((__instance is NutcrackerEnemyAI) ? __instance : null); if (val8 == null) { PufferAI val9 = (PufferAI)(object)((__instance is PufferAI) ? __instance : null); if (val9 == null) { HoarderBugAI val10 = (HoarderBugAI)(object)((__instance is HoarderBugAI) ? __instance : null); if (val10 == null) { RadMechAI val11 = (RadMechAI)(object)((__instance is RadMechAI) ? __instance : null); if (val11 == null) { CaveDwellerAI val12 = (CaveDwellerAI)(object)((__instance is CaveDwellerAI) ? __instance : null); if (val12 == null) { ClaySurgeonAI val13 = (ClaySurgeonAI)(object)((__instance is ClaySurgeonAI) ? __instance : null); if (val13 != null) { KeepItDownPlugin.Instance.BindAudioSources("Barber", val13.musicAudio, ((EnemyAI)val13).creatureSFX); } } else { KeepItDownPlugin.Instance.BindAudioSources("ManeaterScream", val12.screamAudio, ((EnemyAI)val12).creatureSFX, ((EnemyAI)val12).creatureVoice); } } else { KeepItDownPlugin.Instance.BindAudioSources("OldBird", val11.blowtorchAudio, val11.explosionAudio, val11.LocalLRADAudio, val11.LocalLRADAudio2, val11.spotlightOnAudio, val11.engineSFX, ((EnemyAI)val11).creatureSFX, ((EnemyAI)val11).creatureVoice); } } else { KeepItDownPlugin.Instance.BindAudioSources("HoardingBug", ((EnemyAI)val10).creatureSFX, ((EnemyAI)val10).creatureVoice); } } else { KeepItDownPlugin.Instance.BindAudioSources("SporeLizard", ((EnemyAI)val9).creatureSFX, ((EnemyAI)val9).creatureVoice); } } else { KeepItDownPlugin.Instance.BindAudioSources("Nutcracker", ((EnemyAI)val8).creatureSFX, ((EnemyAI)val8).creatureVoice); } } else { KeepItDownPlugin.Instance.BindAudioSource("GhostGirl", ((EnemyAI)val7).creatureVoice); } } else { KeepItDownPlugin.Instance.BindAudioSource("CoilHead", ((EnemyAI)val6).creatureVoice); } } else { KeepItDownPlugin.Instance.BindAudioSources("EyelessDog", ((EnemyAI)val5).creatureSFX, ((EnemyAI)val5).creatureVoice); } } else { KeepItDownPlugin.Instance.BindAudioSources("Thumper", ((EnemyAI)val4).creatureSFX, ((EnemyAI)val4).creatureVoice); } } else { KeepItDownPlugin.Instance.BindAudioSources("Spider", val3.footstepAudio, ((EnemyAI)val3).creatureSFX, ((EnemyAI)val3).creatureVoice); } } else { KeepItDownPlugin.Instance.BindAudioSources("SnareFlea", val2.clingingToPlayer2DAudio, ((EnemyAI)val2).creatureSFX, ((EnemyAI)val2).creatureVoice); } } else { KeepItDownPlugin.Instance.BindAudioSources("Jester", val.farAudio, ((EnemyAI)val).creatureSFX, ((EnemyAI)val).creatureVoice); } } [HarmonyPostfix] [HarmonyPatch(typeof(GrabbableObject), "Start")] private static void GrabbableObject_Start_Postfix(GrabbableObject __instance) { BoomboxItem val = (BoomboxItem)(object)((__instance is BoomboxItem) ? __instance : null); if (val == null) { WalkieTalkie val2 = (WalkieTalkie)(object)((__instance is WalkieTalkie) ? __instance : null); if (val2 == null) { SprayPaintItem val3 = (SprayPaintItem)(object)((__instance is SprayPaintItem) ? __instance : null); if (val3 == null) { JetpackItem val4 = (JetpackItem)(object)((__instance is JetpackItem) ? __instance : null); if (val4 == null) { Shovel val5 = (Shovel)(object)((__instance is Shovel) ? __instance : null); if (val5 == null) { StunGrenadeItem val6 = (StunGrenadeItem)(object)((__instance is StunGrenadeItem) ? __instance : null); if (val6 == null) { WhoopieCushionItem val7 = (WhoopieCushionItem)(object)((__instance is WhoopieCushionItem) ? __instance : null); if (val7 == null) { ShotgunItem val8 = (ShotgunItem)(object)((__instance is ShotgunItem) ? __instance : null); if (val8 == null) { KnifeItem val9 = (KnifeItem)(object)((__instance is KnifeItem) ? __instance : null); if (val9 == null) { SoccerBallProp val10 = (SoccerBallProp)(object)((__instance is SoccerBallProp) ? __instance : null); if (val10 == null) { ClockProp val11 = (ClockProp)(object)((__instance is ClockProp) ? __instance : null); if (val11 != null) { KeepItDownPlugin.Instance.BindAudioSource("Clock", val11.tickAudio); } } else { KeepItDownPlugin.Instance.BindAudioSource("SoccerBall", val10.soccerBallAudio); } } else { KeepItDownPlugin.Instance.BindAudioSource("Knife", val9.knifeAudio); } } else { KeepItDownPlugin.Instance.BindAudioSources("Shotgun", val8.gunShootAudio, val8.gunBulletsRicochetAudio); } } else { KeepItDownPlugin.Instance.BindAudioSource("WhoopieCushion", val7.whoopieCushionAudio); } } else { string key = (((Object)val6).name.Contains("Egg") ? "EasterEgg" : "StunGrenade"); KeepItDownPlugin.Instance.BindAudioSource(key, val6.itemAudio); } } else { KeepItDownPlugin.Instance.BindAudioSource("Shovel", val5.shovelAudio); } } else { KeepItDownPlugin.Instance.BindAudioSources("Jetpack", val4.jetpackAudio, val4.jetpackBeepsAudio); } } else { KeepItDownPlugin.Instance.BindAudioSource("Spraycan", val3.sprayAudio); } } else { KeepItDownPlugin.Instance.BindAudioSource("Walkie-talkie", val2.target); } } else { KeepItDownPlugin.Instance.BindAudioSource("Boombox", val.boomboxAudio); } } [HarmonyPostfix] [HarmonyPatch(typeof(ExtensionLadderItem), "StartLadderAnimation")] private static void ExtensionLadderItem_StartLadderAnimation_Postfix(ExtensionLadderItem __instance) { KeepItDownPlugin.Instance.BindAudioSource("ExtensionLadder", __instance.ladderAudio); } [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) { KeepItDownPlugin.Instance.BindAudioSource("ItemCharger", val.zapAudio); } } [HarmonyPostfix] [HarmonyPatch(typeof(HUDManager), "OnEnable")] private static void HUDManager_OnEnable_Postfix(HUDManager __instance) { KeepItDownPlugin.Instance.BindAudioSource("Scan", __instance.UIAudio); } [HarmonyPostfix] [HarmonyPatch(typeof(HUDManager), "OnDisable")] private static void HUDManager_OnDisable_Postfix(HUDManager __instance) { KeepItDownPlugin.Instance.RemoveBindings("Scan", ((Component)__instance.UIAudio).gameObject); } } public class KeepItDownConfig { private readonly Dictionary<string, VolumeConfig> _volumes = new Dictionary<string, VolumeConfig>(); private readonly ConfigFile _mainCfg; public IReadOnlyDictionary<string, VolumeConfig> Volumes => _volumes; internal KeepItDownConfig(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)) { KeepItDownPlugin.Instance.Log.LogWarning((object)("Volume config for " + key + " already exists!")); return false; } _volumes[key] = CreateVolumeConfig(cfg ?? _mainCfg, key, section); KeepItDownPlugin.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 KeepItDownInfo { public const string Guid = "GranularSoundControl"; public const string Name = "GranularSoundControl"; public const string Version = "1.6.0"; } [BepInPlugin("GranularSoundControl", "GranularSoundControl", "1.6.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class KeepItDownPlugin : BaseUnityPlugin { private const string LethalSettingsGuid = "com.willis.lc.lethalsettings"; private const string LethalConfigGuid = "ainavt.lc.lethalconfig"; public static KeepItDownPlugin Instance { get; private set; } internal ManualLogSource Log => ((BaseUnityPlugin)this).Logger; internal KeepItDownConfig Config { get; private set; } private void Awake() { //IL_020f: Unknown result type (might be due to invalid IL or missing references) Instance = this; Config = new KeepItDownConfig(((BaseUnityPlugin)this).Config); AddConfigs(new string[12] { "Airhorn", "CashRegister", "Dentures", "RobotToy", "Hairdryer", "WhoopieCushion", "Clownhorn", "Shotgun", "EasterEgg", "Knife", "Clock", "SoccerBall" }, "Scrap"); AddConfigs(new string[7] { "Boombox", "Walkie-talkie", "Spraycan", "Jetpack", "Shovel", "ExtensionLadder", "StunGrenade" }, "Tools"); AddConfigs(new string[5] { "Landmine", "Thunder", "Turret", "SteamLeak", "SpikeTrap" }, "Hazards"); AddConfigs(new string[13] { "Jester", "SnareFlea", "Spider", "CoilHead", "SporeLizard", "HoardingBug", "Thumper", "EyelessDog", "GhostGirl", "Nutcracker", "OldBird", "ManeaterScream", "Barber" }, "Entities"); AddConfigs(new string[4] { "Horn", "Radio", "Skidding", "Engine" }, "Cruiser"); AddConfigs(new string[6] { "Scan", "LoudHorn", "ItemCharger", "TV", "ShipDoor", "CompanySpeaker" }, "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 BindAudioSourceClampRange(string key, AudioSource audioSource) { GameObject gameObject = ((Component)audioSource).gameObject; float baseVolume = (audioSource.minDistance = 0.4f); return Bind(key, gameObject, baseVolume, delegate(float v) { audioSource.volume = v; }); } internal bool BindAudioSources(string key, params AudioSource[] audioSources) { return audioSources.All((AudioSource audioSource) => BindAudioSource(key, audioSource)); } internal bool BindAudioSourcesClampRange(string key, params AudioSource[] audioSources) { return audioSources.All((AudioSource audioSource) => BindAudioSourceClampRange(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 KeepItDownPlugin.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>(); KeepItDownConfig config2 = KeepItDownPlugin.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.6.0", 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) && KeepItDownPlugin.Instance.TryGetConfig(value2, out var config4)) { config4.RawValue = value; } } void RefreshOrder(string searchTerm = null) { KeepItDownConfig config3 = KeepItDownPlugin.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.6.0"; 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 KeepItDownPlugin.Instance.Config.Volumes.Values) { value.NormalizedValue = 1f; } } } }