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 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 Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LC_SoundTool")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Various audio related functions. Mainly logs all sounds that are playing and what type of playback they're into the BepInEx console.")]
[assembly: AssemblyFileVersion("1.4.0.0")]
[assembly: AssemblyInformationalVersion("1.4.0")]
[assembly: AssemblyProduct("LC_SoundTool")]
[assembly: AssemblyTitle("LC_SoundTool")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/no00ob/LCSoundTool")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.4.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
internal class <Module>
{
static <Module>()
{
}
}
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace LCSoundToolMod
{
public static class PluginInfo
{
public const string PLUGIN_GUID = "LC_SoundTool";
public const string PLUGIN_NAME = "LC_SoundTool";
public const string PLUGIN_VERSION = "1.4.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)
{
ResourceManager resourceManager = new ResourceManager("LCSoundToolMod.Properties.Resources", typeof(Resources).Assembly);
resourceMan = resourceManager;
}
return resourceMan;
}
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
internal static byte[] soundtool
{
get
{
object @object = ResourceManager.GetObject("soundtool", resourceCulture);
return (byte[])@object;
}
}
internal Resources()
{
}
}
}
namespace LCSoundTool
{
public class AudioSourceExtension : MonoBehaviour
{
public AudioSource audioSource;
public bool playOnAwake = false;
public bool loop = false;
private bool updateHasBeenLogged = false;
private bool hasPlayed = false;
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 (!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;
}
}
[BepInPlugin("LCSoundTool", "LC Sound Tool", "1.4.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";
private ConfigEntry<bool> configUseNetworking;
private ConfigEntry<bool> configSyncRandomSeed;
private ConfigEntry<float> configPlayOnAwakePatchRepeatDelay;
private readonly Harmony harmony = new Harmony("LCSoundTool");
public static SoundTool Instance;
internal ManualLogSource logger;
public KeyboardShortcut toggleAudioSourceDebugLog;
public KeyboardShortcut toggleIndepthDebugLog;
public KeyboardShortcut toggleInformationalDebugLog;
public bool wasKeyDown;
public bool wasKeyDown2;
public bool wasKeyDown3;
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, List<RandomAudioClip>> replacedClips { get; private set; }
public static Dictionary<string, AudioClip> networkedClips => NetworkHandler.networkedAudioClips;
public static Dictionary<string, AudioType> clipTypes { get; private set; }
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_012e: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_014c: Unknown result type (might be due to invalid IL or missing references)
//IL_0151: 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_016f: 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.");
Type[] types = Assembly.GetExecutingAssembly().GetTypes();
Type[] array = types;
foreach (Type type in array)
{
MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
MethodInfo[] array2 = methods;
foreach (MethodInfo methodInfo in array2)
{
object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
if (customAttributes.Length != 0)
{
methodInfo.Invoke(null, null);
}
}
}
logger = Logger.CreateLogSource("LCSoundTool");
logger.LogInfo((object)"Plugin LCSoundTool is loaded!");
toggleAudioSourceDebugLog = new KeyboardShortcut((KeyCode)286, (KeyCode[])(object)new KeyCode[0]);
toggleIndepthDebugLog = new KeyboardShortcut((KeyCode)286, (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 });
toggleInformationalDebugLog = new KeyboardShortcut((KeyCode)286, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 });
debugAudioSources = false;
indepthDebugging = false;
infoDebugging = false;
replacedClips = new Dictionary<string, List<RandomAudioClip>>();
clipTypes = new Dictionary<string, AudioType>();
}
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 (((KeyboardShortcut)(ref toggleInformationalDebugLog)).IsDown() && !wasKeyDown3)
{
wasKeyDown3 = true;
wasKeyDown2 = false;
wasKeyDown = false;
}
if (((KeyboardShortcut)(ref toggleInformationalDebugLog)).IsUp() && wasKeyDown3)
{
wasKeyDown3 = false;
wasKeyDown2 = false;
wasKeyDown = false;
infoDebugging = !infoDebugging;
Instance.logger.LogDebug((object)$"Toggling informational debug logs {infoDebugging}!");
return;
}
if (((KeyboardShortcut)(ref toggleIndepthDebugLog)).IsDown() && !wasKeyDown2)
{
wasKeyDown2 = true;
wasKeyDown = false;
}
if (((KeyboardShortcut)(ref toggleIndepthDebugLog)).IsUp() && wasKeyDown2)
{
wasKeyDown2 = false;
wasKeyDown = false;
debugAudioSources = !debugAudioSources;
indepthDebugging = debugAudioSources;
infoDebugging = debugAudioSources;
Instance.logger.LogDebug((object)$"Toggling in-depth AudioSource debug logs {debugAudioSources}!");
return;
}
if (!wasKeyDown2 && !((KeyboardShortcut)(ref toggleIndepthDebugLog)).IsDown() && ((KeyboardShortcut)(ref toggleAudioSourceDebugLog)).IsDown() && !wasKeyDown)
{
wasKeyDown = true;
wasKeyDown2 = false;
}
if (((KeyboardShortcut)(ref toggleAudioSourceDebugLog)).IsUp() && wasKeyDown)
{
wasKeyDown = false;
wasKeyDown2 = false;
debugAudioSources = !debugAudioSources;
if (indepthDebugging && !debugAudioSources)
{
indepthDebugging = false;
}
Instance.logger.LogDebug((object)$"Toggling AudioSource debug logs {debugAudioSources}!");
}
}
private void OnDestroy()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: 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.ToLower().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 repeatWait = configPlayOnAwakePatchRepeatDelay.Value;
if (repeatWait != 0f)
{
if (repeatWait < 10f)
{
repeatWait = 10f;
}
if (repeatWait > 600f)
{
repeatWait = 600f;
}
((MonoBehaviour)this).StartCoroutine(PatchPlayOnAwakeDelayed(scene, repeatWait));
}
}
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)"Plugin LCSoundTool is 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)"Plugin LCSoundTool is trying to replace an audio clip without new clip specified! This is not allowed.");
return;
}
string name = newClip.GetName();
float num = 100f;
if (name.Contains("-"))
{
string[] array = name.Split('-');
if (array.Length > 1)
{
string s = array[^1];
if (int.TryParse(s, out var result))
{
num = (float)result * 0.01f;
name = string.Join("-", array, 0, array.Length - 1);
}
}
}
if (replacedClips.ContainsKey(originalName) && num >= 100f)
{
Instance.logger.LogWarning((object)"Plugin LCSoundTool is trying to replace an audio clip that already has been replaced with 100% chance of playback! This is not allowed.");
return;
}
num = Mathf.Clamp01(num);
if (replacedClips.ContainsKey(originalName))
{
replacedClips[originalName].Add(new RandomAudioClip(newClip, num));
}
else
{
replacedClips[originalName] = new List<RandomAudioClip>
{
new RandomAudioClip(newClip, num)
};
}
float num2 = 0f;
for (int i = 0; i < replacedClips[originalName].Count(); i++)
{
num2 += replacedClips[originalName][i].chance;
}
if ((num2 < 1f || num2 > 1f) && replacedClips[originalName].Count() > 1)
{
Instance.logger.LogDebug((object)$"The current total combined chance for replaced {replacedClips[originalName].Count()} random audio clips for audio clip {originalName} does not equal 100% (at least yet?)");
}
else if (num2 == 1f && replacedClips[originalName].Count() > 1)
{
Instance.logger.LogDebug((object)$"The current total combined chance for replaced {replacedClips[originalName].Count()} random audio clips for audio clip {originalName} is equal to 100%");
}
}
public static void ReplaceAudioClip(AudioClip originalClip, AudioClip newClip)
{
if ((Object)(object)originalClip == (Object)null)
{
Instance.logger.LogWarning((object)"Plugin LCSoundTool is 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
{
ReplaceAudioClip(originalClip.GetName(), newClip);
}
}
public static void ReplaceAudioClip(string originalName, AudioClip newClip, float chance)
{
if (string.IsNullOrEmpty(originalName))
{
Instance.logger.LogWarning((object)"Plugin LCSoundTool is 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)"Plugin LCSoundTool is trying to replace an audio clip without new clip specified! This is not allowed.");
return;
}
string name = newClip.GetName();
if (replacedClips.ContainsKey(originalName) && chance >= 100f)
{
Instance.logger.LogWarning((object)"Plugin LCSoundTool is trying to replace an audio clip that already has been replaced with 100% chance of playback! This is not allowed.");
return;
}
chance = Mathf.Clamp01(chance);
if (replacedClips.ContainsKey(originalName))
{
replacedClips[originalName].Add(new RandomAudioClip(newClip, chance));
}
else
{
replacedClips[originalName] = new List<RandomAudioClip>
{
new RandomAudioClip(newClip, chance)
};
}
float num = 0f;
for (int i = 0; i < replacedClips[originalName].Count(); i++)
{
num += replacedClips[originalName][i].chance;
}
if ((num < 1f || num > 1f) && replacedClips[originalName].Count() > 1)
{
Instance.logger.LogDebug((object)$"The current total combined chance for replaced {replacedClips[originalName].Count()} random audio clips for audio clip {originalName} does not equal 100% (at least yet?)");
}
else if (num == 1f && replacedClips[originalName].Count() > 1)
{
Instance.logger.LogDebug((object)$"The current total combined chance for replaced {replacedClips[originalName].Count()} random audio clips for audio clip {originalName} is equal to 100%");
}
}
public static void ReplaceAudioClip(AudioClip originalClip, AudioClip newClip, float chance)
{
if ((Object)(object)originalClip == (Object)null)
{
Instance.logger.LogWarning((object)"Plugin LCSoundTool is 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
{
ReplaceAudioClip(originalClip.GetName(), newClip, chance);
}
}
public static void RemoveRandomAudioClip(string name, float chance)
{
if (string.IsNullOrEmpty(name))
{
Instance.logger.LogWarning((object)"Plugin LCSoundTool is trying to restore an audio clip without original clip specified! This is not allowed.");
}
else if (!replacedClips.ContainsKey(name))
{
Instance.logger.LogWarning((object)"Plugin LCSoundTool is trying to restore an audio clip that does not exist! This is not allowed.");
}
else
{
if (!(chance > 0f))
{
return;
}
for (int i = 0; i < replacedClips[name].Count(); i++)
{
if (replacedClips[name][i].chance == chance)
{
replacedClips[name].RemoveAt(i);
break;
}
}
}
}
public static void RestoreAudioClip(string name)
{
if (string.IsNullOrEmpty(name))
{
Instance.logger.LogWarning((object)"Plugin LCSoundTool is trying to restore an audio clip without original clip specified! This is not allowed.");
}
else if (!replacedClips.ContainsKey(name))
{
Instance.logger.LogWarning((object)"Plugin LCSoundTool is trying to restore an audio clip that does not exist! This is not allowed.");
}
else
{
replacedClips.Remove(name);
}
}
public static void RestoreAudioClip(AudioClip clip)
{
if ((Object)(object)clip == (Object)null)
{
Instance.logger.LogWarning((object)"Plugin LCSoundTool is trying to restore an audio clip without original clip specified! This is not allowed.");
}
else
{
RestoreAudioClip(clip.GetName());
}
}
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;
bool flag = true;
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;
}
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;
}
else
{
Instance.logger.LogWarning((object)("Requested audio file does not exist at mod root path " + text3 + "!"));
}
}
if (Directory.Exists(path2))
{
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))
{
Instance.logger.LogWarning((object)("Legacy path contains the requested audio file at path " + text4 + "!"));
text = " legacy ";
text2 = text4;
flag = true;
}
string[] array = soundName.Split('.');
if (array[^1].ToLower().Contains("ogg"))
{
audioType = AudioType.ogg;
Instance.logger.LogDebug((object)"File detected as an Ogg Vorbis file!");
}
else if (array[^1].ToLower().Contains("mp3"))
{
audioType = AudioType.mp3;
Instance.logger.LogDebug((object)"File detected as a MPEG MP3 file!");
}
AudioClip val = null;
if (flag)
{
Instance.logger.LogDebug((object)("Loading AudioClip " + soundName + " from" + text + "path: " + text2));
switch (audioType)
{
case AudioType.wav:
val = WavUtility.LoadFromDiskToAudioClip(text2);
break;
case AudioType.ogg:
val = OggUtility.LoadFromDiskToAudioClip(text2);
break;
case AudioType.mp3:
val = Mp3Utility.LoadFromDiskToAudioClip(text2);
break;
}
Instance.logger.LogDebug((object)$"Finished loading AudioClip {soundName} with length of {val.length}!");
}
else
{
Instance.logger.LogWarning((object)("Failed to load AudioClip " + soundName + " from invalid" + text + "path at " + text2 + "!"));
}
if (string.IsNullOrEmpty(val.GetName()))
{
string empty = string.Empty;
string[] array2 = new string[0];
switch (audioType)
{
case AudioType.wav:
empty = soundName.Replace(".wav", "");
array2 = empty.Split('/');
if (array2.Length <= 1)
{
array2 = empty.Split('\\');
}
empty = array2[^1];
((Object)val).name = empty;
break;
case AudioType.ogg:
empty = soundName.Replace(".ogg", "");
array2 = empty.Split('/');
if (array2.Length <= 1)
{
array2 = empty.Split('\\');
}
empty = array2[^1];
((Object)val).name = empty;
break;
case AudioType.mp3:
empty = soundName.Replace(".mp3", "");
array2 = empty.Split('/');
if (array2.Length <= 1)
{
array2 = empty.Split('\\');
}
empty = array2[^1];
((Object)val).name = empty;
break;
}
}
if ((Object)(object)val != (Object)null)
{
clipTypes.Add(val.GetName(), audioType);
}
return val;
}
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;
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;
}
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;
}
else
{
Instance.logger.LogWarning((object)("Requested audio file does not exist at mod root path " + text3 + "!"));
}
}
if (Directory.Exists(path2))
{
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))
{
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:
Instance.logger.LogDebug((object)"File defined as a WAV file!");
break;
case AudioType.ogg:
Instance.logger.LogDebug((object)"File defined as an Ogg Vorbis file!");
break;
case AudioType.mp3:
Instance.logger.LogDebug((object)"File defined as a MPEG MP3 file!");
break;
}
AudioClip val = null;
if (flag)
{
Instance.logger.LogDebug((object)("Loading AudioClip " + soundName + " from" + text + "path: " + text2));
switch (audioType)
{
case AudioType.wav:
val = WavUtility.LoadFromDiskToAudioClip(text2);
break;
case AudioType.ogg:
val = OggUtility.LoadFromDiskToAudioClip(text2);
break;
case AudioType.mp3:
val = Mp3Utility.LoadFromDiskToAudioClip(text2);
break;
}
Instance.logger.LogDebug((object)$"Finished loading AudioClip {soundName} with length of {val.length}!");
}
else
{
Instance.logger.LogWarning((object)("Failed to load AudioClip " + soundName + " from invalid" + text + "path at " + text2 + "!"));
}
if (string.IsNullOrEmpty(val.GetName()))
{
string empty = string.Empty;
string[] array = new string[0];
switch (audioType)
{
case AudioType.wav:
empty = soundName.Replace(".wav", "");
array = empty.Split('/');
if (array.Length <= 1)
{
array = empty.Split('\\');
}
empty = array[^1];
((Object)val).name = empty;
break;
case AudioType.ogg:
empty = soundName.Replace(".ogg", "");
array = empty.Split('/');
if (array.Length <= 1)
{
array = empty.Split('\\');
}
empty = array[^1];
((Object)val).name = empty;
break;
case AudioType.mp3:
empty = soundName.Replace(".mp3", "");
array = empty.Split('/');
if (array.Length <= 1)
{
array = empty.Split('\\');
}
empty = array[^1];
((Object)val).name = empty;
break;
}
}
if ((Object)(object)val != (Object)null)
{
clipTypes.Add(val.GetName(), audioType);
}
return val;
}
public static void SendNetworkedAudioClip(AudioClip audioClip)
{
if (!Instance.configUseNetworking.Value)
{
Instance.logger.LogWarning((object)$"Networking disabled! Failed to send {audioClip}!");
return;
}
if ((Object)(object)audioClip == (Object)null)
{
Instance.logger.LogWarning((object)$"audioClip variable of SendAudioClip not assigned! Failed to send {audioClip}!");
return;
}
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!");
return;
}
string name = audioClip.GetName();
if (clipTypes.ContainsKey(name))
{
if (clipTypes[name] == AudioType.ogg)
{
NetworkHandler.Instance.SendAudioClipServerRpc(name, OggUtility.AudioClipToByteArray(audioClip, out var _));
return;
}
if (clipTypes[name] == AudioType.mp3)
{
NetworkHandler.Instance.SendAudioClipServerRpc(name, Mp3Utility.AudioClipToByteArray(audioClip, out var _));
return;
}
}
NetworkHandler.Instance.SendAudioClipServerRpc(name, WavUtility.AudioClipToByteArray(audioClip, out var _));
}
public static void RemoveNetworkedAudioClip(AudioClip audioClip)
{
RemoveNetworkedAudioClip(audioClip.GetName());
}
public static void RemoveNetworkedAudioClip(string audioClip)
{
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 (!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 (!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);
}
}
}
}
namespace LCSoundTool.Utilities
{
public static class Mp3Utility
{
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];
int num = 32767;
for (int i = 0; i < samples.Length; i++)
{
short value = (short)(samples[i] * (float)num);
BitConverter.GetBytes(value).CopyTo(array, i * 2);
}
return array;
}
public static AudioClip ByteArrayToAudioClip(byte[] byteArray, string clipName)
{
int num = 16;
int num2 = num / 8;
AudioClip val = AudioClip.Create(clipName, byteArray.Length / num2, 1, 44100, false);
val.SetData(ConvertByteArrayToFloatArray(byteArray), 0);
return val;
}
private static float[] ConvertByteArrayToFloatArray(byte[] byteArray)
{
float[] array = new float[byteArray.Length / 2];
int num = 32767;
for (int i = 0; i < array.Length; i++)
{
short num2 = BitConverter.ToInt16(byteArray, i * 2);
array[i] = (float)num2 / (float)num;
}
return array;
}
public static AudioClip LoadFromDiskToAudioClip(string path)
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Invalid comparison between Unknown and I4
AudioClip result = null;
UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(path, (AudioType)13);
try
{
audioClip.SendWebRequest();
try
{
while (!audioClip.isDone)
{
}
if ((int)audioClip.result != 1)
{
SoundTool.Instance.logger.LogError((object)("Failed to load MP3 AudioClip from path: " + path + " Full error: " + audioClip.error));
}
else
{
result = DownloadHandlerAudioClip.GetContent(audioClip);
}
}
catch (Exception ex)
{
SoundTool.Instance.logger.LogError((object)(ex.Message + ", " + ex.StackTrace));
}
}
finally
{
((IDisposable)audioClip)?.Dispose();
}
return result;
}
}
public static class OggUtility
{
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];
int num = 32767;
for (int i = 0; i < samples.Length; i++)
{
short value = (short)(samples[i] * (float)num);
BitConverter.GetBytes(value).CopyTo(array, i * 2);
}
return array;
}
public static AudioClip ByteArrayToAudioClip(byte[] byteArray, string clipName)
{
int num = 16;
int num2 = num / 8;
AudioClip val = AudioClip.Create(clipName, byteArray.Length / num2, 1, 44100, false);
val.SetData(ConvertByteArrayToFloatArray(byteArray), 0);
return val;
}
private static float[] ConvertByteArrayToFloatArray(byte[] byteArray)
{
float[] array = new float[byteArray.Length / 2];
int num = 32767;
for (int i = 0; i < array.Length; i++)
{
short num2 = BitConverter.ToInt16(byteArray, i * 2);
array[i] = (float)num2 / (float)num;
}
return array;
}
public static AudioClip LoadFromDiskToAudioClip(string path)
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Invalid comparison between Unknown and I4
AudioClip result = null;
UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(path, (AudioType)14);
try
{
audioClip.SendWebRequest();
try
{
while (!audioClip.isDone)
{
}
if ((int)audioClip.result != 1)
{
SoundTool.Instance.logger.LogError((object)("Failed to load OGGVORBIS AudioClip from path: " + path + " Full error: " + audioClip.error));
}
else
{
result = DownloadHandlerAudioClip.GetContent(audioClip);
}
}
catch (Exception ex)
{
SoundTool.Instance.logger.LogError((object)(ex.Message + ", " + ex.StackTrace));
}
}
finally
{
((IDisposable)audioClip)?.Dispose();
}
return result;
}
}
public static class WavUtility
{
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];
int num = 32767;
for (int i = 0; i < samples.Length; i++)
{
short value = (short)(samples[i] * (float)num);
BitConverter.GetBytes(value).CopyTo(array, i * 2);
}
return array;
}
public static AudioClip ByteArrayToAudioClip(byte[] byteArray, string clipName)
{
int num = 16;
int num2 = num / 8;
AudioClip val = AudioClip.Create(clipName, byteArray.Length / num2, 1, 44100, false);
val.SetData(ConvertByteArrayToFloatArray(byteArray), 0);
return val;
}
private static float[] ConvertByteArrayToFloatArray(byte[] byteArray)
{
float[] array = new float[byteArray.Length / 2];
int num = 32767;
for (int i = 0; i < array.Length; i++)
{
short num2 = BitConverter.ToInt16(byteArray, i * 2);
array[i] = (float)num2 / (float)num;
}
return array;
}
public static AudioClip LoadFromDiskToAudioClip(string path)
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Invalid comparison between Unknown and I4
AudioClip result = null;
UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(path, (AudioType)20);
try
{
audioClip.SendWebRequest();
try
{
while (!audioClip.isDone)
{
}
if ((int)audioClip.result != 1)
{
SoundTool.Instance.logger.LogError((object)("Failed to load WAV AudioClip from path: " + path + " Full error: " + audioClip.error));
}
else
{
result = DownloadHandlerAudioClip.GetContent(audioClip);
}
}
catch (Exception ex)
{
SoundTool.Instance.logger.LogError((object)(ex.Message + ", " + ex.StackTrace));
}
}
finally
{
((IDisposable)audioClip)?.Dispose();
}
return result;
}
}
}
namespace LCSoundTool.Patches
{
[HarmonyPatch(typeof(AudioSource))]
internal class AudioSourcePatch
{
private static Dictionary<string, AudioClip> originalClips = new Dictionary<string, AudioClip>();
[HarmonyPatch("Play", new Type[] { })]
[HarmonyPrefix]
public static void Play_Patch(AudioSource __instance)
{
RunDynamicClipReplacement(__instance);
DebugPlayMethod(__instance);
}
[HarmonyPatch("Play", new Type[] { typeof(ulong) })]
[HarmonyPrefix]
public static void Play_UlongPatch(AudioSource __instance)
{
RunDynamicClipReplacement(__instance);
DebugPlayMethod(__instance);
}
[HarmonyPatch("Play", new Type[] { typeof(double) })]
[HarmonyPrefix]
public static void Play_DoublePatch(AudioSource __instance)
{
RunDynamicClipReplacement(__instance);
DebugPlayMethod(__instance);
}
[HarmonyPatch("PlayDelayed", new Type[] { typeof(float) })]
[HarmonyPrefix]
public static void PlayDelayed_Patch(AudioSource __instance)
{
RunDynamicClipReplacement(__instance);
DebugPlayDelayedMethod(__instance);
}
[HarmonyPatch("PlayClipAtPoint", new Type[]
{
typeof(AudioClip),
typeof(Vector3),
typeof(float)
})]
[HarmonyPrefix]
public static bool PlayClipAtPoint_Patch(AudioClip clip, Vector3 position, float volume)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("One shot audio");
val.transform.position = position;
AudioSource val2 = val.AddComponent<AudioSource>();
val2.clip = clip;
val2.spatialBlend = 1f;
val2.volume = volume;
RunDynamicClipReplacement(val2);
val2.Play();
DebugPlayClipAtPointMethod(val2, position);
Object.Destroy((Object)(object)val, clip.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);
DebugPlayOneShotMethod(source, clip);
}
private static void DebugPlayMethod(AudioSource instance)
{
if ((Object)(object)instance == (Object)null)
{
return;
}
if (SoundTool.debugAudioSources && !SoundTool.indepthDebugging && (Object)(object)instance != (Object)null)
{
SoundTool.Instance.logger.LogDebug((object)$"{instance} at {((Component)instance).transform.root} is playing {((Object)instance.clip).name}");
}
else if (SoundTool.indepthDebugging && (Object)(object)instance != (Object)null)
{
SoundTool.Instance.logger.LogDebug((object)$"{instance} is playing {((Object)instance.clip).name} at");
Transform val = ((Component)instance).transform;
while ((Object)(object)val.parent != (Object)null || (Object)(object)val != (Object)(object)((Component)instance).transform.root)
{
SoundTool.Instance.logger.LogDebug((object)$"--- {val.parent}");
val = val.parent;
}
if ((Object)(object)val == (Object)(object)((Component)instance).transform.root)
{
SoundTool.Instance.logger.LogDebug((object)$"--- {((Component)instance).transform.root}");
}
}
}
private static void DebugPlayDelayedMethod(AudioSource instance)
{
if ((Object)(object)instance == (Object)null)
{
return;
}
if (SoundTool.debugAudioSources && !SoundTool.indepthDebugging && (Object)(object)instance != (Object)null)
{
SoundTool.Instance.logger.LogDebug((object)$"{instance} at {((Component)instance).transform.root} is playing {((Object)instance.clip).name} with delay");
}
else if (SoundTool.indepthDebugging && (Object)(object)instance != (Object)null)
{
SoundTool.Instance.logger.LogDebug((object)$"{instance} is playing {((Object)instance.clip).name} with delay at");
Transform val = ((Component)instance).transform;
while ((Object)(object)val.parent != (Object)null || (Object)(object)val != (Object)(object)((Component)instance).transform.root)
{
SoundTool.Instance.logger.LogDebug((object)$"--- {val.parent}");
val = val.parent;
}
if ((Object)(object)val == (Object)(object)((Component)instance).transform.root)
{
SoundTool.Instance.logger.LogDebug((object)$"--- {((Component)instance).transform.root}");
}
}
}
private static void DebugPlayClipAtPointMethod(AudioSource audioSource, Vector3 position)
{
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)audioSource == (Object)null)
{
return;
}
if (SoundTool.debugAudioSources && !SoundTool.indepthDebugging && (Object)(object)audioSource != (Object)null)
{
SoundTool.Instance.logger.LogDebug((object)$"{audioSource} at {((Component)audioSource).transform.root} is playing {((Object)audioSource.clip).name} at point {position}");
}
else if (SoundTool.indepthDebugging && (Object)(object)audioSource != (Object)null)
{
SoundTool.Instance.logger.LogDebug((object)$"{audioSource} is playing {((Object)audioSource.clip).name} located at point {position} within ");
Transform val = ((Component)audioSource).transform;
while ((Object)(object)val.parent != (Object)null || (Object)(object)val != (Object)(object)((Component)audioSource).transform.root)
{
SoundTool.Instance.logger.LogDebug((object)$"--- {val.parent}");
val = val.parent;
}
if ((Object)(object)val == (Object)(object)((Component)audioSource).transform.root)
{
SoundTool.Instance.logger.LogDebug((object)$"--- {((Component)audioSource).transform.root}");
}
}
}
private static void DebugPlayOneShotMethod(AudioSource source, AudioClip clip)
{
if ((Object)(object)source == (Object)null || (Object)(object)clip == (Object)null)
{
return;
}
if (SoundTool.debugAudioSources && !SoundTool.indepthDebugging && (Object)(object)source != (Object)null)
{
SoundTool.Instance.logger.LogDebug((object)$"{source} at {((Component)source).transform.root} is playing one shot {((Object)clip).name}");
}
else if (SoundTool.indepthDebugging && (Object)(object)source != (Object)null)
{
SoundTool.Instance.logger.LogDebug((object)$"{source} is playing one shot {((Object)clip).name} at");
Transform val = ((Component)source).transform;
while ((Object)(object)val.parent != (Object)null || (Object)(object)val != (Object)(object)((Component)source).transform.root)
{
SoundTool.Instance.logger.LogDebug((object)$"--- {val.parent}");
val = val.parent;
}
if ((Object)(object)val == (Object)(object)((Component)source).transform.root)
{
SoundTool.Instance.logger.LogDebug((object)$"--- {((Component)source).transform.root}");
}
}
}
private static void RunDynamicClipReplacement(AudioSource instance)
{
if ((Object)(object)instance == (Object)null || (Object)(object)instance.clip == (Object)null)
{
return;
}
string name = instance.clip.GetName();
if (SoundTool.replacedClips.ContainsKey(name))
{
if (!originalClips.ContainsKey(name))
{
originalClips.Add(name, instance.clip);
}
List<RandomAudioClip> list = SoundTool.replacedClips[name];
float num = 0f;
foreach (RandomAudioClip item in list)
{
num += item.chance;
}
float num2 = Random.Range(0f, num);
{
foreach (RandomAudioClip item2 in list)
{
if (num2 <= item2.chance)
{
instance.clip = item2.clip;
break;
}
num2 -= item2.chance;
}
return;
}
}
if (originalClips.ContainsKey(name))
{
instance.clip = originalClips[name];
originalClips.Remove(name);
}
}
private static AudioClip ReplaceClipWithNew(AudioClip original)
{
if ((Object)(object)original == (Object)null)
{
return original;
}
string name = original.GetName();
if (SoundTool.replacedClips.ContainsKey(name))
{
if (!originalClips.ContainsKey(name))
{
originalClips.Add(name, original);
}
List<RandomAudioClip> list = SoundTool.replacedClips[name];
float num = 0f;
foreach (RandomAudioClip item in list)
{
num += item.chance;
}
float num2 = Random.Range(0f, num);
foreach (RandomAudioClip item2 in list)
{
if (num2 <= item2.chance)
{
return item2.clip;
}
num2 -= item2.chance;
}
}
else if (originalClips.ContainsKey(name))
{
AudioClip result = originalClips[name];
originalClips.Remove(name);
return result;
}
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_003a: 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)
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)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_011f: 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_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_0105: 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 != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2736638642u, val, (RpcDelivery)0);
bool flag = clipName != null;
((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
if (flag)
{
((FastBufferWriter)(ref val2)).WriteValueSafe(clipName, false);
}
bool flag2 = audioData != null;
((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag2, default(ForPrimitives));
if (flag2)
{
((FastBufferWriter)(ref val2)).WriteValueSafe<byte>(audioData, default(ForPrimitives));
}
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2736638642u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage != 2 || (!networkManager.IsClient && !networkManager.IsHost))
{
return;
}
if (!networkedAudioClips.ContainsKey(clipName))
{
AudioClip val3 = null;
if (SoundTool.clipTypes.ContainsKey(clipName))
{
if (SoundTool.clipTypes[clipName] == SoundTool.AudioType.ogg)
{
val3 = OggUtility.ByteArrayToAudioClip(audioData, clipName);
}
else if (SoundTool.clipTypes[clipName] == SoundTool.AudioType.mp3)
{
val3 = Mp3Utility.ByteArrayToAudioClip(audioData, clipName);
}
}
if ((Object)(object)val3 == (Object)null)
{
val3 = WavUtility.ByteArrayToAudioClip(audioData, clipName);
}
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_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 != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1355469546u, val, (RpcDelivery)0);
bool flag = clipName != null;
((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
if (flag)
{
((FastBufferWriter)(ref val2)).WriteValueSafe(clipName, false);
}
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1355469546u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && networkedAudioClips.ContainsKey(clipName))
{
networkedAudioClips.Remove(clipName);
NetworkHandler.ClientNetworkedAudioChanged?.Invoke();
}
}
[ClientRpc]
public void SyncAudioClipsClientRpc(Strings clipNames)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: 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_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: 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 != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3300200130u, val, (RpcDelivery)0);
((FastBufferWriter)(ref val2)).WriteValueSafe<Strings>(ref clipNames, default(ForNetworkSerializable));
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3300200130u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage != 2 || (!networkManager.IsClient && !networkManager.IsHost))
{
return;
}
string[] myStrings = clipNames.MyStrings;
for (int i = 0; i < myStrings.Length; i++)
{
if (!networkedAudioClips.ContainsKey(myStrings[i]))
{
SendExistingAudioClipServerRpc(myStrings[i]);
}
}
}
[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)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1556253924u, val, (RpcDelivery)0);
BytePacker.WriteValueBitPacked(val2, seed);
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1556253924u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
{
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)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_011f: 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_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_0105: 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 val = default(ServerRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(867452943u, val, (RpcDelivery)0);
bool flag = clipName != null;
((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
if (flag)
{
((FastBufferWriter)(ref val2)).WriteValueSafe(clipName, false);
}
bool flag2 = audioData != null;
((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag2, default(ForPrimitives));
if (flag2)
{
((FastBufferWriter)(ref val2)).WriteValueSafe<byte>(audioData, default(ForPrimitives));
}
((NetworkBehaviour)this).__endSendServerRpc(ref val2, 867452943u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
{
ReceiveAudioClipClientRpc(clipName, audioData);
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_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 val = default(ServerRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(3103497155u, val, (RpcDelivery)0);
bool flag = clipName != null;
((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
if (flag)
{
((FastBufferWriter)(ref val2)).WriteValueSafe(clipName, false);
}
((NetworkBehaviour)this).__endSendServerRpc(ref val2, 3103497155u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
{
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)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager == null || !networkManager.IsListening)
{
return;
}
if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
{
ServerRpcParams val = default(ServerRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(178607916u, val, (RpcDelivery)0);
((NetworkBehaviour)this).__endSendServerRpc(ref val2, 178607916u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
{
Strings clipNames = new Strings(networkedAudioClips.Keys.ToArray());
if (clipNames.MyStrings.Length < 1)
{
SoundTool.Instance.logger.LogDebug((object)"No sounds found in networkedClips. Syncing process cancelled!");
}
else
{
SyncAudioClipsClientRpc(clipNames);
}
}
}
[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_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 val = default(ServerRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(4006259189u, val, (RpcDelivery)0);
bool flag = clipName != null;
((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
if (flag)
{
((FastBufferWriter)(ref val2)).WriteValueSafe(clipName, false);
}
((NetworkBehaviour)this).__endSendServerRpc(ref val2, 4006259189u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage != 1 || (!networkManager.IsServer && !networkManager.IsHost))
{
return;
}
if (networkedAudioClips.ContainsKey(clipName))
{
byte[] array = null;
if (SoundTool.clipTypes.ContainsKey(clipName))
{
if (SoundTool.clipTypes[clipName] == SoundTool.AudioType.ogg)
{
array = OggUtility.AudioClipToByteArray(networkedAudioClips[clipName], out var _);
}
else if (SoundTool.clipTypes[clipName] == SoundTool.AudioType.mp3)
{
array = Mp3Utility.AudioClipToByteArray(networkedAudioClips[clipName], out var _);
}
}
if (array == null)
{
array = WavUtility.AudioClipToByteArray(networkedAudioClips[clipName], out var _);
}
ReceiveAudioClipClientRpc(clipName, array);
}
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)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
{
ServerRpcParams val = default(ServerRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(4286510828u, val, (RpcDelivery)0);
BytePacker.WriteValueBitPacked(val2, seed);
((NetworkBehaviour)this).__endSendServerRpc(ref val2, 4286510828u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost) && ((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();
}
[RuntimeInitializeOnLoadMethod]
internal static void InitializeRPCS_NetworkHandler()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Expected O, but got Unknown
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Expected O, but got Unknown
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Expected O, but got Unknown
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Expected O, but got Unknown
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Expected O, but got Unknown
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Expected O, but got Unknown
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Expected O, but got Unknown
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Expected O, but got Unknown
NetworkManager.__rpc_func_table.Add(2736638642u, new RpcReceiveHandler(__rpc_handler_2736638642));
NetworkManager.__rpc_func_table.Add(1355469546u, new RpcReceiveHandler(__rpc_handler_1355469546));
NetworkManager.__rpc_func_table.Add(3300200130u, new RpcReceiveHandler(__rpc_handler_3300200130));
NetworkManager.__rpc_func_table.Add(1556253924u, new RpcReceiveHandler(__rpc_handler_1556253924));
NetworkManager.__rpc_func_table.Add(867452943u, new RpcReceiveHandler(__rpc_handler_867452943));
NetworkManager.__rpc_func_table.Add(3103497155u, new RpcReceiveHandler(__rpc_handler_3103497155));
NetworkManager.__rpc_func_table.Add(178607916u, new RpcReceiveHandler(__rpc_handler_178607916));
NetworkManager.__rpc_func_table.Add(4006259189u, new RpcReceiveHandler(__rpc_handler_4006259189));
NetworkManager.__rpc_func_table.Add(4286510828u, new RpcReceiveHandler(__rpc_handler_4286510828));
}
private static void __rpc_handler_2736638642(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_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_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));
}
target.__rpc_exec_stage = (__RpcExecStage)2;
((NetworkHandler)(object)target).ReceiveAudioClipClientRpc(clipName, audioData);
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)2;
((NetworkHandler)(object)target).RemoveAudioClipClientRpc(clipName);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_3300200130(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_0044: 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)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
Strings clipNames = default(Strings);
((FastBufferReader)(ref reader)).ReadValueSafe<Strings>(ref clipNames, default(ForNetworkSerializable));
target.__rpc_exec_stage = (__RpcExecStage)2;
((NetworkHandler)(object)target).SyncAudioClipsClientRpc(clipNames);
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)2;
((NetworkHandler)(object)target).ReceiveSeedClientRpc(seed);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_867452943(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_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_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));
}
target.__rpc_exec_stage = (__RpcExecStage)1;
((NetworkHandler)(object)target).SendAudioClipServerRpc(clipName, audioData);
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_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: 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);
}
}
}
}
}
namespace LCSoundTool.Resources
{
public static class Assets
{
internal static AssetBundle bundle;
}
}