Decompiled source of MindflayerChestJiggle v1.0.1

BepInEx\plugins\MindflayerChestJiggle\MindflayerChestJiggle.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Unity.Collections;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace UKMindflayerJiggle;

public static class JiggleConfig
{
	public static ConfigEntry<bool> Enabled;

	public static ConfigEntry<float> Amplitude;

	public static ConfigEntry<float> Frequency;

	public static ConfigEntry<float> Damping;

	public static ConfigEntry<float> MaxAngle;

	public static ConfigEntry<float> IdleSway;

	public static ConfigEntry<float> SpineAssist;

	public static ConfigEntry<bool> HitJiggle;

	public static ConfigEntry<float> HitStrength;

	public static ConfigEntry<float> HitRadius;

	public static ConfigEntry<bool> AnyDamage;

	public static ConfigEntry<float> TeleportKick;

	public static ConfigEntry<bool> ShowDebug;

	public static ConfigEntry<string> PanelKey;

	public static ConfigEntry<bool> LogSetup;

	public static ConfigEntry<float> DebugForceAngle;

	public static void Bind(ConfigFile cfg)
	{
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Expected O, but got Unknown
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Expected O, but got Unknown
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Expected O, but got Unknown
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Expected O, but got Unknown
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Expected O, but got Unknown
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Expected O, but got Unknown
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Expected O, but got Unknown
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f1: Expected O, but got Unknown
		//IL_023a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Expected O, but got Unknown
		//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d1: Expected O, but got Unknown
		Enabled = cfg.Bind<bool>("General", "Enabled", true, "Master switch for the Mindflayer chest jiggle.");
		Amplitude = cfg.Bind<float>("Jiggle", "Amplitude", 1.4f, new ConfigDescription("Overall jiggle amplitude / sensitivity to movement. 0 = no motion-driven sway, 3 = very strong.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 3f), Array.Empty<object>()));
		Frequency = cfg.Bind<float>("Jiggle", "Frequency", 5.5f, new ConfigDescription("Spring frequency in Hz. Higher = faster/tighter wobble, lower = loose and floaty.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2f, 20f), Array.Empty<object>()));
		Damping = cfg.Bind<float>("Jiggle", "Damping", 0.22f, new ConfigDescription("Damping ratio. Lower = the chest keeps wobbling longer, higher = it settles quickly.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.02f, 1f), Array.Empty<object>()));
		MaxAngle = cfg.Bind<float>("Jiggle", "MaxAngle", 22f, new ConfigDescription("Maximum rotation of each chest bone in degrees. Prevents extreme deformation.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(3f, 45f), Array.Empty<object>()));
		IdleSway = cfg.Bind<float>("Jiggle", "IdleSway", 0.7f, new ConfigDescription("Small idle breathing sway so the chest still moves while the Mindflayer is standing still. 0 = off.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
		SpineAssist = cfg.Bind<float>("Jiggle", "SpineAssist", 0f, new ConfigDescription("Safety assist: also rotate spine.002 by this fraction of the chest spring angle (capped at 8 degrees). This guarantees visible chest movement even if a rendering layer ignores the two inserted bones. 0 = off.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
		HitJiggle = cfg.Bind<bool>("HitReaction", "Enabled", true, "When a hit lands on the chest, kick the jiggle spring so the chest visibly bounces.");
		HitStrength = cfg.Bind<float>("HitReaction", "Strength", 1f, new ConfigDescription("How hard a hit kicks the chest.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 5f), Array.Empty<object>()));
		HitRadius = cfg.Bind<float>("HitReaction", "ChestRadius", 0.55f, new ConfigDescription("A hit counts as a chest hit when the hit point is within this many metres of either chest bone.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1.5f), Array.Empty<object>()));
		AnyDamage = cfg.Bind<bool>("HitReaction", "AnyHitCounts", false, "If true, any damage to the Mindflayer kicks the chest even when the hit point is not on the chest.");
		TeleportKick = cfg.Bind<float>("HitReaction", "TeleportKick", 1f, new ConfigDescription("Extra jiggle kick when the Mindflayer teleports (it is an action too). 0 = off.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 3f), Array.Empty<object>()));
		ShowDebug = cfg.Bind<bool>("UI", "ShowDebug", false, "Show extra runtime information at the bottom of the F10 panel.");
		PanelKey = cfg.Bind<string>("UI", "PanelKey", "F10", "Keyboard key that opens/closes the adjustment panel (UnityEngine.InputSystem.Key name, e.g. F10, F7).");
		LogSetup = cfg.Bind<bool>("Debug", "LogSetup", true, "Write one log line per Mindflayer when its jiggle rig is created (or when it falls back to spine-only mode).");
		DebugForceAngle = cfg.Bind<float>("Debug", "ForceAngle", 0f, new ConfigDescription("Diagnostic override: force both chest bones to this fixed angle in degrees (0 = normal physics). Use 15-25 to check whether the re-weighted chest actually follows the new bones.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 45f), Array.Empty<object>()));
	}
}
public class JiggleBone
{
	public Transform bone;

	public Vector3 forwardLocal = Vector3.forward;

	public Vector3 upLocal = Vector3.up;

	public Vector3 rightLocal = Vector3.right;

	public Vector3 angle;

	public Vector3 angVel;

	public float phase;

	public float side;

	public Quaternion applied = Quaternion.identity;

	public void Reset()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_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_0035: Unknown result type (might be due to invalid IL or missing references)
		angle = Vector3.zero;
		angVel = Vector3.zero;
		applied = Quaternion.identity;
		if ((Object)(object)bone != (Object)null)
		{
			bone.localRotation = Quaternion.identity;
		}
	}

	public void Apply()
	{
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)bone == (Object)null))
		{
			float magnitude = ((Vector3)(ref angle)).magnitude;
			if (magnitude < 1E-05f)
			{
				applied = Quaternion.identity;
				bone.localRotation = Quaternion.identity;
			}
			else
			{
				applied = Quaternion.AngleAxis(magnitude * 57.29578f, angle / magnitude);
				bone.localRotation = applied;
			}
		}
	}
}
[DefaultExecutionOrder(10000)]
public class MindflayerJiggle : MonoBehaviour
{
	public static int ActiveCount;

	public static int MeshModeCount;

	public static int FallbackCount;

	private Mindflayer mf;

	private SkinnedMeshRenderer smr;

	private Transform spine1;

	private Transform spine2;

	private JiggleBone left;

	private JiggleBone right;

	private Mesh sourceMesh;

	private Mesh builtMesh;

	private Transform[] originalBones;

	private bool ready;

	private bool fallback;

	private float nextRetry;

	private Vector3 prevPos;

	private Quaternion prevRot;

	private Vector3 lastVel;

	private bool hasPrev;

	private JiggleBone fb;

	private Quaternion fbLastOffset = Quaternion.identity;

	private Quaternion fbLastWritten = Quaternion.identity;

	private bool fbHasState;

	private float lastTeleportKick;

	private bool loggedAngle;

	private bool verified;

	private int newBoneWeightVerts = -1;

	public static MindflayerJiggle LastInstance;

	public bool IsReady => ready;

	public bool IsFallback => fallback;

	public float DebugAngleL
	{
		get
		{
			if (left == null)
			{
				return -1f;
			}
			return ((Vector3)(ref left.angle)).magnitude * 57.29578f;
		}
	}

	public float DebugAngleR
	{
		get
		{
			if (right == null)
			{
				return -1f;
			}
			return ((Vector3)(ref right.angle)).magnitude * 57.29578f;
		}
	}

	public float DebugActualAngleL
	{
		get
		{
			//IL_002c: 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)
			if (left == null || (Object)(object)left.bone == (Object)null)
			{
				return -1f;
			}
			return Quaternion.Angle(left.bone.localRotation, left.applied);
		}
	}

	public float DebugActualAngleR
	{
		get
		{
			//IL_002c: 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)
			if (right == null || (Object)(object)right.bone == (Object)null)
			{
				return -1f;
			}
			return Quaternion.Angle(right.bone.localRotation, right.applied);
		}
	}

	public int DebugBoneCount
	{
		get
		{
			if (!((Object)(object)smr != (Object)null) || smr.bones == null)
			{
				return -1;
			}
			return smr.bones.Length;
		}
	}

	public int DebugBindposeCount
	{
		get
		{
			if ((Object)(object)smr == (Object)null || (Object)(object)smr.sharedMesh == (Object)null)
			{
				return -1;
			}
			return smr.sharedMesh.bindposeCount;
		}
	}

	public int DebugNewWeightVerts => newBoneWeightVerts;

	public string DebugBoneNames
	{
		get
		{
			if ((Object)(object)smr == (Object)null || smr.bones == null || smr.bones.Length < 2)
			{
				return "-";
			}
			return ((Object)smr.bones[smr.bones.Length - 2]).name + " / " + ((Object)smr.bones[smr.bones.Length - 1]).name;
		}
	}

	private void OnEnable()
	{
		nextRetry = 0f;
	}

	private void OnDestroy()
	{
		Teardown(restoreRenderer: true);
	}

	private void LateUpdate()
	{
		if (ready && (Object)(object)smr != (Object)null && (Object)(object)smr.sharedMesh != (Object)(object)builtMesh)
		{
			try
			{
				if (originalBones != null && smr.bones != null && smr.bones.Length != originalBones.Length)
				{
					smr.bones = originalBones;
				}
			}
			catch (Exception)
			{
			}
			Teardown(restoreRenderer: false);
		}
		if (!ready && !fallback)
		{
			EnsureSetup();
		}
		if (ready)
		{
			SimulateMesh();
		}
		else if (fallback)
		{
			SimulateFallback();
		}
		if (ready && !verified)
		{
			verified = true;
			VerifyRig();
		}
	}

	private void VerifyRig()
	{
		try
		{
			int num = 0;
			Mesh val = (((Object)(object)smr != (Object)null) ? smr.sharedMesh : null);
			if ((Object)(object)val != (Object)null && smr.bones != null && smr.bones.Length >= 2)
			{
				int num2 = smr.bones.Length - 2;
				int num3 = smr.bones.Length - 1;
				BoneWeight[] boneWeights = val.boneWeights;
				for (int i = 0; i < boneWeights.Length; i++)
				{
					if (((BoneWeight)(ref boneWeights[i])).boneIndex0 == num2 || ((BoneWeight)(ref boneWeights[i])).boneIndex0 == num3 || ((BoneWeight)(ref boneWeights[i])).boneIndex1 == num2 || ((BoneWeight)(ref boneWeights[i])).boneIndex1 == num3 || ((BoneWeight)(ref boneWeights[i])).boneIndex2 == num2 || ((BoneWeight)(ref boneWeights[i])).boneIndex2 == num3 || ((BoneWeight)(ref boneWeights[i])).boneIndex3 == num2 || ((BoneWeight)(ref boneWeights[i])).boneIndex3 == num3)
					{
						num++;
					}
				}
			}
			newBoneWeightVerts = num;
			JigglePlugin.Log(string.Format("rig verify: shared={0} bind={1} bones={2} newWeightVerts={3} actualL={4:F1} actualR={5:F1}", ((Object)(object)val != (Object)null) ? ((Object)val).name : "null", ((Object)(object)val != (Object)null) ? val.bindposeCount : (-1), ((Object)(object)smr != (Object)null && smr.bones != null) ? smr.bones.Length : (-1), num, DebugActualAngleL, DebugActualAngleR));
		}
		catch (Exception ex)
		{
			JigglePlugin.LogWarning("rig verify failed: " + ex.Message);
		}
	}

	private void EnsureSetup()
	{
		if (Time.unscaledTime < nextRetry)
		{
			return;
		}
		nextRetry = Time.unscaledTime + 0.5f;
		if ((Object)(object)mf == (Object)null)
		{
			mf = ((Component)this).GetComponent<Mindflayer>();
		}
		if ((Object)(object)mf == (Object)null)
		{
			return;
		}
		if ((Object)(object)smr == (Object)null || (Object)(object)smr != (Object)(object)mf.smr)
		{
			smr = mf.smr;
		}
		if ((Object)(object)smr == (Object)null)
		{
			return;
		}
		Mesh sharedMesh = smr.sharedMesh;
		if ((Object)(object)sharedMesh == (Object)null)
		{
			return;
		}
		if (fallback)
		{
			if ((Object)(object)sharedMesh == (Object)(object)sourceMesh)
			{
				return;
			}
			Teardown(restoreRenderer: false);
		}
		Transform[] bones = smr.bones;
		if (bones == null || bones.Length < 4)
		{
			return;
		}
		int num = FindBone(bones, "spine.001", "spine1", 1);
		int num2 = FindBone(bones, "spine.002", "spine2", 2);
		int num3 = FindBone(bones, "shoulder.l", "shoulder_l", -1);
		int num4 = FindBone(bones, "shoulder.r", "shoulder_r", -1);
		if (num < 0 || num2 < 0 || num3 < 0 || num4 < 0)
		{
			StartFallback(bones, num2, "required spine/shoulder bones not found");
			return;
		}
		sourceMesh = sharedMesh;
		originalBones = bones;
		spine1 = bones[num];
		spine2 = bones[num2];
		if (!JiggleMesh.TryBuild(smr, num, num2, num3, num4, out var jiggleBone, out var jiggleBone2, out var newMesh, out var _, out var error))
		{
			try
			{
				if ((Object)(object)smr != (Object)null && (Object)(object)sourceMesh != (Object)null)
				{
					smr.sharedMesh = sourceMesh;
				}
				if ((Object)(object)smr != (Object)null && originalBones != null)
				{
					smr.bones = originalBones;
				}
			}
			catch (Exception)
			{
			}
			StartFallback(bones, num2, error);
			return;
		}
		builtMesh = newMesh;
		left = jiggleBone;
		right = jiggleBone2;
		left.phase = Random.Range(0f, 10f);
		right.phase = left.phase + 1.7f;
		ready = true;
		fallback = false;
		fb = null;
		hasPrev = false;
		loggedAngle = false;
		LastInstance = this;
		ActiveCount++;
		MeshModeCount++;
		if (JiggleConfig.LogSetup != null && JiggleConfig.LogSetup.Value)
		{
			JigglePlugin.Log("Mindflayer chest jiggle attached (mesh mode).");
		}
	}

	private void StartFallback(Transform[] bones, int spine2Index, string reason)
	{
		//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_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		if (spine2Index >= 0 && bones != null && spine2Index < bones.Length)
		{
			fallback = true;
			ready = false;
			spine2 = bones[spine2Index];
			int num = FindBone(bones, "spine.001", "spine1", 1);
			spine1 = ((num >= 0 && num < bones.Length) ? bones[num] : null);
			sourceMesh = (((Object)(object)smr != (Object)null) ? smr.sharedMesh : null);
			fb = new JiggleBone();
			fb.bone = spine2;
			fb.forwardLocal = Vector3.forward;
			fb.upLocal = Vector3.up;
			fb.rightLocal = Vector3.right;
			fb.phase = Random.Range(0f, 10f);
			fbHasState = false;
			hasPrev = false;
			LastInstance = this;
			ActiveCount++;
			FallbackCount++;
			if (JiggleConfig.LogSetup == null || JiggleConfig.LogSetup.Value)
			{
				JigglePlugin.LogWarning("Mindflayer jiggle fell back to spine-only mode: " + reason);
			}
		}
	}

	private void Teardown(bool restoreRenderer)
	{
		if (restoreRenderer)
		{
			try
			{
				if ((Object)(object)smr != (Object)null && (Object)(object)builtMesh != (Object)null && (Object)(object)sourceMesh != (Object)null && originalBones != null)
				{
					smr.sharedMesh = sourceMesh;
					smr.bones = originalBones;
				}
			}
			catch (Exception)
			{
			}
		}
		if (left != null && (Object)(object)left.bone != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)left.bone).gameObject);
		}
		if (right != null && (Object)(object)right.bone != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)right.bone).gameObject);
		}
		if ((Object)(object)builtMesh != (Object)null)
		{
			Object.Destroy((Object)(object)builtMesh);
		}
		if (ready)
		{
			MeshModeCount--;
		}
		if (fallback)
		{
			FallbackCount--;
		}
		if (ready || fallback)
		{
			ActiveCount--;
		}
		if (ActiveCount < 0)
		{
			ActiveCount = 0;
		}
		if (MeshModeCount < 0)
		{
			MeshModeCount = 0;
		}
		if (FallbackCount < 0)
		{
			FallbackCount = 0;
		}
		left = null;
		right = null;
		builtMesh = null;
		sourceMesh = null;
		originalBones = null;
		fb = null;
		ready = false;
		fallback = false;
		hasPrev = false;
	}

	private void SimulateMesh()
	{
		//IL_0044: 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_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		if (left == null || right == null || (Object)(object)spine2 == (Object)null)
		{
			return;
		}
		float num = ((JiggleConfig.DebugForceAngle != null) ? JiggleConfig.DebugForceAngle.Value : 0f);
		if (num > 0.01f)
		{
			RestoreFallbackBase(Quaternion.identity);
			Vector3 val = ((((Vector3)(ref left.rightLocal)).sqrMagnitude > 0.0001f) ? ((Vector3)(ref left.rightLocal)).normalized : Vector3.right);
			float num2 = num * ((float)Math.PI / 180f);
			left.angle = val * num2;
			right.angle = val * num2;
			left.angVel = Vector3.zero;
			right.angVel = Vector3.zero;
			left.Apply();
			right.Apply();
			return;
		}
		if (JiggleConfig.Enabled == null || !JiggleConfig.Enabled.Value)
		{
			left.Reset();
			right.Reset();
			RestoreFallbackBase(Quaternion.identity);
			hasPrev = false;
			return;
		}
		float num3 = Time.deltaTime;
		if (num3 <= 1E-06f)
		{
			return;
		}
		if (num3 > 0.05f)
		{
			num3 = 0.05f;
		}
		if (!SampleMotion(num3, out var acc, out var angVel))
		{
			return;
		}
		Vector3 aLocal = spine2.InverseTransformDirection(acc);
		Vector3 wLocal = spine2.InverseTransformDirection(angVel);
		StepBone(left, aLocal, wLocal, num3, 1f, 1f);
		StepBone(right, aLocal, wLocal, num3, 1f, -1f);
		ApplySpineAssist();
		if (!loggedAngle && ((Vector3)(ref left.angle)).magnitude * 57.29578f > 1f)
		{
			loggedAngle = true;
			if (JiggleConfig.LogSetup == null || JiggleConfig.LogSetup.Value)
			{
				JigglePlugin.Log($"jiggle active: L={((Vector3)(ref left.angle)).magnitude * 57.29578f:F1}deg R={((Vector3)(ref right.angle)).magnitude * 57.29578f:F1}deg bones={DebugBoneCount}/{DebugBindposeCount}");
			}
		}
	}

	private void StepBone(JiggleBone b, Vector3 aLocal, Vector3 wLocal, float dt, float scale, float sideSign)
	{
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//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_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: 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_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		float num = JiggleConfig.Amplitude.Value * scale;
		if (num <= 0.0001f)
		{
			b.Reset();
			return;
		}
		float num2 = JiggleConfig.MaxAngle.Value * ((float)Math.PI / 180f);
		float num3 = (float)Math.PI * 2f * JiggleConfig.Frequency.Value;
		float num4 = num3 * num3;
		float num5 = 2f * JiggleConfig.Damping.Value * num3;
		Vector3 val = -Vector3.Cross(b.forwardLocal, aLocal) * (0.03f * num);
		val += b.rightLocal * (0f - Vector3.Dot(aLocal, b.forwardLocal)) * (0.018f * num);
		val += -wLocal * (0.12f * num);
		float value = JiggleConfig.IdleSway.Value;
		if (value > 0.0001f)
		{
			float num6 = 0.02f + 0.045f * num;
			float time = Time.time;
			val += new Vector3(Mathf.Sin(time * 1.9f + b.phase), Mathf.Sin(time * 1.3f + b.phase * 2.1f), Mathf.Sin(time * 1.5f + b.phase * 1.3f)) * (num6 * value);
		}
		val += b.rightLocal * (0.004f * num * sideSign);
		val = Vector3.ClampMagnitude(val, num2);
		Vector3 val2 = (val - b.angle) * num4 - b.angVel * num5;
		b.angVel += val2 * dt;
		b.angVel = Vector3.ClampMagnitude(b.angVel, 60f);
		b.angle += b.angVel * dt;
		b.angle = Vector3.ClampMagnitude(b.angle, num2);
		b.Apply();
	}

	private void ApplySpineAssist()
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		if (left == null || (Object)(object)spine2 == (Object)null)
		{
			return;
		}
		float num = ((JiggleConfig.SpineAssist != null) ? JiggleConfig.SpineAssist.Value : 0f);
		if (num <= 0.0001f)
		{
			RestoreFallbackBase(Quaternion.identity);
			return;
		}
		float num2 = ((Vector3)(ref left.angle)).magnitude * num;
		float num3 = (float)Math.PI * 2f / 45f;
		if (num2 > num3)
		{
			num2 = num3;
		}
		if (num2 < 0.0001f)
		{
			RestoreFallbackBase(Quaternion.identity);
		}
		else
		{
			RestoreFallbackBase(Quaternion.AngleAxis(num2 * 57.29578f, ((Vector3)(ref left.angle)).normalized));
		}
	}

	private void SimulateFallback()
	{
		//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_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: 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_0140: 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_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0206: Unknown result type (might be due to invalid IL or missing references)
		//IL_020d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0212: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Unknown result type (might be due to invalid IL or missing references)
		//IL_0240: Unknown result type (might be due to invalid IL or missing references)
		//IL_0247: Unknown result type (might be due to invalid IL or missing references)
		//IL_024c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0258: Unknown result type (might be due to invalid IL or missing references)
		//IL_025b: Unknown result type (might be due to invalid IL or missing references)
		if (fb == null || (Object)(object)spine2 == (Object)null)
		{
			return;
		}
		float num = ((JiggleConfig.DebugForceAngle != null) ? JiggleConfig.DebugForceAngle.Value : 0f);
		if (num > 0.01f)
		{
			RestoreFallbackBase(Quaternion.AngleAxis(num, Vector3.right));
			return;
		}
		if (JiggleConfig.Enabled == null || !JiggleConfig.Enabled.Value)
		{
			RestoreFallbackBase(Quaternion.identity);
			return;
		}
		float num2 = Time.deltaTime;
		if (!(num2 <= 1E-06f))
		{
			if (num2 > 0.05f)
			{
				num2 = 0.05f;
			}
			if (SampleMotion(num2, out var acc, out var angVel))
			{
				Transform parent = spine2.parent;
				Vector3 val = (((Object)(object)parent != (Object)null) ? parent.InverseTransformDirection(acc) : acc);
				Vector3 val2 = (((Object)(object)parent != (Object)null) ? parent.InverseTransformDirection(angVel) : angVel);
				float num3 = JiggleConfig.Amplitude.Value * 0.35f;
				float num4 = JiggleConfig.MaxAngle.Value * ((float)Math.PI / 180f) * 0.4f;
				float num5 = (float)Math.PI * 2f * JiggleConfig.Frequency.Value;
				float num6 = num5 * num5;
				float num7 = 2f * JiggleConfig.Damping.Value * num5;
				Vector3 val3 = (Vector3.ClampMagnitude(-Vector3.Cross(Vector3.forward, val) * (0.03f * num3) + -val2 * (0.12f * num3), num4) - fb.angle) * num6 - fb.angVel * num7;
				JiggleBone jiggleBone = fb;
				jiggleBone.angVel += val3 * num2;
				fb.angVel = Vector3.ClampMagnitude(fb.angVel, 60f);
				JiggleBone jiggleBone2 = fb;
				jiggleBone2.angle += fb.angVel * num2;
				fb.angle = Vector3.ClampMagnitude(fb.angle, num4);
				float magnitude = ((Vector3)(ref fb.angle)).magnitude;
				Quaternion offset = ((magnitude < 1E-05f) ? Quaternion.identity : Quaternion.AngleAxis(magnitude * 57.29578f, fb.angle / magnitude));
				RestoreFallbackBase(offset);
			}
		}
	}

	private void RestoreFallbackBase(Quaternion offset)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: 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_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: 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_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)spine2 == (Object)null))
		{
			Quaternion localRotation = spine2.localRotation;
			Quaternion val = ((!fbHasState || !(Quaternion.Angle(localRotation, fbLastWritten) < 0.5f)) ? localRotation : (localRotation * Quaternion.Inverse(fbLastOffset)));
			spine2.localRotation = val * offset;
			fbLastOffset = offset;
			fbLastWritten = spine2.localRotation;
			fbHasState = true;
		}
	}

	private bool SampleMotion(float dt, out Vector3 acc, out Vector3 angVel)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_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_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_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		acc = Vector3.zero;
		angVel = Vector3.zero;
		if ((Object)(object)spine2 == (Object)null)
		{
			return false;
		}
		Vector3 position = spine2.position;
		Quaternion rotation = spine2.rotation;
		if (!hasPrev)
		{
			prevPos = position;
			prevRot = rotation;
			lastVel = Vector3.zero;
			hasPrev = true;
			return false;
		}
		float num = 1f / dt;
		Vector3 val = (position - prevPos) * num;
		acc = (val - lastVel) * num;
		lastVel = val;
		Quaternion val2 = rotation * Quaternion.Inverse(prevRot);
		float num2 = default(float);
		Vector3 val3 = default(Vector3);
		((Quaternion)(ref val2)).ToAngleAxis(ref num2, ref val3);
		if (num2 > 180f)
		{
			num2 -= 360f;
		}
		angVel = val3 * (num2 * ((float)Math.PI / 180f) * num);
		prevPos = position;
		prevRot = rotation;
		if (((Vector3)(ref acc)).sqrMagnitude > 6400f)
		{
			acc = ((Vector3)(ref acc)).normalized * 80f;
		}
		if (((Vector3)(ref angVel)).sqrMagnitude > 225f)
		{
			angVel = ((Vector3)(ref angVel)).normalized * 15f;
		}
		return true;
	}

	public void OnHit(Vector3 hitPoint, Vector3 force)
	{
		//IL_00a4: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: 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_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: 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_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_020d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0224: Unknown result type (might be due to invalid IL or missing references)
		//IL_0217: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: Unknown result type (might be due to invalid IL or missing references)
		//IL_0239: Unknown result type (might be due to invalid IL or missing references)
		//IL_023e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0263: Unknown result type (might be due to invalid IL or missing references)
		//IL_0256: Unknown result type (might be due to invalid IL or missing references)
		//IL_0268: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0304: Unknown result type (might be due to invalid IL or missing references)
		//IL_0319: Unknown result type (might be due to invalid IL or missing references)
		//IL_031e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0322: Unknown result type (might be due to invalid IL or missing references)
		//IL_0327: Unknown result type (might be due to invalid IL or missing references)
		//IL_032c: Unknown result type (might be due to invalid IL or missing references)
		if (JiggleConfig.Enabled == null || !JiggleConfig.Enabled.Value || JiggleConfig.HitJiggle == null || !JiggleConfig.HitJiggle.Value || (!ready && !fallback))
		{
			return;
		}
		bool num = JiggleConfig.AnyDamage != null && JiggleConfig.AnyDamage.Value;
		float num2 = ((JiggleConfig.HitRadius != null) ? JiggleConfig.HitRadius.Value : 0.55f);
		bool flag = ((Vector3)(ref hitPoint)).sqrMagnitude > 1E-06f;
		float num3 = float.MaxValue;
		float num4 = float.MaxValue;
		if (ready && left != null && (Object)(object)left.bone != (Object)null)
		{
			num3 = Vector3.Distance(hitPoint, left.bone.position);
			num4 = Vector3.Distance(hitPoint, right.bone.position);
		}
		bool flag2 = flag && (num3 <= num2 || num4 <= num2);
		if (!flag2 && fallback && flag && (Object)(object)spine2 != (Object)null)
		{
			Vector3 val = spine2.position + spine2.up * 0.15f;
			flag2 = Vector3.Distance(hitPoint, val) <= num2;
		}
		if (!num && !flag2)
		{
			return;
		}
		float num5 = ((JiggleConfig.HitStrength != null) ? JiggleConfig.HitStrength.Value : 1f);
		if (num5 <= 0.0001f)
		{
			return;
		}
		Vector3 val2 = force;
		if (((Vector3)(ref val2)).sqrMagnitude < 0.0001f)
		{
			val2 = (flag ? (hitPoint - spine2.position) : spine2.forward);
		}
		if (((Vector3)(ref val2)).sqrMagnitude < 0.0001f)
		{
			val2 = spine2.forward;
		}
		((Vector3)(ref val2)).Normalize();
		Vector3 val3 = spine2.InverseTransformDirection(val2);
		Vector3 val4 = Vector3.Cross((left != null) ? left.upLocal : Vector3.up, val3);
		val4 += ((left != null) ? left.rightLocal : Vector3.right) * (Vector3.Dot(val3, (left != null) ? left.forwardLocal : Vector3.forward) * 0.8f);
		if (((Vector3)(ref val4)).sqrMagnitude < 0.0001f)
		{
			val4 = ((left != null) ? left.rightLocal : Vector3.right);
		}
		((Vector3)(ref val4)).Normalize();
		float num6 = Mathf.Clamp(num5 * (flag2 ? 8f : 4f), 0f, 30f);
		float num7 = 1f;
		float num8 = 1f;
		if (flag2 && flag)
		{
			if (num3 < num4)
			{
				num8 = 0.65f;
			}
			else
			{
				num7 = 0.65f;
			}
		}
		if (ready)
		{
			JiggleBone jiggleBone = left;
			jiggleBone.angVel += val4 * (num6 * num7);
			JiggleBone jiggleBone2 = right;
			jiggleBone2.angVel += val4 * (num6 * num8);
		}
		else if (fb != null)
		{
			JiggleBone jiggleBone3 = fb;
			jiggleBone3.angVel += val4 * num6;
		}
	}

	public void OnTeleport()
	{
		//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_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		if (JiggleConfig.Enabled == null || !JiggleConfig.Enabled.Value || JiggleConfig.TeleportKick == null)
		{
			return;
		}
		float value = JiggleConfig.TeleportKick.Value;
		if (!(value <= 0.0001f) && !(Time.time - lastTeleportKick < 0.15f))
		{
			lastTeleportKick = Time.time;
			Vector3 up = default(Vector3);
			((Vector3)(ref up))..ctor(Random.Range(-1f, 1f), Random.Range(-1f, 1f), Random.Range(-1f, 1f));
			if (((Vector3)(ref up)).sqrMagnitude < 0.0001f)
			{
				up = Vector3.up;
			}
			((Vector3)(ref up)).Normalize();
			if (ready && left != null && right != null)
			{
				JiggleBone jiggleBone = left;
				jiggleBone.angVel += up * (8f * value);
				JiggleBone jiggleBone2 = right;
				jiggleBone2.angVel += up * (7f * value);
			}
			else if (fb != null)
			{
				JiggleBone jiggleBone3 = fb;
				jiggleBone3.angVel += up * (5f * value);
			}
		}
	}

	private static int FindBone(Transform[] bones, string nameA, string nameB, int fallbackIndex)
	{
		for (int i = 0; i < bones.Length; i++)
		{
			if (!((Object)(object)bones[i] == (Object)null))
			{
				string name = ((Object)bones[i]).name;
				if (string.Equals(name, nameA, StringComparison.OrdinalIgnoreCase))
				{
					return i;
				}
				if (nameB != null && string.Equals(name, nameB, StringComparison.OrdinalIgnoreCase))
				{
					return i;
				}
			}
		}
		for (int j = 0; j < bones.Length; j++)
		{
			if (!((Object)(object)bones[j] == (Object)null))
			{
				string name2 = ((Object)bones[j]).name;
				if (name2 != null && name2.ToLowerInvariant().StartsWith(nameA.ToLowerInvariant()))
				{
					return j;
				}
			}
		}
		return fallbackIndex;
	}
}
[HarmonyPatch(typeof(Mindflayer), "Start")]
public static class MindflayerStartPatch
{
	private static void Postfix(Mindflayer __instance)
	{
		if ((Object)(object)__instance != (Object)null && (Object)(object)((Component)__instance).GetComponent<MindflayerJiggle>() == (Object)null)
		{
			((Component)__instance).gameObject.AddComponent<MindflayerJiggle>();
		}
	}
}
[HarmonyPatch(typeof(EnemyIdentifier), "DeliverDamage")]
public static class DeliverDamagePatch
{
	private static void Prefix(EnemyIdentifier __instance, object[] __args)
	{
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)__instance == (Object)null || __args == null || __args.Length < 3 || JiggleConfig.Enabled == null || !JiggleConfig.Enabled.Value)
		{
			return;
		}
		Mindflayer val = ((Component)__instance).GetComponentInParent<Mindflayer>();
		if ((Object)(object)val == (Object)null)
		{
			val = ((Component)__instance).GetComponent<Mindflayer>();
		}
		if (!((Object)(object)val == (Object)null))
		{
			MindflayerJiggle component = ((Component)val).GetComponent<MindflayerJiggle>();
			if (!((Object)(object)component == (Object)null))
			{
				Vector3 force = (Vector3)__args[1];
				Vector3 hitPoint = (Vector3)__args[2];
				component.OnHit(hitPoint, force);
			}
		}
	}
}
[HarmonyPatch(typeof(Mindflayer), "Teleport")]
public static class TeleportPatch
{
	private static void Postfix(Mindflayer __instance)
	{
		if (!((Object)(object)__instance == (Object)null))
		{
			MindflayerJiggle component = ((Component)__instance).GetComponent<MindflayerJiggle>();
			if ((Object)(object)component != (Object)null)
			{
				component.OnTeleport();
			}
		}
	}
}
[HarmonyPatch(typeof(Mindflayer), "TeleportTo")]
public static class TeleportToPatch
{
	private static void Postfix(Mindflayer __instance)
	{
		if (!((Object)(object)__instance == (Object)null))
		{
			MindflayerJiggle component = ((Component)__instance).GetComponent<MindflayerJiggle>();
			if ((Object)(object)component != (Object)null)
			{
				component.OnTeleport();
			}
		}
	}
}
public static class JiggleMesh
{
	private class UVChannel
	{
		public int channel;

		public int dimension;

		public Vector2[] uv2;

		public Vector3[] uv3;

		public Vector4[] uv4;
	}

	private class Geometry
	{
		public int vertexCount;

		public Vector3[] vertices;

		public Vector3[] normals;

		public Vector4[] tangents;

		public Color32[] colors;

		public List<UVChannel> uvs = new List<UVChannel>();

		public int[][] indices;

		public MeshTopology[] topology;
	}

	public static bool TryBuild(SkinnedMeshRenderer smr, int spine1Index, int spine2Index, int shoulderLIndex, int shoulderRIndex, out JiggleBone left, out JiggleBone right, out Mesh newMesh, out Transform[] newBones, out string error)
	{
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: 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_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_012c: 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_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: 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_0143: 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_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0238: Unknown result type (might be due to invalid IL or missing references)
		//IL_0239: Unknown result type (might be due to invalid IL or missing references)
		//IL_023d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0242: Unknown result type (might be due to invalid IL or missing references)
		//IL_0247: Unknown result type (might be due to invalid IL or missing references)
		//IL_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		//IL_0257: Unknown result type (might be due to invalid IL or missing references)
		//IL_025b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0260: Unknown result type (might be due to invalid IL or missing references)
		//IL_0262: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Unknown result type (might be due to invalid IL or missing references)
		//IL_026e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0273: Unknown result type (might be due to invalid IL or missing references)
		//IL_0278: Unknown result type (might be due to invalid IL or missing references)
		//IL_027a: Unknown result type (might be due to invalid IL or missing references)
		//IL_027c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0286: Unknown result type (might be due to invalid IL or missing references)
		//IL_028b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0290: Unknown result type (might be due to invalid IL or missing references)
		//IL_0294: Unknown result type (might be due to invalid IL or missing references)
		//IL_0296: Unknown result type (might be due to invalid IL or missing references)
		//IL_029b: Unknown result type (might be due to invalid IL or missing references)
		//IL_029f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02da: Unknown result type (might be due to invalid IL or missing references)
		//IL_0356: Unknown result type (might be due to invalid IL or missing references)
		//IL_035d: Expected O, but got Unknown
		//IL_0362: Unknown result type (might be due to invalid IL or missing references)
		//IL_0369: Expected O, but got Unknown
		//IL_037f: Unknown result type (might be due to invalid IL or missing references)
		//IL_038d: Unknown result type (might be due to invalid IL or missing references)
		//IL_039e: Unknown result type (might be due to invalid IL or missing references)
		//IL_03be: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0402: Unknown result type (might be due to invalid IL or missing references)
		//IL_0404: Unknown result type (might be due to invalid IL or missing references)
		//IL_0409: Unknown result type (might be due to invalid IL or missing references)
		//IL_040e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0410: Unknown result type (might be due to invalid IL or missing references)
		//IL_0415: Unknown result type (might be due to invalid IL or missing references)
		//IL_041e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0420: Unknown result type (might be due to invalid IL or missing references)
		//IL_0425: Unknown result type (might be due to invalid IL or missing references)
		//IL_042a: Unknown result type (might be due to invalid IL or missing references)
		//IL_042c: 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_0575: Unknown result type (might be due to invalid IL or missing references)
		//IL_0577: Unknown result type (might be due to invalid IL or missing references)
		//IL_057c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0580: Unknown result type (might be due to invalid IL or missing references)
		//IL_0585: Unknown result type (might be due to invalid IL or missing references)
		//IL_058f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0591: Unknown result type (might be due to invalid IL or missing references)
		//IL_0596: Unknown result type (might be due to invalid IL or missing references)
		//IL_059a: Unknown result type (might be due to invalid IL or missing references)
		//IL_059f: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_05fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0608: Unknown result type (might be due to invalid IL or missing references)
		//IL_060d: Unknown result type (might be due to invalid IL or missing references)
		left = null;
		right = null;
		newMesh = null;
		newBones = null;
		error = null;
		Mesh sharedMesh = smr.sharedMesh;
		Transform[] bones = smr.bones;
		if ((Object)(object)sharedMesh == (Object)null)
		{
			error = "sharedMesh is null";
			return false;
		}
		if (bones == null || bones.Length < 4)
		{
			error = "bone array is too small";
			return false;
		}
		if (spine2Index < 0 || spine2Index >= bones.Length)
		{
			error = "bad spine.002 index";
			return false;
		}
		if (shoulderLIndex < 0 || shoulderRIndex < 0)
		{
			error = "shoulder bones not found";
			return false;
		}
		Matrix4x4[] bindposes;
		try
		{
			bindposes = sharedMesh.bindposes;
		}
		catch (Exception ex)
		{
			error = "bindposes not readable: " + ex.Message;
			return false;
		}
		if (bindposes == null || bindposes.Length != bones.Length)
		{
			error = $"bindpose count {((bindposes == null) ? (-1) : bindposes.Length)} != bone count {bones.Length}";
			return false;
		}
		if (!ReadGeometry(sharedMesh, out var g, out var error2))
		{
			error = error2;
			return false;
		}
		if (!ReadBoneWeights(sharedMesh, g.vertexCount, out var weights, out var error3))
		{
			error = error3;
			return false;
		}
		Vector3 val = BindPosition(bindposes[spine1Index]);
		Vector3 val2 = BindPosition(bindposes[spine2Index]);
		Vector3 val3 = BindPosition(bindposes[shoulderLIndex]);
		Vector3 val4 = BindPosition(bindposes[shoulderRIndex]);
		Vector3 val5 = (val3 + val4) * 0.5f;
		Vector3 val6 = val5 - val;
		if (((Vector3)(ref val6)).sqrMagnitude < 1E-06f)
		{
			val6 = Vector3.up;
		}
		((Vector3)(ref val6)).Normalize();
		Vector3 val7 = val4 - val3;
		if (((Vector3)(ref val7)).sqrMagnitude < 1E-06f)
		{
			error = "shoulder bones overlap";
			return false;
		}
		((Vector3)(ref val7)).Normalize();
		Vector3 val8 = -Vector3.Cross(val6, val7);
		if (((Vector3)(ref val8)).sqrMagnitude < 1E-06f)
		{
			error = "invalid chest basis";
			return false;
		}
		((Vector3)(ref val8)).Normalize();
		float num = Vector3.Distance(val2, val5);
		if (num < 0.01f || num > 10f)
		{
			num = 0.32f;
		}
		Vector3 val9 = val2 + val6 * (0.5f * num) + val8 * (0.38f * num);
		Vector3 radii = default(Vector3);
		((Vector3)(ref radii))..ctor(0.6f * num, 0.34f * num, 0.42f * num);
		float num2 = 0.18f * num;
		Vector3 val10 = val9 - val7 * num2;
		Vector3 val11 = val9 + val7 * num2;
		Matrix4x4 val12 = bindposes[spine2Index];
		Vector3 val13 = val10 - val8 * (0.38f * num);
		Vector3 val14 = val11 - val8 * (0.38f * num);
		Vector3 val15 = ((Matrix4x4)(ref val12)).MultiplyPoint3x4(val13);
		Vector3 val16 = ((Matrix4x4)(ref val12)).MultiplyPoint3x4(val14);
		int num3 = bones.Length;
		int num4 = bones.Length + 1;
		int num5 = 0;
		int num6 = 0;
		for (int i = 0; i < g.vertexCount; i++)
		{
			Vector3 v = g.vertices[i];
			float num7 = Falloff(v, val10, radii);
			float num8 = Falloff(v, val11, radii);
			if (num7 > 0.0001f && MoveWeight(ref weights[i], spine2Index, num3, num7))
			{
				num5++;
			}
			if (num8 > 0.0001f && MoveWeight(ref weights[i], spine2Index, num4, num8))
			{
				num6++;
			}
		}
		if (num5 + num6 == 0)
		{
			error = "chest region matched no vertices";
			return false;
		}
		Transform val17 = bones[spine2Index];
		GameObject val18 = new GameObject("UK_Mindflayer_Chest_L");
		GameObject val19 = new GameObject("UK_Mindflayer_Chest_R");
		try
		{
			val18.transform.SetParent(val17, false);
			val18.transform.localPosition = val15;
			val18.transform.localRotation = Quaternion.identity;
			val18.transform.localScale = Vector3.one;
			val19.transform.SetParent(val17, false);
			val19.transform.localPosition = val16;
			val19.transform.localRotation = Quaternion.identity;
			val19.transform.localScale = Vector3.one;
			Matrix4x4[] array = (Matrix4x4[])(object)new Matrix4x4[bindposes.Length + 2];
			Array.Copy(bindposes, array, bindposes.Length);
			array[num3] = Matrix4x4.Translate(-val15) * val12;
			array[num4] = Matrix4x4.Translate(-val16) * val12;
			newMesh = BuildMesh(sharedMesh, g, weights, array);
			if ((Object)(object)newMesh == (Object)null)
			{
				error = "mesh reconstruction failed";
				return false;
			}
			newBones = (Transform[])(object)new Transform[bones.Length + 2];
			Array.Copy(bones, newBones, bones.Length);
			newBones[num3] = val18.transform;
			newBones[num4] = val19.transform;
			smr.sharedMesh = newMesh;
			smr.bones = newBones;
			JigglePlugin.Log(string.Format("assign check: shared={0} bind={1} bones={2} lastBone={3}", ((Object)(object)smr.sharedMesh != (Object)null) ? ((Object)smr.sharedMesh).name : "null", ((Object)(object)smr.sharedMesh != (Object)null) ? smr.sharedMesh.bindposeCount : (-1), (smr.bones != null) ? smr.bones.Length : (-1), (smr.bones != null && smr.bones.Length != 0) ? ((Object)smr.bones[smr.bones.Length - 1]).name : "null"));
			left = new JiggleBone();
			left.bone = val18.transform;
			left.side = -1f;
			JiggleBone obj = left;
			Vector3 val20 = ((Matrix4x4)(ref val12)).MultiplyVector(val8);
			obj.forwardLocal = ((Vector3)(ref val20)).normalized;
			JiggleBone obj2 = left;
			val20 = ((Matrix4x4)(ref val12)).MultiplyVector(val6);
			obj2.upLocal = ((Vector3)(ref val20)).normalized;
			JiggleBone obj3 = left;
			val20 = ((Matrix4x4)(ref val12)).MultiplyVector(val7);
			obj3.rightLocal = ((Vector3)(ref val20)).normalized;
			right = new JiggleBone();
			right.bone = val19.transform;
			right.side = 1f;
			right.forwardLocal = left.forwardLocal;
			right.upLocal = left.upLocal;
			right.rightLocal = left.rightLocal;
			JigglePlugin.Log($"Mindflayer rig built: {g.vertexCount} verts, chest verts L={num5} R={num6}, unit={num:F3}");
			return true;
		}
		catch (Exception ex2)
		{
			error = "rig build exception: " + ex2;
			if ((Object)(object)newMesh != (Object)null)
			{
				Object.Destroy((Object)(object)newMesh);
			}
			newMesh = null;
			Object.Destroy((Object)(object)val18);
			Object.Destroy((Object)(object)val19);
			left = null;
			right = null;
			return false;
		}
	}

	private static bool ReadGeometry(Mesh src, out Geometry g, out string error)
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_033f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0344: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: Unknown result type (might be due to invalid IL or missing references)
		//IL_0239: Unknown result type (might be due to invalid IL or missing references)
		//IL_035e: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c9: Expected I4, but got Unknown
		//IL_029a: Unknown result type (might be due to invalid IL or missing references)
		//IL_029f: Unknown result type (might be due to invalid IL or missing references)
		g = new Geometry();
		error = null;
		try
		{
			int vertexCount = src.vertexCount;
			if (vertexCount <= 0)
			{
				error = "mesh has no vertices";
				return false;
			}
			int num = Mathf.Max(1, src.vertexBufferCount);
			int[] array = new int[num];
			byte[][] array2 = new byte[num][];
			try
			{
				src.vertexBufferTarget = (Target)(src.vertexBufferTarget | 0x20);
			}
			catch (Exception)
			{
			}
			for (int i = 0; i < num; i++)
			{
				array[i] = src.GetVertexBufferStride(i);
				if (array[i] <= 0)
				{
					array2[i] = null;
					continue;
				}
				try
				{
					GraphicsBuffer vertexBuffer = src.GetVertexBuffer(i);
					if (vertexBuffer == null)
					{
						array2[i] = null;
						continue;
					}
					byte[] array3 = new byte[vertexBuffer.count * vertexBuffer.stride];
					vertexBuffer.GetData((Array)array3);
					array2[i] = array3;
				}
				catch (Exception)
				{
					array2[i] = null;
				}
			}
			g.vertexCount = vertexCount;
			g.vertices = ReadVec3(src, array2, array, (VertexAttribute)0, vertexCount);
			if (g.vertices == null)
			{
				error = "no position channel";
				return false;
			}
			g.normals = ReadVec3(src, array2, array, (VertexAttribute)1, vertexCount);
			g.tangents = ReadVec4(src, array2, array, (VertexAttribute)2, vertexCount);
			g.colors = ReadColors(src, array2, array, vertexCount);
			if (src.HasVertexAttribute((VertexAttribute)1) && g.normals == null)
			{
				error = "normal stream not readable";
				return false;
			}
			if (src.HasVertexAttribute((VertexAttribute)2) && g.tangents == null)
			{
				error = "tangent stream not readable";
				return false;
			}
			if (src.HasVertexAttribute((VertexAttribute)3) && g.colors == null)
			{
				error = "color stream not readable";
				return false;
			}
			for (int j = 0; j < 8; j++)
			{
				VertexAttribute val = (VertexAttribute)(4 + j);
				if (!src.HasVertexAttribute(val))
				{
					continue;
				}
				UVChannel uVChannel = new UVChannel();
				uVChannel.channel = j;
				uVChannel.dimension = src.GetVertexAttributeDimension(val);
				Vector4[] array4 = ReadVec4(src, array2, array, val, vertexCount);
				if (array4 == null)
				{
					error = "UV stream not readable (channel " + j + ")";
					return false;
				}
				if (uVChannel.dimension <= 2)
				{
					uVChannel.uv2 = (Vector2[])(object)new Vector2[vertexCount];
					for (int k = 0; k < vertexCount; k++)
					{
						uVChannel.uv2[k] = new Vector2(array4[k].x, array4[k].y);
					}
				}
				else if (uVChannel.dimension == 3)
				{
					uVChannel.uv3 = (Vector3[])(object)new Vector3[vertexCount];
					for (int l = 0; l < vertexCount; l++)
					{
						uVChannel.uv3[l] = new Vector3(array4[l].x, array4[l].y, array4[l].z);
					}
				}
				else
				{
					uVChannel.uv4 = array4;
				}
				g.uvs.Add(uVChannel);
			}
			GraphicsBuffer indexBuffer = src.GetIndexBuffer();
			if (indexBuffer == null)
			{
				error = "index buffer is null";
				return false;
			}
			byte[] array5 = new byte[indexBuffer.count * indexBuffer.stride];
			indexBuffer.GetData((Array)array5);
			int subMeshCount = src.subMeshCount;
			g.indices = new int[subMeshCount][];
			g.topology = (MeshTopology[])(object)new MeshTopology[subMeshCount];
			for (int m = 0; m < subMeshCount; m++)
			{
				SubMeshDescriptor subMesh = src.GetSubMesh(m);
				int indexCount = ((SubMeshDescriptor)(ref subMesh)).indexCount;
				int[] array6 = new int[indexCount];
				for (int n = 0; n < indexCount; n++)
				{
					int num2 = (((int)src.indexFormat != 0) ? BitConverter.ToInt32(array5, (((SubMeshDescriptor)(ref subMesh)).indexStart + n) * 4) : BitConverter.ToUInt16(array5, (((SubMeshDescriptor)(ref subMesh)).indexStart + n) * 2));
					array6[n] = num2 + ((SubMeshDescriptor)(ref subMesh)).baseVertex;
				}
				g.indices[m] = array6;
				g.topology[m] = (MeshTopology)(int)((SubMeshDescriptor)(ref subMesh)).topology;
			}
			return true;
		}
		catch (Exception ex3)
		{
			error = "geometry read failed: " + ex3.Message;
			return false;
		}
	}

	private static Vector3[] ReadVec3(Mesh src, byte[][] streams, int[] strides, VertexAttribute attr, int vc)
	{
		//IL_0001: 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_0014: 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_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: 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_0088: Unknown result type (might be due to invalid IL or missing references)
		if (!src.HasVertexAttribute(attr))
		{
			return null;
		}
		int vertexAttributeStream = src.GetVertexAttributeStream(attr);
		int vertexAttributeOffset = src.GetVertexAttributeOffset(attr);
		VertexAttributeFormat vertexAttributeFormat = src.GetVertexAttributeFormat(attr);
		if (vertexAttributeStream < 0 || vertexAttributeStream >= streams.Length || streams[vertexAttributeStream] == null)
		{
			return null;
		}
		byte[] data = streams[vertexAttributeStream];
		int num = strides[vertexAttributeStream];
		Vector3[] array = (Vector3[])(object)new Vector3[vc];
		int num2 = ComponentSize(vertexAttributeFormat);
		for (int i = 0; i < vc; i++)
		{
			int num3 = i * num + vertexAttributeOffset;
			array[i] = new Vector3(ReadFloat(vertexAttributeFormat, data, num3), ReadFloat(vertexAttributeFormat, data, num3 + num2), ReadFloat(vertexAttributeFormat, data, num3 + num2 * 2));
		}
		return array;
	}

	private static Vector4[] ReadVec4(Mesh src, byte[][] streams, int[] strides, VertexAttribute attr, int vc)
	{
		//IL_0001: 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_0014: 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_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: 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_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)
		if (!src.HasVertexAttribute(attr))
		{
			return null;
		}
		int vertexAttributeStream = src.GetVertexAttributeStream(attr);
		int vertexAttributeOffset = src.GetVertexAttributeOffset(attr);
		VertexAttributeFormat vertexAttributeFormat = src.GetVertexAttributeFormat(attr);
		if (vertexAttributeStream < 0 || vertexAttributeStream >= streams.Length || streams[vertexAttributeStream] == null)
		{
			return null;
		}
		byte[] data = streams[vertexAttributeStream];
		int num = strides[vertexAttributeStream];
		Vector4[] array = (Vector4[])(object)new Vector4[vc];
		int num2 = ComponentSize(vertexAttributeFormat);
		for (int i = 0; i < vc; i++)
		{
			int num3 = i * num + vertexAttributeOffset;
			array[i] = new Vector4(ReadFloat(vertexAttributeFormat, data, num3), ReadFloat(vertexAttributeFormat, data, num3 + num2), ReadFloat(vertexAttributeFormat, data, num3 + num2 * 2), ReadFloat(vertexAttributeFormat, data, num3 + num2 * 3));
		}
		return array;
	}

	private static Color32[] ReadColors(Mesh src, byte[][] streams, int[] strides, int vc)
	{
		//IL_001d: 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_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Invalid comparison between Unknown and I4
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		if (!src.HasVertexAttribute((VertexAttribute)3))
		{
			return null;
		}
		int vertexAttributeStream = src.GetVertexAttributeStream((VertexAttribute)3);
		int vertexAttributeOffset = src.GetVertexAttributeOffset((VertexAttribute)3);
		VertexAttributeFormat vertexAttributeFormat = src.GetVertexAttributeFormat((VertexAttribute)3);
		if (vertexAttributeStream < 0 || vertexAttributeStream >= streams.Length || streams[vertexAttributeStream] == null)
		{
			return null;
		}
		byte[] array = streams[vertexAttributeStream];
		int num = strides[vertexAttributeStream];
		Color32[] array2 = (Color32[])(object)new Color32[vc];
		for (int i = 0; i < vc; i++)
		{
			int num2 = i * num + vertexAttributeOffset;
			if ((int)vertexAttributeFormat == 2)
			{
				array2[i] = new Color32(array[num2], array[num2 + 1], array[num2 + 2], array[num2 + 3]);
			}
			else
			{
				array2[i] = new Color32(ToByte(ReadFloat(vertexAttributeFormat, array, num2)), ToByte(ReadFloat(vertexAttributeFormat, array, num2 + ComponentSize(vertexAttributeFormat))), ToByte(ReadFloat(vertexAttributeFormat, array, num2 + ComponentSize(vertexAttributeFormat) * 2)), ToByte(ReadFloat(vertexAttributeFormat, array, num2 + ComponentSize(vertexAttributeFormat) * 3)));
			}
		}
		return array2;
	}

	private static int ComponentSize(VertexAttributeFormat fmt)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected I4, but got Unknown
		switch ((int)fmt)
		{
		case 0:
		case 10:
		case 11:
			return 4;
		case 1:
		case 4:
		case 5:
		case 8:
		case 9:
			return 2;
		default:
			return 1;
		}
	}

