Decompiled source of Trenches v1.6.1

TrenchesBehaviour.dll

Decompiled 4 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using TrenchesBehaviour.NetcodePatcher;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.VFX;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("TrenchesBehaviour")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TrenchesBehaviour")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("189195ee-7802-4138-b646-76a531e2f09e")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
namespace TrenchesBehaviour
{
	[BepInPlugin("InstanceWorld.Trenches", "Trenches Scripts", "1.0.0")]
	public class TrenchesPatcher : BaseUnityPlugin
	{
		private Harmony harmony = new Harmony("InstanceWorld.Trenches");

		private const string GUID = "InstanceWorld.Trenches";

		private const string NAME = "Trenches Scripts";

		private const string VERSION = "1.0.0";

		private static TrenchesPatcher Inst;

		internal static ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)Inst == (Object)null)
			{
				Inst = this;
			}
			mls = Logger.CreateLogSource("InstanceWorld.Trenches");
			mls.LogInfo((object)"Starting TrenchPatcher...");
			harmony.PatchAll(typeof(TrenchesPatcher));
			harmony.PatchAll(typeof(Turret));
			harmony.PatchAll(typeof(TurretTrigger));
			mls.LogInfo((object)"Patching Networking...");
			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);
					}
				}
			}
			mls.LogInfo((object)"Ended Trenches Patch");
		}
	}
	public class TurretTrigger : MonoBehaviour
	{
		[SerializeField]
		private UnityEvent<GameObject> EnterTracking;

		[SerializeField]
		private UnityEvent<GameObject> ExitTracking;

		private void Start()
		{
			((UnityEvent<PlayerControllerB>)(object)StartOfRound.Instance.playerTeleportedEvent).AddListener((UnityAction<PlayerControllerB>)TeleportCheck);
		}

		private void OnTriggerEnter(Collider other)
		{
			if (((Component)other).CompareTag("Player"))
			{
				TrenchesPatcher.mls.LogInfo((object)"Player entered");
				EnterTracking.Invoke(((Component)other).gameObject);
			}
		}

		private void OnTriggerExit(Collider other)
		{
			if (((Component)other).CompareTag("Player"))
			{
				TrenchesPatcher.mls.LogInfo((object)"Player exited");
				ExitTracking.Invoke(((Component)other).gameObject);
			}
		}

		public void TeleportCheck(PlayerControllerB Player)
		{
			//IL_0007: 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_001a: Unknown result type (might be due to invalid IL or missing references)
			Bounds bounds = ((Collider)((Component)this).GetComponent<MeshCollider>()).bounds;
			if (((Bounds)(ref bounds)).Intersects(((Component)Player).gameObject.GetComponent<Collider>().bounds))
			{
				TrenchesPatcher.mls.LogInfo((object)"Player entered");
				EnterTracking.Invoke(((Component)Player).gameObject);
			}
			else
			{
				TrenchesPatcher.mls.LogInfo((object)"Player exited");
				ExitTracking.Invoke(((Component)Player).gameObject);
			}
		}
	}
}
namespace TrenchesBehaviour.Behaviours
{
	internal class Bullet : MonoBehaviour
	{
		public Vector3 startLocation;

		public Vector3 endLocation;

		public Turret Turret;

		private Vector3 Direction;

		public int BarrelIndex;

		public float speed = 2f;

		private float despawnTime = 5f;

		private float spawntime;

		private void Start()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			startLocation = ((Component)this).transform.position;
			Vector3 val = endLocation - startLocation;
			Direction = ((Vector3)(ref val)).normalized;
			spawntime = Time.time;
		}

