Decompiled source of MaskedReplacePlayer v1.0.1

MaskedReplacePlayer.dll

Decompiled 10 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 BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("MaskedReplacePlayer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("TENCENT")]
[assembly: AssemblyProduct("MaskedReplacePlayer")]
[assembly: AssemblyCopyright("Copyright © TENCENT 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("996ee7ef-3a81-4091-bc49-a4e2e4d566f3")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MaskedReplacePlayer;

[BepInPlugin("MaskedReplacePlayer", "MaskedReplacePlayer", "0.0.1")]
public class Plugin : BaseUnityPlugin
{
	private readonly Harmony harmony = new Harmony("MaskedEnemyRework");

	private static Plugin Instance;

	internal ManualLogSource logger;

	private ConfigEntry<float> ReplaceRatePerMinConfig;

	private ConfigEntry<float> RateChangePerMinConfig;

	private ConfigEntry<bool> ReplaceOutsideConfig;

	private ConfigEntry<bool> RemoveMaskConfig;

	private ConfigEntry<bool> RemoveArmsConfig;

	private ConfigEntry<int> TeleportPlayerConfig;

	private ConfigEntry<int> ShowPlayerNameConfig;

	public static float ReplaceRatePerMin;

	public static float RateChangePerMin;

	public static bool ReplaceOutside;

	public static int TeleportPlayer;

	public static bool RemoveMask;

	public static bool RemoveArms;

	public static int ShowPlayerName;

	public static int PlayerCount;

	public static SpawnableEnemyWithRarity maskedPrefab;

	public static GameObject networkPrefab;

	public static AssetBundle assetBundle { get; private set; }

	private void Awake()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		if ((Object)Instance == (Object)null)
		{
			Instance = this;
		}
		ReplaceRatePerMinConfig = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Replace player rate per min", 5f, (ConfigDescription)null);
		RateChangePerMinConfig = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Rate change per min", 0.5f, (ConfigDescription)null);
		ReplaceOutsideConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Can zombie replace player outside", true, (ConfigDescription)null);
		TeleportPlayerConfig = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Replace player type", 2, "0 = Masked will spawn nearest 1 = Spawn masked and teleport player 2 = Random 0 or 1");
		RemoveMaskConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Remove zombie mask", true, (ConfigDescription)null);
		RemoveArmsConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Remove zombie arms", true, (ConfigDescription)null);
		ShowPlayerNameConfig = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Masked show player name", 1, "0 = close 1 = normal 2 = always");
		ReplaceRatePerMin = ReplaceRatePerMinConfig.Value;
		RateChangePerMin = RateChangePerMinConfig.Value;
		ReplaceOutside = ReplaceOutsideConfig.Value;
		TeleportPlayer = TeleportPlayerConfig.Value;
		RemoveMask = RemoveMaskConfig.Value;
		RemoveArms = RemoveArmsConfig.Value;
		ShowPlayerName = ShowPlayerNameConfig.Value;
		assetBundle = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "networkprefab"));
		logger = ((BaseUnityPlugin)this).Logger;
		networkPrefab = assetBundle.LoadAsset<GameObject>("Assets/AssetBundles/networkPrefab.prefab");
		networkPrefab.AddComponent<MaskedReplaceNetworkComp>();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin MaskedReplacePlayer is loaded");
		harmony.PatchAll(typeof(Plugin));
		harmony.PatchAll(typeof(GetMaskedPrefabForLaterUse));
		harmony.PatchAll(typeof(MaskedReplaceInit));
		harmony.PatchAll(typeof(Masked_Patch));
		harmony.PatchAll(typeof(PlayerController_Patch));
	}
}
[HarmonyPatch(typeof(Terminal))]
internal class GetMaskedPrefabForLaterUse
{
	[HarmonyPatch("Start")]
	[HarmonyPostfix]
	private static void SavesPrefabForLaterUse(ref SelectableLevel[] ___moonsCatalogueList)
	{
		ManualLogSource val = Logger.CreateLogSource("MaskedReplacePlayer");
		SelectableLevel[] array = ___moonsCatalogueList;
		for (int i = 0; i < array.Length; i++)
		{
			foreach (SpawnableEnemyWithRarity enemy in array[i].Enemies)
			{
				if (enemy.enemyType.enemyName == "Masked")
				{
					val.LogInfo((object)"Found Masked!");
					Plugin.maskedPrefab = enemy;
				}
			}
		}
	}
}
internal class MaskedReplaceInit
{
	[HarmonyPatch(typeof(MenuManager), "Start")]
	[HarmonyPostfix]
	public static void InitNetworkPrefab(MenuManager __instance)
	{
		Logger.CreateLogSource("MaskedReplaceNetworkInit").LogInfo((object)"MaskedReplaceNetworkInit");
		if (!NetworkManager.Singleton.NetworkConfig.Prefabs.Prefabs.Select((NetworkPrefab pref) => ((Object)pref.Prefab).name).Contains(((Object)Plugin.networkPrefab).name))
		{
			NetworkManager.Singleton.AddNetworkPrefab(Plugin.networkPrefab);
		}
	}

