Decompiled source of MoreSounds v1.1.0

BepInEx/plugins/ViViKo.MoreSounds.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("ViViKo.MoreSounds")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("MoreSounds")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("MoreSounds")]
[assembly: AssemblyTitle("ViViKo.MoreSounds")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.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 MoreSounds
{
	[ContentWarningPlugin("ViViKo.MoreSounds", "MoreSounds", true)]
	[BepInPlugin("ViViKo.MoreSounds", "MoreSounds", "1.1.0")]
	public class MoreSounds : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("ViViKo.MoreSounds");

		public static MoreSounds Instance;

		public List<AudioClip> sounds = new List<AudioClip>();

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			loadSounds();
			Logger.LogInfo((object)"Plugin MoreSounds v1.1.0 is loaded!");
		}

		private void Start()
		{
			harmony.PatchAll();
		}

		public void loadSounds()
		{
			try
			{
				List<string> list = Directory.GetDirectories(Paths.PluginPath, "moresounds", SearchOption.AllDirectories).ToList();
				List<string> list2 = new List<string>();
				foreach (string item in list)
				{
					if (item != "")
					{
						string[] collection = Directory.GetFiles(item, "*.mp3").Union(Directory.GetFiles(item, "*.wav")).Union(Directory.GetFiles(item, "*.ogg"))
							.ToArray();
						list2.AddRange(collection);
					}
				}
				list2.Sort();
				foreach (string item2 in list2)
				{
					string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(item2);
					string text = Path.GetExtension(item2).ToLower();
					AudioClip val = null;
					switch (text)
					{
					case ".wav":
						val = LoadFromDiskToAudioClip(item2, (AudioType)20);
						break;
					case ".ogg":
						val = LoadFromDiskToAudioClip(item2, (AudioType)14);
						break;
					case ".mp3":
						val = LoadFromDiskToAudioClip(item2, (AudioType)13);
						break;
					}
					if ((Object)(object)val != (Object)null)
					{
						((Object)val).name = fileNameWithoutExtension;
						sounds.Add(val);
						Logger.LogInfo((object)("Loaded '" + fileNameWithoutExtension + "' Sound"));
					}
				}
			}
			catch (Exception ex)
			{
				Logger.LogWarning((object)("Something went wrong with More Sounds! Error: " + ex));
			}
		}

		public static AudioClip LoadFromDiskToAudioClip(string path, AudioType type)
		{
			//IL_0003: 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_0020: Invalid comparison between Unknown and I4
			AudioClip result = null;
			UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(path, type);
			try
			{
				audioClip.SendWebRequest();
				try
				{
					while (!audioClip.isDone)
					{
					}
					if ((int)audioClip.result != 1)
					{
						Logger.LogError((object)("Failed to load AudioClip from path: " + path + " Full error: " + audioClip.error));
					}
					else
					{
						result = DownloadHandlerAudioClip.GetContent(audioClip);
					}
				}
				catch (Exception ex)
				{
					Logger.LogError((object)(ex.Message + ", " + ex.StackTrace));
				}
			}
			finally
			{
				((IDisposable)audioClip)?.Dispose();
			}
			return result;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "ViViKo.MoreSounds";

		public const string PLUGIN_NAME = "MoreSounds";

		public const string PLUGIN_VERSION = "1.1.0";
	}
}
namespace MoreSounds.Patches
{
	[HarmonyPatch(typeof(SoundPlayerItem))]
	public class SoundPlayerItemPatch
	{
		[HarmonyPatch("ConfigItem")]
		[HarmonyPrefix]
		private static void ConfigItemPatch(SoundPlayerItem __instance)
		{
			try
			{
				List<SFX_Instance> sounds = __instance.sounds.ToList();
				SFX_Instance tempSfx = __instance.sounds[0];
				MoreSounds.Instance.sounds.ForEach(delegate(AudioClip sound)
				{
					SFX_Instance val = Object.Instantiate<SFX_Instance>(tempSfx);
					((Object)val).name = ((Object)sound).name;
					val.clips = (AudioClip[])(object)new AudioClip[1] { sound };
					sounds.Add(val);
				});
				__instance.sounds = sounds.ToArray();
			}
			catch (Exception ex)
			{
				MoreSounds.Logger.LogWarning((object)("Something went wrong with More Sounds! Error: " + ex));
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}