Decompiled source of OriginalHornetVoiceLines v1.1.1

Skong.dll

Decompiled a day ago
using System;
using System.Collections;
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.Configuration;
using BepInEx.Logging;
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("Skong")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("ShawPlugin")]
[assembly: AssemblyTitle("Skong")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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 Skong
{
	[BepInPlugin("com.notsora.hornetremembered", "Old Hornet voicelines", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static class Global
		{
			public static bool hasPlayed;
		}

		public static class SoundContext
		{
			public static bool InSkill;

			public static bool CanPlay;
		}

		[HarmonyPatch(typeof(HeroController), "ThrowTool")]
		private class Patch_ThrowTool
		{
			private static void Prefix(HeroController __instance)
			{
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: Expected O, but got Unknown
				//IL_0058: Unknown result type (might be due to invalid IL or missing references)
				//IL_005e: Invalid comparison between Unknown and I4
				float num = Random.Range(0f, 1f);
				if (num <= voiceLineChance.Value)
				{
					SoundContext.CanPlay = true;
					FieldInfo fieldInfo = AccessTools.Field(typeof(HeroController), "willThrowTool");
					ToolItem val = (ToolItem)fieldInfo.GetValue(__instance);
					if ((Object)(object)val != (Object)null && (int)val.Type == 3)
					{
						SoundContext.InSkill = true;
					}
				}
			}

			private static void Postfix(HeroController __instance)
			{
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Expected O, but got Unknown
				//IL_007d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0083: Invalid comparison between Unknown and I4
				//IL_0086: Unknown result type (might be due to invalid IL or missing references)
				//IL_0135: Unknown result type (might be due to invalid IL or missing references)
				//IL_013b: Invalid comparison between Unknown and I4
				//IL_013e: Unknown result type (might be due to invalid IL or missing references)
				SoundContext.InSkill = false;
				FieldInfo fieldInfo = AccessTools.Field(typeof(HeroController), "willThrowTool");
				ToolItem val = (ToolItem)fieldInfo.GetValue(__instance);
				GameManager instance = GameManager.instance;
				AudioSource val2 = ((Component)instance).gameObject.GetComponent<AudioSource>();
				if ((Object)(object)val2 == (Object)null)
				{
					val2 = ((Component)instance).gameObject.AddComponent<AudioSource>();
					val2.playOnAwake = false;
				}
				if (!SoundContext.CanPlay)
				{
					return;
				}
				SoundContext.CanPlay = false;
				if ((Object)(object)val != (Object)null && (int)val.Type == 3 && val.Usage.FsmEventName == "PARRY")
				{
					List<string> list = new List<string> { "laugh1", "laugh2" };
					string text = list[Random.Range(0, list.Count)];
					if (clips.TryGetValue(text, out var value))
					{
						val2.PlayOneShot(value, voiceLineVolume.Value);
					}
					else
					{
						Logger.LogWarning((object)("Clip " + text + " not loaded yet!"));
					}
				}
				else
				{
					if (!((Object)(object)val != (Object)null) || (int)val.Type != 3 || val.Usage.FsmEventName == "PARRY")
					{
						return;
					}
					List<string> list2 = new List<string>();
					if (canAdino.Value)
					{
						list2.Add("adino");
					}
					if (canShaw.Value)
					{
						list2.Add("shaw");
					}
					if (canHegale.Value)
					{
						list2.Add("hegale");
					}
					if (canHaaa.Value)
					{
						list2.Add("haaaa");
					}
					string text2 = list2[Random.Range(0, list2.Count())];
					if (!val2.isPlaying)
					{
						if (clips.TryGetValue(text2, out var value2))
						{
							val2.PlayOneShot(value2, voiceLineVolume.Value);
						}
						else
						{
							Logger.LogWarning((object)("Clip " + text2 + " not loaded yet!"));
						}
					}
				}
			}
		}

		[HarmonyPatch(typeof(AudioSource), "PlayOneShot", new Type[]
		{
			typeof(AudioClip),
			typeof(float)
		})]
		private class Patch_AudioSourcePlayOneShot
		{
			private static bool Prefix(AudioSource __instance, AudioClip clip)
			{
				if (SoundContext.CanPlay && SoundContext.InSkill && (((Object)clip).name.StartsWith("a") || ((Object)clip).name.Contains("Hornet_attack_large")))
				{
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(HeroController), "Die")]
		private class Patch_Die
		{
			private static void Postfix(HeroController __instance)
			{
				AudioSource val = ((Component)__instance).gameObject.GetComponent<AudioSource>();
				if ((Object)(object)val == (Object)null)
				{
					val = ((Component)__instance).gameObject.AddComponent<AudioSource>();
				}
				if (Random.Range(0f, 1f) <= gitGudChance.Value && clips.TryGetValue("gitgud", out var value))
				{
					val.PlayOneShot(value, voiceLineVolume.Value + 0.4f);
				}
			}
		}

		[CompilerGenerated]
		private sealed class <LoadAudio>d__13 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public string filename;

			public string key;

			public Plugin <>4__this;

			private string <pluginFolder>5__1;

			private string <resourcePath>5__2;

			private UnityWebRequest <www>5__3;

			private AudioClip <clip>5__4;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <LoadAudio>d__13(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || num == 1)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<pluginFolder>5__1 = null;
				<resourcePath>5__2 = null;
				<www>5__3 = null;
				<clip>5__4 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e2: Invalid comparison between Unknown and I4
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<pluginFolder>5__1 = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
						<resourcePath>5__2 = Path.Combine(<pluginFolder>5__1, filename);
						if (!File.Exists(<resourcePath>5__2))
						{
							Logger.LogWarning((object)(filename + " not found in plugins folder!"));
							return false;
						}
						<www>5__3 = UnityWebRequestMultimedia.GetAudioClip("file:///" + <resourcePath>5__2, (AudioType)20);
						<>1__state = -3;
						<>2__current = <www>5__3.SendWebRequest();
						<>1__state = 1;
						return true;
					case 1:
						<>1__state = -3;
						if ((int)<www>5__3.result == 1)
						{
							<clip>5__4 = DownloadHandlerAudioClip.GetContent(<www>5__3);
							clips[key] = <clip>5__4;
							Logger.LogInfo((object)("Loaded sound: " + filename + " as " + key));
							<clip>5__4 = null;
						}
						else
						{
							Logger.LogError((object)("Failed to load " + filename + ": " + <www>5__3.error));
						}
						<>m__Finally1();
						<www>5__3 = null;
						return false;
					}
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<www>5__3 != null)
				{
					((IDisposable)<www>5__3).Dispose();
				}
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public static Plugin Instance;

		internal static ManualLogSource Logger;

		public static AudioClip shawClip;

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

		public static ConfigEntry<float> voiceLineVolume;

		public static ConfigEntry<float> gitGudChance;

		public static ConfigEntry<float> voiceLineChance;

		public static ConfigEntry<bool> canShaw;

		public static ConfigEntry<bool> canHaaa;

		public static ConfigEntry<bool> canHegale;

		public static ConfigEntry<bool> canAdino;

		private void Awake()
		{
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Expected O, but got Unknown
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin Skong is loaded!");
			voiceLineVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Volume", "VoiceLineVolume", 0.4f, "Volume for hornet voice lines (0.0 = mute, 1.0 = loud, >1.0 very loud");
			voiceLineChance = ((BaseUnityPlugin)this).Config.Bind<float>("Chance", "VoiceLineChance", 1f, "Chance that hornet will do one of her voice lines from Hollow Knight (0.0 = 0%, 1.0 = 100%)");
			gitGudChance = ((BaseUnityPlugin)this).Config.Bind<float>("Chance", "OnDeathSoundChance", 0.1f, "Chance that hornet will tell you to get good after dying (0.0 = 0%, 1.0 = 100%)");
			canAdino = ((BaseUnityPlugin)this).Config.Bind<bool>("Variance", "AdinoChance", true, "Flag that allows the 'Adino' voice line to play");
			canShaw = ((BaseUnityPlugin)this).Config.Bind<bool>("Variance", "ShawChance", true, "Flag that allows the 'Shaw' voice line to play");
			canHaaa = ((BaseUnityPlugin)this).Config.Bind<bool>("Variance", "HaaaChance", true, "Flag that allows the 'Haaa' voice line to play");
			canHegale = ((BaseUnityPlugin)this).Config.Bind<bool>("Variance", "HegaleChance", true, "Flag that allows the 'Hegale' voice line to play");
			((MonoBehaviour)this).StartCoroutine(LoadAudio("hornet_gitgud.wav", "gitgud"));
			((MonoBehaviour)this).StartCoroutine(LoadAudio("hornet_shaw.wav", "shaw"));
			((MonoBehaviour)this).StartCoroutine(LoadAudio("hornet_adino.wav", "adino"));
			((MonoBehaviour)this).StartCoroutine(LoadAudio("hornet_haaaa.wav", "haaaa"));
			((MonoBehaviour)this).StartCoroutine(LoadAudio("hornet_hegale.wav", "hegale"));
			((MonoBehaviour)this).StartCoroutine(LoadAudio("hornet_laugh1.wav", "laugh1"));
			((MonoBehaviour)this).StartCoroutine(LoadAudio("hornet_laugh2.wav", "laugh2"));
			Harmony val = new Harmony("com.notsora.hornetremembered");
			val.PatchAll();
		}

		[IteratorStateMachine(typeof(<LoadAudio>d__13))]
		private IEnumerator LoadAudio(string filename, string key)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <LoadAudio>d__13(0)
			{
				<>4__this = this,
				filename = filename,
				key = key
			};
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Skong";

		public const string PLUGIN_NAME = "ShawPlugin";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}