Decompiled source of HatterMeleeWeaponsPack v1.0.0

HatterMeleeWeaponsPack.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Photon.Pun;
using REPOLib.Modules;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("HatterMeleeWeaponsPack")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HatterMeleeWeaponsPack")]
[assembly: AssemblyTitle("HatterMeleeWeaponsPack")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace HatterMeleeWeaponsPack;

internal class Katana : MonoBehaviour
{
	public Vector3 bladeBase;

	public Vector3 bladeTip;

	public ItemMelee soundTemplate;

	public MeshRenderer bladeRenderer;

	public int[] glowSlots;

	private const string SlashFile = "katana_slash.pcm";

	private const float DrawPointAlong = 0.75f;

	private const float PointSpacing = 0.03f;

	private const float EndGrace = 0.08f;

	private const float MaxStepMetres = 0.6f;

	private const float ScrollSwingIgnore = 0.6f;

	private const float WaveAhead = 0.15f;

	private PhysGrabObject physGrabObject;

	private PhotonView photonView;

	private HurtCollider hurt;

	private Sound slashSound;

	private ItemBattery battery;

	private ItemToggle toggle;

	private bool charged;

	private Material[] plainMaterials;

	private Light glowLight;

	private static Material glowMaterial;

	private KatanaRift rift;

	private int riftId = -1;

	private bool haveLast;

	private Vector3 lastRel;

	private Vector3 lastWorld;

	private Vector3 lastSent;

	private bool drawing;

	private float strokeLength;

	private float slowTime;

	private int strokeId;

	private readonly List<Vector3> strokePoints = new List<Vector3>();

	private PlayerAvatar strokeHolder;

	private Transform strokeEyes;

	private float nextWave;

	private float nextRefuseLog;

	private bool chargeBlocked;

	private int chainCount;

	private Vector3 chainCentre;

	private float lastRiftAt;

	internal float scrollSwingAt = -10f;

	private Vector3 DrawPoint => ((Component)this).transform.TransformPoint(Vector3.Lerp(bladeBase, bladeTip, 0.75f));

	private static Material GlowMaterial
	{
		get
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			if ((Object)(object)glowMaterial != (Object)null)
			{
				return glowMaterial;
			}
			Shader val = Shader.Find("Sprites/Default");
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			glowMaterial = new Material(val)
			{
				name = "HMWP Katana Glow",
				color = new Color(0.85f, 0.04f, 0.04f)
			};
			((Object)glowMaterial).hideFlags = (HideFlags)32;
			return glowMaterial;
		}
	}

	private int BarsLeft
	{
		get
		{
			if (!((Object)(object)battery == (Object)null) && battery.batteryBars > 0)
			{
				return Mathf.RoundToInt(battery.batteryLife / (100f / (float)battery.batteryBars));
			}
			return 0;
		}
	}

	private void Start()
	{
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Expected O, but got Unknown
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		physGrabObject = ((Component)this).GetComponent<PhysGrabObject>();
		photonView = ((Component)this).GetComponent<PhotonView>();
		hurt = ((Component)this).GetComponentInChildren<HurtCollider>(true);
		battery = ((Component)this).GetComponent<ItemBattery>();
		toggle = ((Component)this).GetComponent<ItemToggle>();
		if ((Object)(object)hurt != (Object)null)
		{
			hurt.enemyDamage = Settings.KatanaBladeDamage.Value;
		}
		slashSound = MakeSound("katana_slash.pcm", 0.9f);
		if ((Object)(object)bladeRenderer != (Object)null)
		{
			plainMaterials = ((Renderer)bladeRenderer).sharedMaterials;
		}
		GameObject val = new GameObject("Katana Glow Light");
		val.transform.SetParent(((Component)this).transform, false);
		val.transform.localPosition = Vector3.Lerp(bladeBase, bladeTip, 0.6f);
		glowLight = val.AddComponent<Light>();
		glowLight.type = (LightType)2;
		glowLight.color = new Color(0.85f, 0.04f, 0.04f);
		glowLight.range = 1.6f;
		glowLight.intensity = 0f;
		((Behaviour)glowLight).enabled = false;
	}

	private void OnDestroy()
	{
		if ((Object)(object)rift != (Object)null)
		{
			rift.Fizzle();
		}
	}

	private PlayerAvatar Holder()
	{
		if ((Object)(object)physGrabObject == (Object)null || physGrabObject.playerGrabbing == null)
		{
			return null;
		}
		foreach (PhysGrabber item in physGrabObject.playerGrabbing)
		{
			if ((Object)(object)item != (Object)null && (Object)(object)item.playerAvatar != (Object)null)
			{
				return item.playerAvatar;
			}
		}
		return null;
	}

	private static Transform Eyes(PlayerAvatar p)
	{
		if (!((Object)(object)p != (Object)null) || !((Object)(object)p.PlayerVisionTarget != (Object)null) || !((Object)(object)p.PlayerVisionTarget.VisionTransform != (Object)null))
		{
			return null;
		}
		return p.PlayerVisionTarget.VisionTransform;
	}

	private static Vector3 EyePosition(PlayerAvatar p, Transform eyes)
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		if (!((Object)(object)eyes != (Object)null))
		{
			return ((Component)p).transform.position + Vector3.up * 1.5f;
		}
		return eyes.position;
	}

	private void Update()
	{
		//IL_007c: 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_0096: Unknown result type (might be due to invalid IL or missing references)
		bool flag = (Object)(object)toggle != (Object)null && toggle.toggleState;
		if (flag != charged)
		{
			charged = flag;
			ApplyGlow();
		}
		if (charged)
		{
			float num = 0.5f + 0.5f * Mathf.Sin(Time.time * 6f);
			if ((Object)(object)GlowMaterial != (Object)null)
			{
				GlowMaterial.color = Color.Lerp(new Color(0.55f, 0.01f, 0.02f), new Color(0.95f, 0.06f, 0.05f), num);
			}
			if ((Object)(object)glowLight != (Object)null)
			{
				glowLight.intensity = 1.2f + 0.8f * num;
			}
		}
	}

	private void ApplyGlow()
	{
		if ((Object)(object)glowLight != (Object)null)
		{
			((Behaviour)glowLight).enabled = charged;
		}
		if ((Object)(object)bladeRenderer == (Object)null || plainMaterials == null || glowSlots == null)
		{
			return;
		}
		if (!charged || (Object)(object)GlowMaterial == (Object)null)
		{
			((Renderer)bladeRenderer).sharedMaterials = plainMaterials;
			return;
		}
		Material[] array = (Material[])plainMaterials.Clone();
		int[] array2 = glowSlots;
		foreach (int num in array2)
		{
			if (num >= 0 && num < array.Length)
			{
				array[num] = GlowMaterial;
			}
		}
		((Renderer)bladeRenderer).sharedMaterials = array;
	}

	private void FixedUpdate()
	{
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_023e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		//IL_0279: Unknown result type (might be due to invalid IL or missing references)
		//IL_0242: Unknown result type (might be due to invalid IL or missing references)
		//IL_0247: Unknown result type (might be due to invalid IL or missing references)
		//IL_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		if (!SemiFunc.IsMasterClientOrSingleplayer())
		{
			return;
		}
		if ((Object)(object)hurt != (Object)null && hurt.enemyDamage != Settings.KatanaBladeDamage.Value)
		{
			hurt.enemyDamage = Settings.KatanaBladeDamage.Value;
		}
		UpdateChargeAllowed();
		bool num = (Object)(object)toggle != (Object)null && toggle.toggleState;
		PlayerAvatar val = Holder();
		if (!num || (Object)(object)val == (Object)null)
		{
			if (drawing)
			{
				EndStroke(release: false, "the katana was let go or uncharged");
			}
			if (chainCount > 0)
			{
				EndChain(((Object)(object)val == (Object)null) ? "let go" : "uncharged");
			}
			haveLast = false;
			return;
		}
		if (chainCount > 0 && !drawing && Time.time > lastRiftAt + Settings.KatanaChainWindowEnd.Value)
		{
			EndChain($"no stroke within {Settings.KatanaChainWindowEnd.Value:0.0} s");
			haveLast = false;
			return;
		}
		Transform eyes = Eyes(val);
		Vector3 drawPoint = DrawPoint;
		Vector3 val2 = drawPoint - EyePosition(val, eyes);
		if (!haveLast)
		{
			haveLast = true;
			lastRel = val2;
			lastWorld = drawPoint;
			return;
		}
		float fixedDeltaTime = Time.fixedDeltaTime;
		Vector3 val3 = val2 - lastRel;
		float magnitude = ((Vector3)(ref val3)).magnitude;
		float num2 = magnitude / fixedDeltaTime;
		float value = Settings.KatanaRiftDrawSpeed.Value;
		if (magnitude > 0.6f || Time.time - scrollSwingAt < 0.6f)
		{
			if (drawing)
			{
				EndStroke(release: false, "a teleport or the scroll swing");
			}
		}
		else if (!drawing)
		{
			bool flag = chainCount > 0 && Time.time < lastRiftAt + Settings.KatanaChainWindowStart.Value;
			if (num2 >= value && !flag)
			{
				StartStroke(val, eyes, magnitude, drawPoint);
			}
		}
		else if (num2 >= value * 0.5f)
		{
			slowTime = 0f;
			float value2 = Settings.KatanaRiftMaxLength.Value;
			float num3 = Mathf.Min(magnitude, value2 - strokeLength);
			Vector3 point = ((num3 < magnitude && magnitude > 1E-05f) ? Vector3.Lerp(lastWorld, drawPoint, num3 / magnitude) : drawPoint);
			strokeLength += num3;
			bool flag2 = strokeLength >= value2 - 0.0001f;
			AddPoint(point, flag2);
			if (flag2)
			{
				EndStroke(release: true, null);
			}
		}
		else
		{
			slowTime += fixedDeltaTime;
			if (slowTime > 0.08f)
			{
				EndStroke(strokeLength >= Settings.KatanaRiftMinLength.Value, null);
			}
		}
		lastRel = val2;
		lastWorld = drawPoint;
	}

	private void UpdateChargeAllowed()
	{
		if ((Object)(object)toggle == (Object)null)
		{
			return;
		}
		string text = ((chainCount > 0) ? null : ((Time.time < nextWave) ? "cooling down" : ((!HasEnergy()) ? "not enough energy" : null)));
		if (text != null && toggle.toggleState)
		{
			toggle.ToggleItem(false, -1);
			if (Settings.KatanaDebugLog.Value && Time.time >= nextRefuseLog)
			{
				nextRefuseLog = Time.time + 1f;
				Plugin.Log.LogInfo((object)("Katana: can't charge, " + text + "."));
			}
		}
		bool flag = text != null;
		if (flag == chargeBlocked)
		{
			return;
		}
		chargeBlocked = flag;
		try
		{
			toggle.ToggleDisable(flag);
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Katana: switching E " + (flag ? "off" : "on") + " failed: " + ex.Message));
		}
	}

	private void StartStroke(PlayerAvatar holder, Transform eyes, float dist, Vector3 world)
	{
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		drawing = true;
		slowTime = 0f;
		strokeId++;
		strokeHolder = holder;
		strokeEyes = eyes;
		strokePoints.Clear();
		strokeLength = Mathf.Min(dist, Settings.KatanaRiftMaxLength.Value);
		AddPoint(lastWorld, force: true);
		AddPoint(world, force: true);
	}

	private void AddPoint(Vector3 point, bool force)
	{
		//IL_0006: 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_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		strokePoints.Add(point);
		if (!force)
		{
			Vector3 val = point - lastSent;
			if (((Vector3)(ref val)).sqrMagnitude < 0.0009f)
			{
				return;
			}
		}
		lastSent = point;
		bool flag = chainCount > 0;
		if (SemiFunc.IsMultiplayer() && (Object)(object)photonView != (Object)null)
		{
			photonView.RPC("HMWPKatanaRiftRPC", (RpcTarget)0, new object[4] { strokeId, point, flag, chainCentre });
		}
		else
		{
			RiftPoint(strokeId, point, flag, chainCentre);
		}
	}

	private void EndStroke(bool release, string why)
	{
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: 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_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: 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_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0211: Unknown result type (might be due to invalid IL or missing references)
		//IL_0216: Unknown result type (might be due to invalid IL or missing references)
		//IL_0218: Unknown result type (might be due to invalid IL or missing references)
		//IL_021a: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: Unknown result type (might be due to invalid IL or missing references)
		//IL_023a: 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_023e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0243: Unknown result type (might be due to invalid IL or missing references)
		//IL_0245: Unknown result type (might be due to invalid IL or missing references)
		//IL_022f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0231: Unknown result type (might be due to invalid IL or missing references)
		//IL_025c: Unknown result type (might be due to invalid IL or missing references)
		//IL_025e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0260: Unknown result type (might be due to invalid IL or missing references)
		//IL_0265: Unknown result type (might be due to invalid IL or missing references)
		//IL_0267: Unknown result type (might be due to invalid IL or missing references)
		//IL_0268: Unknown result type (might be due to invalid IL or missing references)
		//IL_026f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0274: Unknown result type (might be due to invalid IL or missing references)
		//IL_0279: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Unknown result type (might be due to invalid IL or missing references)
		//IL_0255: Unknown result type (might be due to invalid IL or missing references)
		//IL_025a: Unknown result type (might be due to invalid IL or missing references)
		//IL_034b: Unknown result type (might be due to invalid IL or missing references)
		//IL_034d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0329: Unknown result type (might be due to invalid IL or missing references)
		//IL_032b: Unknown result type (might be due to invalid IL or missing references)
		//IL_032d: Unknown result type (might be due to invalid IL or missing references)
		drawing = false;
		slowTime = 0f;
		int id = strokeId;
		if (release && chainCount == 0 && (Time.time < nextWave || !HasEnergy()))
		{
			release = false;
			why = "cooling down or out of energy";
		}
		if (!release || strokePoints.Count < 2 || (Object)(object)strokeHolder == (Object)null)
		{
			if (Settings.KatanaDebugLog.Value)
			{
				Plugin.Log.LogInfo((object)$"Katana: rift of {strokeLength:0.00} m fizzled ({why ?? $"shorter than RiftMinLength {Settings.KatanaRiftMinLength.Value:0.00} m"}).");
			}
			SendEnd(id, opened: false, Vector3.zero, Quaternion.identity, 0f);
			return;
		}
		Vector3 val = ((chainCount > 0) ? chainCentre : PointAlong(0.5f));
		if (chainCount == 0)
		{
			chainCentre = val;
		}
		Vector3 val2 = strokePoints[strokePoints.Count - 1] - strokePoints[0];
		Vector3 val3 = EyePosition(strokeHolder, strokeEyes);
		Vector3 val4 = (((Object)(object)strokeEyes != (Object)null) ? strokeEyes.forward : ((Component)strokeHolder).transform.forward);
		Vector3 val5 = Vector3.ProjectOnPlane(val - val3, Vector3.up);
		if (((Vector3)(ref val5)).sqrMagnitude < 0.04f)
		{
			val5 = Vector3.ProjectOnPlane(val4, Vector3.up);
		}
		if (((Vector3)(ref val5)).sqrMagnitude < 0.0001f)
		{
			val5 = ((Component)strokeHolder).transform.forward;
		}
		((Vector3)(ref val5)).Normalize();
		Vector3 val6 = Vector3.ProjectOnPlane(val4, Vector3.up);
		float num = ((((Vector3)(ref val6)).sqrMagnitude > 0.0001f) ? Mathf.Clamp(Vector3.Angle(val6, val4) * Mathf.Sign(val4.y), -35f, 35f) : 0f);
		Vector3 val7 = Vector3.Cross(Vector3.up, val5);
		Vector3 normalized = ((Vector3)(ref val7)).normalized;
		Vector3 val8 = Quaternion.AngleAxis(0f - num, normalized) * val5;
		Vector3 val9 = Vector3.ProjectOnPlane(val2, val8);
		if (((Vector3)(ref val9)).sqrMagnitude < 0.0025f)
		{
			val9 = normalized;
		}
		((Vector3)(ref val9)).Normalize();
		Vector3 val10 = Vector3.Cross(val8, val9);
		if (val10.y < 0f)
		{
			val10 = -val10;
		}
		Quaternion rotation = Quaternion.LookRotation(val8, val10);
		Vector3 origin = val + val8 * 0.15f;
		float num2 = Mathf.Clamp(strokeLength * Settings.KatanaWaveSpanPerMetre.Value, Settings.KatanaWaveSpanMin.Value, Mathf.Max(Settings.KatanaWaveSpanMin.Value, Settings.KatanaWaveSpanMax.Value));
		if (chainCount == 0)
		{
			SpendEnergy();
		}
		chainCount++;
		lastRiftAt = Time.time;
		if (Settings.KatanaDebugLog.Value)
		{
			Plugin.Log.LogInfo((object)($"Katana: rift {chainCount} of up to {Settings.KatanaChainLength.Value}, {strokeLength:0.00} m, opened; " + $"wave {num2:0.0} m wide, tilted {Vector3.SignedAngle(normalized, val9, val8):0}°."));
		}
		SendEnd(id, opened: true, origin, rotation, num2);
		if (chainCount >= Settings.KatanaChainLength.Value)
		{
			EndChain("its last rift");
		}
	}

	private void EndChain(string why)
	{
		if (Settings.KatanaDebugLog.Value)
		{
			Plugin.Log.LogInfo((object)$"Katana: chain of {chainCount} rift(s) over ({why}).");
		}
		chainCount = 0;
		nextWave = lastRiftAt + Settings.KatanaWaveCooldown.Value;
		if ((Object)(object)toggle != (Object)null && toggle.toggleState)
		{
			toggle.ToggleItem(false, -1);
		}
		UpdateChargeAllowed();
	}

	private Vector3 PointAlong(float fraction)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: 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_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		float num = 0f;
		for (int i = 1; i < strokePoints.Count; i++)
		{
			num += Vector3.Distance(strokePoints[i - 1], strokePoints[i]);
		}
		float num2 = num * fraction;
		float num3 = 0f;
		for (int j = 1; j < strokePoints.Count; j++)
		{
			float num4 = Vector3.Distance(strokePoints[j - 1], strokePoints[j]);
			if (num3 + num4 >= num2)
			{
				if (!(num4 > 1E-06f))
				{
					return strokePoints[j];
				}
				return Vector3.Lerp(strokePoints[j - 1], strokePoints[j], (num2 - num3) / num4);
			}
			num3 += num4;
		}
		return strokePoints[strokePoints.Count - 1];
	}

	private void SendEnd(int id, bool opened, Vector3 origin, Quaternion rotation, float span)
	{
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: 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)
		if (SemiFunc.IsMultiplayer() && (Object)(object)photonView != (Object)null)
		{
			photonView.RPC("HMWPKatanaRiftEndRPC", (RpcTarget)0, new object[5] { id, opened, origin, rotation, span });
		}
		else
		{
			RiftEnd(id, opened, origin, rotation, span);
		}
	}

	[PunRPC]
	public void HMWPKatanaRiftRPC(int id, Vector3 point, bool centred, Vector3 centre, PhotonMessageInfo info)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		if (info.Sender == null || info.Sender.IsMasterClient)
		{
			RiftPoint(id, point, centred, centre);
		}
	}

	[PunRPC]
	public void HMWPKatanaRiftEndRPC(int id, bool opened, Vector3 origin, Quaternion rotation, float span, PhotonMessageInfo info)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		if (info.Sender == null || info.Sender.IsMasterClient)
		{
			RiftEnd(id, opened, origin, rotation, span);
		}
	}

	private void RiftPoint(int id, Vector3 point, bool centred, Vector3 centre)
	{
		//IL_0058: 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)
		if ((Object)(object)rift == (Object)null || riftId != id)
		{
			if ((Object)(object)rift != (Object)null)
			{
				rift.Fizzle();
			}
			rift = KatanaRift.Create();
			riftId = id;
			if (centred)
			{
				rift.CentreOn(centre);
			}
		}
		rift.Add(point);
	}

	private void RiftEnd(int id, bool opened, Vector3 origin, Quaternion rotation, float span)
	{
		//IL_008b: 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)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)rift != (Object)null && riftId == id)
		{
			if (opened)
			{
				rift.Open();
			}
			else
			{
				rift.Fizzle();
			}
			rift = null;
		}
		if (!opened)
		{
			return;
		}
		if (slashSound != null)
		{
			try
			{
				slashSound.Play(origin, 1f, 1f, 1f, 1f);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Katana sound failed: " + ex.Message));
			}
		}
		bool flag = SemiFunc.IsMasterClientOrSingleplayer();
		KatanaWave.Spawn(origin, rotation, span, flag, physGrabObject, flag ? Holder() : null);
	}

	private bool HasEnergy()
	{
		if (!((Object)(object)battery == (Object)null) && Settings.KatanaWaveEnergy.Value > 0)
		{
			return BarsLeft >= Settings.KatanaWaveEnergy.Value;
		}
		return true;
	}

	private void SpendEnergy()
	{
		int value = Settings.KatanaWaveEnergy.Value;
		if (!((Object)(object)battery == (Object)null) && value > 0)
		{
			try
			{
				battery.RemoveFullBar(value);
				battery.OverrideBatteryShow(2f);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Katana: using energy failed: " + ex.Message));
			}
			if (Settings.KatanaDebugLog.Value)
			{
				Plugin.Log.LogInfo((object)$"Katana: wave used {value} energy, {BarsLeft} of {battery.batteryBars} left.");
			}
		}
	}

	internal void ShowImpact(Vector3 point, float size)
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		if (SemiFunc.IsMultiplayer() && (Object)(object)photonView != (Object)null)
		{
			photonView.RPC("HMWPKatanaImpactRPC", (RpcTarget)0, new object[2] { point, size });
		}
		else
		{
			KatanaImpactMark.Spawn(point, size);
		}
	}

	[PunRPC]
	public void HMWPKatanaImpactRPC(Vector3 point, float size, PhotonMessageInfo info)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		if (info.Sender == null || info.Sender.IsMasterClient)
		{
			KatanaImpactMark.Spawn(point, size);
		}
	}

	private Sound MakeSound(string file, float volume)
	{
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Expected O, but got Unknown
		AudioClip val = SoundLibrary.Get(file);
		ItemMelee val2 = (((Object)(object)soundTemplate != (Object)null) ? soundTemplate : ((Component)this).GetComponent<ItemMelee>());
		if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || val2.soundSwing == null)
		{
			return null;
		}
		Sound val3 = new Sound();
		Sound.CopySound(val2.soundSwing, val3);
		val3.Sounds = (AudioClip[])(object)new AudioClip[1] { val };
		val3.Volume = volume;
		val3.VolumeRandom = 0f;
		val3.Pitch = 1f;
		val3.PitchRandom = 0.05f;
		return val3;
	}
}
[HarmonyPatch(typeof(ItemMelee), "ScrollSwingStartRPC")]
internal static class KatanaScrollPatch
{
	private static void Postfix(ItemMelee __instance, int _direction)
	{
		Katana katana = (((Object)(object)__instance != (Object)null) ? ((Component)__instance).GetComponent<Katana>() : null);
		if (!((Object)(object)katana == (Object)null))
		{
			katana.scrollSwingAt = Time.time;
			if (Settings.KatanaDebugLog.Value)
			{
				Plugin.Log.LogInfo((object)("Katana: the sword's scroll swing started (" + ((_direction > 0) ? "out" : "in") + ")."));
			}
		}
	}
}
internal static class KatanaBuilder
{
	private const string SwordPath = "Items/Item Melee Sword";

