Decompiled source of KillMeForMyPower v2.6.1

KillMeForMyPower.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using JetBrains.Annotations;
using KillMeForMyPower.Commands;
using KillMeForMyPower.Managers;
using KillMeForMyPower.Restrictions.BossNameManagement;
using Microsoft.CodeAnalysis;
using ServerSync;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("PowersForbiddenForNewbies")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PowersForbiddenForNewbies")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e78efca2-b045-4686-8901-4fedba31614f")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace KillMeForMyPower
{
	public class KillMeForMyPowerUtils
	{
		private static BossNameEnum parseBossName(string value)
		{
			Logger.Log("Parsing value: " + value);
			return (BossNameEnum)Enum.Parse(typeof(BossNameEnum), value, ignoreCase: true);
		}

		public static BossNameEnum findBossNameByPrefabName(string value, bool logSilent = false)
		{
			Logger.Log("Parsing prefab bossName " + value + " into Enum");
			foreach (BossNameEnum value2 in Enum.GetValues(typeof(BossNameEnum)))
			{
				if (value2.GetFightBossname() == value || value2.ToString() == value)
				{
					return value2;
				}
			}
			if (!logSilent)
			{
				Logger.LogWarning(value + " not a vanilla/monstrum boss name.");
			}
			return BossNameEnum.None;
		}

		public static string getBossNameTranslation(BossNameEnum bossName)
		{
			return bossName.GetTranslationKey();
		}

		public static bool HasDefeatedBossNameStr(string bossName)
		{
			BossNameEnum bossNameEnum;
			try
			{
				bossNameEnum = parseBossName(bossName);
			}
			catch (Exception ex)
			{
				Logger.LogError("Error in HasDefeatedBossName with " + bossName + " in parseBossName. " + ex);
				return false;
			}
			return HasDefeatedBossName(bossNameEnum);
		}

		public static bool HasDefeatedBossName(BossNameEnum bossNameEnum)
		{
			if (bossNameEnum == BossNameEnum.None)
			{
				return true;
			}
			bool flag = BossNameUtils.IsBossPowerGrantedForPlayer(bossNameEnum, Player.m_localPlayer);
			Logger.Log($"hasDefeated(1) for player {Player.m_localPlayer.GetPlayerName()}: {flag}");
			if (!flag)
			{
				flag = ConfigurationFile.activateMidPlayDetection.Value && ((Humanoid)Player.m_localPlayer).HaveUniqueKey(bossNameEnum.GetPowerKey());
				Logger.Log($"hasDefeated(2) for player {Player.m_localPlayer.GetPlayerName()}: {flag}");
				if (flag)
				{
					Logger.Log("Learned the power before. Granting!");
					ZRoutedRpc.instance.InvokeRoutedRPC(0L, "RPC_BossPowerGrantServer", new object[2]
					{
						bossNameEnum.ToString(),
						Player.m_localPlayer.GetPlayerName()
					});
				}
			}
			return flag;
		}

		public static int GetCurrentDay()
		{
			return (int)GameManager.GetPrivateMethod(EnvMan.instance, "GetCurrentDay");
		}

		public static int GetBossMinimumDayForPower(string bossName)
		{
			return parseBossName(bossName) switch
			{
				BossNameEnum.Eikthyr => ConfigurationFile.daysBoss1Eikthyr.Value, 
				BossNameEnum.TheElder => ConfigurationFile.daysBoss2Elder.Value, 
				BossNameEnum.Bonemass => ConfigurationFile.daysBoss3Bonemass.Value, 
				BossNameEnum.Moder => ConfigurationFile.daysBoss4Moder.Value, 
				BossNameEnum.Yagluth => ConfigurationFile.daysBoss5Yagluth.Value, 
				BossNameEnum.Queen => ConfigurationFile.daysBos6Queen.Value, 
				BossNameEnum.Fader => ConfigurationFile.daysBoss7Fader.Value, 
				BossNameEnum.Kall => ConfigurationFile.daysBoss8Kall.Value, 
				_ => ConfigurationFile.daysBoss9odded.Value, 
			};
		}

		public static bool bossIsKilled(string bossToCheck)
		{
			return bossIsKilled(parseBossName(bossToCheck));
		}

		public static bool bossIsKilled(BossNameEnum bossToCheck)
		{
			return HasDefeatedBossName(bossToCheck);
		}
	}
	public enum Effects
	{
		None,
		Burning,
		Frost,
		Lightning,
		Poison
	}
	public enum BossItemDropRule
	{
		Default,
		OnePlayer,
		DropsForEachPlayerNearby
	}
	public enum BossTrophyDropRule
	{
		Default,
		DropsForEachPlayerNearby
	}
	internal class ConfigurationFile
	{
		private static ConfigEntry<bool> _serverConfigLocked;

		public static ConfigEntry<bool> debug;

		public static ConfigEntry<bool> activateMidPlayDetection;

		public static ConfigEntry<string> forbiddenMessage;

		public static ConfigEntry<bool> vendorLocalRestrictions;

		public static ConfigEntry<BossNameEnum> vendorHaldorBossToKill;

		public static ConfigEntry<string> vendorHaldorRestrictionsBosses;

		public static ConfigEntry<string> vendorHaldorRestrictionsGlobalKeys;

		public static ConfigEntry<string> vendorHaldorRestrictionsPlayerKeys;

		public static ConfigEntry<BossNameEnum> vendorHildirBossToKill;

		public static ConfigEntry<string> vendorHildirRestrictionsBosses;

		public static ConfigEntry<string> vendorHildirRestrictionsGlobalKeys;

		public static ConfigEntry<string> vendorHildirRestrictionsPlayerKeys;

		public static ConfigEntry<BossNameEnum> vendorBogWitchBossToKill;

		public static ConfigEntry<string> vendorBogWitchRestrictionsBosses;

		public static ConfigEntry<string> vendorBogWitchRestrictionsGlobalKeys;

		public static ConfigEntry<string> vendorBogWitchRestrictionsPlayerKeys;

		public static ConfigEntry<string> forbiddenVendorMessage;

		public static ConfigEntry<Effects> scareEffect;

		public static ConfigEntry<int> scareEffectDuration;

		public static ConfigEntry<float> minimumPlayersAroundRange;

		public static ConfigEntry<string> minimumPlayersAroundForbiddenMessage;

		public static ConfigEntry<int> minimumPlayersAroundAmount;

		public static ConfigEntry<float> noBuildAroundAltarsRange;

		public static ConfigEntry<bool> restrictEnteringDungeonsBeforeKillingBossesAdmins;

		public static ConfigEntry<bool> restrictEnteringDungeonsBeforeKillingBosses;

		public static ConfigEntry<string> restrictEnteringDungeonsBeforeKillingBossesMessage;

		public static ConfigEntry<bool> restrictExitingQueenDungeonIfAliveOrAlerted;

		public static ConfigEntry<bool> restrictExitingDeepNorthBossDungeonIfAliveOrAlerted;

		public static ConfigEntry<bool> restrictUsingKeyItems;

		public static ConfigEntry<string> restrictUsingKeyItemsMessage;

		public static ConfigEntry<string> itemRestrictionAvailableTooltipMessage;

		public static ConfigEntry<string> itemRestrictionAvailableTooltipYes;

		public static ConfigEntry<string> itemRestrictionAvailableTooltipNo;

		public static ConfigEntry<bool> grantKillToNearbyPlayers;

		public static ConfigEntry<BossItemDropRule> dropsBossItems;

		public static ConfigEntry<BossTrophyDropRule> dropsBossTrophies;

		public static ConfigEntry<bool> despawnEnabled;

		public static ConfigEntry<float> radius;

		public static ConfigEntry<string> exceptionPrefabIdList;

		public static ConfigEntry<bool> minLevelToSpawnBoss;

		public static ConfigEntry<int> maxLevelGapBetweenBossAndPlayer;

		public static ConfigEntry<string> minLevelToSpawnBossNotMet;

		public static ConfigEntry<int> daysBoss1Eikthyr;

		public static ConfigEntry<int> daysBoss2Elder;

		public static ConfigEntry<int> daysBoss3Bonemass;

		public static ConfigEntry<int> daysBoss4Moder;

		public static ConfigEntry<int> daysBoss5Yagluth;

		public static ConfigEntry<int> daysBos6Queen;

		public static ConfigEntry<int> daysBoss7Fader;

		public static ConfigEntry<int> daysBoss8Kall;

		public static ConfigEntry<int> daysBoss9odded;

		public static ConfigEntry<int> maxLevelBeforeBoss1Eikthyr;

		public static ConfigEntry<int> maxLevelBeforeBoss2TheElder;

		public static ConfigEntry<int> maxLevelBeforeBoss3Bonemass;

		public static ConfigEntry<int> maxLevelBeforeBoss4Moder;

		public static ConfigEntry<int> maxLevelBeforeBoss5Yagluth;

		public static ConfigEntry<int> maxLevelBeforeBoss6Queen;

		public static ConfigEntry<int> maxLevelBeforeBoss7Fader;

		public static ConfigEntry<int> maxLevelBeforeBoss8Kall;

		public static ConfigEntry<string> playerListForBoss1EikthyrPower;

		public static ConfigEntry<string> playerListForBoss2TheElderPower;

		public static ConfigEntry<string> playerListForBoss3BonemassPower;

		public static ConfigEntry<string> playerListForBoss4ModerPower;

		public static ConfigEntry<string> playerListForBoss5YagluthPower;

		public static ConfigEntry<string> playerListForBoss6QueenPower;

		public static ConfigEntry<string> playerListForBoss7FaderPower;

		public static ConfigEntry<string> playerListForBoss8KallPower;

		public static ConfigEntry<string> playerListForBoss8TherzieGorrPower;

		public static ConfigEntry<string> playerListForBoss8TherzieBrutalisPower;

		public static ConfigEntry<string> playerListForBoss8TherzieStormHeraldPower;

		public static ConfigEntry<string> playerListForBoss8TherzieSythrakPower;

		private static ConfigFile configFile;

		private static readonly ConfigSync ConfigSync = new ConfigSync("Turbero.KillMeForMyPower")
		{
			DisplayName = "Kill Me For My Power",
			CurrentVersion = "2.6.1",
			MinimumRequiredVersion = "2.6.1"
		};

		internal static void LoadConfig(BaseUnityPlugin plugin)
		{
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Expected O, but got Unknown
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Expected O, but got Unknown
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Expected O, but got Unknown
			//IL_04aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b5: Expected O, but got Unknown
			//IL_04e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ed: Expected O, but got Unknown
			//IL_050c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0517: Expected O, but got Unknown
			//IL_0555: Unknown result type (might be due to invalid IL or missing references)
			//IL_0560: Expected O, but got Unknown
			configFile = plugin.Config;
			_serverConfigLocked = config("1 - General", "Lock Configuration", value: true, "If on, the configuration is locked and can be changed by server admins only.");
			ConfigSync.AddLockingConfigEntry<bool>(_serverConfigLocked);
			debug = config("1 - General", "DebugMode", value: false, "Enabling/Disabling the debugging in the console (default = false)", synchronizedSetting: false);
			activateMidPlayDetection = config("1 - General", "ActivateMidPlayDetection", value: true, "Adds boss power detection to identify if the player had used the power before installing the mod in a mid-play (default = false)");
			forbiddenMessage = config("2 - Config", "ForbiddenMessage", "Kill the forsaken first!", "Message to show when you cannot obtain the forsaken power");
			grantKillToNearbyPlayers = config("2 - Config", "GrantKillToNearbyPlayers", value: true, "Allows nearby players to grant the boss kill (default = true)");
			scareEffect = config("2 - Config", "Scare Effect", Effects.Lightning, "Set up the effect when trying to access restricted items or dungeons (default = Lightning)");
			scareEffectDuration = config("2 - Config", "Scare Effect Duration", 3, "Duration in seconds of the scare effect (default = 3)");
			minimumPlayersAroundAmount = config("2 - Config", "Minimum Players Around - Amount", 1, new ConfigDescription("Minimum of players around an altar to spawn a boss, including yourself (default = 3)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 50), Array.Empty<object>()));
			minimumPlayersAroundRange = config("2 - Config", "Minimum Players Around - Range", 10f, new ConfigDescription("Range to detect minimum of players around an altar to spawn a boss, including yourself (default = 10)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			minimumPlayersAroundForbiddenMessage = config("2 - Config", "Minimum Players Around - Forbidden Message", "You need at least {0} people to spawn the boss!", "Message to show when you cannot spawn the boss due to insufficient people around");
			noBuildAroundAltarsRange = config("2 - Config", "No Build Around Altars Range", 0f, new ConfigDescription("Range in meters around boss altars where the player cannot stand up for building. 0 = the player can build (default = 0)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			vendorLocalRestrictions = config("2.1 - Vendor Restrictions", "VendorLocalRestrictions", value: true, "Vendors allow buying items based on personal progress, not global (default = true)");
			forbiddenVendorMessage = config("2.1 - Vendor Restrictions", "ForbiddenVendorMessage", "You have not killed {0} yet to buy my stuff!", "Message to show when you cannot buy from a NPC");
			vendorHaldorBossToKill = config("2.1.1 - Vendor Restrictions - Haldor", "VendorHaldorBossToKill", BossNameEnum.Eikthyr, "Boss to be killed before being able to talk to Haldor (default = Eikthyr). Set to 'None' to remove this restriction. Possible values: Eikthyr,TheElder,Bonemass,Moder,Yagluth,Queen,Fader,Kall,None");
			vendorHaldorRestrictionsBosses = config("2.1.1 - Vendor Restrictions - Haldor", "VendorHaldorRestrictions", "BeltStrength,Eikthyr;YmirRemains,TheElder;Thunderstone,TheElder;ChickenEgg,Yagluth;$hud_extrainvslot1,Moder;$hud_extrainvslot2,Queen", "Restricted items for Haldor split by comma and semicolon. Ex: BeltStrength,Eikthyr;YmirRemains,TheElder;Thunderstone,TheElder;ChickenEgg,Yagluth. Available boss names: Eikthyr,TheElder,Bonemass,Moder,Yagluth,Queen,Fader,Kall (empty = nothing to restrict)");
			vendorHaldorRestrictionsGlobalKeys = config("2.1.1 - Vendor Restrictions - Haldor", "VendorHaldorRestrictionsGlobalKeys", "", "Restricted items by global keys for Haldor split by comma and semicolon (empty = nothing to restrict)");
			vendorHaldorRestrictionsPlayerKeys = config("2.1.1 - Vendor Restrictions - Haldor", "VendorHaldorRestrictionsPlayerKeys", "", "Restricted items by player keys for Haldor split by comma and semicolon (empty = nothing to restrict)");
			vendorHildirBossToKill = config("2.1.2 - Vendor Restrictions - Hildir", "VendorHildirBossToKill", BossNameEnum.Eikthyr, "Boss to be killed before being able to talk to Haldor (default = Eikthyr). Set to 'None' to remove this restriction. Possible values: Eikthyr,TheElder,Bonemass,Moder,Yagluth,Queen,Fader,Kall,None");
			vendorHildirRestrictionsBosses = config("2.1.2 - Vendor Restrictions - Hildir", "VendorHildirRestrictions", "", "Restricted items for Hildir split by comma and semicolon. Ex: Ironpit,Moder. Available boss names: Eikthyr,TheElder,Bonemass,Moder,Yagluth,Queen,Fader,Kall (empty = nothing to restrict)");
			vendorHildirRestrictionsGlobalKeys = config("2.1.2 - Vendor Restrictions - Hildir", "VendorHildirRestrictionsGlobalKeys", "", "Restricted items by global keys for Hildir split by comma and semicolon (empty = nothing to restrict)");
			vendorHildirRestrictionsPlayerKeys = config("2.1.2 - Vendor Restrictions - Hildir", "VendorHildirRestrictionsPlayerKeys", "ArmorDress2,BossHildir2;ArmorDress3,BossHildir3;ArmorDress5,BossHildir2;ArmorDress6,BossHildir3;ArmorDress8,BossHildir2;ArmorDress9,BossHildir3;ArmorTunic2,BossHildir2;ArmorTunic3,BossHildir3;ArmorTunic5,BossHildir2;ArmorTunic6,BossHildir3;ArmorTunic8,BossHildir2;ArmorTunic9,BossHildir3;ArmorDress1,BossHildir1;ArmorDress4,BossHildir1;ArmorDress7,BossHildir1;ArmorTunic1,BossHildir1;ArmorTunic4,BossHildir1;ArmorTunic7,BossHildir1;ArmorHarvester1,BossHildir1;ArmorHarvester2,BossHildir1;HelmetHat1,BossHildir1;HelmetHat2,BossHildir2;HelmetHat3,BossHildir1;HelmetHat4,BossHildir2;HelmetHat6,BossHildir2;HelmetHat7,BossHildir3;HelmetHat8,BossHildir3;HelmetHat9,BossHildir3;HelmetStrawHat,BossHildir1;FireworksRocket_White,BossHildir3", "Restricted items by player keys for Hildir split by comma and semicolon (empty = nothing to restrict)");
			vendorBogWitchBossToKill = config("2.1.3 - Vendor Restrictions - BogWitch", "VendorBogWitchBossToKill", BossNameEnum.TheElder, "Boss to be killed before being able to talk to Haldor (default = TheElder). Set to 'None' to remove this restriction. Possible values: Eikthyr,TheElder,Bonemass,Moder,Yagluth,Queen,Fader,Kall,None");
			vendorBogWitchRestrictionsBosses = config("2.1.3 - Vendor Restrictions - BogWitch", "VendorBogWitchRestrictions", "HelmetRootCrown,Bonemass;ScytheHandle,Moder;MushroomBzerker,Moder;FragrantBundle,Moder;SpiceForests,TheElder;SpiceMountains,Moder;SpicePlains,Yagluth;SpiceMistlands,Queen;SpiceAshlands,Fader;SpiceDeepNorth,Kall", "Restricted items for BogWitch split by comma. Ex: SpicePlains,Moder;SpiceAshlands,Queen. Available boss names: Eikthyr,TheElder,Bonemass,Moder,Yagluth,Queen,Fader,Kall (empty = nothing to restrict)");
			vendorBogWitchRestrictionsGlobalKeys = config("2.1.3 - Vendor Restrictions - BogWitch", "VendorBogWitchRestrictionsGlobalKeys", "", "Restricted items by global keys for BogWitch split by comma. Ex: SpiceOcean,defeated_serpent (empty = nothing to restrict)");
			vendorBogWitchRestrictionsPlayerKeys = config("2.1.3 - Vendor Restrictions - BogWitch", "VendorBogWitchRestrictionsPlayerKeys", "SpiceOceans,defeated_serpent", "Restricted items by player keys for BogWitch split by comma. Ex: SpiceOcean,defeated_serpent (empty = nothing to restrict)");
			restrictEnteringDungeonsBeforeKillingBossesAdmins = config("2.2 - Dungeon Restrictions", "Restrict Entering Dungeons Before Killing Bosses Admins", value: false, "Restricts accessing dungeons to admins as any regular player. (default = false)");
			restrictEnteringDungeonsBeforeKillingBosses = config("2.2 - Dungeon Restrictions", "Restrict Entering Dungeons Before Killing Bosses", value: true, "Restricts accessing dungeons in biomes if you haven't killed the boss of the previous biome. (default = true)");
			restrictEnteringDungeonsBeforeKillingBossesMessage = config("2.2 - Dungeon Restrictions", "Restrict Entering Dungeons Before Killing Bosses Message", "You must defeat {0} to access this dungeon first!", "Message to show the access restriction to dungeons if previous biome boss has not been defeated.");
			restrictExitingQueenDungeonIfAliveOrAlerted = config("2.2.1 - Dungeon Restrictions - Bosses", "Restrict Exiting Queen Dungeon If Alive or Alerted", value: false, "Blocks user the Queen room without killing her! (default = false)");
			restrictExitingDeepNorthBossDungeonIfAliveOrAlerted = config("2.2.1 - Dungeon Restrictions - Bosses", "Restrict Exiting Deep North Boss Dungeon If Alive or Alerted", value: false, "Blocks user the Deep North boss room without killing him! (default = false)");
			restrictUsingKeyItems = config("2.3 - Item Restrictions", "RestrictUsingKeyItems", value: true, "Restricts using pickaxe antler, crypt key, wishbone and wisplight until you kill the previous boss even if you get them from someone else. (default = true)");
			restrictUsingKeyItemsMessage = config("2.3 - Item Restrictions", "RestrictUsingKeyItemsMessage", "You must kill {0} before doing that action!", "Message to show when you cannot equip or do an action with an important progression item");
			itemRestrictionAvailableTooltipMessage = config("2.3 - Item Restrictions", "ItemRestrictionAvailableTooltipMessage", "Available to use", "Message to show in item descriptions to know when you can start using them");
			itemRestrictionAvailableTooltipYes = config("2.3 - Item Restrictions", "ItemRestrictionAvailableTooltipMessageYes", "YES", "Message to show in item descriptions confirming when you can use them");
			itemRestrictionAvailableTooltipNo = config("2.3 - Item Restrictions", "ItemRestrictionAvailableTooltipMessageNo", "NO", "Message to show in item descriptions confirming when you cannot use them");
			dropsBossItems = config("2.4.1 - Boss drops rules", "Item drops", BossItemDropRule.Default, "If not default, drops a number of boss items according to the selected rule");
			dropsBossTrophies = config("2.4.1 - Boss drops rules", "Trophy drops", BossTrophyDropRule.Default, "If not default, drops a number of trophies according to the number of players nearby");
			despawnEnabled = config("2.4.2 - Boss despawn rules", "Despawn enabled", value: false, new ConfigDescription(string.Empty, (AcceptableValueBase)null, Array.Empty<object>()));
			radius = config("2.4.2 - Boss despawn rules", "Despawn radius", 110f, new ConfigDescription(string.Empty, (AcceptableValueBase)(object)new AcceptableValueRange<float>(25f, 250f), Array.Empty<object>()));
			exceptionPrefabIdList = config("2.4.2 - Boss despawn rules", "Bosses excluded to despawn (prefab ids)", "", new ConfigDescription("The listed bosses will never disappear. List with \", \". Example: Eikthyr,Dragon,GoblinKing", (AcceptableValueBase)null, Array.Empty<object>()));
			minLevelToSpawnBoss = config("2.5 - EpicMMO integration", "Minimum level required", value: true, "If true and epicMMO is enabled, the player needs to have a minimum level required to spawn each boss (default = true)");
			maxLevelGapBetweenBossAndPlayer = config("2.5 - EpicMMO integration", "Maximum Level Gap Between Boss And Player", 10, new ConfigDescription("Maximum difference in levels between the boss and the player who is going to spawn it (default = 5)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
			minLevelToSpawnBossNotMet = config("2.5 - EpicMMO integration", "Not minimum level message", "You need at least level {0} to start this battle", "Message to indicate the player doesn't have the minimum necessary level to spawn the boss");
			daysBoss1Eikthyr = config("3 - Days", "Days Boss 1 - Eikthyr", 100000, "Minimum number of days until the Eikthyr power cannot be obtained without killing him (default = 100000)");
			daysBoss2Elder = config("3 - Days", "Days Boss 2 - Elder", 100000, "Minimum number of days until the Elder power cannot be obtained without killing him (default = 10000)");
			daysBoss3Bonemass = config("3 - Days", "Days Boss 3 - Bonemass", 100000, "Minimum number of days until the Bonemass power cannot be obtained without killing him (default = 100000)");
			daysBoss4Moder = config("3 - Days", "Days Boss 4 - Moder", 100000, "Minimum number of days until the Moder power cannot be obtained without killing him (default = 100000)");
			daysBoss5Yagluth = config("3 - Days", "Days Boss 5 - Yagluth", 100000, "Minimum number of days until the Yagluth power cannot be obtained without killing him (default = 100000)");
			daysBos6Queen = config("3 - Days", "Days Boss 6 - Queen", 100000, "Minimum number of days until the Queen power cannot be obtained without killing him (default = 100000)");
			daysBoss7Fader = config("3 - Days", "Days Boss 7 - Fader", 100000, "Minimum number of days until the Fader power cannot be obtained without killing him (default = 100000)");
			daysBoss8Kall = config("3 - Days", "Days Boss 8 - Kall", 100000, "Minimum number of days until end credits cannot be watched without killing the final boss (default = 100000)");
			daysBoss9odded = config("3 - Days", "Days Boss 9 - Modded", 100000, "Minimum number of days until any modded boss power cannot be obtained without killing him (default = 100000)");
			maxLevelBeforeBoss1Eikthyr = config("4 - Max levels", "MaxLevelBeforeBoss1Eikthyr", 100, "Maximum skill level that player can level up skills before killing Eikthyr (default = 100)");
			maxLevelBeforeBoss2TheElder = config("4 - Max levels", "MaxLevelBeforeBoss2TheElder", 100, "Maximum skill level that player can level up skills before killing The Elder (default = 100)");
			maxLevelBeforeBoss3Bonemass = config("4 - Max levels", "MaxLevelBeforeBoss3Bonemass", 100, "Maximum skill level that player can level up skills before killing Bonemass (default = 100)");
			maxLevelBeforeBoss4Moder = config("4 - Max levels", "MaxLevelBeforeBoss4Moder", 100, "Maximum skill level that player can level up skills before killing Moder (default = 100)");
			maxLevelBeforeBoss5Yagluth = config("4 - Max levels", "MaxLevelBeforeBoss5Yagluth", 100, "Maximum skill level that player can level up skills before killing Yagluth (default = 100)");
			maxLevelBeforeBoss6Queen = config("4 - Max levels", "MaxLevelBeforeBoss6Queen", 100, "Maximum skill level that player can level up skills before killing The Queen (default = 100)");
			maxLevelBeforeBoss7Fader = config("4 - Max levels", "MaxLevelBeforeBoss7Fader", 100, "Maximum skill level that player can level up skills before killing Fader (default = 100)");
			maxLevelBeforeBoss8Kall = config("4 - Max levels", "MaxLevelBeforeBoss8Kall", 100, "Maximum skill level that player can level up skills before killing Kall (default = 100)");
			playerListForBoss1EikthyrPower = config("5 - Power Granted player lists", "Player List for Boss 1 - Eikthyr power", "", "List of player names that can use Eikthyr power after defeating him");
			playerListForBoss2TheElderPower = config("5 - Power Granted player lists", "Player List for Boss 2 - The Elder power", "", "List of player names that can use The Elder power after defeating him");
			playerListForBoss3BonemassPower = config("5 - Power Granted player lists", "Player List for Boss 3 - Bonemass power", "", "List of player names that can use Bonemass power after defeating him");
			playerListForBoss4ModerPower = config("5 - Power Granted player lists", "Player List for Boss 4 - Moder power", "", "List of player names that can use Moder power after defeating her");
			playerListForBoss5YagluthPower = config("5 - Power Granted player lists", "Player List for Boss 5 - Yagluth power", "", "List of player names that can use Yagluth power after defeating him");
			playerListForBoss6QueenPower = config("5 - Power Granted player lists", "Player List for Boss 6 - Queen power", "", "List of player names that can use Queen power after defeating her");
			playerListForBoss7FaderPower = config("5 - Power Granted player lists", "Player List for Boss 7 - Fader power", "", "List of player names that can use Fader power after defeating him");
			playerListForBoss8KallPower = config("5 - Power Granted player lists", "Player List for Boss 8 - Kall", "", "List of player names that has defeated the final boss");
			playerListForBoss8TherzieGorrPower = config("5 - Power Granted player lists", "Player List for Therzie Boss - Gorr power", "", "List of player names that can use Gorr power after defeating him");
			playerListForBoss8TherzieBrutalisPower = config("5 - Power Granted player lists", "Player List for Therzie Boss - Brutalis power", "", "List of player names that can use Brutalis power after defeating him");
			playerListForBoss8TherzieStormHeraldPower = config("5 - Power Granted player lists", "Player List for Therzie Boss - StormHerald power", "", "List of player names that can use StormHerald power after defeating him");
			playerListForBoss8TherzieSythrakPower = config("5 - Power Granted player lists", "Player List for Therzie Boss - Sythrak power", "", "List of player names that can use Sythrak power after defeating him");
		}

		private static ConfigEntry<T> config<T>(string group, string name, T value, string description, bool synchronizedSetting = true)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			return config(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()), synchronizedSetting);
		}

		private static ConfigEntry<T> config<T>(string group, string name, T value, ConfigDescription description, bool synchronizedSetting = true)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			ConfigDescription val = new ConfigDescription(description.Description + (synchronizedSetting ? " [Synced with Server]" : " [Not Synced with Server]"), description.AcceptableValues, description.Tags);
			ConfigEntry<T> val2 = configFile.Bind<T>(group, name, value, val);
			SyncedConfigEntry<T> syncedConfigEntry = ConfigSync.AddConfigEntry<T>(val2);
			syncedConfigEntry.SynchronizedConfig = synchronizedSetting;
			return val2;
		}
	}
	[BepInPlugin("Turbero.KillMeForMyPower", "Kill Me For My Power", "2.6.1")]
	public class KillMeForMyPower : BaseUnityPlugin
	{
		public const string GUID = "Turbero.KillMeForMyPower";

		public const string NAME = "Kill Me For My Power";

		public const string VERSION = "2.6.1";

		private readonly Harmony harmony = new Harmony("Turbero.KillMeForMyPower");

		private void Awake()
		{
			ConfigurationFile.LoadConfig((BaseUnityPlugin)(object)this);
			harmony.PatchAll();
		}

		private void Start()
		{
			((MonoBehaviour)this).StartCoroutine(WaitForNetworking());
		}

		private IEnumerator WaitForNetworking()
		{
			while (ZRoutedRpc.instance == null || (Object)(object)ZNet.instance == (Object)null)
			{
				yield return (object)new WaitForSeconds(1f);
			}
			PowerManagementCommands.RegisterConsoleCommand();
			CheckBossesCommand.RegisterConsoleCommand();
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Console commands registered successfully. IsServer: " + ZNet.instance.IsServer().ToString().ToUpperInvariant()));
		}

		private void onDestroy()
		{
			harmony.UnpatchSelf();
		}
	}
	public static class Logger
	{
		public static ManualLogSource logger = Logger.CreateLogSource("Kill Me For My Power");

		internal static void Log(object s)
		{
			if (ConfigurationFile.debug.Value)
			{
				logger.LogInfo((object)s?.ToString());
			}
		}

		internal static void LogInfo(object s)
		{
			logger.LogInfo((object)s?.ToString());
		}

		internal static void LogWarning(object s)
		{
			logger.LogWarning((object)s?.ToString());
		}

		internal static void LogError(object s)
		{
			logger.LogError((object)s?.ToString());
		}
	}
}
namespace KillMeForMyPower.Restrictions
{
	[HarmonyPatch]
	internal static class BossDespawnRestrictionPath
	{
		private static readonly List<Vector3> bossesOkayToDestroyAndWaiting_spawnPositions = new List<Vector3>();

		private static readonly List<Vector3> bossesReadyToDestroy_spawnPositions = new List<Vector3>();

		[HarmonyPatch(typeof(Humanoid), "CustomFixedUpdate")]
		public static void Postfix(Humanoid __instance)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: 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_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: 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_016c: Unknown result type (might be due to invalid IL or missing references)
			if (!ConfigurationFile.despawnEnabled.Value)
			{
				return;
			}
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name != "main" || (Object)(object)ZNetScene.instance == (Object)null || (Object)(object)ZNet.instance == (Object)null || !Object.op_Implicit((Object)(object)__instance))
			{
				return;
			}
			string text = Localization.instance.Localize(((Character)__instance).m_name);
			BaseAI baseAI = ((Character)__instance).GetBaseAI();
			if ((Object)(object)baseAI == (Object)null)
			{
				return;
			}
			Vector3 item = (Vector3)GameManager.GetPrivateValue(baseAI, "m_spawnPoint");
			if (!IsOkayToDestroy(__instance))
			{
				if (bossesOkayToDestroyAndWaiting_spawnPositions.Contains(item))
				{
					bossesOkayToDestroyAndWaiting_spawnPositions.Remove(item);
				}
			}
			else if (bossesReadyToDestroy_spawnPositions.Contains(item))
			{
				Logger.LogInfo("Despawning " + text + "...");
				ZNetScene.instance.Destroy(((Component)__instance).gameObject);
				((Character)Player.m_localPlayer).Message((MessageType)1, "Despawning " + text + "...", 0, (Sprite)null, false);
				bossesReadyToDestroy_spawnPositions.Remove(item);
				bossesOkayToDestroyAndWaiting_spawnPositions.Remove(item);
			}
			else if (!bossesOkayToDestroyAndWaiting_spawnPositions.Contains(item))
			{
				bossesOkayToDestroyAndWaiting_spawnPositions.Add(item);
				bossesReadyToDestroy_spawnPositions.Add(item);
			}
		}

		private static bool IsOkayToDestroy(Humanoid humanoid)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)humanoid == (Object)null)
			{
				return false;
			}
			Logger.Log("humanoid.name: " + ((Object)humanoid).name);
			string value = ((Object)humanoid).name.Replace("(Clone)", "");
			bool flag = Player.IsPlayerInRange(((Component)humanoid).transform.position, ConfigurationFile.radius.Value);
			bool flag2 = ConfigurationFile.exceptionPrefabIdList.Value.Contains(value);
			return ((Character)humanoid).IsBoss() && !flag && !flag2;
		}
	}
	[HarmonyPatch(typeof(CharacterDrop), "GenerateDropList")]
	public class BossDropsRules
	{
		public static void Postfix(ref Character ___m_character, ref List<KeyValuePair<GameObject, int>> __result)
		{
			if ((ConfigurationFile.dropsBossTrophies.Value == BossTrophyDropRule.Default && ConfigurationFile.dropsBossItems.Value == BossItemDropRule.Default) || !___m_character.IsBoss())
			{
				return;
			}
			int countPlayersNearby = GetCountPlayersNearby(___m_character);
			Logger.Log("result distinct drops count: " + __result.Count);
			Logger.Log("result total items count: " + __result.Select((KeyValuePair<GameObject, int> elem) => elem.Value).Sum());
			Logger.Log("countPlayersNearby: " + countPlayersNearby);
			List<KeyValuePair<GameObject, int>> list = new List<KeyValuePair<GameObject, int>>();
			foreach (KeyValuePair<GameObject, int> item in __result)
			{
				GameObject key = item.Key;
				int num = item.Value;
				string text = ((Object)key).name.ToLowerInvariant();
				Logger.Log($"Previous amount for {text}: {num}");
				if (ConfigurationFile.dropsBossItems.Value != BossItemDropRule.Default)
				{
					int num2 = ((ConfigurationFile.dropsBossItems.Value != BossItemDropRule.DropsForEachPlayerNearby) ? 1 : countPlayersNearby);
					if (text.ToLowerInvariant().Contains("hardantler") || text.ToLowerInvariant().Contains("yagluthdrop"))
					{
						num = 3 * num2;
					}
					else if (text.ToLowerInvariant().Contains("cryptkey") || text.ToLowerInvariant().Contains("wishbone"))
					{
						num = num2;
					}
					else if (text.ToLowerInvariant().Contains("dragontear"))
					{
						num = 10 * num2;
					}
					else if (text.ToLowerInvariant().Contains("queendrop") || text.ToLowerInvariant().Contains("faderdrop"))
					{
						num = 5 * num2;
					}
				}
				if (text.ToLowerInvariant().Contains("trophy"))
				{
					num = ((ConfigurationFile.dropsBossTrophies.Value == BossTrophyDropRule.Default) ? 1 : countPlayersNearby);
				}
				Logger.Log($"New amount for {text}: {num}");
				list.Add(new KeyValuePair<GameObject, int>(key, num));
			}
			__result = list;
			Logger.Log("__result new total items count: " + __result.Select((KeyValuePair<GameObject, int> elem) => elem.Value).Sum());
		}

		private static int GetCountPlayersNearby(Character boss)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			BaseAI component = ((Component)boss).GetComponent<BaseAI>();
			float num = (Object.op_Implicit((Object)(object)component) ? component.m_viewRange : 0f);
			Logger.Log(string.Format("Detection boss range for {0} is {1} meters", ((Object)boss).name.Replace("(Clone)", ""), num));
			List<Player> list = new List<Player>();
			Vector3 position = ((Component)Player.m_localPlayer).transform.position;
			Player.GetPlayersInRange(position, num, list);
			return list.Count;
		}
	}
	[HarmonyPatch(typeof(Character), "OnDeath")]
	public class RegisterBossDefeatPatch
	{
		public static void Postfix(Character __instance)
		{
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: 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)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance != (Object)null) || !__instance.IsBoss())
			{
				return;
			}
			string text = ((Object)__instance).name.Replace("(Clone)", "");
			Player localPlayer = Player.m_localPlayer;
			List<string> list = new List<string>();
			list.Add(localPlayer.GetPlayerName());
			if (ConfigurationFile.grantKillToNearbyPlayers.Value)
			{
				Logger.LogInfo("Finding nearby players to grant the kill");
				BaseAI component = ((Component)__instance).GetComponent<BaseAI>();
				float num = (Object.op_Implicit((Object)(object)component) ? component.m_viewRange : 0f);
				Logger.LogInfo(string.Format("Detection boss range for {0} is {1} meters", ((Object)__instance).name.Replace("(Clone)", ""), num));
				Vector3 position = ((Component)__instance).transform.position;
				List<Player> allPlayers = Player.GetAllPlayers();
				foreach (Player item in allPlayers)
				{
					if (!((Object)(object)item == (Object)null) && !(item.GetPlayerName() == localPlayer.GetPlayerName()) && Vector3.Distance(((Component)item).transform.position, position) <= num)
					{
						list.Add(item.GetPlayerName());
					}
				}
			}
			ZRoutedRpc.instance.InvokeRoutedRPC(0L, "RPC_BossPowerGrantServer", new object[2]
			{
				text,
				string.Join(",", list)
			});
		}
	}
	[HarmonyPatch(typeof(Player), "Save")]
	public class Player_Save_Null_Key_Clean_Patch
	{
		[HarmonyPrefix]
		public static void Prefix(Player __instance)
		{
			List<string> list = __instance.m_customData.Keys.Where((string k) => string.IsNullOrEmpty(k) || k == "null").ToList();
			foreach (string item in list)
			{
				Logger.LogWarning("Removing null key from player " + __instance.GetPlayerName());
				((Humanoid)__instance).RemoveUniqueKey(item);
			}
		}
	}
	public class RPC_BossPowerGrantCalls
	{
		public static void RPC_BossPowerGrantServer(long sender, string bossEnumStr, string playersToGrant)
		{
			BossNameEnum bossNameEnum = KillMeForMyPowerUtils.findBossNameByPrefabName(bossEnumStr, logSilent: true);
			if (bossNameEnum != BossNameEnum.None)
			{
				Logger.Log($"[RPC_BossPowerGrantServer] RPC sent from sender {sender} with {bossEnumStr} ({bossNameEnum}) and {playersToGrant}");
				string[] array = playersToGrant.Split(new char[1] { ',' });
				string[] array2 = array;
				foreach (string playerName in array2)
				{
					BossNameUtils.GrantBossPowerToPlayer(bossNameEnum, playerName, isAdd: true);
				}
			}
		}

		public static void RPC_BossPowerRemoveGrantServer(long sender, string bossEnumStr, string playersToRemoveGrant)
		{
			BossNameEnum bossNameEnum = KillMeForMyPowerUtils.findBossNameByPrefabName(bossEnumStr);
			if (bossNameEnum != BossNameEnum.None)
			{
				Logger.Log($"[RPC_BossPowerRemoveGrantServer] RPC sent from sender {sender} with {bossEnumStr} ({bossNameEnum}) and {playersToRemoveGrant}");
				string[] array = playersToRemoveGrant.Split(new char[1] { ',' });
				string[] array2 = array;
				foreach (string playerName in array2)
				{
					BossNameUtils.GrantBossPowerToPlayer(bossNameEnum, playerName, isAdd: false);
				}
			}
		}
	}
	public class BossPowerRestriction
	{
		[HarmonyPatch(typeof(Player), "ActivateGuardianPower")]
		public static class ActivateGuardianPowerPatch
		{
			public static bool Prefix(Player __instance, ref bool __result)
			{
				string guardianPowerName = __instance.GetGuardianPowerName();
				if (guardianPowerName == null || guardianPowerName.Equals(""))
				{
					return true;
				}
				string text = guardianPowerName.Replace("GP_", "");
				Logger.Log("ActivateGuardianPower - guardianPowerName: " + text);
				if (!KillMeForMyPowerUtils.HasDefeatedBossNameStr(text) && KillMeForMyPowerUtils.GetCurrentDay() < KillMeForMyPowerUtils.GetBossMinimumDayForPower(text))
				{
					((Character)__instance).Message((MessageType)2, ConfigurationFile.forbiddenMessage.Value, 0, (Sprite)null, false);
					ApplyBlockedEffect(text);
					__result = false;
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(ItemStand), "DelayedPowerActivation")]
		public static class DelayedPowerActivationPatch
		{
			public static bool Prefix(ItemStand __instance)
			{
				StatusEffect guardianPower = __instance.m_guardianPower;
				string text = ((guardianPower != null) ? ((Object)guardianPower).name.Replace("GP_", "") : null);
				Logger.Log("DelayedPowerActivation - ItemStand name: " + text);
				if (!KillMeForMyPowerUtils.HasDefeatedBossNameStr(text) && KillMeForMyPowerUtils.GetCurrentDay() < KillMeForMyPowerUtils.GetBossMinimumDayForPower(text))
				{
					((Character)Player.m_localPlayer).Message((MessageType)2, ConfigurationFile.forbiddenMessage.Value, 0, (Sprite)null, false);
					ApplyBlockedEffect(text);
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(ItemStand), "Interact")]
		public static class ItemStandInteractFinalBossBloodPatch
		{
			public static bool Prefix(ItemStand __instance)
			{
				if ((Object)(object)__instance.m_netViewOverride == (Object)null)
				{
					return true;
				}
				string value = ((Object)__instance.m_netViewOverride).name.Replace("(Clone)", "");
				if ("StartPlatform".Equals(value))
				{
					Logger.Log("ItemStand StartPlatform Interact detected");
					string bossName = "Kall";
					if (!KillMeForMyPowerUtils.HasDefeatedBossNameStr(bossName) && KillMeForMyPowerUtils.GetCurrentDay() < KillMeForMyPowerUtils.GetBossMinimumDayForPower(bossName))
					{
						((Character)Player.m_localPlayer).Message((MessageType)2, ConfigurationFile.forbiddenMessage.Value, 0, (Sprite)null, false);
						ApplyBlockedEffect(bossName);
						return false;
					}
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(EndCredits), "Interact")]
		public static class EndCreditsValkyrieInteract
		{
			public static bool Prefix(EndCredits __instance, Humanoid user, bool hold, bool alt, ref bool __result)
			{
				if (!KillMeForMyPowerUtils.HasDefeatedBossNameStr("Kall") && KillMeForMyPowerUtils.GetCurrentDay() < KillMeForMyPowerUtils.GetBossMinimumDayForPower("Kall"))
				{
					((Character)user).Message((MessageType)2, ConfigurationFile.forbiddenMessage.Value, 0, (Sprite)null, false);
					ApplyBlockedEffect("Kall");
					__result = false;
					return false;
				}
				return true;
			}
		}

		private static void ApplyBlockedEffect(string bossName)
		{
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Expected O, but got Unknown
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Expected O, but got Unknown
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Expected O, but got Unknown
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Expected O, but got Unknown
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Expected O, but got Unknown
			//IL_038c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0393: Expected O, but got Unknown
			//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e7: Expected O, but got Unknown
			//IL_044a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0451: Expected O, but got Unknown
			SEMan sEMan = ((Character)Player.m_localPlayer).GetSEMan();
			string text = string.Join(";", from se in sEMan.GetStatusEffects()
				select ((Object)se).name);
			BossNameEnum bossNameEnum = (BossNameEnum)Enum.Parse(typeof(BossNameEnum), bossName, ignoreCase: true);
			if (bossNameEnum == BossNameEnum.Eikthyr && !text.Contains("Lightning"))
			{
				StatusEffect val = ((sEMan != null) ? sEMan.AddStatusEffect("Lightning".GetHashCode(), false, 0, 0f, (short)(-1)) : null);
				val.m_ttl = 5f;
			}
			else if (bossNameEnum == BossNameEnum.TheElder && !text.Contains("Burning"))
			{
				SE_Burning val2 = (SE_Burning)((sEMan != null) ? sEMan.AddStatusEffect("Burning".GetHashCode(), false, 0, 0f, (short)(-1)) : null);
				val2.AddFireDamage(Math.Max(2f, ((Character)Player.m_localPlayer).GetHealth() - 10f));
			}
			else if (bossNameEnum == BossNameEnum.Bonemass && !text.Contains("Poison"))
			{
				SE_Poison val3 = (SE_Poison)((sEMan != null) ? sEMan.AddStatusEffect("Poison".GetHashCode(), false, 0, 0f, (short)(-1)) : null);
				val3.AddDamage(Math.Max(1f, ((Character)Player.m_localPlayer).GetHealth() - 10f));
			}
			else if (bossNameEnum == BossNameEnum.Moder && !text.Contains("Frost"))
			{
				SE_Frost val4 = (SE_Frost)((sEMan != null) ? sEMan.AddStatusEffect("Frost".GetHashCode(), false, 0, 0f, (short)(-1)) : null);
				((StatusEffect)val4).m_ttl = 5f;
			}
			else if (bossNameEnum == BossNameEnum.Yagluth && !text.Contains("Burning"))
			{
				SE_Burning val5 = (SE_Burning)((sEMan != null) ? sEMan.AddStatusEffect("Burning".GetHashCode(), false, 0, 0f, (short)(-1)) : null);
				val5.AddFireDamage(Math.Max(2f, ((Character)Player.m_localPlayer).GetHealth() - 10f));
			}
			else if (bossNameEnum == BossNameEnum.Queen && !text.Contains("Poison"))
			{
				SE_Poison val6 = (SE_Poison)((sEMan != null) ? sEMan.AddStatusEffect("Poison".GetHashCode(), false, 0, 0f, (short)(-1)) : null);
				val6.AddDamage(Math.Max(1f, ((Character)Player.m_localPlayer).GetHealth() - 10f));
			}
			else if (bossNameEnum == BossNameEnum.Fader && !text.Contains("Burning"))
			{
				SE_Burning val7 = (SE_Burning)((sEMan != null) ? sEMan.AddStatusEffect("Burning".GetHashCode(), false, 0, 0f, (short)(-1)) : null);
				val7.AddFireDamage(Math.Max(2f, ((Character)Player.m_localPlayer).GetHealth() - 10f));
			}
			else if (bossNameEnum == BossNameEnum.Kall && !text.Contains("Lightning"))
			{
				StatusEffect val8 = ((sEMan != null) ? sEMan.AddStatusEffect("Lightning".GetHashCode(), false, 0, 0f, (short)(-1)) : null);
				val8.m_ttl = 5f;
			}
			else if (bossNameEnum == BossNameEnum.SE_Boss_Gorr && !text.Contains("Frost"))
			{
				SE_Frost val9 = (SE_Frost)((sEMan != null) ? sEMan.AddStatusEffect("Frost".GetHashCode(), false, 0, 0f, (short)(-1)) : null);
				((StatusEffect)val9).m_ttl = 5f;
			}
			else if (bossNameEnum == BossNameEnum.SE_Boss_Brutalis && !text.Contains("Burning"))
			{
				SE_Burning val10 = (SE_Burning)((sEMan != null) ? sEMan.AddStatusEffect("Burning".GetHashCode(), false, 0, 0f, (short)(-1)) : null);
				val10.AddFireDamage(Math.Max(2f, ((Character)Player.m_localPlayer).GetHealth() - 10f));
			}
			else if (bossNameEnum == BossNameEnum.SE_Boss_Sythrak && !text.Contains("Burning"))
			{
				SE_Burning val11 = (SE_Burning)((sEMan != null) ? sEMan.AddStatusEffect("Burning".GetHashCode(), false, 0, 0f, (short)(-1)) : null);
				val11.AddFireDamage(Math.Max(2f, ((Character)Player.m_localPlayer).GetHealth() - 10f));
			}
			else if (bossNameEnum == BossNameEnum.SE_Boss_StormHerald && !text.Contains("Lightning"))
			{
				StatusEffect val12 = ((sEMan != null) ? sEMan.AddStatusEffect("Lightning".GetHashCode(), false, 0, 0f, (short)(-1)) : null);
				val12.m_ttl = 5f;
			}
		}
	}
	public class DungeonRestriction
	{
		[HarmonyPatch(typeof(Teleport), "OnTriggerEnter")]
		[HarmonyPriority(700)]
		public class Teleport_OnTriggerEnter_Patch
		{
			[HarmonyPrefix]
			public static bool Prefix(Teleport __instance, Collider collider)
			{
				if (!ConfigurationFile.restrictEnteringDungeonsBeforeKillingBosses.Value)
				{
					return true;
				}
				Logger.Log("[Teleport - OnTriggerEnter] entered");
				string text = ((Object)__instance).name.Replace("(Clone)", "").ToLower();
				Logger.Log("[Teleport - OnTriggerEnter] Trying to teleport the player through " + text);
				Player componentInParent = ((Component)collider).GetComponentInParent<Player>();
				if ((Object)(object)componentInParent == (Object)null)
				{
					return true;
				}
				if (!ConfigurationFile.restrictEnteringDungeonsBeforeKillingBossesAdmins.Value && GameManager.IsAdmin(componentInParent))
				{
					Logger.Log("Player " + componentInParent.GetPlayerName() + " is admin. Skipping restriction to enter...");
					return true;
				}
				if (text.Contains("gateway") && !text.Equals("exteriorgateway"))
				{
					text = "gateway";
				}
				return canCrossEntrance(text, componentInParent);
			}
		}

		[HarmonyPatch(typeof(Player), "Interact")]
		public class DetectDungeonInteractPatch
		{
			[HarmonyPrefix]
			public static bool Prefix(GameObject go, Player __instance)
			{
				if ((Object)(object)go == (Object)null)
				{
					return true;
				}
				if (((Object)go).name != "Cube")
				{
					return true;
				}
				Logger.Log("[Player - Interact] Cube touched");
				if (!ConfigurationFile.restrictEnteringDungeonsBeforeKillingBossesAdmins.Value && GameManager.IsAdmin(__instance))
				{
					Logger.Log("Player " + __instance.GetPlayerName() + " is admin. Skipping restriction to enter...");
					return true;
				}
				return canCrossEntrance(((Character)__instance).InInterior() ? "exteriorgateway" : "gateway", __instance);
			}
		}

		private static bool canCrossEntrance(string targetEntranceName, Player player)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Invalid comparison between Unknown and I4
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Invalid comparison between Unknown and I4
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Invalid comparison between Unknown and I4
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Invalid comparison between Unknown and I4
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Invalid comparison between Unknown and I4
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Invalid comparison between Unknown and I4
			if (targetEntranceName == "gateway")
			{
				if ((int)player.GetCurrentBiome() == 8 && !KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.Eikthyr))
				{
					return negateAccess(player, BossNameEnum.Eikthyr);
				}
				if ((int)player.GetCurrentBiome() == 2 && !KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.TheElder))
				{
					return negateAccess(player, BossNameEnum.TheElder);
				}
				if ((int)player.GetCurrentBiome() == 4 && !KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.Bonemass))
				{
					return negateAccess(player, BossNameEnum.Bonemass);
				}
				if ((int)player.GetCurrentBiome() == 512 && !KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.Yagluth))
				{
					return negateAccess(player, BossNameEnum.Yagluth);
				}
				if ((int)player.GetCurrentBiome() == 32 && !KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.Queen))
				{
					return negateAccess(player, BossNameEnum.Queen);
				}
				if ((int)player.GetCurrentBiome() == 64 && !KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.Fader))
				{
					return negateAccess(player, BossNameEnum.Fader);
				}
			}
			if (ConfigurationFile.restrictExitingQueenDungeonIfAliveOrAlerted.Value && targetEntranceName == "exteriorgateway" && IsBossNearbyAndAlert(player, "SeekerQueen"))
			{
				((Character)player).Message((MessageType)2, Localization.instance.Localize("$msg_blockedbyboss"), 0, (Sprite)null, false);
				Effects.scareEffect();
				return false;
			}
			if (ConfigurationFile.restrictExitingDeepNorthBossDungeonIfAliveOrAlerted.Value && targetEntranceName == "exteriorgateway" && IsBossNearbyAndAlert(player, "FrozenKing"))
			{
				((Character)player).Message((MessageType)2, Localization.instance.Localize("$msg_blockedbyboss"), 0, (Sprite)null, false);
				Effects.scareEffect();
				return false;
			}
			return true;
		}

		private static bool negateAccess(Player player, BossNameEnum bossName)
		{
			((Character)player).Message((MessageType)2, ConfigurationFile.restrictEnteringDungeonsBeforeKillingBossesMessage.Value.Replace("{0}", Localization.instance.Localize(bossName.GetTranslationKey())), 0, (Sprite)null, false);
			Effects.scareEffect();
			return false;
		}

		public static bool IsBossNearbyAndAlert(Player player, string bossName)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)player).transform.position;
			foreach (Character allCharacter in Character.GetAllCharacters())
			{
				if ((Object)(object)allCharacter != (Object)null && !allCharacter.IsDead() && ((Object)allCharacter).name.StartsWith(bossName, StringComparison.OrdinalIgnoreCase))
				{
					bool flag = ((Component)allCharacter).GetComponent<BaseAI>().IsAlerted();
					bool flag2 = Location.IsInsideActiveBossDungeon(position);
					Logger.Log($"isAlerted {flag}, isBossActive {flag2}");
					if (!flag && !flag2)
					{
						Logger.LogInfo(bossName + " is neither close nor active. Lucky!");
						return false;
					}
					float num = Vector3.Distance(position, ((Component)allCharacter).transform.position);
					Logger.Log(bossName + " is " + num + " meters away!");
					if (num <= 60f)
					{
						return true;
					}
				}
			}
			return false;
		}
	}
	public class Effects
	{
		public static void scareEffect()
		{
			global::KillMeForMyPower.Effects value = ConfigurationFile.scareEffect.Value;
			if (value != global::KillMeForMyPower.Effects.None)
			{
				SEMan sEMan = ((Character)Player.m_localPlayer).GetSEMan();
				if ((Object)(object)((sEMan != null) ? sEMan.GetStatusEffect(value.ToString().GetHashCode()) : null) == (Object)null)
				{
					StatusEffect val = ((sEMan != null) ? sEMan.AddStatusEffect(value.ToString().GetHashCode(), false, 0, 0f, (short)(-1)) : null);
					val.m_ttl = ConfigurationFile.scareEffectDuration.Value;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Humanoid), "EquipItem")]
	public class PlayerEquipItemPatch
	{
		[HarmonyPrefix]
		public static bool EquipItemPrefix(Humanoid __instance, ItemData item, bool triggerEquipEffects, ref bool __result)
		{
			if ((Object)(object)Player.m_localPlayer == (Object)null)
			{
				return true;
			}
			if (!ConfigurationFile.restrictUsingKeyItems.Value)
			{
				return true;
			}
			if (__instance is Player)
			{
				if (item.m_shared.m_name == "$item_pickaxe_antler" && !KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.Eikthyr))
				{
					((Character)__instance).Message((MessageType)2, ConfigurationFile.restrictUsingKeyItemsMessage.Value.Replace("{0}", BossNameEnum.Eikthyr.GetTranslationKey()), 0, (Sprite)null, false);
					Effects.scareEffect();
					__result = false;
					return false;
				}
				if (item.m_shared.m_name == "$item_wishbone" && !KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.Bonemass))
				{
					((Character)__instance).Message((MessageType)2, ConfigurationFile.restrictUsingKeyItemsMessage.Value.Replace("{0}", BossNameEnum.Bonemass.GetTranslationKey()), 0, (Sprite)null, false);
					Effects.scareEffect();
					__result = false;
					return false;
				}
				if (item.m_shared.m_name == "$item_demister" && !KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.Yagluth))
				{
					((Character)__instance).Message((MessageType)2, ConfigurationFile.restrictUsingKeyItemsMessage.Value.Replace("{0}", BossNameEnum.Yagluth.GetTranslationKey()), 0, (Sprite)null, false);
					Effects.scareEffect();
					__result = false;
					return false;
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Door), "Interact")]
	public class SwampKeyRestrictionPatch
	{
		[HarmonyPrefix]
		public static bool InteractPrefix(Door __instance, Humanoid character, bool hold, ref bool __result)
		{
			if (!ConfigurationFile.restrictUsingKeyItems.Value)
			{
				return true;
			}
			if (((Object)__instance).name.Contains("sunken_crypt_gate") && character is Player && !KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.TheElder))
			{
				((Character)character).Message((MessageType)2, ConfigurationFile.restrictUsingKeyItemsMessage.Value.Replace("{0}", BossNameEnum.TheElder.GetTranslationKey()), 0, (Sprite)null, false);
				Effects.scareEffect();
				__result = false;
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(UITooltip), "UpdateTextElements")]
	public class UITooltipPatch
	{
		public static void Postfix(UITooltip __instance)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			GameObject val = (GameObject)GameManager.GetPrivateValue(__instance, "m_tooltip", BindingFlags.Static | BindingFlags.NonPublic);
			if (!((Object)(object)val != (Object)null))
			{
				return;
			}
			Transform val2 = Utils.FindChild(val.transform, "Text", (IterativeSearchType)0);
			if ((Object)(object)val2 != (Object)null && __instance.m_topic != null)
			{
				if (__instance.m_topic == "$item_pickaxe_antler")
				{
					updateTooltipText(__instance, val2, BossNameEnum.Eikthyr);
				}
				else if (__instance.m_topic == "$item_demister")
				{
					updateTooltipText(__instance, val2, BossNameEnum.Yagluth);
				}
				else if (__instance.m_topic == "$item_wishbone")
				{
					updateTooltipText(__instance, val2, BossNameEnum.Bonemass);
				}
				else if (__instance.m_topic == "$item_cryptkey")
				{
					updateTooltipText(__instance, val2, BossNameEnum.TheElder);
				}
			}
		}

		private static void updateTooltipText(UITooltip __instance, Transform transform, BossNameEnum bossToCheck)
		{
			bool flag = KillMeForMyPowerUtils.HasDefeatedBossName(bossToCheck);
			string text = (flag ? ConfigurationFile.itemRestrictionAvailableTooltipYes.Value : ConfigurationFile.itemRestrictionAvailableTooltipNo.Value);
			string text2 = (flag ? "green" : "red");
			string text3 = ConfigurationFile.itemRestrictionAvailableTooltipMessage.Value + ": <color=" + text2 + ">" + text + "</color>";
			__instance.m_text = __instance.m_text.Replace("_description", "_description\n" + text3);
			((Component)transform).GetComponent<TMP_Text>().text = Localization.instance.Localize(__instance.m_text);
			string[] array = ((Component)transform).GetComponent<TMP_Text>().text.Split(new char[1] { '\n' });
			((Component)transform).GetComponent<TMP_Text>().text = string.Join("\n", array, 0, array.Length - 1);
		}
	}
	[HarmonyPatch(typeof(Player), "TryPlacePiece")]
	public class PlacePatch
	{
		[HarmonyPrefix]
		public static bool PlacePatch_Prefix(Player __instance, Piece piece)
		{
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			Logger.Log("TryPlacePiece | Prefix");
			if (ConfigurationFile.noBuildAroundAltarsRange.Value == 0f)
			{
				return true;
			}
			if ((Object)(object)piece == (Object)null)
			{
				return true;
			}
			OfferingBowl[] array = Object.FindObjectsByType<OfferingBowl>((FindObjectsSortMode)0);
			Logger.Log($"nearbyAltars: {array.Length}");
			OfferingBowl[] array2 = array;
			foreach (OfferingBowl val in array2)
			{
				if (!((Object)(object)val == (Object)null))
				{
					Logger.Log("Altar nearby: " + ((Object)val).name);
					float num = Vector3.Distance(((Component)__instance).transform.position, ((Component)val).transform.position);
					Logger.Log($"Altar distance from piece: {num:F1}m, range allowed = {ConfigurationFile.noBuildAroundAltarsRange.Value}m");
					if (num < ConfigurationFile.noBuildAroundAltarsRange.Value)
					{
						((Character)__instance).Message((MessageType)2, "$msg_nobuildzone", 0, (Sprite)null, false);
						return false;
					}
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Pickable), "Interact")]
	public class GoblinTotemRestrictionPatch
	{
		[HarmonyPrefix]
		public static bool GoblinTotemRestrictionPatch_Prefix(Pickable __instance, Humanoid character, bool repeat, bool alt)
		{
			Logger.Log("GoblinTotemRestrictionPatch_Interact_Prefix");
			if (!ConfigurationFile.restrictUsingKeyItems.Value)
			{
				return true;
			}
			if (((Object)__instance.m_itemPrefab).name.Equals("GoblinTotem"))
			{
				Player localPlayer = Player.m_localPlayer;
				if (!KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.Eikthyr))
				{
					((Character)localPlayer).Message((MessageType)2, ConfigurationFile.restrictUsingKeyItemsMessage.Value.Replace("{0}", BossNameEnum.Eikthyr.GetTranslatedName()), 0, (Sprite)null, false);
					Effects.scareEffect();
					return false;
				}
				if (!KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.TheElder))
				{
					((Character)localPlayer).Message((MessageType)2, ConfigurationFile.restrictUsingKeyItemsMessage.Value.Replace("{0}", BossNameEnum.TheElder.GetTranslatedName()), 0, (Sprite)null, false);
					Effects.scareEffect();
					return false;
				}
				if (!KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.Bonemass))
				{
					((Character)localPlayer).Message((MessageType)2, ConfigurationFile.restrictUsingKeyItemsMessage.Value.Replace("{0}", BossNameEnum.Bonemass.GetTranslatedName()), 0, (Sprite)null, false);
					Effects.scareEffect();
					return false;
				}
				if (!KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.Moder))
				{
					((Character)localPlayer).Message((MessageType)2, ConfigurationFile.restrictUsingKeyItemsMessage.Value.Replace("{0}", BossNameEnum.Moder.GetTranslatedName()), 0, (Sprite)null, false);
					Effects.scareEffect();
					return false;
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(OfferingBowl), "InitiateSpawnBoss")]
	public static class InitiateSpawnBossPatch
	{
		private static bool Prefix(OfferingBowl __instance, Vector3 point, bool removeItemsFromInventory)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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)
			Logger.Log("Detecting players around " + ConfigurationFile.minimumPlayersAroundRange.Value + " meters...");
			List<Player> list = new List<Player>();
			Vector3 position = ((Component)Player.m_localPlayer).transform.position;
			Player.GetPlayersInRange(position, ConfigurationFile.minimumPlayersAroundRange.Value, list);
			if (list.Count < ConfigurationFile.minimumPlayersAroundAmount.Value)
			{
				Logger.Log($"{list} players detected. Minimum required: {ConfigurationFile.minimumPlayersAroundAmount.Value}. Cancelling...");
				((Character)Player.m_localPlayer).Message((MessageType)2, ConfigurationFile.minimumPlayersAroundForbiddenMessage.Value.Replace("{0}", ConfigurationFile.minimumPlayersAroundAmount.Value.ToString()), 0, (Sprite)null, false);
				return false;
			}
			Logger.Log("No monsters detected.");
			if (ConfigurationFile.minLevelToSpawnBoss.Value && EpicMMOSystem_API.IsLoaded())
			{
				try
				{
					string name = ((Object)__instance.m_bossPrefab).name;
					object obj = GetMonsters()[name + "(Clone)"];
					if (obj != null)
					{
						int monsterLevel = GetMonsterLevel(obj);
						int value = ConfigurationFile.maxLevelGapBetweenBossAndPlayer.Value;
						int num = monsterLevel - value;
						if (EpicMMOSystem_API.GetLevel() < num)
						{
							((Character)Player.m_localPlayer).Message((MessageType)2, ConfigurationFile.minLevelToSpawnBossNotMet.Value.Replace("{0}", num.ToString()), 0, (Sprite)null, false);
							return false;
						}
						Logger.Log("Level enough to spawn.");
					}
				}
				catch (Exception ex)
				{
					Logger.LogWarning("Error when calculating monster level. Ignoring restriction. Error: " + ex);
				}
			}
			return true;
		}

		private static IDictionary GetMonsters()
		{
			Type type = Type.GetType("EpicMMOSystem.DataMonsters, EpicMMOSystem");
			if (type == null)
			{
				return new Dictionary<string, object>();
			}
			return type.GetField("dictionary", BindingFlags.Static | BindingFlags.NonPublic)?.GetValue(null) as IDictionary;
		}

		private static int GetMonsterLevel(object monster)
		{
			FieldInfo field = monster.GetType().GetField("level", BindingFlags.Instance | BindingFlags.Public);
			if (field != null)
			{
				return (int)field.GetValue(monster);
			}
			return 0;
		}
	}
	public class LevelCalculation
	{
		public static bool canSkillUp(float skillLevelValue)
		{
			return (KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.Eikthyr) || !(skillLevelValue >= (float)ConfigurationFile.maxLevelBeforeBoss1Eikthyr.Value)) && (KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.TheElder) || !(skillLevelValue >= (float)ConfigurationFile.maxLevelBeforeBoss2TheElder.Value)) && (KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.Bonemass) || !(skillLevelValue >= (float)ConfigurationFile.maxLevelBeforeBoss3Bonemass.Value)) && (KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.Moder) || !(skillLevelValue >= (float)ConfigurationFile.maxLevelBeforeBoss4Moder.Value)) && (KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.Yagluth) || !(skillLevelValue >= (float)ConfigurationFile.maxLevelBeforeBoss5Yagluth.Value)) && (KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.Queen) || !(skillLevelValue >= (float)ConfigurationFile.maxLevelBeforeBoss6Queen.Value)) && (KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.Fader) || !(skillLevelValue >= (float)ConfigurationFile.maxLevelBeforeBoss7Fader.Value)) && (KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.Kall) || !(skillLevelValue >= (float)ConfigurationFile.maxLevelBeforeBoss8Kall.Value));
		}

		private static float currentMaxSkillLevel()
		{
			if (KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.Kall))
			{
				return float.MaxValue;
			}
			if (KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.Fader))
			{
				return ConfigurationFile.maxLevelBeforeBoss8Kall.Value;
			}
			if (KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.Queen))
			{
				return ConfigurationFile.maxLevelBeforeBoss7Fader.Value;
			}
			if (KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.Yagluth))
			{
				return ConfigurationFile.maxLevelBeforeBoss6Queen.Value;
			}
			if (KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.Moder))
			{
				return ConfigurationFile.maxLevelBeforeBoss5Yagluth.Value;
			}
			if (KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.Bonemass))
			{
				return ConfigurationFile.maxLevelBeforeBoss4Moder.Value;
			}
			if (KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.TheElder))
			{
				return ConfigurationFile.maxLevelBeforeBoss3Bonemass.Value;
			}
			if (KillMeForMyPowerUtils.HasDefeatedBossName(BossNameEnum.Eikthyr))
			{
				return ConfigurationFile.maxLevelBeforeBoss2TheElder.Value;
			}
			return ConfigurationFile.maxLevelBeforeBoss1Eikthyr.Value;
		}

		public static bool reviewAndUpdateSkill(Player player, SkillType skillType, string buffName)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			Skill val = ((Character)player).GetSkills().GetSkillList().Find((Skill s) => s.m_info.m_skill == skillType);
			if (val == null)
			{
				return true;
			}
			int num = (int)val.m_level;
			float num2 = (float)num + val.GetLevelPercentage();
			float num3 = currentMaxSkillLevel();
			bool flag = num2 < num3;
			Logger.Log($"Decision with skill {skillType}, skillLevel {num}, percentage {val.GetLevelPercentage()} and currentLevel {num2}: {flag}");
			if (!flag)
			{
				val.m_level = Math.Min(num, num3);
				val.m_accumulator = 0f;
				Logger.Log($"{skillType} rounded to max allowed value: {val.m_level}");
				if (GameManager.isDetailedLevelsInstalled())
				{
					Logger.Log("Checking DetailedLevels buff...");
					List<StatusEffect> list = (List<StatusEffect>)GameManager.GetPrivateValue(((Character)Player.m_localPlayer).GetSEMan(), "m_statusEffects");
					StatusEffect val2 = list.Find((StatusEffect effect) => effect.m_name.Contains(buffName));
					if ((Object)(object)val2 != (Object)null)
					{
						Logger.Log("Fixing value in buff");
						val2.m_name = $"{buffName}: {val.m_level}";
					}
				}
			}
			return flag;
		}
	}
	[HarmonyPatch(typeof(Player), "RaiseSkill")]
	public class Player_RaiseSkill_Prefix_Patch
	{
		private unsafe static bool Prefix(Player __instance, SkillType skill, float value)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance != (Object)null)
			{
				float skillLevel = ((Character)__instance).GetSkills().GetSkillLevel(skill);
				Logger.Log($"Checking skill level availability {skill} with {skillLevel}...");
				if (skillLevel < 100f)
				{
					return LevelCalculation.reviewAndUpdateSkill(__instance, skill, "$skill_" + ((object)(*(SkillType*)(&skill))/*cast due to .constrained prefix*/).ToString().ToLower());
				}
			}
			return true;
		}
	}
	[HarmonyPatch]
	[HarmonyPriority(700)]
	public class Dodge_ManualUpdate_Patch
	{
		private static MethodBase TargetMethod()
		{
			return AccessTools.Method(typeof(Player), "Dodge", (Type[])null, (Type[])null);
		}

		private static void Postfix(ref Player __instance, Vector3 dodgeDir)
		{
			Logger.Log("Checking dodge skill here since it doesn't seem to go through Player.RaiseSkill...");
			WaitForSecondsAsync(__instance, 0.1f);
		}

		private static async Task WaitForSecondsAsync(Player player, float seconds)
		{
			await Task.Delay((int)(Math.Max(0f, seconds) * 1000f));
			LevelCalculation.reviewAndUpdateSkill(player, (SkillType)108, "$skill_dodge");
		}
	}
	[HarmonyPatch(typeof(Character), "Damage")]
	public class BloodMagic_ManualUpdate_Patch
	{
		private static void Postfix(Character __instance, HitData hit)
		{
			if (!((Object)(object)__instance != (Object)null))
			{
				return;
			}
			Character attacker = hit.GetAttacker();
			if (!((Object)(object)attacker != (Object)null))
			{
				return;
			}
			if (attacker.IsTamed() && __instance.IsMonsterFaction(0f))
			{
				WaitForSecondsAsync(null, 0.1f);
			}
			else if (attacker.IsMonsterFaction(0f) && ((object)__instance).GetType() == typeof(Player))
			{
				WaitForSecondsAsync((Player)(object)((__instance is Player) ? __instance : null), 0.1f);
			}
			else if (((Object)attacker).name.Contains("Troll_Summoned"))
			{
				if (((object)__instance).GetType() == typeof(Player))
				{
					WaitForSecondsAsync((Player)(object)((__instance is Player) ? __instance : null), 0.1f);
				}
				else if (__instance.IsTamed())
				{
					WaitForSecondsAsync(null, 0.1f);
				}
			}
		}

		private static async Task WaitForSecondsAsync(Player player, float seconds)
		{
			Logger.Log("Checking blood magic here since it doesn't seem to go through Player.RaiseSkill...");
			await Task.Delay((int)(Math.Max(0f, seconds) * 1000f));
			LevelCalculation.reviewAndUpdateSkill(((Object)(object)player == (Object)null) ? Player.m_localPlayer : player, (SkillType)10, "$skill_bloodmagic");
		}
	}
	[HarmonyPatch(typeof(SkillsDialog), "Setup")]
	[HarmonyPriority(100)]
	public class SkillsDialogAdditions_Patch
	{
		private static void Postfix(SkillsDialog __instance, ref Player player, ref List<GameObject> ___m_elements)
		{
			//IL_003a: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			List<Skill> skillList = ((Character)player).GetSkills().GetSkillList();
			for (int i = 0; i < skillList.Count; i++)
			{
				GameObject val = ___m_elements[i];
				Skill val2 = skillList[i];
				Color color = (LevelCalculation.canSkillUp((int)val2.m_level) ? Color.white : Color.red);
				((Component)Utils.FindChild(val.transform, "leveltext", (IterativeSearchType)0)).GetComponent<TMP_Text>().color = color;
			}
		}
	}
	public class TraderSetup
	{
		private enum RestrictionType
		{
			Boss,
			GlobalKey,
			PlayerKey
		}

		[HarmonyPatch(typeof(Trader), "Interact")]
		public class TraderInteractPatch
		{
			[HarmonyPrefix]
			public static bool InteractPrefix(Trader __instance, Humanoid character, bool hold, bool alt)
			{
				Logger.Log("**Trader.Interact called for " + ((Object)((Component)__instance).gameObject).name);
				if (!ConfigurationFile.vendorLocalRestrictions.Value)
				{
					return true;
				}
				if (!grantedVendor(__instance))
				{
					string mandatoryBossToKill = getMandatoryBossToKill(__instance);
					if (mandatoryBossToKill != null)
					{
						((Character)character).Message((MessageType)2, ConfigurationFile.forbiddenVendorMessage.Value.Replace("{0}", mandatoryBossToKill), 0, (Sprite)null, false);
						return false;
					}
				}
				return true;
			}

			private static string getMandatoryBossToKill(Trader trader)
			{
				if (((Object)((Component)trader).gameObject).name.StartsWith("Haldor") && ConfigurationFile.vendorHaldorBossToKill.Value != BossNameEnum.None)
				{
					return Localization.instance.Localize(KillMeForMyPowerUtils.getBossNameTranslation(ConfigurationFile.vendorHaldorBossToKill.Value));
				}
				if (((Object)((Component)trader).gameObject).name.StartsWith("Hildir") && ConfigurationFile.vendorHildirBossToKill.Value != BossNameEnum.None)
				{
					return Localization.instance.Localize(KillMeForMyPowerUtils.getBossNameTranslation(ConfigurationFile.vendorHildirBossToKill.Value));
				}
				if (((Object)((Component)trader).gameObject).name.StartsWith("BogWitch") && ConfigurationFile.vendorBogWitchBossToKill.Value != BossNameEnum.None)
				{
					return Localization.instance.Localize(KillMeForMyPowerUtils.getBossNameTranslation(ConfigurationFile.vendorBogWitchBossToKill.Value));
				}
				return null;
			}

			private static bool grantedVendor(Trader trader)
			{
				bool flag = ((Object)((Component)trader).gameObject).name.StartsWith("Haldor") && KillMeForMyPowerUtils.bossIsKilled(ConfigurationFile.vendorHaldorBossToKill.Value);
				bool flag2 = ((Object)((Component)trader).gameObject).name.StartsWith("Hildir") && KillMeForMyPowerUtils.bossIsKilled(ConfigurationFile.vendorHildirBossToKill.Value);
				bool flag3 = ((Object)((Component)trader).gameObject).name.StartsWith("BogWitch") && KillMeForMyPowerUtils.bossIsKilled(ConfigurationFile.vendorBogWitchBossToKill.Value);
				return flag || flag2 || flag3;
			}
		}

		[HarmonyPatch(typeof(Trader), "GetAvailableItems")]
		public class TraderGetAvailableItemsPatch
		{
			[HarmonyPriority(700)]
			private static void Prefix(Trader __instance, out List<TradeItem> __state)
			{
				__state = new List<TradeItem>();
				if (!ConfigurationFile.vendorLocalRestrictions.Value)
				{
					return;
				}
				foreach (TradeItem item in __state)
				{
					if (!string.IsNullOrEmpty(item.m_requiredGlobalKey))
					{
						CollectionExtensions.AddItem<TradeItem>((IEnumerable<TradeItem>)__state, item);
					}
				}
			}

			[HarmonyPriority(100)]
			private static void Postfix(Trader __instance, List<TradeItem> __state, ref List<TradeItem> __result)
			{
				Logger.Log("**Trader.GetAvailableItems called for " + ((Object)((Component)__instance).gameObject).name);
				if (!ConfigurationFile.vendorLocalRestrictions.Value)
				{
					return;
				}
				__result.AddRange(__state);
				Logger.Log("- Checking list:");
				foreach (TradeItem item in __result)
				{
					string text = (((Object)(object)item.m_prefab != (Object)null) ? ((Object)((Component)item.m_prefab).gameObject).name : item.m_name);
					Logger.Log("- " + text);
				}
				List<TradeItem> list = new List<TradeItem>();
				if (((Object)__instance).name.Contains("Haldor"))
				{
					addCustomItemsToRemove(__result, list, ConfigurationFile.vendorHaldorRestrictionsGlobalKeys.Value, RestrictionType.GlobalKey);
					addCustomItemsToRemove(__result, list, ConfigurationFile.vendorHaldorRestrictionsPlayerKeys.Value, RestrictionType.PlayerKey);
					addCustomItemsToRemove(__result, list, ConfigurationFile.vendorHaldorRestrictionsBosses.Value, RestrictionType.Boss);
				}
				else if (((Object)__instance).name.Contains("Hildir"))
				{
					addCustomItemsToRemove(__result, list, ConfigurationFile.vendorHildirRestrictionsGlobalKeys.Value, RestrictionType.GlobalKey);
					addCustomItemsToRemove(__result, list, ConfigurationFile.vendorHildirRestrictionsPlayerKeys.Value, RestrictionType.PlayerKey);
					addCustomItemsToRemove(__result, list, ConfigurationFile.vendorHildirRestrictionsBosses.Value, RestrictionType.Boss);
				}
				else if (((Object)__instance).name.Contains("BogWitch"))
				{
					addCustomItemsToRemove(__result, list, ConfigurationFile.vendorBogWitchRestrictionsGlobalKeys.Value, RestrictionType.GlobalKey);
					addCustomItemsToRemove(__result, list, ConfigurationFile.vendorBogWitchRestrictionsPlayerKeys.Value, RestrictionType.PlayerKey);
					addCustomItemsToRemove(__result, list, ConfigurationFile.vendorBogWitchRestrictionsBosses.Value, RestrictionType.Boss);
				}
				foreach (TradeItem item2 in list)
				{
					__result.Remove(item2);
				}
			}

			private static void addCustomItemsToRemove(List<TradeItem> __result, List<TradeItem> customItemsToRemove, string restrictions, RestrictionType restrictionType)
			{
				if (string.IsNullOrEmpty(restrictions))
				{
					return;
				}
				Logger.Log("Checking restriction by " + restrictionType);
				string[] array = restrictions.Split(new char[1] { ';' });
				string[] array2 = array;
				foreach (string text in array2)
				{
					string[] array3 = text.Split(new char[1] { ',' });
					Logger.Log("Checking vendor item " + array3[0] + " against " + array3[1]);
					foreach (TradeItem item in __result)
					{
						string text2 = (((Object)(object)item.m_prefab != (Object)null) ? ((Object)((Component)item.m_prefab).gameObject).name : item.m_name);
						if (text2 == array3[0])
						{
							if ((restrictionType == RestrictionType.Boss && !KillMeForMyPowerUtils.bossIsKilled(array3[1])) || (restrictionType == RestrictionType.GlobalKey && !ZoneSystem.instance.GetGlobalKeys().Contains(array3[1])) || (restrictionType == RestrictionType.PlayerKey && !((Humanoid)Player.m_localPlayer).HaveUniqueKey(array3[1])))
							{
								customItemsToRemove.Add(item);
								Logger.Log($"{array3[0]} will be excluded by missing {restrictionType} {array3[1]}.");
							}
							else
							{
								Logger.Log(array3[0] + " will NOT be excluded.");
							}
							break;
						}
					}
				}
			}
		}

		[HarmonyPatch(typeof(Vegvisir), "Interact")]
		public class HildirMapTablePatch
		{
			public static bool Prefix(Vegvisir __instance, Humanoid character, bool hold, bool alt, ref bool __result)
			{
				if (character is Player && __instance.m_locations.FindAll((VegvisrLocation loc) => (int)loc.m_pinType == 14 || (int)loc.m_pinType == 15 || (int)loc.m_pinType == 16).Count > 0 && !KillMeForMyPowerUtils.HasDefeatedBossName(ConfigurationFile.vendorHildirBossToKill.Value))
				{
					((Character)character).Message((MessageType)2, ConfigurationFile.restrictUsingKeyItemsMessage.Value.Replace("{0}", ConfigurationFile.vendorHildirBossToKill.Value.GetTranslationKey()), 0, (Sprite)null, false);
					Effects.scareEffect();
					__result = false;
					return false;
				}
				return true;
			}
		}
	}
}
namespace KillMeForMyPower.Restrictions.BossNameManagement
{
	public enum BossNameEnum
	{
		[BossNameAttr("Eikthyr", "GP_Eikthyr", "$enemy_eikthyr", "playerListForBoss1EikthyrPower")]
		Eikthyr,
		[BossNameAttr("gd_king", "GP_TheElder", "$enemy_gdking", "playerListForBoss2TheElderPower")]
		TheElder,
		[BossNameAttr("Bonemass", "GP_Bonemass", "$enemy_bonemass", "playerListForBoss3BonemassPower")]
		Bonemass,
		[BossNameAttr("Dragon", "GP_Moder", "$enemy_dragon", "playerListForBoss4ModerPower")]
		Moder,
		[BossNameAttr("GoblinKing", "GP_Yagluth", "$enemy_goblinking", "playerListForBoss5YagluthPower")]
		Yagluth,
		[BossNameAttr("SeekerQueen", "GP_Queen", "$enemy_seekerqueen", "playerListForBoss6QueenPower")]
		Queen,
		[BossNameAttr("Fader", "GP_Fader", "$enemy_fader", "playerListForBoss7FaderPower")]
		Fader,
		[BossNameAttr("FrozenKing_p3", null, "$enemy_frozenking", "playerListForBoss8KallPower")]
		Kall,
		[BossNameAttr(null, null, null, null)]
		None,
		[BossNameAttr("BossGorr_TW", "SE_Boss_Gorr", "Gorr", "playerListForBoss8TherzieGorrPower")]
		SE_Boss_Gorr,
		[BossNameAttr("BossBrutalis_TW", "SE_Boss_Brutalis", "Brutalis", "playerListForBoss8TherzieBrutalisPower")]
		SE_Boss_Brutalis,
		[BossNameAttr("BossStormHerald_TW", "SE_Boss_StormHerald", "StormHerald", "playerListForBoss8TherzieStormHeraldPower")]
		SE_Boss_StormHerald,
		[BossNameAttr("BossSythrak_TW", "SE_Boss_Sythrak", "Sythrak", "playerListForBoss8TherzieSythrakPower")]
		SE_Boss_Sythrak
	}
	internal class BossNameAttr : Attribute
	{
		public string prefabBossName { get; private set; }

