Decompiled source of RuneheimSouls v0.52.8

plugins/RuneheimSouls.dll

Decompiled a day ago
using System;
using System.Buffers;
using System.Buffers.Binary;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using ErEngine;
using ErEngine.Anim;
using ErEngine.Sim;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using MagicaCloth2;
using Microsoft.CodeAnalysis;
using Microsoft.Win32;
using RuneheimCore;
using RuneheimSouls;
using RuneheimSouls.ErPort;
using SoftReferenceableAssets;
using Splatform;
using TMPro;
using Unity.Collections;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.Utilities;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using UnityEngine.UI;
using Valheim.SettingsGui;
using Valheim.UI;
using ZstdSharp;
using ZstdSharp.Unsafe;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("Daytreee")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright (c) 2026 Daytreee. All rights reserved. Not open source: no reuse, decompiling or redistribution without permission.")]
[assembly: AssemblyFileVersion("0.49.0.0")]
[assembly: AssemblyInformationalVersion("0.49.0+ad4bb541ee1eb3871221fb22e835a5e157d2fce6")]
[assembly: AssemblyProduct("Runeheim Souls")]
[assembly: AssemblyTitle("RuneheimSouls")]
[assembly: AssemblyVersion("0.49.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
internal static class RhSafe
{
	private static class Holder<F>
	{
		public static F Value;
	}

	private static ManualLogSource _log;

	private static readonly HashSet<string> _said = new HashSet<string>();

	private const int MaxReports = 300;

	private static ManualLogSource Log
	{
		get
		{
			if (_log == null)
			{
				_log = Logger.CreateLogSource(typeof(RhSafe).Assembly.GetName().Name + " (checks)");
			}
			return _log;
		}
	}

	private static void Warn(string key, string text)
	{
		try
		{
			lock (_said)
			{
				if (_said.Count >= 300 || !_said.Add(key))
				{
					return;
				}
			}
			Log.LogWarning((object)text);
		}
		catch
		{
		}
	}

	private static string Where(string file, int line)
	{
		return Path.GetFileName(file) + ":" + line;
	}

	public static void Swallowed(Exception e, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0, [CallerMemberName] string member = "")
	{
		string text = Where(file, line);
		object obj;
		if (e == null)
		{
			obj = null;
		}
		else
		{
			string? stackTrace = e.StackTrace;
			obj = ((stackTrace == null) ? null : stackTrace.Split(new char[1] { '\n' })[0]?.Trim());
		}
		if (obj == null)
		{
			obj = "";
		}
		string text2 = (string)obj;
		Warn("catch " + text, "Handled error in " + member + " (" + text + "): " + e?.GetType().Name + ": " + e?.Message + " " + text2);
	}

	private static ref F Dummy<T, F>(T instance)
	{
		return ref Holder<F>.Value;
	}

	private static ref F DummyStatic<F>()
	{
		return ref Holder<F>.Value;
	}

	public static FieldRef<T, F> FieldRef<T, F>(string name, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
	{
		try
		{
			return AccessTools.FieldRefAccess<T, F>(name);
		}
		catch (Exception ex)
		{
			Warn("field " + typeof(T).FullName + "." + name, typeof(T).Name + "." + name + " (as " + typeof(F).Name + ") can't be read (" + Where(file, line) + "): " + ex.GetBaseException().Message + ". What uses it is switched off.");
			return Dummy<T, F>;
		}
	}

	public static FieldRef<T, F> FieldRef<T, F>(FieldInfo field, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
	{
		try
		{
			if (field != null)
			{
				return AccessTools.FieldRefAccess<T, F>(field);
			}
		}
		catch (Exception ex)
		{
			Warn("field " + field?.DeclaringType?.FullName + "." + field?.Name, field?.DeclaringType?.Name + "." + field?.Name + " can't be read (" + Where(file, line) + "): " + ex.GetBaseException().Message + ". What uses it is switched off.");
			return Dummy<T, F>;
		}
		Warn("field null " + Where(file, line), "A field looked up at " + Where(file, line) + " wasn't found. What uses it is switched off.");
		return Dummy<T, F>;
	}

	public static FieldRef<F> StaticFieldRef<F>(Type type, string name, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
	{
		try
		{
			FieldInfo fieldInfo = ((type != null) ? AccessTools.Field(type, name) : null);
			if (fieldInfo != null)
			{
				return AccessTools.StaticFieldRefAccess<F>(fieldInfo);
			}
			Warn("static " + type?.FullName + "." + name, type?.Name + "." + name + " wasn't found (" + Where(file, line) + "). What uses it is switched off.");
		}
		catch (Exception ex)
		{
			Warn("static " + type?.FullName + "." + name, type?.Name + "." + name + " (as " + typeof(F).Name + ") can't be read (" + Where(file, line) + "): " + ex.GetBaseException().Message + ". What uses it is switched off.");
		}
		return DummyStatic<F>;
	}

	public static D MethodDelegate<D>(MethodInfo method, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0) where D : Delegate
	{
		try
		{
			if (method != null)
			{
				return AccessTools.MethodDelegate<D>(method, (object)null, true);
			}
			Warn("method null " + Where(file, line), "A method looked up at " + Where(file, line) + " wasn't found. What uses it is switched off.");
		}
		catch (Exception ex)
		{
			Warn("method " + method?.DeclaringType?.FullName + "." + method?.Name, method?.DeclaringType?.Name + "." + method?.Name + " can't be called (" + Where(file, line) + "): " + ex.GetBaseException().Message + ". What uses it is switched off.");
		}
		return null;
	}
}
public class ME_ParticleTrails : MonoBehaviour
{
	public GameObject TrailPrefab;

	private ParticleSystem ps;

	private Particle[] particles;

	private Dictionary<uint, GameObject> hashTrails = new Dictionary<uint, GameObject>();

	private Dictionary<uint, GameObject> newHashTrails = new Dictionary<uint, GameObject>();

	private List<GameObject> currentGO = new List<GameObject>();

	private void Start()
	{
		//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)
		ps = ((Component)this).GetComponent<ParticleSystem>();
		MainModule main = ps.main;
		particles = (Particle[])(object)new Particle[((MainModule)(ref main)).maxParticles];
	}

	private void OnEnable()
	{
		((MonoBehaviour)this).InvokeRepeating("ClearEmptyHashes", 1f, 1f);
	}

	private void OnDisable()
	{
		Clear();
		((MonoBehaviour)this).CancelInvoke("ClearEmptyHashes");
	}

	public void Clear()
	{
		foreach (GameObject item in currentGO)
		{
			Object.Destroy((Object)(object)item);
		}
		currentGO.Clear();
	}

	private void Update()
	{
		UpdateTrail();
	}

	private void UpdateTrail()
	{
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: 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_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: 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_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Invalid comparison between Unknown and I4
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: 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_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		newHashTrails.Clear();
		int num = ps.GetParticles(particles);
		for (int i = 0; i < num; i++)
		{
			if (!hashTrails.ContainsKey(((Particle)(ref particles[i])).randomSeed))
			{
				GameObject val = Object.Instantiate<GameObject>(TrailPrefab, ((Component)this).transform.position, default(Quaternion));
				val.transform.parent = ((Component)this).transform;
				currentGO.Add(val);
				newHashTrails.Add(((Particle)(ref particles[i])).randomSeed, val);
				LineRenderer component = val.GetComponent<LineRenderer>();
				component.widthMultiplier *= ((Particle)(ref particles[i])).startSize;
				continue;
			}
			GameObject val2 = hashTrails[((Particle)(ref particles[i])).randomSeed];
			if ((Object)(object)val2 != (Object)null)
			{
				LineRenderer component2 = val2.GetComponent<LineRenderer>();
				component2.startColor *= Color32.op_Implicit(((Particle)(ref particles[i])).GetCurrentColor(ps));
				component2.endColor *= Color32.op_Implicit(((Particle)(ref particles[i])).GetCurrentColor(ps));
				MainModule main = ps.main;
				if ((int)((MainModule)(ref main)).simulationSpace == 1)
				{
					val2.transform.position = ((Particle)(ref particles[i])).position;
				}
				main = ps.main;
				if ((int)((MainModule)(ref main)).simulationSpace == 0)
				{
					val2.transform.position = ((Component)ps).transform.TransformPoint(((Particle)(ref particles[i])).position);
				}
				newHashTrails.Add(((Particle)(ref particles[i])).randomSeed, val2);
			}
			hashTrails.Remove(((Particle)(ref particles[i])).randomSeed);
		}
		foreach (KeyValuePair<uint, GameObject> hashTrail in hashTrails)
		{
			if ((Object)(object)hashTrail.Value != (Object)null)
			{
				hashTrail.Value.GetComponent<ME_TrailRendererNoise>().IsActive = false;
			}
		}
		AddRange(hashTrails, newHashTrails);
	}

	public void AddRange<T, S>(Dictionary<T, S> source, Dictionary<T, S> collection)
	{
		if (collection == null)
		{
			return;
		}
		foreach (KeyValuePair<T, S> item in collection)
		{
			if (!source.ContainsKey(item.Key))
			{
				source.Add(item.Key, item.Value);
			}
		}
	}

	private void ClearEmptyHashes()
	{
		hashTrails = hashTrails.Where((KeyValuePair<uint, GameObject> h) => (Object)(object)h.Value != (Object)null).ToDictionary((KeyValuePair<uint, GameObject> h) => h.Key, (KeyValuePair<uint, GameObject> h) => h.Value);
	}
}
public class ME_TrailRendererNoise : MonoBehaviour
{
	[Range(0.01f, 10f)]
	public float MinVertexDistance = 0.1f;

	public float VertexTime = 1f;

	public float TotalLifeTime = 3f;

	public bool SmoothCurves;

	public bool IsRibbon;

	public bool IsActive = true;

	[Range(0.001f, 10f)]
	public float Frequency = 1f;

	[Range(0.001f, 10f)]
	public float TimeScale = 0.1f;

	[Range(0.001f, 10f)]
	public float Amplitude = 1f;

	public float Gravity = 1f;

	public float TurbulenceStrength = 1f;

	public bool AutodestructWhenNotActive;

	private LineRenderer lineRenderer;

	private Transform t;

	private Vector3 prevPos;

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

	private List<float> lifeTimes = new List<float>(500);

	private List<Vector3> velocities = new List<Vector3>(500);

	private float randomOffset;

	private List<Vector3> controlPoints = new List<Vector3>();

	private int curveCount;

	private const float MinimumSqrDistance = 0.01f;

	private const float DivisionThreshold = -0.99f;

	private const float SmoothCurvesScale = 0.5f;

	private void Start()
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: 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)
		lineRenderer = ((Component)this).GetComponent<LineRenderer>();
		lineRenderer.useWorldSpace = true;
		t = ((Component)this).transform;
		prevPos = t.position;
		points.Insert(0, t.position);
		lifeTimes.Insert(0, VertexTime);
		velocities.Insert(0, Vector3.zero);
		randomOffset = (float)Random.Range(0, 10000000) / 1000000f;
	}

	private void OnEnable()
	{
		points.Clear();
		lifeTimes.Clear();
		velocities.Clear();
	}

	private void Update()
	{
		if (IsActive)
		{
			AddNewPoints();
		}
		UpdatetPoints();
		if (SmoothCurves && points.Count > 2)
		{
			UpdateLineRendererBezier();
		}
		else
		{
			UpdateLineRenderer();
		}
		if (AutodestructWhenNotActive && !IsActive && points.Count <= 1)
		{
			Object.Destroy((Object)(object)((Component)this).gameObject, TotalLifeTime);
		}
	}

	private void AddNewPoints()
	{
		//IL_0006: 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_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_0087: 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_009e: 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_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = t.position - prevPos;
		if (!(((Vector3)(ref val)).magnitude > MinVertexDistance) && (!IsRibbon || points.Count != 0))
		{
			if (!IsRibbon || points.Count <= 0)
			{
				return;
			}
			val = t.position - points[0];
			if (!(((Vector3)(ref val)).magnitude > MinVertexDistance))
			{
				return;
			}
		}
		prevPos = t.position;
		points.Insert(0, t.position);
		lifeTimes.Insert(0, VertexTime);
		velocities.Insert(0, Vector3.zero);
	}

	private void UpdatetPoints()
	{
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < lifeTimes.Count; i++)
		{
			lifeTimes[i] -= Time.deltaTime;
			if (lifeTimes[i] <= 0f)
			{
				int count = lifeTimes.Count - i;
				lifeTimes.RemoveRange(i, count);
				points.RemoveRange(i, count);
				velocities.RemoveRange(i, count);
				break;
			}
			CalculateTurbuelence(points[i], TimeScale, Frequency, Amplitude, Gravity, i);
		}
	}

	private void UpdateLineRendererBezier()
	{
		if (SmoothCurves && points.Count > 2)
		{
			InterpolateBezier(points, 0.5f);
			List<Vector3> drawingPoints = GetDrawingPoints();
			lineRenderer.positionCount = drawingPoints.Count - 1;
			lineRenderer.SetPositions(drawingPoints.ToArray());
		}
	}

	private void UpdateLineRenderer()
	{
		lineRenderer.positionCount = Mathf.Clamp(points.Count - 1, 0, int.MaxValue);
		lineRenderer.SetPositions(points.ToArray());
	}

	private void CalculateTurbuelence(Vector3 position, float speed, float scale, float height, float gravity, int index)
	{
		//IL_000f: 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_002b: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		float num = Time.timeSinceLevelLoad * speed + randomOffset;
		float num2 = position.x * scale + num;
		float num3 = position.y * scale + num + 10f;
		float num4 = position.z * scale + num + 25f;
		position.x = (Mathf.PerlinNoise(num3, num4) - 0.5f) * height * Time.deltaTime;
		position.y = (Mathf.PerlinNoise(num2, num4) - 0.5f) * height * Time.deltaTime - gravity * Time.deltaTime;
		position.z = (Mathf.PerlinNoise(num2, num3) - 0.5f) * height * Time.deltaTime;
		List<Vector3> list = points;
		list[index] += position * TurbulenceStrength;
	}

	public void InterpolateBezier(List<Vector3> segmentPoints, float scale)
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: 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_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_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_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: 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_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//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_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: 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_011a: 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_0123: 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_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_008c: 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_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
		controlPoints.Clear();
		if (segmentPoints.Count < 2)
		{
			return;
		}
		for (int i = 0; i < segmentPoints.Count; i++)
		{
			if (i == 0)
			{
				Vector3 val = segmentPoints[i];
				Vector3 val2 = segmentPoints[i + 1] - val;
				Vector3 item = val + scale * val2;
				controlPoints.Add(val);
				controlPoints.Add(item);
				continue;
			}
			if (i == segmentPoints.Count - 1)
			{
				Vector3 val3 = segmentPoints[i - 1];
				Vector3 val4 = segmentPoints[i];
				Vector3 val5 = val4 - val3;
				Vector3 item2 = val4 - scale * val5;
				controlPoints.Add(item2);
				controlPoints.Add(val4);
				continue;
			}
			Vector3 val6 = segmentPoints[i - 1];
			Vector3 val7 = segmentPoints[i];
			Vector3 val8 = segmentPoints[i + 1];
			Vector3 val9 = val8 - val6;
			Vector3 normalized = ((Vector3)(ref val9)).normalized;
			Vector3 val10 = scale * normalized;
			val9 = val7 - val6;
			Vector3 item3 = val7 - val10 * ((Vector3)(ref val9)).magnitude;
			Vector3 val11 = scale * normalized;
			val9 = val8 - val7;
			Vector3 item4 = val7 + val11 * ((Vector3)(ref val9)).magnitude;
			controlPoints.Add(item3);
			controlPoints.Add(val7);
			controlPoints.Add(item4);
		}
		curveCount = (controlPoints.Count - 1) / 3;
	}

	public List<Vector3> GetDrawingPoints()
	{
		List<Vector3> list = new List<Vector3>();
		for (int i = 0; i < curveCount; i++)
		{
			List<Vector3> list2 = FindDrawingPoints(i);
			if (i != 0)
			{
				list2.RemoveAt(0);
			}
			list.AddRange(list2);
		}
		return list;
	}

	private List<Vector3> FindDrawingPoints(int curveIndex)
	{
		//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)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		List<Vector3> list = new List<Vector3>();
		Vector3 item = CalculateBezierPoint(curveIndex, 0f);
		Vector3 item2 = CalculateBezierPoint(curveIndex, 1f);
		list.Add(item);
		list.Add(item2);
		FindDrawingPoints(curveIndex, 0f, 1f, list, 1);
		return list;
	}

	private int FindDrawingPoints(int curveIndex, float t0, float t1, List<Vector3> pointList, int insertionIndex)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: 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_0012: 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_0014: 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_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: 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)
		Vector3 val = CalculateBezierPoint(curveIndex, t0);
		Vector3 val2 = CalculateBezierPoint(curveIndex, t1);
		Vector3 val3 = val - val2;
		if (((Vector3)(ref val3)).sqrMagnitude < 0.01f)
		{
			return 0;
		}
		float num = (t0 + t1) / 2f;
		Vector3 val4 = CalculateBezierPoint(curveIndex, num);
		val3 = val - val4;
		Vector3 normalized = ((Vector3)(ref val3)).normalized;
		val3 = val2 - val4;
		Vector3 normalized2 = ((Vector3)(ref val3)).normalized;
		if (Vector3.Dot(normalized, normalized2) > -0.99f || Mathf.Abs(num - 0.5f) < 0.0001f)
		{
			int num2 = 0;
			num2 += FindDrawingPoints(curveIndex, t0, num, pointList, insertionIndex);
			pointList.Insert(insertionIndex + num2, val4);
			num2++;
			return num2 + FindDrawingPoints(curveIndex, num, t1, pointList, insertionIndex + num2);
		}
		return 0;
	}

	public Vector3 CalculateBezierPoint(int curveIndex, float t)
	{
		//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_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: 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_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		int num = curveIndex * 3;
		Vector3 p = controlPoints[num];
		Vector3 p2 = controlPoints[num + 1];
		Vector3 p3 = controlPoints[num + 2];
		Vector3 p4 = controlPoints[num + 3];
		return CalculateBezierPoint(t, p, p2, p3, p4);
	}

	private Vector3 CalculateBezierPoint(float t, Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3)
	{
		//IL_0017: 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_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		float num = 1f - t;
		float num2 = t * t;
		float num3 = num * num;
		float num4 = num3 * num;
		float num5 = num2 * t;
		return num4 * p0 + 3f * num3 * t * p1 + 3f * num * num2 * p2 + num5 * p3;
	}
}
public class ME_LightCurves : MonoBehaviour
{
	public AnimationCurve LightCurve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);

	public float GraphTimeMultiplier = 1f;

	public float GraphIntensityMultiplier = 1f;

	public bool IsLoop;

	private bool canUpdate;

	private float startTime;

	private Light lightSource;

	private void Awake()
	{
		lightSource = ((Component)this).GetComponent<Light>();
		lightSource.intensity = LightCurve.Evaluate(0f);
	}

	private void OnEnable()
	{
		startTime = Time.time;
		canUpdate = true;
	}

	private void Update()
	{
		float num = Time.time - startTime;
		if (canUpdate)
		{
			float intensity = LightCurve.Evaluate(num / GraphTimeMultiplier) * GraphIntensityMultiplier;
			lightSource.intensity = intensity;
		}
		if (num >= GraphTimeMultiplier)
		{
			if (IsLoop)
			{
				startTime = Time.time;
			}
			else
			{
				canUpdate = false;
			}
		}
	}
}
[ExecuteInEditMode]
public class ME_CustomLight : MonoBehaviour
{
	private void Update()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: 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)
		SphericalHarmonicsL2 val = default(SphericalHarmonicsL2);
		LightProbes.GetInterpolatedProbe(((Component)this).transform.position, (Renderer)null, ref val);
		Vector3 val2 = default(Vector3);
		((Vector3)(ref val2))..ctor(((SphericalHarmonicsL2)(ref val))[0, 0] - ((SphericalHarmonicsL2)(ref val))[0, 6], ((SphericalHarmonicsL2)(ref val))[1, 0] - ((SphericalHarmonicsL2)(ref val))[1, 6], ((SphericalHarmonicsL2)(ref val))[2, 0] - ((SphericalHarmonicsL2)(ref val))[2, 6]);
		val2 = Vector3.Max(val2, Vector3.zero);
		Shader.SetGlobalVector("ME_AmbientColor", Vector4.op_Implicit(val2));
	}
}
[ExecuteInEditMode]
public class ME_ParticleCollisionDecal : MonoBehaviour
{
	public ParticleSystem DecalParticles;