	private const string BatPath = "Items/Item Melee Baseball Bat";

	internal const string PrefabName = "Item Melee Katana";

	internal const string DisplayName = "Katana";

	internal const string ModelFile = "katana.mesh";

	private const float HandFromPommel = 0.17f;

	internal const float GripLength = 0.265f;

	internal const float BladeRoot = 0.272f;

	internal const float BladeTip = 0.977f;

	private static GameObject holder;

	internal static GameObject Build()
	{
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: 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_0056: Expected O, but got Unknown
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_0269: Unknown result type (might be due to invalid IL or missing references)
		//IL_027b: Unknown result type (might be due to invalid IL or missing references)
		//IL_029e: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_038c: Unknown result type (might be due to invalid IL or missing references)
		//IL_039d: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_03db: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_0432: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = Resources.Load<GameObject>("Items/Item Melee Sword");
		if ((Object)(object)val == (Object)null)
		{
			Plugin.Log.LogError((object)"'Items/Item Melee Sword' not found.");
			return null;
		}
		MeshLibrary.Model model = MeshLibrary.Get("katana.mesh", "KT_Katana");
		if (model == null)
		{
			return null;
		}
		if ((Object)(object)holder == (Object)null)
		{
			holder = new GameObject("HatterMeleeWeaponsPack.KatanaHolder");
			holder.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)holder);
			((Object)holder).hideFlags = (HideFlags)61;
		}
		GameObject val2 = Object.Instantiate<GameObject>(val, holder.transform);
		((Object)val2).name = "Item Melee Katana";
		Transform transform = val2.transform;
		SetupItem(val2);
		Transform val3 = transform.Find("Force Grab Point");
		Transform val4 = transform.Find("Swing Point");
		Bounds val5 = NunchuckBuilder.LocalRendererBounds(transform);
		Material template = NunchuckBuilder.PickTemplate(transform);
		Vector3 val7;
		Vector3 val8;
		if (!((Object)(object)val3 != (Object)null))
		{
			Vector3 center = ((Bounds)(ref val5)).center;
			Vector3 val6 = NunchuckBuilder.LongAxis(val5);
			val7 = ((Bounds)(ref val5)).extents;
			val8 = center - val6 * ((Vector3)(ref val7)).magnitude * 0.8f;
		}
		else
		{
			val8 = val3.localPosition;
		}
		Vector3 val9 = val8;
		Vector3 val10;
		if ((Object)(object)val4 != (Object)null)
		{
			val7 = val4.localPosition - val9;
			if (((Vector3)(ref val7)).sqrMagnitude > 0.0001f)
			{
				val7 = val4.localPosition - val9;
				val10 = ((Vector3)(ref val7)).normalized;
				goto IL_015e;
			}
		}
		val10 = NunchuckBuilder.LongAxis(val5);
		goto IL_015e;
		IL_015e:
		Vector3 val11 = val10;
		Vector3 val12 = WidthAxis(val5, val11);
		val12 = Quaternion.AngleAxis(Settings.KatanaEdgeRoll.Value, val11) * val12;
		Quaternion rotation = Quaternion.LookRotation(val12, val11);
		Vector3 bottom = val9 - val11 * 0.17f;
		NunchuckBuilder.HideBatMesh(transform);
		LogColliders(transform);
		HurtCollider componentInChildren = ((Component)transform).GetComponentInChildren<HurtCollider>(true);
		if ((Object)(object)componentInChildren != (Object)null)
		{
			componentInChildren.enemyDamage = Settings.KatanaBladeDamage.Value;
		}
		ItemBattery component = val2.GetComponent<ItemBattery>();
		if ((Object)(object)component != (Object)null)
		{
			component.batteryBars = Settings.KatanaEnergy.Value;
			component.onlyShowWhenItemToggleIsOn = false;
		}
		else
		{
			Plugin.Log.LogWarning((object)"The sword has no battery; the katana's energy can't be counted.");
		}
		ItemToggle val13 = val2.GetComponent<ItemToggle>();
		if ((Object)(object)val13 == (Object)null)
		{
			val13 = val2.AddComponent<ItemToggle>();
		}
		val13.toggleState = false;
		val13.playSound = true;
		val13.autoTurnOffWhenEquipped = true;
		GameObject val14 = MeshLibrary.Attach(model, transform, "Katana Mesh", template);
		val14.transform.localPosition = bottom;
		val14.transform.localRotation = rotation;
		Katana katana = val2.AddComponent<Katana>();
		katana.bladeBase = ToItem(new Vector3(0f, 0.272f, 0f));
		katana.bladeTip = ToItem(new Vector3(0f, 0.977f, 0f));
		katana.soundTemplate = val2.GetComponent<ItemMelee>();
		katana.bladeRenderer = val14.GetComponent<MeshRenderer>();
		List<int> list = new List<int>();
		for (int i = 0; i < model.Parts.Count; i++)
		{
			if (model.Parts[i].MaterialName == "Steel Edge" || model.Parts[i].MaterialName == "Steel Hamon")
			{
				list.Add(i);
			}
		}
		katana.glowSlots = list.ToArray();
		if (list.Count < 2)
		{
			Plugin.Log.LogWarning((object)$"Katana: found {list.Count} of the blade's 2 edge materials; the glow will be partial.");
		}
		LogHurtBox(transform, val5, ToItem(new Vector3(0f, 0.272f, 0f)), ToItem(new Vector3(0f, 0.977f, 0f)));
		Plugin.Log.LogInfo((object)(string.Format("Katana from the sword: grip {0}, axis {1}, edge {2} (grip point {3}, ", val9, val11, val12, ((Object)(object)val3 != (Object)null) ? "found" : "guessed") + string.Format("swing point {0}), sword size {1}.", ((Object)(object)val4 != (Object)null) ? "found" : "guessed", ((Bounds)(ref val5)).size)));
		return val2;
		Vector3 ToItem(Vector3 modelPoint)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			return bottom + rotation * modelPoint;
		}
	}

	private static Vector3 WidthAxis(Bounds b, Vector3 axis)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_003b: 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_004d: 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_005a: 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_006f: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: 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_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: 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_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		Vector3 size = ((Bounds)(ref b)).size;
		Vector3[] array = (Vector3[])(object)new Vector3[3]
		{
			Vector3.right,
			Vector3.up,
			Vector3.forward
		};
		float[] array2 = new float[3] { size.x, size.y, size.z };
		Vector3 val = Vector3.zero;
		float num = -1f;
		for (int i = 0; i < 3; i++)
		{
			if (!(Mathf.Abs(Vector3.Dot(array[i], axis)) > 0.7f) && array2[i] > num)
			{
				num = array2[i];
				val = array[i];
			}
		}
		Vector3 val2 = Vector3.ProjectOnPlane(val, axis);
		if (((Vector3)(ref val2)).sqrMagnitude < 1E-06f)
		{
			val2 = Vector3.ProjectOnPlane(Vector3.forward, axis);
		}
		if (((Vector3)(ref val2)).sqrMagnitude < 1E-06f)
		{
			val2 = Vector3.ProjectOnPlane(Vector3.right, axis);
		}
		return ((Vector3)(ref val2)).normalized;
	}

	private static void LogColliders(Transform root)
	{
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: 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)
		StringBuilder stringBuilder = new StringBuilder("Katana: the sword's colliders (kept):");
		Collider[] componentsInChildren = ((Component)root).GetComponentsInChildren<Collider>(true);
		foreach (Collider val in componentsInChildren)
		{
			if (!val.isTrigger && !((Object)(object)((Component)val).GetComponent<HurtCollider>() != (Object)null))
			{
				BoxCollider val2 = (BoxCollider)(object)((val is BoxCollider) ? val : null);
				object obj;
				if (val2 == null)
				{
					CapsuleCollider val3 = (CapsuleCollider)(object)((val is CapsuleCollider) ? val : null);
					obj = ((val3 != null) ? $"capsule r {val3.radius} h {val3.height}" : ((object)val).GetType().Name);
				}
				else
				{
					obj = $"box centre {root.InverseTransformPoint(((Component)val2).transform.TransformPoint(val2.center))} size {Vector3.Scale(val2.size, ((Component)val2).transform.lossyScale)}";
				}
				string arg = (string)obj;
				stringBuilder.Append($"\n  '{((Object)val).name}' {arg}, enabled {val.enabled}");
			}
		}
		Plugin.Log.LogInfo((object)stringBuilder.ToString());
	}

	private static void LogHurtBox(Transform root, Bounds swordBounds, Vector3 bladeBase, Vector3 bladeTip)
	{
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		HurtCollider componentInChildren = ((Component)root).GetComponentInChildren<HurtCollider>(true);
		if ((Object)(object)componentInChildren == (Object)null)
		{
			Plugin.Log.LogWarning((object)"Katana: the sword has no hurt box; it won't do melee damage.");
			return;
		}
		BoxCollider component = ((Component)componentInChildren).GetComponent<BoxCollider>();
		string arg = (((Object)(object)component != (Object)null) ? $"centre {root.InverseTransformPoint(((Component)component).transform.TransformPoint(component.center))}, size {Vector3.Scale(component.size, ((Component)component).transform.lossyScale)}" : "not a box");
		Plugin.Log.LogInfo((object)($"Katana: the sword's hurt box ({arg}) now does {componentInChildren.enemyDamage} damage; " + $"the katana's blade runs {bladeBase} -> {bladeTip}."));
	}

	private static void SetupItem(GameObject go)
	{
		ItemAttributes component = go.GetComponent<ItemAttributes>();
		Item item = component.item;
		Item val = Object.Instantiate<Item>(item);
		((Object)val).name = "Item Melee Katana";
		val.itemName = "Katana";
		val.itemNameLocalized = null;
		val.description = "A razor-sharp katana. Sweep it quickly to the side to slash: the blade hits harder and sends a cutting wave flying forward.";
		GameObject val2 = Resources.Load<GameObject>("Items/Item Melee Baseball Bat");
		ItemAttributes val3 = (((Object)(object)val2 != (Object)null) ? val2.GetComponent<ItemAttributes>() : null);
		Value val4 = (((Object)(object)val3 != (Object)null && (Object)(object)val3.item != (Object)null && (Object)(object)val3.item.value != (Object)null) ? val3.item.value : item.value);
		if ((Object)(object)val4 != (Object)null)
		{
			float num = Settings.ScythePriceMultiplier.Value * Settings.KatanaPriceVsScythe.Value;
			Value val5 = Object.Instantiate<Value>(val4);
			((Object)val5).name = "Item Melee Katana Value";
			val5.valueMin = val4.valueMin * num;
			val5.valueMax = val4.valueMax * num;
			val.value = val5;
		}
		component.item = val;
		component.icon = null;
	}
}
internal class KatanaImpactMark : MonoBehaviour
{
	private const float StrokeTime = 0.07f;