		public string translationKey { get; private set; }

		public string powerKey { get; private set; }

		public string configurationListName { get; private set; }

		internal BossNameAttr(string prefabBossName, string powerKey, string translationKey, string configurationListName)
		{
			this.prefabBossName = prefabBossName;
			this.powerKey = powerKey;
			this.translationKey = translationKey;
			this.configurationListName = configurationListName;
		}
	}
	public static class BossNameFields
	{
		public static string GetGrantedPlayerNamesList(this BossNameEnum p)
		{
			BossNameAttr attr = GetAttr(p);
			return ((ConfigEntry<string>)(typeof(ConfigurationFile).GetField(attr.configurationListName, BindingFlags.Static | BindingFlags.Public)?.GetValue(null)))?.Value;
		}

		public static string GetFightBossname(this BossNameEnum p)
		{
			BossNameAttr attr = GetAttr(p);
			return attr.prefabBossName;
		}

		public static string GetTranslationKey(this BossNameEnum p)
		{
			BossNameAttr attr = GetAttr(p);
			return attr.translationKey;
		}

		public static string GetTranslatedName(this BossNameEnum p)
		{
			BossNameAttr attr = GetAttr(p);
			return Localization.instance.Localize(attr.translationKey);
		}

		public static string GetPowerKey(this BossNameEnum p)
		{
			BossNameAttr attr = GetAttr(p);
			return attr.powerKey;
		}

