Decompiled source of Jebs Counter Audio Overhaul v1.0.3

JebsCounterAudioOverhaul.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using JebsCounterAudioOverhaul.Managers;
using Unity.Netcode;
using UnityEngine;
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: AssemblyTitle("SussyDoorSounds")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SussyDoorSounds")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("99ebfe9c-75d0-432e-93da-af37a36b1d50")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace JebsCounterAudioOverhaul
{
	[BepInPlugin("com.actus.lethalcompany.jebscounteraudiooverhaul", "Jebs Counter Audio Overhaul", "1.0.3")]
	public class JebsCounterAudioOverhaulBase : BaseUnityPlugin
	{
		private const string modGUID = "com.actus.lethalcompany.jebscounteraudiooverhaul";

		private const string modName = "Jebs Counter Audio Overhaul";

		private const string modVersion = "1.0.3";

		internal static JebsCounterAudioOverhaulBase Instance;

		private readonly Harmony harmony = new Harmony("com.actus.lethalcompany.jebscounteraudiooverhaul");

		internal static List<AudioClip> SoundFX;

		internal static ManualLogSource logger;

		internal AssetBundle networkAssets;

		private static string baseFolderPath;

		private static string soundFolderPath;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			logger = Logger.CreateLogSource("com.actus.lethalcompany.jebscounteraudiooverhaul");
			baseFolderPath = ((BaseUnityPlugin)Instance).Info.Location.TrimEnd("JebsCounterAudioOverhaul.dll".ToCharArray());
			soundFolderPath = Path.Combine(baseFolderPath, "Sounds");
			if (!Directory.Exists(soundFolderPath))
			{
				logger.LogError((object)"Sounds folder missing, adding directory!");
				Directory.CreateDirectory(soundFolderPath);
			}
			else
			{
				LoadAllAudioClips();
			}
			networkAssets = AssetBundle.LoadFromFile(Path.Combine(baseFolderPath, "asset"));
			harmony.PatchAll();
		}

		private static void LoadAllAudioClips()
		{
			//IL_0066: 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)
			List<string> list = new List<string>();
			list.AddRange(Directory.GetFiles(soundFolderPath, "*.wav", SearchOption.AllDirectories));
			list.AddRange(Directory.GetFiles(soundFolderPath, "*.mp3", SearchOption.AllDirectories));
			SoundFX = new List<AudioClip>();
			foreach (string item in list)
			{
				AudioType type = (AudioType)(item.EndsWith(".mp3", StringComparison.OrdinalIgnoreCase) ? 13 : 20);
				SoundFX.Add(LoadAudioClipFromDisk(item, type));
			}
		}

		private static AudioClip LoadAudioClipFromDisk(string path, AudioType type)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Invalid comparison between Unknown and I4
			AudioClip val = null;
			UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(path, type);
			try
			{
				audioClip.SendWebRequest();
				try
				{
					while (!audioClip.isDone)
					{
					}
					if ((int)audioClip.result != 1)
					{
						logger.LogError((object)("Failed to load AudioClip from path: " + path + " Full error: " + audioClip.error));
					}
					else
					{
						val = DownloadHandlerAudioClip.GetContent(audioClip);
						if ((Object)(object)val != (Object)null)
						{
							((Object)val).name = Path.GetFileNameWithoutExtension(path);
							logger.LogInfo((object)("Loaded sound: " + ((Object)val).name));
						}
					}
				}
				catch (Exception ex)
				{
					logger.LogError((object)(ex.Message + ", " + ex.StackTrace));
				}
			}
			finally
			{
				((IDisposable)audioClip)?.Dispose();
			}
			return val;
		}
	}
}
namespace JebsCounterAudioOverhaul.Patches
{
	[HarmonyPatch(typeof(DepositItemsDesk), "OpenShutDoor")]
	internal class JebsCounterAudioOverhaulPatch
	{
		[HarmonyPostfix]
		public static void ReplaceDoorSound(bool open, ref DepositItemsDesk __instance)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			if (open)
			{
				NetworkHandler.Instance.MakeDoorSoundServerRpc(NetworkBehaviourReference.op_Implicit((NetworkBehaviour)(object)__instance));
			}
			else
			{
				NetworkHandler.Instance.EventIsOverServerRpc(__isEventOver: false);
			}
		}
	}
	[HarmonyPatch]
	public class NetworkObjectManager
	{
		private static GameObject networkPrefab;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameNetworkManager), "Start")]
		public static void Init()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			if (!((Object)(object)networkPrefab != (Object)null))
			{
				networkPrefab = (GameObject)JebsCounterAudioOverhaulBase.Instance.networkAssets.LoadAsset("JebsCounterNetworkManager.prefab");
				networkPrefab.AddComponent<NetworkHandler>();
				NetworkManager.Singleton.AddNetworkPrefab(networkPrefab);
				JebsCounterAudioOverhaulBase.logger.LogInfo((object)"NetworkObjectManager set!");
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		private static void SpawnNetworkHandler()
		{
			//IL_0024: 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)
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				GameObject val = Object.Instantiate<GameObject>(networkPrefab, Vector3.zero, Quaternion.identity);
				val.GetComponent<NetworkObject>().Spawn(false);
				JebsCounterAudioOverhaulBase.logger.LogInfo((object)"NetworkObject SPAWNED!");
			}
		}
	}
}
namespace JebsCounterAudioOverhaul.Managers
{
	public class NetworkHandler : NetworkBehaviour
	{
		private bool isSoundChosen = false;

