Decompiled source of Company Items v0.3.6

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", "Company Items", "0.3.6")]
	[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
		{
			private static readonly HashSet<string> MorphAudioEvents = new HashSet<string>
			{
				"PlayAudio1", "PlayAudio1RandomClip", "PlayAudio2RandomClip", "PlayAudioB1", "PlayAudio1Oneshot", "PlayAudio2", "PlayAudioB2", "PlayAudio2Oneshot", "PlayAudio3Oneshot", "StopAudio",
				"PauseAudio", "PlayAudio1DefaultClip", "PlayAudio1DefaultClipIfNotPlaying"
			};

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

			private readonly List<AnimationClip> clonedMorphClips = new List<AnimationClip>();

			private readonly HashSet<AnimationClip> morphSoundClips = new HashSet<AnimationClip>();

			private readonly List<AnimatorClipInfo> currentMorphClips = new List<AnimatorClipInfo>();

			private Animator morph;

			private AnimatorOverrideController morphController;

			private AudioClip[] morphSounds;

			private AudioSource morphSoundSource;

			private float nextMorphSound;

			private Vector3 previousMorphPosition;

			private Vector3 morphMotion;

			private int motionX;

			private int motionZ;

			private int motionSpeed;

			private DissonanceComms voice;

			private bool priorMute;

			private bool muteMorphVoice;

			private AudioSource playback;

			private bool priorPlaybackMute;

			private Camera movedCamera;

			private Vector3 cameraPosition;

			private Quaternion cameraRotation;

			private float? previousNameAlpha;

			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 GameObject visual;

			private Light auraLight;

			private Transform[] flames;

			private Transform[] sparks;

			private float safePositionAt;

			private Transform leftPalm;

			private Transform rightPalm;

			private float castAt = -10f;

			private bool leftCast;

			internal float MorphWalkSpeed
			{
				get
				{
					if (Form != 1)
					{
						return 4f;
					}
					return 6f;
				}
			}

			private void ApplyMorph()
			{
				muteMorphVoice = true;
				KeepMorphMuted();
				GrabbableObject currentlyHeldObjectServer = Player.currentlyHeldObjectServer;
				WalkieTalkie val = (WalkieTalkie)(object)((currentlyHeldObjectServer is WalkieTalkie) ? currentlyHeldObjectServer : null);
				if (val != null && Object.op_Implicit((Object)(object)val))
				{
					StopMorphRadio(val, Player);
				}
				if (Player.ItemSlots != null)
				{
					GrabbableObject[] itemSlots = Player.ItemSlots;
					foreach (GrabbableObject val2 in itemSlots)
					{
						WalkieTalkie val3 = (WalkieTalkie)(object)((val2 is WalkieTalkie) ? val2 : null);
						if (val3 != null && Object.op_Implicit((Object)(object)val3))
						{
							StopMorphRadio(val3, Player);
							continue;
						}
						FlashlightItem val4 = (FlashlightItem)(object)((val2 is FlashlightItem) ? val2 : null);
						if (val4 != null && Object.op_Implicit((Object)(object)val4) && ((GrabbableObject)val4).isBeingUsed)
						{
							val4.SwitchFlashlight(false);
						}
					}
				}
				Player.holdingWalkieTalkie = false;
				Player.speakingToWalkieTalkie = false;
				if (((NetworkBehaviour)Player).IsOwner && Player.isCrouching)
				{
					Player.Crouch(false);
				}
				if (Object.op_Implicit((Object)(object)Player.usernameAlpha))
				{
					previousNameAlpha = Player.usernameAlpha.alpha;
					Player.usernameAlpha.alpha = 0f;
				}
				try
				{
					BuildMorph();
				}
				catch (Exception ex)
				{
					if (Object.op_Implicit((Object)(object)visual))
					{
						Object.Destroy((Object)(object)visual);
					}
					visual = null;
					morph = null;
					((BaseUnityPlugin)plugin).Logger.LogWarning((object)("Could not build the mutagen disguise: " + ex.GetBaseException().Message));
				}
			}

			private void BuildMorph()
			{
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Expected O, but got Unknown
				//IL_007e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0083: Unknown result type (might be due to invalid IL or missing references)
				//IL_010f: Unknown result type (might be due to invalid IL or missing references)
				//IL_043b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0440: 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;
				}
				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.SetLocalPositionAndRotation(Vector3.zero, 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));
				if (!Object.op_Implicit((Object)(object)morph) || !Object.op_Implicit((Object)(object)morph.runtimeAnimatorController) || !val2.GetComponentsInChildren<SkinnedMeshRenderer>(true).Any((SkinnedMeshRenderer skin) => Object.op_Implicit((Object)(object)skin.sharedMesh)))
				{
					throw new MissingComponentException("The creature prefab has no animated skin.");
				}
				HoarderBugAI val3 = (HoarderBugAI)(object)((component is HoarderBugAI) ? component : null);
				if (val3 != null)
				{
					morphSounds = val3.chitterSFX;
					morphSoundSource = ((EnemyAI)val3).creatureVoice;
				}
				else
				{
					PufferAI val4 = (PufferAI)(object)((component is PufferAI) ? component : null);
					if (val4 != null)
					{
						morphSounds = val4.footstepsSFX;
						morphSoundSource = ((EnemyAI)val4).creatureSFX;
					}
				}
				PlayAudioAnimationEvent[] components = ((Component)morph).GetComponents<PlayAudioAnimationEvent>();
				MonoBehaviour[] componentsInChildren = val2.GetComponentsInChildren<MonoBehaviour>(true);
				foreach (MonoBehaviour val5 in componentsInChildren)
				{
					if (Object.op_Implicit((Object)(object)val5))
					{
						PlayAudioAnimationEvent val6 = (PlayAudioAnimationEvent)(object)((val5 is PlayAudioAnimationEvent) ? val5 : null);
						if (val6 != null && (Object)(object)((Component)val6).gameObject == (Object)(object)((Component)morph).gameObject)
						{
							val6.onAnimationEventCalled = null;
							val6.destroyObject = null;
							val6.playAudibleNoise = false;
						}
						else if (!(((object)val5).GetType().Namespace == "UnityEngine.Animations.Rigging"))
						{
							Object.DestroyImmediate((Object)(object)val5);
						}
					}
				}
				Collider[] componentsInChildren2 = val2.GetComponentsInChildren<Collider>(true);
				for (int num = 0; num < componentsInChildren2.Length; num++)
				{
					Object.DestroyImmediate((Object)(object)componentsInChildren2[num]);
				}
				Rigidbody[] componentsInChildren3 = val2.GetComponentsInChildren<Rigidbody>(true);
				for (int num = 0; num < componentsInChildren3.Length; num++)
				{
					Object.DestroyImmediate((Object)(object)componentsInChildren3[num]);
				}
				NavMeshAgent[] componentsInChildren4 = val2.GetComponentsInChildren<NavMeshAgent>(true);
				for (int num = 0; num < componentsInChildren4.Length; num++)
				{
					Object.DestroyImmediate((Object)(object)componentsInChildren4[num]);
				}
				Light[] componentsInChildren5 = val2.GetComponentsInChildren<Light>(true);
				for (int num = 0; num < componentsInChildren5.Length; num++)
				{
					Object.DestroyImmediate((Object)(object)componentsInChildren5[num]);
				}
				AudioSource[] componentsInChildren6 = val2.GetComponentsInChildren<AudioSource>(true);
				foreach (AudioSource audio in componentsInChildren6)
				{
					audio.playOnAwake = false;
					((Behaviour)audio).enabled = (Object)(object)audio == (Object)(object)morphSoundSource || components.Any((PlayAudioAnimationEvent events) => (Object)(object)events.audioToPlay == (Object)(object)audio || (Object)(object)events.audioToPlayB == (Object)(object)audio);
				}
				val2.SetActive(true);
				Transform val7 = ((Component)morph).transform;
				while ((Object)(object)val7 != (Object)(object)visual.transform)
				{
					((Component)val7).gameObject.SetActive(true);
					val7 = val7.parent;
				}
				SkinnedMeshRenderer[] componentsInChildren7 = val2.GetComponentsInChildren<SkinnedMeshRenderer>(true);
				foreach (SkinnedMeshRenderer val8 in componentsInChildren7)
				{
					if (Object.op_Implicit((Object)(object)val8.sharedMesh))
					{
						((Renderer)val8).forceRenderingOff = false;
						val8.updateWhenOffscreen = true;
						if (((NetworkBehaviour)Player).IsOwner && Object.op_Implicit((Object)(object)Player.gameplayCamera) && (Player.gameplayCamera.cullingMask & (1 << ((Component)val8).gameObject.layer)) == 0)
						{
							((Component)val8).gameObject.layer = LayerMask.NameToLayer("Default");
						}
					}
				}
				morph.applyRootMotion = false;
				morph.fireEvents = false;
				morph.cullingMode = (AnimatorCullingMode)0;
				((Behaviour)morph).enabled = true;
				if (components.Length != 0)
				{
					PrepareMorphSounds();
				}
				visual.SetActive(true);
				HideHumanModel();
				previousMorphPosition = visual.transform.position;
				AnimatorControllerParameter[] parameters = morph.parameters.Where((AnimatorControllerParameter p) => (int)p.type == 1).ToArray();
				motionX = MorphParameter(parameters, (Form == 1) ? "VelocityX" : "moveX");
				motionZ = MorphParameter(parameters, (Form == 1) ? "VelocityZ" : "moveZ");
				motionSpeed = MorphParameter(parameters, "movementSpeed");
			}

			private void PrepareMorphSounds()
			{
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Expected O, but got Unknown
				morphController = new AnimatorOverrideController(morph.runtimeAnimatorController);
				List<KeyValuePair<AnimationClip, AnimationClip>> list = new List<KeyValuePair<AnimationClip, AnimationClip>>(morphController.overridesCount);
				morphController.GetOverrides(list);
				for (int i = 0; i < list.Count; i++)
				{
					KeyValuePair<AnimationClip, AnimationClip> keyValuePair = list[i];
					AnimationClip val = (Object.op_Implicit((Object)(object)keyValuePair.Value) ? keyValuePair.Value : keyValuePair.Key);
					AnimationEvent[] events = val.events;
					if (events.Length != 0)
					{
						AnimationEvent[] array = events.Where((AnimationEvent e) => MorphAudioEvents.Contains(e.functionName)).ToArray();
						if (array.Length != events.Length)
						{
							val = Object.Instantiate<AnimationClip>(val);
							val.events = array;
							clonedMorphClips.Add(val);
							list[i] = new KeyValuePair<AnimationClip, AnimationClip>(keyValuePair.Key, val);
						}
						if (array.Length != 0)
						{
							morphSoundClips.Add(val);
						}
					}
				}
				if (morphSoundClips.Count != 0)
				{
					morphController.ApplyOverrides((IList<KeyValuePair<AnimationClip, AnimationClip>>)list);
					morph.runtimeAnimatorController = (RuntimeAnimatorController)(object)morphController;
					morph.fireEvents = true;
				}
			}

			private void HideHumanModel()
			{
				SkinnedMeshRenderer[] array = (SkinnedMeshRenderer[])(object)new SkinnedMeshRenderer[4] { Player.thisPlayerModel, Player.thisPlayerModelLOD1, Player.thisPlayerModelLOD2, Player.thisPlayerModelArms };
				foreach (SkinnedMeshRenderer renderer in array)
				{
					HideMorphRenderer((Renderer)(object)renderer);
				}
				MonoBehaviour[] componentsInChildren = ((Component)Player).GetComponentsInChildren<MonoBehaviour>(true);
				foreach (MonoBehaviour val in componentsInChildren)
				{
					if (Object.op_Implicit((Object)(object)val) && ((object)val).GetType().Name == "CosmeticInstance")
					{
						Renderer[] componentsInChildren2 = ((Component)val).GetComponentsInChildren<Renderer>(true);
						foreach (Renderer renderer2 in componentsInChildren2)
						{
							HideMorphRenderer(renderer2);
						}
					}
				}
			}

			private void HideMorphRenderer(Renderer renderer)
			{
				if (Object.op_Implicit((Object)(object)renderer) && !morphHidden.ContainsKey(renderer))
				{
					morphHidden.Add(renderer, renderer.forceRenderingOff);
					renderer.forceRenderingOff = true;
				}
			}

			internal void RenderMorph()
			{
				//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_00b7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00be: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d7: 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_00da: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ea: 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_010c: Unknown result type (might be due to invalid IL or missing references)
				//IL_010f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0125: Unknown result type (might be due to invalid IL or missing references)
				//IL_011d: Unknown result type (might be due to invalid IL or missing references)
				//IL_011e: Unknown result type (might be due to invalid IL or missing references)
				//IL_012d: 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)
				if (Player.isPlayerDead || !Object.op_Implicit((Object)(object)visual) || !Object.op_Implicit((Object)(object)morph))
				{
					return;
				}
				if (Object.op_Implicit((Object)(object)Player.usernameAlpha))
				{
					Player.usernameAlpha.alpha = 0f;
				}
				if (Object.op_Implicit((Object)(object)Player.currentlyHeldObjectServer))
				{
					Renderer[] componentsInChildren = ((Component)Player.currentlyHeldObjectServer).GetComponentsInChildren<Renderer>(true);
					foreach (Renderer renderer in componentsInChildren)
					{
						HideMorphRenderer(renderer);
					}
				}
				float num = Mathf.Max(0.001f, Time.deltaTime);
				Vector3 position = visual.transform.position;
				Vector3 val = Vector3.ClampMagnitude(Vector3.ProjectOnPlane(position - previousMorphPosition, Vector3.up), 1f);
				previousMorphPosition = position;
				Vector3 val2 = visual.transform.InverseTransformDirection(val / (num * ((Form == 1) ? 2f : 5f)));
				morphMotion = Vector3.Lerp(morphMotion, (Form == 1) ? val2 : (-val2), num * 10f);
				float num2 = ((Form == 1) ? 1f : 2f);
				if (motionX != 0)
				{
					morph.SetFloat(motionX, Mathf.Clamp(morphMotion.x, 0f - num2, num2));
				}
				if (motionZ != 0)
				{
					morph.SetFloat(motionZ, Mathf.Clamp(morphMotion.z, 0f - num2, num2));
				}
				if (motionSpeed != 0)
				{
					morph.SetFloat(motionSpeed, Mathf.Clamp(((Vector3)(ref val2)).magnitude, 0f, num2));
				}
				PlayMorphMovementAudio();
				if (((NetworkBehaviour)Player).IsOwner)
				{
					MoveMorphCamera();
				}
			}

			private void PlayMorphMovementAudio()
			{
				if (!Object.op_Implicit((Object)(object)morphSoundSource) || morphSounds == null || morphSounds.Length == 0 || ((Vector3)(ref morphMotion)).sqrMagnitude < 0.06f || Time.unscaledTime < nextMorphSound)
				{
					return;
				}
				currentMorphClips.Clear();
				morph.GetCurrentAnimatorClipInfo(0, currentMorphClips);
				if (!currentMorphClips.Any((AnimatorClipInfo info) => ((AnimatorClipInfo)(ref info)).weight > 0.1f && morphSoundClips.Contains(((AnimatorClipInfo)(ref info)).clip)))
				{
					nextMorphSound = Time.unscaledTime + ((Form == 1) ? 1.35f : 0.39f);
					AudioClip val = morphSounds[Random.Range(0, morphSounds.Length)];
					if (Object.op_Implicit((Object)(object)val))
					{
						morphSoundSource.PlayOneShot(val);
					}
				}
			}

			private static int MorphParameter(AnimatorControllerParameter[] parameters, string name)
			{
				AnimatorControllerParameter? obj = ((IEnumerable<AnimatorControllerParameter>)parameters).FirstOrDefault((Func<AnimatorControllerParameter, bool>)((AnimatorControllerParameter parameter) => parameter.name == name));
				if (obj == null)
				{
					return 0;
				}
				return obj.nameHash;
			}

			private void MoveMorphCamera()
			{
				//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_0060: Unknown result type (might be due to invalid IL or missing references)
				//IL_0065: Unknown result type (might be due to invalid IL or missing references)
				//IL_007f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0084: Unknown result type (might be due to invalid IL or missing references)
				//IL_0089: Unknown result type (might be due to invalid IL or missing references)
				//IL_008a: 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_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_00a4: 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_00af: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00be: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00df: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e4: 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_00f5: 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_013a: 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_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_014c: 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_015a: 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_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_0166: Unknown result type (might be due to invalid IL or missing references)
				//IL_016b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0170: Unknown result type (might be due to invalid IL or missing references)
				//IL_0172: Unknown result type (might be due to invalid IL or missing references)
				//IL_0177: Unknown result type (might be due to invalid IL or missing references)
				Camera gameplayCamera = Player.gameplayCamera;
				if (Object.op_Implicit((Object)(object)gameplayCamera) && ((Behaviour)gameplayCamera).isActiveAndEnabled && Object.op_Implicit((Object)(object)plugin.round) && !((Object)(object)plugin.round.activeCamera != (Object)(object)gameplayCamera))
				{
					Transform transform = ((Component)gameplayCamera).transform;
					Vector3 forward = transform.forward;
					Vector3 val = visual.transform.position + Vector3.up * ((Form == 1) ? 0.78f : 0.53f);
					Vector3 val2 = -forward * 2.45f + Vector3.up * 0.55f + transform.right * 0.24f;
					val2.y = Mathf.Max(0.34f, val2.y);
					Vector3 normalized = ((Vector3)(ref val2)).normalized;
					float num = ((Vector3)(ref val2)).magnitude;
					RaycastHit val3 = default(RaycastHit);
					if (Physics.SphereCast(val, 0.12f, normalized, ref val3, num, plugin.round.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
					{
						num = Mathf.Max(0.09f, ((RaycastHit)(ref val3)).distance - 0.06f);
					}
					movedCamera = gameplayCamera;
					cameraPosition = transform.localPosition;
					cameraRotation = transform.localRotation;
					Vector3 val4 = val + normalized * num;
					transform.SetPositionAndRotation(val4, Quaternion.LookRotation(val + forward * 0.36f - val4));
				}
			}

			internal void RestoreMorphCamera()
			{
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				if (Object.op_Implicit((Object)(object)movedCamera))
				{
					((Component)movedCamera).transform.SetLocalPositionAndRotation(cameraPosition, cameraRotation);
				}
				movedCamera = null;
			}

			private void KeepMorphMuted()
			{
				if (((NetworkBehaviour)Player).IsOwner)
				{
					DissonanceComms val = (Object.op_Implicit((Object)(object)plugin.round) ? plugin.round.voiceChatModule : null);
					if (Object.op_Implicit((Object)(object)val) && (Object)(object)val != (Object)(object)voice)
					{
						DissonanceComms val2 = voice;
						voice = null;
						if (Object.op_Implicit((Object)(object)val2))
						{
							val2.IsMuted = priorMute;
						}
						voice = val;
						priorMute = voice.IsMuted;
					}
					if (Object.op_Implicit((Object)(object)voice))
					{
						voice.IsMuted = true;
					}
					HUDManager instance = HUDManager.Instance;
					if (Player.isTypingChat && Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)instance.chatTextField))
					{
						instance.chatTextField.text = string.Empty;
						instance.chatTextField.DeactivateInputField(false);
						Player.isTypingChat = false;
					}
				}
				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 bool MutesVoice(DissonanceComms comms)
			{
				if (muteMorphVoice)
				{
					return (Object)(object)voice == (Object)(object)comms;
				}
				return false;
			}

			private void RestoreMorph()
			{
				RestoreMorphCamera();
				muteMorphVoice = false;
				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)Player) && Object.op_Implicit((Object)(object)Player.usernameAlpha) && previousNameAlpha.HasValue)
				{
					Player.usernameAlpha.alpha = previousNameAlpha.Value;
				}
				if (Object.op_Implicit((Object)(object)visual))
				{
					visual.SetActive(false);
				}
				foreach (KeyValuePair<Renderer, bool> item in morphHidden)
				{
					if (Object.op_Implicit((Object)(object)item.Key))
					{
						item.Key.forceRenderingOff = item.Value;
					}
				}
				if (Object.op_Implicit((Object)(object)morphController))
				{
					Object.Destroy((Object)(object)morphController);
				}
				foreach (AnimationClip clonedMorphClip in clonedMorphClips)
				{
					if (Object.op_Implicit((Object)(object)clonedMorphClip))
					{
						Object.Destroy((Object)(object)clonedMorphClip);
					}
				}
			}

			internal EffectState(CompanyItemsPlugin plugin, PlayerControllerB player, Gear kind, int form, float duration)
			{
				//IL_006f: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00be: Unknown result type (might be due to invalid IL or missing references)
				//IL_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)
				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 = ((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_01a5: 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_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:
					ApplyMorph();
					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_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_0170: 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)
				{
					KeepMorphMuted();
				}
				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 movement = Player.playerActions.Movement;
						if (((MovementActions)(ref movement)).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 movement = Player.playerActions.Movement;
				Vector3 val = Vector3.zero;
				if (((MovementActions)(ref movement)).Jump.IsPressed())
				{
					Vector2 val2 = Vector2.ClampMagnitude(((MovementActions)(ref movement)).Move.ReadValue<Vector2>(), 1f);
					Vector3 val3 = Vector3.ProjectOnPlane(((Component)Player.gameplayCamera).transform.forward, Vector3.up);
					Vector3 normalized = ((Vector3)(ref val3)).normalized;
					val = Vector3.up * 114f + (normalized * val2.y + ((Component)Player.gameplayCamera).transform.right * val2.x) * 178f;
				}
				Thrust = Vector3.MoveTowards(Thrust, val, ((val == 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;
					}
				}
			}

			internal void Restore()
			{
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				if (Kind == Gear.Slime)
				{
					RestoreMorph();
				}
				if (Object.op_Implicit((Object)(object)visual))
				{
					Object.Destroy((Object)(object)visual);
				}
				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);
					}
				}
			}
		}

		[HarmonyPatch]
		private static class MutagenControls
		{
			[HarmonyPatch]
			private static class HumanControls
			{
				private static IEnumerable<MethodBase> TargetMethods()
				{
					string[] array = new string[9] { "Crouch_performed", "Interact_performed", "ClickHoldInteraction", "Discard_performed", "InspectItem_performed", "ScrollMouse_performed", "UseUtilitySlot_performed", "CanUseItem", "CheckConditionsForEmote" };
					foreach (string text in array)
					{
						yield return AccessTools.DeclaredMethod(typeof(PlayerControllerB), text, (Type[])null, (Type[])null);
					}
				}

				private static bool Prefix(PlayerControllerB __instance)
				{
					return !IsMorphPlayer(__instance);
				}
			}

			[HarmonyPatch]
			private static class HeldItemSecondary
			{
				private static IEnumerable<MethodBase> TargetMethods()
				{
					yield return AccessTools.DeclaredMethod(typeof(GrabbableObject), "ItemInteractLeftRightOnClient", (Type[])null, (Type[])null);
					yield return AccessTools.DeclaredMethod(typeof(GrabbableObject), "InteractLeftRightServerRpc", (Type[])null, (Type[])null);
				}

				private static bool Prefix(GrabbableObject __instance)
				{
					return !IsMorphPlayer(__instance.playerHeldBy);
				}
			}

			[HarmonyPatch]
			private static class LocalChat
			{
				private static IEnumerable<MethodBase> TargetMethods()
				{
					yield return AccessTools.DeclaredMethod(typeof(HUDManager), "EnableChat_performed", (Type[])null, (Type[])null);
					yield return AccessTools.DeclaredMethod(typeof(HUDManager), "SubmitChat_performed", (Type[])null, (Type[])null);
				}

				private static bool Prefix()
				{
					return !IsMorphPlayer(LocalPlayer);
				}
			}

			[HarmonyPatch(typeof(PlayerControllerB), "Update")]
			[HarmonyPrefix]
			[HarmonyPriority(0)]
			private static void ApplyMorphPace(PlayerControllerB __instance, ref bool ___inputHoldingSprint, ref float ___sprintMultiplier, out float? __state)
			{
				__state = null;
				if (((NetworkBehaviour)__instance).IsOwner && IsMorphPlayer(__instance))
				{
					EffectState effectState = instance.gearEffects[__instance.actualClientId];
					effectState.RestoreMorphCamera();
					__state = __instance.movementSpeed;
					__instance.movementSpeed = effectState.MorphWalkSpeed;
					___inputHoldingSprint = false;
					___sprintMultiplier = 1f;
				}
			}

			[HarmonyPatch(typeof(PlayerControllerB), "Update")]
			[HarmonyFinalizer]
			private static void RestorePace(PlayerControllerB __instance, float? __state)
			{
				if (__state.HasValue)
				{
					__instance.movementSpeed = __state.Value;
				}
			}

			[HarmonyPatch(typeof(PlayerControllerB), "LateUpdate")]
			[HarmonyPostfix]
			[HarmonyPriority(0)]
			private static void RenderMorphLate(PlayerControllerB __instance)
			{
				if (IsMorphPlayer(__instance))
				{
					instance.gearEffects[__instance.actualClientId].RenderMorph();
				}
			}

			[HarmonyPatch(typeof(GrabbableObject), "UseItemOnClient")]
			[HarmonyPrefix]
			private static bool BlockHeldItem(GrabbableObject __instance, bool __0)
			{
				if (__0)
				{
					return !IsMorphPlayer(__instance.playerHeldBy);
				}
				return true;
			}

			[HarmonyPatch(typeof(HUDManager), "AddPlayerChatMessageServerRpc")]
			[HarmonyPrefix]
			private static bool BlockChatBroadcast(HUDManager __instance, int __1)
			{
				if (((NetworkBehaviour)__instance).IsServer)
				{
					return !IsMorphSlot(__1);
				}
				return true;
			}

			[HarmonyPatch(/*Could not decode attribute arguments.*/)]
			[HarmonyPrefix]
			private static void KeepVoiceMuted(DissonanceComms __instance, ref bool __0)
			{
				PlayerControllerB localPlayer = LocalPlayer;
				if (IsMorphPlayer(localPlayer) && instance.gearEffects[localPlayer.actualClientId].MutesVoice(__instance))
				{
					__0 = true;
				}
			}

			[HarmonyPatch(typeof(WalkieTalkie), "SetPlayerSpeakingOnWalkieTalkieServerRpc")]
			[HarmonyPrefix]
			private static bool BlockRadioTransmit(WalkieTalkie __instance, int __0)
			{
				if (((NetworkBehaviour)__instance).IsServer)
				{
					return !IsMorphSlot(__0);
				}
				return true;
			}

			[HarmonyPatch(typeof(WalkieTalkie), "SwitchWalkieTalkieOn")]
			[HarmonyPrefix]
			private static bool BlockRadioPower(WalkieTalkie __instance, bool __0)
			{
				if (__0)
				{
					return !IsMorphPlayer(((GrabbableObject)__instance).playerHeldBy);
				}
				return true;
			}

			[HarmonyPatch(typeof(WalkieTalkie), "Update")]
			[HarmonyPostfix]
			private static void StopPoweredRadio(WalkieTalkie __instance)
			{
				if (IsMorphPlayer(((GrabbableObject)__instance).playerHeldBy))
				{
					StopMorphRadio(__instance, ((GrabbableObject)__instance).playerHeldBy);
				}
			}

			[HarmonyPatch(typeof(PlayerControllerB), "PlayerIsHearingOthersThroughWalkieTalkie")]
			[HarmonyPrefix]
			private static bool BlockRadioListening(PlayerControllerB __instance, ref bool __result)
			{
				if (!IsMorphPlayer(__instance))
				{
					return true;
				}
				__result = false;
				return false;
			}

			private static bool IsMorphSlot(int slot)
			{
				StartOfRound instance = StartOfRound.Instance;
				PlayerControllerB[] array = (Object.op_Implicit((Object)(object)instance) ? instance.allPlayerScripts : null);
				if (array != null && slot >= 0 && slot < array.Length)
				{
					return IsMorphPlayer(array[slot]);
				}
				return 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))
				{
					return !IsMorphPlayer(__instance);
				}
				return false;
			}

			[HarmonyPatch(typeof(PlayerControllerB), "ShowNameBillboard")]
			[HarmonyPrefix]
			private static bool HideMorphName(PlayerControllerB __instance)
			{
				return !IsMorphPlayer(__instance);
			}

			[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)
			{
				if (!IsPowerPlayer(__instance))
				{
					return !IsMorphPlayer(__instance);
				}
				return false;
			}

			[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(RoundManager), "LoadNewLevel")]
		private static class ResetBonusScrapRoll
		{
			private static void Prefix()
			{
				if (Object.op_Implicit((Object)(object)instance))
				{
					instance.bonusScrapRolled = false;
				}
			}
		}

		[HarmonyPatch(typeof(RoundManager), "waitForScrapToSpawnToSync")]
		private static class AddBonusScrapToRound
		{
			private static void Prefix(RoundManager __instance, ref NetworkObjectReference[] __0, ref int[] __1)
			{
				if (!Object.op_Implicit((Object)(object)instance))
				{
					return;
				}
				try
				{
					instance.AddBonusScrap(__instance, ref __0, ref __1);
				}
				catch (Exception ex)
				{
					((BaseUnityPlugin)instance).Logger.LogWarning((object)("Could not spawn bonus scrap: " + ex.GetBaseException().Message));
				}
			}
		}

		[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();
					}
				}
			}
		}

		[HarmonyPatch(typeof(Terminal), "Awake")]
		private static class KeepWandCatalogPosition
		{
			private static void Postfix()
			{
				instance?.RestoreWandCatalogPosition(StartOfRound.Instance);
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "LoadShipGrabbableItems")]
		private static class LoadLegacyWandValues
		{
			private static void Prefix(StartOfRound __instance)
			{
				if (!Object.op_Implicit((Object)(object)instance) || !((NetworkBehaviour)__instance).IsServer || !Object.op_Implicit((Object)(object)GameNetworkManager.Instance))
				{
					return;
				}
				try
				{
					instance.MigrateWandValues(__instance, GameNetworkManager.Instance.currentSaveFileName);
				}
				catch (Exception ex)
				{
					((BaseUnityPlugin)instance).Logger.LogWarning((object)("Could not migrate saved wand values: " + ex.Message));
				}
			}
		}

		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.6";

		internal const string WandPrefab = "SaltanisFireballWand";

		private static CompanyItemsPlugin instance;

		private Harmony harmony;

		private Item wand;

		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 ConfigEntry<int> naturalWeightPercent;

		private ConfigEntry<bool> bonusScrapEnabled;

		private ConfigEntry<int> bonusScrapChance;

		private bool bonusScrapRolled;

		private readonly List<Item> worldScrap = new List<Item>();

		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 int formerShopIndex;

		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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Expected O, but got Unknown
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Expected O, but got Unknown
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Expected O, but got Unknown
			instance = this;
			BindScrapSpawning();
			bool num = HasOldConfig();
			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_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