		public static string GetConfigurationListName(this BossNameEnum p)
		{
			BossNameAttr attr = GetAttr(p);
			return attr.configurationListName;
		}

		private static BossNameAttr GetAttr(BossNameEnum p)
		{
			return (BossNameAttr)Attribute.GetCustomAttribute(ForValue(p), typeof(BossNameAttr));
		}

		private static MemberInfo ForValue(BossNameEnum p)
		{
			return typeof(BossNameEnum).GetField(Enum.GetName(typeof(BossNameEnum), p));
		}
	}
	public static class BossNameUtils
	{
		public static void GrantBossPowerToPlayer(BossNameEnum bossNameEnum, string playerName, bool isAdd)
		{
			if (bossNameEnum != BossNameEnum.None)
			{
				UpdateConfigurationGrantedPlayersList(bossNameEnum, playerName, isAdd);
				Logger.LogInfo("Player " + playerName + " " + (isAdd ? "defeated" : "removed") + $" {bossNameEnum}.");
			}
		}

		public static bool IsBossPowerGrantedForPlayer(BossNameEnum bossNameEnum, Player player)
		{
			string grantedPlayerNamesList = bossNameEnum.GetGrantedPlayerNamesList();
			return grantedPlayerNamesList.Contains(player.GetPlayerName());
		}

