Decompiled source of AmazingGraceJester v1.0.0

BepInEx/plugins/AmazingGraceJester.dll

Decompiled a year ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using System.Threading.Tasks;
using BepInEx;
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: AssemblyCompany("AmazingGraceJester")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Makes the Jester play a creepy version of 'Amazing Grace' on windup")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+2fb48d7fb09a0b342c9f5662e5d0e0d2b0d2e256")]
[assembly: AssemblyProduct("AmazingGraceJester")]
[assembly: AssemblyTitle("AmazingGraceJester")]
[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 AmazingGraceJester
{
	[BepInPlugin("ShimmyMySherbet.AmazingGraceJester", "AmazingGraceJester", "1.0.0")]
	public class AmazingJester : BaseUnityPlugin
	{
		private Harmony m_Harmony;

		public static AudioClip AmazingGraceSFX { get; private set; }

		public string CacheDirectory => Path.Combine("BepInEx", "cache");

		public string AmazingGraceFile => Path.Combine(CacheDirectory, "AmazingGraceEffect.ogg");

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			m_Harmony = new Harmony("AmazingGraceJester");
			m_Harmony.PatchAll(typeof(AmazingJester).Assembly);
			Task.Run((Func<Task?>)AwakeAsync);
		}

		private async Task AwakeAsync()
		{
			try
			{
				await LoadAssets();
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Failed to load Amazing Grace Jester: " + ex.Message + ", " + ex.StackTrace));
				throw;
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Amazing Grace Jester is loaded!");
		}

		private async Task LoadAssets()
		{
			if (!File.Exists(AmazingGraceFile))
			{
				await CacheSoundEffect();
			}
			LoadSoundEffect();
		}

		private async Task CacheSoundEffect()
		{
			using Stream manifestStream = typeof(AmazingJester).Assembly.GetManifestResourceStream("AmazingGraceJester.Assets.AmazingGraceEffect.ogg");
			using FileStream file = new FileStream(AmazingGraceFile, FileMode.Create, FileAccess.Write);
			await manifestStream.CopyToAsync(file);
			await file.FlushAsync();
		}

		private void LoadSoundEffect()
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Invalid comparison between Unknown and I4
			string text = "file:///" + Path.GetFullPath(AmazingGraceFile).Replace('\\', '/');
			UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(text, (AudioType)14);
			try
			{
				www.SendWebRequest();
				SpinWait.SpinUntil(() => www.isDone);
				if ((int)www.result == 2)
				{
					Debug.Log((object)www.error);
				}
				else
				{
					AmazingGraceSFX = DownloadHandlerAudioClip.GetContent(www);
				}
			}
			finally
			{
				if (www != null)
				{
					((IDisposable)www).Dispose();
				}
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "AmazingGraceJester";

		public const string PLUGIN_NAME = "AmazingGraceJester";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace AmazingGraceJester.Patches
{
	[HarmonyPatch(typeof(JesterAI), "SetJesterInitialValues")]
	internal static class JesterAIPatch
	{
		[HarmonyPrefix]
		public static void Prefix(JesterAI __instance)
		{
			if ((Object)(object)AmazingJester.AmazingGraceSFX != (Object)null)
			{
				__instance.popGoesTheWeaselTheme = AmazingJester.AmazingGraceSFX;
			}
		}
	}
}