	public bool IsBilboard;

	public bool InstantiateWhenZeroSpeed;

	public float MaxGroundAngleDeviation = 45f;

	public float MinDistanceBetweenDecals = 0.1f;

	public float MinDistanceBetweenSurface = 0.03f;

	private List<ParticleCollisionEvent> collisionEvents = new List<ParticleCollisionEvent>();

	private Particle[] particles;

	private ParticleSystem initiatorPS;

	private List<GameObject> collidedGameObjects = new List<GameObject>();

	private void OnEnable()
	{
		//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)
		collisionEvents.Clear();
		collidedGameObjects.Clear();
		initiatorPS = ((Component)this).GetComponent<ParticleSystem>();
		MainModule main = DecalParticles.main;
		particles = (Particle[])(object)new Particle[((MainModule)(ref main)).maxParticles];
		if (InstantiateWhenZeroSpeed)
		{
			((MonoBehaviour)this).InvokeRepeating("CollisionDetect", 0f, 0.1f);
		}
	}

	private void OnDisable()
	{
		if (InstantiateWhenZeroSpeed)
		{
			((MonoBehaviour)this).CancelInvoke("CollisionDetect");
		}
	}

	private void CollisionDetect()
	{
		int aliveParticles = 0;
		if (InstantiateWhenZeroSpeed)
		{
			aliveParticles = DecalParticles.GetParticles(particles);
		}
		foreach (GameObject collidedGameObject in collidedGameObjects)
		{
			OnParticleCollisionManual(collidedGameObject, aliveParticles);
		}
	}

