Decompiled source of Roblox Subspace Tripmine sound v1.0.1

Roblox Landmine Sound.dll

Decompiled a month 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.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Roblox_Landmine_Sound.Patches;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Roblox Landmine Sound")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Roblox Landmine Sound")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("95847af7-29c0-4bfe-8a01-3471b470aa65")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Roblox_Landmine_Sound
{
	internal class CoroutineRunner : MonoBehaviour
	{
		private static CoroutineRunner _instance;

		public static CoroutineRunner Instance
		{
			get
			{
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Expected O, but got Unknown
				if ((Object)(object)_instance == (Object)null)
				{
					GameObject val = new GameObject("CoroutineRunner");
					_instance = val.AddComponent<CoroutineRunner>();
					Object.DontDestroyOnLoad((Object)(object)val);
				}
				return _instance;
			}
		}

		public void RunCoroutine(IEnumerator routine)
		{
			((MonoBehaviour)this).StartCoroutine(routine);
		}
	}
	[BepInPlugin("float.RobloxLandmineSound", "Roblox Subspace Mine Sounds", "1.0.1.0")]
	public class RobloxLandmine : BaseUnityPlugin
	{
		private const string modGUID = "float.RobloxLandmineSound";

		private const string modName = "Roblox Subspace Mine Sounds";

		private const string modVersion = "1.0.1.0";

		private readonly Harmony harmony = new Harmony("float.RobloxLandmineSound");

		public static RobloxLandmine Instance;

		public static AudioClip newDetonateClip;

		internal ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("float.RobloxLandmineSound");
			mls.LogInfo((object)"Landmine sound mod awake");
			harmony.PatchAll(typeof(RobloxLandmine));
			harmony.PatchAll(typeof(LandmineDetonateSoundPatch));
		}
	}
}
namespace Roblox_Landmine_Sound.Patches
{
	[HarmonyPatch(typeof(Landmine), "Start")]
	internal class LandmineDetonateSoundPatch
	{
		[CompilerGenerated]
		private sealed class <LoadAudioClipFromFile>d__0 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public string filePath;

			public ManualLogSource mls;

			public Action<AudioClip> onLoaded;

			private string <url>5__1;

			private UnityWebRequest <www>5__2;

			private AudioClip <clip>5__3;

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

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

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

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

			private bool MoveNext()
			{
				//IL_0165: Unknown result type (might be due to invalid IL or missing references)
				//IL_016b: Invalid comparison between Unknown and I4
				//IL_0064: Unknown result type (might be due to invalid IL or missing references)
				//IL_006e: Expected O, but got Unknown
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						mls.LogInfo((object)"Waiting for unity to start!");
						<>2__current = (object)new WaitUntil((Func<bool>)delegate
						{
							//IL_0000: Unknown result type (might be due to invalid IL or missing references)
							//IL_0005: Unknown result type (might be due to invalid IL or missing references)
							Scene activeScene = SceneManager.GetActiveScene();
							return ((Scene)(ref activeScene)).name != "";
						});
						<>1__state = 1;
						return true;
					case 1:
						<>1__state = -1;
						if (!File.Exists(filePath))
						{
							mls.LogError((object)("Audio file does not exist: " + filePath));
							return false;
						}
						mls.LogInfo((object)("Loading landmine detonate audio clip from: " + filePath));
						<url>5__1 = "file://" + filePath.Replace("\\", "/");
						<www>5__2 = UnityWebRequestMultimedia.GetAudioClip(<url>5__1, (AudioType)13);
						<>1__state = -3;
						mls.LogInfo((object)"Sending web request");
						<>2__current = <www>5__2.SendWebRequest();
						<>1__state = 2;
						return true;
					case 2:
						<>1__state = -3;
						mls.LogInfo((object)"Web request completed");
						if ((int)<www>5__2.result != 1)
						{
							mls.LogInfo((object)("Failed to load audio: " + <www>5__2.error));
							onLoaded?.Invoke(null);
						}
						else
						{
							mls.LogInfo((object)"Successfully loaded audio!");
							<clip>5__3 = DownloadHandlerAudioClip.GetContent(<www>5__2);
							onLoaded?.Invoke(<clip>5__3);
							<clip>5__3 = null;
						}
						<>m__Finally1();
						<www>5__2 = null;
						return false;
					}
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
			}

			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__2 != null)
				{
					((IDisposable)<www>5__2).Dispose();
				}
			}

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

		[IteratorStateMachine(typeof(<LoadAudioClipFromFile>d__0))]
		public static IEnumerator LoadAudioClipFromFile(string filePath, ManualLogSource mls, Action<AudioClip> onLoaded)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <LoadAudioClipFromFile>d__0(0)
			{
				filePath = filePath,
				mls = mls,
				onLoaded = onLoaded
			};
		}

		[HarmonyPostfix]
		private static void DetonateSoundPatch(Landmine __instance)
		{
			string filePath = Path.Combine(Path.GetDirectoryName(typeof(RobloxLandmine).Assembly.Location), "DetonateSound.mp3");
			CoroutineRunner.Instance.RunCoroutine(LoadAudioClipFromFile(filePath, RobloxLandmine.Instance.mls, delegate(AudioClip clip)
			{
				if ((Object)(object)clip != (Object)null)
				{
					__instance.mineDetonate = clip;
					RobloxLandmine.Instance.mls.LogInfo((object)"Tripmine detonate sound loaded!");
				}
			}));
		}
	}
}