Decompiled source of ReworkedPVP v0.1.2

plugins/PvP.dll

Decompiled 2 days 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 HarmonyLib;
using Photon;
using SideLoader;
using SideLoader.Helpers;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("PvP")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PvP")]
[assembly: AssemblyCopyright("Copyright ©  2019")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("8654b1db-7a3b-411b-9891-c0078b5dda2f")]
[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")]
namespace PvP;

public class BattleRoyale : MonoBehaviour
{
	public static BattleRoyale Instance;

	public bool IsGameplayStarting;

	public bool IsGameplayEnding;

	public static int SupplyDropInterval = 120;

	public float LastSupplyDropTime;

	public int SupplyDropCounter;

	public List<GameObject> ActiveItemContainers = new List<GameObject>();

	public List<GameObject> ActiveBeamObjects = new List<GameObject>();

	public GameObject beamObject;

	public static int EnemyDropInterval = 45;

	public float LastEnemySpawnTime;

	public List<Character> EnemyCharacters = new List<Character>();

	internal void Awake()
	{
		Instance = this;
	}

	internal void Update()
	{
		if (MenuManager.Instance.IsInMainMenuScene)
		{
			if (IsGameplayStarting)
			{
				IsGameplayStarting = false;
				((MonoBehaviour)this).StopAllCoroutines();
			}
			if (PvP.Instance.CurrentGame == PvP.GameModes.BattleRoyale)
			{
				PvP.Instance.CurrentGame = PvP.GameModes.NONE;
			}
		}
		if (!IsGameplayStarting && IsGameplayEnding && !PvPGUI.Instance.ShowGUI)
		{
			PvPGUI.Instance.ShowGUI = true;
		}
	}

	public bool CheckCanStart()
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		List<Factions> list = new List<Factions>();
		foreach (PlayerSystem item in Global.Lobby.PlayersInLobby)
		{
			if (!list.Contains(item.ControlledCharacter.Faction))
			{
				list.Add(item.ControlledCharacter.Faction);
			}
		}
		if (list.Count() > 1)
		{
			return true;
		}
		return false;
	}

	public void StartBattleRoyale(bool skipLoad = false)
	{
		((MonoBehaviour)RPCManager.Instance).photonView.RPC("RPCStartBattleRoyale", (PhotonTargets)0, new object[1] { skipLoad });
	}

	public IEnumerator SetupAfterSceneLoad(bool skipLoad = false)
	{
		if (!skipLoad)
		{
			while (!NetworkLevelLoader.Instance.IsSceneLoading)
			{
				yield return (object)new WaitForSeconds(0.1f);
			}
			while (!NetworkLevelLoader.Instance.IsOverallLoadingDone)
			{
				yield return (object)new WaitForSeconds(0.1f);
			}
		}
		SetupCharacters();
		while (NetworkLevelLoader.Instance.IsGameplayPaused)
		{
			yield return null;
		}
		yield return (object)new WaitForSeconds(1f);
		Debug.Log((object)"Setting up local scene...");
		LocalSceneSetup();
		if (!PhotonNetwork.isNonMasterClientInRoom)
		{
			Debug.Log((object)"Setting up as host...");
			HostSceneSetup();
		}
		Debug.Log((object)"Battle Royale is about to start, finalizing...");
		RPCManager.Instance.StartGameplayRPC(2, "A Battle Royale has begun!");
		EnemyDropInterval = Mathf.Clamp(45 - PlayerManager.Instance.GetRemainingPlayers().Count() * 2, 15, 45);
		Debug.Log((object)"Finalized!");
	}

	private void HostSceneSetup()
	{
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		while (ItemManager.Instance.WorldItems.Keys.Count() > 0)
		{
			ItemManager.Instance.DestroyItem(ItemManager.Instance.WorldItems.Keys[0]);
		}
		if (Templates.BR_Templates.SpawnLocations.ContainsKey(SceneManagerHelper.ActiveSceneName))
		{
			List<Vector3> list = Templates.BR_Templates.SpawnLocations[SceneManagerHelper.ActiveSceneName].ToList();
			{
				foreach (PlayerSystem item in Global.Lobby.PlayersInLobby)
				{
					Character controlledCharacter = item.ControlledCharacter;
					if (list.Count == 0)
					{
						list = Templates.BR_Templates.SpawnLocations[SceneManagerHelper.ActiveSceneName].ToList();
					}
					int index = Random.Range(0, list.Count());
					controlledCharacter.Teleport(list[index], ((Component)controlledCharacter).transform.rotation);
					list.RemoveAt(index);
					controlledCharacter.StatusEffectMngr.Purge();
				}
				return;
			}
		}
		PvP.Instance.StopGameplay("An error has occured! We seem to be in the wrong scene.");
	}

	private void LocalSceneSetup()
	{
		//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0247: Unknown result type (might be due to invalid IL or missing references)
		//IL_0291: Unknown result type (might be due to invalid IL or missing references)
		//IL_0298: Expected O, but got Unknown
		EnvironmentConditions.Instance.SetTimeOfDay(Templates.BR_Templates.TimeOfDayStarts[SceneManagerHelper.ActiveSceneName], false);
		if (Templates.BR_Templates.ObjectsToDeactivate.ContainsKey(SceneManagerHelper.ActiveSceneName))
		{
			foreach (string item in Templates.BR_Templates.ObjectsToDeactivate[SceneManagerHelper.ActiveSceneName])
			{
				GameObject val = GameObject.Find(item);
				if (val != null)
				{
					if (item == "JesusBeam")
					{
						beamObject = val;
					}
					val.SetActive(false);
				}
			}
		}
		if (Templates.BR_Templates.ObjectsToActivate.ContainsKey(SceneManagerHelper.ActiveSceneName))
		{
			foreach (string item2 in Templates.BR_Templates.ObjectsToActivate[SceneManagerHelper.ActiveSceneName])
			{
				GameObject val2 = GameObject.Find(item2);
				if (val2 != null)
				{
					val2.SetActive(true);
					continue;
				}
				GameObject val3 = FindInactiveObjectByName(item2);
				if (val3 != null)
				{
					val3.SetActive(true);
				}
			}
		}
		EnemyCharacters.Clear();
		foreach (Character item3 in CharacterManager.Instance.Characters.Values.Where((Character x) => x.IsAI && (int)x.Faction != 1))
		{
			EnemyCharacters.Add(item3);
			((Component)item3).gameObject.SetActive(false);
		}
		foreach (PlayerSystem item4 in Global.Lobby.PlayersInLobby.Where((PlayerSystem x) => x.IsLocalPlayer))
		{
			Character controlledCharacter = item4.ControlledCharacter;
			string text = "Pouch_" + UID.op_Implicit(controlledCharacter.UID);
			if (Object.op_Implicit((Object)(object)ItemManager.Instance.GetItem(text)))
			{
				ItemManager.Instance.DestroyItem(text);
			}
			ItemContainer val4 = null;
			if (Object.op_Implicit((Object)(object)controlledCharacter.Inventory.PouchPrefab))
			{
				Transform obj = Object.Instantiate<Transform>(controlledCharacter.Inventory.PouchPrefab);
				obj.SetParent(((Component)this).transform, false);
				val4 = ((Component)obj).GetComponent<ItemContainer>();
				((Item)val4).SetKeepAlive();
				((Item)val4).UID = "CustomPouch_" + UID.op_Implicit(controlledCharacter.UID);
				((Item)val4).ProcessInit();
				At.SetField<CharacterInventory>(controlledCharacter.Inventory, "m_inventoryPouch", (object)val4);
				if (PhotonNetwork.isNonMasterClientInRoom)
				{
					((Item)val4).ForceUpdateParentChange();
				}
			}
			if (controlledCharacter.Inventory.MapKnowledge == null)
			{
				CharacterMapKnowledge val5 = new CharacterMapKnowledge();
				val5.Init();
				At.SetField<CharacterInventory>(controlledCharacter.Inventory, "m_mapKnowledge", (object)val5);
			}
			controlledCharacter.Inventory.Equipment.ProcessStart();
			SetupStarterPack(controlledCharacter);
			controlledCharacter.StatusEffectMngr.Purge();
		}
		UICompass[] array = Resources.FindObjectsOfTypeAll<UICompass>();
		for (int num = 0; num < array.Length; num++)
		{
			((UIElement)array[num]).Hide();
		}
	}

	private void SetupCharacters()
	{
		foreach (PlayerSystem item in Global.Lobby.PlayersInLobby)
		{
			CustomPlayerSetup(item.ControlledCharacter);
		}
	}

	private void CustomPlayerSetup(Character _char)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Expected O, but got Unknown
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Expected O, but got Unknown
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Expected O, but got Unknown
		CharacterSave obj = SaveManager.Instance.CreateNewCharacterSave();
		((CharacterSaveData)obj.PSave).NewSave = true;
		((CharacterSaveData)obj.PSave).ManaPoint = 0;
		((CharacterSaveData)obj.PSave).UID = UID.op_Implicit(_char.UID);
		obj.PSave.Name = _char.Name;
		((CharacterSaveData)obj.PSave).VisualData = _char.VisualData;
		obj.PSave.Food = 1000f;
		obj.PSave.Drink = 1000f;
		obj.PSave.HardcoreMode = false;
		obj.ApplyLoadedSaveToChar(_char);
		At.SetField<CharacterStats>(_char.Stats, "m_maxHealthStat", (object)new Stat(500f));
		At.SetField<CharacterStats>(_char.Stats, "m_maxStamina", (object)new Stat(200f));
		At.SetField<CharacterStats>(_char.Stats, "m_maxManaStat", (object)new Stat(75f));
		_char.Stats.GiveManaPoint(1);
		_char.Cheats.Invincible = false;
		_char.Cheats.IndestructibleEquipment = false;
		_char.Cheats.NotAffectedByWeightPenalties = false;
		_char.Cheats.NeedsEnabled = true;
		At.Invoke<CharacterStats>(_char.Stats, "UpdateVitalStats", Array.Empty<object>());
		_char.Stats.Reset();
		_char.Stats.RestoreAllVitals();
		if (At.GetField<CharacterQuickSlotManager>(_char.QuickSlotMngr, "m_quickSlots") is QuickSlot[] source)
		{
			for (int i = 0; i < source.Count(); i++)
			{
				_char.QuickSlotMngr.GetQuickSlot(i).Clear();
			}
		}
	}

	private void SetupStarterPack(Character _char)
	{
		Debug.Log((object)("SetupStarterPack for " + ((Object)((Component)_char).gameObject).name));
		Item val = ItemManager.Instance.GenerateItemNetwork(5300000);
		if ((Object)(object)val != (Object)null)
		{
			_char.Inventory.TakeItem(val.UID, false);
			At.Invoke<CharacterEquipment>(_char.Inventory.Equipment, "EquipWithoutAssociating", new object[2] { val, false });
			ItemContainer val2 = _char.Inventory.Pouch;
			ItemContainer componentInChildren = ((Component)val).GetComponentInChildren<ItemContainer>();
			if (componentInChildren != null)
			{
				val2 = componentInChildren;
			}
			AddItemsToContainer(Templates.BR_Templates.Weapons_Low, 1, ((Component)val2).transform);
			AddItemsToContainer(Templates.BR_Templates.Offhands_Low, 1, ((Component)val2).transform);
			AddItemsToContainer(Templates.BR_Templates.Supplies_Low, 5, ((Component)val2).transform);
			AddItemsToContainer(Templates.StarterSkills, Templates.StarterSkills.Count(), ((Component)val2).transform);
		}
	}

	public void UpdateBR()
	{
		if (!PhotonNetwork.isNonMasterClientInRoom)
		{
			WorldHostUpdate();
		}
	}

	private void WorldHostUpdate()
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_023b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0240: Unknown result type (might be due to invalid IL or missing references)
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		//IL_0261: Unknown result type (might be due to invalid IL or missing references)
		//IL_0270: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f2: 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_0206: Unknown result type (might be due to invalid IL or missing references)
		//IL_020d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0214: Unknown result type (might be due to invalid IL or missing references)
		List<Factions> remainingTeams = PlayerManager.Instance.GetRemainingTeams();
		if (remainingTeams.Count() < 2)
		{
			string text = ((object)remainingTeams[0]/*cast due to .constrained prefix*/).ToString();
			if (!text.EndsWith("s"))
			{
				text += "s";
			}
			PvP.Instance.StopGameplay(text + " have won!");
		}
		if (LastSupplyDropTime <= 0f || Time.time - LastSupplyDropTime > (float)SupplyDropInterval)
		{
			LastSupplyDropTime = Time.time;
			SupplyDropCounter++;
			((MonoBehaviour)this).StartCoroutine(GenerateSupplyDrops());
		}
		if (!(Time.time - LastEnemySpawnTime > (float)EnemyDropInterval) || EnemyCharacters.Count() <= 0)
		{
			return;
		}
		LastEnemySpawnTime = Time.time;
		Character val = null;
		List<Character> list = EnemyCharacters.Where((Character x) => !((Component)x).gameObject.activeSelf).ToList();
		if (list.Count() <= 0)
		{
			return;
		}
		Character butcher = list.Find((Character x) => x.Name.ToLower().Contains("butcher"));
		if (SupplyDropCounter < 3 || !Object.op_Implicit((Object)(object)butcher))
		{
			if (Object.op_Implicit((Object)(object)butcher))
			{
				list.Remove(butcher);
			}
			int index = Random.Range(0, list.Count());
			val = list.ElementAt(index);
		}
		else
		{
			val = butcher;
		}
		if (!Object.op_Implicit((Object)(object)val))
		{
			return;
		}
		if (val.IsDead)
		{
			val.Resurrect();
		}
		string activeSceneName = SceneManagerHelper.ActiveSceneName;
		List<Vector3> list2 = Templates.BR_Templates.SpawnLocations[activeSceneName];
		int index2 = Random.Range(0, list2.Count());
		Vector3 val2 = list2[index2];
		if (PhotonNetwork.offlineMode)
		{
			RPCManager.Instance.SendSpawnEnemyRPC(((object)val.UID/*cast due to .constrained prefix*/).ToString(), val2.x, val2.y, val2.z);
		}
		else
		{
			((MonoBehaviour)RPCManager.Instance).photonView.RPC("SendSpawnEnemyRPC", (PhotonTargets)0, new object[4]
			{
				((object)val.UID/*cast due to .constrained prefix*/).ToString(),
				val2.x,
				val2.y,
				val2.z
			});
		}
		if (val.Name.ToLower().Contains("butcher"))
		{
			RPCManager.SendMessageToAll("The Butcher of Men has spawned!");
			EnemyCharacters.RemoveAll((Character x) => x.UID == butcher.UID);
		}
		PlayerManager.Instance.ChangeFactions(val, (Factions)0);
	}

	public void EndBattleRoyale()
	{
		UICompass[] array = Resources.FindObjectsOfTypeAll<UICompass>();
		for (int i = 0; i < array.Length; i++)
		{
			((UIElement)array[i]).Show(true);
		}
		try
		{
			if (PhotonNetwork.offlineMode)
			{
				RPCManager.Instance.RPCSendCleanup();
			}
			else
			{
				((MonoBehaviour)RPCManager.Instance).photonView.RPC("RPCSendCleanup", (PhotonTargets)0, new object[0]);
			}
			ActiveItemContainers.Clear();
			ActiveBeamObjects.Clear();
		}
		catch
		{
		}
		if (!PhotonNetwork.isNonMasterClientInRoom && !MenuManager.Instance.IsReturningToMainMenu && !MenuManager.Instance.IsInMainMenuScene)
		{
			IsGameplayEnding = true;
		}
	}

	public void AddItemsToContainer(List<int> _itemList, int _amountToAdd, Transform _container, bool _removeWhenAdded = true)
	{
		List<int> list = _itemList.ToList();
		for (int i = 0; i < _amountToAdd; i++)
		{
			if (list.Count() == 0)
			{
				break;
			}
			int index = Random.Range(0, list.Count());
			ItemManager.Instance.GenerateItemNetwork(list[index]).ChangeParent(_container);
			if (_removeWhenAdded)
			{
				list.RemoveAt(index);
			}
		}
	}

	private IEnumerator GenerateSupplyDrops()
	{
		if (ActiveItemContainers.Count() > 0)
		{
			if (PhotonNetwork.offlineMode)
			{
				RPCManager.Instance.RPCSendCleanup();
			}
			else
			{
				((MonoBehaviour)RPCManager.Instance).photonView.RPC("RPCSendCleanup", (PhotonTargets)0, new object[0]);
			}
			yield return (object)new WaitForSeconds(2f);
		}
		if (SupplyDropCounter == 1)
		{
			foreach (PlayerSystem item in Global.Lobby.PlayersInLobby)
			{
				Character controlledCharacter = item.ControlledCharacter;
				TreasureChest component = ((Component)ItemManager.Instance.GenerateItemNetwork(1000110)).GetComponent<TreasureChest>();
				((Component)component).transform.position = ((Component)controlledCharacter).transform.position + new Vector3(1.5f, 0f, 1.5f);
				ActiveItemContainers.Add(((Component)component).gameObject);
				if (!PhotonNetwork.offlineMode)
				{
					((MonoBehaviour)RPCManager.Instance).photonView.RPC("RPCGenerateStash", (PhotonTargets)1, new object[5]
					{
						((Item)component).ItemID,
						((Item)component).UID,
						((Component)component).transform.position.x,
						((Component)component).transform.position.y,
						((Component)component).transform.position.z
					});
				}
				At.Invoke<TreasureChest>(component, "InitDrops", Array.Empty<object>());
				for (int i = 0; i < 5; i++)
				{
					At.SetField<TreasureChest>(component, "m_hasGeneratedContent", (object)false);
					((SelfFilledItemContainer)component).GenerateContents();
				}
			}
			yield break;
		}
		RPCManager.SendMessageToAll("Supply Chests are spawning!");
		List<Vector3> list = Templates.BR_Templates.SupplyDropLocations[SceneManagerHelper.ActiveSceneName].ToList();
		int num = (int)Math.Ceiling((float)PlayerManager.Instance.GetRemainingPlayers().Count() * 0.5f);
		num = Mathf.Clamp(num, 2, list.Count());
		for (int j = 0; j < num; j++)
		{
			if (list.Count == 0)
			{
				break;
			}
			int index = Random.Range(0, list.Count());
			GenerateChestSingle(list[index]);
			list.RemoveAt(index);
		}
	}

	private void GenerateChestSingle(Vector3 position)
	{
		//IL_003f: 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_0089: 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_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		int num = ((SupplyDropCounter != 2) ? 1000040 : 1000000);
		TreasureChest component = ((Component)ItemManager.Instance.GenerateItemNetwork(num)).GetComponent<TreasureChest>();
		ActiveItemContainers.Add(((Component)component).gameObject);
		((Component)component).transform.position = position;
		if (!PhotonNetwork.offlineMode)
		{
			((MonoBehaviour)RPCManager.Instance).photonView.RPC("RPCGenerateStash", (PhotonTargets)1, new object[5]
			{
				((Item)component).ItemID,
				((Item)component).UID,
				position.x,
				position.y,
				position.z
			});
		}
		Transform transform = ((Component)((Component)component).GetComponentInChildren<ItemContainer>()).transform;
		if (SupplyDropCounter == 2)
		{
			AddItemsToContainer(Templates.BR_Templates.Weapons_Med, 1, transform);
			AddItemsToContainer(Templates.BR_Templates.Offhands_High, 1, transform);
			AddItemsToContainer(Templates.BR_Templates.Armor_Low, 2, transform);
			AddItemsToContainer(Templates.BR_Templates.Supplies_Low, 6, transform, _removeWhenAdded: false);
		}
		else
		{
			AddItemsToContainer(Templates.BR_Templates.Weapons_High, 1, transform);
			AddItemsToContainer(Templates.BR_Templates.Offhands_High, 1, transform);
			AddItemsToContainer(Templates.BR_Templates.Armor_High, 2, transform);
			AddItemsToContainer(Templates.BR_Templates.Supplies_High, 6, transform);
		}
		if (PhotonNetwork.offlineMode)
		{
			RPCManager.Instance.RPCSendSupplyDrop(((Item)component).UID, position.x, position.y, position.z);
			return;
		}
		((MonoBehaviour)RPCManager.Instance).photonView.RPC("RPCSendSupplyDrop", (PhotonTargets)0, new object[4]
		{
			((Item)component).UID,
			position.x,
			position.y,
			position.z
		});
	}

	public IEnumerator SupplyDropLocalCoroutine(string itemUID, Vector3 location)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		while (!Object.op_Implicit((Object)(object)ItemManager.Instance.GetItem(itemUID)))
		{
			yield return (object)new WaitForSeconds(0.1f);
		}
		if ((Object)(object)beamObject != (Object)null)
		{
			GameObject val = Object.Instantiate<GameObject>(beamObject);
			val.SetActive(true);
			((Component)val.transform.GetChild(0)).gameObject.SetActive(false);
			Object.DestroyImmediate((Object)(object)val.GetComponent<MeshCollider>());
			val.transform.localScale = new Vector3(100f, 10f, 100f);
			val.transform.position = location + Vector3.up * 10f;
			ActiveBeamObjects.Add(val);
		}
	}

	public void CleanupSupplyObjects()
	{
		int num = 0;
		while (num < ActiveItemContainers.Count() && ActiveItemContainers.Count() >= 1)
		{
			GameObject val = ActiveItemContainers[num];
			if (Object.op_Implicit((Object)(object)val))
			{
				TreasureChest component = val.GetComponent<TreasureChest>();
				if (component != null)
				{
					try
					{
						ItemManager.Instance.DestroyItem(((Item)component).UID);
					}
					catch
					{
					}
				}
			}
			ActiveItemContainers.RemoveAt(num);
			num--;
			num++;
		}
		int num2 = 0;
		while (num2 < ActiveBeamObjects.Count() && ActiveBeamObjects.Count() >= 1)
		{
			GameObject val2 = ActiveBeamObjects[num2];
			if (Object.op_Implicit((Object)(object)val2))
			{
				Object.DestroyImmediate((Object)(object)val2);
			}
			ActiveBeamObjects.RemoveAt(num2);
			num2--;
			num2++;
		}
	}

	public GameObject FindInactiveObjectByName(string name)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		Transform[] array = Resources.FindObjectsOfTypeAll<Transform>();
		for (int i = 0; i < array.Length; i++)
		{
			if ((int)((Object)array[i]).hideFlags == 0 && ((Object)array[i]).name == name)
			{
				return ((Component)array[i]).gameObject;
			}
		}
		return null;
	}
}
public class BattleRoyale_Hooks
{
	[HarmonyPatch(typeof(Character), "Die")]
	public class Character_Die
	{
		[HarmonyPrefix]
		public static void Prefix(Character __instance)
		{
			//IL_0054: 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_0065: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			if (PvP.Instance.CurrentGame != PvP.GameModes.BattleRoyale)
			{
				return;
			}
			if (!__instance.IsAI)
			{
				if (!PhotonNetwork.isNonMasterClientInRoom && At.GetField<Character>(__instance, "m_lastDealers") is List<Pair<UID, float>> list)
				{
					float num = Time.time;
					string text = "";
					foreach (Pair<UID, float> item in list)
					{
						if (item.Value < num)
						{
							num = item.Value;
							text = UID.op_Implicit(item.Key);
						}
					}
					if (text != "")
					{
						Character character = CharacterManager.Instance.GetCharacter(text);
						if (character != null)
						{
							list.Clear();
							At.SetField<Character>(__instance, "m_lastDealers", (object)character);
							RPCManager.SendMessageToAll(character.Name + " has defeated " + __instance.Name);
						}
					}
				}
				foreach (EquipmentSlot item2 in __instance.Inventory.Equipment.EquipmentSlots.Where((EquipmentSlot x) => (Object)(object)x != (Object)null && x.HasItemEquipped))
				{
					__instance.Inventory.DropItem(((Item)item2.EquippedItem).UID);
				}
			}
			else
			{
				if ((Object)(object)__instance.Inventory == (Object)null || (Object)(object)((Component)__instance).GetComponent<LootableOnDeath>() == (Object)null)
				{
					return;
				}
				if (!Object.op_Implicit((Object)(object)__instance.Inventory.Pouch) || !((EffectSynchronizer)__instance.Inventory.Pouch).FullyInitialized)
				{
					__instance.Inventory.ProcessStart();
				}
				if (!PhotonNetwork.isNonMasterClientInRoom)
				{
					if (__instance.Name.ToLower().Contains("butcher"))
					{
						BattleRoyale.Instance.AddItemsToContainer(Templates.BR_Templates.Skills_High, 3, ((Component)__instance.Inventory.Pouch).transform);
						BattleRoyale.Instance.AddItemsToContainer(Templates.BR_Templates.Weapons_High, 1, ((Component)__instance.Inventory.Pouch).transform);
					}
					else if (__instance.Name == "Immaculate" || ((Object)__instance).name == "Shell Horror")
					{
						BattleRoyale.Instance.AddItemsToContainer(Templates.BR_Templates.Skills_High, 1, ((Component)__instance.Inventory.Pouch).transform);
						BattleRoyale.Instance.AddItemsToContainer(Templates.BR_Templates.Skills_Low, 2, ((Component)__instance.Inventory.Pouch).transform);
					}
					else
					{
						BattleRoyale.Instance.AddItemsToContainer(Templates.BR_Templates.Skills_Low, 3, ((Component)__instance.Inventory.Pouch).transform);
					}
				}
			}
			if (__instance.IsLocalPlayer)
			{
				((Component)__instance.OwnerPlayerSys).gameObject.AddComponent<Spectate>();
			}
		}
	}

