Decompiled source of MuteSound v0.1.1

MuteSound.dll

Decompiled 8 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using NineSolsAPI;
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("MuteSound")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("MuteSound")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MuteSound")]
[assembly: AssemblyTitle("MuteSound")]
[assembly: AssemblyVersion("1.0.0.0")]
[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.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;
		}
	}
}
internal sealed class ConfigurationManagerAttributes
{
	public delegate void CustomHotkeyDrawerFunc(ConfigEntryBase setting, ref bool isCurrentlyAcceptingInput);

	public bool? ShowRangeAsPercent;

	public Action<ConfigEntryBase> CustomDrawer;

	public CustomHotkeyDrawerFunc CustomHotkeyDrawer;

	public bool? Browsable;

	public string Category;

	public object DefaultValue;

	public bool? HideDefaultButton;

	public bool? HideSettingName;

	public string Description;

	public string DispName;

	public int? Order;

	public bool? ReadOnly;

	public bool? IsAdvanced;

	public Func<object, string> ObjToStr;

	public Func<string, object> StrToObj;
}
namespace MuteSound
{
	internal static class Log
	{
		private static ManualLogSource? logSource;

		internal static void Init(ManualLogSource logSource)
		{
			Log.logSource = logSource;
		}

		internal static void Debug(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogDebug(data);
			}
		}

		internal static void Error(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogError(data);
			}
		}

		internal static void Fatal(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogFatal(data);
			}
		}

		internal static void Info(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogInfo(data);
			}
		}

		internal static void Message(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogMessage(data);
			}
		}

		internal static void Warning(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogWarning(data);
			}
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("MuteSound", "MuteSound", "1.0.0")]
	public class MuteSound : BaseUnityPlugin
	{
		public ConfigEntry<bool> isMute;

		public ConfigEntry<bool> isToast;

		public ConfigEntry<bool> isToastMute;

		public ConfigEntry<string> muteSoundNames;

		public HashSet<string> muteSoundSet = new HashSet<string>();

		private Harmony harmony;

		public static MuteSound Instance { get; private set; }

		private void Awake()
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Expected O, but got Unknown
			Instance = this;
			Log.Init(((BaseUnityPlugin)this).Logger);
			RCGLifeCycle.DontDestroyForever(((Component)this).gameObject);
			harmony = Harmony.CreateAndPatchAll(typeof(MuteSound).Assembly, (string)null);
			isMute = ((BaseUnityPlugin)this).Config.Bind<bool>("Enable", "Mute Sound", false, "Mute specific sounds by name");
			isToast = ((BaseUnityPlugin)this).Config.Bind<bool>("", "Toast Play SoundName", false, new ConfigDescription("Show toast messages for sound playback", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 2
				}
			}));
			isToastMute = ((BaseUnityPlugin)this).Config.Bind<bool>("", "Toast Mute SoundName", false, new ConfigDescription("Show mute sound playback", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 1
				}
			}));
			muteSoundNames = ((BaseUnityPlugin)this).Config.Bind<string>("Filter", "MuteSoundNames", "", "Comma-separated list of sound names to mute (e.g., sound1,sound2,sound3)");
			UpdateMuteSoundSet();
			muteSoundNames.SettingChanged += delegate
			{
				OnMuteSoundNamesChanged();
			};
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin MuteSound is loaded!");
		}

		private void UpdateMuteSoundSet()
		{
			muteSoundSet = (from name in muteSoundNames.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries)
				select name.Trim()).ToHashSet();
		}

		private void OnMuteSoundNamesChanged()
		{
			UpdateMuteSoundSet();
		}

		private void OnDestroy()
		{
			harmony.UnpatchSelf();
		}
	}
	[HarmonyPatch]
	public class Patches
	{
		[HarmonyPatch(typeof(SoundManager), "PlaySound")]
		[HarmonyPrefix]
		private static bool PatchPlaySound(SoundManager __instance, string soundName, GameObject soundEmitter, EventCallback endCallback = null)
		{
			if (MuteSound.Instance.isToast.Value)
			{
				ToastManager.Toast((object)("Play sound: " + soundName));
			}
			if (MuteSound.Instance.muteSoundSet.Contains(soundName))
			{
				if (MuteSound.Instance.isToastMute.Value)
				{
					ToastManager.Toast((object)("Muted sound: " + soundName));
				}
				return !MuteSound.Instance.isMute.Value;
			}
			return true;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "MuteSound";

		public const string PLUGIN_NAME = "MuteSound";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}