Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of SilencePlease v1.1.2
SilencePlease-1.1.2.dll
Decompiled 4 days agousing 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.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; 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("SilencePlease")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("SilencePlease")] [assembly: AssemblyCopyright("Copyright © 2025")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("b2e7c8a1-4e2d-4c6a-9e2a-1f3e8b7d2c4f")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = "")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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] [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] [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 SilencePlease { [BepInPlugin("org.bepinex.plugins.silenceplease", "Silence Please", "1.1.2")] [BepInIncompatibility("org.bepinex.plugins.valheim_plus")] public class SilencePlease : BaseUnityPlugin { public enum WolfSilenceMode { Off, CubsInRange, On } public enum LogMode { Off, On, UniqueOnly } private sealed class MuteStateCleanup : MonoBehaviour { private AudioSource audioSource = null; public void Initialize(AudioSource source) { audioSource = source; } private void OnDestroy() { originalMuteStates.Remove(audioSource); } } [HarmonyPatch(typeof(ZSFX), "Awake")] private static class RemoveSounds { private static void Postfix(ZSFX __instance) { string prefabName = Utils.GetPrefabName(((Component)__instance).gameObject); bool muted = ShouldMute(__instance, prefabName); AudioSource component = ((Component)__instance).GetComponent<AudioSource>(); if (!((Object)(object)component != (Object)null)) { return; } SetModMute(component, muted); switch (logMode.Value) { case LogMode.On: logger.LogInfo((object)$"Sound effect {prefabName} initialized. Muted: {component.mute}."); break; case LogMode.UniqueOnly: if (loggedPrefabs.Add(prefabName)) { logger.LogInfo((object)$"Sound effect {prefabName} initialized. Muted: {component.mute}."); } break; } } } private const string ModName = "Silence Please"; private const string ModVersion = "1.1.2"; private const string ModGUID = "org.bepinex.plugins.silenceplease"; private static ConfigEntry<string> muteSounds = null; private static readonly HashSet<string> mutedSoundsList = new HashSet<string>(); private static readonly HashSet<string> loggedPrefabs = new HashSet<string>(); private static readonly Dictionary<AudioSource, bool> originalMuteStates = new Dictionary<AudioSource, bool>(); private static ConfigEntry<LogMode> logMode = null; private static ConfigEntry<bool> silenceChickens = null; private static ConfigEntry<float> wolfSilenceRange = null; private static ConfigEntry<bool> silenceShieldGenerators = null; private static ConfigEntry<WolfSilenceMode> wolfSilenceMode = null; private static ConfigEntry<bool> muteEnabled = null; private static ConfigEntry<bool> silenceAsksvin = null; private static SilencePlease selfReference = null; private static ManualLogSource logger => ((BaseUnityPlugin)selfReference).Logger; public void Awake() { //IL_0224: Unknown result type (might be due to invalid IL or missing references) //IL_022a: Expected O, but got Unknown selfReference = this; muteEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enable Mod", true, "Enable/Disable mod"); muteSounds = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Mute Sounds", "", "Comma separated list of the sound effects you want to mute"); silenceChickens = ((BaseUnityPlugin)this).Config.Bind<bool>("Quick Mute", "Silence Chickens", false, "If on, mutes the chicken sound effect (sfx_love)."); silenceShieldGenerators = ((BaseUnityPlugin)this).Config.Bind<bool>("Quick Mute", "Silence Shield Generators", false, "If on, mutes the shield generator sound effect (sfx_shieldgenerator_powered_loop)."); wolfSilenceMode = ((BaseUnityPlugin)this).Config.Bind<WolfSilenceMode>("Quick Mute", "Silence Wolves", WolfSilenceMode.Off, "Controls if wolf howls are muted. 'CubsInRange' only mutes howls if a wolf cub is in range."); silenceAsksvin = ((BaseUnityPlugin)this).Config.Bind<bool>("Quick Mute", "Silence Asksvin", false, "If on, mutes the asksvin sound effects (sfx_asksvin_footstep, sfx_asksvin_idle)."); wolfSilenceRange = ((BaseUnityPlugin)this).Config.Bind<float>("Advanced", "Wolf Silence Range", 30f, "Range to check for nearby wolves when silencing howls."); logMode = ((BaseUnityPlugin)this).Config.Bind<LogMode>("Advanced", "Log Sounds", LogMode.Off, "Controls sound effect logging: Off, On (log all), or UniqueOnly (log each prefab once per session)."); muteSounds.SettingChanged += UpdateMuteList; muteEnabled.SettingChanged += UpdateMuteList; silenceChickens.SettingChanged += UpdateMuteList; silenceShieldGenerators.SettingChanged += UpdateMuteList; wolfSilenceMode.SettingChanged += UpdateMuteList; wolfSilenceRange.SettingChanged += UpdateMuteList; silenceAsksvin.SettingChanged += UpdateMuteList; Assembly executingAssembly = Assembly.GetExecutingAssembly(); Harmony val = new Harmony("org.bepinex.plugins.silenceplease"); val.PatchAll(executingAssembly); UpdateMuteList(null, null); } private static void UpdateMuteList(object? sender, EventArgs? e) { mutedSoundsList.Clear(); if (muteEnabled.Value) { string[] array = muteSounds.Value.Split(new char[1] { ',' }); foreach (string text in array) { string text2 = text.Trim(); if (!string.IsNullOrEmpty(text2)) { mutedSoundsList.Add(text2); } } if (silenceChickens.Value) { mutedSoundsList.Add("sfx_love"); } if (silenceShieldGenerators.Value) { mutedSoundsList.Add("sfx_shieldgenerator_powered_loop"); } if (silenceAsksvin.Value) { mutedSoundsList.Add("sfx_asksvin_footstep"); mutedSoundsList.Add("sfx_asksvin_idle"); } } ZSFX[] array2 = Object.FindObjectsByType<ZSFX>((FindObjectsSortMode)0); foreach (ZSFX val in array2) { string prefabName = Utils.GetPrefabName(((Component)val).gameObject); AudioSource component = ((Component)val).GetComponent<AudioSource>(); if ((Object)(object)component == (Object)null) { continue; } bool flag = originalMuteStates.ContainsKey(component); bool flag2 = ShouldMute(val, prefabName); SetModMute(component, flag2); if (flag2 && !flag) { if (logMode.Value == LogMode.On) { logger.LogInfo((object)("Muted already-active sound effect " + prefabName + " due to mute list update.")); } } else if (!flag2 && flag && logMode.Value == LogMode.On) { logger.LogInfo((object)("Restored the original mute state for " + prefabName + ".")); } } foreach (AudioSource item in new List<AudioSource>(originalMuteStates.Keys)) { if ((Object)(object)item == (Object)null) { originalMuteStates.Remove(item); } } } private static bool ShouldMute(ZSFX zsfx, string prefabName) { //IL_0067: Unknown result type (might be due to invalid IL or missing references) if (!muteEnabled.Value) { return false; } if (mutedSoundsList.Contains(prefabName)) { return true; } if (wolfSilenceMode.Value == WolfSilenceMode.Off || !((Object)zsfx).name.Contains("sfx_wolf_haul")) { return false; } List<Character> list = new List<Character>(); Character.GetCharactersInRange(((Component)zsfx).transform.position, wolfSilenceRange.Value, list); return list.Exists((Character c) => ((Object)c).name == "Wolf_cub(Clone)" || ((Object)c).name == "Wolf_cub" || (wolfSilenceMode.Value == WolfSilenceMode.On && (((Object)c).name == "Wolf(Clone)" || ((Object)c).name == "Wolf"))); } private static void SetModMute(AudioSource audioSource, bool muted) { bool value; if (muted) { if (!originalMuteStates.ContainsKey(audioSource)) { originalMuteStates.Add(audioSource, audioSource.mute); MuteStateCleanup muteStateCleanup = ((Component)audioSource).GetComponent<MuteStateCleanup>(); if ((Object)(object)muteStateCleanup == (Object)null) { muteStateCleanup = ((Component)audioSource).gameObject.AddComponent<MuteStateCleanup>(); } muteStateCleanup.Initialize(audioSource); } audioSource.mute = true; } else if (originalMuteStates.TryGetValue(audioSource, out value)) { audioSource.mute = value; originalMuteStates.Remove(audioSource); } } } }