		[MethodImpl(MethodImplOptions.Synchronized)]
		public static void UpdateConfigurationGrantedPlayersList(BossNameEnum bossNameEnum, string playerName, bool isAdd)
		{
			string grantedPlayerNamesList = bossNameEnum.GetGrantedPlayerNamesList();
			if ((isAdd && grantedPlayerNamesList.Contains(playerName)) || (!isAdd && !grantedPlayerNamesList.Contains(playerName)))
			{
				return;
			}
			string text;
			if (!string.IsNullOrEmpty(grantedPlayerNamesList))
			{
				string[] collection = grantedPlayerNamesList.Split(new char[1] { ',' });
				List<string> list = new List<string>(collection);
				if (isAdd)
				{
					list.Add(playerName);
				}
				else
				{
					list.Remove(playerName);
				}
				list.Sort();
				text = string.Join(",", list.ToArray());
			}
			else
			{
				text = (isAdd ? playerName : "");
			}
			Logger.Log("Result to save: " + text);
			switch (bossNameEnum)
			{
			case BossNameEnum.Eikthyr:
				ConfigurationFile.playerListForBoss1EikthyrPower.Value = text;
				break;
			case BossNameEnum.TheElder:
				ConfigurationFile.playerListForBoss2TheElderPower.Value = text;
				break;
			case BossNameEnum.Bonemass:
				ConfigurationFile.playerListForBoss3BonemassPower.Value = text;
				break;
			case BossNameEnum.Moder:
				ConfigurationFile.playerListForBoss4ModerPower.Value = text;
				break;
			case BossNameEnum.Yagluth:
				ConfigurationFile.playerListForBoss5YagluthPower.Value = text;
				break;
			case BossNameEnum.Queen:
				ConfigurationFile.playerListForBoss6QueenPower.Value = text;
				break;
			case BossNameEnum.Fader:
				ConfigurationFile.playerListForBoss7FaderPower.Value = text;
				break;
			case BossNameEnum.Kall:
				ConfigurationFile.playerListForBoss8KallPower.Value = text;
				break;
			case BossNameEnum.SE_Boss_Gorr:
				ConfigurationFile.playerListForBoss8TherzieGorrPower.Value = text;
				break;
			case BossNameEnum.SE_Boss_Brutalis:
				ConfigurationFile.playerListForBoss8TherzieBrutalisPower.Value = text;
				break;
			case BossNameEnum.SE_Boss_StormHerald:
				ConfigurationFile.playerListForBoss8TherzieStormHeraldPower.Value = text;
				break;
			case BossNameEnum.SE_Boss_Sythrak:
				ConfigurationFile.playerListForBoss8TherzieSythrakPower.Value = text;
				break;
			default:
				Logger.LogWarning("Not saved, boss not found!");
				break;
			}
		}
	}
	[HarmonyPatch(typeof(Game), "Start")]
	public class GameStartPatch
	{
		private static void Prefix()
		{
			ZRoutedRpc.instance.Register<string, string>("RPC_BossPowerGrantServer", (Action<long, string, string>)RPC_BossPowerGrantCalls.RPC_BossPowerGrantServer);
			ZRoutedRpc.instance.Register<string, string>("RPC_BossPowerRemoveGrantServer", (Action<long, string, string>)RPC_BossPowerGrantCalls.RPC_BossPowerRemoveGrantServer);
		}
	}
}
namespace KillMeForMyPower.Managers
{
	public static class EpicMMOSystem_API
	{
		private enum API_State
		{
			NotReady,
			NotInstalled,
			Ready
		}

