Decompiled source of Yodel and EdEddEddy Fall Sounds v1.0.8

plugins/An0n_Patches_Yodel.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using An0n_Patches.Patches;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Photon.Pun;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.Networking;
using Zorro.Settings;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("An0n_Patches")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("An0n_Patches")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("415f18a2-c213-4036-b3f0-7673c0a38c58")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace An0n_Patches
{
	[BepInPlugin("com.an0n.yodelPatch", "An0n Yodel Patch", "1.0.8")]
	public class An0n_Patch_Plugin : BaseUnityPlugin
	{
		public const string pluginGUID = "com.an0n.yodelPatch";

		private const string pluginName = "An0n Yodel Patch";

		private const string pluginVersion = "1.0.8";

		public static ManualLogSource mls = Logger.CreateLogSource("com.an0n.yodelPatch");

		private Harmony harmony = new Harmony("com.an0n.yodelPatch");

		public static ConfigEntry<bool> allowYodel;

		public static ConfigEntry<bool> enableFallDmgSounds;

		public static An0n_Patch_Plugin instance;

		public static string soundLoc;

		private Harmony patcher;

		private void Awake()
		{
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Expected O, but got Unknown
			instance = this;
			allowYodel = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "allowYodel", true, "Allow yodeling or not");
			enableFallDmgSounds = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "enableFallDmgSounds", true, "Enable Ed Edd and Eddy fall damage sounds");
			Debug.Log((object)"[An0nPatch] Yodel Plugin 1.0.8 Loaded!");
			string location = ((BaseUnityPlugin)instance).Info.Location;
			string[] array = location.Split(new char[1] { '\\' });
			array = array.Take(array.Length - 1).ToArray();
			string text = string.Join("\\", array);
			soundLoc = text + "\\edd\\";
			patcher = new Harmony("com.an0n.yodelPatch");
			patcher.PatchAll(typeof(PlayerControllerPatch));
			patcher.PatchAll(typeof(RunManagerPatch));
			patcher.PatchAll(typeof(PlayerSndComponent));
			patcher.PatchAll(typeof(SettingsPatch.SettingsHandler_Constructor_Patch));
			patcher.PatchAll(typeof(SettingsPatch.LocalizedText_GetText_Patch));
		}
	}
}
namespace An0n_Patches.Patches
{
	internal class SettingsPatch
	{
		public class YodelVolumeSetting : FloatSetting, IExposedSetting
		{
			public string settingName = "";

			public YodelVolumeSetting(string name)
			{
				settingName = name;
			}

			public override void ApplyValue()
			{
			}

			protected override float GetDefaultValue()
			{
				return 0.5f;
			}

			protected override float2 GetMinMaxValue()
			{
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				return new float2(0f, 1f);
			}

			public string GetDisplayName()
			{
				return settingName;
			}

			public string GetCategory()
			{
				return "Audio";
			}
		}

		public class FallVolumeSetting : FloatSetting, IExposedSetting
		{
			public string settingName = "";

			public FallVolumeSetting(string name)
			{
				settingName = name;
			}

			public override void ApplyValue()
			{
			}

			protected override float GetDefaultValue()
			{
				return 0.3f;
			}

			protected override float2 GetMinMaxValue()
			{
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				return new float2(0f, 1f);
			}

			public string GetDisplayName()
			{
				return settingName;
			}

			public string GetCategory()
			{
				return "Audio";
			}
		}

		[HarmonyPatch(typeof(LocalizedText), "GetText", new Type[]
		{
			typeof(string),
			typeof(bool)
		})]
		public static class LocalizedText_GetText_Patch
		{
			private static bool Prefix(string id, ref string __result)
			{
				if (settingsList.Contains(id))
				{
					__result = id.ToUpperInvariant();
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(SettingsHandler))]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		public static class SettingsHandler_Constructor_Patch
		{
			private static void Postfix(SettingsHandler __instance)
			{
				SettingsHandler.Instance.AddSetting((Setting)(object)new YodelVolumeSetting(settingsList[0]));
				SettingsHandler.Instance.AddSetting((Setting)(object)new FallVolumeSetting(settingsList[1]));
			}
		}

		public static readonly string[] settingsList = new string[2] { "Yodel Volume", "Fall Dmg Volume" };
	}
	internal class SoundHandler
	{
		[CompilerGenerated]
		private sealed class <LoadAudio>d__1 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public string url;

			public Action<AudioClip> callback;

			private UnityWebRequest <www>5__1;

			private AudioClip <clip>5__2;

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

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