	private const float Hold = 0.25f;

	private const float Fade = 0.45f;

	private static Mesh stroke;

	private static Material material;

	private Transform[] strokes;

	private MeshRenderer[] renderers;

	private MaterialPropertyBlock block;

	private Light flash;

	private float age;

	private float size;

	private static Mesh Stroke
	{
		get
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Expected O, but got Unknown
			if ((Object)(object)stroke != (Object)null)
			{
				return stroke;
			}
			float[] array = new float[5] { -1f, -0.35f, 0f, 0.35f, 1f };
			float[] array2 = new float[5] { 0f, 0.75f, 1f, 0.75f, 0f };
			Color val = default(Color);
			((Color)(ref val))..ctor(0.55f, 0.01f, 0.03f);
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(1f, 0.16f, 0.14f);
			Color[] array3 = (Color[])(object)new Color[5]
			{
				val,
				Color.Lerp(val, val2, 0.5f),
				val2,
				Color.Lerp(val, val2, 0.5f),
				val
			};
			List<Vector3> list = new List<Vector3>();
			List<Color> list2 = new List<Color>();
			List<int> list3 = new List<int>();
			for (int i = 0; i <= 16; i++)
			{
				float num = (float)i / 16f;
				float num2 = 0.045f * Mathf.Pow(Mathf.Max(0f, Mathf.Sin(MathF.PI * num)), 0.8f);
				for (int j = 0; j < array.Length; j++)
				{
					list.Add(new Vector3(num, array[j] * num2, 0f));
					Color item = array3[j];
					item.a = array2[j];
					list2.Add(item);
				}
			}
			int num3 = array.Length;
			for (int k = 0; k < 16; k++)
			{
				for (int l = 0; l < num3 - 1; l++)
				{
					int num4 = k * num3 + l;
					int item2 = num4 + 1;
					int num5 = num4 + num3;
					int item3 = num5 + 1;
					list3.Add(num4);
					list3.Add(num5);
					list3.Add(item2);
					list3.Add(item2);
					list3.Add(num5);
					list3.Add(item3);
				}
			}
			stroke = new Mesh
			{
				name = "HMWP Katana Impact Stroke"
			};
			stroke.SetVertices(list);
			stroke.SetColors(list2);
			stroke.SetTriangles(list3, 0);
			stroke.RecalculateBounds();
			((Object)stroke).hideFlags = (HideFlags)32;
			return stroke;
		}
	}

	private static Material Material
	{
		get
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			if ((Object)(object)material != (Object)null)
			{
				return material;
			}
			Shader val = Shader.Find("Sprites/Default");
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			material = new Material(val)
			{
				name = "HMWP Katana Impact"
			};
			((Object)material).hideFlags = (HideFlags)32;
			return material;
		}
	}

	internal static void Spawn(Vector3 point, float size)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Expected O, but got Unknown
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("HMWP Katana Impact");
		val.transform.position = point;
		KatanaImpactMark katanaImpactMark = val.AddComponent<KatanaImpactMark>();
		katanaImpactMark.size = size;
		katanaImpactMark.block = new MaterialPropertyBlock();
		katanaImpactMark.strokes = (Transform[])(object)new Transform[2];
		katanaImpactMark.renderers = (MeshRenderer[])(object)new MeshRenderer[2];
		for (int i = 0; i < 2; i++)
		{
			Transform transform = new GameObject("Stroke " + (i + 1)).transform;
			transform.SetParent(val.transform, false);
			transform.localRotation = Quaternion.Euler(0f, 0f, (i == 0) ? (-45f) : 45f);
			GameObject val2 = new GameObject("Mesh");
			val2.transform.SetParent(transform, false);
			val2.AddComponent<MeshFilter>().sharedMesh = Stroke;
			MeshRenderer val3 = val2.AddComponent<MeshRenderer>();
			if ((Object)(object)Material != (Object)null)
			{
				((Renderer)val3).sharedMaterial = Material;
			}
			((Renderer)val3).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)val3).receiveShadows = false;
			katanaImpactMark.strokes[i] = transform;
			katanaImpactMark.renderers[i] = val3;
		}
		katanaImpactMark.flash = val.AddComponent<Light>();
		katanaImpactMark.flash.type = (LightType)2;
		katanaImpactMark.flash.color = new Color(0.8f, 0.03f, 0.03f);
		katanaImpactMark.flash.range = 2.5f;
		katanaImpactMark.UpdateLooks();
	}

	private void Update()
	{
		age += Time.deltaTime;
		if (age >= 0.84f)
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
		else
		{
			UpdateLooks();
		}
	}

	private void UpdateLooks()
	{
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		float num = 1f - Mathf.Clamp01((age - 0.14f - 0.25f) / 0.45f);
		float num2 = 1f + 0.25f * Mathf.Clamp01((age - 0.14f - 0.25f) / 0.45f);
		for (int i = 0; i < 2; i++)
		{
			float num3 = Mathf.Clamp01((age - (float)i * 0.07f) / 0.07f);
			Transform obj = strokes[i];
			obj.localScale = new Vector3(size * num2, size * num2, 1f);
			Transform child = obj.GetChild(0);
			child.localPosition = new Vector3(-0.5f, 0f, 0f);
			child.localScale = new Vector3(Mathf.Max(0.001f, num3), 1f, 1f);
			((Renderer)renderers[i]).enabled = num3 > 0f;
			block.SetColor("_Color", new Color(1f, 1f, 1f, num));
			((Renderer)renderers[i]).SetPropertyBlock(block);
		}
		if ((Object)(object)flash != (Object)null)
		{
			flash.intensity = 3f * num * Mathf.Clamp01(age / 0.07f);
		}
	}

	private void LateUpdate()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: 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)
		Camera main = Camera.main;
		if ((Object)(object)main != (Object)null)
		{
			((Component)this).transform.rotation = Quaternion.LookRotation(((Component)this).transform.position - ((Component)main).transform.position, ((Component)main).transform.up);
		}
	}
}
internal class KatanaRift : MonoBehaviour
{
	private enum Phase
	{
		Drawing,
		Opening,
		Holding,
		Closing,
		Fizzling
	}