		public static NetworkHandler Instance { get; private set; }

		public override void OnNetworkSpawn()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				NetworkHandler instance = Instance;
				if (instance != null)
				{
					((Component)instance).gameObject.GetComponent<NetworkObject>().Despawn(true);
				}
			}
			Instance = this;
			((NetworkBehaviour)this).OnNetworkSpawn();
			NetworkManager.__rpc_func_table.Add(584207315u, new RpcReceiveHandler(__rpc_handler_584207315));
			NetworkManager.__rpc_func_table.Add(972684150u, new RpcReceiveHandler(__rpc_handler_972684150));
			NetworkManager.__rpc_func_table.Add(829264651u, new RpcReceiveHandler(__rpc_handler_829264651));
		}

		[ServerRpc(RequireOwnership = false)]
		public void MakeDoorSoundServerRpc(NetworkBehaviourReference __instance)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Invalid comparison between Unknown and I4
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Invalid comparison between Unknown and I4
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if ((Object)(object)networkManager != (Object)null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(584207315u, val, (RpcDelivery)0);
					FastBufferWriter val3 = val2;
					((FastBufferWriter)(ref val3)).WriteValueSafe<NetworkBehaviourReference>(ref __instance, default(ForNetworkSerializable));
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 584207315u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost) && !isSoundChosen && JebsCounterAudioOverhaulBase.SoundFX.Count > 0)
				{
					int randomIndex = GetRandomIndex(0, JebsCounterAudioOverhaulBase.SoundFX.Count);
					AudioClip chosenClip = JebsCounterAudioOverhaulBase.SoundFX[randomIndex];
					ClientRpcParams val4 = default(ClientRpcParams);
					val4.Send = new ClientRpcSendParams
					{
						TargetClientIds = networkManager.ConnectedClientsIds
					};
					ClientRpcParams rpcParams = val4;
					isSoundChosen = true;
					MakeDoorSoundClientRpc(__instance, chosenClip, rpcParams);
				}
			}
		}

		[ClientRpc]
		public void MakeDoorSoundClientRpc(NetworkBehaviourReference __instance, AudioClip chosenClip, ClientRpcParams rpcParams = default(ClientRpcParams))
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Invalid comparison between Unknown and I4
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (!((Object)(object)networkManager == (Object)null) && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(972684150u, rpcParams, (RpcDelivery)0);
					FastBufferWriter val2 = val;
					((FastBufferWriter)(ref val2)).WriteValueSafe<NetworkBehaviourReference>(ref __instance, default(ForNetworkSerializable));
					val2 = val;
					((FastBufferWriter)(ref val2)).WriteValueSafe(((Object)chosenClip).name, false);
					((NetworkBehaviour)this).__endSendClientRpc(ref val, 972684150u, rpcParams, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					((DepositItemsDesk)NetworkBehaviourReference.op_Implicit(__instance)).deskAudio.PlayOneShot(chosenClip);
				}
			}
		}

		private static void __rpc_handler_584207315(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0028: 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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			NetworkHandler networkHandler = target as NetworkHandler;
			NetworkManager networkManager = target.NetworkManager;
			if ((Object)(object)networkManager != (Object)null && networkManager.IsListening)
			{
				NetworkBehaviourReference _instance = default(NetworkBehaviourReference);
				FastBufferReader val = reader;
				((FastBufferReader)(ref val)).ReadValueSafe<NetworkBehaviourReference>(ref _instance, default(ForNetworkSerializable));
				((NetworkBehaviour)networkHandler).__rpc_exec_stage = (__RpcExecStage)1;
				((NetworkHandler)(object)target).MakeDoorSoundServerRpc(_instance);
				((NetworkBehaviour)networkHandler).__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_972684150(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			NetworkHandler networkHandler = target as NetworkHandler;
			NetworkManager networkManager = target.NetworkManager;
			if ((Object)(object)networkManager != (Object)null && networkManager.IsListening)
			{
				string clipName = string.Empty;
				NetworkBehaviourReference _instance = default(NetworkBehaviourReference);
				FastBufferReader val = reader;
				((FastBufferReader)(ref val)).ReadValueSafe<NetworkBehaviourReference>(ref _instance, default(ForNetworkSerializable));
				val = reader;
				((FastBufferReader)(ref val)).ReadValueSafe(ref clipName, false);
				AudioClip chosenClip = ((IEnumerable<AudioClip>)JebsCounterAudioOverhaulBase.SoundFX).FirstOrDefault((Func<AudioClip, bool>)((AudioClip clip) => ((Object)clip).name == clipName)) ?? JebsCounterAudioOverhaulBase.SoundFX.FirstOrDefault();
				((NetworkBehaviour)networkHandler).__rpc_exec_stage = (__RpcExecStage)2;
				((NetworkHandler)(object)target).MakeDoorSoundClientRpc(_instance, chosenClip);
				((NetworkBehaviour)networkHandler).__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void EventIsOverServerRpc(bool __isEventOver)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Invalid comparison between Unknown and I4
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Invalid comparison between Unknown and I4
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if ((Object)(object)networkManager != (Object)null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(829264651u, val, (RpcDelivery)0);
					FastBufferWriter val3 = val2;
					((FastBufferWriter)(ref val3)).WriteValueSafe<bool>(ref __isEventOver, default(ForPrimitives));
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 829264651u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost) && isSoundChosen)
				{
					isSoundChosen = false;
				}
			}
		}

		private static void __rpc_handler_829264651(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0028: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			NetworkHandler networkHandler = target as NetworkHandler;
			NetworkManager networkManager = target.NetworkManager;
			if ((Object)(object)networkManager != (Object)null && networkManager.IsListening)
			{
				bool _isEventOver = false;
				FastBufferReader val = reader;
				((FastBufferReader)(ref val)).ReadValueSafe<bool>(ref _isEventOver, default(ForPrimitives));
				((NetworkBehaviour)networkHandler).__rpc_exec_stage = (__RpcExecStage)1;
				((NetworkHandler)(object)target).EventIsOverServerRpc(_isEventOver);
				((NetworkBehaviour)networkHandler).__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static int GetRandomIndex(int minValue, int maxValue)
		{
			using RandomNumberGenerator randomNumberGenerator = RandomNumberGenerator.Create();
			byte[] array = new byte[4];
			randomNumberGenerator.GetBytes(array);
			int num = BitConverter.ToInt32(array, 0);
			return Math.Abs(num % (maxValue - minValue)) + minValue;
		}
	}
}