Decompiled source of RandomPing v0.1.2

plugins/RandomPing.dll

Decompiled 3 days 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 Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RandomPing")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.2.0")]
[assembly: AssemblyInformationalVersion("0.1.2+8076be89b5a3c4118e7f774d65d8c09981bc888c")]
[assembly: AssemblyProduct("RandomPing")]
[assembly: AssemblyTitle("RandomPing")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/CarrieForle/RandomPingSilksong")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.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]
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace Microsoft.CodeAnalysis
{
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace RandomPing
{
	[BepInPlugin("io.github.carrieforle.randomping", "RandomPing", "0.1.2")]
	public class RandomPingPlugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private sealed class <GetAudioFile>d__6 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public RandomPingPlugin <>4__this;

			private string <targetAudioFile>5__2;

			private UnityWebRequest <www>5__3;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || num == 1)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<targetAudioFile>5__2 = null;
				<www>5__3 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0095: Unknown result type (might be due to invalid IL or missing references)
				//IL_009b: Invalid comparison between Unknown and I4
				bool result;
				try
				{
					int num = <>1__state;
					RandomPingPlugin randomPingPlugin = <>4__this;
					switch (num)
					{
					default:
						result = false;
						break;
					case 0:
						<>1__state = -1;
						<targetAudioFile>5__2 = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)randomPingPlugin).Info.Location), "assets", "ping.mp3");
						<www>5__3 = UnityWebRequestMultimedia.GetAudioClip(new Uri(<targetAudioFile>5__2), (AudioType)13);
						<>1__state = -3;
						<>2__current = <www>5__3.SendWebRequest();
						<>1__state = 1;
						result = true;
						break;
					case 1:
						<>1__state = -3;
						if ((int)<www>5__3.result != 1)
						{
							((BaseUnityPlugin)randomPingPlugin).Logger.LogError((object)("Failed to read audio at \"" + <targetAudioFile>5__2 + "\": " + <www>5__3.error));
						}
						else
						{
							randomPingPlugin.pingAudioClip = DownloadHandlerAudioClip.GetContent(<www>5__3);
							if ((Object)(object)randomPingPlugin.pingAudioClip == (Object)null)
							{
								((BaseUnityPlugin)randomPingPlugin).Logger.LogError((object)("Failed to read audio at \"" + <targetAudioFile>5__2 + "\""));
							}
							else
							{
								randomPingPlugin.pingAudioClip.LoadAudioData();
								randomPingPlugin.pingAudioSource.clip = randomPingPlugin.pingAudioClip;
							}
						}
						result = false;
						<>m__Finally1();
						break;
					}
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
				return result;
			}

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

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<www>5__3 != null)
				{
					((IDisposable)<www>5__3).Dispose();
				}
			}

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

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

			private object <>2__current;

			public RandomPingPlugin <>4__this;

			private bool <playTwice>5__2;

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

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

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

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

			private bool MoveNext()
			{
				//IL_0074: Unknown result type (might be due to invalid IL or missing references)
				//IL_007e: Expected O, but got Unknown
				int num = <>1__state;
				RandomPingPlugin randomPingPlugin = <>4__this;
				if (num != 0)
				{
					if (num != 1)
					{
						return false;
					}
					<>1__state = -1;
					randomPingPlugin.pingAudioSource.PlayOneShot(randomPingPlugin.pingAudioClip, 0.4f);
					if (<playTwice>5__2)
					{
						randomPingPlugin.pingAudioSource.PlayDelayed((float)Random.Range(2, 5));
					}
				}
				else
				{
					<>1__state = -1;
					if ((Object)(object)randomPingPlugin.pingAudioClip == (Object)null)
					{
						return false;
					}
				}
				int num2 = Random.Range(60, 2700);
				<playTwice>5__2 = Random.RandomRangeInt(0, 5) == 0;
				((BaseUnityPlugin)randomPingPlugin).Logger.LogDebug((object)$"Next ping is scheduled in the next {num2:F0} seconds (playTwice: {<playTwice>5__2})");
				<>2__current = (object)new WaitForSecondsRealtime((float)num2);
				<>1__state = 1;
				return true;
			}

			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 <Start>d__5 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public RandomPingPlugin <>4__this;

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

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

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

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

			private bool MoveNext()
			{
				int num = <>1__state;
				RandomPingPlugin randomPingPlugin = <>4__this;
				switch (num)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = ((MonoBehaviour)randomPingPlugin).StartCoroutine(randomPingPlugin.GetAudioFile());
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>2__current = ((MonoBehaviour)randomPingPlugin).StartCoroutine(randomPingPlugin.RandomlyPing());
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -1;
					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 AudioClip? pingAudioClip;

		private AudioSource pingAudioSource;

		private GameObject go;

		private const float volume = 0.4f;

		public const string Id = "io.github.carrieforle.randomping";

		public static string Name => "RandomPing";

		public static string Version => "0.1.2";

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			go = new GameObject("RandomPing");
			Object.DontDestroyOnLoad((Object)(object)go);
			pingAudioSource = go.AddComponent<AudioSource>();
			pingAudioSource.volume = 0.4f;
		}

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

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

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