	private static float ReadFloat(VertexAttributeFormat fmt, byte[] data, int offset)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected I4, but got Unknown
		return (int)fmt switch
		{
			0 => BitConverter.ToSingle(data, offset), 
			1 => HalfToFloat(BitConverter.ToUInt16(data, offset)), 
			2 => (float)(int)data[offset] / 255f, 
			3 => (float)(sbyte)data[offset] / 127f, 
			4 => (float)(int)BitConverter.ToUInt16(data, offset) / 65535f, 
			5 => (float)BitConverter.ToInt16(data, offset) / 32767f, 
			6 => (int)data[offset], 
			7 => (sbyte)data[offset], 
			8 => (int)BitConverter.ToUInt16(data, offset), 
			9 => BitConverter.ToInt16(data, offset), 
			10 => BitConverter.ToUInt32(data, offset), 
			11 => BitConverter.ToInt32(data, offset), 
			_ => 0f, 
		};
	}

	private static byte ToByte(float v)
	{
		return (byte)Mathf.RoundToInt(Mathf.Clamp01(v) * 255f);
	}

	private static float HalfToFloat(ushort h)
	{
		int num = (h >> 15) & 1;
		int num2 = (h >> 10) & 0x1F;
		int num3 = h & 0x3FF;
		float num4;
		switch (num2)
		{
		case 0:
			num4 = ((num3 != 0) ? ((float)num3 / 1024f * Mathf.Pow(2f, -14f)) : 0f);
			break;
		case 31:
			if (num3 == 0)
			{
				if (num != 0)
				{
					return float.NegativeInfinity;
				}
				return float.PositiveInfinity;
			}
			return float.NaN;
		default:
			num4 = (1f + (float)num3 / 1024f) * Mathf.Pow(2f, (float)(num2 - 15));
			break;
		}
		if (num != 0)
		{
			return 0f - num4;
		}
		return num4;
	}

	private static bool ReadBoneWeights(Mesh src, int vertexCount, out BoneWeight[] weights, out string error)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: 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_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		weights = null;
		error = null;
		try
		{
			NativeArray<byte> bonesPerVertex = src.GetBonesPerVertex();
			NativeArray<BoneWeight1> allBoneWeights = src.GetAllBoneWeights();
			if (!bonesPerVertex.IsCreated || bonesPerVertex.Length == 0)
			{
				error = "mesh exposes no per-vertex bone counts";
				return false;
			}
			if (!allBoneWeights.IsCreated || allBoneWeights.Length == 0)
			{
				error = "mesh exposes no bone weights";
				return false;
			}
			BoneWeight[] array = (BoneWeight[])(object)new BoneWeight[vertexCount];
			int num = 0;
			for (int i = 0; i < vertexCount; i++)
			{
				int num2 = bonesPerVertex[i];
				if (num2 > 4)
				{
					num2 = 4;
				}
				BoneWeight b = default(BoneWeight);
				for (int j = 0; j < num2; j++)
				{
					if (num >= allBoneWeights.Length)
					{
						break;
					}
					BoneWeight1 val = allBoneWeights[num++];
					switch (j)
					{
					case 0:
						((BoneWeight)(ref b)).boneIndex0 = ((BoneWeight1)(ref val)).boneIndex;
						((BoneWeight)(ref b)).weight0 = ((BoneWeight1)(ref val)).weight;
						break;
					case 1:
						((BoneWeight)(ref b)).boneIndex1 = ((BoneWeight1)(ref val)).boneIndex;
						((BoneWeight)(ref b)).weight1 = ((BoneWeight1)(ref val)).weight;
						break;
					case 2:
						((BoneWeight)(ref b)).boneIndex2 = ((BoneWeight1)(ref val)).boneIndex;
						((BoneWeight)(ref b)).weight2 = ((BoneWeight1)(ref val)).weight;
						break;
					case 3:
						((BoneWeight)(ref b)).boneIndex3 = ((BoneWeight1)(ref val)).boneIndex;
						((BoneWeight)(ref b)).weight3 = ((BoneWeight1)(ref val)).weight;
						break;
					}
				}
				Normalize(ref b);
				array[i] = b;
			}
			weights = array;
			return true;
		}
		catch (Exception ex)
		{
			error = "bone weight read failed: " + ex.Message;
			return false;
		}
	}

	private static Mesh BuildMesh(Mesh src, Geometry g, BoneWeight[] weights, Matrix4x4[] bindposes)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Expected O, but got Unknown
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		Mesh val = new Mesh();
		((Object)val).name = ((Object)src).name + "_UKJiggle";
		val.indexFormat = src.indexFormat;
		val.SetVertices(g.vertices);
		if (g.normals != null)
		{
			val.SetNormals(g.normals);
		}
		if (g.tangents != null)
		{
			val.SetTangents(g.tangents);
		}
		if (g.colors != null)
		{
			val.colors32 = g.colors;
		}
		for (int i = 0; i < g.uvs.Count; i++)
		{
			UVChannel uVChannel = g.uvs[i];
			if (uVChannel.uv2 != null)
			{
				val.SetUVs(uVChannel.channel, uVChannel.uv2);
			}
			else if (uVChannel.uv3 != null)
			{
				val.SetUVs(uVChannel.channel, uVChannel.uv3);
			}
			else if (uVChannel.uv4 != null)
			{
				val.SetUVs(uVChannel.channel, uVChannel.uv4);
			}
		}
		val.boneWeights = weights;
		val.bindposes = bindposes;
		val.subMeshCount = g.indices.Length;
		for (int j = 0; j < g.indices.Length; j++)
		{
			val.SetIndices(g.indices[j], g.topology[j], j, false);
		}
		val.RecalculateBounds();
		return val;
	}

	private static Vector3 BindPosition(Matrix4x4 bindpose)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		Matrix4x4 inverse = ((Matrix4x4)(ref bindpose)).inverse;
		return ((Matrix4x4)(ref inverse)).MultiplyPoint3x4(Vector3.zero);
	}

	private static float SmoothStep(float a, float b, float x)
	{
		float num = Mathf.Clamp01((x - a) / (b - a));
		return num * num * (3f - 2f * num);
	}

	private static float Falloff(Vector3 v, Vector3 center, Vector3 radii)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: 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_001a: 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_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		float num = (v.x - center.x) / radii.x;
		float num2 = (v.y - center.y) / radii.y;
		float num3 = (v.z - center.z) / radii.z;
		float x = Mathf.Sqrt(num * num + num2 * num2 + num3 * num3);
		return 1f - SmoothStep(0.55f, 1.05f, x);
	}

	private static float GetWeight(ref BoneWeight b, int bone)
	{
		if (((BoneWeight)(ref b)).boneIndex0 == bone)
		{
			return ((BoneWeight)(ref b)).weight0;
		}
		if (((BoneWeight)(ref b)).boneIndex1 == bone)
		{
			return ((BoneWeight)(ref b)).weight1;
		}
		if (((BoneWeight)(ref b)).boneIndex2 == bone)
		{
			return ((BoneWeight)(ref b)).weight2;
		}
		if (((BoneWeight)(ref b)).boneIndex3 == bone)
		{
			return ((BoneWeight)(ref b)).weight3;
		}
		return 0f;
	}

	private static void SetWeight(ref BoneWeight b, int bone, float w)
	{
		if (((BoneWeight)(ref b)).boneIndex0 == bone)
		{
			((BoneWeight)(ref b)).weight0 = w;
		}
		else if (((BoneWeight)(ref b)).boneIndex1 == bone)
		{
			((BoneWeight)(ref b)).weight1 = w;
		}
		else if (((BoneWeight)(ref b)).boneIndex2 == bone)
		{
			((BoneWeight)(ref b)).weight2 = w;
		}
		else if (((BoneWeight)(ref b)).boneIndex3 == bone)
		{
			((BoneWeight)(ref b)).weight3 = w;
		}
	}

	private static bool AddWeight(ref BoneWeight b, int bone, float w)
	{
		if (((BoneWeight)(ref b)).boneIndex0 == bone)
		{
			((BoneWeight)(ref b)).weight0 = ((BoneWeight)(ref b)).weight0 + w;
			return true;
		}
		if (((BoneWeight)(ref b)).boneIndex1 == bone)
		{
			((BoneWeight)(ref b)).weight1 = ((BoneWeight)(ref b)).weight1 + w;
			return true;
		}
		if (((BoneWeight)(ref b)).boneIndex2 == bone)
		{
			((BoneWeight)(ref b)).weight2 = ((BoneWeight)(ref b)).weight2 + w;
			return true;
		}
		if (((BoneWeight)(ref b)).boneIndex3 == bone)
		{
			((BoneWeight)(ref b)).weight3 = ((BoneWeight)(ref b)).weight3 + w;
			return true;
		}
		if (((BoneWeight)(ref b)).weight0 <= 1E-05f)
		{
			((BoneWeight)(ref b)).boneIndex0 = bone;
			((BoneWeight)(ref b)).weight0 = w;
			return true;
		}
		if (((BoneWeight)(ref b)).weight1 <= 1E-05f)
		{
			((BoneWeight)(ref b)).boneIndex1 = bone;
			((BoneWeight)(ref b)).weight1 = w;
			return true;
		}
		if (((BoneWeight)(ref b)).weight2 <= 1E-05f)
		{
			((BoneWeight)(ref b)).boneIndex2 = bone;
			((BoneWeight)(ref b)).weight2 = w;
			return true;
		}
		if (((BoneWeight)(ref b)).weight3 <= 1E-05f)
		{
			((BoneWeight)(ref b)).boneIndex3 = bone;
			((BoneWeight)(ref b)).weight3 = w;
			return true;
		}
		int num = 0;
		float num2 = ((BoneWeight)(ref b)).weight0;
		if (((BoneWeight)(ref b)).weight1 < num2)
		{
			num2 = ((BoneWeight)(ref b)).weight1;
			num = 1;
		}
		if (((BoneWeight)(ref b)).weight2 < num2)
		{
			num2 = ((BoneWeight)(ref b)).weight2;
			num = 2;
		}
		if (((BoneWeight)(ref b)).weight3 < num2)
		{
			num2 = ((BoneWeight)(ref b)).weight3;
			num = 3;
		}
		switch (num)
		{
		case 0:
			((BoneWeight)(ref b)).boneIndex0 = bone;
			((BoneWeight)(ref b)).weight0 = w;
			break;
		case 1:
			((BoneWeight)(ref b)).boneIndex1 = bone;
			((BoneWeight)(ref b)).weight1 = w;
			break;
		case 2:
			((BoneWeight)(ref b)).boneIndex2 = bone;
			((BoneWeight)(ref b)).weight2 = w;
			break;
		default:
			((BoneWeight)(ref b)).boneIndex3 = bone;
			((BoneWeight)(ref b)).weight3 = w;
			break;
		}
		return true;
	}

	private static bool MoveWeight(ref BoneWeight b, int fromBone, int toBone, float fraction)
	{
		float weight = GetWeight(ref b, fromBone);
		if (weight <= 1E-05f)
		{
			return false;
		}
		float num = weight * Mathf.Clamp01(fraction);
		if (num <= 1E-05f)
		{
			return false;
		}
		SetWeight(ref b, fromBone, weight - num);
		AddWeight(ref b, toBone, num);
		Normalize(ref b);
		return true;
	}

	private static void Normalize(ref BoneWeight b)
	{
		float num = ((BoneWeight)(ref b)).weight0 + ((BoneWeight)(ref b)).weight1 + ((BoneWeight)(ref b)).weight2 + ((BoneWeight)(ref b)).weight3;
		if (num <= 1E-06f)
		{
			((BoneWeight)(ref b)).weight0 = 1f;
			return;
		}
		((BoneWeight)(ref b)).weight0 = ((BoneWeight)(ref b)).weight0 / num;
		((BoneWeight)(ref b)).weight1 = ((BoneWeight)(ref b)).weight1 / num;
		((BoneWeight)(ref b)).weight2 = ((BoneWeight)(ref b)).weight2 / num;
		((BoneWeight)(ref b)).weight3 = ((BoneWeight)(ref b)).weight3 / num;
	}
}
public static class JigglePanel
{
	public static bool Open;

