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("SoundsLimitFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Fix the Sound Limit, to hear a multiple sounds properly.")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0+9a4b27ad682db1b4d7bf4f4f8177235f287bb642")]
[assembly: AssemblyProduct("SoundsLimitFix")]
[assembly: AssemblyTitle("SoundsLimitFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.0.0")]
[module: UnverifiableCode]
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 SoundsLimitFix
{
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 maximum number of actually activated sounds that players can hear(these sounds are mixing targets).\nHigher value means, you can hear more sounds, but CPU load increases.\nLower value means, you can hear important sounds first. but some sounds can be cut, it can lower your immersion\n128 is the lowest recommended value", (AcceptableValueBase)(object)new AcceptableValueListSorted<int>(_validNumVoices), Array.Empty<object>()));
_numVirtualVoices = plugin.Config.Bind<int>("Audio Settings", "Virtual Voices", 512, new ConfigDescription("The maximum number of sound instances loaded into memory.\nHigher value means more sounds can be played at the same time. but memory usage can be increased.\nLower value means some sounds can be lost\n512 is the lowest recommended value.\nIf you have a lot of players or unit, set this value higher", (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(".SoundsLimitFix", "SoundsLimitFix", "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 SoundsLimitFix 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 = "SoundsLimitFix";
public const string PLUGIN_NAME = "SoundsLimitFix";
public const string PLUGIN_VERSION = "1.2.0";
}
}