		public enum Attribut
		{
			Strength,
			Agility,
			Intellect,
			Body,
			Vigour,
			Special
		}

		private static API_State state;

		private static MethodInfo eGetLevel;

		private static MethodInfo eAddExp;

		private static MethodInfo eGetAttribute;

		private static MethodInfo eGetAttributeRusty;

		private static MethodInfo eSetSingleRate;

		public static bool IsLoaded()
		{
			Init();
			return state == API_State.Ready;
		}

		public static int GetLevel()
		{
			int result = 0;
			Init();
			if (eGetLevel != null)
			{
				result = (int)eGetLevel.Invoke(null, null);
			}
			return result;
		}

		public static int GetAttribute(Attribut attribute)
		{
			int result = 0;
			Init();
			if (eGetAttribute != null)
			{
				result = (int)eGetAttribute.Invoke(null, new object[1] { attribute });
			}
			return result;
		}

		public static int GetAttributeRusty(string attribute)
		{
			int result = 0;
			Init();
			if (eGetAttributeRusty != null)
			{
				result = (int)eGetAttributeRusty.Invoke(null, new object[1] { attribute });
			}
			return result;
		}

		public static void AddExp(int value)
		{
			Init();
			eAddExp?.Invoke(null, new object[1] { value });
		}

		public static void SetSingleRate(float rate)
		{
			Init();
			eSetSingleRate?.Invoke(null, new object[1] { rate });
		}

