Decompiled source of HEYYEYAAEYAAAEYAEYAA LoudHorn v1.0.0

plugin/HEYYEYAAEYAAAEYAEYAALoudHorn.dll

Decompiled 10 months ago
using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("HEYYEYAAEYAAAEYAEYAALoudHorn")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Blast HEYYEYAAEYAAAEYAEYAA from the Loud Horn")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HEYYEYAAEYAAAEYAEYAA Loud Horn")]
[assembly: AssemblyTitle("HEYYEYAAEYAAAEYAEYAALoudHorn")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace HEYYEYAAEYAAAEYAEYAALoudHorn;

[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[DebuggerNonUserCode]
[CompilerGenerated]
internal class AudioResources
{
	private static ResourceManager resourceMan;

	private static CultureInfo resourceCulture;

	[EditorBrowsable(EditorBrowsableState.Advanced)]
	internal static ResourceManager ResourceManager
	{
		get
		{
			if (resourceMan == null)
			{
				resourceMan = new ResourceManager("HEYYEYAAEYAAAEYAEYAALoudHorn.AudioResources", typeof(AudioResources).Assembly);
			}
			return resourceMan;
		}
	}

	[EditorBrowsable(EditorBrowsableState.Advanced)]
	internal static CultureInfo Culture
	{
		get
		{
			return resourceCulture;
		}
		set
		{
			resourceCulture = value;
		}
	}

	internal static UnmanagedMemoryStream hey_loop => ResourceManager.GetStream("hey_loop", resourceCulture);

	internal static UnmanagedMemoryStream hey_loop_far => ResourceManager.GetStream("hey_loop_far", resourceCulture);

	internal AudioResources()
	{
	}
}
internal class PCMHelpers
{
	public readonly struct PcmHeader
	{
		private const int SizeIndex = 16;

		private readonly float _positiveDepth;

		private readonly float _negativeDepth;

		public int BitDepth { get; }

		public int AudioSampleSize { get; }

		public int AudioSampleCount { get; }

		public ushort Channels { get; }

		public int SampleRate { get; }

		public int AudioStartIndex { get; }

		public int ByteRate { get; }

		public ushort BlockAlign { get; }

		private PcmHeader(int bitDepth, int audioSize, int audioStartIndex, ushort channels, int sampleRate, int byteRate, ushort blockAlign)
		{
			BitDepth = bitDepth;
			_negativeDepth = Mathf.Pow(2f, (float)BitDepth - 1f);
			_positiveDepth = _negativeDepth - 1f;
			AudioSampleSize = bitDepth / 8;
			AudioSampleCount = Mathf.FloorToInt((float)audioSize / (float)AudioSampleSize);
			AudioStartIndex = audioStartIndex;
			Channels = channels;
			SampleRate = sampleRate;
			ByteRate = byteRate;
			BlockAlign = blockAlign;
		}

		public static PcmHeader FromBytes(byte[] pcmBytes)
		{
			using MemoryStream pcmStream = new MemoryStream(pcmBytes);
			return FromStream(pcmStream);
		}

		public static PcmHeader FromStream(Stream pcmStream)
		{
			pcmStream.Position = 16L;
			using BinaryReader binaryReader = new BinaryReader(pcmStream);
			int num = binaryReader.ReadInt32();
			ushort num2 = binaryReader.ReadUInt16();
			string audioFormatFromCode = GetAudioFormatFromCode(num2);
			if (num2 != 1 && num2 == 65534)
			{
				throw new ArgumentOutOfRangeException("pcmStream", $"Detected format code '{num2}' {audioFormatFromCode}, but only PCM and WaveFormatExtensible uncompressed formats are currently supported.");
			}
			ushort channels = binaryReader.ReadUInt16();
			int sampleRate = binaryReader.ReadInt32();
			int byteRate = binaryReader.ReadInt32();
			ushort blockAlign = binaryReader.ReadUInt16();
			ushort bitDepth = binaryReader.ReadUInt16();
			pcmStream.Position = 16 + num + 8;
			int audioSize = binaryReader.ReadInt32();
			return new PcmHeader(bitDepth, audioSize, (int)pcmStream.Position, channels, sampleRate, byteRate, blockAlign);
		}

		public float NormalizeSample(float rawSample)
		{
			float num = ((rawSample < 0f) ? _negativeDepth : _positiveDepth);
			return rawSample / num;
		}

		private static string GetAudioFormatFromCode(ushort code)
		{
			return code switch
			{
				1 => "PCM", 
				2 => "ADPCM", 
				3 => "IEEE", 
				7 => "?-law", 
				65534 => "WaveFormatExtensible", 
				_ => throw new ArgumentOutOfRangeException("code", code, "Unknown wav code format."), 
			};
		}
	}

	public readonly struct PcmData
	{
		public float[] Value { get; }

		public int Length { get; }

		public int Channels { get; }

		public int SampleRate { get; }

		private PcmData(float[] value, int channels, int sampleRate)
		{
			Value = value;
			Length = value.Length;
			Channels = channels;
			SampleRate = sampleRate;
		}

		public static PcmData FromBytes(byte[] bytes)
		{
			if (bytes == null)
			{
				throw new ArgumentNullException("bytes");
			}
			PcmHeader pcmHeader = PcmHeader.FromBytes(bytes);
			if (pcmHeader.BitDepth != 16 && pcmHeader.BitDepth != 32 && pcmHeader.BitDepth != 8)
			{
				throw new ArgumentOutOfRangeException("BitDepth", pcmHeader.BitDepth, "Supported values are: 8, 16, 32");
			}
			float[] array = new float[pcmHeader.AudioSampleCount];
			for (int i = 0; i < array.Length; i++)
			{
				int num = pcmHeader.AudioStartIndex + i * pcmHeader.AudioSampleSize;
				array[i] = pcmHeader.NormalizeSample(pcmHeader.BitDepth switch
				{
					8 => (int)bytes[num], 
					16 => BitConverter.ToInt16(bytes, num), 
					32 => BitConverter.ToInt32(bytes, num), 
					_ => throw new ArgumentOutOfRangeException("BitDepth", pcmHeader.BitDepth, "Supported values are: 8, 16, 32"), 
				});
			}
			return new PcmData(array, pcmHeader.Channels, pcmHeader.SampleRate);
		}
	}
}
[BepInPlugin("HEYYEYAAEYAAAEYAEYAALoudHorn", "HEYYEYAAEYAAAEYAEYAA Loud Horn", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	public ManualLogSource PluginLogger;

	public static AudioClip heMan;

	public static AudioClip heManFar;

	private void Awake()
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		PluginLogger = ((BaseUnityPlugin)this).Logger;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin HEYYEYAAEYAAAEYAEYAALoudHorn is loaded!");
		Harmony val = new Harmony("HEYYEYAAEYAAAEYAEYAALoudHorn");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Audio loading...");
		heMan = GetClipFromResources(AudioResources.hey_loop);
		heManFar = GetClipFromResources(AudioResources.hey_loop_far);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Audio loaded!");
		val.PatchAll();
	}

	private static AudioClip GetClipFromResources(UnmanagedMemoryStream audioResource, string clipName = "pcm")
	{
		MemoryStream memoryStream = new MemoryStream();
		audioResource.CopyTo(memoryStream);
		PCMHelpers.PcmData pcmData = PCMHelpers.PcmData.FromBytes(memoryStream.ToArray());
		AudioClip obj = AudioClip.Create(clipName, pcmData.Length, pcmData.Channels, pcmData.SampleRate, false);
		obj.SetData(pcmData.Value, 0);
		return obj;
	}
}
[HarmonyPatch(typeof(ShipAlarmCord))]
public class ShipHornPatch
{
	[HarmonyPatch("HoldCordDown")]
	[HarmonyPatch("PullCordClientRpc")]
	[HarmonyPatch("PullCordServerRpc")]
	[HarmonyPrefix]
	private static void SoundPatch(AudioSource ___hornClose, AudioSource ___hornFar)
	{
		___hornClose.clip = Plugin.heMan;
		___hornFar.clip = Plugin.heManFar;
	}
}
public static class PluginInfo
{
	public const string PLUGIN_GUID = "HEYYEYAAEYAAAEYAEYAALoudHorn";

	public const string PLUGIN_NAME = "HEYYEYAAEYAAAEYAEYAA Loud Horn";

	public const string PLUGIN_VERSION = "1.0.0";
}