		private void Update()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_00b3: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			if (despawnTime + spawntime < Time.time)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
			else if ((double)Vector3.Distance(endLocation, ((Component)this).transform.position) < 0.02)
			{
				if (((NetworkBehaviour)RoundManager.Instance).IsHost && (Object)(object)Turret != (Object)null)
				{
					Turret.ExplosionClientRpc(((Component)this).transform.position, BarrelIndex);
				}
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
			else
			{
				((Component)this).transform.position = Vector3.MoveTowards(((Component)this).transform.position, endLocation, speed * Time.deltaTime);
			}
		}
	}
	internal class Turret : NetworkBehaviour
	{
		[Header("TreeReferences")]
		public GameObject TBody;

		public GameObject TPitch;

		public GameObject[] FireAnimationObjects;

		[Header("FindPlayer")]
		public GameObject RayStart;

		public LayerMask LayersToHit;

		public GameObject DebugPoint;

		public GameObject currentTarget = null;

		public List<GameObject> InArea;

		[Header("Searching")]
		public bool isReady = false;

		public float min;

		public float max;

		public float start;

		public float DirectionSpeed = 0.02f;

		public bool TurretPause = false;

		[Header("Movement Audio")]
		public AudioSource turnSound;

		public AudioSource turnstopSound;

		public AudioSource turretAreaSound;

		private float nextPosition;

		private bool ResetAngle = false;

		[Header("Fireing")]
		public Transform[] BulletStarts;

		public Vector3 Spread = new Vector3(0.1f, 0.1f, 0.1f);

		public float delay = 0.9f;

		public AudioSource[] HitSoundPos;

		public AudioClip[] HitLocAudio;

		public float AimingMovementSpeed = 5f;

		public AudioSource DetectedSoundSource;

		public GameObject Bullet;

		private float LastShotTime = 0f;

		private int NextBarrelIndex = 0;

		private bool haltFire = false;

		[Header("Lights")]
		public Light L1;

		public Light L2;

		public Color WarningColor;

		public Color AlertColor;

		public MeshRenderer LightBeam;

		public Material WarningMat;

		public Material AlertMat;

		private float percentToTarget = 0f;

		public float initialStop = 20f;

		private bool debugPointplace = false;

		private bool StopFollowingPlayer = true;

		private void Awake()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			UpdateNextPosition();
			if (((NetworkBehaviour)RoundManager.Instance).IsHost)
			{
				((UnityEvent)StartOfRound.Instance.StartNewRoundEvent).AddListener(new UnityAction(AllPlayerReadLoad));
				TrenchesPatcher.mls.LogInfo((object)"server");
			}
		}

		private void Start()
		{
		}

		public void AllPlayerReadLoad()
		{
			TrenchesPatcher.mls.LogInfo((object)"ready");
			isReady = true;
			TPitch.transform.Rotate(25f, 0f, 0f);
			((MonoBehaviour)this).StartCoroutine(PauseRotation(initialStop));
			ChangeLightWarningClientRpc();
		}

		private void Update()
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_008b: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)this).IsHost || !isReady)
			{
				return;
			}
			if ((Object)(object)currentTarget != (Object)null)
			{
				Vector3 position = currentTarget.GetComponent<PlayerControllerB>().cameraContainerTransform.position;
				Vector3 val = position - RayStart.transform.position;
				((Vector3)(ref val)).Normalize();
				RaycastHit val2 = default(RaycastHit);
				if (!Physics.Raycast(RayStart.transform.position, val, ref val2, 600f, LayerMask.op_Implicit(LayersToHit)) || (!((Component)((RaycastHit)(ref val2)).collider).CompareTag("Player") && ((Object)((RaycastHit)(ref val2)).collider).name != "VolumeMain (1)" && ((Object)((RaycastHit)(ref val2)).collider).name != "Imp_NoiseListener") || !InArea.Contains(currentTarget))
				{
					if (!StopFollowingPlayer)
					{
						StopFollowingPlayer = true;
						((MonoBehaviour)this).StartCoroutine(StopAimingForPlayer());
					}
					return;
				}
				StopFollowingPlayer = false;
				AimForPlayer();
				if (!haltFire)
				{
					FireAtPlayerServer();
				}
				return;
			}
			if (InArea.Count > 0)
			{
				PlayerInRange_CheckIfSeen();
			}
			if ((Object)(object)currentTarget == (Object)null && !TurretPause)
			{
				if (ResetAngle)
				{
					CorrectPitch();
				}
				Searching();
			}
		}

		private void PlayerInRange_CheckIfSeen()
		{
			//IL_001f: 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_0025: 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_003b: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit val2 = default(RaycastHit);
			for (int i = 0; i < InArea.Count; i++)
			{
				Vector3 position = InArea[i].GetComponent<PlayerControllerB>().cameraContainerTransform.position;
				Vector3 val = position - RayStart.transform.position;
				((Vector3)(ref val)).Normalize();
				if (Physics.Raycast(RayStart.transform.position, val, ref val2, 600f, LayerMask.op_Implicit(LayersToHit)))
				{
					if ((Object)(object)DebugPoint != (Object)null && debugPointplace)
					{
						TrenchesPatcher.mls.LogInfo((object)("hit name: " + ((Object)((RaycastHit)(ref val2)).collider).name));
						TrenchesPatcher.mls.LogInfo((object)("hit: tag" + ((Component)((RaycastHit)(ref val2)).collider).tag));
						TrenchesPatcher.mls.LogInfo((object)"hit: layer");
						DebugPoint.transform.position = ((RaycastHit)(ref val2)).point;
					}
					if (((Component)((RaycastHit)(ref val2)).collider).CompareTag("Player") || ((Object)((RaycastHit)(ref val2)).collider).name == "VolumeMain (1)" || ((Object)((RaycastHit)(ref val2)).collider).name == "Imp_NoiseListener")
					{
						((MonoBehaviour)this).StopCoroutine(StopAimingForPlayer());
						StopFollowingPlayer = false;
						currentTarget = InArea[i];
						((MonoBehaviour)this).StartCoroutine(PauseRotation(0.5f));
						((MonoBehaviour)this).StartCoroutine(WaitToFire());
						DetectedSoundSource.Play();
						ChangeLightAlertClientRpc();
						break;
					}
				}
			}
		}

		private IEnumerator WaitToFire()
		{
			haltFire = true;
			yield return (object)new WaitForSeconds(1f);
			haltFire = false;
		}

		[ClientRpc]
		private void ChangeLightAlertClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(597477443u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 597477443u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					L1.color = AlertColor;
					L2.color = AlertColor;
					((Renderer)LightBeam).material = AlertMat;
				}
			}
		}

		private IEnumerator StopAimingForPlayer()
		{
			GameObject TargetAtCall = currentTarget;
			yield return (object)new WaitForSeconds(0.5f);
			if (StopFollowingPlayer && (Object)(object)TargetAtCall == (Object)(object)currentTarget)
			{
				((MonoBehaviour)this).StartCoroutine(PauseRotation(2f));
				ResetAngle = true;
				ChangeLightWarningClientRpc();
				currentTarget = null;
			}
		}

		[ClientRpc]
		private void ChangeLightWarningClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2329925200u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2329925200u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					L1.color = WarningColor;
					L2.color = WarningColor;
					((Renderer)LightBeam).material = WarningMat;
				}
			}
		}

		private void CorrectPitch()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			if ((double)Mathf.Abs(30f - TPitch.transform.localEulerAngles.x) < 0.01)
			{
				ResetAngle = false;
			}
			else
			{
				TPitch.transform.localRotation = Quaternion.RotateTowards(TPitch.transform.localRotation, Quaternion.Euler(25f, 0f, 0f), Math.Abs(DirectionSpeed) * Time.deltaTime);
			}
		}

		private void AimForPlayer()
		{
			//IL_0007: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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_006a: 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_007d: 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)
			//IL_0086: 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_00b5: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: 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_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: 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)
			Quaternion localRotation = ((Component)this).transform.localRotation;
			Quaternion val = Quaternion.LookRotation(((Component)this).transform.parent.InverseTransformPoint(currentTarget.transform.position) - ((Component)this).transform.localPosition, ((Component)this).transform.up);
			Quaternion val2 = Quaternion.Euler(0f, ((Quaternion)(ref val)).eulerAngles.y, 0f);
			Quaternion localRotation2 = Quaternion.RotateTowards(localRotation, val2, Math.Abs(AimingMovementSpeed) * Time.deltaTime);
			if (isInBounds(((Quaternion)(ref localRotation2)).eulerAngles.y))
			{
				Quaternion val3 = Quaternion.Euler(((Quaternion)(ref val)).eulerAngles.x, 0f, 0f);
				TPitch.transform.localRotation = Quaternion.RotateTowards(TPitch.transform.localRotation, val3, Math.Abs(AimingMovementSpeed) * Time.deltaTime);
				float x = ((Quaternion)(ref val3)).eulerAngles.x;
				Quaternion localRotation3 = TPitch.transform.localRotation;
				float num = Math.Abs(x - ((Quaternion)(ref localRotation3)).eulerAngles.x);
				if (num < 10f)
				{
					percentToTarget = 1f - Mathf.InverseLerp(0f, 10f, num);
				}
				else
				{
					percentToTarget = 0f;
				}
				((Component)this).transform.localRotation = localRotation2;
			}
		}

		private void FireAtPlayerServer()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_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_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: 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_00ed: 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)
			if (!(LastShotTime + delay > Time.time))
			{
				Vector2 val = Random.insideUnitCircle;
				val = ((Vector2)(ref val)).normalized;
				Vector2 val2 = ((Vector2)(ref val)).normalized * (float)Random.Range(0, 4);
				Vector3 val3 = currentTarget.transform.position + new Vector3(val2.x, 0f, val2.y);
				Vector3 val4 = val3 - BulletStarts[NextBarrelIndex].position;
				Vector3 normalized = ((Vector3)(ref val4)).normalized;
				Vector3 val5 = Vector3.Lerp(BulletStarts[NextBarrelIndex].forward, normalized, percentToTarget);
				RaycastHit val6 = default(RaycastHit);
				if (Physics.Raycast(BulletStarts[NextBarrelIndex].position, val5, ref val6, 600f, LayerMask.op_Implicit(LayersToHit)))
				{
					FireAtPlayerClientRpc(NextBarrelIndex, ((RaycastHit)(ref val6)).point, normalized);
					LastShotTime = Time.time;
					NextBarrelIndex = (NextBarrelIndex + 1) % 2;
				}
			}
		}

		[ClientRpc]
		private void FireAtPlayerClientRpc(int GunBarrelIndex, Vector3 HitPosition, Vector3 Direction)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: 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_016b: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1679051252u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, GunBarrelIndex);
					((FastBufferWriter)(ref val2)).WriteValueSafe(ref HitPosition);
					((FastBufferWriter)(ref val2)).WriteValueSafe(ref Direction);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1679051252u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					((Component)HitSoundPos[GunBarrelIndex]).transform.position = HitPosition;
					RoundManager.PlayRandomClip(HitSoundPos[GunBarrelIndex], HitLocAudio, true, 1f, 0, 1000);
					FireGunBarrelAnimation(GunBarrelIndex);
					Bullet.GetComponent<Bullet>().BarrelIndex = GunBarrelIndex;
					Bullet.GetComponent<Bullet>().Turret = this;
					Bullet.GetComponent<Bullet>().endLocation = HitPosition;
					GameObject val3 = Object.Instantiate<GameObject>(Bullet, BulletStarts[NextBarrelIndex].position, Quaternion.LookRotation(Direction), RoundManager.Instance.mapPropsContainer.transform);
				}
			}
		}

		[ClientRpc]
		public void ExplosionClientRpc(Vector3 Location, int index)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: 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_007e: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1327539756u, val, (RpcDelivery)0);
					((FastBufferWriter)(ref val2)).WriteValueSafe(ref Location);
					BytePacker.WriteValueBitPacked(val2, index);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1327539756u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					((Component)HitSoundPos[index]).GetComponent<ParticleSystem>().Play();
					Landmine.SpawnExplosion(Location + Vector3.up * 0.2f, true, 0f, 8f, 15, 15f, (GameObject)null, false);
				}
			}
		}

		private void FireGunBarrelAnimation(int GunBarrelIndex)
		{
			((Component)BulletStarts[GunBarrelIndex]).GetComponent<VisualEffect>().Play();
			Animator component = FireAnimationObjects[GunBarrelIndex].GetComponent<Animator>();
			component.SetTrigger("FireShot");
		}

		private IEnumerator RenderTrail(TrailRenderer trail, Vector3 HitPosition)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			float TrailTimePercent = 0f;
			Vector3 startPos = ((Component)trail).transform.position;
			while (TrailTimePercent < 1f)
			{
				((Component)trail).transform.position = Vector3.Lerp(startPos, HitPosition, TrailTimePercent);
				TrailTimePercent += Time.deltaTime / trail.time;
				yield return null;
			}
			((Component)trail).transform.position = HitPosition;
			Object.Destroy((Object)(object)((Component)trail).gameObject, trail.time);
		}

		private void Searching()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			((Component)this).transform.Rotate(0f, Time.deltaTime * DirectionSpeed, 0f);
			if (Mathf.Abs(((Component)this).transform.localEulerAngles.y - nextPosition) < 0.3f)
			{
				DirectionSpeed *= -1f;
				UpdateNextPosition();
				((MonoBehaviour)this).StartCoroutine(PauseRotation(1f));
			}
		}

		private void UpdateNextPosition()
		{
			if (DirectionSpeed < 0f)
			{
				nextPosition = ((min < 0f) ? (360f + min) : min);
				nextPosition %= 360f;
			}
			else
			{
				nextPosition = ((max < 0f) ? (360f + max) : max);
				nextPosition %= 360f;
			}
		}

		private bool isInBounds(float angle)
		{
			float num = ((min < 0f) ? (360f + min) : min);
			num %= 360f;
			if ((double)Mathf.Abs(angle - num) < 0.6)
			{
				return false;
			}
			num = ((max < 0f) ? (360f + max) : max);
			num %= 360f;
			if ((double)Mathf.Abs(angle - num) < 0.6)
			{
				return false;
			}
			return true;
		}

		private IEnumerator PauseRotation(float time)
		{
			turnSound.Stop();
			if (time > 0.8f)
			{
				turnstopSound.Play();
			}
			TurretPause = true;
			yield return (object)new WaitForSeconds(time);
			TurretPause = false;
			turnSound.Play();
		}

		public void AddToTargets(GameObject player)
		{
			if (!InArea.Contains(player))
			{
				TrenchesPatcher.mls.LogInfo((object)"Player added to targets");
				InArea.Add(player);
				TrenchesPatcher.mls.LogInfo((object)("Players in area: " + InArea.Count));
			}
		}

		public void RemoveTargets(GameObject player)
		{
			if (InArea.Contains(player))
			{
				if (!InArea.Remove(player))
				{
					TrenchesPatcher.mls.LogError((object)"Could not remove player");
				}
				else
				{
					TrenchesPatcher.mls.LogInfo((object)"Player removed from targets");
				}
			}
		}

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

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_Turret()
		{
			//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
			NetworkManager.__rpc_func_table.Add(597477443u, new RpcReceiveHandler(__rpc_handler_597477443));
			NetworkManager.__rpc_func_table.Add(2329925200u, new RpcReceiveHandler(__rpc_handler_2329925200));
			NetworkManager.__rpc_func_table.Add(1679051252u, new RpcReceiveHandler(__rpc_handler_1679051252));
			NetworkManager.__rpc_func_table.Add(1327539756u, new RpcReceiveHandler(__rpc_handler_1327539756));
		}

		private static void __rpc_handler_597477443(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((Turret)(object)target).ChangeLightAlertClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2329925200(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((Turret)(object)target).ChangeLightWarningClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1679051252(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int gunBarrelIndex = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref gunBarrelIndex);
				Vector3 hitPosition = default(Vector3);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref hitPosition);
				Vector3 direction = default(Vector3);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref direction);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((Turret)(object)target).FireAtPlayerClientRpc(gunBarrelIndex, hitPosition, direction);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1327539756(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				Vector3 location = default(Vector3);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref location);
				int index = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref index);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((Turret)(object)target).ExplosionClientRpc(location, index);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "Turret";
		}
	}
}
namespace TrenchesBehaviour.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}