	private const float DrawWidth = 0.03f;

	private const float OpenWidth = 0.13f;

	private const float OpenTime = 0.1f;

	private const float CloseTime = 0.35f;

	private const float FizzleTime = 0.3f;

	private const float LostTime = 3f;

	private static readonly float[] Rows = new float[7] { -1.9f, -1f, -0.45f, 0f, 0.45f, 1f, 1.9f };

	private static readonly Color Rim = new Color(0.9f, 0.05f, 0.05f);

	private static readonly Color Glow = new Color(0.6f, 0f, 0.02f);

	private static readonly Color Dark = new Color(0.12f, 0f, 0.01f);

	private static readonly Color Black = new Color(0.01f, 0f, 0f);

	private static readonly Color[] RowColour = (Color[])(object)new Color[7] { Glow, Rim, Dark, Black, Dark, Rim, Glow };

	private static readonly float[] RowAlpha = new float[7] { 0f, 1f, 1f, 1f, 1f, 1f, 0f };

	private static Material material;

	private readonly List<Vector3> points = new List<Vector3>();

	private readonly List<float> jag = new List<float>();

	private readonly List<float> girth = new List<float>();

	private readonly List<Vector3> verts = new List<Vector3>();

	private readonly List<Color> colours = new List<Color>();

	private readonly List<int> tris = new List<int>();

