Decompiled source of SevenAmulets v0.4.7

SevenAmulets.dll

Decompiled 2 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.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PEAKLib.Core;
using PEAKLib.Items;
using Peak;
using Peak.Afflictions;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SevenAmulets")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SevenAmulets")]
[assembly: AssemblyTitle("SevenAmulets")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 SevenAmulets
{
	public class Action_Hospitality : ItemAction, IExtraFeedBehavior
	{
		private static float MaxRestore => Mathf.Clamp01(Plugin.HospitalityMaxRestore.Value);

		public override void RunAction()
		{
			Character character = ((ItemActionBase)this).character;
			if (!((Object)(object)character == (Object)null))
			{
				if ((Object)(object)((ItemActionBase)this).item.trueHolderCharacter == (Object)(object)character)
				{
					FeederAction(character, character);
				}
				float num = HungerToRestore(character);
				if (num > 0f)
				{
					character.refs.afflictions.SubtractStatus((STATUSTYPE)1, num, false, false);
				}
			}
		}

		public void FeedeeAction(Character fedCharacter, Character feeder)
		{
		}

		public void FeederAction(Character feeder, Character fedCharacter)
		{
			if (!((Object)(object)feeder == (Object)null) && !((Object)(object)fedCharacter == (Object)null))
			{
				float num = HungerToRestore(fedCharacter);
				float num2 = num * Plugin.HospitalityPetrifyPerHunger.Value;
				num2 = Mathf.Clamp(num2, Plugin.HospitalityMinPetrify.Value, Plugin.HospitalityMaxPetrify.Value);
				feeder.refs.afflictions.AddStatus((STATUSTYPE)13, num2 / 100f, false, true, true, false, false);
				Plugin.Debug($"Hospitality: {((Object)fedCharacter).name} hunger -{num:0.00}, {((Object)feeder).name} petrify +{num2:0}");
			}
		}

		private static float HungerToRestore(Character c)
		{
			return Mathf.Min(c.refs.afflictions.GetCurrentStatus((STATUSTYPE)1), MaxRestore);
		}
	}
	[HarmonyPatch]
	internal static class AmbitionPatches
	{
		private class Tick
		{
			public float next;
		}

		private static readonly ConditionalWeakTable<Affliction, Tick> Ticks = new ConditionalWeakTable<Affliction, Tick>();

		private static float _move = float.NaN;

		private static float _climb = float.NaN;

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Action_ModifyStatus), "RunAction")]
		private static void Cost_Prefix(Action_ModifyStatus __instance, out float __state)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Invalid comparison between Unknown and I4
			__state = float.NaN;
			if (Run.Active && (int)__instance.statusType == 13)
			{
				Action_ApplyAffliction component = ((Component)__instance).GetComponent<Action_ApplyAffliction>();
				if (!((Object)(object)component == (Object)null) && component.affliction is Affliction_RadiateInfiniteStam)
				{
					__state = __instance.changeAmount;
					__instance.changeAmount = Plugin.AmbitionPetrify.Value / 100f;
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Action_ModifyStatus), "RunAction")]
		private static void Cost_Postfix(Action_ModifyStatus __instance, float __state)
		{
			if (!float.IsNaN(__state))
			{
				__instance.changeAmount = __state;
			}
		}

		private static void LoadEnergyDrink()
		{
			if (!float.IsNaN(_move))
			{
				return;
			}
			_move = 1f;
			_climb = 1f;
			GameObject val = Resources.Load<GameObject>("0_Items/Energy Drink");
			Action_ApplyAffliction val2 = (((Object)(object)val != (Object)null) ? val.GetComponent<Action_ApplyAffliction>() : null);
			if ((Object)(object)val2 != (Object)null)
			{
				Affliction affliction = val2.affliction;
				Affliction_FasterBoi val3 = (Affliction_FasterBoi)(object)((affliction is Affliction_FasterBoi) ? affliction : null);
				if (val3 != null)
				{
					_move = val3.moveSpeedMod;
					_climb = val3.climbSpeedMod;
				}
			}
			Plugin.Debug($"Ambition speed uses energy drink values move={_move} climb={_climb}");
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Affliction_RadiateInfiniteStam), "UpdateEffectNetworked")]
		private static void Aura_Postfix(Affliction_RadiateInfiniteStam __instance)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			if (!Run.Active || !Plugin.AmbitionSpeed.Value)
			{
				return;
			}
			Character localCharacter = Character.localCharacter;
			if ((Object)(object)localCharacter == (Object)null || (Object)(object)((Affliction)__instance).character == (Object)null || localCharacter.data.dead)
			{
				return;
			}
			Tick orCreateValue = Ticks.GetOrCreateValue((Affliction)(object)__instance);
			if (!(Time.time < orCreateValue.next))
			{
				orCreateValue.next = Time.time + 0.5f;
				if (!(Vector3.Distance(localCharacter.Center, ((Affliction)__instance).character.Center) > __instance.radius))
				{
					LoadEnergyDrink();
					Effects.Refresh(localCharacter, (Affliction)new Affliction_FasterBoi
					{
						totalTime = 1f,
						moveSpeedMod = _move,
						climbSpeedMod = _climb,
						drowsyOnEnd = 0f,
						climbDelay = 0f
					});
				}
			}
		}
	}
	internal static class AmuletCatalog
	{
		internal sealed class Custom
		{
			public string Key;

			public string Display;

			public int Index;

			public Color Gem;

			public Type Action;

			public bool UseOnFriend;

			public Item Item;
		}

		internal static readonly string[] VanillaPrefabs = new string[4] { "0_Items/Amulet_Healing", "0_Items/Amulet_InfiniteStamina", "0_Items/Amulet_SuperJump", "0_Items/Amulet_Clone" };

		internal static readonly List<Custom> Customs = new List<Custom>
		{
			new Custom
			{
				Key = "Hospitality_Bear",
				Display = "Scout's Hospitality",
				Index = 4,
				Gem = new Color(0.25f, 0.45f, 1f),
				Action = typeof(Action_Hospitality),
				UseOnFriend = true
			},
			new Custom
			{
				Key = "Fellowship_Wolf",
				Display = "Scout's Fellowship",
				Index = 5,
				Gem = new Color(1f, 0.55f, 0.12f),
				Action = typeof(Action_Fellowship)
			},
			new Custom
			{
				Key = "Discipline_Gecko",
				Display = "Scout's Discipline",
				Index = 6,
				Gem = new Color(0.72f, 0.3f, 1f),
				Action = typeof(Action_Discipline)
			}
		};

		private static readonly Dictionary<int, Item> _byIndex = new Dictionary<int, Item>();

		private static GameObject _shelf;

		internal static int TypeCount
		{
			get
			{
				EnsureVanilla();
				return _byIndex.Count;
			}
		}

		internal static IEnumerable<int> AllIndices
		{
			get
			{
				EnsureVanilla();
				return _byIndex.Keys;
			}
		}

		internal static Item ItemFor(int index)
		{
			EnsureVanilla();
			if (!_byIndex.TryGetValue(index, out var value))
			{
				return null;
			}
			return value;
		}

		private static void EnsureVanilla()
		{
			if (_byIndex.Count >= 4)
			{
				return;
			}
			string[] vanillaPrefabs = VanillaPrefabs;
			foreach (string text in vanillaPrefabs)
			{
				GameObject val = Resources.Load<GameObject>(text);
				if ((Object)(object)val == (Object)null)
				{
					Plugin.Log.LogWarning((object)("Missing vanilla amulet " + text));
					continue;
				}
				AmuletBase component = val.GetComponent<AmuletBase>();
				Item component2 = val.GetComponent<Item>();
				if ((Object)(object)component != (Object)null && (Object)(object)component2 != (Object)null)
				{
					_byIndex[component.amuletIndex] = component2;
				}
			}
			foreach (Custom custom in Customs)
			{
				if ((Object)(object)custom.Item != (Object)null)
				{
					_byIndex[custom.Index] = custom.Item;
				}
			}
		}

		internal static void RegisterCustomItems(BepInPlugin owner)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Resources.Load<GameObject>("0_Items/Amulet_Healing");
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogError((object)"Could not find Amulet_Healing to build new amulets from.");
				return;
			}
			_shelf = new GameObject("SevenAmulets.Shelf");
			_shelf.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)_shelf);
			foreach (Custom custom in Customs)
			{
				try
				{
					custom.Item = Build(val, custom);
					new ItemContent(custom.Item).Register(ModDefinition.GetOrCreate(owner));
					Plugin.Log.LogInfo((object)$"Registered {custom.Display} (amulet index {custom.Index}).");
				}
				catch (Exception arg)
				{
					custom.Item = null;
					Plugin.Log.LogError((object)$"Failed to build {custom.Display}: {arg}");
				}
			}
			_byIndex.Clear();
		}

		private static Item Build(GameObject template, Custom c)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//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_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = Object.Instantiate<GameObject>(template, _shelf.transform);
			((Object)obj).name = "SA_Amulet_" + c.Key.Split('_')[0];
			Action_HealingGem component = obj.GetComponent<Action_HealingGem>();
			ItemAction val = (ItemAction)obj.AddComponent(c.Action);
			if ((Object)(object)component != (Object)null)
			{
				val.OnPressed = ((ItemAction)component).OnPressed;
				val.OnHeld = ((ItemAction)component).OnHeld;
				val.OnReleased = ((ItemAction)component).OnReleased;
				val.OnCastFinished = ((ItemAction)component).OnCastFinished;
				val.OnCancelled = ((ItemAction)component).OnCancelled;
				val.OnSecondaryCastFinished = ((ItemAction)component).OnSecondaryCastFinished;
				val.OnSecondaryPressed = ((ItemAction)component).OnSecondaryPressed;
				val.OnSecondaryHeld = ((ItemAction)component).OnSecondaryHeld;
				val.OnSecondaryCancelled = ((ItemAction)component).OnSecondaryCancelled;
				val.OnConsumed = ((ItemAction)component).OnConsumed;
				Object.DestroyImmediate((Object)(object)component);
			}
			else
			{
				val.OnCastFinished = true;
			}
			Item component2 = obj.GetComponent<Item>();
			component2.UIData.itemName = c.Display;
			component2.canUseOnFriend = c.UseOnFriend;
			if (!c.UseOnFriend)
			{
				component2.UIData.hasSecondInteract = false;
			}
			Texture2D val2 = Assets.Icon(c.Key);
			if ((Object)(object)val2 != (Object)null)
			{
				component2.UIData.icon = val2;
			}
			component2.UIData.hasAltIcon = false;
			component2.UIData.hasColorBlindIcon = false;
			AmuletBase component3 = obj.GetComponent<AmuletBase>();
			component3.amuletIndex = c.Index;
			component3.UIColor = c.Gem;
			LootData component4 = obj.GetComponent<LootData>();
			if ((Object)(object)component4 != (Object)null)
			{
				component4.spawnLocations = (SpawnPool)0;
			}
			Looks.Apply(obj, c.Key, c.Gem);
			return component2;
		}

		internal static Custom CustomFor(int index)
		{
			return Customs.Find((Custom x) => x.Index == index && (Object)(object)x.Item != (Object)null);
		}
	}
	internal static class Assets
	{
		private static readonly Dictionary<string, Mesh> _meshes = new Dictionary<string, Mesh>();

		private static readonly Dictionary<string, Texture2D> _icons = new Dictionary<string, Texture2D>();

		private static string ReadText(string name)
		{
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SevenAmulets." + name);
			if (stream == null)
			{
				return null;
			}
			using StreamReader streamReader = new StreamReader(stream);
			return streamReader.ReadToEnd();
		}

		private static byte[] ReadBytes(string name)
		{
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SevenAmulets." + name);
			if (stream == null)
			{
				return null;
			}
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			return memoryStream.ToArray();
		}

		internal static Texture2D Icon(string key)
		{
			return Png("icon_" + key + ".png");
		}

		internal static Texture2D Png(string file)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			if (_icons.TryGetValue(file, out var value))
			{
				return value;
			}
			byte[] array = ReadBytes(file);
			if (array == null)
			{
				return null;
			}
			value = new Texture2D(2, 2, (TextureFormat)4, true)
			{
				name = "SA_" + file
			};
			ImageConversion.LoadImage(value, array);
			((Texture)value).wrapMode = (TextureWrapMode)1;
			Object.DontDestroyOnLoad((Object)(object)value);
			_icons[file] = value;
			return value;
		}

		internal static Mesh Medallion(string key)
		{
			return Obj("Medallion_" + key + ".obj", singleSubmesh: false);
		}

		internal static Mesh Obj(string file, bool singleSubmesh)
		{
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0312: Expected O, but got Unknown
			//IL_012a: 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_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: 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_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: 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_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			if (_meshes.TryGetValue(file, out var value))
			{
				return value;
			}
			string text = ReadText(file);
			if (text == null)
			{
				return null;
			}
			List<Vector3> list = new List<Vector3>();
			List<Vector2> list2 = new List<Vector2>();
			List<Vector3> list3 = new List<Vector3>();
			List<Vector3> list4 = new List<Vector3>();
			List<Vector3> list5 = new List<Vector3>();
			List<Vector2> list6 = new List<Vector2>();
			Dictionary<string, List<int>> dictionary = new Dictionary<string, List<int>>
			{
				["gold"] = new List<int>(),
				["crystal"] = new List<int>()
			};
			string key = "gold";
			CultureInfo invariantCulture = CultureInfo.InvariantCulture;
			string[] array = text.Split('\n');
			for (int i = 0; i < array.Length; i++)
			{
				string text2 = array[i].Trim();
				if (text2.Length == 0)
				{
					continue;
				}
				string[] array2 = text2.Split(' ');
				switch (array2[0])
				{
				case "v":
					list.Add(new Vector3(float.Parse(array2[1], invariantCulture), float.Parse(array2[2], invariantCulture), float.Parse(array2[3], invariantCulture)));
					break;
				case "vt":
					list2.Add(new Vector2(float.Parse(array2[1], invariantCulture), float.Parse(array2[2], invariantCulture)));
					break;
				case "vn":
					list3.Add(new Vector3(float.Parse(array2[1], invariantCulture), float.Parse(array2[2], invariantCulture), float.Parse(array2[3], invariantCulture)));
					break;
				case "g":
					key = array2[1];
					if (!dictionary.ContainsKey(key))
					{
						dictionary[key] = new List<int>();
					}
					break;
				case "f":
				{
					int[] array3 = new int[3];
					for (int j = 0; j < 3; j++)
					{
						string[] array4 = array2[j + 1].Split('/');
						int index = int.Parse(array4[0]) - 1;
						int num = ((array4.Length > 1 && array4[1].Length > 0) ? (int.Parse(array4[1]) - 1) : (-1));
						int num2 = ((array4.Length > 2) ? (int.Parse(array4[2]) - 1) : (-1));
						Vector3 val = list[index];
						val.x = 0f - val.x;
						Vector3 val2 = ((num2 >= 0) ? list3[num2] : Vector3.forward);
						val2.x = 0f - val2.x;
						list4.Add(val);
						list5.Add(val2);
						list6.Add((num >= 0) ? list2[num] : Vector2.zero);
						array3[j] = list4.Count - 1;
					}
					dictionary[key].Add(array3[0]);
					dictionary[key].Add(array3[2]);
					dictionary[key].Add(array3[1]);
					break;
				}
				}
			}
			value = new Mesh
			{
				name = file.Replace(".obj", ""),
				indexFormat = (IndexFormat)1
			};
			value.SetVertices(list4);
			value.SetNormals(list5);
			value.SetUVs(0, list6);
			if (singleSubmesh)
			{
				List<int> list7 = new List<int>();
				foreach (KeyValuePair<string, List<int>> item in dictionary)
				{
					list7.AddRange(item.Value);
				}
				value.subMeshCount = 1;
				value.SetTriangles(list7, 0);
			}
			else
			{
				value.subMeshCount = 2;
				value.SetTriangles(dictionary["gold"], 0);
				value.SetTriangles(dictionary["crystal"], 1);
			}
			value.RecalculateBounds();
			value.RecalculateTangents();
			Object.DontDestroyOnLoad((Object)(object)value);
			_meshes[file] = value;
			return value;
		}
	}
	public class Action_CleansingSalt : ItemAction, IExtraFeedBehavior
	{
		public override void RunAction()
		{
			Character character = ((ItemActionBase)this).character;
			if (!((Object)(object)character == (Object)null) && character.IsLocal)
			{
				int num = Mathf.RoundToInt(Plugin.SaltPetrify.Value);
				character.data.SetPetrify(Mathf.Max(0, character.data.petrifyAmount - num));
				Plugin.Debug($"Cleansing Salt: petrify -{num} -> {character.data.petrifyAmount}");
			}
		}

		public void FeedeeAction(Character fedCharacter, Character feeder)
		{
		}

		public void FeederAction(Character feeder, Character fedCharacter)
		{
		}
	}
	[HarmonyPatch]
	internal static class CleansingSalt
	{
		internal static Item Item;

		private static readonly Color Pink = new Color(1f, 0.86f, 0.9f);

		internal static void Register(BepInPlugin owner)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: 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_0330: 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)
			GameObject val = Resources.Load<GameObject>("0_Items/Cure-All");
			GameObject val2 = Resources.Load<GameObject>("0_Items/Amulet_Healing");
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogError((object)"Cleansing Salt: Cure-All not found.");
				return;
			}
			GameObject val3 = new GameObject("SevenAmulets.SaltShelf");
			val3.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)val3);
			GameObject val4 = Object.Instantiate<GameObject>(val, val3.transform);
			((Object)val4).name = "SA_CleansingSalt";
			ItemAction val5 = null;
			Action_ModifyStatus[] components = val4.GetComponents<Action_ModifyStatus>();
			foreach (Action_ModifyStatus val6 in components)
			{
				if (val5 == null)
				{
					val5 = (ItemAction)(object)val6;
				}
				if ((Object)(object)val6 != (Object)(object)val5)
				{
					Object.DestroyImmediate((Object)(object)val6);
				}
			}
			Action_CleansingSalt action_CleansingSalt = val4.AddComponent<Action_CleansingSalt>();
			if ((Object)(object)val5 != (Object)null)
			{
				((ItemAction)action_CleansingSalt).OnPressed = val5.OnPressed;
				((ItemAction)action_CleansingSalt).OnHeld = val5.OnHeld;
				((ItemAction)action_CleansingSalt).OnReleased = val5.OnReleased;
				((ItemAction)action_CleansingSalt).OnCastFinished = val5.OnCastFinished;
				((ItemAction)action_CleansingSalt).OnCancelled = val5.OnCancelled;
				((ItemAction)action_CleansingSalt).OnSecondaryCastFinished = val5.OnSecondaryCastFinished;
				((ItemAction)action_CleansingSalt).OnConsumed = val5.OnConsumed;
				Object.DestroyImmediate((Object)(object)val5);
			}
			else
			{
				((ItemAction)action_CleansingSalt).OnCastFinished = true;
			}
			MonoBehaviour[] components2 = val4.GetComponents<MonoBehaviour>();
			foreach (MonoBehaviour val7 in components2)
			{
				switch (((Object)(object)val7 != (Object)null) ? ((object)val7).GetType().Name : "")
				{
				case "Action_AddOrRemoveThorns":
				case "Breakable":
				case "ItemCooking":
					Object.DestroyImmediate((Object)(object)val7);
					break;
				}
			}
			Item component = val4.GetComponent<Item>();
			component.totalUses = 1;
			component.UIData.itemName = "Cleansing Salt";
			Texture2D val8 = Assets.Icon("CleansingSalt");
			if ((Object)(object)val8 != (Object)null)
			{
				component.UIData.icon = val8;
			}
			component.UIData.hasAltIcon = false;
			component.UIData.hasColorBlindIcon = false;
			component.canUseOnFriend = true;
			component.itemTags = (ItemTags)(component.itemTags | 0x800);
			LootData component2 = val4.GetComponent<LootData>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.spawnLocations = (SpawnPool)0;
				component2.Rarity = (Rarity)3;
			}
			Mesh val9 = Assets.Obj("CleansingSalt.obj", singleSubmesh: true);
			Transform val10 = val4.transform.Find("Mesh");
			Transform val11 = val4.transform.Find("Jug");
			if (Object.op_Implicit((Object)(object)val11))
			{
				Object.DestroyImmediate((Object)(object)((Component)val11).gameObject);
			}
			Material val12 = null;
			MeshFilter val13 = (Object.op_Implicit((Object)(object)val2) ? Looks.FindMedallion(val2) : null);
			Material[] array = (Object.op_Implicit((Object)(object)val13) ? ((Renderer)((Component)val13).GetComponent<MeshRenderer>()).sharedMaterials : null);
			if (array != null && array.Length > 1)
			{
				val12 = Looks.Tinted(array[1], Pink, "_SA_Salt");
			}
			if (Object.op_Implicit((Object)(object)val10) && Object.op_Implicit((Object)(object)val9))
			{
				((Component)val10).GetComponent<MeshFilter>().sharedMesh = val9;
				MeshRenderer component3 = ((Component)val10).GetComponent<MeshRenderer>();
				if ((Object)(object)val12 != (Object)null)
				{
					((Renderer)component3).sharedMaterials = (Material[])(object)new Material[1] { val12 };
				}
				MeshCollider component4 = ((Component)val10).GetComponent<MeshCollider>();
				if (Object.op_Implicit((Object)(object)component4))
				{
					component4.sharedMesh = val9;
				}
			}
			Item = component;
			new ItemContent(component).Register(ModDefinition.GetOrCreate(owner));
			Plugin.Log.LogInfo((object)"Registered Cleansing Salt.");
		}

		internal static void SyncLoot()
		{
			if (!((Object)(object)Item == (Object)null) && LootData.AllSpawnWeightData != null && LootData.AllSpawnWeightData.TryGetValue((SpawnPool)32768, out var value))
			{
				bool flag = Run.Active && Plugin.SaltInLuggage.Value;
				bool flag2 = value.ContainsKey(Item.itemID);
				if (flag && !flag2)
				{
					value[Item.itemID] = LootData.RarityWeights[(Rarity)3];
				}
				else if (!flag && flag2)
				{
					value.Remove(Item.itemID);
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(LootData), "PopulateLootData")]
		private static void Populate_Postfix()
		{
			SyncLoot();
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(LootData), "GetRandomItems")]
		private static void GetItems_Prefix()
		{
			SyncLoot();
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(LootData), "GetRandomItem")]
		private static void GetItem_Prefix()
		{
			SyncLoot();
		}
	}
	public class Action_Discipline : ItemAction
	{
		public override void RunAction()
		{
			Character character = ((ItemActionBase)this).character;
			if (!((Object)(object)character == (Object)null) && character.IsLocal && !((Object)(object)((ItemActionBase)this).item.trueHolderCharacter != (Object)(object)character))
			{
				Discipline.ToggleLocal();
			}
		}
	}
	internal static class Discipline
	{
		private class Anchor
		{
			public int View;

			public Vector3 Pos;

			public Vector3 Normal;

			public float Ends;

			public float Started = Time.time;

			public GameObject Ledge;

			public ClimbHandle Handle;
		}

		[HarmonyPatch]
		private static class Patches
		{
			private static readonly FieldRef<CharacterClimbing, Character> ClimbChar = AccessTools.FieldRefAccess<CharacterClimbing, Character>("character");

			[HarmonyPrefix]
			[HarmonyPatch(typeof(CharacterClimbing), "StopClimbingRpc")]
			private static bool StopClimbing_Prefix(CharacterClimbing __instance)
			{
				return !IsAnchored(ClimbChar.Invoke(__instance));
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(Interaction), "DoInteractableRaycasts")]
			private static void Raycast_Postfix(ref IInteractible interactableResult)
			{
				IInteractible obj = interactableResult;
				CharacterInteractible val = (CharacterInteractible)(object)((obj is CharacterInteractible) ? obj : null);
				if (val == null || (Object)(object)val.character == (Object)null)
				{
					return;
				}
				Character localCharacter = Character.localCharacter;
				if (!((Object)(object)localCharacter == (Object)null) && !((Object)(object)val.character == (Object)(object)localCharacter) && Anchors.TryGetValue(val.character.refs.view.ViewID, out var value) && !((Object)(object)value.Handle == (Object)null) && !((Object)(object)value.Handle.hanger != (Object)null) && !(Time.time > value.Ends))
				{
					Item currentItem = localCharacter.data.currentItem;
					if (!((Object)(object)currentItem != (Object)null) || !currentItem.canUseOnFriend)
					{
						interactableResult = (IInteractible)(object)value.Handle;
					}
				}
			}

			[HarmonyPrefix]
			[HarmonyPatch(typeof(Character), "RPCA_Fall")]
			private static bool Fall_Prefix(Character __instance)
			{
				return !IsAnchored(__instance);
			}
		}

		private static readonly Dictionary<Character, float> _letGo = new Dictionary<Character, float>();

		private static readonly Action<ClimbHandle> BreakHandle = AccessTools.MethodDelegate<Action<ClimbHandle>>(AccessTools.Method(typeof(ClimbHandle), "Break", (Type[])null, (Type[])null), (object)null, true);

		private static readonly FieldRef<ClimbHandle, PhotonView> HandleView = AccessTools.FieldRefAccess<ClimbHandle, PhotonView>("view");

		private static readonly Dictionary<int, Anchor> Anchors = new Dictionary<int, Anchor>();

		private static float _restTick;

		private static float _selfTick;

		private static float _hold;

		private static float _releaseSent = -10f;

		private const float HoldTime = 0.8f;

		private static readonly Action<Character, Vector3, float> DragTowards = AccessTools.MethodDelegate<Action<Character, Vector3, float>>(AccessTools.Method(typeof(Character), "DragTowards", (Type[])null, (Type[])null), (object)null, true);

		private static readonly Action<Character> LimitFalling = AccessTools.MethodDelegate<Action<Character>>(AccessTools.Method(typeof(Character), "LimitFalling", (Type[])null, (Type[])null), (object)null, true);

		private static int DisciplineItemId
		{
			get
			{
				if (!((Object)(object)AmuletCatalog.CustomFor(6)?.Item != (Object)null))
				{
					return -1;
				}
				return AmuletCatalog.CustomFor(6).Item.itemID;
			}
		}

		private static Key AnchorKey
		{
			get
			{
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				if (!Enum.TryParse<Key>(Plugin.DisciplineKey.Value, ignoreCase: true, out Key result))
				{
					return (Key)21;
				}
				return result;
			}
		}

		internal static void Init()
		{
			Net.Received += OnEvent;
		}

		internal static bool IsAnchored(Character c)
		{
			if ((Object)(object)c != (Object)null && c.refs != null && (Object)(object)c.refs.view != (Object)null && Anchors.TryGetValue(c.refs.view.ViewID, out var value))
			{
				return Time.time < value.Ends;
			}
			return false;
		}

		private static bool HasDiscipline(Character c)
		{
			int disciplineItemId = DisciplineItemId;
			if (disciplineItemId < 0 || (Object)(object)c.player == (Object)null)
			{
				return false;
			}
			ItemSlot[] itemSlots = c.player.itemSlots;
			foreach (ItemSlot val in itemSlots)
			{
				if (val != null && !val.IsEmpty() && (Object)(object)val.prefab != (Object)null && val.prefab.itemID == disciplineItemId)
				{
					return true;
				}
			}
			return false;
		}

		internal static void ToggleLocal()
		{
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: 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_0153: 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_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			Character localCharacter = Character.localCharacter;
			if ((Object)(object)localCharacter == (Object)null || localCharacter.data.dead || localCharacter.data.passedOut)
			{
				return;
			}
			int viewID = localCharacter.refs.view.ViewID;
			if (IsAnchored(localCharacter))
			{
				Net.ToAll(174, viewID);
			}
			else if (localCharacter.data.petrifyAmount < 100 && (localCharacter.data.isClimbingAnything || localCharacter.data.isGrounded))
			{
				localCharacter.refs.afflictions.AddStatus((STATUSTYPE)13, Plugin.DisciplinePetrify.Value / 100f, false, true, true, false, false);
				Vector3 val = (localCharacter.data.isClimbing ? localCharacter.data.climbNormal : (-localCharacter.data.lookDirection));
				val.y = 0f;
				if (((Vector3)(ref val)).sqrMagnitude < 0.01f)
				{
					val = Vector3.forward;
				}
				((Vector3)(ref val)).Normalize();
				Vector3 center = localCharacter.Center;
				int num = PhotonNetwork.AllocateViewID(localCharacter.refs.view.OwnerActorNr);
				Net.ToAll(173, viewID, center.x, center.y, center.z, val.x, val.y, val.z, Plugin.DisciplineDuration.Value, num);
			}
		}

		private static void OnEvent(byte code, object[] d, int sender)
		{
			//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_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)
			switch (code)
			{
			case 173:
			{
				int num = Net.I(d[0]);
				Remove(num);
				Anchor anchor = new Anchor
				{
					View = num,
					Pos = new Vector3(Net.F(d[1]), Net.F(d[2]), Net.F(d[3])),
					Normal = new Vector3(Net.F(d[4]), Net.F(d[5]), Net.F(d[6])),
					Ends = Time.time + Net.F(d[7])
				};
				anchor.Ledge = MakeLedge(anchor);
				if (d.Length > 8)
				{
					anchor.Handle = MakeHandle(anchor, Net.I(d[8]));
				}
				Anchors[num] = anchor;
				Plugin.Debug($"Anchor start {num}");
				break;
			}
			case 174:
				Remove(Net.I(d[0]));
				break;
			}
		}

		private static void Remove(int view)
		{
			if (!Anchors.TryGetValue(view, out var value))
			{
				return;
			}
			if ((Object)(object)value.Ledge != (Object)null)
			{
				Object.Destroy((Object)(object)value.Ledge);
			}
			if ((Object)(object)value.Handle != (Object)null)
			{
				try
				{
					BreakHandle(value.Handle);
				}
				catch (Exception ex)
				{
					Plugin.Debug("Handle break: " + ex.Message);
				}
				Object.Destroy((Object)(object)((Component)value.Handle).gameObject, 1f);
			}
			Anchors.Remove(view);
			Plugin.Debug($"Anchor end {view}");
		}

		private static GameObject MakeLedge(Anchor a)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected O, but got Unknown
			if (!Plugin.DisciplineLadder.Value)
			{
				return null;
			}
			GameObject val = new GameObject("SA_DisciplineLedge")
			{
				layer = LayerMask.NameToLayer("Map")
			};
			val.transform.position = a.Pos + Vector3.up * 1.35f + a.Normal * 0.35f;
			val.transform.rotation = Quaternion.LookRotation(a.Normal, Vector3.up);
			val.AddComponent<BoxCollider>().size = new Vector3(1f, 0.18f, 0.7f);
			return val;
		}

		private static ClimbHandle MakeHandle(Anchor a, int viewId)
		{
			//IL_0005: 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_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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_0092: 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)
			try
			{
				GameObject val = new GameObject("SA_DisciplineGrip");
				val.SetActive(false);
				val.layer = LayerMask.NameToLayer("Default");
				val.transform.position = a.Pos + Vector3.down * 1f + a.Normal * 0.25f;
				val.transform.rotation = Quaternion.LookRotation(-a.Normal, Vector3.up);
				SphereCollider obj = val.AddComponent<SphereCollider>();
				((Collider)obj).isTrigger = true;
				obj.radius = 0.5f;
				PhotonView val2 = val.AddComponent<PhotonView>();
				ClimbHandle val3 = val.AddComponent<ClimbHandle>();
				val.SetActive(true);
				val2.ViewID = viewId;
				HandleView.Invoke(val3) = val2;
				return val3;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Discipline grip: " + ex.Message));
				return null;
			}
		}

		private static bool Airborne(Character c)
		{
			if (!c.data.isGrounded && !c.data.isClimbingAnything && (Object)(object)c.data.currentClimbHandle == (Object)null)
			{
				return c.data.sinceGrounded > 0.2f;
			}
			return false;
		}

		internal static void OnGUI()
		{
			//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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			//IL_00d7: 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_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			Character localCharacter = Character.localCharacter;
			if (!((Object)(object)localCharacter == (Object)null) && Anchors.TryGetValue(localCharacter.refs.view.ViewID, out var value))
			{
				int num = Mathf.Max(0, Mathf.CeilToInt(value.Ends - Time.time));
				int num2 = Mathf.Max(14, Screen.height / 50);
				GUIStyle val = new GUIStyle(GUI.skin.label)
				{
					alignment = (TextAnchor)4,
					fontSize = num2,
					fontStyle = (FontStyle)1
				};
				Rect val2 = default(Rect);
				((Rect)(ref val2))..ctor(0f, (float)Screen.height * 0.72f, (float)Screen.width, (float)num2 * 2f);
				string text = $"ANCHORED  {num}s   -   JUMP, RIGHT-CLICK or {Plugin.DisciplineKey.Value.ToUpperInvariant()} to let go";
				GUI.color = new Color(0f, 0f, 0f, 0.7f);
				GUI.Label(new Rect(((Rect)(ref val2)).x + 2f, ((Rect)(ref val2)).y + 2f, ((Rect)(ref val2)).width, ((Rect)(ref val2)).height), text, val);
				GUI.color = new Color(1f, 0.85f, 0.4f);
				GUI.Label(val2, text, val);
				GUI.color = Color.white;
			}
		}

		internal static void Tick()
		{
			//IL_00d2: 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_036e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_037e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Expected O, but got Unknown
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0407: Expected O, but got Unknown
			//IL_047f: Unknown result type (might be due to invalid IL or missing references)
			//IL_046c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0484: Unknown result type (might be due to invalid IL or missing references)
			//IL_0486: Unknown result type (might be due to invalid IL or missing references)
			//IL_0489: Unknown result type (might be due to invalid IL or missing references)
			//IL_048e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0493: Unknown result type (might be due to invalid IL or missing references)
			//IL_0497: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04af: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_05aa: Unknown result type (might be due to invalid IL or missing references)
			Character localCharacter = Character.localCharacter;
			if (Anchors.Count > 0)
			{
				List<int> list = new List<int>();
				foreach (KeyValuePair<int, Anchor> anchor in Anchors)
				{
					if (Time.time > anchor.Value.Ends + 1f)
					{
						list.Add(anchor.Key);
					}
				}
				foreach (int item in list)
				{
					Remove(item);
				}
			}
			if ((Object)(object)localCharacter == (Object)null)
			{
				return;
			}
			int viewID = localCharacter.refs.view.ViewID;
			if (Run.Active && Keyboard.current != null && ((ButtonControl)Keyboard.current[AnchorKey]).wasPressedThisFrame && HasDiscipline(localCharacter))
			{
				ToggleLocal();
			}
			bool flag = Run.Active && localCharacter.data.isClimbingAnything && localCharacter.data.climbingSpikeCount <= 0 && HasDiscipline(localCharacter);
			if (localCharacter.input.useSecondaryWasPressed && localCharacter.data.isClimbingAnything && !flag && Run.Active)
			{
				Plugin.Log.LogInfo((object)$"Discipline: right-click on a wall ignored - Discipline in pockets: {HasDiscipline(localCharacter)}, pitons carried: {localCharacter.data.climbingSpikeCount} (a piton takes right-click; use the {Plugin.DisciplineKey.Value} key)");
			}
			if (flag && localCharacter.input.useSecondaryIsPressed)
			{
				_hold += Time.deltaTime;
				if (_hold >= 0.8f)
				{
					ToggleLocal();
					_hold = float.NegativeInfinity;
				}
			}
			else
			{
				_hold = 0f;
			}
			if (Anchors.Count == 0)
			{
				return;
			}
			if (Anchors.TryGetValue(viewID, out var value))
			{
				if ((localCharacter.input.jumpWasPressed || localCharacter.input.useSecondaryWasPressed || (Keyboard.current != null && ((ButtonControl)Keyboard.current[AnchorKey]).wasPressedThisFrame && !HasDiscipline(localCharacter))) && Time.time - value.Started > 0.5f && Time.time > _releaseSent + 0.5f)
				{
					_releaseSent = Time.time;
					Net.ToAll(174, viewID);
					Plugin.Debug("Discipline: let go early");
				}
				else if (Time.time > value.Ends || localCharacter.data.dead)
				{
					Net.ToAll(174, viewID);
				}
				else
				{
					if (Time.time > _selfTick)
					{
						_selfTick = Time.time + 0.5f;
						Effects.Refresh(localCharacter, (Affliction)new Affliction_InfiniteStamina(1f));
					}
					Vector3 val = value.Pos - localCharacter.Center;
					if (((Vector3)(ref val)).magnitude > 0.25f)
					{
						DragTowards(localCharacter, value.Pos, 80f);
					}
					LimitFalling(localCharacter);
				}
			}
			if (localCharacter.data.dead)
			{
				return;
			}
			Vector3 val5 = default(Vector3);
			foreach (Anchor value3 in Anchors.Values)
			{
				if (value3.View == viewID || Time.time > value3.Ends)
				{
					continue;
				}
				Vector3 val2 = value3.Pos - localCharacter.Center;
				if ((localCharacter.data.isClimbing || localCharacter.data.isRopeClimbing || ((Object)(object)localCharacter.data.currentClimbHandle == (Object)(object)value3.Handle && (Object)(object)value3.Handle != (Object)null)) && ((Vector3)(ref val2)).magnitude <= Plugin.DisciplineRestRadius.Value + 1.5f)
				{
					if (Time.time > _restTick)
					{
						_restTick = Time.time + 0.5f;
						Effects.Refresh(localCharacter, (Affliction)new Affliction_InfiniteStamina(1f));
					}
					localCharacter.AddStamina(Plugin.DisciplineRestRegen.Value * Time.deltaTime);
				}
				if ((Object)(object)value3.Handle != (Object)null && (Object)(object)localCharacter.data.currentClimbHandle == (Object)(object)value3.Handle)
				{
					_letGo[localCharacter] = Time.time;
				}
				bool num = Airborne(localCharacter);
				Vector3 val3 = (((Object)(object)value3.Handle != (Object)null) ? ((Component)value3.Handle).transform.position : value3.Pos);
				Vector3 val4 = val3 - localCharacter.Center;
				((Vector3)(ref val5))..ctor(val4.x, 0f, val4.z);
				float num2 = val3.y - localCharacter.Center.y;
				float value2;
				bool flag2 = _letGo.TryGetValue(localCharacter, out value2) && Time.time - value2 < 1.5f;
				if (num && !flag2 && ((Vector3)(ref val5)).magnitude <= Plugin.DisciplineBelayRadius.Value && num2 > -2f && num2 < 12f)
				{
					if ((Object)(object)value3.Handle != (Object)null && (Object)(object)value3.Handle.hanger == (Object)null && ((Vector3)(ref val4)).magnitude <= Plugin.DisciplineGrabRadius.Value)
					{
						HandleView.Invoke(value3.Handle).RPC("RPCA_Hang", (RpcTarget)0, new object[1] { localCharacter.refs.view });
						_letGo[localCharacter] = Time.time;
						Plugin.Debug("Discipline: caught onto an anchored scout");
					}
					else
					{
						DragTowards(localCharacter, val3, Plugin.DisciplineBelayPull.Value);
						LimitFalling(localCharacter);
					}
				}
			}
		}
	}
	internal static class Effects
	{
		internal static void Refresh(Character c, Affliction fresh)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)c == (Object)null) && fresh != null)
			{
				CharacterAfflictions afflictions = c.refs.afflictions;
				Affliction val = default(Affliction);
				if (afflictions.HasAfflictionType(fresh.GetAfflictionType(), ref val) && val != null)
				{
					val.totalTime = Mathf.Max(val.totalTime, val.timeElapsed + fresh.totalTime);
				}
				else
				{
					afflictions.AddAffliction(fresh, false);
				}
			}
		}
	}
	public class Action_Fellowship : ItemAction
	{
		public override void RunAction()
		{
			Character character = ((ItemActionBase)this).character;
			if (!((Object)(object)character == (Object)null) && character.refs.view.IsMine && !((Object)(object)((ItemActionBase)this).item.trueHolderCharacter != (Object)(object)character))
			{
				Fellowship.Activate(character);
			}
		}
	}
	internal static class Fellowship
	{
		private static Character _user;

		private static float _reservoir;

		private static float _endTime;

		private static float _extraAtStart;

		internal static void Init()
		{
			Net.Received += OnEvent;
		}

		internal static void Activate(Character user)
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: 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_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: 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)
			if ((Object)(object)_user != (Object)null && (Object)(object)_user != (Object)(object)user)
			{
				End();
			}
			user.refs.afflictions.AddStatus((STATUSTYPE)13, Plugin.FellowshipPetrify.Value / 100f, false, true, true, false, false);
			_user = user;
			_reservoir = 0f;
			_extraAtStart = user.data.extraStamina;
			_endTime = Time.time + Plugin.FellowshipDuration.Value;
			Vector3 center = user.Center;
			float value = Plugin.FellowshipRadius.Value;
			int num = 0;
			foreach (Character allCharacter in Character.AllCharacters)
			{
				if (!((Object)(object)allCharacter == (Object)null) && !((Object)(object)allCharacter == (Object)(object)user) && allCharacter.refs.view.IsMine && !allCharacter.isBot && !(Vector3.Distance(allCharacter.Center, center) > value))
				{
					float num2 = Drain(allCharacter);
					if (num2 > 0f)
					{
						_reservoir += num2;
						num++;
					}
				}
			}
			if (PhotonNetwork.InRoom && !PhotonNetwork.OfflineMode)
			{
				Net.ToOthers(171, user.refs.view.ViewID, center.x, center.y, center.z, value);
			}
			Plugin.Log.LogInfo((object)$"Fellowship activated by {user.characterName}: {num} local teammate(s) drained, reservoir {_reservoir:0.00}");
		}

		private static float Drain(Character c)
		{
			if (c.data.dead || c.data.fullyPassedOut || c.infiniteStam)
			{
				return 0f;
			}
			float num = c.data.currentStamina + c.data.extraStamina;
			if (num <= 0.001f)
			{
				return 0f;
			}
			c.AddStamina(0f - c.data.currentStamina);
			c.SetExtraStamina(0f);
			return num;
		}

		private static void OnEvent(byte code, object[] d, int sender)
		{
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			switch (code)
			{
			case 171:
			{
				int num = Net.I(d[0]);
				Vector3 val = default(Vector3);
				((Vector3)(ref val))..ctor(Net.F(d[1]), Net.F(d[2]), Net.F(d[3]));
				float num2 = Net.F(d[4]);
				float num3 = 0f;
				foreach (Character allCharacter in Character.AllCharacters)
				{
					if (!((Object)(object)allCharacter == (Object)null) && allCharacter.refs.view.IsMine && !allCharacter.isBot && allCharacter.refs.view.ViewID != num && !(Vector3.Distance(allCharacter.Center, val) > num2))
					{
						num3 += Drain(allCharacter);
					}
				}
				if (!(num3 <= 0.001f))
				{
					Net.ToActor(sender, 172, num, num3);
					Plugin.Debug($"Fellowship: gave {num3:0.00} stamina");
				}
				break;
			}
			case 172:
				if (!((Object)(object)_user == (Object)null) && _user.refs.view.ViewID == Net.I(d[0]))
				{
					_reservoir += Net.F(d[1]);
					Plugin.Debug($"Fellowship: received, reservoir {_reservoir:0.00}");
				}
				break;
			}
		}

		internal static void Tick()
		{
			if ((Object)(object)_user == (Object)null)
			{
				return;
			}
			if (_user.data.dead || Time.time > _endTime)
			{
				End();
			}
			else if (!(_reservoir <= 0f))
			{
				float num = 1f - (float)_user.data.petrifyAmount * 0.01f - _user.data.extraStamina;
				if (!(num <= 0.001f))
				{
					float num2 = Mathf.Min(num, _reservoir);
					_user.AddExtraStamina(num2);
					_reservoir -= num2;
				}
			}
		}

		private static void End()
		{
			Character user = _user;
			_user = null;
			_reservoir = 0f;
			if ((Object)(object)user != (Object)null && user.data.extraStamina > _extraAtStart)
			{
				user.SetExtraStamina(_extraAtStart);
			}
			Plugin.Debug("Fellowship ended");
		}
	}
	internal static class Looks
	{
		private static readonly string[] ColorProps = new string[11]
		{
			"_BaseColor", "_Tint", "_Color1", "_Color", "_TintColor", "_MainColor", "_CrystalColor", "_GlowColor", "_EmissionColor", "_Emission_Color",
			"_CrackColor"
		};

		private static readonly string[] TexProps = new string[10] { "_BaseTexture", "_Texture1", "_BaseMap", "_MainTex", "_BaseColorMap", "_Albedo", "_AlbedoMap", "_MainTexture", "_Texture", "_Tex" };

		internal static MeshFilter FindMedallion(GameObject root)
		{
			MeshFilter[] componentsInChildren = root.GetComponentsInChildren<MeshFilter>(true);
			foreach (MeshFilter val in componentsInChildren)
			{
				if ((Object)(object)val.sharedMesh != (Object)null && ((Object)val.sharedMesh).name.StartsWith("Medallion"))
				{
					return val;
				}
			}
			MeshRenderer[] componentsInChildren2 = root.GetComponentsInChildren<MeshRenderer>(true);
			foreach (MeshRenderer val2 in componentsInChildren2)
			{
				Material[] sharedMaterials = ((Renderer)val2).sharedMaterials;
				foreach (Material val3 in sharedMaterials)
				{
					if ((Object)(object)val3 != (Object)null && ((Object)val3).name.Contains("Medallion"))
					{
						return ((Component)val2).GetComponent<MeshFilter>();
					}
				}
			}
			return null;
		}

		internal static Material TintedCrystal(Material original, Color gem)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			Material val = new Material(original)
			{
				name = ((Object)original).name + "_SA"
			};
			int num = 0;
			string[] colorProps = ColorProps;
			float num2 = default(float);
			float num3 = default(float);
			float num4 = default(float);
			float num5 = default(float);
			float num6 = default(float);
			foreach (string text in colorProps)
			{
				if (val.HasProperty(text))
				{
					Color color = val.GetColor(text);
					Color.RGBToHSV(color, ref num2, ref num3, ref num4);
					Color.RGBToHSV(gem, ref num5, ref num6, ref num3);
					Color val2 = Color.HSVToRGB(num5, Mathf.Max(num6, 0.6f), Mathf.Max(num4, 0.05f), true);
					val2.a = color.a;
					val.SetColor(text, val2);
					num++;
				}
			}
			if (Plugin.DebugLogging.Value)
			{
				Shader shader = val.shader;
				StringBuilder stringBuilder = new StringBuilder();
				for (int j = 0; j < shader.GetPropertyCount(); j++)
				{
					stringBuilder.Append(shader.GetPropertyName(j)).Append(' ');
				}
				Plugin.Debug($"Crystal shader '{((Object)shader).name}' props: {stringBuilder} (tinted {num})");
			}
			Object.DontDestroyOnLoad((Object)(object)val);
			return val;
		}

		internal static Material Tinted(Material original, Color tint, string suffix)
		{
			//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_0024: Expected O, but got Unknown
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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_0078: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)original == (Object)null)
			{
				return null;
			}
			Material val = new Material(original)
			{
				name = ((Object)original).name + suffix
			};
			string[] colorProps = ColorProps;
			float num = default(float);
			float num2 = default(float);
			float num3 = default(float);
			float num4 = default(float);
			float num5 = default(float);
			foreach (string text in colorProps)
			{
				if (val.HasProperty(text))
				{
					Color color = val.GetColor(text);
					Color.RGBToHSV(color, ref num, ref num2, ref num3);
					Color.RGBToHSV(tint, ref num4, ref num5, ref num2);
					Color val2 = Color.HSVToRGB(num4, Mathf.Max(num5, 0.35f), Mathf.Max(num3, 0.05f), true);
					val2.a = color.a;
					val.SetColor(text, val2);
				}
			}
			Object.DontDestroyOnLoad((Object)(object)val);
			return val;
		}

		internal static Material Retextured(Material original, Texture2D tex, string suffix)
		{
			//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_002d: Expected O, but got Unknown
			//IL_0054: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Invalid comparison between Unknown and I4
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)original == (Object)null || (Object)(object)tex == (Object)null)
			{
				return original;
			}
			Material val = new Material(original)
			{
				name = ((Object)original).name + suffix
			};
			bool flag = false;
			string[] texProps = TexProps;
			foreach (string text in texProps)
			{
				if (val.HasProperty(text))
				{
					val.SetTexture(text, (Texture)(object)tex);
					val.SetTextureScale(text, Vector2.one);
					val.SetTextureOffset(text, Vector2.zero);
					flag = true;
				}
			}
			if (!flag)
			{
				Shader shader = val.shader;
				for (int j = 0; j < shader.GetPropertyCount(); j++)
				{
					if ((int)shader.GetPropertyType(j) == 4)
					{
						val.SetTexture(shader.GetPropertyName(j), (Texture)(object)tex);
						flag = true;
						break;
					}
				}
			}
			texProps = new string[2] { "_BaseColor", "_Color" };
			foreach (string text2 in texProps)
			{
				if (val.HasProperty(text2))
				{
					val.SetColor(text2, Color.white);
				}
			}
			if (Plugin.DebugLogging.Value)
			{
				Shader shader2 = val.shader;
				StringBuilder stringBuilder = new StringBuilder();
				for (int k = 0; k < shader2.GetPropertyCount(); k++)
				{
					stringBuilder.Append(shader2.GetPropertyName(k)).Append(' ');
				}
				Plugin.Debug($"Retextured '{((Object)original).name}' (shader {((Object)shader2).name}, set={flag}): {stringBuilder}");
			}
			Object.DontDestroyOnLoad((Object)(object)val);
			return val;
		}

		internal static void Apply(GameObject go, string key, Color gem)
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: 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_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: 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_0138: Unknown result type (might be due to invalid IL or missing references)
			Mesh val = Assets.Medallion(key);
			MeshFilter val2 = FindMedallion(go);
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				Plugin.Log.LogWarning((object)$"Could not apply model for {key} (mesh {(Object)(object)val != (Object)null}, medallion {(Object)(object)val2 != (Object)null})");
				return;
			}
			MeshRenderer component = ((Component)val2).GetComponent<MeshRenderer>();
			Material[] sharedMaterials = ((Renderer)component).sharedMaterials;
			Material val3 = ((sharedMaterials.Length != 0) ? sharedMaterials[0] : null);
			Material val4 = ((sharedMaterials.Length > 1) ? TintedCrystal(sharedMaterials[1], gem) : null);
			val2.sharedMesh = val;
			((Renderer)component).sharedMaterials = (Material[])(object)((!((Object)(object)val4 != (Object)null)) ? new Material[2] { val3, val3 } : new Material[2] { val3, val4 });
			((Object)((Component)val2).gameObject).name = "Medallion_" + key;
			MeshCollider component2 = ((Component)val2).GetComponent<MeshCollider>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.sharedMesh = val;
			}
			ParticleSystem[] componentsInChildren = go.GetComponentsInChildren<ParticleSystem>(true);
			foreach (ParticleSystem val5 in componentsInChildren)
			{
				if (((Object)((Component)val5).gameObject).name.StartsWith("AmuletGlow"))
				{
					MainModule main = val5.main;
					Color val6 = gem;
					MinMaxGradient startColor = ((MainModule)(ref main)).startColor;
					val6.a = ((MinMaxGradient)(ref startColor)).color.a;
					((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(val6);
				}
			}
		}

		internal static bool CopyLook(GameObject target, Item from)
		{
			if ((Object)(object)target == (Object)null || (Object)(object)from == (Object)null)
			{
				return false;
			}
			MeshFilter val = FindMedallion(((Component)from).gameObject);
			MeshFilter val2 = FindMedallion(target);
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				return false;
			}
			val2.sharedMesh = val.sharedMesh;
			MeshRenderer component = ((Component)val).GetComponent<MeshRenderer>();
			MeshRenderer component2 = ((Component)val2).GetComponent<MeshRenderer>();
			if ((Object)(object)component != (Object)null && (Object)(object)component2 != (Object)null)
			{
				((Renderer)component2).sharedMaterials = ((Renderer)component).sharedMaterials;
			}
			MeshCollider component3 = ((Component)val2).GetComponent<MeshCollider>();
			if ((Object)(object)component3 != (Object)null)
			{
				component3.sharedMesh = val.sharedMesh;
			}
			return true;
		}
	}
	internal static class Net
	{
		internal const byte FellowshipRequest = 171;

		internal const byte FellowshipGive = 172;

		internal const byte AnchorStart = 173;

		internal const byte AnchorEnd = 174;

		private static bool _hooked;

		internal static event Action<byte, object[], int> Received;

		internal static void Hook()
		{
			if (!_hooked && PhotonNetwork.NetworkingClient != null)
			{
				PhotonNetwork.NetworkingClient.EventReceived += OnEvent;
				_hooked = true;
			}
		}

		private static void OnEvent(EventData e)
		{
			if (e.Code < 171 || e.Code > 174 || !(e.CustomData is object[] arg))
			{
				return;
			}
			try
			{
				Net.Received?.Invoke(e.Code, arg, e.Sender);
			}
			catch (Exception arg2)
			{
				Plugin.Log.LogError((object)$"Event {e.Code} failed: {arg2}");
			}
		}

		internal static void ToAll(byte code, params object[] data)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			if (PhotonNetwork.InRoom)
			{
				PhotonNetwork.RaiseEvent(code, (object)data, new RaiseEventOptions
				{
					Receivers = (ReceiverGroup)1
				}, SendOptions.SendReliable);
				return;
			}
			Action<byte, object[], int> received = Net.Received;
			if (received != null)
			{
				Player localPlayer = PhotonNetwork.LocalPlayer;
				received(code, data, (localPlayer != null) ? localPlayer.ActorNumber : 0);
			}
		}

		internal static void ToOthers(byte code, params object[] data)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			if (PhotonNetwork.InRoom)
			{
				PhotonNetwork.RaiseEvent(code, (object)data, new RaiseEventOptions
				{
					Receivers = (ReceiverGroup)0
				}, SendOptions.SendReliable);
			}
		}

		internal static void ToActor(int actor, byte code, params object[] data)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if (PhotonNetwork.InRoom)
			{
				RaiseEventOptions val = new RaiseEventOptions();
				val.TargetActors = new int[1] { actor };
				PhotonNetwork.RaiseEvent(code, (object)data, val, SendOptions.SendReliable);
			}
			else
			{
				Net.Received?.Invoke(code, data, actor);
			}
		}

		internal static float F(object o)
		{
			return Convert.ToSingle(o);
		}

		internal static int I(object o)
		{
			return Convert.ToInt32(o);
		}
	}
	[BepInPlugin("com.wolfb.peak.sevenamulets", "Seven Amulets", "0.4.7")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "com.wolfb.peak.sevenamulets";

		public const string Name = "Seven Amulets";

		public const string Version = "0.4.7";

		internal static ManualLogSource Log;

		internal static Plugin Instance;

		internal static ConfigEntry<bool> OnlyInFinalAscent;

		internal static ConfigEntry<float> AmbitionPetrify;

		internal static ConfigEntry<bool> AmbitionSpeed;

		internal static ConfigEntry<float> HospitalityMaxRestore;

		internal static ConfigEntry<float> HospitalityPetrifyPerHunger;

		internal static ConfigEntry<float> HospitalityMinPetrify;

		internal static ConfigEntry<float> HospitalityMaxPetrify;

		internal static ConfigEntry<bool> DebugLogging;

		internal static ConfigEntry<float> FellowshipPetrify;

		internal static ConfigEntry<float> FellowshipRadius;

		internal static ConfigEntry<float> FellowshipDuration;

		internal static ConfigEntry<string> DisciplineKey;

		internal static ConfigEntry<float> DisciplinePetrify;

		internal static ConfigEntry<float> DisciplineDuration;

		internal static ConfigEntry<float> DisciplineRestRadius;

		internal static ConfigEntry<float> DisciplineRestRegen;

		internal static ConfigEntry<float> DisciplineBelayRadius;

		internal static ConfigEntry<float> DisciplineBelayPull;

		internal static ConfigEntry<float> DisciplineGrabRadius;

		internal static ConfigEntry<bool> DisciplineLadder;

		internal static ConfigEntry<bool> SpringsEnabled;

		internal static ConfigEntry<bool> SaltInLuggage;

		internal static ConfigEntry<float> SpringPetrifyPerTick;

		internal static ConfigEntry<float> SpringInterval;

		internal static ConfigEntry<float> SpringScale;

		internal static ConfigEntry<float> SpringMinDistance;

		internal static ConfigEntry<float> SpringMaxDistance;

		internal static ConfigEntry<float> SaltPetrify;

		private void Awake()
		{
			//IL_04b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bd: Expected O, but got Unknown
			//IL_04bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			OnlyInFinalAscent = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "OnlyInFinalAscent", true, "Only change anything when a True Final Ascent run is active. Normal runs stay vanilla.");
			DebugLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DebugLogging", false, "Extra log lines for testing.");
			AmbitionPetrify = ((BaseUnityPlugin)this).Config.Bind<float>("Ambition", "PetrifyPerUse", 35f, "Petrify cost per use of Scout's Ambition during the mod (vanilla is 30).");
			AmbitionSpeed = ((BaseUnityPlugin)this).Config.Bind<bool>("Ambition", "SpeedBoost", true, "Ambition's aura also gives the energy drink speed boost (walk + climb), with no drowsiness.");
			HospitalityMaxRestore = ((BaseUnityPlugin)this).Config.Bind<float>("Hospitality", "MaxHungerRestored", 0.6f, "Most hunger removed per use, as a fraction of the bar (0.6 = 60%).");
			HospitalityPetrifyPerHunger = ((BaseUnityPlugin)this).Config.Bind<float>("Hospitality", "PetrifyPerHunger", 40f, "Petrify added per full hunger bar restored (scales with how much it actually fills).");
			HospitalityMinPetrify = ((BaseUnityPlugin)this).Config.Bind<float>("Hospitality", "MinPetrify", 5f, "Minimum petrify per use.");
			HospitalityMaxPetrify = ((BaseUnityPlugin)this).Config.Bind<float>("Hospitality", "MaxPetrify", 24f, "Maximum petrify per use.");
			FellowshipPetrify = ((BaseUnityPlugin)this).Config.Bind<float>("Fellowship", "PetrifyPerUse", 20f, "Petrify cost per use.");
			FellowshipRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Fellowship", "Radius", 8f, "Teammates within this many metres are drained.");
			FellowshipDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Fellowship", "Duration", 20f, "Seconds the pooled stamina lasts.");
			DisciplineKey = ((BaseUnityPlugin)this).Config.Bind<string>("Discipline", "AnchorKey", "G", "Key to anchor / let go while Discipline is in your inventory (Unity Input System key name, e.g. G, V, B).");
			DisciplinePetrify = ((BaseUnityPlugin)this).Config.Bind<float>("Discipline", "PetrifyPerUse", 10f, "Petrify cost per anchor.");
			DisciplineDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Discipline", "MaxSeconds", 30f, "Longest an anchor lasts.");
			DisciplineRestRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Discipline", "RestRadius", 2.5f, "Teammates climbing this close to you rest.");
			DisciplineRestRegen = ((BaseUnityPlugin)this).Config.Bind<float>("Discipline", "RestRegenPerSecond", 0.1f, "Stamina regained per second while resting (1 = full bar).");
			DisciplineBelayRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Discipline", "BelayRadius", 5f, "Falling teammates within this horizontal distance get caught.");
			DisciplineGrabRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Discipline", "GrabRadius", 2.5f, "Falling teammates this close to an anchored scout's grip catch onto it automatically, like grabbing a piton.");
			DisciplineBelayPull = ((BaseUnityPlugin)this).Config.Bind<float>("Discipline", "BelayPull", 120f, "How hard caught teammates are pulled to you.");
			DisciplineLadder = ((BaseUnityPlugin)this).Config.Bind<bool>("Discipline", "HumanLadder", true, "Put a small ledge above the anchored scout's head for teammates to stand on.");
			SpringsEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Purifying Springs", "Enabled", true, "Place Purifying Springs in Final Ascent runs.");
			SpringPetrifyPerTick = ((BaseUnityPlugin)this).Config.Bind<float>("Purifying Springs", "PetrifyRemoved", 5f, "Petrify removed each tick while standing in the water.");
			SpringInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Purifying Springs", "SecondsPerTick", 3f, "Seconds between ticks.");
			SpringScale = ((BaseUnityPlugin)this).Config.Bind<float>("Purifying Springs", "Scale", 0.7f, "Size of the spring compared to the Alpine onsen.");
			SpringMinDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Purifying Springs", "MinDistanceFromStatue", 25f, "Closest a spring is placed to its amulet statue (metres).");
			SpringMaxDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Purifying Springs", "MaxDistanceFromStatue", 75f, "Farthest a spring is placed from its amulet statue (metres).");
			SaltInLuggage = ((BaseUnityPlugin)this).Config.Bind<bool>("Cleansing Salt", "InAncientLuggage", true, "Cleansing Salt can be found in Ancient Luggage (Epic rarity) during Final Ascent runs.");
			SaltPetrify = ((BaseUnityPlugin)this).Config.Bind<float>("Cleansing Salt", "PetrifyRemoved", 30f, "Petrify removed by eating one (30 = 30% of the bar).");
			Step("True Final Ascent hook", Tfa.Init);
			Step("Fellowship", Fellowship.Init);
			Step("Discipline", Discipline.Init);
			Step("New amulet items", delegate
			{
				AmuletCatalog.RegisterCustomItems(((BaseUnityPlugin)this).Info.Metadata);
			});
			Step("Cleansing Salt", delegate
			{
				CleansingSalt.Register(((BaseUnityPlugin)this).Info.Metadata);
			});
			Step("Harmony patches", delegate
			{
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				new Harmony("com.wolfb.peak.sevenamulets").PatchAll(typeof(Plugin).Assembly);
			});
			GameObject val = new GameObject("SevenAmulets.Runner");
			Object.DontDestroyOnLoad((Object)val);
			((Object)val).hideFlags = (HideFlags)61;
			val.AddComponent<StatueShuffler>();
			val.AddComponent<Runner>();
			val.AddComponent<Springs>();
			Log.LogInfo((object)string.Format("{0} {1} loaded. True Final Ascent found: {2}", "Seven Amulets", "0.4.7", Tfa.Installed));
		}

		private static void Step(string what, Action a)
		{
			try
			{
				a();
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Startup step '{what}' failed: {arg}");
			}
		}

		internal static void Debug(string msg)
		{
			if (DebugLogging != null && DebugLogging.Value)
			{
				Log.LogInfo((object)msg);
			}
		}
	}
	internal static class Run
	{
		internal static readonly string[] Spots = new string[7] { "Beach", "Tropics", "Roots", "Alpine", "Mesa", "Caldera", "Gloom" };

		internal const int MinSpots = 5;

		private static readonly Dictionary<int, int> _typeForSpot = new Dictionary<int, int>();

		private static int _lastCount = -1;

		private static int _stable;

		internal static int Seed { get; private set; } = int.MinValue;

		internal static bool Decided { get; private set; }

		internal static bool On { get; private set; }

		internal static int SpotCount { get; private set; }

		internal static HashSet<int> Included { get; private set; } = new HashSet<int>();

		internal static bool Active
		{
			get
			{
				if (Tfa.ModActive)
				{
					return On;
				}
				return false;
			}
		}

		internal static void Reset(int seed)
		{
			Seed = seed;
			Decided = false;
			On = false;
			SpotCount = 0;
			_lastCount = -1;
			_stable = 0;
			Included = new HashSet<int>();
			_typeForSpot.Clear();
		}

		internal static int SpotOf(string name)
		{
			for (int i = 0; i < Spots.Length; i++)
			{
				if (name.Contains("ScoutStatueSpawner_" + Spots[i]))
				{
					return i;
				}
			}
			return -1;
		}

		internal static int TypeForSpot(int spot)
		{
			if (!_typeForSpot.TryGetValue(spot, out var value))
			{
				return -1;
			}
			return value;
		}

		internal static bool TryDecide()
		{
			if (Decided)
			{
				return true;
			}
			if (!Tfa.BuildReady)
			{
				return false;
			}
			List<int> list = (from i in (from s in Object.FindObjectsByType<PropSpawner_AmuletStatues>((FindObjectsInactive)1, (FindObjectsSortMode)0)
					where ((Component)s).transform.childCount > 0 && (Object)(object)((Component)s).GetComponentInChildren<FakeItem>(true) != (Object)null
					select SpotOf(((Object)s).name) into i
					where i >= 0
					select i).Distinct()
				orderby i
				select i).ToList();
			if (list.Count == 0 || list.Count != _lastCount)
			{
				_lastCount = list.Count;
				_stable = 0;
				Plugin.Debug($"Waiting for statues: {list.Count} spots so far");
				return false;
			}
			if (++_stable < 3)
			{
				return false;
			}
			SpotCount = list.Count;
			Decided = true;
			List<int> list2 = AmuletCatalog.AllIndices.OrderBy((int i) => i).ToList();
			if (SpotCount < 5 || list2.Count <= 4)
			{
				On = false;
				Plugin.Log.LogInfo((object)$"Seven Amulets: {SpotCount} amulet statue spots in this run (need {5}+) - staying off, plain TFA.");
				return true;
			}
			Random random = new Random(Seed ^ 0x5A17A11);
			int count = Mathf.Min(SpotCount, list2.Count);
			List<int> list3 = new List<int>(list2);
			for (int num = list3.Count - 1; num > 0; num--)
			{
				int num2 = random.Next(num + 1);
				List<int> list4 = list3;
				int index = num;
				List<int> list5 = list3;
				int index2 = num2;
				int value = list3[num2];
				int value2 = list3[num];
				list4[index] = value;
				list5[index2] = value2;
			}
			List<int> list6 = list3.Take(count).ToList();
			Included = new HashSet<int>(list6);
			for (int num3 = list6.Count - 1; num3 > 0; num3--)
			{
				int num4 = random.Next(num3 + 1);
				List<int> list5 = list6;
				int index2 = num3;
				int index = num4;
				int value2 = list6[num4];
				int value = list6[num3];
				list5[index2] = value2;
				list6[index] = value;
			}
			for (int num5 = 0; num5 < list.Count && num5 < list6.Count; num5++)
			{
				_typeForSpot[list[num5]] = list6[num5];
			}
			On = true;
			string arg = string.Join(", ", list.Select((int s) => Spots[s] + "=" + AmuletCatalog.ItemFor(TypeForSpot(s))?.UIData.itemName));
			Plugin.Log.LogInfo((object)$"Seven Amulets: {SpotCount} statue spots, Stone Scout needs {Included.Count}. {arg}");
			return true;
		}
	}
	internal class Runner : MonoBehaviour
	{
		private void OnGUI()
		{
			try
			{
				Discipline.OnGUI();
			}
			catch
			{
			}
		}

		private void Update()
		{
			Net.Hook();
			try
			{
				Fellowship.Tick();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Fellowship: " + ex));
			}
			try
			{
				Discipline.Tick();
			}
			catch (Exception ex2)
			{
				Plugin.Log.LogError((object)("Discipline: " + ex2));
			}
		}
	}
	internal class Springs : MonoBehaviour
	{
		private const string RoomKey = "SA_Springs";

		private static readonly Color Gold = new Color(1f, 0.82f, 0.35f);

		private static readonly string[][] Tiers = new string[3][]
		{
			new string[2] { "Tropics", "Roots" },
			new string[2] { "Alpine", "Mesa" },
			new string[2] { "Caldera", "Gloom" }
		};

		private const int TierCount = 3;

		private readonly GameObject[] _spawned = (GameObject[])(object)new GameObject[3];

		private readonly float[] _mine = Enumerable.Repeat(float.NaN, 12).ToArray();

		private int _seed = int.MinValue;

		private float _next;

		private static readonly string[] WaterColors = new string[9] { "_WaterColor", "_WaterColorPrimary", "_WaterColorSecodary", "_WaterColorShallow", "_WaterTint", "_WaterTintPreFoam", "_BaseColor", "_Color", "_Tint" };

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

		private static Material _water;

		private static Material _steam;

		private static Material _monkey;

		private void OnEnable()
		{
			SceneManager.sceneLoaded += OnScene;
		}

		private void OnDisable()
		{
			SceneManager.sceneLoaded -= OnScene;
		}

		private void OnScene(Scene s, LoadSceneMode m)
		{
			ResetAll(int.MinValue);
		}

		private void ResetAll(int seed)
		{
			for (int i = 0; i < 3; i++)
			{
				if ((Object)(object)_spawned[i] != (Object)null)
				{
					Object.Destroy((Object)(object)_spawned[i]);
				}
				_spawned[i] = null;
			}
			for (int j = 0; j < _mine.Length; j++)
			{
				_mine[j] = float.NaN;
			}
			_seed = seed;
		}

		private void Update()
		{
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Expected O, but got Unknown
			//IL_0114: 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_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			if (Time.unscaledTime < _next)
			{
				return;
			}
			_next = Time.unscaledTime + 1f;
			if (!Run.Active || !Plugin.SpringsEnabled.Value)
			{
				if (_spawned.Any((GameObject g) => (Object)(object)g != (Object)null))
				{
					ResetAll(_seed);
				}
				return;
			}
			int seed = Tfa.Seed;
			if (seed != _seed)
			{
				ResetAll(seed);
			}
			bool flag = PhotonNetwork.IsMasterClient || !PhotonNetwork.InRoom;
			if (flag)
			{
				bool flag2 = false;
				for (int num = 0; num < 3; num++)
				{
					if (float.IsNaN(_mine[num * 4]))
					{
						PropSpawner_AmuletStatues val = StatueFor(num, seed);
						if (!((Object)(object)val == (Object)null) && ((Component)val).gameObject.activeInHierarchy && ((Component)val).transform.childCount != 0 && TryPick(val, seed + num * 7919, out var best, out var yaw))
						{
							_mine[num * 4] = best.x;
							_mine[num * 4 + 1] = best.y;
							_mine[num * 4 + 2] = best.z;
							_mine[num * 4 + 3] = yaw;
							flag2 = true;
							Plugin.Log.LogInfo((object)$"Purifying Spring {num + 1}/3 placed near {((Object)val).name} at {best}");
						}
					}
				}
				if (flag2 && PhotonNetwork.InRoom)
				{
					Room currentRoom = PhotonNetwork.CurrentRoom;
					Hashtable val2 = new Hashtable();
					((Dictionary<object, object>)(object)val2).Add((object)"SA_Springs", (object)new object[2]
					{
						seed,
						(float[])_mine.Clone()
					});
					currentRoom.SetCustomProperties(val2, (Hashtable)null, (WebFlags)null);
				}
			}
			float[] array = (flag ? _mine : null);
			if (!flag && PhotonNetwork.CurrentRoom != null && ((Dictionary<object, object>)(object)((RoomInfo)PhotonNetwork.CurrentRoom).CustomProperties).TryGetValue((object)"SA_Springs", out object value) && value is object[] array2 && array2.Length == 2 && Net.I(array2[0]) == seed && array2[1] is float[] array3)
			{
				array = array3;
			}
			if (array == null)
			{
				return;
			}
			GameObject[] spawned = _spawned;
			foreach (GameObject val3 in spawned)
			{
				if ((Object)(object)val3 != (Object)null && !val3.activeSelf)
				{
					val3.SetActive(true);
					Plugin.Debug("Purifying Spring was switched off by something - switched back on");
				}
			}
			GameObject val4 = null;
			for (int num3 = 0; num3 < 3 && num3 * 4 + 3 < array.Length; num3++)
			{
				if (!((Object)(object)_spawned[num3] != (Object)null) && !float.IsNaN(array[num3 * 4]))
				{
					if (val4 == null)
					{
						val4 = Template();
					}
					if ((Object)(object)val4 == (Object)null)
					{
						Plugin.Log.LogWarning((object)"Purifying Springs: no onsen in this map to copy.");
						break;
					}
					_spawned[num3] = Build(val4, new Vector3(array[num3 * 4], array[num3 * 4 + 1], array[num3 * 4 + 2]), array[num3 * 4 + 3]);
				}
			}
		}

		private static PropSpawner_AmuletStatues StatueFor(int tier, int seed)
		{
			List<PropSpawner_AmuletStatues> list = (from s in Object.FindObjectsByType<PropSpawner_AmuletStatues>((FindObjectsInactive)1, (FindObjectsSortMode)0)
				where ((Component)s).transform.childCount > 0 && Tiers[tier].Any((string n) => ((Object)s).name.Contains("ScoutStatueSpawner_" + n))
				orderby ((Object)s).name
				select s).ToList();
			if (list.Count == 0)
			{
				return null;
			}
			return list[new Random(seed ^ (5968613 + tier)).Next(list.Count)];
		}

		private static bool TryPick(PropSpawner_AmuletStatues statue, int seed, out Vector3 best, out float yaw)
		{
			//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_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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: 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_0261: 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_018e: 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_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			Random random = new Random(seed);
			List<Vector3> list = (from f in Object.FindObjectsByType<Campfire>((FindObjectsInactive)0, (FindObjectsSortMode)0)
				select ((Component)f).transform.position).ToList();
			int mask = LayerMask.GetMask(new string[2] { "Terrain", "Map" });
			Vector3 position = ((Component)statue).transform.GetChild(0).position;
			best = Vector3.zero;
			yaw = 0f;
			float num = float.MinValue;
			float num2 = float.MinValue;
			Vector3 val = Vector3.zero;
			RaycastHit hit = default(RaycastHit);
			for (int num3 = 0; num3 < 160; num3++)
			{
				float num4 = (float)(random.NextDouble() * 3.1415927410125732 * 2.0);
				float num5 = Mathf.Lerp(Plugin.SpringMinDistance.Value, Plugin.SpringMaxDistance.Value, (float)random.NextDouble());
				if (Physics.Raycast(position + new Vector3(Mathf.Cos(num4) * num5, 60f, Mathf.Sin(num4) * num5), Vector3.down, ref hit, 140f, mask) && !(((RaycastHit)(ref hit)).normal.y < 0.75f) && !BadSurface(((RaycastHit)(ref hit)).collider))
				{
					float num6 = ((list.Count > 0) ? list.Min((Vector3 f) => Vector3.Distance(f, ((RaycastHit)(ref hit)).point)) : 999f);
					float num7 = Mathf.Min(num6, 120f) + Mathf.Clamp(((RaycastHit)(ref hit)).point.y - position.y, -20f, 40f) * 0.8f + (float)random.NextDouble() * 25f;
					if (num7 > num2)
					{
						num2 = num7;
						val = ((RaycastHit)(ref hit)).point;
					}
					if (!(((RaycastHit)(ref hit)).normal.y < 0.85f) && !(num6 < 25f) && Flat(((RaycastHit)(ref hit)).point, 3.5f, mask) && num7 > num)
					{
						num = num7;
						best = ((RaycastHit)(ref hit)).point;
					}
				}
			}
			yaw = (float)random.NextDouble() * 360f;
			if (num > float.MinValue)
			{
				return true;
			}
			if (num2 > float.MinValue)
			{
				best = val;
				Plugin.Debug("Spring near " + ((Object)statue).name + ": no ideal spot, using a looser one");
				return true;
			}
			Plugin.Debug("Spring near " + ((Object)statue).name + ": no ground found yet");
			return false;
		}

		private static bool BadSurface(Collider col)
		{
			string text = (((Object)col).name + " " + (Object.op_Implicit((Object)(object)((Component)col).transform.parent) ? ((Object)((Component)col).transform.parent).name : "")).ToLowerInvariant();
			if (!text.Contains("lava") && !text.Contains("water") && !text.Contains("tar"))
			{
				return text.Contains("spike");
			}
			return true;
		}

		private static bool Flat(Vector3 p, float r, int mask)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit val = default(RaycastHit);
			for (int i = 0; i < 6; i++)
			{
				float num = (float)i * MathF.PI / 3f;
				if (!Physics.Raycast(p + new Vector3(Mathf.Cos(num) * r, 6f, Mathf.Sin(num) * r), Vector3.down, ref val, 14f, mask))
				{
					return false;
				}
				if (Mathf.Abs(((RaycastHit)(ref val)).point.y - p.y) > 2f)
				{
					return false;
				}
			}
			return true;
		}

		private static Material GoldWater(Material original)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0123: Unknown result type (might be due to invalid IL or missing references)
			Material val = Looks.Tinted(original, Gold, "_SA_Pure");
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			string[] waterColors = WaterColors;
			foreach (string text in waterColors)
			{
				if (val.HasProperty(text))
				{
					Color color = val.GetColor(text);
					float num = Mathf.Clamp(Mathf.Max(new float[3] { color.r, color.g, color.b }), 0.35f, 1.2f);
					Color val2 = new Color(1f, 0.78f, 0.25f) * num;
					val2.a = color.a;
					val.SetColor(text, val2);
				}
			}
			if (val.HasProperty("_FoamTint"))
			{
				val.SetColor("_FoamTint", new Color(1f, 0.93f, 0.6f, val.GetColor("_FoamTint").a));
			}
			if (val.HasProperty("_EmissionColor"))
			{
				val.EnableKeyword("_EMISSION");
				val.SetColor("_EmissionColor", new Color(0.55f, 0.38f, 0.08f));
			}
			return val;
		}

		private static Color GoldOf(Color c, float amount)
		{
			//IL_0008: 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_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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)
			float num = Mathf.Max(new float[3] { c.r, c.g, c.b });
			Color val = new Color(1f, 0.8f, 0.3f) * Mathf.Max(num, 0.2f);
			Color result = Color.Lerp(c, val, amount);
			result.a = c.a;
			return result;
		}

		private static Gradient GoldOf(Gradient src, float amount)
		{
			//IL_0012: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			if (src == null)
			{
				return null;
			}
			Gradient val = new Gradient
			{
				mode = src.mode
			};
			val.SetKeys(((IEnumerable<GradientColorKey>)src.colorKeys).Select((Func<GradientColorKey, GradientColorKey>)((GradientColorKey k) => new GradientColorKey(GoldOf(k.color, amount), k.time))).ToArray(), src.alphaKeys);
			return val;
		}

		private static MinMaxGradient GoldOf(MinMaxGradient m, float amount)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected I4, but got Unknown
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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_004d: 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)
			ParticleSystemGradientMode mode = ((MinMaxGradient)(ref m)).mode;
			switch ((int)mode)
			{
			case 0:
				return new MinMaxGradient(GoldOf(((MinMaxGradient)(ref m)).color, amount));
			case 2:
				return new MinMaxGradient(GoldOf(((MinMaxGradient)(ref m)).colorMin, amount), GoldOf(((MinMaxGradient)(ref m)).colorMax, amount));
			case 3:
				return new MinMaxGradient(GoldOf(((MinMaxGradient)(ref m)).gradientMin, amount), GoldOf(((MinMaxGradient)(ref m)).gradientMax, amount));
			default:
			{
				MinMaxGradient result = default(MinMaxGradient);
				((MinMaxGradient)(ref result))..ctor(GoldOf(((MinMaxGradient)(ref m)).gradient, amount));
				((MinMaxGradient)(ref result)).mode = ((MinMaxGradient)(ref m)).mode;
				return result;
			}
			}
		}

		private static void Goldify(ParticleSystem ps, float amount)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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_0053: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
			MainModule main = ps.main;
			((MainModule)(ref main)).startColor = GoldOf(((MainModule)(ref main)).startColor, amount);
			ColorOverLifetimeModule colorOverLifetime = ps.colorOverLifetime;
			if (((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled)
			{
				((ColorOverLifetimeModule)(ref colorOverLifetime)).color = GoldOf(((ColorOverLifetimeModule)(ref colorOverLifetime)).color, amount);
			}
			ColorBySpeedModule colorBySpeed = ps.colorBySpeed;
			if (((ColorBySpeedModule)(ref colorBySpeed)).enabled)
			{
				((ColorBySpeedModule)(ref colorBySpeed)).color = GoldOf(((ColorBySpeedModule)(ref colorBySpeed)).color, amount);
			}
			ParticleSystemRenderer component = ((Component)ps).GetComponent<ParticleSystemRenderer>();
			if ((Object)(object)component != (Object)null && (Object)(object)((Renderer)component).sharedMaterial != (Object)null && amount >= 0.9f)
			{
				if (!_goldMats.TryGetValue(((Renderer)component).sharedMaterial, out var value))
				{
					value = (_goldMats[((Renderer)component).sharedMaterial] = Looks.Tinted(((Renderer)component).sharedMaterial, Gold, "_SA_Gold"));
				}
				((Renderer)component).sharedMaterial = value;
			}
		}

		private static int AddStatueGlow(Transform spring, Vector3 waterCenter)
		{
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Expected O, but got Unknown
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: 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_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: 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_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: 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_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: 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)
			Transform val = null;
			PropSpawner_AmuletStatues[] array = Object.FindObjectsByType<PropSpawner_AmuletStatues>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			foreach (PropSpawner_AmuletStatues val2 in array)
			{
				for (int j = 0; j < ((Component)val2).transform.childCount; j++)
				{
					if (!((Object)(object)val == (Object)null))
					{
						break;
					}
					Transform child = ((Component)val2).transform.GetChild(j);
					if (((IEnumerable)child).Cast<Transform>().Any((Transform c) => ((Object)c).name.StartsWith("Particle System") && Object.op_Implicit((Object)(object)((Component)c).GetComponent<ParticleSystem>())))
					{
						val = child;
					}
				}
				if ((Object)(object)val != (Object)null)
				{
					break;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Debug("Purifying Spring: no amulet statue to copy the glow from");
				return 0;
			}
			int num = 0;
			foreach (Transform item in val)
			{
				Transform val3 = item;
				i