	private void OnParticleCollisionManual(GameObject other, int aliveParticles = -1)
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: 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_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_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: 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_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: 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)
		collisionEvents.Clear();
		int num = ParticlePhysicsExtensions.GetCollisionEvents(initiatorPS, other, collisionEvents);
		for (int i = 0; i < num; i++)
		{
			ParticleCollisionEvent val = collisionEvents[i];
			if (Vector3.Angle(((ParticleCollisionEvent)(ref val)).normal, Vector3.up) > MaxGroundAngleDeviation)
			{
				continue;
			}
			if (InstantiateWhenZeroSpeed)
			{
				val = collisionEvents[i];
				Vector3 velocity = ((ParticleCollisionEvent)(ref val)).velocity;
				if (((Vector3)(ref velocity)).sqrMagnitude > 0.1f)
				{
					continue;
				}
				bool flag = false;
				for (int j = 0; j < aliveParticles; j++)
				{
					val = collisionEvents[i];
					if (Vector3.Distance(((ParticleCollisionEvent)(ref val)).intersection, ((Particle)(ref particles[j])).position) < MinDistanceBetweenDecals)
					{
						flag = true;
					}
				}
				if (flag)
				{
					continue;
				}
			}
			EmitParams val2 = default(EmitParams);
			val = collisionEvents[i];
			Vector3 intersection = ((ParticleCollisionEvent)(ref val)).intersection;
			val = collisionEvents[i];
			((EmitParams)(ref val2)).position = intersection + ((ParticleCollisionEvent)(ref val)).normal * MinDistanceBetweenSurface;
			val = collisionEvents[i];
			Quaternion val3 = Quaternion.LookRotation(-((ParticleCollisionEvent)(ref val)).normal);
			Vector3 eulerAngles = ((Quaternion)(ref val3)).eulerAngles;
			eulerAngles.z = Random.Range(0, 360);
			((EmitParams)(ref val2)).rotation3D = eulerAngles;
			DecalParticles.Emit(val2, 1);
		}
	}

	private void OnParticleCollision(GameObject other)
	{
		if (InstantiateWhenZeroSpeed)
		{
			if (!collidedGameObjects.Contains(other))
			{
				collidedGameObjects.Add(other);
			}
		}
		else
		{
			OnParticleCollisionManual(other);
		}
	}
}
namespace ErEngine
{
	internal static class BalanceSync
	{
		private const string RPC = "Eldenheim_Balance";

		private const string SetRPC = "Eldenheim_BalanceSet";

		public static string PendingNotice;

		private static ConfigFile _config;

		private static Dictionary<ConfigEntryBase, string> _own;

		private static bool _savedBefore;

		private static bool _applying;

		public static bool UsingServer => _own != null;

		public static bool Applying => _applying;

		public static bool Locked
		{
			get
			{
				if (UsingServer)
				{
					return !RhServer.IsAdmin;
				}
				return false;
			}
		}

		private static IEnumerable<ConfigEntryBase> Entries()
		{
			return from k in _config.Keys
				where Server(k.Section)
				select _config[k] into e
				orderby e.Definition.Key
				select e;
		}

		private static bool Server(string section)
		{
			return section.EndsWith("(server)");
		}