	private Mesh mesh;

	private MeshRenderer meshRenderer;

	private MaterialPropertyBlock block;

	private Light glowLight;

	private Phase phase;

	private float phaseTime;

	private float lastAdded;

	private float holdTime;

	private bool centred;

	private Vector3 centre;

	private Vector3 offset;

	private static Material Material
	{
		get
		{
			//IL_0039: 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_004e: Expected O, but got Unknown
			if ((Object)(object)material != (Object)null)
			{
				return material;
			}
			Shader val = Shader.Find("Sprites/Default");
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)"Katana rift: Sprites/Default shader not found; the rift will be invisible.");
				return null;
			}
			material = new Material(val)
			{
				name = "HMWP Katana Rift"
			};
			((Object)material).hideFlags = (HideFlags)32;
			return material;
		}
	}

	internal static KatanaRift Create()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Expected O, but got Unknown
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Expected O, but got Unknown
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Expected O, but got Unknown
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("HMWP Katana Rift");
		KatanaRift katanaRift = val.AddComponent<KatanaRift>();
		katanaRift.mesh = new Mesh
		{
			name = "HMWP Katana Rift"
		};
		katanaRift.mesh.MarkDynamic();
		val.AddComponent<MeshFilter>().sharedMesh = katanaRift.mesh;
		katanaRift.meshRenderer = val.AddComponent<MeshRenderer>();
		if ((Object)(object)Material != (Object)null)
		{
			((Renderer)katanaRift.meshRenderer).sharedMaterial = Material;
		}
		((Renderer)katanaRift.meshRenderer).shadowCastingMode = (ShadowCastingMode)0;
		((Renderer)katanaRift.meshRenderer).receiveShadows = false;
		katanaRift.block = new MaterialPropertyBlock();
		GameObject val2 = new GameObject("Rift Light");
		val2.transform.SetParent(val.transform, false);
		katanaRift.glowLight = val2.AddComponent<Light>();
		katanaRift.glowLight.type = (LightType)2;
		katanaRift.glowLight.color = new Color(0.85f, 0.04f, 0.04f);
		katanaRift.glowLight.range = 2.5f;
		katanaRift.glowLight.intensity = 0f;
		katanaRift.lastAdded = Time.time;
		return katanaRift;
	}

	internal void Add(Vector3 point)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		if (phase == Phase.Drawing)
		{
			points.Add(point);
			float num = ((jag.Count > 0) ? jag[jag.Count - 1] : 0f);
			float num2 = ((girth.Count > 0) ? girth[girth.Count - 1] : 1f);
			jag.Add(Mathf.Clamp(num * 0.55f + Random.Range(-1f, 1f) * 0.6f, -1f, 1f));
			girth.Add(Mathf.Clamp(num2 * 0.6f + Random.Range(0.75f, 1.25f) * 0.4f, 0.75f, 1.25f));
			lastAdded = Time.time;
		}
	}

	internal void CentreOn(Vector3 point)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		centred = true;
		centre = point;
	}

	private Vector3 Middle()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: 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_00ff: 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_009c: 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_00b4: 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)
		float num = 0f;
		for (int i = 1; i < points.Count; i++)
		{
			num += Vector3.Distance(points[i - 1], points[i]);
		}
		float num2 = num * 0.5f;
		float num3 = 0f;
		for (int j = 1; j < points.Count; j++)
		{
			float num4 = Vector3.Distance(points[j - 1], points[j]);
			if (num3 + num4 >= num2)
			{
				if (!(num4 > 1E-06f))
				{
					return points[j];
				}
				return Vector3.Lerp(points[j - 1], points[j], (num2 - num3) / num4);
			}
			num3 += num4;
		}
		if (points.Count <= 0)
		{
			return centre;
		}
		return points[points.Count - 1];
	}

	internal void Open()
	{
		if (phase == Phase.Drawing)
		{
			phase = Phase.Opening;
			phaseTime = 0f;
			holdTime = Mathf.Max(0f, Settings.KatanaRiftDuration.Value - 0.1f - 0.35f);
		}
	}

	internal void Fizzle()
	{
		if (phase == Phase.Drawing || phase == Phase.Opening)
		{
			phase = Phase.Fizzling;
			phaseTime = 0f;
		}
	}

	private void Update()
	{
		phaseTime += Time.deltaTime;
		if (phase == Phase.Drawing && Time.time - lastAdded > 3f)
		{
			Fizzle();
		}
		if (phase == Phase.Opening && phaseTime >= 0.1f)
		{
			phase = Phase.Holding;
			phaseTime = 0f;
		}
		if (phase == Phase.Holding && phaseTime >= holdTime)
		{
			phase = Phase.Closing;
			phaseTime = 0f;
		}
		if ((phase == Phase.Closing && phaseTime >= 0.35f) || (phase == Phase.Fizzling && phaseTime >= 0.3f))
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
	}

	private void LateUpdate()
	{
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0212: Unknown result type (might be due to invalid IL or missing references)
		//IL_0217: Unknown result type (might be due to invalid IL or missing references)
		float width;
		float num;
		float intensity;
		switch (phase)
		{
		case Phase.Opening:
		{
			float num5 = Mathf.Clamp01(phaseTime / 0.1f);
			width = Mathf.Lerp(0.03f, 0.13f, num5);
			num = 1f;
			intensity = Mathf.Lerp(1.5f, 5f, num5);
			break;
		}
		case Phase.Holding:
		{
			float num4 = ((holdTime > 0f) ? Mathf.Clamp01(phaseTime / holdTime) : 1f);
			width = Mathf.Lerp(0.13f, 0.091f, num4) * (0.95f + 0.05f * Mathf.Sin(Time.time * 30f));
			num = 1f;
			intensity = Mathf.Lerp(5f, 3f, num4);
			break;
		}
		case Phase.Closing:
		{
			float num3 = Mathf.Clamp01(phaseTime / 0.35f);
			width = Mathf.Lerp(0.091f, 0f, num3 * num3);
			num = 1f - num3 * num3;
			intensity = 3f * (1f - num3);
			break;
		}
		case Phase.Fizzling:
		{
			float num2 = Mathf.Clamp01(phaseTime / 0.3f);
			width = 0.03f * (1f - num2);
			num = 1f - num2;
			intensity = 1.5f * (1f - num2);
			break;
		}
		default:
			width = 0.03f * (0.9f + 0.1f * Mathf.Sin(Time.time * 40f));
			num = 1f;
			intensity = 1.5f;
			break;
		}
		Rebuild(width);
		block.SetColor("_Color", new Color(1f, 1f, 1f, num));
		((Renderer)meshRenderer).SetPropertyBlock(block);
		if ((Object)(object)glowLight != (Object)null)
		{
			glowLight.intensity = intensity;
			if (points.Count > 0)
			{
				((Component)glowLight).transform.position = points[points.Count / 2] + offset;
			}
		}
	}

	private void Rebuild(float width)
	{
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: 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_0074: 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_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: 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_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		verts.Clear();
		colours.Clear();
		tris.Clear();
		Camera main = Camera.main;
		int count = points.Count;
		if ((Object)(object)main == (Object)null || count < 2)
		{
			mesh.Clear();
			return;
		}
		Vector3 position = ((Component)main).transform.position;
		offset = (centred ? (centre - Middle()) : Vector3.zero);
		for (int i = 0; i < count; i++)
		{
			Vector3 val = Vector3.Cross(points[Mathf.Min(i + 3, count - 1)] - points[Mathf.Max(i - 3, 0)], position - (points[i] + offset));
			val = ((((Vector3)(ref val)).sqrMagnitude > 1E-10f) ? ((Vector3)(ref val)).normalized : Vector3.up);
			float num = (float)i / (float)(count - 1);
			float num2 = Mathf.Pow(Mathf.Max(0f, Mathf.Sin(MathF.PI * num)), 0.6f);
			float num3 = width * num2 * girth[i];
			Vector3 val2 = points[i] + offset + val * (jag[i] * 0.03f * 0.5f * num2);
			for (int j = 0; j < Rows.Length; j++)
			{
				verts.Add(val2 + val * (Rows[j] * num3));
				Color item = RowColour[j];
				item.a = RowAlpha[j];
				colours.Add(item);
			}
		}
		int num4 = Rows.Length;
		for (int k = 0; k < count - 1; k++)
		{
			for (int l = 0; l < num4 - 1; l++)
			{
				int num5 = k * num4 + l;
				int item2 = num5 + 1;
				int num6 = num5 + num4;
				int item3 = num6 + 1;
				tris.Add(num5);
				tris.Add(num6);
				tris.Add(item2);
				tris.Add(item2);
				tris.Add(num6);
				tris.Add(item3);
			}
		}
		mesh.Clear();
		mesh.SetVertices(verts);
		mesh.SetColors(colours);
		mesh.SetTriangles(tris, 0);
		mesh.RecalculateBounds();
	}

	private void OnDestroy()
	{
		if ((Object)(object)mesh != (Object)null)
		{
			Object.Destroy((Object)(object)mesh);
		}
	}
}
internal class KatanaWave : MonoBehaviour
{
	private const float FadeIn = 0.06f;