	[HarmonyPatch(typeof(RoundManager), "Start")]
	[HarmonyPrefix]
	private static void InitMaskedReplace(ref SelectableLevel ___currentLevel)
	{
		if (((NetworkBehaviour)RoundManager.Instance).IsServer)
		{
			Logger.CreateLogSource("MaskedReplaceInit").LogInfo((object)"InitMaskedReplace");
			Object.Instantiate<GameObject>(Plugin.networkPrefab).GetComponent<NetworkObject>().Spawn(false);
		}
	}

	[HarmonyPatch(typeof(RoundManager), "BeginEnemySpawning")]
	[HarmonyPrefix]
	private static void AttachMaskReplaceComp(ref SelectableLevel ___currentLevel)
	{
		ManualLogSource val = Logger.CreateLogSource("MaskedReplaceInit");
		val.LogInfo((object)"MaskedReplaceComp Start Attach");
		if (!Object.op_Implicit((Object)(object)RoundManager.Instance))
		{
			return;
		}
		GameObject gameObject = ((Component)RoundManager.Instance).gameObject;
		if (((NetworkBehaviour)RoundManager.Instance).IsServer)
		{
			MaskedReplaceComp maskedReplaceComp = gameObject.GetComponent<MaskedReplaceComp>();
			if ((Object)(object)maskedReplaceComp == (Object)null)
			{
				maskedReplaceComp = gameObject.AddComponent<MaskedReplaceComp>();
				val.LogInfo((object)"MaskedReplaceComp Created and Attached");
			}
			else
			{
				val.LogInfo((object)"MaskedReplaceComp Attached");
			}
			maskedReplaceComp._currentLevel = ___currentLevel;
			Random.InitState(StartOfRound.Instance.randomMapSeed);
		}
	}
}
internal class MaskedReplaceComp : MonoBehaviour
{
	public SelectableLevel _currentLevel;

	private float nextTimeToCheckSpawn = 60f;

	private float curTime;

	private float CurRate = Plugin.ReplaceRatePerMin;

	private void Update()
	{
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: 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_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		if (!RoundManager.Instance.isSpawningEnemies)
		{
			curTime = 0f;
		}
		else if (curTime == 0f)
		{
			CurRate = Plugin.ReplaceRatePerMin;
			curTime = Time.realtimeSinceStartup;
		}
		else
		{
			if (!(Time.realtimeSinceStartup - curTime > nextTimeToCheckSpawn))
			{
				return;
			}
			curTime = Time.realtimeSinceStartup;
			ManualLogSource val = Logger.CreateLogSource("MaskedReplaceComp");
			float num = Random.Range(0f, 100f);
			val.LogInfo((object)("MaskedReplaceComp Value = " + num + " CurRate: " + CurRate));
			if (num <= CurRate)
			{
				val.LogInfo((object)"MaskedReplaceComp Start Replace Player");
				PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
				List<PlayerControllerB> list = new List<PlayerControllerB>();
				int num2 = 0;
				for (int i = 0; i < StartOfRound.Instance.ClientPlayerList.Count; i++)
				{
					PlayerControllerB val2 = allPlayerScripts[i];
					if (Object.op_Implicit((Object)(object)val2) && !val2.isPlayerDead && (Plugin.ReplaceOutside || val2.isInsideFactory))
					{
						list.Add(val2);
						num2++;
					}
				}
				val.LogInfo((object)("MaskedReplaceComp Can Replace Player Count:" + num2));
				if (num2 > 0)
				{
					int index = Random.Range(0, num2);
					val.LogInfo((object)("MaskedReplaceComp index = " + index));
					PlayerControllerB Player = list[index];
					Vector3 val3 = ((Component)Player).transform.position;
					Quaternion rotation = ((Component)Player).transform.rotation;
					int num3 = Plugin.TeleportPlayer;
					if (Plugin.TeleportPlayer > 1)
					{
						num3 = Random.Range(0, 2);
					}
					if (num3 == 1)
					{
						MaskedStaticPatch.TeleportPlayerRandomly(Player);
					}
					else
					{
						val3 = RoundManager.Instance.GetRandomNavMeshPositionInRadiusSpherical(val3, 10f, default(NavMeshHit));
					}
					MaskedStaticPatch.SpawnMaskedOnTrans(ref _currentLevel, ref Player, val3, rotation);
					val.LogInfo((object)("Replace Player:" + Player.playerClientId));
				}
			}
			CurRate += Plugin.RateChangePerMin;
		}
	}
}
internal class MaskedReplaceNetworkComp : NetworkBehaviour
{
	public static MaskedReplaceNetworkComp Instance;

