Decompiled source of ThorHammer v1.0.4

ThorHammer.Il2Cpp.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Il2CppFishNet.Object;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne;
using Il2CppScheduleOne.Audio;
using Il2CppScheduleOne.Combat;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.Effects;
using Il2CppScheduleOne.Equipping;
using Il2CppScheduleOne.FX;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.NPCs;
using Il2CppScheduleOne.Noise;
using Il2CppScheduleOne.Persistence;
using Il2CppScheduleOne.PlayerScripts;
using Il2CppScheduleOne.Vision;
using Il2CppScheduleOne.Weather;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using S1API.Items;
using S1API.Shops;
using S1MAPI.Gltf;
using S1MAPI.Utils;
using ThorHammer;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Core), "Mjolnir", "1.0.4", "hdlmrell", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ThorHammer.Il2Cpp")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.0+ea2da1c6208f6f22b4b7396e9dab0a1eb1fb605e")]
[assembly: AssemblyProduct("ThorHammer.Il2Cpp")]
[assembly: AssemblyTitle("ThorHammer.Il2Cpp")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 ThorHammer
{
	public class Core : MelonMod
	{
		private bool _itemsRegistered;

		private bool _loadHooked;

		private static ItemDefinition _hammerDef;

		private static Sprite _cachedIcon;

		private static readonly string[] HardwareShopNames = new string[2] { "Handy Hank's Hardware", "Dan's Hardware" };

		private static MelonPreferences_Entry<float> _priceEntry;

		private static MelonPreferences_Entry<bool> _sellAtHardwareEntry;

		private static bool _shopsPopulated;

		public static KeyCode LightningKey { get; private set; } = (KeyCode)120;


		public static float MeleeDamage { get; private set; } = 25f;


		public static float MeleeForce { get; private set; } = 350f;


		public static float ThrowDamage { get; private set; } = 100f;


		public static float ThrowForce { get; private set; } = 600f;


		public static float LightningDamage { get; private set; } = 80f;


		public static float LightningForce { get; private set; } = 400f;


		public static float LightningPanicRadius { get; private set; } = 25f;


		public static float FlightSpeed { get; private set; } = 18f;


		public static float ThrowSpeed { get; private set; } = 40f;


		public static float MaxThrowRange { get; private set; } = 30f;


		public static float WindUpDuration { get; private set; } = 1.2f;


		public static bool StaminaEnabled { get; private set; } = true;


		public static float SwingStaminaCost { get; private set; } = 15f;


		public static float LightningStaminaCost { get; private set; } = 20f;


		public static float WindUpStaminaRate { get; private set; } = 20f;


		public static float FlightStaminaRate { get; private set; } = 15f;


		private static string IconPath => Path.Combine(MelonEnvironment.UserDataDirectory, "S1API", "Icons", "ThorHammer.png");

		public override void OnInitializeMelon()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			ClassInjector.RegisterTypeInIl2Cpp<HammerEquippable>();
			string text = BindEntry(MelonPreferences.CreateCategory("Mjolnir - Controls", "Mjolnir Controls"), "LightningKey", "X", "Lightning Key", "Key to summon lightning from the hammer (e.g. X, F, G, T)", delegate(string _, string v)
			{
				//IL_0044: 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)
				if (Enum.TryParse<KeyCode>(v, ignoreCase: true, out KeyCode result2))
				{
					LightningKey = result2;
				}
				else
				{
					((MelonBase)this).LoggerInstance.Warning($"Invalid lightning key '{v}', keeping {LightningKey}");
				}
			});
			if (Enum.TryParse<KeyCode>(text, ignoreCase: true, out KeyCode result))
			{
				LightningKey = result;
			}
			else
			{
				((MelonBase)this).LoggerInstance.Warning("Invalid lightning key '" + text + "', defaulting to X");
			}
			MelonPreferences_Category obj = MelonPreferences.CreateCategory("Mjolnir - Shop", "Mjolnir Shop");
			_priceEntry = obj.CreateEntry<float>("Price", 10000f, "Shop Price", "Price of Mjolnir at the Arms Dealer (in dollars)", false, false, (ValueValidator)null, (string)null);
			((MelonEventBase<LemonAction<float, float>>)(object)_priceEntry.OnEntryValueChanged).Subscribe((LemonAction<float, float>)delegate(float _, float v)
			{
				OnPriceChanged(v);
			}, 0, false);
			_sellAtHardwareEntry = obj.CreateEntry<bool>("SellAtHardwareStores", false, "Sell at Hardware Stores", "Whether Mjolnir is also sold at hardware stores (Handy Hank's, Dan's)", false, false, (ValueValidator)null, (string)null);
			((MelonEventBase<LemonAction<bool, bool>>)(object)_sellAtHardwareEntry.OnEntryValueChanged).Subscribe((LemonAction<bool, bool>)delegate(bool _, bool v)
			{
				OnHardwareShopToggled(v);
			}, 0, false);
			MelonPreferences_Category cat = MelonPreferences.CreateCategory("Mjolnir - Combat", "Mjolnir Combat");
			MeleeDamage = BindEntry(cat, "MeleeDamage", 25f, "Melee Damage", "Damage dealt by a melee swing", delegate(float _, float v)
			{
				MeleeDamage = v;
			});
			MeleeForce = BindEntry(cat, "MeleeForce", 350f, "Melee Force", "Impact force of a melee swing", delegate(float _, float v)
			{
				MeleeForce = v;
			});
			ThrowDamage = BindEntry(cat, "ThrowDamage", 100f, "Throw Damage", "Damage dealt when the thrown hammer hits", delegate(float _, float v)
			{
				ThrowDamage = v;
			});
			ThrowForce = BindEntry(cat, "ThrowForce", 600f, "Throw Force", "Impact force of the thrown hammer", delegate(float _, float v)
			{
				ThrowForce = v;
			});
			LightningDamage = BindEntry(cat, "LightningDamage", 80f, "Lightning Damage", "Damage dealt by a lightning zap", delegate(float _, float v)
			{
				LightningDamage = v;
			});
			LightningForce = BindEntry(cat, "LightningForce", 400f, "Lightning Force", "Impact force of a lightning zap", delegate(float _, float v)
			{
				LightningForce = v;
			});
			LightningPanicRadius = BindEntry(cat, "LightningPanicRadius", 25f, "Lightning Panic Radius", "Radius around lightning strikes that causes nearby NPCs to panic (0 to disable)", delegate(float _, float v)
			{
				LightningPanicRadius = v;
			});
			MelonPreferences_Category cat2 = MelonPreferences.CreateCategory("Mjolnir - Mechanics", "Mjolnir Mechanics");
			FlightSpeed = BindEntry(cat2, "FlightSpeed", 18f, "Flight Speed", "How fast you fly while holding Space during a charged wind-up", delegate(float _, float v)
			{
				FlightSpeed = v;
			});
			ThrowSpeed = BindEntry(cat2, "ThrowSpeed", 40f, "Throw Speed", "How fast the thrown hammer travels", delegate(float _, float v)
			{
				ThrowSpeed = v;
			});
			MaxThrowRange = BindEntry(cat2, "MaxThrowRange", 30f, "Max Throw Range", "Maximum distance the hammer can travel before returning", delegate(float _, float v)
			{
				MaxThrowRange = v;
			});
			WindUpDuration = Math.Max(0.1f, BindEntry(cat2, "WindUpDuration", 1.2f, "Wind-Up Duration", "Seconds to fully charge the hammer spin (minimum 0.1)", delegate(float _, float v)
			{
				WindUpDuration = Math.Max(0.1f, v);
			}));
			MelonPreferences_Category cat3 = MelonPreferences.CreateCategory("Mjolnir - Stamina", "Mjolnir Stamina");
			StaminaEnabled = BindEntry(cat3, "StaminaEnabled", defaultValue: true, "Stamina Enabled", "Whether hammer actions consume stamina", delegate(bool _, bool v)
			{
				StaminaEnabled = v;
			});
			SwingStaminaCost = BindEntry(cat3, "SwingStaminaCost", 15f, "Swing Stamina Cost", "Stamina consumed per melee swing", delegate(float _, float v)
			{
				SwingStaminaCost = v;
			});
			LightningStaminaCost = BindEntry(cat3, "LightningStaminaCost", 20f, "Lightning Stamina Cost", "Stamina consumed per lightning zap", delegate(float _, float v)
			{
				LightningStaminaCost = v;
			});
			WindUpStaminaRate = BindEntry(cat3, "WindUpStaminaRate", 20f, "Wind-Up Stamina Rate", "Stamina consumed per second while winding up", delegate(float _, float v)
			{
				WindUpStaminaRate = v;
			});
			FlightStaminaRate = BindEntry(cat3, "FlightStaminaRate", 15f, "Flight Stamina Rate", "Stamina consumed per second while flying", delegate(float _, float v)
			{
				FlightStaminaRate = v;
			});
			((MelonBase)this).LoggerInstance.Msg("Initialized.");
		}

		public override void OnSceneWasInitialized(int buildIndex, string sceneName)
		{
			if (sceneName == "Main" && !_itemsRegistered)
			{
				_itemsRegistered = true;
				RegisterItems();
			}
			if (sceneName == "Main" && !_loadHooked)
			{
				LoadManager instance = Singleton<LoadManager>.Instance;
				if ((Object)(object)instance != (Object)null)
				{
					instance.onLoadComplete.AddListener(UnityAction.op_Implicit((Action)OnGameLoaded));
					_loadHooked = true;
				}
			}
		}

		public override void OnSceneWasUnloaded(int buildIndex, string sceneName)
		{
			if (sceneName == "Main")
			{
				_loadHooked = false;
			}
		}

		private void RegisterItems()
		{
			Equippable val = ItemCreator.CreateEquippableBuilder().CreateEquippable<HammerEquippable>("ThorHammerEquippable").WithInteraction(true, true)
				.Build();
			_hammerDef = (ItemDefinition)(object)ItemCreator.CreateBuilder().WithBasicInfo("thor_hammer", "Mjolnir", "Mjolnir. Whosoever holds this hammer, if they be worthy, shall possess the power of Thor.", (ItemCategory)3).WithStackLimit(1)
				.WithPricing(_priceEntry.Value, 0.5f)
				.WithLegalStatus((LegalStatus)0)
				.WithEquippable(val)
				.Build();
			RenderHammerIcon();
			((MelonBase)this).LoggerInstance.Msg("Mjolnir registered.");
		}

		private void RenderHammerIcon()
		{
			//IL_0420: Unknown result type (might be due to invalid IL or missing references)
			//IL_042f: 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_0041: Expected O, but got Unknown
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Expected O, but got Unknown
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: 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_01bd: 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_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: 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_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0344: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0361: Expected O, but got Unknown
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_038e: Expected O, but got Unknown
			//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_cachedIcon != (Object)null)
			{
				_hammerDef.Icon = _cachedIcon;
				return;
			}
			string iconPath = IconPath;
			if (File.Exists(iconPath))
			{
				try
				{
					byte[] array = File.ReadAllBytes(iconPath);
					Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
					if (ImageConversion.LoadImage(val, Il2CppStructArray<byte>.op_Implicit(array)))
					{
						_cachedIcon = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
						((Object)_cachedIcon).name = "ThorHammerIcon";
						_hammerDef.Icon = _cachedIcon;
						((MelonBase)this).LoggerInstance.Msg("Loaded hammer icon from cache.");
						return;
					}
				}
				catch (Exception ex)
				{
					((MelonBase)this).LoggerInstance.Warning("Failed to load cached icon, re-rendering: " + ex.Message);
				}
			}
			GameObject val2 = null;
			Camera val3 = null;
			RenderTexture val4 = null;
			try
			{
				val2 = new GameObject("TH_IconStage");
				val2.transform.position = new Vector3(0f, 5000f, 0f);
				byte[] array2 = EmbeddedResourceLoader.LoadBytes("ThorHammer.Resources.ThorHammer.glb", Assembly.GetExecutingAssembly());
				if (array2 == null)
				{
					((MelonBase)this).LoggerInstance.Warning("Cannot render icon: GLB resource not found");
					return;
				}
				GameObject val5 = GltfLoader.LoadGlb(array2, (Shader)null);
				if ((Object)(object)val5 == (Object)null)
				{
					((MelonBase)this).LoggerInstance.Warning("Cannot render icon: GLB load failed");
					return;
				}
				val5.transform.SetParent(val2.transform, false);
				val5.transform.localPosition = Vector3.zero;
				val5.transform.localRotation = Quaternion.Euler(0f, 135f, -30f);
				val5.transform.localScale = Vector3.one * 0.5f;
				GameObject val6 = new GameObject("TH_IconLight");
				val6.transform.SetParent(val2.transform, false);
				Light obj = val6.AddComponent<Light>();
				obj.type = (LightType)1;
				obj.color = new Color(1f, 0.97f, 0.92f);
				obj.intensity = 1.2f;
				val6.transform.rotation = Quaternion.Euler(50f, -30f, 0f);
				GameObject val7 = new GameObject("TH_IconFill");
				val7.transform.SetParent(val2.transform, false);
				Light obj2 = val7.AddComponent<Light>();
				obj2.type = (LightType)1;
				obj2.color = new Color(0.8f, 0.85f, 0.95f);
				obj2.intensity = 0.5f;
				val7.transform.rotation = Quaternion.Euler(30f, 150f, 0f);
				GameObject val8 = new GameObject("TH_IconCamera");
				val3 = val8.AddComponent<Camera>();
				val3.orthographic = true;
				val3.orthographicSize = 1.8f;
				val3.nearClipPlane = 0.01f;
				val3.farClipPlane = 10f;
				val3.clearFlags = (CameraClearFlags)2;
				val3.backgroundColor = new Color(0f, 0f, 0f, 0f);
				val3.cullingMask = -1;
				((Behaviour)val3).enabled = false;
				val8.transform.position = val2.transform.position + new Vector3(-1.5f, 1.5f, 1.5f);
				val8.transform.LookAt(val2.transform.position);
				val4 = new RenderTexture(256, 256, 24, (RenderTextureFormat)0);
				val4.Create();
				val3.targetTexture = val4;
				val3.Render();
				RenderTexture.active = val4;
				Texture2D val9 = new Texture2D(256, 256, (TextureFormat)4, false);
				val9.ReadPixels(new Rect(0f, 0f, 256f, 256f), 0, 0);
				val9.Apply();
				RenderTexture.active = null;
				try
				{
					string directoryName = Path.GetDirectoryName(iconPath);
					if (!Directory.Exists(directoryName))
					{
						Directory.CreateDirectory(directoryName);
					}
					File.WriteAllBytes(iconPath, Il2CppArrayBase<byte>.op_Implicit((Il2CppArrayBase<byte>)(object)ImageConversion.EncodeToPNG(val9)));
				}
				catch (Exception ex2)
				{
					((MelonBase)this).LoggerInstance.Warning("Failed to save icon to disk: " + ex2.Message);
				}
				_cachedIcon = Sprite.Create(val9, new Rect(0f, 0f, 256f, 256f), new Vector2(0.5f, 0.5f), 100f);
				((Object)_cachedIcon).name = "ThorHammerIcon";
				_hammerDef.Icon = _cachedIcon;
				((MelonBase)this).LoggerInstance.Msg("Rendered hammer icon.");
			}
			catch (Exception ex3)
			{
				((MelonBase)this).LoggerInstance.Error("RenderHammerIcon failed: " + ex3.Message + "\n" + ex3.StackTrace);
			}
			finally
			{
				if ((Object)(object)val3 != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)val3).gameObject);
				}
				if ((Object)(object)val4 != (Object)null)
				{
					val4.Release();
					Object.Destroy((Object)(object)val4);
				}
				if ((Object)(object)val2 != (Object)null)
				{
					Object.Destroy((Object)(object)val2);
				}
			}
		}

		private void OnGameLoaded()
		{
			if (!(_hammerDef == (ItemDefinition)null))
			{
				int num = ShopManager.AddToShops(_hammerDef, new string[1] { "Arms Dealer" });
				if (_sellAtHardwareEntry.Value)
				{
					num += ShopManager.AddToShops(_hammerDef, HardwareShopNames);
				}
				_shopsPopulated = true;
				((MelonBase)this).LoggerInstance.Msg($"Mjolnir added to {num} shop(s).");
			}
		}

		private void OnPriceChanged(float newPrice)
		{
			if (_shopsPopulated && !(_hammerDef == (ItemDefinition)null))
			{
				ItemDefinition hammerDef = _hammerDef;
				StorableItemDefinition val = (StorableItemDefinition)(object)((hammerDef is StorableItemDefinition) ? hammerDef : null);
				if (val != null)
				{
					val.BasePurchasePrice = newPrice;
				}
				Shop[] array = ShopManager.FindShopsByItem("thor_hammer");
				foreach (Shop obj in array)
				{
					obj.RemoveItem("thor_hammer");
					obj.AddItem(_hammerDef, (float?)newPrice);
				}
				((MelonBase)this).LoggerInstance.Msg($"Mjolnir price updated to ${newPrice:N0}.");
			}
		}

		private void OnHardwareShopToggled(bool enabled)
		{
			if (!_shopsPopulated || _hammerDef == (ItemDefinition)null)
			{
				return;
			}
			if (enabled)
			{
				int value = ShopManager.AddToShops(_hammerDef, HardwareShopNames);
				((MelonBase)this).LoggerInstance.Msg($"Mjolnir added to {value} hardware shop(s).");
				return;
			}
			string[] hardwareShopNames = HardwareShopNames;
			for (int i = 0; i < hardwareShopNames.Length; i++)
			{
				Shop shopByName = ShopManager.GetShopByName(hardwareShopNames[i]);
				if (shopByName != null && shopByName.HasItem("thor_hammer"))
				{
					shopByName.RemoveItem("thor_hammer");
				}
			}
			((MelonBase)this).LoggerInstance.Msg("Mjolnir removed from hardware shops.");
		}

		private static T BindEntry<T>(MelonPreferences_Category cat, string id, T defaultValue, string displayName, string description, LemonAction<T, T> onChanged)
		{
			MelonPreferences_Entry<T> obj = cat.CreateEntry<T>(id, defaultValue, displayName, description, false, false, (ValueValidator)null, (string)null);
			((MelonEventBase<LemonAction<T, T>>)(object)obj.OnEntryValueChanged).Subscribe(onChanged, 0, false);
			return obj.Value;
		}
	}
	public class HammerEquippable : Equippable_Viewmodel
	{
		private enum HammerState
		{
			Idle,
			WindingUp,
			FlyingOut,
			FlyingBack,
			Flying
		}

		private const float Range = 1.5f;

		private const float HitRadius = 0.3f;

		private const float SwingCooldown = 0.25f;

		private const float SwingDuration = 0.15f;

		private const float SwingAngle = 70f;

		private const float HitTime = 0.06f;

		private const float WindUpMaxSpinSpeed = 5400f;

		private const float AimFOVReduction = 15f;

		private const float AimZoomDuration = 0.2f;

		private const float LightningAimRadius = 0.5f;

		private const float FlightGracePeriod = 0.5f;

		private const float ThrowHitRadius = 0.3f;

		private const float ReturnSpeed = 45f;

		private const float ReturnCatchDistance = 0.5f;

		private const float SpinSpeed = 1440f;

		private HammerState _state;

		private float _cooldownRemaining;

		private bool _isSwinging;

		private float _swingElapsed;

		private bool _hitChecked;

		private GameObject _hammerModel;

		private Quaternion _modelBaseRotation;

		private float _windUpElapsed;

		private bool _fovOverridden;

		private bool _playerCharged;

		private GameObject _projectile;

		private Vector3 _throwDirection;

		private float _throwDistance;

		private float _savedGravityMultiplier = 1f;

		private float _flightStartTime;

		private AudioClip _thunderClip;

		private bool _thunderClipSearched;

		private static float LightningRange => Core.MaxThrowRange * 0.7f;

		public HammerEquippable(IntPtr ptr)
			: base(ptr)
		{
		}

		public override void Equip(ItemInstance item)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Invalid comparison between Unknown and I4
			((Component)this).gameObject.SetActive(true);
			((Equippable_Viewmodel)this).localPosition = new Vector3(0.35f, -0.3f, 0.5f);
			((Equippable_Viewmodel)this).localEulerAngles = new Vector3(0f, 0f, 0f);
			((Equippable_Viewmodel)this).localScale = Vector3.one;
			LoadHammerModel();
			((Equippable)this).itemInstance = item;
			PlayerSingleton<PlayerInventory>.Instance.SetEquippable((Equippable)(object)this);
			PlayerSingleton<PlayerInventory>.Instance.EquippedSlotChanged();
			((Component)this).transform.localPosition = ((Equippable_Viewmodel)this).localPosition;
			((Component)this).transform.localEulerAngles = ((Equippable_Viewmodel)this).localEulerAngles;
			((Component)this).transform.localScale = ((Equippable_Viewmodel)this).localScale;
			LayerUtility.SetLayerRecursively(((Component)this).gameObject, LayerMask.NameToLayer("Viewmodel"));
			foreach (MeshRenderer componentsInChild in ((Component)this).gameObject.GetComponentsInChildren<MeshRenderer>(true))
			{
				if ((int)((Renderer)componentsInChild).shadowCastingMode == 3)
				{
					((Renderer)componentsInChild).enabled = false;
				}
				else
				{
					((Renderer)componentsInChild).shadowCastingMode = (ShadowCastingMode)0;
				}
			}
		}

		public override void Unequip()
		{
			if (_state == HammerState.Flying)
			{
				StopFlight();
			}
			if (_state == HammerState.WindingUp)
			{
				CancelWindUp();
			}
			CleanupThrow();
			ClearPlayerCharged();
			PlayerSingleton<PlayerInventory>.Instance.SetEquippable((Equippable)null);
			PlayerSingleton<PlayerInventory>.Instance.EquippedSlotChanged();
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}

		private void LoadHammerModel()
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: 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)
			byte[] array = EmbeddedResourceLoader.LoadBytes("ThorHammer.Resources.ThorHammer.glb", Assembly.GetExecutingAssembly());
			if (array == null)
			{
				Melon<Core>.Logger.Error("Failed to load ThorHammer.glb from embedded resources");
				return;
			}
			_hammerModel = GltfLoader.LoadGlb(array, (Shader)null);
			if ((Object)(object)_hammerModel == (Object)null)
			{
				Melon<Core>.Logger.Error("GltfLoader.LoadGlb returned null");
				return;
			}
			_hammerModel.transform.SetParent(((Component)this).transform, false);
			_hammerModel.transform.localPosition = new Vector3(0.02f, -0.15f, 0.05f);
			_hammerModel.transform.localRotation = Quaternion.Euler(0f, 90f, 0f);
			_hammerModel.transform.localScale = Vector3.one * 0.08f;
			_modelBaseRotation = _hammerModel.transform.localRotation;
		}

		public override void Update()
		{
			if (_cooldownRemaining > 0f)
			{
				_cooldownRemaining -= Time.deltaTime;
			}
			switch (_state)
			{
			case HammerState.Idle:
				UpdateSwingAnimation();
				UpdateIdle();
				break;
			case HammerState.WindingUp:
				UpdateWindUp();
				break;
			case HammerState.FlyingOut:
				UpdateFlyingOut();
				break;
			case HammerState.FlyingBack:
				UpdateFlyingBack();
				break;
			case HammerState.Flying:
				UpdateFlying();
				break;
			}
		}

		private void UpdateIdle()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			bool flag = !GameInput.IsTyping && PlayerSingleton<PlayerCamera>.Instance.activeUIElementCount == 0;
			if (flag && GameInput.GetButtonDown((ButtonCode)1))
			{
				StartWindUp();
				return;
			}
			if (flag && Input.GetKeyDown(Core.LightningKey))
			{
				if (Core.StaminaEnabled && PlayerSingleton<PlayerMovement>.Instance.CurrentStaminaReserve < Core.LightningStaminaCost)
				{
					return;
				}
				if (Core.StaminaEnabled)
				{
					PlayerSingleton<PlayerMovement>.Instance.ChangeStamina(0f - Core.LightningStaminaCost, true);
				}
				TryLightningZap();
			}
			if (flag && !_isSwinging && _cooldownRemaining <= 0f && GameInput.GetButtonDown((ButtonCode)0) && (!Core.StaminaEnabled || !(PlayerSingleton<PlayerMovement>.Instance.CurrentStaminaReserve < Core.SwingStaminaCost)))
			{
				if (Core.StaminaEnabled)
				{
					PlayerSingleton<PlayerMovement>.Instance.ChangeStamina(0f - Core.SwingStaminaCost, true);
				}
				StartSwing();
			}
		}

		private void StartSwing()
		{
			_isSwinging = true;
			_swingElapsed = 0f;
			_hitChecked = false;
			_cooldownRemaining = 0.25f;
		}

		private void UpdateSwingAnimation()
		{
			//IL_0085: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			if (!_isSwinging || (Object)(object)_hammerModel == (Object)null)
			{
				return;
			}
			_swingElapsed += Time.deltaTime;
			float num = _swingElapsed / 0.15f;
			if (num >= 1f)
			{
				_isSwinging = false;
				_hammerModel.transform.localRotation = _modelBaseRotation;
				return;
			}
			float num2 = Mathf.Sin(num * (float)Math.PI) * 70f;
			_hammerModel.transform.localRotation = Quaternion.Euler(num2, 0f, 0f) * _modelBaseRotation;
			if (!_hitChecked && _swingElapsed >= 0.06f)
			{
				_hitChecked = true;
				ExecuteMeleeHit();
			}
		}

		private void ExecuteMeleeHit()
		{
			//IL_0011: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			RaycastHit val = default(RaycastHit);
			if (!PlayerSingleton<PlayerCamera>.Instance.LookRaycast(1.5f, ref val, NetworkSingleton<CombatManager>.Instance.MeleeLayerMask, true, 0.3f))
			{
				return;
			}
			IDamageable componentInParent = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<IDamageable>();
			if (componentInParent != null)
			{
				float meleeForce = Core.MeleeForce;
				Impact val2 = new Impact(((RaycastHit)(ref val)).point, ((Component)PlayerSingleton<PlayerCamera>.Instance).transform.forward, meleeForce, Core.MeleeDamage, (EImpactType)1, ((NetworkBehaviour)Player.Local).NetworkObject, Random.Range(int.MinValue, int.MaxValue));
				componentInParent.SendImpact(val2);
				Singleton<FXManager>.Instance.CreateImpactFX(val2, componentInParent);
				PlayerSingleton<PlayerCamera>.Instance.StartCameraShake(0.3f, 0.2f, true);
				NPC componentInParent2 = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<NPC>();
				if ((Object)(object)componentInParent2 != (Object)null)
				{
					StrikeLightningOnNPC(componentInParent2);
					((EntityVisibility)Player.Local.VisualState).ApplyState("melee_attack", (EVisualState)9, 2.5f);
				}
			}
		}

		private void StartWindUp()
		{
			_state = HammerState.WindingUp;
			_windUpElapsed = 0f;
			_isSwinging = false;
			PlayerSingleton<PlayerMovement>.Instance.CanJump = false;
			float num = Singleton<Settings>.Instance.CameraFOV - 15f;
			PlayerSingleton<PlayerCamera>.Instance.OverrideFOV(num, 0.2f);
			_fovOverridden = true;
		}

		private void UpdateWindUp()
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			_windUpElapsed += Time.deltaTime;
			bool flag = _windUpElapsed >= Core.WindUpDuration;
			if (Core.StaminaEnabled)
			{
				PlayerSingleton<PlayerMovement>.Instance.ChangeStamina((0f - Core.WindUpStaminaRate) * Time.deltaTime, true);
				if (PlayerSingleton<PlayerMovement>.Instance.CurrentStaminaReserve <= 0f)
				{
					CancelWindUp();
					return;
				}
			}
			float num = Mathf.Clamp01(_windUpElapsed / Core.WindUpDuration);
			float num2 = num * num * 5400f;
			if ((Object)(object)_hammerModel != (Object)null)
			{
				_hammerModel.transform.Rotate(Vector3.forward, num2 * Time.deltaTime, (Space)1);
			}
			if (flag && !_playerCharged)
			{
				_playerCharged = true;
				Electrifying.ApplyToAvatar(Player.Local.Avatar);
			}
			if (!GameInput.GetButton((ButtonCode)1))
			{
				if (flag)
				{
					StartThrow();
				}
				else
				{
					CancelWindUp();
				}
			}
			else if (flag && GameInput.GetButton((ButtonCode)7))
			{
				StartFlight();
			}
		}

		private void CancelWindUp()
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			_state = HammerState.Idle;
			_windUpElapsed = 0f;
			PlayerSingleton<PlayerMovement>.Instance.CanJump = true;
			ClearPlayerCharged();
			if (_fovOverridden)
			{
				PlayerSingleton<PlayerCamera>.Instance.StopFOVOverride(0.2f);
				_fovOverridden = false;
			}
			if ((Object)(object)_hammerModel != (Object)null)
			{
				_hammerModel.transform.localRotation = _modelBaseRotation;
			}
		}

		private void ClearPlayerCharged()
		{
			if (_playerCharged)
			{
				_playerCharged = false;
				Electrifying.ClearFromAvatar(Player.Local.Avatar);
			}
		}

		private void StartThrow()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: 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_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_00f6: 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_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: 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)
			PlayerSingleton<PlayerMovement>.Instance.CanJump = true;
			ClearPlayerCharged();
			if (_fovOverridden)
			{
				PlayerSingleton<PlayerCamera>.Instance.StopFOVOverride(0.2f);
				_fovOverridden = false;
			}
			if (!((Object)(object)_hammerModel == (Object)null))
			{
				_hammerModel.transform.localRotation = _modelBaseRotation;
				_hammerModel.SetActive(false);
				_projectile = Object.Instantiate<GameObject>(_hammerModel);
				_projectile.SetActive(true);
				_projectile.transform.SetParent((Transform)null, false);
				SetLayerRecursive(_projectile, 0);
				Transform transform = ((Component)PlayerSingleton<PlayerCamera>.Instance).transform;
				_projectile.transform.position = transform.position + transform.forward * 1f;
				_projectile.transform.rotation = Quaternion.LookRotation(transform.forward) * Quaternion.Euler(0f, 90f, 0f);
				_projectile.transform.localScale = Vector3.one * 0.08f;
				_throwDirection = transform.forward;
				_throwDistance = 0f;
				_state = HammerState.FlyingOut;
			}
		}

		private void UpdateFlyingOut()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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_004c: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_projectile == (Object)null)
			{
				CatchHammer();
				return;
			}
			float num = Core.ThrowSpeed * Time.deltaTime;
			_throwDistance += num;
			Transform transform = _projectile.transform;
			transform.position += _throwDirection * num;
			_projectile.transform.Rotate(Vector3.forward, 1440f * Time.deltaTime, (Space)1);
			RaycastHit hit = default(RaycastHit);
			if (Physics.SphereCast(_projectile.transform.position - _throwDirection * num, 0.3f, _throwDirection, ref hit, num, LayerMask.op_Implicit(NetworkSingleton<CombatManager>.Instance.MeleeLayerMask), (QueryTriggerInteraction)2))
			{
				ExecuteThrowHit(hit);
				_state = HammerState.FlyingBack;
			}
			else if (_throwDistance >= Core.MaxThrowRange)
			{
				_state = HammerState.FlyingBack;
			}
		}

		private void UpdateFlyingBack()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//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_005c: 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_0063: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_projectile == (Object)null)
			{
				CatchHammer();
				return;
			}
			Vector3 position = ((Component)PlayerSingleton<PlayerCamera>.Instance).transform.position;
			Vector3 val = position - _projectile.transform.position;
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			float num = 45f * Time.deltaTime;
			Transform transform = _projectile.transform;
			transform.position += normalized * num;
			_projectile.transform.Rotate(Vector3.forward, 1440f * Time.deltaTime, (Space)1);
			if (Vector3.Distance(_projectile.transform.position, position) < 0.5f)
			{
				CatchHammer();
			}
		}

		private void ExecuteThrowHit(RaycastHit hit)
		{
			//IL_0012: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			IDamageable componentInParent = ((Component)((RaycastHit)(ref hit)).collider).GetComponentInParent<IDamageable>();
			if (componentInParent != null)
			{
				Impact val = new Impact(((RaycastHit)(ref hit)).point, _throwDirection, Core.ThrowForce, Core.ThrowDamage, (EImpactType)1, ((NetworkBehaviour)Player.Local).NetworkObject, Random.Range(int.MinValue, int.MaxValue));
				componentInParent.SendImpact(val);
				Singleton<FXManager>.Instance.CreateImpactFX(val, componentInParent);
			}
			NPC componentInParent2 = ((Component)((RaycastHit)(ref hit)).collider).GetComponentInParent<NPC>();
			if ((Object)(object)componentInParent2 != (Object)null)
			{
				StrikeLightningOnNPC(componentInParent2);
				((EntityVisibility)Player.Local.VisualState).ApplyState("melee_attack", (EVisualState)9, 2.5f);
			}
			PlayerSingleton<PlayerCamera>.Instance.StartCameraShake(0.5f, 0.3f, true);
		}

		private void CatchHammer()
		{
			if ((Object)(object)_projectile != (Object)null)
			{
				Object.Destroy((Object)(object)_projectile);
				_projectile = null;
			}
			if ((Object)(object)_hammerModel != (Object)null)
			{
				_hammerModel.SetActive(true);
			}
			_state = HammerState.Idle;
		}

		private void CleanupThrow()
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_projectile != (Object)null)
			{
				Object.Destroy((Object)(object)_projectile);
				_projectile = null;
			}
			if (_fovOverridden)
			{
				PlayerSingleton<PlayerCamera>.Instance.StopFOVOverride(0f);
				_fovOverridden = false;
			}
			if ((Object)(object)_hammerModel != (Object)null)
			{
				_hammerModel.SetActive(true);
				_hammerModel.transform.localRotation = _modelBaseRotation;
			}
			_state = HammerState.Idle;
		}

		private void TryLightningZap()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: 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_006a: 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_009a: Expected O, but got Unknown
			PlayerCamera instance = PlayerSingleton<PlayerCamera>.Instance;
			NPC val = null;
			RaycastHit val2 = default(RaycastHit);
			Vector3 position;
			if (instance.LookRaycast(LightningRange, ref val2, NetworkSingleton<CombatManager>.Instance.MeleeLayerMask, true, 0.5f))
			{
				position = ((RaycastHit)(ref val2)).point;
				val = ((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<NPC>();
				if ((Object)(object)val != (Object)null)
				{
					IDamageable componentInParent = ((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<IDamageable>();
					if (componentInParent != null)
					{
						Impact val3 = new Impact(((RaycastHit)(ref val2)).point, ((Component)instance).transform.forward, Core.LightningForce, Core.LightningDamage, (EImpactType)1, ((NetworkBehaviour)Player.Local).NetworkObject, Random.Range(int.MinValue, int.MaxValue));
						componentInParent.SendImpact(val3);
					}
					Electrifying.ApplyToAvatar(val.Avatar);
				}
			}
			else
			{
				position = ((Component)instance).transform.position + ((Component)instance).transform.forward * LightningRange;
			}
			LightningHelper.StrikeLightning(position);
			if ((Object)(object)val != (Object)null)
			{
				MelonCoroutines.Start(LightningHelper.ClearElectrifyCoroutine(val));
			}
			PlayThunderSound(position);
			EmitLightningNoise(position);
			((EntityVisibility)Player.Local.VisualState).ApplyState("melee_attack", (EVisualState)9, 2.5f);
			PlayerSingleton<PlayerCamera>.Instance.StartCameraShake(0.5f, 0.3f, true);
		}

		private void StrikeLightningOnNPC(NPC npc)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)npc).transform.position;
			LightningHelper.StrikeLightning(position);
			MelonCoroutines.Start(LightningHelper.ClearElectrifyCoroutine(npc));
			Electrifying.ApplyToAvatar(npc.Avatar);
			PlayThunderSound(position);
			EmitLightningNoise(position);
		}

		private static void EmitLightningNoise(Vector3 position)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			if (Core.LightningPanicRadius > 0f)
			{
				NoiseUtility.EmitNoise(position, (ENoiseType)2, Core.LightningPanicRadius, ((Component)Player.Local).gameObject);
			}
		}

		private void PlayThunderSound(Vector3 position)
		{
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			if (!_thunderClipSearched)
			{
				_thunderClipSearched = true;
				ThunderController val = Object.FindObjectOfType<ThunderController>();
				if ((Object)(object)val == (Object)null)
				{
					Il2CppArrayBase<ThunderController> val2 = Resources.FindObjectsOfTypeAll<ThunderController>();
					if (val2.Length > 0)
					{
						val = val2[0];
					}
				}
				if ((Object)(object)val != (Object)null)
				{
					try
					{
						RandomizedAudioSourceController lightningAudio = val._lightningAudio;
						if ((Object)(object)lightningAudio != (Object)null && lightningAudio.Clips != null && ((Il2CppArrayBase<AudioClip>)(object)lightningAudio.Clips).Count > 0)
						{
							_thunderClip = ((Il2CppArrayBase<AudioClip>)(object)lightningAudio.Clips)[0];
						}
					}
					catch
					{
					}
				}
				if ((Object)(object)_thunderClip == (Object)null)
				{
					try
					{
						foreach (AudioClip item in Resources.FindObjectsOfTypeAll<AudioClip>())
						{
							if (!((Object)(object)item == (Object)null))
							{
								string text = ((Object)item).name.ToLowerInvariant();
								if (text.Contains("thunder") || text.Contains("lightning"))
								{
									_thunderClip = item;
									break;
								}
							}
						}
					}
					catch
					{
					}
				}
				if ((Object)(object)_thunderClip != (Object)null)
				{
					Melon<Core>.Logger.Msg("Thunder sound found: " + ((Object)_thunderClip).name);
				}
				else
				{
					Melon<Core>.Logger.Warning("No thunder/lightning AudioClip found in game assets");
				}
			}
			if ((Object)(object)_thunderClip != (Object)null)
			{
				AudioSource.PlayClipAtPoint(_thunderClip, position, 1f);
			}
		}

		private void StartFlight()
		{
			//IL_004f: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			if (_fovOverridden)
			{
				PlayerSingleton<PlayerCamera>.Instance.StopFOVOverride(0.2f);
				_fovOverridden = false;
			}
			_state = HammerState.Flying;
			_flightStartTime = Time.time;
			_savedGravityMultiplier = PlayerMovement.GravityMultiplier;
			PlayerMovement.GravityMultiplier = 0f;
			PlayerSingleton<PlayerMovement>.Instance.Controller.Move(Vector3.up * 0.5f);
			if ((Object)(object)_hammerModel != (Object)null)
			{
				_hammerModel.transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
			}
		}

		private void UpdateFlying()
		{
			//IL_0046: 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_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)
			Transform transform = ((Component)PlayerSingleton<PlayerCamera>.Instance).transform;
			PlayerMovement instance = PlayerSingleton<PlayerMovement>.Instance;
			if (Core.StaminaEnabled)
			{
				instance.ChangeStamina((0f - Core.FlightStaminaRate) * Time.deltaTime, true);
				if (instance.CurrentStaminaReserve <= 0f)
				{
					StopFlight();
					return;
				}
			}
			instance.Controller.Move(transform.forward * Core.FlightSpeed * Time.deltaTime);
			bool flag = Time.time - _flightStartTime > 0.5f;
			if (!GameInput.GetButton((ButtonCode)7) || (flag && instance.IsGrounded))
			{
				StopFlight();
			}
		}

		private void StopFlight()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			_state = HammerState.Idle;
			PlayerMovement.GravityMultiplier = _savedGravityMultiplier;
			PlayerSingleton<PlayerMovement>.Instance.CanJump = true;
			ClearPlayerCharged();
			if ((Object)(object)_hammerModel != (Object)null)
			{
				_hammerModel.transform.localRotation = _modelBaseRotation;
			}
		}

		private static void SetLayerRecursive(GameObject go, int layer)
		{
			go.layer = layer;
			for (int i = 0; i < go.transform.childCount; i++)
			{
				SetLayerRecursive(((Component)go.transform.GetChild(i)).gameObject, layer);
			}
		}
	}
	internal static class LightningHelper
	{
		[CompilerGenerated]
		private sealed class <ClearElectrifyCoroutine>d__2 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public NPC npc;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <ClearElectrifyCoroutine>d__2(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(4f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					if ((Object)(object)npc != (Object)null && (Object)(object)npc.Avatar != (Object)null)
					{
						Electrifying.ClearFromAvatar(npc.Avatar);
					}
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private static VFXEffectHandler _lightningVFX;

		private static bool _searched;

		[IteratorStateMachine(typeof(<ClearElectrifyCoroutine>d__2))]
		internal static IEnumerator ClearElectrifyCoroutine(NPC npc)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <ClearElectrifyCoroutine>d__2(0)
			{
				npc = npc
			};
		}

		internal static void StrikeLightning(Vector3 position)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			EnsureVFX();
			if (!((Object)(object)_lightningVFX == (Object)null))
			{
				((EffectHandler)_lightningVFX).SetPosition(position);
				((EffectHandler)_lightningVFX).Activate();
				((EffectHandler)_lightningVFX).DelayDeactivate(2f, (Action)null);
			}
		}

		private static void EnsureVFX()
		{
			if (_searched)
			{
				return;
			}
			_searched = true;
			Il2CppArrayBase<ThunderController> val = Resources.FindObjectsOfTypeAll<ThunderController>();
			ThunderController val2 = ((val.Length > 0) ? val[0] : null);
			if ((Object)(object)val2 == (Object)null)
			{
				Melon<Core>.Logger.Warning("No ThunderController found — lightning VFX unavailable");
				return;
			}
			VFXEffectHandler val3 = null;
			val3 = val2._lightningEffect;
			if ((Object)(object)val3 == (Object)null && ((WeatherEffectController)val2).visualEffects != null)
			{
				Enumerator<VFXEffectHandler> enumerator = ((WeatherEffectController)val2).visualEffects.GetEnumerator();
				while (enumerator.MoveNext())
				{
					VFXEffectHandler current = enumerator.Current;
					if ((Object)(object)current != (Object)null && ((EffectHandler)current).Id == "Lightning")
					{
						val3 = current;
						break;
					}
				}
			}
			if ((Object)(object)val3 == (Object)null)
			{
				Melon<Core>.Logger.Warning("No lightning VFX found on ThunderController");
				return;
			}
			GameObject val4 = Object.Instantiate<GameObject>(((Component)val3).gameObject);
			((Object)val4).name = "ThorLightningVFX";
			val4.SetActive(true);
			Object.DontDestroyOnLoad((Object)(object)val4);
			_lightningVFX = val4.GetComponent<VFXEffectHandler>();
			if ((Object)(object)_lightningVFX != (Object)null)
			{
				((EffectHandler)_lightningVFX).Deactivate();
				Melon<Core>.Logger.Msg("Cloned game lightning VFX for ThorHammer.");
			}
			else
			{
				Melon<Core>.Logger.Warning("Cloned lightning VFX has no VFXEffectHandler component");
				Object.Destroy((Object)(object)val4);
			}
		}
	}
}