	private const float FadeOut = 0.25f;

	private const float BreakFade = 0.15f;

	private static readonly Color Red = new Color(0.75f, 0.02f, 0.03f, 1f);

	private static readonly FieldInfo EnemyHealthField = AccessTools.Field(typeof(Enemy), "Health");

	private static readonly FieldInfo EnemyBodyField = AccessTools.Field(typeof(EnemyRigidbody), "rb");

	private static readonly FieldInfo DisabledField = AccessTools.Field(typeof(PlayerAvatar), "isDisabled");

	private static readonly FieldInfo DeadField = AccessTools.Field(typeof(PlayerAvatar), "deadSet");

	private Mesh crescent;

	private static Material material;

	private bool authority;

	private PhysGrabObject self;

	private PlayerAvatar slasher;

	private float age;

	private float width;

	private float thickness;

	private float height;

	private float life;

	private float broken = -1f;

	private readonly HashSet<Object> alreadyHit = new HashSet<Object>();

	private readonly Collider[] found = (Collider[])(object)new Collider[64];

	private MeshRenderer glow;

	private MeshRenderer core;

	private MaterialPropertyBlock block;

	private Light lightSource;

	private const float ArcHalfAngle = 0.87266463f;

	private const float EdgeRow = 0.8f;

	private float Growth => Mathf.Lerp(1f, Settings.KatanaWaveGrowth.Value, Mathf.Clamp01(age / Mathf.Max(0.01f, life)));

	private static int WallMask => LayerMask.GetMask(new string[3] { "Default", "StaticGrabObject", "PhysGrabObjectHinge" });

	private float Depth => Lead(width) + thickness * 0.5f;