	private void Awake()
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Expected O, but got Unknown
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Expected O, but got Unknown
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Expected O, but got Unknown
		Logger.CreateLogSource("MaskedReplaceNetworkComp").LogInfo((object)"__rpc_handler_init");
		NetworkManager.__rpc_func_table.Add(3441244552u, new RpcReceiveHandler(__rpc_handler_3441244552));
		NetworkManager.__rpc_func_table.Add(3441244553u, new RpcReceiveHandler(__rpc_handler_3441244553));
		NetworkManager.__rpc_func_table.Add(3441244554u, new RpcReceiveHandler(__rpc_handler_3441244554));
	}

	private void Start()
	{
		NetworkManager.Singleton.OnClientConnectedCallback += OnClientConnected;
		if ((Object)(object)Instance == (Object)null)
		{
			Instance = this;
		}
	}

	public override void OnDestroy()
	{
		if ((Object)(object)NetworkManager.Singleton != (Object)null)
		{
			NetworkManager.Singleton.OnClientConnectedCallback -= OnClientConnected;
		}
	}

	private void OnClientConnected(ulong clientId)
	{
		if (((NetworkBehaviour)this).IsServer)
		{
			Logger.CreateLogSource("MaskedReplaceNetworkComp").LogInfo((object)("OnClientConnected" + clientId + " " + NetworkManager.Singleton.LocalClientId));
			if (clientId != NetworkManager.Singleton.LocalClientId)
			{
				((Component)this).gameObject.GetComponent<NetworkObject>().SpawnAsPlayerObject(clientId, false);
			}
		}
	}

	private static void __rpc_handler_3441244552(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
	{
		//IL_002c: 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_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: 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_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		Logger.CreateLogSource("MaskedReplaceNetworkComp").LogInfo((object)"__rpc_handler_3441244552");
		NetworkManager networkManager = target.NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			NetworkObjectReference netObjectRef = default(NetworkObjectReference);
			((FastBufferReader)(ref reader)).ReadValueSafe<NetworkObjectReference>(ref netObjectRef, default(ForNetworkSerializable));
			bool inFactory = default(bool);
			((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref inFactory, default(ForPrimitives));
			int playerClientId = default(int);
			ByteUnpacker.ReadValueBitPacked(reader, ref playerClientId);
			((NetworkBehaviour)(MaskedReplaceNetworkComp)(object)target).__rpc_exec_stage = (__RpcExecStage)2;
			((MaskedReplaceNetworkComp)(object)target).CreateMaskedSpawnRpc(netObjectRef, inFactory, playerClientId);
			((NetworkBehaviour)(MaskedReplaceNetworkComp)(object)target).__rpc_exec_stage = (__RpcExecStage)0;
		}
	}

	private static void __rpc_handler_3441244553(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
	{
		//IL_0026: 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_004a: 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)
		Logger.CreateLogSource("MaskedReplaceNetworkComp").LogInfo((object)"__rpc_handler_3441244553");
		NetworkManager networkManager = target.NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			ulong playerClientId = default(ulong);
			ByteUnpacker.ReadValueBitPacked(reader, ref playerClientId);
			Vector3 teleportPos = default(Vector3);
			((FastBufferReader)(ref reader)).ReadValueSafe(ref teleportPos);
			((NetworkBehaviour)(MaskedReplaceNetworkComp)(object)target).__rpc_exec_stage = (__RpcExecStage)1;
			((MaskedReplaceNetworkComp)(object)target).RpcServerTeleportPlayer(playerClientId, teleportPos);
			((NetworkBehaviour)(MaskedReplaceNetworkComp)(object)target).__rpc_exec_stage = (__RpcExecStage)0;
		}
	}

	private static void __rpc_handler_3441244554(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
	{
		//IL_0026: 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_004a: 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)
		Logger.CreateLogSource("MaskedReplaceNetworkComp").LogInfo((object)"__rpc_handler_3441244554");
		NetworkManager networkManager = target.NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			ulong playerClientId = default(ulong);
			ByteUnpacker.ReadValueBitPacked(reader, ref playerClientId);
			Vector3 teleportPos = default(Vector3);
			((FastBufferReader)(ref reader)).ReadValueSafe(ref teleportPos);
			((NetworkBehaviour)(MaskedReplaceNetworkComp)(object)target).__rpc_exec_stage = (__RpcExecStage)2;
			((MaskedReplaceNetworkComp)(object)target).RpcTeleportPlayer(playerClientId, teleportPos);
			((NetworkBehaviour)(MaskedReplaceNetworkComp)(object)target).__rpc_exec_stage = (__RpcExecStage)0;
		}
	}

	[ClientRpc]
	public void CreateMaskedSpawnRpc(NetworkObjectReference netObjectRef, bool inFactory, int playerClientId)
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Invalid comparison between Unknown and I4
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Invalid comparison between Unknown and I4
		//IL_0053: 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_0061: 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_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
		Logger.CreateLogSource("MaskedReplaceNetworkComp").LogInfo((object)("CreateMaskedSpawnRpc: " + playerClientId));
		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(3441244552u, val, (RpcDelivery)0);
				((FastBufferWriter)(ref val2)).WriteValueSafe<NetworkObjectReference>(ref netObjectRef, default(ForNetworkSerializable));
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref inFactory, default(ForPrimitives));
				BytePacker.WriteValueBitPacked(val2, playerClientId);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3441244552u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && !((NetworkBehaviour)this).IsServer)
			{
				((MonoBehaviour)this).StartCoroutine(waitForMaskedSpawn(netObjectRef, inFactory, playerClientId));
			}
		}
	}

	private IEnumerator waitForMaskedSpawn(NetworkObjectReference netObjectRef, bool inFactory, int playerClientId)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		Logger.CreateLogSource("MaskedReplaceNetworkComp").LogInfo((object)("waitForMimicEnemySpawn: " + playerClientId));
		PlayerControllerB player = StartOfRound.Instance.allPlayerScripts[playerClientId];
		NetworkObject netObject = null;
		float startTime = Time.realtimeSinceStartup;
		yield return (object)new WaitUntil((Func<bool>)(() => Time.realtimeSinceStartup - startTime > 20f || ((NetworkObjectReference)(ref netObjectRef)).TryGet(ref netObject, (NetworkManager)null)));
		if ((Object)(object)netObject != (Object)null)
		{
			MaskedPlayerEnemy component = ((Component)netObject).GetComponent<MaskedPlayerEnemy>();
			component.mimickingPlayer = player;
			MaskedStaticPatch.RefreshMaskedSight(component);
		}
	}

	[ServerRpc(RequireOwnership = false)]
	public void RpcServerTeleportPlayer(ulong playerClientId, Vector3 TeleportPos)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Invalid comparison between Unknown and I4
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Invalid comparison between Unknown and I4
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: 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_0075: 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)
		ManualLogSource val = Logger.CreateLogSource("MaskedReplaceNetworkComp");
		val.LogInfo((object)"RpcServerTeleportPlayer");
		NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
		if (networkManager != null && networkManager.IsListening)
		{
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val2 = default(ServerRpcParams);
				FastBufferWriter val3 = ((NetworkBehaviour)this).__beginSendServerRpc(3441244553u, val2, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val3, playerClientId);
				((FastBufferWriter)(ref val3)).WriteValueSafe(ref TeleportPos);
				((NetworkBehaviour)this).__endSendServerRpc(ref val3, 3441244553u, val2, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				val.LogInfo((object)("Send To Client:" + playerClientId));
				RpcTeleportPlayer(playerClientId, TeleportPos);
			}
		}
	}

	[ClientRpc]
	public void RpcTeleportPlayer(ulong playerClientId, Vector3 TeleportPos)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Invalid comparison between Unknown and I4
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Invalid comparison between Unknown and I4
		//IL_004d: 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_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_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: 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)
		Logger.CreateLogSource("MaskedReplaceNetworkComp").LogInfo((object)("RpcTeleportPlayer:" + playerClientId));
		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(3441244554u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, playerClientId);
				((FastBufferWriter)(ref val2)).WriteValueSafe(ref TeleportPos);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3441244554u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				MaskedStaticPatch.TeleportPlayerInternal(playerClientId, TeleportPos);
			}
		}
	}
}
internal class MaskedStaticPatch
{
	public static void TeleportPlayerInternal(ulong playerClientId, Vector3 TeleportPos)
	{
		//IL_0039: 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_007e: Unknown result type (might be due to invalid IL or missing references)
		ManualLogSource val = Logger.CreateLogSource("RpcTeleportPlayerRandomly");
		val.LogInfo((object)("playerClientId:" + playerClientId));
		PlayerControllerB val2 = StartOfRound.Instance.allPlayerScripts[playerClientId];
		if (Object.op_Implicit((Object)(object)val2))
		{
			val2.TeleportPlayer(TeleportPos, false, 0f, false, true);
			val2.beamOutParticle.Play();
			val2.movementAudio.PlayOneShot(StartOfRound.Instance.damageSFX);
			string text = val2.playerClientId.ToString();
			Vector3 val3 = TeleportPos;
			val.LogInfo((object)("Teleport Player:" + text + " to " + ((object)(Vector3)(ref val3)).ToString()));
		}
	}