			[DebuggerHidden]
			public <LoadAudio>d__1(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();
					}
				}
				<www>5__1 = null;
				<clip>5__2 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0074: Invalid comparison between Unknown and I4
				//IL_0096: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a1: Expected O, but got Unknown
				bool result;
				try
				{
					switch (<>1__state)
					{
					default:
						result = false;
						break;
					case 0:
						<>1__state = -1;
						<www>5__1 = UnityWebRequestMultimedia.GetAudioClip(url, (AudioType)20);
						<>1__state = -3;
						<>2__current = <www>5__1.SendWebRequest();
						<>1__state = 1;
						result = true;
						break;
					case 1:
						<>1__state = -3;
						if ((int)<www>5__1.result == 2)
						{
							result = false;
						}
						else
						{
							<clip>5__2 = DownloadHandlerAudioClip.GetContent(<www>5__1);
							if (!((Object)<clip>5__2 == (Object)null))
							{
								callback(<clip>5__2);
								<clip>5__2 = null;
								<>m__Finally1();
								result = false;
								break;
							}
							result = false;
						}
						<>m__Finally1();
						break;
					}
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
				return result;
			}

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

			private void <>m__Finally1()
			{
				<>1__state = -1;
				((IDisposable)<www>5__1)?.Dispose();
			}

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

		public static AudioClip newSFX;

		[IteratorStateMachine(typeof(<LoadAudio>d__1))]
		public static IEnumerator LoadAudio(string url, Action<AudioClip> callback)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <LoadAudio>d__1(0)
			{
				url = url,
				callback = callback
			};
		}

