Decompiled source of Refightilization v1.2.0

Refightilization.dll

Decompiled 5 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using On.RoR2;
using R2API.Utils;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using RoR2.Navigation;
using SimpleJSON;
using UnityEngine;
using UnityEngine.Networking;
using VarianceAPI;
using VarianceAPI.Components;
using VarianceAPI.ScriptableObjects;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("Refightilization")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Refightilization")]
[assembly: AssemblyTitle("Refightilization")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Wonda;

[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.Wonda.Refightilization", "Refightilization", "1.2.0")]
public class Refightilization : BaseUnityPlugin
{
	public class PlayerStorage
	{
		public NetworkUser user;

		public CharacterMaster master;

		public GameObject origPrefab;

		public bool isDead;

		public Inventory inventory;

		public bool giftedAffix;

		public bool hadAncientScepter;

		public EquipmentIndex previousEquipment = (EquipmentIndex)(-1);

		public NetworkUser lastDamagedBy;

		public float lastDamagedTime;

		public bool isLoggedOut;

		public int lastStage;
	}

	private const string guid = "com.Wonda.Refightilization";

	private const string modName = "Refightilization";

	private const string version = "1.2.0";

	private RefightilizationConfig _config;

	private RefightilizationLanguage _language;

	private PluginInfo _varianceAPI;

	private PluginInfo _classicItems;

	private PluginInfo _standaloneAncientScepter;

	public List<PlayerStorage> playerStorage = new List<PlayerStorage>();

	private List<GameObject> voidWhitelist = new List<GameObject>();

	private List<GameObject> finalBossWhitelist = new List<GameObject>();

	private List<string> respawnMethodCheck = new List<string> { "RefightRespawn" };

	public float respawnTime;

	private int respawnLoops;

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

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

	public List<EquipmentIndex> currEliteWhitelist = new List<EquipmentIndex>();

	public bool moonDisabled;

	public void Awake()
	{
		_config = new RefightilizationConfig(((BaseUnityPlugin)this).Config);
		SetupHooks();
		respawnMethodCheck.AddRange(_config.PreventPrefabResetMethods);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded Refightilization!");
	}

	public void Start()
	{
		if (Chainloader.PluginInfos.TryGetValue("com.Nebby.VarianceAPI", out var value))
		{
			_varianceAPI = value;
		}
		if (Chainloader.PluginInfos.TryGetValue("com.ThinkInvisible.ClassicItems", out var value2))
		{
			_classicItems = value2;
		}
		if (Chainloader.PluginInfos.TryGetValue("com.DestroyedClone.AncientScepter", out var value3))
		{
			_standaloneAncientScepter = value3;
		}
		if (Chainloader.PluginInfos.TryGetValue("com.rune580.riskofoptions", out var _))
		{
			_config.BuildRiskOfOptionsMenu();
		}
	}

	private void SetupHooks()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Expected O, but got Unknown
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Expected O, but got Unknown
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Expected O, but got Unknown
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Expected O, but got Unknown
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Expected O, but got Unknown
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Expected O, but got Unknown
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Expected O, but got Unknown
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Expected O, but got Unknown
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Expected O, but got Unknown
		Run.Start += new hook_Start(Run_Start);
		GlobalEventManager.OnPlayerCharacterDeath += new hook_OnPlayerCharacterDeath(GlobalEventManager_OnPlayerCharacterDeath);
		GlobalEventManager.onServerDamageDealt += GlobalEventManager_onServerDamageDealt;
		Run.OnServerSceneChanged += new hook_OnServerSceneChanged(Run_OnServerSceneChanged);
		Run.OnUserAdded += new hook_OnUserAdded(Run_OnUserAdded);
		Run.OnUserRemoved += new hook_OnUserRemoved(Run_OnUserRemoved);
		TeleporterInteraction.OnInteractionBegin += new hook_OnInteractionBegin(TeleporterInteraction_OnInteractionBegin);
		GenericPickupController.AttemptGrant += new hook_AttemptGrant(GenericPickupController_AttemptGrant);
		CharacterMaster.Respawn += new hook_Respawn(CharacterMaster_Respawn);
		CharacterMaster.PickRandomSurvivorBodyPrefab += new hook_PickRandomSurvivorBodyPrefab(CharacterMaster_PickRandomSurvivorBodyPrefab);
		Run.BeginGameOver += new hook_BeginGameOver(Run_BeginGameOver);
		InfiniteTowerRun.OnWaveAllEnemiesDefeatedServer += new hook_OnWaveAllEnemiesDefeatedServer(InfiniteTowerRun_OnWaveAllEnemiesDefeatedServer);
	}

	private void Run_Start(orig_Start orig, Run self)
	{
		orig.Invoke(self);
		if (_config.EnableRefightilization)
		{
			respawnTime = _config.RespawnDelay;
			SetupPlayers();
			SetupLang();
			moonDisabled = false;
		}
	}

	private void GlobalEventManager_OnPlayerCharacterDeath(orig_OnPlayerCharacterDeath orig, GlobalEventManager self, DamageReport damageReport, NetworkUser victimNetworkUser)
	{
		//IL_0187: 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_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Expected O, but got Unknown
		if (_config.EnableRefightilization)
		{
			RemoveMonsterVariantItems(victimNetworkUser.master);
		}
		orig.Invoke(self, damageReport, victimNetworkUser);
		if (!_config.EnableRefightilization)
		{
			return;
		}
		if (_config.MurderRevive)
		{
			PlayerStorage playerStorage = FindPlayerStorage(victimNetworkUser.master);
			PlayerStorage playerStorage2 = null;
			if (playerStorage != null && (Object)(object)playerStorage.lastDamagedBy != (Object)null && FindPlayerStorage(playerStorage.lastDamagedBy.master) != null)
			{
				playerStorage2 = FindPlayerStorage(playerStorage.lastDamagedBy.master);
			}
			if (playerStorage != null && !playerStorage.isDead && playerStorage2 != null && playerStorage2.isDead && Time.time <= playerStorage.lastDamagedTime + _config.MurderWindow)
			{
				CleanPlayer(playerStorage2);
				playerStorage2.master.RespawnExtraLife();
				playerStorage2.master.inventory.RemoveItem(Items.ExtraLifeConsumed, 1);
				string text = _language.RevengeMessages[Random.Range(0, _language.RevengeMessages.Count - 1)];
				text = text.Replace("{0}", playerStorage2.master.playerCharacterMasterController.networkUser.userName);
				text = text.Replace("{1}", playerStorage.master.playerCharacterMasterController.networkUser.userName);
				Chat.SendBroadcastChat((ChatMessageBase)new SimpleChatMessage
				{
					baseToken = "<style=cWorldEvent><sprite name=\"Skull\" tint=1> " + text + " <sprite name=\"Skull\" tint=1></style>"
				});
			}
		}
		((MonoBehaviour)this).StartCoroutine(RespawnCheck(((Component)victimNetworkUser.master).transform.position, respawnTime));
		respawnTime += _config.AdditionalRespawnTime;
	}

	private void GlobalEventManager_onServerDamageDealt(DamageReport report)
	{
		if ((_config.EnableRefightilization || _config.MurderRevive) && FindPlayerStorage(report.attackerMaster) != null && FindPlayerStorage(report.victimMaster) != null)
		{
			PlayerStorage obj = FindPlayerStorage(report.victimMaster);
			obj.lastDamagedBy = FindPlayerStorage(report.attackerMaster).user;
			obj.lastDamagedTime = Time.time;
		}
	}

	private void Run_OnServerSceneChanged(orig_OnServerSceneChanged orig, Run self, string sceneName)
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		if (_config.EnableRefightilization)
		{
			((MonoBehaviour)this).StopCoroutine(RespawnCheck());
		}
		orig.Invoke(self, sceneName);
		if (_config.EnableRefightilization)
		{
			if (sceneName.Equals("moon") || sceneName.Equals("moon2"))
			{
				moonDisabled = true;
			}
			if (self.stageClearCount > 0)
			{
				ResetPrefabs();
			}
			((MonoBehaviour)this).Invoke("UpdateStageWhitelist", 1f);
			((MonoBehaviour)this).Invoke("UpdateEliteWhitelist", 1f);
			respawnTime = _config.RespawnDelay;
		}
	}

	private void Run_OnUserAdded(orig_OnUserAdded orig, Run self, NetworkUser user)
	{
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		orig.Invoke(self, user);
		if (!(Run.instance.time > 1f) || !_config.EnableRefightilization)
		{
			return;
		}
		bool flag = false;
		foreach (PlayerStorage item in playerStorage)
		{
			if (item.user.userName == user.userName)
			{
				item.user = user;
				item.master = user.master;
				item.isLoggedOut = false;
				flag = true;
				((BaseUnityPlugin)this).Logger.LogInfo((object)(user.userName + " returned. Marking them as logged in."));
				if (item.lastStage < Run.instance.stageClearCount && Object.op_Implicit((Object)(object)user.master) && Object.op_Implicit((Object)(object)Stage.instance))
				{
					((MonoBehaviour)this).Invoke("NaturalRespawnCharacter", 3f);
				}
				else
				{
					item.isDead = true;
					((MonoBehaviour)this).StartCoroutine(RespawnCheck(((Component)item.master).transform.position, 3f));
				}
				item.master.inventory.CopyItemsFrom(item.inventory);
				break;
			}
		}
		if (!flag)
		{
			SetupPlayers(StageUpdate: false);
		}
	}

	private void NaturalRespawnCharacter()
	{
		foreach (PlayerStorage item in playerStorage)
		{
			if (!item.isDead && !item.isLoggedOut && !Object.op_Implicit((Object)(object)item.master.GetBody()))
			{
				Stage.instance.RespawnCharacter(item.master);
			}
		}
	}

	private void Run_OnUserRemoved(orig_OnUserRemoved orig, Run self, NetworkUser user)
	{
		if (Run.instance.time > 1f && _config.EnableRefightilization)
		{
			foreach (PlayerStorage item in playerStorage)
			{
				if (item.user.userName == user.userName)
				{
					CleanPlayer(item);
					item.inventory.CopyItemsFrom(user.master.inventory);
					break;
				}
			}
		}
		orig.Invoke(self, user);
		if (!(Run.instance.time > 1f) || !_config.EnableRefightilization)
		{
			return;
		}
		foreach (PlayerStorage item2 in playerStorage)
		{
			if (item2.user.userName == user.userName)
			{
				item2.isLoggedOut = true;
				item2.lastStage = Run.instance.stageClearCount;
				((BaseUnityPlugin)this).Logger.LogInfo((object)(user.userName + " left. Marking them as logged out."));
				break;
			}
		}
	}

	private void TeleporterInteraction_OnInteractionBegin(orig_OnInteractionBegin orig, TeleporterInteraction self, Interactor activator)
	{
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Invalid comparison between Unknown and I4
		if (_config.EnableRefightilization)
		{
			foreach (PlayerStorage item in playerStorage)
			{
				if (self.isCharged)
				{
					RemoveMonsterVariantItems(item.master);
				}
				if (self.isCharged)
				{
					((MonoBehaviour)this).StopCoroutine(RespawnCheck());
				}
				if ((Object)(object)item.master != (Object)null && (Object)(object)item.master.GetBody() != (Object)null && (Object)(object)((Component)item.master.GetBody()).gameObject == (Object)(object)((Component)activator).gameObject && item.isDead && (int)item.master.teamIndex != 1 && playerStorage.Count > 1)
				{
					return;
				}
			}
		}
		orig.Invoke(self, activator);
	}

	private void GenericPickupController_AttemptGrant(orig_AttemptGrant orig, GenericPickupController self, CharacterBody body)
	{
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		if (_config.EnableRefightilization)
		{
			foreach (PlayerStorage item in playerStorage)
			{
				if (Object.op_Implicit((Object)(object)item.master.GetBody()) && (Object)(object)((Component)item.master.GetBody()).gameObject == (Object)(object)((Component)body).gameObject && item.isDead && _config.ItemPickupToggle)
				{
					item.master.GetBody().teamComponent.teamIndex = (TeamIndex)1;
				}
			}
			orig.Invoke(self, body);
			{
				foreach (PlayerStorage item2 in playerStorage)
				{
					if (Object.op_Implicit((Object)(object)item2.master.GetBody()) && (Object)(object)((Component)item2.master.GetBody()).gameObject == (Object)(object)((Component)body).gameObject && item2.isDead && _config.ItemPickupToggle)
					{
						item2.master.GetBody().teamComponent.teamIndex = _config.RespawnTeam;
					}
				}
				return;
			}
		}
		orig.Invoke(self, body);
	}

	private CharacterBody CharacterMaster_Respawn(orig_Respawn orig, CharacterMaster self, Vector3 footPosition, Quaternion rotation)
	{
		//IL_005a: 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)
		if (_config.EnableRefightilization)
		{
			string currMethod = new StackFrame(2).GetMethod().Name;
			if (!respawnMethodCheck.Exists((string x) => x.Equals(currMethod)) && FindPlayerStorage(self) != null)
			{
				CleanPlayer(FindPlayerStorage(self));
			}
		}
		return orig.Invoke(self, footPosition, rotation);
	}

	private GameObject CharacterMaster_PickRandomSurvivorBodyPrefab(orig_PickRandomSurvivorBodyPrefab orig, Xoroshiro128Plus rng, NetworkUser networkUser, bool allowHidden)
	{
		if (_config.EnableRefightilization && _config.OverrideMetamorphosis && new StackFrame(6).GetMethod().Name == "RefightRespawn")
		{
			return currEnemyWhitelist[Random.Range(0, currEnemyWhitelist.Count - 1)];
		}
		return orig.Invoke(rng, networkUser, allowHidden);
	}

	private void Run_BeginGameOver(orig_BeginGameOver orig, Run self, GameEndingDef gameEndingDef)
	{
		//IL_001e: 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 (!_config.EnableRefightilization || _config.EndGameWhenEverybodyDead)
		{
			((MonoBehaviour)this).StopCoroutine(RespawnCheck());
			ResetPrefabs();
			orig.Invoke(self, gameEndingDef);
		}
	}

	private void InfiniteTowerRun_OnWaveAllEnemiesDefeatedServer(orig_OnWaveAllEnemiesDefeatedServer orig, InfiniteTowerRun self, InfiniteTowerWaveController wc)
	{
		foreach (PlayerStorage item in playerStorage)
		{
			if (item == null)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Player is null! Continuing.");
			}
			else if (item.isDead)
			{
				item.master.TrueKill();
			}
		}
		orig.Invoke(self, wc);
	}

	private void SetupLang()
	{
		_language = new RefightilizationLanguage();
	}

	private void SetupPlayers(bool StageUpdate = true)
	{
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Expected O, but got Unknown
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Setting up players...");
		if (StageUpdate)
		{
			this.playerStorage.Clear();
		}
		foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
		{
			if (this.playerStorage != null && (Object)(object)instance.networkUser == (Object)null)
			{
				continue;
			}
			if (!StageUpdate && this.playerStorage != null)
			{
				bool flag = false;
				foreach (PlayerStorage item in this.playerStorage)
				{
					if ((Object)(object)item.master == (Object)(object)instance.master)
					{
						flag = true;
						break;
					}
				}
				if (flag)
				{
					continue;
				}
			}
			PlayerStorage playerStorage = new PlayerStorage();
			if (Object.op_Implicit((Object)(object)instance.networkUser))
			{
				playerStorage.user = instance.networkUser;
			}
			if (Object.op_Implicit((Object)(object)instance.master))
			{
				playerStorage.master = instance.master;
			}
			if (Object.op_Implicit((Object)(object)instance.master.bodyPrefab))
			{
				playerStorage.origPrefab = instance.master.bodyPrefab;
			}
			if (Object.op_Implicit((Object)(object)instance.master.inventory))
			{
				playerStorage.inventory = new Inventory();
			}
			this.playerStorage.Add(playerStorage);
			((BaseUnityPlugin)this).Logger.LogInfo((object)(playerStorage.user.userName + " added to PlayerStorage!"));
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Setting up players finished.");
		if (!StageUpdate)
		{
			((MonoBehaviour)this).StartCoroutine(RespawnCheck(new Vector3(0f, 0f, 0f), respawnTime));
		}
	}

	private IEnumerator RespawnCheck(Vector3 deathPos = default(Vector3), float waitTime = 1f)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogInfo((object)("Respawn called! Waiting " + waitTime + " seconds!"));
		yield return (object)new WaitForSeconds(waitTime);
		if (!Object.op_Implicit((Object)(object)Run.instance) || !((Behaviour)Run.instance).isActiveAndEnabled)
		{
			yield break;
		}
		if (!_config.EnableRefightilization)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Nevermind. Mod is disabled via config.");
			yield break;
		}
		if (_config.NoRespawnsAfterTeleporter && Object.op_Implicit((Object)(object)TeleporterInteraction.instance) && TeleporterInteraction.instance.isCharged)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Respawning after teleporter is disabled!");
			yield break;
		}
		if (_config.DisableMoon && moonDisabled)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Respawn prevented due to current stage.");
			yield break;
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Checking players...");
		bool flag = true;
		if (playerStorage == null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"PlayerStorage is null!");
			yield break;
		}
		foreach (PlayerStorage item in playerStorage)
		{
			if (item == null)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Player doesn't exist! Skipping...");
				playerStorage.Remove(item);
				RespawnCheck(deathPos, waitTime);
				yield break;
			}
			if (item.master.IsDeadAndOutOfLivesServer() && !item.isLoggedOut)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)(item.user.userName + " passed spawn check!"));
				if (item.master.preventGameOver)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)("...except " + item.user.userName + " is preventing a game over, so we'll check again in a few seconds."));
					flag = false;
					((MonoBehaviour)this).StartCoroutine(RespawnCheck(new Vector3(0f, 0f, 0f), (waitTime + 1f) * 2f));
					continue;
				}
				if (!item.isDead)
				{
					item.isDead = true;
					item.inventory.CopyItemsFrom(item.master.inventory);
				}
				item.master.teamIndex = _config.RespawnTeam;
				respawnLoops = 0;
				RefightRespawn(item.master, deathPos);
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)(item.user.userName + " failed spawn check."));
				if (!item.isDead)
				{
					flag = false;
				}
			}
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Checking players complete.");
		if (flag && (!((Object)(object)TeleporterInteraction.instance != (Object)null) || !TeleporterInteraction.instance.isInFinalSequence) && _config.EndGameWhenEverybodyDead)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Everybody is dead. Forcibly ending the game.");
			ResetPrefabs();
			Run.instance.BeginGameOver(GameEndings.StandardLoss);
		}
	}

	private void RefightRespawn(CharacterMaster player, Vector3 deathPos)
	{
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0274: Unknown result type (might be due to invalid IL or missing references)
		//IL_027b: Unknown result type (might be due to invalid IL or missing references)
		//IL_027c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0336: Unknown result type (might be due to invalid IL or missing references)
		//IL_0337: Unknown result type (might be due to invalid IL or missing references)
		//IL_0310: Unknown result type (might be due to invalid IL or missing references)
		//IL_0315: Unknown result type (might be due to invalid IL or missing references)
		//IL_0317: Unknown result type (might be due to invalid IL or missing references)
		//IL_031c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0369: Unknown result type (might be due to invalid IL or missing references)
		//IL_036a: Unknown result type (might be due to invalid IL or missing references)
		//IL_036f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0355: Unknown result type (might be due to invalid IL or missing references)
		//IL_035a: Unknown result type (might be due to invalid IL or missing references)
		//IL_035c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0361: Unknown result type (might be due to invalid IL or missing references)
		//IL_0507: Unknown result type (might be due to invalid IL or missing references)
		//IL_050c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0510: Unknown result type (might be due to invalid IL or missing references)
		//IL_052a: Unknown result type (might be due to invalid IL or missing references)
		//IL_052f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0534: Unknown result type (might be due to invalid IL or missing references)
		//IL_0536: Unknown result type (might be due to invalid IL or missing references)
		//IL_053d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0549: Unknown result type (might be due to invalid IL or missing references)
		//IL_075a: Unknown result type (might be due to invalid IL or missing references)
		//IL_075f: Unknown result type (might be due to invalid IL or missing references)
		//IL_077b: Expected O, but got Unknown
		//IL_0636: Unknown result type (might be due to invalid IL or missing references)
		//IL_063c: Invalid comparison between Unknown and I4
		//IL_06a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0670: Unknown result type (might be due to invalid IL or missing references)
		//IL_0675: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Attempting player respawn!");
		respawnLoops++;
		if (respawnLoops > 99)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"INFINITE LOOP CAUGHT! Please file a bug report for Refightilization! This is not intended behavior.");
			return;
		}
		if ((Object)(object)player == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Player is null!? Aborting Respawn.");
			return;
		}
		if ((Object)(object)player.playerCharacterMasterController.networkUser == (Object)null)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Player doesn't have a networkUser!? Aborting Respawn.");
			return;
		}
		if (FindPlayerStorage(player).giftedAffix)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Yoinking that Affix.");
			player.inventory.SetEquipmentIndex(FindPlayerStorage(player).previousEquipment);
			FindPlayerStorage(player).giftedAffix = false;
		}
		List<GameObject> list = currEnemyWhitelist;
		if (Util.CheckRoll(5f, player.playerCharacterMasterController.master) && currSpecialEnemyWhitelist.Count >= 1)
		{
			list = new List<GameObject>(currSpecialEnemyWhitelist);
		}
		if (Util.CheckRoll(0.1f, player.playerCharacterMasterController.master) && finalBossWhitelist.Count >= 1)
		{
			list = new List<GameObject>(finalBossWhitelist);
		}
		if (_config.NoRepeatRespawns && list.Count > 1)
		{
			list.Remove(list.Where((GameObject entity) => ((Object)entity).name == ((Object)player.bodyPrefab).name).FirstOrDefault());
		}
		GameObject val = list[Random.Range(0, list.Count - 1)];
		((BaseUnityPlugin)this).Logger.LogInfo((object)("Found body " + ((Object)val).name + "."));
		TakeScepter(player);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Checked for Ancient Scepter.");
		if (Object.op_Implicit((Object)(object)player.bodyPrefab) && Object.op_Implicit((Object)(object)val))
		{
			player.bodyPrefab = val;
			((BaseUnityPlugin)this).Logger.LogInfo((object)(player.playerCharacterMasterController.networkUser.userName + " was assigned to " + ((Object)player.bodyPrefab).name + "."));
			Vector3 val2 = deathPos;
			Vector3 val3 = default(Vector3);
			((Vector3)(ref val3))..ctor((float)Random.Range(-5, 5), (float)Random.Range(-5, 5), (float)Random.Range(-2, 2));
			Random r = new Random();
			foreach (PlayerCharacterMasterController item in PlayerCharacterMasterController.instances.OrderBy((PlayerCharacterMasterController x) => r.Next()))
			{
				if (!item.master.IsDeadAndOutOfLivesServer() && (Object)(object)item.master != (Object)null)
				{
					val2 = ((Component)item.master).transform.position + val3;
					break;
				}
			}
			if (val2 == deathPos && Object.op_Implicit((Object)(object)TeleporterInteraction.instance))
			{
				val2 = ((Component)TeleporterInteraction.instance).transform.position + val3;
			}
			player.Respawn(GrabNearestNodePosition(val2), Quaternion.identity);
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Respawned " + player.playerCharacterMasterController.networkUser.userName + "!"));
			if (!_config.RespawnAsMonsterVariants)
			{
				RemoveMonsterVariantItems(player);
			}
			CharacterBody body = player.GetBody();
			body.baseMaxHealth *= _config.RespawnHealthMultiplier;
			CharacterBody body2 = player.GetBody();
			body2.baseDamage *= _config.RespawnDamageMultiplier;
			if (Object.op_Implicit((Object)(object)((Component)player.GetBody()).GetComponent<DeathRewards>()))
			{
				DeathRewards component = ((Component)player.GetBody()).GetComponent<DeathRewards>();
				component.goldReward *= (uint)_config.RespawnMoneyMultiplier;
			}
			player.GetBody().baseRegen = 1f;
			player.GetBody().levelRegen = 0.2f;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Applied stats.");
			if (!Object.op_Implicit((Object)(object)((Component)player.GetBody()).GetComponent<InteractionDriver>()))
			{
				((Component)player.GetBody()).gameObject.AddComponent<InteractionDriver>();
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Granting an interaction driver.");
			}
			if (Object.op_Implicit((Object)(object)((Component)player.GetBody()).GetComponent<Interactor>()))
			{
				Interactor component2 = ((Component)player.GetBody()).GetComponent<Interactor>();
				Bounds bounds = ((Renderer)((Component)player.GetBody().modelLocator.modelTransform).GetComponent<CharacterModel>().mainSkinnedMeshRenderer).bounds;
				Vector3 val4 = Vector3.Scale(((Bounds)(ref bounds)).size, ((Component)player.GetBody().modelLocator).transform.localScale);
				float maxInteractionDistance = Mathf.Max(Mathf.Max(val4.x, val4.y), val4.z);
				component2.maxInteractionDistance = maxInteractionDistance;
				if (player.GetBody().isFlying)
				{
					component2.maxInteractionDistance *= 1.5f;
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Modifying interaction distance.");
			}
			ChangeMinionsTeam(player);
			player.GetBody().AddTimedBuff(Buffs.ArmorBoost, 15f);
			player.GetBody().AddTimedBuff(Buffs.CloakSpeed, 30f);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Applied buffs.");
			if (_config.RespawnAffixEnabled && (Util.CheckRoll(_config.RespawnAffixChance, player.playerCharacterMasterController.master) || RunArtifactManager.instance.IsArtifactEnabled(Artifacts.eliteOnlyArtifactDef)))
			{
				if ((int)player.inventory.GetEquipmentIndex() != -1 && !_config.ForceGrantAffix)
				{
					return;
				}
				if (_config.ForceGrantAffix)
				{
					FindPlayerStorage(player).previousEquipment = player.inventory.GetEquipmentIndex();
				}
				int index = Random.Range(0, currEliteWhitelist.Count - 1);
				player.inventory.SetEquipmentIndex(currEliteWhitelist[index]);
				FindPlayerStorage(player).giftedAffix = _config.TakeAffix;
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Gifted affix.");
			}
			respawnLoops = 0;
			if (_config.AnnounceRespawns)
			{
				string text = _language.ReviveMessages[Random.Range(0, _language.ReviveMessages.Count - 1)];
				text = text.Replace("{0}", player.playerCharacterMasterController.networkUser.userName);
				text = text.Replace("{1}", player.GetBody().GetDisplayName());
				Chat.SendBroadcastChat((ChatMessageBase)new SimpleChatMessage
				{
					baseToken = "<style=cWorldEvent><sprite name=\"Skull\" tint=1> " + text + " <sprite name=\"Skull\" tint=1></style>"
				});
			}
		}
		else
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)(player.playerCharacterMasterController.networkUser.userName + " has no bodyPrefab!? Retrying..."));
			RefightRespawn(player, deathPos);
		}
	}

	private void ResetPrefabs()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Resetting player prefabs...");
		if (playerStorage == null)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)"PlayerStorage is null!");
			return;
		}
		foreach (PlayerStorage item in playerStorage)
		{
			if (item == null)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Player is null! Continuing.");
				continue;
			}
			if (item.isDead)
			{
				CleanPlayer(item);
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)(item.user.userName + "'s prefab reset."));
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Reset player prefabs!");
	}

	private void CleanPlayer(PlayerStorage player)
	{
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		player.master.bodyPrefab = player.origPrefab;
		player.master.teamIndex = (TeamIndex)1;
		ChangeMinionsTeam(player.master);
		if (player.giftedAffix)
		{
			player.master.inventory.SetEquipmentIndex(player.previousEquipment);
			player.giftedAffix = false;
		}
		RemoveMonsterVariantItems(player.master);
		((MonoBehaviour)this).StartCoroutine(GiveScepterWait(player.master, 1f));
		player.isDead = false;
	}

	private void ChangeMinionsTeam(CharacterMaster player)
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
		if (!_config.ChangeMinionsTeam)
		{
			return;
		}
		MinionGroup val = null;
		for (int i = 0; i < MinionGroup.instancesList.Count; i++)
		{
			MinionGroup val2 = MinionGroup.instancesList[i];
			if (MinionGroup.instancesList[i].ownerId == ((NetworkBehaviour)player).netId)
			{
				val = val2;
				break;
			}
		}
		if (val == null)
		{
			return;
		}
		MinionOwnership[] members = val.members;
		foreach (MinionOwnership val3 in members)
		{
			if (Object.op_Implicit((Object)(object)val3) && Object.op_Implicit((Object)(object)((Component)val3).GetComponent<CharacterMaster>()))
			{
				((Component)val3).GetComponent<CharacterMaster>().teamIndex = player.teamIndex;
				if (Object.op_Implicit((Object)(object)((Component)val3).GetComponent<CharacterMaster>().GetBody()))
				{
					((Component)val3).GetComponent<CharacterMaster>().GetBody().teamComponent.teamIndex = player.teamIndex;
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Changed " + ((Object)((Component)val3).GetComponent<CharacterMaster>()).name + "'s team."));
			}
		}
	}

	private void UpdateStageWhitelist()
	{
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Updating the stage whitelist.");
		currEnemyWhitelist.Clear();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Whitelist cleared.");
		if (_config.EnableFixedPool)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Fixed pool is enabled.");
			string[] fixedPool = _config.FixedPool;
			foreach (string text in fixedPool)
			{
				currEnemyWhitelist.Add(BodyCatalog.FindBodyPrefab(text));
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Adding " + text + " to the currWhitelist."));
			}
		}
		else if ((Object)(object)ClassicStageInfo.instance == (Object)null || ClassicStageInfo.instance.monsterSelection == null || ClassicStageInfo.instance.monsterSelection.choices == null)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"There is no available monster selection!");
			if (Object.op_Implicit((Object)(object)VoidRaidGauntletController.instance))
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Void raid detected! Forcing monster selection...");
				currEnemyWhitelist.Add(BodyCatalog.FindBodyPrefab("NullifierBody"));
				currEnemyWhitelist.Add(BodyCatalog.FindBodyPrefab("VoidJailerBody"));
				currEnemyWhitelist.Add(BodyCatalog.FindBodyPrefab("VoidMegaCrabBody"));
			}
		}
		else
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Selection isn't null.");
			foreach (ChoiceInfo<DirectorCard> item in ClassicStageInfo.instance.monsterSelection.choices.ToList())
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Testing choice.");
				if (item.value == null)
				{
					continue;
				}
				SpawnCard spawnCard = item.value.spawnCard;
				if ((Object)(object)spawnCard == (Object)null)
				{
					continue;
				}
				GameObject val = BodyCatalog.FindBodyPrefab(((Object)spawnCard.prefab).name.Replace("Master", "Body"));
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)("We have found " + ((Object)val).name + "."));
				if ((!_config.AllowBosses || Run.instance.loopClearCount < _config.BossRequiredLoopCount) && val.GetComponent<CharacterBody>().isChampion)
				{
					if (_config.AllowBosses)
					{
						currSpecialEnemyWhitelist.Add(val);
					}
				}
				else if (((_config.AllowScavengers && Run.instance.loopClearCount >= _config.ScavangerRequiredLoopCount) || !(((Object)val).name == "ScavengerBody")) && !CheckBlacklist(((Object)val).name))
				{
					currEnemyWhitelist.Add(val);
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Adding " + ((Object)val).name + " to the currWhitelist."));
				}
			}
		}
		finalBossWhitelist.Add(BodyCatalog.FindBodyPrefab("BrotherBody"));
		finalBossWhitelist.Add(BodyCatalog.FindBodyPrefab("MiniVoidRaidCrabBodyBase"));
		if (currEnemyWhitelist.Count <= 0)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"No enemies were found, pulling out the backup enemies.");
			string[] fixedPool = _config.FixedPool;
			foreach (string text2 in fixedPool)
			{
				currEnemyWhitelist.Add(BodyCatalog.FindBodyPrefab(text2));
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Adding " + text2 + " to the currWhitelist."));
			}
			if (currEnemyWhitelist.Count <= 0)
			{
				currEnemyWhitelist.Add(BodyCatalog.FindBodyPrefab("LemurianBody"));
			}
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Done updating Whitelist.");
	}

	private void UpdateEliteWhitelist()
	{
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Updating the Elite whitelist.");
		if (CombatDirector.instancesList == null && (Object)(object)CombatDirector.instancesList[0] == (Object)null)
		{
			return;
		}
		currEliteWhitelist.Clear();
		EliteTierDef[] eliteTiers = CombatDirector.eliteTiers;
		if (eliteTiers == null || eliteTiers.Length == 0)
		{
			return;
		}
		for (int i = 0; i < eliteTiers.Length; i++)
		{
			if (!eliteTiers[i].isAvailable((EliteRules)0) && !eliteTiers[i].isAvailable((EliteRules)2))
			{
				continue;
			}
			for (int j = 0; j < eliteTiers[i].eliteTypes.Length; j++)
			{
				if (!((Object)(object)eliteTiers[i].eliteTypes[j] == (Object)null) && !((Object)(object)eliteTiers[i].eliteTypes[j].eliteEquipmentDef == (Object)null) && !((Object)(object)eliteTiers[i].eliteTypes[j].eliteEquipmentDef.pickupIconSprite == (Object)null))
				{
					currEliteWhitelist.Add(eliteTiers[i].eliteTypes[j].eliteEquipmentDef.equipmentIndex);
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Added " + eliteTiers[i].eliteTypes[j].eliteEquipmentDef.nameToken + " to the pool."));
				}
			}
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Done updating Whitelist.");
	}

	private Vector3 GrabNearestNodePosition(Vector3 startPos)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		NodeGraph groundNodes = SceneInfo.instance.groundNodes;
		NodeIndex val = groundNodes.FindClosestNode(startPos, (HullClassification)2, float.PositiveInfinity);
		NodeGraphSpider val2 = new NodeGraphSpider(groundNodes, (HullMask)4);
		val2.AddNodeForNextStep(val);
		List<StepInfo> list = new List<StepInfo>();
		int num = 0;
		List<StepInfo> collectedSteps = val2.collectedSteps;
		while (val2.PerformStep() && num < 8)
		{
			num++;
			for (int i = 0; i < collectedSteps.Count; i++)
			{
				list.Add(collectedSteps[i]);
			}
			collectedSteps.Clear();
		}
		Vector3 result = default(Vector3);
		groundNodes.GetNodePosition(list[Random.Range(0, list.Count - 1)].node, ref result);
		return result;
	}

	private bool CheckBlacklist(string name)
	{
		bool result = false;
		string[] blacklistedEnemies = _config.BlacklistedEnemies;
		foreach (string text in blacklistedEnemies)
		{
			if (name == text)
			{
				result = true;
				break;
			}
		}
		return result;
	}

	private PlayerStorage FindPlayerStorage(CharacterMaster cMaster)
	{
		foreach (PlayerStorage item in playerStorage)
		{
			if ((Object)(object)item.master == (Object)(object)cMaster)
			{
				return item;
			}
		}
		return null;
	}

	private void RemoveMonsterVariantItems(CharacterMaster player)
	{
		if (_varianceAPI != null)
		{
			RemoveMonsterVariantItemsAPI(player);
		}
	}

	private void RemoveMonsterVariantItemsAPI(CharacterMaster Player)
	{
		//IL_0081: 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_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		CharacterBody body = Player.GetBody();
		if (!Object.op_Implicit((Object)(object)body))
		{
			return;
		}
		VariantHandler component = ((Component)body).GetComponent<VariantHandler>();
		if (!Object.op_Implicit((Object)(object)component))
		{
			return;
		}
		foreach (VariantInfo item in component.VariantInfos.ToList())
		{
			if ((Object)(object)item.variantInventory == (Object)null)
			{
				CheckForPurpleHealthBar(body.inventory, item);
			}
			else if (item.variantInventory.ItemInventory.Length != 0)
			{
				VariantInventory[] itemInventory = item.variantInventory.ItemInventory;
				foreach (VariantInventory val in itemInventory)
				{
					ItemDef itemDef = ItemCatalog.GetItemDef(ItemCatalog.FindItemIndex(val.itemDefName));
					Player.inventory.RemoveItem(itemDef, val.amount);
				}
				CheckForPurpleHealthBar(body.inventory, item);
			}
		}
	}

	private void CheckForPurpleHealthBar(Inventory inventory, VariantInfo variantInfo)
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Invalid comparison between Unknown and I4
		ItemDef val = Assets.VAPIAssets.LoadAsset<ItemDef>("PurpleHealthbar");
		if ((int)variantInfo.variantTier >= 1)
		{
			inventory.RemoveItem(val, inventory.GetItemCount(val));
		}
	}

	private void TakeScepter(CharacterMaster player)
	{
		if (_classicItems != null)
		{
			TakeScepterCI(player);
		}
		if (_standaloneAncientScepter != null)
		{
			TakeScepterSAS(player);
		}
	}

	private IEnumerator GiveScepterWait(CharacterMaster player, float time)
	{
		yield return (object)new WaitForSeconds(time);
		GiveScepter(player);
	}

	private void GiveScepter(CharacterMaster player)
	{
		if (_classicItems != null)
		{
			GiveScepterCI(player);
		}
		if (_standaloneAncientScepter != null)
		{
			GiveScepterSAS(player);
		}
	}

	[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
	private void TakeScepterCI(CharacterMaster player)
	{
	}

	[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
	private void GiveScepterCI(CharacterMaster player)
	{
	}

	[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
	private void TakeScepterSAS(CharacterMaster player)
	{
	}

	[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
	private void GiveScepterSAS(CharacterMaster player)
	{
	}
}
internal class RefightilizationConfig
{
	private readonly ConfigEntry<bool> _enableRefightilization;

	private readonly ConfigEntry<bool> _allowBosses;

	private readonly ConfigEntry<bool> _allowScavengers;

	private readonly ConfigEntry<string> _blacklistedEnemies;

	private readonly ConfigEntry<int> _bossRequiredLoopCount;

	private readonly ConfigEntry<int> _scavangerRequiredLoopCount;

	private readonly ConfigEntry<bool> _enableFixedPool;

	private readonly ConfigEntry<string> _fixedPool;

	private readonly ConfigEntry<float> _respawnDelay;

	private readonly ConfigEntry<TeamIndex> _respawnTeam;

	private readonly ConfigEntry<float> _respawnHealthMultiplier;

	private readonly ConfigEntry<float> _respawnDamageMultiplier;

	private readonly ConfigEntry<float> _respawnMoneyMultiplier;

	private readonly ConfigEntry<bool> _respawnAffixEnabled;

	private readonly ConfigEntry<float> _respawnAffixChance;

	private readonly ConfigEntry<float> _additionalRespawnTime;

	private readonly ConfigEntry<bool> _respawnAsMonsterVariants;

	private readonly ConfigEntry<bool> _noRespawnsAfterTeleporter;

	private readonly ConfigEntry<bool> _noRepeatRespawns;

	private readonly ConfigEntry<bool> _itemPickupToggle;

	private readonly ConfigEntry<bool> _removeMonsterVariantItems;

	private readonly ConfigEntry<bool> _takeAffix;

	private readonly ConfigEntry<bool> _forceGrantAffix;

	private readonly ConfigEntry<bool> _murderRevive;

	private readonly ConfigEntry<float> _murderWindow;

	private readonly ConfigEntry<bool> _announceRespawns;

	private readonly ConfigEntry<bool> _disableMoon;

	private readonly ConfigEntry<bool> _overrideMetamorphosis;

	private readonly ConfigEntry<bool> _changeMinionsTeam;

	private readonly ConfigEntry<bool> _endGameWhenEverybodyDead;

	private readonly ConfigEntry<int> _maxRespawnTries;

	private readonly ConfigEntry<string> _preventPrefabResetMethods;

	public bool EnableRefightilization => _enableRefightilization.Value;

	public bool AllowBosses => _allowBosses.Value;

	public bool AllowScavengers => _allowScavengers.Value;

	public string[] BlacklistedEnemies => _blacklistedEnemies.Value.Replace(" ", "").Split(new char[1] { ',' });

	public int BossRequiredLoopCount => _bossRequiredLoopCount.Value;

	public int ScavangerRequiredLoopCount => _scavangerRequiredLoopCount.Value;

	public bool EnableFixedPool => _enableFixedPool.Value;

	public string[] FixedPool => _fixedPool.Value.Replace(" ", "").Split(new char[1] { ',' });

	public float RespawnDelay => _respawnDelay.Value;

	public TeamIndex RespawnTeam => _respawnTeam.Value;

	public float RespawnHealthMultiplier => _respawnHealthMultiplier.Value;

	public float RespawnDamageMultiplier => _respawnDamageMultiplier.Value;

	public float RespawnMoneyMultiplier => _respawnMoneyMultiplier.Value;

	public bool RespawnAffixEnabled => _respawnAffixEnabled.Value;

	public float RespawnAffixChance => _respawnAffixChance.Value;

	public float AdditionalRespawnTime => _additionalRespawnTime.Value;

	public bool RespawnAsMonsterVariants => _respawnAsMonsterVariants.Value;

	public bool NoRespawnsAfterTeleporter => _noRespawnsAfterTeleporter.Value;

	public bool NoRepeatRespawns => _noRepeatRespawns.Value;

	public bool ItemPickupToggle => _itemPickupToggle.Value;

	public bool RemoveMonsterVariantItems => _removeMonsterVariantItems.Value;

	public bool TakeAffix => _takeAffix.Value;

	public bool ForceGrantAffix => _forceGrantAffix.Value;

	public bool MurderRevive => _murderRevive.Value;

	public float MurderWindow => _murderWindow.Value;

	public bool AnnounceRespawns => _announceRespawns.Value;

	public bool DisableMoon => _disableMoon.Value;

	public bool OverrideMetamorphosis => _overrideMetamorphosis.Value;

	public bool ChangeMinionsTeam => _changeMinionsTeam.Value;

	public bool EndGameWhenEverybodyDead => _endGameWhenEverybodyDead.Value;

	public int MaxRespawnTries => _maxRespawnTries.Value;

	public string[] PreventPrefabResetMethods => _preventPrefabResetMethods.Value.Replace(" ", "").Split(new char[1] { ',' });

	public RefightilizationConfig(ConfigFile config)
	{
		_enableRefightilization = config.Bind<bool>("Master", "EnableRefightilization", true, "Enables/Disables the entire mod.");
		_allowBosses = config.Bind<bool>("Monster Categories", "AllowBosses", true, "Allows players to spawn as bosses.");
		_allowScavengers = config.Bind<bool>("Monster Categories", "AllowScavengers", false, "Allows players to spawn as Scavengers.");
		_blacklistedEnemies = config.Bind<string>("Monster Categories", "BlacklistedEnemies", "BeetleBody, JellyfishBody, WispBody, MinorConstructBody, VoidBarnacleBody, ClayBossBody", "Sets monsters to prevent players from spawning as. A list of bodies can be grabbed by using body_list in the console.");
		_bossRequiredLoopCount = config.Bind<int>("Monster Categories", "BossRequiredLoopCount", 2, "The required amount of loops before a player can spawn as a boss.");
		_scavangerRequiredLoopCount = config.Bind<int>("Monster Categories", "ScavangerRequiredLoopCount", 5, "The required amount of loops before a player can spawn as a scavanger.");
		_enableFixedPool = config.Bind<bool>("Monster Categories", "EnableFixedPool", false, "Forces players to respawn from a pre-defined list of monsters, instead of the current stage's monsters.");
		_fixedPool = config.Bind<string>("Monster Categories", "FixedPool", "LemurianBody", "Provides a fixed list of monsters that the player could spawn as with EnableFixedPool enabled. This list will also be used if there are no available monsters to spawn as.");
		_respawnDelay = config.Bind<float>("Respawn Settings", "RespawnDelay", 5f, "Sets the delay until the player can respawn.");
		_respawnTeam = config.Bind<TeamIndex>("Respawn Settings", "RespawnTeam", (TeamIndex)0, "Sets the team of the respawned players.");
		_respawnHealthMultiplier = config.Bind<float>("Respawn Settings", "RespawnHealthMultiplier", 1.1f, "Multiplies the health a player spawns with.");
		_respawnDamageMultiplier = config.Bind<float>("Respawn Settings", "RespawnDamageMultiplier", 5f, "Multiplies the damage a player spawns with.");
		_respawnMoneyMultiplier = config.Bind<float>("Respawn Settings", "RespawnMoneyMultiplier", 1.1f, "Multiplies the money rewarded for killing a player.");
		_respawnAffixEnabled = config.Bind<bool>("Respawn Settings", "RespawnAffixEnabled", true, "Allows players to spawn with affixes if they have an empty equipment slot.");
		_respawnAffixChance = config.Bind<float>("Respawn Settings", "RespawnAffixChance", 60f, "Sets the chance that a respawned player will have an affix.");
		_additionalRespawnTime = config.Bind<float>("Respawn Settings", "AdditionalRespawnTime", 0.2f, "Sets how much respawn time will increase per player death. This will effect everyone.");
		_noRespawnsAfterTeleporter = config.Bind<bool>("Respawn Settings", "NoRespawnsAfterTeleporter", true, "Disables respawning after the Teleporter event concludes.");
		_noRepeatRespawns = config.Bind<bool>("Respawn Settings", "NoRepeatRespawns", true, "Will attempt to prevent the player from respawning as the same monster twice in a row.");
		_itemPickupToggle = config.Bind<bool>("Item Settings", "ItemPickupToggle", true, "Allows monster players to pick up items off the ground. (Disabling won't work if RespawnTeam is set to Player.)");
		_takeAffix = config.Bind<bool>("Item Settings", "TakeAffix", true, "Will take away granted affixes upon respawning.");
		_forceGrantAffix = config.Bind<bool>("Item Settings", "ForceGrantAffix", false, "Will forcibly give the player an aspect, even if they have an equipment item.");
		_murderRevive = config.Bind<bool>("Behavior Settings", "MurderRevive", true, "Will respawn a dead player as a survivor if they kill another player.");
		_murderWindow = config.Bind<float>("Behavior Settings", "MurderWindow", 15f, "The amount of time that a player has after damaging a player to respawn as them.");
		_announceRespawns = config.Bind<bool>("Behavior Settings", "AnnounceRespawns", true, "Will announce a player respawning in the chat.");
		_disableMoon = config.Bind<bool>("Behavior Settings", "DisableMoon", true, "Prevents players from respawning in Commencement.");
		_overrideMetamorphosis = config.Bind<bool>("Behavior Settings", "OverrideMetamorphosis", true, "Allows Refightilization to override Artifact of Metamorphosis's behavior.");
		_changeMinionsTeam = config.Bind<bool>("Behavior Settings", "ChangeMinionsTeam", true, "Minions will have their team changed to match the player.");
		_respawnAsMonsterVariants = config.Bind<bool>("Compatibility Settings", "RespawnAsMonsterVariants", true, "Allows players to respawn as Monster Variants.");
		_removeMonsterVariantItems = config.Bind<bool>("Compatibility Settings", "RemoveMonsterVariantItems", true, "Will remove items given to players by Monster Variants on respawn.");
		_endGameWhenEverybodyDead = config.Bind<bool>("Debug", "EndGameWhenEverybodyDead", true, "Ends the round when everybody is dead. (Keep this on.)");
		_maxRespawnTries = config.Bind<int>("Debug", "MaxRespawnTries", 5, "The maximum attempts the game will make to retry spawning a player.");
		_preventPrefabResetMethods = config.Bind<string>("Debug", "PreventPrefabResetMethods", "SwapCharacters, RevertCharacter, CCSpawnAs", "Manually set methods to not be affected by Refight's BodyPrefab-Resetting behavior. (Don't touch this unless you know what you're doing.)");
	}

	public void BuildRiskOfOptionsMenu()
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Expected O, but got Unknown
		//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_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Expected O, but got Unknown
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Expected O, but got Unknown
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Expected O, but got Unknown
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Expected O, but got Unknown
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Expected O, but got Unknown
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Expected O, but got Unknown
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Expected O, but got Unknown
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Expected O, but got Unknown
		//IL_00fe: 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_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Expected O, but got Unknown
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Expected O, but got Unknown
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Expected O, but got Unknown
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: 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_016f: Expected O, but got Unknown
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Expected O, but got Unknown
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Expected O, but got Unknown
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Expected O, but got Unknown
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Expected O, but got Unknown
		//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Expected O, but got Unknown
		//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f0: Expected O, but got Unknown
		//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0200: Expected O, but got Unknown
		//IL_0206: Unknown result type (might be due to invalid IL or missing references)
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0216: Unknown result type (might be due to invalid IL or missing references)
		//IL_0221: Unknown result type (might be due to invalid IL or missing references)
		//IL_0231: Expected O, but got Unknown
		//IL_022c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0236: Expected O, but got Unknown
		//IL_023c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0246: Expected O, but got Unknown
		//IL_024c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0256: Expected O, but got Unknown
		//IL_025c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0266: Expected O, but got Unknown
		//IL_026c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0276: Expected O, but got Unknown
		//IL_027c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0286: Expected O, but got Unknown
		//IL_028c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0296: Expected O, but got Unknown
		//IL_029c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ac: 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_02c7: Expected O, but got Unknown
		//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cc: Expected O, but got Unknown
		//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02dc: Expected O, but got Unknown
		//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ec: Expected O, but got Unknown
		//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fc: Expected O, but got Unknown
		//IL_0302: Unknown result type (might be due to invalid IL or missing references)
		//IL_030c: Expected O, but got Unknown
		//IL_0312: Unknown result type (might be due to invalid IL or missing references)
		//IL_031c: Expected O, but got Unknown
		//IL_0322: Unknown result type (might be due to invalid IL or missing references)
		//IL_032c: Expected O, but got Unknown
		//IL_0332: Unknown result type (might be due to invalid IL or missing references)
		//IL_033c: Expected O, but got Unknown
		//IL_0342: Unknown result type (might be due to invalid IL or missing references)
		//IL_034c: Expected O, but got Unknown
		//IL_0352: Unknown result type (might be due to invalid IL or missing references)
		//IL_0357: Unknown result type (might be due to invalid IL or missing references)
		//IL_0363: Expected O, but got Unknown
		//IL_035e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0368: Expected O, but got Unknown
		byte[] array = File.ReadAllBytes(Assembly.GetExecutingAssembly().Location.Replace("Refightilization.dll", "") + "icon.png");
		Texture2D val = new Texture2D(256, 256);
		ImageConversion.LoadImage(val, array);
		ModSettingsManager.SetModIcon(Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), Vector2.zero));
		ModSettingsManager.SetModDescriptionToken("REFIGHT_MOD_DESCRIPTION");
		ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(_enableRefightilization));
		ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(_allowBosses));
		ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(_allowScavengers));
		ModSettingsManager.AddOption((BaseOption)new StringInputFieldOption(_blacklistedEnemies));
		ModSettingsManager.AddOption((BaseOption)new IntSliderOption(_bossRequiredLoopCount));
		ModSettingsManager.AddOption((BaseOption)new IntSliderOption(_scavangerRequiredLoopCount));
		ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(_enableFixedPool));
		ModSettingsManager.AddOption((BaseOption)new StringInputFieldOption(_fixedPool));
		ModSettingsManager.AddOption((BaseOption)new StepSliderOption(_respawnDelay, new StepSliderConfig
		{
			min = 0f,
			max = 60f,
			increment = 1f
		}));
		ModSettingsManager.AddOption((BaseOption)new ChoiceOption((ConfigEntryBase)(object)_respawnTeam));
		ModSettingsManager.AddOption((BaseOption)new StepSliderOption(_respawnHealthMultiplier, new StepSliderConfig
		{
			min = 0f,
			max = 2f,
			increment = 0.1f
		}));
		ModSettingsManager.AddOption((BaseOption)new StepSliderOption(_respawnDamageMultiplier, new StepSliderConfig
		{
			min = 0f,
			max = 10f,
			increment = 0.2f
		}));
		ModSettingsManager.AddOption((BaseOption)new StepSliderOption(_respawnMoneyMultiplier, new StepSliderConfig
		{
			min = 0f,
			max = 2f,
			increment = 0.1f
		}));
		ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(_respawnAffixEnabled));
		ModSettingsManager.AddOption((BaseOption)new SliderOption(_respawnAffixChance));
		ModSettingsManager.AddOption((BaseOption)new StepSliderOption(_additionalRespawnTime, new StepSliderConfig
		{
			min = 0f,
			max = 2f,
			increment = 0.1f
		}));
		ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(_noRespawnsAfterTeleporter));
		ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(_noRepeatRespawns));
		ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(_itemPickupToggle));
		ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(_takeAffix));
		ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(_forceGrantAffix));
		ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(_murderRevive));
		ModSettingsManager.AddOption((BaseOption)new StepSliderOption(_murderWindow, new StepSliderConfig
		{
			min = 1f,
			max = 60f,
			increment = 1f
		}));
		ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(_announceRespawns));
		ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(_disableMoon));
		ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(_overrideMetamorphosis));
		ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(_changeMinionsTeam));
		ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(_respawnAsMonsterVariants));
		ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(_removeMonsterVariantItems));
		ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(_endGameWhenEverybodyDead));
		ModSettingsManager.AddOption((BaseOption)new IntSliderOption(_maxRespawnTries));
		ModSettingsManager.AddOption((BaseOption)new StringInputFieldOption(_preventPrefabResetMethods, new InputFieldConfig
		{
			restartRequired = true
		}));
	}
}
internal class RefightilizationLanguage
{
	public List<string> ReviveMessages { get; set; }

	public List<string> RevengeMessages { get; set; }

	public string RiskOfOptionsDescription { get; set; }

	public RefightilizationLanguage()
	{
		ReviveMessages = new List<string>();
		RevengeMessages = new List<string>();
		string text = Language.currentLanguageName;
		JSONNode val = JSON.Parse(new StreamReader(File.Open(Assembly.GetExecutingAssembly().Location.Replace("Refightilization.dll", "") + "LanguageResource.json", FileMode.Open, FileAccess.Read), Encoding.Unicode).ReadToEnd());
		if (val[text] == (object)null)
		{
			text = "en";
		}
		ConvertArrayToStringList(val[text]["reviveMessages"].AsArray, ReviveMessages);
		ConvertArrayToStringList(val[text]["revengeMessages"].AsArray, RevengeMessages);
	}

	private void ConvertArrayToStringList(JSONArray input, List<string> output)
	{
		for (int i = 0; i < ((JSONNode)input).Count; i++)
		{
			output.Add(((JSONNode)input)[i].Value);
		}
	}
}