Decompiled source of ClientSide FallenDown v1.1.0

FallingMusicMod.dll

Decompiled a week 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.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
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(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("FallingMusicMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Plays music when falling")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0.0")]
[assembly: AssemblyProduct("FallingMusicMod")]
[assembly: AssemblyTitle("FallingMusicMod")]
[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 FallingMusicMod
{
	public class AudioSourcePlayer : MonoBehaviour
	{
		[CompilerGenerated]
		private sealed class <FadeOutAndPause>d__8 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public AudioSourcePlayer <>4__this;

			private float <startVolume>5__1;

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

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

			[DebuggerHidden]
			public <FadeOutAndPause>d__8(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<startVolume>5__1 = <>4__this._audioSource.volume;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (<>4__this._audioSource.volume > 0f)
				{
					AudioSource audioSource = <>4__this._audioSource;
					audioSource.volume -= <startVolume>5__1 * Time.deltaTime / <>4__this.fadeDuration;
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				<>4__this._audioSource.Pause();
				<>4__this._isPaused = true;
				<>4__this._audioSource.volume = <>4__this._originalVolume;
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

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

		[CompilerGenerated]
		private sealed class <LoadAudio>d__5 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public AudioSourcePlayer <>4__this;

			private string <audioPath>5__1;

			private string <fullPath>5__2;

			private UnityWebRequest <request>5__3;

			private AudioClip <clip>5__4;

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

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

			[DebuggerHidden]
			public <LoadAudio>d__5(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<audioPath>5__1 = null;
				<fullPath>5__2 = null;
				<request>5__3 = null;
				<clip>5__4 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<audioPath>5__1 = Path.Combine(FallenDownMod.PluginFolderPath, "Fallen Down.ogg");
					<fullPath>5__2 = "file://" + <audioPath>5__1;
					Debug.Log((object)("Attempting to load audio from: " + <fullPath>5__2));
					<request>5__3 = UnityWebRequestMultimedia.GetAudioClip(<fullPath>5__2, (AudioType)14);
					<>2__current = <request>5__3.SendWebRequest();
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					if (<request>5__3.isNetworkError || <request>5__3.isHttpError)
					{
						Debug.LogError((object)("UnityWebRequest Error: " + <request>5__3.error));
					}
					else
					{
						<clip>5__4 = DownloadHandlerAudioClip.GetContent(<request>5__3);
						if ((Object)(object)<clip>5__4 != (Object)null)
						{
							<>4__this._audioSource.clip = <clip>5__4;
							Debug.Log((object)"Successfully loaded audio clip!");
						}
						else
						{
							Debug.LogError((object)"Failed to get AudioClip from request.");
						}
						<clip>5__4 = null;
					}
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

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

		private AudioSource _audioSource;

		public float fadeDuration = 2f;

		private float _originalVolume;

		private bool _isPaused = false;

		private void Awake()
		{
			_audioSource = ((Component)this).gameObject.AddComponent<AudioSource>();
			_audioSource.loop = true;
			_originalVolume = 0.1f;
			_audioSource.volume = _originalVolume;
			((MonoBehaviour)this).StartCoroutine(LoadAudio());
		}

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

		public void PlayOrResume()
		{
			((MonoBehaviour)this).StopAllCoroutines();
			_audioSource.volume = _originalVolume;
			if (_isPaused)
			{
				_audioSource.UnPause();
			}
			else if (!_audioSource.isPlaying)
			{
				_audioSource.Play();
			}
			_isPaused = false;
		}

		public void InitiateFadeOut()
		{
			if (_audioSource.isPlaying)
			{
				((MonoBehaviour)this).StartCoroutine(FadeOutAndPause());
			}
		}

		[IteratorStateMachine(typeof(<FadeOutAndPause>d__8))]
		private IEnumerator FadeOutAndPause()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <FadeOutAndPause>d__8(0)
			{
				<>4__this = this
			};
		}
	}
	[BepInPlugin("com.holycross98.fallendownmod", "Fallen Down Mod", "1.0.0")]
	public class FallenDownMod : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Character), "Update")]
		private class FallenDownPatch
		{
			[HarmonyPostfix]
			private static void PostFix(Character __instance)
			{
				bool flag = __instance.data.currentStamina < 0.005f && __instance.data.extraStamina < 0.001f && __instance.data.avarageVelocity.y < -9f;
				bool flag2 = __instance.data.avarageVelocity.y < -13f;
				bool flag3 = __instance.refs.afflictions.statusSum < 1f;
				if (__instance.IsLocal)
				{
					if (!__instance.data.isGrounded && (flag || flag2) && !_isFallenDownMusicPlaying)
					{
						_audioPlayer.PlayOrResume();
						_isFallenDownMusicPlaying = true;
						((BaseUnityPlugin)_instance).Logger.LogInfo((object)"Started playing Fallen Down music.");
					}
					if (__instance.data.isGrounded && _isFallenDownMusicPlaying && (flag3 || __instance.data.deathTimer > 0.01f))
					{
						_audioPlayer.InitiateFadeOut();
						_isFallenDownMusicPlaying = false;
						((BaseUnityPlugin)_instance).Logger.LogInfo((object)"Stopped playing Fallen Down music. ");
					}
				}
			}
		}

		private static FallenDownMod _instance;

		private static AudioSourcePlayer _audioPlayer;

		private static bool _isFallenDownMusicPlaying;

		public static string PluginFolderPath { get; private set; }

		private void Awake()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			_instance = this;
			PluginFolderPath = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			Harmony val = new Harmony("com.holycross98.fallendownmod.harmony");
			val.PatchAll();
			GameObject val2 = new GameObject("FallenDownAudioPlayer");
			Object.DontDestroyOnLoad((Object)(object)val2);
			_audioPlayer = val2.AddComponent<AudioSourcePlayer>();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Fallen Down Mod has been loaded!");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "FallingMusicMod";

		public const string PLUGIN_NAME = "FallingMusicMod";

		public const string PLUGIN_VERSION = "1.0.0.0";
	}
}