Decompiled source of Yodel and EdEddEddy Fall Sounds v1.0.6

plugins/An0n_Patches_Yodel.dll

Decompiled 2 days 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 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 & FallDmg Patch", "1.0.5")]
	public class An0n_Patch_Plugin : BaseUnityPlugin
	{
		public const string pluginGUID = "com.an0n.yodelPatch";

		private const string pluginName = "An0n Yodel & FallDmg Patch";

		private const string pluginVersion = "1.0.5";

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

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

		public static ConfigEntry<bool> enableFallDmgSounds;

		public static ConfigEntry<bool> allowYodel;

		public static ConfigEntry<float> yodelAndFallVolume;

		public static ConfigEntry<bool> useGameSFXVolume;

		public static An0n_Patch_Plugin instance;

		public static string soundLoc;

		private Harmony patcher;

		private void Awake()
		{
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Expected O, but got Unknown
			instance = this;
			enableFallDmgSounds = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "enableFallDmgSounds", true, "Enable Ed Edd and Eddy fall damage sounds");
			allowYodel = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "allowYodel", true, "Allow yodeling or not");
			useGameSFXVolume = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "useGameSFXVolume", true, "Set yodel and fall to use the game SFX audio setting.");
			yodelAndFallVolume = ((BaseUnityPlugin)this).Config.Bind<float>("General", "yodelAndFallVolume", 1f, "If NOT using useGameSFXVolume, Volume of the yodel and fall damage sounds. 0.0-1.0");
			Debug.Log((object)"[An0nPatch] Yodel & Fall Sounds Plugin 1.0.5 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));
		}
	}
}
namespace An0n_Patches.Patches
{
	internal class SoundHandler
	{
		public static AudioClip newSFX;

		public static IEnumerator LoadAudio(string url, Action<AudioClip> callback)
		{
			UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(url, (AudioType)20);
			try
			{
				yield return www.SendWebRequest();
				if ((int)www.result != 2)
				{
					AudioClip clip = DownloadHandlerAudioClip.GetContent(www);
					if (!((Object)clip == (Object)null))
					{
						callback(clip);
					}
				}
			}
			finally
			{
				((IDisposable)www)?.Dispose();
			}
		}

		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;
					float num = 1f;
					if (rSound != 9)
					{
						num = 0.6f;
					}
					if (An0n_Patch_Plugin.useGameSFXVolume.Value)
					{
						component.volume = num * ((FloatSetting)GameHandler.Instance.SettingsHandler.GetSetting<SFXVolumeSetting>()).Value;
					}
					else
					{
						component.volume = num * An0n_Patch_Plugin.yodelAndFallVolume.Value;
					}
					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
	{
		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;

		public static IEnumerator otherFaceYodelEnable(Character player)
		{
			yield return (object)new WaitForSeconds(1.7f);
			AnimatedMouth pmouth = ((Component)player).GetComponent<AnimatedMouth>();
			((Behaviour)pmouth).enabled = true;
		}

		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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			if (An0n_Patch_Plugin.enableFallDmgSounds.Value)
			{
				list.Insert(64, new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(PlayerControllerPatch), "selfDmgFallPlayAudio", (Type[])null, (Type[])null)));
			}
			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[1] { "A_Scout_Emote_Shrug" });
					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));
				}
			}
		}

		public static IEnumerator yodelEnable(float mult)
		{
			Character locPlayer = Player.localPlayer.character;
			yield return (object)new WaitForSeconds(1.7f * mult);
			yJump = false;
			Player.localPlayer.character.refs.animator.SetBool("Emote", false);
			((Behaviour)((Component)locPlayer).GetComponent<AnimatedMouth>()).enabled = true;
			locPlayer.refs.movement.movementForce = force;
			((Behaviour)locPlayer.refs.animations).enabled = true;
			yield return (object)new WaitForSeconds(10f * mult);
			yodel = false;
		}

		[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);
		}
	}
}