		public static void getAudioAndPlay(Character player, int rSound)
		{
			if ((!An0n_Patch_Plugin.allowYodel.Value && rSound == 9) || (!An0n_Patch_Plugin.enableFallDmgSounds.Value && rSound < 9))
			{
				return;
			}
			string text = "ed" + rSound + ".wav";
			string text2 = An0n_Patch_Plugin.soundLoc + text;
			((MonoBehaviour)RunManager.Instance).StartCoroutine(LoadAudio("file:///" + text2, delegate(AudioClip sound)
			{
				if ((Object)(object)sound == (Object)null)
				{
					Debug.LogError((object)"Failed to load Edd sounds!");
				}
				else
				{
					GameObject gameObject = ((Component)((Component)player).gameObject.transform.FindChild("Scout").FindChild("SFX")).gameObject;
					AudioSource component = gameObject.GetComponent<AudioSource>();
					if ((Object)(object)component == (Object)null)
					{
						gameObject.AddComponent<AudioSource>();
						component = gameObject.GetComponent<AudioSource>();
					}
					component.spatialBlend = 1f;
					component.dopplerLevel = 1f;
					component.minDistance = 12f;
					component.maxDistance = 1000f;
					component.rolloffMode = (AudioRolloffMode)0;
					component.clip = sound;
					component.volume = ((FloatSetting)GameHandler.Instance.SettingsHandler.GetSetting<SettingsPatch.FallVolumeSetting>()).Value * 0.3f;
					if (rSound == 9)
					{
						component.volume = ((FloatSetting)GameHandler.Instance.SettingsHandler.GetSetting<SettingsPatch.YodelVolumeSetting>()).Value * 0.3f;
					}
					component.Play();
					if (((Object)player).name != ((Object)Player.localPlayer.character).name && rSound == 9)
					{
						PlayerControllerPatch.otherFaceYodel(player);
					}
				}
			}));
		}
	}
	[HarmonyPatch(typeof(RunManager))]
	internal class RunManagerPatch : MonoBehaviour
	{
		[HarmonyPatch(typeof(RunManager), "StartRun")]
		[HarmonyPostfix]
		private static void StartPostfix()
		{
			PlayerControllerPatch.yodelEnable(0.1f);
		}
	}
	public static class PlayerSndComponent
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(Character), "Awake")]
		public static void AwakePatch(Character __instance)
		{
			((Component)__instance).gameObject.AddComponent<PlayerControllerPatch>();
		}
	}
	internal class PlayerControllerPatch : MonoBehaviour
	{
		[CompilerGenerated]
		private sealed class <otherFaceYodelEnable>d__4 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public Character player;

			private AnimatedMouth <pmouth>5__1;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<pmouth>5__1 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(1.7f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<pmouth>5__1 = ((Component)player).GetComponent<AnimatedMouth>();
					((Behaviour)<pmouth>5__1).enabled = true;
					return false;
				}
			}

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

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

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

			private object <>2__current;

			public float mult;

			private Character <locPlayer>5__1;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<locPlayer>5__1 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_004b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0055: Expected O, but got Unknown
				//IL_00db: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e5: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<locPlayer>5__1 = Player.localPlayer.character;
					<>2__current = (object)new WaitForSeconds(1.7f * mult);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					yJump = false;
					Player.localPlayer.character.refs.animator.SetBool("Emote", false);
					((Behaviour)((Component)<locPlayer>5__1).GetComponent<AnimatedMouth>()).enabled = true;
					<locPlayer>5__1.refs.movement.movementForce = force;
					((Behaviour)<locPlayer>5__1.refs.animations).enabled = true;
					<>2__current = (object)new WaitForSeconds(10f * mult);
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -1;
					yodel = false;
					return false;
				}
			}

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

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

		private static int lastPlayed = 0;

		public static bool yodel = false;

		public static bool yJump = false;

		private static float force = 0f;

		private static float oldTime = Time.time;

		[IteratorStateMachine(typeof(<otherFaceYodelEnable>d__4))]
		public static IEnumerator otherFaceYodelEnable(Character player)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <otherFaceYodelEnable>d__4(0)
			{
				player = player
			};
		}

		public static void otherFaceYodel(Character player)
		{
			AnimatedMouth component = ((Component)player).GetComponent<AnimatedMouth>();
			((Behaviour)component).enabled = false;
			component.mouthRenderer.material.SetInt("_UseTalkSprites", 1);
			component.isSpeaking = true;
			component.mouthRenderer.material.SetTexture("_TalkSprite", (Texture)(object)component.mouthTextures[2]);
			((MonoBehaviour)RunManager.Instance).StartCoroutine(otherFaceYodelEnable(player));
		}

		[HarmonyTranspiler]
		[HarmonyPatch(typeof(CharacterMovement), "CheckFallDamage")]
		public static IEnumerable<CodeInstruction> FallDamageHook(IEnumerable<CodeInstruction> instructions)
		{
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			if (An0n_Patch_Plugin.enableFallDmgSounds.Value)
			{
				for (int i = 0; i < list.Count; i++)
				{
					CodeInstruction val = list[i];
					if (!(val.opcode == OpCodes.Callvirt))
					{
						continue;
					}
					MethodInfo methodInfo = val.operand as MethodInfo;
					if (methodInfo != null)
					{
						string name = methodInfo.Name;
						string text = methodInfo.DeclaringType?.FullName;
						if (name == "Fall" && text == "Character")
						{
							list.Insert(i, new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(PlayerControllerPatch), "selfDmgFallPlayAudio", (Type[])null, (Type[])null)));
							Debug.Log((object)("[An0nPatch] Appended intruction to fall Callvirt " + name));
							break;
						}
					}
				}
			}
			return list;
		}

		private static void selfDmgFallPlayAudio()
		{
			Random random = new Random();
			int num = random.Next(1, 9);
			if (num == lastPlayed)
			{
				while (num == lastPlayed)
				{
					num = random.Next(1, 9);
				}
			}
			SoundHandler.getAudioAndPlay(Player.localPlayer.character, num);
			Player.localPlayer.character.refs.view.RPC("playPlayerSound", (RpcTarget)1, new object[2]
			{
				Player.localPlayer.character.refs.view.ViewID,
				num
			});
			lastPlayed = num;
		}

		[HarmonyPatch(typeof(CharacterMovement), "TryToJump")]
		[HarmonyPrefix]
		private static bool stopYodelJump(object __instance)
		{
			if (yJump)
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(CharacterMovement), "Update")]
		[HarmonyPostfix]
		private static void yodelKey(object __instance)
		{
			bool keyDown = Input.GetKeyDown((KeyCode)121);
			if (keyDown)
			{
				Debug.Log((object)"Yodel Pressed");
				if (Time.time - oldTime > 10f)
				{
					yodel = false;
					yJump = false;
				}
				oldTime = Time.time;
			}
			if (keyDown && !yodel && An0n_Patch_Plugin.allowYodel.Value)
			{
				yodel = true;
				Debug.Log((object)"Yodel Pressed+allowed");
				Character character = Player.localPlayer.character;
				CharacterData data = character.data;
				if (!data.passedOut && !data.dead && !data.fullyPassedOut)
				{
					Player.localPlayer.character.refs.view.RPC("RPCA_PlayRemove", (RpcTarget)0, new object[2] { "A_Scout_Emote_Shrug", true });
					SoundHandler.getAudioAndPlay(character, 9);
					Player.localPlayer.character.refs.view.RPC("playPlayerSound", (RpcTarget)1, new object[2]
					{
						character.refs.view.ViewID,
						9
					});
					AnimatedMouth component = ((Component)character).GetComponent<AnimatedMouth>();
					((Behaviour)component).enabled = false;
					component.isSpeaking = true;
					component.mouthRenderer.material.SetInt("_UseTalkSprites", 1);
					component.mouthRenderer.material.SetTexture("_TalkSprite", (Texture)(object)component.mouthTextures[2]);
					yJump = true;
					force = character.refs.movement.movementForce;
					character.refs.movement.movementForce = 0f;
					((Behaviour)character.refs.animations).enabled = false;
					((MonoBehaviour)RunManager.Instance).StartCoroutine(yodelEnable(1f));
				}
			}
		}

		[IteratorStateMachine(typeof(<yodelEnable>d__11))]
		public static IEnumerator yodelEnable(float mult)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <yodelEnable>d__11(0)
			{
				mult = mult
			};
		}

		[PunRPC]
		private void playPlayerSound(int name, int rSound)
		{
			Character val = null;
			Character.GetCharacterWithPhotonID(name, ref val);
			Debug.Log((object)("Received message: " + ((Object)val).name + " sound: " + rSound));
			SoundHandler.getAudioAndPlay(val, rSound);
		}
	}
}