using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using BoomboxMod.NetcodePatcher;
using GameNetcodeStuff;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Networking;
[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("BoomboxMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BoomboxMod")]
[assembly: AssemblyTitle("BoomboxMod")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: NetcodePatchedAssembly]
internal class <Module>
{
static <Module>()
{
}
}
namespace BoomboxMod
{
public class AudioEnhancement : MonoBehaviour
{
public static void ApplyAudioEnhancements()
{
BoomboxItem val = Object.FindObjectOfType<BoomboxItem>();
if ((Object)(object)val == (Object)null || (Object)(object)val.boomboxAudio == (Object)null)
{
Debug.LogError((object)"[ApplyAudioEnhancements] No BoomboxItem or AudioSource found!");
return;
}
AudioSource boomboxAudio = val.boomboxAudio;
AudioLowPassFilter val2 = ((Component)val).gameObject.GetComponent<AudioLowPassFilter>();
if ((Object)(object)val2 == (Object)null)
{
val2 = ((Component)val).gameObject.AddComponent<AudioLowPassFilter>();
}
val2.cutoffFrequency = 200f;
val2.lowpassResonanceQ = 1f;
boomboxAudio.volume = Mathf.Clamp(BoomboxMod.volumeClient * 2.2f, 0f, 2.2f);
boomboxAudio.spatialBlend = 1f;
boomboxAudio.dopplerLevel = 0f;
boomboxAudio.minDistance = 3f;
boomboxAudio.maxDistance = 25f;
boomboxAudio.spread = 180f;
boomboxAudio.rolloffMode = (AudioRolloffMode)1;
boomboxAudio.SetCustomCurve((AudioSourceCurveType)0, CreateFadeOutCurve());
boomboxAudio.bypassEffects = false;
boomboxAudio.bypassListenerEffects = false;
boomboxAudio.bypassReverbZones = false;
}
private static AnimationCurve CreateFadeOutCurve()
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Expected O, but got Unknown
Keyframe[] array = (Keyframe[])(object)new Keyframe[3]
{
new Keyframe(5f, 1f),
new Keyframe(35f, 0.6f),
new Keyframe(50f, 0f)
};
return new AnimationCurve(array);
}
}
[HarmonyPatch(typeof(GrabbableObject))]
internal class BoomboxDropPatch
{
[HarmonyPrefix]
[HarmonyPatch("DiscardItem")]
private static void Prefix(GrabbableObject __instance)
{
BoomboxItem val = (BoomboxItem)(object)((__instance is BoomboxItem) ? __instance : null);
if (val != null)
{
AudioSource boomboxAudio = val.boomboxAudio;
if (!((Object)(object)boomboxAudio == (Object)null) && !boomboxAudio.isPlaying)
{
boomboxAudio.Stop();
BoomNetworkManager.instance.StopDroppedBoomboxServerRpc();
}
}
}
}
[HarmonyPatch(typeof(BoomboxItem))]
internal class BoomboxPatch
{
public static string[] musicFiles;
private static string musicDirectory;
public static int trackIndex = 0;
private static ManualLogSource logger = Logger.CreateLogSource("BoomboxPatch");
[HarmonyPrefix]
[HarmonyPatch("ItemActivate")]
private static bool ItemActivatePatch(BoomboxItem __instance, bool used, bool buttonDown)
{
if (!buttonDown)
{
return true;
}
((GrabbableObject)__instance).itemProperties.batteryUsage = 1E+09f;
AudioSource boomboxAudio = __instance.boomboxAudio;
if ((Object)(object)boomboxAudio == (Object)null)
{
logger.LogError((object)"BoomboxItem has no AudioSource! Check if an AudioSource is attached.");
return true;
}
if (boomboxAudio.isPlaying)
{
boomboxAudio.Pause();
return false;
}
if ((Object)(object)boomboxAudio.clip == (Object)null)
{
((MonoBehaviour)__instance).StartCoroutine(PlayNextTrack(boomboxAudio, trackIndex));
}
else
{
boomboxAudio.Play();
}
return false;
}
public static IEnumerator PlayNextTrack(AudioSource audioSource, int trackIndex)
{
if (musicFiles == null || musicFiles.Length == 0)
{
InitializeMusicDirectory();
}
if (musicFiles.Length == 0)
{
logger.LogError((object)"No files found! Please add songs to the BoomboxMusic directory.");
yield break;
}
if ((Object)(object)audioSource == (Object)null)
{
logger.LogError((object)"No files! Please add songs to the BoomboxMusic directory.");
yield break;
}
string filePath = "file://" + musicFiles[trackIndex];
if (!File.Exists(musicFiles[trackIndex]))
{
yield break;
}
AudioType audioType = (AudioType)13;
if (musicFiles[trackIndex].EndsWith(".ogg", StringComparison.OrdinalIgnoreCase))
{
audioType = (AudioType)14;
}
UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(filePath, audioType);
((DownloadHandlerAudioClip)www.downloadHandler).streamAudio = true;
yield return www.SendWebRequest();
if ((int)www.result != 1)
{
Debug.LogError((object)("Failed to load track: " + www.error));
yield break;
}
AudioClip clip = DownloadHandlerAudioClip.GetContent(www);
if (!((Object)(object)clip == (Object)null))
{
audioSource.spatialize = false;
audioSource.spatializePostEffects = false;
audioSource.clip = clip;
audioSource.volume = BoomboxMod.volumeClient;
AudioEnhancement.ApplyAudioEnhancements();
yield return (object)new WaitForSeconds(0.5f);
BoomNetworkManager.instance.ClientReadyServerRpc(NetworkManager.Singleton.LocalClientId);
}
}
private static void InitializeMusicDirectory()
{
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
musicDirectory = Path.Combine(directoryName, "BoomboxMusic");
if (!Directory.Exists(musicDirectory))
{
logger.LogWarning((object)("Music directory does not exist. Creating at: " + musicDirectory));
Directory.CreateDirectory(musicDirectory);
}
musicFiles = (from file in Directory.GetFiles(musicDirectory, "*.*", SearchOption.TopDirectoryOnly)
where file.EndsWith(".mp3", StringComparison.OrdinalIgnoreCase) || file.EndsWith(".ogg", StringComparison.OrdinalIgnoreCase)
select file).ToArray();
}
}
[BepInPlugin("BoomboxMod", "BoomboxMod", "1.0.5")]
public class BoomboxMod : BaseUnityPlugin
{
private const string ModGUID = "BoomboxMod";
private const string ModName = "BoomboxMod";
private const string ModVersion = "1.0.5";
public readonly Harmony harmony = new Harmony("BoomboxMod");
public static BoomboxMod instance;
private InputAction nextTrackAction;
public GameObject netManagerPrefab;
public GameObject landmineAudioPrefab;
public ManualLogSource logger;
public static float volumeClient = 1f;
private InputAction volumeUpAction;
private InputAction volumeDownAction;
private void Awake()
{
//IL_017d: Unknown result type (might be due to invalid IL or missing references)
//IL_0187: Expected O, but got Unknown
//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
//IL_01c4: Expected O, but got Unknown
//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
//IL_0201: Expected O, but got Unknown
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);
}
}
}
if ((Object)(object)instance == (Object)null)
{
instance = this;
Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
}
else
{
Debug.LogError((object)"[BoomboxMod] Duplicate instance detected! Destroying new instance.");
Object.Destroy((Object)(object)((Component)this).gameObject);
}
logger = ((BaseUnityPlugin)this).Logger;
logger.LogInfo((object)"BoomboxMod initialized!");
string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "boomasset");
AssetBundle val = AssetBundle.LoadFromFile(text);
if ((Object)(object)val == (Object)null)
{
logger.LogError((object)"Failed to load custom assets. Ensure 'boomasset' is with the .dll file");
return;
}
netManagerPrefab = val.LoadAsset<GameObject>("assets/boomnetworkmanager.prefab");
netManagerPrefab.AddComponent<BoomNetworkManager>();
landmineAudioPrefab = val.LoadAsset<GameObject>("assets/landminestop.prefab");
harmony.PatchAll();
logger.LogInfo((object)"BoomboxMod patched and networked successfully.");
nextTrackAction = new InputAction("NextTrack", (InputActionType)0, "<Keyboard>/rightArrow", (string)null, (string)null, (string)null);
nextTrackAction.performed += delegate
{
SkipTrack();
};
nextTrackAction.Enable();
volumeUpAction = new InputAction("VolumeUp", (InputActionType)1, "<Keyboard>/upArrow", (string)null, (string)null, (string)null);
volumeUpAction.performed += delegate
{
VolumeUp();
};
volumeUpAction.Enable();
volumeDownAction = new InputAction("VolumeDown", (InputActionType)1, "<Keyboard>/downArrow", (string)null, (string)null, (string)null);
volumeDownAction.performed += delegate
{
VolumeDown();
};
volumeDownAction.Enable();
}
private void VolumeUp()
{
volumeClient = Mathf.Clamp(volumeClient + 0.1f, 0f, 1f);
volumeClient = Mathf.Round(volumeClient * 10f) / 10f;
ApplyVolumeChange();
}
private void VolumeDown()
{
volumeClient = Mathf.Clamp(volumeClient - 0.1f, 0f, 1f);
volumeClient = Mathf.Round(volumeClient * 10f) / 10f;
ApplyVolumeChange();
}
private void ApplyVolumeChange()
{
BoomboxItem val = Object.FindObjectOfType<BoomboxItem>();
if (!((Object)(object)val == (Object)null) && !((Object)(object)val.boomboxAudio == (Object)null))
{
val.boomboxAudio.volume = volumeClient;
logger.LogInfo((object)("Volume: " + volumeClient.ToString("0.0")));
}
}
private void SkipTrack()
{
BoomboxItem[] array = Object.FindObjectsOfType<BoomboxItem>();
if (array.Length == 0)
{
return;
}
PlayerControllerB[] array2 = Object.FindObjectsOfType<PlayerControllerB>();
PlayerControllerB val = null;
BoomboxItem val2 = null;
BoomboxItem[] array3 = array;
foreach (BoomboxItem val3 in array3)
{
GrabbableObject componentInParent = ((Component)val3).GetComponentInParent<GrabbableObject>();
if ((Object)(object)componentInParent == (Object)null || (Object)(object)componentInParent.playerHeldBy == (Object)null)
{
logger.LogInfo((object)"You must be holding the Boombox to skip tracks!");
continue;
}
PlayerControllerB[] array4 = array2;
foreach (PlayerControllerB val4 in array4)
{
if ((Object)(object)componentInParent.playerHeldBy == (Object)(object)val4)
{
val = val4;
val2 = val3;
break;
}
}
}
if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
{
return;
}
if (((NetworkBehaviour)val).OwnerClientId != NetworkManager.Singleton.LocalClientId)
{
logger.LogInfo((object)"You must be holding the Boombox to skip tracks!");
return;
}
if (BoomboxPatch.musicFiles == null || BoomboxPatch.musicFiles.Length == 0)
{
logger.LogError((object)"No music files available! Cannot skip track. Press play maybe.");
return;
}
int num = (BoomboxPatch.trackIndex + 1) % BoomboxPatch.musicFiles.Length;
AudioSource boomboxAudio = val2.boomboxAudio;
if ((Object)(object)BoomNetworkManager.instance != (Object)null)
{
BoomNetworkManager.instance.SkipTrackServerRpc(num);
}
else
{
((MonoBehaviour)val2).StartCoroutine(BoomboxPatch.PlayNextTrack(boomboxAudio, num));
}
}
public void Unload()
{
if (harmony != null)
{
harmony.UnpatchSelf();
}
BoomboxPatch.musicFiles = null;
}
}
public class BoomNetworkManager : NetworkBehaviour
{
public static BoomNetworkManager instance;
private HashSet<ulong> readyClients = new HashSet<ulong>();
private AudioClip preloadedClip = null;
private int preloadedTrackIndex = -1;
private bool isPreloading = false;
private float lastSkipTime = 0f;
private float skipCooldown = 2f;
private void Awake()
{
instance = this;
}
[ServerRpc(RequireOwnership = false)]
public void StopDroppedBoomboxServerRpc()
{
//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)
{
if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
{
ServerRpcParams val = default(ServerRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2408351092u, val, (RpcDelivery)0);
((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2408351092u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
{
StopDroppedBoomboxClientRpc();
}
}
}
[ClientRpc]
public void StopDroppedBoomboxClientRpc()
{
//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 != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(121205134u, val, (RpcDelivery)0);
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 121205134u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
{
BoomboxItem val3 = Object.FindObjectOfType<BoomboxItem>();
if ((Object)(object)val3 != (Object)null && (Object)(object)val3.boomboxAudio != (Object)null)
{
val3.boomboxAudio.Stop();
}
}
}
[ServerRpc(RequireOwnership = false)]
public void SkipTrackServerRpc(int newTrackIndex)
{
//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)
{
return;
}
if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
{
ServerRpcParams val = default(ServerRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(4080895232u, val, (RpcDelivery)0);
BytePacker.WriteValueBitPacked(val2, newTrackIndex);
((NetworkBehaviour)this).__endSendServerRpc(ref val2, 4080895232u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage != 1 || (!networkManager.IsServer && !networkManager.IsHost))
{
return;
}
float time = Time.time;
if (time - lastSkipTime < skipCooldown)
{
Debug.LogWarning((object)"[BoomboxMod] Track skipping too fast! Ignoring request.");
return;
}
lastSkipTime = time;
BoomboxPatch.trackIndex = newTrackIndex;
readyClients.Clear();
BoomboxItem val3 = Object.FindObjectOfType<BoomboxItem>();
if ((Object)(object)val3 != (Object)null && (Object)(object)val3.boomboxAudio != (Object)null)
{
val3.boomboxAudio.Stop();
}
SkipTrackClientRpc(newTrackIndex);
}
[ServerRpc(RequireOwnership = false)]
public void ClientReadyServerRpc(ulong clientId)
{
//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)
{
return;
}
if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
{
ServerRpcParams val = default(ServerRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1705947175u, val, (RpcDelivery)0);
BytePacker.WriteValueBitPacked(val2, clientId);
((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1705947175u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
{
readyClients.Add(clientId);
if (readyClients.Count >= NetworkManager.Singleton.ConnectedClientsList.Count)
{
PlayTrackClientRpc();
}
}
}
[ClientRpc]
public void PlayTrackClientRpc()
{
//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 != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3685604824u, val, (RpcDelivery)0);
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3685604824u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
{
BoomboxItem val3 = Object.FindObjectOfType<BoomboxItem>();
if ((Object)(object)val3 == (Object)null || (Object)(object)val3.boomboxAudio == (Object)null || (Object)(object)val3.boomboxAudio.clip == (Object)null)
{
Debug.LogError((object)"[PlayTrack] No valid audio source or clip found!");
}
else
{
val3.boomboxAudio.Play();
}
}
}
[ClientRpc]
public void SkipTrackClientRpc(int newTrackIndex)
{
//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)
{
return;
}
if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1801367408u, val, (RpcDelivery)0);
BytePacker.WriteValueBitPacked(val2, newTrackIndex);
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1801367408u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage != 2 || (!networkManager.IsClient && !networkManager.IsHost))
{
return;
}
if (BoomboxPatch.musicFiles == null || BoomboxPatch.musicFiles.Length == 0)
{
Debug.LogError((object)"[SkipTrack] No music files available! Cannot skip track.");
return;
}
BoomboxPatch.trackIndex = newTrackIndex;
BoomboxMod.instance.logger.LogInfo((object)"Skipping track!");
BoomboxItem val3 = Object.FindObjectOfType<BoomboxItem>();
if (!((Object)(object)val3 == (Object)null) && !((Object)(object)val3.boomboxAudio == (Object)null))
{
AudioSource boomboxAudio = val3.boomboxAudio;
if ((Object)(object)preloadedClip != (Object)null && preloadedTrackIndex == newTrackIndex)
{
boomboxAudio.clip = preloadedClip;
boomboxAudio.volume = BoomboxMod.volumeClient;
AudioEnhancement.ApplyAudioEnhancements();
ClientReadyServerRpc(NetworkManager.Singleton.LocalClientId);
preloadedClip = null;
}
else
{
((MonoBehaviour)val3).StartCoroutine(LoadTrack(boomboxAudio, newTrackIndex));
}
int trackIndex = (newTrackIndex + 1) % BoomboxPatch.musicFiles.Length;
StartPreloadTrack(trackIndex);
}
}
private IEnumerator LoadTrack(AudioSource audioSource, int trackIndex)
{
string filePath = "file://" + BoomboxPatch.musicFiles[trackIndex];
if (!File.Exists(BoomboxPatch.musicFiles[trackIndex]))
{
yield break;
}
AudioType audioType = (AudioType)13;
if (BoomboxPatch.musicFiles[trackIndex].EndsWith(".ogg", StringComparison.OrdinalIgnoreCase))
{
audioType = (AudioType)14;
}
UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(filePath, audioType);
((DownloadHandlerAudioClip)www.downloadHandler).streamAudio = true;
yield return www.SendWebRequest();
if ((int)www.result != 1)
{
Debug.LogError((object)("[BoomboxMod] Failed to load audio clip: " + www.error));
yield break;
}
AudioClip clip = DownloadHandlerAudioClip.GetContent(www);
if (!((Object)(object)clip == (Object)null))
{
audioSource.clip = clip;
audioSource.volume = BoomboxMod.volumeClient;
AudioEnhancement.ApplyAudioEnhancements();
ClientReadyServerRpc(NetworkManager.Singleton.LocalClientId);
}
}
private void StartPreloadTrack(int trackIndex)
{
if (!isPreloading)
{
((MonoBehaviour)this).StartCoroutine(PreloadTrack(trackIndex));
}
}
private IEnumerator PreloadTrack(int trackIndex)
{
isPreloading = true;
string filePath = "file://" + BoomboxPatch.musicFiles[trackIndex];
if (!File.Exists(BoomboxPatch.musicFiles[trackIndex]))
{
isPreloading = false;
yield break;
}
AudioType audioType = (AudioType)13;
if (BoomboxPatch.musicFiles[trackIndex].EndsWith(".ogg", StringComparison.OrdinalIgnoreCase))
{
audioType = (AudioType)14;
}
UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(filePath, audioType);
((DownloadHandlerAudioClip)www.downloadHandler).streamAudio = true;
www.SendWebRequest();
while (!www.isDone)
{
yield return null;
}
if ((int)www.result != 1)
{
Debug.LogError((object)("[PreloadTrack] Failed to load audio clip: " + www.error));
isPreloading = false;
yield break;
}
AudioClip clip = DownloadHandlerAudioClip.GetContent(www);
if ((Object)(object)clip == (Object)null)
{
isPreloading = false;
yield break;
}
preloadedClip = clip;
preloadedTrackIndex = trackIndex;
isPreloading = false;
}
protected override void __initializeVariables()
{
((NetworkBehaviour)this).__initializeVariables();
}
[RuntimeInitializeOnLoadMethod]
internal static void InitializeRPCS_BoomNetworkManager()
{
//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
NetworkManager.__rpc_func_table.Add(2408351092u, new RpcReceiveHandler(__rpc_handler_2408351092));
NetworkManager.__rpc_func_table.Add(121205134u, new RpcReceiveHandler(__rpc_handler_121205134));
NetworkManager.__rpc_func_table.Add(4080895232u, new RpcReceiveHandler(__rpc_handler_4080895232));
NetworkManager.__rpc_func_table.Add(1705947175u, new RpcReceiveHandler(__rpc_handler_1705947175));
NetworkManager.__rpc_func_table.Add(3685604824u, new RpcReceiveHandler(__rpc_handler_3685604824));
NetworkManager.__rpc_func_table.Add(1801367408u, new RpcReceiveHandler(__rpc_handler_1801367408));
}
private static void __rpc_handler_2408351092(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;
((BoomNetworkManager)(object)target).StopDroppedBoomboxServerRpc();
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_121205134(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)2;
((BoomNetworkManager)(object)target).StopDroppedBoomboxClientRpc();
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_4080895232(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 newTrackIndex = default(int);
ByteUnpacker.ReadValueBitPacked(reader, ref newTrackIndex);
target.__rpc_exec_stage = (__RpcExecStage)1;
((BoomNetworkManager)(object)target).SkipTrackServerRpc(newTrackIndex);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_1705947175(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)
{
ulong clientId = default(ulong);
ByteUnpacker.ReadValueBitPacked(reader, ref clientId);
target.__rpc_exec_stage = (__RpcExecStage)1;
((BoomNetworkManager)(object)target).ClientReadyServerRpc(clientId);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_3685604824(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)2;
((BoomNetworkManager)(object)target).PlayTrackClientRpc();
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_1801367408(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 newTrackIndex = default(int);
ByteUnpacker.ReadValueBitPacked(reader, ref newTrackIndex);
target.__rpc_exec_stage = (__RpcExecStage)2;
((BoomNetworkManager)(object)target).SkipTrackClientRpc(newTrackIndex);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
protected internal override string __getTypeName()
{
return "BoomNetworkManager";
}
}
[HarmonyPatch(typeof(AudioSource))]
internal class DebugAudioPatch
{
[HarmonyPrefix]
[HarmonyPatch("Play", new Type[] { })]
private static bool RedirectLandmineAudio(AudioSource __instance)
{
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
if (((Object)((Component)__instance).gameObject).name.Contains("Landmine") && __instance.spatialize && string.IsNullOrEmpty(AudioSettings.GetSpatializerPluginName()))
{
GameObject landmineAudioPrefab = BoomboxMod.instance.landmineAudioPrefab;
if ((Object)(object)landmineAudioPrefab == (Object)null)
{
return true;
}
GameObject val = Object.Instantiate<GameObject>(landmineAudioPrefab, ((Component)__instance).transform.position, Quaternion.identity);
val.transform.SetParent(((Component)__instance).transform);
((Object)val).name = "LandmineAudioRedirect";
AudioSource component = val.GetComponent<AudioSource>();
component.clip = __instance.clip;
component.Play();
return false;
}
return true;
}
}
[HarmonyPatch(typeof(GameNetworkManager))]
internal class GameNetworkManagerPatcher
{
[HarmonyPostfix]
[HarmonyPatch("Start")]
private static void AddToPrefabs(ref GameNetworkManager __instance)
{
((Component)__instance).GetComponent<NetworkManager>().AddNetworkPrefab(BoomboxMod.instance.netManagerPrefab);
}
[HarmonyPostfix]
[HarmonyPatch("StartDisconnect")]
private static void DisconnectFromServer()
{
try
{
StopAllBoomboxes();
if (NetworkManager.Singleton.IsServer)
{
StartOfRoundPatcher.DestroyNetworkManager();
}
}
catch (Exception arg)
{
Debug.LogError((object)$"[BoomboxMod] Failed to clean up properly! Error: {arg}");
}
}
private static void StopAllBoomboxes()
{
BoomboxItem[] array = Object.FindObjectsOfType<BoomboxItem>();
BoomboxItem[] array2 = array;
foreach (BoomboxItem val in array2)
{
if ((Object)(object)val.boomboxAudio != (Object)null && val.boomboxAudio.isPlaying)
{
val.boomboxAudio.Stop();
}
}
}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class StartOfRoundPatcher
{
private static GameObject BoomBoxNetworkManager;
[HarmonyPostfix]
[HarmonyPatch("Start")]
public static void AwakePatch(StartOfRound __instance)
{
if (!NetworkManager.Singleton.IsServer)
{
BoomboxMod.instance.logger.LogWarning((object)"Skipping NetworkObject spawn - not the server.");
return;
}
BoomBoxNetworkManager = Object.Instantiate<GameObject>(BoomboxMod.instance.netManagerPrefab);
BoomBoxNetworkManager.GetComponent<NetworkObject>().Spawn(false);
}
public static void DestroyNetworkManager()
{
if ((Object)(object)BoomBoxNetworkManager != (Object)null)
{
Object.Destroy((Object)(object)BoomBoxNetworkManager);
BoomBoxNetworkManager = null;
}
}
}
}
namespace BoomboxMod.NetcodePatcher
{
[AttributeUsage(AttributeTargets.Module)]
internal class NetcodePatchedAssemblyAttribute : Attribute
{
}
}