		private static void Init()
		{
			API_State aPI_State = state;
			if ((uint)(aPI_State - 1) > 1u)
			{
				if (Type.GetType("EpicMMOSystem.EpicMMOSystem, EpicMMOSystem") == null)
				{
					state = API_State.NotInstalled;
					return;
				}
				state = API_State.Ready;
				Type type = Type.GetType("API.EMMOS_API, EpicMMOSystem");
				eGetLevel = type?.GetMethod("GetLevel", BindingFlags.Static | BindingFlags.Public);
				eAddExp = type?.GetMethod("AddExp", BindingFlags.Static | BindingFlags.Public);
				eGetAttribute = type?.GetMethod("GetAttribute", BindingFlags.Static | BindingFlags.Public);
				eGetAttributeRusty = type?.GetMethod("GetAttribute", BindingFlags.Static | BindingFlags.Public);
				eSetSingleRate = type?.GetMethod("SetSingleRate", BindingFlags.Static | BindingFlags.Public);
			}
		}
	}
	public class GameManager
	{
		public static object GetPrivateValue(object obj, string name, BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic)
		{
			return obj.GetType().GetField(name, bindingAttr)?.GetValue(obj);
		}

		public static object GetPrivateMethod(object obj, string name, BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic)
		{
			return obj.GetType().GetMethod(name, bindingAttr)?.Invoke(obj, null);
		}

