Decompiled source of PEAK Blow Darts v2.0.0

tony4twentys-PEAK Blow Darts.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using ExitGames.Client.Photon;
using HarmonyLib;
using Peak;
using Peak.Afflictions;
using Photon.Pun;
using Photon.Realtime;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyTitle("PEAK Blow Darts")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PEAK Blow Darts")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("1bf01cad-9d92-4c56-aa0d-03fd3b28b670")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.0.0.0")]
[module: UnverifiableCode]
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace PEAK_Blow_Darts
{
	internal struct DartParam
	{
		public string Label;

		public ConfigEntry<float> Entry;

		public float DefaultValue;

		public float Min;

		public float Max;
	}
	internal struct DartTypeInfo
	{
		public BlowDartType Type;

		public string Id;

		public string Name;

		public bool DefaultEnable;

		public float DefaultChance;

		public ConfigEntry<bool> Enable;

		public ConfigEntry<float> Chance;

		public DartParam[] Params;
	}
	public enum BlowDartType
	{
		Unmodified,
		Injury,
		Poison,
		Cold,
		Hunger,
		Drowsy,
		Curse,
		Hot,
		Crab,
		InfiniteStamina,
		ExtraStamina,
		FasterBoi,
		AfflictionClearer,
		Chaos,
		Invincibility,
		Weight,
		Thorns,
		Spores,
		Web,
		Arrow,
		Petrify,
		FlyTrap,
		Blind,
		Numb,
		Exhausted,
		HealAll,
		HungerBlock,
		Sunscreen,
		LowGravity,
		ClimbingChalk,
		DoubleJump,
		BeetleBonk,
		Bonk,
		AntiSphere,
		Scorpion,
		Tornado,
		Frog,
		BookOfBones,
		BeeSwarm,
		Explosive,
		Warp,
		Tick,
		Summon,
		RocketPack,
		FrogTongue
	}
	public static class BlowDartDataEntryKey
	{
		public static readonly DataEntryKey DartType = (DataEntryKey)181;
	}
	internal enum DartMenuTab
	{
		Positive,
		Negative,
		Extra
	}
	[BepInPlugin("tony4twentys.PEAK_Blow_Darts", "Peak Blow Darts", "2.0.0")]
	public class PEAKBlowDartsPlugin : BaseUnityPlugin
	{
		private struct DartRoll
		{
			public BlowDartType Type;

			public ConfigEntry<bool> Enable;

			public ConfigEntry<float> Chance;
		}

		[HarmonyPatch(typeof(Item), "Start")]
		private static class Item_Start_Patch
		{
			private static void Postfix(Item __instance)
			{
				try
				{
					TryHandleBlowDart(__instance);
				}
				catch (Exception ex)
				{
					LogOnce(ref _loggedItemStartError, "Item.Start postfix failed", ex);
				}
			}
		}

		[HarmonyPatch(typeof(Item), "SetItemInstanceDataRPC")]
		private static class Item_SetItemInstanceDataRPC_Patch
		{
			private static void Postfix(Item __instance)
			{
				try
				{
					if (TryGetDartType(__instance, null, out var dartType))
					{
						ApplyDartType(__instance, dartType);
					}
				}
				catch (Exception ex)
				{
					LogOnce(ref _loggedSyncError, "SetItemInstanceDataRPC postfix failed", ex);
				}
			}
		}

		[HarmonyPatch(typeof(Item), "GetItemName")]
		private static class Item_GetItemName_Patch
		{
			private static void Postfix(Item __instance, ItemInstanceData data, ref string __result)
			{
				try
				{
					if (NetworkSync.ShouldApplyModEffects() && TryGetDartType(__instance, data, out var dartType) && dartType != BlowDartType.Unmodified)
					{
						__result = GetDartName(dartType);
					}
				}
				catch (Exception ex)
				{
					LogOnce(ref _loggedGetItemNameError, "Item.GetItemName postfix failed", ex);
				}
			}
		}

		[HarmonyPatch(typeof(Action_RaycastDart), "RPC_DartImpact")]
		private static class Action_RaycastDart_RPC_DartImpact_Patch
		{
			private static void Postfix(Action_RaycastDart __instance, int characterID, Vector3 origin, Vector3 endpoint)
			{
				//IL_0196: Unknown result type (might be due to invalid IL or missing references)
				//IL_0197: Unknown result type (might be due to invalid IL or missing references)
				//IL_0115: 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_0117: Unknown result type (might be due to invalid IL or missing references)
				//IL_011c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0132: Unknown result type (might be due to invalid IL or missing references)
				//IL_0137: Unknown result type (might be due to invalid IL or missing references)
				//IL_0143: Unknown result type (might be due to invalid IL or missing references)
				//IL_0144: Unknown result type (might be due to invalid IL or missing references)
				//IL_0157: Unknown result type (might be due to invalid IL or missing references)
				//IL_0159: Unknown result type (might be due to invalid IL or missing references)
				//IL_0161: Unknown result type (might be due to invalid IL or missing references)
				//IL_0163: Unknown result type (might be due to invalid IL or missing references)
				//IL_016d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0172: Unknown result type (might be due to invalid IL or missing references)
				//IL_0177: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (!NetworkSync.ShouldApplyModEffects() || !TryGetDartType(((Component)__instance).GetComponent<Item>(), null, out var dartType))
					{
						return;
					}
					Character val = null;
					if (characterID != -1)
					{
						PhotonView photonView = PhotonNetwork.GetPhotonView(characterID);
						if ((Object)(object)photonView != (Object)null)
						{
							val = ((Component)photonView).GetComponent<Character>();
						}
					}
					if ((Object)(object)val != (Object)null && (Object)(object)((MonoBehaviourPun)val).photonView != (Object)null && ((MonoBehaviourPun)val).photonView.IsMine && val.refs != null && (Object)(object)val.refs.afflictions != (Object)null)
					{
						switch (dartType)
						{
						case BlowDartType.Thorns:
						{
							int num2 = Mathf.Max(1, Mathf.RoundToInt(CFG_ThornsAmount.Value / 0.025f));
							val.refs.afflictions.AddThorns(0, num2);
							break;
						}
						case BlowDartType.Arrow:
						{
							int num = Mathf.Max(1, Mathf.RoundToInt(CFG_ArrowAmount.Value / 0.025f));
							Vector3 val2 = origin - endpoint;
							if (((Vector3)(ref val2)).sqrMagnitude < 0.0001f)
							{
								val2 = Vector3.up;
							}
							else
							{
								((Vector3)(ref val2)).Normalize();
							}
							Vector3 val3 = endpoint;
							for (int i = 0; i < num; i++)
							{
								val.refs.afflictions.AddArrow(val3, val2);
								val3 += Random.insideUnitSphere * 0.08f;
							}
							break;
						}
						}
					}
					DartImpactEffects.Handle(((ItemActionBase)__instance).character, val, dartType, origin, endpoint);
				}
				catch (Exception ex)
				{
					LogOnce(ref _loggedSyncError, "RPC_DartImpact postfix failed", ex);
				}
			}
		}

		public const string PluginGuid = "tony4twentys.PEAK_Blow_Darts";

		private static Harmony _harmony;

		internal static PEAKBlowDartsPlugin Instance;

		internal static DartTypeInfo[] MenuTypes;

		internal static ConfigEntry<bool> CFG_ModEnabled;

		internal static ConfigEntry<bool> CFG_ShowPauseMenuButton;

		internal static ConfigEntry<KeyCode> CFG_MenuKey;

		internal static ConfigEntry<KeyCode> CFG_MenuModifier;

		private static bool _loggedItemStartError;

		private static bool _loggedGetItemNameError;

		private static bool _loggedModifyError;

		private static bool _loggedSyncError;

		private static ConfigEntry<bool> CFG_EnableInjury;

		private static ConfigEntry<bool> CFG_EnablePoison;

		private static ConfigEntry<bool> CFG_EnableCold;

		private static ConfigEntry<bool> CFG_EnableHunger;

		private static ConfigEntry<bool> CFG_EnableDrowsy;

		private static ConfigEntry<bool> CFG_EnableCurse;

		private static ConfigEntry<bool> CFG_EnableHot;

		private static ConfigEntry<bool> CFG_EnableCrab;

		private static ConfigEntry<bool> CFG_EnableInfiniteStamina;

		private static ConfigEntry<bool> CFG_EnableExtraStamina;

		private static ConfigEntry<bool> CFG_EnableFasterBoi;

		private static ConfigEntry<bool> CFG_EnableAfflictionClearer;

		private static ConfigEntry<bool> CFG_EnablePandoras;

		private static ConfigEntry<bool> CFG_EnableInvincibility;

		private static ConfigEntry<bool> CFG_EnableThorns;

		private static ConfigEntry<bool> CFG_EnableSpores;

		private static ConfigEntry<bool> CFG_EnableWeb;

		private static ConfigEntry<bool> CFG_EnableArrow;

		private static ConfigEntry<bool> CFG_EnablePetrify;

		private static ConfigEntry<bool> CFG_EnableFlyTrap;

		private static ConfigEntry<bool> CFG_EnableBlind;

		private static ConfigEntry<bool> CFG_EnableNumb;

		private static ConfigEntry<bool> CFG_EnableExhausted;

		private static ConfigEntry<bool> CFG_EnableHealAll;

		private static ConfigEntry<bool> CFG_EnableHungerBlock;

		private static ConfigEntry<bool> CFG_EnableSunscreen;

		private static ConfigEntry<bool> CFG_EnableLowGravity;

		private static ConfigEntry<bool> CFG_EnableDoubleJump;

		private static ConfigEntry<bool> CFG_EnableBeetleBonk;

		private static ConfigEntry<bool> CFG_EnableBonk;

		private static ConfigEntry<bool> CFG_EnableAntiSphere;

		private static ConfigEntry<bool> CFG_EnableScorpion;

		private static ConfigEntry<bool> CFG_EnableTornado;

		private static ConfigEntry<bool> CFG_EnableFrog;

		private static ConfigEntry<bool> CFG_EnableFrogTongue;

		private static ConfigEntry<bool> CFG_EnableBookOfBones;

		private static ConfigEntry<bool> CFG_EnableBeeSwarm;

		private static ConfigEntry<bool> CFG_EnableExplosive;

		private static ConfigEntry<bool> CFG_EnableWarp;

		private static ConfigEntry<bool> CFG_EnableTick;

		private static ConfigEntry<bool> CFG_EnableSummon;

		private static ConfigEntry<bool> CFG_EnableRocketPack;

		private static ConfigEntry<float> CFG_InjuryChance;

		private static ConfigEntry<float> CFG_PoisonChance;

		private static ConfigEntry<float> CFG_ColdChance;

		private static ConfigEntry<float> CFG_HungerChance;

		private static ConfigEntry<float> CFG_DrowsyChance;

		private static ConfigEntry<float> CFG_CurseChance;

		private static ConfigEntry<float> CFG_HotChance;

		private static ConfigEntry<float> CFG_CrabChance;

		private static ConfigEntry<float> CFG_InfiniteStaminaChance;

		private static ConfigEntry<float> CFG_ExtraStaminaChance;

		private static ConfigEntry<float> CFG_FasterBoiChance;

		private static ConfigEntry<float> CFG_AfflictionClearerChance;

		private static ConfigEntry<float> CFG_PandorasChance;

		private static ConfigEntry<float> CFG_InvincibilityChance;

		private static ConfigEntry<float> CFG_ThornsChance;

		private static ConfigEntry<float> CFG_SporesChance;

		private static ConfigEntry<float> CFG_WebChance;

		private static ConfigEntry<float> CFG_ArrowChance;

		private static ConfigEntry<float> CFG_PetrifyChance;

		private static ConfigEntry<float> CFG_FlyTrapChance;

		private static ConfigEntry<float> CFG_BlindChance;

		private static ConfigEntry<float> CFG_NumbChance;

		private static ConfigEntry<float> CFG_ExhaustedChance;

		private static ConfigEntry<float> CFG_HealAllChance;

		private static ConfigEntry<float> CFG_HungerBlockChance;

		private static ConfigEntry<float> CFG_SunscreenChance;

		private static ConfigEntry<float> CFG_LowGravityChance;

		private static ConfigEntry<float> CFG_DoubleJumpChance;

		private static ConfigEntry<float> CFG_BeetleBonkChance;

		private static ConfigEntry<float> CFG_BonkChance;

		private static ConfigEntry<float> CFG_AntiSphereChance;

		private static ConfigEntry<float> CFG_ScorpionChance;

		private static ConfigEntry<float> CFG_TornadoChance;

		private static ConfigEntry<float> CFG_FrogChance;

		private static ConfigEntry<float> CFG_FrogTongueChance;

		private static ConfigEntry<float> CFG_BookOfBonesChance;

		private static ConfigEntry<float> CFG_BeeSwarmChance;

		private static ConfigEntry<float> CFG_ExplosiveChance;

		private static ConfigEntry<float> CFG_WarpChance;

		private static ConfigEntry<float> CFG_TickChance;

		private static ConfigEntry<float> CFG_SummonChance;

		private static ConfigEntry<float> CFG_RocketPackChance;

		private static ConfigEntry<float> CFG_InjuryAmount;

		private static ConfigEntry<float> CFG_PoisonAmount;

		private static ConfigEntry<float> CFG_PoisonDuration;

		private static ConfigEntry<float> CFG_ColdAmount;

		private static ConfigEntry<float> CFG_ColdDuration;

		private static ConfigEntry<float> CFG_HungerAmount;

		private static ConfigEntry<float> CFG_DrowsyAmount;

		private static ConfigEntry<float> CFG_CurseAmount;

		private static ConfigEntry<float> CFG_HotAmount;

		private static ConfigEntry<float> CFG_CrabAmount;

		private static ConfigEntry<float> CFG_InfiniteStaminaDuration;

		private static ConfigEntry<float> CFG_ExtraStaminaAmount;

		private static ConfigEntry<float> CFG_InvincibilityDuration;

		private static ConfigEntry<float> CFG_FasterBoiDuration;

		private static ConfigEntry<float> CFG_FasterBoiMoveSpeed;

		private static ConfigEntry<float> CFG_FasterBoiClimbSpeed;

		private static ConfigEntry<float> CFG_ThornsAmount;

		private static ConfigEntry<float> CFG_SporesAmount;

		private static ConfigEntry<float> CFG_WebAmount;

		private static ConfigEntry<float> CFG_ArrowAmount;

		private static ConfigEntry<float> CFG_PetrifyAmount;

		private static ConfigEntry<float> CFG_FlyTrapAmount;

		private static ConfigEntry<float> CFG_BlindDuration;

		private static ConfigEntry<float> CFG_NumbDuration;

		private static ConfigEntry<float> CFG_ExhaustedDuration;

		private static ConfigEntry<float> CFG_ExhaustedDrain;

		private static ConfigEntry<float> CFG_HealAllAmount;

		private static ConfigEntry<float> CFG_HungerBlockDuration;

		private static ConfigEntry<float> CFG_SunscreenDuration;

		private static ConfigEntry<float> CFG_LowGravityDuration;

		private static ConfigEntry<float> CFG_LowGravityAmount;

		internal static ConfigEntry<float> CFG_BeetleBonkRagdoll;

		internal static ConfigEntry<float> CFG_BeetleBonkForce;

		internal static ConfigEntry<float> CFG_BeetleBonkForceUp;

		internal static ConfigEntry<float> CFG_BeetleBonkRange;

		internal static ConfigEntry<float> CFG_BonkRagdoll;

		internal static ConfigEntry<float> CFG_BonkForce;

		internal static ConfigEntry<float> CFG_BonkRange;

		internal static ConfigEntry<float> CFG_TornadoLifetime;

		internal static ConfigEntry<float> CFG_BeeSwarmAnger;

		internal static ConfigEntry<float> CFG_RocketFuse;

		private static Dictionary<string, ConfigEntry<bool>> _enableById;

		private static Dictionary<string, ConfigEntry<float>> _chanceById;

		private static Dictionary<string, ConfigEntry<float>> _amountById;

		private static Dictionary<string, ConfigEntry<float>> _durationById;

		private static List<DartRoll> _rolls;

		internal static bool IsModEnabled => CFG_ModEnabled != null && CFG_ModEnabled.Value;

		private void Awake()
		{
			//IL_0e41: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e4b: Expected O, but got Unknown
			Instance = this;
			CFG_ModEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ModEnabled", true, "Master toggle. When off, blow guns stay vanilla.");
			CFG_ShowPauseMenuButton = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowPauseMenuButton", true, "Show the Blow Darts button on the pause menu. The hotkey still works if this is off.");
			CFG_MenuKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "MenuKey", (KeyCode)98, "Open the in-game Blow Darts menu (used with MenuModifier). Also available from the pause menu.");
			CFG_MenuModifier = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "MenuModifier", (KeyCode)306, "Optional modifier. Default LeftControl (Ctrl+B). Set to None to use MenuKey alone.");
			CFG_EnableInjury = BindEnable("Injury", enabled: true, "Injury Blow Gun");
			CFG_EnablePoison = BindEnable("Poison", enabled: true, "Poison Blow Gun");
			CFG_EnableCold = BindEnable("Cold", enabled: true, "Frosting Blow Gun");
			CFG_EnableHunger = BindEnable("Hunger", enabled: true, "Hunger Blow Gun");
			CFG_EnableDrowsy = BindEnable("Drowsy", enabled: true, "Drowsy Blow Gun");
			CFG_EnableCurse = BindEnable("Curse", enabled: true, "Curse Blow Gun");
			CFG_EnableHot = BindEnable("Hot", enabled: true, "Burning Blow Gun");
			CFG_EnableCrab = BindEnable("Crab", enabled: false, "Crabby Blow Gun");
			CFG_EnableInfiniteStamina = BindEnable("InfiniteStamina", enabled: true, "Infinite Stamina Blow Gun");
			CFG_EnableExtraStamina = BindEnable("ExtraStamina", enabled: true, "Extra Stamina Blow Gun");
			CFG_EnableFasterBoi = BindEnable("FasterBoi", enabled: true, "Energy Blow Gun");
			CFG_EnableAfflictionClearer = BindEnable("AfflictionClearer", enabled: true, "Affliction Clearer Blow Gun");
			CFG_EnablePandoras = BindEnable("Pandoras", enabled: true, "Pandoras Blow Gun");
			CFG_EnableInvincibility = BindEnable("Invincibility", enabled: true, "Invincibility Blow Gun");
			CFG_EnableThorns = BindEnable("Thorns", enabled: true, "Thorn Blow Gun");
			CFG_EnableSpores = BindEnable("Spores", enabled: true, "Spore Blow Gun");
			CFG_EnableWeb = BindEnable("Web", enabled: true, "Web Blow Gun");
			CFG_EnableArrow = BindEnable("Arrow", enabled: true, "Arrow Blow Gun");
			CFG_EnablePetrify = BindEnable("Petrify", enabled: true, "Petrify Blow Gun");
			CFG_EnableFlyTrap = BindEnable("FlyTrap", enabled: true, "Flytrap Blow Gun");
			CFG_EnableBlind = BindEnable("Blind", enabled: true, "Blind Blow Gun");
			CFG_EnableNumb = BindEnable("Numb", enabled: true, "Numb Blow Gun");
			CFG_EnableExhausted = BindEnable("Exhausted", enabled: true, "Exhaustion Blow Gun");
			CFG_EnableHealAll = BindEnable("HealAll", enabled: true, "Heal-All Blow Gun");
			CFG_EnableHungerBlock = BindEnable("HungerBlock", enabled: true, "HungerBlock Blow Gun");
			CFG_EnableSunscreen = BindEnable("Sunscreen", enabled: true, "Sunscreen Blow Gun");
			CFG_EnableLowGravity = BindEnable("LowGravity", enabled: true, "Low Gravity Blow Gun");
			CFG_EnableDoubleJump = BindEnable("DoubleJump", enabled: true, "Double Jump Blow Gun");
			CFG_EnableBeetleBonk = BindEnable("BeetleBonk", enabled: true, "Beetle Bonk Blow Gun");
			CFG_EnableBonk = BindEnable("Bonk", enabled: true, "Bonk Blow Gun");
			CFG_EnableAntiSphere = BindEnable("AntiSphere", enabled: true, "AntiSphere Blow Gun");
			CFG_EnableScorpion = BindEnable("Scorpion", enabled: true, "Scorpion Blow Gun");
			CFG_EnableTornado = BindEnable("Tornado", enabled: true, "Tornado Blow Gun");
			CFG_EnableFrog = BindEnable("Frog", enabled: true, "Frog Blow Gun");
			CFG_EnableFrogTongue = BindEnable("FrogTongue", enabled: true, "Frog Tongue Blow Gun");
			CFG_EnableBookOfBones = BindEnable("BookOfBones", enabled: true, "Book of Bones Blow Gun");
			CFG_EnableBeeSwarm = BindEnable("BeeSwarm", enabled: true, "Bee Swarm Blow Gun");
			CFG_EnableExplosive = BindEnable("Explosive", enabled: true, "Explosive Blow Gun");
			CFG_EnableWarp = BindEnable("Warp", enabled: true, "Warp Blow Gun");
			CFG_EnableTick = BindEnable("Tick", enabled: true, "Tick Blow Gun");
			CFG_EnableSummon = BindEnable("Summon", enabled: true, "Summon Blow Gun");
			CFG_EnableRocketPack = BindEnable("RocketPack", enabled: true, "Rocketpack Blow Gun");
			CFG_InjuryChance = BindChance("InjuryChance", 0.1f, "Injury Blow Gun");
			CFG_PoisonChance = BindChance("PoisonChance", 0.1f, "Poison Blow Gun");
			CFG_ColdChance = BindChance("ColdChance", 0.1f, "Frosting Blow Gun");
			CFG_HungerChance = BindChance("HungerChance", 0.1f, "Hunger Blow Gun");
			CFG_DrowsyChance = BindChance("DrowsyChance", 0.1f, "Drowsy Blow Gun");
			CFG_CurseChance = BindChance("CurseChance", 0.1f, "Curse Blow Gun");
			CFG_HotChance = BindChance("HotChance", 0.1f, "Burning Blow Gun");
			CFG_CrabChance = BindChance("CrabChance", 0f, "Crabby Blow Gun");
			CFG_InfiniteStaminaChance = BindChance("InfiniteStaminaChance", 0.1f, "Infinite Stamina Blow Gun");
			CFG_ExtraStaminaChance = BindChance("ExtraStaminaChance", 0.1f, "Extra Stamina Blow Gun");
			CFG_FasterBoiChance = BindChance("FasterBoiChance", 0.1f, "Energy Blow Gun");
			CFG_AfflictionClearerChance = BindChance("AfflictionClearerChance", 0.1f, "Affliction Clearer Blow Gun");
			CFG_PandorasChance = BindChance("PandorasChance", 0.1f, "Pandoras Blow Gun");
			CFG_InvincibilityChance = BindChance("InvincibilityChance", 0.01f, "Invincibility Blow Gun");
			CFG_ThornsChance = BindChance("ThornsChance", 0.1f, "Thorn Blow Gun");
			CFG_SporesChance = BindChance("SporesChance", 0.1f, "Spore Blow Gun");
			CFG_WebChance = BindChance("WebChance", 0.1f, "Web Blow Gun");
			CFG_ArrowChance = BindChance("ArrowChance", 0.1f, "Arrow Blow Gun");
			CFG_PetrifyChance = BindChance("PetrifyChance", 0.1f, "Petrify Blow Gun");
			CFG_FlyTrapChance = BindChance("FlyTrapChance", 0.1f, "Flytrap Blow Gun");
			CFG_BlindChance = BindChance("BlindChance", 0.1f, "Blind Blow Gun");
			CFG_NumbChance = BindChance("NumbChance", 0.1f, "Numb Blow Gun");
			CFG_ExhaustedChance = BindChance("ExhaustedChance", 0.1f, "Exhaustion Blow Gun");
			CFG_HealAllChance = BindChance("HealAllChance", 0.1f, "Heal-All Blow Gun");
			CFG_HungerBlockChance = BindChance("HungerBlockChance", 0.1f, "HungerBlock Blow Gun");
			CFG_SunscreenChance = BindChance("SunscreenChance", 0.1f, "Sunscreen Blow Gun");
			CFG_LowGravityChance = BindChance("LowGravityChance", 0.1f, "Low Gravity Blow Gun");
			CFG_DoubleJumpChance = BindChance("DoubleJumpChance", 0.1f, "Double Jump Blow Gun");
			CFG_BeetleBonkChance = BindChance("BeetleBonkChance", 0.1f, "Beetle Bonk Blow Gun");
			CFG_BonkChance = BindChance("BonkChance", 0.1f, "Bonk Blow Gun");
			CFG_AntiSphereChance = BindChance("AntiSphereChance", 0.1f, "AntiSphere Blow Gun");
			CFG_ScorpionChance = BindChance("ScorpionChance", 0.1f, "Scorpion Blow Gun");
			CFG_TornadoChance = BindChance("TornadoChance", 0.1f, "Tornado Blow Gun");
			CFG_FrogChance = BindChance("FrogChance", 0.1f, "Frog Blow Gun");
			CFG_FrogTongueChance = BindChance("FrogTongueChance", 0.1f, "Frog Tongue Blow Gun");
			CFG_BookOfBonesChance = BindChance("BookOfBonesChance", 0.1f, "Book of Bones Blow Gun");
			CFG_BeeSwarmChance = BindChance("BeeSwarmChance", 0.1f, "Bee Swarm Blow Gun");
			CFG_ExplosiveChance = BindChance("ExplosiveChance", 0.1f, "Explosive Blow Gun");
			CFG_WarpChance = BindChance("WarpChance", 0.1f, "Warp Blow Gun");
			CFG_TickChance = BindChance("TickChance", 0.1f, "Tick Blow Gun");
			CFG_SummonChance = BindChance("SummonChance", 0.1f, "Summon Blow Gun");
			CFG_RocketPackChance = BindChance("RocketPackChance", 0.1f, "Rocketpack Blow Gun");
			CFG_InjuryAmount = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "InjuryAmount", 0.25f, "Injury amount (0-1 status bar)");
			CFG_PoisonAmount = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "PoisonAmount", 0.25f, "Poison amount. Instant if PoisonDuration is under 0.05s, otherwise applied per second.");
			CFG_PoisonDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "PoisonDuration", 0.001f, "Poison duration in seconds. Under 0.05s applies poison instantly.");
			CFG_ColdAmount = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "ColdAmount", 0.25f, "Cold amount. Positive adds cold. Instant if ColdDuration is under 0.05s.");
			CFG_ColdDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "ColdDuration", 0.001f, "Cold duration in seconds. Under 0.05s applies cold instantly.");
			CFG_HungerAmount = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "HungerAmount", 0.25f, "Hunger amount");
			CFG_DrowsyAmount = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "DrowsyAmount", 0.25f, "Drowsy amount");
			CFG_CurseAmount = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "CurseAmount", 0.25f, "Curse amount");
			CFG_HotAmount = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "HotAmount", 0.25f, "Hot amount");
			CFG_CrabAmount = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "CrabAmount", 0.25f, "Crab amount");
			CFG_InfiniteStaminaDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "InfiniteStaminaDuration", 30f, "Infinite stamina duration in seconds");
			CFG_ExtraStaminaAmount = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "ExtraStaminaAmount", 0.5f, "Extra stamina amount (0-1 bar). Values above 1 are clamped.");
			CFG_InvincibilityDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "InvincibilityDuration", 30f, "Invincibility duration in seconds");
			CFG_FasterBoiDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "FasterBoiDuration", 20f, "Faster Boi duration in seconds");
			CFG_FasterBoiMoveSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "FasterBoiMoveSpeed", 1.5f, "Faster Boi movement speed added to the movement modifier");
			CFG_FasterBoiClimbSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "FasterBoiClimbSpeed", 1.3f, "Faster Boi climb speed added to climb modifiers");
			CFG_ThornsAmount = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "ThornsAmount", 0.25f, "Thorns amount. About 0.025 per stuck thorn on the body.");
			CFG_SporesAmount = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "SporesAmount", 0.25f, "Spores amount");
			CFG_WebAmount = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "WebAmount", 0.25f, "Web amount");
			CFG_ArrowAmount = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "ArrowAmount", 0.25f, "Arrow amount. About 0.025 per stuck arrow on the body.");
			CFG_PetrifyAmount = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "PetrifyAmount", 0.25f, "Petrify amount");
			CFG_FlyTrapAmount = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "FlyTrapAmount", 0.25f, "Flytrap amount");
			CFG_BlindDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "BlindDuration", 8f, "Blind duration in seconds");
			CFG_NumbDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "NumbDuration", 12f, "Numb duration in seconds");
			CFG_ExhaustedDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "ExhaustedDuration", 8f, "Exhaustion duration in seconds");
			CFG_ExhaustedDrain = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "ExhaustedDrain", 1f, "Stamina drained over the exhaustion duration (0-1)");
			CFG_HealAllAmount = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "HealAllAmount", 1f, "Maximum combined status healed by Heal-All");
			CFG_HungerBlockDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "HungerBlockDuration", 30f, "HungerBlock duration in seconds");
			CFG_SunscreenDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "SunscreenDuration", 45f, "Sunscreen duration in seconds");
			CFG_LowGravityDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "LowGravityDuration", 12f, "Low gravity duration in seconds");
			CFG_LowGravityAmount = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "LowGravityAmount", 1f, "Low gravity strength (integer stacks)");
			CFG_BeetleBonkRagdoll = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "BeetleBonkRagdoll", 2f, "Beetle bonk ragdoll time in seconds");
			CFG_BeetleBonkForce = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "BeetleBonkForce", 400f, "Beetle bonk forward force");
			CFG_BeetleBonkForceUp = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "BeetleBonkForceUp", 100f, "Beetle bonk upward force");
			CFG_BeetleBonkRange = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "BeetleBonkRange", 4f, "Beetle bonk force radius");
			CFG_BonkRagdoll = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "BonkRagdoll", 1f, "Thrown-item style bonk ragdoll time in seconds");
			CFG_BonkForce = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "BonkForce", 100f, "Thrown-item style bonk force");
			CFG_BonkRange = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "BonkRange", 3f, "Thrown-item style bonk force radius");
			MigrateSwappedBonkDefaults();
			CFG_TornadoLifetime = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "TornadoLifetime", 15f, "Tornado lifetime in seconds");
			CFG_BeeSwarmAnger = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "BeeSwarmAnger", 12f, "How long the spawned swarm stays angry");
			CFG_RocketFuse = ((BaseUnityPlugin)this).Config.Bind<float>("Parameters", "RocketFuse", 0.25f, "Rocketpack fuse before launch, in seconds");
			BuildLookups();
			_harmony = new Harmony("tony4twentys.PEAK_Blow_Darts");
			_harmony.PatchAll();
			NetworkSync.Initialize(this);
			PresetStore.Initialize();
			((BaseUnityPlugin)this).Config.SettingChanged += OnConfigChanged;
			SceneManager.sceneLoaded += OnSceneLoaded;
			BlowDartMenu.EnsureCreated();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Peak Blow Darts 2.0.0 loaded. Open the menu with Ctrl+B or the pause menu.");
		}

		private void Update()
		{
			if (IsMenuHotkeyDown())
			{
				BlowDartMenu.Toggle();
			}
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			if ((int)mode != 1)
			{
				BlowDartMenu.OnAfterSceneLoad();
			}
		}

		private ConfigEntry<bool> BindEnable(string id, bool enabled, string name)
		{
			return ((BaseUnityPlugin)this).Config.Bind<bool>("DartTypes", "Enable" + id, enabled, "Enable " + name);
		}

		private ConfigEntry<float> BindChance(string key, float chance, string name)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			return ((BaseUnityPlugin)this).Config.Bind<float>("Chances", key, chance, new ConfigDescription("Chance for " + name + " (0.0-1.0)", (AcceptableValueBase)null, new object[1]
			{
				new AcceptableValueRange<float>(0f, 1f)
			}));
		}

		private static void MigrateSwappedBonkDefaults()
		{
			if (CFG_BeetleBonkForce != null && CFG_BonkForce != null && !(Mathf.Abs(CFG_BeetleBonkForce.Value - 100f) > 0.01f) && !(Mathf.Abs(CFG_BonkForce.Value - 400f) > 0.01f))
			{
				CFG_BeetleBonkForce.Value = 400f;
				CFG_BonkForce.Value = 100f;
			}
		}

		private static DartParam Param(string label, ConfigEntry<float> entry, float defaultValue, float min, float max)
		{
			return new DartParam
			{
				Label = label,
				Entry = entry,
				DefaultValue = defaultValue,
				Min = min,
				Max = max
			};
		}

		private static DartTypeInfo TypeInfo(BlowDartType type, string id, string name, bool defaultEnable, float defaultChance, ConfigEntry<bool> enable, ConfigEntry<float> chance, params DartParam[] extras)
		{
			return new DartTypeInfo
			{
				Type = type,
				Id = id,
				Name = name,
				DefaultEnable = defaultEnable,
				DefaultChance = defaultChance,
				Enable = enable,
				Chance = chance,
				Params = extras
			};
		}

		private static void BuildLookups()
		{
			MenuTypes = new DartTypeInfo[41]
			{
				TypeInfo(BlowDartType.Injury, "Injury", "Injury Blow Gun", true, 0.1f, CFG_EnableInjury, CFG_InjuryChance, Param("Amount", CFG_InjuryAmount, 0.25f, 0f, 1f)),
				TypeInfo(BlowDartType.Poison, "Poison", "Poison Blow Gun", true, 0.1f, CFG_EnablePoison, CFG_PoisonChance, Param("Amount", CFG_PoisonAmount, 0.25f, 0f, 5f), Param("Duration", CFG_PoisonDuration, 0.001f, 0f, 120f)),
				TypeInfo(BlowDartType.Cold, "Cold", "Frosting Blow Gun", true, 0.1f, CFG_EnableCold, CFG_ColdChance, Param("Amount", CFG_ColdAmount, 0.25f, -1f, 1f), Param("Duration", CFG_ColdDuration, 0.001f, 0f, 120f)),
				TypeInfo(BlowDartType.Hunger, "Hunger", "Hunger Blow Gun", true, 0.1f, CFG_EnableHunger, CFG_HungerChance, Param("Amount", CFG_HungerAmount, 0.25f, 0f, 1f)),
				TypeInfo(BlowDartType.Drowsy, "Drowsy", "Drowsy Blow Gun", true, 0.1f, CFG_EnableDrowsy, CFG_DrowsyChance, Param("Amount", CFG_DrowsyAmount, 0.25f, 0f, 1f)),
				TypeInfo(BlowDartType.Curse, "Curse", "Curse Blow Gun", true, 0.1f, CFG_EnableCurse, CFG_CurseChance, Param("Amount", CFG_CurseAmount, 0.25f, 0f, 1f)),
				TypeInfo(BlowDartType.Hot, "Hot", "Burning Blow Gun", true, 0.1f, CFG_EnableHot, CFG_HotChance, Param("Amount", CFG_HotAmount, 0.25f, 0f, 1f)),
				TypeInfo(BlowDartType.Crab, "Crab", "Crabby Blow Gun", false, 0f, CFG_EnableCrab, CFG_CrabChance, Param("Amount", CFG_CrabAmount, 0.25f, 0f, 1f)),
				TypeInfo(BlowDartType.InfiniteStamina, "InfiniteStamina", "Infinite Stamina Blow Gun", true, 0.1f, CFG_EnableInfiniteStamina, CFG_InfiniteStaminaChance, Param("Duration", CFG_InfiniteStaminaDuration, 30f, 0f, 300f)),
				TypeInfo(BlowDartType.ExtraStamina, "ExtraStamina", "Extra Stamina Blow Gun", true, 0.1f, CFG_EnableExtraStamina, CFG_ExtraStaminaChance, Param("Amount (0-1)", CFG_ExtraStaminaAmount, 0.5f, 0f, 1f)),
				TypeInfo(BlowDartType.FasterBoi, "FasterBoi", "Energy Blow Gun", true, 0.1f, CFG_EnableFasterBoi, CFG_FasterBoiChance, Param("Duration", CFG_FasterBoiDuration, 20f, 0f, 300f), Param("Move speed", CFG_FasterBoiMoveSpeed, 1.5f, 0f, 10f), Param("Climb speed", CFG_FasterBoiClimbSpeed, 1.3f, 0f, 10f)),
				TypeInfo(BlowDartType.AfflictionClearer, "AfflictionClearer", "Affliction Clearer Blow Gun", true, 0.1f, CFG_EnableAfflictionClearer, CFG_AfflictionClearerChance),
				TypeInfo(BlowDartType.Chaos, "Pandoras", "Pandoras Blow Gun", true, 0.1f, CFG_EnablePandoras, CFG_PandorasChance),
				TypeInfo(BlowDartType.Invincibility, "Invincibility", "Invincibility Blow Gun", true, 0.01f, CFG_EnableInvincibility, CFG_InvincibilityChance, Param("Duration", CFG_InvincibilityDuration, 30f, 0f, 300f)),
				TypeInfo(BlowDartType.Thorns, "Thorns", "Thorn Blow Gun", true, 0.1f, CFG_EnableThorns, CFG_ThornsChance, Param("Amount", CFG_ThornsAmount, 0.25f, 0f, 1f)),
				TypeInfo(BlowDartType.Spores, "Spores", "Spore Blow Gun", true, 0.1f, CFG_EnableSpores, CFG_SporesChance, Param("Amount", CFG_SporesAmount, 0.25f, 0f, 1f)),
				TypeInfo(BlowDartType.Web, "Web", "Web Blow Gun", true, 0.1f, CFG_EnableWeb, CFG_WebChance, Param("Amount", CFG_WebAmount, 0.25f, 0f, 1f)),
				TypeInfo(BlowDartType.Arrow, "Arrow", "Arrow Blow Gun", true, 0.1f, CFG_EnableArrow, CFG_ArrowChance, Param("Amount", CFG_ArrowAmount, 0.25f, 0f, 1f)),
				TypeInfo(BlowDartType.Petrify, "Petrify", "Petrify Blow Gun", true, 0.1f, CFG_EnablePetrify, CFG_PetrifyChance, Param("Amount", CFG_PetrifyAmount, 0.25f, 0f, 1f)),
				TypeInfo(BlowDartType.Blind, "Blind", "Blind Blow Gun", true, 0.1f, CFG_EnableBlind, CFG_BlindChance, Param("Duration", CFG_BlindDuration, 8f, 0f, 120f)),
				TypeInfo(BlowDartType.Numb, "Numb", "Numb Blow Gun", true, 0.1f, CFG_EnableNumb, CFG_NumbChance, Param("Duration", CFG_NumbDuration, 12f, 0f, 120f)),
				TypeInfo(BlowDartType.Exhausted, "Exhausted", "Exhaustion Blow Gun", true, 0.1f, CFG_EnableExhausted, CFG_ExhaustedChance, Param("Duration", CFG_ExhaustedDuration, 8f, 0.1f, 120f), Param("Drain", CFG_ExhaustedDrain, 1f, 0f, 1f)),
				TypeInfo(BlowDartType.HealAll, "HealAll", "Heal-All Blow Gun", true, 0.1f, CFG_EnableHealAll, CFG_HealAllChance, Param("Max healing", CFG_HealAllAmount, 1f, 0f, 1f)),
				TypeInfo(BlowDartType.HungerBlock, "HungerBlock", "HungerBlock Blow Gun", true, 0.1f, CFG_EnableHungerBlock, CFG_HungerBlockChance, Param("Duration", CFG_HungerBlockDuration, 30f, 0f, 300f)),
				TypeInfo(BlowDartType.Sunscreen, "Sunscreen", "Sunscreen Blow Gun", true, 0.1f, CFG_EnableSunscreen, CFG_SunscreenChance, Param("Duration", CFG_SunscreenDuration, 45f, 0f, 300f)),
				TypeInfo(BlowDartType.LowGravity, "LowGravity", "Low Gravity Blow Gun", true, 0.1f, CFG_EnableLowGravity, CFG_LowGravityChance, Param("Duration", CFG_LowGravityDuration, 12f, 0f, 120f), Param("Stacks", CFG_LowGravityAmount, 1f, 1f, 10f)),
				TypeInfo(BlowDartType.DoubleJump, "DoubleJump", "Double Jump Blow Gun", true, 0.1f, CFG_EnableDoubleJump, CFG_DoubleJumpChance),
				TypeInfo(BlowDartType.BeetleBonk, "BeetleBonk", "Beetle Bonk Blow Gun", true, 0.1f, CFG_EnableBeetleBonk, CFG_BeetleBonkChance, Param("Ragdoll", CFG_BeetleBonkRagdoll, 2f, 0f, 10f), Param("Force", CFG_BeetleBonkForce, 400f, 0f, 2000f), Param("Up force", CFG_BeetleBonkForceUp, 100f, 0f, 2000f), Param("Range", CFG_BeetleBonkRange, 4f, 0.1f, 20f)),
				TypeInfo(BlowDartType.Bonk, "Bonk", "Bonk Blow Gun", true, 0.1f, CFG_EnableBonk, CFG_BonkChance, Param("Ragdoll", CFG_BonkRagdoll, 1f, 0f, 10f), Param("Force", CFG_BonkForce, 100f, 0f, 5000f), Param("Range", CFG_BonkRange, 3f, 0.1f, 20f)),
				TypeInfo(BlowDartType.AntiSphere, "AntiSphere", "AntiSphere Blow Gun", true, 0.1f, CFG_EnableAntiSphere, CFG_AntiSphereChance),
				TypeInfo(BlowDartType.Scorpion, "Scorpion", "Scorpion Blow Gun", true, 0.1f, CFG_EnableScorpion, CFG_ScorpionChance),
				TypeInfo(BlowDartType.Tornado, "Tornado", "Tornado Blow Gun", true, 0.1f, CFG_EnableTornado, CFG_TornadoChance, Param("Lifetime", CFG_TornadoLifetime, 15f, 1f, 120f)),
				TypeInfo(BlowDartType.Frog, "Frog", "Frog Blow Gun", true, 0.1f, CFG_EnableFrog, CFG_FrogChance),
				TypeInfo(BlowDartType.FrogTongue, "FrogTongue", "Frog Tongue Blow Gun", true, 0.1f, CFG_EnableFrogTongue, CFG_FrogTongueChance),
				TypeInfo(BlowDartType.BookOfBones, "BookOfBones", "Book of Bones Blow Gun", true, 0.1f, CFG_EnableBookOfBones, CFG_BookOfBonesChance),
				TypeInfo(BlowDartType.BeeSwarm, "BeeSwarm", "Bee Swarm Blow Gun", true, 0.1f, CFG_EnableBeeSwarm, CFG_BeeSwarmChance, Param("Anger time", CFG_BeeSwarmAnger, 12f, 1f, 60f)),
				TypeInfo(BlowDartType.Explosive, "Explosive", "Explosive Blow Gun", true, 0.1f, CFG_EnableExplosive, CFG_ExplosiveChance),
				TypeInfo(BlowDartType.Warp, "Warp", "Warp Blow Gun", true, 0.1f, CFG_EnableWarp, CFG_WarpChance),
				TypeInfo(BlowDartType.Tick, "Tick", "Tick Blow Gun", true, 0.1f, CFG_EnableTick, CFG_TickChance),
				TypeInfo(BlowDartType.Summon, "Summon", "Summon Blow Gun", true, 0.1f, CFG_EnableSummon, CFG_SummonChance),
				TypeInfo(BlowDartType.RocketPack, "RocketPack", "Rocketpack Blow Gun", true, 0.1f, CFG_EnableRocketPack, CFG_RocketPackChance, Param("Fuse", CFG_RocketFuse, 0.25f, 0.05f, 5f))
			};
			_enableById = new Dictionary<string, ConfigEntry<bool>>(StringComparer.Ordinal);
			_chanceById = new Dictionary<string, ConfigEntry<float>>(StringComparer.Ordinal);
			_amountById = new Dictionary<string, ConfigEntry<float>>(StringComparer.Ordinal);
			_durationById = new Dictionary<string, ConfigEntry<float>>(StringComparer.Ordinal);
			_rolls = new List<DartRoll>(MenuTypes.Length);
			for (int i = 0; i < MenuTypes.Length; i++)
			{
				DartTypeInfo dartTypeInfo = MenuTypes[i];
				dartTypeInfo.Name = GetDartName(dartTypeInfo.Type);
				MenuTypes[i] = dartTypeInfo;
				_enableById[dartTypeInfo.Id] = dartTypeInfo.Enable;
				_chanceById[dartTypeInfo.Id] = dartTypeInfo.Chance;
				_rolls.Add(new DartRoll
				{
					Type = dartTypeInfo.Type,
					Enable = dartTypeInfo.Enable,
					Chance = dartTypeInfo.Chance
				});
				if (dartTypeInfo.Params == null)
				{
					continue;
				}
				for (int j = 0; j < dartTypeInfo.Params.Length; j++)
				{
					DartParam dartParam = dartTypeInfo.Params[j];
					string id = dartTypeInfo.Id;
					if (dartParam.Label.IndexOf("Duration", StringComparison.OrdinalIgnoreCase) >= 0)
					{
						_durationById[id] = dartParam.Entry;
					}
					else if (dartParam.Label.IndexOf("speed", StringComparison.OrdinalIgnoreCase) < 0)
					{
						_amountById[id] = dartParam.Entry;
					}
				}
			}
		}

		internal static bool CanEditGameplaySettings()
		{
			if (!PhotonNetwork.InRoom)
			{
				return true;
			}
			return PhotonNetwork.IsMasterClient;
		}

		internal static bool TryGetMenuType(BlowDartType type, out DartTypeInfo info)
		{
			info = default(DartTypeInfo);
			if (MenuTypes == null)
			{
				return false;
			}
			for (int i = 0; i < MenuTypes.Length; i++)
			{
				if (MenuTypes[i].Type == type)
				{
					info = MenuTypes[i];
					return true;
				}
			}
			return false;
		}

		internal static void SetModEnabled(bool enabled)
		{
			if (CFG_ModEnabled != null)
			{
				CFG_ModEnabled.Value = enabled;
			}
		}

		internal static void SetTypeEnabled(BlowDartType type, bool enabled)
		{
			if (TryGetMenuType(type, out var info))
			{
				info.Enable.Value = enabled;
			}
		}

		internal static void SetTypeChance(BlowDartType type, float chance)
		{
			if (TryGetMenuType(type, out var info))
			{
				info.Chance.Value = Mathf.Clamp01(chance);
			}
		}

		internal static void SetParamValue(DartParam param, float value)
		{
			if (param.Entry != null)
			{
				param.Entry.Value = Mathf.Clamp(value, param.Min, param.Max);
			}
		}

		internal static void SelectAllTypes()
		{
			SetAllTypesEnabled(enabled: true);
		}

		internal static void ClearAllTypes()
		{
			SetAllTypesEnabled(enabled: false);
		}

		internal static void SelectAllInTab(DartMenuTab tab)
		{
			SetTabTypesEnabled(tab, enabled: true);
		}

		internal static void ClearAllInTab(DartMenuTab tab)
		{
			SetTabTypesEnabled(tab, enabled: false);
		}

		private static void SetTabTypesEnabled(DartMenuTab tab, bool enabled)
		{
			if (MenuTypes == null)
			{
				return;
			}
			for (int i = 0; i < MenuTypes.Length; i++)
			{
				DartTypeInfo dartTypeInfo = MenuTypes[i];
				if (GetMenuTab(dartTypeInfo.Type) == tab)
				{
					dartTypeInfo.Enable.Value = enabled;
				}
			}
		}

		private static void SetAllTypesEnabled(bool enabled)
		{
			if (MenuTypes != null)
			{
				for (int i = 0; i < MenuTypes.Length; i++)
				{
					MenuTypes[i].Enable.Value = enabled;
				}
			}
		}

		internal static DartMenuTab GetMenuTab(BlowDartType type)
		{
			switch (type)
			{
			case BlowDartType.InfiniteStamina:
			case BlowDartType.ExtraStamina:
			case BlowDartType.FasterBoi:
			case BlowDartType.AfflictionClearer:
			case BlowDartType.Invincibility:
			case BlowDartType.HealAll:
			case BlowDartType.HungerBlock:
			case BlowDartType.Sunscreen:
			case BlowDartType.LowGravity:
			case BlowDartType.DoubleJump:
				return DartMenuTab.Positive;
			case BlowDartType.Injury:
			case BlowDartType.Poison:
			case BlowDartType.Cold:
			case BlowDartType.Hunger:
			case BlowDartType.Drowsy:
			case BlowDartType.Curse:
			case BlowDartType.Hot:
			case BlowDartType.Crab:
			case BlowDartType.Thorns:
			case BlowDartType.Spores:
			case BlowDartType.Web:
			case BlowDartType.Arrow:
			case BlowDartType.Petrify:
			case BlowDartType.Blind:
			case BlowDartType.Numb:
			case BlowDartType.Exhausted:
				return DartMenuTab.Negative;
			default:
				return DartMenuTab.Extra;
			}
		}

		internal static void ResetAllToDefaults()
		{
			if (MenuTypes == null)
			{
				return;
			}
			if (CFG_ModEnabled != null)
			{
				CFG_ModEnabled.Value = true;
			}
			for (int i = 0; i < MenuTypes.Length; i++)
			{
				DartTypeInfo dartTypeInfo = MenuTypes[i];
				dartTypeInfo.Enable.Value = dartTypeInfo.DefaultEnable;
				dartTypeInfo.Chance.Value = Mathf.Clamp01(dartTypeInfo.DefaultChance);
				if (dartTypeInfo.Params == null)
				{
					continue;
				}
				for (int j = 0; j < dartTypeInfo.Params.Length; j++)
				{
					DartParam dartParam = dartTypeInfo.Params[j];
					if (dartParam.Entry != null)
					{
						dartParam.Entry.Value = Mathf.Clamp(dartParam.DefaultValue, dartParam.Min, dartParam.Max);
					}
				}
			}
		}

		internal bool IsMenuHotkeyDown()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Invalid comparison between Unknown and I4
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Invalid comparison between Unknown and I4
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Invalid comparison between Unknown and I4
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Invalid comparison between Unknown and I4
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Invalid comparison between Unknown and I4
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Invalid comparison between Unknown and I4
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Invalid comparison between Unknown and I4
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			if (BlowDartMenu.IsListeningForHotkey)
			{
				return false;
			}
			KeyCode val = (KeyCode)((CFG_MenuKey == null) ? 98 : ((int)CFG_MenuKey.Value));
			if ((int)val == 0)
			{
				return false;
			}
			KeyCode val2 = (KeyCode)((CFG_MenuModifier == null) ? 306 : ((int)CFG_MenuModifier.Value));
			if ((int)val2 == 0)
			{
				return Input.GetKeyDown(val);
			}
			bool flag = Input.GetKey(val2);
			if ((int)val2 == 306 || (int)val2 == 305)
			{
				flag = Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305);
			}
			else if ((int)val2 == 308 || (int)val2 == 307)
			{
				flag = Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307);
			}
			else if ((int)val2 == 304 || (int)val2 == 303)
			{
				flag = Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303);
			}
			return flag && Input.GetKeyDown(val);
		}

		internal static KeyCode GetMenuKey()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			return (KeyCode)((CFG_MenuKey == null) ? 98 : ((int)CFG_MenuKey.Value));
		}

		internal static KeyCode GetMenuModifier()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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)
			return (KeyCode)((CFG_MenuModifier == null) ? 306 : ((int)CFG_MenuModifier.Value));
		}

		internal static bool GetShowPauseMenuButton()
		{
			return CFG_ShowPauseMenuButton == null || CFG_ShowPauseMenuButton.Value;
		}

		internal static void SetShowPauseMenuButton(bool enabled)
		{
			if (CFG_ShowPauseMenuButton != null)
			{
				CFG_ShowPauseMenuButton.Value = enabled;
			}
		}

		internal static string FormatHotkey()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			KeyCode menuKey = GetMenuKey();
			KeyCode menuModifier = GetMenuModifier();
			if ((int)menuModifier == 0)
			{
				return PrettyKey(menuKey);
			}
			return PrettyKey(menuModifier) + " + " + PrettyKey(menuKey);
		}

		internal static void SetMenuKey(KeyCode key)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Invalid comparison between Unknown and I4
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if (CFG_MenuKey != null && (int)key > 0)
			{
				CFG_MenuKey.Value = key;
			}
		}

		internal static void SetMenuModifier(KeyCode key)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			if (CFG_MenuModifier != null)
			{
				CFG_MenuModifier.Value = key;
			}
		}

		internal unsafe static string PrettyKey(KeyCode key)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Invalid comparison between Unknown and I4
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected I4, but got Unknown
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			KeyCode val = key;
			KeyCode val2 = val;
			if ((int)val2 <= 13)
			{
				if ((int)val2 == 0)
				{
					return "None";
				}
				if ((int)val2 == 13)
				{
					return "Enter";
				}
			}
			else
			{
				if ((int)val2 == 27)
				{
					return "Esc";
				}
				switch (val2 - 303)
				{
				case 3:
					return "Left Ctrl";
				case 2:
					return "Right Ctrl";
				case 5:
					return "Left Alt";
				case 4:
					return "Right Alt";
				case 1:
					return "Left Shift";
				case 0:
					return "Right Shift";
				}
			}
			string text = ((object)(*(KeyCode*)(&key))/*cast due to .constrained prefix*/).ToString();
			if (text.StartsWith("Alpha", StringComparison.Ordinal) && text.Length == 6)
			{
				return text.Substring(5);
			}
			return text;
		}

		private void OnDestroy()
		{
			try
			{
				PresetStore.SaveDefaultQuiet();
			}
			catch
			{
			}
			try
			{
				SceneManager.sceneLoaded -= OnSceneLoaded;
			}
			catch
			{
			}
			((BaseUnityPlugin)this).Config.SettingChanged -= OnConfigChanged;
			BlowDartMenu.DestroyInstance();
			NetworkSync.Shutdown();
			if (_harmony != null)
			{
				_harmony.UnpatchSelf();
			}
		}

		private void OnConfigChanged(object sender, SettingChangedEventArgs e)
		{
			if (!NetworkSync.IsSyncingFromNet && e != null && (object)e.ChangedSetting != CFG_MenuKey && (object)e.ChangedSetting != CFG_MenuModifier && (object)e.ChangedSetting != CFG_ShowPauseMenuButton)
			{
				NetworkSync.ScheduleConfigBroadcast();
			}
		}

		internal string PackConfigData()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendLine("ENABLE_Mod=" + IsModEnabled);
			foreach (KeyValuePair<string, ConfigEntry<bool>> item in _enableById)
			{
				stringBuilder.AppendLine("ENABLE_" + item.Key + "=" + item.Value.Value);
			}
			foreach (KeyValuePair<string, ConfigEntry<float>> item2 in _chanceById)
			{
				stringBuilder.AppendLine("CHANCE_" + item2.Key + "=" + item2.Value.Value.ToString(CultureInfo.InvariantCulture));
			}
			foreach (KeyValuePair<string, ConfigEntry<float>> item3 in _amountById)
			{
				stringBuilder.AppendLine("AMOUNT_" + item3.Key + "=" + item3.Value.Value.ToString(CultureInfo.InvariantCulture));
			}
			foreach (KeyValuePair<string, ConfigEntry<float>> item4 in _durationById)
			{
				stringBuilder.AppendLine("DURATION_" + item4.Key + "=" + item4.Value.Value.ToString(CultureInfo.InvariantCulture));
			}
			stringBuilder.AppendLine("MOVESPEED_FasterBoi=" + CFG_FasterBoiMoveSpeed.Value.ToString(CultureInfo.InvariantCulture));
			stringBuilder.AppendLine("CLIMBSPEED_FasterBoi=" + CFG_FasterBoiClimbSpeed.Value.ToString(CultureInfo.InvariantCulture));
			if (MenuTypes != null)
			{
				for (int i = 0; i < MenuTypes.Length; i++)
				{
					DartTypeInfo dartTypeInfo = MenuTypes[i];
					if (dartTypeInfo.Params == null)
					{
						continue;
					}
					for (int j = 0; j < dartTypeInfo.Params.Length; j++)
					{
						DartParam dartParam = dartTypeInfo.Params[j];
						if (dartParam.Entry != null)
						{
							stringBuilder.AppendLine("PARAM_" + dartTypeInfo.Id + "_" + ParamKey(dartParam.Label) + "=" + dartParam.Entry.Value.ToString(CultureInfo.InvariantCulture));
						}
					}
				}
			}
			return Convert.ToBase64String(Encoding.UTF8.GetBytes(stringBuilder.ToString()));
		}

		internal void UnpackConfigData(string configData)
		{
			try
			{
				string text = Encoding.UTF8.GetString(Convert.FromBase64String(configData));
				string[] array = text.Split(new char[1] { '\n' });
				string[] array2 = array;
				foreach (string text2 in array2)
				{
					if (string.IsNullOrWhiteSpace(text2))
					{
						continue;
					}
					string[] array3 = text2.Split(new char[1] { '=' }, 2);
					if (array3.Length != 2)
					{
						continue;
					}
					string text3 = array3[0].Trim();
					string text4 = array3[1].Trim();
					float result6;
					float result7;
					float result8;
					if (text3 == "ENABLE_Mod")
					{
						if (CFG_ModEnabled != null && bool.TryParse(text4, out var result))
						{
							CFG_ModEnabled.Value = result;
						}
					}
					else if (text3.StartsWith("ENABLE_"))
					{
						if (_enableById.TryGetValue(text3.Substring(7), out var value) && bool.TryParse(text4, out var result2))
						{
							value.Value = result2;
						}
					}
					else if (text3.StartsWith("CHANCE_"))
					{
						if (_chanceById.TryGetValue(text3.Substring(7), out var value2) && float.TryParse(text4, NumberStyles.Float, CultureInfo.InvariantCulture, out var result3))
						{
							value2.Value = Mathf.Clamp01(result3);
						}
					}
					else if (text3.StartsWith("AMOUNT_"))
					{
						if (_amountById.TryGetValue(text3.Substring(7), out var value3) && float.TryParse(text4, NumberStyles.Float, CultureInfo.InvariantCulture, out var result4))
						{
							value3.Value = result4;
						}
					}
					else if (text3.StartsWith("DURATION_"))
					{
						if (_durationById.TryGetValue(text3.Substring(9), out var value4) && float.TryParse(text4, NumberStyles.Float, CultureInfo.InvariantCulture, out var result5))
						{
							value4.Value = result5;
						}
					}
					else if (text3.StartsWith("MOVESPEED_") && float.TryParse(text4, NumberStyles.Float, CultureInfo.InvariantCulture, out result6))
					{
						CFG_FasterBoiMoveSpeed.Value = result6;
					}
					else if (text3.StartsWith("CLIMBSPEED_") && float.TryParse(text4, NumberStyles.Float, CultureInfo.InvariantCulture, out result7))
					{
						CFG_FasterBoiClimbSpeed.Value = result7;
					}
					else if (text3.StartsWith("PARAM_") && float.TryParse(text4, NumberStyles.Float, CultureInfo.InvariantCulture, out result8))
					{
						ApplyPackedParam(text3.Substring(6), result8);
					}
				}
				BlowDartMenu.RefreshIfOpen();
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("[Peak Blow Darts] Failed to unpack host config: " + ex));
			}
		}

		private static string ParamKey(string label)
		{
			if (string.IsNullOrEmpty(label))
			{
				return "Value";
			}
			return label.Replace(" ", string.Empty).Replace("(", string.Empty).Replace(")", string.Empty);
		}

		private static void ApplyPackedParam(string packed, float value)
		{
			if (MenuTypes == null || string.IsNullOrEmpty(packed))
			{
				return;
			}
			int num = packed.IndexOf('_');
			if (num <= 0 || num >= packed.Length - 1)
			{
				return;
			}
			string b = packed.Substring(0, num);
			string b2 = packed.Substring(num + 1);
			for (int i = 0; i < MenuTypes.Length; i++)
			{
				DartTypeInfo dartTypeInfo = MenuTypes[i];
				if (!string.Equals(dartTypeInfo.Id, b, StringComparison.Ordinal) || dartTypeInfo.Params == null)
				{
					continue;
				}
				for (int j = 0; j < dartTypeInfo.Params.Length; j++)
				{
					DartParam dartParam = dartTypeInfo.Params[j];
					if (dartParam.Entry != null && string.Equals(ParamKey(dartParam.Label), b2, StringComparison.OrdinalIgnoreCase))
					{
						dartParam.Entry.Value = Mathf.Clamp(value, dartParam.Min, dartParam.Max);
						return;
					}
				}
			}
		}

		internal static bool IsBlowDart(Item item)
		{
			if (!Object.op_Implicit((Object)(object)item))
			{
				return false;
			}
			return (Object)(object)((Component)item).GetComponent<Action_RaycastDart>() != (Object)null;
		}

		private static void SetItemUIName(Item item, string name)
		{
			if (Object.op_Implicit((Object)(object)item) && item.UIData != null)
			{
				item.UIData.itemName = name;
			}
		}

		private static string GetDartName(BlowDartType dartType)
		{
			return (dartType switch
			{
				BlowDartType.Injury => "Injury Blow Gun", 
				BlowDartType.Poison => "Poison Blow Gun", 
				BlowDartType.Cold => "Frosting Blow Gun", 
				BlowDartType.Hunger => "Hunger Blow Gun", 
				BlowDartType.Drowsy => "Drowsy Blow Gun", 
				BlowDartType.Curse => "Curse Blow Gun", 
				BlowDartType.Hot => "Burning Blow Gun", 
				BlowDartType.Crab => "Crabby Blow Gun", 
				BlowDartType.InfiniteStamina => "Infinite Stamina Blow Gun", 
				BlowDartType.ExtraStamina => "Extra Stamina Blow Gun", 
				BlowDartType.FasterBoi => "Energy Blow Gun", 
				BlowDartType.AfflictionClearer => "Affliction Clearer Blow Gun", 
				BlowDartType.Chaos => "Pandoras Blow Gun", 
				BlowDartType.Invincibility => "Invincibility Blow Gun", 
				BlowDartType.Weight => "Heavy Blow Gun", 
				BlowDartType.Thorns => "Thorn Blow Gun", 
				BlowDartType.Spores => "Spore Blow Gun", 
				BlowDartType.Web => "Web Blow Gun", 
				BlowDartType.Arrow => "Arrow Blow Gun", 
				BlowDartType.Petrify => "Petrify Blow Gun", 
				BlowDartType.FlyTrap => "Flytrap Blow Gun", 
				BlowDartType.Blind => "Blind Blow Gun", 
				BlowDartType.Numb => "Numb Blow Gun", 
				BlowDartType.Exhausted => "Exhaustion Blow Gun", 
				BlowDartType.HealAll => "Heal-All Blow Gun", 
				BlowDartType.HungerBlock => "HungerBlock Blow Gun", 
				BlowDartType.Sunscreen => "Sunscreen Blow Gun", 
				BlowDartType.LowGravity => "Low Gravity Blow Gun", 
				BlowDartType.ClimbingChalk => "Chalk Blow Gun", 
				BlowDartType.DoubleJump => "Double Jump Blow Gun", 
				BlowDartType.BeetleBonk => "Beetle Bonk Blow Gun", 
				BlowDartType.Bonk => "Bonk Blow Gun", 
				BlowDartType.AntiSphere => "AntiSphere Blow Gun", 
				BlowDartType.Scorpion => "Scorpion Blow Gun", 
				BlowDartType.Tornado => "Tornado Blow Gun", 
				BlowDartType.Frog => "Frog Blow Gun", 
				BlowDartType.FrogTongue => "Frog Tongue Blow Gun", 
				BlowDartType.BookOfBones => "Book of Bones Blow Gun", 
				BlowDartType.BeeSwarm => "Bee Swarm Blow Gun", 
				BlowDartType.Explosive => "Explosive Blow Gun", 
				BlowDartType.Warp => "Warp Blow Gun", 
				BlowDartType.Tick => "Tick Blow Gun", 
				BlowDartType.Summon => "Summon Blow Gun", 
				BlowDartType.RocketPack => "Rocketpack Blow Gun", 
				_ => "Modified Blow Gun", 
			}).ToUpperInvariant();
		}

		private static Affliction CreateStatus(STATUSTYPE statusType, float amount)
		{
			//IL_0001: 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_000e: Expected O, but got Unknown
			return (Affliction)new Affliction_AdjustStatus(statusType, amount, 0f);
		}

		private static Affliction CreateAffliction(BlowDartType dartType)
		{
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Expected O, but got Unknown
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Expected O, but got Unknown
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Expected O, but got Unknown
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Expected O, but got Unknown
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Expected O, but got Unknown
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_034a: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: Expected O, but got Unknown
			//IL_0360: Unknown result type (might be due to invalid IL or missing references)
			//IL_0365: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Expected O, but got Unknown
			//IL_037b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0380: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ab: Expected O, but got Unknown
			//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c6: Expected O, but got Unknown
			//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03de: Expected O, but got Unknown
			//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f0: Expected O, but got Unknown
			//IL_0411: Unknown result type (might be due to invalid IL or missing references)
			//IL_0417: Expected O, but got Unknown
			//IL_0419: Unknown result type (might be due to invalid IL or missing references)
			//IL_041e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0429: Unknown result type (might be due to invalid IL or missing references)
			//IL_0435: Expected O, but got Unknown
			//IL_0437: Unknown result type (might be due to invalid IL or missing references)
			//IL_043d: Expected O, but got Unknown
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Expected O, but got Unknown
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Expected O, but got Unknown
			switch (dartType)
			{
			case BlowDartType.Injury:
				return CreateStatus((STATUSTYPE)0, CFG_InjuryAmount.Value);
			case BlowDartType.Poison:
				if (CFG_PoisonDuration.Value > 0.05f)
				{
					return (Affliction)new Affliction_PoisonOverTime(CFG_PoisonDuration.Value, 0f, CFG_PoisonAmount.Value);
				}
				return CreateStatus((STATUSTYPE)3, CFG_PoisonAmount.Value);
			case BlowDartType.Cold:
				if (CFG_ColdDuration.Value > 0.05f)
				{
					return (Affliction)new Affliction_AdjustColdOverTime(CFG_ColdAmount.Value, CFG_ColdDuration.Value);
				}
				return CreateStatus((STATUSTYPE)2, CFG_ColdAmount.Value);
			case BlowDartType.Hunger:
				return CreateStatus((STATUSTYPE)1, CFG_HungerAmount.Value);
			case BlowDartType.Drowsy:
				return CreateStatus((STATUSTYPE)6, CFG_DrowsyAmount.Value);
			case BlowDartType.Curse:
				return CreateStatus((STATUSTYPE)5, CFG_CurseAmount.Value);
			case BlowDartType.Hot:
				return CreateStatus((STATUSTYPE)8, CFG_HotAmount.Value);
			case BlowDartType.Crab:
				return CreateStatus((STATUSTYPE)4, CFG_CrabAmount.Value);
			case BlowDartType.InfiniteStamina:
				return (Affliction)new Affliction_InfiniteStamina(CFG_InfiniteStaminaDuration.Value)
				{
					drowsyAffliction = null,
					climbDelay = 0f
				};
			case BlowDartType.ExtraStamina:
				return (Affliction)new Affliction_AddBonusStamina(Mathf.Clamp(CFG_ExtraStaminaAmount.Value, 0f, 1f), 0f);
			case BlowDartType.FasterBoi:
				return (Affliction)new Affliction_FasterBoi
				{
					totalTime = CFG_FasterBoiDuration.Value,
					moveSpeedMod = CFG_FasterBoiMoveSpeed.Value,
					climbSpeedMod = CFG_FasterBoiClimbSpeed.Value,
					drowsyOnEnd = 0f,
					climbDelay = 0f
				};
			case BlowDartType.AfflictionClearer:
				return null;
			case BlowDartType.Chaos:
				return (Affliction)new Affliction_Chaos(0.5f, 0.2f, 0.3f, 0.1f);
			case BlowDartType.Invincibility:
				return (Affliction)new Affliction_Invincibility
				{
					totalTime = CFG_InvincibilityDuration.Value,
					isFromMilk = false,
					isFromAmulet = false
				};
			case BlowDartType.Weight:
				return CreateStatus((STATUSTYPE)7, 0.25f);
			case BlowDartType.Thorns:
			case BlowDartType.Arrow:
			case BlowDartType.BeetleBonk:
			case BlowDartType.Bonk:
			case BlowDartType.AntiSphere:
			case BlowDartType.Scorpion:
			case BlowDartType.Tornado:
			case BlowDartType.Frog:
			case BlowDartType.BookOfBones:
			case BlowDartType.BeeSwarm:
			case BlowDartType.Explosive:
			case BlowDartType.Warp:
			case BlowDartType.Tick:
			case BlowDartType.Summon:
			case BlowDartType.RocketPack:
			case BlowDartType.FrogTongue:
				return null;
			case BlowDartType.Spores:
				return CreateStatus((STATUSTYPE)10, CFG_SporesAmount.Value);
			case BlowDartType.Web:
				return CreateStatus((STATUSTYPE)11, CFG_WebAmount.Value);
			case BlowDartType.Petrify:
				return CreateStatus((STATUSTYPE)13, CFG_PetrifyAmount.Value);
			case BlowDartType.FlyTrap:
				return CreateStatus((STATUSTYPE)14, CFG_FlyTrapAmount.Value);
			case BlowDartType.Blind:
				return (Affliction)new Affliction_Blind
				{
					totalTime = CFG_BlindDuration.Value
				};
			case BlowDartType.Numb:
				return (Affliction)new Affliction_Numb
				{
					totalTime = CFG_NumbDuration.Value
				};
			case BlowDartType.Exhausted:
				return (Affliction)new Affliction_Exhaustion
				{
					totalTime = Mathf.Max(0.1f, CFG_ExhaustedDuration.Value),
					drainAmount = CFG_ExhaustedDrain.Value
				};
			case BlowDartType.HealAll:
				return (Affliction)new Affliction_HealAll
				{
					maxHealing = CFG_HealAllAmount.Value
				};
			case BlowDartType.HungerBlock:
				return (Affliction)new Affliction_NoHunger
				{
					totalTime = CFG_HungerBlockDuration.Value
				};
			case BlowDartType.Sunscreen:
				return (Affliction)new Affliction_Sunscreen(CFG_SunscreenDuration.Value);
			case BlowDartType.LowGravity:
				return (Affliction)new Affliction_LowGravity(Mathf.Max(1, Mathf.RoundToInt(CFG_LowGravityAmount.Value)), CFG_LowGravityDuration.Value);
			case BlowDartType.ClimbingChalk:
				return (Affliction)new Affliction_ClimbingChalk
				{
					totalTime = 30f,
					climbStaminaMultiplier = 0.5f
				};
			case BlowDartType.DoubleJump:
				return (Affliction)new Affliction_DoubleJumpAmulet();
			default:
				return null;
			}
		}

		private static BlowDartType GetRandomDartType()
		{
			List<(BlowDartType, float)> list = new List<(BlowDartType, float)>(_rolls.Count);
			for (int i = 0; i < _rolls.Count; i++)
			{
				DartRoll dartRoll = _rolls[i];
				if (dartRoll.Enable.Value)
				{
					list.Add((dartRoll.Type, dartRoll.Chance.Value));
				}
			}
			if (list.Count == 0)
			{
				return BlowDartType.Unmodified;
			}
			float num = 0f;
			foreach (var item in list)
			{
				num += item.Item2;
			}
			if (num <= 0f)
			{
				return BlowDartType.Unmodified;
			}
			float num2 = Random.Range(0f, num);
			float num3 = 0f;
			foreach (var item2 in list)
			{
				num3 += item2.Item2;
				if (num2 <= num3)
				{
					return item2.Item1;
				}
			}
			return list[0].Item1;
		}

		internal static bool TryGetDartType(Item item, ItemInstanceData data, out BlowDartType dartType)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			dartType = BlowDartType.Unmodified;
			if (!IsBlowDart(item) && data == null)
			{
				return false;
			}
			IntItemData val = default(IntItemData);
			if (data != null && data.TryGetDataEntry<IntItemData>(BlowDartDataEntryKey.DartType, ref val) && val != null)
			{
				dartType = (BlowDartType)val.Value;
				return true;
			}
			if ((Object)(object)item != (Object)null && item.HasData(BlowDartDataEntryKey.DartType))
			{
				val = item.GetData<IntItemData>(BlowDartDataEntryKey.DartType);
				if (val != null)
				{
					dartType = (BlowDartType)val.Value;
					return true;
				}
			}
			return NetworkSync.TryGetRememberedDart(item, out dartType);
		}

		internal static void ApplyDartType(Item item, BlowDartType dartType)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkSync.ShouldApplyModEffects() && IsBlowDart(item))
			{
				PhotonView itemView = NetworkSync.GetItemView(item);
				if ((Object)(object)itemView != (Object)null)
				{
					NetworkSync.RememberDart(itemView.ViewID, dartType);
				}
				IntItemData data = item.GetData<IntItemData>(BlowDartDataEntryKey.DartType);
				data.Value = (int)dartType;
				if (dartType != BlowDartType.Unmodified)
				{
					ModifyToDartType(item, dartType);
				}
			}
		}

		internal static void ApplyAllExistingBlowDarts()
		{
			Item[] array = Object.FindObjectsByType<Item>((FindObjectsSortMode)0);
			for (int i = 0; i < array.Length; i++)
			{
				if (TryGetDartType(array[i], null, out var dartType))
				{
					ApplyDartType(array[i], dartType);
				}
			}
		}

		internal static void FinishDeferredAssign(Item item)
		{
			if (!IsBlowDart(item) || !NetworkSync.ShouldApplyModEffects())
			{
				return;
			}
			if (TryGetDartType(item, null, out var dartType))
			{
				ApplyDartType(item, dartType);
				if (NetworkSync.CanAssignNewDarts())
				{
					NetworkSync.PushItemInstanceData(item);
					NetworkSync.BroadcastDart(item, dartType);
				}
			}
			else if (!NetworkSync.CanAssignNewDarts())
			{
				NetworkSync.RequestDartFromHost(item);
			}
			else
			{
				AssignNewDartType(item);
			}
		}

		private static void TryHandleBlowDart(Item item)
		{
			if (!IsBlowDart(item) || !NetworkSync.ShouldApplyModEffects())
			{
				return;
			}
			if (TryGetDartType(item, null, out var dartType))
			{
				ApplyDartType(item, dartType);
				if (NetworkSync.CanAssignNewDarts())
				{
					NetworkSync.PushItemInstanceData(item);
					NetworkSync.BroadcastDart(item, dartType);
				}
			}
			else if (NetworkSync.CanAssignNewDarts())
			{
				NetworkSync.StartDeferredAssign(item);
			}
			else
			{
				NetworkSync.RequestDartFromHost(item);
				NetworkSync.StartClientCatchup(item);
			}
		}

		private static void AssignNewDartType(Item item)
		{
			BlowDartType randomDartType = GetRandomDartType();
			ApplyDartType(item, randomDartType);
			NetworkSync.PushItemInstanceData(item);
			NetworkSync.BroadcastDart(item, randomDartType);
		}

		private static void ModifyToDartType(Item dartItem, BlowDartType dartType)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Action_RaycastDart component = ((Component)dartItem).GetComponent<Action_RaycastDart>();
				if (!((Object)(object)component == (Object)null))
				{
					Affliction val = CreateAffliction(dartType);
					component.afflictionsOnHit = (Affliction[])(object)((val == null) ? new Affliction[0] : new Affliction[1] { val });
					SetItemUIName(dartItem, GetDartName(dartType));
					IntItemData data = dartItem.GetData<IntItemData>(BlowDartDataEntryKey.DartType);
					data.Value = (int)dartType;
				}
			}
			catch (Exception ex)
			{
				LogOnce(ref _loggedModifyError, "Failed to modify blow gun to " + dartType, ex);
			}
		}

		internal static void LogInfo(string message)
		{
			if ((Object)(object)Instance != (Object)null)
			{
				((BaseUnityPlugin)Instance).Logger.LogInfo((object)message);
			}
		}

		internal static void LogWarning(string message)
		{
			if ((Object)(object)Instance != (Object)null)
			{
				((BaseUnityPlugin)Instance).Logger.LogWarning((object)message);
			}
		}

		internal static void LogError(string message)
		{
			if ((Object)(object)Instance != (Object)null)
			{
				((BaseUnityPlugin)Instance).Logger.LogError((object)message);
			}
		}

		internal static void LogOnceSync(string message, Exception ex)
		{
			LogOnce(ref _loggedSyncError, message, ex);
		}

		private static void LogOnce(ref bool flag, string message, Exception ex)
		{
			if (!flag)
			{
				flag = true;
				if ((Object)(object)Instance != (Object)null)
				{
					((BaseUnityPlugin)Instance).Logger.LogError((object)("[Peak Blow Darts] " + message + ": " + ex));
				}
			}
		}
	}
	internal static class NetworkSync
	{
		private sealed class NetProxy : MonoBehaviourPunCallbacks, IOnEventCallback
		{
			private Coroutine _debounce;

			private Coroutine _hostSyncWatch;

			public override void OnEnable()
			{
				((MonoBehaviourPunCallbacks)this).OnEnable();
				PhotonNetwork.AddCallbackTarget((object)this);
			}

			public override void OnDisable()
			{
				PhotonNetwork.RemoveCallbackTarget((object)this);
				((MonoBehaviourPunCallbacks)this).OnDisable();
			}

			public override void OnJoinedRoom()
			{
				HandleJoinedRoom();
			}

			public override void OnLeftRoom()
			{
				StopHostSyncWatch();
				TypeByViewId.Clear();
				DeferredAssignInFlight.Clear();
				SetSoloState();
			}

			public override void OnMasterClientSwitched(Player newMasterClient)
			{
				HandleJoinedRoom();
			}

			public override void OnPlayerEnteredRoom(Player newPlayer)
			{
				if (PhotonNetwork.IsMasterClient)
				{
					((MonoBehaviour)this).StartCoroutine(BroadcastAfterJoin());
				}
			}

			public void OnEvent(EventData photonEvent)
			{
				HandleEvent(photonEvent);
			}

			internal void HandleJoinedRoom()
			{
				if (!PhotonNetwork.InRoom)
				{
					SetSoloState();
				}
				else if (PhotonNetwork.IsMasterClient)
				{
					HostModConfirmed = true;
					VanillaHostMode = false;
					StopHostSyncWatch();
					BroadcastConfigNow();
					BroadcastAllDarts();
				}
				else
				{
					HostModConfirmed = false;
					VanillaHostMode = false;
					RequestHostSync();
					RestartHostSyncWatch();
				}
			}

			internal void ScheduleConfigBroadcast()
			{
				if (_debounce != null)
				{
					((MonoBehaviour)this).StopCoroutine(_debounce);
				}
				_debounce = ((MonoBehaviour)this).StartCoroutine(DebounceBroadcast());
			}

			internal void StopHostSyncWatch()
			{
				if (_hostSyncWatch != null)
				{
					((MonoBehaviour)this).StopCoroutine(_hostSyncWatch);
					_hostSyncWatch = null;
				}
			}

			private void RestartHostSyncWatch()
			{
				StopHostSyncWatch();
				if (PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient)
				{
					_hostSyncWatch = ((MonoBehaviour)this).StartCoroutine(WatchForHostSync());
				}
			}

			private IEnumerator DebounceBroadcast()
			{
				yield return (object)new WaitForSeconds(0.25f);
				BroadcastConfigNow();
				PEAKBlowDartsPlugin.ApplyAllExistingBlowDarts();
				_debounce = null;
			}

			private IEnumerator BroadcastAfterJoin()
			{
				yield return (object)new WaitForSeconds(0.5f);
				BroadcastConfigNow();
				BroadcastAllDarts();
			}

			private IEnumerator WatchForHostSync()
			{
				float elapsed = 0f;
				float nextRetry = 2f;
				while (elapsed < 12f)
				{
					if (!PhotonNetwork.InRoom || PhotonNetwork.IsMasterClient || HostModConfirmed)
					{
						yield break;
					}
					elapsed += Time.unscaledDeltaTime;
					if (elapsed >= nextRetry)
					{
						RequestHostSync();
						nextRetry += 2f;
					}
					yield return null;
				}
				if (PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient && !HostModConfirmed)
				{
					VanillaHostMode = true;
					PEAKBlowDartsPlugin.LogWarning("[Peak Blow Darts] Host does not appear to have Peak Blow Darts — leaving blow guns vanilla.");
				}
				_hostSyncWatch = null;
			}
		}

		internal static readonly byte EventCode = ComputeEventCode();

		internal const string Magic = "tony.PEAK_Blow_Darts";

		internal const int ProtocolVersion = 100;

		private const byte SubConfig = 1;

		private const byte SubConfigRequest = 2;

		private const byte SubDartSync = 3;

		private const byte SubDartRequest = 4;

		private const float HostSyncTimeoutSeconds = 12f;

		private const float HostSyncRetrySeconds = 2f;

		internal static bool HostModConfirmed;

		internal static bool VanillaHostMode;

		internal static bool IsSyncingFromNet;

		private static NetProxy _proxy;

		private static readonly Dictionary<int, BlowDartType> TypeByViewId = new Dictionary<int, BlowDartType>();

		private static readonly HashSet<int> DeferredAssignInFlight = new HashSet<int>();

		private static byte ComputeEventCode()
		{
			int num = -2128831035;
			string text = "tony4twentys.PEAK_Blow_Darts";
			for (int i = 0; i < text.Length; i++)
			{
				num = (num ^ text[i]) * 16777619;
			}
			int num2 = ((num != int.MinValue) ? Math.Abs(num) : 0);
			return (byte)(180 + num2 % 20);
		}

		private static object[] Payload(byte sub)
		{
			return new object[3] { "tony.PEAK_Blow_Darts", 100, sub };
		}

		private static object[] Payload(byte sub, object arg0)
		{
			return new object[4] { "tony.PEAK_Blow_Darts", 100, sub, arg0 };
		}

		private static object[] Payload(byte sub, object arg0, object arg1)
		{
			return new object[5] { "tony.PEAK_Blow_Darts", 100, sub, arg0, arg1 };
		}

		internal static bool ShouldApplyModEffects()
		{
			return !VanillaHostMode && PEAKBlowDartsPlugin.IsModEnabled;
		}

		internal static bool CanAssignNewDarts()
		{
			if (VanillaHostMode)
			{
				return false;
			}
			if (!PhotonNetwork.InRoom)
			{
				return true;
			}
			return PhotonNetwork.IsMasterClient;
		}

		internal static void Initialize(PEAKBlowDartsPlugin plugin)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			if (!((Object)(object)_proxy != (Object)null))
			{
				GameObject val = new GameObject("PeakBlowDartsNet");
				Object.DontDestroyOnLoad((Object)(object)val);
				_proxy = val.AddComponent<NetProxy>();
				byte eventCode = EventCode;
				PEAKBlowDartsPlugin.LogInfo("[Peak Blow Darts] RaiseEvent code=" + eventCode + " magic=tony.PEAK_Blow_Darts.");
				if (PhotonNetwork.InRoom)
				{
					_proxy.HandleJoinedRoom();
				}
				else
				{
					SetSoloState();
				}
			}
		}

		internal static void Shutdown()
		{
			if ((Object)(object)_proxy != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_proxy).gameObject);
				_proxy = null;
			}
			TypeByViewId.Clear();
			DeferredAssignInFlight.Clear();
			HostModConfirmed = false;
			VanillaHostMode = false;
			IsSyncingFromNet = false;
		}

		internal static void ScheduleConfigBroadcast()
		{
			if (!((Object)(object)_proxy == (Object)null) && PhotonNetwork.InRoom && PhotonNetwork.IsMasterClient && !IsSyncingFromNet)
			{
				_proxy.ScheduleConfigBroadcast();
			}
		}

		internal static PhotonView GetItemView(Item item)
		{
			if ((Object)(object)item == (Object)null)
			{
				return null;
			}
			try
			{
				if ((Object)(object)((MonoBehaviourPun)item).photonView != (Object)null)
				{
					return ((MonoBehaviourPun)item).photonView;
				}
			}
			catch
			{
			}
			return ((Component)item).GetComponent<PhotonView>();
		}

		internal static void RememberDart(int viewId, BlowDartType dartType)
		{
			if (viewId > 0)
			{
				TypeByViewId[viewId] = dartType;
			}
		}

		internal static bool TryGetRememberedDart(int viewId, out BlowDartType dartType)
		{
			return TypeByViewId.TryGetValue(viewId, out dartType);
		}

		internal static bool TryGetRememberedDart(Item item, out BlowDartType dartType)
		{
			dartType = BlowDartType.Unmodified;
			PhotonView itemView = GetItemView(item);
			return (Object)(object)itemView != (Object)null && TryGetRememberedDart(itemView.ViewID, out dartType);
		}

		internal static void BroadcastDart(Item item, BlowDartType dartType)
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			if ((Object)(object)item == (Object)null || !PhotonNetwork.InRoom)
			{
				return;
			}
			PhotonView itemView = GetItemView(item);
			if ((Object)(object)itemView == (Object)null || (!itemView.IsMine && !PhotonNetwork.IsMasterClient))
			{
				return;
			}
			RememberDart(itemView.ViewID, dartType);
			try
			{
				PhotonNetwork.RaiseEvent(EventCode, (object)Payload(3, itemView.ViewID, (int)dartType), new RaiseEventOptions
				{
					Receivers = (ReceiverGroup)0
				}, SendOptions.SendReliable);
			}
			catch (Exception ex)
			{
				PEAKBlowDartsPlugin.LogOnceSync("RaiseEvent dart sync failed", ex);
			}
		}

		internal static void PushItemInstanceData(Item item)
		{
			if ((Object)(object)item == (Object)null || item.data == null || !PhotonNetwork.InRoom)
			{
				return;
			}
			PhotonView itemView = GetItemView(item);
			if ((Object)(object)itemView == (Object)null || (!itemView.IsMine && !PhotonNetwork.IsMasterClient))
			{
				return;
			}
			try
			{
				itemView.RPC("SetItemInstanceDataRPC", (RpcTarget)1, new object[1] { item.data });
			}
			catch (Exception ex)
			{
				PEAKBlowDartsPlugin.LogOnceSync("SetItemInstanceDataRPC failed", ex);
			}
		}

		internal static void RequestDartFromHost(Item item)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_0067: Expected O, but got Unknown
			if ((Object)(object)item == (Object)null || !PhotonNetwork.InRoom || PhotonNetwork.IsMasterClient)
			{
				return;
			}
			PhotonView itemView = GetItemView(item);
			if ((Object)(object)itemView == (Object)null)
			{
				return;
			}
			try
			{
				PhotonNetwork.RaiseEvent(EventCode, (object)Payload(4, itemView.ViewID, 0), new RaiseEventOptions
				{
					Receivers = (ReceiverGroup)2
				}, SendOptions.SendReliable);
			}
			catch (Exception ex)
			{
				PEAKBlowDartsPlugin.LogOnceSync("dart request failed", ex);
			}
		}

		internal static void BroadcastAllDarts()
		{
			if (!PhotonNetwork.IsMasterClient)
			{
				return;
			}
			Item[] array = Object.FindObjectsByType<Item>((FindObjectsSortMode)0);
			foreach (Item item in array)
			{
				if (PEAKBlowDartsPlugin.TryGetDartType(item, null, out var dartType))
				{
					BroadcastDart(item, dartType);
					PushItemInstanceData(item);
				}
			}
		}

		internal static bool TryBeginDeferredAssign(int key)
		{
			return DeferredAssignInFlight.Add(key);
		}

		internal static void EndDeferredAssign(int key)
		{
			DeferredAssignInFlight.Remove(key);
		}

		internal static void StartDeferredAssign(Item item)
		{
			if (!((Object)(object)_proxy == (Object)null) && !((Object)(object)item == (Object)null))
			{
				PhotonView itemView = GetItemView(item);
				int key = (((Object)(object)itemView != (Object)null && itemView.ViewID > 0) ? itemView.ViewID : ((Object)item).GetInstanceID());
				if (TryBeginDeferredAssign(key))
				{
					((MonoBehaviour)_proxy).StartCoroutine(DeferredAssignRoutine(item, key));
				}
			}
		}

		internal static void StartClientCatchup(Item item)
		{
			if (!((Object)(object)_proxy == (Object)null) && !((Object)(object)item == (Object)null) && !PhotonNetwork.IsMasterClient)
			{
				((MonoBehaviour)_proxy).StartCoroutine(ClientCatchupRoutine(item));
			}
		}

		private static IEnumerator DeferredAssignRoutine(Item item, int key)
		{
			yield return (object)new WaitForSeconds(0.2f);
			PhotonView view = GetItemView(item);
			if ((Object)(object)item != (Object)null && ((Object)(object)view == (Object)null || view.ViewID <= 0))
			{
				yield return (object)new WaitForSeconds(0.35f);
			}
			try
			{
				if ((Object)(object)item != (Object)null)
				{
					PEAKBlowDartsPlugin.FinishDeferredAssign(item);
				}
			}
			finally
			{
				EndDeferredAssign(key);
			}
		}

		private static IEnumerator ClientCatchupRoutine(Item item)
		{
			float[] waits = new float[3] { 0.05f, 0.2f, 0.5f };
			for (int i = 0; i < waits.Length; i++)
			{
				yield return (object)new WaitForSeconds(waits[i]);
				if ((Object)(object)item == (Object)null)
				{
					break;
				}
				if (PEAKBlowDartsPlugin.TryGetDartType(item, null, out var dartType))
				{
					PEAKBlowDartsPlugin.ApplyDartType(item, dartType);
					break;
				}
				RequestDartFromHost(item);
			}
		}

		private static void ApplyRemoteDart(int viewId, BlowDartType dartType)
		{
			RememberDart(viewId, dartType);
			PhotonView val = PhotonView.Find(viewId);
			if (!((Object)(object)val == (Object)null))
			{
				PEAKBlowDartsPlugin.ApplyDartType(((Component)val).GetComponent<Item>(), dartType);
			}
		}

		private static void RespondToDartRequest(int viewId)
		{
			if (PhotonNetwork.IsMasterClient)
			{
				PhotonView val = PhotonView.Find(viewId);
				Item item = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<Item>() : null);
				if (PEAKBlowDartsPlugin.TryGetDartType(item, null, out var dartType))
				{
					BroadcastDart(item, dartType);
					PushItemInstanceData(item);
				}
			}
		}

		private static void SetSoloState()
		{
			HostModConfirmed = true;
			VanillaHostMode = false;
		}

		private static void HandleEvent(EventData photonEvent)
		{
			if (photonEvent == null || photonEvent.Code != EventCode || !(photonEvent.CustomData is object[] array) || array.Length < 3 || !(array[0] is string) || (string)array[0] != "tony.PEAK_Blow_Darts" || Convert.ToInt32(array[1]) != 100)
			{
				return;
			}
			byte b = Convert.ToByte(array[2]);
			if (b == 2 && PhotonNetwork.IsMasterClient)
			{
				BroadcastConfigNow();
				BroadcastAllDarts();
			}
			else if (b == 4 && array.Length >= 4)
			{
				RespondToDartRequest(Convert.ToInt32(array[3]));
			}
			else if (b == 3 && array.Length >= 5)
			{
				ApplyRemoteDart(Convert.ToInt32(array[3]), (BlowDartType)Convert.ToInt32(array[4]));
			}
			else
			{
				if (b != 1 || array.Length < 4 || PhotonNetwork.IsMasterClient)
				{
					return;
				}
				string text = array[3] as string;
				if (string.IsNullOrEmpty(text))
				{
					return;
				}
				try
				{
					IsSyncingFromNet = true;
					if ((Object)(object)_proxy != (Object)null)
					{
						_proxy.StopHostSyncWatch();
					}
					HostModConfirmed = true;
					VanillaHostMode = false;
					PEAKBlowDartsPlugin.Instance.UnpackConfigData(text);
					PEAKBlowDartsPlugin.ApplyAllExistingBlowDarts();
					PEAKBlowDartsPlugin.LogInfo("[Peak Blow Darts] Host config sync applied.");
				}
				catch (Exception ex)
				{
					PEAKBlowDartsPlugin.LogError("[Peak Blow Darts] Config sync error: " + ex);
				}
				finally
				{
					IsSyncingFromNet = false;
				}
			}
		}

		private static void BroadcastConfigNow()
		{
			//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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			if (PhotonNetwork.InRoom && PhotonNetwork.IsMasterClient && !((Object)(object)PEAKBlowDartsPlugin.Instance == (Object)null))
			{
				PhotonNetwork.RaiseEvent(EventCode, (object)Payload(1, PEAKBlowDartsPlugin.Instance.PackConfigData()), new RaiseEventOptions
				{
					Receivers = (ReceiverGroup)0
				}, SendOptions.SendReliable);
			}
		}

		private static void RequestHostSync()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			if (PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient)
			{
				PhotonNetwork.RaiseEvent(EventCode, (object)Payload(2), new RaiseEventOptions
				{
					Receivers = (ReceiverGroup)2
				}, SendOptions.SendReliable);
			}
		}
	}
	internal static class GameAccess
	{
		public static void SetMenuWindowFlags(GUIManager gui, bool blocking, bool showingCursor)
		{
			if (!((Object)(object)gui == (Object)null))
			{
				gui.windowBlockingInput = blocking;
				gui.windowShowingCursor = showingCursor;
			}
		}
	}
	internal static class BlowDartUi
	{
		internal static readonly Color PanelColor = new Color(0.08f, 0.06f, 0.05f, 0.94f);

		internal static readonly Color ButtonColor = new Color(0.1792453f, 0.1253449f, 0.09046815f, 62f / 85f);

		internal static readonly Color ButtonHover = new Color(0.26f, 0.18f, 0.13f, 0.92f);

		internal static readonly Color Cream = new Color(0.95f, 0.93f, 0.88f, 1f);

		internal static readonly Color CreamDim = new Color(0.82f, 0.78f, 0.72f, 0.92f);

		internal static readonly Color AccentOn = new Color(0.55f, 0.42f, 0.22f, 0.95f);

		internal static readonly Color EditedColor = new Color(0.85f, 0.72f, 0.38f, 1f);

		internal static readonly Color FieldWellColor = new Color(0.22f, 0.16f, 0.11f, 1f);

		private static readonly Color CheckboxWellColor = new Color(0.12f, 0.09f, 0.07f, 1f);

		private static readonly Color CheckboxOnColor = new Color(0.92f, 0.78f, 0.38f, 1f);

		private static Sprite _whiteSprite;

		private static GameObject _buttonDonor;

		private static TMP_FontAsset _cachedFont;

		private static int _cachedSceneHandle = -1;

		internal static Canvas CreateOverlayCanvas(GameObject root, int sortingOrder)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			Canvas val = root.GetComponent<Canvas>() ?? root.AddComponent<Canvas>();
			val.renderMode = (RenderMode)0;
			val.overrideSorting = true;
			val.sortingOrder = sortingOrder;
			val.additionalShaderChannels = (AdditionalCanvasShaderChannels)25;
			CanvasScaler val2 = root.GetComponent<CanvasScaler>() ?? root.AddComponent<CanvasScaler>();
			val2.uiScaleMode = (ScaleMode)1;
			val2.referenceResolution = new Vector2(1920f, 1080f);
			val2.matchWidthOrHeight = 1f;
			if ((Object)(object)root.GetComponent<GraphicRaycaster>() == (Object)null)
			{
				root.AddComponent<GraphicRaycaster>();
			}
			return val;
		}

		internal static RectTransform CreatePanel(Transform parent, string name, Vector2 size, Color color)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name, new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Image)
			});
			val.transform.SetParent(parent, false);
			RectTransform component = val.GetComponent<RectTransform>();
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0.5f, 0.5f);
			component.anchorMax = val2;
			component.anchorMin = val2;
			component.pivot = new Vector2(0.5f, 0.5f);
			component.sizeDelta = size;
			Image component2 = val.GetComponent<Image>();
			component2.sprite = WhiteSprite();
			component2.type = (Type)1;
			((Graphic)component2).color = color;
			((Graphic)component2).raycastTarget = true;
			return component;
		}

		internal static TextMeshProUGUI CreateLabel(Transform parent, string name, string text, float fontSize, FontStyles style = (FontStyles)0, TextAlignmentOptions align = (TextAlignmentOptions)513)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_0057: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name, new Type[2]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer)
			});
			val.transform.SetParent(parent, false);
			TextMeshProUGUI val2 = val.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val2).text = text ?? string.Empty;
			((TMP_Text)val2).fontSize = fontSize;
			((TMP_Text)val2).fontStyle = style;
			((TMP_Text)val2).alignment = align;
			((Graphic)val2).color = Cream;
			((Graphic)val2).raycastTarget = false;
			((TMP_Text)val2).enableWordWrapping = false;
			((TMP_Text)val2).overflowMode = (TextOverflowModes)0;
			((MaskableGraphic)val2).maskable = true;
			ApplyFont(val2);
			return val2;
		}

		internal static LayoutElement MakeNonCollapsing(GameObject go, float height, float minWidth = 0f)
		{
			LayoutElement val = go.GetComponent<LayoutElement>() ?? go.AddComponent<LayoutElement>();
			val.minHeight = height;
			val.preferredHeight = height;
			val.flexibleHeight = 0f;
			if (minWidth > 0f)
			{
				val.minWidth = minWidth;
				if (val.preferredWidth < minWidth)
				{
					val.preferredWidth = minWidth;
				}
			}
			return val;
		}

		internal static Button CreateButton(Transform parent, string label, UnityAction onClick, Vector2 preferredSize)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			return CreatePlainButton(parent, label, onClick, preferredSize);
		}

		internal static Button CreatePlainButton(Transform parent, string label, UnityAction onClick, Vector2 preferredSize)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = CreatePlainButtonObject(parent, label);
			ApplyButtonSize(val, preferredSize);
			TextMeshProUGUI componentInChildren = val.GetComponentInChildren<TextMeshProUGUI>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				((TMP_Text)componentInChildren).text = label ?? string.Empty;
				((TMP_Text)componentInChildren).overflowMode = (TextOverflowModes)0;
				((MaskableGraphic)componentInChildren).maskable = true;
				ApplyFont(componentInChildren);
			}
			Button component = val.GetComponent<Button>();
			((UnityEventBase)component.onClick).RemoveAllListeners();
			if (onClick != null)
			{
				((UnityEvent)component.onClick).AddListener(onClick);
			}
			return component;
		}

		internal static KitItemRow CreateItemRow(Transform parent, string label, UnityAction<string> onPick, float height)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Expected O, but got Unknown
			GameObject val = CreatePlainButtonObject(parent, label);
			ApplyButtonSize(val, new Vector2(560f, height));
			TextMeshProUGUI componentInChildren = val.GetComponentInChildren<TextMeshProUGUI>(true);
			if ((Object)(object)componentInChildren != (Object)null)
			{
				((TMP_Text)componentInChildren).text = label ?? string.Empty;
				((TMP_Text)componentInChildren).enableAutoSizing = false;
				((TMP_Text)componentInChildren).fontSize = 18f;
				((TMP_Text)componentInChildren).overflowMode = (TextOverflowModes)0;
				((MaskableGraphic)componentInChildren).maskable = true;
				((Graphic)componentInChildren).raycastTarget = false;
				ApplyFont(componentInChildren);
			}
			KitItemRow row = val.GetComponent<KitItemRow>() ?? val.AddComponent<KitItemRow>();
			row.ItemName = label ?? string.Empty;
			row.Label = componentInChildren;
			row.OnPicked = ((onPick == null) ? null : ((Action<string>)delegate(string s)
			{
				onPick.Invoke(s);
			}));
			Button component = val.GetComponent<Button>();
			((UnityEventBase)component.onClick).RemoveAllListeners();
			if (onPick != null)
			{
				((UnityEvent)component.onClick).AddListener((UnityAction)delegate
				{
					onPick.Invoke(row.ItemName);
				});
			}
			return row;
		}

		internal static Toggle CreateToggle(Transform parent, string label, bool isOn, UnityAction<bool> onChanged, float height = 28f)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Expected O, but got Unknown
			GameObject val = new GameObject("Toggle_" + Sanitize(label), new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Image)
			});
			val.transform.SetParent(parent, false);
			PinTopStretch(val.GetComponent<RectTransform>(), height);
			Image component = val.GetComponent<Image>();
			component.sprite = WhiteSprite();
			((Graphic)component).color = new Color(1f, 1f, 1f, 0.001f);
			((Graphic)component).raycastTarget = true;
			LayoutElement val2 = val.AddComponent<LayoutElement>();
			val2.minHeight = height;
			val2.preferredHeight = height;
			val2.flexibleHeight = 0f;
			val2.flexibleWidth = 1f;
			val2.minWidth = 160f;
			HorizontalLayoutGroup val3 = val.AddComponent<HorizontalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)val3).spacing = 8f;
			((LayoutGroup)val3).childAlignment = (TextAnchor)3;
			((HorizontalOrVerticalLayoutGroup)val3).childControlHeight = false;
			((HorizontalOrVerticalLayoutGroup)val3).childControlWidth = false;
			((HorizontalOrVerticalLayoutGroup)val3).childForceExpandHeight = false;
			((HorizontalOrVerticalLayoutGroup)val3).childForceExpandWidth = false;
			((LayoutGroup)val3).padding = new RectOffset(2, 4, 2, 2);
			Image wellImg;
			Image borderImg;
			Image checkImg = CreateCheckVisual(val.transform, 22f, out wellImg, out borderImg);
			TextMeshProUGUI val4 = CreateLabel(val.transform, "Label", label, 16f, (FontStyles)0, (TextAlignmentOptions)513);
			LayoutElement val5 = ((Component)val4).gameObject.AddComponent<LayoutElement>();
			val5.minWidth = 120f;
			val5.preferredWidth = 220f;
			val5.flexibleWidth = 1f;
			val5.minHeight = height - 4f;
			val5.preferredHeight = height - 4f;
			Toggle val6 = val.AddComponent<Toggle>();
			((Selectable)val6).targetGraphic = (Graphic)(object)component;
			val6.graphic = (Graphic)(object)checkImg;
			ApplyToggleColors(val6);
			val6.SetIsOnWithoutNotify(isOn);
			ApplyCheckMark(wellImg, checkImg, isOn);
			((UnityEvent<bool>)(object)val6.onValueChanged).AddListener((UnityAction<bool>)delegate(bool v)
			{
				ApplyCheckMark(wellImg, checkImg, v);
				onChanged?.Invoke(v);
			});
			return val6;
		}

		internal static Toggle CreateCheckBox(Transform parent, bool isOn, UnityAction<bool> onChanged, float size = 22f)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			GameObject val = new GameObject("CheckBox", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			PinBox(val.GetComponent<RectTransform>(), size, size);
			LayoutElement val2 = val.AddComponent<LayoutElement>();
			val2.preferredWidth = size;
			val2.preferredHeight = size;
			val2.minWidth = size;
			val2.minHeight = size;
			val2.flexibleWidth = 0f;
			val2.flexibleHeight = 0f;
			Image wellImg;
			Image borderImg;
			Image checkImg = CreateCheckVisual(val.transform, size, out wellImg, out borderImg);