	public static void TeleportPlayerRandomly(PlayerControllerB playerController)
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: 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_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: 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_0049: 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)
		ManualLogSource obj = Logger.CreateLogSource("MaskedReplaceComp");
		Vector3 position = RoundManager.Instance.insideAINodes[Random.Range(0, RoundManager.Instance.insideAINodes.Length)].transform.position;
		if (!playerController.isInsideFactory)
		{
			position = ((Component)StartOfRound.Instance.shipInnerRoomBounds).transform.position;
		}
		position = RoundManager.Instance.GetRandomNavMeshPositionInRadiusSpherical(position, 10f, default(NavMeshHit));
		string text = playerController.playerClientId.ToString();
		Vector3 val = position;
		obj.LogInfo((object)("Teleport Player:" + text + " to " + ((object)(Vector3)(ref val)).ToString()));
		MaskedReplaceNetworkComp instance = MaskedReplaceNetworkComp.Instance;
		TeleportPlayerInternal(playerController.playerClientId, position);
		instance.RpcServerTeleportPlayer(playerController.playerClientId, position);
	}

	public static void SpawnMaskedOnTrans(ref SelectableLevel __currentLevel, ref PlayerControllerB Player, Vector3 Position, Quaternion Rotation)
	{
		//IL_001c: 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_0030: 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_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		ManualLogSource val = Logger.CreateLogSource("SpawnMaskedOnTrans");
		SpawnableEnemyWithRarity maskedPrefab = Plugin.maskedPrefab;
		MaskedReplaceNetworkComp instance = MaskedReplaceNetworkComp.Instance;
		NetworkObjectReference netObjectRef = RoundManager.Instance.SpawnEnemyGameObject(Position, ((Quaternion)(ref Rotation)).eulerAngles.y, -1, maskedPrefab.enemyType);
		NetworkObject val2 = default(NetworkObject);
		if (((NetworkObjectReference)(ref netObjectRef)).TryGet(ref val2, (NetworkManager)null))
		{
			bool flag = Position.y < -80f;
			MaskedPlayerEnemy component = ((Component)val2).GetComponent<MaskedPlayerEnemy>();
			component.SetSuit(Player.currentSuitID);
			component.mimickingPlayer = Player;
			component.SetEnemyOutside(!flag);
			val.LogInfo((object)("SpawnMasked Name = " + ((object)(NetworkObjectReference)(ref netObjectRef)).ToString()));
			instance.CreateMaskedSpawnRpc(netObjectRef, flag, (int)Player.playerClientId);
		}
	}

	public static void RefreshMaskedSight(MaskedPlayerEnemy __instance)
	{
		if (Object.op_Implicit((Object)(object)__instance))
		{
			ManualLogSource obj = Logger.CreateLogSource("OnStartClient");
			obj.LogInfo((object)(((Object)__instance).name + " RefreshMaskedSight Start"));
			__instance.SetEnemyOutside(!__instance.mimickingPlayer.isInsideFactory);
			obj.LogInfo((object)(((Object)__instance).name + " RefreshMaskedSight Finish"));
		}
	}

	public static void ReformEnemy(MaskedPlayerEnemy __instance)
	{
		//IL_0064: 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)
		ManualLogSource val = Logger.CreateLogSource("ReformEnemy");
		PlayerControllerB mimickingPlayer = __instance.mimickingPlayer;
		if ((Object)(object)mimickingPlayer == (Object)null)
		{
			val.LogInfo((object)" Player Not Found!! ");
			return;
		}
		val.LogInfo((object)("ReformAndSetNameBillboard, instanceID:" + ((Object)__instance).GetInstanceID() + " PlayerName: " + mimickingPlayer.playerUsername));
		__instance.SetSuit(mimickingPlayer.currentSuitID);
		if (Plugin.RemoveMask)
		{
			((Component)((Component)__instance).gameObject.transform.Find("ScavengerModel/metarig/spine/spine.001/spine.002/spine.003/spine.004/HeadMaskComedy")).gameObject.SetActive(false);
			((Component)((Component)__instance).gameObject.transform.Find("ScavengerModel/metarig/spine/spine.001/spine.002/spine.003/spine.004/HeadMaskTragedy")).gameObject.SetActive(false);
		}
	}

	public static void SetNameBillboard(MaskedPlayerEnemy __instance)
	{
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Expected O, but got Unknown
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_024f: Unknown result type (might be due to invalid IL or missing references)
		//IL_025c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0269: Unknown result type (might be due to invalid IL or missing references)
		//IL_0276: Unknown result type (might be due to invalid IL or missing references)
		//IL_0283: Unknown result type (might be due to invalid IL or missing references)
		//IL_0290: Unknown result type (might be due to invalid IL or missing references)
		//IL_029d: 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_02b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
		ManualLogSource val = Logger.CreateLogSource("SetNameBillboard");
		PlayerControllerB mimickingPlayer = __instance.mimickingPlayer;
		if ((Object)(object)mimickingPlayer == (Object)null)
		{
			val.LogInfo((object)"SetNameBillboard Player Not Found!! ");
			return;
		}
		Masked_ExtValue masked_ExtValue = default(Masked_ExtValue);
		if (!((Component)__instance).gameObject.TryGetComponent<Masked_ExtValue>(ref masked_ExtValue))
		{
			masked_ExtValue = ((Component)__instance).gameObject.AddComponent<Masked_ExtValue>();
		}
		val.LogInfo((object)("SetNameBillboard Start, instance: " + ((Object)__instance).name));
		masked_ExtValue.usernameCanvas = Object.Instantiate<Canvas>(mimickingPlayer.usernameCanvas);
		((Component)masked_ExtValue.usernameCanvas).gameObject.AddComponent<CanvasGroup>();
		GameObject val2 = new GameObject("usernameBillboardText");
		val2.transform.SetParent(((Component)masked_ExtValue.usernameCanvas).transform, false);
		masked_ExtValue.usernameBillboardText = val2.AddComponent<TextMeshProUGUI>();
		((TMP_Text)masked_ExtValue.usernameBillboardText).text = ((TMP_Text)mimickingPlayer.usernameBillboardText).text;
		((TMP_Text)masked_ExtValue.usernameBillboardText).font = ((TMP_Text)mimickingPlayer.usernameBillboardText).font;
		((Graphic)masked_ExtValue.usernameBillboardText).color = ((Graphic)mimickingPlayer.usernameBillboardText).color;
		((TMP_Text)masked_ExtValue.usernameBillboardText).fontSize = ((TMP_Text)mimickingPlayer.usernameBillboardText).fontSize;
		((TMP_Text)masked_ExtValue.usernameBillboardText).enableAutoSizing = ((TMP_Text)mimickingPlayer.usernameBillboardText).enableAutoSizing;
		((TMP_Text)masked_ExtValue.usernameBillboardText).extraPadding = ((TMP_Text)mimickingPlayer.usernameBillboardText).extraPadding;
		((TMP_Text)masked_ExtValue.usernameBillboardText).alignment = ((TMP_Text)mimickingPlayer.usernameBillboardText).alignment;
		((TMP_Text)masked_ExtValue.usernameBillboardText).textStyle = ((TMP_Text)mimickingPlayer.usernameBillboardText).textStyle;
		((TMP_Text)masked_ExtValue.usernameBillboardText).textPreprocessor = ((TMP_Text)mimickingPlayer.usernameBillboardText).textPreprocessor;
		((TMP_Text)masked_ExtValue.usernameBillboardText).characterSpacing = ((TMP_Text)mimickingPlayer.usernameBillboardText).characterSpacing;
		((TMP_Text)masked_ExtValue.usernameBillboardText).wordSpacing = ((TMP_Text)mimickingPlayer.usernameBillboardText).wordSpacing;
		((TMP_Text)masked_ExtValue.usernameBillboardText).lineSpacing = ((TMP_Text)mimickingPlayer.usernameBillboardText).lineSpacing;
		((TMP_Text)masked_ExtValue.usernameBillboardText).margin = ((TMP_Text)mimickingPlayer.usernameBillboardText).margin;
		((TMP_Text)masked_ExtValue.usernameBillboardText).overflowMode = ((TMP_Text)mimickingPlayer.usernameBillboardText).overflowMode;
		((TMP_Text)masked_ExtValue.usernameBillboardText).fontSharedMaterial = ((TMP_Text)mimickingPlayer.usernameBillboardText).fontSharedMaterial;
		((TMP_Text)masked_ExtValue.usernameBillboardText).fontSizeMin = ((TMP_Text)mimickingPlayer.usernameBillboardText).fontSizeMin;
		((TMP_Text)masked_ExtValue.usernameBillboardText).fontSizeMax = ((TMP_Text)mimickingPlayer.usernameBillboardText).fontSizeMax;
		((TMP_Text)masked_ExtValue.usernameBillboardText).enableKerning = ((TMP_Text)mimickingPlayer.usernameBillboardText).enableKerning;
		RectTransform component = ((Component)mimickingPlayer.usernameBillboardText).GetComponent<RectTransform>();
		RectTransform component2 = ((Component)masked_ExtValue.usernameBillboardText).GetComponent<RectTransform>();
		((Transform)component2).localPosition = ((Transform)component).localPosition;
		component2.sizeDelta = component.sizeDelta;
		component2.anchorMin = component.anchorMin;
		component2.anchorMax = component.anchorMax;
		component2.pivot = component.pivot;
		component2.anchoredPosition = component.anchoredPosition;
		((Transform)component2).localScale = ((Transform)component).localScale;
		component2.offsetMin = component.offsetMin;
		component2.offsetMax = component.offsetMax;
		((Transform)component2).right = ((Transform)component).right;
		((Component)masked_ExtValue.usernameBillboardText).gameObject.SetActive(true);
		((Behaviour)masked_ExtValue.usernameBillboardText).enabled = true;
		((Behaviour)masked_ExtValue.usernameCanvas).enabled = true;
		val.LogInfo((object)("SetNameBillboard Finish, Playername:" + ((TMP_Text)masked_ExtValue.usernameBillboardText).text));
	}

	public static CanvasGroup GetCanvasAlpha(Canvas canvas)
	{
		CanvasGroup val = null;
		if (Object.op_Implicit((Object)(object)canvas))
		{
			val = ((Component)canvas).gameObject.GetComponent<CanvasGroup>();
			if (!Object.op_Implicit((Object)(object)val))
			{
				val = ((Component)canvas).gameObject.AddComponent<CanvasGroup>();
			}
		}
		return val;
	}

	public static void ShowNameBillboard(ref MaskedPlayerEnemy __instance)
	{
		Masked_ExtValue masked_ExtValue = default(Masked_ExtValue);
		if (((Component)__instance).gameObject.TryGetComponent<Masked_ExtValue>(ref masked_ExtValue))
		{
			GetCanvasAlpha(masked_ExtValue.usernameCanvas).alpha = 1f;
			((Component)masked_ExtValue.usernameCanvas).gameObject.SetActive(true);
		}
	}
}
internal class Masked_ExtValue : MonoBehaviour
{
	public Canvas usernameCanvas;

