Decompiled source of CustomSoundboards v1.0.1

CustomSoundboards.dll

Decompiled 8 months ago
using System;
using System.Collections;
using System.Collections.Generic;
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 HarmonyLib;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("CustomSoundboards")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Content Warning plugin")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("CustomSoundboards")]
[assembly: AssemblyTitle("CustomSoundboards")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
namespace CustomSoundboards
{
	[BepInPlugin("CustomSoundboards", "CustomSoundboards", "1.0.1")]
	public class CustomSoundBoards : BaseUnityPlugin
	{
		internal static ManualLogSource Logger { get; private set; }

		internal static ConfigEntry<string> SoundboardURLs { get; private set; }

		public static CustomSoundBoards Instance { get; private set; }

		private void Awake()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			string text = "https://www.myinstants.com/media/sounds/metal-pipe-clang.mp3,https://www.myinstants.com/media/sounds/vine-boom.mp3,https://www.myinstants.com/media/sounds/dry-fart.mp3";
			SoundboardURLs = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Sounds", text, "A list of URL's seperated by commas where the sounds will be pull from.");
			Logger.LogInfo((object)"Plugin CustomSoundboards is loaded!");
			Harmony val = new Harmony("CustomSoundBoards");
			val.PatchAll();
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "CustomSoundboards";

		public const string PLUGIN_NAME = "CustomSoundboards";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}
namespace CustomSoundboards.Patches
{
	[HarmonyPatch(typeof(SoundPlayerItem))]
	public class SoundPlayerPatch
	{
		public static List<SFX_Instance> sounds = new List<SFX_Instance>();

		[HarmonyPostfix]
		[HarmonyPatch("ConfigItem")]
		public static void ConfigItem(ItemInstanceData data, SoundPlayerItem __instance)
		{
			sounds = new List<SFX_Instance>();
			((MonoBehaviour)CustomSoundBoards.Instance).StartCoroutine(PatchAudio(__instance, data));
		}

		public static IEnumerator PatchAudio(SoundPlayerItem instance, ItemInstanceData data)
		{
			string[] urls = CustomSoundBoards.SoundboardURLs.Value.Split(",");
			foreach (string url in urls)
			{
				CustomSoundBoards.Logger.LogInfo((object)("Applying " + url + "."));
				UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(url, (AudioType)0);
				try
				{
					yield return www.SendWebRequest();
					if ((int)www.result == 2)
					{
						CustomSoundBoards.Logger.LogError((object)www.error);
						continue;
					}
					AudioClip myClip = DownloadHandlerAudioClip.GetContent(www);
					SFX_Instance sound = ScriptableObject.CreateInstance<SFX_Instance>();
					((Object)sound).name = url.Split("/")[^1];
					sound.settings = new SFX_Settings
					{
						pitch_Variation = 0f,
						volume_Variation = 0f
					};
					sound.clips = (AudioClip[])(object)new AudioClip[1] { myClip };
					sounds.Add(sound);
				}
				finally
				{
					((IDisposable)www)?.Dispose();
				}
			}
			CustomSoundBoards.Logger.LogInfo((object)$"Patched Sounds {sounds.Count} | {instance.sounds.Length}.");
			for (int j = 0; j < instance.sounds.Length; j++)
			{
				sounds.Add(instance.sounds[j]);
			}
			instance.sounds = sounds.ToArray();
			IntRangeEntry entry = default(IntRangeEntry);
			if (data.TryGetEntry<IntRangeEntry>(ref entry))
			{
				data.RemoveDataEntry((ItemDataEntry)(object)entry);
			}
			instance.selectionEntry = new IntRangeEntry
			{
				selectedValue = 0,
				maxValue = instance.sounds.Length
			};
			data.AddDataEntry((ItemDataEntry)(object)instance.selectionEntry);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}