Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of LCSoundTool v81 Fork v81.1.0
BepInEx/plugins/LCSoundTool_v81_Fork/LC_SoundTool.dll
Decompiled 43 minutes ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.CodeDom.Compiler; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Resources; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Threading; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using LCSoundTool.Networking; using LCSoundTool.Patches; using LCSoundTool.Resources; using LCSoundTool.Utilities; using LCSoundToolMod.Properties; using LC_SoundTool.NetcodePatcher; using Microsoft.CodeAnalysis; using Unity.Netcode; using UnityEngine; using UnityEngine.Networking; using UnityEngine.SceneManagement; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("LC_SoundTool")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("LCSoundTool by no00ob, rebuilt for Lethal Company v81.")] [assembly: AssemblyFileVersion("81.1.0.0")] [assembly: AssemblyInformationalVersion("81.1.0+09a2aebe8e3bdb429124b5244891dd811a8bca77")] [assembly: AssemblyProduct("LC Sound Tool v81 Fork")] [assembly: AssemblyTitle("LC_SoundTool")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/9-7-8/LC_ModForks")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("81.1.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] [module: NetcodePatchedAssembly] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace LCSoundToolMod { public static class PluginInfo { public const string PLUGIN_GUID = "LC_SoundTool"; public const string PLUGIN_NAME = "LC Sound Tool v81 Fork"; public const string PLUGIN_VERSION = "81.1.0"; } } namespace LCSoundToolMod.Properties { [GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [DebuggerNonUserCode] [CompilerGenerated] internal class Resources { private static ResourceManager resourceMan; private static CultureInfo resourceCulture; [EditorBrowsable(EditorBrowsableState.Advanced)] internal static ResourceManager ResourceManager { get { if (resourceMan == null) { resourceMan = new ResourceManager("LCSoundToolMod.Properties.Resources", typeof(Resources).Assembly); } return resourceMan; } } [EditorBrowsable(EditorBrowsableState.Advanced)] internal static CultureInfo Culture { get { return resourceCulture; } set { resourceCulture = value; } } internal static byte[] soundtool => (byte[])ResourceManager.GetObject("soundtool", resourceCulture); internal Resources() { } } } namespace LCSoundTool { public class AudioSourceExtension : MonoBehaviour { public AudioSource audioSource; public bool playOnAwake; public bool loop; private bool updateHasBeenLogged; private bool hasPlayed; private void OnEnable() { if (!((Object)(object)audioSource == (Object)null) && !audioSource.isPlaying) { if (playOnAwake) { audioSource.Play(); } if (SoundTool.infoDebugging) { SoundTool.Instance.logger.LogDebug((object)$"(AudioSourceExtension) Started playback of {audioSource} with clip {audioSource.clip} in OnEnable function!"); } updateHasBeenLogged = false; hasPlayed = false; } } private void OnDisable() { if (!((Object)(object)audioSource == (Object)null) && audioSource.isPlaying) { if (playOnAwake) { audioSource.Stop(); } if (SoundTool.infoDebugging) { SoundTool.Instance.logger.LogDebug((object)$"(AudioSourceExtension) Stopped playback of {audioSource} with clip {audioSource.clip} in OnDisable function!"); } updateHasBeenLogged = false; hasPlayed = false; } } private void Update() { if ((Object)(object)audioSource == (Object)null) { return; } if ((Object)(object)audioSource.clip == (Object)null) { hasPlayed = false; } if (audioSource.isPlaying) { updateHasBeenLogged = false; } else if (!((Behaviour)audioSource).isActiveAndEnabled) { hasPlayed = false; } else { if (!playOnAwake) { return; } if ((Object)(object)audioSource.clip != (Object)null && !hasPlayed) { audioSource.Play(); if (SoundTool.infoDebugging) { SoundTool.Instance.logger.LogDebug((object)$"(AudioSourceExtension) Started playback of {audioSource} with clip {audioSource.clip} in Update function!"); } updateHasBeenLogged = false; hasPlayed = true; } else if ((Object)(object)audioSource.clip == (Object)null && !updateHasBeenLogged) { updateHasBeenLogged = true; if (SoundTool.infoDebugging) { SoundTool.Instance.logger.LogDebug((object)$"(AudioSourceExtension) Can not start playback of {audioSource} with missing clip in Update function!"); } } } } } public class RandomAudioClip { public AudioClip clip; [Range(0f, 1f)] public float chance = 1f; public RandomAudioClip(AudioClip clip, float chance) { this.clip = clip; this.chance = chance; } } public class ReplacementAudioClip { public List<RandomAudioClip> clips; public string source = string.Empty; public bool canPlay = true; private bool initialized; public ReplacementAudioClip(AudioClip clip, float chance, string source) { if (!initialized) { Initialize(); } RandomAudioClip randomAudioClip = new RandomAudioClip(clip, chance); if (!clips.ContainsThisRandomAudioClip(randomAudioClip)) { clips.Add(randomAudioClip); this.source = source; } else if (SoundTool.infoDebugging) { SoundTool.Instance.logger.LogDebug((object)$"RandomAudioClip {randomAudioClip.clip.GetName()} ({Mathf.RoundToInt(chance * 100f)}%) already exists withing this AudioClipContainer!"); SoundTool.Instance.logger.LogDebug((object)"- This AudioClipContainer contains the following clip(s):"); for (int i = 0; i < clips.Count; i++) { SoundTool.Instance.logger.LogDebug((object)$"-- Clip {i + 1} - {clips[i].clip.GetName()} with a chance of {Mathf.RoundToInt(clips[i].chance * 100f)}%"); } } } public ReplacementAudioClip(string source) { Initialize(); this.source = source; } public ReplacementAudioClip() { Initialize(); source = string.Empty; } public void AddClip(AudioClip clip, float chance) { if (!initialized) { Initialize(); } RandomAudioClip randomAudioClip = new RandomAudioClip(clip, chance); if (!clips.ContainsThisRandomAudioClip(randomAudioClip)) { clips.Add(randomAudioClip); } else if (SoundTool.infoDebugging) { SoundTool.Instance.logger.LogDebug((object)$"RandomAudioClip {randomAudioClip.clip.GetName()} ({Mathf.RoundToInt(chance * 100f)}%) already exists withing this AudioClipContainer!"); SoundTool.Instance.logger.LogDebug((object)"- This AudioClipContainer contains the following clip(s):"); for (int i = 0; i < clips.Count; i++) { SoundTool.Instance.logger.LogDebug((object)$"-- Clip {i + 1} - {clips[i].clip.GetName()} with a chance of {Mathf.RoundToInt(clips[i].chance * 100f)}%"); } } } public bool Full() { if (!initialized) { Initialize(); } float num = 0f; for (int i = 0; i < clips.Count; i++) { num += clips[i].chance; } return num >= 1f; } public bool ContainsClip(AudioClip clip, float chance) { if (!initialized) { Initialize(); } RandomAudioClip thisClip = new RandomAudioClip(clip, chance); return clips.ContainsThisRandomAudioClip(thisClip); } public float TotalChance() { if (!initialized) { Initialize(); } float num = 0f; for (int i = 0; i < clips.Count; i++) { num += clips[i].chance; } return num; } private void Initialize() { clips = new List<RandomAudioClip>(); initialized = true; } } [BepInPlugin("LCSoundTool", "LC Sound Tool v81 Fork", "81.1.0")] public class SoundTool : BaseUnityPlugin { public enum AudioType { wav, ogg, mp3 } private const string PLUGIN_GUID = "LCSoundTool"; private const string PLUGIN_NAME = "LC Sound Tool v81 Fork"; private ConfigEntry<bool> configUseNetworking; private ConfigEntry<bool> configSyncRandomSeed; private ConfigEntry<float> configPlayOnAwakePatchRepeatDelay; private ConfigEntry<bool> configPrintInfoByDefault; private readonly Harmony harmony = new Harmony("LCSoundTool"); public static SoundTool Instance; internal ManualLogSource logger; public static bool debugAudioSources; public static bool indepthDebugging; public static bool infoDebugging; public static bool networkingInitialized { get; private set; } public static bool networkingAvailable { get; private set; } public static Dictionary<string, ReplacementAudioClip> replacedClips { get; private set; } public static Dictionary<string, AudioClip> networkedClips => NetworkHandler.networkedAudioClips; public static event Action ClientNetworkedAudioChanged { add { NetworkHandler.ClientNetworkedAudioChanged += value; } remove { NetworkHandler.ClientNetworkedAudioChanged -= value; } } public static event Action HostNetworkedAudioChanged { add { NetworkHandler.HostNetworkedAudioChanged += value; } remove { NetworkHandler.HostNetworkedAudioChanged -= value; } } public static bool IsDebuggingOn() { if (debugAudioSources || indepthDebugging || infoDebugging) { return true; } return false; } private void Awake() { //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_020d: Unknown result type (might be due to invalid IL or missing references) networkingAvailable = true; if ((Object)(object)Instance == (Object)null) { Instance = this; } configUseNetworking = ((BaseUnityPlugin)this).Config.Bind<bool>("Experimental", "EnableNetworking", false, "Whether or not to use the networking built into this plugin. If set to true everyone in the lobby needs LCSoundTool installed and networking enabled to join."); configSyncRandomSeed = ((BaseUnityPlugin)this).Config.Bind<bool>("Experimental", "SyncUnityRandomSeed", false, "Whether or not to sync the default Unity randomization seed with all clients. For this feature, networking has to be set to true. Will send the UnityEngine.Random.seed from the host to all clients automatically upon loading a networked scene."); configPlayOnAwakePatchRepeatDelay = ((BaseUnityPlugin)this).Config.Bind<float>("Experimental", "NewPlayOnAwakePatchRepeatDelay", 90f, "How long to wait between checks for new playOnAwake AudioSources. Runs the same patching that is done when each scene is loaded with this delay between each run. DO NOT set too low or high. Anything below 10 or above 600 can cause issues. This time is in seconds. Set to 0 to disable rerunning the patch, but be warned that this might break runtime initialized playOnAwake AudioSources."); configPrintInfoByDefault = ((BaseUnityPlugin)this).Config.Bind<bool>("Logging", "PrintInfoByDefault", false, "Whether or not to print additional information logs created by this mod by default. If set to false, informational logs may be toggled on any time with LeftAlt + F5."); Type[] types = Assembly.GetExecutingAssembly().GetTypes(); for (int i = 0; i < types.Length; i++) { MethodInfo[] methods = types[i].GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic); foreach (MethodInfo methodInfo in methods) { if (methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false).Length != 0) { methodInfo.Invoke(null, null); } } } logger = Logger.CreateLogSource("LCSoundTool"); logger.LogInfo((object)"Plugin LCSoundTool is loaded!"); InputHelper.Initialize(); InputHelper.keybinds.Add("toggleAudioSourceDebugLog", new Keybind(new KeyboardShortcut((KeyCode)286, (KeyCode[])(object)new KeyCode[0]), ToggleDebug)); InputHelper.keybinds.Add("toggleIndepthDebugLog", new Keybind(new KeyboardShortcut((KeyCode)286, (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 }), ToggleIndepthDebug)); InputHelper.keybinds.Add("toggleInformationalDebugLog", new Keybind(new KeyboardShortcut((KeyCode)286, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), ToggleInfoDebug)); InputHelper.keybinds.Add("printAllSoundsDebugLog", new Keybind(new KeyboardShortcut((KeyCode)286, (KeyCode[])(object)new KeyCode[1] { (KeyCode)304 }), PrintAllReplacedSounds)); InputHelper.keybinds.Add("printAllCurrentSoundsDebugLog", new Keybind(new KeyboardShortcut((KeyCode)287, (KeyCode[])(object)new KeyCode[0]), PrintAllCurrentSounds)); debugAudioSources = false; indepthDebugging = false; if (configPrintInfoByDefault.Value) { infoDebugging = true; } else { infoDebugging = false; } replacedClips = new Dictionary<string, ReplacementAudioClip>(); } private void Start() { if (!configUseNetworking.Value) { networkingAvailable = false; Instance.logger.LogWarning((object)"Networking disabled. Mod in fully client side mode, but no networked actions can take place! You can safely ignore this if you want the mod to run fully client side."); } else { networkingAvailable = true; } if (configUseNetworking.Value) { logger.LogDebug((object)"Loading SoundTool AssetBundle..."); Assets.bundle = AssetBundle.LoadFromMemory(LCSoundToolMod.Properties.Resources.soundtool); if ((Object)(object)Assets.bundle == (Object)null) { logger.LogError((object)"Failed to load SoundTool AssetBundle!"); } else { logger.LogDebug((object)"Finished loading SoundTool AssetBundle!"); } } harmony.PatchAll(typeof(AudioSourcePatch)); if (configUseNetworking.Value) { harmony.PatchAll(typeof(GameNetworkManagerPatch)); harmony.PatchAll(typeof(StartOfRoundPatch)); } SceneManager.sceneLoaded += OnSceneLoaded; } private void Update() { if (configUseNetworking.Value) { if (!networkingInitialized) { if ((Object)(object)NetworkHandler.Instance != (Object)null) { networkingInitialized = true; } } else if ((Object)(object)NetworkHandler.Instance == (Object)null) { networkingInitialized = false; } } else { networkingInitialized = false; } if (!InputHelper.CheckInput("printAllCurrentSoundsDebugLog") && !InputHelper.CheckInput("printAllSoundsDebugLog") && !InputHelper.CheckInput("toggleInformationalDebugLog") && !InputHelper.CheckInput("toggleIndepthDebugLog")) { InputHelper.CheckInput("toggleAudioSourceDebugLog"); } } private void OnDestroy() { SceneManager.sceneLoaded -= OnSceneLoaded; } private void OnSceneLoaded(Scene scene, LoadSceneMode mode) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)Instance == (Object)null)) { PatchPlayOnAwakeAudio(scene); OnSceneLoadedNetworking(); if (((Scene)(ref scene)).name.ToLowerInvariant().Contains("level")) { ((MonoBehaviour)this).StopAllCoroutines(); ((MonoBehaviour)this).StartCoroutine(PatchPlayOnAwakeDelayed(scene, 1f)); } } } private IEnumerator PatchPlayOnAwakeDelayed(Scene scene, float wait) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) if (infoDebugging) { logger.LogDebug((object)$"Started playOnAwake patch coroutine with delay of {wait} seconds"); } yield return (object)new WaitForSecondsRealtime(wait); if (infoDebugging) { logger.LogDebug((object)"Running playOnAwake patch coroutine!"); } PatchPlayOnAwakeAudio(scene); float num = configPlayOnAwakePatchRepeatDelay.Value; if (num != 0f) { if (num < 10f) { num = 10f; } if (num > 600f) { num = 600f; } ((MonoBehaviour)this).StartCoroutine(PatchPlayOnAwakeDelayed(scene, num)); } } private void PatchPlayOnAwakeAudio(Scene scene) { if (infoDebugging) { Instance.logger.LogDebug((object)("Grabbing all playOnAwake AudioSources for loaded scene " + ((Scene)(ref scene)).name)); } AudioSource[] allPlayOnAwakeAudioSources = GetAllPlayOnAwakeAudioSources(); if (infoDebugging) { Instance.logger.LogDebug((object)$"Found a total of {allPlayOnAwakeAudioSources.Length} playOnAwake AudioSource(s)!"); Instance.logger.LogDebug((object)$"Starting setup on {allPlayOnAwakeAudioSources.Length} playOnAwake AudioSource(s)..."); } AudioSource[] array = allPlayOnAwakeAudioSources; AudioSourceExtension audioSourceExtension = default(AudioSourceExtension); foreach (AudioSource val in array) { val.Stop(); if (((Component)((Component)val).transform).TryGetComponent<AudioSourceExtension>(ref audioSourceExtension)) { audioSourceExtension.audioSource = val; audioSourceExtension.playOnAwake = true; audioSourceExtension.loop = val.loop; val.playOnAwake = false; if (infoDebugging) { Instance.logger.LogDebug((object)$"-Set- {Array.IndexOf(allPlayOnAwakeAudioSources, val) + 1} {val} done!"); } continue; } AudioSourceExtension audioSourceExtension2 = ((Component)val).gameObject.AddComponent<AudioSourceExtension>(); audioSourceExtension2.audioSource = val; audioSourceExtension2.playOnAwake = true; audioSourceExtension2.loop = val.loop; val.playOnAwake = false; if (infoDebugging) { Instance.logger.LogDebug((object)$"-Add- {Array.IndexOf(allPlayOnAwakeAudioSources, val) + 1} {val} done!"); } } if (infoDebugging) { Instance.logger.LogDebug((object)$"Done setting up {allPlayOnAwakeAudioSources.Length} playOnAwake AudioSources!"); } } private void OnSceneLoadedNetworking() { if (networkingAvailable && networkingInitialized && configSyncRandomSeed.Value) { int num = (int)DateTime.Now.Ticks; Random.InitState(num); SendUnityRandomSeed(num); } } public AudioSource[] GetAllPlayOnAwakeAudioSources() { AudioSource[] array = Object.FindObjectsOfType<AudioSource>(true); List<AudioSource> list = new List<AudioSource>(); for (int i = 0; i < array.Length; i++) { if (array[i].playOnAwake) { list.Add(array[i]); } } return list.ToArray(); } public static void ReplaceAudioClip(string originalName, AudioClip newClip) { if (string.IsNullOrEmpty(originalName)) { Instance.logger.LogWarning((object)"Trying to replace an audio clip without original clip specified! This is not allowed"); } else if ((Object)(object)newClip == (Object)null) { Instance.logger.LogWarning((object)"Trying to replace an audio clip without new clip specified! This is not allowed"); } else { ReplaceAudioClipInternal(originalName, newClip, 1f, string.Empty); } } public static void ReplaceAudioClip(AudioClip originalClip, AudioClip newClip) { if ((Object)(object)originalClip == (Object)null || string.IsNullOrEmpty(originalClip.GetName())) { Instance.logger.LogWarning((object)"Trying to replace an audio clip without original clip specified or original clip's name is empty! This is not allowed."); } else if ((Object)(object)newClip == (Object)null) { Instance.logger.LogWarning((object)"Trying to replace an audio clip without new clip specified! This is not allowed."); } else { ReplaceAudioClipInternal(originalClip.GetName(), newClip, 1f, string.Empty); } } public static void ReplaceAudioClip(string originalName, AudioClip newClip, float chance) { if (string.IsNullOrEmpty(originalName)) { Instance.logger.LogWarning((object)"Trying to replace an audio clip without original clip specified! This is not allowed"); } else if ((Object)(object)newClip == (Object)null) { Instance.logger.LogWarning((object)"Trying to replace an audio clip without new clip specified! This is not allowed"); } else if (chance < 0f || chance > 1f) { Instance.logger.LogWarning((object)$"Trying to replace an audio clip with an invalid chance of {chance}! Chance has to be between 0 - 1.0"); } else { ReplaceAudioClipInternal(originalName, newClip, chance, string.Empty); } } public static void ReplaceAudioClip(AudioClip originalClip, AudioClip newClip, float chance) { if ((Object)(object)originalClip == (Object)null || string.IsNullOrEmpty(originalClip.GetName())) { Instance.logger.LogWarning((object)"Trying to replace an audio clip without original clip specified or original clip's name is empty! This is not allowed."); } else if ((Object)(object)newClip == (Object)null) { Instance.logger.LogWarning((object)"Trying to replace an audio clip without new clip specified! This is not allowed."); } else if (chance < 0f || chance > 1f) { Instance.logger.LogWarning((object)$"Trying to replace an audio clip with an invalid chance of {chance}! Chance has to be between 0 - 1.0"); } else { ReplaceAudioClipInternal(originalClip.GetName(), newClip, chance, string.Empty); } } public static void ReplaceAudioClip(string originalName, AudioClip newClip, string source) { if (string.IsNullOrEmpty(originalName)) { Instance.logger.LogWarning((object)"Trying to replace an audio clip without original clip specified! This is not allowed"); } else if ((Object)(object)newClip == (Object)null) { Instance.logger.LogWarning((object)"Plugin LCSoundTool is trying to replace an audio clip without new clip specified! This is not allowed."); } else { ReplaceAudioClipInternal(originalName, newClip, 1f, source); } } public static void ReplaceAudioClip(AudioClip originalClip, AudioClip newClip, string source) { if ((Object)(object)originalClip == (Object)null || string.IsNullOrEmpty(originalClip.GetName())) { Instance.logger.LogWarning((object)"Trying to replace an audio clip without original clip specified or original clip's name is empty! This is not allowed."); } else if ((Object)(object)newClip == (Object)null) { Instance.logger.LogWarning((object)"Plugin LCSoundTool is trying to replace an audio clip without new clip specified! This is not allowed."); } else { ReplaceAudioClipInternal(originalClip.GetName(), newClip, 1f, source); } } public static void ReplaceAudioClip(string originalName, AudioClip newClip, string[] source) { if (string.IsNullOrEmpty(originalName)) { Instance.logger.LogWarning((object)"Trying to replace an audio clip without original clip specified! This is not allowed"); return; } if ((Object)(object)newClip == (Object)null) { Instance.logger.LogWarning((object)"Trying to replace an audio clip without new clip specified! This is not allowed."); return; } List<string> list = source.ToList(); for (int i = 0; i < list.Count; i++) { if (string.IsNullOrEmpty(list[i])) { list.RemoveAt(i); i--; } } ReplaceAudioClipInternal(originalName, newClip, 1f, string.Join(",", list)); } public static void ReplaceAudioClip(AudioClip originalClip, AudioClip newClip, string[] source) { if ((Object)(object)originalClip == (Object)null || string.IsNullOrEmpty(originalClip.GetName())) { Instance.logger.LogWarning((object)"Trying to replace an audio clip without original clip specified or original clip's name is empty! This is not allowed."); return; } if ((Object)(object)newClip == (Object)null) { Instance.logger.LogWarning((object)"Trying to replace an audio clip without new clip specified! This is not allowed."); return; } List<string> list = source.ToList(); for (int i = 0; i < list.Count; i++) { if (string.IsNullOrEmpty(list[i])) { list.RemoveAt(i); i--; } } ReplaceAudioClipInternal(originalClip.GetName(), newClip, 1f, string.Join(",", list)); } public static void ReplaceAudioClip(string originalName, AudioClip newClip, float chance, string source) { if (string.IsNullOrEmpty(originalName)) { Instance.logger.LogWarning((object)"Trying to replace an audio clip without original clip specified! This is not allowed"); } else if ((Object)(object)newClip == (Object)null) { Instance.logger.LogWarning((object)"Trying to replace an audio clip without new clip specified! This is not allowed"); } else if (chance < 0f || chance > 1f) { Instance.logger.LogWarning((object)$"Trying to replace an audio clip with an invalid chance of {chance}! Chance has to be between 0 - 1.0"); } else { ReplaceAudioClipInternal(originalName, newClip, chance, source); } } public static void ReplaceAudioClip(AudioClip originalClip, AudioClip newClip, float chance, string source) { if ((Object)(object)originalClip == (Object)null || string.IsNullOrEmpty(originalClip.GetName())) { Instance.logger.LogWarning((object)"Trying to replace an audio clip without original clip specified or the specified original clip has no name! This is not allowed"); } else if ((Object)(object)newClip == (Object)null) { Instance.logger.LogWarning((object)"Trying to replace an audio clip without new clip specified! This is not allowed"); } else if (chance < 0f || chance > 1f) { Instance.logger.LogWarning((object)$"Trying to replace an audio clip with an invalid chance of {chance}! Chance has to be between 0 - 1.0"); } else { ReplaceAudioClipInternal(originalClip.GetName(), newClip, chance, source); } } public static void ReplaceAudioClip(string originalName, AudioClip newClip, float chance, string[] source) { if (string.IsNullOrEmpty(originalName)) { Instance.logger.LogWarning((object)"Trying to replace an audio clip without original clip specified! This is not allowed"); return; } if ((Object)(object)newClip == (Object)null) { Instance.logger.LogWarning((object)"Trying to replace an audio clip without new clip specified! This is not allowed."); return; } if (chance < 0f || chance > 1f) { Instance.logger.LogWarning((object)$"Trying to replace an audio clip with an invalid chance of {chance}! Chance has to be between 0 - 1.0"); return; } List<string> list = source.ToList(); for (int i = 0; i < list.Count; i++) { if (string.IsNullOrEmpty(list[i])) { list.RemoveAt(i); i--; } } ReplaceAudioClipInternal(originalName, newClip, chance, string.Join(",", list)); } public static void ReplaceAudioClip(AudioClip originalClip, AudioClip newClip, float chance, string[] source) { if ((Object)(object)originalClip == (Object)null || string.IsNullOrEmpty(originalClip.GetName())) { Instance.logger.LogWarning((object)"Trying to replace an audio clip without original clip specified or original clip's name is empty! This is not allowed."); return; } if ((Object)(object)newClip == (Object)null) { Instance.logger.LogWarning((object)"Trying to replace an audio clip without new clip specified! This is not allowed."); return; } if (chance < 0f || chance > 1f) { Instance.logger.LogWarning((object)$"Trying to replace an audio clip with an invalid chance of {chance}! Chance has to be between 0 - 1.0"); return; } List<string> list = source.ToList(); for (int i = 0; i < list.Count; i++) { if (string.IsNullOrEmpty(list[i])) { list.RemoveAt(i); i--; } } ReplaceAudioClipInternal(originalClip.GetName(), newClip, chance, string.Join(",", list)); } private static void ReplaceAudioClipInternal(string originalName, AudioClip newClip, float chance, string source) { string text = originalName; newClip.GetName(); if (!string.IsNullOrEmpty(source)) { text = originalName + "#" + source; } if (replacedClips.TryGetValue(text, out var value)) { value.AddClip(newClip, chance); } else { replacedClips.Add(text, new ReplacementAudioClip(newClip, chance, source)); } float num = 0f; for (int i = 0; i < replacedClips[text].clips.Count(); i++) { num += replacedClips[text].clips[i].chance; } int num2 = Mathf.RoundToInt(num * 100f); if (infoDebugging && num2 != 100) { Instance.logger.LogDebug((object)$"The combined chance of the {replacedClips[text].clips.Count} random clips for {text} is {num2}% (not 100%, at least yet)."); } } public static void RemoveRandomAudioClip(string name, float chance) { if (string.IsNullOrEmpty(name)) { Instance.logger.LogWarning((object)"Trying to restore an audio clip without original clip specified! This is not allowed"); } else if (!replacedClips.ContainsKey(name)) { Instance.logger.LogWarning((object)"Trying to restore an audio clip that does not exist! This is not allowed"); } else if (chance < 0f || chance > 1f) { Instance.logger.LogWarning((object)$"Trying to restore an audio clip with an invalid chance of {chance}! Chance has to be between 0 - 1.0"); } else { RemoveRandomAudioClipInternal(name, chance, string.Empty); } } public static void RemoveRandomAudioClip(string name, float chance, string source) { if (string.IsNullOrEmpty(name)) { Instance.logger.LogWarning((object)"Trying to restore an audio clip without original clip specified! This is not allowed"); } else if (!replacedClips.ContainsKey(name)) { Instance.logger.LogWarning((object)"Trying to restore an audio clip that does not exist! This is not allowed"); } else { RemoveRandomAudioClipInternal(name, chance, source); } } public static void RemoveRandomAudioClip(string name, float chance, string[] source) { if (string.IsNullOrEmpty(name)) { Instance.logger.LogWarning((object)"Trying to replace an audio clip without original clip specified! This is not allowed"); return; } if (chance < 0f || chance > 1f) { Instance.logger.LogWarning((object)$"Trying to replace an audio clip with an invalid chance of {chance}! Chance has to be between 0 - 1.0"); return; } List<string> list = source.ToList(); for (int i = 0; i < list.Count; i++) { if (string.IsNullOrEmpty(list[i])) { list.RemoveAt(i); i--; } } RemoveRandomAudioClipInternal(name, chance, string.Join(",", list)); } private static void RemoveRandomAudioClipInternal(string name, float chance, string source) { if (!string.IsNullOrEmpty(source)) { name = name + "#" + source; } if (!(chance > 0f)) { return; } for (int i = 0; i < replacedClips[name].clips.Count(); i++) { if (replacedClips[name].clips[i].chance == chance) { replacedClips[name].clips.RemoveAt(i); if (replacedClips[name].clips.Count <= 0) { Instance.logger.LogDebug((object)("Removed replaced AudioClip " + name + " completely as all of it's random clips have been removed.")); replacedClips.Remove(name); } break; } } } public static void RestoreAudioClip(string name) { if (string.IsNullOrEmpty(name)) { Instance.logger.LogWarning((object)"Trying to restore an audio clip without original clip specified! This is not allowed"); } else if (!replacedClips.ContainsKey(name)) { Instance.logger.LogWarning((object)"Trying to restore an audio clip that does not exist! This is not allowed"); } else { RestoreAudioClipInternal(name, string.Empty); } } public static void RestoreAudioClip(string name, string source) { if (string.IsNullOrEmpty(name)) { Instance.logger.LogWarning((object)"Trying to restore an audio clip without original clip specified! This is not allowed"); } else if (!replacedClips.ContainsKey(name)) { Instance.logger.LogWarning((object)"Trying to restore an audio clip that does not exist! This is not allowed"); } else { RestoreAudioClipInternal(name, source); } } public static void RestoreAudioClip(string name, string[] source) { if (string.IsNullOrEmpty(name)) { Instance.logger.LogWarning((object)"Trying to restore an audio clip without original clip specified! This is not allowed"); return; } if (!replacedClips.ContainsKey(name)) { Instance.logger.LogWarning((object)"Trying to restore an audio clip that does not exist! This is not allowed"); return; } List<string> list = source.ToList(); for (int i = 0; i < list.Count; i++) { if (string.IsNullOrEmpty(list[i])) { list.RemoveAt(i); i--; } } RestoreAudioClipInternal(name, string.Join(",", list)); } public static void RestoreAudioClip(AudioClip clip) { if ((Object)(object)clip == (Object)null || string.IsNullOrEmpty(clip.GetName())) { Instance.logger.LogWarning((object)"Trying to restore an audio clip without vanilla clip specified or specified clip's name is empty! This is not allowed"); } else { RestoreAudioClipInternal(clip.GetName(), string.Empty); } } public static void RestoreAudioClip(AudioClip clip, string source) { if ((Object)(object)clip == (Object)null || string.IsNullOrEmpty(clip.GetName())) { Instance.logger.LogWarning((object)"Trying to restore an audio clip without vanilla clip specified or specified clip's name is empty! This is not allowed"); } else { RestoreAudioClipInternal(clip.GetName(), source); } } public static void RestoreAudioClip(AudioClip clip, string[] source) { if ((Object)(object)clip == (Object)null || string.IsNullOrEmpty(clip.GetName())) { Instance.logger.LogWarning((object)"Trying to restore an audio clip without vanilla clip specified or specified clip's name is empty! This is not allowed"); return; } List<string> list = source.ToList(); for (int i = 0; i < list.Count; i++) { if (string.IsNullOrEmpty(list[i])) { list.RemoveAt(i); i--; } } RestoreAudioClipInternal(clip.GetName(), string.Join(",", list)); } private static void RestoreAudioClipInternal(string name, string source) { if (!string.IsNullOrEmpty(source)) { name = name + "#" + source; } replacedClips.Remove(name); } public static AudioClip GetAudioClip(string modFolder, string soundName) { return GetAudioClip(modFolder, string.Empty, soundName); } public static AudioClip GetAudioClip(string modFolder, string subFolder, string soundName) { AudioType audioType = AudioType.wav; string[] array = soundName.Split('.'); if (array[^1].ToLowerInvariant().Contains("wav")) { audioType = AudioType.wav; if (infoDebugging) { Instance.logger.LogDebug((object)"File detected as a PCM WAVE file!"); } } else if (array[^1].ToLowerInvariant().Contains("ogg")) { audioType = AudioType.ogg; if (infoDebugging) { Instance.logger.LogDebug((object)"File detected as an Ogg Vorbis file!"); } } else if (array[^1].ToLowerInvariant().Contains("mp3")) { audioType = AudioType.mp3; if (infoDebugging) { Instance.logger.LogDebug((object)"File detected as a MPEG MP3 file!"); } } else { audioType = AudioType.wav; Instance.logger.LogWarning((object)("Failed to detect file type of a sound file! This may cause issues with other mod functionality. Sound defaulted to WAV. Sound: " + soundName)); } return GetAudioClip(modFolder, subFolder, soundName, audioType); } public static AudioClip GetAudioClip(string modFolder, string soundName, AudioType audioType) { return GetAudioClip(modFolder, string.Empty, soundName, audioType); } public static AudioClip GetAudioClip(string modFolder, string subFolder, string soundName, AudioType audioType) { bool flag = true; bool flag2 = false; string text = " "; string text2 = Path.Combine(Paths.PluginPath, modFolder, subFolder, soundName); string text3 = Path.Combine(Paths.PluginPath, modFolder, soundName); string path = Path.Combine(Paths.PluginPath, modFolder, subFolder); string text4 = Path.Combine(Paths.PluginPath, subFolder, soundName); string path2 = Path.Combine(Paths.PluginPath, subFolder); if (!Directory.Exists(path)) { if (!string.IsNullOrEmpty(subFolder)) { Instance.logger.LogWarning((object)("Requested directory at BepInEx/Plugins/" + modFolder + "/" + subFolder + " does not exist!")); } else { Instance.logger.LogWarning((object)("Requested directory at BepInEx/Plugins/" + modFolder + " does not exist!")); if (!modFolder.Contains("-")) { Instance.logger.LogWarning((object)"This sound mod might not be compatable with mod managers. You should contact the sound mod's author."); } } flag = false; } else { if (infoDebugging) { Instance.logger.LogDebug((object)"Skipping legacy path check..."); } flag2 = true; } if (!File.Exists(text2)) { Instance.logger.LogWarning((object)("Requested audio file does not exist at path " + text2 + "!")); flag = false; Instance.logger.LogDebug((object)("Looking for audio file from mod root instead at " + text3 + "...")); if (File.Exists(text3)) { Instance.logger.LogDebug((object)("Found audio file at path " + text3 + "!")); text2 = text3; flag = true; if (infoDebugging) { Instance.logger.LogDebug((object)"Skipping legacy path check..."); } flag2 = true; } else { Instance.logger.LogWarning((object)("Requested audio file does not exist at mod root path " + text3 + "!")); } } else { if (infoDebugging) { Instance.logger.LogDebug((object)"Skipping legacy path check..."); } flag2 = true; } if (Directory.Exists(path2) && !flag2) { if (!string.IsNullOrEmpty(subFolder)) { Instance.logger.LogWarning((object)("Legacy directory location at BepInEx/Plugins/" + subFolder + " found!")); } else if (!modFolder.Contains("-")) { Instance.logger.LogWarning((object)"Legacy directory location at BepInEx/Plugins found!"); } } if (File.Exists(text4) && !flag2) { Instance.logger.LogWarning((object)("Legacy path contains the requested audio file at path " + text4 + "!")); text = " legacy "; text2 = text4; flag = true; } switch (audioType) { case AudioType.wav: if (infoDebugging) { Instance.logger.LogDebug((object)"File defined as a WAV file!"); } break; case AudioType.ogg: if (infoDebugging) { Instance.logger.LogDebug((object)"File defined as an Ogg Vorbis file!"); } break; case AudioType.mp3: if (infoDebugging) { Instance.logger.LogDebug((object)"File defined as a MPEG MP3 file!"); } break; default: if (infoDebugging) { Instance.logger.LogDebug((object)"File type not defined and was defaulted to WAV file!"); } break; } AudioClip val = null; if (flag) { Instance.logger.LogDebug((object)("Loading AudioClip " + soundName + " from" + text + "path: " + text2)); switch (audioType) { case AudioType.wav: val = AudioUtility.LoadFromDiskToAudioClip(text2, (AudioType)20); break; case AudioType.ogg: val = AudioUtility.LoadFromDiskToAudioClip(text2, (AudioType)14); break; case AudioType.mp3: val = AudioUtility.LoadFromDiskToAudioClip(text2, (AudioType)13); break; } if ((Object)(object)val != (Object)null) { Instance.logger.LogDebug((object)$"Finished loading AudioClip {soundName} with length of {val.length}!"); } else { Instance.logger.LogWarning((object)("Failed to load AudioClip " + soundName + " from" + text + "path: " + text2)); } } else { Instance.logger.LogWarning((object)("Failed to load AudioClip " + soundName + " from invalid" + text + "path at " + text2 + "!")); } if ((Object)(object)val == (Object)null) { return null; } if (string.IsNullOrEmpty(val.GetName())) { string text5 = soundName.Replace(audioType switch { AudioType.mp3 => ".mp3", AudioType.ogg => ".ogg", _ => ".wav", }, ""); string[] array = text5.Split('/'); if (array.Length <= 1) { array = text5.Split('\\'); } text5 = array[^1]; if (infoDebugging) { Instance.logger.LogDebug((object)("soundName " + soundName + " named " + text5)); } ((Object)val).name = text5; } return val; } public static void SendNetworkedAudioClip(AudioClip audioClip) { if ((Object)(object)Instance == (Object)null) { Debug.LogWarning((object)"LCSoundTool is not loaded yet; networked call ignored."); } else if (!Instance.configUseNetworking.Value) { Instance.logger.LogWarning((object)$"Networking disabled! Failed to send {audioClip}!"); } else if ((Object)(object)audioClip == (Object)null) { Instance.logger.LogWarning((object)$"audioClip variable of SendAudioClip not assigned! Failed to send {audioClip}!"); } else if ((Object)(object)Instance == (Object)null || (Object)(object)GameNetworkManagerPatch.networkHandlerHost == (Object)null || (Object)(object)NetworkHandler.Instance == (Object)null) { Instance.logger.LogWarning((object)$"Instance of SoundTool not found or networking has not finished initializing. Failed to send {audioClip}! If you're sending things in Awake or in a scene such as the main menu it might be too early, please try some of the other built-in Unity methods and make sure your networked audio runs only after the player setups a networked connection!"); } else { NetworkHandler.Instance.SendAudioClipServerRpc(audioClip.GetName(), AudioUtility.AudioClipToByteArray(audioClip, out var _), audioClip.channels, audioClip.frequency); } } public static void RemoveNetworkedAudioClip(AudioClip audioClip) { RemoveNetworkedAudioClip(audioClip.GetName()); } public static void RemoveNetworkedAudioClip(string audioClip) { if ((Object)(object)Instance == (Object)null) { Debug.LogWarning((object)"LCSoundTool is not loaded yet; networked call ignored."); } else if (!Instance.configUseNetworking.Value) { Instance.logger.LogWarning((object)("Networking disabled! Failed to remove " + audioClip + "!")); } else if (string.IsNullOrEmpty(audioClip)) { Instance.logger.LogWarning((object)("audioClip variable of RemoveAudioClip not assigned! Failed to remove " + audioClip + "!")); } else if ((Object)(object)Instance == (Object)null || (Object)(object)GameNetworkManagerPatch.networkHandlerHost == (Object)null || (Object)(object)NetworkHandler.Instance == (Object)null) { Instance.logger.LogWarning((object)("Instance of SoundTool not found or networking has not finished initializing. Failed to remove " + audioClip + "! If you're removing things in Awake or in a scene such as the main menu it might be too early, please try some of the other built-in Unity methods and make sure your networked audio runs only after the player setups a networked connection!")); } else { NetworkHandler.Instance.RemoveAudioClipServerRpc(audioClip); } } public static void SyncNetworkedAudioClips() { if ((Object)(object)Instance == (Object)null) { Debug.LogWarning((object)"LCSoundTool is not loaded yet; networked call ignored."); } else if (!Instance.configUseNetworking.Value) { Instance.logger.LogWarning((object)"Networking disabled! Failed to sync audio clips!"); } else if ((Object)(object)Instance == (Object)null || (Object)(object)GameNetworkManagerPatch.networkHandlerHost == (Object)null || (Object)(object)NetworkHandler.Instance == (Object)null) { Instance.logger.LogWarning((object)"Instance of SoundTool not found or networking has not finished initializing. Failed to sync networked audio! If you're syncing things in Awake or in a scene such as the main menu it might be too early, please try some of the other built-in Unity methods and make sure your networked audio runs only after the player setups a networked connection!"); } else { NetworkHandler.Instance.SyncAudioClipsServerRpc(); } } public static void SendUnityRandomSeed(int seed) { if ((Object)(object)Instance == (Object)null) { Debug.LogWarning((object)"LCSoundTool is not loaded yet; networked call ignored."); } else if (!Instance.configUseNetworking.Value) { Instance.logger.LogWarning((object)"Networking disabled! Failed to send Unity random seed!"); } else if ((Object)(object)Instance == (Object)null || (Object)(object)GameNetworkManagerPatch.networkHandlerHost == (Object)null || (Object)(object)NetworkHandler.Instance == (Object)null) { Instance.logger.LogWarning((object)"Instance of SoundTool not found or networking has not finished initializing. Failed to send Unity Random seed! If you're sending the seed in Awake or in a scene such as the main menu it might be too early, please try some of the other built-in Unity methods and make sure your networked methods run only after the player setups a networked connection!"); } else { NetworkHandler.Instance.SendSeedToClientsServerRpc(seed); } } public void ToggleDebug() { debugAudioSources = !debugAudioSources; if (indepthDebugging && !debugAudioSources) { indepthDebugging = false; } Instance.logger.LogDebug((object)$"Toggling AudioSource debug logs {debugAudioSources}!"); } public void ToggleIndepthDebug() { debugAudioSources = !debugAudioSources; indepthDebugging = debugAudioSources; infoDebugging = debugAudioSources; Instance.logger.LogDebug((object)$"Toggling in-depth AudioSource debug logs {debugAudioSources}!"); } public void ToggleInfoDebug() { infoDebugging = !infoDebugging; Instance.logger.LogDebug((object)$"Toggling informational debug logs {infoDebugging}!"); } public void PrintAllReplacedSounds() { Instance.logger.LogDebug((object)" "); Instance.logger.LogDebug((object)"Printing all currently replaced sounds..."); Instance.logger.LogDebug((object)" "); string[] array = replacedClips.Keys.ToArray(); for (int i = 0; i < replacedClips.Count; i++) { ReplacementAudioClip replacementAudioClip = replacedClips[array[i]]; Instance.logger.LogDebug((object)$"Clip named {array[i]} with {replacementAudioClip.clips.Count} replacement clip(s)"); Instance.logger.LogDebug((object)$"- Clip can play? {replacementAudioClip.canPlay}"); Instance.logger.LogDebug((object)("- Clip audio source(s)? " + replacementAudioClip.source)); Instance.logger.LogDebug((object)$"- All {replacementAudioClip.clips.Count} clip(s):"); for (int j = 0; j < replacementAudioClip.clips.Count; j++) { Instance.logger.LogDebug((object)$"-- Clip {j + 1} - {replacementAudioClip.clips[j].clip.GetName()} with chance of {Mathf.RoundToInt(replacementAudioClip.clips[j].chance * 100f)}%"); } Instance.logger.LogDebug((object)$"-- Total - All clips combined chance {Mathf.RoundToInt(replacementAudioClip.TotalChance() * 100f)}%"); } Instance.logger.LogDebug((object)" "); Instance.logger.LogDebug((object)"Finished printing all currently replaced sounds!"); Instance.logger.LogDebug((object)" "); } private void PrintAllCurrentSounds() { //IL_0196: Unknown result type (might be due to invalid IL or missing references) Instance.logger.LogDebug((object)" "); Instance.logger.LogDebug((object)"Printing all sounds in currently loaded scenes..."); Instance.logger.LogDebug((object)" "); AudioSource[] array = Object.FindObjectsOfType<AudioSource>(true); AudioSourceExtension audioSourceExtension = default(AudioSourceExtension); for (int i = 0; i < array.Length; i++) { Instance.logger.LogDebug((object)$"AudioSource {array[i]} with clip {array[i].clip}"); Instance.logger.LogDebug((object)$"- Volume: {array[i].volume}"); Instance.logger.LogDebug((object)$"- Priority: {array[i].priority}"); Instance.logger.LogDebug((object)$"- Plays on awake? {array[i].playOnAwake}"); Instance.logger.LogDebug((object)$"- Loops? {array[i].loop}"); Instance.logger.LogDebug((object)$"- Needs custom LCSoundTool component? {array[i].playOnAwake}"); Instance.logger.LogDebug((object)$"- Contains custom LCSoundTool component? {((Component)((Component)array[i]).transform).TryGetComponent<AudioSourceExtension>(ref audioSourceExtension)}"); Instance.logger.LogDebug((object)$"- Used by PlayAudioAnimationEvent component? {array[i].UsedByAnimationEventScript()}"); Instance.logger.LogDebug((object)$"- Located in Scene: {((Component)array[i]).gameObject.scene}"); Instance.logger.LogDebug((object)"- Located on the following GameObject:"); Transform val = ((Component)array[i]).transform; Instance.logger.LogDebug((object)$"-- (This) {val}"); while ((Object)(object)val != (Object)(object)((Component)array[i]).transform.root) { val = val.parent; Instance.logger.LogDebug((object)$"-- {val}"); } } Instance.logger.LogDebug((object)" "); Instance.logger.LogDebug((object)"Finished printing all sounds in currently loaded scenes!"); Instance.logger.LogDebug((object)" "); } } } namespace LCSoundTool.Utilities { public static class AudioUtility { public static byte[] AudioClipToByteArray(AudioClip audioClip, out float[] samples) { samples = new float[audioClip.samples * audioClip.channels]; audioClip.GetData(samples, 0); byte[] array = new byte[samples.Length * 2]; for (int i = 0; i < samples.Length; i++) { short num = (short)(((samples[i] < -1f) ? (-1f) : ((samples[i] > 1f) ? 1f : samples[i])) * 32767f); array[i * 2] = (byte)num; array[i * 2 + 1] = (byte)(num >> 8); } return array; } public static AudioClip LoadFromMemory(byte[] fileData, string clipName) { if (fileData == null || fileData.Length <= 44) { SoundTool instance = SoundTool.Instance; if (instance != null) { instance.logger.LogWarning((object)("Can't load " + clipName + ": the data is too short to be a WAV file.")); } return null; } int channels = BitConverter.ToInt16(fileData, 22); int frequency = BitConverter.ToInt32(fileData, 24); byte[] array = new byte[fileData.Length - 44]; Array.Copy(fileData, 44, array, 0, array.Length); return ByteArrayToAudioClip(array, clipName, channels, frequency); } public static AudioClip ByteArrayToAudioClip(byte[] byteArray, string clipName, int channels, int frequency) { if (frequency < 1 || frequency > 48000) { frequency = 44100; } if (channels < 1 || channels > 2) { channels = 1; } AudioClip obj = AudioClip.Create(clipName, byteArray.Length / 2, channels, frequency, false); obj.SetData(ConvertByteArrayToFloatArray(byteArray), 0); return obj; } private static float[] ConvertByteArrayToFloatArray(byte[] byteArray) { float[] array = new float[byteArray.Length / 2]; for (int i = 0; i < array.Length; i++) { short num = (short)(byteArray[i * 2] | (byteArray[i * 2 + 1] << 8)); array[i] = (float)num / 32767f; } return array; } public static AudioClip LoadFromDiskToAudioClip(string path, AudioType type) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Invalid comparison between Unknown and I4 //IL_0051: Unknown result type (might be due to invalid IL or missing references) AudioClip result = null; string text = path; try { text = new Uri(Path.GetFullPath(path)).AbsoluteUri; } catch (Exception) { } UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(text, type); try { audioClip.SendWebRequest(); try { while (!audioClip.isDone) { Thread.Yield(); } if ((int)audioClip.result != 1) { SoundTool.Instance.logger.LogError((object)$"Failed to load {type} AudioClip from path: {path} Full error: {audioClip.error}"); } else { result = DownloadHandlerAudioClip.GetContent(audioClip); } } catch (Exception ex2) { SoundTool.Instance.logger.LogError((object)(ex2.Message + ", " + ex2.StackTrace)); } } finally { ((IDisposable)audioClip)?.Dispose(); } return result; } } public static class Extensions { public static bool ContainsThisRandomAudioClip(this List<RandomAudioClip> list, RandomAudioClip thisClip) { if (thisClip == null || (Object)(object)thisClip.clip == (Object)null) { return false; } string name = thisClip.clip.GetName(); for (int i = 0; i < list.Count; i++) { if (list[i] != null && (Object)(object)list[i].clip != (Object)null && list[i].chance == thisClip.chance && list[i].clip.GetName() == name) { return true; } } return false; } public static bool UsedByAnimationEventScript(this AudioSource source) { PlayAudioAnimationEvent componentInChildren = ((Component)((Component)source).transform.root).GetComponentInChildren<PlayAudioAnimationEvent>(); if ((Object)(object)componentInChildren != (Object)null) { if (!((Object)(object)componentInChildren.audioToPlay == (Object)(object)source)) { return (Object)(object)componentInChildren.audioToPlayB == (Object)(object)source; } return true; } return false; } } public static class InputHelper { public static Dictionary<string, Keybind> keybinds; public static void Initialize() { keybinds = new Dictionary<string, Keybind>(); } public static bool CheckInput(string keybind) { if (keybinds == null || !keybinds.TryGetValue(keybind, out var value)) { return false; } if (((KeyboardShortcut)(ref value.shortcut)).IsDown() && !value.wasPressed) { value.wasPressed = true; } if (((KeyboardShortcut)(ref value.shortcut)).IsUp() && value.wasPressed) { value.wasPressed = false; value.onPress?.Invoke(); return true; } return false; } } [Serializable] public class Keybind { public KeyboardShortcut shortcut; public Action onPress; public bool wasPressed; public Keybind(KeyboardShortcut shortcut, Action onPress, bool wasPressed = false) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) this.shortcut = shortcut; this.onPress = onPress; this.wasPressed = wasPressed; } } } namespace LCSoundTool.Patches { [HarmonyPatch(typeof(AudioSource))] internal class AudioSourcePatch { private static readonly Dictionary<string, AudioClip> originalClips = new Dictionary<string, AudioClip>(); [HarmonyPatch("Play", new Type[] { })] [HarmonyPrefix] public static void Play_Patch(AudioSource __instance) { RunDynamicClipReplacement(__instance); DebugPlay(__instance, ((Object)(object)__instance != (Object)null) ? __instance.clip : null, "is playing", ""); } [HarmonyPatch("Play", new Type[] { typeof(ulong) })] [HarmonyPrefix] public static void Play_UlongPatch(AudioSource __instance) { RunDynamicClipReplacement(__instance); DebugPlay(__instance, ((Object)(object)__instance != (Object)null) ? __instance.clip : null, "is playing", ""); } [HarmonyPatch("Play", new Type[] { typeof(double) })] [HarmonyPrefix] public static void Play_DoublePatch(AudioSource __instance) { RunDynamicClipReplacement(__instance); DebugPlay(__instance, ((Object)(object)__instance != (Object)null) ? __instance.clip : null, "is playing", ""); } [HarmonyPatch("PlayDelayed", new Type[] { typeof(float) })] [HarmonyPrefix] public static void PlayDelayed_Patch(AudioSource __instance) { RunDynamicClipReplacement(__instance); DebugPlay(__instance, ((Object)(object)__instance != (Object)null) ? __instance.clip : null, "is playing", " with delay"); } [HarmonyPatch("PlayClipAtPoint", new Type[] { typeof(AudioClip), typeof(Vector3), typeof(float) })] [HarmonyPrefix] public static bool PlayClipAtPoint_Patch(AudioClip clip, Vector3 position, float volume) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Expected O, but got Unknown if ((Object)(object)clip == (Object)null) { return true; } GameObject val = new GameObject($"ClipAtPoint_{clip}"); val.transform.position = position; AudioSource val2 = val.AddComponent<AudioSource>(); val2.clip = clip; val2.spatialBlend = 1f; val2.volume = volume; val2.Play(); DebugPlay(val2, val2.clip, "is playing", $" at point {position}"); AudioClip val3 = (((Object)(object)val2.clip != (Object)null) ? val2.clip : clip); Object.Destroy((Object)val, val3.length * ((Time.timeScale < 0.01f) ? 0.01f : Time.timeScale)); return false; } [HarmonyPatch("PlayOneShotHelper", new Type[] { typeof(AudioSource), typeof(AudioClip), typeof(float) })] [HarmonyPrefix] public static void PlayOneShotHelper_Patch(AudioSource source, ref AudioClip clip, float volumeScale) { clip = ReplaceClipWithNew(clip, source); DebugPlay(source, clip, "is playing one shot", ""); } private static string ClipName(AudioClip clip) { if (!((Object)(object)clip != (Object)null)) { return "(no clip)"; } return ((Object)clip).name; } private static void DebugPlay(AudioSource source, AudioClip clip, string verb, string suffix) { if ((Object)(object)source == (Object)null || (!SoundTool.debugAudioSources && !SoundTool.indepthDebugging)) { return; } if (!SoundTool.indepthDebugging) { SoundTool.Instance.logger.LogDebug((object)$"{source} at {((Component)source).transform.root} {verb} {ClipName(clip)}{suffix}"); return; } SoundTool.Instance.logger.LogDebug((object)$"{source} {verb} {ClipName(clip)}{suffix} at"); Transform parent = ((Component)source).transform.parent; while ((Object)(object)parent != (Object)null) { SoundTool.Instance.logger.LogDebug((object)$"--- {parent}"); parent = parent.parent; } } private static string FindFinalName(string clipName, string sourceName) { string result = clipName; if (sourceName == null || SoundTool.replacedClips.Count == 0) { return result; } foreach (string key in SoundTool.replacedClips.Keys) { int num = key.IndexOf('#'); if (num >= 0 && key.IndexOf('#', num + 1) < 0 && key.IndexOf(clipName, 0, num, StringComparison.Ordinal) >= 0 && key.IndexOf(sourceName, num + 1, StringComparison.Ordinal) >= 0) { result = clipName + "#" + key.Substring(num + 1); } } return result; } private static bool SourceAllows(ReplacementAudioClip replacement, string sourceName) { if (string.IsNullOrEmpty(replacement.source)) { return true; } if (sourceName == null) { return false; } string[] array = replacement.source.Split(','); for (int i = 0; i < array.Length; i++) { if (array[i] == sourceName) { return true; } } return false; } private static RandomAudioClip PickRandom(ReplacementAudioClip replacement) { List<RandomAudioClip> clips = replacement.clips; float num = 0f; for (int i = 0; i < clips.Count; i++) { num += clips[i].chance; } float num2 = Random.Range(0f, num); for (int j = 0; j < clips.Count; j++) { if (num2 <= clips[j].chance) { return clips[j]; } num2 -= clips[j].chance; } return null; } private static void RunDynamicClipReplacement(AudioSource instance) { if ((Object)(object)instance == (Object)null || (Object)(object)instance.clip == (Object)null) { return; } string name = ((Object)((Component)instance).gameObject).name; string name2 = instance.clip.GetName(); string text = FindFinalName(name2, name); if (SoundTool.infoDebugging) { SoundTool.Instance.logger.LogDebug((object)("sourceName " + name + " clipName " + name2 + " finalName " + text)); } AudioClip value3; if (SoundTool.replacedClips.TryGetValue(text, out var value)) { if (!value.canPlay) { return; } if (!originalClips.ContainsKey(name)) { originalClips.Add(name, instance.clip); } bool flag = SourceAllows(value, name); RandomAudioClip randomAudioClip = PickRandom(value); if (randomAudioClip == null) { return; } AudioClip value2; if (flag) { if (SoundTool.infoDebugging) { SoundTool.Instance.logger.LogDebug((object)$"clip replaced with {randomAudioClip.clip}"); } instance.clip = randomAudioClip.clip; } else if (originalClips.TryGetValue(name, out value2)) { instance.clip = value2; originalClips.Remove(name); if (SoundTool.infoDebugging) { SoundTool.Instance.logger.LogDebug((object)$"clip restored to {value2}"); } } } else if (originalClips.TryGetValue(name, out value3)) { instance.clip = value3; originalClips.Remove(name); if (SoundTool.infoDebugging) { SoundTool.Instance.logger.LogDebug((object)$"clip restored to {value3}"); } } } private static AudioClip ReplaceClipWithNew(AudioClip original, AudioSource source = null) { if ((Object)(object)original == (Object)null) { return original; } string name = original.GetName(); string text = (((Object)(object)source != (Object)null) ? ((Object)((Component)source).gameObject).name : null); string text2 = FindFinalName(name, text); if (SoundTool.infoDebugging) { SoundTool.Instance.logger.LogDebug((object)("one shot: sourceName " + (text ?? "(none)") + " clipName " + name + " finalName " + text2)); } if (SoundTool.replacedClips.TryGetValue(text2, out var value)) { if (!value.canPlay) { return original; } if (!originalClips.ContainsKey(text2)) { originalClips.Add(text2, original); } bool flag = SourceAllows(value, text); RandomAudioClip randomAudioClip = PickRandom(value); if (randomAudioClip == null) { return original; } if (flag) { if (SoundTool.infoDebugging) { SoundTool.Instance.logger.LogDebug((object)$"clip replaced with {randomAudioClip.clip}"); } return randomAudioClip.clip; } if (originalClips.TryGetValue(text2, out var value2)) { originalClips.Remove(text2); return value2; } return original; } if (originalClips.TryGetValue(text2, out var value3)) { originalClips.Remove(text2); if (SoundTool.infoDebugging) { SoundTool.Instance.logger.LogDebug((object)$"clip restored to {value3}"); } return value3; } return original; } } [HarmonyPatch(typeof(GameNetworkManager))] internal class GameNetworkManagerPatch { public static GameObject networkPrefab; public static GameObject networkHandlerHost; [HarmonyPatch("Start")] [HarmonyPrefix] public static void Start_Patch() { if (!((Object)(object)networkPrefab != (Object)null)) { SoundTool.Instance.logger.LogDebug((object)"Loading NetworkHandler prefab..."); networkPrefab = Assets.bundle.LoadAsset<GameObject>("SoundToolNetworkHandler.prefab"); if ((Object)(object)networkPrefab == (Object)null) { SoundTool.Instance.logger.LogError((object)"Failed to load NetworkHandler prefab!"); } if ((Object)(object)networkPrefab != (Object)null) { NetworkManager.Singleton.AddNetworkPrefab(networkPrefab); SoundTool.Instance.logger.LogDebug((object)"Registered NetworkHandler prefab!"); } else { SoundTool.Instance.logger.LogWarning((object)"Failed to registered NetworkHandler prefab! No networking can take place."); } } } [HarmonyPatch("StartDisconnect")] [HarmonyPostfix] private static void StartDisconnect_Patch() { try { if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer) { SoundTool.Instance.logger.LogDebug((object)"Destroying NetworkHandler prefab!"); Object.Destroy((Object)(object)networkHandlerHost); networkHandlerHost = null; } } catch { SoundTool.Instance.logger.LogError((object)"Failed to destroy NetworkHandler prefab!"); } } } [HarmonyPatch(typeof(StartOfRound))] internal class StartOfRoundPatch { [HarmonyPatch("Awake")] [HarmonyPostfix] private static void SpawnNetworkHandler() { //IL_0031: 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) try { if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer) { SoundTool.Instance.logger.LogDebug((object)"Spawning NetworkHandler prefab!"); GameNetworkManagerPatch.networkHandlerHost = Object.Instantiate<GameObject>(GameNetworkManagerPatch.networkPrefab, Vector3.zero, Quaternion.identity); GameNetworkManagerPatch.networkHandlerHost.GetComponent<NetworkObject>().Spawn(true); } } catch { SoundTool.Instance.logger.LogError((object)"Failed to spawn NetworkHandler prefab!"); } } } } namespace LCSoundTool.Networking { public class NetworkHandler : NetworkBehaviour { public static NetworkHandler Instance { get; private set; } public static Dictionary<string, AudioClip> networkedAudioClips { get; private set; } public static event Action ClientNetworkedAudioChanged; public static event Action HostNetworkedAudioChanged; public override void OnNetworkSpawn() { Debug.Log((object)"LCSoundTool - NetworkHandler created!"); NetworkHandler.ClientNetworkedAudioChanged = null; NetworkHandler.HostNetworkedAudioChanged = null; networkedAudioClips = new Dictionary<string, AudioClip>(); Instance = this; } [ClientRpc] public void ReceiveAudioClipClientRpc(string clipName, byte[] audioData, int channels, int frequency) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Invalid comparison between Unknown and I4 //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Invalid comparison between Unknown and I4 //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0107: 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_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager; if (networkManager == null || !networkManager.IsListening) { return; } if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost)) { ClientRpcParams val2 = default(ClientRpcParams); FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(292212293u, val2, (RpcDelivery)0); bool flag = clipName != null; ((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag, default(ForPrimitives)); if (flag) { ((FastBufferWriter)(ref val)).WriteValueSafe(clipName, false); } bool flag2 = audioData != null; ((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag2, default(ForPrimitives)); if (flag2) { ((FastBufferWriter)(ref val)).WriteValueSafe<byte>(audioData, default(ForPrimitives)); } BytePacker.WriteValueBitPacked(val, channels); BytePacker.WriteValueBitPacked(val, frequency); ((NetworkBehaviour)this).__endSendClientRpc(ref val, 292212293u, val2, (RpcDelivery)0); } if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost)) { base.__rpc_exec_stage = (__RpcExecStage)0; if (!networkedAudioClips.ContainsKey(clipName)) { AudioClip val3 = null; val3 = AudioUtility.ByteArrayToAudioClip(audioData, clipName, channels, frequency); networkedAudioClips.Add(clipName, val3); NetworkHandler.ClientNetworkedAudioChanged?.Invoke(); } else { SoundTool.Instance.logger.LogDebug((object)("Sound " + clipName + " already exists for this client! Skipping addition of this sound for this client.")); } } } [ClientRpc] public void RemoveAudioClipClientRpc(string clipName) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Invalid comparison between Unknown and I4 //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Invalid comparison between Unknown and I4 //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager; if (networkManager == null || !networkManager.IsListening) { return; } if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost)) { ClientRpcParams val2 = default(ClientRpcParams); FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(1355469546u, val2, (RpcDelivery)0); bool flag = clipName != null; ((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag, default(ForPrimitives)); if (flag) { ((FastBufferWriter)(ref val)).WriteValueSafe(clipName, false); } ((NetworkBehaviour)this).__endSendClientRpc(ref val, 1355469546u, val2, (RpcDelivery)0); } if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost)) { base.__rpc_exec_stage = (__RpcExecStage)0; if (networkedAudioClips.ContainsKey(clipName)) { networkedAudioClips.Remove(clipName); NetworkHandler.ClientNetworkedAudioChanged?.Invoke(); } } } [ClientRpc] public void SyncAudioClipsClientRpc(string clipName) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Invalid comparison between Unknown and I4 //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Invalid comparison between Unknown and I4 //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager; if (networkManager == null || !networkManager.IsListening) { return; } if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost)) { ClientRpcParams val2 = default(ClientRpcParams); FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(2611915412u, val2, (RpcDelivery)0); bool flag = clipName != null; ((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag, default(ForPrimitives)); if (flag) { ((FastBufferWriter)(ref val)).WriteValueSafe(clipName, false); } ((NetworkBehaviour)this).__endSendClientRpc(ref val, 2611915412u, val2, (RpcDelivery)0); } if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost)) { base.__rpc_exec_stage = (__RpcExecStage)0; if (!networkedAudioClips.ContainsKey(clipName)) { SendExistingAudioClipServerRpc(clipName); } } } [ClientRpc] public void ReceiveSeedClientRpc(int seed) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Invalid comparison between Unknown and I4 //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Invalid comparison between Unknown and I4 //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager; if (networkManager != null && networkManager.IsListening) { if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost)) { ClientRpcParams val2 = default(ClientRpcParams); FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(1556253924u, val2, (RpcDelivery)0); BytePacker.WriteValueBitPacked(val, seed); ((NetworkBehaviour)this).__endSendClientRpc(ref val, 1556253924u, val2, (RpcDelivery)0); } if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost)) { base.__rpc_exec_stage = (__RpcExecStage)0; Random.InitState(seed); SoundTool.Instance.logger.LogDebug((object)$"Client received a new Unity Random seed of {seed}!"); } } } [ServerRpc(RequireOwnership = false)] public void SendAudioClipServerRpc(string clipName, byte[] audioData, int channels, int frequency) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Invalid comparison between Unknown and I4 //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Invalid comparison between Unknown and I4 //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_0107: 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_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager; if (networkManager == null || !networkManager.IsListening) { return; } if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost)) { ServerRpcParams val2 = default(ServerRpcParams); FastBufferWriter val = ((NetworkBehaviour)this).__beginSendServerRpc(2399630547u, val2, (RpcDelivery)0); bool flag = clipName != null; ((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag, default(ForPrimitives)); if (flag) { ((FastBufferWriter)(ref val)).WriteValueSafe(clipName, false); } bool flag2 = audioData != null; ((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag2, default(ForPrimitives)); if (flag2) { ((FastBufferWriter)(ref val)).WriteValueSafe<byte>(audioData, default(ForPrimitives)); } BytePacker.WriteValueBitPacked(val, channels); BytePacker.WriteValueBitPacked(val, frequency); ((NetworkBehaviour)this).__endSendServerRpc(ref val, 2399630547u, val2, (RpcDelivery)0); } if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost)) { base.__rpc_exec_stage = (__RpcExecStage)0; ReceiveAudioClipClientRpc(clipName, audioData, channels, frequency); NetworkHandler.HostNetworkedAudioChanged?.Invoke(); } } [ServerRpc(RequireOwnership = false)] public void RemoveAudioClipServerRpc(string clipName) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Invalid comparison between Unknown and I4 //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Invalid comparison between Unknown and I4 //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager; if (networkManager == null || !networkManager.IsListening) { return; } if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost)) { ServerRpcParams val2 = default(ServerRpcParams); FastBufferWriter val = ((NetworkBehaviour)this).__beginSendServerRpc(3103497155u, val2, (RpcDelivery)0); bool flag = clipName != null; ((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag, default(ForPrimitives)); if (flag) { ((FastBufferWriter)(ref val)).WriteValueSafe(clipName, false); } ((NetworkBehaviour)this).__endSendServerRpc(ref val, 3103497155u, val2, (RpcDelivery)0); } if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost)) { base.__rpc_exec_stage = (__RpcExecStage)0; RemoveAudioClipClientRpc(clipName); NetworkHandler.HostNetworkedAudioChanged?.Invoke(); } } [ServerRpc(RequireOwnership = false)] public void SyncAudioClipsServerRpc() { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Invalid comparison between Unknown and I4 //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Invalid comparison between Unknown and I4 //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager; if (networkManager == null || !networkManager.IsListening) { return; } if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost)) { ServerRpcParams val2 = default(ServerRpcParams); FastBufferWriter val = ((NetworkBehaviour)this).__beginSendServerRpc(178607916u, val2, (RpcDelivery)0); ((NetworkBehaviour)this).__endSendServerRpc(ref val, 178607916u, val2, (RpcDelivery)0); } if ((int)base.__rpc_exec_stage != 1 || (!networkManager.IsServer && !networkManager.IsHost)) { return; } base.__rpc_exec_stage = (__RpcExecStage)0; string[] array = networkedAudioClips.Keys.ToArray(); if (array.Length < 1) { SoundTool.Instance.logger.LogDebug((object)"No sounds found in networkedClips. Syncing process cancelled!"); return; } for (int i = 0; i < array.Length; i++) { SyncAudioClipsClientRpc(array[i]); } } [ServerRpc(RequireOwnership = false)] public void SendExistingAudioClipServerRpc(string clipName) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Invalid comparison between Unknown and I4 //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Invalid comparison between Unknown and I4 //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager; if (networkManager == null || !networkManager.IsListening) { return; } if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost)) { ServerRpcParams val2 = default(ServerRpcParams); FastBufferWriter val = ((NetworkBehaviour)this).__beginSendServerRpc(4006259189u, val2, (RpcDelivery)0); bool flag = clipName != null; ((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag, default(ForPrimitives)); if (flag) { ((FastBufferWriter)(ref val)).WriteValueSafe(clipName, false); } ((NetworkBehaviour)this).__endSendServerRpc(ref val, 4006259189u, val2, (RpcDelivery)0); } if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost)) { base.__rpc_exec_stage = (__RpcExecStage)0; if (networkedAudioClips.ContainsKey(clipName)) { byte[] array = null; array = AudioUtility.AudioClipToByteArray(networkedAudioClips[clipName], out var _); ReceiveAudioClipClientRpc(clipName, array, networkedAudioClips[clipName].channels, networkedAudioClips[clipName].frequency); } else { SoundTool.Instance.logger.LogWarning((object)"Trying to obtain and sync a sound from the host that does not exist in the host's game!"); } } } [ServerRpc(RequireOwnership = false)] public void SendSeedToClientsServerRpc(int seed) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Invalid comparison between Unknown and I4 //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Invalid comparison between Unknown and I4 //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager; if (networkManager == null || !networkManager.IsListening) { return; } if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost)) { ServerRpcParams val2 = default(ServerRpcParams); FastBufferWriter val = ((NetworkBehaviour)this).__beginSendServerRpc(4286510828u, val2, (RpcDelivery)0); BytePacker.WriteValueBitPacked(val, seed); ((NetworkBehaviour)this).__endSendServerRpc(ref val, 4286510828u, val2, (RpcDelivery)0); } if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost)) { base.__rpc_exec_stage = (__RpcExecStage)0; if (((NetworkBehaviour)this).IsHost) { ReceiveSeedClientRpc(seed); SoundTool.Instance.logger.LogDebug((object)$"Sending a new Unity random seed of {seed} to all clients..."); } } } protected override void __initializeVariables() { ((NetworkBehaviour)this).__initializeVariables(); } protected override void __initializeRpcs() { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected O, but got Unknown //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Expected O, but got Unknown //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Expected O, but got Unknown //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Expected O, but got Unknown //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Expected O, but got Unknown //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Expected O, but got Unknown //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Expected O, but got Unknown //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Expected O, but got Unknown ((NetworkBehaviour)this).__registerRpc(292212293u, new RpcReceiveHandler(__rpc_handler_292212293), "ReceiveAudioClipClientRpc"); ((NetworkBehaviour)this).__registerRpc(1355469546u, new RpcReceiveHandler(__rpc_handler_1355469546), "RemoveAudioClipClientRpc"); ((NetworkBehaviour)this).__registerRpc(2611915412u, new RpcReceiveHandler(__rpc_handler_2611915412), "SyncAudioClipsClientRpc"); ((NetworkBehaviour)this).__registerRpc(1556253924u, new RpcReceiveHandler(__rpc_handler_1556253924), "ReceiveSeedClientRpc"); ((NetworkBehaviour)this).__registerRpc(2399630547u, new RpcReceiveHandler(__rpc_handler_2399630547), "SendAudioClipServerRpc"); ((NetworkBehaviour)this).__registerRpc(3103497155u, new RpcReceiveHandler(__rpc_handler_3103497155), "RemoveAudioClipServerRpc"); ((NetworkBehaviour)this).__registerRpc(178607916u, new RpcReceiveHandler(__rpc_handler_178607916), "SyncAudioClipsServerRpc"); ((NetworkBehaviour)this).__registerRpc(4006259189u, new RpcReceiveHandler(__rpc_handler_4006259189), "SendExistingAudioClipServerRpc"); ((NetworkBehaviour)this).__registerRpc(4286510828u, new RpcReceiveHandler(__rpc_handler_4286510828), "SendSeedToClientsServerRpc"); ((NetworkBehaviour)this).__initializeRpcs(); } private static void __rpc_handler_292212293(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams) { //IL_002f: 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_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: 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_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) NetworkManager networkManager = target.NetworkManager; if (networkManager != null && networkManager.IsListening) { bool flag = default(bool); ((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives)); string clipName = null; if (flag) { ((FastBufferReader)(ref reader)).ReadValueSafe(ref clipName, false); } bool flag2 = default(bool); ((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag2, default(ForPrimitives)); byte[] audioData = null; if (flag2) { ((FastBufferReader)(ref reader)).ReadValueSafe<byte>(ref audioData, default(ForPrimitives)); } int channels = default(int); ByteUnpacker.ReadValueBitPacked(reader, ref channels); int frequency = default(int); ByteUnpacker.ReadValueBitPacked(reader, ref frequency); target.__rpc_exec_stage = (__RpcExecStage)1; ((NetworkHandler)(object)target).ReceiveAudioClipClientRpc(clipName, audioData, channels, frequency); target.__rpc_exec_stage = (__RpcExecStage)0; } } private static void __rpc_handler_1355469546(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams) { //IL_002f: 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_0061: 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) NetworkManager networkManager = target.NetworkManager; if (networkManager != null && networkManager.IsListening) { bool flag = default(bool); ((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives)); string clipName = null; if (flag) { ((FastBufferReader)(ref reader)).ReadValueSafe(ref clipName, false); } target.__rpc_exec_stage = (__RpcExecStage)1; ((NetworkHandler)(object)target).RemoveAudioClipClientRpc(clipName); target.__rpc_exec_stage = (__RpcExecStage)0; } } private static void __rpc_handler_2611915412(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams) { //IL_002f: 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_0061: 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) NetworkManager networkManager = target.NetworkManager; if (networkManager != null && networkManager.IsListening) { bool flag = default(bool); ((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives)); string clipName = null; if (flag) { ((FastBufferReader)(ref reader)).ReadValueSafe(ref clipName, false); } target.__rpc_exec_stage = (__RpcExecStage)1; ((NetworkHandler)(object)target).SyncAudioClipsClientRpc(clipName); target.__rpc_exec_stage = (__RpcExecStage)0; } } private static void __rpc_handler_1556253924(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams) { //IL_0023: 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_0050: Unknown result type (might be due to invalid IL or missing references) NetworkManager networkManager = target.NetworkManager; if (networkManager != null && networkManager.IsListening) { int seed = default(int); ByteUnpacker.ReadValueBitPacked(reader, ref seed); target.__rpc_exec_stage = (__RpcExecStage)1; ((NetworkHandler)(object)target).ReceiveSeedClientRpc(seed); target.__rpc_exec_stage = (__RpcExecStage)0; } } private static void __rpc_handler_2399630547(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams) { //IL_002f: 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_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: 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_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) NetworkManager networkManager = target.NetworkManager; if (networkManager != null && networkManager.IsListening) { bool flag = default(bool); ((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives)); string clipName = null; if (flag) { ((FastBufferReader)(ref reader)).ReadValueSafe(ref clipName, false); } bool flag2 = default(bool); ((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag2, default(ForPrimitives)); byte[] audioData = null; if (flag2) { ((FastBufferReader)(ref reader)).ReadValueSafe<byte>(ref audioData, default(ForPrimitives)); } int channels = default(int); ByteUnpacker.ReadValueBitPacked(reader, ref channels); int frequency = default(int); ByteUnpacker.ReadValueBitPacked(reader, ref frequency); target.__rpc_exec_stage = (__RpcExecStage)1; ((NetworkHandler)(object)target).SendAudioClipServerRpc(clipName, audioData, channels, frequency); target.__rpc_exec_stage = (__RpcExecStage)0; } } private static void __rpc_handler_3103497155(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams) { //IL_002f: 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_0061: 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) NetworkManager networkManager = target.NetworkManager; if (networkManager != null && networkManager.IsListening) { bool flag = default(bool); ((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives)); string clipName = null; if (flag) { ((FastBufferReader)(ref reader)).ReadValueSafe(ref clipName, false); } target.__rpc_exec_stage = (__RpcExecStage)1; ((NetworkHandler)(object)target).RemoveAudioClipServerRpc(clipName); target.__rpc_exec_stage = (__RpcExecStage)0; } } private static void __rpc_handler_178607916(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) NetworkManager networkManager = target.NetworkManager; if (networkManager != null && networkManager.IsListening) { target.__rpc_exec_stage = (__RpcExecStage)1; ((NetworkHandler)(object)target).SyncAudioClipsServerRpc(); target.__rpc_exec_stage = (__RpcExecStage)0; } } private static void __rpc_handler_4006259189(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams) { //IL_002f: 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_0061: 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) NetworkManager networkManager = target.NetworkManager; if (networkManager != null && networkManager.IsListening) { bool flag = default(bool); ((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives)); string clipName = null; if (flag) { ((FastBufferReader)(ref reader)).ReadValueSafe(ref clipName, false); } target.__rpc_exec_stage = (__RpcExecStage)1; ((NetworkHandler)(object)target).SendExistingAudioClipServerRpc(clipName); target.__rpc_exec_stage = (__RpcExecStage)0; } } private static void __rpc_handler_4286510828(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams) { //IL_0023: 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_0050: Unknown result type (might be due to invalid IL or missing references) NetworkManager networkManager = target.NetworkManager; if (networkManager != null && networkManager.IsListening) { int seed = default(int); ByteUnpacker.ReadValueBitPacked(reader, ref seed); target.__rpc_exec_stage = (__RpcExecStage)1; ((NetworkHandler)(object)target).SendSeedToClientsServerRpc(seed); target.__rpc_exec_stage = (__RpcExecStage)0; } } protected internal override string __getTypeName() { return "NetworkHandler"; } } public struct Strings : INetworkSerializable { private string[] myStrings; public string[] MyStrings { get { return myStrings; } set { myStrings = value; } } public Strings(string[] myStrings) { this.myStrings = myStrings; } public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) if (serializer.IsWriter) { FastBufferWriter fastBufferWriter = serializer.GetFastBufferWriter(); int num = myStrings.Length; ((FastBufferWriter)(ref fastBufferWriter)).WriteValueSafe<int>(ref num, default(ForPrimitives)); for (int i = 0; i < myStrings.Length; i++) { ((FastBufferWriter)(ref fastBufferWriter)).WriteValueSafe(myStrings[i], false); } } if (serializer.IsReader) { FastBufferReader fastBufferReader = serializer.GetFastBufferReader(); int num2 = default(int); ((FastBufferReader)(ref fastBufferReader)).ReadValueSafe<int>(ref num2, default(ForPrimitives)); myStrings = new string[num2]; for (int j = 0; j < num2; j++) { ((FastBufferReader)(ref fastBufferReader)).ReadValueSafe(ref myStrings[j], false);