	[HarmonyPatch(typeof(ItemContainer), "AddItem", new Type[]
	{
		typeof(Item),
		typeof(bool)
	})]
	public class ItemContainer_AddItem
	{
		[HarmonyPrefix]
		public static bool Prefix(ItemContainer __instance, Item _item, ref bool __result)
		{
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Expected I4, but got Unknown
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Expected I4, but got Unknown
			if (PhotonNetwork.isNonMasterClientInRoom)
			{
				return true;
			}
			if (BattleRoyale.Instance.IsGameplayStarting || PvP.Instance.CurrentGame == PvP.GameModes.BattleRoyale)
			{
				if (_item is Skill && (Object)(object)((EffectSynchronizer)__instance).OwnerCharacter != (Object)null && !((EffectSynchronizer)__instance).OwnerCharacter.IsAI)
				{
					if (!((CharacterKnowledge)((EffectSynchronizer)__instance).OwnerCharacter.Inventory.SkillKnowledge).IsItemLearned(_item.ItemID))
					{
						_item.ChangeParent(((Component)((EffectSynchronizer)__instance).OwnerCharacter.Inventory.SkillKnowledge).transform);
					}
					__result = true;
					return false;
				}
				if (_item is Weapon && (Object)(object)((EffectSynchronizer)__instance).OwnerCharacter != (Object)null && Templates.Weapon_Skills.ContainsKey((int)((Weapon)((_item is Weapon) ? _item : null)).Type))
				{
					int num = Templates.Weapon_Skills[(int)((Weapon)((_item is Weapon) ? _item : null)).Type];
					CharacterSkillKnowledge skillKnowledge = ((EffectSynchronizer)__instance).OwnerCharacter.Inventory.SkillKnowledge;
					if (skillKnowledge != null && !((CharacterKnowledge)skillKnowledge).IsItemLearned(num))
					{
						Item val = ItemManager.Instance.GenerateItemNetwork(num);
						val.ChangeParent(((Component)skillKnowledge).transform);
						(At.GetField<CharacterKnowledge>((CharacterKnowledge)(object)skillKnowledge, "m_learnedItems") as List<Item>).Add(val);
					}
				}
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(PlayerCharacterStats), "UpdateWeight")]
	public class PlayerCharacterStats_UpdateWeight
	{
		[HarmonyFinalizer]
		public static Exception Finalizer()
		{
			return null;
		}
	}
}
public class DeathMatch : MonoBehaviour
{
	public static DeathMatch Instance;

