Decompiled source of WishboneMute v1.0.0

WishboneMute.dll

Decompiled 9 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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("WishboneMute")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WishboneMute")]
[assembly: AssemblyTitle("WishboneMute")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace WishboneMute
{
	[BepInPlugin("com.Azura.wishbonemute", "WishboneMute", "1.0.0")]
	public class WishboneMutePlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "com.Azura.wishbonemute";

		public const string PluginName = "WishboneMute";

		public const string PluginVersion = "1.0.0";

		public static ConfigEntry<KeyCode> ToggleKey;

		public static ConfigEntry<bool> MuteAudio;

		public static ConfigEntry<bool> ShowNotification;

		public static bool IsFinderUpdating;

		public static bool IsMuted
		{
			get
			{
				if (MuteAudio != null)
				{
					return MuteAudio.Value;
				}
				return false;
			}
		}

		private void Awake()
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			ToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Général", "ToucheBasculement", (KeyCode)289, "Touche pour couper ou réactiver le son du bréchet (Wishbone).");
			MuteAudio = ((BaseUnityPlugin)this).Config.Bind<bool>("Général", "CouperSonBrechet", true, "Si activé, l'effet sonore du bréchet est coupé (le visuel reste actif).");
			ShowNotification = ((BaseUnityPlugin)this).Config.Bind<bool>("Général", "AfficherNotificationHUD", true, "Affiche un message à l'écran lors du basculement.");
			new Harmony("com.Azura.wishbonemute").PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("{0} v{1} chargé avec succès. Touche: {2}, Mute: {3}", "WishboneMute", "1.0.0", ToggleKey.Value, MuteAudio.Value));
		}

		private void Update()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			if (ToggleKey != null && Input.GetKeyDown(ToggleKey.Value))
			{
				MuteAudio.Value = !MuteAudio.Value;
				string text = (MuteAudio.Value ? "MUTÉ (Silencieux)" : "ACTIF (Sonore)");
				((BaseUnityPlugin)this).Logger.LogInfo((object)("[WishboneMute] Son du bréchet: " + text));
				if (ShowNotification.Value && (Object)(object)Player.m_localPlayer != (Object)null && (Object)(object)MessageHud.instance != (Object)null)
				{
					MessageHud.instance.ShowMessage((MessageType)1, "Bréchet audio : " + text, 0, (Sprite)null, false, true);
				}
			}
		}
	}
	[HarmonyPatch(typeof(SE_Finder), "UpdateStatusEffect")]
	public static class SE_Finder_UpdateStatusEffect_Patch
	{
		[HarmonyPrefix]
		public static void Prefix()
		{
			WishboneMutePlugin.IsFinderUpdating = true;
		}

		[HarmonyPostfix]
		[HarmonyFinalizer]
		public static void Finalizer()
		{
			WishboneMutePlugin.IsFinderUpdating = false;
		}
	}
	[HarmonyPatch(typeof(EffectList), "Create")]
	public static class EffectList_Create_Patch
	{
		[HarmonyPostfix]
		public static void Postfix(ref GameObject[] __result)
		{
			if (!WishboneMutePlugin.IsFinderUpdating || !WishboneMutePlugin.IsMuted || __result == null)
			{
				return;
			}
			for (int i = 0; i < __result.Length; i++)
			{
				GameObject val = __result[i];
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				AudioSource[] componentsInChildren = val.GetComponentsInChildren<AudioSource>(true);
				foreach (AudioSource val2 in componentsInChildren)
				{
					if ((Object)(object)val2 != (Object)null)
					{
						val2.mute = true;
						val2.volume = 0f;
						val2.clip = null;
						val2.Stop();
						((Behaviour)val2).enabled = false;
					}
				}
				ZSFX[] componentsInChildren2 = val.GetComponentsInChildren<ZSFX>(true);
				foreach (ZSFX val3 in componentsInChildren2)
				{
					if ((Object)(object)val3 != (Object)null)
					{
						val3.Stop();
						((Behaviour)val3).enabled = false;
					}
				}
				if (!((Object)(object)val.GetComponentInChildren<ParticleSystem>(true) != (Object)null) && !((Object)(object)val.GetComponentInChildren<Renderer>(true) != (Object)null) && !((Object)(object)val.GetComponentInChildren<Light>(true) != (Object)null) && (componentsInChildren.Length != 0 || componentsInChildren2.Length != 0 || ((Object)val).name.IndexOf("sfx", StringComparison.OrdinalIgnoreCase) >= 0))
				{
					val.SetActive(false);
				}
			}
		}
	}
}