Please disclose if your mod was created primarily 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.1
SilencePlease-1.1.1.dll
Decompiled 10 months 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 = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [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; } } } namespace SilencePlease { [BepInPlugin("org.bepinex.plugins.silenceplease", "Silence Please", "1.1.0")] [BepInIncompatibility("org.bepinex.plugins.valheim_plus")] public class SilencePlease : BaseUnityPlugin { public enum WolfSilenceMode { Off, CubsInRange, On } public enum LogMode { Off, On, UniqueOnly } [HarmonyPatch(typeof(ZSFX), "Awake")] private static class RemoveSounds { private static void Postfix(ZSFX __instance) { //IL_0071: Unknown result type (might be due to invalid IL or missing references) if (!muteEnabled.Value) { return; } string prefabName = Utils.GetPrefabName(((Component)__instance).gameObject); bool flag = false; if (mutedSoundsList.Contains(prefabName)) { flag = true; } if (!flag && wolfSilenceMode.Value != 0 && ((Object)__instance).name.Contains("sfx_wolf_haul")) { List<Character> list = new List<Character>(); Character.GetCharactersInRange(((Component)__instance).transform.position, wolfSilenceRange.Value, list); if (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")))) { flag = true; } } AudioSource component = ((Component)__instance).GetComponent<AudioSource>(); if (!((Object)(object)component != (Object)null)) { return; } component.mute = flag; switch (logMode.Value) { case LogMode.On: if (!flag) { logger.LogInfo((object)("Sound effect " + prefabName + " played.")); } break; case LogMode.UniqueOnly: if (!flag && loggedPrefabs.Add(prefabName)) { logger.LogInfo((object)("Sound effect " + prefabName + " played.")); } break; } } } private const string ModName = "Silence Please"; private const string ModVersion = "1.1.0"; 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 ConfigEntry<LogMode> logMode = null; private static HashSet<string> previousMutedSoundsList = new HashSet<string>(); 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) { previousMutedSoundsList = new HashSet<string>(mutedSoundsList); 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.FindObjectsOfType<ZSFX>(); 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; } if (!muteEnabled.Value) { if (previousMutedSoundsList.Contains(prefabName)) { component.mute = false; if (logMode.Value == LogMode.On) { logger.LogInfo((object)("Unmuted " + prefabName + " because muting is globally disabled.")); } } } else if (mutedSoundsList.Contains(prefabName)) { component.mute = true; if (logMode.Value == LogMode.On) { logger.LogInfo((object)("Muted already-active sound effect " + prefabName + " due to mute list update.")); } } else if (previousMutedSoundsList.Contains(prefabName)) { component.mute = false; if (logMode.Value == LogMode.On) { logger.LogInfo((object)("Unmuted already-active sound effect " + prefabName + " due to mute list update.")); } } } } } }