	internal void Awake()
	{
		Instance = this;
	}

	public void UpdateDM()
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		List<Factions> remainingTeams = PlayerManager.Instance.GetRemainingTeams();
		if (remainingTeams.Count == 1)
		{
			string text = ((object)remainingTeams[0]/*cast due to .constrained prefix*/).ToString();
			if (text.EndsWith("s"))
			{
				text = text.Substring(0, text.Length - 1);
			}
			PvP.Instance.StopGameplay(text + "s have won!");
		}
		else if (remainingTeams.Count <= 0)
		{
			PvP.Instance.StopGameplay("Game ended because there are no active teams!");
		}
	}
}
public class FriendlyFire
{
	[HarmonyPatch(typeof(Character), "IsEnemyClose")]
	public class Character_IsEnemyClose
	{
		[HarmonyPrefix]
		public static bool Prefix(ref bool __result, Character __instance, float _range)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			__result = false;
			Collider[] array = Physics.OverlapSphere(__instance.CenterPosition, _range, Global.LockingPointsMask);
			for (int i = 0; i < array.Length; i++)
			{
				LockingPoint component = ((Component)array[i]).GetComponent<LockingPoint>();
				if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.OwnerChar) && component.OwnerChar.Alive && (component.OwnerChar.IsAI || !PvP.Instance.FriendlyFireEnabled) && OrigIsTargetable(__instance.TargetingSystem, component.OwnerChar))
				{
					__result = true;
					break;
				}
			}
			return false;
		}
	}

	[HarmonyPatch(typeof(TargetingSystem), "IsTargetable", new Type[] { typeof(Character) })]
	public class TargetingSys_IsTargetable
	{
		[HarmonyPrefix]
		public static bool Prefix(ref bool __result, Character ___m_character, Character _char)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			if (___m_character.IsAI || !PvP.Instance.FriendlyFireEnabled)
			{
				return true;
			}
			if (___m_character.UID != _char.UID)
			{
				__result = true;
			}
			else
			{
				__result = false;
			}
			return false;
		}
	}

	[HarmonyPatch(typeof(TargetingSystem), "IsTargetable", new Type[] { typeof(Factions) })]
	public class TargetingSys_IsTargetable_2
	{
		[HarmonyPrefix]
		public static bool Prefix(ref bool __result, Character ___m_character)
		{
			if (___m_character.IsAI || !PvP.Instance.FriendlyFireEnabled)
			{
				return true;
			}
			__result = true;
			return false;
		}
	}

	[HarmonyPatch(typeof(TargetingSystem), "AcquireTarget")]
	public class TargetingSys_AcquireTarget
	{
		[HarmonyPrefix]
		public static bool Prefix(TargetingSystem __instance, ref bool __result, Character ___m_character, ref LockingPoint ___m_currentLockingPoint, ref int ___m_remainingHelpLockCount)
		{
			//IL_0048: 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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_0090: 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)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: 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_0116: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)___m_character) || ___m_character.IsAI || !PvP.Instance.FriendlyFireEnabled || (PvP.Instance.FriendlyFireEnabled && PvP.Instance.FriendlyTargetingEnabled))
			{
				return true;
			}
			if ((Object)(object)__instance.CameraRef != (Object)null)
			{
				Collider[] array = Physics.OverlapSphere(___m_character.CenterPosition, __instance.TrueRange, Global.LockingPointsMask);
				LockingPoint val = null;
				Vector3 val2 = Vector2.op_Implicit(Vector2.zero);
				Matrix4x4 worldToCameraMatrix = __instance.CameraRef.worldToCameraMatrix;
				Collider[] array2 = array;
				foreach (Collider val3 in array2)
				{
					Vector3 val4 = ((Matrix4x4)(ref worldToCameraMatrix)).MultiplyPoint(((Component)val3).transform.position);
					if (!(val4.z < 0f))
					{
						continue;
					}
					val4.z *= 0.1f;
					if ((Object)(object)val == (Object)null || ((Vector3)(ref val4)).magnitude < ((Vector3)(ref val2)).magnitude)
					{
						LockingPoint component = ((Component)val3).GetComponent<LockingPoint>();
						if ((Object)(object)component.OwnerChar == (Object)null || (OrigIsTargetable(__instance, component.OwnerChar) && component.OwnerChar.Alive && !Physics.Linecast(___m_character.CenterPosition, ((Component)val3).transform.position, Global.SightHideMask)))
						{
							val = component;
							val2 = val4;
						}
					}
				}
				if ((Object)(object)val != (Object)null)
				{
					___m_currentLockingPoint = val;
					if (___m_remainingHelpLockCount > 0)
					{
						___m_remainingHelpLockCount--;
					}
					__result = true;
					return false;
				}
			}
			__result = false;
			return false;
		}
	}

	[HarmonyPatch(typeof(Blast), "Hit")]
	public class Blast_Hit
	{
		[HarmonyPrefix]
		public static bool Prefix(Blast __instance, ref List<Hitbox> ___cachedHitBox)
		{
			//IL_002e: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)((EffectSynchronizer)__instance).OwnerCharacter) || ((EffectSynchronizer)__instance).OwnerCharacter.IsAI || !PvP.Instance.FriendlyFireEnabled)
			{
				return true;
			}
			Collider[] array = Physics.OverlapSphere(((Component)__instance).transform.position, __instance.Radius, Global.WeaponHittingMask);
			List<Character> list = new List<Character>();
			___cachedHitBox.Clear();
			for (int i = 0; i < array.Length; i++)
			{
				Hitbox component = ((Component)array[i]).GetComponent<Hitbox>();
				if ((Object)(object)component != (Object)null && (Object)(object)component.OwnerChar != (Object)null && component.OwnerChar.UID != ((EffectSynchronizer)__instance).OwnerCharacter.UID && !component.BlockBox && !list.Contains(component.OwnerChar))
				{
					___cachedHitBox.Add(component);
					list.Add(component.OwnerChar);
				}
			}
			At.Invoke<Blast>(__instance, "AffectHit", new object[1] { ___cachedHitBox });
			return false;
		}
	}

	[HarmonyPatch(typeof(Projectile), "Explode", new Type[]
	{
		typeof(Collider),
		typeof(Vector3),
		typeof(Vector3),
		typeof(bool)
	})]
	public class Projectile_Explode
	{
		[HarmonyPrefix]
		public static bool Prefix(Projectile __instance, Collider _collider, Vector3 _hitPoint, Vector3 _hitDir, ref float ___m_lastHitTimer, ref float ___m_targetLightIntensity, float ___m_lightStartIntensity, ref float ___m_lightIntensityFadeSpeed, SoundPlayer ___m_shootSound, SoundPlayer ___m_travelSound, ParticleSystem ___m_explosionFX, ref object[] ___m_explodeInfos)
		{
			//IL_00fb: 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_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Invalid comparison between Unknown and I4
			if (!Object.op_Implicit((Object)(object)((EffectSynchronizer)__instance).OwnerCharacter) || ((EffectSynchronizer)__instance).OwnerCharacter.IsAI || !PvP.Instance.FriendlyFireEnabled)
			{
				return true;
			}
			___m_lastHitTimer = 5f;
			___m_targetLightIntensity = ___m_lightStartIntensity * 1.8f;
			___m_lightIntensityFadeSpeed = __instance.LightIntensityFade.x * 0.5f;
			if (Object.op_Implicit((Object)(object)___m_shootSound))
			{
				___m_shootSound.Stop(false);
			}
			if (Object.op_Implicit((Object)(object)___m_travelSound))
			{
				___m_travelSound.Stop(false);
			}
			Character val = null;
			if ((Object)(object)_collider != (Object)null)
			{
				if (Object.op_Implicit((Object)(object)___m_explosionFX))
				{
					___m_explosionFX.Play();
				}
				val = UnityEngineExtensions.GetCharacterOwner(_collider);
			}
			bool flag = false;
			if (Object.op_Implicit((Object)(object)val) && (Object)(object)((EffectSynchronizer)__instance).OwnerCharacter != (Object)(object)val)
			{
				if (!__instance.Unblockable && val.ShieldEquipped)
				{
					Hitbox component = ((Component)_collider).GetComponent<Hitbox>();
					if ((Object)(object)component != (Object)null && component.BlockBox && val.Blocking && !val.Countering)
					{
						flag = true;
					}
				}
			}
			else
			{
				val = null;
			}
			At.Invoke<Projectile>(__instance, "OnProjectileHit", new object[4] { val, _hitPoint, _hitDir, flag });
			___m_explodeInfos[0] = val;
			___m_explodeInfos[1] = _hitPoint;
			___m_explodeInfos[2] = _hitDir;
			___m_explodeInfos[3] = (Object)(object)_collider != (Object)null;
			((Component)__instance).SendMessage("OnExplodeDone", (object)___m_explodeInfos, (SendMessageOptions)1);
			if ((int)__instance.EndMode == 0 || ((int)__instance.EndMode == 3 && ((Object)(object)_collider == (Object)null || Global.FullEnvironmentMask == (Global.FullEnvironmentMask | (1 << ((Component)_collider).gameObject.layer)))))
			{
				At.Invoke<Projectile>(__instance, "EndLife", Array.Empty<object>());
			}
			return false;
		}
	}

	[HarmonyPatch(typeof(RaycastProjectile), "CheckCollision")]
	public class RaycastProjectile_CheckCollision
	{
		[HarmonyPrefix]
		public static bool Prefix(ref bool __result, RaycastProjectile __instance, Vector3 _startRaycast, float _dist, ref RaycastHit _hit, ref Vector3 ___m_shootDir, float ___m_radiusAdd, float ___m_capsuleAdd, LockingPoint ___m_homingTarget, List<Character> ___m_hitCharList)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Expected O, but got Unknown
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Invalid comparison between Unknown and I4
			if (!PvP.Instance.FriendlyFireEnabled || Object.op_Implicit((Object)(object)((EffectSynchronizer)__instance).OwnerCharacter) || ((EffectSynchronizer)__instance).OwnerCharacter.IsAI)
			{
				return true;
			}
			_hit = default(RaycastHit);
			int num = RaycastHitLayerMask(__instance);
			RaycastHit[] array = ((__instance.Radius == 0f) ? Physics.RaycastAll(_startRaycast, ___m_shootDir, _dist, num) : ((__instance.Capsule == 0f) ? Physics.CapsuleCastAll(_startRaycast - ((Component)__instance).transform.right * (__instance.Capsule + ___m_capsuleAdd), _startRaycast + ((Component)__instance).transform.right * (__instance.Capsule + ___m_capsuleAdd), __instance.Radius + ___m_radiusAdd, ___m_shootDir, _dist, num) : Physics.SphereCastAll(_startRaycast, __instance.Radius + ___m_radiusAdd, ___m_shootDir, _dist, num)));
			if (array.Length != 0)
			{
				Character val = (Character)At.GetField<Projectile>((Projectile)(object)__instance, "m_ignoredCharacter");
				int num2 = -1;
				for (int i = 0; i < array.Length; i++)
				{
					Character characterOwner = UnityEngineExtensions.GetCharacterOwner(((RaycastHit)(ref array[i])).collider);
					if (!(((EffectSynchronizer)__instance).OwnerCharacter.UID != characterOwner.UID))
					{
						continue;
					}
					bool flag = (Object)(object)characterOwner == (Object)null && !__instance.HitTargetOnly;
					if (!flag)
					{
						flag = !__instance.HitTargetOnly || (Object.op_Implicit((Object)(object)___m_homingTarget) && (Object)(object)characterOwner == (Object)(object)___m_homingTarget.OwnerChar);
						flag &= (Object)(object)characterOwner != (Object)(object)val;
						flag &= !___m_hitCharList.Contains(characterOwner) || (!__instance.MultiTarget && (int)((Projectile)__instance).EndMode == 0);
					}
					if (!flag)
					{
						continue;
					}
					if (((RaycastHit)(ref array[i])).point == Vector3.zero)
					{
						((RaycastHit)(ref array[i])).point = ((Component)__instance).transform.position;
					}
					if (num2 != -1)
					{
						Vector3 val2 = _startRaycast - ((RaycastHit)(ref array[i])).point;
						float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
						val2 = _startRaycast - ((RaycastHit)(ref array[num2])).point;
						if (!(sqrMagnitude < ((Vector3)(ref val2)).sqrMagnitude))
						{
							continue;
						}
					}
					if (Object.op_Implicit((Object)(object)characterOwner))
					{
						___m_hitCharList.Add(characterOwner);
					}
					num2 = i;
				}
				if (num2 != -1)
				{
					_hit = array[num2];
					__result = true;
					return false;
				}
			}
			__result = false;
			return false;
		}

		private static int RaycastHitLayerMask(RaycastProjectile __instance)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Invalid comparison between Unknown and I4
			//IL_0009: 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)
			if (((Projectile)__instance).OnlyExplodeOnLayers)
			{
				return LayerMask.op_Implicit(((Projectile)__instance).ExplodeOnContactWithLayers);
			}
			if ((int)__instance.HitLayer == 2)
			{
				return Global.ProjectileHitAllMask;
			}
			if ((int)__instance.HitLayer == 0)
			{
				return Global.ProjectileHitMeleeMask;
			}
			return Global.ProjectileHitRangedMask;
		}
	}

	public static bool OrigIsTargetable(TargetingSystem instance, Character _character)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		Factions faction = _character.Faction;
		for (int num = instance.TargetableFactions.Length - 1; num >= 0; num--)
		{
			ref Factions reference = ref instance.TargetableFactions[num];
			object target = faction;
			if (((Enum)Unsafe.As<Factions, Factions>(ref reference)/*cast due to .constrained prefix*/).CompareTo(target) == 0)
			{
				return true;
			}
		}
		return false;
	}
}
public class PlayerManager : MonoBehaviour
{
	[HarmonyPatch(typeof(DeployableTrap), "ProcessEffect")]
	public class DeployableTrap_ProcessEffect
	{
		[HarmonyPrefix]
		public static bool Prefix(DeployableTrap __instance, Effect _effect)
		{
			Shooter val = (Shooter)(object)((_effect is Shooter) ? _effect : null);
			if (val != null && PvP.Instance.CurrentGame == PvP.GameModes.BattleRoyale)
			{
				val.Setup(Instance.AllFactions.ToArray(), (!((Object)(object)__instance.FX_HolderTrans != (Object)null)) ? ((Component)__instance).transform : __instance.FX_HolderTrans);
				return false;
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(TrapTrigger), "OnTriggerEnter")]
	public class TrapTrigger_OnTriggerEnter
	{
		[HarmonyPrefix]
		public static bool Prefix(TrapTrigger __instance, Collider _other)
		{
			//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: Expected I4, but got Unknown
			if ((Object)(object)_other == (Object)null)
			{
				return true;
			}
			if (PvP.Instance.CurrentGame != PvP.GameModes.NONE)
			{
				DeployableTrap componentInParent = ((Component)__instance).GetComponentInParent<DeployableTrap>();
				if (componentInParent != null)
				{
					At.SetField<DeployableTrap>(componentInParent, "m_targetFactions", (object)Instance.AllFactions.ToArray());
				}
				List<Character> list = At.GetField<TrapTrigger>(__instance, "m_charactersInTrigger") as List<Character>;
				Character component = ((Component)_other).GetComponent<Character>();
				if ((Object)(object)component != (Object)null && !list.Contains(component))
				{
					list.Add(component);
					if (!(bool)At.GetField<TrapTrigger>(__instance, "m_alreadyTriggered"))
					{
						((TriggerColliderFlag)__instance).Trigger.ActivateBasicAction(component, __instance.OnEnterState - 1);
					}
					At.SetField<TrapTrigger>(__instance, "m_alreadyTriggered", (object)true);
				}
				return false;
			}
			return true;
		}
	}

