Decompiled source of GungnirStaff v1.0.3

plugins/GungnirStaff.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("assembly_guiutils")]
[assembly: IgnoresAccessChecksTo("assembly_utils")]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyCompany("GungnirStaff")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A Valheim mod adding the Gungnir staff.")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3+c18dabb3f7b8e7e9e872b65c165901ce1df9c815")]
[assembly: AssemblyProduct("Gungnir Staff")]
[assembly: AssemblyTitle("GungnirStaff")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.0")]
[module: UnverifiableCode]
[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 GungnirStaff
{
	internal static class Alive
	{
		internal static bool InGame
		{
			get
			{
				if (!((Object)(object)Console.m_instance != (Object)null))
				{
					return (Object)(object)Player.m_localPlayer != (Object)null;
				}
				return true;
			}
		}

		internal static string StatusLine(Harmony harmony)
		{
			int num = ((harmony != null) ? harmony.GetPatchedMethods().Count() : 0);
			return "Gungnir Staff v1.0.3 | Release build 2026-08-30 22:20:13 | loaded from " + LoadedFrom() + " | " + $"{num} patched method(s)";
		}

		private static string LoadedFrom()
		{
			try
			{
				string location = Assembly.GetExecutingAssembly().Location;
				if (string.IsNullOrEmpty(location))
				{
					return "scripts (hot reload, in memory)";
				}
				string fileName = Path.GetFileName(Path.GetDirectoryName(location));
				return string.IsNullOrEmpty(fileName) ? location : fileName;
			}
			catch (Exception)
			{
				return "unknown";
			}
		}

		internal static void Announce(string reason, Harmony harmony)
		{
			string text = "[" + reason + "] " + StatusLine(harmony);
			GungnirStaffPlugin.Log.LogMessage((object)text);
			ToGameConsole(text);
			ToHud(text);
		}

		internal static void ToGameConsole(string text)
		{
			Console instance = Console.m_instance;
			if (instance != null)
			{
				instance.Print(text);
			}
		}

		internal static void ToHud(string text)
		{
			MessageHud instance = MessageHud.m_instance;
			if (instance != null)
			{
				instance.ShowMessage((MessageType)2, text, 0, (Sprite)null, false);
			}
		}
	}
	internal static class BladeGlow
	{
		private const string ObjectName = "GungnirBladeGlow";

		private static ParticleSystem _system;

		private static ParticleSystem _smoke;

		private static Transform _builtFor;

		private static int _rebuilds;

		private static Material _material;

		private static Color _applied = Color.clear;

		private static bool _sweepPending;

		private static int _lastRebuildFrame = -10;

		private static int _consecutiveRebuilds;

		private static bool _loggedAnchor;

		private static Material _smokeMaterial;

		private static bool _smokeSearched;

		private static GameObject _mounted;

		internal static void Apply(GameObject weapon, Transform visual, bool staffStance)
		{
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: 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_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: 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_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			bool flag = ModConfig.WeaponEffect.Value switch
			{
				WeaponEffectMode.Always => true, 
				WeaponEffectMode.Never => false, 
				_ => !staffStance, 
			};
			if (ModConfig.BladeGlowStyle.Value == BladeGlowStyle.None)
			{
				flag = false;
			}
			Renderer val = (((Object)(object)visual != (Object)null) ? FindBlade(visual) : null);
			if (!flag || (Object)(object)val == (Object)null)
			{
				Clear();
				return;
			}
			if ((!((Object)(object)_mounted != (Object)null) && !((Object)(object)_system != (Object)null)) || _builtFor != ((Component)val).transform)
			{
				Clear();
				Build(val, weapon, visual);
				_builtFor = ((Component)val).transform;
				_sweepPending = true;
				if (Time.frameCount == _lastRebuildFrame + 1)
				{
					_consecutiveRebuilds++;
					if (_consecutiveRebuilds == 20)
					{
						GungnirStaffPlugin.Log.LogWarning((object)"Blade glow has rebuilt on 20 consecutive frames - something is tearing it down as fast as it is built.");
					}
				}
				else
				{
					_consecutiveRebuilds = 0;
				}
				_lastRebuildFrame = Time.frameCount;
			}
			NeutraliseScale(((Object)(object)_system != (Object)null) ? ((Component)_system).transform : null);
			NeutraliseScale(((Object)(object)_smoke != (Object)null) ? ((Component)_smoke).transform : null);
			if (!((Object)(object)_system == (Object)null))
			{
				Color val2 = ModConfig.ParseColour(ModConfig.BladeGlowColour.Value, new Color(0.5f, 0.78f, 1f));
				if (_applied != val2)
				{
					_applied = val2;
					Tint(val2);
				}
			}
		}

		internal static void PurgeStrays(Player player)
		{
			if ((Object)(object)player == (Object)null || !_sweepPending)
			{
				return;
			}
			_sweepPending = false;
			GameObject[] array = (GameObject[])(object)new GameObject[1] { ((Component)player).gameObject };
			foreach (GameObject val in array)
			{
				ParticleSystem[] componentsInChildren = val.GetComponentsInChildren<ParticleSystem>(true);
				foreach (ParticleSystem val2 in componentsInChildren)
				{
					if (!((Object)(object)val2 == (Object)null) && val2 != _system && val2 != _smoke && ((Object)((Component)val2).gameObject).name.StartsWith("GungnirBladeGlow", StringComparison.Ordinal))
					{
						Object.DestroyImmediate((Object)(object)((Component)val2).gameObject);
					}
				}
			}
		}

		internal static void Clear()
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_system != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)((Component)_system).gameObject);
			}
			if ((Object)(object)_smoke != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)((Component)_smoke).gameObject);
			}
			_smoke = null;
			if ((Object)(object)_mounted != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)_mounted);
			}
			_mounted = null;
			_system = null;
			_builtFor = null;
			_material = null;
			_applied = Color.clear;
		}

		private static void Build(Renderer blade, GameObject weapon, Transform visual)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!TryMountVanillaEffect(blade))
				{
					_material = BorrowParticleMaterial(weapon);
					GameObject val = new GameObject("GungnirBladeGlow");
					val.transform.SetParent(visual, false);
					val.transform.localPosition = EmitterAnchor(blade, visual);
					val.transform.localRotation = Quaternion.Euler(-90f, 0f, 0f);
					_system = val.AddComponent<ParticleSystem>();
					ParticleSystemRenderer component = val.GetComponent<ParticleSystemRenderer>();
					component.renderMode = (ParticleSystemRenderMode)0;
					component.alignment = (ParticleSystemRenderSpace)0;
					((Renderer)component).material = _material;
					((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
					((Renderer)component).receiveShadows = false;
					if (ModConfig.BladeGlowStyle.Value == BladeGlowStyle.Lightning)
					{
						ConfigureLightning(_system, component, visual);
						BuildOrbit(blade, visual);
					}
					else
					{
						Configure(_system);
					}
					ModConfig.Trace($"Blade glow created ({ModConfig.BladeGlowStyle.Value}).");
				}
			}
			catch (Exception arg)
			{
				GungnirStaffPlugin.Log.LogError((object)$"Could not build the blade glow: {arg}");
				Clear();
			}
		}

		private static void Configure(ParticleSystem ps)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: 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_010d: 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_011e: Expected O, but got Unknown
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: 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_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Expected O, but got Unknown
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			ps.Stop();
			float value = ModConfig.BladeGlowScale.Value;
			MainModule main = ps.main;
			((MainModule)(ref main)).loop = true;
			((MainModule)(ref main)).scalingMode = (ParticleSystemScalingMode)2;
			((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.35f, 0.8f);
			((MainModule)(ref main)).startSpeed = new MinMaxCurve(0.02f, 0.12f);
			((MainModule)(ref main)).startSize = new MinMaxCurve(0.03f * value, 0.07f * value);
			((MainModule)(ref main)).maxParticles = 40;
			((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(-0.01f);
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)0;
			EmissionModule emission = ps.emission;
			((EmissionModule)(ref emission)).enabled = true;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(18f * ModConfig.BladeGlowRate.Value);
			ShapeModule shape = ps.shape;
			((ShapeModule)(ref shape)).enabled = true;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
			((ShapeModule)(ref shape)).radius = 0.05f * value;
			((ShapeModule)(ref shape)).scale = new Vector3(0.5f, 2.4f, 0.5f);
			((ShapeModule)(ref shape)).radiusThickness = 0.7f;
			ColorOverLifetimeModule colorOverLifetime = ps.colorOverLifetime;
			((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
			Gradient val = new Gradient();
			val.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
			{
				new GradientColorKey(Color.white, 0f),
				new GradientColorKey(Color.white, 1f)
			}, (GradientAlphaKey[])(object)new GradientAlphaKey[3]
			{
				new GradientAlphaKey(0f, 0f),
				new GradientAlphaKey(1f, 0.3f),
				new GradientAlphaKey(0f, 1f)
			});
			((ColorOverLifetimeModule)(ref colorOverLifetime)).color = new MinMaxGradient(val);
			SizeOverLifetimeModule sizeOverLifetime = ps.sizeOverLifetime;
			((SizeOverLifetimeModule)(ref sizeOverLifetime)).enabled = true;
			((SizeOverLifetimeModule)(ref sizeOverLifetime)).size = new MinMaxCurve(1f, new AnimationCurve((Keyframe[])(object)new Keyframe[3]
			{
				new Keyframe(0f, 0.3f),
				new Keyframe(0.4f, 1f),
				new Keyframe(1f, 0f)
			}));
			ps.Play();
		}

		private static void ConfigureLightning(ParticleSystem ps, ParticleSystemRenderer renderer, Transform visual)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_0081: 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_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_00ce: 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_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: 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_011d: 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_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Expected O, but got Unknown
			//IL_0175: 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_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: 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_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Expected O, but got Unknown
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			ps.Stop();
			float value = ModConfig.BladeGlowScale.Value;
			renderer.renderMode = (ParticleSystemRenderMode)1;
			renderer.velocityScale = 0.12f;
			renderer.lengthScale = 3.5f;
			MainModule main = ps.main;
			((MainModule)(ref main)).loop = true;
			((MainModule)(ref main)).scalingMode = (ParticleSystemScalingMode)2;
			((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.28f, 0.6f);
			((MainModule)(ref main)).startSpeed = new MinMaxCurve(0.45f, 1.2f);
			((MainModule)(ref main)).startSize = new MinMaxCurve(0.03f * value, 0.07f * value);
			((MainModule)(ref main)).maxParticles = 45;
			((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(0f);
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)0;
			EmissionModule emission = ps.emission;
			((EmissionModule)(ref emission)).enabled = true;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(4.5f * ModConfig.BladeGlowRate.Value);
			((EmissionModule)(ref emission)).SetBursts((Burst[])(object)new Burst[2]
			{
				new Burst(0f, (short)2, (short)4, 0, 0.26f),
				new Burst(0.13f, (short)1, (short)3, 0, 0.42f)
			});
			ShapeModule shape = ps.shape;
			((ShapeModule)(ref shape)).enabled = true;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)4;
			((ShapeModule)(ref shape)).angle = 34f;
			((ShapeModule)(ref shape)).radius = 0.05f * value;
			((ShapeModule)(ref shape)).radiusThickness = 1f;
			ColorOverLifetimeModule colorOverLifetime = ps.colorOverLifetime;
			((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
			Gradient val = new Gradient();
			val.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
			{
				new GradientColorKey(Color.white, 0f),
				new GradientColorKey(Color.white, 1f)
			}, (GradientAlphaKey[])(object)new GradientAlphaKey[3]
			{
				new GradientAlphaKey(1f, 0f),
				new GradientAlphaKey(1f, 0.55f),
				new GradientAlphaKey(0f, 1f)
			});
			((ColorOverLifetimeModule)(ref colorOverLifetime)).color = new MinMaxGradient(val);
			SizeOverLifetimeModule sizeOverLifetime = ps.sizeOverLifetime;
			((SizeOverLifetimeModule)(ref sizeOverLifetime)).enabled = true;
			((SizeOverLifetimeModule)(ref sizeOverLifetime)).size = new MinMaxCurve(1f, new AnimationCurve((Keyframe[])(object)new Keyframe[2]
			{
				new Keyframe(0f, 1f),
				new Keyframe(1f, 0.2f)
			}));
			RotationOverLifetimeModule rotationOverLifetime = ps.rotationOverLifetime;
			((RotationOverLifetimeModule)(ref rotationOverLifetime)).enabled = true;
			((RotationOverLifetimeModule)(ref rotationOverLifetime)).z = new MinMaxCurve(-180f, 180f);
			ps.Play();
		}

		private static void BuildOrbit(Renderer blade, Transform visual)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: 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_00ca: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: 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_0166: 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_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Expected O, but got Unknown
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Expected O, but got Unknown
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			float value = ModConfig.BladeGlowScale.Value;
			GameObject val = new GameObject("GungnirBladeGlowOrbit");
			val.transform.SetParent(visual, false);
			val.transform.localPosition = EmitterAnchor(blade, visual);
			_smoke = val.AddComponent<ParticleSystem>();
			ParticleSystemRenderer component = val.GetComponent<ParticleSystemRenderer>();
			component.renderMode = (ParticleSystemRenderMode)0;
			component.alignment = (ParticleSystemRenderSpace)0;
			((Renderer)component).material = _material;
			((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)component).receiveShadows = false;
			_smoke.Stop();
			MainModule main = _smoke.main;
			((MainModule)(ref main)).loop = true;
			((MainModule)(ref main)).scalingMode = (ParticleSystemScalingMode)2;
			((MainModule)(ref main)).startLifetime = new MinMaxCurve(1.4f, 2.8f);
			((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(0f);
			((MainModule)(ref main)).startSize = new MinMaxCurve(0.012f * value, 0.026f * value);
			((MainModule)(ref main)).maxParticles = 40;
			((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(0f);
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)0;
			EmissionModule emission = _smoke.emission;
			((EmissionModule)(ref emission)).enabled = true;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(10f * ModConfig.BladeGlowRate.Value);
			ShapeModule shape = _smoke.shape;
			((ShapeModule)(ref shape)).enabled = true;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
			((ShapeModule)(ref shape)).radius = 0.1f * value;
			((ShapeModule)(ref shape)).radiusThickness = 0.4f;
			VelocityOverLifetimeModule velocityOverLifetime = _smoke.velocityOverLifetime;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).enabled = true;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).space = (ParticleSystemSimulationSpace)0;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).orbitalX = new MinMaxCurve(-0.9f, 0.9f);
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).orbitalY = new MinMaxCurve(-0.9f, 0.9f);
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).orbitalZ = new MinMaxCurve(-0.9f, 0.9f);
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).radial = new MinMaxCurve(-0.01f, 0.01f);
			ColorOverLifetimeModule colorOverLifetime = _smoke.colorOverLifetime;
			((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
			Gradient val2 = new Gradient();
			val2.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
			{
				new GradientColorKey(Color.white, 0f),
				new GradientColorKey(Color.white, 1f)
			}, (GradientAlphaKey[])(object)new GradientAlphaKey[4]
			{
				new GradientAlphaKey(0f, 0f),
				new GradientAlphaKey(1f, 0.25f),
				new GradientAlphaKey(0.8f, 0.6f),
				new GradientAlphaKey(0f, 1f)
			});
			((ColorOverLifetimeModule)(ref colorOverLifetime)).color = new MinMaxGradient(val2);
			SizeOverLifetimeModule sizeOverLifetime = _smoke.sizeOverLifetime;
			((SizeOverLifetimeModule)(ref sizeOverLifetime)).enabled = true;
			((SizeOverLifetimeModule)(ref sizeOverLifetime)).size = new MinMaxCurve(1f, new AnimationCurve((Keyframe[])(object)new Keyframe[3]
			{
				new Keyframe(0f, 0.3f),
				new Keyframe(0.35f, 1f),
				new Keyframe(1f, 0.2f)
			}));
			_smoke.Play();
		}

		private static Vector3 EmitterAnchor(Renderer blade, Transform visual)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			Bounds bounds = blade.bounds;
			Vector3 val = visual.InverseTransformPoint(((Bounds)(ref bounds)).center);
			Vector3 up = Vector3.up;
			return val + up * ModConfig.BladeGlowOffset.Value;
		}

		private static Material BorrowSmokeMaterial()
		{
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Expected O, but got Unknown
			if ((Object)(object)_smokeMaterial != (Object)null || _smokeSearched)
			{
				return _smokeMaterial;
			}
			_smokeSearched = true;
			string[] array = new string[5] { "SmokeParticleSystem", "RisingSmoke", "SmokeBlob", "SmokeBall", "vfx_Smoke" };
			foreach (string text in array)
			{
				GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab(text) : null);
				if ((Object)(object)val == (Object)null)
				{
					val = PrefabManager.Instance.GetPrefab(text);
				}
				Material val2 = (((Object)(object)val == (Object)null) ? null : (from r in val.GetComponentsInChildren<ParticleSystemRenderer>(true)
					select ((Renderer)r).sharedMaterial).FirstOrDefault((Func<Material, bool>)((Material m) => (Object)(object)m != (Object)null && (Object)(object)m.shader != (Object)null)));
				if ((Object)(object)val2 != (Object)null)
				{
					_smokeMaterial = new Material(val2);
					ModConfig.Trace("Smoke using material from '" + text + "'.");
					return _smokeMaterial;
				}
			}
			ModConfig.Trace("No vanilla smoke material found; falling back to the spark sprite.");
			return null;
		}

		private static void NeutraliseScale(Transform emitter)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: 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)
			if (!((Object)(object)emitter == (Object)null))
			{
				Vector3 val = (((Object)(object)emitter.parent != (Object)null) ? emitter.parent.lossyScale : Vector3.one);
				Vector3 val2 = default(Vector3);
				((Vector3)(ref val2))..ctor(Mathf.Approximately(val.x, 0f) ? 1f : (1f / val.x), Mathf.Approximately(val.y, 0f) ? 1f : (1f / val.y), Mathf.Approximately(val.z, 0f) ? 1f : (1f / val.z));
				if (emitter.localScale != val2)
				{
					emitter.localScale = val2;
				}
			}
		}

		private static void Tint(Color colour)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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_002c: 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)
			Color val = colour * ModConfig.BladeGlowBrightness.Value;
			val.a = 1f;
			MainModule main = _system.main;
			((MainModule)(ref main)).startColor = new MinMaxGradient(val, colour);
			if ((Object)(object)_material == (Object)null)
			{
				return;
			}
			string[] array = new string[4] { "_TintColor", "_Color", "_BaseColor", "_EmissionColor" };
			foreach (string text in array)
			{
				if (_material.HasProperty(text))
				{
					_material.SetColor(text, val);
				}
			}
		}

		private static bool TryMountVanillaEffect(Renderer blade)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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_0083: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
			string value = ModConfig.BladeGlowPrefab.Value;
			if (string.IsNullOrEmpty(value))
			{
				return false;
			}
			GameObject val = FindEffectPrefab(value);
			if ((Object)(object)val == (Object)null)
			{
				GungnirStaffPlugin.Log.LogWarning((object)("Effect prefab '" + value + "' not found; using the mod's own particles. Try one of the names listed in the setting's description."));
				return false;
			}
			GameObject val2 = Object.Instantiate<GameObject>(val, ((Component)blade).transform);
			((Object)val2).name = "GungnirBladeGlow";
			Transform transform = val2.transform;
			Transform transform2 = ((Component)blade).transform;
			Bounds bounds = blade.bounds;
			transform.localPosition = transform2.InverseTransformPoint(((Bounds)(ref bounds)).center);
			val2.transform.localRotation = Quaternion.identity;
			val2.transform.localScale = Vector3.one * ModConfig.BladeGlowScale.Value;
			ZNetView[] componentsInChildren = val2.GetComponentsInChildren<ZNetView>(true);
			foreach (ZNetView val3 in componentsInChildren)
			{
				Object.Destroy((Object)(object)val3);
			}
			TimedDestruction[] componentsInChildren2 = val2.GetComponentsInChildren<TimedDestruction>(true);
			foreach (TimedDestruction val4 in componentsInChildren2)
			{
				Object.Destroy((Object)(object)val4);
			}
			AudioSource[] componentsInChildren3 = val2.GetComponentsInChildren<AudioSource>(true);
			foreach (AudioSource val5 in componentsInChildren3)
			{
				((Behaviour)val5).enabled = false;
			}
			_mounted = val2;
			ModConfig.Trace("Mounted vanilla effect '" + ((Object)val).name + "' on the blade.");
			return true;
		}

		private static GameObject FindEffectPrefab(string name)
		{
			ZNetScene instance = ZNetScene.instance;
			if ((Object)(object)instance != (Object)null)
			{
				GameObject prefab = instance.GetPrefab(name);
				if ((Object)(object)prefab != (Object)null)
				{
					return prefab;
				}
			}
			return PrefabManager.Instance.GetPrefab(name);
		}

		private static Renderer FindBlade(Transform visual)
		{
			return ((IEnumerable<Renderer>)((Component)visual).GetComponentsInChildren<Renderer>(true)).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)((Component)r).gameObject).name.StartsWith("Gungnir_Blade", StringComparison.OrdinalIgnoreCase)));
		}

		private static Material BorrowParticleMaterial(GameObject weapon)
		{
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Expected O, but got Unknown
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Expected O, but got Unknown
			Material val = (((Object)(object)weapon == (Object)null) ? null : (from r in weapon.GetComponentsInChildren<ParticleSystemRenderer>(true)
				select ((Renderer)r).sharedMaterial).FirstOrDefault((Func<Material, bool>)((Material m) => (Object)(object)m != (Object)null && (Object)(object)m.shader != (Object)null)));
			if ((Object)(object)val == (Object)null && (Object)(object)ObjectDB.instance != (Object)null)
			{
				val = (from r in ObjectDB.instance.m_items.Where((GameObject p) => (Object)(object)p != (Object)null).SelectMany((GameObject p) => p.GetComponentsInChildren<ParticleSystemRenderer>(true))
					select ((Renderer)r).sharedMaterial).FirstOrDefault((Func<Material, bool>)((Material m) => (Object)(object)m != (Object)null && (Object)(object)m.shader != (Object)null));
			}
			if ((Object)(object)val != (Object)null)
			{
				return new Material(val);
			}
			Shader val2 = Shader.Find("Particles/Standard Unlit") ?? Shader.Find("Sprites/Default");
			if (!((Object)(object)val2 != (Object)null))
			{
				return null;
			}
			return new Material(val2);
		}
	}
	internal sealed class GungnirCommand : ConsoleCommand
	{
		public override string Name => "gungnir";

		public override string Help => "gungnir status | empty | recover | staffs | holster | find | give [level]";

		public override bool IsCheat => false;

		public override List<string> CommandOptionList()
		{
			return new List<string> { "status", "empty", "recover", "staffs", "holster", "find", "give" };
		}

		public override void Run(string[] args)
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				Print("You need to be in a world first.");
				return;
			}
			switch ((args != null && args.Length != 0) ? args[0].ToLowerInvariant() : "status")
			{
			case "give":
				Give(localPlayer, (args.Length > 1) ? args[1] : null);
				break;
			case "staffs":
				ListStaffs();
				break;
			case "holster":
				Holster(localPlayer);
				break;
			case "find":
				Find((args.Length > 1) ? args[1] : string.Empty);
				break;
			case "empty":
				Empty(localPlayer);
				break;
			case "recover":
				Recover(localPlayer);
				break;
			default:
				Status(localPlayer);
				break;
			}
		}

		private static bool SpawningAllowed()
		{
			if (Environment.GetCommandLineArgs().Any((string a) => string.Equals(a, "-console", StringComparison.OrdinalIgnoreCase)))
			{
				return Terminal.m_cheat;
			}
			return false;
		}

		private static void Give(Player player, string levelArg)
		{
			if (!SpawningAllowed())
			{
				Print("Spawning Gungnir needs a dev session: launch with -console and enable devcommands. Craft it at the Galdr Table instead.");
				return;
			}
			int result = 1;
			if (!string.IsNullOrEmpty(levelArg) && (!int.TryParse(levelArg, out result) || result < 1 || result > 3))
			{
				Print($"Usage: gungnir give [1-{3}]  " + "(got '" + levelArg + "')");
				return;
			}
			if (!GungnirItem.Create())
			{
				Print("Could not create the Gungnir prefab - see the BepInEx log.");
				return;
			}
			ItemData val = ((Humanoid)player).m_inventory.AddItem("GungnirStaff", 1, result, 0, 0L, string.Empty, false);
			if (val == null)
			{
				Print("No room in your inventory.");
				return;
			}
			StaffContainer staffContainer = StaffContainer.For(val);
			if (staffContainer != null)
			{
				staffContainer.OwnQuality = result;
			}
			Print($"Added a Gungnir to your inventory (level {result}, " + $"{GungnirRecipe.SlotsForQuality(result)} rack slots).");
		}

		private static void ListStaffs()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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)
			List<GameObject> list = StaffRegistry.AllStaffPrefabs();
			Print($"Detected {list.Count} staff(s):");
			foreach (GameObject item in list)
			{
				SharedData shared = item.GetComponent<ItemDrop>().m_itemData.m_shared;
				Print($"  {((Object)item).name}  ({shared.m_skillType}, {shared.m_itemType}, " + $"held as {shared.m_animationState})");
			}
		}

		private static void Find(string text)
		{
			if (string.IsNullOrEmpty(text))
			{
				Print("Usage: gungnir find <part of a prefab name>");
				return;
			}
			List<string> list = (from p in ObjectDB.instance.m_items
				where (Object)(object)p != (Object)null && ((Object)p).name.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0
				select ((Object)p).name into n
				orderby n
				select n).ToList();
			Print($"{list.Count} item prefab(s) matching '{text}':");
			foreach (string item in list)
			{
				Print("  " + item);
			}
		}

		private static void Holster(Player player)
		{
			ItemData val = GungnirItem.Active(player);
			if (val == null)
			{
				Print("No Gungnir active.");
				return;
			}
			StaffSwitcher.Holster(player, val);
			Print("Holstered.");
		}

		private static void Empty(Player player)
		{
			ItemData val = GungnirItem.Active(player);
			if (val == null)
			{
				Print($"No Gungnir active (Activation = {ModConfig.Activation.Value}).");
				return;
			}
			StaffSwitcher.Holster(player, val);
			StaffContainer staffContainer = StaffContainer.For(val);
			int num = 0;
			int num2 = 0;
			for (int i = 0; i < staffContainer.Inventory.m_width; i++)
			{
				ItemData val2 = staffContainer.ItemAt(i);
				if (val2 == null)
				{
					continue;
				}
				if (!((Humanoid)player).m_inventory.HaveEmptySlot())
				{
					num2++;
					continue;
				}
				staffContainer.Inventory.RemoveItem(val2);
				if (((Humanoid)player).m_inventory.AddItem(val2))
				{
					num++;
					continue;
				}
				staffContainer.Inventory.AddItem(val2);
				num2++;
			}
			staffContainer.SaveToItem();
			Print($"Moved {num} staff(s) out of the rack into your inventory.");
			if (num2 > 0)
			{
				Print($"{num2} could not be moved - no room. Free some slots and run it again.");
			}
		}

		private static void Recover(Player player)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			int num2 = 0;
			ItemDrop[] array = Resources.FindObjectsOfTypeAll<ItemDrop>();
			foreach (ItemDrop val in array)
			{
				if ((Object)(object)val == (Object)null || val.m_itemData == null)
				{
					continue;
				}
				GameObject gameObject = ((Component)val).gameObject;
				if (gameObject.activeInHierarchy || (Object)(object)gameObject.transform.parent != (Object)null)
				{
					continue;
				}
				Scene scene = gameObject.scene;
				if (!((Scene)(ref scene)).IsValid() || gameObject == GungnirItem.Prefab || !GungnirItem.IsGungnir(val.m_itemData))
				{
					continue;
				}
				num++;
				if (((Humanoid)player).m_inventory.HaveEmptySlot())
				{
					ItemData itemData = val.m_itemData;
					GungnirItem.RepairDropPrefab(itemData);
					if (((Humanoid)player).m_inventory.AddItem(itemData))
					{
						num2++;
						Object.Destroy((Object)(object)gameObject);
					}
				}
			}
			if (num == 0)
			{
				Print("No stranded Gungnirs in this world. Anything dropped before a relog is gone for good - it was never written to the save.");
				return;
			}
			Print($"Found {num} stranded Gungnir(s); returned {num2} to your inventory.");
			if (num2 < num)
			{
				Print("The rest need free inventory slots. Make room and run it again.");
			}
		}

		private static void Status(Player player)
		{
			Print(Alive.StatusLine(GungnirStaffPlugin.Instance?.Harmony));
			ItemData val = GungnirItem.Active(player);
			if (val == null)
			{
				Print("No Gungnir active " + $"(Activation = {ModConfig.Activation.Value}). Try 'gungnir give'.");
				return;
			}
			StaffContainer staffContainer = StaffContainer.For(val);
			int ownQuality = staffContainer.OwnQuality;
			Print($"Level {ownQuality}/{3} " + $"-> {GungnirRecipe.SlotsForQuality(ownQuality)} rack slots");
			PrintDamage(val);
			Print("Selected slot: " + ((staffContainer.SelectedSlot < 0) ? "none" : (staffContainer.SelectedSlot + 1).ToString()));
			Print($"Bar contents ({staffContainer.Inventory.m_width} slots):");
			for (int i = 0; i < staffContainer.Inventory.m_width; i++)
			{
				ItemData val2 = staffContainer.ItemAt(i);
				Print(string.Format("  {0}: {1}", i + 1, (val2 == null) ? "-" : (val2.m_shared.m_name + " (lvl " + val2.m_quality + ")")));
			}
		}

		private static void PrintDamage(ItemData gungnir)
		{
			//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_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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)
			DamageTypes damage = gungnir.GetDamage();
			List<string> parts = new List<string>();
			Add("generic", damage.m_damage);
			Add("pierce", damage.m_pierce);
			Add("slash", damage.m_slash);
			Add("blunt", damage.m_blunt);
			Add("lightning", damage.m_lightning);
			Add("fire", damage.m_fire);
			Add("frost", damage.m_frost);
			Add("poison", damage.m_poison);
			Add("spirit", damage.m_spirit);
			Print($"Base damage every hit: {((DamageTypes)(ref damage)).GetTotalDamage():0.#} " + "(" + ((parts.Count > 0) ? string.Join(", ", parts.ToArray()) : "none") + ")");
			Attack val = gungnir.m_shared?.m_secondaryAttack;
			if (val != null)
			{
				Print($"  secondary x{val.m_damageMultiplier:0.##} " + $"-> {((DamageTypes)(ref damage)).GetTotalDamage() * val.m_damageMultiplier:0.#}");
			}
			Print($"Storm touch: {ModConfig.LightningChance.Value:P0} chance to ADD " + $"{ModConfig.LightningDamage.Value:0.#} lightning on top, with its " + "effect and sound. A failed roll changes nothing about the hit.");
			SharedData shared = gungnir.m_shared;
			int num = Count(shared?.m_hitEffect) + Count(shared?.m_attack?.m_hitEffect);
			Print($"Hit feedback: {num} effect(s) on impact, " + $"{Count(shared?.m_startEffect) + Count(shared?.m_attack?.m_startEffect)} on swing" + ((num == 0) ? "  <- SILENT: no impact sound or spark" : string.Empty));
			void Add(string label, float value)
			{
				if (value > 0f)
				{
					parts.Add($"{label} {value:0.#}");
				}
			}
		}

		private static int Count(EffectList list)
		{
			return (list?.m_effectPrefabs?.Length).GetValueOrDefault();
		}

		private static void Print(string text)
		{
			Alive.ToGameConsole(text);
			GungnirStaffPlugin.Log.LogInfo((object)text);
		}

		internal static void Register()
		{
			if (!CommandManager.Instance.CustomCommands.Any((ConsoleCommand c) => c.Name == "gungnir"))
			{
				CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new GungnirCommand());
			}
		}
	}
	internal static class CrystalColors
	{
		private const string Section = "Crystal colours";

		private static readonly Dictionary<string, string> Defaults = new Dictionary<string, string>
		{
			{ "StaffShield", "#FF0A2E" },
			{ "StaffRedTroll", "#FF2ECC" },
			{ "StaffSkeleton", "#6A0DAD" },
			{ "StaffLightning", "#6A5BFF" },
			{ "StaffIceShards", "#00D4FF" },
			{ "StaffGreenRoots", "#35FF00" },
			{ "StaffClusterbomb", "#FFE100" },
			{ "StaffFireball", "#FF6600" }
		};

		private static readonly Dictionary<string, ConfigEntry<string>> Bound = new Dictionary<string, ConfigEntry<string>>();

		private static ConfigFile _config;

		internal static ConfigEntry<string> Idle;

		internal static ConfigEntry<string> Fallback;

		internal static ConfigEntry<float> GlowIntensity;

		internal static ConfigEntry<float> GlowRange;

		internal static void Bind(ConfigFile config)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			_config = config;
			Bound.Clear();
			Idle = config.Bind<string>("Crystal colours", "NoStaffSelected", "#FFC24A", "Crystal colour when no staff is selected - Gungnir's own idle glow.");
			Fallback = config.Bind<string>("Crystal colours", "UnknownStaff", "#FFFFFF", "Crystal colour for a staff with no entry of its own, e.g. one added by another mod. Its own entry appears here once the game has seen it.");
			GlowIntensity = config.Bind<float>("Crystal colours", "GlowIntensity", 1.6f, new ConfigDescription("Brightness of the light the crystal casts. 0 turns the light off and leaves only the material tint.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 8f), Array.Empty<object>()));
			GlowRange = config.Bind<float>("Crystal colours", "GlowRange", 3.5f, new ConfigDescription("How far the crystal's light reaches, in metres.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 20f), Array.Empty<object>()));
		}

		internal static Color For(ItemData staff)
		{
			//IL_001c: 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_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_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_00cd: Unknown result type (might be due to invalid IL or missing references)
			if (staff == null)
			{
				return Parse(Idle.Value, new Color(1f, 0.76f, 0.29f));
			}
			string text = PrefabNameOf(staff);
			if (string.IsNullOrEmpty(text))
			{
				return Parse(Fallback.Value, new Color(0.79f, 0.64f, 0.15f));
			}
			if (!Bound.TryGetValue(text, out var value))
			{
				Defaults.TryGetValue(text, out var value2);
				value = _config.Bind<string>("Crystal colours", text, value2 ?? Fallback.Value, "Crystal colour while " + text + " is selected. Hex, e.g. #FF6A18.");
				Bound[text] = value;
			}
			return Parse(value.Value, Parse(Fallback.Value, Color.white));
		}

		private static string PrefabNameOf(ItemData item)
		{
			if ((Object)(object)item.m_dropPrefab != (Object)null)
			{
				return ((Object)item.m_dropPrefab).name;
			}
			return item.m_shared?.m_name;
		}

		private static Color Parse(string hex, Color fallback)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			Color result = default(Color);
			if (!string.IsNullOrEmpty(hex) && ColorUtility.TryParseHtmlString(hex.Trim(), ref result))
			{
				return result;
			}
			return fallback;
		}
	}
	internal static class CrystalGlow
	{
		internal const string CrystalObjectName = "Gungnir_Crystal";

		private const string GlowObjectName = "GungnirCrystalGlow";

		private static Light _light;

		private static Material _tinted;

		private static Color _applied = Color.clear;

		internal static void Apply(Player player, ItemData gungnir)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = FindHeldObject(player);
			if ((Object)(object)val == (Object)null)
			{
				Clear();
				return;
			}
			StaffContainer staffContainer = StaffContainer.For(gungnir);
			int num = staffContainer?.SelectedSlot ?? (-1);
			Color val2 = CrystalColors.For((num >= 0) ? staffContainer.ItemAt(num) : null);
			EnsureLight(val);
			if ((Object)(object)_light != (Object)null)
			{
				_light.color = val2;
				_light.intensity = (ModConfig.Enabled.Value ? CrystalColors.GlowIntensity.Value : 0f);
				_light.range = CrystalColors.GlowRange.Value;
			}
			if (_applied != val2)
			{
				TintCrystal(val, val2);
				_applied = val2;
			}
			Renderer crystal = FindCrystal(val);
			CrystalParticles.Apply(crystal, val, player, val2, num >= 0);
		}

		internal static void Clear()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_light != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_light).gameObject);
			}
			CrystalParticles.Clear();
			_light = null;
			_tinted = null;
			_applied = Color.clear;
		}

		private static GameObject FindHeldObject(Player player)
		{
			VisEquipment val = ((Humanoid)(player?)).m_visEquipment;
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			GameObject rightItemInstance = val.m_rightItemInstance;
			if ((Object)(object)rightItemInstance != (Object)null && (Object)(object)FindCrystal(rightItemInstance) != (Object)null)
			{
				return rightItemInstance;
			}
			GameObject leftItemInstance = val.m_leftItemInstance;
			if ((Object)(object)leftItemInstance != (Object)null && (Object)(object)FindCrystal(leftItemInstance) != (Object)null)
			{
				return leftItemInstance;
			}
			return rightItemInstance ?? leftItemInstance;
		}

		private static void EnsureLight(GameObject attach)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_light != (Object)null) || !((Component)_light).transform.IsChildOf(attach.transform))
			{
				if ((Object)(object)_light != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)_light).gameObject);
				}
				GameObject val = new GameObject("GungnirCrystalGlow");
				val.transform.SetParent(attach.transform, false);
				Renderer val2 = FindCrystal(attach);
				Transform transform = val.transform;
				Vector3 position;
				if (!((Object)(object)val2 != (Object)null))
				{
					position = attach.transform.position;
				}
				else
				{
					Bounds bounds = val2.bounds;
					position = ((Bounds)(ref bounds)).center;
				}
				transform.position = position;
				_light = val.AddComponent<Light>();
				_light.type = (LightType)2;
				_light.shadows = (LightShadows)0;
				_light.renderMode = (LightRenderMode)2;
			}
		}

		private static Renderer FindCrystal(GameObject attach)
		{
			Renderer[] componentsInChildren = attach.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (((Object)((Component)val).gameObject).name.StartsWith("Gungnir_Crystal", StringComparison.Ordinal))
				{
					return val;
				}
			}
			return null;
		}

		private static void TintCrystal(GameObject attach, Color colour)
		{
			//IL_0056: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			Renderer val = FindCrystal(attach);
			if (!((Object)(object)val == (Object)null))
			{
				if ((Object)(object)_tinted == (Object)null || (Object)(object)val.material != (Object)(object)_tinted)
				{
					_tinted = val.material;
				}
				if (_tinted.HasProperty("_Color"))
				{
					_tinted.SetColor("_Color", colour);
				}
				if (_tinted.HasProperty("_EmissionColor"))
				{
					_tinted.EnableKeyword("_EMISSION");
					_tinted.SetColor("_EmissionColor", colour * CrystalColors.GlowIntensity.Value);
				}
			}
		}
	}
	internal static class CrystalParticles
	{
		private const string OrbitName = "GungnirCrystalOrbit";

		private const string SparkName = "GungnirCrystalSparks";

		private static ParticleSystem _orbit;

		private static ParticleSystem _sparks;

		private static Material _material;

		private static Color _applied = Color.clear;

		internal static void Apply(Renderer crystal, GameObject weapon, Player player, Color colour, bool staffStance)
		{
			//IL_009f: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			if (ModConfig.CrystalParticles.Value switch
			{
				CrystalParticleMode.Always => 1, 
				CrystalParticleMode.Never => 0, 
				_ => staffStance ? 1 : 0, 
			} == 0 || (Object)(object)crystal == (Object)null)
			{
				Clear();
				return;
			}
			if ((Object)(object)_orbit == (Object)null || !((Component)_orbit).transform.IsChildOf(((Component)crystal).transform))
			{
				Clear();
				Build(crystal, weapon, player);
			}
			if (!((Object)(object)_orbit == (Object)null))
			{
				HoldSize(((Component)_orbit).transform);
				HoldSize(((Object)(object)_sparks != (Object)null) ? ((Component)_sparks).transform : null);
				if (_applied != colour)
				{
					_applied = colour;
					Tint(colour);
				}
			}
		}

		internal static void Clear()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_orbit != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)((Component)_orbit).gameObject);
			}
			if ((Object)(object)_sparks != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)((Component)_sparks).gameObject);
			}
			_orbit = null;
			_sparks = null;
			_material = null;
			_applied = Color.clear;
		}

		private static void Build(Renderer crystal, GameObject weapon, Player player)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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_0067: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				VisEquipment val = (((Object)(object)player != (Object)null) ? ((Humanoid)player).m_visEquipment : null);
				PurgeStrays(weapon);
				if ((Object)(object)val != (Object)null)
				{
					PurgeStrays(val.m_rightItemInstance);
					PurgeStrays(val.m_leftItemInstance);
				}
				_material = BorrowParticleMaterial(weapon);
				float value = ModConfig.CrystalParticleScale.Value;
				Transform transform = ((Component)crystal).transform;
				Bounds bounds = crystal.bounds;
				Vector3 anchor = transform.InverseTransformPoint(((Bounds)(ref bounds)).center);
				_orbit = MakeSystem(((Component)crystal).transform, "GungnirCrystalOrbit", anchor);
				ConfigureOrbit(_orbit, value);
				_sparks = MakeSystem(((Component)crystal).transform, "GungnirCrystalSparks", anchor);
				ConfigureSparks(_sparks, value);
				ModConfig.Trace("Crystal particle systems created.");
			}
			catch (Exception arg)
			{
				GungnirStaffPlugin.Log.LogError((object)$"Could not build crystal particles: {arg}");
				Clear();
			}
		}

		private static ParticleSystem MakeSystem(Transform parent, string name, Vector3 anchor)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_001a: 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)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.transform.localPosition = anchor;
			val.transform.localRotation = Quaternion.identity;
			HoldSize(val.transform);
			ParticleSystem result = val.AddComponent<ParticleSystem>();
			ParticleSystemRenderer component = val.GetComponent<ParticleSystemRenderer>();
			component.renderMode = (ParticleSystemRenderMode)0;
			component.alignment = (ParticleSystemRenderSpace)0;
			((Renderer)component).material = _material;
			((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)component).receiveShadows = false;
			return result;
		}

		private static void ConfigureOrbit(ParticleSystem ps, float scale)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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_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_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: 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_012b: 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)
			ps.Stop();
			MainModule main = ps.main;
			((MainModule)(ref main)).loop = true;
			((MainModule)(ref main)).scalingMode = (ParticleSystemScalingMode)2;
			((MainModule)(ref main)).startLifetime = new MinMaxCurve(1.6f, 3.2f);
			((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(0f);
			((MainModule)(ref main)).startSize = new MinMaxCurve(0.012f * scale, 0.024f * scale);
			((MainModule)(ref main)).maxParticles = 60;
			((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(0f);
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)0;
			EmissionModule emission = ps.emission;
			((EmissionModule)(ref emission)).enabled = true;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(14f * ModConfig.CrystalParticleRate.Value);
			ShapeModule shape = ps.shape;
			((ShapeModule)(ref shape)).enabled = true;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
			((ShapeModule)(ref shape)).radius = 0.115f * scale;
			((ShapeModule)(ref shape)).radiusThickness = 0.45f;
			VelocityOverLifetimeModule velocityOverLifetime = ps.velocityOverLifetime;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).enabled = true;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).space = (ParticleSystemSimulationSpace)0;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).orbitalX = new MinMaxCurve(-1.1f, 1.1f);
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).orbitalY = new MinMaxCurve(-1.1f, 1.1f);
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).orbitalZ = new MinMaxCurve(-1.1f, 1.1f);
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).radial = new MinMaxCurve(-0.012f, 0.012f);
			FadeInOut(ps);
			ShrinkOverLife(ps, 1f, 0.25f);
			ps.Play();
		}

		private static void ConfigureSparks(ParticleSystem ps, float scale)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: 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_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: 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_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			ps.Stop();
			MainModule main = ps.main;
			((MainModule)(ref main)).loop = true;
			((MainModule)(ref main)).scalingMode = (ParticleSystemScalingMode)2;
			((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.45f, 0.9f);
			((MainModule)(ref main)).startSpeed = new MinMaxCurve(0.35f, 0.9f);
			((MainModule)(ref main)).startSize = new MinMaxCurve(0.008f * scale, 0.018f * scale);
			((MainModule)(ref main)).maxParticles = 40;
			((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(0.02f);
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
			EmissionModule emission = ps.emission;
			((EmissionModule)(ref emission)).enabled = true;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(3f * ModConfig.CrystalParticleRate.Value);
			((EmissionModule)(ref emission)).SetBursts((Burst[])(object)new Burst[1]
			{
				new Burst(0f, (short)3, (short)6, 0, 0.85f)
			});
			ShapeModule shape = ps.shape;
			((ShapeModule)(ref shape)).enabled = true;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
			((ShapeModule)(ref shape)).radius = 0.035f * scale;
			((ShapeModule)(ref shape)).radiusThickness = 1f;
			VelocityOverLifetimeModule velocityOverLifetime = ps.velocityOverLifetime;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).enabled = true;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).space = (ParticleSystemSimulationSpace)0;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).radial = new MinMaxCurve(0.05f, 0.25f);
			FadeInOut(ps);
			ShrinkOverLife(ps, 1f, 0f);
			ps.Play();
		}

		private static void HoldSize(Transform t)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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_0090: 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)
			if ((Object)(object)t == (Object)null)
			{
				return;
			}
			Transform parent = t.parent;
			Vector3 val = (((Object)(object)parent != (Object)null) ? parent.lossyScale : Vector3.one);
			if (!Mathf.Approximately(val.x, 0f) && !Mathf.Approximately(val.y, 0f) && !Mathf.Approximately(val.z, 0f))
			{
				Vector3 val2 = default(Vector3);
				((Vector3)(ref val2))..ctor(1f / val.x, 1f / val.y, 1f / val.z);
				if (t.localScale != val2)
				{
					t.localScale = val2;
				}
			}
		}

		private static void PurgeStrays(GameObject root)
		{
			if ((Object)(object)root == (Object)null)
			{
				return;
			}
			ParticleSystem[] componentsInChildren = root.GetComponentsInChildren<ParticleSystem>(true);
			foreach (ParticleSystem val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null) && val != _orbit && val != _sparks)
				{
					string name = ((Object)((Component)val).gameObject).name;
					if (name.StartsWith("GungnirCrystalOrbit", StringComparison.Ordinal) || name.StartsWith("GungnirCrystalSparks", StringComparison.Ordinal))
					{
						Object.DestroyImmediate((Object)(object)((Component)val).gameObject);
					}
				}
			}
		}

		private static void FadeInOut(ParticleSystem ps)
		{
			//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_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_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_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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)
			ColorOverLifetimeModule colorOverLifetime = ps.colorOverLifetime;
			((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
			Gradient val = new Gradient();
			val.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
			{
				new GradientColorKey(Color.white, 0f),
				new GradientColorKey(Color.white, 1f)
			}, (GradientAlphaKey[])(object)new GradientAlphaKey[4]
			{
				new GradientAlphaKey(0f, 0f),
				new GradientAlphaKey(1f, 0.25f),
				new GradientAlphaKey(0.85f, 0.6f),
				new GradientAlphaKey(0f, 1f)
			});
			((ColorOverLifetimeModule)(ref colorOverLifetime)).color = new MinMaxGradient(val);
		}

		private static void ShrinkOverLife(ParticleSystem ps, float from, float to)
		{
			//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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			SizeOverLifetimeModule sizeOverLifetime = ps.sizeOverLifetime;
			((SizeOverLifetimeModule)(ref sizeOverLifetime)).enabled = true;
			AnimationCurve val = new AnimationCurve((Keyframe[])(object)new Keyframe[3]
			{
				new Keyframe(0f, (to > 0f) ? 0.4f : 0.2f),
				new Keyframe(0.3f, from),
				new Keyframe(1f, to)
			});
			((SizeOverLifetimeModule)(ref sizeOverLifetime)).size = new MinMaxCurve(1f, val);
		}

		private static void Tint(Color colour)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			Color val = colour * ModConfig.CrystalParticleBrightness.Value;
			val.a = 1f;
			ParticleSystem[] array = (ParticleSystem[])(object)new ParticleSystem[2] { _orbit, _sparks };
			foreach (ParticleSystem val2 in array)
			{
				if (!((Object)(object)val2 == (Object)null))
				{
					MainModule main = val2.main;
					((MainModule)(ref main)).startColor = new MinMaxGradient(val, colour);
				}
			}
			if ((Object)(object)_material == (Object)null)
			{
				return;
			}
			string[] array2 = new string[4] { "_TintColor", "_Color", "_BaseColor", "_EmissionColor" };
			foreach (string text in array2)
			{
				if (_material.HasProperty(text))
				{
					_material.SetColor(text, val);
				}
			}
		}

		private static Material BorrowParticleMaterial(GameObject weapon)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Expected O, but got Unknown
			Material val = (((Object)(object)weapon == (Object)null) ? null : (from r in weapon.GetComponentsInChildren<ParticleSystemRenderer>(true)
				select ((Renderer)r).sharedMaterial).FirstOrDefault((Func<Material, bool>)((Material m) => (Object)(object)m != (Object)null && (Object)(object)m.shader != (Object)null)));
			if ((Object)(object)val != (Object)null)
			{
				return new Material(val);
			}
			Shader val2 = Shader.Find("Particles/Standard Unlit") ?? Shader.Find("Legacy Shaders/Particles/Additive") ?? Shader.Find("Sprites/Default");
			if ((Object)(object)val2 == (Object)null)
			{
				GungnirStaffPlugin.Log.LogWarning((object)"No particle shader available; crystal motes may not render.");
				return null;
			}
			return new Material(val2);
		}
	}
	internal static class GungnirBar
	{
		private const string SlotKeyLabelName = "GungnirSlotKey";

		private static GameObject _root;

		private static InventoryGrid _grid;

		private static Inventory _bound;

		private static readonly List<TMP_Text> _slotKeyLabels = new List<TMP_Text>();

		private static int _labelledSlots = -1;

		private static bool _dragging;

		private static Vector2 _dragGrabPoint;

		private static Vector2 _dragStartPosition;

		private static Vector2 _dragPosition;

		private static bool _writingOwnPosition;

		internal static InventoryGrid Grid => _grid;

		internal static StaffContainer Container { get; private set; }

		internal static void Refresh(Player player)
		{
			InventoryGui instance = InventoryGui.m_instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)player == (Object)null)
			{
				Hide();
				return;
			}
			ItemData val = GungnirItem.Active(player);
			if (!ShouldShow(val))
			{
				Hide();
			}
			else
			{
				if ((Object)(object)_grid == (Object)null && !Build(instance))
				{
					return;
				}
				Container = ((val != null) ? StaffContainer.For(val) : null);
				if (Container == null)
				{
					Hide();
					return;
				}
				if (!_root.activeSelf)
				{
					_root.SetActive(true);
				}
				UpdateDrag();
				ApplyLayout();
				_bound = Container.Inventory;
				_grid.UpdateInventory(_bound, player, instance.m_dragItem);
				SyncSlotKeyLabels();
				HighlightSelected();
			}
		}

		private static bool ShouldShow(ItemData gungnir)
		{
			switch (ModConfig.Visibility.Value)
			{
			case BarVisibility.Always:
				return true;
			case BarVisibility.InventoryOnly:
				if (gungnir != null)
				{
					return InventoryGui.IsVisible();
				}
				return false;
			default:
				return gungnir != null;
			}
		}

		private static void Hide()
		{
			EndDrag(commit: false);
			Container = null;
			if ((Object)(object)_root != (Object)null && _root.activeSelf)
			{
				_root.SetActive(false);
			}
		}

		internal static void Teardown()
		{
			if ((Object)(object)_root != (Object)null)
			{
				Object.Destroy((Object)(object)_root);
			}
			_dragging = false;
			_root = null;
			_grid = null;
			_bound = null;
			Container = null;
			_slotKeyLabels.Clear();
			_labelledSlots = -1;
		}

		private static void SyncSlotKeyLabels()
		{
			List<Element> elements = _grid.m_elements;
			if (!ModConfig.ShowSlotKeys.Value || elements == null)
			{
				if (_slotKeyLabels.Count > 0)
				{
					ClearSlotKeyLabels();
				}
			}
			else
			{
				if (LabelsAreCurrent(elements.Count))
				{
					return;
				}
				ClearSlotKeyLabels();
				for (int i = 0; i < elements.Count; i++)
				{
					TMP_Text val = BuildSlotKeyLabel(elements[i], i);
					if ((Object)(object)val != (Object)null)
					{
						_slotKeyLabels.Add(val);
					}
				}
				_labelledSlots = elements.Count;
				ModConfig.Trace($"Built {_slotKeyLabels.Count} shortcut label(s) for {elements.Count} slot(s).");
			}
		}

		private static bool LabelsAreCurrent(int slots)
		{
			if (_labelledSlots != slots)
			{
				return false;
			}
			foreach (TMP_Text slotKeyLabel in _slotKeyLabels)
			{
				if ((Object)(object)slotKeyLabel == (Object)null)
				{
					return false;
				}
			}
			return true;
		}

		private static void ClearSlotKeyLabels()
		{
			foreach (TMP_Text slotKeyLabel in _slotKeyLabels)
			{
				if ((Object)(object)slotKeyLabel != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)slotKeyLabel).gameObject);
				}
			}
			_slotKeyLabels.Clear();
			_labelledSlots = -1;
		}

		private static TMP_Text BuildSlotKeyLabel(Element element, int slot)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: 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_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			TMP_Text val = element?.m_amount;
			if ((Object)(object)val == (Object)null || (Object)(object)element.m_go == (Object)null || slot >= 8)
			{
				return null;
			}
			string text = Inputs.ShortLabel(ModConfig.SlotKeys[slot].Value);
			if (string.IsNullOrEmpty(text))
			{
				return null;
			}
			GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject, element.m_go.transform);
			((Object)val2).name = "GungnirSlotKey";
			val2.SetActive(true);
			TMP_Text component = val2.GetComponent<TMP_Text>();
			if ((Object)(object)component == (Object)null)
			{
				Object.Destroy((Object)(object)val2);
				return null;
			}
			float num = SlotHeight(element);
			Transform transform = val2.transform;
			RectTransform val3 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			if ((Object)(object)val3 != (Object)null)
			{
				val3.anchorMin = new Vector2(0.5f, 0f);
				val3.anchorMax = new Vector2(0.5f, 0f);
				val3.pivot = new Vector2(0.5f, 1f);
				val3.anchoredPosition = new Vector2(0f, (0f - num) * 0.04f);
				val3.sizeDelta = new Vector2(num * 1.6f, num * 0.4f);
				((Transform)val3).localScale = Vector3.one;
				((Transform)val3).localRotation = Quaternion.identity;
			}
			((Behaviour)component).enabled = true;
			component.text = text;
			component.fontSize = num * 0.26f * ModConfig.SlotKeyScale.Value;
			component.enableAutoSizing = false;
			component.alignment = (TextAlignmentOptions)258;
			component.textWrappingMode = (TextWrappingModes)0;
			component.overflowMode = (TextOverflowModes)0;
			((Graphic)component).color = new Color(1f, 1f, 1f, 0.7f);
			((Graphic)component).raycastTarget = false;
			return component;
		}

		private static float SlotHeight(Element element)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = element.m_go.transform;
			RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			float num;
			if (!((Object)(object)val != (Object)null))
			{
				num = 0f;
			}
			else
			{
				Rect rect = val.rect;
				num = ((Rect)(ref rect)).height;
			}
			float num2 = num;
			if (!(num2 > 1f))
			{
				return 64f;
			}
			return num2;
		}

		private static bool Build(InventoryGui gui)
		{
			InventoryGrid playerGrid = gui.m_playerGrid;
			Transform val = FindAlwaysActiveUiRoot(gui);
			if ((Object)(object)playerGrid == (Object)null || (Object)(object)val == (Object)null)
			{
				return false;
			}
			try
			{
				_root = Object.Instantiate<GameObject>(((Component)playerGrid).gameObject, val);
				((Object)_root).name = "GungnirStaffBar";
				_root.transform.SetAsLastSibling();
				_grid = _root.GetComponent<InventoryGrid>();
				if ((Object)(object)_grid == (Object)null)
				{
					Teardown();
					return false;
				}
				MakeSelfSufficient();
				ClearClonedSlots();
				_grid.m_onSelected = null;
				_grid.m_onRightClick = null;
				InventoryGrid grid = _grid;
				grid.m_onSelected = (Action<InventoryGrid, ItemData, Vector2i, Modifier>)Delegate.Combine(grid.m_onSelected, new Action<InventoryGrid, ItemData, Vector2i, Modifier>(OnSelected));
				InventoryGrid grid2 = _grid;
				grid2.m_onRightClick = (Action<InventoryGrid, ItemData, Vector2i>)Delegate.Combine(grid2.m_onRightClick, new Action<InventoryGrid, ItemData, Vector2i>(OnRightClick));
				ModConfig.Trace("Staff bar created under '" + ((Object)val).name + "'.");
				return true;
			}
			catch (Exception arg)
			{
				GungnirStaffPlugin.Log.LogError((object)$"Could not build the staff bar: {arg}");
				Teardown();
				return false;
			}
		}

		private static Transform FindAlwaysActiveUiRoot(InventoryGui gui)
		{
			GameObject val = (((Object)(object)Hud.m_instance != (Object)null) ? Hud.m_instance.m_rootObject : null);
			if ((Object)(object)val != (Object)null)
			{
				return val.transform;
			}
			Canvas componentInParent = ((Component)gui).GetComponentInParent<Canvas>();
			Canvas val2 = (((Object)(object)componentInParent != (Object)null) ? componentInParent.rootCanvas : null);
			if (!((Object)(object)val2 != (Object)null))
			{
				return ((Component)gui).transform.root;
			}
			return ((Component)val2).transform;
		}

		private static void MakeSelfSufficient()
		{
			Canvas val = _root.GetComponent<Canvas>();
			if ((Object)(object)val == (Object)null)
			{
				val = _root.AddComponent<Canvas>();
			}
			Canvas val2 = (((Object)(object)InventoryGui.m_instance != (Object)null) ? ((Component)InventoryGui.m_instance).GetComponentInParent<Canvas>() : null);
			int num = (((Object)(object)val2 != (Object)null) ? val2.sortingOrder : 0);
			val.overrideSorting = true;
			val.sortingOrder = num + 5;
			ModConfig.Trace($"Rack canvas sortingOrder {val.sortingOrder} " + $"(inventory canvas is {num}).");
			if ((Object)(object)_root.GetComponent<GraphicRaycaster>() == (Object)null)
			{
				_root.AddComponent<GraphicRaycaster>();
			}
		}

		private static void ClearClonedSlots()
		{
			_grid.m_elements?.Clear();
			RectTransform gridRoot = _grid.m_gridRoot;
			if (!((Object)(object)gridRoot == (Object)null))
			{
				for (int num = ((Transform)gridRoot).childCount - 1; num >= 0; num--)
				{
					Object.DestroyImmediate((Object)(object)((Component)((Transform)gridRoot).GetChild(num)).gameObject);
				}
			}
		}

		internal static void OnLayoutSettingChanged()
		{
			if (!_writingOwnPosition)
			{
				Teardown();
			}
		}

		private static void UpdateDrag()
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			int value = ModConfig.MoveBarMouseButton.Value;
			if (value < 0 || !InventoryGui.IsVisible())
			{
				EndDrag(commit: false);
			}
			else if (!_dragging)
			{
				if (ZInput.GetMouseButtonDown(value) && PointerIsOverSlots() && TryPointerInParent(out var point))
				{
					_dragging = true;
					_dragGrabPoint = point;
					_dragStartPosition = ConfiguredPosition();
					_dragPosition = _dragStartPosition;
				}
			}
			else
			{
				if (TryPointerInParent(out var point2))
				{
					_dragPosition = ClampToRange(_dragStartPosition + (point2 - _dragGrabPoint));
				}
				if (!ZInput.GetMouseButton(value))
				{
					EndDrag(commit: true);
				}
			}
		}

		private static void EndDrag(bool commit)
		{
			if (!_dragging)
			{
				return;
			}
			_dragging = false;
			if (commit)
			{
				_writingOwnPosition = true;
				try
				{
					ModConfig.BarOffsetX.Value = Mathf.Round(_dragPosition.x);
					ModConfig.BarOffsetY.Value = Mathf.Round(_dragPosition.y);
				}
				finally
				{
					_writingOwnPosition = false;
				}
				ModConfig.Trace($"Staff bar moved to {ModConfig.BarOffsetX.Value}, {ModConfig.BarOffsetY.Value}.");
			}
		}

		private static bool TryPointerInParent(out Vector2 point)
		{
			//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_0050: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			point = Vector2.zero;
			RectTransform val = (RectTransform)(((Object)(object)_root != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			Canvas component = _root.GetComponent<Canvas>();
			Camera val2 = (((Object)(object)component != (Object)null && (int)component.renderMode != 0) ? component.worldCamera : null);
			return RectTransformUtility.ScreenPointToLocalPointInRectangle(val, Vector2.op_Implicit(ZInput.mousePosition), val2, ref point);
		}

		private static Vector2 ConfiguredPosition()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			return new Vector2(ModConfig.BarOffsetX.Value, ModConfig.BarOffsetY.Value);
		}

		private static Vector2 ClampToRange(Vector2 position)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			return new Vector2(Mathf.Clamp(position.x, -2000f, 2000f), Mathf.Clamp(position.y, -2000f, 2000f));
		}

		private static void ApplyLayout()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = _root.transform;
			RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			if (!((Object)(object)val == (Object)null))
			{
				val.anchorMin = new Vector2(0.5f, 0f);
				val.anchorMax = new Vector2(0.5f, 0f);
				val.pivot = new Vector2(0.5f, 0f);
				val.anchoredPosition = (_dragging ? _dragPosition : ConfiguredPosition());
				((Transform)val).localScale = Vector3.one * ModConfig.BarScale.Value;
			}
		}

		private static void HighlightSelected()
		{
			int num = Container?.SelectedSlot ?? (-1);
			if (num >= 0 && _bound != null && _grid.m_elements != null && num < _grid.m_elements.Count)
			{
				Element element = _grid.GetElement(num, 0, _bound.m_width);
				if ((Object)(object)element?.m_equiped != (Object)null)
				{
					((Behaviour)element.m_equiped).enabled = true;
				}
			}
		}

		private static bool PointerIsOverSlots()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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)
			List<Element> list = (((Object)(object)_grid != (Object)null) ? _grid.m_elements : null);
			if (list == null || list.Count == 0)
			{
				return false;
			}
			Canvas component = _root.GetComponent<Canvas>();
			Camera val = (((Object)(object)component != (Object)null && (int)component.renderMode != 0) ? component.worldCamera : null);
			foreach (Element item in list)
			{
				RectTransform val2 = (RectTransform)(((Object)(object)item?.m_go != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
				if ((Object)(object)val2 != (Object)null && RectTransformUtility.RectangleContainsScreenPoint(val2, Vector2.op_Implicit(ZInput.mousePosition), val))
				{
					return true;
				}
			}
			return false;
		}

		internal static bool PointerIsOverBar()
		{
			//IL_004b: 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)
			if ((Object)(object)_root == (Object)null || !_root.activeInHierarchy)
			{
				return false;
			}
			Transform transform = _root.transform;
			RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			Canvas component = _root.GetComponent<Canvas>();
			Camera val2 = (((Object)(object)component != (Object)null && (int)component.renderMode != 0) ? component.worldCamera : null);
			return RectTransformUtility.RectangleContainsScreenPoint(val, Vector2.op_Implicit(ZInput.mousePosition), val2);
		}

		internal static bool TryPlaceDraggedItem(InventoryGui gui)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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)
			ItemData dragItem = gui.m_dragItem;
			if (dragItem == null || (Object)(object)_grid == (Object)null || Container == null || _bound == null)
			{
				return false;
			}
			Player localPlayer = Player.m_localPlayer;
			if (!StaffRegistry.IsStaff(dragItem))
			{
				if (localPlayer != null)
				{
					((Character)localPlayer).Message((MessageType)2, "$gungnir_msg_only_staffs", 0, (Sprite)null);
				}
				return true;
			}
			Vector2i val = _grid.GetHoveredElement()?.m_pos ?? FirstFreeSlot();
			if (val.x < 0)
			{
				if (localPlayer != null)
				{
					((Character)localPlayer).Message((MessageType)2, "$gungnir_msg_rack_full", 0, (Sprite)null);
				}
				return true;
			}
			if (!_grid.DropItem(gui.m_dragInventory, dragItem, gui.m_dragAmount, val))
			{
				return true;
			}
			gui.SetupDragItem((ItemData)null, (Inventory)null, 0);
			Container.SaveToItem();
			ModConfig.Trace($"Placed {dragItem.m_shared.m_name} into rack slot {val.x + 1}.");
			return true;
		}

		private static Vector2i FirstFreeSlot()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < _bound.m_width; i++)
			{
				if (_bound.GetItemAt(i, 0) == null)
				{
					return new Vector2i(i, 0);
				}
			}
			return new Vector2i(-1, 0);
		}

		private static void OnRightClick(InventoryGrid grid, ItemData item, Vector2i pos)
		{
			//IL_0005: 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)
			ModConfig.Trace(string.Format("Rack right-click at slot {0}, item={1}.", pos.x + 1, item?.m_shared?.m_name ?? "empty"));
			Player localPlayer = Player.m_localPlayer;
			ItemData val = GungnirItem.Active(localPlayer);
			if (val != null && item != null)
			{
				StaffSwitcher.Select(localPlayer, val, pos.x);
			}
		}

		private static void OnSelected(InventoryGrid grid, ItemData item, Vector2i pos, Modifier mod)
		{
			//IL_0019: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Invalid comparison between Unknown and I4
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			InventoryGui instance = InventoryGui.m_instance;
			Player localPlayer = Player.m_localPlayer;
			ModConfig.Trace($"Rack left-click at slot {pos.x + 1}, mod={mod}, " + "slotItem=" + (item?.m_shared?.m_name ?? "empty") + ", dragging=" + (instance?.m_dragItem?.m_shared?.m_name ?? "nothing") + ".");
			if (!((Object)(object)instance == (Object)null) && !((Object)(object)localPlayer == (Object)null))
			{
				if ((int)mod == 2)
				{
					MoveToPlayerInventory(localPlayer, item);
				}
				else
				{
					instance.OnSelectedItem(grid, item, pos, mod);
				}
			}
		}

		private static void MoveToPlayerInventory(Player player, ItemData item)
		{
			if (item == null || Container == null)
			{
				return;
			}
			Inventory inventory = ((Humanoid)player).m_inventory;
			if (inventory == null)
			{
				return;
			}
			if (!inventory.CanAddItem(item, -1))
			{
				((Character)player).Message((MessageType)2, "$msg_noroom", 0, (Sprite)null);
				return;
			}
			inventory.MoveItemToThis(Container.Inventory, item);
			Container.SaveToItem();
			ItemData val = GungnirItem.Active(player);
			if (val != null)
			{
				StaffSwitcher.Reapply(player, val);
			}
		}
	}
	internal static class GungnirItem
	{
		internal const string PrefabName = "GungnirStaff";

		internal const string NameToken = "$gungnir_item_name";

		internal const string DescToken = "$gungnir_item_desc";

		internal const float PrimaryPierce = 95f;

		internal const float SecondaryPierce = 113f;

		private static readonly string[] BaseWeaponCandidates = new string[5] { "SpearSplitner_Lightning", "SpearSplitner", "SpearCarapace", "SpearElderbark", "SpearBronze" };

		internal static GameObject Prefab { get; private set; }

		internal static SharedData BaseShared { get; private set; }

		internal static bool HasVanillaItems(ObjectDB db)
		{
			if ((Object)(object)db == (Object)null || db.m_items == null || db.m_items.Count == 0)
			{
				return false;
			}
			string[] baseWeaponCandidates = BaseWeaponCandidates;
			foreach (string text in baseWeaponCandidates)
			{
				if ((Object)(object)db.GetItemPrefab(text) != (Object)null)
				{
					return true;
				}
			}
			return false;
		}

		internal static bool IsGungnir(ItemData item)
		{
			if (item == null)
			{
				return false;
			}
			if ((Object)(object)item.m_dropPrefab != (Object)null)
			{
				if (item.m_dropPrefab != Prefab)
				{
					return ((Object)item.m_dropPrefab).name == "GungnirStaff";
				}
				return true;
			}
			if (item.m_shared == null || !(item.m_shared.m_name == "$gungnir_item_name"))
			{
				if (item.m_customData != null)
				{
					return item.m_customData.ContainsKey("gungnir.inv");
				}
				return false;
			}
			return true;
		}

		internal static bool Create()
		{
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Expected O, but got Unknown
			ObjectDB instance = ObjectDB.instance;
			if ((Object)(object)instance == (Object)null || instance.m_items == null || instance.m_items.Count == 0)
			{
				ModConfig.Trace("ObjectDB not ready; deferring Gungnir prefab creation.");
				return false;
			}
			GameObject itemPrefab = instance.GetItemPrefab("GungnirStaff");
			if ((Object)(object)itemPrefab != (Object)null)
			{
				Prefab = itemPr