Decompiled source of PongonsAwfulBindings v1.2.0

PongonsAwfulBindings.dll

Decompiled 20 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using TrinketAndBindingFramework;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[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("PongonsAwfulBindings")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.11.0.0")]
[assembly: AssemblyInformationalVersion("1.11.0")]
[assembly: AssemblyProduct("PongonsAwfulBindings")]
[assembly: AssemblyTitle("PongonsAwfulBindings")]
[assembly: AssemblyVersion("1.11.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace PongonsAwfulBindings
{
	internal sealed class AmmoCrate : MonoBehaviour, Clickable
	{
		private static GameObject _template;

		private static Sprite _blankSprite;

		private bool _used;

		private bool _canInteract = true;

		private ObjectTagger _tagger;

		internal static GameObject Template
		{
			get
			{
				if ((Object)(object)_template == (Object)null)
				{
					_template = BuildTemplate();
				}
				return _template;
			}
		}

		private static GameObject BuildTemplate()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_0098: 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_00a1: 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_00b1: 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)
			try
			{
				GameObject val = new GameObject("PistolPackTemplates");
				val.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)val);
				GameObject val2 = new GameObject("AmmoCrate");
				val2.transform.SetParent(val.transform, false);
				GameObject ammo = PistolPackItems.Ammo;
				if ((Object)(object)ammo != (Object)null)
				{
					val2.layer = ammo.layer;
				}
				if (!BakedModel.TryLoad("ammocrate.bin", out var mesh, out var materials))
				{
					CrateMesh.Build(out mesh, out materials);
				}
				val2.AddComponent<MeshFilter>().sharedMesh = mesh;
				MeshRenderer obj = val2.AddComponent<MeshRenderer>();
				((Renderer)obj).sharedMaterials = materials;
				((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
				((Renderer)obj).receiveShadows = false;
				BoxCollider obj2 = val2.AddComponent<BoxCollider>();
				Bounds bounds = mesh.bounds;
				obj2.center = ((Bounds)(ref bounds)).center;
				bounds = mesh.bounds;
				obj2.size = ((Bounds)(ref bounds)).size;
				val2.AddComponent<Rigidbody>().mass = 4f;
				ObjectTagger val3 = val2.AddComponent<ObjectTagger>();
				if (val3.tags == null)
				{
					val3.tags = new List<string>();
				}
				val3.tags.Add("Button");
				val2.AddComponent<AmmoCrate>();
				AwfulBindingsPlugin.Log.LogInfo((object)"Pistol Pack: ammo crate template built");
				return val2;
			}
			catch (Exception ex)
			{
				AwfulBindingsPlugin.Log.LogError((object)("Pistol Pack: could not build the ammo crate: " + ex));
				return null;
			}
		}

		private void Awake()
		{
			_tagger = ((Component)this).GetComponent<ObjectTagger>();
		}

		public void Interact(InteractionInfo info)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			if (_used)
			{
				return;
			}
			_used = true;
			GameObject ammo = PistolPackItems.Ammo;
			if ((Object)(object)ammo != (Object)null)
			{
				int num = Mathf.Max(1, PistolPackConfig.CrateMinAmmo.Value);
				int num2 = Mathf.Max(num, PistolPackConfig.CrateMaxAmmo.Value);
				int num3 = Random.Range(num, num2 + 1);
				for (int i = 0; i < num3; i++)
				{
					Vector3 val = ((Component)this).transform.position + Vector3.up * 0.3f + Random.insideUnitSphere * 0.15f;
					Rigidbody component = Object.Instantiate<GameObject>(ammo, val, Random.rotation).GetComponent<Rigidbody>();
					if ((Object)(object)component != (Object)null)
					{
						component.AddForce(Random.insideUnitSphere * 1.5f + Vector3.up * 1.5f, (ForceMode)2);
					}
				}
			}
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}

		public void StartInteract(ENT_Player p, string s)
		{
		}

		public void StopInteract(ENT_Player p, string s)
		{
		}

		public void StopInteract(ENT_Player p, Hand hand, string s)
		{
		}

		public void SetInteractable(bool b)
		{
			_canInteract = b;
		}

		public bool CanInteract(InteractionInfo info)
		{
			if (_canInteract)
			{
				return !_used;
			}
			return false;
		}

		public ObjectTagger GetTagger()
		{
			if (!((Object)(object)_tagger != (Object)null))
			{
				return ((Component)this).GetComponent<ObjectTagger>();
			}
			return _tagger;
		}

		public GameObject GetGameObject()
		{
			return ((Component)this).gameObject;
		}

		public Sprite GetSprite()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_006f: Expected O, but got Unknown
			//IL_007a: 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)
			if ((Object)(object)_blankSprite == (Object)null)
			{
				Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false);
				val.SetPixel(0, 0, new Color(0f, 0f, 0f, 0f));
				val.Apply();
				_blankSprite = Sprite.Create(val, new Rect(0f, 0f, 1f, 1f), new Vector2(0.5f, 0.5f), 100f);
				Sprite blankSprite = _blankSprite;
				((Object)blankSprite).hideFlags = (HideFlags)(((Object)blankSprite).hideFlags | 0x20);
			}
			return _blankSprite;
		}
	}
	internal static class CrateMesh
	{
		private static readonly Color Olive = new Color(0.26f, 0.31f, 0.17f);

		private static readonly Color DarkOlive = new Color(0.17f, 0.2f, 0.11f);

		private static readonly Color Strap = new Color(0.11f, 0.12f, 0.08f);

		private static readonly Color Stencil = new Color(0.85f, 0.72f, 0.2f);

		internal static void Build(out Mesh mesh, out Material[] materials)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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_007a: 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_00ab: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: 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_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Expected O, but got Unknown
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			List<Vector3> list2 = new List<Vector3>();
			List<Color32> list3 = new List<Color32>();
			List<int> list4 = new List<int>();
			AddBox(list, list2, list3, list4, new Vector3(0f, 0.13f, 0f), new Vector3(0.46f, 0.26f, 0.3f), Olive);
			AddBox(list, list2, list3, list4, new Vector3(0f, 0.262f, 0f), new Vector3(0.48f, 0.03f, 0.32f), DarkOlive);
			AddBox(list, list2, list3, list4, new Vector3(-0.13f, 0.13f, 0f), new Vector3(0.04f, 0.27f, 0.31f), Strap);
			AddBox(list, list2, list3, list4, new Vector3(0.13f, 0.13f, 0f), new Vector3(0.04f, 0.27f, 0.31f), Strap);
			AddBox(list, list2, list3, list4, new Vector3(0f, 0.13f, 0.152f), new Vector3(0.14f, 0.07f, 0.006f), Stencil);
			AddBox(list, list2, list3, list4, new Vector3(0f, 0.13f, -0.152f), new Vector3(0.14f, 0.07f, 0.006f), Stencil);
			mesh = new Mesh
			{
				name = "AmmoCrate"
			};
			mesh.SetVertices(list);
			mesh.SetNormals(list2);
			mesh.SetColors(list3);
			mesh.SetTriangles(list4, 0);
			mesh.RecalculateBounds();
			Mesh obj = mesh;
			((Object)obj).hideFlags = (HideFlags)(((Object)obj).hideFlags | 0x20);
			Material val = BakedModel.MakeMaterial(Olive, cullOff: false);
			materials = (Material[])(object)new Material[1] { val };
		}

		private static void AddBox(List<Vector3> v, List<Vector3> n, List<Color32> c, List<int> t, Vector3 center, Vector3 size, Color color)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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_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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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_004b: 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_0057: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: 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)
			//IL_00b8: 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_00c4: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: 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_0139: 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_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_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: 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_016d: 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_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: 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_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: 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_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: 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_01d3: 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_01e3: 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_01ea: 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_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: 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_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: 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_0231: 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_023f: 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_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: 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)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: 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_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = size * 0.5f;
			AddFace(v, n, c, t, color, center, Vector3.right, new Vector3(val.x, 0f - val.y, 0f - val.z), new Vector3(val.x, val.y, 0f - val.z), new Vector3(val.x, val.y, val.z), new Vector3(val.x, 0f - val.y, val.z));
			AddFace(v, n, c, t, color, center, Vector3.left, new Vector3(0f - val.x, 0f - val.y, val.z), new Vector3(0f - val.x, val.y, val.z), new Vector3(0f - val.x, val.y, 0f - val.z), new Vector3(0f - val.x, 0f - val.y, 0f - val.z));
			AddFace(v, n, c, t, color, center, Vector3.up, new Vector3(0f - val.x, val.y, 0f - val.z), new Vector3(0f - val.x, val.y, val.z), new Vector3(val.x, val.y, val.z), new Vector3(val.x, val.y, 0f - val.z));
			AddFace(v, n, c, t, color, center, Vector3.down, new Vector3(0f - val.x, 0f - val.y, val.z), new Vector3(0f - val.x, 0f - val.y, 0f - val.z), new Vector3(val.x, 0f - val.y, 0f - val.z), new Vector3(val.x, 0f - val.y, val.z));
			AddFace(v, n, c, t, color, center, Vector3.forward, new Vector3(val.x, 0f - val.y, val.z), new Vector3(val.x, val.y, val.z), new Vector3(0f - val.x, val.y, val.z), new Vector3(0f - val.x, 0f - val.y, val.z));
			AddFace(v, n, c, t, color, center, Vector3.back, new Vector3(0f - val.x, 0f - val.y, 0f - val.z), new Vector3(0f - val.x, val.y, 0f - val.z), new Vector3(val.x, val.y, 0f - val.z), new Vector3(val.x, 0f - val.y, 0f - val.z));
		}

		private static void AddFace(List<Vector3> v, List<Vector3> n, List<Color32> c, List<int> t, Color color, Vector3 center, Vector3 normal, Vector3 a, Vector3 b, Vector3 cc, Vector3 d)
		{
			//IL_0008: 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_000c: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_0052: Unknown result type (might be due to invalid IL or missing references)
			int count = v.Count;
			v.Add(center + a);
			v.Add(center + b);
			v.Add(center + cc);
			v.Add(center + d);
			for (int i = 0; i < 4; i++)
			{
				n.Add(normal);
				c.Add(Color32.op_Implicit(color));
			}
			t.Add(count);
			t.Add(count + 1);
			t.Add(count + 2);
			t.Add(count);
			t.Add(count + 2);
			t.Add(count + 3);
		}
	}
	internal static class AngryConfig
	{
		internal static ConfigEntry<float> RedRoachChance;

		internal static ConfigEntry<int> ExtraCopies;

		internal static ConfigEntry<string> RoachNames;

		internal static ConfigEntry<string> RedNames;

		internal static ConfigEntry<string> NeverSwap;

		internal static ConfigEntry<string> ExcludedDenizens;

		internal static ConfigEntry<bool> LogDecisions;

		internal static void Init(ConfigFile c)
		{
			RedRoachChance = c.Bind<float>("Angry", "RedRoachChance", 0.5f, "Chance (0 to 1) that a normal or gold roach spawn is replaced by a red roach.");
			ExtraCopies = c.Bind<int>("Angry", "ExtraCopies", 1, "Extra copies of every denizen that spawns. 1 = spawns are doubled, 2 = tripled. Capped at 5.");
			RoachNames = c.Bind<string>("Angry", "RoachNames", "roach", "Comma-separated, case-insensitive. Only prefabs whose name contains one of these are treated as roaches.");
			RedNames = c.Bind<string>("Angry", "RedNames", "red", "Comma-separated, case-insensitive. A roach prefab whose name contains one of these is a red roach.");
			NeverSwap = c.Bind<string>("Angry", "NeverSwap", "red,plat,ruby,giant", "Comma-separated, case-insensitive. Roaches whose name contains any of these are never replaced by a red roach (so only the normal and gold roaches are). The giant roach is its own enemy, not a roach pickup.");
			ExcludedDenizens = c.Bind<string>("Angry", "ExcludedDenizens", "door,trap,deathwall,manager,ratking,mother", "Comma-separated, case-insensitive. Denizens whose prefab or class name contains any of these are not duplicated (doors, traps, bosses and other things that shouldn't have a twin).");
			LogDecisions = c.Bind<bool>("Angry", "LogDecisions", true, "Log each distinct roach swap and each denizen that gets duplicated (once per name) to BepInEx's log, so you can see the game's real names and adjust the lists above.");
		}
	}
	internal sealed class AngryController : MonoBehaviour
	{
		internal const string PerkId = "brokenshoes_angry";

		internal static bool Active;

		private void Update()
		{
			ENT_Player val = null;
			try
			{
				val = ENT_Player.GetPlayer();
			}
			catch
			{
			}
			bool flag = (Object)(object)val != (Object)null && !((GameEntity)val).dead && HasPerk(val);
			if (flag != Active)
			{
				Active = flag;
				AwfulBindingsPlugin.Log.LogInfo((object)("Angry " + (flag ? "active" : "inactive")));
			}
		}

		private static bool HasPerk(ENT_Player p)
		{
			IEnumerable perks = p.perks;
			if (perks == null)
			{
				return false;
			}
			foreach (object item in perks)
			{
				Perk val = (Perk)((item is Perk) ? item : null);
				if ((Object)(object)val != (Object)null && val.id == "brokenshoes_angry")
				{
					return true;
				}
			}
			return false;
		}
	}
	internal static class AngryNames
	{
		private static readonly HashSet<string> Logged = new HashSet<string>();

		private static string _roachSrc;

		private static string _redSrc;

		private static string _neverSrc;

		private static string _exclSrc;

		private static string[] _roach;

		private static string[] _red;

		private static string[] _never;

		private static string[] _excl;

		internal static string[] Roach => Cached(ref _roachSrc, ref _roach, AngryConfig.RoachNames.Value);

		internal static string[] Red => Cached(ref _redSrc, ref _red, AngryConfig.RedNames.Value);

		internal static string[] Never => Cached(ref _neverSrc, ref _never, AngryConfig.NeverSwap.Value);

		internal static string[] Excluded => Cached(ref _exclSrc, ref _excl, AngryConfig.ExcludedDenizens.Value);

		private static string[] Split(string s)
		{
			List<string> list = new List<string>();
			if (!string.IsNullOrEmpty(s))
			{
				string[] array = s.ToLowerInvariant().Split(',');
				for (int i = 0; i < array.Length; i++)
				{
					string text = array[i].Trim();
					if (text.Length > 0)
					{
						list.Add(text);
					}
				}
			}
			return list.ToArray();
		}

		private static string[] Cached(ref string src, ref string[] cache, string current)
		{
			if (cache == null || src != current)
			{
				src = current;
				cache = Split(current);
			}
			return cache;
		}

		internal static bool ContainsAny(string haystack, string[] needles)
		{
			foreach (string value in needles)
			{
				if (haystack.Contains(value))
				{
					return true;
				}
			}
			return false;
		}

		internal static void Note(string kind, string text)
		{
			if (AngryConfig.LogDecisions.Value)
			{
				string item = kind + "|" + text;
				if (Logged.Count <= 300 && Logged.Add(item))
				{
					AwfulBindingsPlugin.Log.LogInfo((object)("Angry " + kind + ": " + text));
				}
			}
		}
	}
	internal static class AngryRoaches
	{
		private static GameObject _red;

		private static float _nextSearch;

		internal static bool IsRed(GameObject go)
		{
			if ((Object)(object)go == (Object)null)
			{
				return false;
			}
			string haystack = ((Object)go).name.ToLowerInvariant();
			if (AngryNames.ContainsAny(haystack, AngryNames.Roach))
			{
				return AngryNames.ContainsAny(haystack, AngryNames.Red);
			}
			return false;
		}

		internal static bool Replaceable(GameObject go)
		{
			if ((Object)(object)go == (Object)null)
			{
				return false;
			}
			string haystack = ((Object)go).name.ToLowerInvariant();
			if (AngryNames.ContainsAny(haystack, AngryNames.Roach))
			{
				return !AngryNames.ContainsAny(haystack, AngryNames.Never);
			}
			return false;
		}

		internal static GameObject FindRed(SpawnTableAsset entry)
		{
			if (entry != null && entry.prefabs != null)
			{
				List<GameObject> list = new List<GameObject>();
				foreach (GameObject prefab in entry.prefabs)
				{
					if (IsRed(prefab))
					{
						list.Add(prefab);
					}
				}
				if (list.Count > 0)
				{
					return list[Random.Range(0, list.Count)];
				}
			}
			return GlobalRed();
		}

		private static GameObject GlobalRed()
		{
			if ((Object)(object)_red != (Object)null)
			{
				return _red;
			}
			if (Time.unscaledTime < _nextSearch)
			{
				return null;
			}
			_nextSearch = Time.unscaledTime + 5f;
			try
			{
				WKAssetDatabase fullCombinedAssetDatabase = CL_AssetManager.GetFullCombinedAssetDatabase();
				if ((Object)(object)fullCombinedAssetDatabase != (Object)null)
				{
					_red = Search(fullCombinedAssetDatabase.denizenPrefabs) ?? Search(fullCombinedAssetDatabase.entityPrefabs);
					if ((Object)(object)_red != (Object)null)
					{
						AwfulBindingsPlugin.Log.LogInfo((object)("Angry: red roach prefab = '" + ((Object)_red).name + "'"));
					}
					else
					{
						AngryNames.Note("warning", "no red roach prefab found in the game's databases (check [Angry] RoachNames / RedNames)");
					}
				}
			}
			catch (Exception ex)
			{
				AwfulBindingsPlugin.Log.LogWarning((object)("Angry: red roach search failed: " + ex.Message));
			}
			return _red;
		}

		private static GameObject Search(List<GameObject> list)
		{
			if (list == null)
			{
				return null;
			}
			foreach (GameObject item in list)
			{
				if (IsRed(item))
				{
					return item;
				}
			}
			return null;
		}
	}
	internal static class AngryDoubler
	{
		private struct Spawned
		{
			internal Denizen Denizen;

			internal Vector3 Scale;
		}

		private static int _depth;

		private static bool _cloning;

		private static readonly List<Spawned> Pending = new List<Spawned>();

		internal static void Enter()
		{
			_depth++;
		}

		internal static void Exit()
		{
			if (_depth > 0)
			{
				_depth--;
			}
			if (_depth > 0 || Pending.Count == 0)
			{
				return;
			}
			List<Spawned> list = new List<Spawned>(Pending);
			Pending.Clear();
			if (!AngryController.Active)
			{
				return;
			}
			_cloning = true;
			try
			{
				foreach (Spawned item in list)
				{
					Duplicate(item);
				}
			}
			catch (Exception ex)
			{
				AwfulBindingsPlugin.Log.LogWarning((object)("Angry: duplicating denizens failed: " + ex.Message));
			}
			finally
			{
				_cloning = false;
			}
		}

		internal static void Collect(Denizen d)
		{
			//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)
			if (!_cloning && _depth > 0 && !((Object)(object)d == (Object)null) && AngryController.Active && !AngryNames.ContainsAny((((Object)((Component)d).gameObject).name + "|" + ((object)d).GetType().Name).ToLowerInvariant(), AngryNames.Excluded))
			{
				Pending.Add(new Spawned
				{
					Denizen = d,
					Scale = ((Component)d).transform.localScale
				});
			}
		}

		private static void Duplicate(Spawned s)
		{
			//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_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_00b5: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			Denizen denizen = s.Denizen;
			if ((Object)(object)denizen == (Object)null || !((Component)denizen).gameObject.activeInHierarchy)
			{
				return;
			}
			int num = Mathf.Clamp(AngryConfig.ExtraCopies.Value, 0, 5);
			if (num != 0)
			{
				Transform transform = ((Component)denizen).transform;
				float num2 = 0.5f;
				Collider componentInChildren = ((Component)denizen).GetComponentInChildren<Collider>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					Bounds bounds = componentInChildren.bounds;
					Vector3 extents = ((Bounds)(ref bounds)).extents;
					num2 = Mathf.Clamp(((Vector3)(ref extents)).magnitude, 0.3f, 3f);
				}
				for (int i = 0; i < num; i++)
				{
					float num3 = (num2 * 2f + 0.2f) * (float)(1 + i / 2) * ((i % 2 == 0) ? 1f : (-1f));
					GameObject obj = Object.Instantiate<GameObject>(((Component)denizen).gameObject, transform.position + transform.right * num3, transform.rotation, transform.parent);
					((Object)obj).name = ((Object)((Component)denizen).gameObject).name;
					obj.transform.localScale = s.Scale;
				}
				AngryNames.Note("doubles", ((Object)((Component)denizen).gameObject).name + " (" + ((object)denizen).GetType().Name + ")");
			}
		}
	}
	[HarmonyPatch(typeof(SpawnTableAsset), "GetRandomPrefab")]
	internal static class AngryRoachPatch
	{
		private static void Postfix(SpawnTableAsset __instance, ref GameObject __result)
		{
			if (AngryController.Active && !((Object)(object)__result == (Object)null) && AngryRoaches.Replaceable(__result) && !(Random.value >= Mathf.Clamp01(AngryConfig.RedRoachChance.Value)))
			{
				GameObject val = AngryRoaches.FindRed(__instance);
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val == (Object)(object)__result))
				{
					AngryNames.Note("swaps", ((Object)__result).name + " -> " + ((Object)val).name);
					__result = val;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Denizen), "OnEnable")]
	internal static class AngryDenizenEnablePatch
	{
		private static void Postfix(Denizen __instance)
		{
			AngryDoubler.Collect(__instance);
		}
	}
	[HarmonyPatch(typeof(UT_SPT_Spawner), "Spawn", new Type[] { typeof(string) })]
	internal static class AngrySptSpawnerPatch
	{
		private static void Prefix()
		{
			AngryDoubler.Enter();
		}

		private static Exception Finalizer(Exception __exception)
		{
			AngryDoubler.Exit();
			return __exception;
		}
	}
	[HarmonyPatch(typeof(UT_RadiusSpawner), "Spawn")]
	internal static class AngryRadiusSpawnerPatch
	{
		private static void Prefix()
		{
			AngryDoubler.Enter();
		}

		private static Exception Finalizer(Exception __exception)
		{
			AngryDoubler.Exit();
			return __exception;
		}
	}
	[HarmonyPatch(typeof(UT_TriggerSpawner), "Spawn")]
	internal static class AngryTriggerSpawnerPatch
	{
		private static void Prefix()
		{
			AngryDoubler.Enter();
		}

		private static Exception Finalizer(Exception __exception)
		{
			AngryDoubler.Exit();
			return __exception;
		}
	}
	[HarmonyPatch(typeof(UT_MeshFaceSpawner), "Spawn")]
	internal static class AngryMeshFaceSpawnerPatch
	{
		private static void Prefix()
		{
			AngryDoubler.Enter();
		}

		private static Exception Finalizer(Exception __exception)
		{
			AngryDoubler.Exit();
			return __exception;
		}
	}
	[HarmonyPatch(typeof(ENV_DenizenWaveZone), "SpawnDenizens")]
	internal static class AngryWaveZonePatch
	{
		private static void Prefix()
		{
			AngryDoubler.Enter();
		}

		private static Exception Finalizer(Exception __exception)
		{
			AngryDoubler.Exit();
			return __exception;
		}
	}
	internal static class BakedModel
	{
		internal static bool TryLoad(string resourceName, out Mesh mesh, out Material[] materials)
		{
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Expected O, but got Unknown
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: 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_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: 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_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: 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_01a1: 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_01bd: Unknown result type (might be due to invalid IL or missing references)
			mesh = null;
			materials = null;
			try
			{
				using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
				if (stream == null)
				{
					return false;
				}
				using BinaryReader binaryReader = new BinaryReader(stream);
				string text = new string(binaryReader.ReadChars(4));
				if (text != "DOP1" && text != "DOP4")
				{
					return false;
				}
				bool flag = text == "DOP4";
				int num = binaryReader.ReadInt32();
				List<Vector3> list = new List<Vector3>();
				List<Vector3> list2 = new List<Vector3>();
				List<Vector2> list3 = new List<Vector2>();
				List<Color32> list4 = new List<Color32>();
				List<int[]> list5 = new List<int[]>();
				List<Material> list6 = new List<Material>();
				for (int i = 0; i < num; i++)
				{
					int num2 = binaryReader.ReadInt32();
					int num3 = binaryReader.ReadInt32();
					Color val = new Color(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
					bool cullOff = binaryReader.ReadInt32() != 0;
					string text2 = null;
					if (flag)
					{
						int num4 = binaryReader.ReadInt32();
						if (num4 > 0)
						{
							text2 = new string(binaryReader.ReadChars(num4));
						}
					}
					Texture2D val2 = ((text2 != null) ? LoadTexture(text2) : null);
					Material val3 = (((Object)(object)val2 != (Object)null) ? MakeTexturedMaterial(val2, cullOff) : null);
					Color val4 = val;
					if ((Object)(object)val2 != (Object)null)
					{
						val4 = ((!((Object)(object)val3 != (Object)null)) ? AverageColor(val2) : Color.white);
					}
					if ((Object)(object)val3 == (Object)null)
					{
						val3 = MakeMaterial(val4, cullOff);
					}
					int count = list.Count;
					Color32 item = Color32.op_Implicit(val4);
					for (int j = 0; j < num2; j++)
					{
						list.Add(new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle()));
						list2.Add(new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle()));
						if (flag)
						{
							list3.Add(new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle()));
						}
						list4.Add(item);
					}
					int[] array = new int[num3];
					for (int k = 0; k < num3; k++)
					{
						array[k] = count + binaryReader.ReadUInt16();
					}
					list5.Add(array);
					list6.Add(val3);
				}
				Mesh val5 = new Mesh
				{
					name = resourceName
				};
				val5.indexFormat = (IndexFormat)1;
				val5.SetVertices(list);
				val5.SetNormals(list2);
				if (flag)
				{
					val5.SetUVs(0, list3);
				}
				val5.SetColors(list4);
				val5.subMeshCount = list5.Count;
				for (int l = 0; l < list5.Count; l++)
				{
					val5.SetTriangles(list5[l], l);
				}
				val5.RecalculateBounds();
				((Object)val5).hideFlags = (HideFlags)(((Object)val5).hideFlags | 0x20);
				mesh = val5;
				materials = list6.ToArray();
				return true;
			}
			catch (Exception ex)
			{
				AwfulBindingsPlugin.Log.LogError((object)("Could not load baked model " + resourceName + ": " + ex.Message));
				return false;
			}
		}

		private static Texture2D LoadTexture(string resourceName)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
				if (stream == null)
				{
					return null;
				}
				byte[] array;
				using (MemoryStream memoryStream = new MemoryStream())
				{
					stream.CopyTo(memoryStream);
					array = memoryStream.ToArray();
				}
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
				if (!ImageConversion.LoadImage(val, array))
				{
					return null;
				}
				((Texture)val).filterMode = (FilterMode)0;
				((Texture)val).wrapMode = (TextureWrapMode)0;
				((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 0x20);
				return val;
			}
			catch
			{
				return null;
			}
		}

		private static Color AverageColor(Texture2D tex)
		{
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			try
			{
				Color32[] pixels = tex.GetPixels32();
				long num = 0L;
				long num2 = 0L;
				long num3 = 0L;
				Color32[] array = pixels;
				foreach (Color32 val in array)
				{
					num += val.r;
					num2 += val.g;
					num3 += val.b;
				}
				int num4 = Math.Max(1, pixels.Length);
				return new Color((float)num / (255f * (float)num4), (float)num2 / (255f * (float)num4), (float)num3 / (255f * (float)num4), 1f);
			}
			catch
			{
				return Color.gray;
			}
		}

		private static Material MakeTexturedMaterial(Texture2D tex, bool cullOff)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			//IL_0059: 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)
			Shader val = Shader.Find("Unlit/Texture");
			if ((Object)(object)val == (Object)null)
			{
				val = Shader.Find("Mobile/Unlit (Supports Lightmap)");
			}
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			Material val2 = new Material(val);
			val2.mainTexture = (Texture)(object)tex;
			if (val2.HasProperty("_Cull"))
			{
				val2.SetInt("_Cull", (!cullOff) ? 2 : 0);
			}
			((Object)val2).hideFlags = (HideFlags)(((Object)val2).hideFlags | 0x20);
			return val2;
		}

		internal static Material MakeMaterial(Color color, bool cullOff)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_007a: 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_00f0: 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)
			bool flag = true;
			Shader val = Shader.Find("Hidden/Internal-Colored");
			if ((Object)(object)val == (Object)null)
			{
				val = Shader.Find("Unlit/Color");
				flag = false;
			}
			if ((Object)(object)val == (Object)null)
			{
				val = Shader.Find("Sprites/Default");
				flag = true;
			}
			if ((Object)(object)val == (Object)null)
			{
				val = Shader.Find("Standard");
				flag = false;
			}
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			Material val2 = new Material(val);
			if (val2.HasProperty("_Color"))
			{
				val2.SetColor("_Color", flag ? Color.white : color);
			}
			if (val2.HasProperty("_Cull"))
			{
				val2.SetInt("_Cull", (!cullOff) ? 2 : 0);
			}
			if (val2.HasProperty("_ZWrite"))
			{
				val2.SetInt("_ZWrite", 1);
			}
			if (val2.HasProperty("_SrcBlend"))
			{
				val2.SetInt("_SrcBlend", 1);
			}
			if (val2.HasProperty("_DstBlend"))
			{
				val2.SetInt("_DstBlend", 0);
			}
			((Object)val2).hideFlags = (HideFlags)(((Object)val2).hideFlags | 0x20);
			return val2;
		}
	}
	internal static class BlindnessConfig
	{
		internal static ConfigEntry<float> OverlayAlpha;

		internal static ConfigEntry<float> FogMultiplier;

		internal static ConfigEntry<float> FogMin;

		internal static ConfigEntry<float> FogDarken;

		internal static ConfigEntry<float> HandColorScale;

		internal static void Init(ConfigFile c)
		{
			OverlayAlpha = c.Bind<float>("Blindness", "OverlayAlpha", 0.55f, "");
			FogMultiplier = c.Bind<float>("Blindness", "FogMultiplier", 2.5f, "");
			FogMin = c.Bind<float>("Blindness", "FogMin", 0.03f, "");
			FogDarken = c.Bind<float>("Blindness", "FogDarken", 0.85f, "");
			HandColorScale = c.Bind<float>("Blindness", "HandColorScale", 0.1f, "");
		}
	}
	internal sealed class BlindnessController : MonoBehaviour
	{
		internal const string PerkId = "brokenshoes_blindness";

		internal static bool Active;

		private GameObject _root;

		private Image _black;

		private void Update()
		{
			//IL_0064: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			ENT_Player val = null;
			try
			{
				val = ENT_Player.GetPlayer();
			}
			catch
			{
			}
			Active = (Object)(object)val != (Object)null && !((GameEntity)val).dead && HasPerk(val);
			if (!Active)
			{
				if ((Object)(object)_root != (Object)null && _root.activeSelf)
				{
					_root.SetActive(false);
				}
			}
			else if (EnsureUi())
			{
				Color black = Color.black;
				black.a = Mathf.Clamp01(BlindnessConfig.OverlayAlpha.Value);
				((Graphic)_black).color = black;
				if (!_root.activeSelf)
				{
					_root.SetActive(true);
				}
			}
		}

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

		private bool EnsureUi()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			//IL_0091: 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_00a7: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_root != (Object)null)
			{
				return true;
			}
			try
			{
				_root = new GameObject("BlindnessHud");
				Object.DontDestroyOnLoad((Object)(object)_root);
				Canvas obj = _root.AddComponent<Canvas>();
				obj.renderMode = (RenderMode)0;
				obj.sortingOrder = 200;
				GameObject val = new GameObject("Black", new Type[2]
				{
					typeof(RectTransform),
					typeof(Image)
				});
				val.transform.SetParent(_root.transform, false);
				RectTransform component = val.GetComponent<RectTransform>();
				component.anchorMin = Vector2.zero;
				component.anchorMax = Vector2.one;
				component.offsetMin = Vector2.zero;
				component.offsetMax = Vector2.zero;
				_black = val.GetComponent<Image>();
				((Graphic)_black).color = new Color(0f, 0f, 0f, 0f);
				((Graphic)_black).raycastTarget = false;
				_root.SetActive(false);
				AwfulBindingsPlugin.Log.LogInfo((object)"Blindness ready");
				return true;
			}
			catch (Exception ex)
			{
				if ((Object)(object)_root != (Object)null)
				{
					Object.Destroy((Object)(object)_root);
				}
				_root = null;
				_black = null;
				AwfulBindingsPlugin.Log.LogError((object)("Blindness could not set up its overlay: " + ex));
				return false;
			}
		}

		private static bool HasPerk(ENT_Player p)
		{
			IEnumerable perks = p.perks;
			if (perks == null)
			{
				return false;
			}
			foreach (object item in perks)
			{
				Perk val = (Perk)((item is Perk) ? item : null);
				if ((Object)(object)val != (Object)null && val.id == "brokenshoes_blindness")
				{
					return true;
				}
			}
			return false;
		}
	}
	internal sealed class BlindnessFogState
	{
		public FXData Data;

		public Color Fog;

		public Color FogTop;

		public float Mult;
	}
	[HarmonyPatch(typeof(FXManager), "FXRender")]
	internal static class BlindnessFogPatch
	{
		private static void Prefix(out BlindnessFogState __state)
		{
			//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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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)
			__state = null;
			if (BlindnessController.Active)
			{
				FXData fxData = FXManager.fxData;
				if (fxData != null)
				{
					__state = new BlindnessFogState
					{
						Data = fxData,
						Fog = fxData.fog,
						FogTop = fxData.fogTop,
						Mult = fxData.fogMultiplier
					};
					float num = Mathf.Clamp01(BlindnessConfig.FogDarken.Value);
					fxData.fog = Color.Lerp(fxData.fog, Color.black, num);
					fxData.fogTop = Color.Lerp(fxData.fogTop, Color.black, num);
					fxData.fogMultiplier = Mathf.Max(fxData.fogMultiplier * Mathf.Max(0f, BlindnessConfig.FogMultiplier.Value), Mathf.Max(0f, BlindnessConfig.FogMin.Value));
				}
			}
		}

		private static void Postfix(BlindnessFogState __state)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			if (__state != null && __state.Data != null)
			{
				__state.Data.fog = __state.Fog;
				__state.Data.fogTop = __state.FogTop;
				__state.Data.fogMultiplier = __state.Mult;
			}
		}
	}
	[HarmonyPatch(typeof(Hand_SpriteController), "SetStaminaInfo")]
	internal static class BlindnessHandPatch
	{
		private static void Prefix(ref float amount)
		{
			if (BlindnessController.Active)
			{
				amount *= Mathf.Clamp01(BlindnessConfig.HandColorScale.Value);
			}
		}
	}
	internal static class CleaverConfig
	{
		internal static ConfigEntry<string> PrefabName;

		internal static ConfigEntry<int> Cost;

		internal static ConfigEntry<float> ScoreMultiplierBonus;

		internal static void Init(ConfigFile c)
		{
			PrefabName = c.Bind<string>("Cleaver", "PrefabName", "Item_Cleaver", "");
			Cost = c.Bind<int>("Cleaver", "Cost", 0, "");
			ScoreMultiplierBonus = c.Bind<float>("Cleaver", "ScoreMultiplierBonus", 0f, "");
		}
	}
	internal static class CleaverTrinket
	{
		internal const string TrinketId = "pongon_cleaver";

		private static Item_Object _cached;

		private static bool _loggedMissing;

		internal static List<Item_Object> GrantItems()
		{
			List<Item_Object> list = new List<Item_Object>();
			Item_Object val = FindCleaver();
			if ((Object)(object)val != (Object)null)
			{
				list.Add(val);
			}
			return list;
		}

		private static Item_Object FindCleaver()
		{
			if ((Object)(object)_cached != (Object)null)
			{
				return _cached;
			}
			List<string> list = new List<string>();
			string value = CleaverConfig.PrefabName.Value;
			if (!string.IsNullOrWhiteSpace(value))
			{
				list.Add(value.Trim());
			}
			if (!list.Contains("Item_Cleaver"))
			{
				list.Add("Item_Cleaver");
			}
			if (!list.Contains("Cleaver"))
			{
				list.Add("Cleaver");
			}
			foreach (string item in list)
			{
				Item_Object val = ItemOf(GetPrefab(item));
				if ((Object)(object)val != (Object)null)
				{
					return Found(val, "prefab name '" + item + "'");
				}
			}
			StringBuilder stringBuilder = new StringBuilder();
			try
			{
				WKAssetDatabase fullCombinedAssetDatabase = CL_AssetManager.GetFullCombinedAssetDatabase();
				if ((Object)(object)fullCombinedAssetDatabase != (Object)null && fullCombinedAssetDatabase.itemPrefabs != null)
				{
					foreach (GameObject itemPrefab in fullCombinedAssetDatabase.itemPrefabs)
					{
						if ((Object)(object)itemPrefab == (Object)null)
						{
							continue;
						}
						stringBuilder.Append(((Object)itemPrefab).name).Append(", ");
						Item_Object component = itemPrefab.GetComponent<Item_Object>();
						if (!((Object)(object)component == (Object)null))
						{
							Item itemData = component.itemData;
							if (IsCleaver(((Object)itemPrefab).name) || (itemData != null && (IsCleaver(itemData.itemName) || IsCleaver(itemData.prefabName))))
							{
								return Found(component, "item database entry '" + ((Object)itemPrefab).name + "'");
							}
						}
					}
				}
			}
			catch (Exception ex)
			{
				AwfulBindingsPlugin.Log.LogWarning((object)("[Cleaver] Item database search failed: " + ex.Message));
			}
			if (!_loggedMissing)
			{
				_loggedMissing = true;
				AwfulBindingsPlugin.Log.LogWarning((object)("[Cleaver] Could not find the Cleaver item, so the trinket gives nothing. Set [Cleaver] PrefabName in the config to the right prefab name. Item prefabs found: " + stringBuilder));
			}
			return null;
		}

		private static Item_Object Found(Item_Object io, string how)
		{
			_cached = io;
			AwfulBindingsPlugin.Log.LogInfo((object)("[Cleaver] Found the Cleaver via " + how));
			return io;
		}

		private static GameObject GetPrefab(string name)
		{
			try
			{
				return CL_AssetManager.GetAssetGameObject(name, "");
			}
			catch
			{
				return null;
			}
		}

		private static Item_Object ItemOf(GameObject go)
		{
			if (!((Object)(object)go != (Object)null))
			{
				return null;
			}
			return go.GetComponent<Item_Object>();
		}

		private static bool IsCleaver(string s)
		{
			if (!string.IsNullOrEmpty(s))
			{
				return s.IndexOf("cleaver", StringComparison.OrdinalIgnoreCase) >= 0;
			}
			return false;
		}
	}
	internal static class DeathsGripConfig
	{
		internal static ConfigEntry<bool> ReplaceSpecialHolds;

		internal static ConfigEntry<string> ExcludeNames;

		internal static ConfigEntry<string> OnlyNames;

		internal static ConfigEntry<bool> RequireVisibleModel;

		internal static void Init(ConfigFile c)
		{
			ReplaceSpecialHolds = c.Bind<bool>("DeathsGrip", "ReplaceSpecialHolds", false, "Normal handholds always become crumbling holds. Set this to true to also replace the special ones (icy, damaging...). Ropes and holds that already crumble are never replaced.");
			ExcludeNames = c.Bind<string>("DeathsGrip", "ExcludeNames", "rebar,rope,pipe,ladder,env,pole,beam,vine,chain,cable,lever,button,wheel,terrain,ground,wall,floor,cliff,ledge,structure", "Comma-separated, case-insensitive. A handhold type whose name (or prefab name) contains any of these is never replaced (rebar, ropes, environmental grabs...). Every handhold type, and whether it was replaced and why, is written to the BepInEx log the first time Death's Grip is active, so you can add names here.");
			OnlyNames = c.Bind<string>("DeathsGrip", "OnlyNames", "", "Optional, comma-separated. If you fill this in, ONLY handhold types whose name contains one of these are replaced (ExcludeNames still applies). Leave empty to replace every normal grip.");
			RequireVisibleModel = c.Bind<bool>("DeathsGrip", "RequireVisibleModel", true, "Only replace holds that have a visible model in the level. Invisible grabs (environmental grab zones) are skipped. Turn this off if nothing gets replaced.");
		}
	}
	internal sealed class DeathsGripController : MonoBehaviour
	{
		internal const string PerkId = "brokenshoes_deathsgrip";

		internal static bool Active;

		private void Update()
		{
			Refresh();
		}

		internal static bool Refresh()
		{
			ENT_Player val = null;
			try
			{
				val = ENT_Player.GetPlayer();
			}
			catch
			{
			}
			bool flag = (Object)(object)val != (Object)null && !((GameEntity)val).dead && HasPerk(val);
			if (flag != Active)
			{
				Active = flag;
				AwfulBindingsPlugin.Log.LogInfo((object)("Death's Grip " + (flag ? "active" : "inactive")));
			}
			return Active;
		}

		private static bool HasPerk(ENT_Player p)
		{
			IEnumerable perks = p.perks;
			if (perks == null)
			{
				return false;
			}
			foreach (object item in perks)
			{
				Perk val = (Perk)((item is Perk) ? item : null);
				if ((Object)(object)val != (Object)null && val.id == "brokenshoes_deathsgrip")
				{
					return true;
				}
			}
			return false;
		}
	}
	internal sealed class HoldSwapState
	{
		public Dictionary<string, HandholdType> Dict;

		public readonly List<KeyValuePair<Transform, string>> Renamed = new List<KeyValuePair<Transform, string>>();

		public readonly List<Renderer> OldVisuals = new List<Renderer>();

		public bool AddedCopy;

		public bool AddedSpawn;
	}
	[HarmonyPatch(typeof(HandholdManager), "LoadHandholds")]
	internal static class DeathsGripHandholdPatch
	{
		private const string KeyCopy = "__deathsgrip_copy";

		private const string KeySpawn = "__deathsgrip_spawn";

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

		private static readonly Dictionary<HandholdType, string> TypeVerdicts = new Dictionary<HandholdType, string>();

		private static HandholdType _source;

		private static HandholdType _copyClone;

		private static HandholdType _spawnClone;

		private static bool _tableLogged;

		private static int _callLogs;

		private static void Prefix(HandholdManager __instance, GameObject g, out HoldSwapState __state)
		{
			__state = null;
			try
			{
				if ((Object)(object)__instance == (Object)null || (Object)(object)g == (Object)null)
				{
					return;
				}
				if (!DeathsGripController.Refresh())
				{
					if (_callLogs < 6)
					{
						_callLogs++;
						AwfulBindingsPlugin.Log.LogInfo((object)("Death's Grip: holds were made for '" + ((Object)g).name + "' while the binding was inactive"));
					}
					return;
				}
				List<HandholdType> handholdTypes = __instance.handholdTypes;
				if (handholdTypes == null || handholdTypes.Count == 0)
				{
					return;
				}
				Traverse val = Traverse.Create((object)__instance);
				Dictionary<string, HandholdType> value = val.Field("handholdDict").GetValue<Dictionary<string, HandholdType>>();
				if (value == null)
				{
					return;
				}
				if (value.Count == 0)
				{
					val.Method("LoadHandholdTypes", Array.Empty<object>()).GetValue();
					value = val.Field("handholdDict").GetValue<Dictionary<string, HandholdType>>();
					if (value == null || value.Count == 0)
					{
						return;
					}
				}
				if (!_tableLogged)
				{
					_tableLogged = true;
					LogTable(handholdTypes, value);
				}
				if (!EnsureClones(handholdTypes))
				{
					return;
				}
				List<Transform> value2 = val.Method("TraverseHierarchy", new object[1] { g.transform }).GetValue<List<Transform>>();
				if (value2 == null)
				{
					return;
				}
				HoldSwapState holdSwapState = new HoldSwapState
				{
					Dict = value
				};
				Dictionary<string, int> dictionary = new Dictionary<string, int>();
				int num = 0;
				foreach (Transform item in value2)
				{
					if ((Object)(object)item == (Object)null || !((Object)item).name.Contains("handhold"))
					{
						continue;
					}
					string[] array = ((Object)item).name.Split(':');
					HandholdType val2 = handholdTypes[0];
					if (array.Length > 1)
					{
						string key = array[1].Split('.')[0];
						if (value.ContainsKey(key))
						{
							val2 = value[key];
						}
					}
					if (!IsNormalGrip(item, val2, out var reason))
					{
						dictionary.TryGetValue(reason, out var value3);
						dictionary[reason] = value3 + 1;
						continue;
					}
					bool flag = _copyClone != null && !val2.spawnPrefab;
					if (!flag)
					{
						Renderer[] componentsInChildren = ((Component)item).GetComponentsInChildren<Renderer>(true);
						foreach (Renderer val3 in componentsInChildren)
						{
							if (val3 is MeshRenderer || val3 is SkinnedMeshRenderer)
							{
								holdSwapState.OldVisuals.Add(val3);
							}
						}
					}
					holdSwapState.Renamed.Add(new KeyValuePair<Transform, string>(item, ((Object)item).name));
					((Object)item).name = "handhold:" + (flag ? "__deathsgrip_copy" : "__deathsgrip_spawn");
					num++;
				}
				if (num > 0)
				{
					if (_copyClone != null)
					{
						value["__deathsgrip_copy"] = _copyClone;
						holdSwapState.AddedCopy = true;
					}
					value["__deathsgrip_spawn"] = _spawnClone;
					holdSwapState.AddedSpawn = true;
				}
				if ((num > 0 || dictionary.Count > 0) && _callLogs < 40)
				{
					_callLogs++;
					StringBuilder stringBuilder = new StringBuilder();
					foreach (KeyValuePair<string, int> item2 in dictionary)
					{
						stringBuilder.Append(item2.Value).Append("x ").Append(item2.Key)
							.Append("; ");
					}
					AwfulBindingsPlugin.Log.LogInfo((object)("Death's Grip: '" + ((Object)g).name + "': " + num + " grip(s) now crumbling" + ((dictionary.Count > 0) ? (", kept: " + stringBuilder) : "")));
				}
				__state = holdSwapState;
			}
			catch (Exception ex)
			{
				AwfulBindingsPlugin.Log.LogWarning((object)("Death's Grip could not swap the holds: " + ex));
				__state = null;
			}
		}

		private static Exception Finalizer(HoldSwapState __state, Exception __exception)
		{
			if (__state == null)
			{
				return __exception;
			}
			try
			{
				foreach (KeyValuePair<Transform, string> item in __state.Renamed)
				{
					if ((Object)(object)item.Key != (Object)null)
					{
						((Object)item.Key).name = item.Value;
					}
				}
				if (__state.AddedCopy)
				{
					__state.Dict.Remove("__deathsgrip_copy");
				}
				if (__state.AddedSpawn)
				{
					__state.Dict.Remove("__deathsgrip_spawn");
				}
				if (__exception == null)
				{
					foreach (Renderer oldVisual in __state.OldVisuals)
					{
						if ((Object)(object)oldVisual != (Object)null)
						{
							oldVisual.enabled = false;
						}
					}
				}
			}
			catch (Exception ex)
			{
				AwfulBindingsPlugin.Log.LogWarning((object)("Death's Grip could not restore the hold table: " + ex));
			}
			return __exception;
		}

		private static bool IsNormalGrip(Transform placeholder, HandholdType original, out string reason)
		{
			reason = "";
			if (original == null || (Object)(object)original.prefab == (Object)null)
			{
				reason = "no type";
				return false;
			}
			string text = TypeVerdict(original);
			if (text != null)
			{
				reason = text;
				return false;
			}
			if (DeathsGripConfig.RequireVisibleModel.Value && !((!original.spawnPrefab) ? HasVisibleRenderer(placeholder) : ((Object)(object)original.prefab.GetComponentInChildren<Renderer>(true) != (Object)null)))
			{
				reason = "no visible model (invisible grab)";
				return false;
			}
			return true;
		}

		private static bool HasVisibleRenderer(Transform t)
		{
			Renderer[] componentsInChildren = ((Component)t).GetComponentsInChildren<Renderer>(false);
			foreach (Renderer val in componentsInChildren)
			{
				if ((Object)(object)val != (Object)null && val.enabled && (val is MeshRenderer || val is SkinnedMeshRenderer))
				{
					return true;
				}
			}
			return false;
		}

		private static string TypeVerdict(HandholdType t)
		{
			if (TypeVerdicts.TryGetValue(t, out var value))
			{
				if (!(value == ""))
				{
					return value;
				}
				return null;
			}
			string text = Judge(t);
			TypeVerdicts[t] = text ?? "";
			Note("type:" + t.name, "Death's Grip: handhold type '" + t.name + "' -> " + ((text == null) ? "normal grip, REPLACED with crumbling" : ("kept (" + text + ")")));
			return text;
		}

		private static string Judge(HandholdType t)
		{
			CL_Handhold hold = GetHold(t);
			if ((Object)(object)hold == (Object)null)
			{
				return "no CL_Handhold on its prefab";
			}
			if (hold is CL_Handhold_Breakable)
			{
				return "already crumbles";
			}
			if (hold is CL_Handhold_Rope)
			{
				return "rope";
			}
			string text = ((t.name != null) ? t.name.ToLowerInvariant() : string.Empty);
			string text2 = (((Object)(object)t.prefab != (Object)null) ? ((Object)t.prefab).name.ToLowerInvariant() : string.Empty);
			string text3 = FirstMatch(text, DeathsGripConfig.ExcludeNames.Value);
			if (text3 == null)
			{
				text3 = FirstMatch(text2, DeathsGripConfig.ExcludeNames.Value);
			}
			if (text3 != null)
			{
				return "excluded name '" + text3 + "'";
			}
			string value = DeathsGripConfig.OnlyNames.Value;
			if (!string.IsNullOrEmpty(value) && value.Trim().Length > 0 && FirstMatch(text, value) == null && FirstMatch(text2, value) == null)
			{
				return "not in OnlyNames";
			}
			if (((object)hold).GetType() != typeof(CL_Handhold) && !DeathsGripConfig.ReplaceSpecialHolds.Value)
			{
				return "special hold (" + ((object)hold).GetType().Name + ")";
			}
			return null;
		}

		private static string FirstMatch(string text, string csv)
		{
			if (string.IsNullOrEmpty(text) || string.IsNullOrEmpty(csv))
			{
				return null;
			}
			string[] array = csv.ToLowerInvariant().Split(',');
			for (int i = 0; i < array.Length; i++)
			{
				string text2 = array[i].Trim();
				if (text2.Length > 0 && text.Contains(text2))
				{
					return text2;
				}
			}
			return null;
		}

		private static CL_Handhold GetHold(HandholdType t)
		{
			if (t == null || (Object)(object)t.prefab == (Object)null)
			{
				return null;
			}
			CL_Handhold val = t.prefab.GetComponent<CL_Handhold>();
			if ((Object)(object)val == (Object)null)
			{
				val = t.prefab.GetComponentInChildren<CL_Handhold>(true);
			}
			return val;
		}

		private static bool EnsureClones(List<HandholdType> types)
		{
			//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_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Expected O, but got Unknown
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			if (_spawnClone != null && (Object)(object)_spawnClone.prefab != (Object)null)
			{
				return true;
			}
			HandholdType val = null;
			foreach (HandholdType type in types)
			{
				if (type != null && GetHold(type) is CL_Handhold_Breakable)
				{
					if (type.name != null && type.name.ToLowerInvariant().Contains("crumb"))
					{
						val = type;
						break;
					}
					if (val == null)
					{
						val = type;
					}
				}
			}
			GameObject val2 = val?.prefab;
			if ((Object)(object)val2 == (Object)null)
			{
				CL_Handhold_Breakable[] array = Resources.FindObjectsOfTypeAll<CL_Handhold_Breakable>();
				foreach (CL_Handhold_Breakable val3 in array)
				{
					if ((Object)(object)val3 != (Object)null)
					{
						Scene scene = ((Component)val3).gameObject.scene;
						if (!((Scene)(ref scene)).IsValid())
						{
							val2 = ((Component)val3).gameObject;
							break;
						}
					}
				}
			}
			if ((Object)(object)val2 == (Object)null)
			{
				Note("nocrumble", "Death's Grip: no crumbling handhold found, nothing is replaced.");
				return false;
			}
			_source = val;
			_spawnClone = new HandholdType
			{
				name = "deathsgrip_spawn",
				prefab = val2,
				spawnPrefab = true
			};
			bool flag = (Object)(object)val2.GetComponent<CL_Handhold_Breakable>() != (Object)null;
			_copyClone = ((!flag) ? ((HandholdType)null) : new HandholdType
			{
				name = "deathsgrip_copy",
				prefab = val2,
				spawnPrefab = false
			});
			Note("crumble", "Death's Grip: crumbling hold = prefab '" + ((Object)val2).name + "'" + ((val != null) ? (" (handhold type '" + val.name + "', " + (val.spawnPrefab ? "spawns prefab" : "copies components") + ")") : "") + "; components " + (flag ? "on the root, so holds keep their own model" : "on a child, so the crumbling model is spawned instead"));
			return true;
		}

		private static void LogTable(List<HandholdType> types, Dictionary<string, HandholdType> dict)
		{
			List<string> list = new List<string>(dict.Keys);
			AwfulBindingsPlugin.Log.LogInfo((object)("Death's Grip: the game knows " + types.Count + " handhold type(s); placeholder keys: " + string.Join(", ", list.ToArray()) + "; default (no key) = '" + ((types[0] != null) ? types[0].name : "?") + "'"));
			foreach (HandholdType type in types)
			{
				if (type != null)
				{
					CL_Handhold hold = GetHold(type);
					bool flag = (Object)(object)type.prefab != (Object)null && (Object)(object)type.prefab.GetComponentInChildren<Renderer>(true) != (Object)null;
					AwfulBindingsPlugin.Log.LogInfo((object)("Handhold type: '" + type.name + "' [" + (((Object)(object)hold != (Object)null) ? ((object)hold).GetType().Name : "no CL_Handhold") + ", " + (type.spawnPrefab ? "spawns prefab" : "copies components") + ", prefab " + (flag ? "has" : "has no") + " model]"));
				}
			}
		}

		private static void Note(string key, string message)
		{
			if (Logged.Add(key))
			{
				AwfulBindingsPlugin.Log.LogInfo((object)message);
			}
		}
	}
	internal sealed class DopplegangerAnimator : MonoBehaviour
	{
		private const float TorsoCenterX = 0.005f;

		private const float ShoulderX = 0.09f;

		private const float ShoulderY = 0.575f;

		private const float HandReach = 0.3f;

		private const float ShaftStart = 0.055f;

		private const float ShaftEnd = 0.275f;

		private const float HipY = 0.35f;

		private const float KneeY = 0.175f;

		private const float MinArmScale = 0.3f;

		private Mesh _mesh;

		private Vector3[] _base;

		private Vector3[] _cur;

		private sbyte[] _armSide;

		private float[] _armW;

		private sbyte[] _legSide;

		private float[] _kneeW;

		private readonly Vector3[] _shoulder = (Vector3[])(object)new Vector3[2];

		private readonly Vector3[] _hip = (Vector3[])(object)new Vector3[2];

		private readonly Vector3[] _kneeRest = (Vector3[])(object)new Vector3[2];

		private readonly float[] _thigh = new float[2];

		private readonly float[] _knee = new float[2];

		private readonly float[] _splay = new float[2];

		private readonly Quaternion[] _thighRot = (Quaternion[])(object)new Quaternion[2];

		private readonly Quaternion[] _shinRot = (Quaternion[])(object)new Quaternion[2];

		private readonly Vector3[] _kneePos = (Vector3[])(object)new Vector3[2];

		private readonly Vector3[] _hand = (Vector3[])(object)new Vector3[2];

		private readonly Vector3[] _armDir = (Vector3[])(object)new Vector3[2];

		private readonly Quaternion[] _armRot = (Quaternion[])(object)new Quaternion[2];

		private readonly float[] _armK = new float[2];

		private readonly int[] _armHand = new int[2] { -1, -1 };

		private readonly int[] _handArm = new int[2] { -1, -1 };

		private readonly Vector3[] _gripPos = (Vector3[])(object)new Vector3[2];

		private Vector3 _vel;

		private float _phase;

		private float _climbPhase;

		private float _time;

		private bool _init;

		internal bool Init(Mesh instanceMesh)
		{
			//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_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)instanceMesh == (Object)null || DopplegangerModel.BaseVerts == null)
			{
				return false;
			}
			_mesh = instanceMesh;
			_base = DopplegangerModel.BaseVerts;
			_armSide = DopplegangerModel.ArmSide;
			_armW = DopplegangerModel.ArmW;
			_legSide = DopplegangerModel.LegSide;
			_kneeW = DopplegangerModel.KneeW;
			_cur = (Vector3[])(object)new Vector3[_base.Length];
			_shoulder[0] = new Vector3(-0.085f, 0.575f, 0f);
			_shoulder[1] = new Vector3(0.095000006f, 0.575f, 0f);
			for (int i = 0; i < 2; i++)
			{
				_hip[i] = new Vector3(DopplegangerModel.HipX[i], 0.35f, 0f);
				_kneeRest[i] = new Vector3(DopplegangerModel.HipX[i], 0.175f, 0f);
			}
			ResetPose();
			return true;
		}

		internal void ResetPose()
		{
			//IL_0008: 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)
			_init = false;
			_vel = Vector3.zero;
			_armHand[0] = (_armHand[1] = -1);
			_handArm[0] = (_handArm[1] = -1);
		}

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

		internal void Animate(float dt, Vector3 worldVel, bool grounded, bool grip0, Vector3 pos0, bool grip1, Vector3 pos1)
		{
			//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)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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_0098: 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_00ba: 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_00c8: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_mesh == (Object)null) && _base != null && !(dt <= 0f))
			{
				dt = Mathf.Min(dt, 0.1f);
				_time += dt;
				Transform transform = ((Component)this).transform;
				Vector3 val = Quaternion.Inverse(transform.rotation) * worldVel;
				_vel = (_init ? Vector3.Lerp(_vel, val, 1f - Mathf.Exp(-12f * dt)) : val);
				Vector2 val2 = new Vector2(_vel.x, _vel.z);
				float magnitude = ((Vector2)(ref val2)).magnitude;
				float y = _vel.y;
				_gripPos[0] = pos0;
				_gripPos[1] = pos1;
				UpdateGrip(0, grip0, pos0, transform);
				UpdateGrip(1, grip1, pos1, transform);
				bool flag = (grip0 || grip1) && !grounded;
				float move = Mathf.Clamp01(magnitude / 4.5f);
				if (grounded)
				{
					float num = ((_vel.z >= -0.3f) ? 1f : (-1f));
					_phase += num * magnitude * 2.6f * dt;
				}
				float num2 = (flag ? Mathf.Clamp01(y / 1.8f) : 0f);
				_climbPhase += dt * num2 * 9f;
				float rising = ((!grounded) ? Mathf.Clamp01(y / 4f) : 0f);
				float falling = ((!grounded) ? Mathf.Clamp01((0f - y) / 8f) : 0f);
				AnimateLegs(dt, grounded, flag, move, num2, rising, falling);
				AnimateArms(dt, transform, grounded, flag, move, falling);
				_init = true;
				Deform();
			}
		}

		private void UpdateGrip(int hand, bool gripping, Vector3 world, Transform tr)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			if (!gripping)
			{
				int num = _handArm[hand];
				if (num >= 0)
				{
					_armHand[num] = -1;
					_handArm[hand] = -1;
				}
			}
			else if (_handArm[hand] < 0)
			{
				float num2 = tr.InverseTransformPoint(world).x - 0.005f;
				int num3 = ((Mathf.Abs(num2) > 0.05f) ? ((num2 > 0f) ? 1 : 0) : hand);
				if (_armHand[num3] >= 0)
				{
					num3 = 1 - num3;
				}
				_armHand[num3] = hand;
				_handArm[hand] = num3;
			}
		}

		private void AnimateLegs(float dt, bool grounded, bool hanging, float move, float climb, float rising, float falling)
		{
			//IL_0281: 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_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: 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)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			float num = DopplegangerConfig.GaitDegrees.Value * move;
			float num2 = (_init ? (1f - Mathf.Exp(-16f * dt)) : 1f);
			for (int i = 0; i < 2; i++)
			{
				float num3 = Mathf.Sin(_time * 1.5f + (float)i * 1.9f);
				float num5;
				float num6;
				float num7;
				if (hanging)
				{
					float num4 = Mathf.Max(0f, Mathf.Sin(_climbPhase + (float)i * MathF.PI));
					num5 = 0f - Mathf.Clamp(_vel.z * 3f, -20f, 20f) + 7f * num3 + climb * 40f * num4;
					num6 = 12f + 8f * num3 + climb * 70f * num4;
					num7 = 5f + 3f * num3;
				}
				else if (!grounded)
				{
					float num8 = Mathf.Sin(_time * 11f + (float)i * MathF.PI);
					num5 = Mathf.Lerp((i == 0) ? 22f : (-8f), 38f, rising) + falling * 28f * num8;
					num6 = Mathf.Lerp(35f, 65f, rising) + falling * 20f * (0.5f + 0.5f * num8);
					num7 = 6f + falling * 18f;
				}
				else
				{
					float num9 = _phase + ((i == 0) ? 0f : MathF.PI);
					num5 = num * Mathf.Sin(num9);
					num6 = 50f * move * Mathf.Max(0f, Mathf.Cos(num9));
					num7 = 0f;
				}
				_thigh[i] = (_init ? Mathf.Lerp(_thigh[i], num5, num2) : num5);
				_knee[i] = (_init ? Mathf.Lerp(_knee[i], num6, num2) : num6);
				_splay[i] = (_init ? Mathf.Lerp(_splay[i], num7, num2) : num7);
				float num10 = ((i == 0) ? (-1f) : 1f);
				float num11 = _thigh[i] * (MathF.PI / 180f);
				float num12 = (_thigh[i] - Mathf.Max(0f, _knee[i])) * (MathF.PI / 180f);
				float num13 = _splay[i] * (MathF.PI / 180f);
				Vector3 val = new Vector3(num10 * Mathf.Sin(num13), 0f - Mathf.Cos(num11), Mathf.Sin(num11));
				Vector3 normalized = ((Vector3)(ref val)).normalized;
				val = new Vector3(num10 * Mathf.Sin(num13), 0f - Mathf.Cos(num12), Mathf.Sin(num12));
				Vector3 normalized2 = ((Vector3)(ref val)).normalized;
				_thighRot[i] = Quaternion.FromToRotation(Vector3.down, normalized);
				_shinRot[i] = Quaternion.FromToRotation(Vector3.down, normalized2);
				_kneePos[i] = _hip[i] + normalized * 0.175f;
			}
		}

		private static float ReachFor(float scale)
		{
			return 0.055f + 0.22f * scale + 0.025000006f;
		}

		private void AnimateArms(float dt, Transform tr, bool grounded, bool hanging, float move, float falling)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: 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_009e: 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_00a7: 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_00b1: 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_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: 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_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: 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_022c: 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_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: 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_0258: 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_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_02c1: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Max(1f, DopplegangerConfig.MaxArmStretch.Value);
			float num2 = Mathf.Max(1f, DopplegangerConfig.ArmReachSpeed.Value);
			for (int i = 0; i < 2; i++)
			{
				float num3 = ((i == 0) ? (-1f) : 1f);
				Vector3 val = _shoulder[i];
				int num4 = _armHand[i];
				Vector3 val4;
				float num6;
				if (num4 >= 0)
				{
					Vector3 val2 = tr.InverseTransformPoint(_gripPos[num4]);
					Vector3 val3 = val2 - val;
					float magnitude = ((Vector3)(ref val3)).magnitude;
					float num5 = ReachFor(num);
					if (magnitude > num5 && magnitude > 0.0001f)
					{
						val2 = val + val3 * (num5 / magnitude);
					}
					val4 = val2;
					num6 = num2;
				}
				else
				{
					float num7;
					float num8;
					if (!grounded && !hanging)
					{
						num7 = Mathf.Lerp(25f, -10f, falling) + 14f * Mathf.Sin(_time * 9f + (float)i * 1.7f) * (0.4f + falling);
						num8 = 0f;
					}
					else if (hanging)
					{
						num7 = 60f + 8f * Mathf.Sin(_time * 1.7f + (float)i);
						num8 = 0.1f * Mathf.Sin(_time * 1.3f + (float)i * 2f);
					}
					else
					{
						num7 = Mathf.Lerp(72f, 58f, move) + 2f * Mathf.Sin(_time * 1.2f + (float)i);
						num8 = 0.55f * move * Mathf.Sin(_phase + ((i == 0) ? MathF.PI : 0f));
					}
					float num9 = num7 * (MathF.PI / 180f);
					Vector3 val5 = new Vector3(num3 * Mathf.Cos(num9), 0f - Mathf.Sin(num9), num8);
					Vector3 normalized = ((Vector3)(ref val5)).normalized;
					val4 = val + normalized * 0.3f;
					num6 = 12f;
				}
				_hand[i] = (_init ? Vector3.Lerp(_hand[i], val4, 1f - Mathf.Exp((0f - num6) * dt)) : val4);
				Vector3 val6 = _hand[i] - val;
				float magnitude2 = ((Vector3)(ref val6)).magnitude;
				Vector3 val7 = ((magnitude2 > 0.0001f) ? (val6 / magnitude2) : Vector3.down);
				float num10 = (magnitude2 - 0.055f - 0.025000006f) / 0.22f;
				_armK[i] = Mathf.Clamp(num10, 0.3f, num);
				_armDir[i] = val7;
				_armRot[i] = Quaternion.FromToRotation(new Vector3(num3, 0f, 0f), val7);
			}
		}

		private void Deform()
		{
			//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_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: 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_014c: 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_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: 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_0177: 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_0189: 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_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: 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_01b2: 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_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_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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: 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_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_0104: 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_010b: 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_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			int num = _base.Length;
			for (int i = 0; i < num; i++)
			{
				Vector3 val = _base[i];
				float num2 = _armW[i];
				if (num2 > 0f)
				{
					int num3 = ((_armSide[i] > 0) ? 1 : 0);
					float num4 = ((num3 == 0) ? (-1f) : 1f);
					Vector3 val2 = _shoulder[num3];
					Vector3 val3 = val - val2;
					float num5 = val3.x * num4;
					float num6 = _armK[num3];
					float num7 = ((num5 <= 0.055f) ? num5 : ((!(num5 <= 0.275f)) ? (0.055f + 0.22f * num6 + (num5 - 0.275f)) : (0.055f + (num5 - 0.055f) * num6)));
					Vector3 val4 = _armDir[num3] * num7 + _armRot[num3] * new Vector3(0f, val3.y, val3.z);
					val = val2 + Vector3.Lerp(val3, val4, num2);
				}
				else if (_legSide[i] != 0)
				{
					int num8 = ((_legSide[i] >= 0) ? 1 : 0);
					Vector3 val5 = _hip[num8];
					Vector3 val6 = val5 + _thighRot[num8] * (val - val5);
					Vector3 val7 = _kneePos[num8] + _shinRot[num8] * (val - _kneeRest[num8]);
					val = Vector3.Lerp(val6, val7, _kneeW[i]);
				}
				_cur[i] = val;
			}
			_mesh.vertices = _cur;
		}
	}
	internal static class DopplegangerConfig
	{
		internal static ConfigEntry<float> DelaySeconds;

		internal static ConfigEntry<float> TouchRadius;

		internal static ConfigEntry<float> DrainPerSecond;

		internal static ConfigEntry<float> TickSeconds;

		internal static ConfigEntry<float> MassSlow;

		internal static ConfigEntry<string> SubstructureNames;

		internal static ConfigEntry<float> ModelScale;

		internal static ConfigEntry<bool> LogLevels;

		internal static ConfigEntry<bool> Animate;

		internal static ConfigEntry<float> MaxArmStretch;

		internal static ConfigEntry<float> ArmReachSpeed;

		internal static ConfigEntry<float> GaitDegrees;

		internal static ConfigEntry<float> TextureScale;

		internal static ConfigEntry<bool> SmoothTexture;

		internal static ConfigEntry<bool> Dither;

		internal static ConfigEntry<int> DitherPixelSize;

		internal static ConfigEntry<int> DitherLevels;

		internal static ConfigEntry<float> DitherIntensity;

		internal static void Init(ConfigFile c)
		{
			DelaySeconds = c.Bind<float>("Doppleganger", "DelaySeconds", 5f, "How many seconds behind you the Doppleganger is (it forms this long after your first movement input).");
			TouchRadius = c.Bind<float>("Doppleganger", "TouchRadius", 0.9f, "Horizontal distance (m) at which the Doppleganger counts as touching you.");
			DrainPerSecond = c.Bind<float>("Doppleganger", "DrainPerSecond", 6f, "Health lost per second while touching the Doppleganger.");
			TickSeconds = c.Bind<float>("Doppleganger", "TickSeconds", 0.25f, "Seconds between damage ticks while touching.");
			MassSlow = c.Bind<float>("Doppleganger", "MassSlowInSubstructure", 0.15f, "How much slower the Mass is during Substructure (0.15 = 15% slower).");
			SubstructureNames = c.Bind<string>("Doppleganger", "SubstructureNames", "substructure", "Comma-separated, case-insensitive. If the current level, region or subregion name contains one of these, it counts as Substructure. The names the game uses are logged whenever you enter a new level.");
			ModelScale = c.Bind<float>("Doppleganger", "ModelScale", 1f, "Size of the Doppleganger relative to you (1 = same height).");
			LogLevels = c.Bind<bool>("Doppleganger", "LogLevels", true, "Log the level / region / subregion names and whether it's a safe area each time you enter a new level.");
			Animate = c.Bind<bool>("Doppleganger", "Animate", true, "Animate the legs (walking, jumping, dangling) and arms (reaching for the holds you grabbed). Turn off to keep the copy in a stiff T-pose.");
			MaxArmStretch = c.Bind<float>("Doppleganger", "MaxArmStretch", 4f, "How many times longer than normal its arms may stretch to reach a hold you grabbed (1 = no stretching).");
			ArmReachSpeed = c.Bind<float>("Doppleganger", "ArmReachSpeed", 20f, "How fast its hands snap onto a hold (higher = snappier).");
			GaitDegrees = c.Bind<float>("Doppleganger", "GaitDegrees", 38f, "How far its legs swing forward and back while running, in degrees.");
			TextureScale = c.Bind<float>("Doppleganger", "TextureScale", 1f, "Size of the speckles on its body (BakedTexture.png). 1 = as baked, 2 = twice as many, finer speckles, 0.5 = bigger ones. Takes effect the next time the game starts.");
			SmoothTexture = c.Bind<bool>("Doppleganger", "SmoothTexture", false, "false = nearest-neighbour texture (hard, crisp speckles). true = smooth (trilinear + mipmaps), which blurs the speckles but doesn't shimmer at a distance. Takes effect the next time the game starts.");
			Dither = c.Bind<bool>("Doppleganger", "Dither", true, "Dither its body texture like the Dithering group in Doppleganger.blend's compositor (Bayer 8x8). The following Dither options take effect the next time the game starts.");
			DitherPixelSize = c.Bind<int>("Doppleganger", "DitherPixelSize", 6, "Size of one dither pixel, in texels of the body texture (the blend used 3 screen pixels, about 6 texels at the model's size).");
			DitherLevels = c.Bind<int>("Doppleganger", "DitherLevels", 21, "Colour levels per channel (Color Amount in the blend; 21 there).");
			DitherIntensity = c.Bind<float>("Doppleganger", "DitherIntensity", 1f, "How strong the Bayer pattern is, 0..1 (1 in the blend). 0 = just the pixelation and colour levels, no pattern.");
		}
	}
	internal sealed class DopplegangerController : MonoBehaviour
	{
		private struct Sample
		{
			public float T;

			public Vector3 Feet;

			public float Yaw;

			public float Height;

			public float Width;

			public bool Grounded;

			public bool Grip0;

			public bool Grip1;

			public Vector3 GripPos0;

			public Vector3 GripPos1;
		}

		internal const string PerkId = "brokenshoes_doppleganger";

		internal static DopplegangerController Instance;

		private readonly List<Sample> _samples = new List<Sample>();

		private bool _active;

		private ENT_Player _player;

		private bool _waitingForInput;

		private bool _started;

		private float _t0;

		private bool _inSafe;

		private Vector3 _startPos;

		private float _standingHeight = 1.8f;

		private float _refHeight;

		private bool _loggedProportions;

		private GameObject _doppel;

		private DopplegangerAnimator _anim;

		private Vector3 _prevFeet;

		private bool _hasPrevFeet;

		private bool _doppelFailed;

		private float _touchTimer;

		private bool _hurtErrorLogged;

		private bool _massSlowed;

		private string _lastLevelKey;

		private void Awake()
		{
			Instance = this;
		}

		private void OnDestroy()
		{
			DestroyDoppel();
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
		}

		internal void OnWorldOffset(float amount)
		{
			if (_active)
			{
				for (int i = 0; i < _samples.Count; i++)
				{
					Sample value = _samples[i];
					value.Feet.y += amount;
					value.GripPos0.y += amount;
					value.GripPos1.y += amount;
					_samples[i] = value;
				}
				_startPos.y += amount;
				_prevFeet.y += amount;
			}
		}

		private void Update()
		{
			ENT_Player val