		public static bool isDetailedLevelsInstalled()
		{
			return Chainloader.PluginInfos.ContainsKey("Turbero.DetailedLevels");
		}

		public static bool IsAdmin(Player player)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			Logger.Log("[IsAdmin] Checking powerCommandsAdminPlayersList...");
			string playerName = player.GetPlayerName();
			Logger.Log("[IsAdmin] Finding All PlayerInfo...");
			List<PlayerInfo> list = ZNet.instance.GetPlayerList().FindAll((PlayerInfo p) => p.m_name == playerName);
			if (list.Count == 0)
			{
				return false;
			}
			string userID = list[0].m_userInfo.m_id.m_userID;
			Logger.Log("[IsAdmin] Matching steamID " + userID + " in adminList...");
			return (Object)(object)ZNet.instance != (Object)null && ZNet.instance.GetAdminList() != null && ZNet.instance.GetAdminList().Contains(userID);
		}
	}
}
namespace KillMeForMyPower.Commands
{
	public class PowerManagementCommands
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static ConsoleEvent <>9__0_0;

			public static ConsoleEvent <>9__0_1;

			internal void <RegisterConsoleCommand>b__0_0(ConsoleEventArgs args)
			{
				if (!GameManager.IsAdmin(Player.m_localPlayer))
				{
					args.Context.AddString("You are not an admin.");
					return;
				}
				if (args.Args.Length < 3)
				{
					args.Context.AddString("Usage: add_power <name> <boss_name>");
					return;
				}
				ZRoutedRpc.instance.InvokeRoutedRPC(0L, "RPC_BossPowerGrantServer", new object[2]
				{
					args.Args[2],
					args.Args[1]
				});
			}