	public static PlayerManager Instance;

	public List<Factions> AllFactions;

	internal void Awake()
	{
		Instance = this;
		AllFactions = new List<Factions>();
		for (int i = 0; i < 10; i++)
		{
			AllFactions.Add((Factions)i);
		}
	}

	public void ChangeFactions(Character c, Factions faction)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected I4, but got Unknown
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		((MonoBehaviour)RPCManager.Instance).photonView.RPC("SendChangeFactionsRPC", (PhotonTargets)0, new object[3]
		{
			(int)faction,
			((object)c.UID/*cast due to .constrained prefix*/).ToString(),
			true
		});
	}

	public List<Factions> GetRemainingTeams()
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		List<Factions> list = new List<Factions>();
		foreach (KeyValuePair<Factions, List<PlayerSystem>> currentPlayer in PvP.Instance.CurrentPlayers)
		{
			if ((int)currentPlayer.Key == 0)
			{
				continue;
			}
			bool flag = false;
			foreach (PlayerSystem item in currentPlayer.Value)
			{
				if ((Object)(object)item.ControlledCharacter != (Object)null && !item.ControlledCharacter.IsDead)
				{
					flag = true;
					break;
				}
			}
			if (flag)
			{
				list.Add(currentPlayer.Key);
			}
		}
		return list;
	}

	public List<Character> GetRemainingPlayers()
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		List<Character> list = new List<Character>();
		foreach (KeyValuePair<Factions, List<PlayerSystem>> currentPlayer in PvP.Instance.CurrentPlayers)
		{
			foreach (PlayerSystem item in PvP.Instance.CurrentPlayers[currentPlayer.Key])
			{
				if ((Object)(object)item.ControlledCharacter != (Object)null && !item.ControlledCharacter.IsDead)
				{
					list.Add(item.ControlledCharacter);
				}
			}
		}
		return list;
	}
}
[BepInPlugin("piratader", "REWORKEDPvP", "0.1.0")]
public class PvP : BaseUnityPlugin
{
	public enum GameModes
	{
		NONE,
		Deathmatch,
		BattleRoyale
	}