		public static void Apply(Harmony h, ConfigFile config)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Expected O, but got Unknown
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			_config = config;
			_config.SettingChanged += delegate(object _, SettingChangedEventArgs args)
			{
				if (Server(args.ChangedSetting.Definition.Section))
				{
					Changed();
					if (!_applying && UsingServer && RhServer.IsAdmin && (Object)(object)ZNet.instance != (Object)null && !ZNet.instance.IsServer())
					{
						ZNetPeer serverPeer = ZNet.instance.GetServerPeer();
						if (serverPeer != null)
						{
							serverPeer.m_rpc.Invoke("Eldenheim_BalanceSet", new object[2]
							{
								args.ChangedSetting.Definition.Key,
								args.ChangedSetting.GetSerializedValue()
							});
						}
					}
				}
			};
			h.Patch((MethodBase)AccessTools.Method(typeof(ZNet), "OnNewConnection", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(BalanceSync), "Connected", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			h.Patch((MethodBase)AccessTools.Method(typeof(ZNet), "RPC_PeerInfo", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(BalanceSync), "PeerInfo", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			h.Patch((MethodBase)AccessTools.Method(typeof(ZNet), "OnDestroy", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(BalanceSync), "Left", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		private static ZPackage Values()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			ZPackage val = new ZPackage();
			List<ConfigEntryBase> list = Entries().ToList();
			val.Write(list.Count);
			foreach (ConfigEntryBase item in list)
			{
				val.Write(item.Definition.Key);
				val.Write(item.GetSerializedValue());
			}
			return val;
		}

		private static void Changed()
		{
			if (_applying || (Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer())
			{
				return;
			}
			foreach (ZNetPeer peer in ZNet.instance.GetPeers())
			{
				peer.m_rpc.Invoke("Eldenheim_Balance", new object[1] { Values() });
			}
		}

		private static void Connected(ZNet __instance, ZNetPeer peer)
		{
			if (!__instance.IsServer())
			{
				peer.m_rpc.Register<ZPackage>("Eldenheim_Balance", (Action<ZRpc, ZPackage>)Received);
			}
			else
			{
				peer.m_rpc.Register<string, string>("Eldenheim_BalanceSet", (Action<ZRpc, string, string>)AdminSet);
			}
		}

		private static void PeerInfo(ZNet __instance, ZRpc rpc)
		{
			if (__instance.IsServer() && rpc.IsConnected())
			{
				rpc.Invoke("Eldenheim_Balance", new object[1] { Values() });
			}
		}

		private static void AdminSet(ZRpc rpc, string key, string value)
		{
			object obj;
			if (rpc == null)
			{
				obj = null;
			}
			else
			{
				ISocket socket = rpc.GetSocket();
				obj = ((socket != null) ? socket.GetHostName() : null);
			}
			string text = (string)obj;
			if ((Object)(object)ZNet.instance == (Object)null || string.IsNullOrEmpty(text) || !ZNet.instance.IsAdmin(text))
			{
				Plugin.Report("balance: refused a change of " + key + " from a player who isn't an admin (" + text + ")");
			}
			else
			{
				ConfigEntryBase val = Entries().FirstOrDefault((Func<ConfigEntryBase, bool>)((ConfigEntryBase x) => x.Definition.Key == key));
				if (val != null)
				{
					val.SetSerializedValue(value);
				}
			}
		}

		private static void Received(ZRpc rpc, ZPackage pkg)
		{
			Dictionary<string, ConfigEntryBase> dictionary = Entries().ToDictionary((ConfigEntryBase e) => e.Definition.Key);
			if (_own == null)
			{
				_own = dictionary.Values.ToDictionary((ConfigEntryBase e) => e, (ConfigEntryBase e) => e.GetSerializedValue());
				_savedBefore = _config.SaveOnConfigSet;
				_config.SaveOnConfigSet = false;
			}
			_applying = true;
			try
			{
				int num = pkg.ReadInt();
				for (int num2 = 0; num2 < num; num2++)
				{
					string key = pkg.ReadString();
					string serializedValue = pkg.ReadString();
					if (dictionary.TryGetValue(key, out var value))
					{
						value.SetSerializedValue(serializedValue);
					}
				}
			}
			finally
			{
				_applying = false;
			}
			Plugin.Report("balance: using the server's settings");
			if (Settings.RequireCombatOnly != null && Settings.RequireCombatOnly.Value && !CombatOnly.Active)
			{
				if (CombatOnly.Setting != null)
				{
					CombatOnly.Setting.Value = true;
				}
				PendingNotice = "This server requires Souls Combat Only. It's now switched on: restart the game to play with it.";
			}
		}

		private static void Left()
		{
			if (_own == null)
			{
				return;
			}
			_applying = true;
			try
			{
				foreach (KeyValuePair<ConfigEntryBase, string> item in _own)
				{
					item.Key.SetSerializedValue(item.Value);
				}
			}
			finally
			{
				_applying = false;
			}
			_own = null;
			_config.SaveOnConfigSet = _savedBefore;
			if (_savedBefore)
			{
				_config.Save();
			}
		}
	}
	public class Bindings
	{
		public static readonly Dictionary<string, bool> Forced = new Dictionary<string, bool>();

		public static Vector2? ForcedStick;

		private readonly Dictionary<string, InputControl> _controls = new Dictionary<string, InputControl>();

		private readonly Dictionary<string, bool> _was = new Dictionary<string, bool>();

		private Input _pending;

		private bool _walk;

		private readonly HashSet<string> _blocked = new HashSet<string>();

		private readonly HashSet<string> _heldOver = new HashSet<string>();

		private bool _hadInput;

		private bool _hadMenu;

		private bool _hadPadInventory;

		private bool _radial;

		private bool _padInventory;

		private static readonly string[] Actions = new string[10] { "Dodge", "Sprint", "Jump", "LightAttack", "HeavyAttack", "Guard", "Crouch", "Walk", "LockOn", "TwoHandModifier" };

		private bool _sprintHeld;

		private bool _padSprint;

		private bool _padSprintWas;

		private static readonly Bindings Probe = new Bindings();

		private static float _padModifierSince = -1f;

		public static bool ModifierHeld()
		{
			if (Forced.TryGetValue("TwoHandModifier", out var value))
			{
				return value;
			}
			if (Probe.Read(Settings.Keyboard["TwoHandModifier"].Value))
			{
				return true;
			}
			if (_padModifierSince >= 0f)
			{
				return Time.unscaledTime - _padModifierSince >= 0.15f;
			}
			return false;
		}

		public static bool LightHeld()
		{
			if (Forced.TryGetValue("LightAttack", out var value))
			{
				return value;
			}
			if (!Probe.Read(Settings.Keyboard["LightAttack"].Value))
			{
				return Probe.Read(Settings.Gamepad["LightAttack"].Value);
			}
			return true;
		}

		public static void TrackModifier()
		{
			_padModifierSince = ((!Probe.Read(Settings.Gamepad["TwoHandModifier"].Value)) ? (-1f) : ((_padModifierSince < 0f) ? Time.unscaledTime : _padModifierSince));
		}

		private bool Down(string action)
		{
			if (Forced.TryGetValue(action, out var value))
			{
				return value;
			}
			if (_radial)
			{
				return false;
			}
			if (_padInventory && (!Settings.DodgeInInventory.Value || (!(action == "Dodge") && !(action == "Sprint"))))
			{
				return false;
			}
			if (!Read(Settings.Keyboard[action].Value))
			{
				_heldOver.Remove(action);
			}
			else if (!_heldOver.Contains(action))
			{
				return true;
			}
			bool num = Read(Settings.Gamepad[action].Value);
			if (!num)
			{
				_blocked.Remove(action);
			}
			if (num)
			{
				return !_blocked.Contains(action);
			}
			return false;
		}

		private bool Read(string binding)
		{
			if (string.IsNullOrEmpty(binding))
			{
				return false;
			}
			if (binding.StartsWith("Valheim:"))
			{
				return ZInput.GetButton(binding.Substring(8));
			}
			if (binding.StartsWith("<Gamepad>/") && Gamepad.current != null)
			{
				InputControl obj = ((InputControl)Gamepad.current).TryGetChildControl(binding.Substring(10));
				ButtonControl val = (ButtonControl)(object)((obj is ButtonControl) ? obj : null);
				if (val != null)
				{
					return val.isPressed;
				}
				return false;
			}
			if (!_controls.TryGetValue(binding, out var value) || value == null || !value.device.added)
			{
				value = InputSystem.FindControl(binding);
				_controls[binding] = value;
			}
			ButtonControl val2 = (ButtonControl)(object)((value is ButtonControl) ? value : null);
			if (val2 != null)
			{
				return val2.isPressed;
			}
			return false;
		}

		public void IgnoreHeld(params string[] keep)
		{
			string[] actions = Actions;
			foreach (string text in actions)
			{
				if (!keep.Contains(text))
				{
					if (Read(Settings.Keyboard[text].Value))
					{
						_heldOver.Add(text);
					}
					if (Read(Settings.Gamepad[text].Value))
					{
						_blocked.Add(text);
					}
				}
			}
		}

		private static void Feed(ref Button b, bool down, bool pressed, bool released)
		{
			b.Held = down;
			b.Pressed |= pressed;
			b.Released |= released;
		}

		private bool Edge(string action, out bool pressed, out bool released)
		{
			bool flag = Down(action);
			_was.TryGetValue(action, out var value);
			_was[action] = flag;
			pressed = flag && !value;
			released = !flag && value;
			return flag;
		}

		public void Gather(bool takeInput, bool menuOpen, float camYawUnityDeg, bool padInventory = false, bool radial = false)
		{
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: 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)
			_radial = radial && Forced.Count == 0;
			menuOpen = menuOpen || radial;
			if (takeInput && (!_hadInput || (_hadMenu && !menuOpen) || padInventory != _hadPadInventory))
			{
				_padInventory = false;
				string[] actions = Actions;
				foreach (string text in actions)
				{
					if (Read(Settings.Gamepad[text].Value))
					{
						_blocked.Add(text);
					}
				}
			}
			_hadInput = takeInput;
			_hadMenu = menuOpen;
			_hadPadInventory = padInventory;
			_padInventory = padInventory;
			if (!takeInput)
			{
				foreach (string item in new List<string>(_was.Keys))
				{
					_was[item] = false;
				}
				_pending.Mv = default(Vec2);
				_padSprint = (_padSprintWas = false);
				_pending.Dodge.Held = (_pending.Jump.Held = (_pending.Light.Held = (_pending.Heavy.Held = (_pending.Guard.Held = false))));
				return;
			}
			Vector2 val = (Vector2)(((??)ForcedStick) ?? ((padInventory && !Settings.LeftJoystickInventory.Value) ? Vector2.zero : ReadStick()));
			_pending.Mv = new Vec2(val.x, val.y);
			_pending.CamYaw = Space.YawToSim(camYawUnityDeg);
			bool pressed;
			bool released;
			bool flag = Edge("TwoHandModifier", out pressed, out released);
			bool pressed2;
			bool released2;
			bool held = Edge("Dodge", out pressed2, out released2);
			bool flag2 = false;
			if (menuOpen && !padInventory && Forced.Count == 0)
			{
				held = (pressed2 = (released2 = false));
			}
			bool value = Settings.SeparateSprint.Value;
			bool flag3 = Settings.Dodge.Value == DodgeTrigger.Press || value;
			if (value || flag3)
			{
				bool flag4 = value && Edge("Sprint", out released, out pressed) && (!menuOpen || padInventory || Forced.Count != 0);
				bool flag5 = value && !_radial && (!_padInventory || Settings.DodgeInInventory.Value) && Read(Settings.Gamepad["Sprint"].Value) && !_blocked.Contains("Sprint");
				flag2 = flag5 && !_padSprintWas;
				_padSprintWas = flag5;
				float magnitude = ((Vector2)(ref val)).magnitude;
				if ((PadLayout.Sprint == null || PadLayout.Sprint.Value == PadLayout.SprintKind.Click) && flag2 && magnitude > 0.3f && (!menuOpen || padInventory))
				{
					_padSprint = true;
				}
				if (magnitude < 0.2f || !value)
				{
					_padSprint = false;
				}
				flag4 |= _padSprint;
				if (flag3 ? pressed2 : released2)
				{
					_pending.Dodge.Pressed = true;
					_pending.Dodge.Released = true;
				}
				if (flag4 != _sprintHeld)
				{
					if (flag4)
					{
						_pending.Dodge.Pressed = true;
					}
					else
					{
						_pending.Dodge.Released = true;
					}
					_sprintHeld = flag4;
				}
				_pending.Dodge.Held = _sprintHeld;
			}
			else
			{
				_pending.Dodge.Held = held;
				_pending.Dodge.Pressed |= pressed2;
				_pending.Dodge.Released |= released2;
			}
			bool pressed3;
			bool released3;
			bool down = Edge("Jump", out pressed3, out released3);
			Feed(ref _pending.Jump, down, pressed3, released3);
			bool pressed4;
			bool released4;
			bool down2 = Edge("LightAttack", out pressed4, out released4);
			bool pressed5;
			bool released5;
			bool down3 = Edge("HeavyAttack", out pressed5, out released5);
			bool pressed6;
			bool released6;
			bool down4 = Edge("Guard", out pressed6, out released6);
			if (menuOpen && Forced.Count == 0)
			{
				down2 = (down3 = (down4 = (pressed4 = (pressed5 = (pressed6 = false)))));
				flag = false;
			}
			if (flag)
			{
				_pending.TwoHandRight |= pressed4;
				_pending.TwoHandLeft |= pressed6;
				pressed4 = (pressed6 = false);
				down2 = (down4 = false);
			}
			Feed(ref _pending.Light, down2, pressed4, released4);
			Feed(ref _pending.Heavy, down3, pressed5, released5);
			Feed(ref _pending.Guard, down4, pressed6, released6);
			Edge("Crouch", out var pressed7, out pressed);
			if (flag2 && ((Vector2)(ref val)).magnitude > 0.3f && Settings.Gamepad["Crouch"].Value == Settings.Gamepad["Sprint"].Value)
			{
				pressed7 = false;
			}
			_pending.Crouch |= pressed7 && !menuOpen;
			Edge("Walk", out var pressed8, out pressed);
			if (pressed8)
			{
				_walk = !_walk;
			}
			_pending.Walk = _walk;
			Edge("LockOn", out var pressed9, out pressed);
			_pending.Lock |= pressed9;
		}

		private static Vector2 ReadStick()
		{
			//IL_00a3: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			float num = 0f;
			float num2 = 0f;
			if (ZInput.GetButton("Forward"))
			{
				num2 += 1f;
			}
			if (ZInput.GetButton("Backward"))
			{
				num2 -= 1f;
			}
			if (ZInput.GetButton("Right"))
			{
				num += 1f;
			}
			if (ZInput.GetButton("Left"))
			{
				num -= 1f;
			}
			Vector2 result = default(Vector2);
			((Vector2)(ref result))..ctor(num, num2);
			if (((Vector2)(ref result)).sqrMagnitude > 1f)
			{
				((Vector2)(ref result)).Normalize();
			}
			Gamepad current = Gamepad.current;
			if (current != null)
			{
				Vector2 val = ((InputControl<Vector2>)(object)current.leftStick).ReadValue();
				if (((Vector2)(ref val)).sqrMagnitude > ((Vector2)(ref result)).sqrMagnitude)
				{
					result = val;
					return result;
				}
			}
			return result;
		}

		public Input Take()
		{
			Input pending = _pending;
			_pending.Dodge.Pressed = (_pending.Dodge.Released = false);
			_pending.Jump.Pressed = (_pending.Jump.Released = false);
			_pending.Light.Pressed = (_pending.Light.Released = false);
			_pending.Heavy.Pressed = (_pending.Heavy.Released = false);
			_pending.Guard.Pressed = (_pending.Guard.Released = false);
			_pending.Crouch = (_pending.Lock = (_pending.TwoHandRight = (_pending.TwoHandLeft = false)));
			_pending.NextWeapon = (_pending.NextLeft = false);
			return pending;
		}
	}
	public class Controller : MonoBehaviour
	{
		private enum BowPhase
		{
			None,
			Draw,
			Hold,
			Fire
		}

		private struct SkinnedPair
		{
			public Vector3 AxisRight;

			public Vector3 AxisLeft;

			public Vector3 OffsetRight;

			public Vector3 OffsetLeft;

			public Vector2 RangeRight;

			public Vector2 RangeLeft;

			public float RadiusRight;

			public float RadiusLeft;
		}

		private sealed class PairSplit
		{
			public GameObject Instance;

			public Vector3[] R0;

			public Vector3[] L0;

			public float[] DriftR;

			public float[] DriftL;

			public float Next;
		}

		private const int BOW_START = 36010;

		private const int BOW_START_AGAIN = 36011;

		private const int BOW_HOLD = 36020;

		private const int BOW_LOOSE = 36000;

		private const int BOW_CROUCH = 500;

		private const float BOW_IN = 0.12f;

		private const float BOW_OUT = 0.25f;

		private static FieldRef<VisEquipment, int> _visLeftItem;

		private static bool _visLeftItemFailed;

		private static readonly string[] BowUpperBones = new string[13]
		{
			"Spine", "Spine1", "Spine2", "Neck", "Head", "LeftShoulder", "LeftArm", "LeftForeArm", "LeftHand", "RightShoulder",
			"RightArm", "RightForeArm", "RightHand"
		};

		private BowPhase _bowPhase;

		private bool _bowAgain;

		private bool _bowWasDrawing;

		private float _bowT;

		private float _bowW;

		private int _bowFrame = -1;

		private Clip _bowClip;

		private bool _bowLooped;

		private ErPose _bowEr;

		private Quaternion[] _bowLocal;

		private int[] _bowUpper;

		private int _bowSpine = -1;

		private int _bowSpine1 = -1;

		private int _bowSpine2 = -1;

		public static Controller Local;

		public static Clips Clips;

		public bool BlockingNow;

		public Character LockTarget;

		public readonly List<string> Log = new List<string>();

		public string Why = "";

		public IFighterBrain Brain;

		private Player _vp;

		private Rigidbody _body;

		private Animator _animator;

		private VisEquipment _vis;

		private readonly Bindings _bindings = new Bindings();

		private readonly PhysicsLevel _level = new PhysicsLevel();

		private readonly Combat _combat = new Combat();

		private readonly Combat.Blade _rightBlade = new Combat.Blade();

		private readonly Combat.Blade _leftBlade = new Combat.Blade();

		private Steps _steps;

		private Chooser _chooser;

		private Retarget _retarget;

		private PoseOutput _pose;

		private Quaternion[] _local;

		private float _acc;

		private float _weight;

		private ItemData _lastRight;

		private ItemData _lastLeft;

		private Grip _lastGrip;

		private GameObject _lastRightInstance;

		private GameObject _lastLeftInstance;

		private Vector3 _bladeRight;

		private Vector3 _bladeLeft;

		private Vector2 _rangeRight;

		private Vector2 _rangeLeft;

		private Vector3 _offsetRight;

		private Vector3 _offsetLeft;

		private float _radiusRight;

		private float _radiusLeft;

		private float _clock;

		private bool _recenter;

		private float _bodyY;

		private float _stepEase;

		private float _rootY;

		private Vector3 _rootAt;

		private float _grip;

		private bool _counterSounded;

		private Vector3 _tickFrom;

		private Vector3 _tickTo;

		private Vector3 _expected;

		private float _yawFrom;

		private float _yawTo;

		private static readonly FieldRef<Character, Vector3> RootMotion = RhSafe.FieldRef<Character, Vector3>("m_rootMotion", "RuneheimSouls\\ErEngine\\Controller.cs", 86);

		private static readonly FieldRef<Character, Vector3> CurrentVel = RhSafe.FieldRef<Character, Vector3>("m_currentVel", "RuneheimSouls\\ErEngine\\Controller.cs", 87);

		private static readonly FieldRef<Character, float> MaxAirAltitude = RhSafe.FieldRef<Character, float>("m_maxAirAltitude", "RuneheimSouls\\ErEngine\\Controller.cs", 88);

		private static readonly FieldRef<Character, bool> Running = RhSafe.FieldRef<Character, bool>("m_running", "RuneheimSouls\\ErEngine\\Controller.cs", 89);

		private static readonly FieldRef<Character, float> LastGroundTouch = RhSafe.FieldRef<Character, float>("m_lastGroundTouch", "RuneheimSouls\\ErEngine\\Controller.cs", 90);

		private static readonly FieldRef<Character, float> JumpTimer = RhSafe.FieldRef<Character, float>("m_jumpTimer", "RuneheimSouls\\ErEngine\\Controller.cs", 91);

		private static readonly FieldRef<Character, Vector3> PushForce = RhSafe.FieldRef<Character, Vector3>("m_pushForce", "RuneheimSouls\\ErEngine\\Controller.cs", 92);

		private static readonly FieldRef<Character, bool> HasGroundContact = RhSafe.FieldRef<Character, bool>("m_groundContact", "RuneheimSouls\\ErEngine\\Controller.cs", 93);

		private static readonly FieldRef<Character, Vector3> ContactNormal = RhSafe.FieldRef<Character, Vector3>("m_groundContactNormal", "RuneheimSouls\\ErEngine\\Controller.cs", 94);

		private static readonly FieldRef<Character, Vector3> ContactPoint = RhSafe.FieldRef<Character, Vector3>("m_groundContactPoint", "RuneheimSouls\\ErEngine\\Controller.cs", 95);

		private static readonly FieldRef<Character, Collider> LowestContact = RhSafe.FieldRef<Character, Collider>("m_lowestContactCollider", "RuneheimSouls\\ErEngine\\Controller.cs", 96);

		private static readonly FieldRef<Character, bool> Sliding = RhSafe.FieldRef<Character, bool>("m_sliding", "RuneheimSouls\\ErEngine\\Controller.cs", 97);

		private static readonly FieldRef<Character, bool> WallRunning = RhSafe.FieldRef<Character, bool>("m_wallRunning", "RuneheimSouls\\ErEngine\\Controller.cs", 98);

		private Vector3 _carry;

		private static readonly FieldRef<Humanoid, ItemData> RightItem = RhSafe.FieldRef<Humanoid, ItemData>("m_rightItem", "RuneheimSouls\\ErEngine\\Controller.cs", 100);

		private static readonly FieldRef<Humanoid, ItemData> LeftItem = RhSafe.FieldRef<Humanoid, ItemData>("m_leftItem", "RuneheimSouls\\ErEngine\\Controller.cs", 101);

		private static readonly FieldRef<VisEquipment, GameObject> RightInstance = RhSafe.FieldRef<VisEquipment, GameObject>("m_rightItemInstance", "RuneheimSouls\\ErEngine\\Controller.cs", 102);

		private static readonly FieldRef<VisEquipment, GameObject> LeftInstance = RhSafe.FieldRef<VisEquipment, GameObject>("m_leftItemInstance", "RuneheimSouls\\ErEngine\\Controller.cs", 103);

		private static readonly MethodInfo TakeInput = AccessTools.Method(typeof(PlayerController), "TakeInput", (Type[])null, (Type[])null);

		private static readonly Func<PlayerController, bool, bool> TakeInputFast = ((TakeInput != null) ? AccessTools.MethodDelegate<Func<PlayerController, bool, bool>>(TakeInput, (object)null, true) : null);

		private PlayerController _pc;

		private static bool padBusyMissing;

		private bool _povDodging;

		private float _povGuardAt = -10f;

		private bool _leapQueued;

		private float _leapAt;

		private bool _povCrouch;

		private bool _povDodgeTaken;

		private bool _povAir;

		private static readonly MethodInfo SetCrouchM = AccessTools.Method(typeof(Player), "SetCrouch", (Type[])null, (Type[])null);

		private static readonly FieldRef<Character, Vector3> MoveDirRef = RhSafe.FieldRef<Character, Vector3>("m_moveDir", "RuneheimSouls\\ErEngine\\Controller.cs", 194);

		private static readonly List<Controller> All = new List<Controller>();

		private static readonly int StateKey = StringExtensionMethods.GetStableHashCode("eh_pose");

		private static readonly int DataKey = StringExtensionMethods.GetStableHashCode("eh_data");

		private static readonly FieldRef<VisEquipment, int> RightHash = RhSafe.FieldRef<VisEquipment, int>("m_currentRightItemHash", "RuneheimSouls\\ErEngine\\Controller.cs", 323);

		private static readonly FieldRef<VisEquipment, int> LeftHash = RhSafe.FieldRef<VisEquipment, int>("m_currentLeftItemHash", "RuneheimSouls\\ErEngine\\Controller.cs", 324);

		private static readonly FieldRef<VisEquipment, int> RightQuality = RhSafe.FieldRef<VisEquipment, int>("m_currentRightItemQuality", "RuneheimSouls\\ErEngine\\Controller.cs", 325);

		private static readonly FieldRef<VisEquipment, int> LeftQuality = RhSafe.FieldRef<VisEquipment, int>("m_currentLeftItemQuality", "RuneheimSouls\\ErEngine\\Controller.cs", 326);

		private static readonly FieldRef<VisEquipment, int> LeftVariant = RhSafe.FieldRef<VisEquipment, int>("m_currentLeftItemVariant", "RuneheimSouls\\ErEngine\\Controller.cs", 327);

		private ZNetView _nview;

		private byte[] _sent;

		private byte[] _got;

		private uint _revision;

		private bool _warned;

		private ItemData _remoteRight;

		private ItemData _remoteLeft;

		private bool _sentInvincible;

		private Grip? _keptGrip;

		private ItemData _keptRight;

		private ItemData _keptLeft;

		private bool _syncInstantly;

		private bool _swapping;

		private Vector3Int _swapTo;

		private static readonly Dictionary<string, SkinnedPair> SkinnedCache = new Dictionary<string, SkinnedPair>();

		private GameObject _twin;

		private GameObject _twinOf;

		private bool _leftShield;

		private bool _skinnedBlades;

		private string _pairKey;

		private PairSplit _pairSplit;

		private int _lastMovesets;

		private readonly HashSet<GameObject> _hidden = new HashSet<GameObject>();

		private readonly Dictionary<GameObject, Behaviour[]> _hiddenLights = new Dictionary<GameObject, Behaviour[]>();

		private static readonly Dictionary<string, float> PoleTip = new Dictionary<string, float>
		{
			{ "Halberd", 1.87f },
			{ "Banished Knight's Halberd", 1.9f },
			{ "Short Spear", 1.66f },
			{ "Smithscript Spear", 1.66f },
			{ "Great Spear", 2.26f },
			{ "Guardian's Swordspear", 1.84f },
			{ "Cross-Naginata", 2f }
		};

		private readonly Dictionary<GameObject, Vector3> _poleRest = new Dictionary<GameObject, Vector3>();

		public static Vector3 LeftBladeAxis = Vector3.down;

		public static Vector3 ShieldFaceAxis = Vector3.forward;

		private static readonly MethodInfo AttachBackItem = AccessTools.Method(typeof(VisEquipment), "AttachBackItem", (Type[])null, (Type[])null);

		private static readonly MethodInfo TriggerEquipEffect = AccessTools.Method(typeof(Humanoid), "TriggerEquipEffect", (Type[])null, (Type[])null);

		private static readonly FieldRef<VisEquipment, GameObject> RightBack = RhSafe.FieldRef<VisEquipment, GameObject>("m_rightBackItemInstance", "RuneheimSouls\\ErEngine\\Controller.cs", 1496);

		private static readonly FieldRef<VisEquipment, GameObject> LeftBack = RhSafe.FieldRef<VisEquipment, GameObject>("m_leftBackItemInstance", "RuneheimSouls\\ErEngine\\Controller.cs", 1497);

		private ItemData _sheathed;

		private GameObject _sheathedBack;

		private bool _sheathMirrored;

		private Transform _sheathBone;

		private Matrix4x4 _sheathLocal;

		private Grip _sheathGrip;

		private Transform _crossRight;

		private Transform _crossLeft;

		private Transform _crossBone;

		private Transform _facedRight;

		private Matrix4x4 _crossLocal;

		private const float FIST_REACH = 0.3f;

		private static readonly UpdateMethod BeforeCloth = (UpdateMethod)delegate
		{
			foreach (Controller item in All)
			{
				item.WritePose();
				item.WriteBow();
			}
		};

		private static UpdateMethod _hooked;

		private int _posedFrame = -1;

		private static readonly Dictionary<MeleeWeaponTrail, Controller> TrailOwners = new Dictionary<MeleeWeaponTrail, Controller>();

		private static bool _drivingTrails;

		private static readonly List<MeleeWeaponTrail> TrailScratch = new List<MeleeWeaponTrail>();

		private float _posedAt;

		private int _stepFrame = -1;

		private readonly Dictionary<MagicaCloth, ClothUpdateMode> _clothModes = new Dictionary<MagicaCloth, ClothUpdateMode>();

		private float _clothScanAt;

		private bool _clothFollowing;

		private static bool _clothFailed;

		private const float AutoRotateRate = 60f;

		private const float AutoRotateHold = 3f;

		private float _autoRotateIdle;

		private float _groundY;

		private float _groundRate;

		internal Vector3 LastMiss;

		internal float ChestPitch;

		private float _armOut;

		private float _gripRaw;

		private readonly Quaternion[] _leftArmShown = (Quaternion[])(object)new Quaternion[3];

		private bool _leftArmHeld;

		private float _leftArmEase;

		private static readonly FieldRef<Player, float> StaminaField = RhSafe.FieldRef<Player, float>("m_stamina", "RuneheimSouls\\ErEngine\\Controller.cs", 2581);

		private static readonly FieldRef<Player, float> RegenTimer = RhSafe.FieldRef<Player, float>("m_staminaRegenTimer", "RuneheimSouls\\ErEngine\\Controller.cs", 2582);

		private bool _exhausted;

		private static readonly MethodInfo OnSneaking = AccessTools.Method(typeof(Player), "OnSneaking", (Type[])null, (Type[])null);

		private float _sneakTimer;

		private static readonly FieldRef<Character, Biome> LastBiome = RhSafe.FieldRef<Character, Biome>("m_lastBiome", "RuneheimSouls\\ErEngine\\Controller.cs", 2713);

		private static readonly FieldRef<Character, Heightmap> LastHeightmap = RhSafe.FieldRef<Character, Heightmap>("m_lastHeightmap", "RuneheimSouls\\ErEngine\\Controller.cs", 2714);

		private static readonly FieldRef<Character, Vector3> LastGroundHeight = RhSafe.FieldRef<Character, Vector3>("m_lastGroundHeight", "RuneheimSouls\\ErEngine\\Controller.cs", 2715);

		private static readonly FieldRef<Character, Vector3> LastDeepSnowWalkPos = RhSafe.FieldRef<Character, Vector3>("m_lastDeepSnowWalkPos", "RuneheimSouls\\ErEngine\\Controller.cs", 2716);

		private static readonly FieldRef<Character, Vector3> LastSnowPieceRemove = RhSafe.FieldRef<Character, Vector3>("m_lastSnowPieceRemove", "RuneheimSouls\\ErEngine\\Controller.cs", 2717);

		private static readonly FieldRef<Character, bool> IceShoes = RhSafe.FieldRef<Character, bool>("m_iceShoes", "RuneheimSouls\\ErEngine\\Controller.cs", 2718);

		private static readonly FieldRef<Character, bool> Skating = RhSafe.FieldRef<Character, bool>("m_skating", "RuneheimSouls\\ErEngine\\Controller.cs", 2719);

		private static readonly int SnowPieceMask = LayerMask.GetMask(new string[4] { "piece", "piece_nonsolid", "item", "terrain" });

		private static readonly Collider[] SnowPieces = (Collider[])(object)new Collider[32];

		private static readonly int SlipperyMask = LayerMask.GetMask(new string[2] { "static_solid", "Default" });

		private Vector3 _iceVel;

		private const float SWIM_IN = 0.3f;

		private const float SWIM_OUT = 0.2f;

		private bool _catapulted;

		private static readonly FieldInfo Vagons = AccessTools.Field(typeof(Vagon), "m_instances");

		private const float ChopGrace = 0.35f;

		private float _chopUntil = -1f;

		private static readonly Collider[] ChopHits = (Collider[])(object)new Collider[24];

		private static int _chopMask = -1;

		private float _lastDodgeRoll = -1f;

		private static readonly MethodInfo DodgeStamina = AccessTools.Method(typeof(Player), "GetDodgeStaminaUse", (Type[])null, (Type[])null);

		private float _runSkillTimer;

		private float _wasAirF;

		private static readonly Attack EitrProbe = new Attack();

		private bool _breakSounded;

		private static float _valheimDodge = -1f;

		private static readonly int ParryKey = StringExtensionMethods.GetStableHashCode("eh_parry");

		private EffectList _vanillaParry;

		private EffectList _quietParry;

		private int _parries;

		private int _seenParries = -1;

		private const float BAKED_ATTACK_RATE = 0.9f;

		private const float SCEPTRE_ATTACK_RATE = 0.9f;

		private const float AUTO_LOCK_RANGE = 10f;

		private const float AUTO_TARGET_RANGE = 6f;

		private Character _autoTarget;

		private static readonly int SightMask = LayerMask.GetMask(new string[4] { "Default", "static_solid", "piece", "terrain" });

		private float _flick;

		private float _switchWait;

		private bool _stickCentred = true;

		private static Texture2D _dot;

		private Vec3 _hitFrom;

		private bool _fell;

		private bool _judging;

		private float _meterBefore = -1f;

		private float _gripHold;

		public float ArmPeak;

		public bool Active { get; private set; }

		public Player Sim { get; private set; }

		public bool Ai => Brain != null;

		private bool Remote
		{
			get
			{
				if ((Object)(object)_nview != (Object)null && _nview.IsValid())
				{
					return !_nview.IsOwner();
				}
				return false;
			}
		}

		public ItemData Right
		{
			get
			{
				if (!Remote)
				{
					return RightItem.Invoke((Humanoid)(object)_vp);
				}
				return _remoteRight;
			}
		}

		public bool Attacking
		{
			get
			{
				if (Active && Sim != null)
				{
					if (Sim.State != StateKind.Act || !Sim.Act.Id.IsAttack)
					{
						return Sim.AirAttackState.HasValue;
					}
					return true;
				}
				return false;
			}
		}

		public ItemData Left
		{
			get
			{
				if (!Remote)
				{
					return LeftItem.Invoke((Humanoid)(object)_vp);
				}
				return _remoteLeft;
			}
		}

		public static bool PresetOn
		{
			get
			{
				if (EldenheimCompat.Active && Settings.BalancePreset != null)
				{
					return Settings.BalancePreset.Value;
				}
				return false;
			}
		}

		public static bool StaggerPresetOn
		{
			get
			{
				if (EldenheimCompat.Active && Settings.StaggerPreset != null)
				{
					return Settings.StaggerPreset.Value;
				}
				return false;
			}
		}

		internal PhysicsLevel Level => _level;

		internal float HipsY => _bodyY;

		internal float AimShown => _chooser?.AimShown ?? 0f;

		internal string ShownClip => _chooser?.Clip;

		internal string FeetDebug
		{
			get
			{
				if (_retarget != null)
				{
					return $"sink {_retarget.LastSink:0.000} feet {_retarget.FootLift[0]:0.000} {_retarget.FootLift[1]:0.000}";
				}
				return "";
			}
		}

		internal string HandDebug => "";

		public bool Sneaking
		{
			get
			{
				if (Active && Sim != null && Sim.Crouching && Sim.State == StateKind.Ground)
				{
					return Sim.Speed > 0.1f;
				}
				return false;
			}
		}

		private ItemData Unarmed
		{
			get
			{
				if (!((Object)(object)((Humanoid)_vp).m_unarmedWeapon != (Object)null))
				{
					return null;
				}
				return ((Humanoid)_vp).m_unarmedWeapon.m_itemData;
			}
		}

		public bool Blocking
		{
			get
			{
				if (!_judging)
				{
					if (Sim != null)
					{
						if (!Sim.GuardUp() && !Sim.AttackGuard())
						{
							if (Sim.State == StateKind.Act)
							{
								return Sim.Act.Id == ActionId.GuardHit;
							}
							return false;
						}
						return true;
					}
					return false;
				}
				return BlockingNow;
			}
		}

		public ItemData Blocker
		{
			get
			{
				if (Sim != null)
				{
					if (Sim.Grip != Grip.TwoHandRight && !Sim.GuardsWithRight() && !Sim.AttackGuard())
					{
						return Left;
					}
					return Right;
				}
				return null;
			}
		}

		public Retarget Retargeter => _retarget;

		public Chooser Chooser => _chooser;

		private static int VisLeftHash(VisEquipment vis)
		{
			if (_visLeftItem == null && !_visLeftItemFailed)
			{
				try
				{
					_visLeftItem = RhSafe.FieldRef<VisEquipment, int>("m_leftItem", "RuneheimSouls\\ErEngine\\BowPose.cs", 27);
				}
				catch (Exception ex)
				{
					_visLeftItemFailed = true;
					Plugin.Report("bow pose: no VisEquipment.m_leftItem: " + ex.Message);
				}
			}
			if (_visLeftItem == null)
			{
				return 0;
			}
			return _visLeftItem.Invoke(vis);
		}

		private void WriteBow()
		{
			if (_bowFrame == Time.frameCount)
			{
				return;
			}
			_bowFrame = Time.frameCount;
			try
			{
				TickBow(Time.deltaTime);
			}
			catch (Exception ex)
			{
				_bowPhase = BowPhase.None;
				_bowW = 0f;
				Plugin.Report("bow pose failed: " + ex);
			}
		}

		private ItemData HeldBow()
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Invalid comparison between Unknown and I4
			ItemData val = (Remote ? null : ((Humanoid)_vp).GetCurrentWeapon());
			if (val == null && Remote && (Object)(object)_vis != (Object)null && (Object)(object)ObjectDB.instance != (Object)null)
			{
				int num = VisLeftHash(_vis);
				GameObject val2 = ((num == 0) ? null : ObjectDB.instance.GetItemPrefab(num));
				val = ((!((Object)(object)val2 != (Object)null)) ? null : val2.GetComponent<ItemDrop>()?.m_itemData);
			}
			if (val == null || (int)val.m_shared.m_skillType != 8 || !val.m_shared.m_attack.m_bowDraw)
			{
				return null;
			}
			return val;
		}

		private static int BowCategory(ItemData bow)
		{
			if (!(bow.m_shared.m_name == "$item_bow"))
			{
				return 44;
			}
			return 51;
		}

		private Clip BowClip(int category, int id, bool crouch)
		{
			return Clips.Get(Chooser.ClipName(category, (uint)(crouch ? (id + 500) : id))) ?? Clips.Get(Chooser.ClipName(category, (uint)id));
		}

		private void TickBow(float dt)
		{
			//IL_03b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_045a: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Unknown result type (might be due to invalid IL or missing references)
			//IL_0431: Unknown result type (might be due to invalid IL or missing references)
			//IL_043c: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0506: Unknown result type (might be due to invalid IL or missing references)
			//IL_050b: Unknown result type (might be due to invalid IL or missing references)
			if (Active || Ai || Clips == null || (Object)(object)_vp == (Object)null || (Object)(object)_animator == (Object)null || !Settings.Enabled.Value || !Settings.BowAnimations.Value)
			{
				_bowPhase = BowPhase.None;
				_bowW = 0f;
				_bowWasDrawing = false;
				return;
			}
			ItemData val = HeldBow();
			string text = val?.m_shared.m_attack.m_drawAnimationState;
			bool flag = !string.IsNullOrEmpty(text) && _animator.GetBool(text);
			int category = ((val != null) ? BowCategory(val) : 44);
			bool crouch = _animator.GetBool("crouching");
			if (flag)
			{
				if (_bowPhase == BowPhase.None || _bowPhase == BowPhase.Fire)
				{
					_bowAgain = _bowPhase == BowPhase.Fire;
					_bowPhase = BowPhase.Draw;
					_bowT = 0f;
				}
				if (_bowPhase == BowPhase.Draw)
				{
					Clip clip = BowClip(category, _bowAgain ? 36011 : 36010, crouch);
					float num = ((clip != null) ? ((float)(clip.Frames - 1) / 30f) : 0f);
					_bowT = (Remote ? (_bowT + dt) : Mathf.Max(_bowT, ((Humanoid)_vp).GetAttackDrawPercentage() * num));
					_bowClip = clip;
					_bowLooped = false;
					if (clip == null || _bowT >= num)
					{
						_bowPhase = BowPhase.Hold;
						_bowT = 0f;
					}
				}
				if (_bowPhase == BowPhase.Hold)
				{
					_bowT += dt;
					_bowClip = BowClip(category, 36020, crouch);
					_bowLooped = true;
				}
			}
			else if (_bowWasDrawing)
			{
				bool flag2 = val == null || ((Character)_vp).InDodge() || ((Character)_vp).IsStaggering() || ((Character)_vp).IsBlocking() || ((Character)_vp).IsDead();
				_bowPhase = ((!flag2) ? BowPhase.Fire : BowPhase.None);
				_bowT = 0f;
			}
			else if (_bowPhase == BowPhase.Fire)
			{
				_bowT += dt;
			}
			_bowWasDrawing = flag;
			float num2 = 0f;
			if (_bowPhase == BowPhase.Fire)
			{
				_bowClip = BowClip(category, 36000, crouch);
				_bowLooped = false;
				float num3 = ((_bowClip != null) ? ((float)(_bowClip.Frames - 1) / 30f) : 0f);
				if (_bowClip == null || _bowT >= num3 || ((Character)_vp).InDodge() || ((Character)_vp).IsStaggering() || val == null)
				{
					_bowPhase = BowPhase.None;
				}
				else
				{
					num2 = ((_bowT < num3 - 0.25f) ? 1f : 0f);
				}
			}
			else if (_bowPhase != BowPhase.None)
			{
				num2 = 1f;
			}
			_bowW = Mathf.MoveTowards(_bowW, num2, dt / ((num2 > _bowW) ? 0.12f : 0.25f));
			if (_bowW <= 0f || _bowClip == null || !BowRig())
			{
				return;
			}
			Clips.Sample(_bowClip, _bowT * 30f, _bowLooped, _bowEr);
			_retarget.Solve(_bowEr, _bowLocal, out var _);
			List<Transform> bones = _retarget.Bones;
			Transform val2 = bones[_bowSpine];
			val2.rotation = Quaternion.Slerp(val2.rotation, ((Component)this).transform.rotation * _retarget.ModelOf(val2), _bowW);
			int[] bowUpper = _bowUpper;
			foreach (int num4 in bowUpper)
			{
				if (num4 != _bowSpine && (Object)(object)bones[num4] != (Object)null)
				{
					bones[num4].localRotation = Quaternion.Slerp(bones[num4].localRotation, _bowLocal[num4], _bowW);
				}
			}
			Quaternion val3 = Quaternion.AngleAxis((0f - Mathf.Clamp(Mathf.Asin(Mathf.Clamp(((Character)_vp).GetLookDir().y, -1f, 1f)) * 57.29578f, -70f, 70f)) * _bowW / 3f, ((Component)this).transform.right);
			bowUpper = new int[3] { _bowSpine, _bowSpine1, _bowSpine2 };
			foreach (int num5 in bowUpper)
			{
				if (num5 >= 0 && (Object)(object)bones[num5] != (Object)null)
				{
					bones[num5].rotation = val3 * bones[num5].rotation;
				}
			}
		}

		private bool BowRig()
		{
			if (_retarget == null)
			{
				BuildPose();
			}
			if (_retarget == null)
			{
				return false;
			}
			if (_bowUpper == null)
			{
				List<Transform> bones = _retarget.Bones;
				List<int> list = new List<int>();
				for (int i = 0; i < bones.Count; i++)
				{
					string text = (((Object)(object)bones[i] != (Object)null) ? ((Object)bones[i]).name : "");
					if (text.StartsWith("LeftHand") || text.StartsWith("RightHand") || Array.IndexOf(BowUpperBones, text) >= 0)
					{
						list.Add(i);
					}
					if (text == "Spine")
					{
						_bowSpine = i;
					}
					if (text == "Spine1")
					{
						_bowSpine1 = i;
					}
					if (text == "Spine2")
					{
						_bowSpine2 = i;
					}
				}
				_bowUpper = list.ToArray();
				_bowEr = new ErPose(Clips.Bones.Length);
				_bowEr.CopyFrom(Clips.Rest);
				_bowLocal = (Quaternion[])(object)new Quaternion[bones.Count];
			}
			return _bowSpine >= 0;
		}

		public float PlayUse(bool grease = false)
		{
			if (!Active || Sim == null || !Sim.StartUse(grease))
			{
				return -1f;
			}
			ActionDef actionDef = ErData.Action(grease ? ActionId.UseGrease : ActionId.UseItem);
			if (actionDef == null)
			{
				return 0.6f;
			}
			return actionDef.Total * 0.45f / 30f;
		}

		private static bool PadWindowBusy()
		{
			if (padBusyMissing)
			{
				return false;
			}
			try
			{
				return PadBusyNow();
			}
			catch
			{
				padBusyMissing = true;
				return false;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static bool PadBusyNow()
		{
			return RhPad.DrivingOrJustClosed;
		}

		public static Controller For(Player vp)
		{
			Controller controller = ((Component)vp).GetComponent<Controller>();
			if ((Object)(object)controller == (Object)null)
			{
				controller = ((Component)vp).gameObject.AddComponent<Controller>();
			}
			return controller;
		}

		private void Awake()
		{
			_vp = ((Component)this).GetComponent<Player>();
			_body = ((Component)this).GetComponent<Rigidbody>();
			_vis = ((Component)this).GetComponent<VisEquipment>();
			_nview = ((Component)this).GetComponent<ZNetView>();
			_animator = Traverse.Create((object)_vp).Field("m_animator").GetValue<Animator>();
			All.Add(this);
		}

		private void OnDestroy()
		{
			All.Remove(this);
			if ((Object)(object)Local == (Object)(object)this)
			{
				Local = null;
			}
		}

		public static bool Posing(Character c)
		{
			Controller controller = default(Controller);
			if (c is Player && ((Component)c).TryGetComponent<Controller>(ref controller))
			{
				return controller.Active;
			}
			return false;
		}

		public bool PowerStance()
		{
			if (PresetOn)
			{
				return InPowerStance();
			}
			return false;
		}

		private bool InPowerStance()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Invalid comparison between Unknown and I4
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Invalid comparison between Unknown and I4
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Invalid comparison between Unknown and I4
			if (Sim == null || Sim.Grip != Grip.OneHand)
			{
				return false;
			}
			ItemData right = Right;
			ItemData left = Left;
			if (right == null)
			{
				return false;
			}
			if (Hands.IsPair(right))
			{
				return (int)right.m_shared.m_skillType != 11;
			}
			if (left != null && left != right && (int)right.m_shared.m_itemType == 3)
			{
				return (int)left.m_shared.m_itemType == 3;
			}
			return false;
		}

		private bool InTwoHanding()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Invalid comparison between Unknown and I4
			//IL_0056: 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_005e: Invalid comparison between Unknown and I4
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Invalid comparison between Unknown and I4
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Invalid comparison between Unknown and I4
			if (Sim == null || Sim.Grip == Grip.OneHand)
			{
				return false;
			}
			ItemData val = ((Sim.Grip == Grip.TwoHandLeft) ? Left : Right);
			if (val == null || Hands.IsPair(val) || (int)val.m_shared.m_skillType == 11)
			{
				return false;
			}
			ItemType itemType = val.m_shared.m_itemType;
			if ((int)itemType != 3 && (int)itemType != 14)
			{
				return (int)itemType == 22;
			}
			return true;
		}

		public bool TwoHanding()
		{
			if (PresetOn)
			{
				return InTwoHanding();
			}
			return false;
		}

		private void PovLeapInput(ref Input inp)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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)
			if (!PovCompat.Active || Remote || Ai || Sim == null)
			{
				_leapQueued = false;
				return;
			}
			MoveDirRef.Invoke((Character)(object)_vp) = (inp.Wish(out var dir) ? Space.ToUnity(dir) : Vector3.zero);
			if (Sim.Crouching != _povCrouch)
			{
				_povCrouch = Sim.Crouching;
				SetCrouchM?.Invoke(_vp, new object[1] { _povCrouch });
			}
			if (PovCompat.Oiling(out var canMove))
			{
				inp.Light = default(Button);
				inp.Heavy = default(Button);
				inp.Dodge = default(Button);
				if (!canMove)
				{
					inp.Mv = default(Vec2);
				}
				return;
			}
			if (_povDodgeTaken)
			{
				if (inp.Dodge.Held || inp.Dodge.Released)
				{
					inp.Dodge = default(Button);
					return;
				}
				_povDodgeTaken = false;
			}
			if (inp.Dodge.Pressed && PovCompat.DodgeTaken(_vp, MoveDirRef.Invoke((Character)(object)_vp)))
			{
				inp.Dodge = default(Button);
				_povDodgeTaken = true;
			}
			else if (_leapQueued)
			{
				if (Time.time - _leapAt > 0.7f || Sim.AirAttackState.HasValue)
				{
					_leapQueued = false;
				}
				else if (Sim.State == StateKind.Air)
				{
					inp.Heavy.Pressed = true;
					inp.Heavy.Held = true;
					_leapQueued = false;
				}
				else
				{
					inp.Heavy = default(Button);
				}
			}
			else if (inp.Heavy.Pressed && Sim.State == StateKind.Ground)
			{
				ItemData w = ((Sim.Grip == Grip.TwoHandLeft) ? Left : Right);
				if (PovCompat.LeapMode(_vp, w))
				{
					inp.Heavy = default(Button);
					inp.Jump.Pressed = true;
					inp.Jump.Held = true;
					_leapQueued = true;
					_leapAt = Time.time;
				}
			}
		}

		public static bool HeavyMove(AttackKind k)
		{
			if (k != AttackKind.Heavy1 && k != AttackKind.Heavy2 && k != AttackKind.Heavy1Charge && k != AttackKind.Heavy2Charge && k != AttackKind.RunHeavy && k != AttackKind.JumpHeavyLand)
			{
				return k == AttackKind.JumpHeavyLandShort;
			}
			return true;
		}

		public float PresetDamage(ItemData weapon)
		{
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Invalid comparison between Unknown and I4
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Invalid comparison between Unknown and I4
			if (!PresetOn || Sim == null)
			{
				return 1f;
			}
			float num = 1f;
			if (PowerStance())
			{
				num *= 1f + Settings.PowerStanceDamage.Value / 100f;
			}
			if (TwoHanding())
			{
				num *= 1f + Settings.TwoHandDamage.Value / 100f;
			}
			Player sim = Sim;
			if (sim.State == StateKind.Act && (Player.IsChargeKind(sim.Act.Id) || Player.IsHeavyRelease(sim.Act.Id)))
			{
				num *= 1f + sim.ChargeFraction() * Settings.ChargeDamage.Value / 100f;
			}
			bool flag = weapon != null && ((int)weapon.m_shared.m_itemType == 14 || (int)weapon.m_shared.m_itemType == 22);
			bool? flag2 = null;
			AirAttack? airAttackState = sim.AirAttackState;
			if (airAttackState.HasValue)
			{
				flag2 = airAttackState.GetValueOrDefault().Heavy;
			}
			else if (sim.State == StateKind.Act && sim.Act.Id.IsAttack)
			{
				switch (sim.Act.Id.Kind)
				{
				case AttackKind.JumpHeavyLand:
				case AttackKind.JumpHeavyLandShort:
					flag2 = true;
					break;
				case AttackKind.JumpLightLand:
				case AttackKind.JumpLightLandShort:
				case AttackKind.PairedJumpLand:
				case AttackKind.PairedJumpLandShort:
					flag2 = false;
					break;
				case AttackKind.RunHeavy:
					num *= 1f + Settings.RunningHeavy.Value / 100f;
					break;
				}
			}
			if (flag2 == true)
			{
				num *= 1f + Settings.JumpHeavy.Value / 100f;
			}
			else if (flag2 == false)
			{
				num *= 1f + (flag ? Settings.JumpLightTwoHanded.Value : Settings.JumpLightOneHanded.Value) / 100f;
			}
			return num;
		}

		public float PresetStagger(ItemData weapon)
		{
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Invalid comparison between Unknown and I4
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Invalid comparison between Unknown and I4
			if (!StaggerPresetOn || Sim == null)
			{
				return 1f;
			}
			float num = 1f;
			if (InPowerStance())
			{
				num *= 1f + Settings.PowerStanceStagger.Value / 100f;
			}
			if (InTwoHanding())
			{
				num *= 1f + Settings.TwoHandStagger.Value / 100f;
			}
			Player sim = Sim;
			if (sim.State == StateKind.Act && (Player.IsChargeKind(sim.Act.Id) || Player.IsHeavyRelease(sim.Act.Id)))
			{
				num *= 1f + sim.ChargeFraction() * Settings.ChargeStagger.Value / 100f;
			}
			bool flag = weapon != null && ((int)weapon.m_shared.m_itemType == 14 || (int)weapon.m_shared.m_itemType == 22);
			bool? flag2 = null;
			AirAttack? airAttackState = sim.AirAttackState;
			if (airAttackState.HasValue)
			{
				flag2 = airAttackState.GetValueOrDefault().Heavy;
			}
			else if (sim.State == StateKind.Act && sim.Act.Id.IsAttack)
			{
				switch (sim.Act.Id.Kind)
				{
				case AttackKind.JumpHeavyLand:
				case AttackKind.JumpHeavyLandShort:
					flag2 = true;
					break;
				case AttackKind.JumpLightLand:
				case AttackKind.JumpLightLandShort:
				case AttackKind.PairedJumpLand:
				case AttackKind.PairedJumpLandShort:
					flag2 = false;
					break;
				case AttackKind.RunHeavy:
					num *= 1f + Settings.RunningHeavyStagger.Value / 100f;
					break;
				}
			}
			if (flag2 == true)
			{
				num *= 1f + Settings.JumpHeavyStagger.Value / 100f;
			}
			else if (flag2 == false)
			{
				num *= 1f + (flag ? Settings.JumpLightTwoHandedStagger.Value : Settings.JumpLightOneHandedStagger.Value) / 100f;
			}
			return num;
		}

		public float PresetCost(ActionId id, float cost)
		{
			if (!PresetOn || Sim == null || !id.IsAttack)
			{
				return cost;
			}
			if (PowerStance())
			{
				cost *= 1f + Settings.PowerStanceStamina.Value / 100f;
			}
			if (TwoHanding())
			{
				cost *= 1f + Settings.TwoHandStamina.Value / 100f;
			}
			if (Player.IsChargeKind(id) || Player.IsHeavyRelease(id))
			{
				cost *= 1f + Sim.ChargeFraction() * Settings.ChargeStamina.Value / 100f;
			}
			if (id.Kind == AttackKind.RunHeavy)
			{
				cost *= 1f + Settings.RunningHeavyStamina.Value / 100f;
			}
			return cost;
		}

		public float PresetAirCost(bool heavy, ItemData weapon, float cost)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Invalid comparison between Unknown and I4
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Invalid comparison between Unknown and I4
			if (!PresetOn || Sim == null)
			{
				return cost;
			}
			if (PowerStance())
			{
				cost *= 1f + Settings.PowerStanceStamina.Value / 100f;
			}
			if (TwoHanding())
			{
				cost *= 1f + Settings.TwoHandStamina.Value / 100f;
			}
			bool flag = weapon != null && ((int)weapon.m_shared.m_itemType == 14 || (int)weapon.m_shared.m_itemType == 22);
			float num = (heavy ? Settings.JumpHeavyStamina.Value : (flag ? Settings.JumpLightTwoHandedStamina.Value : Settings.JumpLightOneHandedStamina.Value));
			return cost * (1f + num / 100f);
		}

		private void Publish(bool on)
		{
			if (!((Object)(object)_nview == (Object)null) && _nview.IsValid() && _nview.IsOwner())
			{
				ZDO zDO = _nview.GetZDO();
				bool flag = on && Sim != null && Sim.Invincible();
				if (flag != _sentInvincible)
				{
					_sentInvincible = flag;
					zDO.Set(ZDOVars.s_dodgeinv, flag);
				}
				byte[] array = ((on && Sim != null) ? PoseState.Write(Sim) : Array.Empty<byte>());
				if (_sent == null || !array.SequenceEqual(_sent))
				{
					_sent = array;
					zDO.Set(StateKey, array);
					zDO.Set(DataKey, Plugin.DataHash, false);
				}
			}
		}

		private void FixedUpdate()
		{
			//IL_0327: Unknown result type (might be due to invalid IL or missing references)
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			if (!Remote)
			{
				return;
			}
			float fixedDeltaTime = Time.fixedDeltaTime;
			ZDO zDO = _nview.GetZDO();
			bool flag = false;
			if (zDO.DataRevision != _revision)
			{
				_revision = zDO.DataRevision;
				byte[] byteArray = zDO.GetByteArray(StateKey, (byte[])null);
				if (byteArray != null && (_got == null || !byteArray.SequenceEqual(_got)))
				{
					_got = byteArray;
					flag = true;
				}
			}
			RemoteParries(zDO);
			int num = zDO.GetInt(DataKey, 0);
			if (num != 0 && num != Plugin.DataHash && !_warned)
			{
				_warned = true;
				Plugin.Report(_vp.GetPlayerName() + " has a different Eldenheim data build: shown with Valheim's animation");
			}
			bool flag2 = Clips != null && ErData.Loaded && Plugin.DataHash != 0 && num == Plugin.DataHash && _got != null && _got.Length > 1 && !((Character)_vp).IsDead() && (Object)(object)_animator != (Object)null && _animator.isInitialized && (Object)(object)_animator.avatar != (Object)null && _animator.avatar.isValid;
			if (flag2)
			{
				if (Sim == null)
				{
					Sim = new Player(new Vec3(0f, 0f, 0f));
				}
				if (flag || !Active)
				{
					StateKind state = Sim.State;
					ActionId id = Sim.Act.Id;
					float f = Sim.Act.F;
					float num2 = Sim.AirAttackState?.F ?? (-1f);
					flag2 = PoseState.Read(_got, Sim);
					if (flag2 && Sim.State == state && Sim.Act.Id == id && Sim.Act.F < f && f - Sim.Act.F < 3f)
					{
						Sim.Act.F = f;
					}
					if (flag2)
					{
						AirAttack? airAttackState = Sim.AirAttackState;
						if (airAttackState.HasValue)
						{
							AirAttack valueOrDefault = airAttackState.GetValueOrDefault();
							if (valueOrDefault.F < num2 && num2 - valueOrDefault.F < 3f)
							{
								valueOrDefault.F = num2;
								Sim.AirAttackState = valueOrDefault;
							}
						}
					}
				}
				else
				{
					PoseState.Advance(Sim, fixedDeltaTime);
				}
			}
			if (flag2 && !Active)
			{
				Active = true;
				BuildPose();
				ErSounds.Preload((Character)(object)_vp);
			}
			else if (!flag2 && Active)
			{
				Active = false;
				_combat.StopTrails();
				RestoreHandVisuals();
				RestorePoles();
			}
			if (!Active)
			{
				FadeOutPose(fixedDeltaTime);
				return;
			}
			_clock += fixedDeltaTime;
			Sim.Pos = Space.ToSim(((Component)this).transform.position);
			Sim.Yaw = Space.YawToSim(((Component)this).transform.eulerAngles.y);
			_remoteRight = RemoteItem(_remoteRight, RightHash.Invoke(_vis), RightQuality.Invoke(_vis), 0);
			_remoteLeft = RemoteItem(_remoteLeft, LeftHash.Invoke(_vis), LeftQuality.Invoke(_vis), LeftVariant.Invoke(_vis));
			HandVisuals(Sim);
			TrackBlades();
			_combat.RemoteTrails(_vp, Sim, _rightBlade, _leftBlade);
			RemoteSounds();
			Log.Clear();
		}

		private static ItemData RemoteItem(ItemData had, int hash, int quality, int variant)
		{
			if (hash == 0 || (Object)(object)ObjectDB.instance == (Object)null)
			{
				return null;
			}
			if (had != null && (Object)(object)had.m_dropPrefab != (Object)null && StringExtensionMethods.GetStableHashCode(((Object)had.m_dropPrefab).name) == hash && had.m_quality == quality && had.m_variant == variant)
			{
				return had;
			}
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(hash);
			ItemDrop val = (((Object)(object)itemPrefab != (Object)null) ? itemPrefab.GetComponent<ItemDrop>() : null);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			ItemData obj = val.m_itemData.Clone();
			obj.m_dropPrefab = itemPrefab;
			obj.m_quality = quality;
			obj.m_variant = variant;
			return obj;
		}

		private static int Weapon(string name)
		{
			return Array.FindIndex(ErData.Weapons, (WeaponInfo w) => w.Name == name);
		}

		public static bool? HasMove(ItemData item, AttackKind[] kinds)
		{
			if (ErData.Weapons == null)
			{
				return null;
			}
			if (item == null || kinds == null)
			{
				return false;
			}
			string text = ClassOf(item, IsTwoHanded(item), Hands.IsPair(item));
			int num = ((text != null) ? Weapon(text) : (-1));
			if (num < 0)
			{
				return false;
			}
			foreach (AttackKind kind in kinds)
			{
				if (ErData.Attack(num, twoHand: false, kind) != null || ErData.Attack(num, twoHand: true, kind) != null)
				{
					return true;
				}
			}
			return false;
		}

		internal static string MovesetClass(ItemData item)
		{
			return ClassOf(item, IsTwoHanded(item), Hands.IsPair(item));
		}

		private static bool IsTwoHanded(ItemData item)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			return (int)item.m_shared.m_itemType == 14;
		}