	private static Rect windowRect = new Rect(60f, 60f, 500f, 640f);

	private static Font cjkFont;

	private static bool fontTried;

	private static bool cursorSaved;

	private static CursorLockMode savedLock;

	private static bool savedVisible;

	public static void Toggle()
	{
		//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)
		Open = !Open;
		if (Open)
		{
			savedLock = Cursor.lockState;
			savedVisible = Cursor.visible;
			cursorSaved = true;
			KeepCursorUnlocked();
			return;
		}
		RestoreCursor();
		try
		{
			if (JigglePlugin.Cfg != null)
			{
				JigglePlugin.Cfg.Save();
			}
		}
		catch (Exception)
		{
		}
	}

	public static void KeepCursorUnlocked()
	{
		Cursor.visible = true;
		Cursor.lockState = (CursorLockMode)0;
	}

	public static void RestoreCursor()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		if (cursorSaved)
		{
			Cursor.visible = savedVisible;
			Cursor.lockState = savedLock;
			cursorSaved = false;
		}
	}

	public static void Draw()
	{
		//IL_003f: 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_005f: Expected O, but got Unknown
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		if (!Open)
		{
			return;
		}
		KeepCursorUnlocked();
		EnsureFont();
		Font font = GUI.skin.font;
		if ((Object)(object)cjkFont != (Object)null)
		{
			GUI.skin.font = cjkFont;
		}
		try
		{
			windowRect = GUILayout.Window(19015, windowRect, new WindowFunction(DrawWindow), "夺心魔胸部摇晃  |  Mindflayer Chest Jiggle  v1.0.1", Array.Empty<GUILayoutOption>());
		}
		finally
		{
			GUI.skin.font = font;
		}
	}

	private static void EnsureFont()
	{
		if (fontTried)
		{
			return;
		}
		fontTried = true;
		try
		{
			cjkFont = Font.CreateDynamicFontFromOSFont(new string[6] { "Microsoft YaHei", "微软雅黑", "SimHei", "Noto Sans CJK SC", "Arial Unicode MS", "Arial" }, 14);
		}
		catch (Exception)
		{
			cjkFont = null;
		}
	}

	private static void DrawWindow(int id)
	{
		//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.Space(2f);
		GUILayout.Label("F10 打开/关闭本面板 · 设置会写入 BepInEx/config", Array.Empty<GUILayoutOption>());
		GUILayout.Space(6f);
		Toggle("启用胸部摇晃 (Enabled)", JiggleConfig.Enabled);
		GUILayout.Space(6f);
		GUILayout.Label("— 摇晃手感 —", Array.Empty<GUILayoutOption>());
		Slider("幅度 (Amplitude)", JiggleConfig.Amplitude, 0f, 3f, "0.00");
		Slider("频率 Hz (Frequency)", JiggleConfig.Frequency, 2f, 20f, "0.0");
		Slider("阻尼 (Damping)", JiggleConfig.Damping, 0.02f, 1f, "0.00");
		Slider("最大角度 (Max Angle)", JiggleConfig.MaxAngle, 3f, 45f, "0");
		Slider("待机微晃 (Idle Sway)", JiggleConfig.IdleSway, 0f, 1f, "0.00");
		GUILayout.Space(6f);
		GUILayout.Label("— 受击摇晃 —", Array.Empty<GUILayoutOption>());
		Toggle("被打中胸部时摇晃 (Hit Reaction)", JiggleConfig.HitJiggle);
		Slider("受击强度 (Hit Strength)", JiggleConfig.HitStrength, 0f, 5f, "0.00");
		Slider("胸部命中半径 (Chest Radius)", JiggleConfig.HitRadius, 0.1f, 1.5f, "0.00");
		Toggle("打中任何部位都摇晃 (Any Hit)", JiggleConfig.AnyDamage);
		Slider("传送抖动 (Teleport Kick)", JiggleConfig.TeleportKick, 0f, 3f, "0.00");
		GUILayout.Space(6f);
		GUILayout.Label("— 其它 —", Array.Empty<GUILayoutOption>());
		Toggle("显示调试信息 (Show Debug)", JiggleConfig.ShowDebug);
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		if (GUILayout.Button("重置默认", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(110f) }))
		{
			ResetDefaults();
		}
		if (GUILayout.Button("保存配置", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(110f) }))
		{
			try
			{
				JigglePlugin.Cfg.Save();
			}
			catch (Exception)
			{
			}
		}
		if (GUILayout.Button("关闭 (F10)", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(110f) }))
		{
			Toggle();
		}
		GUILayout.EndHorizontal();
		if (JiggleConfig.ShowDebug != null && JiggleConfig.ShowDebug.Value)
		{
			GUILayout.Space(6f);
			GUILayout.Label("— 诊断 —", Array.Empty<GUILayoutOption>());
			Slider("固定角度(0=正常物理)", JiggleConfig.DebugForceAngle, 0f, 45f, "0.0");
			Slider("脊椎辅助 (Spine Assist)", JiggleConfig.SpineAssist, 0f, 1f, "0.00");
			MindflayerJiggle lastInstance = MindflayerJiggle.LastInstance;
			if ((Object)(object)lastInstance != (Object)null)
			{
				GUILayout.Label($"最近一只: L={lastInstance.DebugAngleL:F1}° R={lastInstance.DebugAngleR:F1}°  实际偏差 L={lastInstance.DebugActualAngleL:F1}° R={lastInstance.DebugActualAngleR:F1}°", Array.Empty<GUILayoutOption>());
				GUILayout.Label($"骨骼={lastInstance.DebugBoneCount} 渲染网格bind={lastInstance.DebugBindposeCount}  新骨骼权重顶点={lastInstance.DebugNewWeightVerts}", Array.Empty<GUILayoutOption>());
				GUILayout.Label("末两根骨骼: " + lastInstance.DebugBoneNames, Array.Empty<GUILayoutOption>());
			}
			GUILayout.Space(4f);
			GUILayout.Label($"活动夺心魔: {MindflayerJiggle.ActiveCount}   网格模式: {MindflayerJiggle.MeshModeCount}   仅脊椎回退: {MindflayerJiggle.FallbackCount}", Array.Empty<GUILayoutOption>());
			GUILayout.Label($"每秒帧数: {1f / Mathf.Max(0.0001f, Time.smoothDeltaTime):F0}   F10 键可在 cfg 里改", Array.Empty<GUILayoutOption>());
			if (MindflayerJiggle.ActiveCount == 0)
			{
				GUILayout.Label("当前没有检测到夺心魔。进入有夺心魔的关卡或 Sandbox 生成一只即可。", Array.Empty<GUILayoutOption>());
			}
		}
		GUILayout.Space(4f);
		GUILayout.Label("拖动标题栏可移动窗口。关闭面板后鼠标会恢复游戏锁定。", Array.Empty<GUILayoutOption>());
		GUI.DragWindow(new Rect(0f, 0f, 10000f, 24f));
	}

	private static void ResetDefaults()
	{
		JiggleConfig.Enabled.Value = true;
		JiggleConfig.Amplitude.Value = 1.4f;
		JiggleConfig.Frequency.Value = 5.5f;
		JiggleConfig.Damping.Value = 0.22f;
		JiggleConfig.MaxAngle.Value = 22f;
		JiggleConfig.IdleSway.Value = 0.7f;
		JiggleConfig.SpineAssist.Value = 0f;
		JiggleConfig.HitJiggle.Value = true;
		JiggleConfig.HitStrength.Value = 1f;
		JiggleConfig.HitRadius.Value = 0.55f;
		JiggleConfig.AnyDamage.Value = false;
		JiggleConfig.TeleportKick.Value = 1f;
		JiggleConfig.ShowDebug.Value = false;
		JiggleConfig.DebugForceAngle.Value = 0f;
		try
		{
			JigglePlugin.Cfg.Save();
		}
		catch (Exception)
		{
		}
	}

	private static void Toggle(string label, ConfigEntry<bool> entry)
	{
		if (entry != null)
		{
			bool flag = GUILayout.Toggle(entry.Value, label, Array.Empty<GUILayoutOption>());
			if (flag != entry.Value)
			{
				entry.Value = flag;
			}
		}
	}

	private static void Slider(string label, ConfigEntry<float> entry, float min, float max, string format)
	{
		if (entry != null)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label(label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(230f) });
			float num = GUILayout.HorizontalSlider(entry.Value, min, max, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(160f) });
			if (Mathf.Abs(num - entry.Value) > 0.0001f)
			{
				entry.Value = num;
			}
			GUILayout.Label(num.ToString(format), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(55f) });