Decompiled source of ServersideQoL Player BETA v1.99.4

ServersideQoL.Player.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ArgusMagnus")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyCopyright("ArgusMagnus")]
[assembly: AssemblyDescription("Configure some apsects around the player (e.g. infinite stamina for various activities, methods to permanently unlock item effects such as increased carry weight)")]
[assembly: AssemblyFileVersion("1.99.4.0")]
[assembly: AssemblyInformationalVersion("1.99.4-beta+80c81ad250a0109e44b175db632e72dae9da8db5")]
[assembly: AssemblyProduct("ServersideQoL.Player")]
[assembly: AssemblyTitle("ServersideQoL.Player")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/ArgusMagnus/ValheimServersideQoL")]
[assembly: AssemblyVersion("1.99.4.0")]
[module: RefSafetyRules(11)]
[CompilerGenerated]
internal sealed class <>z__ReadOnlyArray<T> : IEnumerable, ICollection, IList, IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection<T>, IList<T>
{
	int ICollection.Count => _items.Length;

	bool ICollection.IsSynchronized => false;

	object ICollection.SyncRoot => this;

	object IList.this[int index]
	{
		get
		{
			return _items[index];
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	bool IList.IsFixedSize => true;

	bool IList.IsReadOnly => true;

	int IReadOnlyCollection<T>.Count => _items.Length;

	T IReadOnlyList<T>.this[int index] => _items[index];

	int ICollection<T>.Count => _items.Length;

	bool ICollection<T>.IsReadOnly => true;

	T IList<T>.this[int index]
	{
		get
		{
			return _items[index];
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	public <>z__ReadOnlyArray(T[] items)
	{
		_items = items;
	}

	IEnumerator IEnumerable.GetEnumerator()
	{
		return ((IEnumerable)_items).GetEnumerator();
	}

	void ICollection.CopyTo(Array array, int index)
	{
		((ICollection)_items).CopyTo(array, index);
	}

	int IList.Add(object value)
	{
		throw new NotSupportedException();
	}

	void IList.Clear()
	{
		throw new NotSupportedException();
	}

	bool IList.Contains(object value)
	{
		return ((IList)_items).Contains(value);
	}

	int IList.IndexOf(object value)
	{
		return ((IList)_items).IndexOf(value);
	}

	void IList.Insert(int index, object value)
	{
		throw new NotSupportedException();
	}

	void IList.Remove(object value)
	{
		throw new NotSupportedException();
	}

	void IList.RemoveAt(int index)
	{
		throw new NotSupportedException();
	}

	IEnumerator<T> IEnumerable<T>.GetEnumerator()
	{
		return ((IEnumerable<T>)_items).GetEnumerator();
	}

	void ICollection<T>.Add(T item)
	{
		throw new NotSupportedException();
	}

	void ICollection<T>.Clear()
	{
		throw new NotSupportedException();
	}

	bool ICollection<T>.Contains(T item)
	{
		return ((ICollection<T>)_items).Contains(item);
	}

	void ICollection<T>.CopyTo(T[] array, int arrayIndex)
	{
		((ICollection<T>)_items).CopyTo(array, arrayIndex);
	}

	bool ICollection<T>.Remove(T item)
	{
		throw new NotSupportedException();
	}

	int IList<T>.IndexOf(T item)
	{
		return ((IList<T>)_items).IndexOf(item);
	}

	void IList<T>.Insert(int index, T item)
	{
		throw new NotSupportedException();
	}

	void IList<T>.RemoveAt(int index)
	{
		throw new NotSupportedException();
	}
}
[CompilerGenerated]
internal sealed class <>z__ReadOnlyList<T> : IEnumerable, ICollection, IList, IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection<T>, IList<T>
{
	int ICollection.Count => _items.Count;

	bool ICollection.IsSynchronized => false;

	object ICollection.SyncRoot => this;

	object IList.this[int index]
	{
		get
		{
			return _items[index];
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	bool IList.IsFixedSize => true;

	bool IList.IsReadOnly => true;

	int IReadOnlyCollection<T>.Count => _items.Count;

	T IReadOnlyList<T>.this[int index] => _items[index];

	int ICollection<T>.Count => _items.Count;

	bool ICollection<T>.IsReadOnly => true;

	T IList<T>.this[int index]
	{
		get
		{
			return _items[index];
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	public <>z__ReadOnlyList(List<T> items)
	{
		_items = items;
	}

	IEnumerator IEnumerable.GetEnumerator()
	{
		return ((IEnumerable)_items).GetEnumerator();
	}

	void ICollection.CopyTo(Array array, int index)
	{
		((ICollection)_items).CopyTo(array, index);
	}

	int IList.Add(object value)
	{
		throw new NotSupportedException();
	}

	void IList.Clear()
	{
		throw new NotSupportedException();
	}

	bool IList.Contains(object value)
	{
		return ((IList)_items).Contains(value);
	}

	int IList.IndexOf(object value)
	{
		return ((IList)_items).IndexOf(value);
	}

	void IList.Insert(int index, object value)
	{
		throw new NotSupportedException();
	}

	void IList.Remove(object value)
	{
		throw new NotSupportedException();
	}

	void IList.RemoveAt(int index)
	{
		throw new NotSupportedException();
	}

	IEnumerator<T> IEnumerable<T>.GetEnumerator()
	{
		return ((IEnumerable<T>)_items).GetEnumerator();
	}

	void ICollection<T>.Add(T item)
	{
		throw new NotSupportedException();
	}

	void ICollection<T>.Clear()
	{
		throw new NotSupportedException();
	}

	bool ICollection<T>.Contains(T item)
	{
		return _items.Contains(item);
	}

	void ICollection<T>.CopyTo(T[] array, int arrayIndex)
	{
		_items.CopyTo(array, arrayIndex);
	}

	bool ICollection<T>.Remove(T item)
	{
		throw new NotSupportedException();
	}

	int IList<T>.IndexOf(T item)
	{
		return _items.IndexOf(item);
	}

	void IList<T>.Insert(int index, T item)
	{
		throw new NotSupportedException();
	}

	void IList<T>.RemoveAt(int index)
	{
		throw new NotSupportedException();
	}
}
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ServersideQoL.Player
{
	public sealed class Config : ConfigBase<Config>
	{
		public sealed class LocalizationConfig
		{
			public string SacrificedMegingjord { get; init; } = "You were permanently granted increased carrying weight";

			public string SacrificedCryptKey { get; init; } = "You were permanently granted the ability to open sunken crypt doors";

			public string SacrificedWishbone { get; init; } = "You were permanently granted the ability to sense hidden objects";

			public string SacrificedTornSpirit { get; init; } = "You were permanently granted a wisp companion";
		}

		private const string Section = "Player";

		public override ConfigEntry<bool> Enabled { get; } = ConfigBase<Config>.BindEx<bool>(cfg, "Player", true, "Enables/disables the entire mod", (AcceptableValueBase)null, (Deprecated<Config>)null, "Enabled");

		public ConfigEntry<bool> InfiniteBuildingStamina { get; } = ConfigBase<Config>.BindEx<bool>(cfg, "Player", false, GetInfiniteXDescription("building"), (AcceptableValueBase)null, (Deprecated<Config>)null, "InfiniteBuildingStamina");

		public ConfigEntry<bool> InfiniteFarmingStamina { get; } = ConfigBase<Config>.BindEx<bool>(cfg, "Player", false, GetInfiniteXDescription("farming"), (AcceptableValueBase)null, (Deprecated<Config>)null, "InfiniteFarmingStamina");

		public ConfigEntry<bool> InfiniteMiningStamina { get; } = ConfigBase<Config>.BindEx<bool>(cfg, "Player", false, GetInfiniteXDescription("mining"), (AcceptableValueBase)null, (Deprecated<Config>)null, "InfiniteMiningStamina");

		public ConfigEntry<bool> InfiniteWoodCuttingStamina { get; } = ConfigBase<Config>.BindEx<bool>(cfg, "Player", false, GetInfiniteXDescription("cutting wood"), (AcceptableValueBase)null, (Deprecated<Config>)null, "InfiniteWoodCuttingStamina");

		public ConfigEntry<bool> InfiniteEncumberedStamina { get; } = ConfigBase<Config>.BindEx<bool>(cfg, "Player", false, GetInfiniteXDescription("encumbered"), (AcceptableValueBase)null, (Deprecated<Config>)null, "InfiniteEncumberedStamina");

		public ConfigEntry<bool> InfiniteSneakingStamina { get; } = ConfigBase<Config>.BindEx<bool>(cfg, "Player", false, GetInfiniteXDescription("sneaking"), (AcceptableValueBase)null, (Deprecated<Config>)null, "InfiniteSneakingStamina");

		public ConfigEntry<bool> InfiniteSwimmingStamina { get; } = ConfigBase<Config>.BindEx<bool>(cfg, "Player", false, GetInfiniteXDescription("swimming"), (AcceptableValueBase)null, (Deprecated<Config>)null, "InfiniteSwimmingStamina");

		public ConfigEntry<Emotes> OpenCartEmote { get; }

		public ConfigEntry<bool> CanSacrificeMegingjord { get; }

		public ConfigEntry<bool> CanSacrificeCryptKey { get; }

		public ConfigEntry<bool> CanSacrificeWishbone { get; }

		public ConfigEntry<bool> CanSacrificeTornSpirit { get; }

		public YamlConfigEntry<LocalizationConfig> Localization { get; }

		public Config(ConfigFile cfg, Logger logger)
		{
			string text = $"Emote to open the inventory of an attached cart.\r\n{(object)(Emotes)(-1)} to disable this feature, {(object)(Emotes)(-2)} to use any emote as trigger.\r\nYou can bind emotes to buttons with chat commands.\r\nFor example, on xbox you can bind the Y-Button to the wave-emote by entering \"/bind JoystickButton3 {(object)(Emotes)0}\" in the in-game chat.\r\nIf you use emotes exclusively for this feature, it is recommended to set the value to {(object)(Emotes)(-2)} as it is more reliably detected than specific emotes, especially on bad connection/with crossplay.";
			List<Emotes> list = new List<Emotes>();
			list.Add((Emotes)(-1));
			list.Add((Emotes)(-2));
			list.AddRange(Enum.GetValues(typeof(Emotes)).Cast<Emotes>());
			OpenCartEmote = ConfigBase<Config>.BindEx<Emotes>(cfg, "Player", (Emotes)(-1), text, (AcceptableValueBase)(object)new AcceptableEnum<Emotes>((IEnumerable<Emotes>)new <>z__ReadOnlyList<Emotes>(list)), (Deprecated<Config>)null, "OpenCartEmote");
			CanSacrificeMegingjord = ConfigBase<Config>.BindEx<bool>(cfg, "Player", false, "If true, players can permanently unlock increased carrying weight by sacrificing a megingjord in an obliterator", (AcceptableValueBase)null, (Deprecated<Config>)null, "CanSacrificeMegingjord");
			CanSacrificeCryptKey = ConfigBase<Config>.BindEx<bool>(cfg, "Player", false, "If true, players can permanently unlock the ability to open sunken crypt doors by sacrificing a crypt key in an obliterator", (AcceptableValueBase)null, (Deprecated<Config>)null, "CanSacrificeCryptKey");
			CanSacrificeWishbone = ConfigBase<Config>.BindEx<bool>(cfg, "Player", false, "If true, players can permanently unlock the ability to sense hidden objects by sacrificing a wishbone in an obliterator", (AcceptableValueBase)null, (Deprecated<Config>)null, "CanSacrificeWishbone");
			CanSacrificeTornSpirit = ConfigBase<Config>.BindEx<bool>(cfg, "Player", false, "If true, players can permanently unlock a wisp companion by sacrificing a torn spirit in an obliterator. WARNING: Wisp companion cannot be unsummoned and will stay as long as this setting is enabled.", (AcceptableValueBase)null, (Deprecated<Config>)null, "CanSacrificeTornSpirit");
			Localization = ConfigBase<Config>.BindYaml<LocalizationConfig>(cfg, "Localization");
			base..ctor(cfg, logger);
		}

		private static string GetInfiniteXDescription(string action)
		{
			return FormattableString.Invariant(FormattableStringFactory.Create("True to give players infinite stamina when {0}.\r\nPlayer stamina will still be drained, but when nearly depleted, just enough stamina will be restored to continue indefinitely.\r\nIf you want infinite stamina in general, set the global key '{1}' to 0.", action, "StaminaRate"));
		}
	}
	[Processor("28b93edf-6ede-4dbe-92ed-99275be3915f")]
	public sealed class CryptDoorProcessor : Processor<CryptDoorProcessor.PrefabInfo>
	{
		public sealed record PrefabInfo(Door Door) : ProcessorPrefabInfo()
		{
			[CompilerGenerated]
			public override string ToString()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append("PrefabInfo");
				stringBuilder.Append(" { ");
				if (((ProcessorPrefabInfo)this).PrintMembers(stringBuilder))
				{
					stringBuilder.Append(' ');
				}
				stringBuilder.Append('}');
				return stringBuilder.ToString();
			}

			[CompilerGenerated]
			protected override bool PrintMembers(StringBuilder builder)
			{
				if (((ProcessorPrefabInfo)this).PrintMembers(builder))
				{
					builder.Append(", ");
				}
				builder.Append("Door = ");
				builder.Append(Door);
				return true;
			}

			[CompilerGenerated]
			public override int GetHashCode()
			{
				return ((ProcessorPrefabInfo)this).GetHashCode() * -1521134295 + EqualityComparer<Door>.Default.GetHashCode(Door);
			}

			[CompilerGenerated]
			public sealed override bool Equals(ProcessorPrefabInfo? other)
			{
				return ((object)this).Equals((object?)other);
			}

			[CompilerGenerated]
			public bool Equals(PrefabInfo? other)
			{
				return (object)this == other || (((ProcessorPrefabInfo)this).Equals((ProcessorPrefabInfo)(object)other) && EqualityComparer<Door>.Default.Equals(Door, other.Door));
			}

			[CompilerGenerated]
			private PrefabInfo(PrefabInfo original)
				: base((ProcessorPrefabInfo)(object)original)
			{
				Door = original.Door;
			}
		}

		private readonly List<ServersideQoLZDO> _allowedPlayers = new List<ServersideQoLZDO>();

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

		private readonly IEnumerable<int> _visEquipmentVars = new <>z__ReadOnlyArray<int>(new int[9]
		{
			ZDOVars.s_helmetItem,
			ZDOVars.s_chestItem,
			ZDOVars.s_legItem,
			ZDOVars.s_shoulderItem,
			ZDOVars.s_utilityItem,
			ZDOVars.s_leftItem,
			ZDOVars.s_rightItem,
			ZDOVars.s_leftBackItem,
			ZDOVars.s_rightBackItem
		});

		protected override void Initialize()
		{
			_allowedPlayers.Clear();
			_keyItemWeightByHash.Clear();
		}

		protected override ProcessResult Process(ServersideQoLZDO zdo, IReadOnlyList<Peer> peers, PrefabInfo prefabInfo)
		{
			//IL_0023: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_032d: 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_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			ItemDrop keyItem = prefabInfo.Door.m_keyItem;
			if (keyItem != null && ((Object)keyItem).name == "CryptKey")
			{
				ZDOVars vars = zdo.Vars;
				if (((ZDOVars)(ref vars)).GetState(0) == 0)
				{
					ComponentFieldAccessor<Door> val = zdo.Fields<Door>();
					if (!ConfigBase<Config>.Instance.CanSacrificeCryptKey.Value)
					{
						val.Reset((Func<Expression<Func<Door, ItemDrop>>>)(() => (Door x) => x.m_keyItem), "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.Player\\CryptDoorProcessor.cs", 33);
						return (ProcessResult)2;
					}
					_allowedPlayers.Clear();
					if (ZoneSystem.instance.GetGlobalKey((GlobalKeys)36))
					{
						foreach (Peer peer in peers)
						{
							if (!(Vector3.Distance(peer.RefPos, zdo.ZDO.GetPosition()) > 16f))
							{
								PlayerState playerState = peer.PlayerState;
								if (playerState != null && PlayerProcessor.GetSacrifiedCryptKey(playerState.PlayerID))
								{
									_allowedPlayers.Add(playerState.ZDO);
								}
							}
						}
					}
					if (_allowedPlayers.Count == 0)
					{
						if (val.UpdateResetValue((Func<Expression<Func<Door, ItemDrop>>>)(() => (Door x) => x.m_keyItem), "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.Player\\CryptDoorProcessor.cs", 51))
						{
							return (ProcessResult)8;
						}
					}
					else
					{
						int num = 0;
						int num2 = 0;
						_keyItemWeightByHash.Clear();
						foreach (int visEquipmentVar in _visEquipmentVars)
						{
							foreach (ServersideQoLZDO allowedPlayer in _allowedPlayers)
							{
								int num3 = allowedPlayer.ZDO.GetInt(visEquipmentVar, 0);
								if (num3 != 0)
								{
									int value = ((!_keyItemWeightByHash.TryGetValue(num3, out value)) ? 1 : (value + 1));
									_keyItemWeightByHash[num3] = value;
									if (value > num)
									{
										num = value;
										num2 = num3;
									}
								}
							}
						}
						_keyItemWeightByHash.Clear();
						_allowedPlayers.Clear();
						if (num2 != 0)
						{
							GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(num2);
							ItemDrop val2 = ((itemPrefab != null) ? itemPrefab.GetComponent<ItemDrop>() : null);
							if (val2 != null)
							{
								if (val.UpdateValue((Func<Expression<Func<Door, ItemDrop>>>)(() => (Door x) => x.m_keyItem), val2, "C:\\repos\\Valheim.ServersideQoL\\ServersideQoL.Player\\CryptDoorProcessor.cs", 83))
								{
									return (ProcessResult)8;
								}
								goto IL_0328;
							}
						}
						((Processor)this).Logger.LogWarning((object)$"Item {num2} was chosen as key, but it's not a valid ItemDrop");
					}
					goto IL_0328;
				}
			}
			return (ProcessResult)2;
			IL_0328:
			return (ProcessResult)0;
		}
	}
	[BepInPlugin("ArgusMagnus.ServersideQoL.Player", "ServersideQoL.Player", "1.99.4")]
	public sealed class PlayerPlugin : ServersideQoLPluginBase<PlayerPlugin, Config>
	{
		public const string Author = "ArgusMagnus";

		public const string PluginName = "ServersideQoL.Player";

		public const string PluginGuid = "ArgusMagnus.ServersideQoL.Player";

		public const string PluginVersion = "1.99.4";

		public const string PluginInformationalVersion = "1.99.4-beta";

		internal const string DependencyDirectory = "C:\\repos\\Valheim.ServersideQoL\\Dependencies\\";

		private DateTimeOffset BuildTimestamp { get; } = new DateTimeOffset(639209323753416586L, default(TimeSpan));

		protected override Config CreateConfigSingleton(ConfigFile configFile, Logger logger)
		{
			return new Config(configFile, logger);
		}

		protected override void RegisterProcessors(IProcessorCollection processors)
		{
			processors.Add<PlayerProcessor>().Add<CryptDoorProcessor>().Add<VagonProcessor>();
		}

		private void Awake()
		{
			bool flag = true;
			ServersideQoLPluginBase<PlayerPlugin, Config>.Logger.LogWarning((object)string.Format("You are running a pre-release version: {0} ({1})", "1.99.4-beta", BuildTimestamp.LocalDateTime));
		}
	}
	[Processor("7b156eea-3364-40ca-83ad-417a55fa6e4b")]
	[DependsOn<PlayerRegistryProcessor>]
	public sealed class PlayerProcessor : Processor<PrefabInfo>
	{
		private readonly Dictionary<ServersideQoLZDO, ServersideQoLZDO> _attachedCartsByPlayer = new Dictionary<ServersideQoLZDO, ServersideQoLZDO>();

		protected override void Initialize()
		{
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Expected O, but got Unknown
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Invalid comparison between Unknown and I4
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Expected O, but got Unknown
			bool flag = false;
			if (Game.m_staminaRate > 0f)
			{
				flag = ConfigBase<Config>.Instance.InfiniteBuildingStamina.Value || ConfigBase<Config>.Instance.InfiniteFarmingStamina.Value || ConfigBase<Config>.Instance.InfiniteMiningStamina.Value || ConfigBase<Config>.Instance.InfiniteWoodCuttingStamina.Value;
			}
			Intercept.UpdateInterception("SetTrigger", (Delegate)new Action<RoutedRPCData, string>(OnZSyncAnimationSetTrigger), flag);
			Intercept.UpdateInterception("RPC_AnimateLever", (Delegate)new Action<ServersideQoLZDO, RoutedRPCData>(RPC_AnimateLever), ConfigBase<Config>.Instance.CanSacrificeMegingjord.Value || ConfigBase<Config>.Instance.CanSacrificeCryptKey.Value || ConfigBase<Config>.Instance.CanSacrificeWishbone.Value || ConfigBase<Config>.Instance.CanSacrificeTornSpirit.Value);
			Processor.Instance<PlayerRegistryProcessor>().StaminaUpdated -= new StaminaUpdatedHandler(OnPlayerStaminaUpdated);
			if (ConfigBase<Config>.Instance.InfiniteEncumberedStamina.Value || ConfigBase<Config>.Instance.InfiniteSneakingStamina.Value || ConfigBase<Config>.Instance.InfiniteSwimmingStamina.Value)
			{
				Processor.Instance<PlayerRegistryProcessor>().StaminaUpdated += new StaminaUpdatedHandler(OnPlayerStaminaUpdated);
			}
			Processor.Instance<PlayerRegistryProcessor>().EmoteDetected -= OnEmoteDetected;
			if ((int)ConfigBase<Config>.Instance.OpenCartEmote.Value != -1)
			{
				Processor.Instance<PlayerRegistryProcessor>().EmoteDetected += OnEmoteDetected;
			}
			_attachedCartsByPlayer.Clear();
		}

		protected override ProcessResult Process(ServersideQoLZDO zdo, IReadOnlyList<Peer> peers, PrefabInfo prefabInfo)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			PlayerState state = Processor.Instance<PlayerRegistryProcessor>().GetState(zdo);
			if (state == null)
			{
				return (ProcessResult)2;
			}
			if (ConfigBase<Config>.Instance.CanSacrificeMegingjord.Value && GetSacrifiedMegingjord(state.PlayerID))
			{
				RPC.AddStatusEffect(zdo, StatusEffects.Megingjord, false, 0, 0f);
			}
			if (ConfigBase<Config>.Instance.CanSacrificeWishbone.Value && GetSacrifiedWishbone(state.PlayerID))
			{
				RPC.AddStatusEffect(zdo, StatusEffects.Wishbone, false, 0, 0f);
			}
			if (ConfigBase<Config>.Instance.CanSacrificeTornSpirit.Value && GetSacrifiedTornSpirit(state.PlayerID))
			{
				RPC.AddStatusEffect(zdo, StatusEffects.Demister, false, 0, 0f);
			}
			RPC.AddStatusEffect(zdo, StringExtensionMethods.GetStableHashCode("Rested", true), false, 0, 0f);
			return (ProcessResult)2;
		}

		private void OnPlayerStaminaUpdated(ServersideQoLZDO zdo, PlayerState state, bool staminaValueChanged)
		{
			//IL_0036: 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_0093: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			if (staminaValueChanged)
			{
				return;
			}
			ZDOVars vars;
			if ((float)state.Stamina < state.PrefabInfo.Player.m_encumberedStaminaDrain && ConfigBase<Config>.Instance.InfiniteEncumberedStamina.Value)
			{
				vars = zdo.Vars;
				if (((ZDOVars)(ref vars)).GetAnimationIsEncumbered(false))
				{
					RPC.UseStamina(zdo, 0f - state.PrefabInfo.Player.m_encumberedStaminaDrain);
					return;
				}
			}
			if ((float)state.Stamina < state.PrefabInfo.Player.m_sneakStaminaDrain && ConfigBase<Config>.Instance.InfiniteSneakingStamina.Value)
			{
				vars = zdo.Vars;
				if (((ZDOVars)(ref vars)).GetAnimationIsCrouching(false))
				{
					RPC.UseStamina(zdo, 0f - state.PrefabInfo.Player.m_sneakStaminaDrain);
					return;
				}
			}
			if ((float)state.Stamina < state.PrefabInfo.Player.m_swimStaminaDrainMinSkill && ConfigBase<Config>.Instance.InfiniteSwimmingStamina.Value)
			{
				vars = zdo.Vars;
				if (((ZDOVars)(ref vars)).GetAnimationInWater(false))
				{
					RPC.UseStamina(zdo, 0f - state.PrefabInfo.Player.m_swimStaminaDrainMinSkill);
				}
			}
		}

		private void OnZSyncAnimationSetTrigger(RoutedRPCData data, string name)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			PlayerState stateForCharacterID = Processor.Instance<PlayerRegistryProcessor>().GetStateForCharacterID(data.m_targetZDO);
			if (stateForCharacterID == null)
			{
				return;
			}
			ItemDrop val = null;
			ZDOVars vars = stateForCharacterID.ZDO.Vars;
			int rightItem = ((ZDOVars)(ref vars)).GetRightItem(0);
			if (rightItem != 0)
			{
				GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(rightItem);
				val = ((itemPrefab != null) ? itemPrefab.GetComponent<ItemDrop>() : null);
				if (val == null)
				{
					((Processor)this).Logger.LogWarning((object)$"Player {stateForCharacterID.PlayerName}: SetTrigger({name}): Right item prefab '{rightItem}' not found");
				}
			}
			if (val != null && CheckStamina(name))
			{
				float attackStamina = val.m_itemData.m_shared.m_attack.m_attackStamina;
				vars = stateForCharacterID.ZDO.Vars;
				if (((ZDOVars)(ref vars)).GetStamina(0f) < 2f * attackStamina)
				{
					RPC.UseStamina(stateForCharacterID.ZDO, 0f - attackStamina);
				}
			}
			static bool CheckStamina(string triggerName)
			{
				switch (triggerName)
				{
				case "swing_pickaxe":
					return ConfigBase<Config>.Instance.InfiniteMiningStamina.Value;
				case "swing_hammer":
					return ConfigBase<Config>.Instance.InfiniteBuildingStamina.Value;
				case "swing_hoe":
				case "scything":
					return ConfigBase<Config>.Instance.InfiniteFarmingStamina.Value;
				case "swing_axe0":
				case "battleaxe_attack0":
				case "dualaxes0":
					return ConfigBase<Config>.Instance.InfiniteWoodCuttingStamina.Value;
				default:
					return false;
				}
			}
		}

		private void RPC_AnimateLever(ServersideQoLZDO zdo, RoutedRPCData data)
		{
			ContainerState state = Processor.Instance<ContainerRegistryProcessor>().GetState(zdo);
			if (state == null)
			{
				return;
			}
			PrefabInfo prefabInfo = state.PrefabInfo;
			if (prefabInfo == null || prefabInfo.Incinerator == null)
			{
				return;
			}
			PlayerState val = null;
			IInventory val2 = null;
			if (ConfigBase<Config>.Instance.CanSacrificeMegingjord.Value && (val2 ?? (val2 = state.GetInventory())).Items.Any(delegate(ItemData x)
			{
				GameObject dropPrefab = x.m_dropPrefab;
				return ((dropPrefab != null) ? ((Object)dropPrefab).name : null) == "BeltStrength";
			}))
			{
				if (val == null)
				{
					val = Processor.Instance<PlayerRegistryProcessor>().GetStateForPeerID(data.m_senderPeerID);
				}
				if (val == null)
				{
					((Processor)this).Logger.LogError((object)$"Player ZDO with peer ID {data.m_senderPeerID} not found");
				}
				else
				{
					SetSacrifiedMegingjord(val.PlayerID, value: true);
					RPC.AddStatusEffect(val.ZDO, StatusEffects.Megingjord, false, 0, 0f);
					RPC.ShowMessage(data.m_senderPeerID, (MessageType)2, ConfigBase<Config>.Instance.Localization.Value.SacrificedMegingjord);
				}
			}
			if (ConfigBase<Config>.Instance.CanSacrificeCryptKey.Value && (val2 ?? (val2 = state.GetInventory())).Items.Any(delegate(ItemData x)
			{
				GameObject dropPrefab = x.m_dropPrefab;
				return ((dropPrefab != null) ? ((Object)dropPrefab).name : null) == "CryptKey";
			}))
			{
				if (val == null)
				{
					val = Processor.Instance<PlayerRegistryProcessor>().GetStateForPeerID(data.m_senderPeerID);
				}
				if (val == null)
				{
					((Processor)this).Logger.LogError((object)$"Player ZDO with peer ID {data.m_senderPeerID} not found");
				}
				else
				{
					SetSacrifiedCryptKey(val.PlayerID, value: true);
					RPC.ShowMessage(data.m_senderPeerID, (MessageType)2, ConfigBase<Config>.Instance.Localization.Value.SacrificedCryptKey);
				}
			}
			if (ConfigBase<Config>.Instance.CanSacrificeWishbone.Value && (val2 ?? (val2 = state.GetInventory())).Items.Any(delegate(ItemData x)
			{
				GameObject dropPrefab = x.m_dropPrefab;
				return ((dropPrefab != null) ? ((Object)dropPrefab).name : null) == "Wishbone";
			}))
			{
				if (val == null)
				{
					val = Processor.Instance<PlayerRegistryProcessor>().GetStateForPeerID(data.m_senderPeerID);
				}
				if (val == null)
				{
					((Processor)this).Logger.LogError((object)$"Player ZDO with peer ID {data.m_senderPeerID} not found");
				}
				else
				{
					SetSacrifiedWishbone(val.PlayerID, value: true);
					RPC.AddStatusEffect(val.ZDO, StatusEffects.Wishbone, false, 0, 0f);
					RPC.ShowMessage(data.m_senderPeerID, (MessageType)2, ConfigBase<Config>.Instance.Localization.Value.SacrificedWishbone);
				}
			}
			if (ConfigBase<Config>.Instance.CanSacrificeTornSpirit.Value && (val2 ?? (val2 = state.GetInventory())).Items.Any(delegate(ItemData x)
			{
				GameObject dropPrefab = x.m_dropPrefab;
				return ((dropPrefab != null) ? ((Object)dropPrefab).name : null) == "YagluthDrop";
			}))
			{
				if (val == null)
				{
					val = Processor.Instance<PlayerRegistryProcessor>().GetStateForPeerID(data.m_senderPeerID);
				}
				if (val == null)
				{
					((Processor)this).Logger.LogError((object)$"Player ZDO with peer ID {data.m_senderPeerID} not found");
					return;
				}
				SetSacrifiedTornSpirit(val.PlayerID, value: true);
				RPC.AddStatusEffect(val.ZDO, StatusEffects.Demister, false, 0, 0f);
				RPC.ShowMessage(data.m_senderPeerID, (MessageType)2, ConfigBase<Config>.Instance.Localization.Value.SacrificedTornSpirit);
			}
		}

		private void OnEmoteDetected(ServersideQoLZDO zdo, PlayerState state, Emotes emote)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			//IL_001e: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			if (((int)ConfigBase<Config>.Instance.OpenCartEmote.Value == -2 || ConfigBase<Config>.Instance.OpenCartEmote.Value == emote) && _attachedCartsByPlayer.TryGetValue(zdo, out ServersideQoLZDO value) && value.ZDO.GetOwner() == state.Owner)
			{
				ZDOVars vars = value.Vars;
				if (((ZDOVars)(ref vars)).GetAttachJoint(false))
				{
					RPC.OpenResponse(value, true);
				}
			}
		}

		internal void UpdateAttachedCart(ServersideQoLZDO cart)
		{
			//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)
			cart.AssertIsAll<Vagon, Container>();
			PlayerState stateForPeerID = Processor.Instance<PlayerRegistryProcessor>().GetStateForPeerID(cart.ZDO.GetOwner());
			if (stateForPeerID != null)
			{
				ZDOVars vars = cart.Vars;
				if (!((ZDOVars)(ref vars)).GetAttachJoint(false))
				{
					_attachedCartsByPlayer.Remove(stateForPeerID.ZDO);
					return;
				}
				if (!_attachedCartsByPlayer.TryAdd(stateForPeerID.ZDO, cart))
				{
					_attachedCartsByPlayer[stateForPeerID.ZDO] = cart;
					return;
				}
				stateForPeerID.ZDO.Destroyed += OnPlayerDestroyed;
				cart.Destroyed += OnCartDestroyed;
			}
		}

		private void OnPlayerDestroyed(ServersideQoLZDO zdo)
		{
			if (_attachedCartsByPlayer.Remove(zdo, out ServersideQoLZDO value))
			{
				value.Destroyed -= OnCartDestroyed;
			}
		}

		private void OnCartDestroyed(ServersideQoLZDO zdo)
		{
			List<ServersideQoLZDO> list = null;
			foreach (var (item, val3) in _attachedCartsByPlayer)
			{
				if (val3 == zdo)
				{
					(list ?? (list = new List<ServersideQoLZDO>())).Add(item);
				}
			}
			if (list == null)
			{
				return;
			}
			foreach (ServersideQoLZDO item2 in list)
			{
				if (_attachedCartsByPlayer.Remove(item2, out ServersideQoLZDO _))
				{
					item2.Destroyed -= OnPlayerDestroyed;
				}
			}
		}

		private static bool GetSacrifiedMegingjord(long playerID, bool defaultValue = false)
		{
			return Processor.DataZDO.ZDO.GetBool($"player{playerID}_SacrifiedMegingjord", defaultValue);
		}

		private static void SetSacrifiedMegingjord(long playerID, bool value)
		{
			Processor.DataZDO.ZDO.Set($"player{playerID}_SacrifiedMegingjord", value);
		}

		internal static bool GetSacrifiedCryptKey(long playerID, bool defaultValue = false)
		{
			return Processor.DataZDO.ZDO.GetBool($"player{playerID}_SacrifiedCryptKey", defaultValue);
		}

		private static void SetSacrifiedCryptKey(long playerID, bool value)
		{
			Processor.DataZDO.ZDO.Set($"player{playerID}_SacrifiedCryptKey", value);
		}

		private static bool GetSacrifiedWishbone(long playerID, bool defaultValue = false)
		{
			return Processor.DataZDO.ZDO.GetBool($"player{playerID}_SacrifiedWishbone", defaultValue);
		}

		private static void SetSacrifiedWishbone(long playerID, bool value)
		{
			Processor.DataZDO.ZDO.Set($"player{playerID}_SacrifiedWishbone", value);
		}

		private static bool GetSacrifiedTornSpirit(long playerID, bool defaultValue = false)
		{
			return Processor.DataZDO.ZDO.GetBool($"player{playerID}_SacrifiedTornSpirit", defaultValue);
		}

		private static void SetSacrifiedTornSpirit(long playerID, bool value)
		{
			Processor.DataZDO.ZDO.Set($"player{playerID}_SacrifiedTornSpirit", value);
		}
	}
	[Processor("8a10c73e-67db-4dc2-8b0c-3242aac82e3b")]
	public sealed class VagonProcessor : Processor<VagonProcessor.PrefabInfo>
	{
		public sealed record PrefabInfo(Vagon Vagon, Piece Piece, Container Container) : ProcessorPrefabInfo()
		{
			[CompilerGenerated]
			public override string ToString()
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append("PrefabInfo");
				stringBuilder.Append(" { ");
				if (((ProcessorPrefabInfo)this).PrintMembers(stringBuilder))
				{
					stringBuilder.Append(' ');
				}
				stringBuilder.Append('}');
				return stringBuilder.ToString();
			}

			[CompilerGenerated]
			protected override bool PrintMembers(StringBuilder builder)
			{
				if (((ProcessorPrefabInfo)this).PrintMembers(builder))
				{
					builder.Append(", ");
				}
				builder.Append("Vagon = ");
				builder.Append(Vagon);
				builder.Append(", Piece = ");
				builder.Append(Piece);
				builder.Append(", Container = ");
				builder.Append(Container);
				return true;
			}

			[CompilerGenerated]
			public override int GetHashCode()
			{
				return ((((ProcessorPrefabInfo)this).GetHashCode() * -1521134295 + EqualityComparer<Vagon>.Default.GetHashCode(Vagon)) * -1521134295 + EqualityComparer<Piece>.Default.GetHashCode(Piece)) * -1521134295 + EqualityComparer<Container>.Default.GetHashCode(Container);
			}

			[CompilerGenerated]
			public sealed override bool Equals(ProcessorPrefabInfo? other)
			{
				return ((object)this).Equals((object?)other);
			}

			[CompilerGenerated]
			public bool Equals(PrefabInfo? other)
			{
				return (object)this == other || (((ProcessorPrefabInfo)this).Equals((ProcessorPrefabInfo)(object)other) && EqualityComparer<Vagon>.Default.Equals(Vagon, other.Vagon) && EqualityComparer<Piece>.Default.Equals(Piece, other.Piece) && EqualityComparer<Container>.Default.Equals(Container, other.Container));
			}

			[CompilerGenerated]
			private PrefabInfo(PrefabInfo original)
				: base((ProcessorPrefabInfo)(object)original)
			{
				Vagon = original.Vagon;
				Piece = original.Piece;
				Container = original.Container;
			}
		}

		protected override ProcessResult Process(ServersideQoLZDO zdo, IReadOnlyList<Peer> peers, PrefabInfo prefabInfo)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Invalid comparison between Unknown and I4
			//IL_0028: 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_002b: Unknown result type (might be due to invalid IL or missing references)
			if ((int)ConfigBase<Config>.Instance.OpenCartEmote.Value == -1)
			{
				return (ProcessResult)2;
			}
			Processor.Instance<PlayerProcessor>().UpdateAttachedCart(zdo);
			return (ProcessResult)0;
		}
	}
}