Decompiled source of Goofy Ahh Blender v0.1.0

GoofyAhhBlender.dll

Decompiled 8 months ago
using System;
using System.Collections.Generic;
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 BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("GoofyAhhBlender")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+aa2f881beb4f7c4aa6fe0639d15b2d48fee8f758")]
[assembly: AssemblyProduct("GoofyAhhBlender")]
[assembly: AssemblyTitle("GoofyAhhBlender")]
[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 ContentWendigos
{
	[BepInPlugin("GoofyAhhBlender", "GoofyAhhBlender", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Bot_ToolkitBoy), "RPCA_BonkTool")]
		private class Bot_ToolkitBoyPatch
		{
			private static void Postfix(Bot_ToolkitBoy __instance)
			{
				//IL_0067: Unknown result type (might be due to invalid IL or missing references)
				object value = Traverse.Create((object)__instance.bot).Field("botSounds").GetValue();
				UniversalBotSounds val = (UniversalBotSounds)((value is UniversalBotSounds) ? value : null);
				val.alertSound.clips = soundEffects.ToArray();
				WriteToConsole("PLAYING AUDIO " + val.alertSound.clips.Length);
				val.alertSound.Play(((Component)__instance).transform.position, true, 5f, (Transform)null);
			}
		}

		private static string assembly_path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

		private Harmony harmonyInstance = new Harmony("GoofyAhhHarmony");

		private static List<AudioClip> soundEffects = new List<AudioClip>();

		private static Random rand = new Random();

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin GoofyAhhBlender is loaded!");
			WriteToConsole("PATCHING ALL");
			harmonyInstance.PatchAll();
			string[] files = Directory.GetFiles(assembly_path + "\\Sounds");
			foreach (string text in files)
			{
				if (Path.GetExtension(text).ToLower() == ".mp3")
				{
					soundEffects.Add(LoadAudioFile(text, (AudioType)13));
					continue;
				}
				if (Path.GetExtension(text).ToLower() == ".wav")
				{
					soundEffects.Add(LoadAudioFile(text, (AudioType)20));
					continue;
				}
				throw new Exception("Bad audio type - MP3 or WAV only");
			}
			WriteToConsole("Loaded " + soundEffects.Count + " Clips");
		}

		private static void WriteToConsole(string output)
		{
			Console.WriteLine("GoofyAhhPrint: " + output);
		}

		private static AudioClip LoadAudioFile(string audioFilePath, AudioType type = 13)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Invalid comparison between Unknown and I4
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Invalid comparison between Unknown and I4
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			if (File.Exists(audioFilePath))
			{
				UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(audioFilePath, type);
				try
				{
					audioClip.SendWebRequest();
					while ((int)audioClip.result == 0)
					{
					}
					if ((int)audioClip.result != 1)
					{
						WriteToConsole("www.error " + audioClip.error);
						WriteToConsole(" www.uri " + audioClip.uri);
						WriteToConsole(" www.url " + audioClip.url);
						Result result = audioClip.result;
						WriteToConsole(" www.result " + ((object)(Result)(ref result)).ToString());
						return null;
					}
					AudioClip content = DownloadHandlerAudioClip.GetContent(audioClip);
					((Object)content).name = audioFilePath;
					return content;
				}
				finally
				{
					((IDisposable)audioClip)?.Dispose();
				}
			}
			WriteToConsole("AUDIO FILE NOT FOUND");
			return null;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "GoofyAhhBlender";

		public const string PLUGIN_NAME = "GoofyAhhBlender";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}