Decompiled source of LethalPhones v1.0.11

LethalPhones/LethalPhones.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using LethalPhones.NetcodePatcher;
using Microsoft.CodeAnalysis;
using Scoops.misc;
using Scoops.patch;
using Scoops.service;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Animations.Rigging;
using UnityEngine.InputSystem;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("LethalPhones")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.0.0.0")]
[assembly: AssemblyInformationalVersion("0.0.0-alpha.0.75+593025ff38d79cf945340cb265a07bce5655c053")]
[assembly: AssemblyProduct("LethalPhones")]
[assembly: AssemblyTitle("LethalPhones")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
		NetworkVariableSerializationTypes.InitializeSerializer_UnmanagedByMemcpy<float>();
		NetworkVariableSerializationTypes.InitializeEqualityChecker_UnmanagedIEquatable<float>();
	}
}
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 Scoops
{
	public class Config
	{
		public static ConfigEntry<float> recordingStartDist;

		public static ConfigEntry<float> backgroundVoiceDist;

		public static ConfigEntry<float> eavesdropDist;

		public static ConfigEntry<float> backgroundSoundMod;

		public static ConfigEntry<float> voiceSoundMod;

		public static ConfigEntry<float> deathHangupTime;

		public static ConfigEntry<bool> hideHands;

		public static ConfigEntry<int> maxPhoneBugs;

		public static ConfigEntry<float> chancePhoneBug;

		public static ConfigEntry<float> minPhoneBugInterval;

		public static ConfigEntry<float> maxPhoneBugInterval;

		public Config(ConfigFile cfg)
		{
			voiceSoundMod = cfg.Bind<float>("General", "voiceSoundMod", 0f, "All voices on calls have their volume adjusted by this value.");
			backgroundSoundMod = cfg.Bind<float>("General", "backgroundSoundMod", -0.1f, "All background noises on calls have their volume adjusted by this value.");
			recordingStartDist = cfg.Bind<float>("General", "recordingStartDist", 15f, "Disables phones while in this distance to the person you're calling.");
			backgroundVoiceDist = cfg.Bind<float>("General", "backgroundVoiceDist", 20f, "The distance at which you can hear other players in the background of a call.");
			eavesdropDist = cfg.Bind<float>("General", "eavesdropDist", 5f, "The distance at which you can listen in on someone else's call.");
			deathHangupTime = cfg.Bind<float>("General", "deathHangupTime", 0.5f, "The time it takes (in seconds) for a call to auto-hangup after death.");
			hideHands = cfg.Bind<bool>("General", "hideHands", false, "If true, the model's right hand will not be used for dialing. (useful if using a custom model with hands too big/small for the phone)");
			maxPhoneBugs = cfg.Bind<int>("Enemies.HoardingBugs", "maxPhoneBugs", 1, "Maximum number of Hoarding Bugs that can spawn with phones.");
			chancePhoneBug = cfg.Bind<float>("Enemies.HoardingBugs", "chancePhoneBug", 0.1f, "The chance (0 - 1) that a Hoarding Bug will be spawned with a phone.");
			minPhoneBugInterval = cfg.Bind<float>("Enemies.HoardingBugs", "minPhoneBugInterval", 10f, "The shortest time (in seconds) between calls from each Hoarding Bug.");
			maxPhoneBugInterval = cfg.Bind<float>("Enemies.HoardingBugs", "maxPhoneBugInterval", 100f, "The longest time (in seconds) between calls from each Hoarding Bug.");
		}
	}
	public class LethalPhonesInputClass : LcInputActions
	{
		[InputAction("<Keyboard>/backquote", Name = "Toggle Phone", GamepadPath = "<Gamepad>/leftStickPress")]
		public InputAction TogglePhoneKey { get; set; }

		[InputAction("<Keyboard>/q", Name = "Hangup Phone", GamepadPath = "<Gamepad>/dpad/down")]
		public InputAction HangupPhoneKey { get; set; }

		[InputAction("<Mouse>/leftButton", Name = "Pickup Phone", GamepadPath = "<Gamepad>/rightTrigger")]
		public InputAction PickupPhoneKey { get; set; }

		[InputAction("<Keyboard>/z", Name = "Dial Phone", GamepadPath = "<Gamepad>/leftShoulder")]
		public InputAction DialPhoneKey { get; set; }

		[InputAction("<Keyboard>/g", Name = "Toggle Phone Volume", GamepadPath = "<Gamepad>/buttonEast")]
		public InputAction VolumePhoneKey { get; set; }
	}
	[BepInPlugin("LethalPhones", "LethalPhones", "1.0.11")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static AssetBundle LethalPhoneAssets;

		private readonly Harmony _harmony = new Harmony("LethalPhones");

		internal static LethalPhonesInputClass InputActionInstance = new LethalPhonesInputClass();

		public static Plugin Instance { get; set; }

		public static Config PhoneConfig { get; internal set; }

		public static ManualLogSource Log => ((BaseUnityPlugin)Instance).Logger;

		public Plugin()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			Instance = this;
		}

		private void Awake()
		{
			NetcodePatcher();
			string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			string text = Path.Combine(directoryName, "lethalphonesassets");
			LethalPhoneAssets = AssetBundle.LoadFromFile(text);
			PhoneAssetManager.Init();
			PhoneConfig = new Config(((BaseUnityPlugin)this).Config);
			Log.LogInfo((object)"Applying patches...");
			ApplyPluginPatch();
			Log.LogInfo((object)"Patches applied");
		}

		private void ApplyPluginPatch()
		{
			_harmony.PatchAll(typeof(PlayerPhonePatch));
			_harmony.PatchAll(typeof(PlayerControllerB_SetPlayerSanityLevel_Patch));
			_harmony.PatchAll(typeof(HoardingBugPhonePatch));
			_harmony.PatchAll(typeof(StartOfRoundPhonePatch));
			_harmony.PatchAll(typeof(NetworkObjectManager));
			_harmony.PatchAll(typeof(ShipTeleporterPhonePatch));
		}

		private static void NetcodePatcher()
		{
			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);
					}
				}
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "LethalPhones";

		public const string PLUGIN_NAME = "LethalPhones";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace Scoops.service
{
	public class AudioSourceStorage
	{
		public AudioSource audioSource;

		private GameObject audioSourceHolder;

		private float origVolume;

		private float origPan;

		private bool hadLowPass;

		private bool hadHighPass;

		private bool hadOcclude;

		private float origLowPass;

		private float origLowPassResQ;

		private float origHighPass;

		private float origHighPassResQ;

		public AudioSourceStorage(AudioSource audioSource)
		{
			this.audioSource = audioSource;
			audioSourceHolder = ((Component)audioSource).gameObject;
			origVolume = audioSource.volume;
			origPan = audioSource.panStereo;
			hadLowPass = (Object)(object)audioSourceHolder.GetComponent<AudioLowPassFilter>() != (Object)null;
			hadHighPass = (Object)(object)audioSourceHolder.GetComponent<AudioHighPassFilter>() != (Object)null;
			hadOcclude = (Object)(object)audioSourceHolder.GetComponent<OccludeAudio>() != (Object)null;
			if (hadLowPass)
			{
				origLowPass = audioSourceHolder.GetComponent<AudioLowPassFilter>().cutoffFrequency;
				origLowPassResQ = audioSourceHolder.GetComponent<AudioLowPassFilter>().lowpassResonanceQ;
			}
			if (hadHighPass)
			{
				origHighPass = audioSourceHolder.GetComponent<AudioHighPassFilter>().cutoffFrequency;
				origHighPassResQ = audioSourceHolder.GetComponent<AudioHighPassFilter>().highpassResonanceQ;
			}
		}

		public void InitAudio()
		{
			if (!((Object)(object)audioSource != (Object)null))
			{
				return;
			}
			audioSource.spatialBlend = 0f;
			audioSource.panStereo = -0.4f;
			if ((Object)(object)audioSourceHolder != (Object)null)
			{
				if (!hadLowPass)
				{
					audioSourceHolder.AddComponent<AudioLowPassFilter>();
				}
				if (!hadHighPass)
				{
					audioSourceHolder.AddComponent<AudioHighPassFilter>();
				}
				if (hadOcclude)
				{
					((Behaviour)audioSourceHolder.GetComponent<OccludeAudio>()).enabled = false;
				}
				audioSourceHolder.GetComponent<AudioLowPassFilter>().cutoffFrequency = 2899f;
				audioSourceHolder.GetComponent<AudioLowPassFilter>().lowpassResonanceQ = 3f;
				audioSourceHolder.GetComponent<AudioHighPassFilter>().cutoffFrequency = 1613f;
				audioSourceHolder.GetComponent<AudioHighPassFilter>().highpassResonanceQ = 1f;
			}
		}

		public void ApplyPhone(float dist, float callQuality = 1f, float listenDist = 0f, float listenAngle = 0f, bool staticMode = false)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Invalid comparison between Unknown and I4
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Invalid comparison between Unknown and I4
			if (!((Object)(object)audioSourceHolder != (Object)null) || !((Object)(object)audioSource != (Object)null))
			{
				return;
			}
			float num = 0f;
			if ((int)audioSource.rolloffMode == 1)
			{
				num = Mathf.Clamp01(Mathf.InverseLerp(audioSource.maxDistance, audioSource.minDistance, dist) + Config.backgroundSoundMod.Value);
			}
			else if ((int)audioSource.rolloffMode == 2)
			{
				AnimationCurve customCurve = audioSource.GetCustomCurve((AudioSourceCurveType)0);
				if (customCurve != null)
				{
					num = Mathf.Clamp01(customCurve.Evaluate(dist / audioSource.maxDistance) + Config.backgroundSoundMod.Value);
				}
			}
			else
			{
				num = Mathf.Clamp01(audioSource.minDistance * (1f / (1f + (dist - 1f))) + Config.backgroundSoundMod.Value);
			}
			audioSource.volume = origVolume * num;
			if (staticMode)
			{
				audioSource.volume = 0f;
			}
			if (Object.op_Implicit((Object)(object)audioSourceHolder.GetComponent<AudioLowPassFilter>()))
			{
				audioSourceHolder.GetComponent<AudioLowPassFilter>().cutoffFrequency = Mathf.Lerp(2000f, 2899f, callQuality);
				audioSourceHolder.GetComponent<AudioLowPassFilter>().lowpassResonanceQ = Mathf.Lerp(5f, 3f, callQuality);
			}
			if (Object.op_Implicit((Object)(object)audioSourceHolder.GetComponent<AudioHighPassFilter>()))
			{
				audioSourceHolder.GetComponent<AudioHighPassFilter>().highpassResonanceQ = Mathf.Lerp(2f, 1f, callQuality);
			}
			if (listenDist != 0f)
			{
				float num2 = Mathf.InverseLerp(Config.eavesdropDist.Value, 0f, listenDist);
				audioSource.volume *= num2;
				if (Object.op_Implicit((Object)(object)audioSourceHolder.GetComponent<AudioLowPassFilter>()))
				{
					audioSourceHolder.GetComponent<AudioLowPassFilter>().cutoffFrequency = 750f;
				}
				audioSource.panStereo = listenAngle;
			}
		}

		public void Reset()
		{
			if (!((Object)(object)audioSourceHolder != (Object)null))
			{
				return;
			}
			if ((Object)(object)audioSource != (Object)null)
			{
				audioSource.spatialBlend = 1f;
				audioSource.panStereo = origPan;
				audioSource.volume = origVolume;
			}
			if (hadOcclude && Object.op_Implicit((Object)(object)audioSourceHolder.GetComponent<OccludeAudio>()))
			{
				((Behaviour)audioSourceHolder.GetComponent<OccludeAudio>()).enabled = true;
			}
			if (Object.op_Implicit((Object)(object)audioSourceHolder.GetComponent<AudioLowPassFilter>()))
			{
				if (hadLowPass)
				{
					audioSourceHolder.GetComponent<AudioLowPassFilter>().cutoffFrequency = origLowPass;
					audioSourceHolder.GetComponent<AudioLowPassFilter>().lowpassResonanceQ = origLowPassResQ;
				}
				else
				{
					Object.Destroy((Object)(object)audioSourceHolder.GetComponent<AudioLowPassFilter>());
				}
			}
			if (Object.op_Implicit((Object)(object)audioSourceHolder.GetComponent<AudioHighPassFilter>()))
			{
				if (hadHighPass)
				{
					audioSourceHolder.GetComponent<AudioHighPassFilter>().cutoffFrequency = origHighPass;
					audioSourceHolder.GetComponent<AudioHighPassFilter>().highpassResonanceQ = origHighPassResQ;
				}
				else
				{
					Object.Destroy((Object)(object)audioSourceHolder.GetComponent<AudioHighPassFilter>());
				}
			}
		}
	}
	public class PhoneAssetManager
	{
		public static AudioClip phoneRingCaller;

		public static AudioClip phoneRingReciever;

		public static AudioClip phonePickup;

		public static AudioClip phoneHangup;

		public static AudioClip phoneRotaryForward;

		public static AudioClip phoneRotaryBackward;

		public static AudioClip phoneRotaryStopper;

		public static AudioClip phoneRotaryFinish;

		public static AudioClip phoneBusy;

		public static AudioClip phoneRingVibrate;

		public static AudioClip phoneSwitch;

		public static AudioClip phoneStaticOne;

		public static AudioClip phoneStaticTwo;

		public static AudioClip phoneStaticThree;

		public static void Init()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Expected O, but got Unknown
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Expected O, but got Unknown
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Expected O, but got Unknown
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Expected O, but got Unknown
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Expected O, but got Unknown
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Expected O, but got Unknown
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Expected O, but got Unknown
			Plugin.Log.LogInfo((object)"Loading Assets...");
			phoneRingCaller = (AudioClip)Plugin.LethalPhoneAssets.LoadAsset("PhoneRing_Caller");
			phoneRingReciever = (AudioClip)Plugin.LethalPhoneAssets.LoadAsset("PhoneRing_Reciever");
			phonePickup = (AudioClip)Plugin.LethalPhoneAssets.LoadAsset("PhonePickup");
			phoneHangup = (AudioClip)Plugin.LethalPhoneAssets.LoadAsset("PhoneHangup");
			phoneRotaryForward = (AudioClip)Plugin.LethalPhoneAssets.LoadAsset("RotaryDialForwardOptionTwo");
			phoneRotaryBackward = (AudioClip)Plugin.LethalPhoneAssets.LoadAsset("RotaryDialBackOptionOne");
			phoneRotaryStopper = (AudioClip)Plugin.LethalPhoneAssets.LoadAsset("RotaryStopperOptionOne");
			phoneRotaryFinish = (AudioClip)Plugin.LethalPhoneAssets.LoadAsset("RotaryFinishOptionOne");
			phoneBusy = (AudioClip)Plugin.LethalPhoneAssets.LoadAsset("PhoneBusy");
			phoneRingVibrate = (AudioClip)Plugin.LethalPhoneAssets.LoadAsset("PhoneRing_Vibrate");
			phoneSwitch = (AudioClip)Plugin.LethalPhoneAssets.LoadAsset("PhoneSwitch");
			phoneStaticOne = (AudioClip)Plugin.LethalPhoneAssets.LoadAsset("PhoneStaticOne");
			phoneStaticTwo = (AudioClip)Plugin.LethalPhoneAssets.LoadAsset("PhoneStaticTwo");
			phoneStaticThree = (AudioClip)Plugin.LethalPhoneAssets.LoadAsset("PhoneStaticThree");
		}
	}
	public class PhoneNetworkHandler : NetworkBehaviour
	{
		private Dictionary<string, ulong> phoneNumberDict;

		private Dictionary<string, PhoneBehavior> phoneObjectDict;

		public PlayerPhone localPhone;

		public static PhoneNetworkHandler Instance { get; private set; }

		public override void OnNetworkSpawn()
		{
			if ((NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer) && (Object)(object)Instance != (Object)null)
			{
				((Component)Instance).gameObject.GetComponent<NetworkObject>().Despawn(true);
			}
			Instance = this;
			phoneNumberDict = new Dictionary<string, ulong>();
			phoneObjectDict = new Dictionary<string, PhoneBehavior>();
			((NetworkBehaviour)this).OnNetworkSpawn();
		}

		public void CreateNewPhone(ulong phoneId)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			CreateNewPhoneNumberServerRpc(phoneId);
		}

		[ServerRpc(RequireOwnership = false)]
		public void CreateNewPhoneNumberServerRpc(ulong phoneId, ServerRpcParams serverRpcParams = default(ServerRpcParams))
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: 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))
			{
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendServerRpc(3708225570u, serverRpcParams, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val, phoneId);
				((NetworkBehaviour)this).__endSendServerRpc(ref val, 3708225570u, serverRpcParams, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ulong senderClientId = serverRpcParams.Receive.SenderClientId;
				int num = Random.Range(0, 10000);
				string text = num.ToString("D4");
				while (phoneNumberDict.ContainsKey(num.ToString()))
				{
					num = Random.Range(0, 10000);
					text = num.ToString("D4");
				}
				PhoneBehavior component = ((Component)((NetworkBehaviour)this).GetNetworkObject(phoneId)).GetComponent<PhoneBehavior>();
				Plugin.Log.LogInfo((object)("New phone for object: " + phoneId));
				((Component)component).GetComponent<NetworkObject>().ChangeOwnership(senderClientId);
				phoneNumberDict.Add(text, ((NetworkBehaviour)component).NetworkObjectId);
				phoneObjectDict.Add(text, component);
				component.SetNewPhoneNumberClientRpc(text);
			}
		}

		public void DeletePlayerPhone(int playerId)
		{
			PlayerControllerB val = StartOfRound.Instance.allPlayerScripts[playerId];
			Plugin.Log.LogInfo((object)("Deleting phone for player: " + ((Object)val).name));
			PlayerPhone phone = ((Component)((Component)val).transform.Find("PhonePrefab(Clone)")).GetComponent<PlayerPhone>();
			string key = phoneNumberDict.FirstOrDefault((KeyValuePair<string, ulong> x) => x.Value == ((NetworkBehaviour)phone).NetworkObjectId).Key;
			((Component)phone).GetComponent<NetworkObject>().RemoveOwnership();
			RemoveNumber(key);
		}

		public void DeletePhone(ulong phoneId)
		{
			Plugin.Log.LogInfo((object)("Deleting phone with ID: " + phoneId));
			PhoneBehavior phone = ((Component)((NetworkBehaviour)this).GetNetworkObject(phoneId)).GetComponent<PhoneBehavior>();
			string key = phoneNumberDict.FirstOrDefault((KeyValuePair<string, ulong> x) => x.Value == ((NetworkBehaviour)phone).NetworkObjectId).Key;
			((Component)phone).GetComponent<NetworkObject>().RemoveOwnership();
			RemoveNumber(key);
		}

		public void RemoveNumber(string number)
		{
			if (number != null)
			{
				Plugin.Log.LogInfo((object)("Removing number: " + number));
				phoneObjectDict.Remove(number);
				phoneNumberDict.Remove(number);
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void MakeOutgoingCallServerRpc(string number, ulong senderId, ServerRpcParams serverRpcParams = default(ServerRpcParams))
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: 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))
			{
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendServerRpc(2838937995u, serverRpcParams, (RpcDelivery)0);
				bool flag = number != null;
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val)).WriteValueSafe(number, false);
				}
				BytePacker.WriteValueBitPacked(val, senderId);
				((NetworkBehaviour)this).__endSendServerRpc(ref val, 2838937995u, serverRpcParams, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ulong senderId2 = senderId;
				string key = phoneNumberDict.FirstOrDefault((KeyValuePair<string, ulong> x) => x.Value == senderId2).Key;
				if (phoneNumberDict.ContainsKey(number))
				{
					phoneObjectDict[number].RecieveCallClientRpc(senderId2, key);
				}
				else
				{
					phoneObjectDict[key].InvalidCallClientRpc("Invalid #");
				}
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void AcceptIncomingCallServerRpc(string number, ulong accepterId, ServerRpcParams serverRpcParams = default(ServerRpcParams))
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: 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))
			{
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendServerRpc(3789588791u, serverRpcParams, (RpcDelivery)0);
				bool flag = number != null;
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val)).WriteValueSafe(number, false);
				}
				BytePacker.WriteValueBitPacked(val, accepterId);
				((NetworkBehaviour)this).__endSendServerRpc(ref val, 3789588791u, serverRpcParams, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ulong accepterId2 = accepterId;
				string key = phoneNumberDict.FirstOrDefault((KeyValuePair<string, ulong> x) => x.Value == accepterId2).Key;
				phoneObjectDict[number].CallAcceptedClientRpc(accepterId2, key);
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void HangUpCallServerRpc(string number, ulong cancellerId, ServerRpcParams serverRpcParams = default(ServerRpcParams))
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: 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))
			{
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendServerRpc(835668601u, serverRpcParams, (RpcDelivery)0);
				bool flag = number != null;
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val)).WriteValueSafe(number, false);
				}
				BytePacker.WriteValueBitPacked(val, cancellerId);
				((NetworkBehaviour)this).__endSendServerRpc(ref val, 835668601u, serverRpcParams, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage != 1 || (!networkManager.IsServer && !networkManager.IsHost))
			{
				return;
			}
			ulong cancellerId2 = cancellerId;
			if (phoneNumberDict.ContainsKey(number))
			{
				string key = phoneNumberDict.FirstOrDefault((KeyValuePair<string, ulong> x) => x.Value == cancellerId2).Key;
				phoneObjectDict[number].HangupCallClientRpc(cancellerId2, key);
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void LineBusyServerRpc(string number, ServerRpcParams serverRpcParams = default(ServerRpcParams))
		{
			//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))
			{
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendServerRpc(16429471u, serverRpcParams, (RpcDelivery)0);
				bool flag = number != null;
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val)).WriteValueSafe(number, false);
				}
				((NetworkBehaviour)this).__endSendServerRpc(ref val, 16429471u, serverRpcParams, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				phoneObjectDict[number].InvalidCallClientRpc("Line Busy");
			}
		}

		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_PhoneNetworkHandler()
		{
			//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
			NetworkManager.__rpc_func_table.Add(3708225570u, new RpcReceiveHandler(__rpc_handler_3708225570));
			NetworkManager.__rpc_func_table.Add(2838937995u, new RpcReceiveHandler(__rpc_handler_2838937995));
			NetworkManager.__rpc_func_table.Add(3789588791u, new RpcReceiveHandler(__rpc_handler_3789588791));
			NetworkManager.__rpc_func_table.Add(835668601u, new RpcReceiveHandler(__rpc_handler_835668601));
			NetworkManager.__rpc_func_table.Add(16429471u, new RpcReceiveHandler(__rpc_handler_16429471));
		}

		private static void __rpc_handler_3708225570(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				ulong phoneId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref phoneId);
				ServerRpcParams server = rpcParams.Server;
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((PhoneNetworkHandler)(object)target).CreateNewPhoneNumberServerRpc(phoneId, server);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2838937995(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_005b: 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_0069: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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 number = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref number, false);
				}
				ulong senderId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref senderId);
				ServerRpcParams server = rpcParams.Server;
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((PhoneNetworkHandler)(object)target).MakeOutgoingCallServerRpc(number, senderId, server);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3789588791(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_005b: 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_0069: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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 number = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref number, false);
				}
				ulong accepterId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref accepterId);
				ServerRpcParams server = rpcParams.Server;
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((PhoneNetworkHandler)(object)target).AcceptIncomingCallServerRpc(number, accepterId, server);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_835668601(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_005b: 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_0069: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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 number = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref number, false);
				}
				ulong cancellerId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref cancellerId);
				ServerRpcParams server = rpcParams.Server;
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((PhoneNetworkHandler)(object)target).HangUpCallServerRpc(number, cancellerId, server);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_16429471(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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: 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 = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string number = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref number, false);
				}
				ServerRpcParams server = rpcParams.Server;
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((PhoneNetworkHandler)(object)target).LineBusyServerRpc(number, server);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "PhoneNetworkHandler";
		}
	}
}
namespace Scoops.patch
{
	[HarmonyPatch(typeof(HoarderBugAI))]
	public class HoardingBugPhonePatch
	{
		public static int phoneBugs;

