Decompiled source of ShutUp v0.1.0

plugins/ShutUp.dll

Decompiled 20 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ShutUp")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ShutUp")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("0.1.0.0")]
namespace ShutUp;

[BepInPlugin("orax.ShutUp", "ShutUp", "0.1.0")]
internal class ShutUp : BaseUnityPlugin
{
	[HarmonyPatch(typeof(ZSFX), "Awake")]
	private static class ZSFXMutePatch
	{
		private static void Postfix(ZSFX __instance)
		{
			string text = CloneSuffixRegex.Replace(((Object)((Component)__instance).gameObject).name.Trim(), string.Empty).Trim();
			if (_logSoundNames.Value)
			{
				Log.LogInfo((object)("Sound effect name: " + text));
			}
			if (MutedNames.Contains(text))
			{
				((Component)__instance).GetComponent<AudioSource>().mute = true;
				Log.LogDebug((object)("Muted sound effect: " + text));
			}
		}
	}

	public const string PluginGUID = "orax.ShutUp";

	public const string PluginName = "ShutUp";

	public const string PluginVersion = "0.1.0";

	internal static ManualLogSource Log;

	private static readonly Regex CloneSuffixRegex = new Regex("(?:\\(Clone\\))+$", RegexOptions.Compiled);

	private static ConfigEntry<bool> _enabled;

	private static ConfigEntry<string> _mutedSounds;

	private static ConfigEntry<bool> _logSoundNames;

	private static readonly HashSet<string> MutedNames = new HashSet<string>(StringComparer.Ordinal);

	private Harmony _harmony;

	private void Awake()
	{
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Set to false to disable the mod without uninstalling it.");
		_mutedSounds = ((BaseUnityPlugin)this).Config.Bind<string>("Sounds", "Muted sounds", "sfx_chicken_eat,sfx_chicken_idle_vocal,sfx_deer_alerted,sfx_deer_idle,sfx_wolf_haul", "Comma separated list of the exact sound names to mute.\nNames are matched case-sensitively, and the whole name has to match: 'sfx_wolf' does not mute 'sfx_wolf_haul'.\nThe '(Clone)' suffix is ignored, so names copied from the log work as they are.\nTurn on 'Log sound names' to find the names the game uses: they are written to the BepInEx log.");
		_logSoundNames = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Log sound names", false, "Write the name of every sound effect created by the game to the BepInEx log.\nUseful to find out which names to put in 'Muted sounds'.");
		_enabled.SettingChanged += OnSettingsChanged;
		_mutedSounds.SettingChanged += OnSettingsChanged;
		RebuildMuteList();
		_harmony = new Harmony("orax.ShutUp");
		_harmony.PatchAll();
		Log.LogInfo((object)string.Format("{0} has landed. {1} sound name(s) muted.", "ShutUp", MutedNames.Count));
	}

	private void OnDestroy()
	{
		Harmony harmony = _harmony;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
	}

	private static void OnSettingsChanged(object sender, EventArgs e)
	{
		RebuildMuteList();
	}

	private static void RebuildMuteList()
	{
		MutedNames.Clear();
		if (!_enabled.Value || string.IsNullOrEmpty(_mutedSounds.Value))
		{
			return;
		}
		string[] array = _mutedSounds.Value.Split(new char[1] { ',' });
		for (int i = 0; i < array.Length; i++)
		{
			string text = array[i].Trim();
			if (text.Length > 0)
			{
				MutedNames.Add(text);
			}
		}
	}
}