Decompiled source of Sentry Guns v1.0.1

BestMod.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using ExitGames.Client.Photon;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;

[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("Omniscye")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+c574138cfea486cfa7104eae1a6f135c166daf8b")]
[assembly: AssemblyProduct("BestMod")]
[assembly: AssemblyTitle("BestMod")]
[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.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 TurretGunMod
{
	[BepInPlugin("com.user.turretgun", "Turret Gun Mod", "1.0.5")]
	public class TurretGunMod : BaseUnityPlugin, IOnEventCallback
	{
		public const byte DeployEventCode = 69;

		public const byte UndeployEventCode = 70;

		private bool _callbacksRegistered;

		private void OnDisable()
		{
			if (_callbacksRegistered)
			{
				PhotonNetwork.RemoveCallbackTarget((object)this);
				_callbacksRegistered = false;
			}
		}

		private bool IsGameReady()
		{
			if (!PhotonNetwork.IsConnected || !PhotonNetwork.InRoom)
			{
				return false;
			}
			if (SemiFunc.MenuLevel())
			{
				return false;
			}
			if (!SemiFunc.LevelGenDone())
			{
				return false;
			}
			if (!Object.op_Implicit((Object)(object)SemiFunc.PlayerAvatarLocal()))
			{
				return false;
			}
			if ((Object)(object)PhysGrabber.instance == (Object)null)
			{
				return false;
			}
			return true;
		}

		private void Update()
		{
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: 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_0100: Unknown result type (might be due to invalid IL or missing references)
			if (IsGameReady())
			{
				if (!_callbacksRegistered)
				{
					PhotonNetwork.AddCallbackTarget((object)this);
					_callbacksRegistered = true;
				}
				if (!Input.GetKeyDown((KeyCode)308))
				{
					return;
				}
				if ((Object)(object)PhysGrabber.instance.grabbedPhysGrabObject != (Object)null)
				{
					ItemGun component = ((Component)PhysGrabber.instance.grabbedPhysGrabObject).GetComponent<ItemGun>();
					if ((Object)(object)component != (Object)null)
					{
						int mask = LayerMask.GetMask(new string[1] { "Default" });
						Vector3 pos = ((Component)component).transform.position + Vector3.down * 1.5f;
						RaycastHit val = default(RaycastHit);
						if (Physics.Raycast(((Component)component).transform.position, Vector3.down, ref val, 5f, mask))
						{
							pos = ((RaycastHit)(ref val)).point;
						}
						PhotonView component2 = ((Component)component).GetComponent<PhotonView>();
						if ((Object)(object)component2 != (Object)null)
						{
							SendDeployEvent(component2.ViewID, pos);
						}
					}
				}
				else
				{
					CheckForTurretPickup();
				}
			}
			else if (_callbacksRegistered)
			{
				PhotonNetwork.RemoveCallbackTarget((object)this);
				_callbacksRegistered = false;
			}
		}

		private void CheckForTurretPickup()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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)
			if ((Object)(object)Camera.main == (Object)null)
			{
				return;
			}
			Ray val = default(Ray);
			((Ray)(ref val))..ctor(((Component)Camera.main).transform.position, ((Component)Camera.main).transform.forward);
			RaycastHit val2 = default(RaycastHit);
			if (!Physics.Raycast(val, ref val2, 3f, LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct())))
			{
				return;
			}
			TurretController componentInParent = ((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<TurretController>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				PhotonView component = ((Component)componentInParent).GetComponent<PhotonView>();
				if ((Object)(object)component != (Object)null)
				{
					SendUndeployEvent(component.ViewID);
				}
			}
		}

		private void SendDeployEvent(int viewID, Vector3 pos)
		{
			//IL_0012: 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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			object[] array = new object[2] { viewID, pos };
			RaiseEventOptions val = new RaiseEventOptions
			{
				Receivers = (ReceiverGroup)1
			};
			PhotonNetwork.RaiseEvent((byte)69, (object)array, val, SendOptions.SendReliable);
		}

		private void SendUndeployEvent(int viewID)
		{
			//IL_0011: 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)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			object[] array = new object[1] { viewID };
			RaiseEventOptions val = new RaiseEventOptions
			{
				Receivers = (ReceiverGroup)1
			};
			PhotonNetwork.RaiseEvent((byte)70, (object)array, val, SendOptions.SendReliable);
		}

		public void OnEvent(EventData photonEvent)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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)
			if (photonEvent.Code == 69)
			{
				object[] array = (object[])photonEvent.CustomData;
				int num = (int)array[0];
				Vector3 targetPos = (Vector3)array[1];
				PhotonView val = PhotonView.Find(num);
				if ((Object)(object)val != (Object)null)
				{
					ItemGun component = ((Component)val).GetComponent<ItemGun>();
					if ((Object)(object)component != (Object)null)
					{
						DeployTurret(component, targetPos);
					}
				}
			}
			else
			{
				if (photonEvent.Code != 70)
				{
					return;
				}
				object[] array2 = (object[])photonEvent.CustomData;
				int num2 = (int)array2[0];
				PhotonView val2 = PhotonView.Find(num2);
				if ((Object)(object)val2 != (Object)null)
				{
					TurretController component2 = ((Component)val2).GetComponent<TurretController>();
					if ((Object)(object)component2 != (Object)null)
					{
						component2.Undeploy();
					}
				}
			}
		}

		private void DeployTurret(ItemGun gun, Vector3 targetPos)
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)((Component)gun).GetComponent<TurretController>() != (Object)null))
			{
				if (((Component)gun).GetComponent<PhotonView>().IsMine && (Object)(object)PhysGrabber.instance != (Object)null && (Object)(object)PhysGrabber.instance.grabbedPhysGrabObject == (Object)(object)((Component)gun).GetComponent<PhysGrabObject>())
				{
					PhysGrabber.instance.ReleaseObject(((Component)gun).GetComponent<PhotonView>().ViewID, 0.1f);
				}
				GameObject val = GameObject.CreatePrimitive((PrimitiveType)3);
				val.transform.localScale = new Vector3(0.1f, 0.75f, 0.1f);
				val.transform.position = targetPos + Vector3.up * 0.375f;
				if (Object.op_Implicit((Object)(object)val.GetComponent<Collider>()))
				{
					Object.Destroy((Object)(object)val.GetComponent<Collider>());
				}
				Vector3 val2 = val.transform.position + Vector3.up * 0.425f;
				PhysGrabObject component = ((Component)gun).GetComponent<PhysGrabObject>();
				if ((Object)(object)component != (Object)null)
				{
					component.Teleport(val2, Quaternion.identity);
				}
				TurretController turretController = ((Component)gun).gameObject.AddComponent<TurretController>();
				turretController.stilt = val;
				turretController.Setup();
			}
		}
	}
	public class TurretController : MonoBehaviour
	{
		public GameObject stilt;

		private ItemGun itemGun;

		private PhysGrabObject physGrabObject;

		private ItemBattery itemBattery;

		private Rigidbody rb;

		private float checkEnemyTimer;

		private Transform target;

		private float range = 25f;

		public void Setup()
		{
			//IL_0072: 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)
			itemGun = ((Component)this).GetComponent<ItemGun>();
			physGrabObject = ((Component)this).GetComponent<PhysGrabObject>();
			itemBattery = ((Component)this).GetComponent<ItemBattery>();
			rb = ((Component)this).GetComponent<Rigidbody>();
			if ((Object)(object)physGrabObject != (Object)null)
			{
				((Behaviour)physGrabObject).enabled = false;
			}
			if ((Object)(object)rb != (Object)null)
			{
				rb.isKinematic = true;
				rb.velocity = Vector3.zero;
				rb.angularVelocity = Vector3.zero;
			}
		}

		public void Undeploy()
		{
			if ((Object)(object)stilt != (Object)null)
			{
				Object.Destroy((Object)(object)stilt);
			}
			if ((Object)(object)physGrabObject != (Object)null)
			{
				((Behaviour)physGrabObject).enabled = true;
			}
			if ((Object)(object)rb != (Object)null)
			{
				rb.isKinematic = false;
			}
			Object.Destroy((Object)(object)this);
		}

		private void Update()
		{
			//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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: 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)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: 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_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Invalid comparison between Unknown and I4
			if ((Object)(object)stilt != (Object)null)
			{
				((Component)this).transform.position = stilt.transform.position + Vector3.up * 0.425f;
			}
			if ((Object)(object)itemBattery != (Object)null)
			{
				itemBattery.batteryLife = 100f;
			}
			if ((Object)(object)itemGun == (Object)null || !((Component)itemGun).GetComponent<PhotonView>().IsMine)
			{
				return;
			}
			checkEnemyTimer -= Time.deltaTime;
			if (checkEnemyTimer <= 0f)
			{
				checkEnemyTimer = 0.1f;
				FindTarget();
			}
			if ((Object)(object)target != (Object)null)
			{
				Vector3 val = target.position - ((Component)this).transform.position;
				Quaternion val2 = Quaternion.LookRotation(val);
				((Component)this).transform.rotation = Quaternion.RotateTowards(((Component)this).transform.rotation, val2, Time.deltaTime * 500f);
				if (Vector3.Angle(((Component)this).transform.forward, val) < 10f && (int)itemGun.stateCurrent == 0)
				{
					itemGun.Shoot();
				}
			}
		}

		private void FindTarget()
		{
			//IL_00ac: 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_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			target = null;
			float num = range;
			if ((Object)(object)EnemyDirector.instance == (Object)null || EnemyDirector.instance.enemiesSpawned == null)
			{
				return;
			}
			RaycastHit val4 = default(RaycastHit);
			foreach (EnemyParent item in EnemyDirector.instance.enemiesSpawned)
			{
				if (!((Object)(object)item != (Object)null) || !item.Spawned || !((Object)(object)item.Enemy != (Object)null))
				{
					continue;
				}
				Transform val = item.Enemy.CenterTransform;
				if ((Object)(object)val == (Object)null)
				{
					val = ((Component)item.Enemy).transform;
				}
				float num2 = Vector3.Distance(((Component)this).transform.position, val.position);
				if (num2 < num)
				{
					Vector3 val2 = (((Object)(object)itemGun.gunMuzzle != (Object)null) ? itemGun.gunMuzzle.position : ((Component)this).transform.position);
					Vector3 val3 = val.position - val2;
					if (Physics.Raycast(val2, val3, ref val4, num2 + 1f, LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct())) && ((Object)(object)((RaycastHit)(ref val4)).transform == (Object)(object)val || ((RaycastHit)(ref val4)).transform.IsChildOf(((Component)item).transform) || (Object)(object)((Component)((RaycastHit)(ref val4)).collider).GetComponentInParent<EnemyParent>() == (Object)(object)item))
					{
						num = num2;
						target = val;
					}
				}
			}
		}

		private void OnDestroy()
		{
			if ((Object)(object)stilt != (Object)null)
			{
				Object.Destroy((Object)(object)stilt);
			}
			if ((Object)(object)physGrabObject != (Object)null)
			{
				((Behaviour)physGrabObject).enabled = true;
			}
			if ((Object)(object)rb != (Object)null)
			{
				rb.isKinematic = false;
			}
		}
	}
}