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.Configuration;
using BepInEx.Logging;
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: AssemblyCompany("LCMaxSoundsFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Simple mod that increase max number of simultaneous playing sounds, hopefully fixing missing footsteps and other missing sound problems.")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0+9a4b27ad682db1b4d7bf4f4f8177235f287bb642")]
[assembly: AssemblyProduct("LCMaxSoundsFix")]
[assembly: AssemblyTitle("LCMaxSoundsFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.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 LCMaxSoundFix
{
public class AcceptableValueListSorted<T> : AcceptableValueList<T> where T : IEquatable<T>, IComparable<T>
{
public AcceptableValueListSorted(params T[] acceptableValues)
: base(acceptableValues)
{
Array.Sort(((AcceptableValueList<T>)this).AcceptableValues);
}
public override object Clamp(object value)
{
if (value is IComparable<T>)
{
int num = 0;
T other = (T)value;
for (int i = 0; i < ((AcceptableValueList<T>)this).AcceptableValues.Length; i++)
{
int num2 = ((AcceptableValueList<T>)this).AcceptableValues[i].CompareTo(other);
if (num2 == 0)
{
num = i;
break;
}
if (num2 < 0)
{
num = i;
}
else if (num2 > 0)
{
if (i == 0)
{
num = i;
}
else if (typeof(T) == typeof(int))
{
int num3 = Math.Abs(Convert.ToInt32(((AcceptableValueList<T>)this).AcceptableValues[i]) - (int)value);
int num4 = Math.Abs(Convert.ToInt32(((AcceptableValueList<T>)this).AcceptableValues[i - 1]) - (int)value);
num = ((num3 < num4) ? i : (i - 1));
}
break;
}
}
return ((AcceptableValueList<T>)this).AcceptableValues[num];
}
return base.Clamp(value);
}
}
internal static class AudioConfig
{
private static ConfigEntry<int> _numRealVoices = null;
private static ConfigEntry<int> _numVirtualVoices = null;
private static readonly int[] _validNumVoices = new int[13]
{
1, 2, 4, 8, 16, 32, 50, 64, 100, 128,
256, 512, 1024
};
public static void Bind(BaseUnityPlugin plugin)
{
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Expected O, but got Unknown
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Expected O, but got Unknown
if (plugin == null)
{
throw new ArgumentNullException("plugin");
}
Unbind();
_numRealVoices = plugin.Config.Bind<int>("Audio Settings", "Real Voices", 128, new ConfigDescription("The current maximum number of simultaneously audible sounds in the game. Game default: 40", (AcceptableValueBase)(object)new AcceptableValueListSorted<int>(_validNumVoices), Array.Empty<object>()));
_numVirtualVoices = plugin.Config.Bind<int>("Audio Settings", "Virtual Voices", 1024, new ConfigDescription("The maximum number of managed sounds in the game. Beyond this limit sounds will simply stop playing. Game default: 512", (AcceptableValueBase)(object)new AcceptableValueListSorted<int>(_validNumVoices), Array.Empty<object>()));
_numRealVoices.SettingChanged += OnSettingChanged;
_numVirtualVoices.SettingChanged += OnSettingChanged;
ApplyChanges();
}
public static void Unbind()
{
if (_numRealVoices != null)
{
_numRealVoices.SettingChanged -= OnSettingChanged;
((ConfigEntryBase)_numRealVoices).ConfigFile.Remove(((ConfigEntryBase)_numRealVoices).Definition);
_numRealVoices = null;
}
if (_numVirtualVoices != null)
{
_numVirtualVoices.SettingChanged -= OnSettingChanged;
((ConfigEntryBase)_numVirtualVoices).ConfigFile.Remove(((ConfigEntryBase)_numVirtualVoices).Definition);
_numVirtualVoices = null;
}
}
private static void OnSettingChanged(object sender, EventArgs e)
{
ApplyChanges();
}
private static void ApplyChanges()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
ManualLogSource logger = Plugin.Logger;
if (logger != null)
{
logger.LogDebug((object)"Applying audio settings...");
}
AudioConfiguration configuration = AudioSettings.GetConfiguration();
configuration.numRealVoices = _numRealVoices.Value;
configuration.numVirtualVoices = _numVirtualVoices.Value;
AudioSettings.Reset(configuration);
ManualLogSource logger2 = Plugin.Logger;
if (logger2 != null)
{
logger2.LogInfo((object)$"Audio settings (numRealVoices={_numRealVoices.Value}; numVirtualVoices={_numVirtualVoices.Value}) are applied.");
}
}
}
[BepInPlugin(".LCMaxSoundsFix", "LCMaxSoundsFix", "1.2.0")]
internal class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Logger { get; private set; }
protected Plugin()
{
Logger = ((BaseUnityPlugin)this).Logger;
}
protected void Awake()
{
ManualLogSource logger = Logger;
if (logger != null)
{
logger.LogInfo((object)"Plugin LCMaxSoundsFix is loaded!");
}
ManualLogSource logger2 = Logger;
if (logger2 != null)
{
logger2.LogDebug((object)"Binding audio config...");
}
AudioConfig.Bind((BaseUnityPlugin)(object)this);
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "LCMaxSoundsFix";
public const string PLUGIN_NAME = "LCMaxSoundsFix";
public const string PLUGIN_VERSION = "1.2.0";
}
}