Decompiled source of CamOverhead v1.0.1

CamOverhead.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Experimental.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("OverheadCameraMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Sandbox testing with network sync.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("OverheadCameraMod")]
[assembly: AssemblyTitle("OverheadCameraMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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 OverheadCameraMod
{
	[BepInPlugin("com.professional.overheadcam", "Overhead WebCam Mod", "1.0.0")]
	public class OverheadCamPlugin : BaseUnityPlugin
	{
		public const string ModGUID = "com.professional.overheadcam";

		public const string ModName = "Overhead WebCam Mod";

		public const string ModVersion = "1.0.0";

		private readonly Harmony _harmony = new Harmony("com.professional.overheadcam");

		public static ConfigEntry<string> ConfigSelectedCamera;

		public static ConfigEntry<bool> ConfigShowLocalPreview;

		internal static ManualLogSource Log;

		private void Awake()
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			string[] array = WebCamTexture.devices.Select((WebCamDevice d) => ((WebCamDevice)(ref d)).name).ToArray();
			if (array.Length == 0)
			{
				array = new string[1] { "Aucune caméra" };
			}
			ConfigSelectedCamera = ((BaseUnityPlugin)this).Config.Bind<string>("1. Camera Settings", "Active Camera", array[0], new ConfigDescription("Select the webcam.", (AcceptableValueBase)(object)new AcceptableValueList<string>(array), Array.Empty<object>()));
			ConfigShowLocalPreview = ((BaseUnityPlugin)this).Config.Bind<bool>("2. Preferences", "Show Local Preview", true, new ConfigDescription("Toggle the visibility of your own overhead drone.", (AcceptableValueBase)null, Array.Empty<object>()));
			ConfigSelectedCamera.SettingChanged += delegate
			{
				SandboxPatches.RestartWebcam();
			};
			_harmony.PatchAll(typeof(SandboxPatches));
			Log.LogInfo((object)"=== OverheadCam: V2.0 DEPLOYED ===");
		}
	}
	public class LocalWebcamCropper : MonoBehaviour
	{
		private Renderer _renderer;

		private bool _isCropped;

		private void Start()
		{
			_renderer = ((Component)this).GetComponent<Renderer>();
		}

		private void Update()
		{
			//IL_00d3: 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)
			if (_isCropped || !((Object)(object)_renderer != (Object)null) || !((Object)(object)_renderer.material.mainTexture != (Object)null))
			{
				return;
			}
			Texture mainTexture = _renderer.material.mainTexture;
			if (mainTexture.width > 100 && mainTexture.height > 100)
			{
				float num = (float)mainTexture.width / (float)mainTexture.height;
				float num2 = 1f;
				float num3 = 1f;
				float num4 = 0f;
				float num5 = 0f;
				if (num > 1f)
				{
					num2 = 1f / num;
					num4 = (1f - num2) / 2f;
				}
				else if (num < 1f)
				{
					num3 = num;
					num5 = (1f - num3) / 2f;
				}
				_renderer.material.mainTextureScale = new Vector2(num2, num3);
				_renderer.material.mainTextureOffset = new Vector2(num4, num5);
				_isCropped = true;
			}
		}
	}
	public class IndependentDroneFollower : MonoBehaviour
	{
		public PlayerControllerB TargetPlayer;

		private bool _isFixedOnDeath;

		private Vector3 _deathPosition;

		private float _randomOffset;

		private Transform _cctvContainer;

		private Transform _shakeContainer;

		private Renderer _outlineRenderer;

		private FieldInfo _voiceStateField;

		private PropertyInfo _isSpeakingProp;

		private PropertyInfo _amplitudeProp;

		private float _currentSpin;

		private float _targetSpin;

		private float _spinCooldown;

		private void Start()
		{
			_randomOffset = Random.Range(0f, 100f);
			_voiceStateField = typeof(PlayerControllerB).GetField("voicePlayerState");
		}

		private void LateUpdate()
		{
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_0398: Unknown result type (might be due to invalid IL or missing references)
			//IL_039d: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: Unknown result type (might be due to invalid IL or missing references)
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0370: Unknown result type (might be due to invalid IL or missing references)
			//IL_0375: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_0414: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Unknown result type (might be due to invalid IL or missing references)
			//IL_042a: Unknown result type (might be due to invalid IL or missing references)
			//IL_042f: Unknown result type (might be due to invalid IL or missing references)
			//IL_043f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0449: Unknown result type (might be due to invalid IL or missing references)
			//IL_044e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0453: Unknown result type (might be due to invalid IL or missing references)
			//IL_0454: Unknown result type (might be due to invalid IL or missing references)
			//IL_0460: Unknown result type (might be due to invalid IL or missing references)
			//IL_0465: Unknown result type (might be due to invalid IL or missing references)
			//IL_046a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0477: Unknown result type (might be due to invalid IL or missing references)
			//IL_047c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0488: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)TargetPlayer == (Object)null)
			{
				return;
			}
			if ((Object)(object)_cctvContainer == (Object)null)
			{
				_cctvContainer = ((Component)this).transform.Find("CCTV_Container");
				if ((Object)(object)_cctvContainer != (Object)null)
				{
					_shakeContainer = _cctvContainer.Find("Shake_Container");
					if ((Object)(object)_shakeContainer != (Object)null)
					{
						Transform val = _shakeContainer.Find("Screen/Outline");
						if ((Object)(object)val != (Object)null)
						{
							_outlineRenderer = ((Component)val).GetComponent<Renderer>();
						}
					}
				}
			}
			if ((Object)(object)_cctvContainer != (Object)null && ((NetworkBehaviour)TargetPlayer).IsOwner)
			{
				((Component)_cctvContainer).gameObject.SetActive(OverheadCamPlugin.ConfigShowLocalPreview.Value);
			}
			if (!((NetworkBehaviour)TargetPlayer).IsOwner && !TargetPlayer.isPlayerDead)
			{
				bool flag = false;
				float num = 0f;
				try
				{
					if (_voiceStateField != null)
					{
						object value = _voiceStateField.GetValue(TargetPlayer);
						if (value != null)
						{
							if (_isSpeakingProp == null)
							{
								_isSpeakingProp = value.GetType().GetProperty("IsSpeaking");
							}
							if (_amplitudeProp == null)
							{
								_amplitudeProp = value.GetType().GetProperty("Amplitude");
							}
							flag = (bool)_isSpeakingProp.GetValue(value);
							num = (float)_amplitudeProp.GetValue(value);
						}
					}
				}
				catch
				{
				}
				if ((Object)(object)_outlineRenderer != (Object)null)
				{
					Color color = _outlineRenderer.material.color;
					float num2 = ((flag && num > 0.03f) ? 0.4f : 0f);
					color.a = Mathf.Lerp(color.a, num2, Time.deltaTime * 10f);
					_outlineRenderer.material.color = color;
					((Component)_outlineRenderer).gameObject.SetActive(color.a > 0.01f);
				}
				if ((Object)(object)_shakeContainer != (Object)null)
				{
					if (num > 0.08f)
					{
						float num3 = Mathf.Clamp((num - 0.08f) * 0.8f, 0f, 0.25f);
						_shakeContainer.localPosition = new Vector3(Random.Range(0f - num3, num3), Random.Range(0f - num3, num3), 0f);
					}
					else
					{
						_shakeContainer.localPosition = Vector3.Lerp(_shakeContainer.localPosition, Vector3.zero, Time.deltaTime * 20f);
					}
					if (num > 0.35f && Time.time > _spinCooldown)
					{
						_targetSpin += 360f;
						_spinCooldown = Time.time + 3f;
					}
					_currentSpin = Mathf.Lerp(_currentSpin, _targetSpin, Time.deltaTime * 5f);
					_shakeContainer.localRotation = Quaternion.Euler(0f, 0f, _currentSpin);
				}
			}
			float num4 = Mathf.Sin((Time.time + _randomOffset) * 1.5f) * 0.08f;
			if (TargetPlayer.isPlayerDead)
			{
				if (!_isFixedOnDeath)
				{
					_deathPosition = ((Component)this).transform.position - new Vector3(0f, num4, 0f);
					_isFixedOnDeath = true;
				}
				((Component)this).transform.position = _deathPosition + new Vector3(0f, num4, 0f);
				return;
			}
			_isFixedOnDeath = false;
			float num5 = (((NetworkBehaviour)TargetPlayer).IsOwner ? 3.5f : 2.8f);
			bool flag2 = TargetPlayer.isCrouching;
			if ((Object)(object)TargetPlayer.playerBodyAnimator != (Object)null)
			{
				flag2 = TargetPlayer.playerBodyAnimator.GetBool("crouching");
			}
			if (flag2)
			{
				num5 -= 1.2f;
			}
			Vector3 val2 = ((Component)TargetPlayer).transform.position + ((Component)TargetPlayer).transform.up * num5 + ((Component)TargetPlayer).transform.forward * 0.5f;
			val2 += new Vector3(0f, num4, 0f);
			((Component)this).transform.position = Vector3.Lerp(((Component)this).transform.position, val2, Time.deltaTime * 15f);
		}
	}
	public class CCTVEffects : MonoBehaviour
	{
		private GameObject _recLight;

		private Renderer _screenRenderer;

		private float _timer;

		private Color _cctvColor = new Color(0.75f, 0.92f, 0.82f, 1f);

		public void Setup(Renderer r)
		{
			_screenRenderer = r;
		}

		private void Start()
		{
			//IL_004d: 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_0090: 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_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Expected O, but got Unknown
			_recLight = GameObject.CreatePrimitive((PrimitiveType)0);
			Object.Destroy((Object)(object)_recLight.GetComponent<Collider>());
			_recLight.transform.SetParent(((Component)this).transform, false);
			_recLight.transform.localPosition = new Vector3(-0.33f, 0.33f, -0.02f);
			_recLight.transform.localScale = new Vector3(0.04f, 0.04f, 0.01f);
			_recLight.GetComponent<Renderer>().material = new Material(Shader.Find("Sprites/Default"))
			{
				color = Color.red
			};
		}

		private void Update()
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			_timer += Time.deltaTime;
			if ((Object)(object)_recLight != (Object)null)
			{
				_recLight.SetActive(Mathf.Sin(_timer * 5f) > 0f);
			}
			if ((Object)(object)_screenRenderer != (Object)null)
			{
				float num = Random.Range(0.98f, 1.02f);
				_screenRenderer.material.color = _cctvColor * num;
			}
		}
	}
	internal class SandboxPatches
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static HandleNamedMessageDelegate <0>__OnReceiveFrame;
		}

		public static WebCamTexture HardwareStream;

		private static Texture2D _sendBuffer;

		private static Texture2D _scanlineTex;

		private static Dictionary<ulong, GameObject> _playerDrones = new Dictionary<ulong, GameObject>();

		private static Dictionary<ulong, Texture2D> _remoteTextures = new Dictionary<ulong, Texture2D>();

		private static float _nextSendTime;

		private const string MSG_NAME = "OverheadCam_Networked";

		private static bool _networkRegistered = false;

		private static object _pixelLock = new object();

		private static bool _isEncoding = false;

		private static byte[] _finishedJpegData;

		public static void RestartWebcam()
		{
			CleanupResources();
			InitResources();
			if ((Object)(object)NetworkManager.Singleton != (Object)null && _playerDrones.TryGetValue(NetworkManager.Singleton.LocalClientId, out var value))
			{
				Transform val = value.transform.Find("CCTV_Container/Shake_Container/Screen");
				if ((Object)(object)val != (Object)null)
				{
					((Component)val).GetComponent<Renderer>().material.mainTexture = (Texture)(object)HardwareStream;
					Object.Destroy((Object)(object)((Component)val).GetComponent<LocalWebcamCropper>());
					((Component)val).gameObject.AddComponent<LocalWebcamCropper>();
				}
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "OnDestroy")]
		[HarmonyPostfix]
		private static void PostfixStartOfRoundDestroy()
		{
			CleanupResources();
		}

		[HarmonyPatch(typeof(StartOfRound), "Start")]
		[HarmonyPostfix]
		private static void PostfixStart()
		{
			CleanupResources();
			_finishedJpegData = null;
			_isEncoding = false;
			_networkRegistered = false;
		}

		[HarmonyPatch(typeof(PlayerControllerB), "Update")]
		[HarmonyPostfix]
		private static void PostfixUpdate(PlayerControllerB __instance)
		{
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Expected O, but got Unknown
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0312: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			bool flag = __instance.isPlayerControlled || __instance.isPlayerDead;
			if (!_networkRegistered)
			{
				NetworkManager singleton = NetworkManager.Singleton;
				if (((singleton != null) ? singleton.CustomMessagingManager : null) != null)
				{
					NetworkManager.Singleton.CustomMessagingManager.UnregisterNamedMessageHandler("OverheadCam_Networked");
					CustomMessagingManager customMessagingManager = NetworkManager.Singleton.CustomMessagingManager;
					object obj = <>O.<0>__OnReceiveFrame;
					if (obj == null)
					{
						HandleNamedMessageDelegate val = OnReceiveFrame;
						<>O.<0>__OnReceiveFrame = val;
						obj = (object)val;
					}
					customMessagingManager.RegisterNamedMessageHandler("OverheadCam_Networked", (HandleNamedMessageDelegate)obj);
					_networkRegistered = true;
				}
			}
			ulong playerClientId = __instance.playerClientId;
			if (!flag && _playerDrones.ContainsKey(playerClientId))
			{
				Object.Destroy((Object)(object)_playerDrones[playerClientId]);
				_playerDrones.Remove(playerClientId);
				if (_remoteTextures.TryGetValue(playerClientId, out var value))
				{
					Object.Destroy((Object)(object)value);
				}
				_remoteTextures.Remove(playerClientId);
				return;
			}
			if (!_playerDrones.ContainsKey(playerClientId) && __instance.isPlayerControlled)
			{
				if ((Object)(object)HardwareStream == (Object)null && ((NetworkBehaviour)__instance).IsOwner)
				{
					InitResources();
				}
				GameObject val2 = new GameObject($"CCTV_{playerClientId}");
				val2.AddComponent<IndependentDroneFollower>().TargetPlayer = __instance;
				Texture val3 = (Texture)((!flag || ((NetworkBehaviour)__instance).IsOwner) ? ((object)HardwareStream) : ((object)new Texture2D(2, 2, (TextureFormat)3, false)));
				if (!((NetworkBehaviour)__instance).IsOwner)
				{
					((Texture2D)val3).SetPixels((Color[])(object)new Color[4]
					{
						Color.black,
						Color.black,
						Color.black,
						Color.black
					});
					((Texture2D)val3).Apply();
					_remoteTextures[playerClientId] = (Texture2D)val3;
				}
				CreateCCTVScreen(val2.transform, val3, ((NetworkBehaviour)__instance).IsOwner);
				_playerDrones.Add(playerClientId, val2);
			}
			if (!(((NetworkBehaviour)__instance).IsOwner && flag))
			{
				return;
			}
			byte[] array = null;
			lock (_pixelLock)
			{
				if (_finishedJpegData != null)
				{
					array = _finishedJpegData;
					_finishedJpegData = null;
				}
			}
			if (array != null)
			{
				int num = array.Length;
				if (NetworkManager.Singleton.IsServer)
				{
					FastBufferWriter val4 = default(FastBufferWriter);
					foreach (ulong connectedClientsId in NetworkManager.Singleton.ConnectedClientsIds)
					{
						if (connectedClientsId != NetworkManager.Singleton.LocalClientId)
						{
							((FastBufferWriter)(ref val4))..ctor(num + 12, (Allocator)2, 256000);
							try
							{
								ulong localClientId = NetworkManager.Singleton.LocalClientId;
								((FastBufferWriter)(ref val4)).WriteValueSafe<ulong>(ref localClientId, default(ForPrimitives));
								((FastBufferWriter)(ref val4)).WriteValueSafe<int>(ref num, default(ForPrimitives));
								((FastBufferWriter)(ref val4)).WriteBytesSafe(array, -1, 0);
								NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("OverheadCam_Networked", connectedClientsId, val4, (NetworkDelivery)4);
							}
							finally
							{
								((IDisposable)(FastBufferWriter)(ref val4)).Dispose();
							}
						}
					}
				}
				else
				{
					FastBufferWriter val5 = default(FastBufferWriter);
					((FastBufferWriter)(ref val5))..ctor(num + 12, (Allocator)2, 256000);
					try
					{
						ulong localClientId = NetworkManager.Singleton.LocalClientId;
						((FastBufferWriter)(ref val5)).WriteValueSafe<ulong>(ref localClientId, default(ForPrimitives));
						((FastBufferWriter)(ref val5)).WriteValueSafe<int>(ref num, default(ForPrimitives));
						((FastBufferWriter)(ref val5)).WriteBytesSafe(array, -1, 0);
						NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("OverheadCam_Networked", 0uL, val5, (NetworkDelivery)4);
					}
					finally
					{
						((IDisposable)(FastBufferWriter)(ref val5)).Dispose();
					}
				}
			}
			if (Time.time > _nextSendTime && (Object)(object)HardwareStream != (Object)null && HardwareStream.isPlaying && !_isEncoding)
			{
				_nextSendTime = Time.time + 0.1f;
				ProcessAndEncodeFrameThreaded();
			}
		}

		private static void ProcessAndEncodeFrameThreaded()
		{
			//IL_00b1: 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)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Expected O, but got Unknown
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			if (((Texture)HardwareStream).width < 50)
			{
				return;
			}
			_isEncoding = true;
			int encSize = 360;
			RenderTexture temporary = RenderTexture.GetTemporary(encSize, encSize, 0);
			float num = (float)((Texture)HardwareStream).width / (float)((Texture)HardwareStream).height;
			float num2 = 1f;
			float num3 = 1f;
			float num4 = 0f;
			float num5 = 0f;
			if (num > 1f)
			{
				num2 = 1f / num;
				num4 = (1f - num2) / 2f;
			}
			else if (num < 1f)
			{
				num3 = num;
				num5 = (1f - num3) / 2f;
			}
			Graphics.Blit((Texture)(object)HardwareStream, temporary, new Vector2(num2, num3), new Vector2(num4, num5));
			RenderTexture.active = temporary;
			if ((Object)(object)_sendBuffer == (Object)null || ((Texture)_sendBuffer).width != encSize)
			{
				_sendBuffer = new Texture2D(encSize, encSize, (TextureFormat)3, false);
			}
			_sendBuffer.ReadPixels(new Rect(0f, 0f, (float)encSize, (float)encSize), 0, 0);
			_sendBuffer.Apply();
			byte[] rawPixels = _sendBuffer.GetRawTextureData();
			RenderTexture.active = null;
			RenderTexture.ReleaseTemporary(temporary);
			Task.Run(delegate
			{
				byte[] finishedJpegData = ImageConversion.EncodeArrayToJPG((Array)rawPixels, (GraphicsFormat)7, (uint)encSize, (uint)encSize, 0u, 70);
				lock (_pixelLock)
				{
					_finishedJpegData = finishedJpegData;
				}
				_isEncoding = false;
			});
		}

		private static void OnReceiveFrame(ulong senderId, FastBufferReader reader)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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_00a6: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			ulong key = default(ulong);
			((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref key, default(ForPrimitives));
			int num = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			byte[] array = new byte[num];
			((FastBufferReader)(ref reader)).ReadBytesSafe(ref array, num, 0);
			if (NetworkManager.Singleton.IsServer && senderId != NetworkManager.Singleton.LocalClientId)
			{
				FastBufferWriter val = default(FastBufferWriter);
				foreach (ulong connectedClientsId in NetworkManager.Singleton.ConnectedClientsIds)
				{
					if (connectedClientsId != senderId && connectedClientsId != NetworkManager.Singleton.LocalClientId)
					{
						((FastBufferWriter)(ref val))..ctor(num + 12, (Allocator)2, 256000);
						try
						{
							((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref key, default(ForPrimitives));
							((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives));
							((FastBufferWriter)(ref val)).WriteBytesSafe(array, -1, 0);
							NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("OverheadCam_Networked", connectedClientsId, val, (NetworkDelivery)4);
						}
						finally
						{
							((IDisposable)(FastBufferWriter)(ref val)).Dispose();
						}
					}
				}
			}
			if (_remoteTextures.TryGetValue(key, out var value))
			{
				ImageConversion.LoadImage(value, array);
				value.Apply();
			}
		}

		public static void InitResources()
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)HardwareStream == (Object)null && WebCamTexture.devices.Length != 0)
			{
				string value = OverheadCamPlugin.ConfigSelectedCamera.Value;
				HardwareStream = new WebCamTexture(value, 1280, 720, 30);
				HardwareStream.Play();
			}
			if ((Object)(object)_scanlineTex == (Object)null)
			{
				_scanlineTex = new Texture2D(1, 128);
				for (int i = 0; i < 128; i++)
				{
					_scanlineTex.SetPixel(0, i, (i % 2 == 0) ? new Color(0f, 0f, 0f, 0.3f) : new Color(0f, 0f, 0f, 0f));
				}
				_scanlineTex.Apply();
			}
		}

		private static void CleanupResources()
		{
			if ((Object)(object)HardwareStream != (Object)null)
			{
				HardwareStream.Stop();
				Object.Destroy((Object)(object)HardwareStream);
				HardwareStream = null;
			}
			if ((Object)(object)_sendBuffer != (Object)null)
			{
				Object.Destroy((Object)(object)_sendBuffer);
				_sendBuffer = null;
			}
			foreach (Texture2D value in _remoteTextures.Values)
			{
				if ((Object)(object)value != (Object)null)
				{
					Object.Destroy((Object)(object)value);
				}
			}
			_remoteTextures.Clear();
			foreach (GameObject value2 in _playerDrones.Values)
			{
				if ((Object)(object)value2 != (Object)null)
				{
					Object.Destroy((Object)(object)value2);
				}
			}
			_playerDrones.Clear();
		}

		private static void CreateCCTVScreen(Transform parent, Texture tex, bool isLocalPlayer)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Expected O, but got Unknown
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Expected O, but got Unknown
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Expected O, but got Unknown
			GameObject val = new GameObject("CCTV_Container");
			val.transform.SetParent(parent, false);
			val.AddComponent<BillboardDisplay>();
			GameObject val2 = new GameObject("Shake_Container");
			val2.transform.SetParent(val.transform, false);
			GameObject val3 = GameObject.CreatePrimitive((PrimitiveType)5);
			((Object)val3).name = "Screen";
			Object.Destroy((Object)(object)val3.GetComponent<Collider>());
			val3.transform.SetParent(val2.transform, false);
			val3.transform.localScale = new Vector3(0.72f, 0.72f, 1f);
			Renderer component = val3.GetComponent<Renderer>();
			component.material = new Material(Shader.Find("Sprites/Default"))
			{
				mainTexture = tex
			};
			if (isLocalPlayer)
			{
				val3.AddComponent<LocalWebcamCropper>();
			}
			GameObject val4 = GameObject.CreatePrimitive((PrimitiveType)5);
			((Object)val4).name = "Outline";
			Object.Destroy((Object)(object)val4.GetComponent<Collider>());
			val4.transform.SetParent(val3.transform, false);
			val4.transform.localScale = new Vector3(1.04f, 1.04f, 1f);
			val4.transform.localPosition = new Vector3(0f, 0f, 0.01f);
			Renderer component2 = val4.GetComponent<Renderer>();
			component2.material = new Material(Shader.Find("Sprites/Default"));
			component2.material.color = new Color(0.2f, 1f, 0.2f, 0f);
			if (isLocalPlayer)
			{
				val4.SetActive(false);
			}
			GameObject val5 = GameObject.CreatePrimitive((PrimitiveType)5);
			Object.Destroy((Object)(object)val5.GetComponent<Collider>());
			val5.transform.SetParent(val3.transform, false);
			val5.transform.localPosition = new Vector3(0f, 0f, -0.01f);
			val5.GetComponent<Renderer>().material = new Material(Shader.Find("Sprites/Default"))
			{
				mainTexture = (Texture)(object)_scanlineTex
			};
			val3.AddComponent<CCTVEffects>().Setup(component);
		}
	}
	public class BillboardDisplay : MonoBehaviour
	{
		private Camera _cam;

		private void LateUpdate()
		{
			//IL_004b: 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_0060: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_cam == (Object)null)
			{
				_cam = GameNetworkManager.Instance?.localPlayerController?.gameplayCamera;
			}
			if ((Object)(object)_cam != (Object)null)
			{
				((Component)this).transform.forward = ((Component)this).transform.position - ((Component)_cam).transform.position;
			}
		}
	}
}