Decompiled source of Shackle Cannon v0.1.2

BepInEx/plugins/ShackleCannon/RetroTsunami.ShackleCannon.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PEAKLib.Core;
using PEAKLib.Items;
using Photon.Pun;
using UnityEngine;
using UnityEngine.Rendering;
using Zorro.Settings;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Retro Tsunami")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.2.0")]
[assembly: AssemblyInformationalVersion("0.1.2")]
[assembly: AssemblyProduct("RetroTsunami.ShackleCannon")]
[assembly: AssemblyTitle("RetroTsunami.ShackleCannon")]
[assembly: AssemblyVersion("0.1.2.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ShackleCannon
{
	internal static class ChainEndpoints
	{
		private sealed class State
		{
			internal ChainPath Path;
		}

		private static readonly ConditionalWeakTable<object, State> states = new ConditionalWeakTable<object, State>();

		private static FieldInfo character = null;

		private static FieldInfo data = null;

		private static FieldInfo heldVine = null;

		private static FieldInfo colliderRoot = null;

		internal static void Configure(Assembly game)
		{
			character = AccessTools.Field(game.GetType("CharacterVineClimbing"), "character");
			data = AccessTools.Field(game.GetType("Character"), "data");
			heldVine = AccessTools.Field(game.GetType("CharacterData"), "heldVine");
			colliderRoot = AccessTools.Field(game.GetType("JungleVine"), "colliderRoot");
			if (character == null || data == null || heldVine == null || colliderRoot == null)
			{
				throw new MissingFieldException("Chain endpoint fields missing.");
			}
		}

		internal static ChainPath? Register(object chain)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			states.Remove(chain);
			object? value = colliderRoot.GetValue(chain);
			Transform val = (Transform)((value is Transform) ? value : null);
			if ((Object)(object)val == (Object)null || val.childCount != 50)
			{
				return null;
			}
			PathPoint[] array = new PathPoint[50];
			for (int i = 0; i < 50; i++)
			{
				Vector3 position = val.GetChild(i).position;
				array[i] = new PathPoint(position.x, position.y, position.z);
			}
			ChainPath chainPath = new ChainPath(array);
			if (chainPath.Length > 40f)
			{
				states.Add(chain, new State
				{
					Path = chainPath
				});
			}
			return chainPath;
		}

		private static float Bound(float original, object climbing)
		{
			object value = character.GetValue(climbing);
			object obj = ((value == null) ? null : data.GetValue(value));
			object obj2 = ((obj == null) ? null : heldVine.GetValue(obj));
			if (obj2 == null || !states.TryGetValue(obj2, out State value2))
			{
				return original;
			}
			return ChainPolicy.EndpointBound(original, value2.Path.Length);
		}

		internal static IEnumerable<CodeInstruction> FixedTranspiler(IEnumerable<CodeInstruction> instructions)
		{
			return EndpointRewrite.Rewrite(instructions, AccessTools.Method(typeof(ChainEndpoints), "Bound", (Type[])null, (Type[])null), 2);
		}

		internal static IEnumerable<CodeInstruction> GrabTranspiler(IEnumerable<CodeInstruction> instructions)
		{
			return EndpointRewrite.Rewrite(instructions, AccessTools.Method(typeof(ChainEndpoints), "Bound", (Type[])null, (Type[])null), 1);
		}

		internal static void PositionPrefix(object __instance, ref int clampFromBottom, ref int clampFromTop)
		{
			if (clampFromBottom == 1 && clampFromTop == 1 && states.TryGetValue(__instance, out State _))
			{
				clampFromBottom = 0;
				clampFromTop = 0;
			}
		}
	}
	internal readonly struct PathPoint
	{
		internal readonly float X;

		internal readonly float Y;

		internal readonly float Z;

		internal PathPoint(float x, float y, float z)
		{
			X = x;
			Y = y;
			Z = z;
		}

		internal static float Distance(PathPoint a, PathPoint b)
		{
			return (float)Math.Sqrt((a.X - b.X) * (a.X - b.X) + (a.Y - b.Y) * (a.Y - b.Y) + (a.Z - b.Z) * (a.Z - b.Z));
		}

		internal static PathPoint Lerp(PathPoint a, PathPoint b, float t)
		{
			return new PathPoint(a.X + (b.X - a.X) * t, a.Y + (b.Y - a.Y) * t, a.Z + (b.Z - a.Z) * t);
		}
	}
	internal sealed class ChainPath
	{
		private readonly PathPoint[] points;

		private readonly float[] distances;

		internal float Length => distances[distances.Length - 1];

		internal ChainPath(PathPoint[] source)
		{
			if (source.Length < 2)
			{
				throw new ArgumentException("At least two points required.");
			}
			points = (PathPoint[])source.Clone();
			distances = new float[points.Length];
			for (int i = 1; i < points.Length; i++)
			{
				distances[i] = distances[i - 1] + PathPoint.Distance(points[i - 1], points[i]);
			}
			if (float.IsNaN(Length) || float.IsInfinity(Length) || Length <= 0f)
			{
				throw new ArgumentException("Invalid path length.");
			}
		}

		internal PathPoint At(float distance)
		{
			if (distance <= 0f)
			{
				return points[0];
			}
			if (distance >= Length)
			{
				return points[points.Length - 1];
			}
			int num = Array.BinarySearch(distances, distance);
			if (num >= 0)
			{
				return points[num];
			}
			num = ~num;
			return PathPoint.Lerp(points[num - 1], points[num], (distance - distances[num - 1]) / (distances[num] - distances[num - 1]));
		}
	}
	internal static class ChainPolicy
	{
		internal static float EndpointBound(float original, float length)
		{
			if (length <= 40f || float.IsNaN(length) || float.IsInfinity(length))
			{
				return original;
			}
			float num = Math.Min(0.01f, 0.5f / length);
			if (original != 0.01f)
			{
				if (original != 0.99f)
				{
					return original;
				}
				return 1f - num;
			}
			return num;
		}

		internal static int SectionCount(float length, float sectionLength)
		{
			return Math.Max(1, (int)Math.Round(length / sectionLength, MidpointRounding.AwayFromZero));
		}
	}
	public sealed class ChargeFeedback : MonoBehaviour
	{
		private Item item;

		private AudioSource? audio;

		private static AudioClip? rumble;

		private float nextPulse;

		private void Awake()
		{
			item = ((Component)this).GetComponent<Item>();
		}

		private void Update()
		{
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Expected O, but got Unknown
			if ((Object)(object)item == (Object)null)
			{
				Stop();
				return;
			}
			if (!FeedbackPolicy.IsCharging((Object)(object)Character.localCharacter != (Object)null && (Object)(object)item.holderCharacter == (Object)(object)Character.localCharacter, item.isUsingPrimary, item.finishedCast, item.castProgress) || Time.timeScale == 0f)
			{
				Stop();
				return;
			}
			float num = Mathf.Clamp01(item.castProgress);
			if (Plugin.Shake.Value && Plugin.ChargeShake.Value && (Object)(object)GamefeelHandler.instance != (Object)null && GamefeelHandler.instance.setting != null && Time.time >= nextPulse)
			{
				GamefeelHandler.instance.AddPerlinShake(FeedbackPolicy.ChargeAmount(num), 0.11f, Mathf.Lerp(12f, 22f, num));
				nextPulse = Time.time + 0.1f;
			}
			if (!Plugin.ChargeSound.Value)
			{
				if ((Object)(object)audio != (Object)null)
				{
					audio.Stop();
				}
				return;
			}
			if ((Object)(object)audio == (Object)null)
			{
				if ((Object)(object)rumble == (Object)null)
				{
					float[] array = new float[11025];
					for (int i = 0; i < array.Length; i++)
					{
						float num2 = (float)i / 22050f;
						array[i] = 0.25f * Mathf.Sin(MathF.PI * 120f * num2) + 0.08f * Mathf.Sin(MathF.PI * 240f * num2) + 0.035f * Mathf.Sin(MathF.PI * 480f * num2);
					}
					rumble = AudioClip.Create("ShackleChargeRumble", array.Length, 1, 22050, false);
					rumble.SetData(array, 0);
				}
				GameObject val = new GameObject("ShackleChargeAudio");
				val.transform.SetParent(((Component)this).transform, false);
				audio = val.AddComponent<AudioSource>();
				audio.playOnAwake = false;
				audio.loop = true;
				audio.spatialBlend = 0f;
				audio.clip = rumble;
			}
			audio.volume = Mathf.Lerp(0.1f, 0.4f, num);
			audio.pitch = Mathf.Lerp(0.8f, 1.5f, num);
			if (!audio.isPlaying)
			{
				audio.Play();
			}
		}

		private void Stop()
		{
			if ((Object)(object)audio != (Object)null && audio.isPlaying)
			{
				audio.Stop();
			}
			nextPulse = 0f;
		}

		private void OnDisable()
		{
			Stop();
		}

		private void OnDestroy()
		{
			Stop();
		}
	}
	internal static class ConfigPolicy
	{
		internal static float Range(float value)
		{
			if (!float.IsNaN(value) && !float.IsInfinity(value))
			{
				return Math.Max(100f, Math.Min(10000f, value));
			}
			return 2000f;
		}

		internal static float Speed(float value)
		{
			if (!float.IsNaN(value) && !float.IsInfinity(value))
			{
				return Math.Max(1f, Math.Min(4f, value));
			}
			return 2f;
		}
	}
	internal sealed class CurvePath
	{
		private const int Samples = 1024;

		private readonly PathPoint a;

		private readonly PathPoint b;

		private readonly PathPoint c;

		private readonly float[] distances = new float[1025];

		internal float Length => distances[1024];

		internal CurvePath(PathPoint from, PathPoint mid, PathPoint to)
		{
			a = from;
			b = mid;
			c = to;
			PathPoint pathPoint = Position(0f);
			for (int i = 1; i <= 1024; i++)
			{
				PathPoint pathPoint2 = Position((float)i / 1024f);
				distances[i] = distances[i - 1] + PathPoint.Distance(pathPoint, pathPoint2);
				pathPoint = pathPoint2;
			}
			if (float.IsNaN(Length) || float.IsInfinity(Length) || Length <= 0.0001f)
			{
				throw new ArgumentException("Degenerate curve.");
			}
		}

		private PathPoint Position(float t)
		{
			return PathPoint.Lerp(PathPoint.Lerp(a, b, t), PathPoint.Lerp(b, c, t), t);
		}

		private float Parameter(float distance)
		{
			if (distance <= 0f)
			{
				return 0f;
			}
			if (distance >= Length)
			{
				return 1f;
			}
			int num = Array.BinarySearch(distances, distance);
			if (num >= 0)
			{
				return (float)num / 1024f;
			}
			num = ~num;
			float num2 = (distance - distances[num - 1]) / (distances[num] - distances[num - 1]);
			return ((float)(num - 1) + num2) / 1024f;
		}

		internal PathPoint At(float distance)
		{
			if (distance < 0f || distance > Length)
			{
				float num = ((distance < 0f) ? distance : (distance - Length));
				PathPoint pathPoint = ((distance < 0f) ? a : c);
				PathPoint pathPoint2 = Tangent(distance);
				float num2 = PathPoint.Distance(new PathPoint(0f, 0f, 0f), pathPoint2);
				return new PathPoint(pathPoint.X + pathPoint2.X * num / num2, pathPoint.Y + pathPoint2.Y * num / num2, pathPoint.Z + pathPoint2.Z * num / num2);
			}
			return Position(Parameter(distance));
		}

		internal PathPoint Tangent(float distance)
		{
			float num = Parameter(distance);
			PathPoint result = new PathPoint(2f * ((1f - num) * (b.X - a.X) + num * (c.X - b.X)), 2f * ((1f - num) * (b.Y - a.Y) + num * (c.Y - b.Y)), 2f * ((1f - num) * (b.Z - a.Z) + num * (c.Z - b.Z)));
			if (PathPoint.Distance(result, new PathPoint(0f, 0f, 0f)) < 1E-05f)
			{
				return new PathPoint(c.X - a.X, c.Y - a.Y, c.Z - a.Z);
			}
			return result;
		}
	}
	internal static class EndpointRewrite
	{
		internal static List<CodeInstruction> Rewrite(IEnumerable<CodeInstruction> source, MethodInfo helper, int expectedEach)
		{
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Expected O, but got Unknown
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Expected O, but got Unknown
			List<CodeInstruction> list = source.Select((Func<CodeInstruction, CodeInstruction>)((CodeInstruction i) => new CodeInstruction(i))).ToList();
			if (list.Count((CodeInstruction i) => IsBound(i, 0.01f)) != expectedEach || list.Count((CodeInstruction i) => IsBound(i, 0.99f)) != expectedEach)
			{
				throw new InvalidOperationException("Unexpected climbing-bound IL; patch refused.");
			}
			List<CodeInstruction> list2 = new List<CodeInstruction>();
			foreach (CodeInstruction item in list)
			{
				list2.Add(item);
				if (IsBound(item, 0.01f) || IsBound(item, 0.99f))
				{
					list2.Add(new CodeInstruction(OpCodes.Ldarg_0, (object)null));
					list2.Add(new CodeInstruction(OpCodes.Call, (object)helper));
				}
			}
			return list2;
			static bool IsBound(CodeInstruction i, float f)
			{
				if (i.opcode == OpCodes.Ldc_R4 && i.operand is float num)
				{
					return num == f;
				}
				return false;
			}
		}
	}
	internal static class FeedbackPolicy
	{
		internal static float ActivationSeconds(float original, float multiplier)
		{
			if (float.IsNaN(multiplier) || float.IsInfinity(multiplier))
			{
				multiplier = 2f;
			}
			multiplier = Math.Max(1f, Math.Min(5f, multiplier));
			if (!(original > 0f) || float.IsInfinity(original))
			{
				return original;
			}
			return original * multiplier;
		}

		internal static float ChargeAmount(float progress)
		{
			return 0.06f + 0.28f * Math.Max(0f, Math.Min(1f, progress));
		}

		internal static bool IsCharging(bool localHeld, bool usingPrimary, bool finished, float progress)
		{
			if (localHeld && usingPrimary && !finished && progress > 0f)
			{
				return progress < 1f;
			}
			return false;
		}
	}
	internal static class ImpactEffect
	{
		private static GameObject? template;

		private static readonly HashSet<Type> Allowed = new HashSet<Type>
		{
			typeof(Transform),
			typeof(ParticleSystem),
			typeof(ParticleSystemRenderer),
			typeof(MeshFilter),
			typeof(MeshRenderer),
			typeof(SkinnedMeshRenderer),
			typeof(Animator),
			typeof(Animation),
			typeof(AudioSource),
			typeof(Light),
			typeof(ExplosionEffect),
			typeof(SFX_PlayOneShot),
			typeof(DestroyAfterTime)
		};

		internal static void Prepare(ItemDatabase database, Transform staging)
		{
			GameObject[] array = (from i in database.itemLookup.Values
				select ((Component)i).GetComponent<Dynamite>() into d
				where (Object)(object)d != (Object)null && (Object)(object)d.explosionPrefab != (Object)null
				select d.explosionPrefab).Distinct().ToArray();
			if (array.Length != 1)
			{
				throw new InvalidOperationException("Expected one dynamite explosion prefab; found " + array.Length);
			}
			Dictionary<GameObject, GameObject> cache = new Dictionary<GameObject, GameObject>();
			HashSet<GameObject> visiting = new HashSet<GameObject>();
			HashSet<string> stripped = new HashSet<string>();
			template = Copy(array[0]);
			Plugin.ReportVisual("Prepared cosmetic dynamite impact: " + ((Object)array[0]).name + "; sanitized prefabs=" + cache.Count + "; removed=" + string.Join(", ", stripped.OrderBy((string s) => s)), warning: false);
			GameObject Copy(GameObject original)
			{
				if (visiting.Contains(original))
				{
					throw new InvalidOperationException("Cyclic explosion prefab references.");
				}
				if (cache.TryGetValue(original, out GameObject value))
				{
					return value;
				}
				if (cache.Count >= 16)
				{
					throw new InvalidOperationException("Unexpected explosion prefab graph size.");
				}
				visiting.Add(original);
				GameObject val = Object.Instantiate<GameObject>(original, staging);
				((Object)val).name = "ShackleCosmetic_" + ((Object)original).name;
				cache.Add(original, val);
				MonoBehaviour[] componentsInChildren = val.GetComponentsInChildren<MonoBehaviour>(true);
				foreach (MonoBehaviour val2 in componentsInChildren)
				{
					if (!((Object)(object)val2 == (Object)null) && !Allowed.Contains(((object)val2).GetType()))
					{
						stripped.Add(((object)val2).GetType().FullName);
						Object.DestroyImmediate((Object)(object)val2);
					}
				}
				Component[] componentsInChildren2 = val.GetComponentsInChildren<Component>(true);
				foreach (Component val3 in componentsInChildren2)
				{
					if ((Object)(object)val3 != (Object)null && !Allowed.Contains(((object)val3).GetType()))
					{
						stripped.Add(((object)val3).GetType().FullName);
						Object.DestroyImmediate((Object)(object)val3);
					}
				}
				if (val.GetComponentsInChildren<Component>(true).Any((Component c) => (Object)(object)c != (Object)null && !Allowed.Contains(((object)c).GetType())))
				{
					throw new InvalidOperationException("Could not strip all non-cosmetic components.");
				}
				SFX_PlayOneShot[] componentsInChildren3 = val.GetComponentsInChildren<SFX_PlayOneShot>(true);
				foreach (SFX_PlayOneShot obj in componentsInChildren3)
				{
					obj.beforePlayAction = null;
					obj.afterPlayAction = null;
					obj.sfxs = obj.sfxs ?? Array.Empty<SFX_Instance>();
				}
				ExplosionEffect[] componentsInChildren4 = val.GetComponentsInChildren<ExplosionEffect>(true);
				foreach (ExplosionEffect obj2 in componentsInChildren4)
				{
					if ((Object)(object)obj2.explosionOrb == (Object)null)
					{
						throw new InvalidOperationException("Missing explosion orb prefab.");
					}
					obj2.explosionOrb = Copy(obj2.explosionOrb);
				}
				if ((Object)(object)val.GetComponent<DestroyAfterTime>() == (Object)null)
				{
					val.AddComponent<DestroyAfterTime>().time = 10f;
				}
				visiting.Remove(original);
				return val;
			}
		}

		internal static void Play(Vector3 position)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Invalid comparison between Unknown and I4
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.Impact.Value && !((Object)(object)template == (Object)null) && !((Object)(object)GamefeelHandler.instance == (Object)null) && GamefeelHandler.instance.setting != null && (int)((EnumSetting<OffOnMode>)(object)GamefeelHandler.instance.setting).Value != 1)
			{
				GameObject obj = Object.Instantiate<GameObject>(template, position, Quaternion.identity);
				obj.SetActive(true);
				Object.Destroy((Object)(object)obj, 10f);
			}
		}
	}
	public sealed class ShackleChain : MonoBehaviour
	{
		private bool impactPlayed;

		[PunRPC]
		public void ShackleImpactV1(Vector3 position, PhotonMessageInfo info)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			PhotonView component = ((Component)this).GetComponent<PhotonView>();
			if ((Object)(object)component == (Object)null || info.Sender != component.Owner || impactPlayed)
			{
				return;
			}
			impactPlayed = true;
			try
			{
				ImpactEffect.Play(position);
			}
			catch (Exception ex)
			{
				Plugin.ReportVisual("Cosmetic impact failed; chain remains usable. " + ex, warning: true);
			}
		}

		internal void SendImpact(Vector3 position)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			PhotonView component = ((Component)this).GetComponent<PhotonView>();
			if ((Object)(object)component != (Object)null && component.IsMine)
			{
				component.RPC("ShackleImpactV1", (RpcTarget)0, new object[1] { position });
			}
		}
	}
	internal static class Palette
	{
		internal static Color Hex(string value)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			Color result = default(Color);
			ColorUtility.TryParseHtmlString("#" + value, ref result);
			return result;
		}

		internal static void Paint(GameObject root, bool chain)
		{
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Expected O, but got Unknown
			//IL_011c: 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)
			OwnedMaterials ownedMaterials = root.AddComponent<OwnedMaterials>();
			Renderer[] componentsInChildren = root.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				Material[] sharedMaterials = val.sharedMaterials;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					if ((Object)(object)sharedMaterials[j] == (Object)null)
					{
						continue;
					}
					Material obj = sharedMaterials[j];
					string text = ((Object)obj).name.ToLowerInvariant();
					Color val2 = Hex((!chain) ? (text.Contains("grip") ? "72221c" : (text.Contains("metal") ? "ffffff" : (text.Contains("rope") ? "af004f" : "ff5d4b"))) : (text.Contains("vine") ? "c7e4f3" : (text.Contains("spike") ? "ffcd15" : "66023c")));
					Material val3 = new Material(obj);
					ownedMaterials.Materials.Add(val3);
					string[] array = new string[3] { "_Tint", "_BaseColor", "_Color" };
					foreach (string text2 in array)
					{
						if (val3.HasProperty(text2))
						{
							val2.a = val3.GetColor(text2).a;
							val3.SetColor(text2, val2);
							break;
						}
					}
					sharedMaterials[j] = val3;
				}
				val.sharedMaterials = sharedMaterials;
			}
		}
	}
	public sealed class OwnedMaterials : MonoBehaviour
	{
		[NonSerialized]
		internal readonly List<Material> Materials = new List<Material>();

		private void OnDestroy()
		{
			foreach (Material material in Materials)
			{
				if ((Object)(object)material != (Object)null)
				{
					Object.Destroy((Object)(object)material);
				}
			}
		}
	}
	internal static class Feedback
	{
		private static AudioClip? clip;

		internal static void Play()
		{
			//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_0145: Expected O, but got Unknown
			if (Plugin.Shake.Value && (Object)(object)GamefeelHandler.instance != (Object)null && GamefeelHandler.instance.setting != null)
			{
				GamefeelHandler.instance.AddPerlinShake(0.25f, 0.22f, 18f);
			}
			if (!Plugin.Sound.Value)
			{
				return;
			}
			if ((Object)(object)clip == (Object)null)
			{
				float[] array = new float[7350];
				for (int i = 0; i < array.Length; i++)
				{
					float num = (float)i / 22050f;
					float num2 = Mathf.Sin(MathF.PI * Mathf.Min(1f, num / 0.008f) / 2f) * Mathf.Exp((0f - num) * 16f);
					array[i] = 0.22f * num2 * (Mathf.Sin(MathF.PI * 660f * num) + 0.4f * Mathf.Sin(MathF.PI * 1580f * num));
				}
				clip = AudioClip.Create("ShackleActivation", array.Length, 1, 22050, false);
				clip.SetData(array, 0);
			}
			GameObject val = new GameObject("ShackleActivationAudio");
			AudioSource obj = val.AddComponent<AudioSource>();
			obj.spatialBlend = 0f;
			obj.playOnAwake = false;
			obj.clip = clip;
			obj.volume = 0.45f;
			obj.Play();
			Object.Destroy((Object)val, 1f);
		}
	}
	internal static class Patches
	{
		internal sealed class ShotContext
		{
			internal ShotContext? Parent;

			internal bool IsShackle;

			internal ShackleChain? Chain;

			internal Vector3 Impact;
		}

		[ThreadStatic]
		private static ShotContext? activeShot;

		private static readonly Func<Character, float, bool, bool, bool> Spend = (Func<Character, float, bool, bool, bool>)Delegate.CreateDelegate(typeof(Func<Character, float, bool, bool, bool>), AccessTools.Method(typeof(Character), "UseStamina", (Type[])null, (Type[])null));

		private static readonly FieldInfo CharacterField = AccessTools.Field(typeof(CharacterVineClimbing), "character");

		private static HarmonyMethod H(Type type, string name)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			return new HarmonyMethod(AccessTools.Method(type, name, (Type[])null, (Type[])null));
		}

		private static HarmonyMethod H(string name)
		{
			return H(typeof(Patches), name);
		}

		internal static void Install(Harmony h)
		{
			h.Patch((MethodBase)AccessTools.Method(typeof(VineShooter), "WillAttach", (Type[])null, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, H("Targeting"), (HarmonyMethod)null, (HarmonyMethod)null);
			h.Patch((MethodBase)AccessTools.Method(typeof(JungleVine), "ForceBuildVine_RPC", (Type[])null, (Type[])null), (HarmonyMethod)null, H("Built"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			h.Patch((MethodBase)AccessTools.Method(typeof(JungleVine), "GetPosition", (Type[])null, (Type[])null), H(typeof(ChainEndpoints), "PositionPrefix"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			h.Patch((MethodBase)AccessTools.Method(typeof(CharacterVineClimbing), "FixedUpdate", (Type[])null, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, H("Fixed"), (HarmonyMethod)null, (HarmonyMethod)null);
			h.Patch((MethodBase)AccessTools.Method(typeof(CharacterVineClimbing), "GrabVineRpc", (Type[])null, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, H(typeof(ChainEndpoints), "GrabTranspiler"), (HarmonyMethod)null, (HarmonyMethod)null);
			h.Patch((MethodBase)AccessTools.Method(typeof(CharacterVineClimbing), "Update", (Type[])null, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, H("Stamina"), (HarmonyMethod)null, (HarmonyMethod)null);
			h.Patch((MethodBase)AccessTools.Method(typeof(VineShooter), "OnPrimaryFinishedCast", (Type[])null, (Type[])null), H("BeforeShot"), H("AfterShot"), (HarmonyMethod)null, H("ShotFinally"), (HarmonyMethod)null);
		}

		internal static bool Own(Character c)
		{
			if ((Object)(object)c != (Object)null && c.data.isVineClimbing && (Object)(object)c.data.heldVine != (Object)null)
			{
				return (Object)(object)((Component)c.data.heldVine).GetComponent<ShackleChain>() != (Object)null;
			}
			return false;
		}

		private static float Angle(float original, VineShooter item)
		{
			if (!((Object)(object)((Component)item).GetComponent<ShackleItem>() != (Object)null) || !Plugin.Angles.Value)
			{
				return original;
			}
			if (!(original < 0f))
			{
				return 2f;
			}
			return -2f;
		}

		private static float Range(float original, VineShooter item)
		{
			if (!((Object)(object)((Component)item).GetComponent<ShackleItem>() != (Object)null))
			{
				return original;
			}
			return ConfigPolicy.Range(Plugin.Range.Value);
		}

		private static float Speed(float original, CharacterVineClimbing climbing)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			if (!Own((Character)CharacterField.GetValue(climbing)))
			{
				return original;
			}
			return original * ConfigPolicy.Speed(Plugin.Speed.Value);
		}

		private static bool StaminaCost(Character c, float amount, bool bonus, bool ignoreAscents)
		{
			if (!Own(c) || !Plugin.FreeStamina.Value)
			{
				return Spend(c, amount, bonus, ignoreAscents);
			}
			return true;
		}

		internal static IEnumerable<CodeInstruction> Targeting(IEnumerable<CodeInstruction> input)
		{
			return ScopedRewrite.Target(input, AccessTools.Method(typeof(Patches), "Range", (Type[])null, (Type[])null), AccessTools.Method(typeof(Patches), "Angle", (Type[])null, (Type[])null));
		}

		internal static IEnumerable<CodeInstruction> Fixed(IEnumerable<CodeInstruction> input)
		{
			return ScopedRewrite.Speed(ChainEndpoints.FixedTranspiler(input), AccessTools.Method(typeof(Patches), "Speed", (Type[])null, (Type[])null));
		}

		internal static IEnumerable<CodeInstruction> Stamina(IEnumerable<CodeInstruction> input)
		{
			return ScopedRewrite.Stamina(input, AccessTools.Method(typeof(Patches), "StaminaCost", (Type[])null, (Type[])null));
		}

		private static void Built(JungleVine __instance, Vector3 from, Vector3 to, Vector3 mid)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)((Component)__instance).GetComponent<ShackleChain>() == (Object)null)
			{
				return;
			}
			Plugin.Builds++;
			if (activeShot != null && activeShot.IsShackle && __instance.photonView.IsMine)
			{
				activeShot.Chain = ((Component)__instance).GetComponent<ShackleChain>();
				activeShot.Impact = to;
			}
			try
			{
				ChainPath chainPath = ChainEndpoints.Register(__instance);
				if (chainPath == null)
				{
					throw new InvalidOperationException("Expected 50 vanilla collider points.");
				}
				if (!SmoothChainVisual.TryBuild(__instance, from, mid, to) && !RepeatedChainVisual.TryBuild((Component)(object)__instance, chainPath))
				{
					Transform val = ((Component)__instance).transform.Find("Mesh");
					if ((Object)(object)val != (Object)null)
					{
						Vector3 localScale = val.localScale;
						val.localScale = new Vector3(1f, 1f, localScale.z);
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.ReportVisual("Chain visual failed; vanilla physics retained: " + ex, warning: true);
			}
		}

		private static void BeforeShot(VineShooter __instance, out ShotContext __state)
		{
			__state = new ShotContext
			{
				Parent = activeShot,
				IsShackle = ((Object)(object)((Component)__instance).GetComponent<ShackleItem>() != (Object)null)
			};
			activeShot = __state;
		}

		private static void AfterShot(ShotContext __state)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__state.Chain == (Object)null)
			{
				return;
			}
			try
			{
				Feedback.Play();
			}
			catch (Exception ex)
			{
				Plugin.ReportVisual("Shot feedback failed: " + ex, warning: true);
			}
			try
			{
				__state.Chain.SendImpact(__state.Impact);
			}
			catch (Exception ex2)
			{
				Plugin.ReportVisual("Impact notification failed: " + ex2, warning: true);
			}
		}

		private static Exception? ShotFinally(Exception? __exception, ShotContext? __state)
		{
			if (__state != null)
			{
				activeShot = __state.Parent;
			}
			return __exception;
		}
	}
	[BepInPlugin("RetroTsunami.ShackleCannon", "Shackle Cannon", "0.1.2")]
	[BepInDependency("com.github.PEAKModding.PEAKLib.Core", "1.7.2")]
	[BepInDependency("com.github.PEAKModding.PEAKLib.Items", "1.6.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Id = "RetroTsunami.ShackleCannon";

		internal static Plugin Instance;

		internal static ConfigEntry<float> Range;

		internal static ConfigEntry<float> Speed;

		internal static ConfigEntry<float> ActivationMultiplier;

		internal static ConfigEntry<bool> ChargeShake;

		internal static ConfigEntry<bool> ChargeSound;

		internal static ConfigEntry<bool> Impact;

		private ConfigEntry<KeyboardShortcut> testSpawnKey;

		private Item? registeredItem;

		internal static ConfigEntry<bool> Angles;

		internal static ConfigEntry<bool> FreeStamina;

		internal static ConfigEntry<bool> Shake;

		internal static ConfigEntry<bool> Sound;

		private Harmony? harmony;

		private bool registered;

		private GameObject? templates;

		internal static int Builds;

		private void Awake()
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Expected O, but got Unknown
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Expected O, but got Unknown
			//IL_01cf: 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_022e: Expected O, but got Unknown
			Instance = this;
			if (Chainloader.PluginInfos.ContainsKey("RetroTsunami.ExtendedChainLauncher"))
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"ExtendedChainLauncher is also installed. Its global patches may conflict with Shackle Cannon and change the ordinary launcher. Disable it for the supported configuration.");
			}
			Range = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MaxRange", 2000f, new ConfigDescription("Maximum targeting range in world units.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(100f, 10000f), Array.Empty<object>()));
			Angles = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "RemoveAngleLimit", true, "Allow all aiming angles; vanilla grounding and surface checks remain.");
			FreeStamina = ((BaseUnityPlugin)this).Config.Bind<bool>("Climbing", "InfiniteStaminaOnShackle", true, "Prevent ongoing stamina drain only on Shackle chains. Does not refill stamina; initial grab cost remains.");
			Speed = ((BaseUnityPlugin)this).Config.Bind<float>("Climbing", "ClimbSpeedMultiplier", 2f, new ConfigDescription("Shackle climbing speed. Set 1 for vanilla speed. Does not affect sliding.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 4f), Array.Empty<object>()));
			Shake = ((BaseUnityPlugin)this).Config.Bind<bool>("Feedback", "CameraShake", true, "Brief local shake after successful placement; respects game photosensitivity setting.");
			Sound = ((BaseUnityPlugin)this).Config.Bind<bool>("Feedback", "ActivationSound", true, "Short original local activation chime after successful placement.");
			ActivationMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ActivationTimeMultiplier", 2f, new ConfigDescription("Activation duration relative to vanilla. Restart after changes.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 5f), Array.Empty<object>()));
			ChargeShake = ((BaseUnityPlugin)this).Config.Bind<bool>("Feedback", "ChargeShake", true, "Ramping shake during activation. CameraShake is the master shake switch.");
			ChargeSound = ((BaseUnityPlugin)this).Config.Bind<bool>("Feedback", "ChargeSound", true, "Looping charge rumble during activation; stops on release or cancellation.");
			Impact = ((BaseUnityPlugin)this).Config.Bind<bool>("Feedback", "ImpactExplosion", true, "Cosmetic dynamite effect at the anchor. No damage, knockback or terrain effects; no replay for late joiners.");
			testSpawnKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Testing", "SpawnKey", KeyboardShortcut.Empty, "Optional host-only test spawn shortcut, e.g. F8. Unbound by default; restart after editing config.");
			try
			{
				Assembly assembly = typeof(VineShooter).Assembly;
				if (assembly.ManifestModule.ModuleVersionId != new Guid("e9a4fa24-a068-4abd-8c8d-66c4b2b65471"))
				{
					throw new NotSupportedException("Unsupported PEAK Assembly-CSharp build. No item or patches installed. Send the updated Managed assemblies.");
				}
				ChainEndpoints.Configure(assembly);
				harmony = new Harmony("RetroTsunami.ShackleCannon");
				Patches.Install(harmony);
				((MonoBehaviour)this).StartCoroutine(RegisterWhenReady());
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Shackle Cannon patches ready. All players require this mod and PEAKLib; match configuration across clients.");
			}
			catch (Exception ex)
			{
				Harmony? obj = harmony;
				if (obj != null)
				{
					obj.UnpatchSelf();
				}
				((BaseUnityPlugin)this).Logger.LogError((object)ex);
			}
		}

		private IEnumerator RegisterWhenReady()
		{
			FieldInfo ready = AccessTools.Field(typeof(ItemContent).Assembly.GetType("PEAKLib.Items.ItemRegistrar"), "ItemDatabaseLoaded");
			if (ready == null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"PEAKLib registration hook changed; item registration aborted.");
				yield break;
			}
			while (ready.GetValue(null) == null || LocalizedText.mainTable == null)
			{
				yield return null;
			}
			yield return null;
			try
			{
				Register((ItemDatabase)ready.GetValue(null));
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Shackle registration failed; restart after reporting this log. " + ex));
			}
		}

		private void Register(ItemDatabase db)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Expected O, but got Unknown
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: 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_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			if (registered)
			{
				return;
			}
			Item[] array = db.itemLookup.Values.Where((Item i) => (Object)(object)i != (Object)null && (Object)(object)((Component)i).GetComponent<VineShooter>() != (Object)null && (Object)(object)((Component)i).GetComponent<VineShooter>().vinePrefab != (Object)null && ((Component)i).GetComponent<VineShooter>().vinePrefab.GetComponentsInChildren<MeshFilter>(true).Any((MeshFilter f) => (Object)(object)f.sharedMesh != (Object)null && ((Object)f.sharedMesh).name == "Chain.001")).Distinct().ToArray();
			if (array.Length != 1)
			{
				throw new InvalidOperationException("Expected one vanilla chain launcher; found " + array.Length);
			}
			templates = new GameObject("ShackleCannon_InactiveTemplates");
			templates.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)templates);
			Item val = array[0];
			GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject, templates.transform);
			((Object)val2).name = "ShackleCannon";
			val2.AddComponent<ShackleItem>();
			val2.AddComponent<ChargeFeedback>();
			Item component = val2.GetComponent<Item>();
			ItemUIData val3 = new ItemUIData();
			FieldInfo[] fields = typeof(ItemUIData).GetFields(BindingFlags.Instance | BindingFlags.Public);
			foreach (FieldInfo fieldInfo in fields)
			{
				fieldInfo.SetValue(val3, fieldInfo.GetValue(val.UIData));
			}
			component.UIData = val3;
			val3.itemName = "Shackle Cannon";
			component.usingTimePrimary = FeedbackPolicy.ActivationSeconds(val.usingTimePrimary, ActivationMultiplier.Value);
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Activation duration: vanilla={val.usingTimePrimary:F2}s; Shackle={component.usingTimePrimary:F2}s.");
			component.itemTags = (ItemTags)(component.itemTags | 1);
			VineShooter component2 = val2.GetComponent<VineShooter>();
			component2.maxLength = ConfigPolicy.Range(Range.Value);
			GameObject val4 = Object.Instantiate<GameObject>(component2.vinePrefab, templates.transform);
			((Object)val4).name = "ShackleChain";
			val4.AddComponent<ShackleChain>();
			component2.vinePrefab = val4;
			Palette.Paint(val2, chain: false);
			Palette.Paint(val4, chain: true);
			LootData val5 = val2.GetComponent<LootData>() ?? val2.AddComponent<LootData>();
			val5.Rarity = (Rarity)5;
			val5.spawnLocations = (SpawnPool)163840;
			val5.rarityOverrides = new List<ItemRarityOverride>();
			val5.banInSolo = false;
			val5.excludeBasedOnCustomRunSetting = false;
			val5.excludeFromCustomRunSelection = false;
			val5.useOtherItemForSpawningValidity = null;
			using (MD5 mD = MD5.Create())
			{
				ushort key = BitConverter.ToUInt16(mD.ComputeHash(Encoding.UTF8.GetBytes("RetroTsunami.ShackleCannonRetroTsunami.ShackleCannon:" + ((Object)val2).name)), 0);
				if (db.itemLookup.ContainsKey(key))
				{
					throw new InvalidOperationException("Shackle item ID collision at " + key + ". Report installed mods; no network prefab was registered.");
				}
			}
			ModDefinition orCreate = ModDefinition.GetOrCreate(((BaseUnityPlugin)this).Info);
			NetworkPrefabManager.RegisterNetworkPrefab(orCreate, val4);
			new ItemContent(component).Register(orCreate);
			LootData.PopulateLootData();
			registeredItem = component;
			registered = true;
			try
			{
				ImpactEffect.Prepare(db, templates.transform);
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Impact effect unavailable; chain mechanics unaffected. " + ex));
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Registered Shackle Cannon ID={component.itemID}, prefab={((Object)component).name}; chain={((Object)val4).name}; pools={val5.spawnLocations}; vanilla source={((Object)val).name}. Test natural campfire rewards separately.");
		}

		private void Update()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			if (!registered || (Object)(object)registeredItem == (Object)null)
			{
				return;
			}
			KeyboardShortcut value = testSpawnKey.Value;
			if ((int)((KeyboardShortcut)(ref value)).MainKey == 0)
			{
				return;
			}
			value = testSpawnKey.Value;
			if (!((KeyboardShortcut)(ref value)).IsDown())
			{
				return;
			}
			Character localCharacter = Character.localCharacter;
			if (!PhotonNetwork.InRoom || !PhotonNetwork.IsMasterClient || (Object)(object)localCharacter == (Object)null || localCharacter.data.dead || localCharacter.data.fullyPassedOut)
			{
				return;
			}
			try
			{
				ItemDatabase.Add(registeredItem, localCharacter.Center + ((Component)localCharacter).transform.forward * 1.5f);
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Test spawn failed: " + ex));
			}
		}

		internal static void ReportVisual(string message, bool warning)
		{
			if (warning)
			{
				((BaseUnityPlugin)Instance).Logger.LogWarning((object)message);
			}
			else
			{
				((BaseUnityPlugin)Instance).Logger.LogInfo((object)message);
			}
		}
	}
	public sealed class ShackleItem : MonoBehaviour
	{
	}
	internal sealed class RepeatedChainVisual : MonoBehaviour
	{
		private GameObject? generated;

		private Material? ownedMaterial;

		private Renderer? original;

		private bool wasEnabled;

		internal static bool TryBuild(Component chain, ChainPath path)
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Expected O, but got Unknown
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Expected O, but got Unknown
			//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_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: 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_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: 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_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			if (path.Length <= 40f)
			{
				return false;
			}
			MeshFilter val = ((IEnumerable<MeshFilter>)chain.GetComponentsInChildren<MeshFilter>(true)).FirstOrDefault((Func<MeshFilter, bool>)((MeshFilter f) => (Object)(object)f.sharedMesh != (Object)null && ((Object)f.sharedMesh).name == "Chain.001"));
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			MeshRenderer component = ((Component)val).GetComponent<MeshRenderer>();
			if ((Object)(object)component == (Object)null || (Object)(object)((Renderer)component).sharedMaterial == (Object)null || ((Object)((Renderer)component).sharedMaterial.shader).name != "W/Vine")
			{
				return false;
			}
			float x = ((Component)val).transform.localScale.x;
			if (!Mathf.Approximately(x, 0.1706f))
			{
				return false;
			}
			RepeatedChainVisual repeatedChainVisual = chain.GetComponent<RepeatedChainVisual>() ?? chain.gameObject.AddComponent<RepeatedChainVisual>();
			repeatedChainVisual.Clear();
			try
			{
				int num = ChainPolicy.SectionCount(path.Length, 40f);
				if (num > 256)
				{
					throw new InvalidOperationException("Repeated mesh section cap exceeded.");
				}
				repeatedChainVisual.generated = new GameObject("ShackleCannon_RepeatedVisual");
				repeatedChainVisual.generated.transform.SetParent(chain.transform, false);
				repeatedChainVisual.ownedMaterial = new Material(((Renderer)component).sharedMaterial);
				repeatedChainVisual.ownedMaterial.SetFloat("_Hang", 0f);
				repeatedChainVisual.ownedMaterial.SetFloat("_LengthScale", 1f);
				for (int num2 = 0; num2 < num; num2++)
				{
					Vector3 val2 = Vector(path.At(path.Length * (float)num2 / (float)num));
					Vector3 val3 = Vector(path.At(path.Length * (float)(num2 + 1) / (float)num)) - val2;
					if (((Vector3)(ref val3)).sqrMagnitude < 0.0001f)
					{
						throw new InvalidOperationException("Degenerate mesh section.");
					}
					GameObject val4 = new GameObject("ChainSection_" + num2)
					{
						layer = ((Component)val).gameObject.layer
					};
					val4.transform.SetParent(repeatedChainVisual.generated.transform, false);
					val4.transform.position = val2;
					val4.transform.rotation = Quaternion.LookRotation(val3, (Mathf.Abs(Vector3.Dot(((Vector3)(ref val3)).normalized, Vector3.up)) > 0.99f) ? Vector3.right : Vector3.up);
					val4.transform.localScale = new Vector3(x, x, x * ((Vector3)(ref val3)).magnitude / 40f);
					val4.AddComponent<MeshFilter>().sharedMesh = val.sharedMesh;
					MeshRenderer obj = val4.AddComponent<MeshRenderer>();
					((Renderer)obj).sharedMaterial = repeatedChainVisual.ownedMaterial;
					((Renderer)obj).shadowCastingMode = ((Renderer)component).shadowCastingMode;
					((Renderer)obj).receiveShadows = ((Renderer)component).receiveShadows;
				}
				repeatedChainVisual.original = (Renderer?)(object)component;
				repeatedChainVisual.wasEnabled = ((Renderer)component).enabled;
				((Renderer)component).enabled = false;
				Plugin.ReportVisual($"Repeated chain visual built: {num} original mesh sections; path={path.Length:F1} units. Endpoint margin about 0.5 units.", warning: false);
				return true;
			}
			catch (Exception ex)
			{
				repeatedChainVisual.Clear();
				Plugin.ReportVisual("Repeated chain mesh failed; using thickness fallback: " + ex, warning: true);
				return false;
			}
		}

		private static Vector3 Vector(PathPoint p)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(p.X, p.Y, p.Z);
		}

		private void Clear()
		{
			if ((Object)(object)original != (Object)null)
			{
				original.enabled = wasEnabled;
			}
			original = null;
			if ((Object)(object)generated != (Object)null)
			{
				generated.SetActive(false);
				Object.Destroy((Object)(object)generated);
			}
			if ((Object)(object)ownedMaterial != (Object)null)
			{
				Object.Destroy((Object)(object)ownedMaterial);
			}
			generated = null;
			ownedMaterial = null;
		}

		private void OnDestroy()
		{
			Clear();
		}
	}
	internal static class ScopedRewrite
	{
		internal static List<CodeInstruction> Target(IEnumerable<CodeInstruction> input, MethodInfo range, MethodInfo angle)
		{
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Expected O, but got Unknown
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Expected O, but got Unknown
			List<CodeInstruction> list = input.Select((Func<CodeInstruction, CodeInstruction>)((CodeInstruction i) => new CodeInstruction(i))).ToList();
			if (!(from i in list
				where i.opcode == OpCodes.Ldc_R4
				select (float)i.operand).SequenceEqual(new float[3] { 0.6f, -0.7f, 0.5f }) || list.Count((CodeInstruction i) => Field(i, "VineShooter", "maxLength")) != 1)
			{
				throw new InvalidOperationException("Unexpected targeting IL; patch refused.");
			}
			List<CodeInstruction> list2 = new List<CodeInstruction>();
			foreach (CodeInstruction item in list)
			{
				list2.Add(item);
				if (Field(item, "VineShooter", "maxLength") || item.opcode == OpCodes.Ldc_R4)
				{
					list2.Add(new CodeInstruction(OpCodes.Ldarg_0, (object)null));
					list2.Add(new CodeInstruction(OpCodes.Call, (object)(Field(item, "VineShooter", "maxLength") ? range : angle)));
				}
			}
			return list2;
		}

		internal static List<CodeInstruction> Speed(IEnumerable<CodeInstruction> input, MethodInfo helper)
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			List<CodeInstruction> list = input.Select((Func<CodeInstruction, CodeInstruction>)((CodeInstruction i) => new CodeInstruction(i))).ToList();
			if (list.Count((CodeInstruction i) => Field(i, "CharacterVineClimbing", "climbSpeedMod")) != 1)
			{
				throw new InvalidOperationException("Unexpected speed IL; patch refused.");
			}
			int num = list.FindIndex((CodeInstruction i) => Field(i, "CharacterVineClimbing", "climbSpeedMod"));
			list.InsertRange(num + 1, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[2]
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Call, (object)helper)
			});
			return list;
		}

		internal static List<CodeInstruction> Stamina(IEnumerable<CodeInstruction> input, MethodInfo helper)
		{
			List<CodeInstruction> list = input.Select((Func<CodeInstruction, CodeInstruction>)((CodeInstruction i) => new CodeInstruction(i))).ToList();
			CodeInstruction[] array = list.Where((CodeInstruction i) => (i.opcode == OpCodes.Call || i.opcode == OpCodes.Callvirt) && i.operand is MethodInfo methodInfo2 && methodInfo2.DeclaringType?.FullName == "Character" && methodInfo2.Name == "UseStamina").ToArray();
			if (array.Length != 1)
			{
				throw new InvalidOperationException("Unexpected stamina IL; patch refused.");
			}
			MethodInfo methodInfo = (MethodInfo)array[0].operand;
			if (methodInfo.ReturnType != typeof(bool) || !(from p in methodInfo.GetParameters()
				select p.ParameterType).SequenceEqual(new Type[3]
			{
				typeof(float),
				typeof(bool),
				typeof(bool)
			}))
			{
				throw new InvalidOperationException("Unexpected stamina signature.");
			}
			array[0].opcode = OpCodes.Call;
			array[0].operand = helper;
			return list;
		}

		private static bool Field(CodeInstruction i, string type, string name)
		{
			if (i.opcode == OpCodes.Ldfld && i.operand is FieldInfo fieldInfo && fieldInfo.DeclaringType?.FullName == type && fieldInfo.Name == name)
			{
				return fieldInfo.FieldType == typeof(float);
			}
			return false;
		}
	}
	public sealed class SmoothChainVisual : MonoBehaviour
	{
		private sealed class Geometry
		{
			internal VertexAttributeDescriptor[] Attributes;

			internal byte[][] Streams;

			internal int[] Strides;

			internal int[] Triangles;

			internal int Count;

			internal int PositionStream;

			internal int PositionOffset;

			internal int NormalStream = -1;

			internal int NormalOffset;

			internal int TangentStream = -1;

			internal int TangentOffset;
		}

		private static readonly Dictionary<Mesh, Geometry?> Cache = new Dictionary<Mesh, Geometry>();

		private readonly List<Mesh> meshes = new List<Mesh>();

		private GameObject? generated;

		private Material? material;

		private Renderer? original;

		private bool originalEnabled;

		internal static bool TryBuild(JungleVine chain, Vector3 from, Vector3 mid, Vector3 to)
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Expected O, but got Unknown
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Expected O, but got Unknown
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: 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_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: 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_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: 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_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d8: Expected O, but got Unknown
			//IL_0332: 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_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_0386: Unknown result type (might be due to invalid IL or missing references)
			//IL_0393: Unknown result type (might be due to invalid IL or missing references)
			//IL_0398: Unknown result type (might be due to invalid IL or missing references)
			//IL_039d: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0501: Unknown result type (might be due to invalid IL or missing references)
			//IL_0521: Unknown result type (might be due to invalid IL or missing references)
			MeshFilter val = ((IEnumerable<MeshFilter>)((Component)chain).GetComponentsInChildren<MeshFilter>(true)).FirstOrDefault((Func<MeshFilter, bool>)((MeshFilter f) => (Object)(object)f.sharedMesh != (Object)null && ((Object)f.sharedMesh).name == "Chain.001"));
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			MeshRenderer component = ((Component)val).GetComponent<MeshRenderer>();
			if ((Object)(object)component == (Object)null || (Object)(object)((Renderer)component).sharedMaterial == (Object)null || ((Object)((Renderer)component).sharedMaterial.shader).name != "W/Vine")
			{
				return false;
			}
			if (!Mathf.Approximately(((Component)val).transform.localScale.x, 0.1706f))
			{
				return false;
			}
			if (!Cache.TryGetValue(val.sharedMesh, out Geometry value))
			{
				try
				{
					value = Read(val.sharedMesh);
				}
				catch (Exception ex)
				{
					value = null;
					Plugin.ReportVisual("GPU link readback unavailable; using straight section fallback. " + ex, warning: true);
				}
				Cache[val.sharedMesh] = value;
			}
			if (value == null)
			{
				return false;
			}
			SmoothChainVisual smoothChainVisual = ((Component)chain).GetComponent<SmoothChainVisual>() ?? ((Component)chain).gameObject.AddComponent<SmoothChainVisual>();
			smoothChainVisual.Clear();
			try
			{
				CurvePath curvePath = new CurvePath(P(from), P(mid), P(to));
				int num = (int)Math.Ceiling(curvePath.Length / 40f);
				if (num > 256)
				{
					throw new InvalidOperationException("Visual section cap exceeded.");
				}
				smoothChainVisual.generated = new GameObject("ShackleSmoothLinks");
				smoothChainVisual.generated.transform.SetParent(((Component)chain).transform, false);
				smoothChainVisual.material = new Material(((Renderer)component).sharedMaterial);
				smoothChainVisual.material.SetFloat("_Hang", 0f);
				smoothChainVisual.material.SetFloat("_LengthScale", 1f);
				Vector3 val2 = to - from;
				Vector3 val3 = ((Mathf.Abs(Vector3.Dot(((Vector3)(ref val2)).normalized, Vector3.up)) > 0.9f) ? Vector3.right : Vector3.up);
				for (int num2 = 0; num2 < num; num2++)
				{
					byte[][] array = value.Streams.Select((byte[] b) => (byte[])b.Clone()).ToArray();
					bool[] array2 = new bool[value.Count];
					for (int num3 = 0; num3 < value.Count; num3++)
					{
						int offset = num3 * value.Strides[value.PositionStream] + value.PositionOffset;
						Vector3 val4 = Read3(array[value.PositionStream], offset) * 0.1706f;
						float num4 = (float)(num2 * 40) + val4.z;
						array2[num3] = num4 <= curvePath.Length + 0.15f;
						Vector3 val5 = V(curvePath.At(num4));
						val2 = V(curvePath.Tangent(num4));
						Quaternion val6 = Quaternion.LookRotation(((Vector3)(ref val2)).normalized, val3);
						Vector3 val7 = val5 + val6 * new Vector3(val4.x, val4.y, 0f);
						Write3(array[value.PositionStream], offset, ((Component)chain).transform.InverseTransformPoint(val7));
						if (value.NormalStream >= 0)
						{
							int offset2 = num3 * value.Strides[value.NormalStream] + value.NormalOffset;
							Write3(array[value.NormalStream], offset2, ((Component)chain).transform.InverseTransformDirection(val6 * Read3(array[value.NormalStream], offset2)));
						}
						if (value.TangentStream >= 0)
						{
							int offset3 = num3 * value.Strides[value.TangentStream] + value.TangentOffset;
							Write3(array[value.TangentStream], offset3, ((Component)chain).transform.InverseTransformDirection(val6 * Read3(array[value.TangentStream], offset3)));
						}
					}
					Mesh val8 = new Mesh
					{
						name = "ShackleBentLinks_" + num2
					};
					smoothChainVisual.meshes.Add(val8);
					val8.SetVertexBufferParams(value.Count, value.Attributes);
					for (int num5 = 0; num5 < array.Length; num5++)
					{
						val8.SetVertexBufferData<byte>(array[num5], 0, 0, array[num5].Length, num5, (MeshUpdateFlags)0);
					}
					List<int> list = new List<int>();
					for (int num6 = 0; num6 < value.Triangles.Length; num6 += 3)
					{
						int num7 = value.Triangles[num6];
						int num8 = value.Triangles[num6 + 1];
						int num9 = value.Triangles[num6 + 2];
						if (array2[num7] && array2[num8] && array2[num9])
						{
							list.Add(num7);
							list.Add(num8);
							list.Add(num9);
						}
					}
					val8.triangles = list.ToArray();
					if (value.NormalStream < 0)
					{
						val8.RecalculateNormals();
					}
					val8.RecalculateBounds();
					val8.UploadMeshData(true);
					GameObject val9 = new GameObject("Links_" + num2)
					{
						layer = ((Component)val).gameObject.layer
					};
					val9.transform.SetParent(smoothChainVisual.generated.transform, false);
					val9.AddComponent<MeshFilter>().sharedMesh = val8;
					MeshRenderer obj = val9.AddComponent<MeshRenderer>();
					((Renderer)obj).sharedMaterial = smoothChainVisual.material;
					((Renderer)obj).shadowCastingMode = ((Renderer)component).shadowCastingMode;
					((Renderer)obj).receiveShadows = ((Renderer)component).receiveShadows;
				}
				smoothChainVisual.original = (Renderer?)(object)component;
				smoothChainVisual.originalEnabled = ((Renderer)component).enabled;
				((Renderer)component).enabled = false;
				Plugin.ReportVisual($"Smooth links built: {curvePath.Length:F1} units, {num} mesh batches, {value.Count * num} vertices. Vanilla collider path retained.", warning: false);
				return true;
			}
			catch (Exception ex2)
			{
				smoothChainVisual.Clear();
				Plugin.ReportVisual("Smooth renderer failed; using repeated sections. " + ex2, warning: true);
				return false;
			}
		}

		private static Geometry Read(Mesh mesh)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: 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_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: 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_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			if (mesh.subMeshCount != 1 || mesh.vertexCount != 5120)
			{
				throw new InvalidOperationException("Unexpected source link mesh.");
			}
			if ((int)mesh.GetVertexAttributeFormat((VertexAttribute)0) != 0 || mesh.GetVertexAttributeDimension((VertexAttribute)0) != 3)
			{
				throw new InvalidOperationException("Unexpected position encoding.");
			}
			Geometry geometry = new Geometry
			{
				Count = mesh.vertexCount,
				Attributes = mesh.GetVertexAttributes(),
				Streams = new byte[mesh.vertexBufferCount][],
				Strides = new int[mesh.vertexBufferCount],
				PositionStream = mesh.GetVertexAttributeStream((VertexAttribute)0),
				PositionOffset = mesh.GetVertexAttributeOffset((VertexAttribute)0)
			};
			for (int i = 0; i < geometry.Streams.Length; i++)
			{
				geometry.Strides[i] = mesh.GetVertexBufferStride(i);
				geometry.Streams[i] = new byte[geometry.Count * geometry.Strides[i]];
				GraphicsBuffer vertexBuffer = mesh.GetVertexBuffer(i);
				try
				{
					if (vertexBuffer == null)
					{
						throw new InvalidOperationException("Missing vertex buffer.");
					}
					vertexBuffer.GetData((Array)geometry.Streams[i]);
				}
				finally
				{
					((IDisposable)vertexBuffer)?.Dispose();
				}
			}
			float num = float.MaxValue;
			float num2 = float.MinValue;
			for (int j = 0; j < geometry.Count; j++)
			{
				Vector3 val = Read3(geometry.Streams[geometry.PositionStream], j * geometry.Strides[geometry.PositionStream] + geometry.PositionOffset);
				if (float.IsNaN(val.x + val.y + val.z) || float.IsInfinity(val.x + val.y + val.z))
				{
					throw new InvalidOperationException("Nonfinite source vertices.");
				}
				num = Math.Min(num, val.z);
				num2 = Math.Max(num2, val.z);
			}
			if (Math.Abs(num2 - num - 236.15198f) > 0.1f)
			{
				throw new InvalidOperationException("Readback bounds do not match supplied mesh report.");
			}
			if (mesh.HasVertexAttribute((VertexAttribute)1) && (int)mesh.GetVertexAttributeFormat((VertexAttribute)1) == 0)
			{
				geometry.NormalStream = mesh.GetVertexAttributeStream((VertexAttribute)1);
				geometry.NormalOffset = mesh.GetVertexAttributeOffset((VertexAttribute)1);
			}
			if (mesh.HasVertexAttribute((VertexAttribute)2) && (int)mesh.GetVertexAttributeFormat((VertexAttribute)2) == 0)
			{
				geometry.TangentStream = mesh.GetVertexAttributeStream((VertexAttribute)2);
				geometry.TangentOffset = mesh.GetVertexAttributeOffset((VertexAttribute)2);
			}
			SubMeshDescriptor subMesh = mesh.GetSubMesh(0);
			if ((int)((SubMeshDescriptor)(ref subMesh)).topology != 0)
			{
				throw new InvalidOperationException("Unexpected topology.");
			}
			GraphicsBuffer indexBuffer = mesh.GetIndexBuffer();
			try
			{
				if (indexBuffer == null)
				{
					throw new InvalidOperationException("Missing index buffer.");
				}
				int num3 = (((int)mesh.indexFormat == 0) ? 2 : 4);
				byte[] array = new byte[indexBuffer.count * indexBuffer.stride];
				indexBuffer.GetData((Array)array);
				geometry.Triangles = new int[((SubMeshDescriptor)(ref subMesh)).indexCount];
				for (int k = 0; k < geometry.Triangles.Length; k++)
				{
					int startIndex = (((SubMeshDescriptor)(ref subMesh)).indexStart + k) * num3;
					geometry.Triangles[k] = ((num3 == 2) ? BitConverter.ToUInt16(array, startIndex) : checked((int)BitConverter.ToUInt32(array, startIndex))) + ((SubMeshDescriptor)(ref subMesh)).baseVertex;
					if (geometry.Triangles[k] < 0 || geometry.Triangles[k] >= geometry.Count)
					{
						throw new InvalidOperationException("Invalid source index.");
					}
				}
				return geometry;
			}
			finally
			{
				((IDisposable)indexBuffer)?.Dispose();
			}
		}

		private static Vector3 Read3(byte[] b, int offset)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(BitConverter.ToSingle(b, offset), BitConverter.ToSingle(b, offset + 4), BitConverter.ToSingle(b, offset + 8));
		}

		private static void Write3(byte[] b, int offset, Vector3 p)
		{
			//IL_0002: 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_0020: Unknown result type (might be due to invalid IL or missing references)
			WriteFloat(b, offset, p.x);
			WriteFloat(b, offset + 4, p.y);
			WriteFloat(b, offset + 8, p.z);
		}

		private static void WriteFloat(byte[] b, int offset, float value)
		{
			uint num = (uint)BitConverter.SingleToInt32Bits(value);
			b[offset] = (byte)num;
			b[offset + 1] = (byte)(num >> 8);
			b[offset + 2] = (byte)(num >> 16);
			b[offset + 3] = (byte)(num >> 24);
		}

		private static PathPoint P(Vector3 p)
		{
			//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_000c: Unknown result type (might be due to invalid IL or missing references)
			return new PathPoint(p.x, p.y, p.z);
		}

		private static Vector3 V(PathPoint p)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(p.X, p.Y, p.Z);
		}

		private void Clear()
		{
			if ((Object)(object)original != (Object)null)
			{
				original.enabled = originalEnabled;
			}
			original = null;
			if ((Object)(object)generated != (Object)null)
			{
				generated.SetActive(false);
				Object.Destroy((Object)(object)generated);
			}
			generated = null;
			foreach (Mesh mesh in meshes)
			{
				if ((Object)(object)mesh != (Object)null)
				{
					Object.Destroy((Object)(object)mesh);
				}
			}
			meshes.Clear();
			if ((Object)(object)material != (Object)null)
			{
				Object.Destroy((Object)(object)material);
			}
			material = null;
		}

		private void OnDestroy()
		{
			Clear();
		}
	}
}