ThorHammer.Mono.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using FishNet.Object;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using S1API.Items;
using S1API.Shops;
using S1MAPI.Gltf;
using S1MAPI.Utils;
using ScheduleOne;
using ScheduleOne.Audio;
using ScheduleOne.Combat;
using ScheduleOne.DevUtilities;
using ScheduleOne.Effects;
using ScheduleOne.Equipping;
using ScheduleOne.FX;
using ScheduleOne.ItemFramework;
using ScheduleOne.NPCs;
using ScheduleOne.Noise;
using ScheduleOne.Persistence;
using ScheduleOne.PlayerScripts;
using ScheduleOne.Vision;
using ScheduleOne.Weather;
using ThorHammer;
using UnityEngine;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Core), "Mjolnir", "1.0.4", "hdlmrell", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ThorHammer.Mono")]
[assembly: AssemblyConfiguration("MonoRelease")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.0+ea2da1c6208f6f22b4b7396e9dab0a1eb1fb605e")]
[assembly: AssemblyProduct("ThorHammer.Mono")]
[assembly: AssemblyTitle("ThorHammer.Mono")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 ThorHammer
{
	public class Core : MelonMod
	{
		private bool _itemsRegistered;

		private bool _loadHooked;

		private static ItemDefinition _hammerDef;

		private static Sprite _cachedIcon;

		private static readonly string[] HardwareShopNames = new string[2] { "Handy Hank's Hardware", "Dan's Hardware" };

		private static MelonPreferences_Entry<float> _priceEntry;

		private static MelonPreferences_Entry<bool> _sellAtHardwareEntry;

		private static bool _shopsPopulated;

		public static KeyCode LightningKey { get; private set; } = (KeyCode)120;


		public static float MeleeDamage { get; private set; } = 25f;


		public static float MeleeForce { get; private set; } = 350f;


		public static float ThrowDamage { get; private set; } = 100f;


		public static float ThrowForce { get; private set; } = 600f;


		public static float LightningDamage { get; private set; } = 80f;


		public static float LightningForce { get; private set; } = 400f;


		public static float LightningPanicRadius { get; private set; } = 25f;


		public static float FlightSpeed { get; private set; } = 18f;


		public static float ThrowSpeed { get; private set; } = 40f;


		public static float MaxThrowRange { get; private set; } = 30f;


		public static float WindUpDuration { get; private set; } = 1.2f;


		public static bool StaminaEnabled { get; private set; } = true;


		public static float SwingStaminaCost { get; private set; } = 15f;


		public static float LightningStaminaCost { get; private set; } = 20f;


		public static float WindUpStaminaRate { get; private set; } = 20f;


		public static float FlightStaminaRate { get; private set; } = 15f;


		private static string IconPath => Path.Combine(MelonEnvironment.UserDataDirectory, "S1API", "Icons", "ThorHammer.png");

		public override void OnInitializeMelon()
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			MelonPreferences_Category cat = MelonPreferences.CreateCategory("Mjolnir - Controls", "Mjolnir Controls");
			string text = BindEntry(cat, "LightningKey", "X", "Lightning Key", "Key to summon lightning from the hammer (e.g. X, F, G, T)", delegate(string _, string v)
			{
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				if (Enum.TryParse<KeyCode>(v, ignoreCase: true, out KeyCode result2))
				{
					LightningKey = result2;
				}
				else
				{
					((MelonBase)this).LoggerInstance.Warning($"Invalid lightning key '{v}', keeping {LightningKey}");
				}
			});
			if (Enum.TryParse<KeyCode>(text, ignoreCase: true, out KeyCode result))
			{
				LightningKey = result;
			}
			else
			{
				((MelonBase)this).LoggerInstance.Warning("Invalid lightning key '" + text + "', defaulting to X");
			}
			MelonPreferences_Category val = MelonPreferences.CreateCategory("Mjolnir - Shop", "Mjolnir Shop");
			_priceEntry = val.CreateEntry<float>("Price", 10000f, "Shop Price", "Price of Mjolnir at the Arms Dealer (in dollars)", false, false, (ValueValidator)null, (string)null);
			((MelonEventBase<LemonAction<float, float>>)(object)_priceEntry.OnEntryValueChanged).Subscribe((LemonAction<float, float>)delegate(float _, float v)
			{
				OnPriceChanged(v);
			}, 0, false);
			_sellAtHardwareEntry = val.CreateEntry<bool>("SellAtHardwareStores", false, "Sell at Hardware Stores", "Whether Mjolnir is also sold at hardware stores (Handy Hank's, Dan's)", false, false, (ValueValidator)null, (string)null);
			((MelonEventBase<LemonAction<bool, bool>>)(object)_sellAtHardwareEntry.OnEntryValueChanged).Subscribe((LemonAction<bool, bool>)delegate(bool _, bool v)
			{
				OnHardwareShopToggled(v);
			}, 0, false);
			MelonPreferences_Category cat2 = MelonPreferences.CreateCategory("Mjolnir - Combat", "Mjolnir Combat");
			MeleeDamage = BindEntry(cat2, "MeleeDamage", 25f, "Melee Damage", "Damage dealt by a melee swing", delegate(float _, float v)
			{
				MeleeDamage = v;
			});
			MeleeForce = BindEntry(cat2, "MeleeForce", 350f, "Melee Force", "Impact force of a melee swing", delegate(float _, float v)
			{
				MeleeForce = v;
			});
			ThrowDamage = BindEntry(cat2, "ThrowDamage", 100f, "Throw Damage", "Damage dealt when the thrown hammer hits", delegate(float _, float v)
			{
				ThrowDamage = v;
			});
			ThrowForce = BindEntry(cat2, "ThrowForce", 600f, "Throw Force", "Impact force of the thrown hammer", delegate(float _, float v)
			{
				ThrowForce = v;
			});
			LightningDamage = BindEntry(cat2, "LightningDamage", 80f, "Lightning Damage", "Damage dealt by a lightning zap", delegate(float _, float v)
			{
				LightningDamage = v;
			});
			LightningForce = BindEntry(cat2, "LightningForce", 400f, "Lightning Force", "Impact force of a lightning zap", delegate(float _, float v)
			{
				LightningForce = v;
			});
			LightningPanicRadius = BindEntry(cat2, "LightningPanicRadius", 25f, "Lightning Panic Radius", "Radius around lightning strikes that causes nearby NPCs to panic (0 to disable)", delegate(float _, float v)
			{
				LightningPanicRadius = v;
			});
			MelonPreferences_Category cat3 = MelonPreferences.CreateCategory("Mjolnir - Mechanics", "Mjolnir Mechanics");
			FlightSpeed = BindEntry(cat3, "FlightSpeed", 18f, "Flight Speed", "How fast you fly while holding Space during a charged wind-up", delegate(float _, float v)
			{
				FlightSpeed = v;
			});
			ThrowSpeed = BindEntry(cat3, "ThrowSpeed", 40f, "Throw Speed", "How fast the thrown hammer travels", delegate(float _, float v)
			{
				ThrowSpeed = v;
			});
			MaxThrowRange = BindEntry(cat3, "MaxThrowRange", 30f, "Max Throw Range", "Maximum distance the hammer can travel before returning", delegate(float _, float v)
			{
				MaxThrowRange = v;
			});
			WindUpDuration = Math.Max(0.1f, BindEntry(cat3, "WindUpDuration", 1.2f, "Wind-Up Duration", "Seconds to fully charge the hammer spin (minimum 0.1)", delegate(float _, float v)
			{
				WindUpDuration = Math.Max(0.1f, v);
			}));
			MelonPreferences_Category cat4 = MelonPreferences.CreateCategory("Mjolnir - Stamina", "Mjolnir Stamina");
			StaminaEnabled = BindEntry(cat4, "StaminaEnabled", defaultValue: true, "Stamina Enabled", "Whether hammer actions consume stamina", delegate(bool _, bool v)
			{
				StaminaEnabled = v;
			});
			SwingStaminaCost = BindEntry(cat4, "SwingStaminaCost", 15f, "Swing Stamina Cost", "Stamina consumed per melee swing", delegate(float _, float v)
			{
				SwingStaminaCost = v;
			});
			LightningStaminaCost = BindEntry(cat4, "LightningStaminaCost", 20f, "Lightning Stamina Cost", "Stamina consumed per lightning zap", delegate(float _, float v)
			{
				LightningStaminaCost = v;
			});
			WindUpStaminaRate = BindEntry(cat4, "WindUpStaminaRate", 20f, "Wind-Up Stamina Rate", "Stamina consumed per second while winding up", delegate(float _, float v)
			{
				WindUpStaminaRate = v;
			});
			FlightStaminaRate = BindEntry(cat4, "FlightStaminaRate", 15f, "Flight Stamina Rate", "Stamina consumed per second while flying", delegate(float _, float v)
			{
				FlightStaminaRate = v;
			});
			((MelonBase)this).LoggerInstance.Msg("Initialized.");
		}

		public override void OnSceneWasInitialized(int buildIndex, string sceneName)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			if (sceneName == "Main" && !_itemsRegistered)
			{
				_itemsRegistered = true;
				RegisterItems();
			}
			if (sceneName == "Main" && !_loadHooked)
			{
				LoadManager instance = Singleton<LoadManager>.Instance;
				if ((Object)(object)instance != (Object)null)
				{
					instance.onLoadComplete.AddListener(new UnityAction(OnGameLoaded));
					_loadHooked = true;
				}
			}
		}

		public override void OnSceneWasUnloaded(int buildIndex, string sceneName)
		{
			if (sceneName == "Main")
			{
				_loadHooked = false;
			}
		}

		private void RegisterItems()
		{
			Equippable val = ItemCreator.CreateEquippableBuilder().CreateEquippable<HammerEquippable>("ThorHammerEquippable").WithInteraction(true, true)
				.Build();
			_hammerDef = (ItemDefinition)(object)ItemCreator.CreateBuilder().WithBasicInfo("thor_hammer", "Mjolnir", "Mjolnir. Whosoever holds this hammer, if they be worthy, shall possess the power of Thor.", (ItemCategory)3).WithStackLimit(1)
				.WithPricing(_priceEntry.Value, 0.5f)
				.WithLegalStatus((LegalStatus)0)
				.WithEquippable(val)
				.Build();
			RenderHammerIcon();
			((MelonBase)this).LoggerInstance.Msg("Mjolnir registered.");
		}

		private void RenderHammerIcon()
		{
			//IL_048e: Unknown result type (might be due to invalid IL or missing references)
			//IL_049d: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Expected O, but got Unknown
			//IL_0125: 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_0052: Expected O, but got Unknown
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Expected O, but got Unknown
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Expected O, but got Unknown
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Expected O, but got Unknown
			//IL_034a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_0386: Unknown result type (might be due to invalid IL or missing references)
			//IL_038b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Expected O, but got Unknown
			//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f1: Expected O, but got Unknown
			//IL_0407: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_cachedIcon != (Object)null)
			{
				_hammerDef.Icon = _cachedIcon;
				return;
			}
			string iconPath = IconPath;
			if (File.Exists(iconPath))
			{
				try
				{
					byte[] array = File.ReadAllBytes(iconPath);
					Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
					if (ImageConversion.LoadImage(val, array))
					{
						_cachedIcon = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
						((Object)_cachedIcon).name = "ThorHammerIcon";
						_hammerDef.Icon = _cachedIcon;
						((MelonBase)this).LoggerInstance.Msg("Loaded hammer icon from cache.");
						return;
					}
				}
				catch (Exception ex)
				{
					((MelonBase)this).LoggerInstance.Warning("Failed to load cached icon, re-rendering: " + ex.Message);
				}
			}
			GameObject val2 = null;
			Camera val3 = null;
			RenderTexture val4 = null;
			try
			{
				val2 = new GameObject("TH_IconStage");
				val2.transform.position = new Vector3(0f, 5000f, 0f);
				byte[] array2 = EmbeddedResourceLoader.LoadBytes("ThorHammer.Resources.ThorHammer.glb", Assembly.GetExecutingAssembly());
				if (array2 == null)
				{
					((MelonBase)this).LoggerInstance.Warning("Cannot render icon: GLB resource not found");
					return;
				}
				GameObject val5 = GltfLoader.LoadGlb(array2, (Shader)null);
				if ((Object)(object)val5 == (Object)null)
				{
					((MelonBase)this).LoggerInstance.Warning("Cannot render icon: GLB load failed");
					return;
				}
				val5.transform.SetParent(val2.transform, false);
				val5.transform.localPosition = Vector3.zero;
				val5.transform.localRotation = Quaternion.Euler(0f, 135f, -30f);
				val5.transform.localScale = Vector3.one * 0.5f;
				GameObject val6 = new GameObject("TH_IconLight");
				val6.transform.SetParent(val2.transform, false);
				Light val7 = val6.AddComponent<Light>();
				val7.type = (LightType)1;
				val7.color = new Color(1f, 0.97f, 0.92f);
				val7.intensity = 1.2f;
				val6.transform.rotation = Quaternion.Euler(50f, -30f, 0f);
				GameObject val8 = new GameObject("TH_IconFill");
				val8.transform.SetParent(val2.transform, false);
				Light val9 = val8.AddComponent<Light>();
				val9.type = (LightType)1;
				val9.color = new Color(0.8f, 0.85f, 0.95f);
				val9.intensity = 0.5f;
				val8.transform.rotation = Quaternion.Euler(30f, 150f, 0f);
				GameObject val10 = new GameObject("TH_IconCamera");
				val3 = val10.AddComponent<Camera>();
				val3.orthographic = true;
				val3.orthographicSize = 1.8f;
				val3.nearClipPlane = 0.01f;
				val3.farClipPlane = 10f;
				val3.clearFlags = (CameraClearFlags)2;
				val3.backgroundColor = new Color(0f, 0f, 0f, 0f);
				val3.cullingMask = -1;
				((Behaviour)val3).enabled = false;
				val10.transform.position = val2.transform.position + new Vector3(-1.5f, 1.5f, 1.5f);
				val10.transform.LookAt(val2.transform.position);
				val4 = new RenderTexture(256, 256, 24, (RenderTextureFormat)0);
				val4.Create();
				val3.targetTexture = val4;
				val3.Render();
				RenderTexture.active = val4;
				Texture2D val11 = new Texture2D(256, 256, (TextureFormat)4, false);
				val11.ReadPixels(new Rect(0f, 0f, 256f, 256f), 0, 0);
				val11.Apply();
				RenderTexture.active = null;
				try
				{
					string directoryName = Path.GetDirectoryName(iconPath);
					if (!Directory.Exists(directoryName))
					{
						Directory.CreateDirectory(directoryName);
					}
					File.WriteAllBytes(iconPath, ImageConversion.EncodeToPNG(val11));
				}
				catch (Exception ex2)
				{
					((MelonBase)this).LoggerInstance.Warning("Failed to save icon to disk: " + ex2.Message);
				}
				_cachedIcon = Sprite.Create(val11, new Rect(0f, 0f, 256f, 256f), new Vector2(0.5f, 0.5f), 100f);
				((Object)_cachedIcon).name = "ThorHammerIcon";
				_hammerDef.Icon = _cachedIcon;
				((MelonBase)this).LoggerInstance.Msg("Rendered hammer icon.");
			}
			catch (Exception ex3)
			{
				((MelonBase)this).LoggerInstance.Error("RenderHammerIcon failed: " + ex3.Message + "\n" + ex3.StackTrace);
			}
			finally
			{
				if ((Object)(object)val3 != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)val3).gameObject);
				}
				if ((Object)(object)val4 != (Object)null)
				{
					val4.Release();
					Object.Destroy((Object)(object)val4);
				}
				if ((Object)(object)val2 != (Object)null)
				{
					Object.Destroy((Object)(object)val2);
				}
			}
		}

		private void OnGameLoaded()
		{
			if (!(_hammerDef == (ItemDefinition)null))
			{
				int num = ShopManager.AddToShops(_hammerDef, new string[1] { "Arms Dealer" });
				if (_sellAtHardwareEntry.Value)
				{
					num += ShopManager.AddToShops(_hammerDef, HardwareShopNames);
				}
				_shopsPopulated = true;
				((MelonBase)this).LoggerInstance.Msg($"Mjolnir added to {num} shop(s).");
			}
		}

		private void OnPriceChanged(float newPrice)
		{
			if (_shopsPopulated && !(_hammerDef == (ItemDefinition)null))
			{
				ItemDefinition hammerDef = _hammerDef;
				StorableItemDefinition val = (StorableItemDefinition)(object)((hammerDef is StorableItemDefinition) ? hammerDef : null);
				if (val != null)
				{
					val.BasePurchasePrice = newPrice;
				}
				Shop[] array = ShopManager.FindShopsByItem("thor_hammer");
				Shop[] array2 = array;
				foreach (Shop val2 in array2)
				{
					val2.RemoveItem("thor_hammer");
					val2.AddItem(_hammerDef, (float?)newPrice);
				}
				((MelonBase)this).LoggerInstance.Msg($"Mjolnir price updated to ${newPrice:N0}.");
			}
		}

		private void OnHardwareShopToggled(bool enabled)
		{
			if (!_shopsPopulated || _hammerDef == (ItemDefinition)null)
			{
				return;
			}
			if (enabled)
			{
				int num = ShopManager.AddToShops(_hammerDef, HardwareShopNames);
				((MelonBase)this).LoggerInstance.Msg($"Mjolnir added to {num} hardware shop(s).");
				return;
			}
			string[] hardwareShopNames = HardwareShopNames;
			foreach (string text in hardwareShopNames)
			{
				Shop shopByName = ShopManager.GetShopByName(text);
				if (shopByName != null && shopByName.HasItem("thor_hammer"))
				{
					shopByName.RemoveItem("thor_hammer");
				}
			}
			((MelonBase)this).LoggerInstance.Msg("Mjolnir removed from hardware shops.");
		}

		private static T BindEntry<T>(MelonPreferences_Category cat, string id, T defaultValue, string displayName, string description, LemonAction<T, T> onChanged)
		{
			MelonPreferences_Entry<T> val = cat.CreateEntry<T>(id, defaultValue, displayName, description, false, false, (ValueValidator)null, (string)null);
			((MelonEventBase<LemonAction<T, T>>)(object)val.OnEntryValueChanged).Subscribe(onChanged, 0, false);
			return val.Value;
		}
	}
	public class HammerEquippable : Equippable_Viewmodel
	{
		private enum HammerState
		{
			Idle,
			WindingUp,
			FlyingOut,
			FlyingBack,
			Flying
		}

		private const float Range = 1.5f;

		private const float HitRadius = 0.3f;

		private const float SwingCooldown = 0.25f;

		private const float SwingDuration = 0.15f;

		private const float SwingAngle = 70f;

		private const float HitTime = 0.06f;

		private const float WindUpMaxSpinSpeed = 5400f;

		private const float AimFOVReduction = 15f;

		private const float AimZoomDuration = 0.2f;

		private const float LightningAimRadius = 0.5f;

		private const float FlightGracePeriod = 0.5f;

		private const float ThrowHitRadius = 0.3f;

		private const float ReturnSpeed = 45f;

		private const float ReturnCatchDistance = 0.5f;

		private const float SpinSpeed = 1440f;

		private HammerState _state = HammerState.Idle;

		private float _cooldownRemaining;

		private bool _isSwinging;

		private float _swingElapsed;

		private bool _hitChecked;

		private GameObject _hammerModel;

		private Quaternion _modelBaseRotation;

		private float _windUpElapsed;

		private bool _fovOverridden;

		private bool _playerCharged;

		private GameObject _projectile;

		private Vector3 _throwDirection;

		private float _throwDistance;

		private float _savedGravityMultiplier = 1f;

		private float _flightStartTime;

		private AudioClip _thunderClip;

		private bool _thunderClipSearched;

		private static float LightningRange => Core.MaxThrowRange * 0.7f;

		public override void Equip(ItemInstance item)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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)
			((Component)this).gameObject.SetActive(true);
			base.localPosition = new Vector3(0.35f, -0.3f, 0.5f);
			base.localEulerAngles = new Vector3(0f, 0f, 0f);
			base.localScale = Vector3.one;
			LoadHammerModel();
			((Equippable_Viewmodel)this).Equip(item);
		}

		public override void Unequip()
		{
			if (_state == HammerState.Flying)
			{
				StopFlight();
			}
			if (_state == HammerState.WindingUp)
			{
				CancelWindUp();
			}
			CleanupThrow();
			ClearPlayerCharged();
			((Equippable_Viewmodel)this).Unequip();
		}

		private void LoadHammerModel()
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			byte[] array = EmbeddedResourceLoader.LoadBytes("ThorHammer.Resources.ThorHammer.glb", Assembly.GetExecutingAssembly());
			if (array == null)
			{
				Melon<Core>.Logger.Error("Failed to load ThorHammer.glb from embedded resources");
				return;
			}
			_hammerModel = GltfLoader.LoadGlb(array, (Shader)null);
			if ((Object)(object)_hammerModel == (Object)null)
			{
				Melon<Core>.Logger.Error("GltfLoader.LoadGlb returned null");
				return;
			}
			_hammerModel.transform.SetParent(((Component)this).transform, false);
			_hammerModel.transform.localPosition = new Vector3(0.02f, -0.15f, 0.05f);
			_hammerModel.transform.localRotation = Quaternion.Euler(0f, 90f, 0f);
			_hammerModel.transform.localScale = Vector3.one * 0.08f;
			_modelBaseRotation = _hammerModel.transform.localRotation;
		}

		protected override void Update()
		{
			((Equippable)this).Update();
			if (_cooldownRemaining > 0f)
			{
				_cooldownRemaining -= Time.deltaTime;
			}
			switch (_state)
			{
			case HammerState.Idle:
				UpdateSwingAnimation();
				UpdateIdle();
				break;
			case HammerState.WindingUp:
				UpdateWindUp();
				break;
			case HammerState.FlyingOut:
				UpdateFlyingOut();
				break;
			case HammerState.FlyingBack:
				UpdateFlyingBack();
				break;
			case HammerState.Flying:
				UpdateFlying();
				break;
			}
		}

		private void UpdateIdle()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			bool flag = !GameInput.IsTyping && PlayerSingleton<PlayerCamera>.Instance.activeUIElementCount == 0;
			if (flag && GameInput.GetButtonDown((ButtonCode)1))
			{
				StartWindUp();
				return;
			}
			if (flag && Input.GetKeyDown(Core.LightningKey))
			{
				if (Core.StaminaEnabled && PlayerSingleton<PlayerMovement>.Instance.CurrentStaminaReserve < Core.LightningStaminaCost)
				{
					return;
				}
				if (Core.StaminaEnabled)
				{
					PlayerSingleton<PlayerMovement>.Instance.ChangeStamina(0f - Core.LightningStaminaCost, true);
				}
				TryLightningZap();
			}
			if (flag && !_isSwinging && _cooldownRemaining <= 0f && GameInput.GetButtonDown((ButtonCode)0) && (!Core.StaminaEnabled || !(PlayerSingleton<PlayerMovement>.Instance.CurrentStaminaReserve < Core.SwingStaminaCost)))
			{
				if (Core.StaminaEnabled)
				{
					PlayerSingleton<PlayerMovement>.Instance.ChangeStamina(0f - Core.SwingStaminaCost, true);
				}
				StartSwing();
			}
		}

		private void StartSwing()
		{
			_isSwinging = true;
			_swingElapsed = 0f;
			_hitChecked = false;
			_cooldownRemaining = 0.25f;
		}

		private void UpdateSwingAnimation()
		{
			//IL_0099: 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_00a4: 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)
			if (!_isSwinging || (Object)(object)_hammerModel == (Object)null)
			{
				return;
			}
			_swingElapsed += Time.deltaTime;
			float num = _swingElapsed / 0.15f;
			if (num >= 1f)
			{
				_isSwinging = false;
				_hammerModel.transform.localRotation = _modelBaseRotation;
				return;
			}
			float num2 = Mathf.Sin(num * MathF.PI) * 70f;
			_hammerModel.transform.localRotation = Quaternion.Euler(num2, 0f, 0f) * _modelBaseRotation;
			if (!_hitChecked && _swingElapsed >= 0.06f)
			{
				_hitChecked = true;
				ExecuteMeleeHit();
			}
		}

		private void ExecuteMeleeHit()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			RaycastHit val = default(RaycastHit);
			if (!PlayerSingleton<PlayerCamera>.Instance.LookRaycast(1.5f, ref val, NetworkSingleton<CombatManager>.Instance.MeleeLayerMask, true, 0.3f))
			{
				return;
			}
			IDamageable componentInParent = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<IDamageable>();
			if (componentInParent != null)
			{
				float meleeForce = Core.MeleeForce;
				Impact val2 = new Impact(((RaycastHit)(ref val)).point, ((Component)PlayerSingleton<PlayerCamera>.Instance).transform.forward, meleeForce, Core.MeleeDamage, (EImpactType)1, ((NetworkBehaviour)Player.Local).NetworkObject, Random.Range(int.MinValue, int.MaxValue));
				componentInParent.SendImpact(val2);
				Singleton<FXManager>.Instance.CreateImpactFX(val2, componentInParent);
				PlayerSingleton<PlayerCamera>.Instance.StartCameraShake(0.3f, 0.2f, true);
				NPC componentInParent2 = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<NPC>();
				if ((Object)(object)componentInParent2 != (Object)null)
				{
					StrikeLightningOnNPC(componentInParent2);
					((EntityVisibility)Player.Local.VisualState).ApplyState("melee_attack", (EVisualState)9, 2.5f);
				}
			}
		}

		private void StartWindUp()
		{
			_state = HammerState.WindingUp;
			_windUpElapsed = 0f;
			_isSwinging = false;
			PlayerSingleton<PlayerMovement>.Instance.CanJump = false;
			float num = Singleton<Settings>.Instance.CameraFOV - 15f;
			PlayerSingleton<PlayerCamera>.Instance.OverrideFOV(num, 0.2f);
			_fovOverridden = true;
		}

		private void UpdateWindUp()
		{
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			_windUpElapsed += Time.deltaTime;
			bool flag = _windUpElapsed >= Core.WindUpDuration;
			if (Core.StaminaEnabled)
			{
				PlayerSingleton<PlayerMovement>.Instance.ChangeStamina((0f - Core.WindUpStaminaRate) * Time.deltaTime, true);
				if (PlayerSingleton<PlayerMovement>.Instance.CurrentStaminaReserve <= 0f)
				{
					CancelWindUp();
					return;
				}
			}
			float num = Mathf.Clamp01(_windUpElapsed / Core.WindUpDuration);
			float num2 = num * num * 5400f;
			if ((Object)(object)_hammerModel != (Object)null)
			{
				_hammerModel.transform.Rotate(Vector3.forward, num2 * Time.deltaTime, (Space)1);
			}
			if (flag && !_playerCharged)
			{
				_playerCharged = true;
				Electrifying.ApplyToAvatar(Player.Local.Avatar);
			}
			if (!GameInput.GetButton((ButtonCode)1))
			{
				if (flag)
				{
					StartThrow();
				}
				else
				{
					CancelWindUp();
				}
			}
			else if (flag && GameInput.GetButton((ButtonCode)7))
			{
				StartFlight();
			}
		}

		private void CancelWindUp()
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			_state = HammerState.Idle;
			_windUpElapsed = 0f;
			PlayerSingleton<PlayerMovement>.Instance.CanJump = true;
			ClearPlayerCharged();
			if (_fovOverridden)
			{
				PlayerSingleton<PlayerCamera>.Instance.StopFOVOverride(0.2f);
				_fovOverridden = false;
			}
			if ((Object)(object)_hammerModel != (Object)null)
			{
				_hammerModel.transform.localRotation = _modelBaseRotation;
			}
		}

		private void ClearPlayerCharged()
		{
			if (_playerCharged)
			{
				_playerCharged = false;
				Electrifying.ClearFromAvatar(Player.Local.Avatar);
			}
		}

		private void StartThrow()
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: 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)
			PlayerSingleton<PlayerMovement>.Instance.CanJump = true;
			ClearPlayerCharged();
			if (_fovOverridden)
			{
				PlayerSingleton<PlayerCamera>.Instance.StopFOVOverride(0.2f);
				_fovOverridden = false;
			}
			if (!((Object)(object)_hammerModel == (Object)null))
			{
				_hammerModel.transform.localRotation = _modelBaseRotation;
				_hammerModel.SetActive(false);
				_projectile = Object.Instantiate<GameObject>(_hammerModel);
				_projectile.SetActive(true);
				_projectile.transform.SetParent((Transform)null, false);
				SetLayerRecursive(_projectile, 0);
				Transform transform = ((Component)PlayerSingleton<PlayerCamera>.Instance).transform;
				_projectile.transform.position = transform.position + transform.forward * 1f;
				_projectile.transform.rotation = Quaternion.LookRotation(transform.forward) * Quaternion.Euler(0f, 90f, 0f);
				_projectile.transform.localScale = Vector3.one * 0.08f;
				_throwDirection = transform.forward;
				_throwDistance = 0f;
				_state = HammerState.FlyingOut;
			}
		}

		private void UpdateFlyingOut()
		{
			//IL_0044: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: 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_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: 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)
			if ((Object)(object)_projectile == (Object)null)
			{
				CatchHammer();
				return;
			}
			float num = Core.ThrowSpeed * Time.deltaTime;
			_throwDistance += num;
			Transform transform = _projectile.transform;
			transform.position += _throwDirection * num;
			_projectile.transform.Rotate(Vector3.forward, 1440f * Time.deltaTime, (Space)1);
			RaycastHit hit = default(RaycastHit);
			if (Physics.SphereCast(_projectile.transform.position - _throwDirection * num, 0.3f, _throwDirection, ref hit, num, LayerMask.op_Implicit(NetworkSingleton<CombatManager>.Instance.MeleeLayerMask), (QueryTriggerInteraction)2))
			{
				ExecuteThrowHit(hit);
				_state = HammerState.FlyingBack;
			}
			else if (_throwDistance >= Core.MaxThrowRange)
			{
				_state = HammerState.FlyingBack;
			}
		}

		private void UpdateFlyingBack()
		{
			//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_002e: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_projectile == (Object)null)
			{
				CatchHammer();
				return;
			}
			Vector3 position = ((Component)PlayerSingleton<PlayerCamera>.Instance).transform.position;
			Vector3 val = position - _projectile.transform.position;
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			float num = 45f * Time.deltaTime;
			Transform transform = _projectile.transform;
			transform.position += normalized * num;
			_projectile.transform.Rotate(Vector3.forward, 1440f * Time.deltaTime, (Space)1);
			if (Vector3.Distance(_projectile.transform.position, position) < 0.5f)
			{
				CatchHammer();
			}
		}

		private void ExecuteThrowHit(RaycastHit hit)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			IDamageable componentInParent = ((Component)((RaycastHit)(ref hit)).collider).GetComponentInParent<IDamageable>();
			if (componentInParent != null)
			{
				Impact val = new Impact(((RaycastHit)(ref hit)).point, _throwDirection, Core.ThrowForce, Core.ThrowDamage, (EImpactType)1, ((NetworkBehaviour)Player.Local).NetworkObject, Random.Range(int.MinValue, int.MaxValue));
				componentInParent.SendImpact(val);
				Singleton<FXManager>.Instance.CreateImpactFX(val, componentInParent);
			}
			NPC componentInParent2 = ((Component)((RaycastHit)(ref hit)).collider).GetComponentInParent<NPC>();
			if ((Object)(object)componentInParent2 != (Object)null)
			{
				StrikeLightningOnNPC(componentInParent2);
				((EntityVisibility)Player.Local.VisualState).ApplyState("melee_attack", (EVisualState)9, 2.5f);
			}
			PlayerSingleton<PlayerCamera>.Instance.StartCameraShake(0.5f, 0.3f, true);
		}

		private void CatchHammer()
		{
			if ((Object)(object)_projectile != (Object)null)
			{
				Object.Destroy((Object)(object)_projectile);
				_projectile = null;
			}
			if ((Object)(object)_hammerModel != (Object)null)
			{
				_hammerModel.SetActive(true);
			}
			_state = HammerState.Idle;
		}

		private void CleanupThrow()
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_projectile != (Object)null)
			{
				Object.Destroy((Object)(object)_projectile);
				_projectile = null;
			}
			if (_fovOverridden)
			{
				PlayerSingleton<PlayerCamera>.Instance.StopFOVOverride(0f);
				_fovOverridden = false;
			}
			if ((Object)(object)_hammerModel != (Object)null)
			{
				_hammerModel.SetActive(true);
				_hammerModel.transform.localRotation = _modelBaseRotation;
			}
			_state = HammerState.Idle;
		}

		private void TryLightningZap()
		{
			//IL_0016: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: 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)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			PlayerCamera instance = PlayerSingleton<PlayerCamera>.Instance;
			NPC val = null;
			RaycastHit val2 = default(RaycastHit);
			Vector3 position;
			if (instance.LookRaycast(LightningRange, ref val2, NetworkSingleton<CombatManager>.Instance.MeleeLayerMask, true, 0.5f))
			{
				position = ((RaycastHit)(ref val2)).point;
				val = ((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<NPC>();
				if ((Object)(object)val != (Object)null)
				{
					IDamageable componentInParent = ((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<IDamageable>();
					if (componentInParent != null)
					{
						Impact val3 = new Impact(((RaycastHit)(ref val2)).point, ((Component)instance).transform.forward, Core.LightningForce, Core.LightningDamage, (EImpactType)1, ((NetworkBehaviour)Player.Local).NetworkObject, Random.Range(int.MinValue, int.MaxValue));
						componentInParent.SendImpact(val3);
					}
					Electrifying.ApplyToAvatar(val.Avatar);
				}
			}
			else
			{
				position = ((Component)instance).transform.position + ((Component)instance).transform.forward * LightningRange;
			}
			LightningHelper.StrikeLightning(position);
			if ((Object)(object)val != (Object)null)
			{
				MelonCoroutines.Start(LightningHelper.ClearElectrifyCoroutine(val));
			}
			PlayThunderSound(position);
			EmitLightningNoise(position);
			((EntityVisibility)Player.Local.VisualState).ApplyState("melee_attack", (EVisualState)9, 2.5f);
			PlayerSingleton<PlayerCamera>.Instance.StartCameraShake(0.5f, 0.3f, true);
		}

		private void StrikeLightningOnNPC(NPC npc)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			Vector3 position = ((Component)npc).transform.position;
			LightningHelper.StrikeLightning(position);
			MelonCoroutines.Start(LightningHelper.ClearElectrifyCoroutine(npc));
			Electrifying.ApplyToAvatar(npc.Avatar);
			PlayThunderSound(position);
			EmitLightningNoise(position);
		}

		private static void EmitLightningNoise(Vector3 position)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			if (Core.LightningPanicRadius > 0f)
			{
				NoiseUtility.EmitNoise(position, (ENoiseType)2, Core.LightningPanicRadius, ((Component)Player.Local).gameObject);
			}
		}

		private void PlayThunderSound(Vector3 position)
		{
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			if (!_thunderClipSearched)
			{
				_thunderClipSearched = true;
				ThunderController val = Object.FindObjectOfType<ThunderController>();
				if ((Object)(object)val == (Object)null)
				{
					ThunderController[] array = Resources.FindObjectsOfTypeAll<ThunderController>();
					if (array.Length != 0)
					{
						val = array[0];
					}
				}
				if ((Object)(object)val != (Object)null)
				{
					try
					{
						object? obj = typeof(ThunderController).GetField("_lightningAudio", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(val);
						AudioSourceController val2 = (AudioSourceController)((obj is AudioSourceController) ? obj : null);
						if (val2 != null && ((object)val2).GetType().GetField("Clips", BindingFlags.Instance | BindingFlags.Public)?.GetValue(val2) is AudioClip[] array2 && array2.Length != 0)
						{
							_thunderClip = array2[0];
						}
					}
					catch
					{
					}
				}
				if ((Object)(object)_thunderClip == (Object)null)
				{
					try
					{
						AudioClip[] array3 = Resources.FindObjectsOfTypeAll<AudioClip>();
						AudioClip[] array4 = array3;
						foreach (AudioClip val3 in array4)
						{
							if (!((Object)(object)val3 == (Object)null))
							{
								string text = ((Object)val3).name.ToLowerInvariant();
								if (text.Contains("thunder") || text.Contains("lightning"))
								{
									_thunderClip = val3;
									break;
								}
							}
						}
					}
					catch
					{
					}
				}
				if ((Object)(object)_thunderClip != (Object)null)
				{
					Melon<Core>.Logger.Msg("Thunder sound found: " + ((Object)_thunderClip).name);
				}
				else
				{
					Melon<Core>.Logger.Warning("No thunder/lightning AudioClip found in game assets");
				}
			}
			if ((Object)(object)_thunderClip != (Object)null)
			{
				AudioSource.PlayClipAtPoint(_thunderClip, position, 1f);
			}
		}

		private void StartFlight()
		{
			//IL_0055: 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_0064: 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)
			if (_fovOverridden)
			{
				PlayerSingleton<PlayerCamera>.Instance.StopFOVOverride(0.2f);
				_fovOverridden = false;
			}
			_state = HammerState.Flying;
			_flightStartTime = Time.time;
			_savedGravityMultiplier = PlayerMovement.GravityMultiplier;
			PlayerMovement.GravityMultiplier = 0f;
			PlayerSingleton<PlayerMovement>.Instance.Controller.Move(Vector3.up * 0.5f);
			if ((Object)(object)_hammerModel != (Object)null)
			{
				_hammerModel.transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
			}
		}

		private void UpdateFlying()
		{
			//IL_0058: 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_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)
			Transform transform = ((Component)PlayerSingleton<PlayerCamera>.Instance).transform;
			PlayerMovement instance = PlayerSingleton<PlayerMovement>.Instance;
			if (Core.StaminaEnabled)
			{
				instance.ChangeStamina((0f - Core.FlightStaminaRate) * Time.deltaTime, true);
				if (instance.CurrentStaminaReserve <= 0f)
				{
					StopFlight();
					return;
				}
			}
			instance.Controller.Move(transform.forward * Core.FlightSpeed * Time.deltaTime);
			bool flag = Time.time - _flightStartTime > 0.5f;
			if (!GameInput.GetButton((ButtonCode)7) || (flag && instance.IsGrounded))
			{
				StopFlight();
			}
		}

		private void StopFlight()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			_state = HammerState.Idle;
			PlayerMovement.GravityMultiplier = _savedGravityMultiplier;
			PlayerSingleton<PlayerMovement>.Instance.CanJump = true;
			ClearPlayerCharged();
			if ((Object)(object)_hammerModel != (Object)null)
			{
				_hammerModel.transform.localRotation = _modelBaseRotation;
			}
		}

		private static void SetLayerRecursive(GameObject go, int layer)
		{
			go.layer = layer;
			for (int i = 0; i < go.transform.childCount; i++)
			{
				SetLayerRecursive(((Component)go.transform.GetChild(i)).gameObject, layer);
			}
		}
	}
	internal static class LightningHelper
	{
		[CompilerGenerated]
		private sealed class <ClearElectrifyCoroutine>d__2 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public NPC npc;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <ClearElectrifyCoroutine>d__2(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(4f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					if ((Object)(object)npc != (Object)null && (Object)(object)npc.Avatar != (Object)null)
					{
						Electrifying.ClearFromAvatar(npc.Avatar);
					}
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private static VFXEffectHandler _lightningVFX;

		private static bool _searched;

		[IteratorStateMachine(typeof(<ClearElectrifyCoroutine>d__2))]
		internal static IEnumerator ClearElectrifyCoroutine(NPC npc)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <ClearElectrifyCoroutine>d__2(0)
			{
				npc = npc
			};
		}

		internal static void StrikeLightning(Vector3 position)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			EnsureVFX();
			if (!((Object)(object)_lightningVFX == (Object)null))
			{
				((EffectHandler)_lightningVFX).SetPosition(position);
				((EffectHandler)_lightningVFX).Activate();
				((EffectHandler)_lightningVFX).DelayDeactivate(2f, (Action)null);
			}
		}

		private static void EnsureVFX()
		{
			if (_searched)
			{
				return;
			}
			_searched = true;
			ThunderController[] array = Resources.FindObjectsOfTypeAll<ThunderController>();
			ThunderController val = ((array.Length != 0) ? array[0] : null);
			if ((Object)(object)val == (Object)null)
			{
				Melon<Core>.Logger.Warning("No ThunderController found — lightning VFX unavailable");
				return;
			}
			VFXEffectHandler val2 = null;
			object? obj = typeof(ThunderController).GetField("_lightningEffect", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(val);
			val2 = (VFXEffectHandler)((obj is VFXEffectHandler) ? obj : null);
			if ((Object)(object)val2 == (Object)null && typeof(WeatherEffectController).GetField("visualEffects", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(val) is IList list)
			{
				foreach (object item in list)
				{
					VFXEffectHandler val3 = (VFXEffectHandler)((item is VFXEffectHandler) ? item : null);
					if (val3 != null && ((EffectHandler)val3).Id == "Lightning")
					{
						val2 = val3;
						break;
					}
				}
			}
			if ((Object)(object)val2 == (Object)null)
			{
				Melon<Core>.Logger.Warning("No lightning VFX found on ThunderController");
				return;
			}
			GameObject val4 = Object.Instantiate<GameObject>(((Component)val2).gameObject);
			((Object)val4).name = "ThorLightningVFX";
			val4.SetActive(true);
			Object.DontDestroyOnLoad((Object)(object)val4);
			_lightningVFX = val4.GetComponent<VFXEffectHandler>();
			if ((Object)(object)_lightningVFX != (Object)null)
			{
				((EffectHandler)_lightningVFX).Deactivate();
				Melon<Core>.Logger.Msg("Cloned game lightning VFX for ThorHammer.");
			}
			else
			{
				Melon<Core>.Logger.Warning("Cloned lightning VFX has no VFXEffectHandler component");
				Object.Destroy((Object)(object)val4);
			}
		}
	}
}