		public static bool Playable(ItemData item)
		{
			if (item != null)
			{
				string text = ClassOf(item, IsTwoHanded(item), Hands.IsPair(item));
				if (text != null)
				{
					if (ErData.Weapons != null)
					{
						return Weapon(text) >= 0;
					}
					return true;
				}
			}
			return false;
		}

		private static string ClassOf(ItemData item, bool twoHanded, bool dual)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			if ((int)item.m_shared.m_itemType == 15)
			{
				return "Torch";
			}
			return WeaponMovesets.For(item, TypeKey(item, twoHanded, dual));
		}

		internal static string TypeKey(ItemData item)
		{
			if (item != null)
			{
				return TypeKey(item, IsTwoHanded(item), Hands.IsPair(item));
			}
			return null;
		}

		private static string TypeKey(ItemData item, bool twoHanded, bool dual)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			//IL_0017: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected I4, but got Unknown
			if ((int)item.m_shared.m_itemType == 15)
			{
				return null;
			}
			SkillType skillType = item.m_shared.m_skillType;
			switch (skillType - 1)
			{
			case 0:
				if (!twoHanded)
				{
					return "OneHandedSwords";
				}
				return "TwoHandedSwords";
			case 1:
				return "Knives";
			case 2:
				if (!twoHanded)
				{
					return "OneHandedClubs";
				}
				return "TwoHandedClubs";
			case 6:
				if (!twoHanded || dual)
				{
					return "OneHandedAxes";
				}
				return "TwoHandedAxes";
			case 3:
				return "Polearms";
			case 4:
				return "Spears";
			case 10:
				return "Knuckles";
			default:
				return null;
			}
		}

		public static bool Handless(int weapon)
		{
			if (weapon != ErData.FIST)
			{
				if (weapon >= 0 && weapon < ErData.Weapons.Length)
				{
					byte category = ErData.Weapons[weapon].Category;
					if (category != 42 && category != 55)
					{
						return category == 53;
					}
					return true;
				}
				return false;
			}
			return true;
		}

		public static bool Map(ItemData right, ItemData left, out int weapon, out int leftHand, out Grip grip)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Invalid comparison between Unknown and I4
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Invalid comparison between Unknown and I4
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Invalid comparison between Unknown and I4