	[HarmonyPatch(typeof(InteractionRevive), "OnActivate")]
	public class InteractionRevive_OnActivate
	{
		[HarmonyPrefix]
		public static bool Prefix(InteractionRevive __instance)
		{
			if (Instance.CurrentGame == GameModes.NONE)
			{
				return true;
			}
			object field = At.GetField<InteractionBase>((InteractionBase)(object)__instance, "m_lastCharacter");
			Character val = (Character)((field is Character) ? field : null);
			if (val != null && val.IsLocalPlayer)
			{
				RPCManager.Instance.SendUIMessageLocal(val, "You cannot revive players during a game!");
				((MonoBehaviour)Instance).StartCoroutine(Instance.FixReviveInteraction((InteractionBase)(object)__instance, ((InteractionBase)__instance).OnActivationEvent));
				((InteractionBase)__instance).OnActivationEvent = null;
			}
			return false;
		}
	}

	[HarmonyPatch(typeof(InteractionRevive), "ProcessText")]
	public class InteractionRevive_ProcessText
	{
		[HarmonyPostfix]
		public static void Postfix(ref string __result)
		{
			if (Instance.CurrentGame != GameModes.NONE)
			{
				__result = "";
			}
		}
	}

	public const string GUID = "piratader";

	public const string NAME = "REWORKEDPvP";

	public const string VERSION = "0.1.0";

	public static PvP Instance;

	public Settings settings = new Settings();

	private const string savePath = "BepInEx\\config\\PvP.json";

	private const string MenuKey = "PvP Menu";

	public GameModes CurrentGame;

	public float GameStartTime;

	public Dictionary<Factions, List<PlayerSystem>> CurrentPlayers = new Dictionary<Factions, List<PlayerSystem>>();

	public bool FriendlyFireEnabled;

	public bool FriendlyTargetingEnabled;

	public bool EnemiesDisabled;

	internal void Awake()
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Expected O, but got Unknown
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		Instance = this;
		CustomKeybindings.AddAction("PvP Menu", (KeybindingsCategory)0, (ControlType)0, (InputType)1);
		LoadSettings();
		SceneManager.activeSceneChanged += SceneManager_activeSceneChanged;
		new Harmony("piratader").PatchAll();
		GameObject val = new GameObject("PvP");
		Object.DontDestroyOnLoad((Object)val);
		val.AddComponent<RPCManager>();
		PhotonView val2 = val.AddComponent<PhotonView>();
		val2.viewID = 998;
		Debug.Log((object)("Registered PvP with ViewID " + val2.viewID));
		val.AddComponent<PvPGUI>();
		val.AddComponent<PlayerManager>();
		val.AddComponent<BattleRoyale>();
		val.AddComponent<DeathMatch>();
	}

	private void SceneManager_activeSceneChanged(Scene arg0, Scene arg1)
	{
		string text = SceneManagerHelper.ActiveSceneName.ToLower();
		if (!text.Contains("lowmemory") && !text.Contains("mainmenu"))
		{
			((MonoBehaviour)Instance).StartCoroutine(OnSceneChange());
		}
	}

	private IEnumerator OnSceneChange()
	{
		while (NetworkLevelLoader.Instance.IsGameplayLoading || !NetworkLevelLoader.Instance.AllPlayerDoneLoading)
		{
			yield return (object)new WaitForSeconds(0.3f);
		}
		if (EnemiesDisabled)
		{
			SetEnemiesActive(active: false);
		}
	}

	public static void SetEnemiesActive(bool active)
	{
		Instance.EnemiesDisabled = !active;
		((Component)AISquadManager.Instance).gameObject.SetActive(active);
	}

	internal void Update()
	{
		if ((MenuManager.Instance.IsReturningToMainMenu || Global.IsApplicationClosing) && CurrentGame != GameModes.NONE)
		{
			CurrentGame = GameModes.NONE;
			if (!PhotonNetwork.isNonMasterClientInRoom)
			{
				StopGameplay("The host has left the game!");
			}
		}
		if (Global.Lobby.PlayersInLobbyCount >= 1 && !NetworkLevelLoader.Instance.IsGameplayPaused)
		{
			if (CustomKeybindings.GetKeyDown("PvP Menu"))
			{
				PvPGUI.Instance.ShowGUI = !PvPGUI.Instance.ShowGUI;
			}
			if (CurrentGame != GameModes.NONE)
			{
				UpdateGameplay();
			}
		}
	}

	public void StartGameplay(int _mode, string messageToPlayers = "")
	{
		CurrentGame = (GameModes)_mode;
		((MonoBehaviour)RPCManager.Instance).photonView.RPC("StartGameplayRPC", (PhotonTargets)0, new object[2] { _mode, messageToPlayers });
	}

	public void StopGameplay(string messageToPlayers = "")
	{
		((MonoBehaviour)RPCManager.Instance).photonView.RPC("StopGameplayRPC", (PhotonTargets)0, new object[1] { messageToPlayers });
	}

	private void UpdateGameplay()
	{
		if (CurrentGame != GameModes.BattleRoyale && CurrentGame == GameModes.Deathmatch)
		{
			DeathMatch.Instance.UpdateDM();
		}
	}

	private IEnumerator FixReviveInteraction(InteractionBase _base, UnityAction action)
	{
		yield return (object)new WaitForSeconds(0.1f);
		_base.OnActivationEvent = action;
	}

	private void LoadSettings()
	{
		bool flag = false;
		if (File.Exists("BepInEx\\config\\PvP.json"))
		{
			Settings settings = JsonUtility.FromJson<Settings>(File.ReadAllText("BepInEx\\config\\PvP.json"));
			if (settings != null)
			{
				this.settings = settings;
				flag = true;
			}
		}
		if (!flag)
		{
			this.settings = new Settings();
			SaveSettings();
		}
	}

	internal void OnDisable()
	{
		SaveSettings();
	}

	private void SaveSettings()
	{
		if (!Directory.Exists("BepInEx\\config"))
		{
			Directory.CreateDirectory("BepInEx\\config");
		}
		if (File.Exists("BepInEx\\config\\PvP.json"))
		{
			File.Delete("BepInEx\\config\\PvP.json");
		}
		File.WriteAllText("BepInEx\\config\\PvP.json", JsonUtility.ToJson((object)settings, true));
	}
}
public class PvPGUI : MonoBehaviour
{
	public static PvPGUI Instance;

	private static readonly int WINDOW_ID = 6313531;

	public Rect m_windowRect = Rect.zero;

	public Vector2 scroll = Vector2.zero;

	private Vector2 m_virtualSize = new Vector2(1920f, 1080f);

	private Vector2 m_currentSize = Vector2.zero;

	public Matrix4x4 m_scaledMatrix;

	private bool m_showGUI;

	public int guiPage;

	public bool lastMenuToggle;

	public bool ConfirmingBattleRoyale;

	public Dictionary<Factions, Color> TeamColors = new Dictionary<Factions, Color>
	{
		{
			(Factions)0,
			Color.white
		},
		{
			(Factions)1,
			Color.green
		},
		{
			(Factions)2,
			Color.red * 2f
		},
		{
			(Factions)3,
			Color.cyan * Color.grey
		},
		{
			(Factions)4,
			Color.magenta
		},
		{
			(Factions)5,
			new Color(0.8f, 0.3f, 0.3f)
		},
		{
			(Factions)6,
			new Color(0.3f, 0.3f, 1f)
		},
		{
			(Factions)7,
			Color.gray
		},
		{
			(Factions)8,
			Color.yellow
		}
	};

	public bool ShowGUI
	{
		get
		{
			return m_showGUI;
		}
		set
		{
			m_showGUI = value;
			if (m_showGUI)
			{
				ForceUnlockCursor.AddUnlockSource();
			}
			else
			{
				ForceUnlockCursor.RemoveUnlockSource();
			}
		}
	}

	internal void Awake()
	{
		Instance = this;
	}

	internal void Start()
	{
		ShowGUI = PvP.Instance.settings.Show_Menu_On_Startup;
	}

