Decompiled source of Dont Touch Me v1.2.4

BepInEx\plugins\DontTouchMe.dll

Decompiled 3 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using GameNetcodeStuff;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("DontTouchMe")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DontTouchMe")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("2b5c0b79-7fa5-44d5-a3d7-384bed3474cb")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
internal class <Module>
{
	static <Module>()
	{
	}
}
namespace DontTouchMe;

public class Assets
{
	public static AssetBundle MainAssetBundle;

	public static EnemyType EnemyType;

	public static TerminalNode EnemyNode;

	public static TerminalKeyword EnemyKeyword;

	public static AudioClip AudioMasked1;

	public static AudioClip AudioMasked2;

	internal static Stream GetEmbededResource(string name)
	{
		return Assembly.GetExecutingAssembly().GetManifestResourceStream("DontTouchMe." + name);
	}

	public static void Init()
	{
		Stream embededResource = GetEmbededResource("dtm.bundle");
		MainAssetBundle = AssetBundle.LoadFromStream(embededResource);
		EnemyType = MainAssetBundle.LoadAsset<EnemyType>("Assets/Mods/DontTouchMe/Resources/DTMEnemy.asset");
		EnemyNode = MainAssetBundle.LoadAsset<TerminalNode>("Assets/Mods/DontTouchMe/Resources/DTMNode.asset");
		EnemyKeyword = MainAssetBundle.LoadAsset<TerminalKeyword>("Assets/Mods/DontTouchMe/Resources/DTMKeyword.asset");
		AudioMasked1 = MainAssetBundle.LoadAsset<AudioClip>("Assets/Mods/DontTouchMe/Resources/dtm_masked_laugh1.wav");
		AudioMasked2 = MainAssetBundle.LoadAsset<AudioClip>("Assets/Mods/DontTouchMe/Resources/dtm_masked_laugh2.wav");
	}
}
public class DTMEntityAI : EnemyAI
{
	public static List<DTMEntityAI> Instances = new List<DTMEntityAI>();

	[Header("DTM Specific")]
	public InteractTrigger[] Triggers;

	public GameObject Music;

	public AudioSource VoiceA;

	public AudioSource VoiceB;

	private float AttackTime;

	private bool IsAttacking;

	private bool HasAttacked;

	private bool AttemptedMurder;

	public MaskedPlayerEnemy MaskedEnemy;

	[Header("Disguise")]
	public GameObject MainModel;

	public GameObject Disguise;

	private int DisguiseID;

	private float ScreenShakeTime;

	private const float KillWindowMin = 2.3f;

	private const float KillWindowMax = 3.5f;

	private float KillWindowStart = 2.8f;

	private const string ButtonTouchParam = "Touched";

	private const string ButtonPressParam = "Press";

	private Coroutine ExplodePlayerCoroutine;

	public static int Count => Instances.Count;

	public static DTMEntityAI GetClosest(Vector3 pos)
	{
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		DTMEntityAI dTMEntityAI = null;
		if (Instances.Count == 0)
		{
			return dTMEntityAI;
		}
		if (Instances.Count == 1)
		{
			return Instances[0];
		}
		float num = float.MaxValue;
		foreach (DTMEntityAI instance in Instances)
		{
			if ((Object)(object)instance == (Object)null)
			{
				Instances.RemoveAll((DTMEntityAI v) => (Object)(object)v == (Object)null);
				dTMEntityAI = GetClosest(pos);
				break;
			}
			float num2 = Vector3.Distance(((Component)instance).transform.position, pos);
			if ((Object)(object)dTMEntityAI == (Object)null || num2 < num)
			{
				dTMEntityAI = instance;
				num = num2;
			}
		}
		return dTMEntityAI;
	}

	public void SetTrigger(bool interactable)
	{
		InteractTrigger[] triggers = Triggers;
		foreach (InteractTrigger val in triggers)
		{
			val.interactable = interactable;
		}
	}

	public bool CanBeShocked()
	{
		if (!IsAttacking)
		{
			return !HasAttacked;
		}
		return false;
	}

	public override void OnDestroy()
	{
		((EnemyAI)this).OnDestroy();
		Instances.Remove(this);
	}

