Decompiled source of SimpleAudioOptions v1.0.2

SimpleAudioOptions.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("SimpleAudioOptions")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Azumatt")]
[assembly: AssemblyProduct("SimpleAudioOptions")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4358610B-F3F4-4843-B7AF-98B7BC60DCDE")]
[assembly: AssemblyFileVersion("1.0.2")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.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.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;
		}
	}
}
namespace SimpleAudioOptions
{
	[BepInPlugin("Azumatt.SimpleAudioOptions", "SimpleAudioOptions", "1.0.2")]
	public class SimpleAudioOptionsPlugin : BaseUnityPlugin
	{
		public enum CustomAudioSpeakerMode
		{
			Mono = 1,
			Stereo,
			Quad,
			Surround,
			Mode5point1,
			Mode7point1,
			Prologic
		}

		private enum Toggle
		{
			Off,
			On
		}

		private class ConfigurationManagerAttributes
		{
			[UsedImplicitly]
			public int? Order;

			[UsedImplicitly]
			public bool? Browsable;

			[UsedImplicitly]
			public string? Category;

			[UsedImplicitly]
			public Action<ConfigEntryBase>? CustomDrawer;
		}

		internal const string ModName = "SimpleAudioOptions";

		internal const string ModVersion = "1.0.2";

		internal const string Author = "Azumatt";

		private const string ModGUID = "Azumatt.SimpleAudioOptions";

		private static string ConfigFileName = "Azumatt.SimpleAudioOptions.cfg";

		private static string ConfigFileFullPath;

		internal static SimpleAudioOptionsPlugin context;

		private readonly Harmony _harmony = new Harmony("Azumatt.SimpleAudioOptions");

		public static readonly ManualLogSource SimpleAudioOptionsLogger;

		private static ConfigEntry<Toggle> EnableModControl;

		private static ConfigEntry<CustomAudioSpeakerMode> SpeakerMode;

		private static ConfigEntry<int> DspBufferSize;

		private static ConfigEntry<int> SampleRate;

		public void Awake()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Expected O, but got Unknown
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Expected O, but got Unknown
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: 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)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			context = this;
			EnableModControl = config("1 - General", "Enable Mod Control", Toggle.On, new ConfigDescription("Enable the mod's control over audio settings. If disabled, the game's defaults will be used.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 3
				}
			}));
			SpeakerMode = config("1 - General", "Speaker Mode", CustomAudioSpeakerMode.Stereo, new ConfigDescription("The speaker mode to use for the game. This will be applied on game start. Changing this value live can result in audio issues, but it is possible to change it live.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 2
				}
			}));
			DspBufferSize = config("1 - General", "DSP Buffer Size", 1024, new ConfigDescription("The size of the digital signal processing buffer.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 1
				}
			}));
			SampleRate = config("1 - General", "Sample Rate", 44100, new ConfigDescription("The audio system sample rate.", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 0
				}
			}));
			if (EnableModControl.Value == Toggle.On)
			{
				AudioConfiguration configuration = AudioSettings.GetConfiguration();
				configuration.speakerMode = (AudioSpeakerMode)SpeakerMode.Value;
				configuration.dspBufferSize = DspBufferSize.Value;
				configuration.sampleRate = SampleRate.Value;
				AudioSettings.Reset(configuration);
			}
			SpeakerMode.SettingChanged += UpdateAudioSettings;
			DspBufferSize.SettingChanged += UpdateAudioSettings;
			SampleRate.SettingChanged += UpdateAudioSettings;
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			_harmony.PatchAll(executingAssembly);
			SetupWatcher();
			Utilities.AutoDoc();
		}

		private void OnDestroy()
		{
			((BaseUnityPlugin)this).Config.Save();
		}

		private void SetupWatcher()
		{
			FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, ConfigFileName);
			fileSystemWatcher.Changed += ReadConfigValues;
			fileSystemWatcher.Created += ReadConfigValues;
			fileSystemWatcher.Renamed += ReadConfigValues;
			fileSystemWatcher.IncludeSubdirectories = true;
			fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
			fileSystemWatcher.EnableRaisingEvents = true;
		}

		private void ReadConfigValues(object sender, FileSystemEventArgs e)
		{
			if (!File.Exists(ConfigFileFullPath))
			{
				return;
			}
			try
			{
				SimpleAudioOptionsLogger.LogDebug((object)"ReadConfigValues called");
				((BaseUnityPlugin)this).Config.Reload();
			}
			catch
			{
				SimpleAudioOptionsLogger.LogError((object)("There was an issue loading your " + ConfigFileName));
				SimpleAudioOptionsLogger.LogError((object)"Please check your config entries for spelling and format!");
			}
		}

		private void UpdateAudioSettings(object sender, EventArgs e)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			if (EnableModControl.Value == Toggle.On)
			{
				AudioConfiguration configuration = AudioSettings.GetConfiguration();
				configuration.speakerMode = (AudioSpeakerMode)SpeakerMode.Value;
				configuration.dspBufferSize = DspBufferSize.Value;
				configuration.sampleRate = SampleRate.Value;
				AudioSettings.Reset(configuration);
				((BaseUnityPlugin)this).Config.Save();
			}
		}

		private ConfigEntry<T> config<T>(string group, string name, T value, ConfigDescription description)
		{
			return ((BaseUnityPlugin)this).Config.Bind<T>(group, name, value, description);
		}

		private ConfigEntry<T> config<T>(string group, string name, T value, string description)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			return config(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()));
		}

		static SimpleAudioOptionsPlugin()
		{
			string configPath = Paths.ConfigPath;
			char directorySeparatorChar = Path.DirectorySeparatorChar;
			ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName;
			context = null;
			SimpleAudioOptionsLogger = Logger.CreateLogSource("SimpleAudioOptions");
			EnableModControl = null;
			SpeakerMode = null;
			DspBufferSize = null;
			SampleRate = null;
		}
	}
	public class Utilities
	{
		internal static void AutoDoc()
		{
		}
	}
}