	internal void Update()
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: 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_0064: 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)
		if (m_currentSize.x != (float)Screen.width || m_currentSize.y != (float)Screen.height)
		{
			m_scaledMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3((float)Screen.width / m_virtualSize.x, (float)Screen.height / m_virtualSize.y, 1f));
			m_currentSize = new Vector2((float)Screen.width, (float)Screen.height);
		}
		if (!NetworkLevelLoader.Instance.IsGameplayPaused)
		{
			_ = Global.Lobby.PlayersInLobbyCount;
			_ = 0;
		}
	}

	internal void OnGUI()
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: 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_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Expected O, but got Unknown
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Expected O, but got Unknown
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Expected O, but got Unknown
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		GUISkin skin = GUI.skin;
		GUI.skin = UIStyles.WindowSkin;
		Matrix4x4 matrix = GUI.matrix;
		if (PvP.Instance.settings.Enable_Menu_Scaling)
		{
			GUI.matrix = m_scaledMatrix;
		}
		if (!(m_windowRect == Rect.zero))
		{
			_ = m_windowRect;
		}
		else
		{
			m_windowRect = new Rect(50f, 50f, 500f, 300f);
		}
		if (!ConfirmingBattleRoyale && ShowGUI)
		{
			m_windowRect = GUI.Window(WINDOW_ID, m_windowRect, new WindowFunction(DrawWindow), "PvP 0.1.0");
		}
		else if (ConfirmingBattleRoyale || BattleRoyale.Instance.IsGameplayEnding)
		{
			float num = Screen.width / 2 - 200;
			float num2 = ((Global.Lobby.LocalPlayerCount <= 1) ? ((float)(Screen.height / 2 - 150)) : ((float)(Screen.height / 4 - 150)));
			if (ConfirmingBattleRoyale)
			{
				GUI.Window(WINDOW_ID, new Rect(num, num2, 400f, 250f), new WindowFunction(BattleRoyaleConfirmStart), "Are you sure?");
			}
			else if (BattleRoyale.Instance.IsGameplayEnding)
			{
				GUI.Window(WINDOW_ID, new Rect(num, num2, 400f, 150f), new WindowFunction(BattleRoyaleGameEnd), "Play again?");
			}
		}
		if (PvP.Instance.CurrentGame != PvP.GameModes.NONE)
		{
			CurrentGameWindow();
		}
		GUI.matrix = matrix;
		GUI.skin = skin;
	}

	private void DrawWindow(int id)
	{
		//IL_0020: 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_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		GUI.DragWindow(new Rect(0f, 0f, ((Rect)(ref m_windowRect)).width - 50f, 20f));
		if (GUI.Button(new Rect(((Rect)(ref m_windowRect)).width - 50f, 0f, 45f, 20f), "X"))
		{
			ShowGUI = false;
		}
		GUILayout.BeginArea(new Rect(3f, 25f, ((Rect)(ref m_windowRect)).width - 8f, ((Rect)(ref m_windowRect)).height - 5f));
		GUILayout.BeginHorizontal(GUI.skin.box, Array.Empty<GUILayoutOption>());
		GUILayout.Space(150f);
		if (guiPage == 0)
		{
			GUI.color = Color.green;
		}
		else
		{
			GUI.color = Color.white;
		}
		if (GUILayout.Button("Main", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) }))
		{
			guiPage = 0;
		}
		if (guiPage == 1)
		{
			GUI.color = Color.green;
		}
		else
		{
			GUI.color = Color.white;
		}
		if (GUILayout.Button("Settings", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) }))
		{
			guiPage = 1;
		}
		GUI.color = Color.white;
		GUILayout.EndHorizontal();
		GUI.skin.box.alignment = (TextAnchor)0;
		scroll = GUILayout.BeginScrollView(scroll, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(((Rect)(ref m_windowRect)).height - 70f) });
		switch (guiPage)
		{
		case 0:
			MainPage();
			break;
		case 1:
			SettingsPage();
			break;
		}
		GUILayout.EndScrollView();
		GUILayout.EndArea();
	}

	private void MainPage()
	{
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_016e: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: 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_035f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0365: Invalid comparison between Unknown and I4
		//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0302: Unknown result type (might be due to invalid IL or missing references)
		//IL_0417: Unknown result type (might be due to invalid IL or missing references)
		//IL_0398: Unknown result type (might be due to invalid IL or missing references)
		//IL_039e: Unknown result type (might be due to invalid IL or missing references)
		//IL_039f: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
		if (Global.Lobby.PlayersInLobbyCount > 0 && !NetworkLevelLoader.Instance.IsGameplayPaused)
		{
			if (!PhotonNetwork.isNonMasterClientInRoom)
			{
				if (PvP.Instance.CurrentGame == PvP.GameModes.NONE)
				{
					GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
					if (GUILayout.Button("Begin Deathmatch", Array.Empty<GUILayoutOption>()))
					{
						PvP.Instance.StartGameplay(1, "A Deathmatch has begun!");
					}
					if (GUILayout.Button("Begin Battle Royale", Array.Empty<GUILayoutOption>()))
					{
						ConfirmingBattleRoyale = true;
					}
					GUILayout.EndHorizontal();
				}
				else if (GUILayout.Button("End Gameplay", Array.Empty<GUILayoutOption>()))
				{
					PvP.Instance.StopGameplay("The host has ended the game.");
				}
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				if (!PvP.Instance.FriendlyFireEnabled)
				{
					GUI.color = Color.red;
					if (GUILayout.Button("Enable Friendly Fire", Array.Empty<GUILayoutOption>()))
					{
						RPCManager.SendFriendyFire(enabled: true);
					}
				}
				else
				{
					GUI.color = Color.green;
					if (GUILayout.Button("Disable Friendly Fire", Array.Empty<GUILayoutOption>()))
					{
						RPCManager.SendFriendyFire(enabled: false);
					}
					if (!PvP.Instance.FriendlyTargetingEnabled)
					{
						GUI.color = Color.red;
						if (GUILayout.Button("Enable Friendly Targeting", Array.Empty<GUILayoutOption>()))
						{
							RPCManager.SendFriendyTargeting(enabled: true);
						}
					}
					else if (GUILayout.Button("Disable Friendly Targeting", Array.Empty<GUILayoutOption>()))
					{
						RPCManager.SendFriendyTargeting(enabled: false);
					}
				}
				if (!PvP.Instance.EnemiesDisabled)
				{
					GUI.color = Color.green;
					if (GUILayout.Button("Disable Enemies", Array.Empty<GUILayoutOption>()))
					{
						RPCManager.SendSetEnemiesActive(active: false);
					}
				}
				else
				{
					GUI.color = Color.red;
					if (GUILayout.Button("Enable Enemies", Array.Empty<GUILayoutOption>()))
					{
						RPCManager.SendSetEnemiesActive(active: true);
					}
				}
				GUILayout.EndHorizontal();
				GUI.color = Color.white;
			}
			GUILayout.Label("Characters: ", Array.Empty<GUILayoutOption>());
			{
				foreach (PlayerSystem item in Global.Lobby.PlayersInLobby)
				{
					if (!item.ControlledCharacter.Initialized)
					{
						continue;
					}
					GUILayout.BeginHorizontal(GUI.skin.box, Array.Empty<GUILayoutOption>());
					GUI.skin.label.wordWrap = false;
					GUI.color = TeamColors[item.ControlledCharacter.Faction];
					string name = item.ControlledCharacter.Name;
					name = (item.ControlledCharacter.IsWorldHost ? (name + " [Host]") : ((!item.ControlledCharacter.IsLocalPlayer) ? (name + " [Online]") : (name + " [Local]")));
					GUILayout.Label(name, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(130f) });
					GUILayout.Label("Team: ", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(40f) });
					if (!PhotonNetwork.isNonMasterClientInRoom || item.ControlledCharacter.IsLocalPlayer)
					{
						if ((int)item.ControlledCharacter.Faction != 0 && PvP.Instance.CurrentGame == PvP.GameModes.NONE)
						{
							if (GUILayout.Button("<", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(30f) }))
							{
								Factions faction = (Factions)(item.ControlledCharacter.Faction - 1);
								PlayerManager.Instance.ChangeFactions(item.ControlledCharacter, faction);
							}
						}
						else
						{
							GUILayout.Space(35f);
						}
					}
					GUILayout.Label(((object)Unsafe.As<Factions, Factions>(ref item.ControlledCharacter.Faction)/*cast due to .constrained prefix*/).ToString(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) });
					if (!PhotonNetwork.isNonMasterClientInRoom || item.ControlledCharacter.IsLocalPlayer)
					{
						if ((int)item.ControlledCharacter.Faction != 8 && PvP.Instance.CurrentGame == PvP.GameModes.NONE)
						{
							if (GUILayout.Button(">", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(30f) }))
							{
								Factions faction2 = (Factions)(item.ControlledCharacter.Faction + 1);
								PlayerManager.Instance.ChangeFactions(item.ControlledCharacter, faction2);
							}
						}
						else
						{
							GUILayout.Space(35f);
						}
						if (item.ControlledCharacter.IsDead && PvP.Instance.CurrentGame == PvP.GameModes.NONE && GUILayout.Button("Resurrect", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(75f) }))
						{
							RPCManager.Instance.SendResurrect(item.ControlledCharacter);
						}
					}
					GUI.skin.label.wordWrap = true;
					GUI.color = Color.white;
					GUILayout.EndHorizontal();
				}
				return;
			}
		}
		GUILayout.Label("Load up a character to begin...", Array.Empty<GUILayoutOption>());
	}

	private void SettingsPage()
	{
		GUILayout.BeginVertical(GUI.skin.box, Array.Empty<GUILayoutOption>());
		PvP.Instance.settings.Show_Menu_On_Startup = GUILayout.Toggle(PvP.Instance.settings.Show_Menu_On_Startup, "Show Menu On Startup", Array.Empty<GUILayoutOption>());
		PvP.Instance.settings.Enable_Menu_Scaling = GUILayout.Toggle(PvP.Instance.settings.Enable_Menu_Scaling, "Enable Menu Scaling", Array.Empty<GUILayoutOption>());
		GUILayout.Space(15f);
		GUILayout.EndVertical();
	}

	private void BattleRoyaleConfirmStart(int windowID)
	{
		//IL_0014: 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)
		GUI.DragWindow(new Rect(0f, 0f, 400f, 20f));
		GUILayout.BeginArea(new Rect(15f, 25f, 370f, 350f));
		GUI.skin.label.alignment = (TextAnchor)4;
		string text = "Are you sure you want to start a Battle Royale?";
		if (SceneManagerHelper.ActiveSceneName != "Monsoon")
		{
			text += "\r\n\r\nThis will teleport all players to Monsoon.";
		}
		GUILayout.Label(text, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(370f) });
		GUILayout.Label("<b><color=red>WARNING:</color> This will WIPE the character save and you will need to manually restore your save from a backup if you wish to restore it for this character.\r\n\r\nIt is highly recommended to use a fresh character for Battle Royale so that you don't care if it gets wiped.</b>", Array.Empty<GUILayoutOption>());
		GUILayout.Space(20f);
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		if (GUILayout.Button("No, go back!", Array.Empty<GUILayoutOption>()))
		{
			ConfirmingBattleRoyale = false;
		}
		GUILayout.Space(30f);
		if (GUILayout.Button("Yes, I'm sure!", Array.Empty<GUILayoutOption>()))
		{
			ConfirmingBattleRoyale = false;
			ShowGUI = false;
			if (BattleRoyale.Instance.CheckCanStart())
			{
				BattleRoyale.Instance.StartBattleRoyale();
			}
			else
			{
				RPCManager.Instance.SendUIMessageLocal(CharacterManager.Instance.GetFirstLocalCharacter(), "There are not enough teams to start!");
			}
		}
		GUILayout.EndHorizontal();
		GUILayout.EndArea();
	}

	private void BattleRoyaleGameEnd(int windowID)
	{
		//IL_0014: 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)
		GUI.DragWindow(new Rect(0f, 0f, 400f, 20f));
		GUILayout.BeginArea(new Rect(15f, 65f, 370f, 350f));
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		if (GUILayout.Button("Play Again", Array.Empty<GUILayoutOption>()))
		{
			BattleRoyale.Instance.StartBattleRoyale(skipLoad: true);
			BattleRoyale.Instance.IsGameplayEnding = false;
			ShowGUI = false;
		}
		GUILayout.Space(30f);
		if (GUILayout.Button("End Lobby", Array.Empty<GUILayoutOption>()))
		{
			BattleRoyale.Instance.IsGameplayEnding = false;
			ShowGUI = false;
			((MonoBehaviour)RPCManager.Instance).photonView.RPC("EndBattleRoyaleRPC", (PhotonTargets)0, new object[0]);
		}
		GUILayout.EndHorizontal();
		GUILayout.EndArea();
	}

	private void CurrentGameWindow()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.BeginArea(new Rect(15f, 15f, 240f, (float)Screen.height * 0.7f));
		if (PvP.Instance.CurrentGame == PvP.GameModes.BattleRoyale && BattleRoyale.Instance.IsGameplayStarting)
		{
			GUILayout.Label("A Battle Royale is starting...", Array.Empty<GUILayoutOption>());
		}
		else
		{
			GUIStyle label = GUI.skin.label;
			label.fontSize *= 2;
			TimeSpan timeSpan = TimeSpan.FromSeconds(Time.time - PvP.Instance.GameStartTime);
			GUILayout.Label(timeSpan.Minutes.ToString("0") + ":" + timeSpan.Seconds.ToString("00"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(40f) });
			GUIStyle label2 = GUI.skin.label;
			label2.fontSize /= 2;
			GUILayout.Label("Current Teams:", Array.Empty<GUILayoutOption>());
			foreach (KeyValuePair<Factions, List<PlayerSystem>> currentPlayer in PvP.Instance.CurrentPlayers)
			{
				if ((int)currentPlayer.Key == 0)
				{
					continue;
				}
				GUI.color = TeamColors[currentPlayer.Key];
				GUILayout.Label(((object)currentPlayer.Key/*cast due to .constrained prefix*/).ToString() + ":", Array.Empty<GUILayoutOption>());
				GUI.color = Color.white;
				foreach (PlayerSystem item in currentPlayer.Value)
				{
					if (item.ControlledCharacter.IsDead)
					{
						GUI.color = Color.black;
						GUILayout.Label(" - " + item.ControlledCharacter.Name + " (DEAD)", Array.Empty<GUILayoutOption>());
						continue;
					}
					GUILayout.Label(" - " + item.ControlledCharacter.Name + " (" + Math.Round((decimal)item.ControlledCharacter.Stats.CurrentHealth) + " / " + item.ControlledCharacter.Stats.MaxHealth + ")", Array.Empty<GUILayoutOption>());
				}
			}
		}
		GUILayout.EndArea();
	}
}
public class UIStyles
{
	private static GUISkin _customSkin;

