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 SagTag Audio Muffler v0.0.1
AudioMuffler.dll
Decompiled 15 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.SceneManagement; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("AudioMuffler")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("AudioMuffler")] [assembly: AssemblyTitle("AudioMuffler")] [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 AudioMuffler { internal class AudioMufflerUI : MonoBehaviour { private class Row { public RectTransform Root; public Image Bg; public TextMeshProUGUI Name; public TextMeshProUGUI MuteLabel; public TextMeshProUGUI Pct; public TextMeshProUGUI PlayLabel; public Button PlayBtn; public Button MuteBtn; public Image MuteImg; public Slider Slider; public SoundEntry Entry; } public static TMP_FontAsset Font; private static AudioMufflerUI instance; private const float RowH = 46f; private const float RH = 42f; private const float BH = 34f; private static readonly Color Accent = new Color(1f, 0.45f, 0.1f, 1f); private static readonly Color PanelBg = new Color(0.06f, 0.06f, 0.06f, 0.97f); private static readonly Color ButtonBg = new Color(0.17f, 0.17f, 0.17f, 1f); private static readonly Color RowBg = new Color(0.11f, 0.11f, 0.11f, 1f); private static readonly Color MutedBg = new Color(0.5f, 0.13f, 0.08f, 1f); private GameObject root; private TMP_InputField search; private ScrollRect scroll; private RectTransform viewport; private RectTransform content; private TextMeshProUGUI status; private TextMeshProUGUI sortLabel; private TextMeshProUGUI modLabel; private readonly List<Row> rows = new List<Row>(); private List<SoundEntry> view = new List<SoundEntry>(); private bool sortByName; private bool onlyModified; private GameObject floatBtn; private Func<bool> pauseOpen; public static AudioMufflerUI GetOrCreate() { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown if ((Object)(object)instance != (Object)null) { return instance; } GameObject val = new GameObject("AudioMufflerUI"); Object.DontDestroyOnLoad((Object)(object)val); instance = val.AddComponent<AudioMufflerUI>(); instance.Build(); return instance; } public void Open() { root.SetActive(true); search.SetTextWithoutNotify(""); SoundRegistry.ScanLoadedClips(); Rebuild(resetScroll: true); } public void SetPauseMenuCheck(Func<bool> isOpen) { pauseOpen = isOpen; } public void Close() { AudioPreview.Stop(); AudioRules.SaveIfDirty(); if ((Object)(object)root != (Object)null) { root.SetActive(false); } } private void Update() { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Invalid comparison between Unknown and I4 if ((Object)(object)root == (Object)null) { return; } if (root.activeSelf && (int)Cursor.lockState == 1) { Close(); } if ((Object)(object)floatBtn != (Object)null) { bool flag = pauseOpen != null && !root.activeSelf && pauseOpen(); if (floatBtn.activeSelf != flag) { floatBtn.SetActive(flag); } } } private void Build() { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Expected O, but got Unknown //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01ff: Unknown result type (might be due to invalid IL or missing references) //IL_020f: Expected O, but got Unknown //IL_021b: Unknown result type (might be due to invalid IL or missing references) //IL_023b: Unknown result type (might be due to invalid IL or missing references) //IL_024b: Expected O, but got Unknown //IL_028b: Unknown result type (might be due to invalid IL or missing references) //IL_0335: Unknown result type (might be due to invalid IL or missing references) //IL_0350: Unknown result type (might be due to invalid IL or missing references) //IL_036b: Unknown result type (might be due to invalid IL or missing references) //IL_037c: Unknown result type (might be due to invalid IL or missing references) //IL_038d: Unknown result type (might be due to invalid IL or missing references) //IL_03e4: Unknown result type (might be due to invalid IL or missing references) //IL_0404: Unknown result type (might be due to invalid IL or missing references) //IL_0410: Expected O, but got Unknown //IL_041c: Unknown result type (might be due to invalid IL or missing references) //IL_043c: Unknown result type (might be due to invalid IL or missing references) //IL_0448: Expected O, but got Unknown //IL_0473: Unknown result type (might be due to invalid IL or missing references) //IL_04ad: Unknown result type (might be due to invalid IL or missing references) //IL_04bc: Unknown result type (might be due to invalid IL or missing references) //IL_04dc: Unknown result type (might be due to invalid IL or missing references) //IL_04e8: Expected O, but got Unknown //IL_04e8: Expected O, but got Unknown Canvas val = ((Component)this).gameObject.AddComponent<Canvas>(); val.renderMode = (RenderMode)0; val.sortingOrder = 500; CanvasScaler val2 = ((Component)this).gameObject.AddComponent<CanvasScaler>(); val2.uiScaleMode = (ScaleMode)1; val2.referenceResolution = new Vector2(1920f, 1080f); val2.screenMatchMode = (ScreenMatchMode)0; val2.matchWidthOrHeight = 0.5f; ((Component)this).gameObject.AddComponent<GraphicRaycaster>(); RectTransform val3 = NewRect("Root", ((Component)this).transform); Stretch(val3); AddImage(val3, new Color(0f, 0f, 0f, 0.65f)); root = ((Component)val3).gameObject; RectTransform val4 = NewRect("Panel", (Transform)(object)val3); Vector2 val5 = default(Vector2); ((Vector2)(ref val5))..ctor(0.5f, 0.5f); val4.pivot = val5; Vector2 anchorMin = (val4.anchorMax = val5); val4.anchorMin = anchorMin; val4.sizeDelta = new Vector2(1000f, 760f); val4.anchoredPosition = Vector2.zero; AddImage(val4, PanelBg); TextMeshProUGUI val7 = AddText(val4, "Title", "AUDIO MUFFLER", 34f, (TextAlignmentOptions)4097, Accent); SetAbs(((TMP_Text)val7).rectTransform, 20f, 10f, 700f, 50f); AddButton(val4, "X", 28f, ButtonBg, 920f, 12f, 60f, 44f, new UnityAction(Close), out var text); search = BuildInput(val4, "SEARCH...", 20f, 70f, 480f, 44f); ((UnityEvent<string>)(object)search.onValueChanged).AddListener((UnityAction<string>)delegate { Rebuild(resetScroll: true); }); AddButton(val4, "SORT: RECENT", 22f, ButtonBg, 510f, 70f, 200f, 44f, (UnityAction)delegate { sortByName = !sortByName; ((TMP_Text)sortLabel).text = (sortByName ? "SORT: NAME" : "SORT: RECENT"); Rebuild(resetScroll: true); }, out sortLabel); AddButton(val4, "ONLY MODIFIED: OFF", 20f, ButtonBg, 720f, 70f, 260f, 44f, (UnityAction)delegate { onlyModified = !onlyModified; ((TMP_Text)modLabel).text = (onlyModified ? "ONLY MODIFIED: ON" : "ONLY MODIFIED: OFF"); Rebuild(resetScroll: true); }, out modLabel); RectTransform val8 = NewRect("Scroll", (Transform)(object)val4); SetAbs(val8, 20f, 124f, 960f, 560f); AddImage(val8, new Color(0f, 0f, 0f, 0.35f)); scroll = ((Component)val8).gameObject.AddComponent<ScrollRect>(); scroll.horizontal = false; scroll.vertical = true; scroll.movementType = (MovementType)2; scroll.scrollSensitivity = 30f; viewport = NewRect("Viewport", (Transform)(object)val8); Stretch(viewport); ((Component)viewport).gameObject.AddComponent<RectMask2D>(); content = NewRect("Content", (Transform)(object)viewport); content.anchorMin = new Vector2(0f, 1f); content.anchorMax = new Vector2(1f, 1f); content.pivot = new Vector2(0.5f, 1f); content.sizeDelta = Vector2.zero; content.anchoredPosition = Vector2.zero; scroll.viewport = viewport; scroll.content = content; ((UnityEvent<Vector2>)(object)scroll.onValueChanged).AddListener((UnityAction<Vector2>)delegate { RefreshRows(); }); AddButton(val4, "RESET ALL", 22f, ButtonBg, 20f, 696f, 200f, 44f, (UnityAction)delegate { AudioRules.ResetAll(); Rebuild(resetScroll: false); }, out text); AddButton(val4, "REFRESH", 22f, ButtonBg, 230f, 696f, 160f, 44f, (UnityAction)delegate { SoundRegistry.ScanLoadedClips(); Rebuild(resetScroll: false); }, out text); status = AddText(val4, "Status", "", 20f, (TextAlignmentOptions)4100, new Color(1f, 1f, 1f, 0.6f)); SetAbs(((TMP_Text)status).rectTransform, 400f, 696f, 580f, 44f); TextMeshProUGUI text2; Button val9 = AddButton((RectTransform)((Component)this).transform, "> AUDIO", 26f, ButtonBg, 30f, 30f, 220f, 56f, new UnityAction(Open), out text2); floatBtn = ((Component)val9).gameObject; floatBtn.SetActive(false); AudioPreview.StateChanged += delegate { if ((Object)(object)root != (Object)null && root.activeSelf) { RefreshRows(); } }; SceneManager.sceneLoaded += delegate { if ((Object)(object)root != (Object)null) { Close(); } }; root.SetActive(false); } private void Rebuild(bool resetScroll) { //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) string q = (search.text ?? "").Trim(); IEnumerable<SoundEntry> source = SoundRegistry.All; if (q.Length > 0) { source = source.Where((SoundEntry e) => e.Name.IndexOf(q, StringComparison.OrdinalIgnoreCase) >= 0); } if (onlyModified) { source = source.Where((SoundEntry e) => !AudioRules.Get(e.Name).IsDefault); } source = (sortByName ? source.OrderBy<SoundEntry, string>((SoundEntry e) => e.Name, StringComparer.OrdinalIgnoreCase) : source.OrderByDescending((SoundEntry e) => e.LastHeard).ThenBy<SoundEntry, string>((SoundEntry e) => e.Name, StringComparer.OrdinalIgnoreCase)); view = source.ToList(); content.sizeDelta = new Vector2(0f, (float)view.Count * 46f + 4f); if (resetScroll) { content.anchoredPosition = Vector2.zero; } ((TMP_Text)status).text = view.Count + " sounds"; RefreshRows(); } private void RefreshRows() { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)viewport == (Object)null) { return; } Rect rect = viewport.rect; float num = ((Rect)(ref rect)).height; if (num <= 1f) { num = 560f; } int num2 = Mathf.Max(0, Mathf.FloorToInt(content.anchoredPosition.y / 46f)); int num3 = Mathf.CeilToInt(num / 46f) + 2; while (rows.Count < num3) { rows.Add(CreateRow()); } for (int i = 0; i < rows.Count; i++) { int num4 = num2 + i; Row row = rows[i]; if (num4 >= view.Count) { ((Component)row.Root).gameObject.SetActive(false); continue; } ((Component)row.Root).gameObject.SetActive(true); row.Root.anchoredPosition = new Vector2(0f, (float)(-num4) * 46f - 2f); row.Entry = view[num4]; BindRow(row); } } private Row CreateRow() { //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Expected O, but got Unknown //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01d7: Expected O, but got Unknown //IL_0283: Unknown result type (might be due to invalid IL or missing references) Row r = new Row(); r.Root = NewRect("Row", (Transform)(object)content); r.Root.anchorMin = new Vector2(0f, 1f); r.Root.anchorMax = new Vector2(1f, 1f); r.Root.pivot = new Vector2(0.5f, 1f); r.Root.sizeDelta = new Vector2(0f, 42f); r.Bg = AddImage(r.Root, RowBg); r.Name = AddText(r.Root, "Name", "", 22f, (TextAlignmentOptions)4097, Color.white); SetAbs(((TMP_Text)r.Name).rectTransform, 10f, 0f, 400f, 42f); r.PlayBtn = AddButton(r.Root, "PLAY", 20f, ButtonBg, 420f, 4f, 70f, 34f, (UnityAction)delegate { OnPlay(r); }, out r.PlayLabel); r.MuteBtn = AddButton(r.Root, "MUTE", 20f, ButtonBg, 500f, 4f, 110f, 34f, (UnityAction)delegate { OnMute(r); }, out r.MuteLabel); r.MuteImg = ((Component)r.MuteBtn).GetComponent<Image>(); r.Slider = AddSlider(r.Root); SetAbs(((Component)r.Slider).GetComponent<RectTransform>(), 630f, 4f, 230f, 34f); ((UnityEvent<float>)(object)r.Slider.onValueChanged).AddListener((UnityAction<float>)delegate(float v) { OnVolume(r, v); }); r.Pct = AddText(r.Root, "Pct", "100%", 20f, (TextAlignmentOptions)4098, Color.white); SetAbs(((TMP_Text)r.Pct).rectTransform, 870f, 0f, 80f, 42f); return r; } private void BindRow(Row r) { //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) SoundEntry entry = r.Entry; Rule rule = AudioRules.Get(entry.Name); ((TMP_Text)r.Name).text = entry.Name; ((Graphic)r.Name).color = (rule.IsDefault ? Color.white : Accent); ((TMP_Text)r.MuteLabel).text = (rule.Muted ? "MUTED" : "MUTE"); ((Graphic)r.MuteImg).color = (rule.Muted ? MutedBg : ButtonBg); r.Slider.SetValueWithoutNotify(rule.Volume); ((TMP_Text)r.Pct).text = Mathf.RoundToInt(rule.Volume * 100f) + "%"; ((Selectable)r.PlayBtn).interactable = (Object)(object)entry.Clip != (Object)null; ((TMP_Text)r.PlayLabel).text = (((Object)(object)entry.Clip != (Object)null && (Object)(object)AudioPreview.Current == (Object)(object)entry.Clip) ? "STOP" : "PLAY"); } private void OnPlay(Row r) { if (r.Entry == null) { return; } AudioClip clip = r.Entry.Clip; if (!((Object)(object)clip == (Object)null)) { if ((Object)(object)AudioPreview.Current == (Object)(object)clip) { AudioPreview.Stop(); } else { AudioPreview.Play(clip); } } } private void OnMute(Row r) { if (r.Entry != null) { Rule rule = AudioRules.Get(r.Entry.Name); AudioRules.Set(r.Entry.Name, !rule.Muted, rule.Volume); BindRow(r); } } private void OnVolume(Row r, float value) { //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) if (r.Entry != null) { float num = Mathf.Round(value * 100f) / 100f; Rule rule = AudioRules.Get(r.Entry.Name); AudioRules.Set(r.Entry.Name, rule.Muted, num); ((TMP_Text)r.Pct).text = Mathf.RoundToInt(num * 100f) + "%"; ((Graphic)r.Name).color = (AudioRules.Get(r.Entry.Name).IsDefault ? Color.white : Accent); } } private static RectTransform NewRect(string name, Transform parent) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) }); val.transform.SetParent(parent, false); return val.GetComponent<RectTransform>(); } private static void Stretch(RectTransform rt) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) rt.anchorMin = Vector2.zero; rt.anchorMax = Vector2.one; rt.offsetMin = Vector2.zero; rt.offsetMax = Vector2.zero; } private static void SetAbs(RectTransform rt, float x, float y, float w, float h) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) Vector2 val = default(Vector2); ((Vector2)(ref val))..ctor(0f, 1f); rt.anchorMax = val; rt.anchorMin = val; rt.pivot = new Vector2(0f, 1f); rt.anchoredPosition = new Vector2(x, 0f - y); rt.sizeDelta = new Vector2(w, h); } private static Image AddImage(RectTransform rt, Color c) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) Image val = ((Component)rt).gameObject.AddComponent<Image>(); ((Graphic)val).color = c; return val; } private static TextMeshProUGUI AddText(RectTransform parent, string name, string text, float size, TextAlignmentOptions align, Color color) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) RectTransform val = NewRect(name, (Transform)(object)parent); TextMeshProUGUI val2 = ((Component)val).gameObject.AddComponent<TextMeshProUGUI>(); if ((Object)(object)Font != (Object)null) { ((TMP_Text)val2).font = Font; } ((TMP_Text)val2).text = text; ((TMP_Text)val2).fontSize = size; ((TMP_Text)val2).alignment = align; ((Graphic)val2).color = color; ((TMP_Text)val2).enableWordWrapping = false; ((TMP_Text)val2).overflowMode = (TextOverflowModes)1; ((Graphic)val2).raycastTarget = false; return val2; } private static Button AddButton(RectTransform parent, string label, float size, Color bg, float x, float y, float w, float h, UnityAction onClick, out TextMeshProUGUI text) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) RectTransform val = NewRect("Btn_" + label, (Transform)(object)parent); SetAbs(val, x, y, w, h); Image targetGraphic = AddImage(val, bg); Button val2 = ((Component)val).gameObject.AddComponent<Button>(); ((Selectable)val2).targetGraphic = (Graphic)(object)targetGraphic; ColorBlock colors = ((Selectable)val2).colors; ((ColorBlock)(ref colors)).normalColor = Color.white; ((ColorBlock)(ref colors)).highlightedColor = new Color(0.85f, 0.85f, 0.85f, 1f); ((ColorBlock)(ref colors)).pressedColor = new Color(0.65f, 0.65f, 0.65f, 1f); ((ColorBlock)(ref colors)).disabledColor = new Color(0.5f, 0.5f, 0.5f, 0.6f); ((Selectable)val2).colors = colors; text = AddText(val, "Label", label, size, (TextAlignmentOptions)4098, Accent); Stretch(((TMP_Text)text).rectTransform); ((UnityEvent)val2.onClick).AddListener(onClick); return val2; } private static Slider AddSlider(RectTransform parent) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Unknown result type (might be due to invalid IL or missing references) RectTransform val = NewRect("Slider", (Transform)(object)parent); RectTransform val2 = NewRect("Background", (Transform)(object)val); val2.anchorMin = new Vector2(0f, 0.35f); val2.anchorMax = new Vector2(1f, 0.65f); val2.offsetMin = Vector2.zero; val2.offsetMax = Vector2.zero; AddImage(val2, new Color(0.25f, 0.25f, 0.25f, 1f)); RectTransform val3 = NewRect("Fill Area", (Transform)(object)val); val3.anchorMin = new Vector2(0f, 0.35f); val3.anchorMax = new Vector2(1f, 0.65f); val3.offsetMin = Vector2.zero; val3.offsetMax = Vector2.zero; RectTransform val4 = NewRect("Fill", (Transform)(object)val3); val4.anchorMin = Vector2.zero; val4.anchorMax = Vector2.one; val4.offsetMin = Vector2.zero; val4.offsetMax = Vector2.zero; AddImage(val4, Accent); RectTransform val5 = NewRect("Handle Slide Area", (Transform)(object)val); val5.anchorMin = Vector2.zero; val5.anchorMax = Vector2.one; val5.offsetMin = new Vector2(8f, 0f); val5.offsetMax = new Vector2(-8f, 0f); RectTransform val6 = NewRect("Handle", (Transform)(object)val5); val6.anchorMin = new Vector2(0f, 0.1f); val6.anchorMax = new Vector2(0f, 0.9f); val6.sizeDelta = new Vector2(16f, 0f); Image targetGraphic = AddImage(val6, Color.white); Slider val7 = ((Component)val).gameObject.AddComponent<Slider>(); val7.fillRect = val4; val7.handleRect = val6; ((Selectable)val7).targetGraphic = (Graphic)(object)targetGraphic; val7.direction = (Direction)0; val7.minValue = 0f; val7.maxValue = 1f; val7.wholeNumbers = false; val7.value = 1f; return val7; } private static TMP_InputField BuildInput(RectTransform parent, string placeholder, float x, float y, float w, float h) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) RectTransform val = NewRect("Search", (Transform)(object)parent); SetAbs(val, x, y, w, h); ((Component)val).gameObject.SetActive(false); Image targetGraphic = AddImage(val, new Color(0.12f, 0.12f, 0.12f, 1f)); TMP_InputField val2 = ((Component)val).gameObject.AddComponent<TMP_InputField>(); RectTransform val3 = NewRect("TextArea", (Transform)(object)val); val3.anchorMin = Vector2.zero; val3.anchorMax = Vector2.one; val3.offsetMin = new Vector2(10f, 4f); val3.offsetMax = new Vector2(-10f, -4f); ((Component)val3).gameObject.AddComponent<RectMask2D>(); TextMeshProUGUI val4 = AddText(val3, "Text", "", 24f, (TextAlignmentOptions)4097, Color.white); Stretch(((TMP_Text)val4).rectTransform); TextMeshProUGUI val5 = AddText(val3, "Placeholder", placeholder, 24f, (TextAlignmentOptions)4097, new Color(1f, 1f, 1f, 0.35f)); ((TMP_Text)val5).fontStyle = (FontStyles)2; Stretch(((TMP_Text)val5).rectTransform); val2.textViewport = val3; val2.textComponent = (TMP_Text)(object)val4; val2.placeholder = (Graphic)(object)val5; ((Selectable)val2).targetGraphic = (Graphic)(object)targetGraphic; val2.caretColor = Accent; val2.selectionColor = new Color(1f, 0.45f, 0.1f, 0.35f); ((Component)val).gameObject.SetActive(true); return val2; } } internal class Rule { public bool Muted; public float Volume = 1f; public bool IsDefault => !Muted && Volume >= 0.999f; } internal static class AudioRules { private static readonly Dictionary<string, Rule> rules = new Dictionary<string, Rule>(); private static string path; private static bool dirty; public static int Count => rules.Count; public static void Init(string configDir) { path = Path.Combine(configDir, "AudioMuffler.rules.txt"); Load(); } public static Rule Get(string name) { Rule value; return rules.TryGetValue(name, out value) ? value : new Rule(); } public static float Multiplier(string name) { if (rules.Count == 0) { return 1f; } if (!rules.TryGetValue(name, out var value)) { return 1f; } return value.Muted ? 0f : value.Volume; } public static void Set(string name, bool muted, float volume) { if (string.IsNullOrEmpty(name)) { return; } volume = Mathf.Clamp01(volume); if (!muted && volume >= 0.999f) { if (rules.Remove(name)) { dirty = true; } } else { rules[name] = new Rule { Muted = muted, Volume = volume }; SoundRegistry.Ensure(name); dirty = true; } } public static void ResetAll() { if (rules.Count != 0) { rules.Clear(); dirty = true; } } private static void Load() { try { if (!File.Exists(path)) { return; } string[] array = File.ReadAllLines(path); foreach (string text in array) { string[] array2 = text.Split('\t'); if (array2.Length >= 3 && array2[0].Length != 0) { if (!float.TryParse(array2[2], NumberStyles.Float, CultureInfo.InvariantCulture, out var result)) { result = 1f; } rules[array2[0]] = new Rule { Muted = (array2[1] == "1"), Volume = Mathf.Clamp01(result) }; SoundRegistry.Ensure(array2[0]); } } } catch (Exception) { } } public static void SaveIfDirty() { if (!dirty || path == null) { return; } dirty = false; try { IEnumerable<string> contents = rules.Select((KeyValuePair<string, Rule> kv) => kv.Key + "\t" + (kv.Value.Muted ? "1" : "0") + "\t" + kv.Value.Volume.ToString("R", CultureInfo.InvariantCulture)); File.WriteAllLines(path, contents); } catch (Exception) { } } } internal class SoundEntry { public string Name; public AudioClip Clip; public float LastHeard = -1f; public int Plays; } internal static class SoundRegistry { private static readonly Dictionary<string, SoundEntry> entries = new Dictionary<string, SoundEntry>(); public static IEnumerable<SoundEntry> All => entries.Values; public static SoundEntry Ensure(string name) { if (string.IsNullOrEmpty(name)) { return null; } if (!entries.TryGetValue(name, out var value)) { value = new SoundEntry { Name = name }; entries[name] = value; } return value; } public static void Heard(AudioClip clip) { if (!((Object)(object)clip == (Object)null)) { SoundEntry soundEntry = Ensure(((Object)clip).name); if (soundEntry != null) { soundEntry.Clip = clip; soundEntry.LastHeard = Time.unscaledTime; soundEntry.Plays++; } } } public static void ScanLoadedClips() { AudioClip[] array = Resources.FindObjectsOfTypeAll<AudioClip>(); foreach (AudioClip val in array) { SoundEntry soundEntry = Ensure(((Object)val).name); if (soundEntry != null && (Object)(object)soundEntry.Clip == (Object)null) { soundEntry.Clip = val; } } } } internal static class AudioController { private class State { public float Base; public float Last; public bool Modified; } private static readonly Dictionary<AudioSource, State> tracked = new Dictionary<AudioSource, State>(); private static readonly List<AudioSource> dead = new List<AudioSource>(); private static int modifiedCount; private static float nextScan; private static float nextCleanup; public static void Track(AudioSource src) { if (!((Object)(object)src == (Object)null) && !AudioPreview.IsPreview(src)) { if (!tracked.TryGetValue(src, out var value)) { value = new State(); tracked[src] = value; } ApplyOne(src, value); } } private static void ApplyOne(AudioSource src, State st) { AudioClip clip = src.clip; float num = (((Object)(object)clip != (Object)null) ? AudioRules.Multiplier(((Object)clip).name) : 1f); if (!st.Modified) { if (!(num >= 0.999f)) { st.Base = src.volume; st.Modified = true; modifiedCount++; st.Last = st.Base * num; src.volume = st.Last; } return; } if (!Mathf.Approximately(src.volume, st.Last)) { st.Base = src.volume; } if (num >= 0.999f) { src.volume = st.Base; st.Modified = false; modifiedCount--; } else { st.Last = st.Base * num; src.volume = st.Last; } } public static void Tick() { float unscaledTime = Time.unscaledTime; if (unscaledTime >= nextScan) { nextScan = unscaledTime + 1f; Scan(); } if (unscaledTime >= nextCleanup) { nextCleanup = unscaledTime + 10f; Cleanup(); } if (AudioRules.Count == 0 && modifiedCount == 0) { return; } foreach (KeyValuePair<AudioSource, State> item in tracked) { if (!((Object)(object)item.Key == (Object)null)) { ApplyOne(item.Key, item.Value); } } } private static void Scan() { AudioSource[] array = Object.FindObjectsOfType<AudioSource>(); foreach (AudioSource val in array) { if (!((Object)(object)val.clip == (Object)null) && val.isPlaying && !AudioPreview.IsPreview(val)) { if (!tracked.ContainsKey(val)) { SoundRegistry.Heard(val.clip); } Track(val); } } } private static void Cleanup() { dead.Clear(); foreach (KeyValuePair<AudioSource, State> item in tracked) { if ((Object)(object)item.Key == (Object)null) { if (item.Value.Modified) { modifiedCount--; } dead.Add(item.Key); } } foreach (AudioSource item2 in dead) { tracked.Remove(item2); } } } internal static class AudioPreview { private const float PreviewGain = 0.8f; private static AudioSource source; private static bool active; private static float prevVolume = 1f; public static AudioClip Current => (active && (Object)(object)source != (Object)null) ? source.clip : null; public static event Action StateChanged; public static bool IsPreview(AudioSource s) { return (Object)(object)source != (Object)null && (Object)(object)s == (Object)(object)source; } public static void Play(AudioClip clip) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown if (!((Object)(object)clip == (Object)null)) { if ((Object)(object)source == (Object)null) { GameObject val = new GameObject("AudioMufflerPreview"); ((Object)val).hideFlags = (HideFlags)61; source = val.AddComponent<AudioSource>(); source.spatialBlend = 0f; source.playOnAwake = false; source.ignoreListenerVolume = true; } if (!active) { prevVolume = AudioListener.volume; AudioListener.volume = 0f; active = true; } source.volume = 0.8f * prevVolume; source.Stop(); source.clip = clip; source.Play(); Raise(); } } public static void Stop() { if ((Object)(object)source != (Object)null) { source.Stop(); } if (active) { AudioListener.volume = prevVolume; active = false; Raise(); } } public static void Tick() { if (active) { if (AudioListener.volume > 0f) { prevVolume = AudioListener.volume; AudioListener.volume = 0f; } if ((Object)(object)source == (Object)null || !source.isPlaying) { Stop(); } } } private static void Raise() { AudioPreview.StateChanged?.Invoke(); } } internal static class AudioPatches { public static void Apply(Harmony h) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Expected O, but got Unknown HarmonyMethod val = new HarmonyMethod(typeof(AudioPatches), "PlayPrefix", (Type[])null); MethodInfo[] array = new MethodInfo[4] { AccessTools.Method(typeof(AudioSource), "Play", Type.EmptyTypes, (Type[])null), AccessTools.Method(typeof(AudioSource), "Play", new Type[1] { typeof(ulong) }, (Type[])null), AccessTools.Method(typeof(AudioSource), "PlayDelayed", new Type[1] { typeof(float) }, (Type[])null), AccessTools.Method(typeof(AudioSource), "PlayScheduled", new Type[1] { typeof(double) }, (Type[])null) }; MethodInfo[] array2 = array; foreach (MethodInfo methodInfo in array2) { if (!(methodInfo == null)) { try { h.Patch((MethodBase)methodInfo, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } catch (Exception) { } } } MethodInfo methodInfo2 = AccessTools.Method(typeof(AudioSource), "PlayOneShot", new Type[2] { typeof(AudioClip), typeof(float) }, (Type[])null); if (methodInfo2 != null) { try { h.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(AudioPatches), "OneShotPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } catch (Exception) { } } } private static void PlayPrefix(AudioSource __instance) { if (!((Object)(object)__instance == (Object)null) && !AudioPreview.IsPreview(__instance)) { AudioClip clip = __instance.clip; if (!((Object)(object)clip == (Object)null)) { SoundRegistry.Heard(clip); AudioController.Track(__instance); } } } private static void OneShotPrefix(AudioSource __instance, AudioClip __0, ref float __1) { if (!((Object)(object)__0 == (Object)null) && !AudioPreview.IsPreview(__instance)) { SoundRegistry.Heard(__0); __1 *= AudioRules.Multiplier(((Object)__0).name); } } } internal static class ButtonInjector { public static void Inject(Button template, string objName, string label, UnityAction onClick) { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Expected O, but got Unknown //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_017c: Unknown result type (might be due to invalid IL or missing references) Transform parent = ((Component)template).transform.parent; if ((Object)(object)parent.Find(objName) != (Object)null) { return; } List<RectTransform> list = new List<RectTransform>(); foreach (Transform item in parent) { Transform val = item; if (((Component)val).gameObject.activeSelf && !((Object)(object)((Component)val).GetComponent<Button>() == (Object)null)) { RectTransform val2 = (RectTransform)(object)((val is RectTransform) ? val : null); if ((Object)(object)val2 != (Object)null) { list.Add(val2); } } } if (list.Count == 0) { list.Add(((Component)template).GetComponent<RectTransform>()); } list = list.OrderByDescending((RectTransform r) => r.anchoredPosition.y).ToList(); RectTransform val3 = list[0]; float num; if (list.Count <= 1) { Rect rect = val3.rect; num = ((Rect)(ref rect)).height + 5f; } else { num = val3.anchoredPosition.y - list[1].anchoredPosition.y; } float num2 = num; GameObject val4 = Object.Instantiate<GameObject>(((Component)val3).gameObject, parent); ((Object)val4).name = objName; val4.SetActive(true); RectTransform component = val4.GetComponent<RectTransform>(); component.anchoredPosition = val3.anchoredPosition + new Vector2(0f, num2); Button component2 = val4.GetComponent<Button>(); for (int num3 = 0; num3 < ((UnityEventBase)component2.onClick).GetPersistentEventCount(); num3++) { ((UnityEventBase)component2.onClick).SetPersistentListenerState(num3, (UnityEventCallState)0); } ((UnityEventBase)component2.onClick).RemoveAllListeners(); ((UnityEvent)component2.onClick).AddListener(onClick); TextMeshProUGUI componentInChildren = val4.GetComponentInChildren<TextMeshProUGUI>(true); if ((Object)(object)componentInChildren != (Object)null) { ((TMP_Text)componentInChildren).text = label; if ((Object)(object)AudioMufflerUI.Font == (Object)null) { AudioMufflerUI.Font = ((TMP_Text)componentInChildren).font; } } } } [HarmonyPatch(typeof(MenuManager), "Start")] internal static class MainMenuPatch { [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static UnityAction <>9__0_0; internal void <Postfix>b__0_0() { AudioMufflerUI.GetOrCreate().Open(); } } [HarmonyPostfix] private static void Postfix(MenuManager __instance) { //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Expected O, but got Unknown try { GameObject val = GameObject.Find("Canvas/MenuContainer") ?? GameObject.Find("MenuContainer"); if ((Object)(object)val == (Object)null) { return; } Button componentInChildren = val.GetComponentInChildren<Button>(true); if ((Object)(object)componentInChildren == (Object)null) { return; } object obj = <>c.<>9__0_0; if (obj == null) { UnityAction val2 = delegate { AudioMufflerUI.GetOrCreate().Open(); }; <>c.<>9__0_0 = val2; obj = (object)val2; } ButtonInjector.Inject(componentInChildren, "AudioMufflerButton", "> AUDIO", (UnityAction)obj); } catch (Exception) { } } } [HarmonyPatch(typeof(QuickMenuManager), "Start")] internal static class QuickMenuPatch { [HarmonyPostfix] private static void Postfix(QuickMenuManager __instance) { try { Button resume = ((IEnumerable<Button>)Resources.FindObjectsOfTypeAll<Button>()).FirstOrDefault((Func<Button, bool>)delegate(Button b) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) Scene scene = ((Component)b).gameObject.scene; if (!((Scene)(ref scene)).IsValid()) { return false; } TMP_Text componentInChildren2 = ((Component)b).GetComponentInChildren<TMP_Text>(true); return (Object)(object)componentInChildren2 != (Object)null && componentInChildren2.text.IndexOf("resume", StringComparison.OrdinalIgnoreCase) >= 0; }); Func<bool> pauseMenuCheck; if ((Object)(object)resume != (Object)null) { if ((Object)(object)AudioMufflerUI.Font == (Object)null) { TMP_Text componentInChildren = ((Component)resume).GetComponentInChildren<TMP_Text>(true); if ((Object)(object)componentInChildren != (Object)null) { AudioMufflerUI.Font = componentInChildren.font; } } pauseMenuCheck = () => (Object)(object)resume != (Object)null && ((Component)resume).gameObject.activeInHierarchy; } else { pauseMenuCheck = () => (Object)(object)__instance != (Object)null && Traverse.Create((object)__instance).Field("isMenuOpen").GetValue<bool>(); } AudioMufflerUI.GetOrCreate().SetPauseMenuCheck(pauseMenuCheck); } catch (Exception) { } } } [BepInPlugin("skript.audiomuffler", "AudioMuffler", "0.1.0")] public class Plugin : BaseUnityPlugin { public const string PluginGuid = "skript.audiomuffler"; public const string PluginName = "AudioMuffler"; public const string PluginVersion = "0.1.0"; private void Awake() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Expected O, but got Unknown AudioRules.Init(Paths.ConfigPath); GameObject val = new GameObject("AudioMufflerManager"); ((Object)val).hideFlags = (HideFlags)61; val.AddComponent<AudioMufflerManager>(); Harmony val2 = new Harmony("skript.audiomuffler"); AudioPatches.Apply(val2); Type[] array = new Type[2] { typeof(MainMenuPatch), typeof(QuickMenuPatch) }; foreach (Type type in array) { try { val2.CreateClassProcessor(type).Patch(); } catch (Exception) { } } } } internal class AudioMufflerManager : MonoBehaviour { private float nextSave; private void LateUpdate() { AudioController.Tick(); } private void Update() { AudioPreview.Tick(); if (Time.unscaledTime >= nextSave) { nextSave = Time.unscaledTime + 5f; AudioRules.SaveIfDirty(); } } private void OnApplicationQuit() { AudioRules.SaveIfDirty(); } } }