Decompiled source of ParryNoise v2.0.0

ParryNoisePlugin.dll

Decompiled 19 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
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: AssemblyTitle("ParryNoisePlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ParryNoisePlugin")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("8df2bcad-5899-40ae-bfca-ba5aa3ecf878")]
[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")]
[BepInPlugin("org.intdependent.parrynoise", "ParryNoise", "2.0.0")]
public class ParryNoisePlugin : BaseUnityPlugin
{
	[CompilerGenerated]
	private sealed class <LoadSound>d__5 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public ParryNoisePlugin <>4__this;

		private string <folder>5__1;

		private string <path>5__2;

		private UnityWebRequest <uwr>5__3;

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

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

		[DebuggerHidden]
		public <LoadSound>d__5(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();
				}
			}
			<folder>5__1 = null;
			<path>5__2 = null;
			<uwr>5__3 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Invalid comparison between Unknown and I4
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Invalid comparison between Unknown and I4
			try
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<folder>5__1 = Path.GetDirectoryName(((BaseUnityPlugin)<>4__this).Info.Location);
					<path>5__2 = Path.Combine(<folder>5__1, "parry.ogg");
					if (!File.Exists(<path>5__2))
					{
						Log.LogError((object)"parry.ogg not found!");
						return false;
					}
					<uwr>5__3 = UnityWebRequestMultimedia.GetAudioClip("file:///" + <path>5__2.Replace("\\", "/"), (AudioType)14);
					<>1__state = -3;
					<>2__current = <uwr>5__3.SendWebRequest();
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -3;
					if ((int)<uwr>5__3.result == 2 || (int)<uwr>5__3.result == 3)
					{
						Log.LogError((object)("Failed to load custom parry sound: " + <uwr>5__3.error));
					}
					else
					{
						customClip = DownloadHandlerAudioClip.GetContent(<uwr>5__3);
						((Object)customClip).name = "custom_parry";
						Log.LogInfo((object)"Successfully loaded custom parry sound");
						ApplyToExistingObjects();
					}
					<>m__Finally1();
					<uwr>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 (<uwr>5__3 != null)
			{
				((IDisposable)<uwr>5__3).Dispose();
			}
		}

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

	public static AudioClip customClip;

	public static ManualLogSource Log;

	private static readonly FieldInfo parryLightField = typeof(TimeController).GetField("parryLight", BindingFlags.Instance | BindingFlags.NonPublic);

	private static readonly FieldInfo parryFlashField = typeof(TimeController).GetField("parryFlash", BindingFlags.Instance | BindingFlags.NonPublic);

	private void Awake()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		new Harmony("org.intdependent.parrynoise").PatchAll();
		((MonoBehaviour)this).StartCoroutine(LoadSound());
		Log.LogInfo((object)"ParryNoise loaded");
	}

	[IteratorStateMachine(typeof(<LoadSound>d__5))]
	private IEnumerator LoadSound()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <LoadSound>d__5(0)
		{
			<>4__this = this
		};
	}

	public static void ApplyToExistingObjects()
	{
		TimeController instance = MonoSingleton<TimeController>.Instance;
		if ((Object)(object)instance != (Object)null)
		{
			ApplyCustomClip(instance);
		}
		Punch[] array = Resources.FindObjectsOfTypeAll<Punch>();
		Punch[] array2 = array;
		foreach (Punch punch in array2)
		{
			ApplyCustomClip(punch);
		}
	}

	public static void ApplyCustomClip(TimeController tc)
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Expected O, but got Unknown
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Expected O, but got Unknown
		if ((Object)(object)customClip == (Object)null || (Object)(object)tc == (Object)null)
		{
			return;
		}
		try
		{
			GameObject val = (GameObject)parryLightField.GetValue(tc);
			if ((Object)(object)val != (Object)null)
			{
				AudioSource[] componentsInChildren = val.GetComponentsInChildren<AudioSource>(true);
				AudioSource[] array = componentsInChildren;
				foreach (AudioSource val2 in array)
				{
					val2.clip = customClip;
					Log.LogInfo((object)"Replaced clip on parryLight AudioSource");
				}
			}
		}
		catch (Exception ex)
		{
			Log.LogError((object)("Error replacing parryLight sound: " + ex));
		}
		try
		{
			GameObject val3 = (GameObject)parryFlashField.GetValue(tc);
			if ((Object)(object)val3 != (Object)null)
			{
				AudioSource[] componentsInChildren2 = val3.GetComponentsInChildren<AudioSource>(true);
				AudioSource[] array2 = componentsInChildren2;
				foreach (AudioSource val4 in array2)
				{
					val4.clip = customClip;
					Log.LogInfo((object)"Replaced clip on parryFlash AudioSource");
				}
			}
		}
		catch (Exception ex2)
		{
			Log.LogError((object)("Error replacing parryFlash sound: " + ex2));
		}
	}

	public static void ApplyCustomClip(Punch punch)
	{
		if ((Object)(object)customClip == (Object)null || (Object)(object)punch == (Object)null)
		{
			return;
		}
		try
		{
			if ((Object)(object)punch.specialHit != (Object)null)
			{
				punch.specialHit.clip = customClip;
				Log.LogInfo((object)"Replaced clip on Punch.specialHit");
			}
		}
		catch (Exception ex)
		{
			Log.LogError((object)("Error replacing Punch.specialHit sound: " + ex));
		}
	}
}
[HarmonyPatch(typeof(TimeController), "Awake")]
internal class TimeControllerAwakePatch
{
	private static void Postfix(TimeController __instance)
	{
		ParryNoisePlugin.ApplyCustomClip(__instance);
	}
}
[HarmonyPatch(typeof(Punch), "Start")]
internal class PunchStartPatch
{
	private static void Postfix(Punch __instance)
	{
		ParryNoisePlugin.ApplyCustomClip(__instance);
	}
}