	public static Texture2D m_nofocusTex;

	public static Texture2D m_focusTex;

	private static GUIStyle _horizBarStyle;

	public static GUISkin WindowSkin
	{
		get
		{
			if ((Object)(object)_customSkin == (Object)null)
			{
				try
				{
					_customSkin = CreateWindowSkin();
				}
				catch
				{
					_customSkin = GUI.skin;
				}
			}
			return _customSkin;
		}
	}

	private static GUIStyle HorizontalBar
	{
		get
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			if (_horizBarStyle == null)
			{
				_horizBarStyle = new GUIStyle();
				_horizBarStyle.normal.background = Texture2D.whiteTexture;
				_horizBarStyle.margin = new RectOffset(0, 0, 4, 4);
				_horizBarStyle.fixedHeight = 2f;
			}
			return _horizBarStyle;
		}
	}

	public static void HorizontalLine(Color color)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		Color color2 = GUI.color;
		GUI.color = color;
		GUILayout.Box(GUIContent.none, HorizontalBar, Array.Empty<GUILayoutOption>());
		GUI.color = color2;
	}

	private static GUISkin CreateWindowSkin()
	{
		//IL_002e: 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_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: 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)
		GUISkin obj = Object.Instantiate<GUISkin>(GUI.skin);
		Object.DontDestroyOnLoad((Object)(object)obj);
		m_nofocusTex = MakeTex(550, 700, new Color(0.1f, 0.1f, 0.1f, 0.7f));
		m_focusTex = MakeTex(550, 700, new Color(0.3f, 0.3f, 0.3f, 1f));
		obj.window.normal.background = m_nofocusTex;
		obj.window.onNormal.background = m_focusTex;
		obj.box.normal.textColor = Color.white;
		obj.window.normal.textColor = Color.white;
		obj.button.normal.textColor = Color.white;
		obj.textField.normal.textColor = Color.white;
		obj.label.normal.textColor = Color.white;
		return obj;
	}

	public static Texture2D MakeTex(int width, int height, Color col)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Expected O, but got Unknown
		Color[] array = (Color[])(object)new Color[width * height];
		for (int i = 0; i < array.Length; i++)
		{
			array[i] = col;
		}
		Texture2D val = new Texture2D(width, height);
		val.SetPixels(array);
		val.Apply();
		return val;
	}
}
public class RPCManager : MonoBehaviour
{
	public static RPCManager Instance;

	internal void Awake()
	{
		Instance = this;
	}

	public static void SendSetEnemiesActive(bool active)
	{
		if (!PhotonNetwork.isNonMasterClientInRoom)
		{
			((MonoBehaviour)Instance).photonView.RPC("RPCSetEnemiesActive", (PhotonTargets)3, new object[1] { active });
		}
	}

	[PunRPC]
	private void RPCSetEnemiesActive(bool active)
	{
		PvP.SetEnemiesActive(active);
	}

	public static void SendSetPlayerActive(string uid, bool active)
	{
		((MonoBehaviour)Instance).photonView.RPC("RPCSetPlayerActive", (PhotonTargets)3, new object[2] { uid, active });
	}

	[PunRPC]
	private void RPCSetPlayerActive(string uid, bool active)
	{
		Character character = CharacterManager.Instance.GetCharacter(uid);
		if (character != null)
		{
			((Component)character).gameObject.SetActive(active);
		}
	}

	public static void SendFriendyFire(bool enabled)
	{
		SendMessageToAll((enabled ? "Enabling" : "Disabling") + " Friendly Fire!");
		((MonoBehaviour)Instance).photonView.RPC("SendFriendlyFireRPC", (PhotonTargets)3, new object[1] { enabled });
	}

	[PunRPC]
	private void SendFriendlyFireRPC(bool enabled)
	{
		PvP.Instance.FriendlyFireEnabled = enabled;
	}

	public static void SendFriendyTargeting(bool enabled)
	{
		SendMessageToAll((enabled ? "Enabling" : "Disabling") + " Friendly Targeting!");
		((MonoBehaviour)Instance).photonView.RPC("SendFriendlyTargetingRPC", (PhotonTargets)3, new object[1] { enabled });
	}

	[PunRPC]
	private void SendFriendlyTargetingRPC(bool enabled)
	{
		PvP.Instance.FriendlyTargetingEnabled = enabled;
	}

	[PunRPC]
	public void StartGameplayRPC(int _mode, string messageToPlayers = "")
	{
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		if (PvPGUI.Instance.ShowGUI)
		{
			PvPGUI.Instance.ShowGUI = false;
		}
		if (_mode == 2)
		{
			BattleRoyale.Instance.IsGameplayStarting = false;
			BattleRoyale.Instance.LastSupplyDropTime = -1f;
			BattleRoyale.Instance.LastEnemySpawnTime = Time.time;
			BattleRoyale.Instance.SupplyDropCounter = 0;
			BattleRoyale.Instance.ActiveItemContainers.Clear();
			BattleRoyale.Instance.ActiveBeamObjects.Clear();
		}
		PvP.Instance.CurrentPlayers.Clear();
		foreach (PlayerSystem item in Global.Lobby.PlayersInLobby)
		{
			if ((int)item.ControlledCharacter.Faction == 0)
			{
				if (item.IsLocalPlayer)
				{
					((Component)item).gameObject.AddComponent<Spectate>();
				}
				continue;
			}
			if (PvP.Instance.CurrentPlayers.ContainsKey(item.ControlledCharacter.Faction))
			{
				PvP.Instance.CurrentPlayers[item.ControlledCharacter.Faction].Add(item);
			}
			else
			{
				PvP.Instance.CurrentPlayers.Add(item.ControlledCharacter.Faction, new List<PlayerSystem> { item });
			}
			if (item.ControlledCharacter.IsLocalPlayer)
			{
				Instance.SendUIMessageLocal(item.ControlledCharacter, messageToPlayers);
			}
		}
		PvP.Instance.CurrentGame = (PvP.GameModes)_mode;
		PvP.Instance.GameStartTime = Time.time;
	}

	[PunRPC]
	public void StopGameplayRPC(string messageToPlayers = "")
	{
		if (PvP.Instance.CurrentGame == PvP.GameModes.BattleRoyale)
		{
			BattleRoyale.Instance.EndBattleRoyale();
		}
		PvP.Instance.CurrentGame = PvP.GameModes.NONE;
		List<PlayerSystem> list = Global.Lobby.PlayersInLobby;
		if (PhotonNetwork.isNonMasterClientInRoom)
		{
			list = list.Where((PlayerSystem x) => (Object)(object)x.ControlledCharacter != (Object)null && x.ControlledCharacter.IsLocalPlayer).ToList();
		}
		foreach (PlayerSystem item in list)
		{
			((Component)item).GetComponent<Spectate>()?.EndSpectate();
			if (messageToPlayers != "" && (Object)(object)item.ControlledCharacter != (Object)null && item.ControlledCharacter.IsLocalPlayer)
			{
				Instance.SendUIMessageLocal(item.ControlledCharacter, messageToPlayers);
			}
			if (!PhotonNetwork.isNonMasterClientInRoom && (Object)(object)item.ControlledCharacter != (Object)null && item.ControlledCharacter.IsDead)
			{
				Instance.SendResurrect(item.ControlledCharacter);
			}
		}
	}

	public static void SendMessageToAll(string message)
	{
		((MonoBehaviour)Instance).photonView.RPC("SendMessageToAllRPC", (PhotonTargets)0, new object[1] { message });
	}

	[PunRPC]
	private void SendMessageToAllRPC(string message)
	{
		foreach (PlayerSystem item in Global.Lobby.PlayersInLobby.Where((PlayerSystem x) => x.ControlledCharacter.IsLocalPlayer))
		{
			SendUIMessageLocal(item.ControlledCharacter, message);
		}
	}

	public void SendUIMessageLocal(Character c, string message)
	{
		c.CharacterUI.NotificationPanel.ShowNotification(message, 5f);
	}

	[PunRPC]
	public void SendChangeFactionsRPC(int factionInt, string UID, bool alliedToSame = true)
	{
		//IL_0017: 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)
		//IL_0023: 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_0034: Unknown result type (might be due to invalid IL or missing references)
		Character character = CharacterManager.Instance.GetCharacter(UID);
		if (character != null)
		{
			Factions faction = (Factions)factionInt;
			character.Faction = faction;
			character.DetectabilityEmitter.Faction = faction;
			List<Factions> list = PlayerManager.Instance.AllFactions.Where((Factions x) => x != faction).ToList();
			character.TargetingSystem.TargetableFactions = list.ToArray();
			if (!alliedToSame)
			{
				character.TargetingSystem.AlliedToSameFaction = false;
			}
			else
			{
				character.TargetingSystem.AlliedToSameFaction = true;
			}
		}
	}

	public void SendResurrect(Character _character)
	{
		if (!PhotonNetwork.offlineMode)
		{
			((MonoBehaviour)_character).photonView.RPC("SendResurrect", (PhotonTargets)0, new object[3]
			{
				true,
				string.Empty,
				true
			});
		}
		else
		{
			_character.Resurrect();
		}
	}

	[PunRPC]
	public void RPCStartBattleRoyale(bool skipLoad = false)
	{
		if (SceneManagerHelper.ActiveSceneName == "Monsoon")
		{
			skipLoad = true;
		}
		BattleRoyale.Instance.IsGameplayStarting = true;
		PvP.Instance.CurrentGame = PvP.GameModes.BattleRoyale;
		if (!skipLoad)
		{
			foreach (PlayerSystem item in Global.Lobby.PlayersInLobby.Where((PlayerSystem x) => x.ControlledCharacter.IsLocalPlayer))
			{
				Character controlledCharacter = item.ControlledCharacter;
				CharacterManager.Instance.RequestAreaSwitch(controlledCharacter, AreaManager.Instance.GetAreaFromSceneName("Monsoon"), 0, 0, 1.5f, "Battle Royale!");
			}
		}
		if (Global.CheatsEnabled)
		{
			Global.CheatsEnabled = false;
			foreach (PlayerSystem item2 in Global.Lobby.PlayersInLobby.Where((PlayerSystem x) => x.ControlledCharacter.IsLocalPlayer))
			{
				CharacterControl characterControl = item2.ControlledCharacter.CharacterControl;
				((LocalCharacterControl)((characterControl is LocalCharacterControl) ? characterControl : null)).MovementMultiplier = 1f;
			}
		}
		((MonoBehaviour)this).StartCoroutine(BattleRoyale.Instance.SetupAfterSceneLoad(skipLoad));
	}

	[PunRPC]
	public void SendSpawnEnemyRPC(string uid, float x, float y, float z)
	{
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Expected O, but got Unknown
		Character val = BattleRoyale.Instance.EnemyCharacters.Find((Character w) => w.UID == UID.op_Implicit(uid));
		if (val != null)
		{
			((Component)val).gameObject.SetActive(true);
			val.Teleport(new Vector3(x, y, z), ((Component)val).transform.rotation);
			int num = 50;
			if (val.Name.ToLower().Contains("butcher"))
			{
				num = 200;
			}
			else if (((Object)val).name.ToLower().Contains("illuminator"))
			{
				num = 20;
			}
			At.SetField<CharacterStats>(val.Stats, "m_maxHealthStat", (object)new Stat((float)num));
		}
	}