		public static PhoneNetworkHandler PhoneManager;

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void CreatePhoneAssets(ref HoarderBugAI __instance)
		{
			//IL_0076: 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)
			PhoneManager = PhoneNetworkHandler.Instance;
			if ((NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer) && phoneBugs < Config.maxPhoneBugs.Value && Random.Range(0f, 1f) <= Config.chancePhoneBug.Value)
			{
				phoneBugs++;
				GameObject val = Object.Instantiate<GameObject>(NetworkObjectManager.bugPhonePrefab, Vector3.zero, Quaternion.identity);
				val.GetComponent<NetworkObject>().Spawn(false);
				val.GetComponent<NetworkObject>().TrySetParent(((Component)__instance).transform, false);
				PhoneManager.CreateNewPhone(val.GetComponent<NetworkObject>().NetworkObjectId);
			}
		}

		[HarmonyPatch("KillEnemy")]
		[HarmonyPrefix]
		private static void BugDead(ref HoarderBugAI __instance, bool destroy = false)
		{
			if (((NetworkBehaviour)__instance).IsServer && (Object)(object)__instance != (Object)null && (Object)(object)((Component)__instance).transform.Find("BugPhonePrefab(Clone)") != (Object)null)
			{
				HoardingPhone component = ((Component)((Component)__instance).transform.Find("BugPhonePrefab(Clone)")).GetComponent<HoardingPhone>();
				if ((Object)(object)component != (Object)null)
				{
					component.Death();
					((NetworkBehaviour)component).NetworkObject.Despawn(true);
				}
			}
		}

