using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using ATL; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using I2.Loc; using ShinyShoe; using ShinyShoe.Audio; using ShinyShoe.Loading; using TMPro; using UnityEngine; using UnityEngine.Networking; using UnityEngine.U2D; 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: AssemblyTitle("Patty_SoundChanger_MOD")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Patty_SoundChanger_MOD")] [assembly: AssemblyCopyright("Copyright © 2025")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("33a86151-483d-4513-8190-9fd71a0bf018")] [assembly: AssemblyFileVersion("2.1.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("2.1.0.0")] namespace Patty_SoundChanger_MOD; internal sealed class ConfigurationManagerAttributes { public delegate void CustomHotkeyDrawerFunc(ConfigEntryBase setting, ref bool isCurrentlyAcceptingInput); public bool? ShowRangeAsPercent; public Action 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 ObjToStr; public Func StrToObj; } public interface ISoundChanger { SoundData CreateNewMusicEntry(string entryName, string description = "", string defaultVal = ""); SoundData CreateNewSFXEntry(string entryName, string description = "", string defaultVal = ""); BattleMusicTrack RegisterToBattleMusic(SoundData musicData, bool isBoss = false); void RegisterMusicEntry(SoundData musicData); ConfigEntry GetEntry(string entryName); bool IsMusicEntry(ConfigEntryBase entry); bool IsSFXEntry(ConfigEntryBase entry); bool IsValidEntry(ConfigEntryBase entry); SoundData GetMusicData(string entryName); SoundData GetMusicData(ConfigEntryBase entry); SoundData GetSFXData(string entryName); SoundData GetSFXData(ConfigEntryBase entry); List GetBattleMusicTracks(bool isBoss = false); BattleMusicTrack GetBattleMusicTrack(string trackName); SoundManager GetSoundManager(); CoreAudioSystem GetCoreAudioSystem(); CoreAudioSystemData GetCoreAudioSystemData(); MusicDefinition[] GetMusicDefinitions(); SoundCueDefinition[] GetSFXDefinitions(); MusicDefinition GetMusicDefinition(string trackName); SoundCueDefinition GetSFXDefinition(string trackName); void ChangeSound(string entryName, string filePath, bool replayMusic = true, Action onPlay = null); void ChangeSound(string entryName, AudioClip audioClip, bool replayMusic = true, Action onPlay = null); void ChangeSound(ConfigEntryBase entry, string filePath, bool replayMusic = true, Action onPlay = null); void ChangeSound(ConfigEntryBase entry, AudioClip audioClip, bool replayMusic = true, Action onPlay = null); void RegisterOriginalAudio(ConfigEntryBase entry, AudioClip audioClip); void PlayEntry(string entryName, Action onPlay = null); void PlayEntry(ConfigEntryBase entry, Action onPlay = null); void PlayMusic(string entryName, bool isBattleMusic = false, float crossfadeTimeSeconds = 0.25f, string displayedName = "", Action onPlay = null); void PlayMusic(ConfigEntryBase entry, bool isBattleMusic = false, float crossfadeTimeSeconds = 0.25f, string displayedName = "", Action onPlay = null); void PlaySFX(string entryName, bool loop = false, Action onPlay = null); void PlaySFX(ConfigEntryBase entry, bool loop = false, Action onPlay = null); void LoadFileForEntry(string entryName, Action onLoad = null, Action onPlay = null); void LoadFileForEntry(ConfigEntryBase entry, Action onLoad = null, Action onPlay = null); void ResetEntry(string entryName); void ResetEntry(ConfigEntryBase entry); string GetCurrentlyPlayingMusicName(); bool HasInitializedSoundManager(); } internal class MenuPatch { [HarmonyPrefix] [HarmonyPatch(typeof(SettingsScreen), "ApplyScreenInput")] public static bool SettingsScreen_ApplyScreenInput(CoreInputControlMapping mapping, IGameUIComponent triggeredUI, Controls triggeredMappingID, ref bool __result) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)SoundDialog.Instance == (Object)null) { return true; } if (((ScreenDialog)SoundDialog.Instance).ApplyScreenInput(mapping, triggeredUI, triggeredMappingID)) { __result = true; return false; } return true; } [HarmonyPostfix] [HarmonyPatch(typeof(PauseDialog), "ApplyScreenInput")] public static void PauseDialog_ApplyScreenInput(CoreInputControlMapping mapping, IGameUIComponent triggeredUI, Controls triggeredMappingID, ref bool __result) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) if (!__result && (Object)(object)SoundDialog.Instance != (Object)null) { __result = ((ScreenDialog)SoundDialog.Instance).ApplyScreenInput(mapping, triggeredUI, triggeredMappingID); } } [HarmonyPrefix] [HarmonyPatch(typeof(SettingsScreen), "CloseDialog")] public static bool CloseDialog() { if ((Object)(object)SoundDialog.Instance != (Object)null && ((ScreenTransition)SoundDialog.Instance).Active) { ((ScreenDialog)SoundDialog.Instance).Close(); return false; } return true; } } internal class OrderedDictionary : IDictionary, ICollection>, IEnumerable>, IEnumerable, IDictionary, ICollection { [CompilerGenerated] private sealed class d__25 : IEnumerator>, IDisposable, IEnumerator { private int <>1__state; private KeyValuePair <>2__current; public OrderedDictionary <>4__this; private IDictionaryEnumerator <>s__1; private DictionaryEntry 5__2; KeyValuePair IEnumerator>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__25(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { int num = <>1__state; if (num == -3 || num == 1) { try { } finally { <>m__Finally1(); } } <>s__1 = null; 5__2 = default(DictionaryEntry); <>1__state = -2; } private bool MoveNext() { try { switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>s__1 = <>4__this.privateDictionary.GetEnumerator(); <>1__state = -3; break; case 1: <>1__state = -3; 5__2 = default(DictionaryEntry); break; } if (<>s__1.MoveNext()) { 5__2 = (DictionaryEntry)<>s__1.Current; <>2__current = new KeyValuePair((TKey)5__2.Key, (TValue)5__2.Value); <>1__state = 1; return true; } <>m__Finally1(); <>s__1 = null; return false; } catch { //try-fault ((IDisposable)this).Dispose(); throw; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void <>m__Finally1() { <>1__state = -1; if (<>s__1 is IDisposable disposable) { disposable.Dispose(); } } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } private readonly Hashtable privateHashtable; private readonly OrderedDictionary privateDictionary; public int Count => privateDictionary.Count; public bool IsReadOnly => false; public TValue this[int index] { get { if (index < 0 || index >= Count) { throw new ArgumentOutOfRangeException("index"); } return (TValue)privateDictionary[index]; } set { if (index < 0 || index >= Count) { throw new ArgumentOutOfRangeException("index"); } privateDictionary[index] = value; } } public TValue this[TKey key] { get { if (key == null) { throw new ArgumentNullException("key"); } if (privateDictionary.Contains(key)) { return (TValue)privateDictionary[key]; } throw new KeyNotFoundException("key not found in dictionary"); } set { if (key == null) { throw new ArgumentNullException("key"); } privateDictionary[key] = value; } } public ICollection Keys { get { List list = new List(privateDictionary.Count); foreach (TKey key in privateDictionary.Keys) { list.Add(key); } return list; } } public ICollection Values { get { List list = new List(privateDictionary.Count); foreach (TValue value in privateDictionary.Values) { list.Add(value); } return list; } } bool IDictionary.IsFixedSize => ((IDictionary)privateDictionary).IsFixedSize; bool IDictionary.IsReadOnly => privateDictionary.IsReadOnly; ICollection IDictionary.Keys => privateDictionary.Keys; ICollection IDictionary.Values => privateDictionary.Values; object IDictionary.this[object key] { get { return privateDictionary[key]; } set { privateDictionary[key] = value; } } int ICollection.Count => privateDictionary.Count; bool ICollection.IsSynchronized => ((ICollection)privateDictionary).IsSynchronized; object ICollection.SyncRoot => ((ICollection)privateDictionary).SyncRoot; public OrderedDictionary() { privateDictionary = new OrderedDictionary(); privateHashtable = (Hashtable)AccessTools.DeclaredProperty(typeof(OrderedDictionary), "objectsTable").GetValue(privateDictionary); } public OrderedDictionary(IDictionary dictionary) { if (dictionary == null) { return; } foreach (KeyValuePair item in dictionary) { privateDictionary.Add(item.Key, item.Value); } } public void Add(KeyValuePair item) { Add(item.Key, item.Value); } public void Add(TKey key, TValue value) { if (key == null) { throw new ArgumentNullException("key"); } privateDictionary.Add(key, value); } public void Clear() { privateDictionary.Clear(); } public bool Contains(KeyValuePair item) { if (item.Key == null || !privateDictionary.Contains(item.Key)) { return false; } return privateDictionary[item.Key].Equals(item.Value); } public bool ContainsKey(TKey key) { if (key == null) { throw new ArgumentNullException("key"); } return privateDictionary.Contains(key); } public bool ContainsValue(TValue value) { if (value == null) { throw new ArgumentNullException("value"); } return privateHashtable.ContainsValue(value); } public void CopyTo(KeyValuePair[] array, int arrayIndex) { if (array == null) { throw new ArgumentNullException("array"); } if (arrayIndex < 0) { throw new ArgumentOutOfRangeException("arrayIndex"); } if (array.Rank > 1 || arrayIndex >= array.Length || array.Length - arrayIndex < privateDictionary.Count) { throw new ArgumentOutOfRangeException("array"); } int num = arrayIndex; foreach (DictionaryEntry item in privateDictionary) { array[num] = new KeyValuePair((TKey)item.Key, (TValue)item.Value); num++; } } [IteratorStateMachine(typeof(OrderedDictionary<, >.d__25))] public IEnumerator> GetEnumerator() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__25(0) { <>4__this = this }; } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } public bool Remove(KeyValuePair item) { if (Contains(item)) { privateDictionary.Remove(item.Key); return true; } return false; } public bool Remove(TKey key) { if (key == null) { throw new ArgumentNullException("key"); } if (privateDictionary.Contains(key)) { privateDictionary.Remove(key); return true; } return false; } public bool TryGetValue(TKey key, out TValue value) { if (key == null) { throw new ArgumentNullException("key"); } bool flag = privateDictionary.Contains(key); value = (flag ? ((TValue)privateDictionary[key]) : default(TValue)); return flag; } void IDictionary.Add(object key, object value) { privateDictionary.Add(key, value); } void IDictionary.Clear() { privateDictionary.Clear(); } bool IDictionary.Contains(object key) { return privateDictionary.Contains(key); } IDictionaryEnumerator IDictionary.GetEnumerator() { return privateDictionary.GetEnumerator(); } void IDictionary.Remove(object key) { privateDictionary.Remove(key); } void ICollection.CopyTo(Array array, int index) { privateDictionary.CopyTo(array, index); } } public sealed class SoundChangerManager : ISoundChanger { public SoundData CreateNewMusicEntry(string entryName, string description = "", string defaultVal = "") { //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Expected O, but got Unknown //IL_00b7: Expected O, but got Unknown //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Expected O, but got Unknown ConfigEntryBase val = ((IEnumerable)Plugin.MusicEntries.Keys).FirstOrDefault((Func)((ConfigEntryBase musicEntry) => musicEntry.Definition.Key == entryName)); if (val != null) { Plugin.LogSource.LogError((object)("Cannot create new music entry, Already have music with same entry name " + entryName)); return null; } ConfigEntry val2 = Plugin.Config.Bind(new ConfigDefinition("Basic", entryName), defaultVal, new ConfigDescription(description, (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { HideDefaultButton = true, HideSettingName = true, CustomDrawer = Plugin.MusicDrawer } })); val2.SettingChanged += Plugin.Entry_SettingChanged; Plugin.MusicEntries[(ConfigEntryBase)(object)val2] = SoundData.Create(val2, new MusicDefinition()); return Plugin.MusicEntries[(ConfigEntryBase)(object)val2]; } public SoundData CreateNewSFXEntry(string entryName, string description = "", string defaultVal = "") { //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Expected O, but got Unknown //IL_00b7: Expected O, but got Unknown //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Expected O, but got Unknown ConfigEntryBase val = ((IEnumerable)Plugin.SFXEntries.Keys).FirstOrDefault((Func)((ConfigEntryBase sfxEntry) => sfxEntry.Definition.Key == entryName)); if (val != null) { Plugin.LogSource.LogError((object)("Cannot create new sfx entry, Already have SFX with same entry name " + entryName)); return null; } ConfigEntry val2 = Plugin.Config.Bind(new ConfigDefinition("Basic", entryName), defaultVal, new ConfigDescription(description, (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { HideDefaultButton = true, HideSettingName = true, CustomDrawer = Plugin.MusicDrawer } })); val2.SettingChanged += Plugin.Entry_SettingChanged; Plugin.SFXEntries[(ConfigEntryBase)(object)val2] = SoundData.Create(val2, new SoundCueDefinition()); return Plugin.SFXEntries[(ConfigEntryBase)(object)val2]; } public BattleMusicTrack RegisterToBattleMusic(SoundData musicData, bool isBoss = false) { //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: 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_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) if (musicData == null) { Plugin.LogSource.LogError((object)"Cannot register to battle music, data is null"); return default(BattleMusicTrack); } if (!HasInitializedSoundManager()) { return default(BattleMusicTrack); } SoundManager soundManager = GetSoundManager(); List battleMusicTracks = GetBattleMusicTracks(isBoss); if (battleMusicTracks.Exists((BattleMusicTrack track) => track.trackNameData == musicData.definition.Name)) { Plugin.LogSource.LogWarning((object)("Already registered battle music track with entry name " + musicData.definition.Name)); Plugin.LogSource.LogWarning((object)"Removing the duplicated entry..."); battleMusicTracks.RemoveAll((BattleMusicTrack track) => track.trackNameData == musicData.entryName); } BattleMusicTrack val = default(BattleMusicTrack); val.publicTrackNameKey = musicData.GetTitle(); val.trackNameData = musicData.definition.Name; BattleMusicTrack val2 = val; battleMusicTracks.Add(val2); RegisterMusicEntry(musicData); return val2; } public void RegisterMusicEntry(SoundData musicData) { if (musicData == null) { Plugin.LogSource.LogError((object)"Cannot register music, data is null"); } else { if (!HasInitializedSoundManager()) { return; } SoundManager soundManager = GetSoundManager(); CoreAudioSystem coreAudioSystem = GetCoreAudioSystem(); CoreAudioSystemData coreAudioSystemData = GetCoreAudioSystemData(); if (coreAudioSystemData.MusicDefData.Tracks.Any((MusicDefinition definition) => definition.Name == musicData.definition.Name)) { Plugin.LogSource.LogWarning((object)("Already registered music track with entry name " + musicData.definition.Name)); Plugin.LogSource.LogWarning((object)"Removing the duplicated entry..."); List list = coreAudioSystemData.MusicDefData.Tracks.ToList(); list.RemoveAll((MusicDefinition definition) => definition.Name == musicData.definition.Name); coreAudioSystemData.MusicDefData.Tracks = list.ToArray(); } coreAudioSystemData.MusicDefData.Tracks = CollectionExtensions.AddToArray(coreAudioSystemData.MusicDefData.Tracks, musicData.definition); } } public ConfigEntry GetEntry(string entryName) { ConfigEntryBase val = ((IEnumerable)Plugin.MusicEntries.Keys).FirstOrDefault((Func)((ConfigEntryBase entry) => entry.Definition.Key == entryName)); if (val == null) { val = ((IEnumerable)Plugin.SFXEntries.Keys).FirstOrDefault((Func)((ConfigEntryBase entry) => entry.Definition.Key == entryName)); } if (val == null) { Plugin.LogSource.LogError((object)("Cannot find entry named " + entryName)); } return val as ConfigEntry; } public bool IsMusicEntry(ConfigEntryBase entry) { return Plugin.MusicEntries.ContainsKey(entry); } public bool IsSFXEntry(ConfigEntryBase entry) { return Plugin.SFXEntries.ContainsKey(entry); } public bool IsValidEntry(ConfigEntryBase entry) { bool flag = entry != null && (IsMusicEntry(entry) || IsSFXEntry(entry)); if (!flag) { ManualLogSource logSource = Plugin.LogSource; object obj; if (entry == null) { obj = null; } else { ConfigDefinition definition = entry.Definition; obj = ((definition != null) ? definition.Key : null); } logSource.LogError((object)((string?)obj + " is not a valid entry")); } return flag; } public SoundData GetMusicData(string entryName) { ConfigEntry entry = GetEntry(entryName); return GetMusicData((ConfigEntryBase)(object)entry); } public SoundData GetMusicData(ConfigEntryBase entry) { if (!IsValidEntry(entry)) { return null; } if (!IsMusicEntry(entry)) { Plugin.LogSource.LogError((object)"Entry is valid but is not a music entry"); return null; } return Plugin.MusicEntries[entry]; } public SoundData GetSFXData(string entryName) { ConfigEntry entry = GetEntry(entryName); return GetSFXData((ConfigEntryBase)(object)entry); } public SoundData GetSFXData(ConfigEntryBase entry) { if (!IsValidEntry(entry)) { return null; } if (!IsSFXEntry(entry)) { Plugin.LogSource.LogError((object)"Entry is valid but is not an SFX entry"); return null; } return Plugin.SFXEntries[entry]; } public void ChangeSound(string entryName, string filePath, bool replayMusic = true, Action onPlay = null) { ConfigEntry entry = GetEntry(entryName); ChangeSound((ConfigEntryBase)(object)entry, filePath, replayMusic, onPlay); } public void ChangeSound(string entryName, AudioClip audioClip, bool replayMusic = true, Action onPlay = null) { ConfigEntry entry = GetEntry(entryName); ChangeSound((ConfigEntryBase)(object)entry, audioClip, replayMusic, onPlay); } public void ChangeSound(ConfigEntryBase entry, string filePath, bool replayMusic = true, Action onPlay = null) { if (!IsValidEntry(entry)) { return; } if (!File.Exists(filePath)) { Plugin.LogSource.LogError((object)("Cannot load " + filePath + " because its not valid path")); return; } entry.BoxedValue = filePath; ((MonoBehaviour)Plugin.Instance).StartCoroutine(Plugin.LoadAudioClip(filePath, delegate(AudioClip audioClip) { Plugin.OnAudioClipLoaded(entry, audioClip, replayMusic, onPlay); RegisterOriginalAudio(entry, audioClip); })); } public void ChangeSound(ConfigEntryBase entry, AudioClip audioClip, bool replayMusic = true, Action onPlay = null) { if (IsValidEntry(entry)) { if ((Object)(object)audioClip == (Object)null) { Plugin.LogSource.LogError((object)("AudioClip is null, Cannot assign to entry " + entry.Definition.Key)); return; } entry.BoxedValue = ((Object)audioClip).name; Plugin.OnAudioClipLoaded(entry, audioClip, replayMusic, onPlay); RegisterOriginalAudio(entry, audioClip); } } public void RegisterOriginalAudio(ConfigEntryBase entry, AudioClip audioClip) { if (IsMusicEntry(entry)) { SoundData musicData = GetMusicData(entry.Definition.Key); if (!Plugin.OriginalMusics.ContainsKey(musicData.definition)) { Plugin.OriginalMusics[musicData.definition] = new List { audioClip }; } } else { SoundData sFXData = GetSFXData(entry.Definition.Key); if (!Plugin.OriginalSFX.ContainsKey(sFXData.definition)) { Plugin.OriginalSFX[sFXData.definition] = new List { audioClip }; } } } public void PlayEntry(string entryName, Action onPlay = null) { ConfigEntry entry = GetEntry(entryName); PlayEntry((ConfigEntryBase)(object)entry, onPlay); } public void PlayEntry(ConfigEntryBase entry, Action onPlay = null) { if (IsValidEntry(entry)) { if (IsMusicEntry(entry)) { Plugin.PlayMusic(entry, isBattleMusic: false, 0.25f, "", onPlay); } else if (IsSFXEntry(entry)) { Plugin.PlaySFX(entry, loop: false, onPlay); } } } public void PlayMusic(string entryName, bool isBattleMusic = false, float crossfadeTimeSeconds = 0.25f, string displayedName = "", Action onPlay = null) { ConfigEntry entry = GetEntry(entryName); PlayMusic((ConfigEntryBase)(object)entry, isBattleMusic, crossfadeTimeSeconds, displayedName, onPlay); } public void PlayMusic(ConfigEntryBase entry, bool isBattleMusic = false, float crossfadeTimeSeconds = 0.25f, string displayedName = "", Action onPlay = null) { if (IsValidEntry(entry) && IsMusicEntry(entry)) { Plugin.PlayMusic(entry, isBattleMusic, crossfadeTimeSeconds, displayedName, onPlay); } } public void PlaySFX(string entryName, bool loop = false, Action onPlay = null) { ConfigEntry entry = GetEntry(entryName); PlaySFX((ConfigEntryBase)(object)entry, loop, onPlay); } public void PlaySFX(ConfigEntryBase entry, bool loop = false, Action onPlay = null) { if (IsValidEntry(entry) && IsSFXEntry(entry)) { Plugin.PlaySFX(entry, loop, onPlay); } } public void LoadFileForEntry(string entryName, Action onLoad = null, Action onPlay = null) { ConfigEntry entry = GetEntry(entryName); LoadFileForEntry((ConfigEntryBase)(object)entry, onLoad, onPlay); } public void LoadFileForEntry(ConfigEntryBase entry, Action onLoad = null, Action onPlay = null) { if (IsValidEntry(entry)) { Plugin.LoadFile(entry, "", existFile: false, onLoad, onPlay); } } public void ResetEntry(string entryName) { ConfigEntry entry = GetEntry(entryName); ResetEntry((ConfigEntryBase)(object)entry); } public void ResetEntry(ConfigEntryBase entry) { if (IsValidEntry(entry)) { if (Plugin.soundChangerManager.IsMusicEntry(entry)) { Plugin.soundChangerManager.GetMusicData(entry.Definition.Key).AudioData = null; } else if (Plugin.soundChangerManager.IsSFXEntry(entry)) { Plugin.soundChangerManager.GetSFXData(entry.Definition.Key).AudioData = null; } entry.BoxedValue = ""; Plugin.ResetEntryBase(entry); } } public string GetCurrentlyPlayingMusicName() { if (!HasInitializedSoundManager()) { return ""; } SoundManager soundManager = AllGameManagers.Instance.GetSoundManager(); string result = soundManager.GetCurrentMusicTrackName(); if (!string.IsNullOrWhiteSpace(soundManager.currentTrackName)) { result = soundManager.currentTrackName; } return result; } public bool HasInitializedSoundManager() { AllGameManagers instance = AllGameManagers.Instance; if ((Object)(object)instance != (Object)null && (Object)(object)instance.GetSoundManager() != (Object)null) { return true; } Plugin.LogSource.LogError((object)"SoundManager isn't initialized yet, try waiting a bit more before registering"); return false; } public List GetBattleMusicTracks(bool isBoss) { if (!HasInitializedSoundManager()) { return null; } SoundManager soundManager = AllGameManagers.Instance.GetSoundManager(); return (!isBoss) ? Traverse.Create((object)soundManager).Field>("battleMusicTracks").Value : Traverse.Create((object)soundManager).Field>("bossBattleMusicTracks").Value; } public BattleMusicTrack GetBattleMusicTrack(string trackName) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: 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_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0025: 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_0073: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) BattleMusicTrack result = default(BattleMusicTrack); if (!HasInitializedSoundManager()) { return result; } List battleMusicTracks = GetBattleMusicTracks(isBoss: false); result = battleMusicTracks.Find((BattleMusicTrack track) => track.trackNameData == trackName); if (string.IsNullOrWhiteSpace(result.trackNameData)) { battleMusicTracks = GetBattleMusicTracks(isBoss: false); result = battleMusicTracks.Find((BattleMusicTrack track) => track.trackNameData == trackName); } return result; } public SoundManager GetSoundManager() { if (!HasInitializedSoundManager()) { return null; } return AllGameManagers.Instance.GetSoundManager(); } public CoreAudioSystem GetCoreAudioSystem() { if (!HasInitializedSoundManager()) { return null; } SoundManager soundManager = AllGameManagers.Instance.GetSoundManager(); return Traverse.Create((object)soundManager).Field("audioSystem").Value; } public CoreAudioSystemData GetCoreAudioSystemData() { if (!HasInitializedSoundManager()) { return null; } SoundManager soundManager = AllGameManagers.Instance.GetSoundManager(); CoreAudioSystem value = Traverse.Create((object)soundManager).Field("audioSystem").Value; return Traverse.Create((object)value).Field("AudioSystemData").GetValue(); } public MusicDefinition[] GetMusicDefinitions() { if (!HasInitializedSoundManager()) { return null; } return GetCoreAudioSystemData().MusicDefData.Tracks; } public SoundCueDefinition[] GetSFXDefinitions() { if (!HasInitializedSoundManager()) { return null; } return GetCoreAudioSystemData().GlobalSoundEffectData.Sounds; } public MusicDefinition GetMusicDefinition(string trackName) { if (!HasInitializedSoundManager()) { return null; } return GetMusicDefinitions().First((MusicDefinition definition) => definition.Name == trackName); } public SoundCueDefinition GetSFXDefinition(string trackName) { if (!HasInitializedSoundManager()) { return null; } return GetSFXDefinitions().First((SoundCueDefinition definition) => definition.Name == trackName); } } public enum SoundType { Unknown, Music, SFX } public class SoundData : IDisposable { internal static readonly Lazy emptyTrack = new Lazy((Func)(() => new Track())); private AudioClip _audioData; public readonly SoundType type; public readonly ConfigEntry entry; public readonly T definition; public readonly string entryName; public Track TrackData { get; private set; } public AudioClip AudioData { get { return _audioData; } set { _audioData = value; if ((Object)(object)value == (Object)null) { TrackData = emptyTrack.Value; } if (type == SoundType.Music) { SoundData soundData = AsMusic(); for (int i = 0; i < soundData.definition.Clips.Length; i++) { soundData.definition.Clips[i].Clip = _audioData; } } else if (type == SoundType.SFX) { SoundData soundData2 = AsSFX(); for (int j = 0; j < soundData2.definition.Clips.Length; j++) { soundData2.definition.Clips[j] = _audioData; } } } } public Sprite CoverSprite { get; set; } ~SoundData() { Dispose(); } public void Dispose() { entry.SettingChanged -= Entry_SettingChanged; } private SoundData(T definition, ConfigEntry entry) { this.definition = definition; this.entry = entry; entryName = ((ConfigEntryBase)entry).Definition.Key; TrackData = emptyTrack.Value; if (typeof(MusicDefinition).IsAssignableFrom(typeof(T))) { type = SoundType.Music; } else if (typeof(SoundCueDefinition).IsAssignableFrom(typeof(T))) { type = SoundType.SFX; } CreateTrackInfo(); this.entry.SettingChanged += Entry_SettingChanged; } public static SoundData Create(ConfigEntry entry, T definition) { if (!IsValidType()) { return null; } if (entry == null) { Plugin.LogSource.LogError((object)"Cannot create SoundData with null entry"); return null; } if (definition == null) { Plugin.LogSource.LogError((object)"Cannot create SoundData with null definition"); return null; } return new SoundData(definition, entry); } public static bool IsValidType() { if (typeof(MusicDefinition).IsAssignableFrom(typeof(T)) || typeof(SoundCueDefinition).IsAssignableFrom(typeof(T))) { return true; } Plugin.LogSource.LogError((object)"T must be of type CoreMusicData.MusicDefinition or CoreSoundEffectData.SoundCueDefinition"); return false; } private void CreateTrackInfo() { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected O, but got Unknown if (IsFileExist()) { TrackData = new Track(GetFilePath(), (IProgress)null, true); if (IEnumerableUtility.IsNullOrEmpty((IEnumerable)TrackData.EmbeddedPictures)) { return; } PictureInfo val = ((IEnumerable)TrackData.EmbeddedPictures).FirstOrDefault((Func)((PictureInfo picture) => picture != null && (int)picture.PicType == 2)); if (val == null) { val = ((IEnumerable)TrackData.EmbeddedPictures).FirstOrDefault((Func)((PictureInfo picture) => picture != null && (int)picture.PicType == 18)); } if (val == null) { val = ((IEnumerable)TrackData.EmbeddedPictures).FirstOrDefault((Func)((PictureInfo picture) => picture != null)); } if (val != null) { AssignCover(val.PictureData); } } else { TrackData = emptyTrack.Value; } } private void Entry_SettingChanged(object sender, EventArgs e) { CreateTrackInfo(); } public SoundData AsMusic() { return this as SoundData; } public SoundData AsSFX() { return this as SoundData; } public bool AssignDefinitionToData(T definition) { //IL_0128: 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_01e1: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) //IL_0202: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Expected O, but got Unknown //IL_021e: Unknown result type (might be due to invalid IL or missing references) //IL_0253: Expected O, but got Unknown if (!IsValidType()) { return false; } if (definition == null) { Plugin.LogSource.LogError((object)"Cannot assign data to null definition"); return false; } if (type == SoundType.Music) { SoundData soundData = AsMusic(); object obj = definition; MusicDefinition val = (MusicDefinition)((obj is MusicDefinition) ? obj : null); if (soundData == null) { Plugin.LogSource.LogError((object)"The instance isn't SoundData somehow despite the type is a music"); return false; } if (val == null) { Plugin.LogSource.LogError((object)"The target instance isn't MusicDefinition somehow despite the type is a music"); return false; } if (soundData.definition == null) { Plugin.LogSource.LogError((object)"Definition is null"); return false; } soundData.definition.Mixer = val.Mixer; if (!IEnumerableUtility.IsNullOrEmpty((IEnumerable)val.Clips)) { soundData.definition.Clips = (MusicClipDefinition[])(object)new MusicClipDefinition[val.Clips.Length]; for (int i = 0; i < val.Clips.Length; i++) { soundData.definition.Clips[i] = new MusicClipDefinition { MixerGroup = val.Clips[i]?.MixerGroup, Clip = val.Clips[i]?.Clip }; } } else { soundData.definition.Clips = (MusicClipDefinition[])(object)new MusicClipDefinition[1]; } if (!IEnumerableUtility.IsNullOrEmpty((IEnumerable)val.Snapshots)) { soundData.definition.Snapshots = (MusicSnapshotDefinition[])(object)new MusicSnapshotDefinition[val.Snapshots.Length]; for (int j = 0; j < val.Clips.Length; j++) { soundData.definition.Snapshots[j] = new MusicSnapshotDefinition { Name = val.Snapshots[j]?.Name, Snapshot = val.Snapshots[j]?.Snapshot, TransitionTimeSeconds = (val.Snapshots[j]?.TransitionTimeSeconds).Value }; } } else { soundData.definition.Snapshots = (MusicSnapshotDefinition[])(object)new MusicSnapshotDefinition[1]; } soundData.definition.Name = ((ConfigEntryBase)entry).Definition.Key; } else if (type == SoundType.SFX) { SoundData soundData2 = AsSFX(); object obj2 = definition; SoundCueDefinition val2 = (SoundCueDefinition)((obj2 is SoundCueDefinition) ? obj2 : null); if (soundData2 == null) { Plugin.LogSource.LogError((object)"The instance isn't SoundData somehow despite the type is an SFX"); return false; } if (val2 == null) { Plugin.LogSource.LogError((object)"The target instance isn't SoundCueDefinition somehow despite the type is an SFX"); return false; } if (soundData2.definition == null) { Plugin.LogSource.LogError((object)"Definition is null"); return false; } if (!IEnumerableUtility.IsNullOrEmpty((IEnumerable)val2.Clips)) { soundData2.definition.Clips = (AudioClip[])(object)new AudioClip[val2.Clips.Length]; for (int k = 0; k < val2.Clips.Length; k++) { soundData2.definition.Clips[k] = val2.Clips[k]; } } else { soundData2.definition.Clips = (AudioClip[])(object)new AudioClip[1]; } soundData2.definition.VolumeMin = val2.VolumeMin; soundData2.definition.VolumeMax = val2.VolumeMax; soundData2.definition.PitchMin = val2.PitchMin; soundData2.definition.PitchMax = val2.PitchMax; soundData2.definition.Loop = val2.Loop; if (!IEnumerableUtility.IsNullOrEmpty((IEnumerable)val2.Tags)) { soundData2.definition.Tags = new string[val2.Tags.Length]; for (int l = 0; l < val2.Tags.Length; l++) { soundData2.definition.Tags[l] = val2.Tags[l]; } } else { soundData2.definition.Tags = new string[1]; } soundData2.definition.Name = ((ConfigEntryBase)entry).Definition.Key; } return true; } public void AssignCover(string filePath) { if (!File.Exists(filePath)) { Plugin.LogSource.LogError((object)("Cannot create cover for entry " + entryName + " on non-existent file")); } else { AssignCover(File.ReadAllBytes(filePath)); } } public void AssignCover(byte[] data) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Expected O, but got Unknown //IL_002f: 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) Texture2D val = new Texture2D(0, 0); if (ImageConversion.LoadImage(val, data)) { CoverSprite = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), Vector2.zero, 100f, 0u, (SpriteMeshType)1); } else { Plugin.LogSource.LogError((object)("Failed creating cover image for entry " + entryName)); } } public string GetTitle() { string result = ""; if (!IsEmptyTrackData() && !string.IsNullOrWhiteSpace(TrackData.Title)) { result = TrackData.Title; } else if (File.Exists(entry.Value)) { result = Path.GetFileNameWithoutExtension(entry.Value); } else if ((Object)(object)AudioData != (Object)null) { result = Plugin.RemoveGUIDFromName(AudioData); } return result; } public string GetFilePath() { string text = entry.Value; if (!File.Exists(text)) { if (Path.IsPathRooted(text)) { Plugin.LogSource.LogError((object)("The path must not be rooted if you want to make it relative to the mod path " + text)); } text = Path.Combine(Plugin.BasePath, text); } return text; } public string GetExtension() { return Path.GetExtension(entry.Value); } public bool IsFileExist() { return File.Exists(GetFilePath()); } public bool IsEmptyTrackData() { return TrackData == emptyTrack.Value; } public int Duration() { int result = 0; if ((Object)(object)AudioData != (Object)null) { result = Mathf.RoundToInt(AudioData.length); } else if (!IsEmptyTrackData()) { result = TrackData.Duration; } return result; } } public class SoundDialog : ScreenDialog { internal Dictionary scrollRectsSection = new Dictionary(); internal Dictionary tabsSection = new Dictionary(); internal List soundList = new List(); internal GameUISelectableButton soundChangerButton; internal TextMeshProUGUI headerTitle; internal TMP_Text musicLabel; internal LayoutElement ContentLayout; public static SoundDialog Instance { get; private set; } public static SettingsScreen SettingsScreen { get; } = (SettingsScreen)AllGameManagers.Instance.GetScreenManager().GetScreen((ScreenName)18); public static PauseDialog PauseDialog { get; private set; } private void Start() { //IL_0087: 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) ((Object)this).name = "Sound Dialog"; PauseDialog = Traverse.Create((object)SettingsScreen).Field("pauseDialog").Value; headerTitle = ((Component)((Component)this).transform.Find("Header/Title")).GetComponent(); ((TMP_Text)headerTitle).enableAutoSizing = true; ((TMP_Text)headerTitle).overflowMode = (TextOverflowModes)1; ((TMP_Text)headerTitle).fontSizeMin = 20f; ((TMP_Text)headerTitle).rectTransform.sizeDelta = new Vector2(-100f, 64f); musicLabel = Traverse.Create((object)PauseDialog).Field("musicLabel").Value; musicLabel.overflowMode = (TextOverflowModes)1; ContentLayout = new GameObject("Content Layout").AddComponent(); ContentLayout.preferredHeight = 818f; ((Component)ContentLayout).transform.SetParent(((Component)this).transform.Find("Content"), false); InitializeTabs(); CreateSection("Music", tabsSection["Music"], Plugin.MusicEntries.Keys.ToList()); CreateSection("SFX", tabsSection["SFX"], Plugin.SFXEntries.Keys.ToList()); Traverse val = Traverse.Create((object)this); base._canvasGroup = ((Component)this).GetComponent(); val.Field("_timelineTransition").SetValue((object)((Component)this).GetComponent()); base._closeButton = ((Component)((Component)this).transform.Find("Bg container/CloseButton")).GetComponent(); Traverse.Create((object)PauseDialog).Field("musicLabelRoot").Value.SetActive(true); Plugin.musicChanged.AddListener((Action)UpdateCurrentMusicName); SetSection(Plugin.currentSectionEntry.Value, updateEntry: false); Plugin.currentSectionEntry.SettingChanged += CurrentSectionEntry_SettingChanged; Instance.UpdateCurrentMusicName(AllGameManagers.Instance.GetSoundManager().currentTrackName); } private void CurrentSectionEntry_SettingChanged(object sender, EventArgs e) { SetSection(Plugin.currentSectionEntry.Value, updateEntry: false); } private void CreateSoundChangerButton(PauseDialog pauseDialog) { GameUISelectableButton value = Traverse.Create((object)pauseDialog).Field("settingsButton").Value; soundChangerButton = Object.Instantiate(value, ((Component)value).transform.parent); ((Object)soundChangerButton).name = "Sound Changer button"; ((Component)soundChangerButton).transform.SetSiblingIndex(1); TMP_Text componentInChildren = ((Component)soundChangerButton).GetComponentInChildren(true); Object.DestroyImmediate((Object)(object)((Component)componentInChildren).GetComponent()); componentInChildren.text = "Sound Changer"; } private void OnDestroy() { Plugin.musicChanged.RemoveListener((Action)UpdateCurrentMusicName); Plugin.currentSectionEntry.SettingChanged -= CurrentSectionEntry_SettingChanged; } internal void UpdateCurrentMusicName(string trackName) { TextMeshProHelper.SetTextSafe(musicLabel, trackName, true); ((TMP_Text)headerTitle).text = "Currently Playing: " + trackName + ""; } internal void SetSection(string sectionName, bool updateEntry) { if (!scrollRectsSection.ContainsKey(sectionName)) { Plugin.LogSource.LogError((object)("Section named " + sectionName + " doesn't exist")); return; } if (updateEntry) { Plugin.SetBrowsableSection(sectionName, Plugin.currentSectionEntry.Value != sectionName); Plugin.currentSectionEntry.Value = sectionName; } foreach (KeyValuePair item in tabsSection) { item.Value.SetActivated(item.Key == sectionName); } } private void InitializeTabs() { Object.Destroy((Object)(object)((Component)((Component)this).transform.Find("Content/Content")).gameObject); Object.Destroy((Object)(object)((Component)headerTitle).GetComponent()); Transform val = ((Component)this).transform.Find("Content/Tabs"); for (int i = 2; i < val.childCount - 1; i++) { Object.Destroy((Object)(object)((Component)val.GetChild(i)).gameObject); } tabsSection["Music"] = ((Component)val.GetChild(0)).GetComponent(); tabsSection["SFX"] = ((Component)val.GetChild(1)).GetComponent(); } private void CreateSection(string sectionName, SettingsTab settingsTab, List entries) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) RectTransform val = new GameObject(sectionName + " Section").AddComponent(); ((Component)val).gameObject.layer = LayerMask.NameToLayer("UI"); ((Component)val).transform.SetParent(((Component)ContentLayout).transform, false); val.anchoredPosition = new Vector2(0f, 30f); scrollRectsSection[sectionName] = CreateScrollRect((Transform)(object)val); Traverse.Create((object)settingsTab).Field("sectionRoot").SetValue((object)((Component)val).gameObject); TextMeshProUGUI componentInChildren = ((Component)settingsTab).GetComponentInChildren(true); Object.DestroyImmediate((Object)(object)((Component)componentInChildren).GetComponent()); ((TMP_Text)componentInChildren).text = sectionName; for (int i = 0; i < entries.Count; i++) { ConfigEntryBase entry = entries[i]; soundList.Add(CreateItem(entry, scrollRectsSection[sectionName], i % 2 == 1)); } CreateEmptyItem(scrollRectsSection[sectionName]); } private ScrollRect CreateScrollRect(Transform parent) { //IL_0006: 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_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Expected O, but got Unknown //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Expected O, but got Unknown //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_0269: Unknown result type (might be due to invalid IL or missing references) ScrollRect val = new GameObject("ScrollRect").AddComponent(); ((Component)val).transform.localPosition = new Vector3(0f, -20f); ((Component)val).transform.SetParent(parent, false); ((Component)val).gameObject.layer = LayerMask.NameToLayer("UI"); GameObject val2 = new GameObject("Viewport", new Type[3] { typeof(RectTransform), typeof(Image), typeof(Mask) }); val2.transform.SetParent(((Component)val).transform, false); val.viewport = val2.GetComponent(); val.viewport.anchoredPosition = new Vector2(0f, 340f); val.viewport.pivot = new Vector2(0.5f, 1f); val.viewport.sizeDelta = new Vector2(1000f, 720f); val2.GetComponent().showMaskGraphic = false; Transform val3 = ((Component)this).transform.Find("Bg container/Image bg banner"); val2.GetComponent().sprite = ((Component)val3).GetComponent().sprite; val2.GetComponent().type = (Type)1; AspectRatioFitter component = ((Component)val3).GetComponent(); AspectRatioFitter val4 = val2.AddComponent(); val4.aspectRatio = component.aspectRatio; val4.aspectMode = component.aspectMode; GameObject val5 = new GameObject("Content", new Type[3] { typeof(RectTransform), typeof(GridLayoutGroup), typeof(ContentSizeFitter) }); val5.transform.SetParent(val2.transform, false); RectTransform component2 = val5.GetComponent(); component2.pivot = new Vector2(0.5f, 1f); val.content = component2; val.content.sizeDelta = val.viewport.sizeDelta; val.vertical = true; val.horizontal = false; val.scrollSensitivity = 80f; val.inertia = false; val.verticalScrollbarVisibility = (ScrollbarVisibility)1; val.movementType = (MovementType)2; val.decelerationRate = 0.135f; val.verticalScrollbar = CreateVerticalScrollbar(((Component)val).transform); val5.GetComponent().verticalFit = (FitMode)2; GridLayoutGroup component3 = ((Component)component2).GetComponent(); component3.cellSize = new Vector2(1000f, 100f); ((LayoutGroup)component3).childAlignment = (TextAnchor)1; component3.constraint = (Constraint)1; component3.constraintCount = 1; return val; } private Scrollbar CreateVerticalScrollbar(Transform parent) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown //IL_007e: 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_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: 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_00ff: Expected O, but got Unknown //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Expected O, but got Unknown //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: Unknown result type (might be due to invalid IL or missing references) //IL_0222: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Expected O, but got Unknown //IL_024e: Unknown result type (might be due to invalid IL or missing references) //IL_0258: Unknown result type (might be due to invalid IL or missing references) //IL_026a: Unknown result type (might be due to invalid IL or missing references) //IL_027c: Unknown result type (might be due to invalid IL or missing references) //IL_028e: Unknown result type (might be due to invalid IL or missing references) //IL_0298: Unknown result type (might be due to invalid IL or missing references) //IL_02aa: Unknown result type (might be due to invalid IL or missing references) //IL_02b4: Unknown result type (might be due to invalid IL or missing references) //IL_02cc: Unknown result type (might be due to invalid IL or missing references) //IL_02d1: Unknown result type (might be due to invalid IL or missing references) //IL_02d6: Unknown result type (might be due to invalid IL or missing references) //IL_02e0: Expected O, but got Unknown //IL_0314: Unknown result type (might be due to invalid IL or missing references) //IL_0338: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("Vertical Scrollbar", new Type[2] { typeof(Scrollbar), typeof(Image) }); Scrollbar component = val.GetComponent(); component.direction = (Direction)2; val.GetComponent().type = (Type)1; val.GetComponent().sprite = Plugin.scrollbarAtlas.GetSprite("SH_Bg_Scrollbar"); RectTransform component2 = val.GetComponent(); ((Transform)component2).SetParent(parent, false); component2.anchoredPosition = new Vector2(460f, 285f); component2.anchorMin = new Vector2(1f, 0f); component2.anchorMax = new Vector2(1f, 1f); component2.pivot = new Vector2(1f, 1f); component2.sizeDelta = new Vector2(24f, 510f); GameObject val2 = new GameObject("Sliding Area", new Type[1] { typeof(RectTransform) }); RectTransform component3 = val2.GetComponent(); ((Transform)component3).SetParent(val.transform, false); component3.anchorMin = Vector2.zero; component3.anchorMax = Vector2.one; component3.sizeDelta = Vector2.zero; GameObject val3 = new GameObject("Handle", new Type[1] { typeof(Image) }); RectTransform component4 = val3.GetComponent(); ((Transform)component4).SetParent(val2.transform, false); component4.anchorMin = new Vector2(0f, 0.6831f); component4.anchorMax = new Vector2(1f, 0f); component4.offsetMax = Vector2.zero; component4.offsetMin = Vector2.zero; component4.pivot = new Vector2(0.5f, 0.5f); component4.sizeDelta = Vector2.zero; ((Component)component4).GetComponent().type = (Type)1; ((Component)component4).GetComponent().sprite = Plugin.scrollbarAtlas.GetSprite("CMP_Scrollbar"); GameObject val4 = new GameObject("Target Graphic", new Type[1] { typeof(Image) }); val4.transform.SetParent(((Component)component4).transform, false); Image component5 = val4.GetComponent(); ((Graphic)component5).rectTransform.sizeDelta = Vector2.one * 20f; ((Graphic)component5).rectTransform.anchorMax = Vector2.one; ((Graphic)component5).rectTransform.anchorMin = Vector2.zero; ((Graphic)component5).rectTransform.offsetMax = Vector2.one * 10f; ((Graphic)component5).rectTransform.offsetMin = Vector2.one * -10f; component5.type = (Type)1; component5.sprite = Sprite.Create(new Texture2D(0, 0), Rect.zero, Vector2.zero); Sprite sprite = Plugin.scrollbarAtlas.GetSprite("SH_Square_Border_Highlight"); component.handleRect = component4; ((Selectable)component).targetGraphic = (Graphic)(object)component5; ((Selectable)component).transition = (Transition)2; SpriteState spriteState = default(SpriteState); ((SpriteState)(ref spriteState)).pressedSprite = sprite; ((SpriteState)(ref spriteState)).highlightedSprite = sprite; ((SpriteState)(ref spriteState)).selectedSprite = sprite; ((Selectable)component).spriteState = spriteState; return component; } private GameObject CreateEmptyItem(ScrollRect scrollRect) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) ContentSizeFitter val = new GameObject("Empty", new Type[1] { typeof(RectTransform) }).AddComponent(); ((Component)val).transform.SetParent((Transform)(object)scrollRect.content, false); val.horizontalFit = (FitMode)2; val.verticalFit = (FitMode)2; return ((Component)val).gameObject; } private SoundInfo CreateItem(ConfigEntryBase entry, ScrollRect scrollRect, bool createBG) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) SoundInfo soundInfo = new GameObject(entry.Definition.Key).AddComponent(); ((Component)soundInfo).transform.SetParent((Transform)(object)scrollRect.content, false); if (createBG) { Image val = new GameObject("BG").AddComponent(); ((Graphic)val).color = new Color(0f, 0f, 0f, 0.5f); ((Graphic)val).rectTransform.anchorMin = Vector2.zero; ((Graphic)val).rectTransform.anchorMax = Vector2.one; ((Component)val).transform.SetParent(((Component)soundInfo).transform, false); } soundInfo.Set(SettingsScreen, entry); return soundInfo; } public override bool ApplyScreenInput(CoreInputControlMapping mapping, IGameUIComponent triggeredUI, Controls triggeredMappingID) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_002c: 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_00f2: Unknown result type (might be due to invalid IL or missing references) if (((ScreenDialog)this).ApplyScreenInput(mapping, triggeredUI, triggeredMappingID)) { return true; } if ((Object)(object)soundChangerButton != (Object)null && soundChangerButton.TryTrigger(mapping, triggeredUI, triggeredMappingID, false, false)) { ((ScreenDialog)this).Open(); return true; } foreach (KeyValuePair item in tabsSection) { if ((Object)(object)item.Value != (Object)null && item.Value.TryTrigger(mapping, triggeredUI, triggeredMappingID)) { SetSection(item.Key, updateEntry: true); return true; } } foreach (SoundInfo sound in soundList) { if (!((Component)sound).gameObject.activeInHierarchy || !sound.TryTrigger(mapping, triggeredUI, triggeredMappingID)) { continue; } return true; } return false; } public override void Close() { ((ScreenDialog)this).Close(); SoundManager.PlaySfxSignal.Dispatch("UI_Cancel"); } internal static void CreateDialog(SettingsScreen settingScreen) { if (!((Object)(object)settingScreen == (Object)null)) { Traverse val = Traverse.Create((object)settingScreen); SettingsDialog value = val.Field("settingsDialog").Value; PauseDialog value2 = val.Field("pauseDialog").Value; SettingsDialog val2 = Object.Instantiate(value, ((Component)value).transform.parent); GameObject gameObject = ((Component)val2).gameObject; Object.DestroyImmediate((Object)(object)val2); Instance = gameObject.AddComponent(); Instance.CreateSoundChangerButton(value2); } } } public class NativeFileDialog { [Flags] public enum OFN_Flags { OFN_ALLOWMULTISELECT = 0x200, OFN_CREATEPROMPT = 0x2000, OFN_DONTADDTORECENT = 0x2000000, OFN_ENABLEHOOK = 0x20, OFN_ENABLEINCLUDENOTIFY = 0x400000, OFN_ENABLESIZING = 0x800000, OFN_ENABLETEMPLATE = 0x40, OFN_ENABLETEMPLATEHANDLE = 0x80, OFN_EXPLORER = 0x80000, OFN_EXTENSIONDIFFERENT = 0x400, OFN_FILEMUSTEXIST = 0x1000, OFN_FORCESHOWHIDDEN = 0x10000000, OFN_HIDEREADONLY = 4, OFN_LONGNAMES = 0x200000, OFN_NOCHANGEDIR = 8, OFN_NODEREFERENCELINKS = 0x100000, OFN_NOLONGNAMES = 0x40000, OFN_NONETWORKBUTTON = 0x20000, OFN_NOREADONLYRETURN = 0x8000, OFN_NOTESTFILECREATE = 0x10000, OFN_NOVALIDATE = 0x100, OFN_OVERWRITEPROMPT = 2, OFN_PATHMUSTEXIST = 0x800, OFN_READONLY = 1, OFN_SHAREAWARE = 0x4000, OFN_SHOWHELP = 0x10 } [Flags] public enum OFN_Flags_EX { OFN_EX_NOPLACESBAR = 1 } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] private struct OpenFileName { public int lStructSize; public IntPtr hwndOwner; public IntPtr hInstance; public string lpstrFilter; public string lpstrCustomFilter; public int nMaxCustFilter; public int nFilterIndex; public string lpstrFile; public int nMaxFile; public string lpstrFileTitle; public int nMaxFileTitle; public string lpstrInitialDir; public string lpstrTitle; public int Flags; public short nFileOffset; public short nFileExtension; public string lpstrDefExt; public IntPtr lCustData; public IntPtr lpfnHook; public string lpTemplateName; public IntPtr pvReserved; public int dwReserved; public int FlagsEx; } [DllImport("comdlg32.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern bool GetOpenFileName(ref OpenFileName ofn); public static void OpenSingleFile(Action onComplete, string title = "Open File", string filter = "All Files\0*.*\0\0", string initialDir = "", string initialFile = "") { OpenFileName ofn = default(OpenFileName); ofn.lStructSize = Marshal.SizeOf(ofn); ofn.lpstrFilter = filter; char[] array = new char[260]; if (!string.IsNullOrEmpty(initialFile)) { initialFile.CopyTo(0, array, 0, Math.Min(initialFile.Length, 259)); } ofn.lpstrFile = new string(array); ofn.nMaxFile = ofn.lpstrFile.Length; ofn.lpstrFileTitle = new string(new char[64]); ofn.nMaxFileTitle = ofn.lpstrFileTitle.Length; ofn.lpstrInitialDir = initialDir; ofn.lpstrTitle = title; ofn.Flags = 530440; if (GetOpenFileName(ref ofn)) { onComplete?.Invoke(ofn.lpstrFile); } } } internal class PatchList { [HarmonyPostfix] [HarmonyPatch(typeof(AppManager), "DoesThisBuildReportErrors")] public static void DisableErrorReportingPatch(ref bool __result) { __result = false; } [HarmonyPrefix] [HarmonyPatch(typeof(AudioClip), "LoadAudioData")] public static bool LoadAudioData(AudioClip __instance, ref bool __result) { if (((Object)__instance).name.Contains("Patty_SoundChanger_MOD")) { __result = true; return false; } return true; } [HarmonyPrefix] [HarmonyPatch(typeof(AudioClip), "UnloadAudioData")] public static bool UnloadAudioData(AudioClip __instance, ref bool __result) { if (((Object)__instance).name.Contains("Patty_SoundChanger_MOD")) { __result = true; return false; } return true; } [HarmonyPrefix] [HarmonyPatch(/*Could not decode attribute arguments.*/)] public static void CurrentTrackName_Set(SoundManager __instance, CoreAudioSystem ___audioSystem, ref string value) { string modifiedAudioName = Plugin.GetModifiedAudioName(value, ___audioSystem); if (!string.IsNullOrEmpty(modifiedAudioName)) { value = modifiedAudioName; } } [HarmonyPostfix] [HarmonyPatch(typeof(LoadScreen), "StartLoadingScreen")] public static void StartLoadingScreen(LoadScreen __instance) { Plugin.CreateEntries(); } [HarmonyPostfix] [HarmonyPatch(typeof(SoundManager), "PlayMusic")] public static void PlayMusic(SoundManager __instance, string trackName, List ___battleMusicTracks, List ___bossBattleMusicTracks, CoreAudioSystem ___audioSystem) { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) string text = __instance.currentTrackName; string modifiedAudioName = Plugin.GetModifiedAudioName(trackName, ___audioSystem); if (!string.IsNullOrEmpty(modifiedAudioName)) { text = modifiedAudioName; } else { IEnumerable source = ___battleMusicTracks.Union(___bossBattleMusicTracks); BattleMusicTrack val = source.FirstOrDefault((Func)((BattleMusicTrack track) => track.trackNameData == trackName)); if (!string.IsNullOrEmpty(val.trackNameData)) { text = val.publicTrackNameKey; } } if (string.IsNullOrEmpty(text)) { text = trackName; } else if (LocalizationManager.IsTranslatableTerm(text)) { text = LocalizationManager.GetTranslation(text, true, 0, true, true, (GameObject)null, (string)null, (ILocalizationParameterContext)null); } else if (LocalizationManager.IsTranslatableTerm(trackName)) { text = LocalizationManager.GetTranslation(trackName, true, 0, true, true, (GameObject)null, (string)null, (ILocalizationParameterContext)null); } text = Plugin.RemoveTranslationWrap(text); Plugin.musicChanged.Dispatch(text); } [HarmonyPostfix] [HarmonyPatch(typeof(SoundManager), "PlayBattleMusic")] public static void PlayBattleMusic(SoundManager __instance) { string text = __instance.currentTrackName; if (LocalizationManager.IsTranslatableTerm(text)) { text = LocalizationManager.GetTranslation(text, true, 0, true, true, (GameObject)null, (string)null, (ILocalizationParameterContext)null); } if (text.StartsWith("KEY>>") && text.EndsWith("<<")) { text = Plugin.RemoveTranslationWrap(text); Plugin.OnMusicChanged(text); SoundManager.BattleMusicChanged.Dispatch(text); } Plugin.musicChanged.Dispatch(text); } } [BepInPlugin("Patty_SoundChanger_MOD", "Sound Changer", "2.1.0")] public class Plugin : BaseUnityPlugin { [CompilerGenerated] private sealed class <>c__DisplayClass75_0 { public SoundManager soundManager; public bool isBattleMusic; public float crossfadeTimeSeconds; public ConfigEntryBase entry; public string displayedName; public Action onPlay; } [CompilerGenerated] private sealed class d__77 : IEnumerator, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public string filePath; public Action onComplete; private UnityWebRequest 5__1; private AudioClip 5__2; object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__77(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { int num = <>1__state; if (num == -3 || num == 1) { try { } finally { <>m__Finally1(); } } 5__1 = null; 5__2 = null; <>1__state = -2; } private bool MoveNext() { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Invalid comparison between Unknown and I4 try { switch (<>1__state) { default: return false; case 0: <>1__state = -1; 5__1 = UnityWebRequestMultimedia.GetAudioClip(filePath, GetAudioType(filePath)); <>1__state = -3; <>2__current = 5__1.SendWebRequest(); <>1__state = 1; return true; case 1: <>1__state = -3; if ((int)5__1.result == 1) { 5__2 = DownloadHandlerAudioClip.GetContent(5__1); ((Object)5__2).name = "Patty_SoundChanger_MOD_" + Path.GetFileNameWithoutExtension(filePath); onComplete?.Invoke(5__2); 5__2 = null; } else { LogSource.LogError((object)5__1.error); onComplete?.Invoke(null); } <>m__Finally1(); 5__1 = null; return false; } } catch { //try-fault ((IDisposable)this).Dispose(); throw; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void <>m__Finally1() { <>1__state = -1; if (5__1 != null) { ((IDisposable)5__1).Dispose(); } } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } public const string MUSIC_SECTION = "Music"; public const string SFX_SECTION = "SFX"; internal static Traverse configurationManagerTraverse; internal static Lazy centeredStyle = new Lazy((Func)(() => new GUIStyle { alignment = (TextAnchor)4 })); internal static ConfigEntry currentSectionEntry; internal static MethodInfo rebuildSettings; internal static SpriteAtlas scrollbarAtlas; internal static ConfigEntry enableIngameMenu; public static readonly Signal musicChanged = new Signal(); public static readonly ISoundChanger soundChangerManager = new SoundChangerManager(); public static readonly Signal onInitialize = new Signal(); internal static bool Initialized { get; private set; } internal static string BasePath { get; } = Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName; internal static Plugin Instance { get; private set; } internal static ManualLogSource LogSource { get; private set; } internal static Harmony PluginHarmony { get; private set; } internal static ConfigFile Config { get; private set; } internal static OrderedDictionary> MusicEntries { get; private set; } = new OrderedDictionary>(); internal static OrderedDictionary> SFXEntries { get; private set; } = new OrderedDictionary>(); internal static OrderedDictionary> OriginalMusics { get; private set; } = new OrderedDictionary>(); internal static OrderedDictionary> OriginalSFX { get; private set; } = new OrderedDictionary>(); internal static int LeftColumnWidth { get { if (configurationManagerTraverse == null) { return 260; } Traverse val = configurationManagerTraverse.Property("LeftColumnWidth", (object[])null); if (!val.PropertyExists()) { return 260; } return val.GetValue(); } } private void Awake() { //IL_003f: Expected O, but got Unknown //IL_00af: Expected O, but got Unknown //IL_0079: Expected O, but got Unknown //IL_01c4: Expected O, but got Unknown //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Expected O, but got Unknown //IL_0193: Expected O, but got Unknown //IL_01f5: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_026c: Expected O, but got Unknown //IL_026c: Expected O, but got Unknown //IL_027c: Unknown result type (might be due to invalid IL or missing references) //IL_02e9: Unknown result type (might be due to invalid IL or missing references) //IL_02f3: Expected O, but got Unknown //IL_02f3: Expected O, but got Unknown Instance = this; LogSource = ((BaseUnityPlugin)this).Logger; Config = ((BaseUnityPlugin)this).Config; try { PluginHarmony = Harmony.CreateAndPatchAll(typeof(PatchList), "Patty_SoundChanger_MOD"); } catch (HarmonyException val) { HarmonyException val2 = val; LogSource.LogError((object)((Exception)(((object)((Exception)(object)val2).InnerException) ?? ((object)val2))).Message); } try { PluginHarmony.PatchAll(typeof(TranspilerFix)); } catch (HarmonyException val3) { HarmonyException val4 = val3; LogSource.LogError((object)((Exception)(((object)((Exception)(object)val4).InnerException) ?? ((object)val4))).Message); try { PluginHarmony.PatchAll(typeof(TemporaryFix)); } catch (HarmonyException val5) { HarmonyException val6 = val5; LogSource.LogError((object)((Exception)(((object)((Exception)(object)val6).InnerException) ?? ((object)val6))).Message); } } if (Chainloader.PluginInfos.TryGetValue("com.bepis.bepinex.configurationmanager", out var value)) { configurationManagerTraverse = Traverse.Create((object)value.Instance); try { Type type = ((object)value.Instance).GetType().Assembly.GetType("ConfigurationManager.ConfigurationManager"); rebuildSettings = AccessTools.DeclaredMethod(type, "BuildSettingList", (Type[])null, (Type[])null); } catch (Exception ex) { LogSource.LogError((object)(ex.InnerException ?? ex).Message); } } enableIngameMenu = Config.Bind(new ConfigDefinition("Basic", "Toggle in-game menu"), true, new ConfigDescription("If enabled, then create an in-game menu (recommended to disable if future game update breaks this mod). Restart to apply", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Order = 10001 } })); if (enableIngameMenu.Value) { try { PluginHarmony.PatchAll(typeof(MenuPatch)); } catch (HarmonyException val7) { HarmonyException val8 = val7; LogSource.LogError((object)((Exception)(((object)((Exception)(object)val8).InnerException) ?? ((object)val8))).Message); } } Config.Bind(new ConfigDefinition("Basic", "Currently Playing"), "", new ConfigDescription("Only for references as to what music is currently playing in game", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Order = 10000, CustomDrawer = CurrentlyPlayingDrawer, HideDefaultButton = true, HideSettingName = true, ReadOnly = true } })); currentSectionEntry = Config.Bind(new ConfigDefinition("Basic", "Toggled Section"), "", new ConfigDescription("Only for toggling sections", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Order = 9999, CustomDrawer = ToggleSectionDrawer, HideDefaultButton = true, HideSettingName = true, ReadOnly = true } })); if (string.IsNullOrEmpty(currentSectionEntry.Value) || (currentSectionEntry.Value != "Music" && currentSectionEntry.Value != "SFX")) { currentSectionEntry.Value = "Music"; } if (enableIngameMenu.Value) { AssetBundle val9 = AssetBundle.LoadFromFile(Path.Combine(BasePath, "scrollbar.bundle")); scrollbarAtlas = val9.LoadAsset("ScrollbarAtlas"); val9.Unload(false); } musicChanged.AddListener((Action)OnMusicChanged); } private void OnDestroy() { musicChanged.RemoveListener((Action)OnMusicChanged); } internal static void OnMusicChanged(string trackName) { SoundManager soundManager = AllGameManagers.Instance.GetSoundManager(); Traverse.Create((object)soundManager).Property("currentTrackName", (object[])null).SetValue((object)trackName); } internal static void CreateEntries() { //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Expected O, but got Unknown if (Initialized) { return; } AllGameManagers instance = AllGameManagers.Instance; if ((Object)(object)instance == (Object)null || (Object)(object)instance.GetSoundManager() == (Object)null) { return; } Initialized = true; if (enableIngameMenu.Value) { SettingsScreen settingScreen = (SettingsScreen)instance.GetScreenManager().GetScreen((ScreenName)18); SoundDialog.CreateDialog(settingScreen); } SoundManager soundManager = instance.GetSoundManager(); Traverse val = Traverse.Create((object)soundManager); CoreAudioSystem value = val.Field("audioSystem").Value; CoreAudioSystemData value2 = Traverse.Create((object)value).Field("AudioSystemData").GetValue(); foreach (MusicDefinition item in value2.MusicDefData.Tracks.OrderBy((MusicDefinition track) => track.Name)) { CreateEntry(item); } foreach (SoundCueDefinition item2 in value2.GlobalSoundEffectData.Sounds.OrderBy((SoundCueDefinition track) => track.Name)) { CreateEntry(item2); } SetBrowsableSection(currentSectionEntry.Value); onInitialize.Dispatch(); } internal static void CreateEntry(MusicDefinition definition) { //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Expected O, but got Unknown //IL_012b: Expected O, but got Unknown if (definition == null || MusicEntries.Values.Any((SoundData data) => data?.definition == definition)) { return; } if (!OriginalMusics.ContainsKey(definition)) { OriginalMusics[definition] = new List(); MusicClipDefinition[] clips = definition.Clips; foreach (MusicClipDefinition val in clips) { OriginalMusics[definition].Add(val.Clip); } } ConfigEntry entry = Config.Bind(new ConfigDefinition("Basic", definition.Name), "", new ConfigDescription("", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { HideDefaultButton = true, HideSettingName = true, CustomDrawer = MusicDrawer } })); entry.SettingChanged += Entry_SettingChanged; MusicEntries[(ConfigEntryBase)(object)entry] = SoundData.Create(entry, definition); if (MusicEntries[(ConfigEntryBase)(object)entry].IsFileExist()) { ((MonoBehaviour)Instance).StartCoroutine(LoadAudioClip(MusicEntries[(ConfigEntryBase)(object)entry].GetFilePath(), delegate(AudioClip audioClip) { OnAudioClipLoaded((ConfigEntryBase)(object)entry, audioClip); })); } } internal static void CreateEntry(SoundCueDefinition definition) { //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Expected O, but got Unknown //IL_0126: Expected O, but got Unknown if (definition == null || SFXEntries.Values.Any((SoundData data) => data?.definition == definition)) { return; } if (!OriginalSFX.ContainsKey(definition)) { OriginalSFX[definition] = new List(); AudioClip[] clips = definition.Clips; foreach (AudioClip item in clips) { OriginalSFX[definition].Add(item); } } ConfigEntry entry = Config.Bind(new ConfigDefinition("Basic", definition.Name), "", new ConfigDescription("", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { HideDefaultButton = true, HideSettingName = true, CustomDrawer = MusicDrawer } })); entry.SettingChanged += Entry_SettingChanged; SFXEntries[(ConfigEntryBase)(object)entry] = SoundData.Create(entry, definition); if (SFXEntries[(ConfigEntryBase)(object)entry].IsFileExist()) { ((MonoBehaviour)Instance).StartCoroutine(LoadAudioClip(SFXEntries[(ConfigEntryBase)(object)entry].GetFilePath(), delegate(AudioClip audioClip) { OnAudioClipLoaded((ConfigEntryBase)(object)entry, audioClip); })); } } internal static void Entry_SettingChanged(object sender, EventArgs e) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) ResetEntryBase(((SettingChangedEventArgs)e).ChangedSetting); } internal static void ResetEntryBase(ConfigEntryBase entryBase, Action onPlay = null) { string text = entryBase.BoxedValue as string; if (!string.IsNullOrEmpty(text) && File.Exists(text)) { return; } AllGameManagers instance = AllGameManagers.Instance; if ((Object)(object)instance == (Object)null || (Object)(object)instance.GetSoundManager() == (Object)null) { return; } SoundManager soundManager = instance.GetSoundManager(); if (MusicEntries.TryGetValue(entryBase, out var value)) { string currentMusicTrackName = soundManager.GetCurrentMusicTrackName(); bool flag = false; foreach (KeyValuePair> originalMusic in OriginalMusics) { if (originalMusic.Key == value.definition) { MusicClipDefinition[] clips = originalMusic.Key.Clips; for (int i = 0; i < clips.Length; i++) { clips[i].Clip = originalMusic.Value[i]; } flag = true; break; } } if (!flag) { LogSource.LogWarning((object)"Cannot found original music to reset to"); } if (value.entryName == currentMusicTrackName) { ReplayMusic(entryBase, GetPlayingMusicName(), onPlay); } } else { if (!SFXEntries.TryGetValue(entryBase, out var value2)) { return; } foreach (KeyValuePair> item in OriginalSFX) { if (item.Key == value2.definition) { AudioClip[] clips2 = item.Key.Clips; for (int j = 0; j < clips2.Length; j++) { clips2[j] = item.Value[j]; } break; } } } } internal static string GetPlayingMusicName() { //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: 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_00c0: Unknown result type (might be due to invalid IL or missing references) AllGameManagers instance = AllGameManagers.Instance; if ((Object)(object)instance == (Object)null) { return ""; } if ((Object)(object)instance.GetSoundManager() == (Object)null) { return ""; } SoundManager soundManager = instance.GetSoundManager(); Traverse val = Traverse.Create((object)soundManager); List value = val.Field>("battleMusicTracks").Value; List value2 = val.Field>("bossBattleMusicTracks").Value; value.AddRange(value2); string text = ""; string musicName = soundManager.GetCurrentMusicTrackName(); BattleMusicTrack val2 = value.Find((BattleMusicTrack track) => track.trackNameData == musicName); if (!string.IsNullOrEmpty(val2.publicTrackNameKey)) { text = val2.publicTrackNameKey; if (LocalizationManager.IsTranslatableTerm(text)) { text = LocalizationExtensions.Localize(text, (ILocalizationParameterContext)null); } } return text; } internal static string GetModifiedAudioName(string trackName, CoreAudioSystem coreAudioSystem) { if (string.IsNullOrWhiteSpace(trackName)) { return ""; } Traverse val = Traverse.Create((object)coreAudioSystem).Method("GetCurrentTrack", Array.Empty()); if (!val.MethodExists()) { return ""; } Traverse val2 = Traverse.Create(val.GetValue()).Field("MusicDefinition"); if (!val2.FieldExists() || val2.GetValue() == null) { return ""; } MusicDefinition value = val2.GetValue(); if (value == null || IEnumerableUtility.IsNullOrEmpty((IEnumerable)value.Clips)) { return ""; } if (value.Name != trackName) { if (!trackName.StartsWith("KEY>>") || !trackName.EndsWith("<<")) { return ""; } trackName = trackName.Substring("KEY>>".Length, trackName.Length - ("KEY>>".Length + "<<".Length)); if (value.Name != trackName) { return ""; } } MusicClipDefinition val3 = ((IEnumerable)value.Clips).FirstOrDefault((Func)((MusicClipDefinition source) => source != null && (Object)(object)source.Clip != (Object)null && ((Object)source.Clip).name.Contains("Patty_SoundChanger_MOD"))); if (val3 != null) { foreach (KeyValuePair> musicEntry in MusicEntries) { if (musicEntry.Value.definition == value) { return musicEntry.Value.GetTitle(); } } return RemoveGUIDFromName(val3.Clip); } return ""; } internal static string RemoveTranslationWrap(string trackName) { if (!trackName.StartsWith("KEY>>") || !trackName.EndsWith("<<")) { return trackName; } trackName = trackName.Substring("KEY>>".Length, trackName.Length - ("KEY>>".Length + "<<".Length)); return trackName; } internal static string RemoveGUIDFromName(AudioClip audioClip) { return RemoveGUIDFromName(((Object)audioClip).name); } internal static string RemoveGUIDFromName(string audioName) { int num = "Patty_SoundChanger_MOD".Length + 1; return audioName.Substring(num, audioName.Length - num); } internal static void ToggleSectionDrawer(ConfigEntryBase entry) { bool flag = GUILayout.Button("Toggle Music", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }); bool flag2 = GUILayout.Button("Toggle SFX", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }); if (flag) { currentSectionEntry.Value = "Music"; SetBrowsableSection(currentSectionEntry.Value); } else if (flag2) { currentSectionEntry.Value = "SFX"; SetBrowsableSection(currentSectionEntry.Value); } } internal static void SetBrowsableSection(string section, bool updateList = true) { bool browsable = section == "Music"; bool browsable2 = section == "SFX"; SetEntriesBrowsable(SFXEntries.Keys, browsable2); SetEntriesBrowsable(MusicEntries.Keys, browsable); if (updateList && !(rebuildSettings == null)) { rebuildSettings.Invoke(configurationManagerTraverse.GetValue(), null); } } internal static void SetEntriesBrowsable(IEnumerable entries, bool browsable) { foreach (object entry in entries) { ConfigEntry val = (ConfigEntry)entry; ConfigurationManagerAttributes configurationManagerAttributes = (ConfigurationManagerAttributes)((ConfigEntryBase)val).Description.Tags.First(); configurationManagerAttributes.Browsable = browsable; } } internal static void CurrentlyPlayingDrawer(ConfigEntryBase entry) { AllGameManagers instance = AllGameManagers.Instance; if (!((Object)(object)instance == (Object)null) && !((Object)(object)instance.GetSoundManager() == (Object)null)) { SoundManager soundManager = instance.GetSoundManager(); string text = soundManager.GetCurrentMusicTrackName(); if (!string.IsNullOrEmpty(soundManager.currentTrackName)) { text = soundManager.currentTrackName; } GUILayout.Label("Currently playing: " + text + "", centeredStyle.Value, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }); } } internal static bool IsCurrentMusic(ConfigEntryBase entry) { bool result = false; AllGameManagers instance = AllGameManagers.Instance; if ((Object)(object)instance != (Object)null && (Object)(object)instance.GetSoundManager() != (Object)null && instance.GetSoundManager().GetCurrentMusicTrackName() == entry.Definition.Key) { result = true; } return result; } internal static void MusicDrawer(ConfigEntryBase entry) { //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Expected O, but got Unknown bool flag = IsCurrentMusic(entry); string text = ""; string text2 = ""; if (flag) { text = ""; text2 = ""; } GUILayout.Label(new GUIContent(text + entry.Definition.Key + text2, (Texture)null, entry.Description.Description), (GUILayoutOption[])(object)new GUILayoutOption[2] { GUILayout.Width((float)LeftColumnWidth - 20f), GUILayout.MaxWidth((float)LeftColumnWidth - 20f) }); string text3 = entry.BoxedValue as string; bool flag2 = File.Exists(text3); if (text3 != null && flag2) { GUILayout.Label(text + Path.GetFileName(text3) + text2, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }); } bool flag3 = GUILayout.Button("Load File", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }); if (GUILayout.Button(" ▶ ", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) })) { if (MusicEntries.ContainsKey(entry)) { PlayMusic(entry); } else { PlaySFX(entry); } } if (flag2 && GUILayout.Button("Reset", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(false) })) { entry.BoxedValue = ""; ResetEntryBase(entry); } if (flag3) { LoadFile(entry, text3, flag2); } } internal static void LoadFile(ConfigEntryBase entry, string targetPath, bool existFile, Action onComplete = null, Action onPlay = null) { string filter = "Supported Files (*.wav; *.ogg; *.mp3)\0*.wav;*.ogg;*.mp3\0WAV Files (*.wav)\0*.wav\0OGG Files (*.ogg)\0*.ogg\0MP3 Files (*.mp3)\0*.mp3\0All Files\0*.*\0\0"; string initialDir = BasePath; if (existFile) { initialDir = Directory.GetParent(targetPath).FullName; } NativeFileDialog.OpenSingleFile(delegate(string filePath) { ((MonoBehaviour)Instance).StartCoroutine(LoadAudioClip(filePath, delegate(AudioClip audioClip) { if (!((Object)(object)audioClip == (Object)null)) { entry.BoxedValue = filePath; OnAudioClipLoaded(entry, audioClip, replayMusic: true, onPlay); onComplete?.Invoke(filePath, audioClip); } })); }, "Select audio to replace with", filter, initialDir, targetPath); } internal static AudioType GetAudioType(string filePath) { //IL_0041: 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_0053: 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_0056: 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) //IL_004f: Unknown result type (might be due to invalid IL or missing references) return (AudioType)(Path.GetExtension(filePath)?.ToUpperInvariant() switch { ".MP3" => 13, ".OGG" => 14, ".WAV" => 20, _ => 0, }); } internal static void OnAudioClipLoaded(ConfigEntryBase entry, AudioClip audioClip, bool replayMusic = false, Action onPlay = null) { try { if ((Object)(object)audioClip == (Object)null) { return; } if (MusicEntries.TryGetValue(entry, out var value)) { value.AudioData = audioClip; MusicDefinition definition = value.definition; if (definition != null) { MusicClipDefinition[] clips = definition.Clips; if (((clips != null) ? new bool?(IEnumerableUtility.IsNullOrEmpty((IEnumerable)clips)) : null).GetValueOrDefault()) { LogSource.LogError((object)"Definition is null, you're likely calling load before assigning a definition after creating an empty SoundData. Try to use AssignDefinitionToData before loading a file"); return; } } if (replayMusic) { ReplayMusic(entry, "", onPlay); } } else { if (!SFXEntries.TryGetValue(entry, out var value2)) { return; } value2.AudioData = audioClip; SoundCueDefinition definition2 = value2.definition; if (definition2 != null) { AudioClip[] clips2 = definition2.Clips; if (((clips2 != null) ? new bool?(IEnumerableUtility.IsNullOrEmpty((IEnumerable)clips2)) : null).GetValueOrDefault()) { LogSource.LogError((object)"Definition is null, you're likely calling load before assigning a definition after creating an empty SoundData. Try to use AssignDefinitionToData before loading a file"); } } } } catch (Exception ex) { LogSource.LogError((object)(ex.InnerException ?? ex).Message); LogSource.LogError((object)"You're likely loading too early before the Definition has been loaded, connect a method to Plugin.onInitialize instead"); } } internal static void ReplayMusic(ConfigEntryBase entry, string displayedName = "", Action onPlay = null) { AllGameManagers instance = AllGameManagers.Instance; if (!((Object)(object)instance == (Object)null) && !((Object)(object)instance.GetSoundManager() == (Object)null)) { SoundManager soundManager = instance.GetSoundManager(); if (soundManager.GetCurrentMusicTrackName() == entry.Definition.Key) { PlayMusic(entry, isBattleMusic: false, 0.25f, "", onPlay); } } } internal static void PlayMusic(ConfigEntryBase entry, bool isBattleMusic = false, float crossfadeTimeSeconds = 0.25f, string displayedName = "", Action onPlay = null) { <>c__DisplayClass75_0 CS$<>8__locals0 = new <>c__DisplayClass75_0(); CS$<>8__locals0.isBattleMusic = isBattleMusic; CS$<>8__locals0.crossfadeTimeSeconds = crossfadeTimeSeconds; CS$<>8__locals0.entry = entry; CS$<>8__locals0.displayedName = displayedName; CS$<>8__locals0.onPlay = onPlay; AllGameManagers instance = AllGameManagers.Instance; if (!((Object)(object)instance == (Object)null) && !((Object)(object)instance.GetSoundManager() == (Object)null)) { CS$<>8__locals0.soundManager = instance.GetSoundManager(); CS$<>8__locals0.soundManager.StopMusic(0.25f); ((MonoBehaviour)Instance).StartCoroutine(WaitUntilMusicStops()); } [IteratorStateMachine(typeof(<>c__DisplayClass75_0.<g__WaitUntilMusicStops|0>d))] IEnumerator WaitUntilMusicStops() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <>c__DisplayClass75_0.<g__WaitUntilMusicStops|0>d(0) { <>4__this = CS$<>8__locals0 }; } } internal static void PlaySFX(ConfigEntryBase entry, bool loop = false, Action onPlay = null) { //IL_006a: Unknown result type (might be due to invalid IL or missing references) AllGameManagers instance = AllGameManagers.Instance; if (!((Object)(object)instance == (Object)null) && !((Object)(object)instance.GetSoundManager() == (Object)null)) { SoundManager soundManager = instance.GetSoundManager(); SoundData soundData = SFXEntries[entry]; bool loop2 = soundData.definition.Loop; soundData.definition.Loop = loop; soundManager.PlaySfx(entry.Definition.Key, (AudioSfxPriority)0, false, 0f); soundData.definition.Loop = loop2; onPlay?.Invoke(entry.Definition.Key); } } [IteratorStateMachine(typeof(d__77))] internal static IEnumerator LoadAudioClip(string filePath, Action onComplete = null) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__77(0) { filePath = filePath, onComplete = onComplete }; } } public static class PluginInfo { public const string GUID = "Patty_SoundChanger_MOD"; public const string Name = "Sound Changer"; public const string Version = "2.1.0"; } public class SoundInfo : MonoBehaviour { internal ConfigEntryBase entry; internal TMP_Text titleTMP; internal TMP_Text replacementTMP; internal Dictionary buttons = new Dictionary(3); internal bool TryTrigger(CoreInputControlMapping mapping, IGameUIComponent triggeredUI, Controls triggeredMappingID) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) foreach (KeyValuePair button in buttons) { if (button.Key.TryTrigger(mapping, triggeredUI, triggeredMappingID, false, false)) { button.Value(); return true; } } return false; } internal void Set(SettingsScreen settingsScreen, ConfigEntryBase entry) { //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_015a: 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_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_01f5: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Unknown result type (might be due to invalid IL or missing references) //IL_0269: Unknown result type (might be due to invalid IL or missing references) //IL_02b4: Unknown result type (might be due to invalid IL or missing references) //IL_02d0: Unknown result type (might be due to invalid IL or missing references) Traverse val = Traverse.Create((object)settingsScreen); PauseDialog value = val.Field("pauseDialog").Value; GameUISelectableButton value2 = Traverse.Create((object)value).Field("settingsButton").Value; TMP_Text value3 = Traverse.Create((object)value).Field("musicLabel").Value; ContentSizeFitter val2 = ((Component)this).gameObject.AddComponent(); val2.verticalFit = (FitMode)2; val2.horizontalFit = (FitMode)2; TMP_Text val3 = Object.Instantiate(value3, ((Component)val2).transform); Object.DestroyImmediate((Object)(object)((Component)val3).GetComponent()); val3.rectTransform.anchorMin = Vector2.zero; val3.rectTransform.pivot = new Vector2(0f, 0.5f); val3.rectTransform.anchoredPosition = new Vector2(0f, 0f); val3.rectTransform.sizeDelta = new Vector2(300f, 33f); ((Object)val3).name = "Label"; val3.alignment = (TextAlignmentOptions)513; val3.overflowMode = (TextOverflowModes)1; val3.fontSizeMax = 30f; val3.fontSizeMin = 18f; val3.enableAutoSizing = true; TMP_Text val4 = Object.Instantiate(val3, ((Component)val2).transform); ((Object)val4).name = "Replacement Label"; val4.rectTransform.anchoredPosition = new Vector2(320f, 0f); GameUISelectableButton val5 = Object.Instantiate(value2, ((Component)val2).transform); ((Component)val5).GetComponent().anchorMax = new Vector2(1f, 0.5f); ((Component)val5).GetComponent().anchorMin = new Vector2(1f, 0.5f); ((Component)val5).GetComponent().anchoredPosition = new Vector2(-20f, 0f); ((Component)val5).GetComponent().pivot = new Vector2(1f, 0.5f); ((Component)val5).GetComponent().sizeDelta = new Vector2(100f, 64f); Object.DestroyImmediate((Object)(object)((Component)val5).GetComponentInChildren()); ((TMP_Text)((Component)val5).GetComponentInChildren()).text = "Reset"; ((Object)val5).name = "Reset Button"; GameUISelectableButton val6 = Object.Instantiate(val5, ((Component)val2).transform); ((Component)val6).GetComponent().sizeDelta = new Vector2(120f, 64f); ((Component)val6).GetComponent().anchoredPosition = new Vector2(-150f, 0f); ((TMP_Text)((Component)val6).GetComponentInChildren()).text = "Load File"; ((Object)val6).name = "Load File Button"; GameUISelectableButton val7 = Object.Instantiate(val6, ((Component)val2).transform); ((Component)val7).GetComponent().sizeDelta = new Vector2(50f, 64f); ((Component)val7).GetComponent().anchoredPosition = new Vector2(-300f, 0f); ((TMP_Text)((Component)val7).GetComponentInChildren()).text = " ▶ "; ((Object)val7).name = "Play Button"; this.entry = entry; ((ConfigEntry)(object)this.entry).SettingChanged += SoundInfo_SettingChanged; titleTMP = val3; replacementTMP = val4; buttons[val7] = PlayMusic; buttons[val6] = LoadFile; buttons[val5] = ResetMusic; UpdateText(); Plugin.musicChanged.AddListener((Action)OnMusicChanged); } private void OnDestroy() { ((ConfigEntry)(object)entry).SettingChanged -= SoundInfo_SettingChanged; Plugin.musicChanged.RemoveListener((Action)OnMusicChanged); } private void OnMusicChanged(string trackName) { UpdateText(); } private void SoundInfo_SettingChanged(object sender, EventArgs e) { UpdateText(); } internal void PlayMusic() { if (Plugin.MusicEntries.ContainsKey(entry)) { Plugin.PlayMusic(entry, isBattleMusic: false, 0.25f, "", delegate { UpdateText(); }); } else { Plugin.PlaySFX(entry); } } internal void LoadFile() { string text = entry.BoxedValue as string; bool existFile = File.Exists(text); Plugin.LoadFile(entry, text, existFile, null, delegate { UpdateText(); }); } internal string GetTitle() { if (Plugin.soundChangerManager.IsMusicEntry(entry)) { return Plugin.soundChangerManager.GetMusicData(entry.Definition.Key).GetTitle(); } if (Plugin.soundChangerManager.IsSFXEntry(entry)) { return Plugin.soundChangerManager.GetSFXData(entry.Definition.Key).GetTitle(); } return ""; } internal void ResetMusic() { Plugin.soundChangerManager.ResetEntry(entry); Plugin.ResetEntryBase(entry, delegate { UpdateText(); }); } public void UpdateText() { bool flag = Plugin.IsCurrentMusic(entry); string text = ""; string text2 = ""; if (flag) { text = ""; text2 = ""; } titleTMP.text = text + entry.Definition.Key + text2; replacementTMP.text = text + GetTitle() + text2; } } internal class TemporaryFix { [HarmonyPrefix] [HarmonyPatch(typeof(MusicNotificationHandler), "OnBattleMusicChanged")] public static void OnBattleMusicChanged(ref string trackName) { trackName = AllGameManagers.Instance.GetSoundManager().currentTrackName; } } internal class TranspilerFix { [HarmonyTranspiler] [HarmonyPatch(typeof(SoundManager), "PlayBattleMusic")] public static IEnumerable PlayBattleMusic(IEnumerable instructions) { //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Expected O, but got Unknown //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Expected O, but got Unknown //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Expected O, but got Unknown //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Expected O, but got Unknown List list = new List(instructions); int num = list.FindIndex((CodeInstruction codeInstruction) => codeInstruction.opcode == OpCodes.Ldsfld && codeInstruction.operand.ToString().Contains("BattleMusicChanged")); if (num <= 0) { return instructions; } int num2 = 1; for (int i = num; i < list.Count; i++) { CodeInstruction val = list[i]; if (val.opcode == OpCodes.Callvirt) { object operand = val.operand; if (operand != null && (operand.ToString()?.Contains("Dispatch")).GetValueOrDefault()) { break; } } num2++; } list.RemoveRange(num, num2); List list2 = new List(); list2.Add(new CodeInstruction(OpCodes.Ldsfld, (object)AccessTools.DeclaredField(typeof(SoundManager), "BattleMusicChanged"))); list2.Add(new CodeInstruction(OpCodes.Ldarg_0, (object)null)); list2.Add(new CodeInstruction(OpCodes.Call, (object)AccessTools.PropertyGetter(typeof(SoundManager), "currentTrackName"))); list2.Add(new CodeInstruction(OpCodes.Callvirt, (object)AccessTools.DeclaredMethod(typeof(Signal), "Dispatch", (Type[])null, (Type[])null))); List collection = list2; list.InsertRange(num, collection); return list; } }