Decompiled source of WeirdRouteJingleOnKnuckleblasterParry v0.1.0

WeirdRouteJingleOnKnuckleblasterParry.dll

Decompiled 15 hours ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
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("WeirdRouteJingleOnKnuckleblasterParry")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WeirdRouteJingleOnKnuckleblasterParry")]
[assembly: AssemblyTitle("WeirdRouteJingleOnKnuckleblasterParry")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace WeirdRouteJingleOnKnuckleblasterParry
{
	[BepInPlugin("tamersoup625.ultrakill.weirdrouteonknuckleparry", "Weird Route Jingle on Knuckleblaster Parry", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private class PluginPatches
		{
			[HarmonyPatch(typeof(Punch), "ActiveFrame")]
			[HarmonyPostfix]
			private static void DetectHeavyParry(Punch __instance, ref ProjectileParryZone ___ppz)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Invalid comparison between Unknown and I4
				if ((int)__instance.type != 1 || __instance.hitSomething)
				{
					return;
				}
				HeavyParryExtra orAddComponent = GameObjectExtensions.GetOrAddComponent<HeavyParryExtra>(((Component)__instance).gameObject);
				if (Time.time - orAddComponent.timeWhenParried < 0.3f)
				{
					return;
				}
				if ((Object)(object)___ppz == (Object)null)
				{
					___ppz = ((Component)((Component)__instance).transform.parent).GetComponentInChildren<ProjectileParryZone>();
				}
				if (!((Object)(object)___ppz != (Object)null))
				{
					return;
				}
				Projectile val = ___ppz.CheckParryZone();
				if ((Object)(object)val != (Object)null && !val.unparryable && !val.undeflectable)
				{
					Log.LogInfo((object)"Tried to parry projectile with the knuckleblaster");
					Log.LogInfo((object)val);
					orAddComponent.timeWhenParried = Time.time;
					if ((Object)(object)orAddComponent.audioSource == (Object)null)
					{
						orAddComponent.audioSource = ((Component)((Component)__instance).transform.parent).gameObject.AddComponent<AudioSource>();
						orAddComponent.audioSource.playOnAwake = false;
						orAddComponent.audioSource.clip = jingle;
					}
					orAddComponent.audioSource.Play();
				}
			}
		}

		private class HeavyParryExtra : MonoBehaviour
		{
			public float timeWhenParried;

			public AudioSource audioSource;
		}

		private static ManualLogSource Log;

		public static AudioClip jingle;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"WRJOKP Ready!");
			Harmony.CreateAndPatchAll(typeof(PluginPatches), (string)null);
			string text = string.Join(GetAssemblyFolder(), "/jingle.mp3");
			((MonoBehaviour)this).StartCoroutine(LoadJingle());
		}

		private IEnumerator LoadJingle()
		{
			string jingleUri = "file:///" + GetAssemblyFolder() + "/jingle.mp3";
			Log.LogInfo((object)jingleUri);
			UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(jingleUri, (AudioType)13);
			try
			{
				yield return www.SendWebRequest();
				if ((int)www.result == 2)
				{
					Log.LogInfo((object)"Failed to load jingle.mp3!");
					Log.LogInfo((object)www.error);
				}
				else
				{
					AudioClip audioClip = DownloadHandlerAudioClip.GetContent(www);
					jingle = audioClip;
				}
			}
			finally
			{
				((IDisposable)www)?.Dispose();
			}
		}

		private static string GetAssemblyFolder()
		{
			string codeBase = Assembly.GetExecutingAssembly().CodeBase;
			UriBuilder uriBuilder = new UriBuilder(codeBase);
			string path = Uri.UnescapeDataString(uriBuilder.Path);
			return Path.GetDirectoryName(path);
		}
	}
}