	public override void Start()
	{
		//IL_00ee: 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_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Expected O, but got Unknown
		Instances.Add(this);
		base.skinnedMeshRenderers = ((Component)this).gameObject.GetComponentsInChildren<SkinnedMeshRenderer>(true);
		base.meshRenderers = ((Component)this).gameObject.GetComponentsInChildren<MeshRenderer>(true);
		base.thisNetworkObject = ((Component)this).gameObject.GetComponentInChildren<NetworkObject>(true);
		base.thisEnemyIndex = RoundManager.Instance.numberOfEnemiesInScene;
		RoundManager instance = RoundManager.Instance;
		instance.numberOfEnemiesInScene++;
		base.isOutside = Plugin.SpawnOutsideChance > 0 && Random.Range(0, 100) < Plugin.SpawnOutsideChance;
		if (base.isOutside)
		{
			base.allAINodes = GameObject.FindGameObjectsWithTag("OutsideAINode");
			if ((Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null)
			{
				((EnemyAI)this).EnableEnemyMesh(!StartOfRound.Instance.hangarDoorsClosed || !GameNetworkManager.Instance.localPlayerController.isInHangarShipRoom, false);
			}
		}
		else
		{
			base.allAINodes = GameObject.FindGameObjectsWithTag("AINode");
		}
		base.serverPosition = ((Component)this).transform.position;
		base.updatePositionThreshold = 0f;
		base.path1 = new NavMeshPath();
		base.openDoorSpeedMultiplier = base.enemyType.doorSpeedMultiplier;
		ResetInteraction(changeLocation: true);
		Debug.Log((object)"DON'T TOUCH ME | DON'T TOUCH ME | DON'T TOUCH ME | DON'T TOUCH ME | DON'T TOUCH ME | DON'T TOUCH ME");
		Debug.Log((object)("Spawned Outside: " + base.isOutside));
	}

	private void ResetInteraction(bool changeLocation)
	{
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
		MaskedEnemy = null;
		base.targetPlayer = null;
		IsAttacking = false;
		HasAttacked = false;
		AttemptedMurder = false;
		SetTrigger(interactable: true);
		((Component)VoiceA).gameObject.SetActive(false);
		base.creatureAnimator.ResetTrigger("Touched");
		base.creatureAnimator.ResetTrigger("Press");
		if (changeLocation)
		{
			if (((NetworkBehaviour)this).IsOwner)
			{
				Vector3 position = base.allAINodes[Random.Range(0, base.allAINodes.Length)].transform.position;
				position = RoundManager.Instance.GetNavMeshPosition(position, RoundManager.Instance.navHit, 1f, -1);
				((Component)this).transform.position = position;
				((Component)this).transform.rotation = Quaternion.Euler(0f, Random.Range(-180f, 180f), 0f);
				DisguiseID = ((Random.Range(0, 100) < Plugin.DisguiseAsItemChance) ? Random.Range(1, Disguise.transform.childCount) : (-1));
				Debug.Log((object)"[DTM] Trying to sync position with other players.");
				SyncSpawnOnServer();
			}
			else
			{
				base.isClientCalculatingAI = false;
			}
		}
	}

	public override void Update()
	{
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: 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_010a: 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)
		//IL_0123: 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_0143: 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)
		if (!IsAttacking)
		{
			return;
		}
		if (Object.op_Implicit((Object)(object)MaskedEnemy))
		{
			MaskedEnemy = null;
			base.targetPlayer = null;
		}
		float num = Time.time - AttackTime;
		PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
		bool flag = ((EnemyAI)this).PlayerIsTargetable(localPlayerController, false, false) || (localPlayerController.hasBegunSpectating && Object.op_Implicit((Object)(object)localPlayerController.spectatedPlayerScript) && ((EnemyAI)this).PlayerIsTargetable(localPlayerController.spectatedPlayerScript, false, false));
		if (flag && ScreenShakeTime < Time.time)
		{
			HUDManager.Instance.ShakeCamera((ScreenShakeType)3);
			ScreenShakeTime = Time.time + 0.1f;
		}
		AudioSource voiceA = VoiceA;
		bool flag3 = (VoiceB.mute = flag);
		voiceA.mute = !flag3;
		if (num > KillWindowStart && num < 4.4f)
		{
			if (localPlayerController.isPlayerControlled && !localPlayerController.isPlayerDead && flag)
			{
				Vector3 val = ((Component)localPlayerController).transform.position - ((Component)this).transform.position;
				Vector3 val2 = ((Vector3)(ref val)).normalized * Random.Range(15f, 30f);
				val2.y = Random.Range(10f, 15f);
				Vector3 val3 = val2;
				val = default(Vector3);
				localPlayerController.KillPlayer(val3, true, (CauseOfDeath)3, 0, val);
				ExplodePlayerServerRpc((int)localPlayerController.playerClientId);
			}
			if (Plugin.IncludeMonstersOnKill && ((NetworkBehaviour)this).IsServer && !AttemptedMurder)
			{
				foreach (EnemyAI spawnedEnemy in RoundManager.Instance.SpawnedEnemies)
				{
					if (Object.op_Implicit((Object)(object)spawnedEnemy) && spawnedEnemy.isOutside == base.isOutside && (Object)(object)((Component)spawnedEnemy).gameObject != (Object)(object)((Component)this).gameObject && spawnedEnemy.thisNetworkObject.IsSpawned && (Plugin.IncludeUnkillableMonsters || spawnedEnemy.enemyType.canDie))
					{
						Debug.Log((object)("[DTM] Killing " + ((Object)spawnedEnemy).name));
						spawnedEnemy.thisNetworkObject.Despawn(true);
					}
				}
				AttemptedMurder = true;
			}
		}
		if (num >= 5f)
		{
			if (Plugin.DestroyEntityAfterTouch)
			{
				IsAttacking = false;
				HasAttacked = true;
				((EnemyAI)this).KillEnemy(true);
			}
			else
			{
				ResetInteraction(Plugin.ChangeLocationAfterTouch);
			}
		}
	}

