Decompiled source of UK CPAP v1.0.3

plugins/ultrakillParrySoundAndAudioReplacer.dll

Decompiled 5 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.1", FrameworkDisplayName = ".NET Framework 4.7.1")]
[assembly: AssemblyCompany("ultrakillParrySoundAndAudioReplacer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ultrakillParrySoundAndAudioReplacer")]
[assembly: AssemblyTitle("ultrakillParrySoundAndAudioReplacer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 ultrakillParrySoundAndAudioReplacer
{
	public class HarmonyPatches
	{
		private static Harmony instance;

		public const string InstanceId = "ultrakillParrySoundAndAudioReplacer";

		public static bool IsPatched { get; private set; }

		internal static void ApplyHarmonyPatches()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			if (!IsPatched)
			{
				if (instance == null)
				{
					instance = new Harmony("ultrakillParrySoundAndAudioReplacer");
				}
				instance.PatchAll(Assembly.GetExecutingAssembly());
				IsPatched = true;
			}
		}

		internal static void RemoveHarmonyPatches()
		{
			if (instance != null && IsPatched)
			{
				instance.UnpatchSelf();
				IsPatched = false;
			}
		}
	}
	[BepInPlugin("ultrakillParrySoundAndAudioReplacer", "ultrakillParrySoundAndAudioReplacer", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Lets make some noise!, " + Assets.AudioPath));
			HarmonyPatches.ApplyHarmonyPatches();
		}
	}
	[HarmonyPatch(typeof(HUDOptions))]
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal class HudPatch
	{
		private static void Postfix(HUDOptions __instance)
		{
			if ((Object)(object)((Component)__instance).GetComponent<AudioReplacer>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<AudioReplacer>();
			}
		}
	}
	public static class SoundConverter
	{
		public static int FindBitDepth(byte[] ByteArray)
		{
			byte[] array = new byte[2];
			for (int i = 0; i < 2; i++)
			{
				byte b = (array[i] = ByteArray[i + 34]);
				array[^1] = b;
			}
			return BitConverter.ToInt16(array, 0);
		}

		public static float[] ConvertByteToFloat(byte[] byteArray)
		{
			int num = (byteArray.Length - 44) / 2;
			float[] array = new float[num];
			switch (FindBitDepth(byteArray))
			{
			case 16:
			{
				for (int j = 0; j < num; j++)
				{
					short num3 = BitConverter.ToInt16(byteArray, 44 + j * 2);
					array[j] = (float)num3 / 32768f;
				}
				break;
			}
			case 32:
			{
				for (int i = 0; i < num; i++)
				{
					int num2 = BitConverter.ToInt32(byteArray, 44 + i * 4);
					array[i] = (float)num2 / 32768f;
				}
				break;
			}
			}
			return array;
		}

		public static int FindFrequency(byte[] ByteArray)
		{
			byte[] array = new byte[4];
			for (int i = 0; i < 3; i++)
			{
				byte b = (array[i] = ByteArray[i + 24]);
				array[^1] = b;
			}
			int num = BitConverter.ToInt32(array, 0);
			return num * 2;
		}
	}
	public static class Assets
	{
		private static string ModDir;

		public static string AudioPath;

		private static byte[] RawAudio;

		private static float[] FloatArray;

		private static int Frequency;

		public static AudioClip AudioParryClip;

		static Assets()
		{
			ModDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			AudioPath = Path.Combine(ModDir, "ParryNoise");
			RawAudio = File.ReadAllBytes(Path.Combine(AudioPath, "parry.wav"));
			FloatArray = SoundConverter.ConvertByteToFloat(RawAudio);
			Frequency = SoundConverter.FindFrequency(RawAudio);
			AudioParryClip = AudioClip.Create("ParryNoise", FloatArray.Length, 1, Frequency, false);
			AudioParryClip.SetData(FloatArray, 0);
		}
	}
	public class AudioReplacer : MonoBehaviour
	{
		private GameObject AudioClipObject;

		private GameObject ParryFlash;

		private AudioSource AudioSource;

		internal static ManualLogSource Logger;

		private void Awake()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			Console.WriteLine("Audio making");
			if ((Object)(object)ParryFlash == (Object)null)
			{
				ParryFlash = ((Component)((Component)this).transform.Find("ParryFlash")).gameObject;
				AudioClipObject = new GameObject("Audio Clip");
				AudioClipObject.SetActive(true);
				AudioSource = AudioClipObject.AddComponent<AudioSource>();
				AudioSource.playOnAwake = false;
				AudioSource.spatialBlend = 0f;
				AudioSource.volume = 1f;
				if ((Object)(object)Assets.AudioParryClip != (Object)null)
				{
					AudioSource.clip = Assets.AudioParryClip;
					AudioClipObject.transform.SetParent(((Component)this).gameObject.transform);
				}
			}
		}

		private void Update()
		{
			if ((Object)(object)ParryFlash != (Object)null && ParryFlash.activeSelf && !((Object)(object)AudioClipObject == (Object)null))
			{
				AudioSource.Play();
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "ultrakillParrySoundAndAudioReplacer";

		public const string PLUGIN_NAME = "ultrakillParrySoundAndAudioReplacer";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}