Decompiled source of BEYOND INFINITE for Act 3 Final Boss v1.0.5

bepinex_soundmod.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
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: AssemblyCompany("bepinex_soundmod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e757f32b2aedcab5f692b99aeff9d90b9b90c833")]
[assembly: AssemblyProduct("BepInEx Sound Mod")]
[assembly: AssemblyTitle("bepinex_soundmod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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 bepinex_soundmod
{
	[BepInPlugin("bepinex_soundmod", "BepInEx Sound Mod", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(AudioSource))]
		internal class AudioSourcePatch
		{
			[HarmonyPatch("Play", new Type[] { })]
			[HarmonyPrefix]
			public static void Play_Patch(AudioSource __instance)
			{
				ReplaceClip(__instance);
			}

			[HarmonyPatch("Play", new Type[] { typeof(ulong) })]
			[HarmonyPrefix]
			public static void Play_UlongPatch(AudioSource __instance)
			{
				ReplaceClip(__instance);
			}

			[HarmonyPatch("Play", new Type[] { typeof(double) })]
			[HarmonyPrefix]
			public static void Play_DoublePatch(AudioSource __instance)
			{
				ReplaceClip(__instance);
			}

			[HarmonyPatch("PlayDelayed", new Type[] { typeof(float) })]
			[HarmonyPrefix]
			public static void PlayDelayed_Patch(AudioSource __instance)
			{
				ReplaceClip(__instance);
			}

			[HarmonyPatch("PlayOneShotHelper", new Type[]
			{
				typeof(AudioSource),
				typeof(AudioClip),
				typeof(float)
			})]
			[HarmonyPrefix]
			public static void PlayOneShotHelper_Patch(AudioSource source, ref AudioClip clip, float volumeScale)
			{
				clip = ReplaceClip(clip, source);
			}

			public static void ReplaceClip(AudioSource source)
			{
				source.clip = ReplaceClip(source.clip, source);
			}

			public static AudioClip ReplaceClip(AudioClip clip, AudioSource source)
			{
				Logger.LogDebug((object)string.Format("Audio \"{0}\", source \"{1}\", replaced: {2}", ((Object)(object)clip == (Object)null) ? "unk" : ((Object)clip).name, ((Object)(object)source == (Object)null) ? "unk" : ((Object)source).name, replacedClips.ContainsKey(((Object)clip).name)));
				if (replacedClips.ContainsKey(((Object)clip).name))
				{
					return replacedClips[((Object)clip).name];
				}
				return clip;
			}
		}

		internal static ManualLogSource Logger;

		public static readonly Dictionary<string, AudioClip> replacedClips = new Dictionary<string, AudioClip>();

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin bepinex_soundmod is loaded!");
			string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "sounds");
			Logger.LogInfo((object)("Sounds path: \"" + text + "\""));
			if (!Directory.Exists(text))
			{
				Directory.CreateDirectory(text);
			}
			string[] files = Directory.GetFiles(text, "*", SearchOption.AllDirectories);
			foreach (string text2 in files)
			{
				string text3 = Path.GetExtension(text2).Substring(1);
				string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text2);
				string text4 = fileNameWithoutExtension + "." + text3;
				Logger.LogInfo((object)("Loading file \"" + text4 + "\"..."));
				AudioClip val = LoadClip(Path.Combine(text, text2), text3.ToLower());
				if ((Object)(object)val != (Object)null)
				{
					Logger.LogInfo((object)("Loaded file \"" + text4 + "\"!"));
					((Object)val).name = fileNameWithoutExtension;
					replacedClips.Add(fileNameWithoutExtension, val);
				}
			}
			string text5 = "";
			foreach (string key in replacedClips.Keys)
			{
				text5 = text5 + "\"" + key + "\", ";
			}
			Logger.LogInfo((object)$"{replacedClips.Count} sound replacements: {text5.Substring(0, text5.Length - 2)}");
			Harmony.CreateAndPatchAll(typeof(AudioSourcePatch), (string)null);
		}

		public static AudioClip LoadClip(string path, string format)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Invalid comparison between Unknown and I4
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			AudioType val = (AudioType)0;
			if (format != null)
			{
				int length = format.Length;
				if (length != 3)
				{
					if (length == 4)
					{
						char c = format[0];
						if (c != 'a')
						{
							if (c == 'm' && format == "mpeg")
							{
								goto IL_00db;
							}
						}
						else if (format == "aiff")
						{
							goto IL_00d3;
						}
					}
				}
				else
				{
					char c = format[1];
					if ((uint)c <= 99u)
					{
						switch (c)
						{
						case 'a':
							if (format == "wav")
							{
								val = (AudioType)20;
							}
							break;
						case 'c':
							if (format == "acc")
							{
								val = (AudioType)1;
							}
							break;
						}
					}
					else if (c != 'g')
					{
						if (c != 'i')
						{
							if (c == 'p' && format == "mpg")
							{
								goto IL_00db;
							}
						}
						else if (format == "aif")
						{
							goto IL_00d3;
						}
					}
					else if (format == "ogg")
					{
						val = (AudioType)14;
					}
				}
			}
			goto IL_00de;
			IL_00db:
			val = (AudioType)13;
			goto IL_00de;
			IL_00de:
			UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(path, val);
			try
			{
				audioClip.SendWebRequest();
				try
				{
					while (!audioClip.isDone)
					{
					}
					if ((int)audioClip.result == 1)
					{
						return DownloadHandlerAudioClip.GetContent(audioClip);
					}
					Logger.LogWarning((object)("Failed to load clip: " + audioClip.error));
				}
				catch (Exception ex)
				{
					Logger.LogError((object)("Caught error while loading clip: " + ex.Message + ", " + ex.StackTrace));
				}
			}
			finally
			{
				((IDisposable)audioClip)?.Dispose();
			}
			return null;
			IL_00d3:
			val = (AudioType)2;
			goto IL_00de;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "bepinex_soundmod";

		public const string PLUGIN_NAME = "BepInEx Sound Mod";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}