	private IEnumerator ExplodePlayerEffect(int clientId)
	{
		PlayerControllerB killedPlayer = StartOfRound.Instance.allPlayerScripts[clientId];
		float startTime = Time.realtimeSinceStartup;
		yield return (object)new WaitUntil((Func<bool>)(() => Time.realtimeSinceStartup - startTime > 1f || (Object)(object)killedPlayer.deadBody != (Object)null));
		Transform transform = ((Component)killedPlayer).transform;
		if ((Object)(object)killedPlayer.deadBody != (Object)null)
		{
			transform = ((Component)killedPlayer.deadBody).transform;
		}
		Object.Instantiate<GameObject>(StartOfRound.Instance.explosionPrefab, transform.position + Vector3.up * 0.5f, Quaternion.Euler(-90f, 0f, 0f), RoundManager.Instance.mapPropsContainer.transform).SetActive(true);
		base.inSpecialAnimation = false;
	}

	[ClientRpc]
	private void ExplodePlayerClientRpc(int clientId)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Invalid comparison between Unknown and I4
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager == null || !networkManager.IsListening)
		{
			return;
		}
		if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
		{
			ClientRpcParams val = default(ClientRpcParams);
			FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3906254083u, val, (RpcDelivery)0);
			BytePacker.WriteValueBitPacked(val2, clientId);
			((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3906254083u, val, (RpcDelivery)0);
		}
		if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
		{
			if (ExplodePlayerCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(ExplodePlayerCoroutine);
			}
			ExplodePlayerCoroutine = ((MonoBehaviour)this).StartCoroutine(ExplodePlayerEffect(clientId));
		}
	}

	[ServerRpc(RequireOwnership = false)]
	private void ExplodePlayerServerRpc(int clientId)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Invalid comparison between Unknown and I4
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(877622320u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, clientId);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 877622320u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ExplodePlayerClientRpc(clientId);
			}
		}
	}

	private void UpdateDisguise()
	{
		MainModel.SetActive(DisguiseID < 1);
		Disguise.SetActive(!MainModel.activeSelf);
		if (Disguise.activeSelf)
		{
			Transform transform = Disguise.transform;
			for (int i = 1; i < transform.childCount; i++)
			{
				((Component)transform.GetChild(i)).gameObject.SetActive(i == DisguiseID);
			}
		}
	}

	private void SyncSpawnOnServer()
	{
		//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_0058: 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_0035: 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)
		base.serverPosition = ((Component)this).transform.position;
		Debug.Log((object)("[DTM] Sync Spawn On Server: " + DisguiseID));
		if (((NetworkBehaviour)this).IsOwner)
		{
			SpawnClientRpc(base.serverPosition, ((Component)this).transform.eulerAngles.y, DisguiseID);
		}
		else
		{
			SpawnServerRpc(base.serverPosition, ((Component)this).transform.eulerAngles.y, DisguiseID);
		}
	}

	[ClientRpc]
	public void SpawnClientRpc(Vector3 newPos, float yRot, int disguise)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: 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_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3860255087u, val, (RpcDelivery)0);
				((FastBufferWriter)(ref val2)).WriteValueSafe(ref newPos);
				((FastBufferWriter)(ref val2)).WriteValueSafe<float>(ref yRot, default(ForPrimitives));
				BytePacker.WriteValueBitPacked(val2, disguise);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3860255087u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				Debug.Log((object)("[DTM] Received new spawn: " + DisguiseID));
				DisguiseID = disguise;
				((Component)this).transform.position = newPos;
				((Component)this).transform.rotation = Quaternion.Euler(0f, yRot, 0f);
				Music.SetActive(Plugin.PlayMusic && DisguiseID < 1);
				UpdateDisguise();
			}
		}
	}

	[ServerRpc]
	public void SpawnServerRpc(Vector3 newPos, float yRot, int disguise)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Invalid comparison between Unknown and I4
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Invalid comparison between Unknown and I4
		//IL_0137: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: 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_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Invalid comparison between Unknown and I4
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager == null || !networkManager.IsListening)
		{
			return;
		}
		if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
		{
			if (((NetworkBehaviour)this).OwnerClientId != networkManager.LocalClientId)
			{
				if ((int)networkManager.LogLevel <= 1)
				{
					Debug.LogError((object)"Only the owner can invoke a ServerRpc that requires ownership!");
				}
				return;
			}
			ServerRpcParams val = default(ServerRpcParams);
			FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2003288437u, val, (RpcDelivery)0);
			((FastBufferWriter)(ref val2)).WriteValueSafe(ref newPos);
			((FastBufferWriter)(ref val2)).WriteValueSafe<float>(ref yRot, default(ForPrimitives));
			BytePacker.WriteValueBitPacked(val2, disguise);
			((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2003288437u, val, (RpcDelivery)0);
		}
		if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
		{
			SpawnClientRpc(newPos, yRot, disguise);
		}
	}

	public void OnTouched(PlayerControllerB player)
	{
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		if (!IsAttacking && !((Object)(object)player == (Object)null))
		{
			int num = ((DisguiseID > 0) ? 80 : 20);
			if (Random.Range(0, 100) > num)
			{
				StartAttack(!player.isInsideFactory);
			}
			else if (Random.Range(0, 100) < 10)
			{
				player.JumpToFearLevel(1f, true);
			}
			else
			{
				player.DamagePlayer(999, true, true, (CauseOfDeath)0, Random.Range(1, 3), false, default(Vector3));
			}
		}
	}

	public void StartAttack(bool outside)
	{
		Debug.Log((object)"[DTM] Starting attack");
		if (((NetworkBehaviour)this).IsOwner)
		{
			AttackClientRpc(outside);
		}
		else
		{
			AttackServerRpc(outside);
		}
	}

	[ClientRpc]
	public void AttackClientRpc(bool outside)
	{
		//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)
		{
			return;
		}
		if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
		{
			ClientRpcParams val = default(ClientRpcParams);
			FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3888608358u, val, (RpcDelivery)0);
			((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref outside, default(ForPrimitives));
			((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3888608358u, val, (RpcDelivery)0);
		}
		if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
		{
			Debug.Log((object)"[DTM] Attempting attack on client");
			if (!IsAttacking && !HasAttacked)
			{
				AttackTime = Time.time;
				ScreenShakeTime = 0f;
				KillWindowStart = Random.Range(2.3f, 3.5f);
				DisguiseID = -1;
				Disguise.SetActive(false);
				MainModel.SetActive(true);
				Music.SetActive(false);
				((Component)VoiceA).gameObject.SetActive(true);
				base.isOutside = outside;
				SetTrigger(interactable: false);
				IsAttacking = true;
				base.creatureAnimator.SetTrigger("Touched");
			}
		}
	}

	[ServerRpc(RequireOwnership = false)]
	public void AttackServerRpc(bool outside)
	{
		//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)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2283008872u, val, (RpcDelivery)0);
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref outside, default(ForPrimitives));
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2283008872u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				Debug.Log((object)"[DTM] Attempting attack from server");
				AttackClientRpc(outside);
			}
		}
	}

	public override void HitEnemy(int force = 1, PlayerControllerB playerWhoHit = null, bool playHitSFX = false, int hitID = -1)
	{
		Debug.Log((object)("[DTM] Hit by enemy: " + (object)playerWhoHit));
		OnTouched(playerWhoHit);
	}

	public override void SetEnemyStunned(bool setToStunned, float setToStunTime = 1f, PlayerControllerB setStunnedByPlayer = null)
	{
		if (setToStunned)
		{
			OnTouched(setStunnedByPlayer);
		}
	}

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

	[RuntimeInitializeOnLoadMethod]
	internal static void InitializeRPCS_DTMEntityAI()
	{
		//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
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Expected O, but got Unknown
		NetworkManager.__rpc_func_table.Add(3906254083u, new RpcReceiveHandler(__rpc_handler_3906254083));
		NetworkManager.__rpc_func_table.Add(877622320u, new RpcReceiveHandler(__rpc_handler_877622320));
		NetworkManager.__rpc_func_table.Add(3860255087u, new RpcReceiveHandler(__rpc_handler_3860255087));
		NetworkManager.__rpc_func_table.Add(2003288437u, new RpcReceiveHandler(__rpc_handler_2003288437));
		NetworkManager.__rpc_func_table.Add(3888608358u, new RpcReceiveHandler(__rpc_handler_3888608358));
		NetworkManager.__rpc_func_table.Add(2283008872u, new RpcReceiveHandler(__rpc_handler_2283008872));
	}

	private static void __rpc_handler_3906254083(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
	{
		//IL_0023: 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_0050: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = target.NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			int clientId = default(int);
			ByteUnpacker.ReadValueBitPacked(reader, ref clientId);
			target.__rpc_exec_stage = (__RpcExecStage)2;
			((DTMEntityAI)(object)target).ExplodePlayerClientRpc(clientId);
			target.__rpc_exec_stage = (__RpcExecStage)0;
		}
	}

	private static void __rpc_handler_877622320(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
	{
		//IL_0023: 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_0050: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = target.NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			int clientId = default(int);
			ByteUnpacker.ReadValueBitPacked(reader, ref clientId);
			target.__rpc_exec_stage = (__RpcExecStage)1;
			((DTMEntityAI)(object)target).ExplodePlayerServerRpc(clientId);
			target.__rpc_exec_stage = (__RpcExecStage)0;
		}
	}

	private static void __rpc_handler_3860255087(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_004b: 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_0069: 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)
		NetworkManager networkManager = target.NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			Vector3 newPos = default(Vector3);
			((FastBufferReader)(ref reader)).ReadValueSafe(ref newPos);
			float yRot = default(float);
			((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref yRot, default(ForPrimitives));
			int disguise = default(int);
			ByteUnpacker.ReadValueBitPacked(reader, ref disguise);
			target.__rpc_exec_stage = (__RpcExecStage)2;
			((DTMEntityAI)(object)target).SpawnClientRpc(newPos, yRot, disguise);
			target.__rpc_exec_stage = (__RpcExecStage)0;
		}
	}

	private static void __rpc_handler_2003288437(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Invalid comparison between Unknown and I4
		NetworkManager networkManager = target.NetworkManager;
		if (networkManager == null || !networkManager.IsListening)
		{
			return;
		}
		if (rpcParams.Server.Receive.SenderClientId != target.OwnerClientId)
		{
			if ((int)networkManager.LogLevel <= 1)
			{
				Debug.LogError((object)"Only the owner can invoke a ServerRpc that requires ownership!");
			}
			return;
		}
		Vector3 newPos = default(Vector3);
		((FastBufferReader)(ref reader)).ReadValueSafe(ref newPos);
		float yRot = default(float);
		((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref yRot, default(ForPrimitives));
		int disguise = default(int);
		ByteUnpacker.ReadValueBitPacked(reader, ref disguise);
		target.__rpc_exec_stage = (__RpcExecStage)1;
		((DTMEntityAI)(object)target).SpawnServerRpc(newPos, yRot, disguise);
		target.__rpc_exec_stage = (__RpcExecStage)0;
	}

	private static void __rpc_handler_3888608358(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 outside = default(bool);
			((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref outside, default(ForPrimitives));
			target.__rpc_exec_stage = (__RpcExecStage)2;
			((DTMEntityAI)(object)target).AttackClientRpc(outside);
			target.__rpc_exec_stage = (__RpcExecStage)0;
		}
	}

	private static void __rpc_handler_2283008872(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 outside = default(bool);
			((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref outside, default(ForPrimitives));
			target.__rpc_exec_stage = (__RpcExecStage)1;
			((DTMEntityAI)(object)target).AttackServerRpc(outside);
			target.__rpc_exec_stage = (__RpcExecStage)0;
		}
	}

	protected internal override string __getTypeName()
	{
		return "DTMEntityAI";
	}
}
public class DTMHitBox : MonoBehaviour, IHittable, IShockableWithGun
{
	public DTMEntityAI mainScript;

