Decompiled source of PrzedmiotyKompanii v0.3.2

plugins/PrzedmiotyKompanii.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using Dissonance;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace PrzedmiotyKompanii
{
	[BepInPlugin("saltanis.przedmiotykmp", "Przedmioty Kompanii", "0.3.2")]
	[BepInDependency("evaisa.lethallib", "1.2.0")]
	public sealed class CompanyItemsPlugin : BaseUnityPlugin
	{
		private sealed class TapeSelection
		{
			internal ulong Owner;

			internal readonly List<ulong> Objects = new List<ulong>(3);
		}

		[Serializable]
		private sealed class PackedItem
		{
			public string Name;

			public string Prefab;

			public int Value;
		}

		[Serializable]
		private sealed class BundleRecord
		{
			public int Id;

			public float Weight;

			public PackedItem[] Items;
		}

		[Serializable]
		private sealed class BundleSave
		{
			public BundleRecord[] Bundles;
		}

		[HarmonyPatch(typeof(GameNetworkManager), "SaveItemsInShip")]
		private static class SaveBundleContents
		{
			private static void Prefix(GameNetworkManager __instance)
			{
				if (Object.op_Implicit((Object)(object)instance) && __instance.isHostingGame)
				{
					instance.StoreBundleRecords();
				}
			}
		}

		[HarmonyPatch]
		private static class PackedCarryWeight
		{
			private static IEnumerable<MethodBase> TargetMethods()
			{
				Type player = typeof(PlayerControllerB);
				string[] array = new string[6] { "BeginGrabObject", "GrabObjectClientRpc", "DespawnHeldObjectOnClient", "SetObjectAsNoLongerHeld", "PlaceGrabbableObject", "DestroyItemInSlot" };
				foreach (string text in array)
				{
					yield return AccessTools.Method(player, text, (Type[])null, (Type[])null);
				}
				yield return AccessTools.EnumeratorMoveNext((MethodBase)AccessTools.Method(player, "GrabObject", (Type[])null, (Type[])null));
			}

			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> original)
			{
				List<CodeInstruction> list = original.ToList();
				FieldInfo fieldInfo = AccessTools.Field(typeof(GrabbableObject), "itemProperties");
				FieldInfo fieldInfo2 = AccessTools.Field(typeof(Item), "weight");
				MethodInfo operand = AccessTools.Method(typeof(CompanyItemsPlugin), "CarryWeight", (Type[])null, (Type[])null);
				for (int i = 1; i < list.Count; i++)
				{
					if (CodeInstructionExtensions.LoadsField(list[i], fieldInfo2, false) && CodeInstructionExtensions.LoadsField(list[i - 1], fieldInfo, false))
					{
						list[i - 1].opcode = OpCodes.Nop;
						list[i - 1].operand = null;
						list[i].opcode = OpCodes.Call;
						list[i].operand = operand;
					}
				}
				return list;
			}
		}

		[HarmonyPatch(typeof(GameNetworkManager), "Start")]
		private static class RegisterAtStartup
		{
			private static void Prefix()
			{
				instance?.RegisterItems();
			}
		}

		[HarmonyPatch(typeof(GrabbableObject), "ItemActivate")]
		private static class UseWand
		{
			private static void Postfix(GrabbableObject __instance, bool __1)
			{
				CompanyItemsPlugin instance = CompanyItemsPlugin.instance;
				if (!((Object)(object)instance == (Object)null) && instance.IsWand(__instance) && ((NetworkBehaviour)__instance).IsOwner)
				{
					instance.OnWandInput(__instance, __1);
				}
			}
		}

		private enum InputKind : byte
		{
			Start = 1,
			Cancel,
			Fire
		}

		private enum EffectKind : byte
		{
			Charge = 1,
			Cancel,
			Launch,
			Burst,
			Miss,
			Shatter
		}

		private sealed class Charge
		{
			internal ulong Item;

			internal float Started;

			internal float Duration;
		}

		private sealed class Shot
		{
			internal ulong Id;

			internal ulong Caster;

			internal Vector3 Position;

			internal Vector3 Direction;

			internal float Age;
		}

		private sealed class ChargeLight
		{
			internal GameObject Root;

			internal Transform Orb;

			internal Light Light;

			internal float Start;

			internal float Duration;
		}

		private sealed class FlightLight
		{
			internal GameObject Root;

			internal Vector3 Start;

			internal Vector3 Direction;

			internal float Started;
		}

		private sealed class BurstLight
		{
			internal GameObject Root;

			internal Transform Flash;

			internal Light Light;

			internal LineRenderer Wave;

			internal Fragment[] Fire;

			internal Fragment[] Smoke;

			internal Fragment[] Sparks;

			internal float Started;

			internal float Radius;
		}

		private sealed class ShatteredStaff
		{
			internal GameObject Root;

			internal Fragment[] Shards;

			internal float Started;
		}

		private struct Fragment
		{
			internal Transform Part;

			internal Vector3 Start;

			internal Vector3 Travel;

			internal Vector3 Size;

			internal Vector3 Spin;
		}

		[HarmonyPatch(typeof(GrabbableObject), "ItemActivate")]
		private static class UseCrewGear
		{
			private static void Postfix(GrabbableObject __instance, bool __1)
			{
				//IL_0095: Unknown result type (might be due to invalid IL or missing references)
				CompanyItemsPlugin instance = CompanyItemsPlugin.instance;
				CrewGear crewGear = GearOf(__instance);
				if (__1 && Object.op_Implicit((Object)(object)crewGear) && crewGear.Kind != Gear.Drum && crewGear.Kind != Gear.Bundle && ((NetworkBehaviour)__instance).IsOwner && Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)instance.net) && instance.messenger != null)
				{
					PlayerControllerB localPlayer = LocalPlayer;
					if (Object.op_Implicit((Object)(object)localPlayer) && !InUseMenu(localPlayer) && Object.op_Implicit((Object)(object)localPlayer.gameplayCamera) && !((Object)(object)__instance != (Object)(object)localPlayer.currentlyHeldObjectServer))
					{
						instance.SendGearInput(GearInput.Use, ((NetworkBehaviour)__instance).NetworkObjectId, ((Component)localPlayer.gameplayCamera).transform.forward);
					}
				}
			}
		}

		[HarmonyPatch(typeof(GrabbableObject), "GetItemDataToSave")]
		private static class SaveGearItem
		{
			private static void Postfix(GrabbableObject __instance, ref int __result)
			{
				CrewGear crewGear = GearOf(__instance);
				if (Object.op_Implicit((Object)(object)crewGear) && (crewGear.Kind == Gear.Receipt || crewGear.Kind == Gear.Bundle))
				{
					__result = crewGear.SaveData;
				}
			}
		}

		[HarmonyPatch(typeof(GrabbableObject), "LoadItemSaveData")]
		private static class LoadGearItem
		{
			private static void Postfix(GrabbableObject __instance, int __0)
			{
				CrewGear crewGear = GearOf(__instance);
				if (Object.op_Implicit((Object)(object)crewGear) && (crewGear.Kind == Gear.Receipt || crewGear.Kind == Gear.Bundle))
				{
					crewGear.SaveData = __0;
					if (Object.op_Implicit((Object)(object)instance) && crewGear.Kind == Gear.Bundle)
					{
						instance.ReloadBundle(__instance, crewGear);
					}
				}
			}
		}

		private enum GearInput : byte
		{
			Use,
			PowerShot,
			Snapshot,
			CancelReceipt
		}

		private enum GearEvent : byte
		{
			Active,
			End,
			Notice,
			PowerLaunch,
			PowerImpact,
			PowerMiss,
			Mark,
			Recall,
			ClearMark,
			Packed,
			Scrap,
			ChargeReceipt,
			EndReceiptCharge
		}

		private struct ReceiptCharge
		{
			internal ulong Receipt;

			internal float Due;
		}

		private struct TicketAnchor
		{
			internal Vector3 Point;

			internal float Yaw;

			internal int Flags;

			internal int Level;

			internal int Seed;
		}

		private struct PendingValue
		{
			internal int Value;

			internal int SaveData;

			internal Vector3 Extras;

			internal Vector3 Models;

			internal float Until;
		}

		private sealed class EffectState
		{
			internal readonly PlayerControllerB Player;

			internal readonly Gear Kind;

			internal readonly int Form;

			internal readonly float Until;

			internal readonly float Height;

			internal readonly float Radius;

			internal readonly Vector3 Center;

			internal Vector3 LastSpacious;

			internal Vector3 Thrust;

			private readonly CompanyItemsPlugin plugin;

			private readonly Vector3 originalScale;

			private readonly float originalNearClip;

			private readonly int healthBefore;

			private int? maxHealthBefore;

			private readonly Dictionary<Renderer, bool> hidden = new Dictionary<Renderer, bool>();

			private GameObject visual;

			private Animator morph;

			private Light auraLight;

			private Transform[] flames;

			private Transform[] sparks;

			private AudioClip[] footsteps;

			private float stepAt;

			private float safePositionAt;

			private Vector3 previousPosition;

			private DissonanceComms voice;

			private bool priorMute;

			private AudioSource playback;

			private bool priorPlaybackMute;

			private Vector3 movement;

			private int motionX;

			private int motionZ;

			private int motionSpeed;

			private Transform leftPalm;

			private Transform rightPalm;

			private float castAt = -10f;

			private bool leftCast;

			internal EffectState(CompanyItemsPlugin plugin, PlayerControllerB player, Gear kind, int form, float duration)
			{
				//IL_004e: 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_0099: Unknown result type (might be due to invalid IL or missing references)
				//IL_009e: Unknown result type (might be due to invalid IL or missing references)
				//IL_009f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a0: 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)
				//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
				this.plugin = plugin;
				Player = player;
				Kind = kind;
				Form = form;
				Until = Time.unscaledTime + duration;
				originalScale = ((Component)player).transform.localScale;
				originalNearClip = ((((NetworkBehaviour)player).IsOwner && Object.op_Implicit((Object)(object)player.gameplayCamera)) ? player.gameplayCamera.nearClipPlane : 0f);
				healthBefore = player.health;
				LastSpacious = (previousPosition = ((Component)player).transform.position);
				if (Object.op_Implicit((Object)(object)player.thisController))
				{
					Height = player.thisController.height;
					Radius = player.thisController.radius;
					Center = player.thisController.center;
				}
			}

			internal void Apply()
			{
				//IL_016e: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
				switch (Kind)
				{
				case Gear.Gum:
				case Gear.UltraGum:
				{
					float num = ((Kind == Gear.UltraGum) ? 0.05f : 0.2f);
					((Component)Player).transform.localScale = originalScale * num;
					if (originalNearClip > 0f)
					{
						Player.gameplayCamera.nearClipPlane = Mathf.Min(originalNearClip, num * 0.16f);
					}
					plugin.ShowGumBubble(Player, 0.22f);
					plugin.PlayOneShot(plugin.gumPop, ((Component)Player).transform.position, 0.62f, 12f);
					break;
				}
				case Gear.Bean:
					if (((NetworkBehaviour)Player).IsOwner)
					{
						if (GeneralImprovementsHealth.Value?.GetValue(null) is int value)
						{
							maxHealthBefore = value;
						}
						Player.health = 1000;
						Player.MakeCriticallyInjured(false);
						if (Object.op_Implicit((Object)(object)HUDManager.Instance))
						{
							HUDManager.Instance.UpdateHealthUI(Player.health, false);
						}
					}
					BuildAura();
					plugin.PlayOneShot(plugin.powerCharge, ((Component)Player).transform.position, 0.6f, 16f);
					break;
				case Gear.Slime:
					if (BuildMorph())
					{
						KeepMorphMuted();
					}
					plugin.PlayOneShot(plugin.gumPop, ((Component)Player).transform.position, 0.54f, 12f);
					break;
				}
			}

			internal void Tick()
			{
				//IL_006f: 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_0099: Unknown result type (might be due to invalid IL or missing references)
				//IL_009e: Unknown result type (might be due to invalid IL or missing references)
				//IL_012f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0134: Unknown result type (might be due to invalid IL or missing references)
				//IL_0184: Unknown result type (might be due to invalid IL or missing references)
				if (!Object.op_Implicit((Object)(object)Player) || Player.isPlayerDead)
				{
					return;
				}
				if (IsShrinkGear(Kind))
				{
					if (plugin.net.IsServer && Time.unscaledTime >= safePositionAt)
					{
						safePositionAt = Time.unscaledTime + 0.12f;
						if (plugin.FitsAt(Player, ((Component)Player).transform.position, Height, Radius, Center))
						{
							LastSpacious = ((Component)Player).transform.position;
						}
					}
				}
				else if (Kind == Gear.Slime)
				{
					if (Object.op_Implicit((Object)(object)visual))
					{
						KeepMorphMuted();
						AnimateMorph();
					}
				}
				else
				{
					if (Kind != Gear.Bean)
					{
						return;
					}
					AnimateAura();
					if (((NetworkBehaviour)Player).IsOwner && Player.playerActions != null && Object.op_Implicit((Object)(object)Player.gameplayCamera) && !InUseMenu(Player) && !plugin.round.shipIsLeaving)
					{
						MovementActions val = Player.playerActions.Movement;
						if (((MovementActions)(ref val)).ActivateItem.IsPressed() && Time.unscaledTime >= plugin.localShotAt)
						{
							plugin.localShotAt = Time.unscaledTime + 1f / 3f;
							plugin.SendGearInput(GearInput.PowerShot, 0uL, ((Component)Player.gameplayCamera).transform.forward);
						}
					}
				}
			}

			internal void ApplyFlight()
			{
				//IL_0095: Unknown result type (might be due to invalid IL or missing references)
				//IL_009a: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
				//IL_015a: Unknown result type (might be due to invalid IL or missing references)
				//IL_015f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0160: Unknown result type (might be due to invalid IL or missing references)
				//IL_0161: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00de: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
				//IL_0102: Unknown result type (might be due to invalid IL or missing references)
				//IL_0107: Unknown result type (might be due to invalid IL or missing references)
				//IL_0108: Unknown result type (might be due to invalid IL or missing references)
				//IL_0112: Unknown result type (might be due to invalid IL or missing references)
				//IL_0117: Unknown result type (might be due to invalid IL or missing references)
				//IL_0118: Unknown result type (might be due to invalid IL or missing references)
				//IL_011e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0133: Unknown result type (might be due to invalid IL or missing references)
				//IL_0138: Unknown result type (might be due to invalid IL or missing references)
				//IL_013e: 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_014d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0152: 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_017f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0184: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
				if (!((NetworkBehaviour)Player).IsOwner || !Object.op_Implicit((Object)(object)Player.thisController) || !Object.op_Implicit((Object)(object)Player.gameplayCamera) || Player.playerActions == null || Player.isPlayerDead || Player.inSpecialInteractAnimation || Player.inVehicleAnimation || Player.isClimbingLadder || InUseMenu(Player) || plugin.round.shipIsLeaving)
				{
					Thrust = Vector3.zero;
					return;
				}
				MovementActions val = Player.playerActions.Movement;
				Vector3 val2 = Vector3.zero;
				if (((MovementActions)(ref val)).Jump.IsPressed())
				{
					Vector2 val3 = Vector2.ClampMagnitude(((MovementActions)(ref val)).Move.ReadValue<Vector2>(), 1f);
					Vector3 val4 = Vector3.ProjectOnPlane(((Component)Player.gameplayCamera).transform.forward, Vector3.up);
					Vector3 normalized = ((Vector3)(ref val4)).normalized;
					val2 = Vector3.up * 114f + (normalized * val3.y + ((Component)Player.gameplayCamera).transform.right * val3.x) * 178f;
				}
				Thrust = Vector3.MoveTowards(Thrust, val2, ((val2 == Vector3.zero) ? 280f : 290f) * Time.deltaTime);
				if (((Vector3)(ref Thrust)).sqrMagnitude > 1f)
				{
					PlayerControllerB player = Player;
					player.externalForces += Thrust;
				}
			}

			internal void FlightCollision(ControllerColliderHit collision)
			{
				//IL_0047: Unknown result type (might be due to invalid IL or missing references)
				//IL_004d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0061: Unknown result type (might be due to invalid IL or missing references)
				//IL_0086: Unknown result type (might be due to invalid IL or missing references)
				//IL_008b: Unknown result type (might be due to invalid IL or missing references)
				//IL_008d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
				if (((NetworkBehaviour)Player).IsOwner && !Player.isPlayerDead && Object.op_Implicit((Object)(object)collision.collider) && !collision.collider.isTrigger && !Object.op_Implicit((Object)(object)((Component)collision.collider).GetComponentInParent<PlayerControllerB>()) && !(0f - Vector3.Dot(Thrust, collision.normal) < 83f) && (!(collision.normal.y > 0.55f) || !(Thrust.y > 0f)))
				{
					Vector3 thrust = Thrust;
					Thrust = Vector3.zero;
					plugin.PlayOneShot(plugin.shatterSound, collision.point, 0.7f, 22f);
					Player.KillPlayer(thrust, true, (CauseOfDeath)2, 0, default(Vector3), false);
				}
			}

			private void BuildAura()
			{
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Expected O, but got Unknown
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_011b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0120: Unknown result type (might be due to invalid IL or missing references)
				//IL_0156: Unknown result type (might be due to invalid IL or missing references)
				//IL_016a: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
				plugin.PreparePowerArt();
				visual = new GameObject("Power Bean aura");
				visual.transform.SetParent(((Component)Player).transform, false);
				auraLight = visual.AddComponent<Light>();
				auraLight.range = 3.2f;
				auraLight.color = new Color(1f, 0.75f, 0.2f);
				auraLight.intensity = (((NetworkBehaviour)Player).IsOwner ? 0.42f : 1.5f);
				auraLight.shadows = (LightShadows)0;
				flames = (Transform[])(object)new Transform[((NetworkBehaviour)Player).IsOwner ? 8 : 12];
				for (int i = 0; i < flames.Length; i++)
				{
					Transform transform = new GameObject("Wstęga płomienia").transform;
					transform.SetParent(visual.transform, false);
					Part("Złoty płomień", transform, plugin.powerFlame, (i % 3 == 0) ? plugin.powerAmber : plugin.powerGold, Vector3.zero, Vector3.one);
					Part("Jasne wnętrze płomienia", transform, plugin.powerFlame, plugin.powerCore, new Vector3(0.025f, 0.04f, -0.022f), new Vector3(0.39f, 0.8f, 0.94f));
					flames[i] = transform;
				}
				sparks = (Transform[])(object)new Transform[((NetworkBehaviour)Player).IsOwner ? 10 : 22];
				for (int j = 0; j < sparks.Length; j++)
				{
					sparks[j] = Part("Żółta smuga energii", visual.transform, plugin.splinter, (j % 3 == 0) ? plugin.powerCore : plugin.powerGold, Vector3.zero, Vector3.zero);
				}
				visual.AddComponent<PowerArmMotion>().Attach(this);
				SkinnedMeshRenderer val = (((NetworkBehaviour)Player).IsOwner ? Player.thisPlayerModelArms : Player.thisPlayerModel);
				if (Object.op_Implicit((Object)(object)val))
				{
					leftPalm = ((IEnumerable<Transform>)val.bones).FirstOrDefault((Func<Transform, bool>)((Transform bone) => Object.op_Implicit((Object)(object)bone) && ((Object)bone).name == "hand.L"));
					rightPalm = ((IEnumerable<Transform>)val.bones).FirstOrDefault((Func<Transform, bool>)((Transform bone) => Object.op_Implicit((Object)(object)bone) && ((Object)bone).name == "hand.R"));
				}
			}

			internal Vector3 ShotOrigin(Vector3 fallback, bool left)
			{
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				Transform val = (left ? leftPalm : rightPalm);
				if (Object.op_Implicit((Object)(object)val))
				{
					Vector3 val2 = val.position - fallback;
					if (((Vector3)(ref val2)).sqrMagnitude < 2f)
					{
						return val.position;
					}
				}
				return fallback;
			}

			internal void AnimateShot(bool left)
			{
				castAt = Time.time;
				leftCast = left;
			}

			internal void PoseShot()
			{
				//IL_0089: Unknown result type (might be due to invalid IL or missing references)
				//IL_0093: Unknown result type (might be due to invalid IL or missing references)
				//IL_0099: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
				float num = (Time.time - castAt) / 0.24f;
				if (!(num < 0f) && !(num > 1f) && Object.op_Implicit((Object)(object)Player) && !Player.isPlayerDead && !InUseMenu(Player))
				{
					float num2 = Mathf.Sin(num * (float)Math.PI);
					Transform val = (Object.op_Implicit((Object)(object)Player.gameplayCamera) ? ((Component)Player.gameplayCamera).transform : ((Component)Player).transform);
					Vector3 shift = (val.forward * 0.3f + val.up * 0.16f) * num2;
					if (leftCast)
					{
						WandPose.MoveHand(Player, leftPalm, shift);
					}
					else
					{
						WandPose.MoveRightHand(Player, shift);
					}
				}
			}

			private void AnimateAura()
			{
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0067: 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_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_0123: Unknown result type (might be due to invalid IL or missing references)
				//IL_0133: Unknown result type (might be due to invalid IL or missing references)
				//IL_0138: Unknown result type (might be due to invalid IL or missing references)
				//IL_014d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0152: Unknown result type (might be due to invalid IL or missing references)
				//IL_0164: Unknown result type (might be due to invalid IL or missing references)
				//IL_0166: Unknown result type (might be due to invalid IL or missing references)
				//IL_0183: Unknown result type (might be due to invalid IL or missing references)
				//IL_0188: 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_0199: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
				//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
				//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
				//IL_0314: Unknown result type (might be due to invalid IL or missing references)
				//IL_031b: Unknown result type (might be due to invalid IL or missing references)
				if (Object.op_Implicit((Object)(object)visual) && sparks != null)
				{
					float time = Time.time;
					Vector3 val = ((((NetworkBehaviour)Player).IsOwner && Object.op_Implicit((Object)(object)Player.gameplayCamera)) ? ((Component)Player).transform.InverseTransformDirection(((Component)Player.gameplayCamera).transform.forward) : Vector3.zero);
					auraLight.intensity = (((NetworkBehaviour)Player).IsOwner ? 0.52f : 2.1f) * (0.87f + 0.13f * Mathf.Sin(time * 10f));
					Vector3 val2 = default(Vector3);
					for (int i = 0; i < flames.Length; i++)
					{
						float num = (float)i * 2f * (float)Math.PI / (float)flames.Length + Mathf.Sin(time * 2.9f + (float)i) * 0.15f;
						float num2 = 0.5f + 0.5f * Mathf.Sin(time * (11f + (float)(i % 3)) + (float)i * 2.35f);
						((Vector3)(ref val2))..ctor(Mathf.Cos(num), 0f, Mathf.Sin(num));
						flames[i].localPosition = val2 * (0.47f + num2 * 0.11f) + Vector3.up * (0.025f + (float)(i % 3) * 0.17f);
						flames[i].localRotation = Quaternion.LookRotation(val2) * Quaternion.Euler(-8f + num2 * 16f, 0f, 0f);
						float num3 = Mathf.Max(0f, Vector3.Dot(val2, val));
						float num4 = (0.85f + num2 * 0.73f) * (1f - num3 * 0.57f);
						flames[i].localScale = new Vector3(0.82f - num2 * 0.2f, num4, 1f);
					}
					for (int j = 0; j < sparks.Length; j++)
					{
						float num5 = Mathf.Repeat(time * (1.21f + (float)(j % 4) * 0.13f) + (float)j * 0.137f, 1f);
						float num6 = (float)j * 2.39996f + time * 0.9f;
						float num7 = 0.49f + Mathf.Sin(num5 * (float)Math.PI) * 0.27f;
						float num8 = (((NetworkBehaviour)Player).IsOwner ? 1.12f : 2.14f);
						sparks[j].localPosition = new Vector3(Mathf.Cos(num6) * num7, 0.05f + num8 * num5, Mathf.Sin(num6) * num7);
						sparks[j].localRotation = Quaternion.LookRotation(new Vector3(Mathf.Cos(num6) * 0.23f, 0.95f, Mathf.Sin(num6) * 0.23f));
						float num9 = Mathf.Sin(num5 * (float)Math.PI);
						sparks[j].localScale = new Vector3(0.033f, 0.033f, 0.42f + (float)(j % 3) * 0.16f) * num9;
					}
				}
			}

			private bool BuildMorph()
			{
				//IL_002f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0039: Expected O, but got Unknown
				//IL_007f: Unknown result type (might be due to invalid IL or missing references)
				//IL_008f: Unknown result type (might be due to invalid IL or missing references)
				EnemyType val = plugin.MorphType(Form);
				if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val.enemyPrefab))
				{
					return false;
				}
				visual = new GameObject("Mutagen morph");
				visual.SetActive(false);
				visual.transform.SetParent(((Component)Player).transform, false);
				GameObject val2 = Object.Instantiate<GameObject>(val.enemyPrefab, visual.transform, false);
				val2.transform.localPosition = Vector3.zero;
				val2.transform.localRotation = Quaternion.identity;
				EnemyAI component = val2.GetComponent<EnemyAI>();
				morph = ((Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.creatureAnimator)) ? component.creatureAnimator : val2.GetComponentInChildren<Animator>(true));
				HoarderBugAI val3 = (HoarderBugAI)(object)((component is HoarderBugAI) ? component : null);
				if (val3 != null)
				{
					footsteps = val3.chitterSFX;
				}
				else
				{
					PufferAI val4 = (PufferAI)(object)((component is PufferAI) ? component : null);
					if (val4 != null)
					{
						footsteps = val4.footstepsSFX;
					}
				}
				MonoBehaviour[] componentsInChildren = val2.GetComponentsInChildren<MonoBehaviour>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
				}
				Rigidbody[] componentsInChildren2 = val2.GetComponentsInChildren<Rigidbody>(true);
				for (int i = 0; i < componentsInChildren2.Length; i++)
				{
					Object.DestroyImmediate((Object)(object)componentsInChildren2[i]);
				}
				NavMeshAgent[] componentsInChildren3 = val2.GetComponentsInChildren<NavMeshAgent>(true);
				for (int i = 0; i < componentsInChildren3.Length; i++)
				{
					Object.DestroyImmediate((Object)(object)componentsInChildren3[i]);
				}
				Collider[] componentsInChildren4 = val2.GetComponentsInChildren<Collider>(true);
				for (int i = 0; i < componentsInChildren4.Length; i++)
				{
					Object.DestroyImmediate((Object)(object)componentsInChildren4[i]);
				}
				AudioSource[] componentsInChildren5 = val2.GetComponentsInChildren<AudioSource>(true);
				for (int i = 0; i < componentsInChildren5.Length; i++)
				{
					((Behaviour)componentsInChildren5[i]).enabled = false;
				}
				Light[] componentsInChildren6 = val2.GetComponentsInChildren<Light>(true);
				for (int i = 0; i < componentsInChildren6.Length; i++)
				{
					Object.DestroyImmediate((Object)(object)componentsInChildren6[i]);
				}
				LODGroup[] componentsInChildren7 = val2.GetComponentsInChildren<LODGroup>(true);
				for (int i = 0; i < componentsInChildren7.Length; i++)
				{
					componentsInChildren7[i].ForceLOD(0);
				}
				int num = LayerMask.NameToLayer("Enemies");
				if (num < 0 || (((NetworkBehaviour)Player).IsOwner && Object.op_Implicit((Object)(object)Player.gameplayCamera) && (Player.gameplayCamera.cullingMask & (1 << num)) == 0))
				{
					num = LayerMask.NameToLayer("Default");
				}
				SkinnedMeshRenderer[] array = (from renderer in val2.GetComponentsInChildren<SkinnedMeshRenderer>(true)
					where Object.op_Implicit((Object)(object)renderer.sharedMesh)
					select renderer).ToArray();
				if (array.Length == 0)
				{
					Object.Destroy((Object)(object)visual);
					visual = null;
					morph = null;
					return false;
				}
				SkinnedMeshRenderer[] array2 = array;
				foreach (SkinnedMeshRenderer obj in array2)
				{
					((Component)obj).gameObject.layer = num;
					((Renderer)obj).forceRenderingOff = false;
					((Renderer)obj).enabled = true;
					obj.updateWhenOffscreen = true;
					Transform val5 = ((Component)obj).transform;
					while ((Object)(object)val5 != (Object)(object)visual.transform)
					{
						((Component)val5).gameObject.SetActive(true);
						val5 = val5.parent;
					}
				}
				if (Object.op_Implicit((Object)(object)morph))
				{
					morph.applyRootMotion = false;
					morph.fireEvents = false;
					morph.cullingMode = (AnimatorCullingMode)0;
					motionX = GetMorphParameter((Form == 1) ? "VelocityX" : "moveX");
					motionZ = GetMorphParameter((Form == 1) ? "VelocityZ" : "moveZ");
					motionSpeed = GetMorphParameter("movementSpeed");
				}
				array2 = (SkinnedMeshRenderer[])(object)new SkinnedMeshRenderer[4] { Player.thisPlayerModel, Player.thisPlayerModelLOD1, Player.thisPlayerModelLOD2, Player.thisPlayerModelArms };
				foreach (SkinnedMeshRenderer val6 in array2)
				{
					if (Object.op_Implicit((Object)(object)val6))
					{
						hidden[(Renderer)(object)val6] = ((Renderer)val6).forceRenderingOff;
						((Renderer)val6).forceRenderingOff = true;
					}
				}
				componentsInChildren = ((Component)Player).GetComponentsInChildren<MonoBehaviour>(true);
				foreach (MonoBehaviour val7 in componentsInChildren)
				{
					if (!Object.op_Implicit((Object)(object)val7) || !(((object)val7).GetType().Name == "CosmeticInstance"))
					{
						continue;
					}
					Renderer[] componentsInChildren8 = ((Component)val7).GetComponentsInChildren<Renderer>(true);
					foreach (Renderer val8 in componentsInChildren8)
					{
						if (!hidden.ContainsKey(val8))
						{
							hidden[val8] = val8.forceRenderingOff;
							val8.forceRenderingOff = true;
						}
					}
				}
				visual.SetActive(true);
				return true;
			}

			private void AnimateMorph()
			{
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//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_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_004a: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0054: Unknown result type (might be due to invalid IL or missing references)
				//IL_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
				Vector3 position = ((Component)Player).transform.position;
				Vector3 val = Vector3.ProjectOnPlane(position - previousPosition, Vector3.up);
				previousPosition = position;
				Vector3 val2 = ((Component)Player).transform.InverseTransformDirection(val / Mathf.Max(0.005f, Time.deltaTime));
				movement = Vector3.Lerp(movement, val2, Mathf.Clamp01(Time.deltaTime * 14f));
				if (Object.op_Implicit((Object)(object)morph))
				{
					if (motionX != 0)
					{
						morph.SetFloat(motionX, Mathf.Clamp(movement.x / 2.8f, -1f, 1f));
					}
					if (motionZ != 0)
					{
						morph.SetFloat(motionZ, Mathf.Clamp(movement.z / 2.8f, -1f, 1f));
					}
					if (motionSpeed != 0)
					{
						morph.SetFloat(motionSpeed, Mathf.Clamp(((Vector3)(ref movement)).magnitude / 2.8f, 0f, 1.6f));
					}
					morph.speed = Mathf.Lerp(0.78f, 1.32f, Mathf.Clamp01(((Vector3)(ref movement)).magnitude / 4f));
				}
				if (Object.op_Implicit((Object)(object)Player.usernameAlpha))
				{
					Player.usernameAlpha.alpha = 0f;
				}
				AudioClip[] array = footsteps;
				if (array != null && array.Length != 0 && ((Vector3)(ref movement)).sqrMagnitude > 0.65f && Time.unscaledTime >= stepAt)
				{
					stepAt = Time.unscaledTime + ((Form == 1) ? 0.83f : 0.37f);
					plugin.PlayOneShot(footsteps[Random.Range(0, footsteps.Length)], position, (Form == 1) ? 0.28f : 0.47f, 13f);
				}
			}

			private int GetMorphParameter(string name)
			{
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Invalid comparison between Unknown and I4
				AnimatorControllerParameter[] parameters = morph.parameters;
				foreach (AnimatorControllerParameter val in parameters)
				{
					if ((int)val.type == 1 && val.name == name)
					{
						return val.nameHash;
					}
				}
				return 0;
			}

			private void KeepMorphMuted()
			{
				if (((NetworkBehaviour)Player).IsOwner && !Object.op_Implicit((Object)(object)voice) && Object.op_Implicit((Object)(object)plugin.round) && Object.op_Implicit((Object)(object)plugin.round.voiceChatModule))
				{
					voice = plugin.round.voiceChatModule;
					priorMute = voice.IsMuted;
				}
				if (Object.op_Implicit((Object)(object)voice))
				{
					voice.IsMuted = true;
				}
				if ((Object)(object)playback != (Object)(object)Player.currentVoiceChatAudioSource)
				{
					if (Object.op_Implicit((Object)(object)playback))
					{
						playback.mute = priorPlaybackMute;
					}
					playback = Player.currentVoiceChatAudioSource;
					if (Object.op_Implicit((Object)(object)playback))
					{
						priorPlaybackMute = playback.mute;
					}
				}
				if (Object.op_Implicit((Object)(object)playback))
				{
					playback.mute = true;
				}
			}

			internal void Restore()
			{
				//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
				if (Object.op_Implicit((Object)(object)voice))
				{
					voice.IsMuted = priorMute;
				}
				if (Object.op_Implicit((Object)(object)playback))
				{
					playback.mute = priorPlaybackMute;
				}
				if (Object.op_Implicit((Object)(object)visual))
				{
					Object.Destroy((Object)(object)visual);
				}
				foreach (KeyValuePair<Renderer, bool> item in hidden)
				{
					if (Object.op_Implicit((Object)(object)item.Key))
					{
						item.Key.forceRenderingOff = item.Value;
					}
				}
				if (!Object.op_Implicit((Object)(object)Player))
				{
					return;
				}
				if (IsShrinkGear(Kind))
				{
					((Component)Player).transform.localScale = originalScale;
					if (originalNearClip > 0f && Object.op_Implicit((Object)(object)Player.gameplayCamera))
					{
						Player.gameplayCamera.nearClipPlane = originalNearClip;
					}
				}
				if (Kind == Gear.Bean && maxHealthBefore.HasValue && GeneralImprovementsHealth.Value.GetValue(null) is int num && num == 1000)
				{
					GeneralImprovementsHealth.Value.SetValue(null, maxHealthBefore.Value);
				}
				if (Kind == Gear.Bean && ((NetworkBehaviour)Player).IsOwner && !Player.isPlayerDead)
				{
					Player.health = Mathf.Max(1, Mathf.Min(healthBefore, Player.health));
					Player.MakeCriticallyInjured(Player.health < 10);
					if (Object.op_Implicit((Object)(object)HUDManager.Instance))
					{
						HUDManager.Instance.UpdateHealthUI(Player.health, false);
					}
				}
			}
		}

		[DefaultExecutionOrder(1050)]
		private sealed class PowerArmMotion : MonoBehaviour
		{
			private EffectState effect;

			internal void Attach(EffectState state)
			{
				effect = state;
			}

			private void LateUpdate()
			{
				effect?.PoseShot();
			}
		}

		[HarmonyPatch]
		private static class PlayerEffectPatches
		{
			[HarmonyPatch(typeof(PlayerControllerB), "BeginGrabObject")]
			[HarmonyPrefix]
			private static bool BlockPickup(PlayerControllerB __instance)
			{
				if (!AvoidTarget(__instance))
				{
					return !IsPowerPlayer(__instance);
				}
				return false;
			}

			[HarmonyPatch(typeof(PlayerControllerB), "FirstEmptyItemSlot")]
			[HarmonyPostfix]
			private static void BlockAlternatePickup(PlayerControllerB __instance, ref int __result)
			{
				if (!BlockPickup(__instance))
				{
					__result = -1;
				}
			}

			[HarmonyPatch(typeof(PlayerControllerB), "GrabObjectServerRpc")]
			[HarmonyPrefix]
			private static bool BlockHostPickup(PlayerControllerB __instance, NetworkObjectReference __0)
			{
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				if (!((NetworkBehaviour)__instance).IsServer || BlockPickup(__instance))
				{
					return true;
				}
				AccessTools.Method(typeof(PlayerControllerB), "GrabObjectClientRpc", (Type[])null, (Type[])null).Invoke(__instance, new object[2] { false, __0 });
				return false;
			}

			[HarmonyPatch(typeof(PlayerControllerB), "ActivateItem_performed")]
			[HarmonyPrefix]
			private static bool BlockItemUse(PlayerControllerB __instance)
			{
				if (!IsPowerPlayer(__instance))
				{
					if (Object.op_Implicit((Object)(object)instance))
					{
						return instance.GearFor(__instance) != Gear.Slime;
					}
					return true;
				}
				return false;
			}

			[HarmonyPatch(typeof(PlayerControllerB), "ShowNameBillboard")]
			[HarmonyPrefix]
			private static bool HideMorphName(PlayerControllerB __instance)
			{
				if (Object.op_Implicit((Object)(object)instance))
				{
					return instance.GearFor(__instance) != Gear.Slime;
				}
				return true;
			}

			[HarmonyPatch(typeof(PlayerControllerB), "PlayFootstepSound")]
			[HarmonyPrefix]
			private static bool ReplaceMorphStep(PlayerControllerB __instance)
			{
				return HideMorphName(__instance);
			}

			[HarmonyPatch(typeof(PlayerControllerB), "PlayFootstepServer")]
			[HarmonyPrefix]
			private static bool HideFootstepNoise(PlayerControllerB __instance)
			{
				return !AvoidTarget(__instance);
			}

			[HarmonyPatch(typeof(PlayerControllerB), "PlayFootstepLocal")]
			[HarmonyPrefix]
			private static bool HideLocalFootstepNoise(PlayerControllerB __instance)
			{
				return !AvoidTarget(__instance);
			}

			[HarmonyPatch(typeof(PlayerControllerB), "Jump_performed")]
			[HarmonyPrefix]
			private static bool RebindJumpDuringFlight(PlayerControllerB __instance)
			{
				return !IsPowerPlayer(__instance);
			}

			[HarmonyPatch(typeof(PlayerControllerB), "Update")]
			[HarmonyPrefix]
			private static void UsePowerFlight(PlayerControllerB __instance)
			{
				if (IsPowerPlayer(__instance))
				{
					instance.gearEffects[__instance.actualClientId].ApplyFlight();
				}
			}

			[HarmonyPatch(typeof(PlayerControllerB), "OnControllerColliderHit")]
			[HarmonyPostfix]
			private static void PowerCrash(PlayerControllerB __instance, ControllerColliderHit __0)
			{
				if (IsPowerPlayer(__instance))
				{
					instance.gearEffects[__instance.actualClientId].FlightCollision(__0);
				}
			}

			[HarmonyPatch(typeof(PlayerControllerB), "DamagePlayer")]
			[HarmonyTranspiler]
			[HarmonyPriority(0)]
			private static IEnumerable<CodeInstruction> RaiseHealthCap(IEnumerable<CodeInstruction> original)
			{
				//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b8: Expected O, but got Unknown
				List<CodeInstruction> list = original.ToList();
				MethodInfo methodInfo = AccessTools.Method(typeof(Mathf), "Clamp", new Type[3]
				{
					typeof(int),
					typeof(int),
					typeof(int)
				}, (Type[])null);
				FieldInfo fieldInfo = AccessTools.Field(typeof(PlayerControllerB), "health");
				MethodInfo operand = AccessTools.Method(typeof(PlayerEffectPatches), "ClampHealth", (Type[])null, (Type[])null);
				for (int i = 0; i + 1 < list.Count; i++)
				{
					if (CodeInstructionExtensions.Calls(list[i], methodInfo) && CodeInstructionExtensions.StoresField(list[i + 1], fieldInfo))
					{
						list.Insert(i, CodeInstructionExtensions.MoveBlocksFrom(CodeInstructionExtensions.MoveLabelsFrom(new CodeInstruction(OpCodes.Ldarg_0, (object)null), list[i]), list[i]));
						list[i + 1].operand = operand;
						break;
					}
				}
				return list;
			}

			private static int ClampHealth(int value, int min, int max, PlayerControllerB player)
			{
				return Mathf.Clamp(value, min, IsPowerPlayer(player) ? 1000 : max);
			}
		}

		[HarmonyPatch]
		private static class ThreatPatches
		{
			[HarmonyPatch]
			private static class FilterVisibility
			{
				private static IEnumerable<MethodBase> TargetMethods()
				{
					yield return AccessTools.Method(typeof(EnemyAI), "CheckLineOfSightForPlayer", (Type[])null, (Type[])null);
					yield return AccessTools.Method(typeof(EnemyAI), "CheckLineOfSightForClosestPlayer", (Type[])null, (Type[])null);
				}

				private static void Postfix(ref PlayerControllerB __result)
				{
					if (AvoidTarget(__result))
					{
						__result = null;
					}
				}
			}

			[HarmonyPatch]
			private static class IgnoreContacts
			{
				private static IEnumerable<MethodBase> TargetMethods()
				{
					yield return AccessTools.Method(typeof(EnemyAICollisionDetect), "OnTriggerStay", (Type[])null, (Type[])null);
					yield return AccessTools.Method(typeof(Landmine), "OnTriggerEnter", (Type[])null, (Type[])null);
					yield return AccessTools.Method(typeof(Landmine), "OnTriggerExit", (Type[])null, (Type[])null);
					yield return AccessTools.Method(typeof(SpikeRoofTrap), "OnTriggerStay", (Type[])null, (Type[])null);
					yield return AccessTools.Method(typeof(SandSpiderWebTrap), "OnTriggerStay", (Type[])null, (Type[])null);
				}

				private static bool Prefix(Collider __0, object __instance)
				{
					PlayerControllerB player = (Object.op_Implicit((Object)(object)__0) ? ((Component)__0).GetComponentInParent<PlayerControllerB>() : null);
					if (!(__instance is EnemyAICollisionDetect))
					{
						if (Object.op_Implicit((Object)(object)instance))
						{
							return !IsShrinkGear(instance.GearFor(player));
						}
						return true;
					}
					return !AvoidTarget(player);
				}
			}

			private static readonly RaycastHit[] TurretHits = (RaycastHit[])(object)new RaycastHit[24];

			[HarmonyPatch(typeof(EnemyAI), "PlayerIsTargetable")]
			[HarmonyPostfix]
			private static void FilterTargets(PlayerControllerB __0, ref bool __result)
			{
				if (AvoidTarget(__0))
				{
					__result = false;
				}
			}

			[HarmonyPatch(typeof(EnemyAI), "SetMovingTowardsTargetPlayer")]
			[HarmonyPrefix]
			private static bool PreventChase(PlayerControllerB __0)
			{
				return !AvoidTarget(__0);
			}

			[HarmonyPatch(typeof(EnemyAI), "Update")]
			[HarmonyPostfix]
			private static void ForgetHiddenTarget(EnemyAI __instance)
			{
				if (AvoidTarget(__instance.targetPlayer))
				{
					__instance.targetPlayer = null;
					__instance.movingTowardsTargetPlayer = false;
				}
			}

			[HarmonyPatch(typeof(Turret), "Update")]
			[HarmonyPrefix]
			private static void ForgetTurretTarget(Turret __instance)
			{
				if (IgnoreTurret(__instance.targetPlayerWithRotation))
				{
					__instance.targetPlayerWithRotation = null;
				}
			}

			[HarmonyPatch(typeof(Turret), "CheckForPlayersInLineOfSight")]
			[HarmonyTranspiler]
			private static IEnumerable<CodeInstruction> IgnoreSmallInTurretRay(IEnumerable<CodeInstruction> original)
			{
				MethodInfo raycast = AccessTools.Method(typeof(Physics), "Raycast", new Type[5]
				{
					typeof(Ray),
					typeof(RaycastHit).MakeByRefType(),
					typeof(float),
					typeof(int),
					typeof(QueryTriggerInteraction)
				}, (Type[])null);
				MethodInfo ignoredRay = AccessTools.Method(typeof(ThreatPatches), "RayPastSmallPlayer", (Type[])null, (Type[])null);
				foreach (CodeInstruction item in original)
				{
					if (CodeInstructionExtensions.Calls(item, raycast))
					{
						item.operand = ignoredRay;
					}
					yield return item;
				}
			}

			private static bool IgnoreTurret(PlayerControllerB player)
			{
				if (Object.op_Implicit((Object)(object)instance))
				{
					return IsShrinkGear(instance.GearFor(player));
				}
				return false;
			}

			private static bool RayPastSmallPlayer(Ray ray, out RaycastHit hit, float range, int mask, QueryTriggerInteraction trigger)
			{
				//IL_0000: 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_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_002b: 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_0047: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0073: Unknown result type (might be due to invalid IL or missing references)
				//IL_009b: Unknown result type (might be due to invalid IL or missing references)
				//IL_009d: Unknown result type (might be due to invalid IL or missing references)
				if (!Physics.Raycast(ray, ref hit, range, mask, trigger))
				{
					return false;
				}
				if (!IgnoreTurret(((Component)((RaycastHit)(ref hit)).collider).GetComponentInParent<PlayerControllerB>()))
				{
					return true;
				}
				int num = Physics.RaycastNonAlloc(ray, TurretHits, range, mask, trigger);
				RaycastHit[] array = ((num == TurretHits.Length) ? Physics.RaycastAll(ray, range, mask, trigger) : TurretHits);
				if (array != TurretHits)
				{
					num = array.Length;
				}
				float num2 = float.PositiveInfinity;
				hit = default(RaycastHit);
				for (int i = 0; i < num; i++)
				{
					RaycastHit val = array[i];
					if (!(((RaycastHit)(ref val)).distance >= num2) && !IgnoreTurret(((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<PlayerControllerB>()))
					{
						num2 = ((RaycastHit)(ref val)).distance;
						hit = val;
					}
				}
				return Object.op_Implicit((Object)(object)((RaycastHit)(ref hit)).collider);
			}
		}

		private sealed class PowerShot
		{
			internal ulong Id;

			internal ulong Caster;

			internal Vector3 Point;

			internal Vector3 Direction;

			internal float Age;
		}

		private sealed class PowerVisual
		{
			internal GameObject Root;

			internal Vector3 Start;

			internal Vector3 Direction;

			internal float Born;

			internal Transform Wake;
		}

		[HarmonyPatch(typeof(GrabbableObject), "OnDestroy")]
		private static class ClearDestroyedWand
		{
			private static void Prefix(GrabbableObject __instance)
			{
				NetworkManager singleton = NetworkManager.Singleton;
				StartOfRound instance = StartOfRound.Instance;
				if (!Object.op_Implicit((Object)(object)CompanyItemsPlugin.instance) || (!CompanyItemsPlugin.instance.IsWand(__instance) && !Object.op_Implicit((Object)(object)GearOf(__instance))) || !Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)singleton) || !singleton.IsListening || singleton.ShutdownInProgress)
				{
					return;
				}
				PlayerControllerB[] allPlayerScripts = instance.allPlayerScripts;
				foreach (PlayerControllerB val in allPlayerScripts)
				{
					if (!Object.op_Implicit((Object)(object)val) || val.ItemSlots == null)
					{
						continue;
					}
					bool flag = val.ItemOnlySlot == __instance;
					int num = Array.IndexOf(val.ItemSlots, __instance);
					if (!flag && num < 0)
					{
						continue;
					}
					if (flag)
					{
						val.ItemOnlySlot = null;
					}
					if (num >= 0)
					{
						val.ItemSlots[num] = null;
					}
					val.carryWeight = Mathf.Clamp(val.carryWeight - (CarryWeight(__instance) - 1f), 1f, 10f);
					bool flag2 = val.currentlyHeldObjectServer == __instance || val.currentlyHeldObject == __instance;
					if (val.currentlyHeldObjectServer == __instance)
					{
						val.currentlyHeldObjectServer = null;
					}
					if (val.currentlyHeldObject == __instance)
					{
						val.currentlyHeldObject = null;
					}
					if ((Object)(object)val.heldObjectServerCopy == (Object)(object)((Component)__instance).gameObject)
					{
						val.heldObjectServerCopy = null;
					}
					if (flag2)
					{
						val.isHoldingObject = false;
						val.twoHanded = false;
						val.twoHandedAnimation = false;
						val.activatingItem = false;
					}
					if (((NetworkBehaviour)val).IsOwner && Object.op_Implicit((Object)(object)HUDManager.Instance))
					{
						HUDManager instance2 = HUDManager.Instance;
						if (flag && Object.op_Implicit((Object)(object)instance2.itemOnlySlotIcon))
						{
							((Behaviour)instance2.itemOnlySlotIcon).enabled = false;
						}
						if (num >= 0 && num < instance2.itemSlotIcons.Length)
						{
							((Behaviour)instance2.itemSlotIcons[num]).enabled = false;
						}
						if (flag2)
						{
							instance2.ClearControlTips();
							((Behaviour)instance2.holdingTwoHandedItem).enabled = false;
							val.playerBodyAnimator.SetBool("cancelHolding", true);
							val.playerBodyAnimator.SetTrigger("Throw");
						}
						instance.SendChangedWeightEvent();
					}
				}
			}
		}

		private const string BundleSaveKey = "saltanis.przedmiotykmp.cargo.v1";

		private readonly Dictionary<ulong, TapeSelection> tapeSelections = new Dictionary<ulong, TapeSelection>();

		private readonly Dictionary<int, BundleRecord> bundleRecords = new Dictionary<int, BundleRecord>();

		private static readonly FieldRef<PlayerControllerB, int> PickupMask = AccessTools.FieldRefAccess<PlayerControllerB, int>("interactableObjectsMask");

		private string bundleSlot;

		private int bundleSequence;

		internal const string Id = "saltanis.przedmiotykmp";

		internal const string Version = "0.3.2";

		internal const string WandPrefab = "SaltanisFireballWand";

		private static CompanyItemsPlugin instance;

		private Harmony harmony;

		private Item wand;

		private ConfigEntry<int> wandPrice;

		private ConfigEntry<float> chargeSeconds;

		private ConfigEntry<float> blastRadius;

		private ConfigEntry<int> blastDamage;

		private ConfigEntry<float> wandBreakChance;

		private AudioClip chargeSound;

		private AudioClip launchSound;

		private AudioClip burstSound;

		private AudioClip shatterSound;

		private const string InputMessage = "saltanis.przedmiotykmp/3/input";

		private const string EffectMessage = "saltanis.przedmiotykmp/3/effect";

		private const int InputSize = 21;

		private const int EffectSize = 41;

		private const float FlightSeconds = 2.6f;

		private const float Speed = 23f;

		private const float HitRadius = 0.16f;

		private readonly Dictionary<ulong, Charge> charges = new Dictionary<ulong, Charge>();

		private readonly List<Shot> shots = new List<Shot>();

		private readonly RaycastHit[] hitBuffer = (RaycastHit[])(object)new RaycastHit[40];

		private readonly Collider[] initialOverlaps = (Collider[])(object)new Collider[20];

		private int additionalHitLayers;

		private NetworkManager net;

		private StartOfRound round;

		private CustomMessagingManager messenger;

		private GrabbableObject localWand;

		private float localRequested;

		private float localStart;

		private float localDuration;

		private ulong shotSequence;

		private const int EnemyBlastForce = 10;

		private const float LethalPlayerRadius = 0.55f;

		private const float BurstLifetime = 1.4f;

		private readonly Dictionary<ulong, ChargeLight> chargeVisuals = new Dictionary<ulong, ChargeLight>();

		private readonly Dictionary<ulong, FlightLight> flightVisuals = new Dictionary<ulong, FlightLight>();

		private readonly List<BurstLight> bursts = new List<BurstLight>();

		private readonly List<ShatteredStaff> shatteredStaves = new List<ShatteredStaff>();

		private readonly Random itemRandom = new Random();

		private readonly Dictionary<Gear, Item> gearItems = new Dictionary<Gear, Item>();

		private Mesh gearBox;

		private Mesh gearQuad;

		private Mesh gearTube;

		private Mesh gearRing;

		private Material gearMetal;

		private Material gearPaper;

		private Material gearRubber;

		private Material gearYellow;

		private Material gearSilver;

		private const string GearInputMessage = "saltanis.przedmiotykmp/4/gear-input";

		private const string GearEventMessage = "saltanis.przedmiotykmp/4/gear-event";

		private const int GearInputBytes = 21;

		private const int GearEventBytes = 49;

		private const float PotionDuration = 60f;

		private const float ReceiptChargeSeconds = 1f;

		private readonly Dictionary<ulong, EffectState> gearEffects = new Dictionary<ulong, EffectState>();

		private readonly Dictionary<ulong, TicketAnchor> ticketAnchors = new Dictionary<ulong, TicketAnchor>();

		private readonly Dictionary<ulong, ReceiptCharge> receiptCharges = new Dictionary<ulong, ReceiptCharge>();

		private readonly Dictionary<ulong, GameObject> ticketMarkers = new Dictionary<ulong, GameObject>();

		private readonly Dictionary<ulong, PendingValue> pendingValues = new Dictionary<ulong, PendingValue>();

		private readonly Dictionary<ulong, float> nextPowerShot = new Dictionary<ulong, float>();

		private float nextGearCheck;

		private float snapshotAt;

		private string gearNotice;

		private float gearNoticeUntil;

		private ulong chargingReceipt;

		private float receiptChargeStarted;

		private bool receiptHudActive;

		private static readonly Lazy<FieldInfo> GeneralImprovementsHealth = new Lazy<FieldInfo>(delegate
		{
			Type type = AccessTools.TypeByName("GeneralImprovements.Patches.PlayerControllerBPatch");
			return (!(type == null)) ? AccessTools.Field(type, "CurrentMaxHealth") : null;
		});

		private const float PowerInterval = 1f / 3f;

		private const float PowerSpeed = 65f;

		private const float PowerLifetime = 1.1f;

		private const float PowerRadius = 0.115f;

		private readonly List<PowerShot> powerShots = new List<PowerShot>();

		private readonly Dictionary<ulong, PowerVisual> powerVisuals = new Dictionary<ulong, PowerVisual>();

		private readonly List<ulong> expiredPowerVisuals = new List<ulong>();

		private float localShotAt;

		private ulong powerSequence;

		private Material powerCore;

		private Material powerGold;

		private Material powerAmber;

		private Mesh powerFlame;

		private Mesh powerWake;

		private Material bubblePink;

		private AudioClip powerCharge;

		private AudioClip powerPulse;

		private AudioClip gumPop;

		private Mesh sphere;

		private Material ember;

		private Material flame;

		private Material core;

		private Material smoke;

		private Mesh splinter;

		private Material staffMetal;

		private Material staffBrass;

		private const float StaffFoot = -0.865f;

		private const float CrownExtension = 0.17f;

		internal static readonly Vector3 WandTip = new Vector3(0.016f, 0.023f, 0.735f);

		private static PlayerControllerB LocalPlayer
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)GameNetworkManager.Instance))
				{
					return null;
				}
				return GameNetworkManager.Instance.localPlayerController;
			}
		}

		private void ResetBundles()
		{
			tapeSelections.Clear();
			bundleRecords.Clear();
			bundleSlot = null;
			bundleSequence = 0;
		}

		private void LoadBundleRecords()
		{
			string text = GameNetworkManager.Instance?.currentSaveFileName;
			if (string.IsNullOrEmpty(text) || bundleSlot == text)
			{
				return;
			}
			bundleSlot = text;
			bundleRecords.Clear();
			bundleSequence = 0;
			try
			{
				string text2 = ES3.Load<string>("saltanis.przedmiotykmp.cargo.v1", text, string.Empty);
				if (string.IsNullOrEmpty(text2))
				{
					return;
				}
				BundleRecord[] array = JsonUtility.FromJson<BundleSave>(text2)?.Bundles ?? Array.Empty<BundleRecord>();
				foreach (BundleRecord bundleRecord in array)
				{
					if (bundleRecord != null && bundleRecord.Id > 0)
					{
						PackedItem[] items = bundleRecord.Items;
						if (items != null && items.Length == 3)
						{
							bundleRecords[bundleRecord.Id] = bundleRecord;
							bundleSequence = Math.Max(bundleSequence, bundleRecord.Id);
						}
					}
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Could not read saved scrap bundles. " + ex));
			}
		}

		private void StoreBundleRecords()
		{
			LoadBundleRecords();
			if (!string.IsNullOrEmpty(bundleSlot))
			{
				BundleSave bundleSave = new BundleSave
				{
					Bundles = bundleRecords.Values.ToArray()
				};
				ES3.Save<string>("saltanis.przedmiotykmp.cargo.v1", JsonUtility.ToJson((object)bundleSave), bundleSlot);
			}
		}

		private void ReloadBundle(GrabbableObject prop, CrewGear gear)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			LoadBundleRecords();
			if (bundleRecords.TryGetValue(gear.SaveData, out var value))
			{
				gear.PackedWeight = value.Weight;
				DrawBundleContents(gear, BundleIndices(value));
			}
		}

		private Item FindPackedItem(PackedItem saved)
		{
			return (StartOfRound.Instance?.allItemsList?.itemsList)?.Find((Item item) => Object.op_Implicit((Object)(object)item) && Object.op_Implicit((Object)(object)item.spawnPrefab) && ((Object)item).name == saved.Name && ((Object)item.spawnPrefab).name == saved.Prefab);
		}

		private Vector3 BundleIndices(BundleRecord record)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			List<Item> itemsList = StartOfRound.Instance.allItemsList.itemsList;
			return new Vector3((float)itemsList.IndexOf(FindPackedItem(record.Items[0])), (float)itemsList.IndexOf(FindPackedItem(record.Items[1])), (float)itemsList.IndexOf(FindPackedItem(record.Items[2])));
		}

		private static bool CanPack(GrabbableObject item, GrabbableObject tape)
		{
			if (Object.op_Implicit((Object)(object)item) && (Object)(object)item != (Object)(object)tape && ((NetworkBehaviour)item).IsSpawned && item.grabbable && !item.deactivated && !item.isHeld && !item.isHeldByEnemy && !item.isPocketed && Object.op_Implicit((Object)(object)item.itemProperties) && Object.op_Implicit((Object)(object)item.itemProperties.spawnPrefab) && item.itemProperties.isScrap && !item.itemProperties.twoHanded)
			{
				return item.scrapValue > 0;
			}
			return false;
		}

		private void AddToTape(PlayerControllerB player, GrabbableObject tape, Vector3 direction)
		{
			//IL_006f: 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_0049: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: 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_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_050f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0525: Unknown result type (might be due to invalid IL or missing references)
			//IL_0545: Unknown result type (might be due to invalid IL or missing references)
			ulong actualClientId = player.actualClientId;
			Vector3 val = (Object.op_Implicit((Object)(object)player.gameplayCamera) ? ((Component)player.gameplayCamera).transform.position : (((Component)player).transform.position + Vector3.up * 1.45f));
			Vector3 val2 = val - ((Component)player).transform.position;
			if (((Vector3)(ref val2)).sqrMagnitude > 9f)
			{
				val = ((Component)player).transform.position + Vector3.up * 1.45f;
			}
			int num = round.collidersAndRoomMaskAndDefault | additionalHitLayers | PickupMask.Invoke(player);
			GrabbableObject val3 = null;
			int num2 = Physics.RaycastNonAlloc(val, direction, hitBuffer, 4.5f, num, (QueryTriggerInteraction)2);
			float num3 = float.PositiveInfinity;
			for (int i = 0; i < num2; i++)
			{
				RaycastHit val4 = hitBuffer[i];
				Collider collider = ((RaycastHit)(ref val4)).collider;
				if (Object.op_Implicit((Object)(object)collider) && !(((RaycastHit)(ref val4)).distance >= num3) && !((Component)collider).transform.IsChildOf(((Component)player).transform) && !((Component)collider).transform.IsChildOf(((Component)tape).transform) && !Object.op_Implicit((Object)(object)((Component)collider).GetComponent<ScanNodeProperties>()))
				{
					GrabbableObject componentInParent = ((Component)collider).GetComponentInParent<GrabbableObject>();
					if (!collider.isTrigger || Object.op_Implicit((Object)(object)componentInParent))
					{
						num3 = ((RaycastHit)(ref val4)).distance;
						val3 = componentInParent;
					}
				}
			}
			if (!CanPack(val3, tape))
			{
				NotifyGear(actualClientId, 5);
				return;
			}
			if (!tapeSelections.TryGetValue(((NetworkBehaviour)tape).NetworkObjectId, out var value) || value.Owner != actualClientId)
			{
				Dictionary<ulong, TapeSelection> dictionary = tapeSelections;
				ulong networkObjectId = ((NetworkBehaviour)tape).NetworkObjectId;
				TapeSelection obj = new TapeSelection
				{
					Owner = actualClientId
				};
				value = obj;
				dictionary[networkObjectId] = obj;
			}
			value.Objects.RemoveAll(delegate(ulong objectId)
			{
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				GrabbableObject val7 = FindGearObject(objectId);
				if (CanPack(val7, tape))
				{
					Vector3 val8 = ((Component)val7).transform.position - ((Component)player).transform.position;
					return ((Vector3)(ref val8)).sqrMagnitude > 49f;
				}
				return true;
			});
			ulong networkObjectId2 = ((NetworkBehaviour)val3).NetworkObjectId;
			if (value.Objects.Contains(networkObjectId2))
			{
				NotifyGear(actualClientId, 11);
				return;
			}
			value.Objects.Add(networkObjectId2);
			if (value.Objects.Count < 3)
			{
				NotifyGear(actualClientId, (value.Objects.Count == 1) ? 6 : 7);
				return;
			}
			GrabbableObject[] array = value.Objects.Select(FindGearObject).ToArray();
			LoadBundleRecords();
			BundleRecord bundleRecord = new BundleRecord
			{
				Id = ++bundleSequence,
				Weight = 1f,
				Items = new PackedItem[3]
			};
			int num4 = 0;
			while (num4 < array.Length)
			{
				GrabbableObject val5 = array[num4];
				if (CanPack(val5, tape))
				{
					val2 = ((Component)val5).transform.position - ((Component)player).transform.position;
					if (!(((Vector3)(ref val2)).sqrMagnitude > 49f))
					{
						bundleRecord.Weight += Mathf.Max(0f, val5.itemProperties.weight - 1f);
						bundleRecord.Items[num4] = new PackedItem
						{
							Name = ((Object)val5.itemProperties).name,
							Prefab = ((Object)val5.itemProperties.spawnPrefab).name,
							Value = val5.scrapValue
						};
						num4++;
						continue;
					}
				}
				value.Objects.Clear();
				NotifyGear(actualClientId, 9);
				return;
			}
			GrabbableObject val6;
			try
			{
				val6 = SpawnLooseGear(gearItems[Gear.Bundle], ((Component)val3).transform.position + Vector3.up * 0.18f, val3.isInShipRoom, val3.isInFactory, bundleRecord.Items.Sum((PackedItem entry) => entry.Value), bundleRecord.Id);
			}
			catch (Exception ex)
			{
				value.Objects.Clear();
				((BaseUnityPlugin)this).Logger.LogError((object)("Could not bundle the three items. " + ex));
				NotifyGear(actualClientId, 0);
				return;
			}
			bundleRecords[bundleRecord.Id] = bundleRecord;
			GearOf(val6).PackedWeight = bundleRecord.Weight;
			GrabbableObject[] array2 = array;
			for (int num5 = 0; num5 < array2.Length; num5++)
			{
				((NetworkBehaviour)array2[num5]).NetworkObject.Despawn(true);
			}
			tapeSelections.Remove(((NetworkBehaviour)tape).NetworkObjectId);
			((NetworkBehaviour)tape).NetworkObject.Despawn(true);
			PublishGear(GearEvent.Packed, ((NetworkBehaviour)val6).NetworkObjectId, 0uL, val6.scrapValue, bundleRecord.Id, BundleIndices(bundleRecord), new Vector3(bundleRecord.Weight, 0f, 0f));
			NotifyGear(actualClientId, 8);
			PlayOneShot(shatterSound, ((Component)val6).transform.position, 0.35f, 9f);
		}

		private GrabbableObject SpawnLooseGear(Item definition, Vector3 position, bool ship, bool inside, int value, int saveData)
		{
			//IL_0006: 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_000d: 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
			GameObject val = Object.Instantiate<GameObject>(definition.spawnPrefab, position, Quaternion.Euler(definition.restingRotation), ship ? round.elevatorTransform : null);
			GrabbableObject component = val.GetComponent<GrabbableObject>();
			try
			{
				component.isInShipRoom = ship;
				component.isInElevator = ship;
				component.isInFactory = inside;
				component.SetScrapValue(value);
				if (definition.requiresBattery)
				{
					component.insertedBattery = new Battery(false, 1f);
				}
				if (definition.saveItemVariable && (Object)(object)definition != (Object)(object)gearItems[Gear.Bundle])
				{
					component.LoadItemSaveData(saveData);
				}
				CrewGear crewGear = GearOf(component);
				if (Object.op_Implicit((Object)(object)crewGear))
				{
					crewGear.SaveData = saveData;
				}
				((NetworkBehaviour)component).NetworkObject.Spawn(false);
				return component;
			}
			catch
			{
				if (Object.op_Implicit((Object)(object)component) && ((NetworkBehaviour)component).IsSpawned)
				{
					((NetworkBehaviour)component).NetworkObject.Despawn(true);
				}
				else
				{
					Object.Destroy((Object)(object)val);
				}
				throw;
			}
		}

		private void SetGearValue(GrabbableObject prop, int value, int saveData, Vector3 extras, Vector3 models)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			if (value > 0)
			{
				prop.SetScrapValue(value);
			}
			CrewGear crewGear = GearOf(prop);
			if (!Object.op_Implicit((Object)(object)crewGear))
			{
				return;
			}
			crewGear.SaveData = saveData;
			if (crewGear.Kind == Gear.Bundle)
			{
				if (extras.x >= 1f)
				{
					crewGear.PackedWeight = extras.x;
				}
				DrawBundleContents(crewGear, models);
			}
		}

		private void DrawBundleContents(CrewGear gear, Vector3 models)
		{
			//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_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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected O, but got Unknown
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			if (gear.PackedModels == models && gear.HasPackedModels)
			{
				return;
			}
			List<Item> list = StartOfRound.Instance?.allItemsList?.itemsList;
			if (list == null)
			{
				return;
			}
			if (Object.op_Implicit((Object)(object)gear.Display))
			{
				Object.Destroy((Object)(object)gear.Display);
			}
			gear.PackedModels = models;
			gear.HasPackedModels = true;
			gear.Display = new GameObject("Zawartość paczki");
			gear.Display.transform.SetParent(((Component)gear).transform, false);
			for (int i = 0; i < 3; i++)
			{
				int num = (int)((Vector3)(ref models))[i];
				if (num < 0 || num >= list.Count || !Object.op_Implicit((Object)(object)list[num]) || !Object.op_Implicit((Object)(object)list[num].spawnPrefab))
				{
					continue;
				}
				MeshRenderer val = ((IEnumerable<MeshRenderer>)list[num].spawnPrefab.GetComponentsInChildren<MeshRenderer>(true)).FirstOrDefault((Func<MeshRenderer, bool>)delegate(MeshRenderer candidate)
				{
					if (Object.op_Implicit((Object)(object)candidate))
					{
						MeshFilter component = ((Component)candidate).GetComponent<MeshFilter>();
						return Object.op_Implicit((Object)(object)((component != null) ? component.sharedMesh : null));
					}
					return false;
				});
				if (Object.op_Implicit((Object)(object)val))
				{
					Mesh sharedMesh = ((Component)val).GetComponent<MeshFilter>().sharedMesh;
					Bounds bounds = sharedMesh.bounds;
					float num2 = 0.24f / Mathf.Max(0.001f, Mathf.Max(((Bounds)(ref bounds)).size.x, Mathf.Max(((Bounds)(ref bounds)).size.y, ((Bounds)(ref bounds)).size.z)));
					Transform transform = new GameObject("Złożony złom").transform;
					transform.SetParent(gear.Display.transform, false);
					transform.localPosition = new Vector3((float)(i - 1) * 0.17f, 0.17f, (float)(i % 2) * -0.055f);
					transform.localRotation = Quaternion.Euler(13f + (float)i * 19f, 31f * (float)i, 21f - (float)i * 16f);
					((Renderer)((Component)Part("Widoczny przedmiot", transform, sharedMesh, Object.op_Implicit((Object)(object)((Renderer)val).sharedMaterial) ? ((Renderer)val).sharedMaterial : gearMetal, -((Bounds)(ref bounds)).center * num2, Vector3.one * num2)).GetComponent<MeshRenderer>()).sharedMaterials = ((Renderer)val).sharedMaterials;
				}
			}
		}

		private static float CarryWeight(GrabbableObject item)
		{
			CrewGear crewGear = GearOf(item);
			if (!Object.op_Implicit((Object)(object)crewGear) || crewGear.Kind != Gear.Bundle || !(crewGear.PackedWeight >= 1f))
			{
				return item.itemProperties.weight;
			}
			return crewGear.PackedWeight;
		}

		private void Awake()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Expected O, but got Unknown
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Expected O, but got Unknown
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Expected O, but got Unknown
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Expected O, but got Unknown
			instance = this;
			bool num = HasOldConfig();
			wandPrice = ((BaseUnityPlugin)this).Config.Bind<int>("Fireball Wand", "Cena", 240, new ConfigDescription("Price in the terminal store.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 2000), Array.Empty<object>()));
			chargeSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Fireball Wand", "CzasLadowania", 5f, new ConfigDescription("Seconds to fully charge the wand. Set by the host.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 12f), Array.Empty<object>()));
			blastRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Fireball Wand", "PromienWybuchu", 11f, new ConfigDescription("Blast radius in meters. Set by the host.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 22f), Array.Empty<object>()));
			if (num && Mathf.Approximately(blastRadius.Value, 5.5f))
			{
				blastRadius.Value = 11f;
			}
			blastDamage = ((BaseUnityPlugin)this).Config.Bind<int>("Fireball Wand", "Obrazenia", 65, new ConfigDescription("Damage to players within the blast radius. Set by the host.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
			wandBreakChance = ((BaseUnityPlugin)this).Config.Bind<float>("Fireball Wand", "SzansaRozpadu", 0.5f, new ConfigDescription("Chance of the wand breaking after each shot. Set by the host.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			additionalHitLayers = LayerMask.GetMask(new string[9] { "Enemies", "EnemiesNotRendered", "Props", "PhysicsObject", "Terrain", "MiscLevelGeometry", "MapHazards", "Railing", "Vehicle" });
			LoadSounds();
			LoadGearSounds();
			harmony = new Harmony("saltanis.przedmiotykmp");
			harmony.PatchAll();
		}

		private bool HasOldConfig()
		{
			try
			{
				if (!File.Exists(((BaseUnityPlugin)this).Config.ConfigFilePath))
				{
					return false;
				}
				string text = File.ReadLines(((BaseUnityPlugin)this).Config.ConfigFilePath).FirstOrDefault();
				return text != null && (text.EndsWith(" v0.1.0") || text.EndsWith(" v0.1.1"));
			}
			catch (IOException)
			{
				return false;
			}
			catch (UnauthorizedAccessException)
			{
				return false;
			}
		}

		private void OnDestroy()
		{
			ResetSession();
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			instance = null;
		}

		private void RegisterItems()
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)wand))
			{
				Item val = ((IEnumerable<Item>)Resources.FindObjectsOfTypeAll<Item>()).FirstOrDefault((Func<Item, bool>)((Item item) => Object.op_Implicit((Object)(object)item) && ((Object)item).name == "MetalSheet" && Object.op_Implicit((Object)(object)item.spawnPrefab) && Object.op_Implicit((Object)(object)item.spawnPrefab.GetComponent<PhysicsProp>())));
				if (!Object.op_Implicit((Object)(object)val))
				{
					((BaseUnityPlugin)this).Logger.LogError((object)"Could not find the vanilla PhysicsProp template for the wand.");
					return;
				}
				GameObject val2 = NetworkPrefabs.CloneNetworkPrefab(val.spawnPrefab, "SaltanisFireballWand");
				val2.transform.localScale = Vector3.one;
				wand = Object.Instantiate<Item>(val);
				((Object)wand).name = "SaltanisFireballWand";
				wand.itemName = "Fireball Wand";
				wand.spawnPrefab = val2;
				wand.creditsWorth = wandPrice.Value;
				wand.isScrap = false;
				wand.requiresBattery = false;
				wand.weight = 1.025f;
				wand.twoHanded = false;
				wand.twoHandedAnimation = false;
				wand.canBeGrabbedBeforeGameStart = true;
				wand.holdButtonUse = true;
				wand.syncUseFunction = false;
				wand.usableInSpecialAnimations = false;
				wand.verticalOffset = 0.065f;
				wand.restingRotation = Vector3.zero;
				wand.rotationOffset = new Vector3(-42.05f, 136.53f, 132.35f);
				wand.positionOffset = new Vector3(0.039f, -0.032f, 0.029f);
				wand.meshVariants = Array.Empty<Mesh>();
				wand.materialVariants = Array.Empty<Material>();
				wand.toolTips = new string[1] { "Charge fireball : [Hold LMB]" };
				PhysicsProp component = val2.GetComponent<PhysicsProp>();
				((GrabbableObject)component).itemProperties = wand;
				((GrabbableObject)component).grabbable = true;
				val2.tag = "PhysicsProp";
				CreateWandModel(val2);
				val2.AddComponent<WandPose>();
				TerminalNode val3 = ScriptableObject.CreateInstance<TerminalNode>();
				val3.displayText = "FIREBALL WAND\n\nHold the use button to charge and launch a fireball. Each shot can shatter the wand and deal 10 damage to the caster. The fireball explodes on impact and can kill a Coil-Head. Keep crewmates clear of the blast.\n\n";
				val3.clearPreviousText = true;
				Items.RegisterShopItem(wand, (TerminalNode)null, (TerminalNode)null, val3, wandPrice.Value);
				RegisterGear(val);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Registered the Fireball Wand in the store and item catalog.");
			}
		}

		private bool IsWand(GrabbableObject item)
		{
			if (Object.op_Implicit((Object)(object)item) && Object.op_Implicit((Object)(object)wand))
			{
				return (Object)(object)item.itemProperties == (Object)(object)wand;
			}
			return false;
		}

		private GrabbableObject HeldWand(PlayerControllerB player)
		{
			if (!Object.op_Implicit((Object)(object)player) || !player.isPlayerControlled || player.isPlayerDead || !player.isHoldingObject)
			{
				return null;
			}
			GrabbableObject currentlyHeldObjectServer = player.currentlyHeldObjectServer;
			if (!IsWand(currentlyHeldObjectServer) || !((NetworkBehaviour)currentlyHeldObjectServer).IsSpawned || currentlyHeldObjectServer.isPocketed || ((NetworkBehaviour)currentlyHeldObjectServer).OwnerClientId != player.actualClientId)
			{
				return null;
			}
			return currentlyHeldObjectServer;
		}

		private void LoadSounds()
		{
			string text = Path.Combine(Paths.ConfigPath, "PrzedmiotyKompanii", "I_CAST_FIREBALL.wav");
			if (File.Exists(text))
			{
				try
				{
					chargeSound = ReadWav(text);
				}
				catch (Exception ex)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not load I_CAST_FIREBALL.wav. " + ex.Message));
				}
			}
			if (!Object.op_Implicit((Object)(object)chargeSound))
			{
				chargeSound = Synth("Narastanie zaklęcia", 5f, delegate(float t, float p, float noise)
				{
					float num = Mathf.Sin(6.283f * (62f * t + 18f * t * t));
					float num2 = Mathf.Sin(6.283f * (164f * t + 13f * t * t)) * Mathf.Sin(6.283f * (2f * t + t * t));
					return (num * 0.18f + num2 * 0.1f + noise * 0.015f) * Mathf.Sin(p * (float)Math.PI) * (0.2f + 0.8f * p);
				});
			}
			launchSound = Synth("Wystrzał Fireballa", 0.32f, (float t, float p, float noise) => (noise * (0.34f - 0.16f * p) + 0.11f * Mathf.Sin(6.283f * (155f * t - 110f * t * t))) * Mathf.Sin(p * (float)Math.PI) * (1f - p));
			burstSound = Synth("Wybuch Fireballa", 0.72f, (float t, float p, float noise) => (noise * 0.32f + 0.43f * Mathf.Sin(6.283f * (75f * t - 30f * t * t))) * Mathf.Min(1f, t * 170f) * Mathf.Pow(1f - p, 3f));
			shatterSound = Synth("Trzask kostura", 0.33f, (float t, float p, float noise) => (noise * 0.4f + 0.13f * Mathf.Sin(6.283f * t * 1470f)) * Mathf.Exp(-16f * t) * Mathf.Min(1f, 570f * t));
		}

		private static AudioClip Synth(string title, float length, Func<float, float, float, float> sample)
		{
			float[] array = new float[Mathf.CeilToInt(length * 22050f)];
			Random random = new Random(210);
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = sample((float)i / 22050f, (float)i / (float)array.Length, (float)(2.0 * random.NextDouble() - 1.0));
			}
			AudioClip obj = AudioClip.Create(title, array.Length, 1, 22050, false);
			obj.SetData(array, 0);
			return obj;
		}

		private static AudioClip ReadWav(string file)
		{
			using BinaryReader binaryReader = new BinaryReader(File.OpenRead(file));
			if (binaryReader.BaseStream.Length > 16777216 || new string(binaryReader.ReadChars(4)) != "RIFF")
			{
				throw new InvalidDataException("Expected a 16-bit PCM WAV file.");
			}
			binaryReader.ReadInt32();
			if (new string(binaryReader.ReadChars(4)) != "WAVE")
			{
				throw new InvalidDataException("Invalid WAV file.");
			}
			int num = 0;
			int num2 = 0;
			byte[] array = null;
			while (binaryReader.BaseStream.Position + 8 <= binaryReader.BaseStream.Length)
			{
				string text = new string(binaryReader.ReadChars(4));
				int num3 = binaryReader.ReadInt32();
				long num4 = binaryReader.BaseStream.Position + num3;
				if (num3 < 0 || num4 > binaryReader.BaseStream.Length)
				{
					throw new InvalidDataException("Invalid WAV header.");
				}
				if (text == "fmt " && num3 >= 16)
				{
					ushort num5 = binaryReader.ReadUInt16();
					num2 = binaryReader.ReadUInt16();
					num = binaryReader.ReadInt32();
					binaryReader.ReadInt32();
					binaryReader.ReadUInt16();
					int num6 = binaryReader.ReadUInt16();
					if (num5 != 1 || num6 != 16 || num2 < 1 || num2 > 2 || num < 8000 || num > 96000)
					{
						throw new InvalidDataException("Use 16-bit PCM WAV, mono or stereo.");
					}
				}
				else if (text == "data")
				{
					array = binaryReader.ReadBytes(num3);
				}
				binaryReader.BaseStream.Position = num4 + (num3 & 1);
			}
			if (array == null || num == 0 || array.Length < 2 * num2 || array.Length % (2 * num2) != 0)
			{
				throw new InvalidDataException("The WAV file contains no audio samples.");
			}
			float[] array2 = new float[array.Length / (2 * num2)];
			for (int i = 0; i < array2.Length; i++)
			{
				int num7 = i * num2 * 2;
				for (int j = 0; j < num2; j++)
				{
					array2[i] += (float)BitConverter.ToInt16(array, num7 + 2 * j) / (32768f * (float)num2);
				}
			}
			AudioClip obj = AudioClip.Create("I CAST FIREBALL!", array2.Length, 1, num, false);
			obj.SetData(array2, 0);
			return obj;
		}

		private void PlayCharge(GameObject obj, float duration, bool local)
		{
			AudioSource val = obj.AddComponent<AudioSource>();
			val.clip = chargeSound;
			val.spatialBlend = (local ? 0f : 1f);
			val.rolloffMode = (AudioRolloffMode)0;
			val.minDistance = 1.8f;
			val.maxDistance = 16f;
			val.volume = 0.78f;
			val.pitch = Mathf.Clamp(chargeSound.length / duration, 1f, 3f);
			val.time = Mathf.Max(0f, chargeSound.length - duration * val.pitch);
			float num = duration - (chargeSound.length - val.time) / val.pitch;
			if (num > 0.01f)
			{
				val.PlayDelayed(num);
			}
			else
			{
				val.Play();
			}
		}

		private void PlayOneShot(AudioClip clip, Vector3 position, float volume, float range)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			GameObject val = new GameObject(((Object)clip).name);
			val.transform.position = position;
			AudioSource obj = val.AddComponent<AudioSource>();
			obj.spatialBlend = 1f;
			obj.rolloffMode = (AudioRolloffMode)0;
			obj.minDistance = 2f;
			obj.maxDistance = range;
			obj.PlayOneShot(clip, volume);
			Object.Destroy((Object)val, clip.length + 0.15f);
		}

		private void Update()
		{
			NetworkManager singleton = NetworkManager.Singleton;
			StartOfRound val = StartOfRound.Instance;
			if (!Object.op_Implicit((Object)(object)singleton) || !singleton.IsListening || !Object.op_Implicit((Object)(object)val) || !((NetworkBehaviour)val).IsSpawned)
			{
				if (net != null)
				{
					ResetSession();
				}
				return;
			}
			if ((Object)(object)singleton != (Object)(object)net || (Object)(object)val != (Object)(object)round)
			{
				ResetSession();
				net = singleton;
				round = val;
			}
			BindMessages();
			TickGear();
			TickLocalCharge();
			if (net.IsServer)
			{
				TickHost();
			}
			UpdateVisuals();
		}

		private void BindMessages()
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			if (messenger == null && net.CustomMessagingManager != null)
			{
				messenger = net.CustomMessagingManager;
				if (net.IsServer)
				{
					messenger.RegisterNamedMessageHandler("saltanis.przedmiotykmp/3/input", new HandleNamedMessageDelegate(ReceiveInput));
				}
				else
				{
					messenger.RegisterNamedMessageHandler("saltanis.przedmiotykmp/3/effect", new HandleNamedMessageDelegate(ReceiveEffect));
				}
				BindGear();
			}
		}

		private void ResetSession()
		{
			if (messenger != null)
			{
				UnbindGear();
				messenger.UnregisterNamedMessageHandler("saltanis.przedmiotykmp/3/input");
				messenger.UnregisterNamedMessageHandler("saltanis.przedmiotykmp/3/effect");
			}
			messenger = null;
			net = null;
			round = null;
			localWand = null;
			localDuration = 0f;
			charges.Clear();
			shots.Clear();
			ResetGear();
			ClearVisuals();
		}

		private void OnWandInput(GrabbableObject item, bool buttonDown)
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)net) || messenger == null)
			{
				return;
			}
			if (!buttonDown)
			{
				if ((Object)(object)localWand == (Object)(object)item)
				{
					CancelLocal();
				}
			}
			else if (!Object.op_Implicit((Object)(object)localWand) && !((Object)(object)item != (Object)(object)HeldWand(LocalPlayer)) && !round.shipIsLeaving)
			{
				localWand = item;
				localRequested = Time.unscaledTime;
				localDuration = 0f;
				SendInput(InputKind.Start, ((NetworkBehaviour)item).NetworkObjectId, Vector3.zero);
			}
		}

		private void CancelLocal()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			GrabbableObject val = localWand;
			localWand = null;
			localDuration = 0f;
			StopChargeEffect(net.LocalClientId);
			if (Object.op_Implicit((Object)(object)val))
			{
				SendInput(InputKind.Cancel, ((NetworkBehaviour)val).NetworkObjectId, Vector3.zero);
			}
		}

		private void TickLocalCharge()
		{
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)localWand))
			{
				PlayerControllerB localPlayer = LocalPlayer;
				if (round.shipIsLeaving || (Object)(object)HeldWand(localPlayer) != (Object)(object)localWand || localPlayer.disableInteract || localPlayer.inTerminalMenu || localPlayer.isTypingChat || (Object.op_Implicit((Object)(object)localPlayer.quickMenuManager) && localPlayer.quickMenuManager.isMenuOpen) || (localDuration == 0f && Time.unscaledTime - localRequested > 2f))
				{
					CancelLocal();
				}
				else if (localDuration != 0f && !(Time.unscaledTime - localStart < localDuration))
				{
					ulong networkObjectId = ((NetworkBehaviour)localWand).NetworkObjectId;
					localWand = null;
					localDuration = 0f;
					SendInput(InputKind.Fire, networkObjectId, ((Component)localPlayer.gameplayCamera).transform.forward);
				}
			}
		}

		private PlayerControllerB PlayerByClient(ulong client)
		{
			PlayerControllerB[] allPlayerScripts = round.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if (Object.op_Implicit((Object)(object)val) && val.actualClientId == client && val.isPlayerControlled && !val.isPlayerDead)
				{
					return val;
				}
			}
			return null;
		}

		private unsafe void SendInput(InputKind action, ulong item, Vector3 aim)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			if (net.IsServer)
			{
				AcceptInput(net.LocalClientId, action, item, aim);
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(21, (Allocator)2, -1);
			try
			{
				byte b = (byte)action;
				((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref b, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref item, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe(ref aim);
				messenger.SendNamedMessage("saltanis.przedmiotykmp/3/input", 0uL, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private void ReceiveInput(ulong sender, FastBufferReader packet)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			if (((FastBufferReader)(ref packet)).Length - ((FastBufferReader)(ref packet)).Position == 21 && net.ConnectedClients.ContainsKey(sender))
			{
				byte action = default(byte);
				((FastBufferReader)(ref packet)).ReadValueSafe<byte>(ref action, default(ForPrimitives));
				ulong item = default(ulong);
				((FastBufferReader)(ref packet)).ReadValueSafe<ulong>(ref item, default(ForPrimitives));
				Vector3 aim = default(Vector3);
				((FastBufferReader)(ref packet)).ReadValueSafe(ref aim);
				AcceptInput(sender, (InputKind)action, item, aim);
			}
		}

		private void AcceptInput(ulong sender, InputKind action, ulong item, Vector3 aim)
		{
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: 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_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			if (action == InputKind.Cancel)
			{
				if (charges.TryGetValue(sender, out var value) && value.Item == item)
				{
					CancelHost(sender);
				}
				return;
			}
			PlayerControllerB val = PlayerByClient(sender);
			GrabbableObject val2 = HeldWand(val);
			if (!Object.op_Implicit((Object)(object)val2) || ((NetworkBehaviour)val2).NetworkObjectId != item || round.shipIsLeaving)
			{
				return;
			}
			Vector3 val3;
			if (action == InputKind.Start && !charges.ContainsKey(sender))
			{
				float value2 = chargeSeconds.Value;
				charges.Add(sender, new Charge
				{
					Item = item,
					Started = Time.unscaledTime,
					Duration = value2
				});
				ulong id = sender;
				float amount = value2;
				val3 = default(Vector3);
				Vector3 position = val3;
				val3 = default(Vector3);
				Broadcast(EffectKind.Charge, id, position, val3, amount);
			}
			if (action == InputKind.Fire && charges.TryGetValue(sender, out var value3) && value3.Item == item && !(Time.unscaledTime - value3.Started < value3.Duration - 0.04f) && ((Vector3)(ref aim)).sqrMagnitude >= 0.9f && ((Vector3)(ref aim)).sqrMagnitude <= 1.1f)
			{
				charges.Remove(sender);
				ulong id2 = sender;
				val3 = default(Vector3);
				Vector3 position2 = val3;
				val3 = default(Vector3);
				Broadcast(EffectKind.Cancel, id2, position2, val3);
				Vector3 val4 = ((Component)val.gameplayCamera).transform.position;
				val3 = val4 - ((Component)val).transform.position;
				if (((Vector3)(ref val3)).sqrMagnitude > 9f)
				{
					val4 = ((Component)val).transform.position + Vector3.up * 1.45f;
				}
				Shot shot = new Shot
				{
					Id = ++shotSequence,
					Caster = sender,
					Position = val4,
					Direction = ((Vector3)(ref aim)).normalized
				};
				sho