		[HarmonyPatch(typeof(RoundManager), "UnloadSceneObjectsEarly")]
		[HarmonyPrefix]
		private static void UnloadScene(ref RoundManager __instance)
		{
			if (!((NetworkBehaviour)__instance).IsServer)
			{
				return;
			}
			HoardingPhone[] array = Object.FindObjectsOfType<HoardingPhone>();
			for (int i = 0; i < array.Length; i++)
			{
				if (((NetworkBehaviour)array[i]).IsSpawned)
				{
					array[i].Death();
					((NetworkBehaviour)array[i]).NetworkObject.Despawn(true);
				}
			}
		}
	}
	[HarmonyPatch]
	public class NetworkObjectManager
	{
		private static GameObject networkPrefab;

		public static GameObject phonePrefab;

		public static GameObject bugPhonePrefab;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameNetworkManager), "Start")]
		public static void Init()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected O, but got Unknown
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Expected O, but got Unknown
			if ((Object)(object)networkPrefab == (Object)null)
			{
				networkPrefab = (GameObject)Plugin.LethalPhoneAssets.LoadAsset("PhoneNetworkHandler");
				networkPrefab.AddComponent<PhoneNetworkHandler>();
				NetworkManager.Singleton.AddNetworkPrefab(networkPrefab);
			}
			if ((Object)(object)phonePrefab == (Object)null)
			{
				phonePrefab = (GameObject)Plugin.LethalPhoneAssets.LoadAsset("PhonePrefab");
				phonePrefab.AddComponent<PlayerPhone>();
				NetworkManager.Singleton.AddNetworkPrefab(phonePrefab);
			}
			if ((Object)(object)bugPhonePrefab == (Object)null)
			{
				bugPhonePrefab = (GameObject)Plugin.LethalPhoneAssets.LoadAsset("BugPhonePrefab");
				bugPhonePrefab.AddComponent<HoardingPhone>();
				NetworkManager.Singleton.AddNetworkPrefab(bugPhonePrefab);
			}
		}

		[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);
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	[HarmonyPatch("SetPlayerSanityLevel")]
	public static class PlayerControllerB_SetPlayerSanityLevel_Patch
	{
		private static FieldInfo f_isPlayerAlone = AccessTools.Field(typeof(PlayerControllerB), "isPlayerAlone");

		private static MethodInfo m_UpdatePhoneSanity = AccessTools.Method(typeof(PlayerPhone), "UpdatePhoneSanity", new Type[1] { typeof(PlayerControllerB) }, (Type[])null);

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Expected O, but got Unknown
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			int num = -1;
			for (int i = 0; i < list.Count - 3; i++)
			{
				if (list[i].opcode == OpCodes.Ldarg_0 && list[i + 1].opcode == OpCodes.Ldfld && list[i + 2].opcode == OpCodes.Ldc_R4 && list[i + 3].opcode == OpCodes.Bge_Un)
				{
					num = i + 1;
					break;
				}
			}
			List<CodeInstruction> collection = new List<CodeInstruction>
			{
				new CodeInstruction(OpCodes.Call, (object)m_UpdatePhoneSanity),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null)
			};
			if (num != -1)
			{
				list.InsertRange(num, collection);
			}
			return list;
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	public class PlayerPhonePatch
	{
		public static PhoneNetworkHandler PhoneManager;

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void CreatePhoneAssets(ref PlayerControllerB __instance)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Expected O, but got Unknown
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Expected O, but got Unknown
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Expected O, but got Unknown
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Expected O, but got Unknown
			//IL_039f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = (GameObject)Plugin.LethalPhoneAssets.LoadAsset("PhoneAudioExternal");
			Object.Instantiate<GameObject>(val, ((Component)__instance).transform.Find("Audios"));
			GameObject val2 = (GameObject)Plugin.LethalPhoneAssets.LoadAsset("LocalPhoneModel");
			GameObject val3 = Object.Instantiate<GameObject>(val2, __instance.localArmsTransform.Find("shoulder.L").Find("arm.L_upper").Find("arm.L_lower")
				.Find("hand.L"), false);
			GameObject val4 = (GameObject)Plugin.LethalPhoneAssets.LoadAsset("ServerPhoneModel");
			GameObject val5 = Object.Instantiate<GameObject>(val4, __instance.lowerSpine.Find("spine.002").Find("spine.003").Find("shoulder.L")
				.Find("arm.L_upper")
				.Find("arm.L_lower")
				.Find("hand.L"), false);
			Transform val6 = __instance.localArmsTransform.Find("RigArms");
			Transform val7 = __instance.meshContainer.Find("metarig").Find("Rig 1");
			GameObject val8 = (GameObject)Plugin.LethalPhoneAssets.LoadAsset("RightArmPhone");
			GameObject val9 = (GameObject)Plugin.LethalPhoneAssets.LoadAsset("LeftArmPhone");
			GameObject val10 = (GameObject)Plugin.LethalPhoneAssets.LoadAsset("ServerLeftArmPhone");
			GameObject val11 = (GameObject)Plugin.LethalPhoneAssets.LoadAsset("ServerPhoneTargetHolder");
			GameObject val12 = Object.Instantiate<GameObject>(val8, val6, false);
			GameObject val13 = Object.Instantiate<GameObject>(val9, val6, false);
			GameObject val14 = Object.Instantiate<GameObject>(val10, val7, false);
			GameObject val15 = Object.Instantiate<GameObject>(val11, __instance.lowerSpine.Find("spine.002").Find("spine.003"), false);
			((ChainIKConstraintData)(ref ((RigConstraint<ChainIKConstraintJob, ChainIKConstraintData, ChainIKConstraintJobBinder<ChainIKConstraintData>>)(object)val12.GetComponent<ChainIKConstraint>()).data)).root = __instance.localArmsTransform.Find("shoulder.R").Find("arm.R_upper");
			((ChainIKConstraintData)(ref ((RigConstraint<ChainIKConstraintJob, ChainIKConstraintData, ChainIKConstraintJobBinder<ChainIKConstraintData>>)(object)val12.GetComponent<ChainIKConstraint>()).data)).tip = __instance.localArmsTransform.Find("shoulder.R").Find("arm.R_upper").Find("arm.R_lower")
				.Find("hand.R");
			((ChainIKConstraintData)(ref ((RigConstraint<ChainIKConstraintJob, ChainIKConstraintData, ChainIKConstraintJobBinder<ChainIKConstraintData>>)(object)val13.GetComponent<ChainIKConstraint>()).data)).root = __instance.localArmsTransform.Find("shoulder.L").Find("arm.L_upper");
			((ChainIKConstraintData)(ref ((RigConstraint<ChainIKConstraintJob, ChainIKConstraintData, ChainIKConstraintJobBinder<ChainIKConstraintData>>)(object)val13.GetComponent<ChainIKConstraint>()).data)).tip = __instance.localArmsTransform.Find("shoulder.L").Find("arm.L_upper").Find("arm.L_lower")
				.Find("hand.L");
			((ChainIKConstraintData)(ref ((RigConstraint<ChainIKConstraintJob, ChainIKConstraintData, ChainIKConstraintJobBinder<ChainIKConstraintData>>)(object)val14.GetComponent<ChainIKConstraint>()).data)).root = __instance.lowerSpine.Find("spine.002").Find("spine.003").Find("shoulder.L")
				.Find("arm.L_upper");
			((ChainIKConstraintData)(ref ((RigConstraint<ChainIKConstraintJob, ChainIKConstraintData, ChainIKConstraintJobBinder<ChainIKConstraintData>>)(object)val14.GetComponent<ChainIKConstraint>()).data)).tip = __instance.lowerSpine.Find("spine.002").Find("spine.003").Find("shoulder.L")
				.Find("arm.L_upper")
				.Find("arm.L_lower")
				.Find("hand.L");
			((ChainIKConstraintData)(ref ((RigConstraint<ChainIKConstraintJob, ChainIKConstraintData, ChainIKConstraintJobBinder<ChainIKConstraintData>>)(object)val14.GetComponent<ChainIKConstraint>()).data)).target = val15.transform.Find("ServerPhoneTarget");
			((Object)val12.GetComponent<ChainIKConstraint>()).MarkDirty();
			((Object)val13.GetComponent<ChainIKConstraint>()).MarkDirty();
			((Object)val14.GetComponent<ChainIKConstraint>()).MarkDirty();
			((Component)__instance.playerBodyAnimator).GetComponent<RigBuilder>().Build();
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				GameObject val16 = Object.Instantiate<GameObject>(NetworkObjectManager.phonePrefab, Vector3.zero, Quaternion.identity);
				val16.GetComponent<NetworkObject>().Spawn(false);
				val16.GetComponent<NetworkObject>().TrySetParent(((Component)__instance).transform, false);
			}
		}

		[HarmonyPatch("SpectateNextPlayer")]
		[HarmonyPostfix]
		private static void SpectatedNextPlayer(ref PlayerControllerB __instance)
		{
			PlayerPhone[] array = Object.FindObjectsByType<PlayerPhone>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			for (int i = 0; i < array.Length; i++)
			{
				array[i].spectatorClear = true;
			}
		}

		[HarmonyPatch("ConnectClientToPlayerObject")]
		[HarmonyPostfix]
		private static void InitPhone(ref PlayerControllerB __instance)
		{
			PhoneManager = PhoneNetworkHandler.Instance;
			NetworkObject component = ((Component)((Component)__instance).transform.Find("PhonePrefab(Clone)")).GetComponent<NetworkObject>();
			PhoneManager.CreateNewPhone(component.NetworkObjectId);
			Plugin.InputActionInstance.TogglePhoneKey.performed += OnTogglePhoneKeyPressed;
			Plugin.InputActionInstance.PickupPhoneKey.performed += OnPickupPhoneKeyPressed;
			Plugin.InputActionInstance.HangupPhoneKey.performed += OnHangupPhoneKeyPressed;
			Plugin.InputActionInstance.VolumePhoneKey.performed += OnVolumePhoneKeyPressed;
		}

		[HarmonyPatch("OnDestroy")]
		[HarmonyPrefix]
		private static void CleanupPhone(ref PlayerControllerB __instance)
		{
			if ((((NetworkBehaviour)__instance).IsOwner && __instance.isPlayerControlled && (!((NetworkBehaviour)__instance).IsServer || __instance.isHostPlayerObject)) || __instance.isTestingPlayer)
			{
				Plugin.InputActionInstance.TogglePhoneKey.performed -= OnTogglePhoneKeyPressed;
				Plugin.InputActionInstance.PickupPhoneKey.performed -= OnPickupPhoneKeyPressed;
				Plugin.InputActionInstance.HangupPhoneKey.performed -= OnHangupPhoneKeyPressed;
				Plugin.InputActionInstance.VolumePhoneKey.performed -= OnVolumePhoneKeyPressed;
			}
		}

		[HarmonyPatch("DamagePlayer")]
		[HarmonyPostfix]
		private static void PlayerDamaged(ref PlayerControllerB __instance, int damageNumber, bool hasDamageSFX = true, bool callRPC = true, CauseOfDeath causeOfDeath = 0, int deathAnimation = 0, bool fallDamage = false, Vector3 force = default(Vector3))
		{
			if ((((NetworkBehaviour)__instance).IsOwner && __instance.isPlayerControlled && (!((NetworkBehaviour)__instance).IsServer || __instance.isHostPlayerObject)) || __instance.isTestingPlayer)
			{
				float change = 0f - Mathf.Clamp01((float)damageNumber / 100f);
				PhoneManager.localPhone.InfluenceConnectionQuality(change);
			}
		}

		[HarmonyPatch("DisablePlayerModel")]
		[HarmonyPostfix]
		private static void PlayerModelDisabled(ref PlayerControllerB __instance, GameObject playerObject, bool enable = false, bool disableLocalArms = false)
		{
			PlayerPhone component = ((Component)((Component)__instance).transform.Find("PhonePrefab(Clone)")).GetComponent<PlayerPhone>();
			component.SetPhoneLocalModelActive();
			component.SetPhoneServerModelActive();
		}

		[HarmonyPatch("KillPlayerClientRpc")]
		[HarmonyPostfix]
		private static void PlayerDeath(ref PlayerControllerB __instance, int playerId, bool spawnBody, Vector3 bodyVelocity, int causeOfDeath, int deathAnimation)
		{
			PlayerPhone component = ((Component)((Component)__instance).transform.Find("PhonePrefab(Clone)")).GetComponent<PlayerPhone>();
			component.Death(causeOfDeath);
		}

		[HarmonyPatch("SpawnDeadBody")]
		[HarmonyPostfix]
		private static void PlayerSpawnBody(ref PlayerControllerB __instance, int playerId, Vector3 bodyVelocity, int causeOfDeath, PlayerControllerB deadPlayerController, int deathAnimation = 0, Transform overridePosition = null)
		{
			PlayerPhone component = ((Component)((Component)__instance).transform.Find("PhonePrefab(Clone)")).GetComponent<PlayerPhone>();
			component.ApplyCorpse();
		}

		private static void OnTogglePhoneKeyPressed(CallbackContext context)
		{
			if (!((Object)(object)PhoneManager == (Object)null) && !((Object)(object)PhoneManager.localPhone == (Object)null))
			{
				PlayerControllerB player = PhoneManager.localPhone.player;
				if (!((Object)(object)player == (Object)null) && !player.quickMenuManager.isMenuOpen && !player.isGrabbingObjectAnimation && !player.isTypingChat && !player.inTerminalMenu && !player.throwingObject && !player.IsInspectingItem)
				{
					PhoneManager.localPhone.ToggleActive(!PhoneManager.localPhone.toggled);
				}
			}
		}

		private static void OnPickupPhoneKeyPressed(CallbackContext context)
		{
			if (!((Object)(object)PhoneManager == (Object)null) && !((Object)(object)PhoneManager.localPhone == (Object)null))
			{
				PlayerControllerB player = PhoneManager.localPhone.player;
				if (!((Object)(object)player == (Object)null) && !player.quickMenuManager.isMenuOpen && !player.isGrabbingObjectAnimation && !player.isTypingChat && !player.inTerminalMenu && !player.throwingObject && !player.IsInspectingItem)
				{
					PhoneManager.localPhone.CallButtonPressed();
				}
			}
		}

		private static void OnHangupPhoneKeyPressed(CallbackContext context)
		{
			if (!((Object)(object)PhoneManager == (Object)null) && !((Object)(object)PhoneManager.localPhone == (Object)null))
			{
				PlayerControllerB player = PhoneManager.localPhone.player;
				if (!((Object)(object)player == (Object)null) && !player.quickMenuManager.isMenuOpen && !player.isGrabbingObjectAnimation && !player.isTypingChat && !player.inTerminalMenu && !player.throwingObject && !player.IsInspectingItem)
				{
					PhoneManager.localPhone.HangupButtonPressed();
				}
			}
		}

		private static void OnVolumePhoneKeyPressed(CallbackContext context)
		{
			PlayerControllerB player = PhoneManager.localPhone.player;
			if (!((Object)(object)player == (Object)null) && !player.quickMenuManager.isMenuOpen && !player.isGrabbingObjectAnimation && !player.isTypingChat && !player.inTerminalMenu && !player.throwingObject && !player.IsInspectingItem)
			{
				PhoneManager.localPhone.VolumeButtonPressed();
			}
		}

		[HarmonyPatch("ActivateItem_performed")]
		[HarmonyPrefix]
		private static bool ActivateItem_performed(ref PlayerControllerB __instance)
		{
			if ((!((NetworkBehaviour)__instance).IsOwner || !__instance.isPlayerControlled || (((NetworkBehaviour)__instance).IsServer && !__instance.isHostPlayerObject)) && !__instance.isTestingPlayer)
			{
				return true;
			}
			if (PhoneManager.localPhone.toggled)
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch("InspectItem_performed")]
		[HarmonyPrefix]
		private static bool InspectItem_performed(ref PlayerControllerB __instance)
		{
			if ((!((NetworkBehaviour)__instance).IsOwner || !__instance.isPlayerControlled || (((NetworkBehaviour)__instance).IsServer && !__instance.isHostPlayerObject)) && !__instance.isTestingPlayer)
			{
				return true;
			}
			if (PhoneManager.localPhone.toggled)
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch("QEItemInteract_performed")]
		[HarmonyPrefix]
		private static bool QEItemInteract_performed(ref PlayerControllerB __instance)
		{
			if ((!((NetworkBehaviour)__instance).IsOwner || !__instance.isPlayerControlled || (((NetworkBehaviour)__instance).IsServer && !__instance.isHostPlayerObject)) && !__instance.isTestingPlayer)
			{
				return true;
			}
			if (PhoneManager.localPhone.toggled)
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch("ItemSecondaryUse_performed")]
		[HarmonyPrefix]
		private static bool ItemSecondaryUse_performed(ref PlayerControllerB __instance)
		{
			if ((!((NetworkBehaviour)__instance).IsOwner || !__instance.isPlayerControlled || (((NetworkBehaviour)__instance).IsServer && !__instance.isHostPlayerObject)) && !__instance.isTestingPlayer)
			{
				return true;
			}
			if (PhoneManager.localPhone.toggled)
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch("ItemTertiaryUse_performed")]
		[HarmonyPrefix]
		private static bool ItemTertiaryUse_performed(ref PlayerControllerB __instance)
		{
			if ((!((NetworkBehaviour)__instance).IsOwner || !__instance.isPlayerControlled || (((NetworkBehaviour)__instance).IsServer && !__instance.isHostPlayerObject)) && !__instance.isTestingPlayer)
			{
				return true;
			}
			if (PhoneManager.localPhone.toggled)
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch("Interact_performed")]
		[HarmonyPostfix]
		private static void Interact_performed(ref PlayerControllerB __instance)
		{
			if (((((NetworkBehaviour)__instance).IsOwner && __instance.isPlayerControlled && (!((NetworkBehaviour)__instance).IsServer || __instance.isHostPlayerObject)) || __instance.isTestingPlayer) && PhoneManager.localPhone.toggled && __instance.inTerminalMenu)
			{
				PhoneManager.localPhone.ToggleActive(active: false);
			}
		}

		[HarmonyPatch("GrabObjectClientRpc")]
		[HarmonyPostfix]
		private static void GrabObjectClientRpc(ref PlayerControllerB __instance, bool grabValidated, NetworkObjectReference grabbedObject)
		{
			if (((((NetworkBehaviour)__instance).IsOwner && __instance.isPlayerControlled && (!((NetworkBehaviour)__instance).IsServer || __instance.isHostPlayerObject)) || __instance.isTestingPlayer) && PhoneManager.localPhone.toggled)
			{
				PhoneManager.localPhone.ToggleActive(active: false);
			}
		}

		[HarmonyPatch("ScrollMouse_performed")]
		[HarmonyPostfix]
		private static void ScrollMouse_performed(ref PlayerControllerB __instance)
		{
			if (((((NetworkBehaviour)__instance).IsOwner && __instance.isPlayerControlled && (!((NetworkBehaviour)__instance).IsServer || __instance.isHostPlayerObject)) || __instance.isTestingPlayer) && PhoneManager.localPhone.toggled && __instance.isHoldingObject)
			{
				PhoneManager.localPhone.ToggleActive(active: false);
			}
		}
	}
	[HarmonyPatch(typeof(ShipTeleporter))]
	public class ShipTeleporterPhonePatch
	{
		[HarmonyPatch("TeleportPlayerOutWithInverseTeleporter")]
		[HarmonyPostfix]
		private static void InverseTeleported(ref ShipTeleporter __instance, int playerObj, Vector3 teleportPos)
		{
			PlayerControllerB val = StartOfRound.Instance.allPlayerScripts[playerObj];
			if (!((Object)(object)val == (Object)null) && ((NetworkBehaviour)val).IsLocalPlayer)
			{
				PlayerPhone localPhone = PhoneNetworkHandler.Instance.localPhone;
				if ((Object)(object)localPhone != (Object)null)
				{
					localPhone.InfluenceConnectionQuality(-1f);
				}
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	public class StartOfRoundPhonePatch
	{
		private static float updateInterval;

		private static List<AudioSource> sortedSources = new List<AudioSource>();

		[HarmonyPatch("ReviveDeadPlayers")]
		[HarmonyPostfix]
		private static void ResetPhones(ref StartOfRound __instance)
		{
			PlayerPhone[] array = Object.FindObjectsByType<PlayerPhone>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			for (int i = 0; i < array.Length; i++)
			{
				array[i].Revive();
			}
			PhoneNetworkHandler.Instance.localPhone.ToggleActive(active: false);
		}

		[HarmonyPatch("OnPlayerDC")]
		[HarmonyPrefix]
		private static void CleanupPlayerPhone(ref StartOfRound __instance, int playerObjectNumber, ulong clientId)
		{
			PhoneNetworkHandler.Instance.DeletePlayerPhone(playerObjectNumber);
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void Update(ref StartOfRound __instance)
		{
			if (updateInterval >= 0f)
			{
				updateInterval -= Time.deltaTime;
				return;
			}
			updateInterval = 1f;
			AudioSource[] array = Object.FindObjectsByType<AudioSource>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			sortedSources = new List<AudioSource>();
			for (int i = 0; i < array.Length; i++)
			{
				if (array[i].spatialBlend != 0f)
				{
					sortedSources.Add(array[i]);
				}
			}
		}

		public static List<AudioSource> GetAllAudioSourcesInRange(Vector3 position)
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: 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)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			List<AudioSource> list = new List<AudioSource>();
			PlayerControllerB val = StartOfRound.Instance.localPlayerController;
			if (val.isPlayerDead)
			{
				val = val.spectatedPlayerScript;
			}
			if ((Object)(object)val != (Object)null && sortedSources.Count > 0)
			{
				for (int i = 0; i < sortedSources.Count; i++)
				{
					if (Object.op_Implicit((Object)(object)sortedSources[i]))
					{
						Vector3 val2 = position - ((Component)sortedSources[i]).transform.position;
						float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
						val2 = ((Component)val).transform.position - ((Component)sortedSources[i]).transform.position;
						float sqrMagnitude2 = ((Vector3)(ref val2)).sqrMagnitude;
						val2 = ((Component)val).transform.position - position;
						float sqrMagnitude3 = ((Vector3)(ref val2)).sqrMagnitude;
						if (sqrMagnitude3 > Config.recordingStartDist.Value * Config.recordingStartDist.Value && sqrMagnitude < sortedSources[i].maxDistance * sortedSources[i].maxDistance && sqrMagnitude < sqrMagnitude2)
						{
							list.Add(sortedSources[i]);
						}
					}
				}
			}
			return list;
		}
	}
}
namespace Scoops.misc
{
	public class HoardingPhone : PhoneBehavior
	{
		public HoarderBugAI bug;

		public GameObject serverPhoneModel;

		private float chitterInterval = 0f;

		private float randomChitterTime = 3f;

		private bool preppingCall = false;

		private bool preppingPickup = false;

		private IEnumerator activePickupDelayCoroutine;

		private IEnumerator activeCallDelayCoroutine;

		private IEnumerator activeCallTimeoutCoroutine;

		public override void Start()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			base.Start();
			bug = ((Component)((Component)this).transform.parent).GetComponent<HoarderBugAI>();
			ringAudio = ((Component)this).GetComponent<AudioSource>();
			GameObject val = (GameObject)Plugin.LethalPhoneAssets.LoadAsset("BugServerPhoneModel");
			serverPhoneModel = Object.Instantiate<GameObject>(val, bug.animationContainer.Find("Armature").Find("Abdomen").Find("Chest")
				.Find("Head")
				.Find("Bone.03")
				.Find("Bone.04")
				.Find("Bone.04_end"), false);
		}

		public void Death()
		{
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			HoardingBugPhonePatch.phoneBugs--;
			if (activePhoneRingCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(activePhoneRingCoroutine);
			}
			if (activePickupDelayCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(activePickupDelayCoroutine);
			}
			if (activeCallDelayCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(activeCallDelayCoroutine);
			}
			if (activeCallTimeoutCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(activeCallTimeoutCoroutine);
			}
			if (((NetworkBehaviour)this).IsOwner)
			{
				if (activeCall != null)
				{
					PhoneNetworkHandler.Instance.HangUpCallServerRpc(activeCall, ((NetworkBehaviour)this).NetworkObjectId);
					activeCall = null;
					StartOfRound.Instance.UpdatePlayerVoiceEffects();
				}
				if (outgoingCall != null)
				{
					PhoneNetworkHandler.Instance.HangUpCallServerRpc(outgoingCall, ((NetworkBehaviour)this).NetworkObjectId);
					outgoingCall = null;
				}
				if (incomingCall != null)
				{
					PhoneNetworkHandler.Instance.HangUpCallServerRpc(incomingCall, ((NetworkBehaviour)this).NetworkObjectId);
					incomingCall = null;
				}
				PhoneNetworkHandler.Instance.RemoveNumber(phoneNumber);
			}
		}

		public override void Update()
		{
			if (((NetworkBehaviour)this).IsOwner && !((EnemyAI)bug).isEnemyDead && outgoingCall == null && activeCall == null)
			{
				if (incomingCall == null)
				{
					if (!preppingCall)
					{
						activeCallDelayCoroutine = CallDelayCoroutine(Random.Range(Config.minPhoneBugInterval.Value, Config.maxPhoneBugInterval.Value));
						((MonoBehaviour)this).StartCoroutine(activeCallDelayCoroutine);
					}
				}
				else if (!preppingPickup)
				{
					activePickupDelayCoroutine = PickupDelayCoroutine(2f);
					((MonoBehaviour)this).StartCoroutine(activePickupDelayCoroutine);
				}
			}
			if (activeCall != null)
			{
				if (chitterInterval >= randomChitterTime)
				{
					chitterInterval = 0f;
					randomChitterTime = Random.Range(4f, 8f);
					RoundManager.PlayRandomClip(((EnemyAI)bug).creatureVoice, bug.chitterSFX, true, 1f, 0, 1000);
				}
				else
				{
					chitterInterval += Time.deltaTime;
				}
			}
			base.Update();
		}

		private IEnumerator PickupDelayCoroutine(float time)
		{
			preppingPickup = true;
			yield return (object)new WaitForSeconds(time);
			if (incomingCall != null && outgoingCall == null && activeCall == null && !((EnemyAI)bug).isEnemyDead)
			{
				activeCall = incomingCall;
				activeCaller = incomingCaller;
				incomingCall = null;
				PhoneNetworkHandler.Instance.AcceptIncomingCallServerRpc(activeCall, ((NetworkBehaviour)this).NetworkObjectId);
				StopRingingServerRpc();
				PlayPickupSoundServerRpc();
				UpdateCallValues();
			}
			preppingPickup = false;
		}

		private IEnumerator CallDelayCoroutine(float time)
		{
			preppingCall = true;
			yield return (object)new WaitForSeconds(time);
			if (incomingCall == null && outgoingCall == null && activeCall == null && !((EnemyAI)bug).isEnemyDead)
			{
				CallRandomNumber();
				if (outgoingCall != null)
				{
					activeCallTimeoutCoroutine = CallTimeoutCoroutine(outgoingCall);
					((MonoBehaviour)this).StartCoroutine(activeCallTimeoutCoroutine);
					UpdateCallValues();
				}
			}
			preppingCall = false;
		}

		private IEnumerator CallTimeoutCoroutine(string number)
		{
			yield return (object)new WaitForSeconds(14f);
			if (outgoingCall == number)
			{
				PhoneNetworkHandler.Instance.HangUpCallServerRpc(outgoingCall, ((NetworkBehaviour)this).NetworkObjectId);
				outgoingCall = null;
				UpdateCallValues();
			}
		}

		public void UpdateCallValues()
		{
			UpdateCallValuesServerRpc((outgoingCall == null) ? (-1) : int.Parse(outgoingCall), (incomingCall == null) ? (-1) : int.Parse(incomingCall), (activeCall == null) ? (-1) : int.Parse(activeCall), incomingCaller, activeCaller);
		}

		[ServerRpc]
		public void UpdateCallValuesServerRpc(int outgoingCallUpdate, int incomingCallUpdate, int activeCallUpdate, ulong incomingCallerUpdate, ulong activeCallerUpdate)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Invalid comparison between Unknown and I4
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: 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_00d1: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Invalid comparison between Unknown and I4
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				if (((NetworkBehaviour)this).OwnerClientId != networkManager.LocalClientId)
				{
					if ((int)networkManager.LogLevel <= 1)
					{
						Debug.LogError((object)"Only the owner can invoke a ServerRpc that requires ownership!");
					}
					return;
				}
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1512617338u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, outgoingCallUpdate);
				BytePacker.WriteValueBitPacked(val2, incomingCallUpdate);
				BytePacker.WriteValueBitPacked(val2, activeCallUpdate);
				BytePacker.WriteValueBitPacked(val2, incomingCallerUpdate);
				BytePacker.WriteValueBitPacked(val2, activeCallerUpdate);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1512617338u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				UpdateCallValuesClientRpc(outgoingCallUpdate, incomingCallUpdate, activeCallUpdate, incomingCallerUpdate, activeCallerUpdate);
			}
		}

		[ClientRpc]
		public void UpdateCallValuesClientRpc(int outgoingCallUpdate, int incomingCallUpdate, int activeCallUpdate, ulong incomingCallerUpdate, ulong activeCallerUpdate)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: 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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2549375854u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, outgoingCallUpdate);
					BytePacker.WriteValueBitPacked(val2, incomingCallUpdate);
					BytePacker.WriteValueBitPacked(val2, activeCallUpdate);
					BytePacker.WriteValueBitPacked(val2, incomingCallerUpdate);
					BytePacker.WriteValueBitPacked(val2, activeCallerUpdate);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2549375854u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					outgoingCall = ((outgoingCallUpdate == -1) ? null : outgoingCallUpdate.ToString("D4"));
					incomingCall = ((incomingCallUpdate == -1) ? null : incomingCallUpdate.ToString("D4"));
					activeCall = ((activeCallUpdate == -1) ? null : activeCallUpdate.ToString("D4"));
					incomingCaller = incomingCallerUpdate;
					activeCaller = activeCallerUpdate;
				}
			}
		}

		public override void ApplyPhoneVoiceEffect(float distance = 0f, float listeningDistance = 0f, float listeningAngle = 0f, float connectionQuality = 1f)
		{
			if (!((Object)(object)bug == (Object)null) && !((Object)(object)((EnemyAI)bug).creatureVoice == (Object)null))
			{
				AudioSource creatureVoice = ((EnemyAI)bug).creatureVoice;
				AudioLowPassFilter component = ((Component)creatureVoice).GetComponent<AudioLowPassFilter>();
				AudioHighPassFilter component2 = ((Component)creatureVoice).GetComponent<AudioHighPassFilter>();
				OccludeAudio component3 = ((Component)creatureVoice).GetComponent<OccludeAudio>();
				component3.overridingLowPass = true;
				creatureVoice.volume = 1f;
				creatureVoice.spatialBlend = 0f;
				creatureVoice.bypassListenerEffects = false;
				creatureVoice.bypassEffects = false;
				creatureVoice.panStereo = (GameNetworkManager.Instance.localPlayerController.isPlayerDead ? 0f : (-0.4f));
				component3.lowPassOverride = Mathf.Lerp(6000f, 3000f, connectionQuality);
				if ((Object)(object)component != (Object)null)
				{
					((Behaviour)component).enabled = true;
					component.lowpassResonanceQ = Mathf.Lerp(6f, 3f, connectionQuality);
				}
				if ((Object)(object)component2 != (Object)null)
				{
					((Behaviour)component2).enabled = true;
					component2.highpassResonanceQ = Mathf.Lerp(3f, 1f, connectionQuality);
				}
				if (distance != 0f)
				{
					float num = Mathf.InverseLerp(Config.backgroundVoiceDist.Value, 0f, distance);
					creatureVoice.volume *= num;
					component3.lowPassOverride = 1500f;
				}
				if (listeningDistance != 0f)
				{
					float num2 = Mathf.InverseLerp(Config.eavesdropDist.Value, 0f, listeningDistance);
					creatureVoice.volume *= num2;
					component3.lowPassOverride = 750f;
					creatureVoice.panStereo = listeningAngle;
				}
				creatureVoice.volume += Config.voiceSoundMod.Value;
				if ((staticMode && hardStatic) || ((EnemyAI)bug).isEnemyDead)
				{
					creatureVoice.volume = 0f;
				}
			}
		}

		public override void RemovePhoneVoiceEffect()
		{
			if (!((Object)(object)bug == (Object)null) && !((Object)(object)((EnemyAI)bug).creatureVoice == (Object)null))
			{
				AudioSource creatureVoice = ((EnemyAI)bug).creatureVoice;
				AudioLowPassFilter component = ((Component)creatureVoice).GetComponent<AudioLowPassFilter>();
				AudioHighPassFilter component2 = ((Component)creatureVoice).GetComponent<AudioHighPassFilter>();
				OccludeAudio component3 = ((Component)creatureVoice).GetComponent<OccludeAudio>();
				component3.overridingLowPass = false;
				creatureVoice.volume = 1f;
				creatureVoice.spatialBlend = 1f;
				creatureVoice.bypassListenerEffects = false;
				creatureVoice.bypassEffects = false;
				creatureVoice.panStereo = 0f;
				if ((Object)(object)component != (Object)null)
				{
					((Behaviour)component).enabled = true;
					component.lowpassResonanceQ = 1f;
				}
				if ((Object)(object)component2 != (Object)null)
				{
					((Behaviour)component2).enabled = false;
					component2.highpassResonanceQ = 1f;
				}
			}
		}

		protected override void __initializeVariables()
		{
			base.__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_HoardingPhone()
		{
			//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
			NetworkManager.__rpc_func_table.Add(1512617338u, new RpcReceiveHandler(__rpc_handler_1512617338));
			NetworkManager.__rpc_func_table.Add(2549375854u, new RpcReceiveHandler(__rpc_handler_2549375854));
		}

		private static void __rpc_handler_1512617338(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: 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_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: 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)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: 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_0055: Invalid comparison between Unknown and I4
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if (rpcParams.Server.Receive.SenderClientId != target.OwnerClientId)
			{
				if ((int)networkManager.LogLevel <= 1)
				{
					Debug.LogError((object)"Only the owner can invoke a ServerRpc that requires ownership!");
				}
				return;
			}
			int outgoingCallUpdate = default(int);
			ByteUnpacker.ReadValueBitPacked(reader, ref outgoingCallUpdate);
			int incomingCallUpdate = default(int);
			ByteUnpacker.ReadValueBitPacked(reader, ref incomingCallUpdate);
			int activeCallUpdate = default(int);
			ByteUnpacker.ReadValueBitPacked(reader, ref activeCallUpdate);
			ulong incomingCallerUpdate = default(ulong);
			ByteUnpacker.ReadValueBitPacked(reader, ref incomingCallerUpdate);
			ulong activeCallerUpdate = default(ulong);
			ByteUnpacker.ReadValueBitPacked(reader, ref activeCallerUpdate);
			target.__rpc_exec_stage = (__RpcExecStage)1;
			((HoardingPhone)(object)target).UpdateCallValuesServerRpc(outgoingCallUpdate, incomingCallUpdate, activeCallUpdate, incomingCallerUpdate, activeCallerUpdate);
			target.__rpc_exec_stage = (__RpcExecStage)0;
		}

		private static void __rpc_handler_2549375854(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_004a: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int outgoingCallUpdate = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref outgoingCallUpdate);
				int incomingCallUpdate = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref incomingCallUpdate);
				int activeCallUpdate = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref activeCallUpdate);
				ulong incomingCallerUpdate = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref incomingCallerUpdate);
				ulong activeCallerUpdate = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref activeCallerUpdate);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((HoardingPhone)(object)target).UpdateCallValuesClientRpc(outgoingCallUpdate, incomingCallUpdate, activeCallUpdate, incomingCallerUpdate, activeCallerUpdate);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "HoardingPhone";
		}
	}
	public class PhoneBehavior : NetworkBehaviour
	{
		public string phoneNumber;

		public bool spectatorClear = false;

		public ulong activeCaller = 0uL;

		public ulong incomingCaller = 0uL;

		protected AudioSource ringAudio;

		protected AudioSource thisAudio;

		protected AudioSource target;

		protected string incomingCall = null;

		protected string activeCall = null;

		protected string outgoingCall = null;

		protected List<AudioSource> untrackedAudioSources = new List<AudioSource>();

		protected List<AudioSourceStorage> audioSourcesInRange = new List<AudioSourceStorage>();

		protected HashSet<PhoneBehavior> modifiedVoices = new HashSet<PhoneBehavior>();

		protected Queue<int> dialedNumbers = new Queue<int>(4);

		protected float updateInterval;

		protected float connectionInterval = 0f;

		protected bool staticMode = false;

		protected bool hardStatic = false;

		protected float staticChance = 0f;

		public float targetConnectionQuality = 1f;

		public float currentConnectionQuality = 1f;

		public NetworkVariable<float> connectionQuality = new NetworkVariable<float>(1f, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);

		protected IEnumerator activePhoneRingCoroutine;

		public virtual void Start()
		{
			thisAudio = ((Component)this).GetComponent<AudioSource>();
			target = ((Component)((Component)this).transform.Find("Target")).gameObject.GetComponent<AudioSource>();
			GetAllAudioSourcesToUpdate();
		}

		public virtual void Update()
		{
			if (activeCall == null || spectatorClear)
			{
				if (!spectatorClear)
				{
					activeCaller = 0uL;
				}
				staticChance = 0f;
				if (target.isPlaying)
				{
					target.Stop();
				}
				if (audioSourcesInRange.Count > 0)
				{
					foreach (AudioSourceStorage item in audioSourcesInRange)
					{
						item.Reset();
					}
					audioSourcesInRange.Clear();
				}
				if (modifiedVoices.Count > 0)
				{
					foreach (PhoneBehavior modifiedVoice in modifiedVoices)
					{
						modifiedVoice.RemovePhoneVoiceEffect();
					}
					modifiedVoices.Clear();
				}
				spectatorClear = false;
			}
			GetAllAudioSourcesToUpdate();
			UpdateAllAudioSources();
			UpdatePlayerVoices();
			if (((NetworkBehaviour)this).IsOwner)
			{
				if (connectionInterval >= 0.75f)
				{
					connectionInterval = 0f;
					ManageConnectionQuality();
				}
				else
				{
					connectionInterval += Time.deltaTime;
				}
				if (updateInterval >= 0f)
				{
					updateInterval -= Time.deltaTime;
					return;
				}
				updateInterval = 1f;
				UpdateConnectionQualityServerRpc(currentConnectionQuality);
			}
		}

		public void CallRandomNumber()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			string randomExistingPhoneNumber = GetRandomExistingPhoneNumber();
			if (randomExistingPhoneNumber != null && !(randomExistingPhoneNumber == ""))
			{
				outgoingCall = randomExistingPhoneNumber;
				PhoneNetworkHandler.Instance.MakeOutgoingCallServerRpc(randomExistingPhoneNumber, ((NetworkBehaviour)this).NetworkObjectId);
			}
		}

		public string GetRandomExistingPhoneNumber()
		{
			PhoneBehavior[] array = Object.FindObjectsByType<PhoneBehavior>((FindObjectsInactive)0, (FindObjectsSortMode)0);
			List<PhoneBehavior> list = new List<PhoneBehavior>();
			for (int i = 0; i < array.Length; i++)
			{
				if ((Object)(object)array[i] != (Object)(object)this && array[i].phoneNumber != null && array[i].phoneNumber != "")
				{
					list.Add(array[i]);
				}
			}
			if (list.Count > 0)
			{
				PhoneBehavior phoneBehavior = list[Random.Range(0, list.Count)];
				return phoneBehavior.phoneNumber;
			}
			return null;
		}

		protected virtual void GetAllAudioSourcesToUpdate()
		{
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: 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)
			if ((Object)(object)PhoneNetworkHandler.Instance.localPhone == (Object)null || activeCall == null || activeCaller == 0)
			{
				return;
			}
			PhoneBehavior component = ((Component)((NetworkBehaviour)this).GetNetworkObject(activeCaller)).GetComponent<PhoneBehavior>();
			if ((Object)(object)component == (Object)null)
			{
				return;
			}
			if ((Object)(object)component != (Object)(object)PhoneNetworkHandler.Instance.localPhone && !component.IsBeingSpectated())
			{
				PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
				Vector3 val = ((Component)localPlayerController).transform.position - ((Component)component).transform.position;
				float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
				if (sqrMagnitude > Config.eavesdropDist.Value * Config.eavesdropDist.Value)
				{
					return;
				}
			}
			untrackedAudioSources = StartOfRoundPhonePatch.GetAllAudioSourcesInRange(((Component)this).transform.position);
			foreach (AudioSource untrackedAudioSource in untrackedAudioSources)
			{
				if ((Object)(object)untrackedAudioSource != (Object)null && untrackedAudioSource.spatialBlend != 0f)
				{
					AudioSourceStorage audioSourceStorage = new AudioSourceStorage(untrackedAudioSource);
					audioSourceStorage.InitAudio();
					audioSourcesInRange.Add(audioSourceStorage);
				}
			}
		}

		protected virtual void UpdateAllAudioSources()
		{
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: 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_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)PhoneNetworkHandler.Instance.localPhone == (Object)null || (Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null || activeCall == null || activeCaller == 0)
			{
				return;
			}
			PhoneBehavior component = ((Component)((NetworkBehaviour)this).GetNetworkObject(activeCaller)).GetComponent<PhoneBehavior>();
			if ((Object)(object)component == (Object)null)
			{
				return;
			}
			float num = 0f;
			float listenAngle = 0f;
			if ((Object)(object)component != (Object)(object)PhoneNetworkHandler.Instance.localPhone && !component.IsBeingSpectated())
			{
				PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
				num = Vector3.Distance(((Component)localPlayerController).transform.position, ((Component)component).transform.position);
				if (num > Config.eavesdropDist.Value)
				{
					return;
				}
				Vector3 val = ((Component)component).transform.position - ((Component)localPlayerController).transform.position;
				val /= num;
				listenAngle = Vector3.Dot(val, ((Component)localPlayerController).transform.right);
			}
			float callQuality = ((component.connectionQuality.Value < connectionQuality.Value) ? component.connectionQuality.Value : connectionQuality.Value);
			for (int num2 = audioSourcesInRange.Count - 1; num2 >= 0; num2--)
			{
				AudioSourceStorage audioSourceStorage = audioSourcesInRange[num2];
				AudioSource audioSource = audioSourceStorage.audioSource;
				if ((Object)(object)audioSource != (Object)null)
				{
					float num3 = Vector3.Distance(((Component)audioSource).transform.position, ((Component)component).transform.position);
					Vector3 val2 = ((Component)audioSource).transform.position - ((Component)this).transform.position;
					float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
					val2 = ((Component)component).transform.position - ((Component)this).transform.position;
					float sqrMagnitude2 = ((Vector3)(ref val2)).sqrMagnitude;
					if (sqrMagnitude2 <= Config.recordingStartDist.Value * Config.recordingStartDist.Value || num3 * num3 < sqrMagnitude || sqrMagnitude > audioSource.maxDistance * audioSource.maxDistance)
					{
						audioSourceStorage.Reset();
						audioSourcesInRange.RemoveAt(num2);
					}
					else
					{
						audioSourceStorage.ApplyPhone(sqrMagnitude, callQuality, num, listenAngle, staticMode && hardStatic);
					}
				}
				else
				{
					audioSourcesInRange.RemoveAt(num2);
				}
			}
		}

		protected virtual bool IsBeingSpectated()
		{
			return false;
		}

		protected virtual void UpdatePlayerVoices()
		{
			//IL_00b9: 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_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: 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_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)GameNetworkManager.Instance == (Object)null || (Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null || activeCaller == 0L || activeCall == null || (((NetworkBehaviour)this).IsOwner && (Object)(object)this != (Object)(object)PhoneNetworkHandler.Instance.localPhone))
			{
				return;
			}
			float num = 0f;
			float listeningAngle = 0f;
			if (!((NetworkBehaviour)this).IsOwner && !IsBeingSpectated())
			{
				PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
				num = Vector3.Distance(((Component)localPlayerController).transform.position, ((Component)this).transform.position);
				if (num > Config.eavesdropDist.Value)
				{
					return;
				}
				Vector3 val = ((Component)this).transform.position - ((Component)localPlayerController).transform.position;
				val /= num;
				listeningAngle = Vector3.Dot(val, ((Component)localPlayerController).transform.right);
			}
			PhoneBehavior component = ((Component)((NetworkBehaviour)this).GetNetworkObject(activeCaller)).GetComponent<PhoneBehavior>();
			if ((Object)(object)component == (Object)(object)PhoneNetworkHandler.Instance.localPhone)
			{
				return;
			}
			float quality = ((component.connectionQuality.Value < connectionQuality.Value) ? component.connectionQuality.Value : connectionQuality.Value);
			if (((NetworkBehaviour)this).IsOwner || num > 0f)
			{
				UpdateStatic(quality, num);
			}
			float num2 = Vector3.Distance(((Component)component).transform.position, ((Component)this).transform.position);
			if (num2 > Config.recordingStartDist.Value)
			{
				modifiedVoices.Add(component);
				component.ApplyPhoneVoiceEffect(0f, num, listeningAngle, quality);
			}
			else if (modifiedVoices.Contains(component))
			{
				modifiedVoices.Remove(component);
				component.RemovePhoneVoiceEffect();
			}
			for (int i = 0; i < StartOfRound.Instance.allPlayerScripts.Length; i++)
			{
				PlayerControllerB val2 = StartOfRound.Instance.allPlayerScripts[i];
				PlayerPhone component2 = ((Component)((Component)val2).transform.Find("PhonePrefab(Clone)")).GetComponent<PlayerPhone>();
				if ((Object)(object)val2 != (Object)null && (Object)(object)component2 != (Object)null && val2.isPlayerControlled && !val2.isPlayerDead && !((NetworkBehaviour)val2).IsLocalPlayer && (Object)(object)val2 != (Object)(object)GameNetworkManager.Instance.localPlayerController && (Object)(object)component2 != (Object)(object)this && (Object)(object)component2 != (Object)(object)component)
				{
					float num3 = Vector3.Distance(((Component)component2).transform.position, ((Component)component).transform.position);
					Vector3 val3 = ((Component)component2).transform.position - ((Component)GameNetworkManager.Instance.localPlayerController).transform.position;
					float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude;
					if (sqrMagnitude > Config.recordingStartDist.Value * Config.recordingStartDist.Value && num3 < Config.backgroundVoiceDist.Value)
					{
						modifiedVoices.Add(component2);
						component2.ApplyPhoneVoiceEffect(num3, num, listeningAngle, quality);
					}
					else if (modifiedVoices.Contains(component2))
					{
						modifiedVoices.Remove(component2);
						component2.RemovePhoneVoiceEffect();
					}
				}
			}
		}

		protected virtual void UpdateCallingUI()
		{
		}

		public virtual bool PhoneInsideFactory()
		{
			return true;
		}

		public virtual bool PhoneInsideShip()
		{
			return false;
		}

		public void InfluenceConnectionQuality(float change)
		{
			currentConnectionQuality = Mathf.Clamp01(currentConnectionQuality + change);
		}

		protected virtual void ManageConnectionQuality()
		{
			//IL_002f: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: 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_0175: Unknown result type (might be due to invalid IL or missing references)
			targetConnectionQuality = 1f;
			LevelWeatherType[] array = new LevelWeatherType[4];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			LevelWeatherType[] source = (LevelWeatherType[])(object)array;
			LevelWeatherType[] source2 = (LevelWeatherType[])(object)new LevelWeatherType[1] { (LevelWeatherType)2 };
			if (source.Contains(TimeOfDay.Instance.currentLevelWeather))
			{
				targetConnectionQuality -= 0.25f;
			}
			if (source2.Contains(TimeOfDay.Instance.currentLevelWeather))
			{
				targetConnectionQuality -= 0.5f;
			}
			if (PhoneInsideFactory())
			{
				targetConnectionQuality -= 0.1f;
				float num = 300f;
				EntranceTeleport[] array2 = Object.FindObjectsOfType<EntranceTeleport>(false);
				for (int i = 0; i < array2.Length; i++)
				{
					if (!array2[i].isEntranceToBuilding)
					{
						float num2 = Vector3.Distance(((Component)array2[i]).transform.position, ((Component)this).transform.position);
						if (num2 < num)
						{
							num = num2;
						}
					}
				}
				targetConnectionQuality -= Mathf.Lerp(0f, 0.4f, Mathf.InverseLerp(0f, 300f, num));
				float num3 = 300f;
				LungProp[] array3 = Object.FindObjectsOfType<LungProp>(false);
				for (int j = 0; j < array3.Length; j++)
				{
					if (array3[j].isLungDocked)
					{
						float num4 = Vector3.Distance(((Component)array3[j]).transform.position, ((Component)this).transform.position);
						if (num4 < num3)
						{
							num3 = num4;
						}
					}
				}
				if (num3 <= 50f)
				{
					targetConnectionQuality -= Mathf.Lerp(0.4f, 0f, Mathf.InverseLerp(0f, 50f, num3));
				}
			}
			targetConnectionQuality = Mathf.Clamp01(targetConnectionQuality);
			if (targetConnectionQuality < currentConnectionQuality)
			{
				currentConnectionQuality = targetConnectionQuality;
			}
			else if (targetConnectionQuality > currentConnectionQuality)
			{
				currentConnectionQuality += 0.005f;
			}
			if (staticChance > 0f)
			{
				float num5 = Mathf.Lerp(0.15f, 0.85f, staticChance);
				staticMode = Random.Range(0f, 1f) < num5;
				hardStatic = Random.Range(0f, 1f) < num5;
			}
			else
			{
				staticMode = false;
				hardStatic = false;
			}
		}

		protected void UpdateStatic(float quality, float dist = 0f)
		{
			if (quality <= 0.5f)
			{
				staticChance = Mathf.InverseLerp(0.5f, 0f, quality);
				if (staticMode)
				{
					float num = 1f;
					if (dist != 0f)
					{
						num = Mathf.InverseLerp(Config.eavesdropDist.Value, 0f, dist);
						target.panStereo = 0f;
					}
					else
					{
						target.panStereo = -0.4f;
					}
					if (hardStatic)
					{
						((Component)target).GetComponent<AudioLowPassFilter>().cutoffFrequency = 2899f;
						target.volume = 1f * num;
					}
					else
					{
						((Component)target).GetComponent<AudioLowPassFilter>().cutoffFrequency = Mathf.Lerp(1000f, 2800f, staticChance);
						target.volume = Mathf.Clamp01(staticChance + 0.75f) * num;
					}
					if (!target.isPlaying)
					{
						switch (Random.Range(1, 4))
						{
						case 1:
							target.clip = PhoneAssetManager.phoneStaticOne;
							break;
						case 2:
							target.clip = PhoneAssetManager.phoneStaticTwo;
							break;
						case 3:
							target.clip = PhoneAssetManager.phoneStaticThree;
							break;
						}
						target.Play();
					}
				}
				else if (target.isPlaying)
				{
					target.Stop();