	bool IHittable.Hit(int force, Vector3 hitDirection, PlayerControllerB playerWhoHit, bool playHitSFX, int hitID = -1)
	{
		((EnemyAI)mainScript).SetEnemyStunned(true, 1f, playerWhoHit);
		return true;
	}

	bool IShockableWithGun.CanBeShocked()
	{
		return mainScript.CanBeShocked();
	}

	Vector3 IShockableWithGun.GetShockablePosition()
	{
		//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_0039: 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_001e: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)((EnemyAI)mainScript).eye != (Object)null)
		{
			return ((EnemyAI)mainScript).eye.position;
		}
		return ((Component)this).transform.position + Vector3.up * 1f;
	}

	float IShockableWithGun.GetDifficultyMultiplier()
	{
		return ((EnemyAI)mainScript).enemyType.stunGameDifficultyMultiplier;
	}

	void IShockableWithGun.ShockWithGun(PlayerControllerB shockedByPlayer)
	{
		((EnemyAI)mainScript).SetEnemyStunned(true, 0.25f, shockedByPlayer);
		DTMEntityAI dTMEntityAI = mainScript;
		((EnemyAI)dTMEntityAI).stunnedIndefinitely = ((EnemyAI)dTMEntityAI).stunnedIndefinitely + 1;
	}

