Decompiled source of DeathSoundMod v1.0.4

UltrakillDeathSoundMod.dll

Decompiled a day 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 Microsoft.CodeAnalysis;
using PluginConfig.API;
using PluginConfig.API.Fields;
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("UltrakillDeathSoundMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("UltrakillDeathSoundMod")]
[assembly: AssemblyTitle("UltrakillDeathSoundMod")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
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;
		}
	}
	[CompilerGenerated]
	[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 UltrakillDeathSoundMod
{
	[BepInPlugin("celinathemadlass.Ultrakill.DeathSoundMod", "Ultrakill Death Sound Mod", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Main : BaseUnityPlugin
	{
		private enum PlaybackType
		{
			Replace,
			Add
		}

		private NewMovement? PlayerScript;

		private AudioClip NewDeathSound = null;

		private bool TrackedDeathState;

		private PluginConfigurator PluginConfig = null;

		private EnumField<PlaybackType> SoundPlaybackPanel = null;

		private FloatField VolumePanel = null;

		private string SoundFilePath = null;

		private bool LoadingSound = false;

		private AudioSource AddAudioSource = null;

		private AudioClip OldAudioClip = null;

		private IEnumerator RemoveAfterPlayback(float PlaybackLength, AudioSource DeletedSource)
		{
			yield return (object)new WaitForSeconds(PlaybackLength);
			Object.Destroy((Object)(object)DeletedSource);
		}

		private IEnumerator LoadSound()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loading new death sound");
			LoadingSound = true;
			UnityWebRequest AudioFile = UnityWebRequestMultimedia.GetAudioClip(SoundFilePath, (AudioType)13);
			try
			{
				yield return AudioFile.SendWebRequest();
				if ((int)AudioFile.result == 2)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)AudioFile.error);
				}
				else
				{
					if (AudioFile.responseCode == 404)
					{
						((BaseUnityPlugin)this).Logger.LogError((object)"The file for the path 'deathsound.mp3' has not been found! Verify it's there!");
					}
					NewDeathSound = DownloadHandlerAudioClip.GetContent(AudioFile);
				}
			}
			finally
			{
				((IDisposable)AudioFile)?.Dispose();
			}
			LoadingSound = false;
		}

		private void Awake()
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)4;
			TrackedDeathState = false;
			PluginConfig = PluginConfigurator.Create("Death Sound Mod", "celinathemadlass.Ultrakill.DeathSoundMod");
			SoundPlaybackPanel = new EnumField<PlaybackType>(PluginConfig.rootPanel, "Sound Playback Mode", "sound_playback", PlaybackType.Replace);
			VolumePanel = new FloatField(PluginConfig.rootPanel, "Sound Volume", "sound_volume", 100f);
			VolumePanel.maximumValue = 100f;
			VolumePanel.minimumValue = 0f;
			string location = Assembly.GetExecutingAssembly().Location;
			SoundFilePath = Path.Combine(Path.GetDirectoryName(location), "deathsound.mp3");
			string text = Path.Combine(Path.GetDirectoryName(location), "icon.png");
			((BaseUnityPlugin)this).Logger.LogWarning((object)SoundFilePath);
			PluginConfig.SetIconWithURL("file://" + text);
			((MonoBehaviour)this).StartCoroutine(LoadSound());
		}

		private void Update()
		{
			if ((Object)(object)PlayerScript == (Object)null)
			{
				PlayerScript = MonoSingleton<NewMovement>.Instance;
				if ((Object)(object)PlayerScript == (Object)null)
				{
					return;
				}
			}
			if (PlayerScript.dead && !TrackedDeathState)
			{
				TrackedDeathState = true;
				DeathSequence deathSequence = PlayerScript.deathSequence;
				AudioSource component = ((Component)((Component)deathSequence).transform).GetComponent<AudioSource>();
				if ((Object)(object)AddAudioSource == (Object)null)
				{
					OldAudioClip = component.clip;
					AddAudioSource = Object.Instantiate<AudioSource>(component);
					((Component)AddAudioSource).transform.SetParent(((Component)deathSequence).transform);
				}
				if (SoundPlaybackPanel.value == PlaybackType.Replace)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)"Replacing death sound with new one");
					((Behaviour)component).enabled = true;
					component.bypassEffects = true;
					component.bypassListenerEffects = true;
					component.Stop();
					component.clip = NewDeathSound;
					component.volume = VolumePanel.value / 100f;
					component.Play();
				}
				else if (SoundPlaybackPanel.value == PlaybackType.Add)
				{
					component.Stop();
					component.clip = OldAudioClip;
					component.Play();
					((BaseUnityPlugin)this).Logger.LogInfo((object)"Adding new death sound ontop");
					((Component)AddAudioSource).transform.SetParent(((Component)deathSequence).transform);
					((Behaviour)AddAudioSource).enabled = true;
					AddAudioSource.bypassEffects = true;
					AddAudioSource.bypassListenerEffects = true;
					AddAudioSource.Stop();
					AddAudioSource.clip = NewDeathSound;
					AddAudioSource.volume = VolumePanel.value / 100f;
					AddAudioSource.Play();
				}
			}
			else if (!PlayerScript.dead && TrackedDeathState)
			{
				TrackedDeathState = false;
			}
		}
	}
}