Decompiled source of VeinControl v1.0.0

VeinControl.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.Gameplay.Scripting;
using ProjectM.Gameplay.Systems;
using ProjectM.Network;
using ProjectM.Shared;
using ProjectM.UI;
using Stunlock.Core;
using Stunlock.Network;
using TMPro;
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: SecurityPermission((SecurityAction)8, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : System.Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(/*Could not decode attribute arguments.*/)]
	internal sealed class RefSafetyRulesAttribute : System.Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace VeinControl
{
	[BepInPlugin("com.zeeCameLsnake.VeinControl", "VeinControl", "1.0.0")]
	public class VeinControlPlugin : BasePlugin
	{
		public const string PluginGUID = "com.zeeCameLsnake.VeinControl";

		public const string PluginName = "VeinControl";

		public const string PluginVersion = "1.0.0";

		internal static ManualLogSource Log;

		internal static bool IsServer;

		private Harmony _harmony;

		public override void Load()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			Log = ((BasePlugin)this).Log;
			IsServer = Application.productName == "VRisingServer";
			_harmony = new Harmony("com.zeeCameLsnake.VeinControl");
			bool flag = default(bool);
			if (IsServer)
			{
				ServerPart.Load();
				_harmony.PatchAll(typeof(ServerPatches));
				ManualLogSource log = Log;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(69, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("VeinControl");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" v");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.0");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded (server part: non-lethal feed cancel, feed key safety net).");
				}
				log.LogInfo(val);
			}
			else
			{
				VeinControlConfig.Bind(((BasePlugin)this).Config);
				_harmony.PatchAll(typeof(ClientPatches));
				ManualLogSource log2 = Log;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(70, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("VeinControl");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" v");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.0");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded (client part: separate feed key, cancel keys, prompt label).");
				}
				log2.LogInfo(val);
			}
		}

		public override bool Unload()
		{
			if (!IsServer)
			{
				FeedInput.Teardown();
				FeedHudLabels.Teardown();
			}
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			return true;
		}
	}
	[HarmonyPatch]
	internal static class ClientPatches
	{
		[HarmonyPatch(typeof(GameplayInputSystem), "OnUpdate")]
		[HarmonyPrefix]
		private static void InputPrefix(GameplayInputSystem __instance)
		{
			try
			{
				VeinControlConfig.PollLiveReload();
			}
			catch (System.Exception ex)
			{
				Util.LogExceptionOnce("PollLiveReload", ex);
			}
			try
			{
				FeedInput.Prefix(__instance);
			}
			catch (System.Exception ex2)
			{
				Util.LogExceptionOnce("FeedInput", ex2);
			}
			try
			{
				ClientLink.Tick(((ComponentSystemBase)__instance).World);
			}
			catch (System.Exception ex3)
			{
				Util.LogExceptionOnce("ClientLink", ex3);
			}
		}

		[HarmonyPatch(typeof(InteractHUDSystem), "OnUpdate")]
		[HarmonyPostfix]
		private static void InteractHudPostfix(InteractHUDSystem __instance)
		{
			try
			{
				FeedHudLabels.Update(__instance);
			}
			catch (System.Exception ex)
			{
				Util.LogExceptionOnce("FeedHudLabels", ex);
			}
		}

		[HarmonyPatch(typeof(FeedInteractionProgressSystem), "OnUpdate")]
		[HarmonyPostfix]
		private static void FeedProgressPostfix(FeedInteractionProgressSystem __instance)
		{
			try
			{
				FeedHudLabels.UpdateAbortLine(__instance);
			}
			catch (System.Exception ex)
			{
				Util.LogExceptionOnce("FeedHudLabels.AbortLine", ex);
			}
		}

		[HarmonyPatch(typeof(ClientChatSystem), "OnUpdate")]
		[HarmonyPrefix]
		private static void ChatPrefix(ClientChatSystem __instance)
		{
			try
			{
				ClientLink.ReadServerMessages(__instance);
			}
			catch (System.Exception ex)
			{
				Util.LogExceptionOnce("ClientLink.Read", ex);
			}
		}
	}
	internal static class VeinControlConfig
	{
		private const string SectionGeneral = "1. General";

		private const string SectionFeedKey = "2. Separate Feed Key";

		private const string SectionCancel = "3. Non-Lethal Feed Cancel";

		private const string SectionDebug = "4. Debug";

		internal static ConfigFile File;

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<bool> LiveReload;

		internal static ConfigEntry<bool> SeparateFeedKey;

		internal static Hotkey FeedKey;

		internal static Hotkey FeedKeyAlt;

		internal static ConfigEntry<bool> RequireFeedKeyForVBlood;

		internal static ConfigEntry<bool> AllowInteractFallThrough;

		internal static ConfigEntry<bool> StrictInteractWithoutServerMod;

		internal static ConfigEntry<bool> EnableNonLethalCancel;

		internal static ConfigEntry<bool> UseInterruptAbilityCastKey;

		internal static Hotkey CancelFeedKey;

		internal static ConfigEntry<bool> AllowFeedKeyToggleCancel;

		internal static ConfigEntry<bool> AllowPrimaryAttackCancel;

		internal static ConfigEntry<float> SpareGraceSeconds;

		internal static ConfigEntry<bool> LogDiagnostics;

		private const float PollSeconds = 0.5f;

		private static float _nextPoll;

		private static System.DateTime _loadedWriteTime;

		private static System.DateTime _pendingWriteTime;

		private static bool _reloadErrorLogged;

		internal static bool SeparationActive => Enabled.Value && SeparateFeedKey.Value;

		internal static bool SpareActive => Enabled.Value && EnableNonLethalCancel.Value;

		internal static void Bind(ConfigFile cfg)
		{
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Expected O, but got Unknown
			File = cfg;
			Enabled = cfg.Bind<bool>("1. General", "Enabled", true, "Master switch for VeinControl. Off: vanilla Feed and Interact behavior.");
			LiveReload = cfg.Bind<bool>("1. General", "LiveReload", true, "Re-reads this config file automatically about half a second after it is saved, so changes apply without restarting the game.");
			SeparateFeedKey = cfg.Bind<bool>("2. Separate Feed Key", "SeparateFeedKey", true, "The Interact key (vanilla: F) no longer bites (feeds on) wounded enemies. Biting needs FeedKey or FeedKeyAlt. Works on every server, also on servers without VeinControl.");
			FeedKey = Hotkey.Bind(cfg, "2. Separate Feed Key", "FeedKey", HotkeyKey.F2, "Key that bites (feeds on) a wounded target. The floating prompt shows this key instead of Interact.");
			FeedKeyAlt = Hotkey.Bind(cfg, "2. Separate Feed Key", "FeedKeyAlt", HotkeyKey.None, "Alternative bite key, like the second keybind column in the game's settings. Example: Mouse4 to bite with a side mouse button while F2 stays the keyboard key.");
			RequireFeedKeyForVBlood = cfg.Bind<bool>("2. Separate Feed Key", "RequireFeedKeyForVBlood", false, "Off: downed V Blood bosses can be fed on with Interact as well as with the feed keys. On: V Blood bosses also need FeedKey or FeedKeyAlt.");
			AllowInteractFallThrough = cfg.Bind<bool>("2. Separate Feed Key", "AllowInteractFallThrough", true, "On: Interact next to a wounded enemy uses the next object in reach instead (blood orb, loot, door, chest, mount). Off: Interact does nothing while a wounded enemy is targeted.");
			StrictInteractWithoutServerMod = cfg.Bind<bool>("2. Separate Feed Key", "StrictInteractWithoutServerMod", false, "Only for servers WITHOUT VeinControl (no effect in solo games or on servers with VeinControl). There, no server safety net catches a bite that slips through (rare, for example with lag), and a bite cannot be spared: stopping it with LMB kills the target, as in vanilla. This switch is a trade-off, not a must. Off (default): Interact keeps picking up items (blood orbs, loot) next to wounded enemies, with a small remaining risk. On: Interact does nothing at all while a wounded enemy is targeted, so it can never bite there; picking up items next to wounded enemies with Interact is then NOT possible on those servers.");
			EnableNonLethalCancel = cfg.Bind<bool>("3. Non-Lethal Feed Cancel", "EnableNonLethalCancel", true, "Stopping a bite early spares the target, so high-blood targets stay alive for subduing. Needs VeinControl on the server (included automatically in solo games). Never applies to V Blood bosses or revives.");
			UseInterruptAbilityCastKey = cfg.Bind<bool>("3. Non-Lethal Feed Cancel", "UseInterruptAbilityCastKey", true, "Your in-game 'Interrupt Ability Cast' key (Controls -> General) spares the target during a bite. That key has no other function during a bite, so sharing it is intended. Off: only the keys below spare the target.");
			CancelFeedKey = Hotkey.Bind(cfg, "3. Non-Lethal Feed Cancel", "CancelFeedKey", HotkeyKey.None, "Extra key that spares the target during a bite. Useful if 'Interrupt Ability Cast' is not bound in the game's settings.");
			AllowFeedKeyToggleCancel = cfg.Bind<bool>("3. Non-Lethal Feed Cancel", "AllowFeedKeyToggleCancel", true, "Pressing FeedKey or FeedKeyAlt during a bite spares the target (also when the bite was started with the other key).");
			AllowPrimaryAttackCancel = cfg.Bind<bool>("3. Non-Lethal Feed Cancel", "AllowPrimaryAttackCancel", false, "Off: [LMB] Abort during a bite still kills the target without taking its blood, as in vanilla (a quick finisher). On: [LMB] Abort also spares the target (needs VeinControl on the server). Note: your character still swings right after the bite stops. SpareGraceSeconds (below) makes sure that swing does no damage.");
			SpareGraceSeconds = cfg.Bind<float>("3. Non-Lethal Feed Cancel", "SpareGraceSeconds", 1.5f, new ConfigDescription("After every spare (with any spare key), your own hits on the spared target (and those of your minions) do no damage for this many seconds. It catches the swing that follows a spare with LMB (AllowPrimaryAttackCancel) and hasty hits right after any spare; your attacks count again after that moment. Damage from other players and from enemies still counts. Example: 1.5 = one and a half seconds. 0 = off. Needs VeinControl on the server; the server may set a lower limit (MaxSpareGraceSeconds).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 5f), System.Array.Empty<object>()));
			LogDiagnostics = cfg.Bind<bool>("4. Debug", "LogDiagnostics", false, "Writes feed key decisions, pass-by results, interact targets (incl. mount revive and prison cells) and spare requests to the BepInEx log.");
			_loadedWriteTime = WriteTime();
			_pendingWriteTime = _loadedWriteTime;
		}

		private static System.DateTime WriteTime()
		{
			try
			{
				string configFilePath = File.ConfigFilePath;
				return File.Exists(configFilePath) ? File.GetLastWriteTimeUtc(configFilePath) : System.DateTime.MinValue;
			}
			catch (System.Exception)
			{
				return System.DateTime.MinValue;
			}
		}

		internal static void PollLiveReload()
		{
			if (File == null || !LiveReload.Value)
			{
				return;
			}
			float unscaledTime = Time.unscaledTime;
			if (unscaledTime < _nextPoll)
			{
				return;
			}
			_nextPoll = unscaledTime + 0.5f;
			System.DateTime dateTime = WriteTime();
			if (dateTime == System.DateTime.MinValue || dateTime == _loadedWriteTime)
			{
				return;
			}
			if (dateTime != _pendingWriteTime)
			{
				_pendingWriteTime = dateTime;
				return;
			}
			bool saveOnConfigSet = File.SaveOnConfigSet;
			File.SaveOnConfigSet = false;
			try
			{
				File.Reload();
				_loadedWriteTime = WriteTime();
				_pendingWriteTime = _loadedWriteTime;
				_reloadErrorLogged = false;
				VeinControlPlugin.Log.LogInfo((object)"Config file changed, reloaded (LiveReload).");
			}
			catch (System.Exception ex)
			{
				if (!_reloadErrorLogged)
				{
					_reloadErrorLogged = true;
					VeinControlPlugin.Log.LogWarning((object)("Config reload failed, trying again: " + ex.Message));
				}
			}
			finally
			{
				File.SaveOnConfigSet = saveOnConfigSet;
			}
		}

		internal static void Diag(string text)
		{
			if (LogDiagnostics != null && LogDiagnostics.Value)
			{
				VeinControlPlugin.Log.LogInfo((object)("[Diag] " + text));
			}
		}
	}
	public enum HotkeyKey
	{
		None,
		F1,
		F2,
		F3,
		F4,
		F5,
		F6,
		F7,
		F8,
		F9,
		F10,
		F11,
		F12,
		PageUp,
		PageDown,
		Home,
		End,
		Insert,
		Delete,
		Pause,
		ScrollLock,
		Alpha0,
		Alpha1,
		Alpha2,
		Alpha3,
		Alpha4,
		Alpha5,
		Alpha6,
		Alpha7,
		Alpha8,
		Alpha9,
		A,
		B,
		C,
		D,
		E,
		F,
		G,
		H,
		I,
		J,
		K,
		L,
		M,
		N,
		O,
		P,
		Q,
		R,
		S,
		T,
		U,
		V,
		W,
		X,
		Y,
		Z,
		Keypad0,
		Keypad1,
		Keypad2,
		Keypad3,
		Keypad4,
		Keypad5,
		Keypad6,
		Keypad7,
		Keypad8,
		Keypad9,
		KeypadPeriod,
		KeypadDivide,
		KeypadMultiply,
		KeypadMinus,
		KeypadPlus,
		KeypadEnter,
		UpArrow,
		DownArrow,
		LeftArrow,
		RightArrow,
		Tab,
		Space,
		Return,
		Backspace,
		BackQuote,
		Minus,
		Equals,
		LeftBracket,
		RightBracket,
		Backslash,
		Semicolon,
		Quote,
		Comma,
		Period,
		Slash,
		Mouse3,
		Mouse4,
		Mouse5,
		Mouse6
	}
	public enum HotkeyModifier
	{
		None,
		Shift,
		Control,
		Alt
	}
	internal class Hotkey
	{
		public ConfigEntry<HotkeyKey> Key;

		public ConfigEntry<HotkeyModifier> Modifier;

		private HotkeyKey _cachedKey = HotkeyKey.None;

		private KeyCode _cachedKeyCode = (KeyCode)0;

		public KeyCode KeyCode
		{
			get
			{
				//IL_0047: Unknown result type (might be due to invalid IL or missing references)
				//IL_004c: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: 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_0040: Unknown result type (might be due to invalid IL or missing references)
				HotkeyKey value = Key.Value;
				if (value != _cachedKey)
				{
					_cachedKey = value;
					KeyCode val = default(KeyCode);
					_cachedKeyCode = (KeyCode)(System.Enum.TryParse<KeyCode>(((object)value/*cast due to .constrained prefix*/).ToString(), ref val) ? ((int)val) : 0);
				}
				return _cachedKeyCode;
			}
		}

		public bool IsBound => (int)KeyCode > 0;

		internal static Hotkey Bind(ConfigFile cfg, string section, string name, HotkeyKey defaultKey, string description)
		{
			return new Hotkey
			{
				Key = cfg.Bind<HotkeyKey>(section, name, defaultKey, description + " None = not bound. Choose a key the game does not use outside menus: a key with its own in-game binding (e.g. Q, a weapon skill by default) triggers both actions. Letter keys follow the key positions of a US keyboard (on a German keyboard, Y is the key labelled Z); Mouse3 is the game's Mouse Button 5, Mouse4 its Mouse Button 4. The floating prompt shows the game's name of the key."),
				Modifier = cfg.Bind<HotkeyModifier>(section, name + "Modifier", HotkeyModifier.None, "Modifier for " + name + ": None (no modifier held), Shift, Control or Alt. Note: Shift, Ctrl and Alt already have actions in the game's default keybindings, so pressing the modifier also triggers its in-game action (check your own bindings).")
			};
		}

		public bool IsDown()
		{
			//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_000b: Unknown result type (might be due to invalid IL or missing references)
			KeyCode keyCode = KeyCode;
			if ((int)keyCode == 0 || !Input.GetKeyDown(keyCode))
			{
				return false;
			}
			bool flag = Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303);
			bool flag2 = Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305);
			bool flag3 = Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307) || Input.GetKey((KeyCode)313);
			return Modifier.Value switch
			{
				HotkeyModifier.Shift => flag && !flag2 && !flag3, 
				HotkeyModifier.Control => flag2 && !flag && !flag3, 
				HotkeyModifier.Alt => flag3 && !flag && !flag2, 
				_ => !flag && !flag2 && !flag3, 
			};
		}

		public bool IsHeld()
		{
			//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_000b: Unknown result type (might be due to invalid IL or missing references)
			KeyCode keyCode = KeyCode;
			return (int)keyCode != 0 && Input.GetKey(keyCode);
		}

		public virtual string ToString()
		{
			if (!IsBound)
			{
				return "not bound";
			}
			return Modifier.Value switch
			{
				HotkeyModifier.Shift => "Shift+" + ((object)Key.Value/*cast due to .constrained prefix*/).ToString(), 
				HotkeyModifier.Control => "Ctrl+" + ((object)Key.Value/*cast due to .constrained prefix*/).ToString(), 
				HotkeyModifier.Alt => "Alt+" + ((object)Key.Value/*cast due to .constrained prefix*/).ToString(), 
				_ => ((object)Key.Value/*cast due to .constrained prefix*/).ToString(), 
			};
		}
	}
	internal static class Util
	{
		internal const SyncedButtonInputAction Interact = (SyncedButtonInputAction)1;

		internal const SyncedButtonInputAction Interrupt = (SyncedButtonInputAction)4096;

		internal const SyncedButtonInputAction Primary = (SyncedButtonInputAction)2;

		internal const SyncedButtonInputAction None = (SyncedButtonInputAction)0;

		private static readonly CultureInfo Inv = CultureInfo.InvariantCulture;

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

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

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

		internal static ManualLogSource Log => VeinControlPlugin.Log;

		internal static string F(float v)
		{
			return v.ToString("0.##", (IFormatProvider)(object)Inv);
		}

		internal static void LogExceptionOnce(string where, System.Exception ex)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			string text = string.Concat(new string[5]
			{
				where,
				":",
				((MemberInfo)ex.GetType()).Name,
				":",
				ex.Message
			});
			if (LoggedExceptions.Add(text))
			{
				ManualLogSource log = Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(3, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(where);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("] ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<System.Exception>(ex);
				}
				log.LogError(val);
			}
		}

		internal static bool IsNull(Entity e)
		{
			//IL_0000: 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)
			return e.Index == 0 && e.Version == 0;
		}

		internal static bool Same(Entity a, Entity b)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			return a.Index == b.Index && a.Version == b.Version;
		}

		internal static long Key(Entity e)
		{
			//IL_0000: 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)
			return ((long)e.Index << 32) | (uint)e.Version;
		}

		internal static bool Has(SyncedButtonInputAction set, SyncedButtonInputAction bit)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Invalid comparison between Unknown and I4
			return (set & bit) > 0;
		}

		internal static bool IsFeedAbility(World world, EntityManager em, PrefabGUID ability)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			int guidHash = ((PrefabGUID)(ref ability)).GuidHash;
			if (guidHash == 0)
			{
				return false;
			}
			bool result = default(bool);
			if (FeedTagCache.TryGetValue(guidHash, ref result))
			{
				return result;
			}
			bool flag = false;
			try
			{
				PrefabCollectionSystem existingSystemManaged = world.GetExistingSystemManaged<PrefabCollectionSystem>();
				if (existingSystemManaged != null)
				{
					PrefabLookupMap prefabLookupMap = existingSystemManaged._PrefabLookupMap;
					Entity val = default(Entity);
					if (((PrefabLookupMap)(ref prefabLookupMap)).TryGetValue(ability, ref val) && ((EntityManager)(ref em)).Exists(val))
					{
						flag = ((EntityManager)(ref em)).HasComponent<FeedAbilityTag>(val);
					}
				}
			}
			catch (System.Exception ex)
			{
				LogExceptionOnce("IsFeedAbility", ex);
			}
			FeedTagCache[guidHash] = flag;
			return flag;
		}

		internal static bool OnlyFeedAbilities(World world, EntityManager em, Entity u)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0040: Unknown result type (might be due to invalid IL or missing references)
			if (!((EntityManager)(ref em)).HasComponent<InteractAbilityBuffer>(u))
			{
				return false;
			}
			DynamicBuffer<InteractAbilityBuffer> buffer = ((EntityManager)(ref em)).GetBuffer<InteractAbilityBuffer>(u, true);
			if (buffer.Length == 0)
			{
				return false;
			}
			for (int i = 0; i < buffer.Length; i++)
			{
				if (!IsFeedAbility(world, em, buffer[i].Ability))
				{
					return false;
				}
			}
			return true;
		}

		internal static bool IsVBlood(EntityManager em, Entity e)
		{
			//IL_0000: 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_0014: Unknown result type (might be due to invalid IL or missing references)
			return !IsNull(e) && ((EntityManager)(ref em)).Exists(e) && ((EntityManager)(ref em)).HasComponent<VBloodConsumeSource>(e);
		}

		internal static bool IsMount(EntityManager em, Entity e)
		{
			//IL_0000: 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_0014: Unknown result type (might be due to invalid IL or missing references)
			return !IsNull(e) && ((EntityManager)(ref em)).Exists(e) && ((EntityManager)(ref em)).HasComponent<Mountable>(e);
		}

		internal static bool IsSeparatedFeedTarget(World world, EntityManager em, Entity target, PrefabGUID ability, bool vbloodNeedsFeedKey)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			if (!IsFeedAbility(world, em, ability))
			{
				return false;
			}
			if (IsNull(target) || !((EntityManager)(ref em)).Exists(target))
			{
				return false;
			}
			if (IsMount(em, target))
			{
				return false;
			}
			if (!vbloodNeedsFeedKey && IsVBlood(em, target))
			{
				return false;
			}
			return true;
		}

		internal static bool TryGetInteractor(EntityManager em, Entity character, out Interactor interactor)
		{
			//IL_0002: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			interactor = default(Interactor);
			if (!((EntityManager)(ref em)).HasComponent<Interactor>(character))
			{
				return false;
			}
			interactor = ((EntityManager)(ref em)).GetComponentData<Interactor>(character);
			return true;
		}

		internal static Entity SpellTargetOf(EntityManager em, Entity buff)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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)
			return ((EntityManager)(ref em)).HasComponent<SpellTarget>(buff) ? ((EntityManager)(ref em)).GetComponentData<SpellTarget>(buff).Target._Entity : Entity.Null;
		}

		internal static Entity OwnerOf(EntityManager em, Entity e)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			return ((EntityManager)(ref em)).HasComponent<EntityOwner>(e) ? ((EntityManager)(ref em)).GetComponentData<EntityOwner>(e).Owner : Entity.Null;
		}

		internal static bool TryPos(EntityManager em, Entity e, out float3 pos)
		{
			//IL_0002: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			//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_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_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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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)
			pos = default(float3);
			if (!((EntityManager)(ref em)).HasComponent<LocalToWorld>(e))
			{
				return false;
			}
			float4 c = ((EntityManager)(ref em)).GetComponentData<LocalToWorld>(e).Value.c3;
			pos = new float3(c.x, c.y, c.z);
			return true;
		}

		internal static float DistSq(float3 a, float3 b)
		{
			//IL_0001: 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_000f: 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_001d: 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)
			float num = a.x - b.x;
			float num2 = a.y - b.y;
			float num3 = a.z - b.z;
			return num * num + num2 * num2 + num3 * num3;
		}

		internal static string PrefabName(World world, PrefabGUID guid)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			int guidHash = ((PrefabGUID)(ref guid)).GuidHash;
			if (guidHash == 0)
			{
				return "none";
			}
			string result = default(string);
			if (PrefabNames.TryGetValue(guidHash, ref result))
			{
				return result;
			}
			string text = guidHash.ToString((IFormatProvider)(object)Inv);
			try
			{
				PrefabCollectionSystem existingSystemManaged = world.GetExistingSystemManaged<PrefabCollectionSystem>();
				FixedString128Bytes val = default(FixedString128Bytes);
				if (existingSystemManaged != null)
				{
					PrefabLookupMap prefabLookupMap = existingSystemManaged._PrefabLookupMap;
					if (((PrefabLookupMap)(ref prefabLookupMap)).TryGetFixedName(guid, ref val))
					{
						text = $"{val}({guidHash})";
					}
				}
			}
			catch (System.Exception ex)
			{
				LogExceptionOnce("PrefabName", ex);
			}
			PrefabNames[guidHash] = text;
			return text;
		}

		internal static string Describe(World world, EntityManager em, Entity e)
		{
			//IL_0001: 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_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			if (IsNull(e))
			{
				return "nothing";
			}
			if (!((EntityManager)(ref em)).Exists(e))
			{
				return "gone";
			}
			return ((EntityManager)(ref em)).HasComponent<PrefabGUID>(e) ? PrefabName(world, ((EntityManager)(ref em)).GetComponentData<PrefabGUID>(e)) : $"{e.Index}:{e.Version}";
		}
	}
	internal static class Protocol
	{
		internal const int Version = 1;

		internal const string Marker = "[[VeinControl]] ";

		internal const string Hello = "[VeinControl] Feed control is active on this server.";

		internal const SyncedButtonInputAction BiteMarker = (SyncedButtonInputAction)16384;

		internal const float DefaultGraceSeconds = 1.5f;

		internal static string SettingsWire(bool separate, bool spare, float grace)
		{
			return $"set {1} {(separate ? 1 : 0)} {(spare ? 1 : 0)} {grace.ToString("0.###", (IFormatProvider)(object)CultureInfo.InvariantCulture)}";
		}
	}
	internal static class ClientLink
	{
		private const int CheckIntervalFrames = 30;

		private static ulong _greetedWorld;

		private static bool _greeted;

		private static bool _serverSpare;

		private static string _lastSent;

		private static int _nextCheckFrame;

		private static ulong _noticeWorld;

		internal static bool ServerPresent(World world)
		{
			return _greeted && world != null && world.SequenceNumber == _greetedWorld;
		}

		internal static bool ServerAllowsSpare(World world)
		{
			return ServerPresent(world) && _serverSpare;
		}

		internal unsafe static void ReadServerMessages(ClientChatSystem sys)
		{
			//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_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_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_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_0026: 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_0038: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Invalid comparison between Unknown and I4
			//IL_00a1: 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_00ec: Expected O, but got Unknown
			EntityManager entityManager = ((ComponentSystemBase)sys).EntityManager;
			EntityQuery receiveChatMessagesQuery = sys._ReceiveChatMessagesQuery;
			NativeArray<Entity> val = ((EntityQuery)(ref receiveChatMessagesQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			try
			{
				Enumerator<Entity> enumerator = val.GetEnumerator();
				bool flag = default(bool);
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					if (!((EntityManager)(ref entityManager)).HasComponent<ChatMessageServerEvent>(current))
					{
						continue;
					}
					ChatMessageServerEvent componentData = ((EntityManager)(ref entityManager)).GetComponentData<ChatMessageServerEvent>(current);
					if ((int)componentData.MessageType != 6)
					{
						continue;
					}
					string text = ((object)(*(FixedString512Bytes*)(&componentData.MessageText))/*cast due to .constrained prefix*/).ToString();
					if (text.StartsWith("[VeinControl] Feed control is active on this server.", (StringComparison)4))
					{
						((EntityManager)(ref entityManager)).DestroyEntity(current);
						_greeted = true;
						_greetedWorld = ((ComponentSystemBase)sys).World.SequenceNumber;
						_serverSpare = !text.Contains("spare=0");
						_lastSent = null;
						ManualLogSource log = VeinControlPlugin.Log;
						BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(56, 1, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("The server runs VeinControl: non-lethal feed cancel is ");
							((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(_serverSpare ? "available" : "switched off by the server");
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(".");
						}
						log.LogInfo(val2);
					}
				}
			}
			finally
			{
				val.Dispose();
			}
		}

		internal static void Tick(World world)
		{
			if (world == null)
			{
				return;
			}
			int frameCount = Time.frameCount;
			if (frameCount < _nextCheckFrame)
			{
				return;
			}
			_nextCheckFrame = frameCount + 30;
			if (!ServerPresent(world))
			{
				Entity val = default(Entity);
				if (_noticeWorld != world.SequenceNumber && ConsoleShared.TryGetLocalCharacterInCurrentWorld(ref val, world))
				{
					_noticeWorld = world.SequenceNumber;
					VeinControlPlugin.Log.LogInfo((object)"Your character is in the world, and no VeinControl server part has greeted so far. If no line \"The server runs VeinControl\" follows, the separate feed key still works, but the non-lethal feed cancel is not available here (solo play and hosting need the ServerLaunchFix mod; on a dedicated server, VeinControl must be installed on the server).");
				}
				return;
			}
			string text = Protocol.SettingsWire(VeinControlConfig.SeparationActive, VeinControlConfig.SpareActive, VeinControlConfig.SpareGraceSeconds.Value);
			if (!(text == _lastSent))
			{
				Send(world, text);
				_lastSent = text;
				VeinControlConfig.Diag("settings sent to the server: '" + text + "'");
			}
		}

		private static void Send(World world, string text)
		{
			//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_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_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_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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_0040: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = world.EntityManager;
			Entity val = ((EntityManager)(ref entityManager)).CreateEntity((ComponentType[])(object)new ComponentType[3]
			{
				ComponentType.ReadOnly<SendNetworkEventTag>(),
				ComponentType.ReadOnly<NetworkEventType>(),
				ComponentType.ReadOnly<ChatMessageEvent>()
			});
			try
			{
				((EntityManager)(ref entityManager)).SetComponentData<ChatMessageEvent>(val, new ChatMessageEvent
				{
					MessageType = (ChatMessageType)4,
					MessageText = new FixedString512Bytes("[[VeinControl]] " + text)
				});
				((EntityManager)(ref entityManager)).SetComponentData<NetworkEventType>(val, new NetworkEventType
				{
					EventId = NetworkEvents.EventId_ChatMessageEvent,
					IsAdminEvent = false,
					IsDebugEvent = false
				});
			}
			catch
			{
				((EntityManager)(ref entityManager)).DestroyEntity(val);
				throw;
			}
		}
	}
	internal struct InputEdit
	{
		public SyncedButtonInputAction AddDown;

		public SyncedButtonInputAction AddPressed;

		public SyncedButtonInputAction AddUp;

		public SyncedButtonInputAction Remove;

		public bool Any => (int)AddDown != 0 || (int)AddPressed != 0 || (int)AddUp != 0 || (int)Remove > 0;

		public SyncedInputState Apply(SyncedInputState s)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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_0020: 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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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_003e: 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_0049: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			s.InputsDown = (SyncedButtonInputAction)((s.InputsDown & (ushort)(~Remove)) | AddDown);
			s.InputsPressed = (SyncedButtonInputAction)((s.InputsPressed & (ushort)(~Remove)) | AddPressed);
			s.InputsUp = (SyncedButtonInputAction)((s.InputsUp & (ushort)(~Remove)) | AddUp);
			return s;
		}
	}
	internal static class FeedInput
	{
		private struct FeedInfo
		{
			public bool Feeding;

			public bool IsRevive;

			public bool VBlood;

			public Entity Victim;
		}

		private const int MaskTailFrames = 20;

		private static World _stateWorld;

		private static Entity _stateEntity;

		private static EntityQuery _siphonQuery;

		private static World _siphonWorld;

		private static bool _feedInject;

		private static SyncedButtonInputAction _feedMarker;

		private static bool _pendingFeedPress;

		private static bool _toggleArmed;

		private static bool _wasFeeding;

		private static bool _interruptUpNext;

		private static bool _interactUpNext;

		private static bool _heldBack;

		private static Entity _lastDiagTarget;

		private static int _lastDiagAbility;

		[field: CompilerGenerated]
		[field: DebuggerBrowsable(/*Could not decode attribute arguments.*/)]
		internal static bool SpareableFeedActive
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			private set;
		}

		[field: CompilerGenerated]
		[field: DebuggerBrowsable(/*Could not decode attribute arguments.*/)]
		internal static InputActionSystem InputActions
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			private set;
		}

		internal static void Teardown()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (_stateWorld != null && _stateWorld.IsCreated)
				{
					FeedMask.Restore(_stateWorld.EntityManager, "plugin unloaded");
				}
			}
			catch
			{
			}
		}

		private static bool FindState(World world, EntityManager em)
		{
			//IL_000b: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			if (_stateWorld == world && ((EntityManager)(ref em)).Exists(_stateEntity))
			{
				return true;
			}
			_stateWorld = world;
			_stateEntity = Entity.Null;
			EntityQuery val = ((EntityManager)(ref em)).CreateEntityQuery((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadWrite<State>() });
			NativeArray<Entity> val2 = ((EntityQuery)(ref val)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			try
			{
				if (val2.Length > 0)
				{
					_stateEntity = val2[0];
				}
			}
			finally
			{
				val2.Dispose();
			}
			if (Util.IsNull(_stateEntity))
			{
				Util.LogExceptionOnce("FindState", new System.Exception("GameplayInputSystem.State not found: VeinControl cannot change any input in this world."));
				return false;
			}
			return true;
		}

		internal static void Prefix(GameplayInputSystem sys)
		{
			//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_0032: 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_0080: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00e3: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			World world = ((ComponentSystemBase)sys).World;
			EntityManager entityManager = ((ComponentSystemBase)sys).EntityManager;
			InputActions = sys._InputActionSystem;
			Entity local = default(Entity);
			if (!ConsoleShared.TryGetLocalCharacterInCurrentWorld(ref local, world) || !FindState(world, entityManager))
			{
				return;
			}
			int frameCount = Time.frameCount;
			FeedMask.Tick(entityManager, frameCount);
			if (!VeinControlConfig.Enabled.Value)
			{
				FeedMask.Restore(entityManager, "VeinControl disabled");
				ResetPressState();
				return;
			}
			FeedInfo feed = LocalFeed(world, entityManager, local);
			SpareableFeedActive = feed.Feeding && !feed.IsRevive && !feed.VBlood;
			State componentData = ((EntityManager)(ref entityManager)).GetComponentData<State>(_stateEntity);
			SyncedInputState inputState = componentData.Input.InputState;
			InputEdit inputEdit = (feed.Feeding ? DecideWhileFeeding(world, feed, inputState) : DecideNotFeeding(world, entityManager, local, inputState, frameCount));
			_wasFeeding = feed.Feeding;
			if (inputEdit.Any)
			{
				Input input = componentData.Input;
				input.InputState = inputEdit.Apply(inputState);
				componentData.Input = input;
				((EntityManager)(ref entityManager)).SetComponentData<State>(_stateEntity, componentData);
			}
		}

		private static void ResetPressState()
		{
			_feedInject = false;
			_pendingFeedPress = false;
			_heldBack = false;
		}

		private static InputEdit PendingUps()
		{
			InputEdit result = default(InputEdit);
			if (_interruptUpNext)
			{
				_interruptUpNext = false;
				ref SyncedButtonInputAction addUp = ref result.AddUp;
				addUp = (SyncedButtonInputAction)((uint)addUp | 0x1000u);
			}
			if (_interactUpNext)
			{
				_interactUpNext = false;
				ref SyncedButtonInputAction addUp2 = ref result.AddUp;
				addUp2 = (SyncedButtonInputAction)((uint)addUp2 | 1u);
			}
			return result;
		}

		private static InputEdit DecideWhileFeeding(World world, FeedInfo feed, SyncedInputState real)
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: 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_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			InputEdit result = PendingUps();
			ResetPressState();
			bool flag = VeinControlConfig.FeedKey.IsHeld() || VeinControlConfig.FeedKeyAlt.IsHeld();
			bool flag2 = VeinControlConfig.FeedKey.IsDown() || VeinControlConfig.FeedKeyAlt.IsDown();
			if (!_wasFeeding)
			{
				_toggleArmed = false;
			}
			if (!flag)
			{
				_toggleArmed = true;
			}
			if (feed.IsRevive || feed.VBlood)
			{
				return result;
			}
			bool spareActive = VeinControlConfig.SpareActive;
			if ((!spareActive || !VeinControlConfig.UseInterruptAbilityCastKey.Value) && Util.Has((SyncedButtonInputAction)(real.InputsDown | real.InputsPressed), (SyncedButtonInputAction)4096))
			{
				ref SyncedButtonInputAction remove = ref result.Remove;
				remove = (SyncedButtonInputAction)((uint)remove | 0x1000u);
			}
			if (!spareActive || !ClientLink.ServerAllowsSpare(world))
			{
				return result;
			}
			string text = null;
			if (VeinControlConfig.AllowFeedKeyToggleCancel.Value && flag2 && _toggleArmed)
			{
				text = "feed key";
				_toggleArmed = false;
			}
			if (VeinControlConfig.CancelFeedKey.IsDown())
			{
				text = "CancelFeedKey";
			}
			if (VeinControlConfig.AllowPrimaryAttackCancel.Value)
			{
				if (Util.Has((SyncedButtonInputAction)(real.InputsDown | real.InputsPressed | real.InputsUp), (SyncedButtonInputAction)2))
				{
					ref SyncedButtonInputAction remove2 = ref result.Remove;
					remove2 = (SyncedButtonInputAction)((uint)remove2 | 2u);
				}
				if (Util.Has(real.InputsDown, (SyncedButtonInputAction)2))
				{
					text = "LMB (AllowPrimaryAttackCancel)";
				}
			}
			if (text != null)
			{
				ref SyncedButtonInputAction addDown = ref result.AddDown;
				addDown = (SyncedButtonInputAction)((uint)addDown | 0x1000u);
				ref SyncedButtonInputAction addPressed = ref result.AddPressed;
				addPressed = (SyncedButtonInputAction)((uint)addPressed | 0x1000u);
				_interruptUpNext = true;
				VeinControlConfig.Diag("spare request (" + text + ") during the feed on " + Util.Describe(world, world.EntityManager, feed.Victim));
			}
			return result;
		}

		private static InputEdit DecideNotFeeding(World world, EntityManager em, Entity local, SyncedInputState real, int frame)
		{
			//IL_0042: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: 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)
			//IL_0093: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Expected I4, but got Unknown
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: 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_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Expected I4, but got Unknown
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Expected I4, but got Unknown
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: Unknown result type (might be due to invalid IL or missing references)
			//IL_035c: Unknown result type (might be due to invalid IL or missing references)
			InputEdit result = PendingUps();
			if (!VeinControlConfig.SeparationActive)
			{
				FeedMask.Restore(em, "separate feed key off");
				ResetPressState();
				return result;
			}
			bool flag = ClientLink.ServerPresent(world);
			bool value = VeinControlConfig.RequireFeedKeyForVBlood.Value;
			Util.TryGetInteractor(em, local, out var interactor);
			bool flag2 = Util.IsFeedAbility(world, em, interactor.InteractAbilityGuid) && !Util.IsNull(interactor.Target) && ((EntityManager)(ref em)).Exists(interactor.Target) && !Util.IsMount(em, interactor.Target);
			bool flag3 = Util.IsSeparatedFeedTarget(world, em, interactor.Target, interactor.InteractAbilityGuid, value);
			bool flag4 = Util.IsNull(interactor.Target);
			DiagTarget(world, em, interactor, flag2, flag3);
			bool flag5 = VeinControlConfig.FeedKey.IsHeld() || VeinControlConfig.FeedKeyAlt.IsHeld();
			bool flag6 = VeinControlConfig.FeedKey.IsDown() || VeinControlConfig.FeedKeyAlt.IsDown();
			if (flag6 || _pendingFeedPress)
			{
				_heldBack = false;
				if (flag6 && FeedMask.On)
				{
					FeedMask.Restore(em, "feed key pressed");
					_pendingFeedPress = true;
					return result;
				}
				_pendingFeedPress = false;
				if (!flag2)
				{
					VeinControlConfig.Diag("feed key pressed, but the interact target is no Feed target (" + Util.Describe(world, em, interactor.Target) + ")");
					return result;
				}
				_feedMarker = (SyncedButtonInputAction)(flag ? 16384 : 0);
				ref SyncedButtonInputAction addDown = ref result.AddDown;
				addDown = (SyncedButtonInputAction)(addDown | (1 | _feedMarker));
				ref SyncedButtonInputAction addPressed = ref result.AddPressed;
				addPressed = (SyncedButtonInputAction)(addPressed | (1 | _feedMarker));
				if (flag5)
				{
					_feedInject = true;
				}
				else
				{
					_interactUpNext = true;
				}
				VeinControlConfig.Diag("feed key -> bite " + Util.Describe(world, em, interactor.Target) + (flag ? " (with bite marker)" : ""));
				return result;
			}
			if (_feedInject)
			{
				if (flag5)
				{
					ref SyncedButtonInputAction addPressed2 = ref result.AddPressed;
					addPressed2 = (SyncedButtonInputAction)(addPressed2 | (1 | _feedMarker));
				}
				else
				{
					ref SyncedButtonInputAction addUp = ref result.AddUp;
					addUp = (SyncedButtonInputAction)((uint)addUp | 1u);
					_feedInject = false;
				}
				return result;
			}
			bool flag7 = Util.Has(real.InputsDown, (SyncedButtonInputAction)1);
			bool flag8 = Util.Has(real.InputsPressed, (SyncedButtonInputAction)1);
			bool flag9 = !flag && VeinControlConfig.StrictInteractWithoutServerMod.Value;
			bool flag10 = VeinControlConfig.AllowInteractFallThrough.Value && !flag9;
			if (!flag7 && !flag8)
			{
				if (_heldBack)
				{
					_heldBack = false;
					if (!flag3 && !flag4)
					{
						ref SyncedButtonInputAction addDown2 = ref result.AddDown;
						addDown2 = (SyncedButtonInputAction)((uint)addDown2 | 1u);
						_interactUpNext = true;
						VeinControlConfig.Diag("Interact (short press) passed on to " + Util.Describe(world, em, interactor.Target));
					}
				}
				return result;
			}
			if (flag3 && flag10)
			{
				FeedMask.Activate(world, em, local, frame + 20, value);
			}
			else if (FeedMask.On)
			{
				FeedMask.KeepAlive(frame + 20);
			}
			if (flag3 || flag4)
			{
				ref SyncedButtonInputAction remove = ref result.Remove;
				remove = (SyncedButtonInputAction)((uint)remove | 1u);
				if (!_heldBack)
				{
					_heldBack = true;
					if (flag3)
					{
						VeinControlConfig.Diag("Interact on Feed target " + Util.Describe(world, em, interactor.Target) + ": held back" + (flag10 ? ", looking for the next object" : (" (" + (flag9 ? "StrictInteractWithoutServerMod" : "AllowInteractFallThrough off") + ")")));
					}
				}
				return result;
			}
			if (_heldBack)
			{
				_heldBack = false;
				ref SyncedButtonInputAction addDown3 = ref result.AddDown;
				addDown3 = (SyncedButtonInputAction)((uint)addDown3 | 1u);
				VeinControlConfig.Diag("Interact passed on to " + Util.Describe(world, em, interactor.Target));
			}
			return result;
		}

		private static FeedInfo LocalFeed(World world, EntityManager em, Entity local)
		{
			//IL_0044: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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_009a: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			if (_siphonWorld != world)
			{
				_siphonQuery = ((EntityManager)(ref em)).CreateEntityQuery((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<Script_Siphon_Blood_Buff_DataShared>() });
				_siphonWorld = world;
			}
			FeedInfo result = default(FeedInfo);
			NativeArray<Entity> val = ((EntityQuery)(ref _siphonQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			try
			{
				for (int i = 0; i < val.Length; i++)
				{
					Entity val2 = val[i];
					if (Util.Same(Util.OwnerOf(em, val2), local))
					{
						result.Feeding = true;
						result.IsRevive = ((EntityManager)(ref em)).GetComponentData<Script_Siphon_Blood_Buff_DataShared>(val2).IsRevive;
						result.Victim = Util.SpellTargetOf(em, val2);
						result.VBlood = Util.IsVBlood(em, result.Victim);
					}
				}
			}
			finally
			{
				val.Dispose();
			}
			return result;
		}

		private static void DiagTarget(World world, EntityManager em, Interactor it, bool feedable, bool separated)
		{
			//IL_0017: 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_001d: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: 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_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			if (VeinControlConfig.LogDiagnostics.Value && (!Util.Same(it.Target, _lastDiagTarget) || ((PrefabGUID)(ref it.InteractAbilityGuid)).GuidHash != _lastDiagAbility))
			{
				_lastDiagTarget = it.Target;
				_lastDiagAbility = ((PrefabGUID)(ref it.InteractAbilityGuid)).GuidHash;
				if (!Util.IsNull(it.Target))
				{
					bool flag = Util.IsFeedAbility(world, em, it.InteractAbilityGuid);
					VeinControlConfig.Diag($"interact target {Util.Describe(world, em, it.Target)} via {Util.PrefabName(world, it.InteractAbilityGuid)}: feedTag={flag} mount={Util.IsMount(em, it.Target)} vblood={Util.IsVBlood(em, it.Target)} -> {(separated ? "needs the feed key" : (feedable ? "Feed allowed with Interact" : "normal interaction"))}");
				}
			}
		}
	}
	internal static class FeedMask
	{
		private const float Range = 10f;

		private static readonly List<Entity> Masked = new List<Entity>();

		private static EntityQuery _query;

		private static World _queryWorld;

		private static int _until = -1;

		[field: CompilerGenerated]
		[field: DebuggerBrowsable(/*Could not decode attribute arguments.*/)]
		internal static bool On
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			private set;
		}

		internal static void Activate(World world, EntityManager em, Entity local, int until, bool includeVBlood)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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_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)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			_until = Math.Max(_until, until);
			bool flag = !On;
			On = true;
			int count = Masked.Count;
			if (_queryWorld != world)
			{
				_query = ((EntityManager)(ref em)).CreateEntityQuery((ComponentType[])(object)new ComponentType[2]
				{
					ComponentType.ReadOnly<BloodConsumeSource>(),
					ComponentType.ReadOnly<InteractAbilityBuffer>()
				});
				_queryWorld = world;
			}
			float3 pos;
			bool flag2 = Util.TryPos(em, local, out pos);
			StringBuilder val = ((!VeinControlConfig.LogDiagnostics.Value) ? ((StringBuilder)null) : new StringBuilder());
			NativeArray<Entity> val2 = ((EntityQuery)(ref _query)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			try
			{
				for (int i = 0; i < val2.Length; i++)
				{
					Entity val3 = val2[i];
					if (Util.IsMount(em, val3) || (!includeVBlood && Util.IsVBlood(em, val3)) || (flag2 && Util.TryPos(em, val3, out var pos2) && Util.DistSq(pos, pos2) > 100f) || !Util.OnlyFeedAbilities(world, em, val3))
					{
						continue;
					}
					BloodConsumeSource componentData = ((EntityManager)(ref em)).GetComponentData<BloodConsumeSource>(val3);
					if (componentData.CanBeConsumed)
					{
						componentData.CanBeConsumed = false;
						((EntityManager)(ref em)).SetComponentData<BloodConsumeSource>(val3, componentData);
						Masked.Add(val3);
						if (val != null && val.Length < 400)
						{
							val.Append(' ').Append(Util.Describe(world, em, val3));
						}
					}
				}
			}
			finally
			{
				val2.Dispose();
			}
			if (val != null && (flag || Masked.Count > count))
			{
				VeinControlConfig.Diag($"client mask {(flag ? "on" : "extended")}: {Masked.Count - count} unit(s):{val}");
			}
		}

		internal static void KeepAlive(int until)
		{
			if (On)
			{
				_until = Math.Max(_until, until);
			}
		}

		internal static void Tick(EntityManager em, int frame)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			if (On && frame > _until)
			{
				Restore(em, "Interact released");
			}
		}

		internal static void Restore(EntityManager em, string why)
		{
			//IL_0025: 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_0034: 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_0042: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			if (!On)
			{
				return;
			}
			On = false;
			_until = -1;
			Enumerator<Entity> enumerator = Masked.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					if (((EntityManager)(ref em)).Exists(current) && ((EntityManager)(ref em)).HasComponent<BloodConsumeSource>(current))
					{
						BloodConsumeSource componentData = ((EntityManager)(ref em)).GetComponentData<BloodConsumeSource>(current);
						componentData.CanBeConsumed = true;
						((EntityManager)(ref em)).SetComponentData<BloodConsumeSource>(current, componentData);
					}
				}
			}
			finally
			{
				((System.IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
			}
			Masked.Clear();
			VeinControlConfig.Diag("client mask off (" + why + ")");
		}
	}
	internal static class FeedHudLabels
	{
		private sealed class Prop<T>
		{
			private readonly Func<T> _get;

			private readonly Action<T> _set;

			private readonly Func<T, T, bool> _same;

			private T _vanilla;

			private T _applied;

			private bool _active;

			public Prop(Func<T> get, Action<T> set, Func<T, T, bool> same)
			{
				_get = get;
				_set = set;
				_same = same;
			}

			public void Apply(T want)
			{
				T val = _get.Invoke();
				if (!_active || !_same.Invoke(val, want))
				{
					if (!_active || !_same.Invoke(val, _applied))
					{
						_vanilla = val;
					}
					_set.Invoke(want);
					_applied = want;
					_active = true;
				}
			}

			public void Restore()
			{
				if (_active)
				{
					_active = false;
					if (_same.Invoke(_get.Invoke(), _applied))
					{
						_set.Invoke(_vanilla);
					}
				}
			}
		}

		private const float ModifierGap = 4f;

		private const float MinFontSize = 12f;

		private static System.IntPtr _boundText;

		private static Prop<string> _str;

		private static Prop<TextAlignmentOptions> _align;

		private static Prop<Vector4> _margin;

		private static Prop<float> _size;

		private static Prop<bool> _textOn;

		private static Prop<bool> _textGo;

		private static Prop<bool> _imageOn;

		private static Prop<bool> _imageGo;

		private static Prop<Sprite> _sprite;

		private static bool _applied;

		private static string _lastShape;

		private static string _calKey;

		private static float _rightMargin;

		private static float _keyGap;

		private const string KeyColor = "#82C9D9";

		private static string _lastAbortLine;

		private static int _bindingVersion = -2147483648;

		private static string _interruptKey;

		private static string _primaryKey;

		private static bool Eq<T>(T a, T b)
		{
			return EqualityComparer<T>.Default.Equals(a, b);
		}

		private static bool SameSprite(Sprite a, Sprite b)
		{
			return (((Object)(object)a == (Object)null) ? System.IntPtr.Zero : ((Il2CppObjectBase)a).Pointer) == (((Object)(object)b == (Object)null) ? System.IntPtr.Zero : ((Il2CppObjectBase)b).Pointer);
		}

		private static void Bind(TextMeshProUGUI text, Image image)
		{
			if (!(_boundText == ((Il2CppObjectBase)text).Pointer))
			{
				_boundText = ((Il2CppObjectBase)text).Pointer;
				_applied = false;
				_calKey = null;
				_str = new Prop<string>(() => ((TMP_Text)text).text, delegate(string v)
				{
					((TMP_Text)text).text = v;
				}, Eq);
				_align = new Prop<TextAlignmentOptions>(() => ((TMP_Text)text).alignment, delegate(TextAlignmentOptions v)
				{
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					((TMP_Text)text).alignment = v;
				}, Eq<TextAlignmentOptions>);
				_margin = new Prop<Vector4>(() => ((TMP_Text)text).margin, delegate(Vector4 v)
				{
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					((TMP_Text)text).margin = v;
				}, Eq<Vector4>);
				_size = new Prop<float>(() => ((TMP_Text)text).fontSize, delegate(float v)
				{
					((TMP_Text)text).fontSize = v;
				}, Eq);
				_textOn = new Prop<bool>(() => ((Behaviour)text).enabled, delegate(bool v)
				{
					((Behaviour)text).enabled = v;
				}, Eq);
				_textGo = new Prop<bool>(() => ((Component)text).gameObject.activeSelf, delegate(bool v)
				{
					((Component)text).gameObject.SetActive(v);
				}, Eq);
				_sprite = new Prop<Sprite>(() => image.sprite, delegate(Sprite v)
				{
					image.sprite = v;
				}, SameSprite);
				_imageOn = new Prop<bool>(() => ((Behaviour)image).enabled, delegate(bool v)
				{
					((Behaviour)image).enabled = v;
				}, Eq);
				_imageGo = new Prop<bool>(() => ((Component)image).gameObject.activeSelf, delegate(bool v)
				{
					((Component)image).gameObject.SetActive(v);
				}, Eq);
			}
		}

		internal static void Update(InteractHUDSystem sys)
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			InteractHUDParent interactHUD = sys._InteractHUD;
			if ((Object)(object)interactHUD == (Object)null || (Object)(object)interactHUD.InteractKeyText == (Object)null)
			{
				return;
			}
			TextMeshProUGUI text = interactHUD.InteractKeyText.Text;
			Image interactKeyImage = interactHUD.InteractKeyImage;
			if (!((Object)(object)text == (Object)null) && !((Object)(object)interactKeyImage == (Object)null))
			{
				Bind(text, interactKeyImage);
				Hotkey hotkey = LabelKey();
				if (hotkey != null && VeinControlConfig.SeparationActive && Util.IsSeparatedFeedTarget(((ComponentSystemBase)sys).World, ((ComponentSystemBase)sys).EntityManager, sys._LastInteractTarget, sys._LastInteractAbilityGuid, VeinControlConfig.RequireFeedKeyForVBlood.Value))
				{
					Show(interactHUD, text, interactKeyImage, hotkey);
				}
				else if (_applied)
				{
					RestoreAll();
				}
			}
		}

		private static void Show(InteractHUDParent hud, TextMeshProUGUI text, Image image, Hotkey key)
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: 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_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0449: Unknown result type (might be due to invalid IL or missing references)
			//IL_0464: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			KeyVisuals.Visual visual = KeyVisuals.For(key.Key.Value);
			string text2 = KeyVisuals.ModifierText(key.Modifier.Value);
			string text3 = ((text2 == null) ? "" : $"<color=#{NameColorHex(hud)}>{text2} +</color>");
			Rect rect = ((TMP_Text)text).rectTransform.rect;
			float width = ((Rect)(ref rect)).width;
			rect = ((Graphic)image).rectTransform.rect;
			float width2 = ((Rect)(ref rect)).width;
			if ((Object)(object)visual.Icon != (Object)null)
			{
				_str.Apply(text3);
				_align.Apply((TextAlignmentOptions)516);
				_margin.Apply(new Vector4(-400f, 0f, width - (width - width2) / 2f + 4f, 0f));
				_size.Restore();
				_sprite.Apply(visual.Icon);
				_imageGo.Apply(want: true);
				_imageOn.Apply(want: true);
				_textGo.Apply(want: true);
				_textOn.Apply(text2 != null);
			}
			else
			{
				string text4 = visual.Text;
				_size.Restore();
				float fontSize = ((TMP_Text)text).fontSize;
				Vector4 margin = ((TMP_Text)text).margin;
				float num = ((TMP_Text)text).GetPreferredValues(text4).x - Mathf.Max(0f, margin.x) - Mathf.Max(0f, margin.z);
				float num2 = ((num > width && num > 0f) ? Mathf.Max(12f, fontSize * width / num) : fontSize);
				if (text2 == null)
				{
					_str.Apply(text4);
					_align.Restore();
					_margin.Restore();
				}
				else
				{
					string text5 = $"{text3}|{text4}|{Util.F(num2)}";
					if (text5 != _calKey)
					{
						_align.Apply((TextAlignmentOptions)516);
						if (num2 < fontSize - 0.01f)
						{
							_size.Apply(num2);
						}
						Calibrate(text, image, text4, width2);
						_calKey = text5;
					}
					_str.Apply($"{text3}<space={Util.F(_keyGap)}>{text4}");
					_align.Apply((TextAlignmentOptions)516);
					_margin.Apply(new Vector4(-400f, 0f, _rightMargin, 0f));
				}
				if (num2 < fontSize - 0.01f)
				{
					_size.Apply(num2);
				}
				_imageOn.Apply(want: false);
				_textGo.Apply(want: true);
				_textOn.Apply(want: true);
			}
			_applied = true;
			string text6 = $"{key} -> text '{((TMP_Text)text).text}', icon '{(((Object)(object)visual.Icon == (Object)null) ? "-" : ((Object)visual.Icon).name)}', from game {visual.FromGame}, size {Util.F(((TMP_Text)text).fontSize)}, alignment {((TMP_Text)text).alignment}, margin {((TMP_Text)text).margin}";
			if (text6 != _lastShape)
			{
				_lastShape = text6;
				VeinControlConfig.Diag("prompt label: " + text6);
			}
		}

		private static void Calibrate(TextMeshProUGUI text, Image image, string name, float circle)
		{
			//IL_0013: 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_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_004a: 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_0056: 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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				_str.Apply(name);
				_margin.Apply(Vector4.zero);
				((TMP_Text)text).ForceMeshUpdate(true, true);
				Bounds textBounds = ((TMP_Text)text).textBounds;
				RectTransform rectTransform = ((Graphic)image).rectTransform;
				Rect rect = rectTransform.rect;
				Vector3 val = ((Transform)rectTransform).TransformPoint(Vector2.op_Implicit(((Rect)(ref rect)).center));
				float x = ((Transform)((TMP_Text)text).rectTransform).InverseTransformPoint(val).x;
				float num = ((Bounds)(ref textBounds)).max.x - ((Bounds)(ref textBounds)).min.x;
				float num2 = ((Bounds)(ref textBounds)).max.x - num / 2f;
				_rightMargin = num2 - x;
				_keyGap = Mathf.Max(0f, circle / 2f + 4f - num / 2f);
				Rect rect2 = ((TMP_Text)text).rectTransform.rect;
				VeinControlConfig.Diag($"prompt calibration '{name}': text box x {Util.F(((Rect)(ref rect2)).xMin)}..{Util.F(((Rect)(ref rect2)).xMax)}, key glyphs x {Util.F(((Bounds)(ref textBounds)).min.x)}..{Util.F(((Bounds)(ref textBounds)).max.x)}, circle centre {Util.F(x)}, circle {Util.F(circle)} -> right margin {Util.F(_rightMargin)}, gap {Util.F(_keyGap)}");
			}
			catch (System.Exception ex)
			{
				Util.LogExceptionOnce("FeedHudLabels.Calibrate", ex);
				_rightMargin = 0f;
				_keyGap = 4f;
			}
		}

		private static void RestoreAll()
		{
			_textOn.Restore();
			_textGo.Restore();
			_imageOn.Restore();
			_imageGo.Restore();
			_sprite.Restore();
			_size.Restore();
			_margin.Restore();
			_align.Restore();
			_str.Restore();
			_applied = false;
		}

		private static string NameColorHex(InteractHUDParent hud)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				LocalizedText interactNameText = hud.InteractNameText;
				TextMeshProUGUI val = ((interactNameText != null) ? interactNameText.Text : null);
				if ((Object)(object)val != (Object)null)
				{
					return ColorUtility.ToHtmlStringRGB(((Graphic)val).color);
				}
			}
			catch (System.Exception ex)
			{
				Util.LogExceptionOnce("NameColorHex", ex);
			}
			return "FFFFFF";
		}

		internal static void UpdateAbortLine(FeedInteractionProgressSystem sys)
		{
			if (!VeinControlConfig.SpareActive || !FeedInput.SpareableFeedActive || !ClientLink.ServerAllowsSpare(((ComponentSystemBase)sys).World))
			{
				return;
			}
			FeedInteractionProgress feedInteractionProgress = sys._FeedInteractionProgress;
			if ((Object)(object)feedInteractionProgress == (Object)null || (Object)(object)feedInteractionProgress.TextAbort == (Object)null || (Object)(object)feedInteractionProgress.TextAbort.Text == (Object)null)
			{
				return;
			}
			RefreshBindings();
			string text = SpareKeyLabel();
			if (text == null)
			{
				return;
			}
			string text2 = (string.IsNullOrEmpty(_primaryKey) ? "Left Mouse" : _primaryKey);
			string text3 = (VeinControlConfig.AllowPrimaryAttackCancel.Value ? $"Press <color={"#82C9D9"}>{text}</color> or <color={"#82C9D9"}>{text2}</color> to spare" : $"Press <color={"#82C9D9"}>{text}</color> to spare, <color={"#82C9D9"}>{text2}</color> to kill");
			TextMeshProUGUI text4 = feedInteractionProgress.TextAbort.Text;
			if (!(((TMP_Text)text4).text == text3))
			{
				((TMP_Text)text4).text = text3;
				if (text3 != _lastAbortLine)
				{
					_lastAbortLine = text3;
					VeinControlConfig.Diag("feed bar abort line: '" + text3 + "'");
				}
			}
		}

		private static string SpareKeyLabel()
		{
			if (VeinControlConfig.UseInterruptAbilityCastKey.Value && !string.IsNullOrEmpty(_interruptKey))
			{
				return _interruptKey;
			}
			if (VeinControlConfig.CancelFeedKey.IsBound)
			{
				return KeyVisuals.DisplayName(VeinControlConfig.CancelFeedKey);
			}
			if (VeinControlConfig.AllowFeedKeyToggleCancel.Value && LabelKey() != null)
			{
				return KeyVisuals.DisplayName(LabelKey());
			}
			return null;
		}

		private static void RefreshBindings()
		{
			InputActionSystem inputActions = FeedInput.InputActions;
			if (inputActions == null)
			{
				Util.LogExceptionOnce("RefreshBindings", new System.Exception("The game's keybinding system is not available yet; the abort line shows the feed key instead of the interrupt key."));
				return;
			}
			int inputChangeVersion = inputActions.InputChangeVersion;
			if (inputChangeVersion != _bindingVersion)
			{
				_bindingVersion = inputChangeVersion;
				_interruptKey = Binding(inputActions, (ButtonInputAction)2);
				_primaryKey = Binding(inputActions, (ButtonInputAction)100);
				VeinControlConfig.Diag($"detected keybindings: 'Interrupt Ability Cast' = '{_interruptKey}', Primary = '{_primaryKey}'");
			}
		}

		private unsafe static string Binding(InputActionSystem ias, ButtonInputAction action)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			bool[] array = new bool[2] { true, false };
			foreach (bool flag in array)
			{
				try
				{
					string inputText = ias.GetBindingDisplayInfo(action, flag, false, default(Nullable_Unboxed<ControllerType>)).InputText;
					if (!string.IsNullOrEmpty(inputText))
					{
						return inputText;
					}
				}
				catch (System.Exception ex)
				{
					Util.LogExceptionOnce("Binding " + ((object)(*(ButtonInputAction*)(&action))/*cast due to .constrained prefix*/).ToString(), ex);
				}
			}
			return null;
		}

		private static Hotkey LabelKey()
		{
			if (VeinControlConfig.FeedKey.IsBound)
			{
				return VeinControlConfig.FeedKey;
			}
			if (VeinControlConfig.FeedKeyAlt.IsBound)
			{
				return VeinControlConfig.FeedKeyAlt;
			}
			return null;
		}

		internal static void Teardown()
		{
			try
			{
				if (_applied)
				{
					RestoreAll();
				}
			}
			catch
			{
			}
			_applied = false;
		}
	}
	internal static class KeyVisuals
	{
		internal struct Visual
		{
			public string Text;

			public Sprite Icon;

			public bool FromGame;
		}

		private static readonly Dictionary<HotkeyKey, Visual> Cache = new Dictionary<HotkeyKey, Visual>();

		internal static Visual For(HotkeyKey key)
		{
			Visual result = default(Visual);
			if (Cache.TryGetValue(key, ref result))
			{
				return result;
			}
			bool final;
			Visual visual = Lookup(key, out final);
			if (final)
			{
				Cache[key] = visual;
			}
			return visual;
		}

		internal static string DisplayName(Hotkey hotkey)
		{
			string text = ModifierText(hotkey.Modifier.Value);
			string text2 = For(hotkey.Key.Value).Text;
			return (text == null) ? text2 : (text + "+" + text2);
		}

		internal static string ModifierText(HotkeyModifier modifier)
		{
			return modifier switch
			{
				HotkeyModifier.Shift => "Shift", 
				HotkeyModifier.Control => "Ctrl", 
				HotkeyModifier.Alt => "Alt", 
				_ => null, 
			};
		}

		private static Visual Lookup(HotkeyKey key, out bool final)
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			//IL_0080: 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)
			final = true;
			Visual result = new Visual
			{
				Text = FallbackText(key),
				Icon = null,
				FromGame = false
			};
			string text = ControlPath(key);
			if (text == null)
			{
				return result;
			}
			InputActionSystem inputActions = FeedInput.InputActions;
			if (inputActions == null)
			{
				final = false;
				return result;
			}
			InputAction val = null;
			try
			{
				val = new InputAction("VeinControlKeyProbe", (InputActionType)1, text, (string)null, (string)null, (string)null);
				string text2 = default(string);
				Sprite val2 = default(Sprite);
				string text3 = default(string);
				inputActions.GetBindingDisplayInfo(val, 0, ref text2, ref val2, ref text3, false, default(Nullable_Unboxed<ControllerType>));
				if (string.IsNullOrWhiteSpace(text2) && (Object)(object)val2 == (Object)null)
				{
					return result;
				}
				return new Visual
				{
					Text = (string.IsNullOrWhiteSpace(text2) ? result.Text : text2.Trim()),
					Icon = val2,
					FromGame = true
				};
			}
			catch (System.Exception ex)
			{
				Util.LogExceptionOnce("KeyVisuals.Lookup", ex);
				return result;
			}
			finally
			{
				try
				{
					if (val != null)
					{
						val.Dispose();
					}
				}
				catch
				{
				}
			}
		}

		private static string FallbackText(HotkeyKey key)
		{
			string text = ((object)key/*cast due to .constrained prefix*/).ToString();
			switch (key)
			{
			case HotkeyKey.Mouse3:
				return "Mouse Button 5";
			case HotkeyKey.Mouse4:
				return "Mouse Button 4";
			default:
			{
				int num = default(int);
				if (text.StartsWith("Mouse", (StringComparison)4) && int.TryParse(text.Substring(5), ref num))
				{
					return "Mouse Button " + (num + 1);
				}
				if (text.StartsWith("Alpha", (StringComparison)4))
				{
					return text.Substring(5);
				}
				return text;
			}
			}
		}

		private static string ControlPath(HotkeyKey key)
		{
			string text = ((object)key/*cast due to .constrained prefix*/).ToString();
			switch (key)
			{
			case HotkeyKey.None:
				return null;
			case HotkeyKey.Mouse3:
				return "<Mouse>/backButton";
			case HotkeyKey.Mouse4:
				return "<Mouse>/forwardButton";
			default:
				if (text.StartsWith("Mouse", (StringComparison)4))
				{
					return null;
				}
				if (text.Length == 1)
				{
					return "<Keyboard>/" + text.ToLowerInvariant();
				}
				if (text.StartsWith("Alpha", (StringComparison)4))
				{
					return "<Keyboard>/" + text.Substring(5);
				}
				if (text.Length <= 3 && text[0] == 'F' && char.IsDigit(text[1]))
				{
					return "<Keyboard>/" + text.ToLowerInvariant();
				}
				if (text.StartsWith("Keypad", (StringComparison)4))
				{
					string text2 = text.Substring(6);
					return "<Keyboard>/numpad" + text2;
				}
				return key switch
				{
					HotkeyKey.Return => "<Keyboard>/enter", 
					HotkeyKey.BackQuote => "<Keyboard>/backquote", 
					_ => "<Keyboard>/" + char.ToLowerInvariant(text[0]) + text.Substring(1), 
				};
			}
		}
	}
	internal static class ServerPart
	{
		private class Player
		{
			public bool Separate;

			public bool Spare = true;

			public float Grace = 1.5f;

			public bool MarkedPress;

			public int LastHeldFrame = -1000;
		}

		private class FeedTrack
		{
			public Entity Buff;

			public Entity Player;

			public Entity Victim;

			public bool VBlood;

			public bool IsRevive;

			public bool Done;
		}

		private struct Grace
		{
			public long Player;

			public float Until;
		}

		private const string ServerConfigFileName = "com.zeeCameLsnake.VeinControl.Server.cfg";

		private const int SpareWindowFrames = 60;

		private const int PressGapFrames = 3;

		private const int SafetyNetWindow = 30;

		internal static ConfigEntry<bool> EnableNonLethalCancel;

		internal static ConfigEntry<bool> FeedKeySafetyNet;

		internal static ConfigEntry<float> MaxSpareGraceSeconds;

		internal static ConfigEntry<bool> LogDiagnostics;

		private static readonly Dictionary<long, Player> Players = new Dictionary<long, Player>();

		private static readonly List<FeedTrack> Feeds = new List<FeedTrack>();

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

		private static readonly Dictionary<long, Grace> GraceUntil = new Dictionary<long, Grace>();

		private static World _queryWorld;

		private static EntityQuery _siphonQuery;

		private static EntityQuery _playerQuery;

		internal static void Load()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			BepInPlugin val = new BepInPlugin("com.zeeCameLsnake.VeinControl", "VeinControl", "1.0.0");
			ConfigFile val2 = new ConfigFile(Path.Combine(Paths.ConfigPath, "com.zeeCameLsnake.VeinControl.Server.cfg"), true, val);
			EnableNonLethalCancel = val2.Bind<bool>("Server 1. Settings", "EnableNonLethalCancel", true, "Allows spared (non-lethal) early feed ends on this server: a player who stops a bite early with the 'Interrupt Ability Cast' key (or the VeinControl cancel keys) leaves the target alive. Off: every early end is lethal as in vanilla (e.g. for PvP servers). V Blood bosses and revives are never affected. This file belongs to the server part of VeinControl; players' own settings are in their game's config.");
			FeedKeySafetyNet = val2.Bind<bool>("Server 1. Settings", "FeedKeySafetyNet", true, "For players with the VeinControl client and a separate feed key: a bite that was started with the Interact key (not with the feed key) is ended at once without killing the target. A guarantee in case the client misses a press, for example with lag.");
			MaxSpareGraceSeconds = val2.Bind<float>("Server 1. Settings", "MaxSpareGraceSeconds", 5f, new ConfigDescription("Upper limit for the grace window after a spare. Each player sets their own window in their game's config (SpareGraceSeconds, default 1.5 s): during it, that player's own hits (and those of their minions) on the target they just spared do no damage. It catches the swing that follows a spare with LMB. Damage from other players and from enemies still counts, so the window only holds back the sparing player and their minions. Players without the client part get 1.5 s. Example: 2 = no player gets more than two seconds. 0 = grace window off for everyone.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 5f), System.Array.Empty<object>()));
			LogDiagnostics = val2.Bind<bool>("Server 2. Debug", "LogDiagnostics", false, "Writes handshakes, feed starts/ends, spares and safety-net hits to BepInEx_Server/LogOutput.log.");
		}

		private static void Diag(string text)
		{
			if (LogDiagnostics != null && LogDiagnostics.Value)
			{
				VeinControlPlugin.Log.LogInfo((object)("[Diag] " + text));
			}
		}

		private static void EnsureQueries(World world)
		{
			//IL_0013: Unknown result type (might b