	Transform IShockableWithGun.GetShockableTransform()
	{
		return ((Component)this).transform;
	}

	NetworkObject IShockableWithGun.GetNetworkObject()
	{
		return ((NetworkBehaviour)mainScript).NetworkObject;
	}

	void IShockableWithGun.StopShockingWithGun()
	{
	}
}
[BepInPlugin("Kittenji.DontTouchMe", "Don't Touch Me", "1.2.4")]
public class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(GameNetworkManager))]
	internal class GameNetworkManagerPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPatch()
		{
			((Component)GameNetworkManager.Instance).GetComponent<NetworkManager>().AddNetworkPrefab(Assets.EnemyType.enemyPrefab);
			Debug.Log((object)"[DTM] Added network prefab");
		}
	}

	[HarmonyPatch(typeof(Terminal))]
	internal class TerminalPatch
	{
		private static Random TerminalRandom = new Random();

		private static FieldInfo InteractTriggerField = AccessTools.Field(typeof(Terminal), "terminalTrigger");

		private static InteractTrigger m_Trigger;

		private static bool HandlingSpecialEvent;

		private static InteractTrigger GetTrigger(Terminal __instance)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			if ((Object)(object)m_Trigger == (Object)null)
			{
				m_Trigger = (InteractTrigger)InteractTriggerField.GetValue(__instance);
			}
			return m_Trigger;
		}

		private static void PerformRandomTPOnPlayer(PlayerControllerB localPlayer, int index, bool redirected = false)
		{
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: 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_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: 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_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			if (localPlayer.isPlayerDead)
			{
				return;
			}
			bool flag;
			Vector3 val;
			switch (index)
			{
			default:
				return;
			case 0:
			case 1:
			{
				flag = index == 0;
				GameObject[] array = (flag ? RoundManager.Instance.insideAINodes : RoundManager.Instance.outsideAINodes);
				if (array.Length != 0)
				{
					val = array[Random.Range(0, array.Length)].transform.position;
					val = RoundManager.Instance.GetRandomNavMeshPositionInRadiusSpherical(val, 10f, default(NavMeshHit));
					Debug.LogWarning((object)"Where am I anyway?");
					break;
				}
				return;
			}
			case 2:
			{
				Turret[] array2 = Object.FindObjectsOfType<Turret>(false);
				if (array2 == null || array2.Length == 0)
				{
					PerformRandomTPOnPlayer(localPlayer, redirected ? Random.Range(0, 2) : 3, redirected: true);
					return;
				}
				Turret val3 = array2[Random.Range(0, array2.Length)];
				if ((Object)(object)val3 == (Object)null)
				{
					return;
				}
				val = ((Component)val3).transform.position;
				flag = val.y < -80f;
				val = RoundManager.Instance.GetRandomNavMeshPositionInRadiusSpherical(val, 2f, default(NavMeshHit));
				Debug.LogError((object)"Run Forest, RUN!!!");
				break;
			}
			case 3:
			{
				Landmine[] array3 = Object.FindObjectsOfType<Landmine>(false);
				if (array3 == null || array3.Length == 0)
				{
					PerformRandomTPOnPlayer(localPlayer, redirected ? Random.Range(0, 2) : 2, redirected: true);
					return;
				}
				Landmine val4 = array3[Random.Range(0, array3.Length)];
				if ((Object)(object)val4 == (Object)null)
				{
					return;
				}
				val = ((Component)val4).transform.position;
				flag = val.y < -80f;
				val = RoundManager.Instance.GetRandomNavMeshPositionInRadiusSpherical(val, 2f, default(NavMeshHit));
				Debug.LogError((object)"WAIT, DON'T MOVE!!!... Or do... I'm a programmer, not a land mine inspector.");
				break;
			}
			case 4:
			{
				List<EnemyAI> spawnedEnemies = RoundManager.Instance.SpawnedEnemies;
				if (spawnedEnemies == null || spawnedEnemies.Count == 0)
				{
					PerformRandomTPOnPlayer(localPlayer, Random.Range(0, 2), redirected: true);
					return;
				}
				EnemyAI val2 = spawnedEnemies[Random.Range(0, spawnedEnemies.Count)];
				val = ((Component)val2).transform.position;
				flag = val.y < -80f;
				val = RoundManager.Instance.GetRandomNavMeshPositionInRadiusSpherical(val, 8f, default(NavMeshHit));
				Debug.LogError((object)"OH NO!, that is horrible!!!............ anyway..");
				break;
			}
			case 5:
				val = ((Component)localPlayer).transform.position + Vector3.up * 100f;
				flag = false;
				Debug.LogError((object)"Fly like a bird... wait, why are you falling?");
				break;
			}
			if (!localPlayer.isPlayerDead)
			{
				localPlayer.DropAllHeldItems(true, false);
				localPlayer.isInElevator = false;
				localPlayer.isInHangarShipRoom = false;
				localPlayer.isInsideFactory = flag;
				localPlayer.averageVelocity = 0f;
				localPlayer.velocityLastFrame = Vector3.zero;
				localPlayer.TeleportPlayer(val, false, 0f, false, true);
				HUDManager.Instance.ShakeCamera((ScreenShakeType)1);
			}
		}

		private static IEnumerator SpecialEvent(Terminal __instance, int index)
		{
			HandlingSpecialEvent = true;
			PlayerControllerB localPlayer = GameNetworkManager.Instance.localPlayerController;
			InteractTrigger trigger = GetTrigger(__instance);
			if (!Object.op_Implicit((Object)(object)trigger))
			{
				HandlingSpecialEvent = false;
				yield break;
			}
			yield return (object)new WaitForSeconds(0.35f);
			switch (index)
			{
			case 1:
				__instance.QuitTerminal(true);
				if (Random.Range(0, 100) < 34)
				{
					while (trigger.currentCooldownValue > 0f)
					{
						yield return null;
					}
					localPlayer.DropAllHeldItems(true, false);
					Debug.LogError((object)"Haha, butter fingers!");
				}
				else
				{
					Debug.LogWarning((object)"GET OUT!");
				}
				break;
			case 2:
				__instance.QuitTerminal(true);
				while (trigger.currentCooldownValue > 0f)
				{
					yield return null;
				}
				if (!StartOfRound.Instance.inShipPhase)
				{
					index = RoundManager.Instance.GetRandomWeightedIndex(Terminal_Weights_TP, (Random)null);
					PerformRandomTPOnPlayer(localPlayer, index);
				}
				break;
			case 3:
			{
				__instance.QuitTerminal(true);
				while (trigger.currentCooldownValue > 0f)
				{
					yield return null;
				}
				for (int i = 0; i < localPlayer.ItemSlots.Length; i++)
				{
					GrabbableObject val = localPlayer.ItemSlots[i];
					if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.itemProperties) && val.itemProperties.requiresBattery)
					{
						val.insertedBattery = new Battery(true, 0f);
					}
				}
				Debug.LogError((object)"This mod is not sponsored by DURACELL");
				break;
			}
			case 4:
			{
				__instance.QuitTerminal(true);
				while (trigger.currentCooldownValue > 0f)
				{
					yield return null;
				}
				if (StartOfRound.Instance.inShipPhase)
				{
					break;
				}
				GameObject[] outsideAINodes = RoundManager.Instance.outsideAINodes;
				if (outsideAINodes.Length != 0)
				{
					int num = Random.Range(1, 5);
					for (int j = 0; j < num; j++)
					{
						RoundManager.Instance.SpawnEnemyOnServer(Vector3.zero, Random.Range(-180f, 180f), -3);
					}
					Debug.LogError((object)("OOPS! Have fun with " + ((num > 1) ? "those" : "that") + "..."));
				}
				break;
			}
			case 5:
				__instance.QuitTerminal(true);
				while (trigger.currentCooldownValue > 0f)
				{
					yield return null;
				}
				if (!StartOfRound.Instance.inShipPhase && localPlayer.health > 5)
				{
					localPlayer.DamagePlayer(localPlayer.health - 5, true, true, (CauseOfDeath)0, 0, false, default(Vector3));
					Debug.LogError((object)"Ouch, that must hurt.");
				}
				break;
			case 6:
				__instance.QuitTerminal(true);
				while (trigger.currentCooldownValue > 0f)
				{
					yield return null;
				}
				if (!StartOfRound.Instance.inShipPhase)
				{
					localPlayer.KillPlayer(Vector3.up, true, (CauseOfDeath)0, 0, default(Vector3));
					Debug.LogError((object)"Curiosity killed the cat, in this case... you");
				}
				break;
			}
			HandlingSpecialEvent = false;
		}

		[HarmonyPatch("RunTerminalEvents")]
		[HarmonyPostfix]
		private static void RunTerminalEventsPatch(ref Terminal __instance, TerminalNode node)
		{
			if (node.terminalEvent == "dontReadMe")
			{
				Debug.Log((object)"Don't read me, please.");
				int randomWeightedIndex = RoundManager.Instance.GetRandomWeightedIndex(Terminal_Weights, TerminalRandom);
				if (!HandlingSpecialEvent)
				{
					((MonoBehaviour)__instance).StartCoroutine(SpecialEvent(__instance, randomWeightedIndex));
				}
			}
		}

		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void StartPatch(ref Terminal __instance)
		{
			//IL_00e3: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Expected O, but got Unknown
			Debug.Log((object)"[DTM] Adding terminal entries");
			TerminalNode terminalNode = Assets.EnemyNode;
			TerminalKeyword val = __instance.terminalNodes.allKeywords.First((TerminalKeyword k) => k.word == "info");
			if (!__instance.enemyFiles.Any((TerminalNode x) => x.creatureName == terminalNode.creatureName))
			{
				TerminalKeyword keyword = Assets.EnemyKeyword;
				keyword.defaultVerb = val;
				List<TerminalKeyword> list = __instance.terminalNodes.allKeywords.ToList();
				if (!list.Any((TerminalKeyword x) => x.word == keyword.word))
				{
					list.Add(keyword);
					__instance.terminalNodes.allKeywords = list.ToArray();
				}
				List<CompatibleNoun> list2 = val.compatibleNouns.ToList();
				if (!list2.Any((CompatibleNoun x) => x.noun.word == keyword.word))
				{
					list2.Add(new CompatibleNoun
					{
						noun = keyword,
						result = terminalNode
					});
				}
				val.compatibleNouns = list2.ToArray();
				terminalNode.creatureFileID = __instance.enemyFiles.Count;
				__instance.enemyFiles.Add(terminalNode);
				Assets.EnemyType.enemyPrefab.GetComponentInChildren<ScanNodeProperties>().creatureScanID = terminalNode.creatureFileID;
				Debug.Log((object)"[DTM] Done adding entries.");
			}
		}
	}

	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void AwakePatch(ref StartOfRound __instance)
		{
			//IL_007b: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			EnemyType enemyDef = Assets.EnemyType;
			SelectableLevel[] levels = __instance.levels;
			foreach (SelectableLevel val in levels)
			{
				if (val.Enemies.Count >= 2 && !val.Enemies.Any((SpawnableEnemyWithRarity e) => (Object)(object)e.enemyType == (Object)(object)enemyDef))
				{
					Debug.Log((object)("[DTM] Adding entity to level: " + val.PlanetName));
					val.Enemies.Add(new SpawnableEnemyWithRarity
					{
						enemyType = enemyDef,
						rarity = SpawnRarity
					});
				}
			}
		}
	}

	private const string modGUID = "Kittenji.DontTouchMe";

	private readonly Harmony harmony = new Harmony("Kittenji.DontTouchMe");

	public static bool PlayMusic = true;

	public static bool IncludeMonstersOnKill = true;

	public static bool IncludeUnkillableMonsters = true;

	public static bool DestroyMonstersOnKill = true;

	public static int SpawnRarity = 24;

	public static int SpawnOutsideChance = 2;

	public static bool ChangeLocationAfterTouch = true;

	public static bool DestroyEntityAfterTouch = true;

	public static int DisguiseAsItemChance = 40;

	private const int Terminal_Weight_None = 0;

	private const int Terminal_Weight_Quit = 0;

	private const int Terminal_Weight_TP = 15;

	private const int Terminal_Weight_Battery = 14;

	private const int Terminal_Weight_Punish = 14;

	private const int Terminal_Weight_Break = 3;

	private const int Terminal_Weight_Kill = 1;

	private const int Terminal_Weight_TP_Inside = 36;

	private const int Terminal_Weight_TP_Outside = 36;

	private const int Terminal_Weight_TP_Turret = 18;

	private const int Terminal_Weight_TP_Landmine = 6;

	private const int Terminal_Weight_TP_Monster = 3;

	private const int Terminal_Weight_TP_Sky = 1;

	private const int Terminal_Punish_Min = 1;

	private const int Terminal_Punish_Max = 5;

	private static readonly int[] Terminal_Weights = new int[7] { 0, 0, 15, 14, 14, 3, 1 };

	private static readonly int[] Terminal_Weights_TP = new int[6] { 36, 36, 18, 6, 3, 1 };

	private void Awake()
	{
		SpawnRarity = ((BaseUnityPlugin)this).Config.Bind<int>("Spawning", "Spawn Rarity", 24, "Spawn rarity. Lower value means lower chance to spawn. (default = 24)").Value;
		SpawnOutsideChance = ((BaseUnityPlugin)this).Config.Bind<int>("Spawning", "Spawn Rarity Outside", 2, "Random chance percentage for this entity to spawn outside. (default = 2)").Value;
		DisguiseAsItemChance = ((BaseUnityPlugin)this).Config.Bind<int>("Spawning", "Disguise As Item Chance", 45, "Random chance percentage for this entity to disguise itself as an item. (default = 45)").Value;
		ChangeLocationAfterTouch = ((BaseUnityPlugin)this).Config.Bind<bool>("Interaction", "Changes Location", true, "If 'true' the entity will change it's position to a random location after the animation. (default = true)").Value;
		DestroyEntityAfterTouch = ((BaseUnityPlugin)this).Config.Bind<bool>("Interaction", "Destroy After Touch", false, "If 'true' the entity will hide for the rest of the round after touch. It will teleport to a different location. (default = false)").Value;
		IncludeMonstersOnKill = ((BaseUnityPlugin)this).Config.Bind<bool>("Interaction", "Include Monsters On Kill", true, "If 'true' the entity will not pick favorites and will try killing monsters in the facility as well. (default = true)").Value;
		DestroyMonstersOnKill = ((BaseUnityPlugin)this).Config.Bind<bool>("Interaction", "Destroy Monsters On Kill", true, "If 'true' monsters will directly despawn to prevent lag and other potential issues. (default = true)").Value;
		IncludeUnkillableMonsters = ((BaseUnityPlugin)this).Config.Bind<bool>("Interaction", "Include Unkillable Monsters", true, "If 'true' the entity will also kill unkillable monsters too. (default = true)").Value;
		PlayMusic = ((BaseUnityPlugin)this).Config.Bind<bool>("Audio", "Play Music", true, "If 'true' the entity will play ominous music (Lobotomy Corp OST - Neutral 01) that can be heard in the distance, getting more noticeable the closer you get to it. (default = true)").Value;
		SpawnRarity = Mathf.Min(100, Mathf.Max(1, SpawnRarity));
		SpawnOutsideChance = Mathf.Min(100, Mathf.Max(0, SpawnOutsideChance));
		DisguiseAsItemChance = Mathf.Min(100, Mathf.Max(0, DisguiseAsItemChance));
		((BaseUnityPlugin)this).Config.Save();
		Assets.Init();
		harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Patched!");
		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);
				}
			}
		}
	}
}