	private static Material Material
	{
		get
		{
			//IL_0039: 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_004e: Expected O, but got Unknown
			if ((Object)(object)material != (Object)null)
			{
				return material;
			}
			Shader val = Shader.Find("Sprites/Default");
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)"Katana wave: Sprites/Default shader not found; the wave will be invisible.");
				return null;
			}
			material = new Material(val)
			{
				name = "HMWP Katana Wave"
			};
			((Object)material).hideFlags = (HideFlags)32;
			return material;
		}
	}

	private static bool Flag(FieldInfo f, object o)
	{
		if (f != null)
		{
			return (bool)f.GetValue(o);
		}
		return false;
	}

	internal static void Spawn(Vector3 position, Quaternion rotation, float span, bool authority, PhysGrabObject self, PlayerAvatar slasher)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Expected O, but got Unknown
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("HMWP Katana Wave");
		val.transform.SetPositionAndRotation(position, rotation);
		KatanaWave katanaWave = val.AddComponent<KatanaWave>();
		katanaWave.authority = authority;
		katanaWave.self = self;
		katanaWave.slasher = slasher;
		katanaWave.width = Mathf.Max(0.2f, span);
		katanaWave.thickness = Settings.KatanaWaveThickness.Value;
		katanaWave.height = Settings.KatanaWaveHeight.Value;
		katanaWave.life = Settings.KatanaWaveLifetime.Value;
		katanaWave.block = new MaterialPropertyBlock();
		Mesh mesh = (katanaWave.crescent = Crescent(katanaWave.width, katanaWave.thickness, katanaWave.height));
		katanaWave.glow = Layer(val.transform, "Glow", mesh, new Vector3(1.06f, 1.35f, 1.12f));
		katanaWave.core = Layer(val.transform, "Core", mesh, Vector3.one);
		katanaWave.lightSource = val.AddComponent<Light>();
		katanaWave.lightSource.type = (LightType)2;
		katanaWave.lightSource.color = Red;
		katanaWave.lightSource.range = 5f;
		katanaWave.lightSource.intensity = 0f;
		katanaWave.UpdateLooks();
	}

	private static MeshRenderer Layer(Transform parent, string name, Mesh mesh, Vector3 scale)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject(name);
		val.transform.SetParent(parent, false);
		val.transform.localScale = scale;
		val.AddComponent<MeshFilter>().sharedMesh = mesh;
		MeshRenderer val2 = val.AddComponent<MeshRenderer>();
		if ((Object)(object)Material != (Object)null)
		{
			((Renderer)val2).sharedMaterial = Material;
		}
		((Renderer)val2).shadowCastingMode = (ShadowCastingMode)0;
		((Renderer)val2).receiveShadows = false;
		return val2;
	}

	private void FixedUpdate()
	{
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: 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: 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)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: 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_00e0: 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)
		float fixedDeltaTime = Time.fixedDeltaTime;
		age += fixedDeltaTime;
		if (broken >= 0f)
		{
			broken += fixedDeltaTime;
			if (broken >= 0.15f)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
			return;
		}
		if (age >= life + 0.25f)
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
			return;
		}
		Vector3 position = ((Component)this).transform.position;
		Vector3 val = ((Component)this).transform.forward * Settings.KatanaWaveSpeed.Value * fixedDeltaTime;
		float magnitude = ((Vector3)(ref val)).magnitude;
		RaycastHit val2 = default(RaycastHit);
		if (Settings.KatanaWaveStopsAtWalls.Value && age > 0.05f && Physics.Raycast(position, ((Component)this).transform.forward, ref val2, magnitude, WallMask, (QueryTriggerInteraction)1))
		{
			magnitude = ((RaycastHit)(ref val2)).distance;
			val = ((Component)this).transform.forward * magnitude;
			broken = 0f;
		}
		Grow();
		if (authority && age <= life)
		{
			HitAlong(position, val);
		}
		((Component)this).transform.position = position + val;
	}

	private void Grow()
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		((Component)this).transform.localScale = new Vector3(Growth, 1f, 1f);
	}

	private void HitAlong(Vector3 from, Vector3 step)
	{
		//IL_0058: 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_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_006f: 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_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_030f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0310: Unknown result type (might be due to invalid IL or missing references)
		//IL_026c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0275: Unknown result type (might be due to invalid IL or missing references)
		//IL_027e: 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_0294: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
		float magnitude = ((Vector3)(ref step)).magnitude;
		Vector3 val = default(Vector3);
		((Vector3)(ref val))..ctor(width * Growth * 0.5f, Mathf.Max(height * 0.5f, 0.3f) + 0.2f, magnitude * 0.5f + Depth * 0.5f + 0.2f);
		Vector3 val2 = from + step * 0.5f + ((Component)this).transform.forward * BackOffset(width, thickness);
		Vector3 forward = ((Component)this).transform.forward;
		int value = Settings.KatanaWaveDamage.Value;
		float value2 = Settings.KatanaWavePush.Value;
		int num = Physics.OverlapBoxNonAlloc(val2, val, found, ((Component)this).transform.rotation, -1, (QueryTriggerInteraction)1);
		for (int i = 0; i < num; i++)
		{
			Collider val3 = found[i];
			if ((Object)(object)val3 == (Object)null || ((Object)(object)self != (Object)null && (Object)(object)((Component)val3).GetComponentInParent<PhysGrabObject>() == (Object)(object)self))
			{
				continue;
			}
			EnemyRigidbody componentInParent = ((Component)val3).GetComponentInParent<EnemyRigidbody>();
			Enemy val4 = (((Object)(object)componentInParent != (Object)null) ? componentInParent.enemy : ((Component)val3).GetComponentInParent<Enemy>());
			try
			{
				if ((Object)(object)val4 != (Object)null)
				{
					if (alreadyHit.Add((Object)(object)val4))
					{
						object? obj = EnemyHealthField?.GetValue(val4);
						EnemyHealth val5 = (EnemyHealth)(((obj is EnemyHealth) ? obj : null) ?? ((Component)val4).GetComponentInChildren<EnemyHealth>());
						if ((Object)(object)val5 != (Object)null && value > 0)
						{
							val5.Hurt(value, forward);
						}
						Rigidbody val6 = (Rigidbody)(((Object)(object)componentInParent != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
						if ((Object)(object)val6 != (Object)null && value2 > 0f)
						{
							val6.AddForce(forward * value2, (ForceMode)1);
						}
						Mark(val3, val2, forward);
						if (Settings.KatanaDebugLog.Value)
						{
							Plugin.Log.LogInfo((object)$"Katana wave hit {((Object)val4).name}: {value} damage.");
						}
					}
				}
				else if (((Object)val3).name.StartsWith("Hitbox") && alreadyHit.Add((Object)(object)((Component)val3).transform.root))
				{
					((Component)val3).SendMessageUpwards("TargetDummyHit", (object)new float[5] { value, forward.x, forward.y, forward.z, value2 }, (SendMessageOptions)1);
					Mark(val3, val2, forward);
					if (Settings.KatanaDebugLog.Value)
					{
						Plugin.Log.LogInfo((object)$"Katana wave hit dummy {((Object)((Component)val3).transform.root).name}: {value} damage.");
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Katana wave hit failed: " + ex.Message));
			}
		}
		if (Settings.KatanaWaveFriendlyFire.Value)
		{
			HitPlayers(val2, val, value);
		}
	}

	private void Mark(Collider c, Vector3 centre, Vector3 dir)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: 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_0029: 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_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: 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_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: 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_004b: 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_0054: 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_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		Katana katana = (((Object)(object)self != (Object)null) ? ((Component)self).GetComponent<Katana>() : null);
		Vector3 val = centre - dir * 3f;
		MeshCollider val2 = (MeshCollider)(object)((c is MeshCollider) ? c : null);
		Vector3 val3;
		Bounds bounds;
		if (val2 == null || val2.convex)
		{
			val3 = c.ClosestPoint(val);
		}
		else
		{
			bounds = c.bounds;
			val3 = ((Bounds)(ref bounds)).ClosestPoint(val);
		}
		Vector3 val4 = val3;
		val4 -= dir * 0.08f;
		bounds = c.bounds;
		Vector3 size = ((Bounds)(ref bounds)).size;
		float size2 = Mathf.Clamp(((Vector3)(ref size)).magnitude * 0.6f, 0.6f, 1.4f);
		if ((Object)(object)katana != (Object)null)
		{
			katana.ShowImpact(val4, size2);
		}
		else
		{
			KatanaImpactMark.Spawn(val4, size2);
		}
	}

	private void HitPlayers(Vector3 centre, Vector3 half, int damage)
	{
		//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_0010: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: 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_00dc: 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_00f9: 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_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		Quaternion val = Quaternion.Inverse(((Component)this).transform.rotation);
		foreach (PlayerAvatar item in SemiFunc.PlayerGetList())
		{
			if ((Object)(object)item == (Object)null || (Object)(object)item == (Object)(object)slasher || !((Component)item).gameObject.activeInHierarchy || (Object)(object)item.playerHealth == (Object)null || Flag(DisabledField, item) || Flag(DeadField, item) || alreadyHit.Contains((Object)(object)item))
			{
				continue;
			}
			for (float num = 0.4f; num <= 1.6f; num += 0.6f)
			{
				Vector3 val2 = ((Component)item).transform.position + Vector3.up * num;
				Vector3 val3 = val * (val2 - centre);
				if (!(Mathf.Abs(val3.x) > half.x + 0.35f) && !(Mathf.Abs(val3.y) > half.y + 0.35f) && !(Mathf.Abs(val3.z) > half.z + 0.35f))
				{
					alreadyHit.Add((Object)(object)item);
					try
					{
						item.playerHealth.HurtOther(damage, val2, false, -1, false);
					}
					catch (Exception ex)
					{
						Plugin.Log.LogWarning((object)("Katana wave player hit failed: " + ex.Message));
					}
					if (Settings.KatanaDebugLog.Value)
					{
						Plugin.Log.LogInfo((object)$"Katana wave hit player {((Object)item).name}: {damage} damage.");
					}
					break;
				}
			}
		}
	}

	private void Update()
	{
		UpdateLooks();
	}

	private void OnDestroy()
	{
		if ((Object)(object)crescent != (Object)null)
		{
			Object.Destroy((Object)(object)crescent);
		}
	}

	private void UpdateLooks()
	{
		//IL_00a9: 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)
		float num = Mathf.Clamp01(age / 0.06f);
		if (age > life)
		{
			num *= 1f - Mathf.Clamp01((age - life) / 0.25f);
		}
		if (broken >= 0f)
		{
			num *= 1f - Mathf.Clamp01(broken / 0.15f);
		}
		float num2 = 0.92f + 0.08f * Mathf.Sin(age * 47f);
		block.SetColor("_Color", new Color(0.8f, 0.05f, 0.06f, 0.4f * num * num2));
		if ((Object)(object)glow != (Object)null)
		{
			((Renderer)glow).SetPropertyBlock(block);
		}
		block.SetColor("_Color", new Color(1f, 1f, 1f, num));
		if ((Object)(object)core != (Object)null)
		{
			((Renderer)core).SetPropertyBlock(block);
		}
		if ((Object)(object)lightSource != (Object)null)
		{
			lightSource.intensity = 3f * num;
		}
	}

	private static float ArcRadius(float width)
	{
		return width * 0.5f / Mathf.Sin(0.87266463f);
	}

	private static float Lead(float width)
	{
		return ArcRadius(width) * (1f - Mathf.Cos(0.87266463f));
	}

	private static float BackOffset(float width, float thickness)
	{
		float num = thickness * 0.5f * 0.19999999f;
		float num2 = 0f - (Lead(width) + 0.8f * thickness * 0.5f);
		return (num + num2) * 0.5f;
	}

	private static Mesh Crescent(float width, float thickness, float height)
	{
		//IL_008d: 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_0095: 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_009d: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: 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_00c0: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: 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_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: Expected O, but got Unknown
		//IL_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0230: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: Unknown result type (might be due to invalid IL or missing references)
		//IL_0247: Unknown result type (might be due to invalid IL or missing references)
		//IL_024c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0250: Unknown result type (might be due to invalid IL or missing references)
		Color val = default(Color);
		((Color)(ref val))..ctor(0.3f, 0f, 0.02f);
		Color val2 = default(Color);
		((Color)(ref val2))..ctor(0.62f, 0.01f, 0.04f);
		Color val3 = default(Color);
		((Color)(ref val3))..ctor(0.95f, 0.1f, 0.1f);
		float[] rows = new float[7] { -1f, -0.6f, -0.2f, 0.2f, 0.55f, 0.8f, 1f };
		float[] alpha = new float[7] { 0f, 0.3f, 0.5f, 0.7f, 0.95f, 1f, 0f };
		Color[] colour = (Color[])(object)new Color[7]
		{
			val,
			val,
			val2,
			val2,
			Color.Lerp(val2, val3, 0.5f),
			val3,
			val2
		};
		float[] bandRows = new float[5] { -1f, -0.45f, 0f, 0.45f, 1f };
		float[] bandAlpha = new float[5] { 0f, 0.6f, 1f, 0.6f, 0f };
		Color[] bandColour = (Color[])(object)new Color[5]
		{
			val2,
			Color.Lerp(val2, val3, 0.5f),
			val3,
			Color.Lerp(val2, val3, 0.5f),
			val2
		};
		float radius = ArcRadius(width);
		float num = Lead(width);
		float shiftZ = 0f - (num + 0.8f * thickness * 0.5f);
		List<Vector3> verts = new List<Vector3>();
		List<Color> colours = new List<Color>();
		List<int> tris = new List<int>();
		Strip(rows.Length, (float t, int r) => OnCrescent(t, rows[r]), delegate(float t, int r)
		{
			//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_0023: Unknown result type (might be due to invalid IL or missing references)
			Color result = colour[r];
			result.a = alpha[r] * TipFade(t);
			return result;
		});
		Strip(bandRows.Length, (float t, int r) => OnCrescent(t, 0.8f) + Vector3.up * (bandRows[r] * height * 0.5f * Taper(t)), delegate(float t, int r)
		{
			//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_0023: Unknown result type (might be due to invalid IL or missing references)
			Color result = bandColour[r];
			result.a = bandAlpha[r] * TipFade(t);
			return result;
		});
		Mesh val4 = new Mesh
		{
			name = "HMWP Katana Wave"
		};
		val4.SetVertices(verts);
		val4.SetColors(colours);
		val4.SetTriangles(tris, 0);
		val4.RecalculateBounds();
		Bounds bounds = val4.bounds;
		if (!float.IsNaN(((Bounds)(ref bounds)).size.x))
		{
			bounds = val4.bounds;
			if (!float.IsNaN(((Bounds)(ref bounds)).size.z))
			{
				goto IL_0270;
			}
		}
		Plugin.Log.LogWarning((object)"Katana wave: the crescent mesh has invalid points; it won't be visible.");
		goto IL_0270;
		IL_0270:
		return val4;
		Vector3 OnCrescent(float t, float v)
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			float num2 = t * 0.87266463f;
			float num3 = thickness * 0.5f * Mathf.Pow(Mathf.Max(0f, Mathf.Cos(t * MathF.PI * 0.5f)), 0.9f);
			float num4 = radius + v * num3;
			return new Vector3(Mathf.Sin(num2) * num4, 0f, Mathf.Cos(num2) * num4 - radius * Mathf.Cos(0.87266463f) + shiftZ);
		}
		void Strip(int rowCount, Func<float, int, Vector3> at, Func<float, int, Color> col)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			int count = verts.Count;
			for (int i = 0; i <= 48; i++)
			{
				float arg = (float)i / 48f * 2f - 1f;
				for (int j = 0; j < rowCount; j++)
				{
					verts.Add(at(arg, j));
					colours.Add(col(arg, j));
				}
			}
			for (int k = 0; k < 48; k++)
			{
				for (int l = 0; l < rowCount - 1; l++)
				{
					int num2 = count + k * rowCount + l;
					int item = num2 + 1;
					int num3 = num2 + rowCount;
					int item2 = num3 + 1;
					tris.Add(num2);
					tris.Add(num3);
					tris.Add(item);
					tris.Add(item);
					tris.Add(num3);
					tris.Add(item2);
				}
			}
		}
		static float Taper(float t)
		{
			return Mathf.Pow(Mathf.Max(0f, Mathf.Cos(t * MathF.PI * 0.5f)), 0.7f);
		}
		static float TipFade(float t)
		{
			return 1f - Mathf.Pow(Mathf.Abs(t), 6f);
		}
	}
}
internal static class MeshLibrary
{
	internal class Part
	{
		public string MaterialName;

