Decompiled source of UIMine v1.0.1

BepInEx/plugins/UIMineSound/UIMineSound.dll

Decompiled 11 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("UIMineSound")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UIMineSound")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("98e77627-3328-4f9c-bf3e-c5b793d17a8d")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace UIMineSound
{
	[BepInPlugin("KurisuBot.UIMineSound", "UIMineSound", "1.0.0")]
	public class UIMineSound : BaseUnityPlugin
	{
		public static UIMineSound instance;

		public static ConfigEntry<bool> silenceMines;

		internal ManualLogSource mls;

		private readonly Harmony harmony = new Harmony("KurisuBot.UIMineSound");

		internal static List<AudioClip> UI;

		internal static AssetBundle Bundle;

		internal static string text;

		private void Awake()
		{
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			text = ((BaseUnityPlugin)instance).Info.Location.TrimEnd("UIMineSound.dll".ToCharArray());
			mls = Logger.CreateLogSource("KurisuBot.UIMineSound");
			UI = new List<AudioClip>();
			Bundle = AssetBundle.LoadFromFile(text + "ui");
			if ((Object)(object)Bundle != (Object)null)
			{
				UI = Bundle.LoadAllAssets<AudioClip>().ToList();
			}
			mls.LogInfo((object)"UIMineSound Loading. . .");
			silenceMines = ((BaseUnityPlugin)this).Config.Bind<bool>("UIMines", "SilenceMines", false, "Silence the passive mine beeping.");
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			mls.LogInfo((object)"UIMineSound Loaded!!");
		}

		public static void Log(string message)
		{
			((BaseUnityPlugin)instance).Logger.LogInfo((object)message);
		}
	}
}
namespace UIMineSound.Patches
{
	[HarmonyPatch(typeof(Landmine))]
	internal class MinePatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void ReplaceSound(Landmine __instance, ref AudioSource ___mineAudio, ref AudioSource ___mineFarAudio, ref Animator ___mineAnimator)
		{
			if (UIMineSound.silenceMines.Value.Equals(obj: true))
			{
				((Behaviour)___mineAudio).enabled = false;
				((Behaviour)___mineFarAudio).enabled = false;
				___mineAnimator.speed = 0f;
			}
			__instance.mineTrigger = UIMineSound.UI[0];
		}

		[HarmonyPatch("PressMineServerRpc")]
		[HarmonyPrefix]
		private static void TurnBackOn(ref AudioSource ___mineAudio, ref AudioSource ___mineFarAudio, ref Animator ___mineAnimator)
		{
			___mineAnimator.speed = 1f;
			((Behaviour)___mineAudio).enabled = true;
			___mineAudio.pitch = 1f;
			((Behaviour)___mineFarAudio).enabled = true;
		}
	}
}