	[PunRPC]
	public void EndBattleRoyaleRPC()
	{
		MenuManager.Instance.BackToMainMenu();
	}

	[PunRPC]
	public void RPCSendSupplyDrop(string itemUID, float x, float y, float z)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		((MonoBehaviour)this).StartCoroutine(BattleRoyale.Instance.SupplyDropLocalCoroutine(itemUID, new Vector3(x, y, z)));
	}

	[PunRPC]
	public void RPCSendCleanup()
	{
		BattleRoyale.Instance.CleanupSupplyObjects();
	}

	[PunRPC]
	public void RPCGenerateStash(int itemID, string UID, float x, float y, float z)
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		TreasureChest component = ((Component)ItemManager.Instance.GenerateItemNetwork(itemID)).GetComponent<TreasureChest>();
		((Item)component).UID = UID;
		((Item)component).SaveType = (SaveTypes)0;
		((Component)component).transform.position = new Vector3(x, y, z);
		BattleRoyale.Instance.ActiveItemContainers.Add(((Component)component).gameObject);
	}
}
public class Spectate : MonoBehaviour
{
	private static Camera m_camera;

	private Character m_ownerCharacter;

	private Vector3 m_startPosition;

	private Character m_target;

	private int m_spectateTargetIndex;

	private bool hasTarget;

	public static Transform CameraTransform => VideoCamera.Instance.VideoCameraTrans;

	public static Camera FreeCamera
	{
		get
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			if (!Object.op_Implicit((Object)(object)m_camera))
			{
				m_camera = (Camera)At.GetField<VideoCamera>(VideoCamera.Instance, "m_camera");
			}
			return m_camera;
		}
	}

	public Character[] AvailableTargets => PlayerManager.Instance.GetRemainingPlayers().ToArray();

	internal void Awake()
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: 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)
		m_ownerCharacter = ((Component)this).gameObject.GetComponent<PlayerSystem>().ControlledCharacter;
		m_startPosition = ((Component)m_ownerCharacter).transform.position;
		List<Character> list = new List<Character>();
		CharacterManager.Instance.FindCharactersInRange(((Component)m_ownerCharacter).transform.position, 10f, ref list);
		if (list.Contains(m_ownerCharacter))
		{
			list.Remove(m_ownerCharacter);
		}
		RPCManager.SendSetPlayerActive(UID.op_Implicit(m_ownerCharacter.UID), active: false);
		SetFreeCam(active: true);
		if (list.Count > 0)
		{
			SetTarget(list[0]);
		}
	}

	private void SetFreeCam(bool active)
	{
		At.Invoke<VideoCamera>(VideoCamera.Instance, "SetCameraActive", new object[1] { active });
		if (active)
		{
			At.SetField<VideoCamera>(VideoCamera.Instance, "m_flyMode", (object)true);
			Global.LockCursor(true);
		}
	}

	internal void Update()
	{
		if (Input.GetKeyDown((KeyCode)276))
		{
			CycleTarget(-1);
		}
		else if (Input.GetKeyDown((KeyCode)275))
		{
			CycleTarget(1);
		}
		else if (Input.GetKeyDown((KeyCode)273) || Input.GetKeyDown((KeyCode)274))
		{
			m_spectateTargetIndex = 0;
			ReleaseTarget();
		}
		else if (Input.GetKeyDown((KeyCode)27) && !PvPGUI.Instance.ShowGUI)
		{
			ReleaseTarget();
			PvPGUI.Instance.ShowGUI = true;
			Global.LockCursor(false);
		}
		if (hasTarget)
		{
			UpdateTarget();
		}
	}

	private void UpdateTarget()
	{
		//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_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: 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_0064: 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)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)m_target) || m_target.IsDead)
		{
			ReleaseTarget();
			return;
		}
		Vector3 position = ((Component)m_target).transform.position + Vector3.up * 4f + ((Component)m_target).transform.forward * -6f;
		((Component)FreeCamera).transform.position = position;
		CameraTransform.position = position;
		((Component)FreeCamera).transform.LookAt(((Component)m_target).transform);
		CameraTransform.LookAt(((Component)m_target).transform);
	}

	private void CycleTarget(int change)
	{
		if (change == -1)
		{
			if (m_spectateTargetIndex > 0)
			{
				m_spectateTargetIndex--;
			}
			else
			{
				m_spectateTargetIndex = AvailableTargets.Length - 1;
			}
		}
		else if (m_spectateTargetIndex < AvailableTargets.Length - 1)
		{
			m_spectateTargetIndex++;
		}
		else
		{
			m_spectateTargetIndex = 0;
		}
		SetTarget(AvailableTargets[m_spectateTargetIndex]);
	}

	private void SetTarget(Character target)
	{
		hasTarget = true;
		m_target = target;
		Global.LockCursor(true);
		RPCManager.Instance.SendUIMessageLocal(m_ownerCharacter, "Spectating " + target.Name);
		At.SetField<VideoCamera>(VideoCamera.Instance, "m_targetTrans", (object)((Component)target).transform);
		At.SetField<VideoCamera>(VideoCamera.Instance, "m_state", (object)(VideoCamState)2);
	}

	private void ReleaseTarget()
	{
		hasTarget = false;
		m_target = null;
		At.SetField<VideoCamera>(VideoCamera.Instance, "m_targetTrans", (object)null);
		At.SetField<VideoCamera>(VideoCamera.Instance, "m_state", (object)(VideoCamState)0);
	}

	public void EndSpectate()
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		ReleaseTarget();
		SetFreeCam(active: false);
		RPCManager.SendSetPlayerActive(UID.op_Implicit(m_ownerCharacter.UID), active: true);
		m_ownerCharacter.Teleport(m_startPosition, Quaternion.identity);
		Object.Destroy((Object)(object)this);
	}
}
public class Settings
{
	public bool Enable_Menu_Scaling;

	public bool Show_Menu_On_Startup = true;
}
public static class Templates
{
	public static class BR_Templates
	{
		public static readonly Dictionary<string, float> TimeOfDayStarts = new Dictionary<string, float> { { "Monsoon", 23f } };

		public static readonly Dictionary<string, List<Vector3>> SpawnLocations = new Dictionary<string, List<Vector3>> { 
		{
			"Monsoon",
			new List<Vector3>
			{
				new Vector3(50.4f, -2.7f, 102.6f),
				new Vector3(93.9f, -6.97f, 109.1f),
				new Vector3(137.5f, 22.13f, 172.5f),
				new Vector3(91.7f, -4.37f, 195.2f),
				new Vector3(81.82f, -3.38f, 258.07f),
				new Vector3(146.4f, 9.03f, 255.2f),
				new Vector3(-11.6f, 4.78f, 276.93f),
				new Vector3(61.3f, 4.46f, 192.4f),
				new Vector3(3.04f, -0.744f, 200.03f),
				new Vector3(-15.39f, -0.37f, 146.63f),
				new Vector3(40.2f, -4.43f, 208.093f),
				new Vector3(77.34f, 4.465f, 136.96f)
			}
		} };

		public static readonly Dictionary<string, List<Vector3>> SupplyDropLocations = new Dictionary<string, List<Vector3>> { 
		{
			"Monsoon",
			new List<Vector3>
			{
				new Vector3(92.48f, -5.45f, 138.99f),
				new Vector3(-18.96f, -0.29f, 208.71f),
				new Vector3(90.05f, 4.465f, 162.2f),
				new Vector3(97.65f, 10.52f, 290.009f),
				new Vector3(121.197f, 0.182f, 232.48f),
				new Vector3(-6.46f, 11.67f, 287.92f)
			}
		} };

		public static readonly Dictionary<string, List<string>> ObjectsToDeactivate = new Dictionary<string, List<string>> { 
		{
			"Monsoon",
			new List<string> { "JesusBeam", "Tree Behavior UNPC", "Tree_Behavior_CityCheck", "Tree Behavior Teleport", "Tree_Behavior_Council", "CharactersToDesactivate", "Allies", "DialogueAutomaticGuards", "AutomaticDialogueInn", "AreaSwitchToMarsh" }
		} };

		public static readonly Dictionary<string, List<string>> ObjectsToActivate = new Dictionary<string, List<string>> { 
		{
			"Monsoon",
			new List<string> { "WarzoneMonsoon", "Ennemies" }
		} };

		public static readonly List<int> Skills_Low = new List<int>
		{
			8100090, 8100140, 8100130, 8100071, 8100101, 8100121, 8100260, 8100360, 8205350, 8205000,
			8205120, 8205050, 8205080, 8205150, 8205210
		};

		public static readonly List<int> Skills_High = new List<int>
		{
			8100020, 8100370, 8100350, 8100280, 8100200, 8200310, 8200030, 8200031, 8200032, 8200100,
			8200101, 8200102, 8200103, 8205320, 8205330
		};

		public static readonly List<int> Weapons_Low = new List<int> { 2000061, 2000110, 2000151, 2000120, 2010020, 2010040, 2010041, 2010080, 2020030 };

		public static readonly List<int> Weapons_Med = new List<int>
		{
			2000021, 2000031, 2020060, 2020110, 2020020, 2100000, 2100110, 2130000, 2130022, 2120000,
			2120030, 2140070, 2200010, 2200040
		};

		public static readonly List<int> Weapons_High = new List<int>
		{
			2000150, 2000170, 2010070, 2010130, 2010140, 2020140, 2020160, 2100100, 2100160, 2110100,
			2110110, 2120070, 2130021, 2130160, 2140120, 2140130, 2200030, 2200040, 2200020
		};

		public static readonly List<int> Offhands_Low = new List<int> { 2300120, 2300070, 2300210, 2300050 };

		public static readonly List<int> Offhands_High = new List<int> { 5110100, 5110110, 5110002, 5110004, 2300171, 2300160, 2300091, 2300220, 5100090 };

		public static readonly List<int> Armor_Low = new List<int>
		{
			3000010, 3000011, 3000012, 3000020, 3000021, 3000022, 3000030, 3000031, 3000034, 3000180,
			3000181, 3000182, 3000183, 3000184, 3000103, 3000250
		};

		public static readonly List<int> Armor_High = new List<int>
		{
			3000061, 3100120, 3100201, 3100202, 3100200, 3000103, 3000252, 3000302, 3000303, 3100010,
			3100012, 3100013, 3100040, 3100041, 3100042, 3100080, 3100081, 3100082, 3100090, 3100091,
			3100092, 3100150, 3100151, 3100152, 3100170, 3100171, 3100172
		};

		public static readonly List<int> Supplies_Low = new List<int>
		{
			4300010, 4300010, 4300010, 4300010, 4300010, 4300010, 4300010, 4300060, 4300060, 4300060,
			4300020, 4300020, 4300030, 4300030, 4300050, 4300070, 4300080, 4300100, 4300120
		};

		public static readonly List<int> Supplies_High = new List<int>
		{
			4300240, 4300240, 4300240, 4300260, 4300260, 4300260, 4300250, 4300250, 4300250, 4400070,
			4400060, 4400051, 4400041, 4400031
		};
	}

	public static readonly List<int> StarterSkills = new List<int> { 8100010, 8200040, 8100072, 8200600, 8100120, 8100190 };

	public static readonly Dictionary<int, int> Weapon_Skills = new Dictionary<int, int>
	{
		{ 0, 8100290 },
		{ 1, 8100380 },
		{ 2, 8100270 },
		{ 50, 8100320 },
		{ 51, 8100362 },
		{ 52, 8100300 },
		{ 53, 8100310 },
		{ 54, 8100340 }
	};
}