		public Color Color;

		public float Smoothness;

		public float Metallic;
	}

	internal class Model
	{
		public string Name;

		public Mesh Mesh;

		public List<Part> Parts = new List<Part>();
	}

	private static readonly Dictionary<string, Dictionary<string, Model>> cache = new Dictionary<string, Dictionary<string, Model>>();

	private static readonly Dictionary<string, Material> materialCache = new Dictionary<string, Material>();

	internal static Model Get(string file, string objectName)
	{
		if (!cache.TryGetValue(file, out var value))
		{
			value = (cache[file] = Load(file));
		}
		if (value == null || !value.TryGetValue(objectName, out var value2))
		{
			return null;
		}
		return value2;
	}

	private static Dictionary<string, Model> Load(string file)
	{
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e9: Expected O, but got Unknown
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		string text = "HatterMeleeWeaponsPack.Assets." + file;
		using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(text);
		if (stream == null)
		{
			Plugin.Log.LogError((object)("Embedded model '" + text + "' is missing."));
			return null;
		}
		using BinaryReader binaryReader = new BinaryReader(stream);
		if (Encoding.ASCII.GetString(binaryReader.ReadBytes(4)) != "HWM1")
		{
			Plugin.Log.LogError((object)("'" + file + "' is not a HWM1 model."));
			return null;
		}
		Dictionary<string, Model> dictionary = new Dictionary<string, Model>();
		int num = binaryReader.ReadInt32();
		for (int i = 0; i < num; i++)
		{
			Model model = new Model
			{
				Name = ReadString(binaryReader)
			};
			List<Vector3> list = new List<Vector3>();
			List<Vector3> list2 = new List<Vector3>();
			List<int[]> list3 = new List<int[]>();
			int num2 = binaryReader.ReadInt32();
			for (int j = 0; j < num2; j++)
			{
				Part part = new Part
				{
					MaterialName = ReadString(binaryReader)
				};
				part.Color = new Color(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
				part.Smoothness = binaryReader.ReadSingle();
				part