			internal void <RegisterConsoleCommand>b__0_1(ConsoleEventArgs args)
			{
				if (!GameManager.IsAdmin(Player.m_localPlayer))
				{
					args.Context.AddString("You are not an admin.");
					return;
				}
				if (args.Args.Length < 3)
				{
					args.Context.AddString("Usage: add_power <name> <boss_name>");
					return;
				}
				ZRoutedRpc.instance.InvokeRoutedRPC(0L, "RPC_BossPowerRemoveGrantServer", new object[2]
				{
					args.Args[2],
					args.Args[1]
				});
			}
		}

		public static void RegisterConsoleCommand()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			object obj = <>c.<>9__0_0;
			if (obj == null)
			{
				ConsoleEvent val = delegate(ConsoleEventArgs args)
				{
					if (!GameManager.IsAdmin(Player.m_localPlayer))
					{
						args.Context.AddString("You are not an admin.");
					}
					else if (args.Args.Length < 3)
					{
						args.Context.AddString("Usage: add_power <name> <boss_name>");
					}
					else
					{
						ZRoutedRpc.instance.InvokeRoutedRPC(0L, "RPC_BossPowerGrantServer", new object[2]
						{
							args.Args[2],
							args.Args[1]
						});
					}
				};
				<>c.<>9__0_0 = val;
				obj = (object)val;
			}
			new ConsoleCommand("add_power", "[player] [boss_name]", (ConsoleEvent)obj, false, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
			object obj2 = <>c.<>9__0_1;
			if (obj2 == null)
			{
				ConsoleEvent val2 = delegate(ConsoleEventArgs args)
				{
					if (!GameManager.IsAdmin(Player.m_localPlayer))
					{
						args.Context.AddString("You are not an admin.");
					}
					else if (args.Args.Length < 3)
					{
						args.Context.AddString("Usage: add_power <name> <boss_name>");
					}
					else
					{
						ZRoutedRpc.instance.InvokeRoutedRPC(0L, "RPC_BossPowerRemoveGrantServer", new object[2]
						{
							args.Args[2],
							args.Args[1]
						});
					}
				};
				<>c.<>9__0_1 = val2;
				obj2 = (object)val2;
			}
			new ConsoleCommand("remove_power", "[boss_order] [player]", (ConsoleEvent)obj2, false, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
		}
	}
	public class CheckBossesCommand
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static ConsoleEvent <>9__0_0;

			internal void <RegisterConsoleCommand>b__0_0(ConsoleEventArgs args)
			{
				bool flag = false;
				string playerName = Player.m_localPlayer.GetPlayerName();
				args.Context.AddString("=== Bosses killed and allowed to use their powers ===");
				foreach (BossNameEnum value in Enum.GetValues(typeof(BossNameEnum)))
				{
					if (!string.IsNullOrEmpty(value.GetConfigurationListName()))
					{
						string grantedPlayerNamesList = value.GetGrantedPlayerNamesList();
						if ((!string.IsNullOrEmpty(grantedPlayerNamesList) && grantedPlayerNamesList.Contains(playerName)) || (ConfigurationFile.activateMidPlayDetection.Value && ((Humanoid)Player.m_localPlayer).HaveUniqueKey(value.GetPowerKey())))
						{
							args.Context.AddString("- " + Localization.instance.Localize(value.GetTranslationKey()));
							flag = true;
						}
					}
				}
				if (!flag)
				{
					args.Context.AddString("NONE");
				}
			}
		}

		public static void RegisterConsoleCommand()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			object obj = <>c.<>9__0_0;
			if (obj == null)
			{
				ConsoleEvent val = delegate(ConsoleEventArgs args)
				{
					bool flag = false;
					string playerName = Player.m_localPlayer.GetPlayerName();
					args.Context.AddString("=== Bosses killed and allowed to use their powers ===");
					foreach (BossNameEnum value in Enum.GetValues(typeof(BossNameEnum)))
					{
						if (!string.IsNullOrEmpty(value.GetConfigurationListName()))
						{
							string grantedPlayerNamesList = value.GetGrantedPlayerNamesList();
							if ((!string.IsNullOrEmpty(grantedPlayerNamesList) && grantedPlayerNamesList.Contains(playerName)) || (ConfigurationFile.activateMidPlayDetection.Value && ((Humanoid)Player.m_localPlayer).HaveUniqueKey(value.GetPowerKey())))
							{
								args.Context.AddString("- " + Localization.instance.Localize(value.GetTranslationKey()));
								flag = true;
							}
						}
					}
					if (!flag)
					{
						args.Context.AddString("NONE");
					}
				};
				<>c.<>9__0_0 = val;
				obj = (object)val;
			}
			new ConsoleCommand("bosses_permissions", "", (ConsoleEvent)obj, false, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
		}
	}
}
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ServerSync
{
	[PublicAPI]
	internal abstract class OwnConfigEntryBase
	{
		public object? LocalBaseValue;

		public bool SynchronizedConfig = true;

		public abstract ConfigEntryBase BaseConfig { get; }
	}
	[PublicAPI]
	internal class SyncedConfigEntry<T>(ConfigEntry<T> sourceConfig) : OwnConfigEntryBase()
	{
		public readonly ConfigEntry<T> SourceConfig = sourceConfig;

		public override ConfigEntryBase BaseConfig => (ConfigEntryBase)(object)SourceConfig;

		public T Value
		{
			get
			{
				return SourceConfig.Value;
			}
			set
			{
				SourceConfig.Value = value;
			}
		}

		public void AssignLocalValue(T value)
		{
			if (LocalBaseValue == null)
			{
				Value = value;
			}
			else
			{
				LocalBaseValue = value;
			}
		}
	}
	internal abstract class CustomSyncedValueBase
	{
		public object? LocalBaseValue;

		public readonly string Identifier;

		public readonly Type Type;

		private object? boxedValue;

		protected bool localIsOwner;

		public readonly int Priority;

		public object? BoxedValue
		{
			get
			{
				return boxedValue;
			}
			set
			{
				boxedValue = value;
				this.ValueChanged?.Invoke();
			}
		}

		public event Action? ValueChanged;

		protected CustomSyncedValueBase(ConfigSync configSync, string identifier, Type type, int priority)
		{
			Priority = priority;
			Identifier = identifier;
			Type = type;
			configSync.AddCustomValue(this);
			localIsOwner = configSync.IsSourceOfTruth;
			configSync.SourceOfTruthChanged += delegate(bool truth)
			{
				localIsOwner = truth;
			};
		}
	}
	[PublicAPI]
	internal sealed class CustomSyncedValue<T> : CustomSyncedValueBase
	{
		public T Value
		{
			get
			{
				return (T)base.BoxedValue;
			}
			set
			{
				base.BoxedValue = value;
			}
		}

		public CustomSyncedValue(ConfigSync configSync, string identifier, T value = default(T), int priority = 0)
			: base(configSync, identifier, typeof(T), priority)
		{
			Value = value;
		}

		public void AssignLocalValue(T value)
		{
			if (localIsOwner)
			{
				Value = value;
			}
			else
			{
				LocalBaseValue = value;
			}
		}
	}
	internal class ConfigurationManagerAttributes
	{
		[UsedImplicitly]
		public bool? ReadOnly = false;
	}
	[PublicAPI]
	internal class ConfigSync
	{
		[HarmonyPatch(typeof(ZRpc), "HandlePackage")]
		private static class SnatchCurrentlyHandlingRPC
		{
			public static ZRpc? currentRpc;

			[HarmonyPrefix]
			private sta