	public TextMeshProUGUI usernameBillboardText;
}
[HarmonyPatch(typeof(MaskedPlayerEnemy))]
internal class Masked_Patch
{
	[HarmonyPatch("Awake")]
	[HarmonyPostfix]
	private static void OnSpawn(ref MaskedPlayerEnemy __instance)
	{
		Logger.CreateLogSource("Masked_Patch").LogInfo((object)("Masked Spawned " + ((Object)__instance).GetInstanceID()));
	}

	[HarmonyPatch("Update")]
	[HarmonyPrefix]
	private static void Update_ShowBillboard(ref MaskedPlayerEnemy __instance)
	{
		//IL_00ad: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: 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_00f9: 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_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		ManualLogSource val = Logger.CreateLogSource("Masked_Patch");
		Masked_ExtValue masked_ExtValue = default(Masked_ExtValue);
		if (((Component)__instance).gameObject.TryGetComponent<Masked_ExtValue>(ref masked_ExtValue))
		{
			Canvas usernameCanvas = masked_ExtValue.usernameCanvas;
			CanvasGroup canvasAlpha = MaskedStaticPatch.GetCanvasAlpha(usernameCanvas);
			Transform transform = ((Component)usernameCanvas).transform;
			TextMeshProUGUI usernameBillboardText = masked_ExtValue.usernameBillboardText;
			if (Object.op_Implicit((Object)(object)usernameCanvas) && Object.op_Implicit((Object)(object)transform) && Object.op_Implicit((Object)(object)canvasAlpha))
			{
				if (!((Component)usernameBillboardText).gameObject.activeInHierarchy || !Object.op_Implicit((Object)(object)((Graphic)usernameBillboardText).canvas))
				{
					((TMP_Text)usernameBillboardText).transform.SetParent(transform, false);
				}
				if (Plugin.ShowPlayerName > 1)
				{
					canvasAlpha.alpha = 1f;
					((Component)usernameCanvas).gameObject.SetActive(true);
					Vector3 val2 = default(Vector3);
					((Vector3)(ref val2)).Set(((Component)__instance).transform.position.x, ((Component)__instance).transform.position.y + 2.64f, ((Component)__instance).transform.position.z);
					transform.SetPositionAndRotation(val2, transform.rotation);
					transform.LookAt(GameNetworkManager.Instance.localPlayerController.localVisorTargetPoint);
				}
				else if (canvasAlpha.alpha >= 0f && (Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null)
				{
					canvasAlpha.alpha -= Time.deltaTime;
					Vector3 val3 = default(Vector3);
					((Vector3)(ref val3)).Set(((Component)__instance).transform.position.x, ((Component)__instance).transform.position.y + 2.64f, ((Component)__instance).transform.position.z);
					transform.SetPositionAndRotation(val3, transform.rotation);
					transform.LookAt(GameNetworkManager.Instance.localPlayerController.localVisorTargetPoint);
				}
				else if (((Component)usernameCanvas).gameObject.activeSelf)
				{
					((Component)usernameCanvas).gameObject.SetActive(false);
				}
			}
			else
			{
				val.LogInfo((object)"Masked_ExtValue Init Failed");
			}
		}
		else if (Object.op_Implicit((Object)(object)__instance.mimickingPlayer))
		{
			val.LogInfo((object)"SetEnemyOutside to AutoReformAndSetNameBillboard");
			__instance.SetEnemyOutside(((EnemyAI)__instance).isOutside);
		}
		else
		{
			val.LogInfo((object)"not mimickingPlayer");
		}
	}

	[HarmonyPatch("SetHandsOutClientRpc")]
	[HarmonyPrefix]
	private static void RemoveMaskedArms(ref bool setOut)
	{
		if (Plugin.RemoveArms)
		{
			setOut = false;
		}
	}

	[HarmonyPatch("SetEnemyOutside")]
	[HarmonyPostfix]
	public static void AutoReformAndSetNameBillboard(MaskedPlayerEnemy __instance)
	{
		Logger.CreateLogSource("AutoReformAndSetNameBillboard").LogInfo((object)"AutoReformAndSetNameBillboard! ");
		MaskedStaticPatch.ReformEnemy(__instance);
		MaskedStaticPatch.SetNameBillboard(__instance);
	}

	[HarmonyPatch("waitForMimicEnemySpawn")]
	[HarmonyPostfix]
	private static void AfterKillingSpawn(ref NetworkObjectReference netObjectRef, ref bool inFactory, ref int playerKilled)
	{
		PlayerControllerB val = StartOfRound.Instance.allPlayerScripts[playerKilled];
		Logger.CreateLogSource("AutoReformAndSetNameBillboard").LogInfo((object)("AfterKillingSpawn, killed player id = " + playerKilled + "PlayerName = " + val.playerUsername));
		NetworkObject val2 = null;
		((NetworkObjectReference)(ref netObjectRef)).TryGet(ref val2, (NetworkManager)null);
		if ((Object)(object)val2 != (Object)null)
		{
			MaskedPlayerEnemy component = ((Component)val2).GetComponent<MaskedPlayerEnemy>();
			component.mimickingPlayer = val;
			component.SetSuit(val.currentSuitID);
			component.SetEnemyOutside(!inFactory);
		}
	}

	[HarmonyPatch("OnDestroy")]
	[HarmonyPrefix]
	public static void DestroyBillboard(MaskedPlayerEnemy __instance)
	{
		Masked_ExtValue masked_ExtValue = default(Masked_ExtValue);
		if (((Component)__instance).gameObject.TryGetComponent<Masked_ExtValue>(ref masked_ExtValue))
		{
			Object.Destroy((Object)(object)masked_ExtValue.usernameBillboardText);
			Object.Destroy((Object)(object)masked_ExtValue.usernameCanvas);
		}
	}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerController_Patch
{
	[HarmonyPatch("SetHoverTipAndCurrentInteractTrigger")]
	[HarmonyPrefix]
	private static void AimingMasked(PlayerControllerB __instance)
	{
		//IL_0018: 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_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		if (Plugin.ShowPlayerName != 1)
		{
			return;
		}
		Ray val = default(Ray);
		((Ray)(ref val))..ctor(((Component)__instance.gameplayCamera).transform.position, ((Component)__instance.gameplayCamera).transform.forward);
		LayerMask val2 = LayerMask.op_Implicit(524288);
		RaycastHit val3 = default(RaycastHit);
		if (!__instance.isFreeCamera && Physics.Raycast(val, ref val3, 5f, LayerMask.op_Implicit(val2)))
		{
			EnemyAICollisionDetect component = ((Component)((RaycastHit)(ref val3)).collider).gameObject.GetComponent<EnemyAICollisionDetect>();
			MaskedPlayerEnemy __instance2 = null;
			if (Object.op_Implicit((Object)(object)component))
			{
				__instance2 = ((Component)component.mainScript).gameObject.GetComponent<MaskedPlayerEnemy>();
			}
			if ((Object)(object)__instance2 != (Object)null)
			{
				MaskedStaticPatch.ShowNameBillboard(ref __instance2);
			}
		}
	}
}