Decompiled source of MissileTurrets v1.3.5

MissileTurret/MissileTurret.dll

Decompiled 5 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
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 JetBrains.Annotations;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using MissileTurret.NetcodePatcher;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MissileTurret")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MissileTurret")]
[assembly: AssemblyTitle("MissileTurret")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 MissileTurret
{
	public class MissileAI : NetworkBehaviour
	{
		public Transform player;

		private float _speed = 0f;

		private float _currentLaunchTime;

		private readonly float launchTimeSeconds = 0.4f;

		private float _aliveTimeSeconds;

		private Rigidbody _rigidbody;

		public static float MaxTurnSpeed = 1f;

		public static float MaxSpeed = 0.7f;

		public static float Acceleration = 0.001f;

		public static float KillRange = 1f;

		public static float DamageRange = 5f;

		private void Awake()
		{
			_rigidbody = ((Component)this).GetComponent<Rigidbody>();
			_currentLaunchTime = launchTimeSeconds;
		}

		private void Update()
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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)
			//IL_0063: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: 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_010b: 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_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: 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_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)this).transform;
			Vector3 forward = transform.forward;
			_aliveTimeSeconds += Time.deltaTime;
			if (_currentLaunchTime > 0f)
			{
				_currentLaunchTime -= Time.deltaTime;
				transform.position += transform.up * (_speed * 1.5f);
				_speed += 0.0004f * Time.deltaTime;
			}
			else if (_speed < MaxSpeed)
			{
				_speed += Acceleration * Time.deltaTime;
			}
			_rigidbody.MovePosition(transform.position + forward * (_speed * Time.deltaTime));
			if (NetworkManager.Singleton.IsServer || NetworkManager.Singleton.IsHost)
			{
				Vector3 val = player.position + Vector3.up - transform.position;
				Quaternion val2 = Quaternion.LookRotation(val);
				transform.rotation = Quaternion.Lerp(transform.rotation, val2, ((Vector3)(ref val)).magnitude * (MaxTurnSpeed * Time.deltaTime));
			}
			if (_aliveTimeSeconds > 10f)
			{
				EndIt();
			}
		}

		private void OnCollisionEnter(Collision other)
		{
			EndIt();
		}

		private void EndIt()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				ExplodeClientRpc(((Component)this).transform.position, KillRange, DamageRange);
				NetworkObject component = ((Component)this).GetComponent<NetworkObject>();
				if (component != null && component.IsSpawned)
				{
					component.Despawn(true);
				}
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}

		[ClientRpc]
		public void ExplodeClientRpc(Vector3 position, float killRange, float damageRange)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: 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_008a: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: 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)
			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(1416639908u, val, (RpcDelivery)0);
					((FastBufferWriter)(ref val2)).WriteValueSafe(ref position);
					((FastBufferWriter)(ref val2)).WriteValueSafe<float>(ref killRange, default(ForPrimitives));
					((FastBufferWriter)(ref val2)).WriteValueSafe<float>(ref damageRange, default(ForPrimitives));
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1416639908u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					Landmine.SpawnExplosion(position, true, killRange, damageRange, 50, 0f, (GameObject)null, false);
				}
			}
		}

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

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_MissileAI()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(1416639908u, new RpcReceiveHandler(__rpc_handler_1416639908));
		}

		private static void __rpc_handler_1416639908(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				Vector3 position = default(Vector3);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref position);
				float killRange = default(float);
				((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref killRange, default(ForPrimitives));
				float damageRange = default(float);
				((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref damageRange, default(ForPrimitives));
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((MissileAI)(object)target).ExplodeClientRpc(position, killRange, damageRange);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected internal override string __getTypeName()
		{
			return "MissileAI";
		}
	}
	public class MissileTurretAI : NetworkBehaviour
	{
		private enum MissileTurretState
		{
			SEARCHING,
			FIRING,
			CHARGING,
			DISABLED
		}

		public Transform rod;

		public Transform rail;

		public GameObject missile;

		public GameObject laser;

		public static float RotationRange;

		public static float RotationSpeed;

		private float _currentRotationSpeed;

		private MissileTurretState _state;

		private MissileTurretState _lastState;

		[CanBeNull]
		private PlayerControllerB _targetPlayer;

		private RaycastHit _lastHit;

		private float _currentReloadTime;

		public static float ReloadTimeSeconds;

		private float _currentChargeTime;

		public static float ChargeTimeSeconds;

		public AudioSource acquireTargetAudio;

		public AudioSource disableAudio;

		public AudioSource enableAudio;

		private float _currentDisableTime = 0f;

		public static float DisableTimeSeconds = 8f;

		private void Awake()
		{
			_currentReloadTime = ReloadTimeSeconds;
			_currentChargeTime = ChargeTimeSeconds;
			_currentRotationSpeed = RotationSpeed;
			_currentDisableTime = DisableTimeSeconds;
			TerminalAccessibleObject component = ((Component)this).GetComponent<TerminalAccessibleObject>();
			((UnityEventBase)component.terminalCodeEvent).AddListener((object)this, typeof(MissileTurretAI).GetMethod("DisableTurret"));
			laser.SetActive(false);
			ToggleLaserClientRpc(active: false);
		}

		private void Update()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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_027f: 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_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: 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_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_048b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0490: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0537: Unknown result type (might be due to invalid IL or missing references)
			//IL_053c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0550: Unknown result type (might be due to invalid IL or missing references)
			//IL_055e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0563: Unknown result type (might be due to invalid IL or missing references)
			//IL_0577: Unknown result type (might be due to invalid IL or missing references)
			//IL_0580: Unknown result type (might be due to invalid IL or missing references)
			//IL_0582: 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_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: 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_038d: 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)
			MissileTurretState? missileTurretState = null;
			RaycastHit lastHit = default(RaycastHit);
			switch (_state)
			{
			case MissileTurretState.SEARCHING:
				if (Physics.Raycast(rod.position + rod.up, rod.up, ref lastHit, 30f, 1051400, (QueryTriggerInteraction)1) && ((Component)((RaycastHit)(ref lastHit)).transform).CompareTag("Player"))
				{
					if ((Object)(object)((RaycastHit)(ref lastHit)).collider != (Object)(object)((RaycastHit)(ref _lastHit)).collider)
					{
						_targetPlayer = ((Component)((RaycastHit)(ref lastHit)).transform).GetComponent<PlayerControllerB>();
						_lastHit = lastHit;
					}
					missileTurretState = MissileTurretState.CHARGING;
				}
				else
				{
					_targetPlayer = null;
					missileTurretState = MissileTurretState.SEARCHING;
				}
				if (NetworkManager.Singleton.IsServer || NetworkManager.Singleton.IsHost)
				{
					rod.Rotate(Vector3.forward, _currentRotationSpeed * Time.deltaTime);
					float z = rod.localEulerAngles.z;
					if ((z > RotationRange && z <= 180f && _currentRotationSpeed > 0f) || (z < 360f - RotationRange && z > 180f && _currentRotationSpeed < 0f))
					{
						_currentRotationSpeed = 0f - _currentRotationSpeed;
					}
					SetYawClientRpc(z);
				}
				break;
			case MissileTurretState.CHARGING:
				if (_lastState != MissileTurretState.CHARGING)
				{
					acquireTargetAudio.Play();
					if (NetworkManager.Singleton.IsServer || NetworkManager.Singleton.IsHost)
					{
						ToggleLaserClientRpc(active: true);
					}
				}
				if (_currentChargeTime <= 0f)
				{
					_currentChargeTime = ChargeTimeSeconds;
					missileTurretState = MissileTurretState.FIRING;
					if (NetworkManager.Singleton.IsServer || NetworkManager.Singleton.IsHost)
					{
						ToggleLaserClientRpc(active: false);
					}
				}
				else
				{
					_currentChargeTime -= Time.deltaTime;
				}
				break;
			case MissileTurretState.FIRING:
				if (_targetPlayer == null)
				{
					missileTurretState = MissileTurretState.SEARCHING;
					break;
				}
				if (_lastState != MissileTurretState.FIRING)
				{
					if ((!Physics.Raycast(rod.position + rod.forward, ((Component)_targetPlayer).transform.position - rod.position, ref lastHit, 30f, 1051400, (QueryTriggerInteraction)1) || !((Component)((RaycastHit)(ref lastHit)).transform).CompareTag("Player")) && (!Physics.Raycast(rod.position + rod.forward, ((Component)_targetPlayer).transform.position - rod.position, ref lastHit, 30f, 1051400, (QueryTriggerInteraction)1) || !((Component)((RaycastHit)(ref lastHit)).transform).CompareTag("Player")))
					{
						missileTurretState = MissileTurretState.SEARCHING;
						break;
					}
					if (NetworkManager.Singleton.IsServer || NetworkManager.Singleton.IsHost)
					{
						MissileAI component = Object.Instantiate<GameObject>(Plugin.MissilePrefab, rod.position + Vector3.up, Quaternion.LookRotation(rod.up)).GetComponent<MissileAI>();
						component.player = ((Component)_targetPlayer).transform;
						((Component)component).GetComponent<NetworkObject>().Spawn(true);
						ToggleMissileClientRpc(active: false);
					}
				}
				if (_currentReloadTime <= 0f)
				{
					if (NetworkManager.Singleton.IsServer || NetworkManager.Singleton.IsHost)
					{
						ToggleMissileClientRpc(active: true);
					}
					_currentReloadTime = ReloadTimeSeconds;
					missileTurretState = MissileTurretState.SEARCHING;
				}
				else
				{
					_currentReloadTime -= Time.deltaTime;
				}
				break;
			case MissileTurretState.DISABLED:
				if (_lastState != MissileTurretState.DISABLED)
				{
					disableAudio.Play();
					if (NetworkManager.Singleton.IsServer || NetworkManager.Singleton.IsHost)
					{
						Vector3 localEulerAngles = rail.localEulerAngles;
						localEulerAngles.x = -30f;
						rail.localEulerAngles = localEulerAngles;
						Vector3 localPosition = rail.localPosition;
						localPosition.y = -0.67f;
						rail.localPosition = localPosition;
						SetRailClientRpc(localEulerAngles, localPosition);
					}
				}
				if (_currentDisableTime <= 0f)
				{
					_currentDisableTime = DisableTimeSeconds;
					enableAudio.Play();
					if (NetworkManager.Singleton.IsServer || NetworkManager.Singleton.IsHost)
					{
						Vector3 localEulerAngles2 = rail.localEulerAngles;
						localEulerAngles2.x = 0f;
						rail.localEulerAngles = localEulerAngles2;
						Vector3 localPosition2 = rail.localPosition;
						localPosition2.y = 0f;
						rail.localPosition = localPosition2;
						SetRailClientRpc(localEulerAngles2, localPosition2);
					}
					missileTurretState = MissileTurretState.SEARCHING;
				}
				else
				{
					_currentDisableTime -= Time.deltaTime;
				}
				break;
			}
			_lastState = _state;
			if (missileTurretState.HasValue && missileTurretState != _state && (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer))
			{
				_state = missileTurretState.Value;
				SetStateClientRpc(_state, _lastState);
			}
		}

		public void DisableTurret(PlayerControllerB pc)
		{
			if (pc != null)
			{
				_lastState = _state;
				_state = MissileTurretState.DISABLED;
				SetStateClientRpc(_state, _lastState);
			}
		}

		[ClientRpc]
		private void SetStateClientRpc(MissileTurretState state, MissileTurretState lastState)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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_009e: 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)
			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(3177718372u, val, (RpcDelivery)0);
					((FastBufferWriter)(ref val2)).WriteValueSafe<MissileTurretState>(ref state, default(ForEnums));
					((FastBufferWriter)(ref val2)).WriteValueSafe<MissileTurretState>(ref lastState, default(ForEnums));
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3177718372u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					_state = state;
					_lastState = lastState;
				}
			}
		}

		[ClientRpc]
		private void SetYawClientRpc(float yaw)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: 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(2936333528u, val, (RpcDelivery)0);
					((FastBufferWriter)(ref val2)).WriteValueSafe<float>(ref yaw, default(ForPrimitives));
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2936333528u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					Vector3 localEulerAngles = rod.localEulerAngles;
					localEulerAngles.z = yaw;
					rod.localEulerAngles = localEulerAngles;
				}
			}
		}

		[ClientRpc]
		private void SetRailClientRpc(Vector3 localEulers, Vector3 localPos)
		{
			//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_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: 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)
			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(3970896126u, val, (RpcDelivery)0);
					((FastBufferWriter)(ref val2)).WriteValueSafe(ref localEulers);
					((FastBufferWriter)(ref val2)).WriteValueSafe(ref localPos);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3970896126u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					rail.localPosition = localPos;
					rail.localEulerAngles = localEulers;
				}
			}
		}

		[ClientRpc]
		private void ToggleMissileClientRpc(bool active)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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)
			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(1599590863u, val, (RpcDelivery)0);
					((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref active, default(ForPrimitives));
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1599590863u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					missile.SetActive(active);
				}
			}
		}

		[ClientRpc]
		private void ToggleLaserClientRpc(bool active)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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)
			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(1199733162u, val, (RpcDelivery)0);
					((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref active, default(ForPrimitives));
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1199733162u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					laser.SetActive(active);
				}
			}
		}

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

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_MissileTurretAI()
		{
			//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(3177718372u, new RpcReceiveHandler(__rpc_handler_3177718372));
			NetworkManager.__rpc_func_table.Add(2936333528u, new RpcReceiveHandler(__rpc_handler_2936333528));
			NetworkManager.__rpc_func_table.Add(3970896126u, new RpcReceiveHandler(__rpc_handler_3970896126));
			NetworkManager.__rpc_func_table.Add(1599590863u, new RpcReceiveHandler(__rpc_handler_1599590863));
			NetworkManager.__rpc_func_table.Add(1199733162u, new RpcReceiveHandler(__rpc_handler_1199733162));
		}

		private static void __rpc_handler_3177718372(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_004a: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				MissileTurretState state = default(MissileTurretState);
				((FastBufferReader)(ref reader)).ReadValueSafe<MissileTurretState>(ref state, default(ForEnums));
				MissileTurretState lastState = default(MissileTurretState);
				((FastBufferReader)(ref reader)).ReadValueSafe<MissileTurretState>(ref lastState, default(ForEnums));
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((MissileTurretAI)(object)target).SetStateClientRpc(state, lastState);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2936333528(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_0044: 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)
			{
				float yawClientRpc = default(float);
				((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref yawClientRpc, default(ForPrimitives));
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((MissileTurretAI)(object)target).SetYawClientRpc(yawClientRpc);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3970896126(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//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_0052: 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 localEulers = default(Vector3);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref localEulers);
				Vector3 localPos = default(Vector3);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref localPos);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((MissileTurretAI)(object)target).SetRailClientRpc(localEulers, localPos);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1599590863(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_0044: 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)
			{
				bool active = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref active, default(ForPrimitives));
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((MissileTurretAI)(object)target).ToggleMissileClientRpc(active);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1199733162(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_0044: 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)
			{
				bool active = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref active, default(ForPrimitives));
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((MissileTurretAI)(object)target).ToggleLaserClientRpc(active);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		protected internal override string __getTypeName()
		{
			return "MissileTurretAI";
		}
	}
	[BepInPlugin("Finnerex.MissileTurret", "MissileTurret", "1.3.3")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static SpawnableMapObject MissileTurretMapObj;

		public static GameObject MissileTurretPrefab;

		public static GameObject MissilePrefab;

		public static ManualLogSource TheLogger;

		public int MaxTurrets;

		public int MinTurrets;

		private void Awake()
		{
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Expected O, but got Unknown
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Expected O, but got Unknown
			TheLogger = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Missile Turret Loading???");
			Configure();
			InitializeNetworkBehaviours();
			string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(directoryName, "missileturretassetbundle"));
			if (val == null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Failed to load assets");
				return;
			}
			MissileTurretPrefab = val.LoadAsset<GameObject>("MissileTurret");
			MissilePrefab = val.LoadAsset<GameObject>("Missile");
			MissileTurretAI missileTurretAI = MissileTurretPrefab.AddComponent<MissileTurretAI>();
			missileTurretAI.rod = MissileTurretPrefab.transform.Find("missileTurret/Mount/Rod");
			missileTurretAI.rail = missileTurretAI.rod.Find("Rod.001");
			missileTurretAI.missile = ((Component)missileTurretAI.rail.Find("Cylinder")).gameObject;
			missileTurretAI.acquireTargetAudio = ((Component)missileTurretAI.rod).GetComponent<AudioSource>();
			missileTurretAI.disableAudio = ((Component)missileTurretAI.rod.Find("DisableSound")).GetComponent<AudioSource>();
			missileTurretAI.enableAudio = ((Component)missileTurretAI.rod.Find("EnableSound")).GetComponent<AudioSource>();
			missileTurretAI.laser = ((Component)missileTurretAI.rod.Find("LaserLight")).gameObject;
			MissilePrefab.AddComponent<MissileAI>();
			Utilities.FixMixerGroups(MissileTurretPrefab);
			Utilities.FixMixerGroups(MissilePrefab);
			NetworkPrefabs.RegisterNetworkPrefab(MissileTurretPrefab);
			NetworkPrefabs.RegisterNetworkPrefab(MissilePrefab);
			AnimationCurve curve = new AnimationCurve((Keyframe[])(object)new Keyframe[2]
			{
				new Keyframe(0f, (float)MinTurrets, 0.267f, 0.267f, 0f, 0.246f),
				new Keyframe(1f, (float)MaxTurrets, 61f, 61f, 0.015f * (float)MaxTurrets, 0f)
			});
			MissileTurretMapObj = new SpawnableMapObject
			{
				prefabToSpawn = MissileTurretPrefab,
				spawnFacingAwayFromWall = true,
				numberToSpawn = curve
			};
			MapObjects.RegisterMapObject(MissileTurretMapObj, (LevelTypes)(-1), (Func<SelectableLevel, AnimationCurve>)((SelectableLevel _) => curve));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Missile Turret Loaded!!!");
		}

		private static void InitializeNetworkBehaviours()
		{
			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);
					}
				}
			}
		}

		private void Configure()
		{
			//IL_0012: 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_002d: Expected O, but got Unknown
			//IL_002d: Expected O, but got Unknown
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			//IL_0063: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			//IL_009c: Expected O, but got Unknown
			//IL_00bc: 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_00db: Expected O, but got Unknown
			//IL_00db: Expected O, but got Unknown
			//IL_00f5: 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_0114: Expected O, but got Unknown
			//IL_0114: Expected O, but got Unknown
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Expected O, but got Unknown
			//IL_0153: Expected O, but got Unknown
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Expected O, but got Unknown
			//IL_018c: Expected O, but got Unknown
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Expected O, but got Unknown
			//IL_01c5: Expected O, but got Unknown
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Expected O, but got Unknown
			//IL_01fe: Expected O, but got Unknown
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Expected O, but got Unknown
			//IL_023d: Expected O, but got Unknown
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Expected O, but got Unknown
			//IL_0276: Expected O, but got Unknown
			MaxTurrets = ((BaseUnityPlugin)this).Config.Bind<int>(new ConfigDefinition("Spawn Options", "Max Turrets"), 6, new ConfigDescription("Maximum number of turrets that can be spawned", (AcceptableValueBase)null, Array.Empty<object>())).Value;
			MinTurrets = ((BaseUnityPlugin)this).Config.Bind<int>(new ConfigDefinition("Spawn Options", "Min Turrets"), 0, new ConfigDescription("Minimum number of turrets that can be spawned", (AcceptableValueBase)null, Array.Empty<object>())).Value;
			MissileAI.MaxSpeed = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Missile Options", "Max Speed"), 0.7f, new ConfigDescription("Maximum speed of a missile", (AcceptableValueBase)null, Array.Empty<object>())).Value * 100f;
			MissileAI.MaxTurnSpeed = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Missile Options", "Turn Rate"), 0.6f, new ConfigDescription("How fast the missile can turn", (AcceptableValueBase)null, Array.Empty<object>())).Value;
			MissileAI.Acceleration = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Missile Options", "Acceleration"), 0.6f, new ConfigDescription("Acceleration of the missile", (AcceptableValueBase)null, Array.Empty<object>())).Value * 100f;
			MissileAI.KillRange = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Missile Options", "Explosive Kill Range"), 1f, new ConfigDescription("Distance from explosion to kill", (AcceptableValueBase)null, Array.Empty<object>())).Value;
			MissileAI.DamageRange = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Missile Options", "Explosive Damage Range"), 5f, new ConfigDescription("Distance from explosion to damage", (AcceptableValueBase)null, Array.Empty<object>())).Value;
			MissileTurretAI.RotationRange = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Missile Turret Options", "Rotation Range"), 45f, new ConfigDescription("The angle the turret's search is restricted to in degrees left & right", (AcceptableValueBase)null, Array.Empty<object>())).Value;
			MissileTurretAI.RotationSpeed = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Missile Turret Options", "Rotation Rate"), 0.25f, new ConfigDescription("The speed at which the turret rotates", (AcceptableValueBase)null, Array.Empty<object>())).Value * 100f;
			MissileTurretAI.ReloadTimeSeconds = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Missile Turret Options", "Reload Time"), 6f, new ConfigDescription("The time it takes for the turret to reload in seconds", (AcceptableValueBase)null, Array.Empty<object>())).Value;
			MissileTurretAI.ChargeTimeSeconds = ((BaseUnityPlugin)this).Config.Bind<float>(new ConfigDefinition("Missile Turret Options", "Charge Time"), 0.5f, new ConfigDescription("The time it takes for the turret to shoot at a target in seconds", (AcceptableValueBase)null, Array.Empty<object>())).Value;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "MissileTurret";

		public const string PLUGIN_NAME = "MissileTurret";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace MissileTurret.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}