Decompiled source of SomethingCapsule v1.0.0

plugins\SomethingCapsule.dll

Decompiled 39 minutes 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.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SomethingCapsule")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SomethingCapsule")]
[assembly: AssemblyTitle("SomethingCapsule")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace WhiteKnuckleThirdHandMod;

public class PillHandItem : HandItem
{
	private bool consumed;

	public override void Initialize(Item i, Hand h)
	{
		((HandItem)this).Initialize(i, h);
		consumed = false;
	}

	public override void Use()
	{
		if (!consumed && (!((Object)(object)ThirdHandPillMod.Instance != (Object)null) || ThirdHandPillMod.Instance.CanEatMorePills))
		{
			consumed = true;
			if ((Object)(object)ThirdHandPillMod.Instance != (Object)null)
			{
				ThirdHandPillMod.Instance.OnPillEaten();
			}
			if (base.itemUseEvent != null)
			{
				base.itemUseEvent.Invoke();
			}
			if (base.item != null)
			{
				base.item.Destroy(true);
			}
			else
			{
				((HandItem)this).RemoveItem();
			}
		}
	}
}
internal static class ThirdHandHarmonyPatches
{
	private static ButtonInput thirdHandButton;

	private static ButtonInput thirdHandThrowButton;

	private static ButtonInput blockedSwapButton;

	private static readonly FieldInfo fiPressed = AccessTools.Field(typeof(ButtonInput), "<Pressed>k__BackingField");

	private static readonly FieldInfo fiDown = AccessTools.Field(typeof(ButtonInput), "<Down>k__BackingField");

	private static readonly FieldInfo fiUp = AccessTools.Field(typeof(ButtonInput), "<Up>k__BackingField");

	private static readonly MethodInfo miStartInteraction = AccessTools.Method(typeof(ENT_Player), "StartInteraction", new Type[1] { typeof(int) }, (Type[])null);

	public static void UpdateThirdHandInputState()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		//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_0038: Expected O, but got Unknown
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Expected O, but got Unknown
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: 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_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		if (thirdHandButton == null)
		{
			thirdHandButton = new ButtonInput
			{
				name = "ThirdHand"
			};
		}
		if (thirdHandThrowButton == null)
		{
			thirdHandThrowButton = new ButtonInput
			{
				name = "ThirdHandThrow"
			};
		}
		if (blockedSwapButton == null)
		{
			blockedSwapButton = new ButtonInput
			{
				name = "Hand-Swap"
			};
		}
		ThirdHandPillMod instance = ThirdHandPillMod.Instance;
		bool flag = ((Object)(object)CL_GameManager.gMan != (Object)null && CL_GameManager.gMan.isPaused) || ((Object)(object)instance != (Object)null && (instance.IsRebinding || instance.IsChoking || instance.IsBetrayalLocked));
		KeyCode val = (KeyCode)((!((Object)(object)instance != (Object)null)) ? 325 : ((int)instance.GrabKey));
		KeyCode val2 = (KeyCode)((!((Object)(object)instance != (Object)null)) ? 327 : ((int)instance.DropKey));
		fiPressed?.SetValue(thirdHandButton, !flag && Input.GetKey(val));
		fiDown?.SetValue(thirdHandButton, !flag && Input.GetKeyDown(val));
		fiUp?.SetValue(thirdHandButton, !flag && Input.GetKeyUp(val));
		fiPressed?.SetValue(thirdHandThrowButton, !flag && Input.GetKey(val2));
		fiDown?.SetValue(thirdHandThrowButton, !flag && Input.GetKeyDown(val2));
		fiUp?.SetValue(thirdHandThrowButton, !flag && Input.GetKeyUp(val2));
		fiPressed?.SetValue(blockedSwapButton, false);
		fiDown?.SetValue(blockedSwapButton, false);
		fiUp?.SetValue(blockedSwapButton, false);
	}

	[HarmonyPatch(typeof(InputManager), "GetButton", new Type[] { typeof(string) })]
	[HarmonyPrefix]
	public static bool GetButtonPrefix(string name, ref ButtonInput __result)
	{
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Invalid comparison between Unknown and I4
		switch (name)
		{
		case "ThirdHand":
			if (thirdHandButton == null)
			{
				UpdateThirdHandInputState();
			}
			__result = thirdHandButton;
			return false;
		case "ThirdHandThrow":
			if (thirdHandThrowButton == null)
			{
				UpdateThirdHandInputState();
			}
			__result = thirdHandThrowButton;
			return false;
		case "Hand-Swap":
		{
			ThirdHandPillMod instance = ThirdHandPillMod.Instance;
			if ((Object)(object)instance != (Object)null && (int)instance.GrabKey == 325)
			{
				if (blockedSwapButton == null)
				{
					UpdateThirdHandInputState();
				}
				__result = blockedSwapButton;
				return false;
			}
			break;
		}
		}
		return true;
	}

	[HarmonyPatch(typeof(ENT_Player), "Actions")]
	[HarmonyPostfix]
	public static void ActionsPostfix(ENT_Player __instance)
	{
		if (!((Object)(object)__instance == (Object)null) && __instance.hands != null && __instance.hands.Length > 2 && (!((Object)(object)CL_GameManager.gMan != (Object)null) || !CL_GameManager.gMan.isPaused) && (!((Object)(object)ThirdHandPillMod.Instance != (Object)null) || !ThirdHandPillMod.Instance.IsRebinding))
		{
			miStartInteraction?.Invoke(__instance, new object[1] { 2 });
		}
	}

	[HarmonyPatch(typeof(Hand), "SetSprite", new Type[]
	{
		typeof(Sprite),
		typeof(Sprite)
	})]
	[HarmonyPrefix]
	public static void HandSetSpritePrefix(Hand __instance, Sprite background)
	{
		if (__instance != null && __instance.id == 2 && (Object)(object)background != (Object)null)
		{
			ThirdHandPillMod.Instance?.RecordThirdHandBaseSprite(background);
		}
	}

	[HarmonyPatch(typeof(Hand_Base), "ProcessCosmetics")]
	[HarmonyPrefix]
	public static bool HandBaseProcessCosmeticsPrefix(Hand_Base __instance)
	{
		if ((Object)(object)__instance != (Object)null && __instance.hand != null && __instance.hand.id == 2 && (Object)(object)__instance.hand.GetHandItem() == (Object)null)
		{
			return false;
		}
		return true;
	}

	[HarmonyPatch(typeof(Hand_Base), "LateUpdate")]
	[HarmonyPostfix]
	public static void HandBaseLateUpdatePostfix(Hand_Base __instance)
	{
		if ((Object)(object)__instance != (Object)null && __instance.hand != null && __instance.hand.id == 2)
		{
			ThirdHandPillMod.Instance?.UpdateThirdHandChimera(__instance.hand.GetPlayer());
		}
	}

	[HarmonyPatch(typeof(ENT_Player), "LateUpdate")]
	[HarmonyPostfix]
	public static void PlayerLateUpdatePostfix(ENT_Player __instance)
	{
		if (!((Object)(object)__instance == (Object)null) && __instance.hands != null && __instance.hands.Length > 2)
		{
			ThirdHandPillMod.Instance?.UpdateThirdHandChimera(__instance);
		}
	}

	[HarmonyPatch(typeof(CL_CosmeticManager), "GetCosmeticInHand", new Type[] { typeof(int) })]
	[HarmonyPrefix]
	public static void GetCosmeticInHandPrefix(ref int i)
	{
		if (i >= 2)
		{
			i = 1;
		}
	}

	[HarmonyPatch(typeof(UI_TabGroup), "OnEnable")]
	[HarmonyPostfix]
	public static void TabGroupOnEnablePostfix(UI_TabGroup __instance)
	{
		ThirdHandPillMod.Instance?.TryInjectControlsTab(__instance);
	}

	[HarmonyPatch(typeof(UI_TabGroup), "Start")]
	[HarmonyPostfix]
	public static void TabGroupStartPostfix(UI_TabGroup __instance)
	{
		ThirdHandPillMod.Instance?.TryInjectControlsTab(__instance);
	}

	[HarmonyPatch(typeof(OS_Computer_Interface), "Start")]
	[HarmonyPostfix]
	public static void PerkMachineStartPostfix(OS_Computer_Interface __instance)
	{
		ThirdHandPillMod.Instance?.OnPerkMachineStarted(__instance);
	}

	[HarmonyPatch(typeof(ENV_VendingMachine), "Start")]
	[HarmonyPostfix]
	public static void VendingMachineStartPostfix(ENV_VendingMachine __instance)
	{
		ThirdHandPillMod.Instance?.OnVendingMachineStarted(__instance);
	}

	[HarmonyPatch(typeof(ENV_RoachTrader), "Start")]
	[HarmonyPostfix]
	public static void RoachTraderStartPostfix(ENV_RoachTrader __instance)
	{
		ThirdHandPillMod.Instance?.OnRoachTraderStarted(__instance);
	}
}
public class ThirdHandTabController : MonoBehaviour
{
	public TMP_Text grabValueText;

	public TMP_Text dropValueText;

	public TMP_Text transferValueText;

	private void OnEnable()
	{
		RefreshLabels();
	}

	private void Update()
	{
		RefreshLabels();
	}

	public void RefreshLabels()
	{
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		ThirdHandPillMod instance = ThirdHandPillMod.Instance;
		if (!((Object)(object)instance == (Object)null))
		{
			if ((Object)(object)grabValueText != (Object)null)
			{
				grabValueText.text = ((instance.ListeningTarget == "grab") ? "PRESS ANY KEY..." : instance.FormatKeyNameEn(instance.GrabKey));
			}
			if ((Object)(object)dropValueText != (Object)null)
			{
				dropValueText.text = ((instance.ListeningTarget == "drop") ? "PRESS ANY KEY..." : instance.FormatKeyNameEn(instance.DropKey));
			}
			if ((Object)(object)transferValueText != (Object)null)
			{
				transferValueText.text = ((instance.ListeningTarget == "transfer") ? "PRESS ANY KEY..." : instance.FormatKeyNameEn(instance.TransferKey));
			}
		}
	}
}
[BepInPlugin("com.romanchik.whiteknuckle.somethingcapsule", "SomethingCapsule", "1.6.0")]
public class ThirdHandPillMod : BaseUnityPlugin
{
	private const string PillPrefabName = "item_capsule";

	private const int PillsRequired = 5;

	private Harmony harmony;

	private ConfigEntry<KeyCode> cfgGrabKey;

	private ConfigEntry<KeyCode> cfgDropKey;

	private ConfigEntry<KeyCode> cfgTransferKey;

	private Item_Object pillItemTemplate;

	private PillHandItem pillHandTemplate;

	private Mesh pillMesh;

	private Texture2D pillHandTexture;

	private Texture2D pillWorldTexture;

	private AudioClip swallowSound;

	private AudioClip mutateSound;

	private AudioClip chokeGrabSound;

	private AudioClip struggleHitSound;

	private bool consoleRegistered;

	private float chokeDamageTimer;

	private float chokeStruggleProgress;

	private const float ChokeEscapeThreshold = 8f;

	private int lastStruggleButton = -1;

	private float chokeVisualAmount;

	private float chokePushbackImpulse;

	private Vector3 thirdHandBaseSpriteLocalPos = Vector3.zero;

	private Vector3 thirdHandBaseSpriteLocalScale = Vector3.one;

	private bool thirdHandBaseTransformSaved;

	private float rogueDropCountdown;

	private float rogueDropWarnTimer;

	private bool rogueDropWarningActive;

	private float betrayalLockTimer;

	private float currentHangDuration;

	private float slipCheckCountdown;

	private float slipCooldownCountdown;

	private bool slipWarningActive;

	private float slipWarnTimer;

	private float stealCountdown;

	private bool stealWarningActive;

	private float stealWarnTimer;

	private int stealTargetHandIdx = -1;

	private float bagGrabCountdown;

	private bool bagGrabWarningActive;

	private float bagGrabWarnTimer;

	private float rogueUseCountdown;

	private bool rogueUseWarningActive;

	private float rogueUseWarnTimer;

	private HandItem rogueUseStopTarget;

	private float rogueUseStopTimer;

	private float mischiefCountdown;

	private string lastMischiefType = "";

	private float handSlapCountdown;

	private bool handSlapWarningActive;

	private float handSlapWarnTimer;

	private int handSlapTargetIdx = -1;

	private float handSlapLungeTimer;

	private float handSlapLungeDir;

	private bool eyePokeWarningActive;

	private float eyePokeWarnTimer;

	private int eyePokeTargetEye = -1;

	private float eyePokeLungeTimer;

	private float eyePokeLungeDir;

	private float leftEyeBlindTimer;

	private float rightEyeBlindTimer;

	private float leftEyeBlindAlpha;

	private float rightEyeBlindAlpha;

	private Canvas eyeBlindCanvas;

	private Image leftEyeBlindImage;

	private Image rightEyeBlindImage;

	private Canvas mutagenVignetteCanvas;

	private Image mutagenVignetteImage;

	private float currentVignetteAlpha;

	private float currentVignetteScale = 1.12f;

	private float unlockFlashTimer;

	private int lastSummonFrame = -1;

	private readonly HashSet<int> injectedTabGroups = new HashSet<int>();

	private readonly HashSet<int> spawnedPerkMachines = new HashSet<int>();

	private float nextPerkMachineScanTime;

	private float rebindIgnoreUntil;

	private SpriteRenderer chimeraLeftSr;

	private SpriteRenderer chimeraRightSr;

	private Material chimeraLeftSourceMat;

	private Material chimeraRightSourceMat;

	private Material chimeraLeftMat;

	private Material chimeraRightMat;

	private Sprite lastThirdBaseSprite;

	private Sprite straightOpenSprite;

	private Sprite straightGrabSprite;

	private bool loggedChimeraDebug;

	private readonly Dictionary<Sprite, Sprite> leftHalfSpriteCache = new Dictionary<Sprite, Sprite>();

	private readonly Dictionary<Sprite, Sprite> rightHalfSpriteCache = new Dictionary<Sprite, Sprite>();

	private static readonly FieldInfo fiViewSwayInitialPos = AccessTools.Field(typeof(ViewSway), "initialPosition");

	private static readonly FieldInfo fiGrabFakeHandholds = AccessTools.Field(typeof(ENT_Player), "grabAnywhereFakeHandholds");

	private static readonly FieldInfo fiGrabPositions = AccessTools.Field(typeof(ENT_Player), "grabAnywherePosition");

	private static readonly FieldInfo fiGrabHits = AccessTools.Field(typeof(ENT_Player), "grabAnywhereHit");

	private static readonly FieldInfo fiCosmeticSwapDict = AccessTools.Field(typeof(Cosmetic_HandItem), "swapDict");

	private static readonly FieldInfo fiCosmeticSpriteNames = AccessTools.Field(typeof(Cosmetic_HandItem), "spriteNames");

	public static ThirdHandPillMod Instance { get; private set; }

	public KeyCode GrabKey
	{
		get
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if (cfgGrabKey == null)
			{
				return (KeyCode)325;
			}
			return cfgGrabKey.Value;
		}
	}

	public KeyCode DropKey
	{
		get
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if (cfgDropKey == null)
			{
				return (KeyCode)327;
			}
			return cfgDropKey.Value;
		}
	}

	public KeyCode TransferKey
	{
		get
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if (cfgTransferKey == null)
			{
				return (KeyCode)326;
			}
			return cfgTransferKey.Value;
		}
	}

	public string ListeningTarget { get; private set; }

	public bool IsRebinding => ListeningTarget != null;

	public int PillsEaten { get; private set; }

	public bool ThirdHandUnlocked { get; private set; }

	public bool CanEatMorePills
	{
		get
		{
			if (!ThirdHandUnlocked)
			{
				return PillsEaten < 5;
			}
			return false;
		}
	}

	public bool IsChoking { get; private set; }

	public bool IsBetrayalLocked => betrayalLockTimer > 0f;

	private void Awake()
	{
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Expected O, but got Unknown
		Instance = this;
		cfgGrabKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "ThirdHandGrabKey", (KeyCode)325, "Third Hand Grab / Use key (default: Middle Mouse)");
		cfgDropKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "ThirdHandDropKey", (KeyCode)327, "Third Hand Drop / Stash key (default: Mouse 5)");
		cfgTransferKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "ThirdHandTransferKey", (KeyCode)326, "Third Hand Transfer to/from main hands key (default: Mouse 4)");
		harmony = new Harmony("com.romanchik.whiteknuckle.somethingcapsule");
		harmony.PatchAll(typeof(ThirdHandHarmonyPatches));
		SceneManager.sceneLoaded += OnSceneLoaded;
	}

	private void OnDestroy()
	{
		SceneManager.sceneLoaded -= OnSceneLoaded;
		Harmony obj = harmony;
		if (obj != null)
		{
			obj.UnpatchSelf();
		}
	}

	private void Start()
	{
		pillMesh = LoadObjMesh("Capsule.obj");
		pillWorldTexture = LoadCustomTexture("Capsule_texture.jpg", mipmap: true) ?? CreatePillWorldTexture();
		pillHandTexture = LoadCustomTexture("Capsule_PillOnly.png", mipmap: false) ?? CreatePillHandSpriteTexture();
		swallowSound = CreateSwallowSound();
		mutateSound = CreateMutateSound();
		chokeGrabSound = CreateChokeGrabSound();
		struggleHitSound = CreateStruggleHitSound();
		TryRegisterConsoleCommand();
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		TryRegisterConsoleCommand();
		spawnedPerkMachines.Clear();
		nextPerkMachineScanTime = Time.time + 1f;
		if ((int)mode == 0 || ((Scene)(ref scene)).name.IndexOf("Menu", StringComparison.OrdinalIgnoreCase) >= 0)
		{
			PillsEaten = 0;
			ThirdHandUnlocked = false;
			IsChoking = false;
			rogueDropCountdown = 0f;
			rogueDropWarningActive = false;
			rogueDropWarnTimer = 0f;
			betrayalLockTimer = 0f;
			slipCheckCountdown = 0f;
			slipCooldownCountdown = 0f;
			slipWarningActive = false;
			slipWarnTimer = 0f;
			currentHangDuration = 0f;
			stealCountdown = 0f;
			stealWarningActive = false;
			stealWarnTimer = 0f;
			stealTargetHandIdx = -1;
			bagGrabCountdown = 0f;
			bagGrabWarningActive = false;
			bagGrabWarnTimer = 0f;
			rogueUseCountdown = 0f;
			rogueUseWarningActive = false;
			rogueUseWarnTimer = 0f;
			rogueUseStopTarget = null;
			rogueUseStopTimer = 0f;
			handSlapCountdown = 0f;
			handSlapWarningActive = false;
			handSlapWarnTimer = 0f;
			handSlapTargetIdx = -1;
			handSlapLungeTimer = 0f;
			handSlapLungeDir = 0f;
			eyePokeWarningActive = false;
			eyePokeWarnTimer = 0f;
			eyePokeTargetEye = -1;
			eyePokeLungeTimer = 0f;
			eyePokeLungeDir = 0f;
			leftEyeBlindTimer = 0f;
			rightEyeBlindTimer = 0f;
			leftEyeBlindAlpha = 0f;
			rightEyeBlindAlpha = 0f;
			if ((Object)(object)eyeBlindCanvas != (Object)null)
			{
				((Behaviour)eyeBlindCanvas).enabled = false;
			}
			mischiefCountdown = 0f;
			lastMischiefType = "";
			chokeVisualAmount = 0f;
			chokeStruggleProgress = 0f;
			thirdHandBaseTransformSaved = false;
			chimeraLeftSourceMat = null;
			chimeraRightSourceMat = null;
			loggedChimeraDebug = false;
			currentVignetteAlpha = 0f;
			unlockFlashTimer = 0f;
			if ((Object)(object)mutagenVignetteCanvas != (Object)null)
			{
				((Behaviour)mutagenVignetteCanvas).enabled = false;
			}
		}
	}

	public void StartListeningForRebind(string target)
	{
		ListeningTarget = target;
		rebindIgnoreUntil = Time.unscaledTime + 0.18f;
	}

	public void ResetBindsToDefault()
	{
		cfgGrabKey.Value = (KeyCode)325;
		cfgDropKey.Value = (KeyCode)327;
		cfgTransferKey.Value = (KeyCode)326;
		ListeningTarget = null;
		((BaseUnityPlugin)this).Config.Save();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"[PillMod] Third Hand binds reset to defaults.");
	}

	public unsafe string FormatKeyNameEn(KeyCode k)
	{
		//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_0024: Expected I4, but got Unknown
		//IL_0024: 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_0044: Expected I4, but got Unknown
		return (k - 303) switch
		{
			1 => "L-SHIFT", 
			0 => "R-SHIFT", 
			3 => "L-CTRL", 
			2 => "R-CTRL", 
			5 => "L-ALT", 
			4 => "R-ALT", 
			_ => (k - 325) switch
			{
				0 => "MIDDLE MOUSE", 
				1 => "MOUSE 4", 
				2 => "MOUSE 5", 
				3 => "MOUSE 6", 
				4 => "MOUSE 7", 
				_ => ((object)(*(KeyCode*)(&k))/*cast due to .constrained prefix*/).ToString().ToUpperInvariant(), 
			}, 
		};
	}

	public void RecordThirdHandBaseSprite(Sprite s)
	{
		if ((Object)(object)s != (Object)null)
		{
			lastThirdBaseSprite = s;
		}
	}

	private void EnsureChimeraRenderers(Hand hand2)
	{
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Expected O, but got Unknown
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		if (hand2 != null && !((Object)(object)hand2.handSprite == (Object)null) && (!((Object)(object)chimeraLeftSr != (Object)null) || !((Object)(object)chimeraRightSr != (Object)null) || !((Object)(object)((Component)chimeraLeftSr).transform.parent == (Object)(object)((Component)hand2.handSprite).transform)))
		{
			Transform transform = ((Component)hand2.handSprite).transform;
			int layer = ((Component)hand2.handSprite).gameObject.layer;
			GameObject val = new GameObject("ThirdHand_ChimeraLeftHalf");
			val.layer = layer;
			val.transform.SetParent(transform, false);
			val.transform.localPosition = Vector3.zero;
			val.transform.localRotation = Quaternion.identity;
			val.transform.localScale = Vector3.one;
			chimeraLeftSr = val.AddComponent<SpriteRenderer>();
			GameObject val2 = new GameObject("ThirdHand_ChimeraRightHalf");
			val2.layer = layer;
			val2.transform.SetParent(transform, false);
			val2.transform.localPosition = Vector3.zero;
			val2.transform.localRotation = Quaternion.identity;
			val2.transform.localScale = Vector3.one;
			chimeraRightSr = val2.AddComponent<SpriteRenderer>();
		}
	}

	private void EnsureStraightHandSprites(Hand refHand)
	{
		if ((Object)(object)straightOpenSprite != (Object)null && (Object)(object)straightGrabSprite != (Object)null)
		{
			return;
		}
		if (refHand != null && refHand.handPoses != null)
		{
			foreach (HandPoses handPose in refHand.handPoses)
			{
				if (handPose != null && !((Object)(object)handPose.sprite == (Object)null))
				{
					if (((Object)handPose.sprite).name == "HND_B1A2")
					{
						straightOpenSprite = handPose.sprite;
					}
					else if (((Object)handPose.sprite).name == "HND_B1A3")
					{
						straightGrabSprite = handPose.sprite;
					}
				}
			}
		}
		if (!((Object)(object)straightOpenSprite == (Object)null) && !((Object)(object)straightGrabSprite == (Object)null))
		{
			return;
		}
		Sprite[] array = Resources.FindObjectsOfTypeAll<Sprite>();
		foreach (Sprite val in array)
		{
			if (!((Object)(object)val == (Object)null))
			{
				if ((Object)(object)straightOpenSprite == (Object)null && ((Object)val).name == "HND_B1A2")
				{
					straightOpenSprite = val;
				}
				else if ((Object)(object)straightGrabSprite == (Object)null && ((Object)val).name == "HND_B1A3")
				{
					straightGrabSprite = val;
				}
				if ((Object)(object)straightOpenSprite != (Object)null && (Object)(object)straightGrabSprite != (Object)null)
				{
					break;
				}
			}
		}
	}

	public void UpdateThirdHandChimera(ENT_Player player)
	{
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0410: Unknown result type (might be due to invalid IL or missing references)
		//IL_0426: Unknown result type (might be due to invalid IL or missing references)
		//IL_043b: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_0301: Unknown result type (might be due to invalid IL or missing references)
		//IL_0330: Unknown result type (might be due to invalid IL or missing references)
		//IL_037a: Unknown result type (might be due to invalid IL or missing references)
		//IL_039b: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_0206: Unknown result type (might be due to invalid IL or missing references)
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0210: Unknown result type (might be due to invalid IL or missing references)
		//IL_0212: Unknown result type (might be due to invalid IL or missing references)
		//IL_0228: Unknown result type (might be due to invalid IL or missing references)
		//IL_022f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Unknown result type (might be due to invalid IL or missing references)
		//IL_045e: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_05fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0603: Unknown result type (might be due to invalid IL or missing references)
		//IL_060f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0511: Unknown result type (might be due to invalid IL or missing references)
		//IL_062d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0632: Unknown result type (might be due to invalid IL or missing references)
		//IL_063a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0641: Unknown result type (might be due to invalid IL or missing references)
		//IL_0648: Unknown result type (might be due to invalid IL or missing references)
		//IL_0654: Unknown result type (might be due to invalid IL or missing references)
		//IL_07b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_07be: Unknown result type (might be due to invalid IL or missing references)
		//IL_07c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0693: Unknown result type (might be due to invalid IL or missing references)
		//IL_069d: Expected O, but got Unknown
		//IL_0840: Unknown result type (might be due to invalid IL or missing references)
		//IL_06da: Unknown result type (might be due to invalid IL or missing references)
		//IL_06e4: Expected O, but got Unknown
		//IL_08b3: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)player == (Object)null || player.hands == null || player.hands.Length <= 2)
		{
			return;
		}
		Hand val = player.hands[0];
		Hand val2 = player.hands[1];
		Hand val3 = player.hands[2];
		if (val == null || val2 == null || val3 == null || (Object)(object)val3.handSprite == (Object)null)
		{
			return;
		}
		bool flag = (Object)(object)val3.GetHandItem() != (Object)null;
		if (!thirdHandBaseTransformSaved)
		{
			thirdHandBaseSpriteLocalPos = ((Component)val3.handSprite).transform.localPosition;
			thirdHandBaseSpriteLocalScale = ((Component)val3.handSprite).transform.localScale;
			thirdHandBaseTransformSaved = true;
		}
		float num = (IsChoking ? Mathf.Clamp01(1f - chokeStruggleProgress / 8f * 0.45f) : 0f);
		chokeVisualAmount = Mathf.Lerp(chokeVisualAmount, num, Time.deltaTime * (IsChoking ? 10f : 8f));
		chokePushbackImpulse = Mathf.Lerp(chokePushbackImpulse, 0f, Time.deltaTime * 14f);
		if (handSlapLungeTimer > 0f)
		{
			handSlapLungeTimer = Mathf.Max(0f, handSlapLungeTimer - Time.deltaTime);
		}
		if (eyePokeLungeTimer > 0f)
		{
			eyePokeLungeTimer = Mathf.Max(0f, eyePokeLungeTimer - Time.deltaTime);
		}
		if (chokeVisualAmount > 0.005f && !flag)
		{
			float num2 = (IsChoking ? 0.022f : 0.005f);
			Vector3 val4 = default(Vector3);
			((Vector3)(ref val4))..ctor(Random.Range(0f - num2, num2), Random.Range(0f - num2, num2), 0f);
			float num3 = chokeVisualAmount * 0.34f - chokePushbackImpulse * 0.14f;
			float num4 = 1f + chokeVisualAmount * 0.28f;
			((Component)val3.handSprite).transform.localPosition = thirdHandBaseSpriteLocalPos + new Vector3(0f, num3, (0f - chokeVisualAmount) * 0.08f) + val4;
			((Component)val3.handSprite).transform.localScale = thirdHandBaseSpriteLocalScale * num4;
			((Component)val3.handSprite).transform.localRotation = Quaternion.Euler(0f, 0f, Random.Range(-4f, 4f) * chokeVisualAmount);
		}
		else if (eyePokeLungeTimer > 0f && !flag)
		{
			float num5 = Mathf.Sin(eyePokeLungeTimer / 0.24f * MathF.PI);
			((Component)val3.handSprite).transform.localPosition = thirdHandBaseSpriteLocalPos + new Vector3(eyePokeLungeDir * num5 * 0.28f, num5 * 0.42f, (0f - num5) * 0.1f);
			((Component)val3.handSprite).transform.localScale = thirdHandBaseSpriteLocalScale * (1f + num5 * 0.38f);
			((Component)val3.handSprite).transform.localRotation = Quaternion.Euler(0f, 0f, (0f - eyePokeLungeDir) * num5 * 16f);
		}
		else if (handSlapLungeTimer > 0f && !flag)
		{
			float num6 = Mathf.Sin(handSlapLungeTimer / 0.22f * MathF.PI);
			((Component)val3.handSprite).transform.localPosition = thirdHandBaseSpriteLocalPos + new Vector3(handSlapLungeDir * num6 * 0.42f, num6 * 0.08f, 0f);
			((Component)val3.handSprite).transform.localScale = thirdHandBaseSpriteLocalScale * (1f + num6 * 0.12f);
			((Component)val3.handSprite).transform.localRotation = Quaternion.Euler(0f, 0f, (0f - handSlapLungeDir) * num6 * 22f);
		}
		else
		{
			((Component)val3.handSprite).transform.localPosition = thirdHandBaseSpriteLocalPos;
			((Component)val3.handSprite).transform.localScale = thirdHandBaseSpriteLocalScale;
			((Component)val3.handSprite).transform.localRotation = Quaternion.identity;
		}
		if ((Object)(object)val3.handForegroundSprite != (Object)null)
		{
			((Component)val3.handForegroundSprite).transform.localRotation = Quaternion.identity;
		}
		EnsureChimeraRenderers(val3);
		if ((Object)(object)chimeraLeftSr == (Object)null || (Object)(object)chimeraRightSr == (Object)null)
		{
			return;
		}
		if (flag || !((Renderer)val3.handSprite).enabled || !((Component)val3.handSprite).gameObject.activeInHierarchy)
		{
			((Renderer)chimeraLeftSr).enabled = false;
			((Renderer)chimeraRightSr).enabled = false;
			return;
		}
		EnsureStraightHandSprites(val2);
		Sprite val5 = ((IsChoking || handSlapWarningActive || handSlapLungeTimer > 0f || eyePokeWarningActive || eyePokeLungeTimer > 0f || val3.IsHolding() || val3.IsHanging() || Input.GetKey(GrabKey)) ? (straightGrabSprite ?? lastThirdBaseSprite ?? val3.handSprite.sprite) : (straightOpenSprite ?? lastThirdBaseSprite ?? val3.handSprite.sprite));
		if ((Object)(object)val5 == (Object)null)
		{
			((Renderer)chimeraLeftSr).enabled = false;
			((Renderer)chimeraRightSr).enabled = false;
			return;
		}
		Material mat;
		Sprite val6 = ResolveCosmeticSpriteForHand(val, val5, out mat);
		Material mat2;
		Sprite val7 = ResolveCosmeticSpriteForHand(val2, val5, out mat2);
		Sprite halfSprite = GetHalfSprite(val6, isLeftHalf: true);
		Sprite halfSprite2 = GetHalfSprite(val7, isLeftHalf: false);
		if ((Object)(object)halfSprite == (Object)null || (Object)(object)halfSprite2 == (Object)null)
		{
			((Renderer)chimeraLeftSr).enabled = false;
			((Renderer)chimeraRightSr).enabled = false;
			return;
		}
		Color color = val3.handSprite.color;
		val3.handSprite.color = new Color(color.r, color.g, color.b, 0f);
		if ((Object)(object)val3.handForegroundSprite != (Object)null)
		{
			Color color2 = val3.handForegroundSprite.color;
			val3.handForegroundSprite.color = new Color(color2.r, color2.g, color2.b, 0f);
		}
		if ((Object)(object)mat != (Object)null && (Object)(object)mat != (Object)(object)chimeraLeftSourceMat)
		{
			if ((Object)(object)chimeraLeftMat != (Object)null)
			{
				Object.Destroy((Object)(object)chimeraLeftMat);
			}
			chimeraLeftMat = new Material(mat);
			chimeraLeftSourceMat = mat;
		}
		if ((Object)(object)mat2 != (Object)null && (Object)(object)mat2 != (Object)(object)chimeraRightSourceMat)
		{
			if ((Object)(object)chimeraRightMat != (Object)null)
			{
				Object.Destroy((Object)(object)chimeraRightMat);
			}
			chimeraRightMat = new Material(mat2);
			chimeraRightSourceMat = mat2;
		}
		ApplyIndependentStaminaToMaterial(chimeraLeftMat, val3);
		ApplyIndependentStaminaToMaterial(chimeraRightMat, val3);
		if (!loggedChimeraDebug)
		{
			loggedChimeraDebug = true;
			((BaseUnityPlugin)this).Logger.LogInfo((object)("[PillMod] Upright Chimera active! base='" + ((Object)val5).name + "' | LEFT='" + ((Object)val6).name + "' mat='" + (((Object)(object)mat != (Object)null) ? ((Object)mat).name : "null") + "' | RIGHT='" + ((Object)val7).name + "' mat='" + (((Object)(object)mat2 != (Object)null) ? ((Object)mat2).name : "null") + "'"));
		}
		Color color3 = default(Color);
		((Color)(ref color3))..ctor(color.r, color.g, color.b, 1f);
		((Renderer)chimeraLeftSr).enabled = true;
		chimeraLeftSr.sprite = halfSprite;
		if ((Object)(object)chimeraLeftMat != (Object)null)
		{
			((Renderer)chimeraLeftSr).sharedMaterial = chimeraLeftMat;
		}
		((Renderer)chimeraLeftSr).sortingLayerID = ((Renderer)val3.handSprite).sortingLayerID;
		((Renderer)chimeraLeftSr).sortingOrder = ((Renderer)val3.handSprite).sortingOrder;
		chimeraLeftSr.color = color3;
		((Renderer)chimeraRightSr).enabled = true;
		chimeraRightSr.sprite = halfSprite2;
		if ((Object)(object)chimeraRightMat != (Object)null)
		{
			((Renderer)chimeraRightSr).sharedMaterial = chimeraRightMat;
		}
		((Renderer)chimeraRightSr).sortingLayerID = ((Renderer)val3.handSprite).sortingLayerID;
		((Renderer)chimeraRightSr).sortingOrder = ((Renderer)val3.handSprite).sortingOrder + 1;
		chimeraRightSr.color = color3;
	}

	private void ApplyIndependentStaminaToMaterial(Material targetMat, Hand hand2)
	{
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)targetMat == (Object)null) && hand2 != null)
		{
			Material val = (((Object)(object)hand2.handSprite != (Object)null) ? ((Renderer)hand2.handSprite).sharedMaterial : null);
			float num = (((Object)(object)val != (Object)null && val.HasFloat("_StaminaAmount")) ? val.GetFloat("_StaminaAmount") : Mathf.Clamp01(1f - hand2.GetGripStrengthPercent()));
			if (targetMat.HasFloat("_StaminaAmount"))
			{
				targetMat.SetFloat("_StaminaAmount", num);
			}
			if (targetMat.HasColor("_StaminaColor"))
			{
				Color val2 = (((Object)(object)val != (Object)null && val.HasColor("_StaminaColor")) ? val.GetColor("_StaminaColor") : Color.red);
				targetMat.SetColor("_StaminaColor", val2);
			}
			if (targetMat.HasColor("_StaminaOutlineColor"))
			{
				Color val3 = (((Object)(object)val != (Object)null && val.HasColor("_StaminaOutlineColor")) ? val.GetColor("_StaminaOutlineColor") : Color.red);
				targetMat.SetColor("_StaminaOutlineColor", val3);
			}
			if (targetMat.HasColor("_OutlineMaskColor") && (Object)(object)val != (Object)null && val.HasColor("_OutlineMaskColor"))
			{
				targetMat.SetColor("_OutlineMaskColor", val.GetColor("_OutlineMaskColor"));
			}
		}
	}

	private Sprite ResolveCosmeticSpriteForHand(Hand hand, Sprite baseSprite, out Material mat)
	{
		mat = (((Object)(object)hand.handSprite != (Object)null) ? ((Renderer)hand.handSprite).sharedMaterial : null);
		if ((Object)(object)baseSprite == (Object)null)
		{
			return null;
		}
		string text = ((Object)baseSprite).name;
		if (hand.currentCosmetics != null)
		{
			foreach (Cosmetic_HandItem currentCosmetic in hand.currentCosmetics)
			{
				if ((Object)(object)currentCosmetic == (Object)null)
				{
					continue;
				}
				if (fiCosmeticSpriteNames?.GetValue(currentCosmetic) is Dictionary<Sprite, string> dictionary && dictionary.TryGetValue(baseSprite, out var value) && !string.IsNullOrEmpty(value))
				{
					text = value;
				}
				if (!(fiCosmeticSwapDict?.GetValue(currentCosmetic) is Dictionary<string, List<SwapSprite>> dictionary2) || string.IsNullOrEmpty(text) || !dictionary2.TryGetValue(text, out var value2) || value2 == null || value2.Count <= 0)
				{
					continue;
				}
				SwapSprite val = null;
				foreach (SwapSprite item in value2)
				{
					if (item != null && item.replacementSprites != null && item.replacementSprites.Count != 0)
					{
						if (item.hand == hand.id)
						{
							val = item;
							break;
						}
						if (val == null)
						{
							val = item;
						}
					}
				}
				if (val != null && (Object)(object)val.replacementSprites[0] != (Object)null)
				{
					if ((Object)(object)val.material != (Object)null)
					{
						mat = val.material;
					}
					return val.replacementSprites[0];
				}
			}
		}
		return baseSprite;
	}

	private Sprite GetHalfSprite(Sprite src, bool isLeftHalf)
	{
		//IL_0043: 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_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_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)src == (Object)null || (Object)(object)src.texture == (Object)null)
		{
			return null;
		}
		Dictionary<Sprite, Sprite> dictionary = (isLeftHalf ? leftHalfSpriteCache : rightHalfSpriteCache);
		if (dictionary.TryGetValue(src, out var value) && (Object)(object)value != (Object)null)
		{
			return value;
		}
		try
		{
			Rect rect = src.rect;
			Vector2 pivot = src.pivot;
			float num = Mathf.Floor(((Rect)(ref rect)).width * 0.52f);
			float num2 = ((Rect)(ref rect)).width - num;
			if (num < 1f || num2 < 1f || ((Rect)(ref rect)).height < 1f)
			{
				return src;
			}
			Rect val = default(Rect);
			Vector2 val2 = default(Vector2);
			if (isLeftHalf)
			{
				((Rect)(ref val))..ctor(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, num, ((Rect)(ref rect)).height);
				((Vector2)(ref val2))..ctor(pivot.x / num, pivot.y / ((Rect)(ref rect)).height);
			}
			else
			{
				((Rect)(ref val))..ctor(((Rect)(ref rect)).x + num, ((Rect)(ref rect)).y, num2, ((Rect)(ref rect)).height);
				((Vector2)(ref val2))..ctor((pivot.x - num) / num2, pivot.y / ((Rect)(ref rect)).height);
			}
			Sprite val3 = Sprite.Create(src.texture, val, val2, src.pixelsPerUnit, 0u, (SpriteMeshType)0);
			((Object)val3).name = ((Object)src).name + (isLeftHalf ? "_LeftHalf" : "_RightHalf");
			dictionary[src] = val3;
			return val3;
		}
		catch
		{
			return src;
		}
	}

	private void Update()
	{
		//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_002e: 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)
		if (ListeningTarget != null)
		{
			if (Time.unscaledTime >= rebindIgnoreUntil)
			{
				if (Input.GetKeyDown((KeyCode)27))
				{
					ListeningTarget = null;
				}
				else
				{
					KeyCode val = DetectAnyPressedKey();
					if ((int)val != 0)
					{
						ApplyRebind(ListeningTarget, val);
						ListeningTarget = null;
					}
				}
			}
			ThirdHandHarmonyPatches.UpdateThirdHandInputState();
			return;
		}
		ThirdHandHarmonyPatches.UpdateThirdHandInputState();
		if (!consoleRegistered)
		{
			TryRegisterConsoleCommand();
		}
		if ((Object)(object)pillItemTemplate == (Object)null && (Object)(object)CL_AssetManager.GetBaseAssetDatabase() != (Object)null)
		{
			EnsurePillTemplates();
		}
		if (Time.time >= nextPerkMachineScanTime)
		{
			nextPerkMachineScanTime = Time.time + 1.5f;
			ScanAndSpawnPillsNearPerkMachines();
		}
		if (betrayalLockTimer > 0f)
		{
			betrayalLockTimer = Mathf.Max(0f, betrayalLockTimer - Time.deltaTime);
		}
		UpdateMutagenVignette();
		UpdateEyeBlindOverlay();
		if (!ThirdHandUnlocked)
		{
			return;
		}
		ENT_Player player = ENT_Player.GetPlayer();
		if (!((Object)(object)player != (Object)null))
		{
			return;
		}
		if (player.hands != null && player.hands.Length == 2)
		{
			TryAddNativeThirdHand(player);
		}
		else if (player.hands != null && player.hands.Length > 2)
		{
			UpdateSentientChokeBehavior(player);
			if (!IsChoking)
			{
				UpdateSentientMischiefDirector(player);
				UpdateSentientEyePokeBehavior(player);
				UpdateSentientHandSlapBehavior(player);
				UpdateSentientRogueUseBehavior(player);
				UpdateSentientRogueDropBehavior(player);
				UpdateSentientClimbBetrayalBehavior(player);
				UpdateSentientStealBehavior(player);
				UpdateSentientBagGrabBehavior(player);
				HandleThirdHandItemActions(player);
			}
		}
	}

	private void ApplyGentleHandTwitch(Hand hand, float maxShake)
	{
		if (hand == null || (Object)(object)hand.handModel == (Object)null)
		{
			return;
		}
		ViewSway component = ((Component)hand.handModel).GetComponent<ViewSway>();
		if (!((Object)(object)component == (Object)null))
		{
			float shake = component.GetShake();
			if (shake < maxShake)
			{
				hand.ShakeHand(maxShake - shake);
			}
		}
	}

	public void OnPerkMachineStarted(OS_Computer_Interface comp)
	{
		TrySpawnPillNearPerkMachine(comp);
	}

	public void OnVendingMachineStarted(ENV_VendingMachine vm)
	{
		TrySpawnPillNearVendingMachine(vm);
	}

	public void OnRoachTraderStarted(ENV_RoachTrader trader)
	{
		TrySpawnPillNearRoachTrader(trader);
	}

	private void ScanAndSpawnPillsNearPerkMachines()
	{
		if ((Object)(object)Camera.main == (Object)null)
		{
			return;
		}
		OS_Computer_Interface[] array = Object.FindObjectsByType<OS_Computer_Interface>((FindObjectsSortMode)0);
		if (array != null)
		{
			for (int i = 0; i < array.Length; i++)
			{
				TrySpawnPillNearPerkMachine(array[i]);
			}
		}
		ENV_VendingMachine[] array2 = Object.FindObjectsByType<ENV_VendingMachine>((FindObjectsSortMode)0);
		if (array2 != null)
		{
			for (int j = 0; j < array2.Length; j++)
			{
				TrySpawnPillNearVendingMachine(array2[j]);
			}
		}
		ENV_RoachTrader[] array3 = Object.FindObjectsByType<ENV_RoachTrader>((FindObjectsSortMode)0);
		if (array3 != null)
		{
			for (int k = 0; k < array3.Length; k++)
			{
				TrySpawnPillNearRoachTrader(array3[k]);
			}
		}
		ENV_RationVendor[] array4 = Object.FindObjectsByType<ENV_RationVendor>((FindObjectsSortMode)0);
		if (array4 != null)
		{
			for (int l = 0; l < array4.Length; l++)
			{
				TrySpawnPillNearRationVendor(array4[l]);
			}
		}
	}

	private void TrySpawnPillNearVendingMachine(ENV_VendingMachine vm)
	{
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: 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_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: 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_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: 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_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_016a: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)vm == (Object)null || !((Component)vm).gameObject.activeInHierarchy)
		{
			return;
		}
		int instanceID = ((Object)vm).GetInstanceID();
		if (!spawnedPerkMachines.Contains(instanceID) && EnsurePillTemplates())
		{
			spawnedPerkMachines.Add(instanceID);
			Vector3 val = ((!((Object)(object)vm.spawnSpot != (Object)null)) ? (((Component)vm).transform.position + ((Component)vm).transform.forward * 0.95f + ((Component)vm).transform.right * 0.35f + Vector3.up * 0.65f) : (vm.spawnSpot.position + vm.spawnSpot.right * 0.35f + Vector3.up * 0.45f));
			Vector3 val2 = val;
			RaycastHit val3 = default(RaycastHit);
			RaycastHit val4 = default(RaycastHit);
			if (Physics.Raycast(val, Vector3.down, ref val3, 4f, -1, (QueryTriggerInteraction)1))
			{
				val2 = ((RaycastHit)(ref val3)).point + Vector3.up * 0.14f;
			}
			else if ((Object)(object)vm.spawnSpot != (Object)null && Physics.Raycast(vm.spawnSpot.position + Vector3.up * 0.45f, Vector3.down, ref val4, 4f, -1, (QueryTriggerInteraction)1))
			{
				val2 = ((RaycastHit)(ref val4)).point + Vector3.up * 0.14f;
			}
			SpawnPillAt(val2);
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"[PillMod] Капсула заспавнена рядом с торговым автоматом '{((Object)vm).name}' ({val2})");
		}
	}

	private void TrySpawnPillNearRoachTrader(ENV_RoachTrader trader)
	{
		//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_0081: 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_0092: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: 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_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_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: 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_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)trader == (Object)null || !((Component)trader).gameObject.activeInHierarchy)
		{
			return;
		}
		int instanceID = ((Object)trader).GetInstanceID();
		if (spawnedPerkMachines.Contains(instanceID) || !EnsurePillTemplates())
		{
			return;
		}
		spawnedPerkMachines.Add(instanceID);
		Vector3 position = ((Component)trader).transform.position;
		if ((Object)(object)trader.barterer != (Object)null && (Object)(object)trader.barterer.buyItemLocator != (Object)null)
		{
			position = trader.barterer.buyItemLocator.position;
		}
		Vector3 val = position + ((Component)trader).transform.forward * 0.85f + ((Component)trader).transform.right * 0.65f + Vector3.up * 0.55f;
		if ((Object)(object)trader.barterer != (Object)null && (Object)(object)trader.barterer.inputZone != (Object)null)
		{
			Bounds bounds = ((Collider)trader.barterer.inputZone).bounds;
			((Bounds)(ref bounds)).Expand(0.25f);
			if (((Bounds)(ref bounds)).Contains(val))
			{
				val += ((Component)trader).transform.right * 0.65f;
			}
		}
		Vector3 val2 = val;
		RaycastHit val3 = default(RaycastHit);
		if (Physics.Raycast(val, Vector3.down, ref val3, 4f, -1, (QueryTriggerInteraction)1))
		{
			val2 = ((RaycastHit)(ref val3)).point + Vector3.up * 0.14f;
		}
		SpawnPillAt(val2);
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"[PillMod] Капсула заспавнена рядом с торговцем '{((Object)trader).name}' ({val2})");
	}

	private void TrySpawnPillNearRationVendor(ENV_RationVendor rv)
	{
		//IL_0049: 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_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_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: 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_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_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)
		if ((Object)(object)rv == (Object)null || !((Component)rv).gameObject.activeInHierarchy)
		{
			return;
		}
		int instanceID = ((Object)rv).GetInstanceID();
		if (!spawnedPerkMachines.Contains(instanceID) && EnsurePillTemplates())
		{
			spawnedPerkMachines.Add(instanceID);
			Vector3 val;
			RaycastHit val2 = default(RaycastHit);
			if (Physics.Raycast(val = ((Component)rv).transform.position + ((Component)rv).transform.forward * 0.9f + ((Component)rv).transform.right * 0.35f + Vector3.up * 0.6f, Vector3.down, ref val2, 4f, -1, (QueryTriggerInteraction)1))
			{
				val = ((RaycastHit)(ref val2)).point + Vector3.up * 0.14f;
			}
			SpawnPillAt(val);
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"[PillMod] Капсула заспавнена рядом с автоматом пайков '{((Object)rv).name}' ({val})");
		}
	}

	private bool IsPerkMachine(OS_Computer_Interface comp)
	{
		if ((Object)(object)comp == (Object)null || !((Component)comp).gameObject.activeInHierarchy)
		{
			return false;
		}
		OS_Manager val = comp.GetComputer() ?? comp.managerPrefab;
		if ((Object)(object)val != (Object)null)
		{
			if ((Object)(object)((Component)val).GetComponentInChildren<App_PerkPage>(true) != (Object)null)
			{
				return true;
			}
			if (val.apps != null)
			{
				for (int i = 0; i < val.apps.Count; i++)
				{
					Application val2 = val.apps[i];
					if (val2 != null)
					{
						if (!string.IsNullOrEmpty(val2.id) && val2.id.IndexOf("perk", StringComparison.OrdinalIgnoreCase) >= 0)
						{
							return true;
						}
						if ((Object)(object)val2.app != (Object)null && (Object)(object)((Component)val2.app).GetComponentInChildren<App_PerkPage>(true) != (Object)null)
						{
							return true;
						}
					}
				}
			}
		}
		if ((Object)(object)comp.lever != (Object)null)
		{
			return true;
		}
		if ((Object)(object)comp.desktopData != (Object)null)
		{
			if (!string.IsNullOrEmpty(comp.desktopData.id) && comp.desktopData.id.IndexOf("perk", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
			if (!string.IsNullOrEmpty(comp.desktopData.diskName) && comp.desktopData.diskName.IndexOf("perk", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
		}
		return false;
	}

	private void TrySpawnPillNearPerkMachine(OS_Computer_Interface comp)
	{
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: 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_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: 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_014e: 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_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: 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_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: 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)
		//IL_016e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: 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_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: 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_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: 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_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)comp == (Object)null)
		{
			return;
		}
		int instanceID = ((Object)comp).GetInstanceID();
		if (!spawnedPerkMachines.Contains(instanceID) && IsPerkMachine(comp) && EnsurePillTemplates())
		{
			spawnedPerkMachines.Add(instanceID);
			Vector3 position = ((Component)comp).transform.position;
			Vector3 val4;
			if ((Object)(object)comp.playerPosition != (Object)null)
			{
				Vector3 val = comp.playerPosition.position - position;
				val.y = 0f;
				Vector3 val2 = ((((Vector3)(ref val)).sqrMagnitude > 0.01f) ? ((Vector3)(ref val)).normalized : comp.playerPosition.forward);
				Vector3 val3 = Vector3.Cross(Vector3.up, val2);
				Vector3 normalized = ((Vector3)(ref val3)).normalized;
				val4 = position + val2 * 0.85f + normalized * 0.45f;
				val4.y = Mathf.Max(position.y, comp.playerPosition.position.y) + 0.65f;
			}
			else
			{
				val4 = position + ((Component)comp).transform.forward * 0.95f + ((Component)comp).transform.right * 0.4f + Vector3.up * 0.65f;
			}
			Vector3 val5 = val4;
			RaycastHit val6 = default(RaycastHit);
			RaycastHit val7 = default(RaycastHit);
			if (Physics.Raycast(val4, Vector3.down, ref val6, 4f, -1, (QueryTriggerInteraction)1))
			{
				val5 = ((RaycastHit)(ref val6)).point + Vector3.up * 0.14f;
			}
			else if ((Object)(object)comp.playerPosition != (Object)null && Physics.Raycast(comp.playerPosition.position + Vector3.up * 0.65f, Vector3.down, ref val7, 4f, -1, (QueryTriggerInteraction)1))
			{
				val5 = ((RaycastHit)(ref val7)).point + Vector3.up * 0.14f;
			}
			SpawnPillAt(val5);
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"[PillMod] Мутагенная пилюля заспавнена рядом с автоматом перков '{((Object)comp).name}' ({val5})");
		}
	}

	private float ComputeSentientChaosMultiplier(ENT_Player player)
	{
		if ((Object)(object)player == (Object)null)
		{
			return 1f;
		}
		int num = 0;
		if (player.hands != null)
		{
			for (int i = 0; i < player.hands.Length; i++)
			{
				Hand val = player.hands[i];
				if (val != null && val.GetGripStrengthPercent() <= 0.45f)
				{
					num++;
				}
			}
		}
		float num2 = Mathf.Max(0.01f, ((GameEntity)player).maxHealth);
		float num3 = Mathf.Clamp01(((GameEntity)player).health / num2);
		float num4 = (1f - num3) * 10f;
		return Mathf.Clamp(1f + (float)num * 3f + num4, 1f, 10f);
	}

	private float ComputeScaledChance(float baseChance, float chaosMult)
	{
		float num = Mathf.Clamp01((chaosMult - 1f) / 9f);
		return Mathf.Clamp(Mathf.Lerp(baseChance, 0.9f, num), 0f, 0.9f);
	}

	private bool IsAnyMischiefWarningActive()
	{
		if (!IsChoking && !slipWarningActive && !stealWarningActive && !bagGrabWarningActive && !rogueDropWarningActive && !rogueUseWarningActive && !handSlapWarningActive)
		{
			return eyePokeWarningActive;
		}
		return true;
	}

	private void UpdateSentientMischiefDirector(ENT_Player player)
	{
		if ((Object)(object)player == (Object)null || ((GameEntity)player).dead || ((Object)(object)CL_GameManager.gMan != (Object)null && CL_GameManager.gMan.isPaused) || player.hands == null || player.hands.Length <= 2 || IsAnyMischiefWarningActive() || Inventory.IsShowingInventory())
		{
			return;
		}
		float num = ComputeSentientChaosMultiplier(player);
		if (mischiefCountdown <= 0f)
		{
			mischiefCountdown = Random.Range(28f, 32f);
			return;
		}
		mischiefCountdown -= Time.deltaTime * num;
		if (mischiefCountdown > 0f)
		{
			return;
		}
		float num2 = ComputeScaledChance(0.45f, num);
		if (Random.value >= num2)
		{
			mischiefCountdown = Random.Range(10f, 14f);
			return;
		}
		List<string> list = new List<string>(7);
		Hand val = player.hands[0];
		Hand val2 = player.hands[1];
		Hand val3 = player.hands[2];
		int num3;
		int num4;
		if ((Object)(object)Inventory.instance != (Object)null && Inventory.instance.itemHands != null)
		{
			num3 = ((Inventory.instance.itemHands.Length > 2) ? 1 : 0);
			if (num3 != 0 && Inventory.instance.itemHands[2] != null)
			{
				num4 = ((Inventory.instance.itemHands[2].currentItem != null) ? 1 : 0);
				goto IL_013e;
			}
		}
		else
		{
			num3 = 0;
		}
		num4 = 0;
		goto IL_013e;
		IL_013e:
		bool flag = (byte)num4 != 0;
		bool flag2 = num3 != 0 && ((Inventory.instance.itemHands[0] != null && Inventory.instance.itemHands[0].currentItem != null) || (Inventory.instance.itemHands[1] != null && Inventory.instance.itemHands[1].currentItem != null));
		bool flag3 = val3 != null && (val3.IsHolding() || val3.IsHanging()) && (Object)(object)val3.GetHandItem() == (Object)null;
		list.Add("choke");
		bool flag4 = (val != null && val.GetGripStrengthPercent() > 0.05f) || (val2 != null && val2.GetGripStrengthPercent() > 0.05f);
		if (!flag3 && !IsBetrayalLocked && flag4)
		{
			list.Add("hand_slap");
		}
		if (flag)
		{
			list.Add("rogue_drop");
		}
		if (CanRogueUseThirdHandItem(player, out var _))
		{
			list.Add("rogue_use");
		}
		if (!flag && !flag3 && !IsBetrayalLocked && flag2)
		{
			list.Add("steal");
		}
		if (!flag && !flag3 && !IsBetrayalLocked && GetBackpackItemsForGrab().Count > 0)
		{
			list.Add("bag_grab");
		}
		if (flag3 && currentHangDuration >= 1f && slipCooldownCountdown <= 0f)
		{
			list.Add("climb_slip");
		}
		if (!flag3 && !IsBetrayalLocked && (leftEyeBlindTimer <= 0.5f || rightEyeBlindTimer <= 0.5f))
		{
			list.Add("eye_poke");
		}
		if (list.Count == 0)
		{
			mischiefCountdown = Random.Range(28f, 32f);
			return;
		}
		string text = list[Random.Range(0, list.Count)];
		if (list.Count > 1 && text == lastMischiefType)
		{
			text = list[Random.Range(0, list.Count)];
		}
		bool flag5 = false;
		switch (text)
		{
		case "choke":
			StartChokeAttack(player);
			flag5 = IsChoking;
			break;
		case "hand_slap":
			flag5 = TriggerHandSlapWarning(player);
			break;
		case "rogue_drop":
			flag5 = TriggerRogueItemDropWarning(player);
			break;
		case "rogue_use":
			flag5 = TriggerRogueItemUseWarning(player);
			break;
		case "steal":
			flag5 = TriggerStealWarning(player);
			break;
		case "bag_grab":
			flag5 = TriggerBagGrabWarning(player);
			break;
		case "climb_slip":
			flag5 = TriggerBetrayalSlipWarning(player);
			break;
		case "eye_poke":
			flag5 = TriggerEyePokeWarning(player);
			break;
		}
		if (flag5)
		{
			lastMischiefType = text;
		}
		mischiefCountdown = Random.Range(28f, 32f);
	}

	private void UpdateSentientClimbBetrayalBehavior(ENT_Player player)
	{
		if ((Object)(object)player == (Object)null || ((GameEntity)player).dead || ((Object)(object)CL_GameManager.gMan != (Object)null && CL_GameManager.gMan.isPaused) || player.hands == null || player.hands.Length <= 2)
		{
			return;
		}
		float num = ComputeSentientChaosMultiplier(player);
		if (slipCooldownCountdown > 0f)
		{
			slipCooldownCountdown = Mathf.Max(0f, slipCooldownCountdown - Time.deltaTime * num);
		}
		Hand val = player.hands[2];
		if (val == null)
		{
			return;
		}
		if ((!val.IsHolding() && !val.IsHanging()) || !((Object)(object)val.GetHandItem() == (Object)null))
		{
			currentHangDuration = 0f;
			slipWarningActive = false;
			slipWarnTimer = 0f;
			return;
		}
		currentHangDuration += Time.deltaTime;
		if (slipWarningActive)
		{
			ApplyGentleHandTwitch(val, 0.055f);
			slipWarnTimer -= Time.deltaTime;
			if (slipWarnTimer <= 0f)
			{
				slipWarningActive = false;
				ExecuteBetrayalSlip(player);
			}
			return;
		}
		if (slipCheckCountdown > 0f)
		{
			slipCheckCountdown -= Time.deltaTime * num;
		}
		if (currentHangDuration >= 1f && slipCooldownCountdown <= 0f && slipCheckCountdown <= 0f && !IsAnyMischiefWarningActive())
		{
			slipCheckCountdown = Mathf.Max(2.5f, 0.55f * num);
			float num2 = ComputeScaledChance(0.45f, num);
			if (Random.value < num2 && TriggerBetrayalSlipWarning(player))
			{
				lastMischiefType = "climb_slip";
				mischiefCountdown = Random.Range(28f, 32f);
			}
		}
	}

	private void UpdateSentientStealBehavior(ENT_Player player)
	{
		if ((Object)(object)player == (Object)null || ((GameEntity)player).dead || ((Object)(object)CL_GameManager.gMan != (Object)null && CL_GameManager.gMan.isPaused) || player.hands == null || player.hands.Length <= 2 || (Object)(object)Inventory.instance == (Object)null || Inventory.instance.itemHands == null || Inventory.instance.itemHands.Length <= 2)
		{
			return;
		}
		Hand val = player.hands[2];
		if (val == null)
		{
			return;
		}
		ItemHand val2 = Inventory.instance.itemHands[0];
		ItemHand val3 = Inventory.instance.itemHands[1];
		ItemHand val4 = Inventory.instance.itemHands[2];
		bool num = val4 != null && val4.currentItem != null;
		bool flag = val.IsHolding() || val.IsHanging();
		bool flag2 = val2 != null && val2.currentItem != null;
		bool flag3 = val3 != null && val3.currentItem != null;
		if (num || (!flag2 && !flag3))
		{
			stealWarningActive = false;
			stealWarnTimer = 0f;
			stealTargetHandIdx = -1;
			stealCountdown = Random.Range(26f, 34f);
		}
		else if (flag || slipWarningActive || IsBetrayalLocked || bagGrabWarningActive)
		{
			if (stealWarningActive)
			{
				stealWarningActive = false;
				stealWarnTimer = 0f;
				stealTargetHandIdx = -1;
			}
		}
		else
		{
			if (!stealWarningActive)
			{
				return;
			}
			if (stealTargetHandIdx < 0 || stealTargetHandIdx > 1 || Inventory.instance.itemHands[stealTargetHandIdx] == null || Inventory.instance.itemHands[stealTargetHandIdx].currentItem == null)
			{
				stealWarningActive = false;
				stealWarnTimer = 0f;
				stealTargetHandIdx = -1;
				return;
			}
			ApplyGentleHandTwitch(val, 0.045f);
			if (player.hands[stealTargetHandIdx] != null)
			{
				ApplyGentleHandTwitch(player.hands[stealTargetHandIdx], 0.03f);
			}
			stealWarnTimer -= Time.deltaTime;
			if (stealWarnTimer <= 0f)
			{
				int victimIdx = stealTargetHandIdx;
				stealWarningActive = false;
				stealTargetHandIdx = -1;
				ExecuteStealFromHand(player, victimIdx);
			}
		}
	}

	public bool TriggerStealWarning(ENT_Player player)
	{
		if ((Object)(object)player == (Object)null || IsChoking || stealWarningActive || bagGrabWarningActive || slipWarningActive || IsBetrayalLocked)
		{
			return false;
		}
		if (player.hands == null || player.hands.Length <= 2)
		{
			return false;
		}
		if ((Object)(object)Inventory.instance == (Object)null || Inventory.instance.itemHands == null || Inventory.instance.itemHands.Length <= 2)
		{
			return false;
		}
		Hand val = player.hands[2];
		if (val == null || val.IsHolding() || val.IsHanging())
		{
			return false;
		}
		if (Inventory.instance.itemHands[2] != null && Inventory.instance.itemHands[2].currentItem != null)
		{
			return false;
		}
		bool flag = Inventory.instance.itemHands[0] != null && Inventory.instance.itemHands[0].currentItem != null;
		bool flag2 = Inventory.instance.itemHands[1] != null && Inventory.instance.itemHands[1].currentItem != null;
		if (!flag && !flag2)
		{
			return false;
		}
		if (flag && flag2)
		{
			stealTargetHandIdx = ((!(Random.value < 0.5f)) ? 1 : 0);
		}
		else
		{
			stealTargetHandIdx = ((!flag) ? 1 : 0);
		}
		stealWarningActive = true;
		stealWarnTimer = 0.5f;
		PlayAudioClip2D(chokeGrabSound, 0.5f);
		((BaseUnityPlugin)this).Logger.LogInfo((object)("[PillMod] 3-я рука тянется вырвать предмет из " + ((stealTargetHandIdx == 0) ? "левой" : "правой") + " руки!"));
		return true;
	}

	private void ExecuteStealFromHand(ENT_Player player, int victimIdx)
	{
		if ((Object)(object)player == (Object)null || player.hands == null || player.hands.Length <= 2 || (Object)(object)Inventory.instance == (Object)null || Inventory.instance.itemHands == null || Inventory.instance.itemHands.Length <= 2 || victimIdx < 0 || victimIdx > 1)
		{
			return;
		}
		ItemHand val = Inventory.instance.itemHands[victimIdx];
		ItemHand val2 = Inventory.instance.itemHands[2];
		Hand val3 = player.hands[2];
		if (val != null && val.currentItem != null && val2 != null && val2.currentItem == null && val3 != null && !val3.IsHolding() && !val3.IsHanging())
		{
			Item currentItem = val.currentItem;
			Inventory.instance.ClearItemFromHand(currentItem);
			Inventory.instance.AddItemToHand(currentItem, 2);
			ApplyGentleHandTwitch(val3, 0.075f);
			if (player.hands[victimIdx] != null)
			{
				ApplyGentleHandTwitch(player.hands[victimIdx], 0.055f);
			}
			PlayAudioClip2D(struggleHitSound, 0.8f);
			stealCountdown = Random.Range(26f, 36f);
			((BaseUnityPlugin)this).Logger.LogInfo((object)("[PillMod] 3-я рука нагло отняла предмет '" + currentItem.itemName + "' из " + ((victimIdx == 0) ? "левой" : "правой") + " руки!"));
		}
	}

	private List<Item> GetBackpackItemsForGrab()
	{
		List<Item> list = new List<Item>();
		if ((Object)(object)Inventory.instance == (Object)null)
		{
			return list;
		}
		List<Item> items = Inventory.instance.GetItems(true, false, true);
		if (items == null)
		{
			return list;
		}
		for (int i = 0; i < items.Count; i++)
		{
			Item val = items[i];
			if (val == null || val.hasBeenDestroyed)
			{
				continue;
			}
			bool flag = false;
			if (Inventory.instance.itemHands != null)
			{
				for (int j = 0; j < Inventory.instance.itemHands.Length; j++)
				{
					if (Inventory.instance.itemHands[j] != null && Inventory.instance.itemHands[j].currentItem == val)
					{
						flag = true;
						break;
					}
				}
			}
			if (!flag)
			{
				list.Add(val);
			}
		}
		return list;
	}

	private void UpdateSentientBagGrabBehavior(ENT_Player player)
	{
		if ((Object)(object)player == (Object)null || ((GameEntity)player).dead || ((Object)(object)CL_GameManager.gMan != (Object)null && CL_GameManager.gMan.isPaused) || player.hands == null || player.hands.Length <= 2 || (Object)(object)Inventory.instance == (Object)null || Inventory.instance.itemHands == null || Inventory.instance.itemHands.Length <= 2)
		{
			return;
		}
		Hand val = player.hands[2];
		if (val == null)
		{
			return;
		}
		ItemHand val2 = Inventory.instance.itemHands[2];
		bool num = val2 != null && val2.currentItem != null;
		bool flag = val.IsHolding() || val.IsHanging();
		List<Item> backpackItemsForGrab = GetBackpackItemsForGrab();
		if (num || backpackItemsForGrab.Count == 0)
		{
			bagGrabWarningActive = false;
			bagGrabWarnTimer = 0f;
			bagGrabCountdown = Random.Range(28f, 36f);
		}
		else if (flag || slipWarningActive || IsBetrayalLocked || stealWarningActive || Inventory.IsShowingInventory())
		{
			if (bagGrabWarningActive)
			{
				bagGrabWarningActive = false;
				bagGrabWarnTimer = 0f;
			}
		}
		else if (bagGrabWarningActive)
		{
			ApplyGentleHandTwitch(val, 0.045f);
			bagGrabWarnTimer -= Time.deltaTime;
			if (bagGrabWarnTimer <= 0f)
			{
				bagGrabWarningActive = false;
				ExecuteBagGrab(player);
			}
		}
	}

	public bool TriggerBagGrabWarning(ENT_Player player)
	{
		if ((Object)(object)player == (Object)null || IsChoking || bagGrabWarningActive || stealWarningActive || slipWarningActive || IsBetrayalLocked)
		{
			return false;
		}
		if (Inventory.IsShowingInventory())
		{
			return false;
		}
		if (player.hands == null || player.hands.Length <= 2)
		{
			return false;
		}
		if ((Object)(object)Inventory.instance == (Object)null || Inventory.instance.itemHands == null || Inventory.instance.itemHands.Length <= 2)
		{
			return false;
		}
		Hand val = player.hands[2];
		if (val == null || val.IsHolding() || val.IsHanging())
		{
			return false;
		}
		if (Inventory.instance.itemHands[2] != null && Inventory.instance.itemHands[2].currentItem != null)
		{
			return false;
		}
		if (GetBackpackItemsForGrab().Count == 0)
		{
			return false;
		}
		bagGrabWarningActive = true;
		bagGrabWarnTimer = 0.55f;
		PlayAudioClip2D(chokeGrabSound, 0.45f);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"[PillMod] 3-я рука сама полезла в рюкзак за случайным предметом!");
		return true;
	}

	private void ExecuteBagGrab(ENT_Player player)
	{
		if ((Object)(object)player == (Object)null || player.hands == null || player.hands.Length <= 2 || (Object)(object)Inventory.instance == (Object)null || Inventory.instance.itemHands == null || Inventory.instance.itemHands.Length <= 2 || Inventory.IsShowingInventory())
		{
			return;
		}
		Hand val = player.hands[2];
		ItemHand val2 = Inventory.instance.itemHands[2];
		if (val == null || val2 == null || val2.currentItem != null || val.IsHolding() || val.IsHanging())
		{
			return;
		}
		List<Item> backpackItemsForGrab = GetBackpackItemsForGrab();
		if (backpackItemsForGrab.Count == 0)
		{
			return;
		}
		Item val3 = backpackItemsForGrab[Random.Range(0, backpackItemsForGrab.Count)];
		if (val3 == null)
		{
			return;
		}
		List<Pouch> allPouches = Inventory.instance.GetAllPouches();
		if (allPouches != null)
		{
			for (int i = 0; i < allPouches.Count; i++)
			{
				Pouch val4 = allPouches[i];
				if (val4 != null && val4.pouchItems != null && val4.pouchItems.Contains(val3))
				{
					val4.RemoveItemFromPouch(val3);
				}
			}
		}
		Inventory.instance.AddItemToHand(val3, 2);
		Inventory.instance.UpdatePouches(true);
		ApplyGentleHandTwitch(val, 0.07f);
		PlayAudioClip2D(struggleHitSound, 0.65f);
		bagGrabCountdown = Random.Range(28f, 38f);
		((BaseUnityPlugin)this).Logger.LogInfo((object)("[PillMod] 3-я рука сама вытащила из рюкзака предмет '" + val3.itemName + "'!"));
	}

	public bool TriggerBetrayalSlipWarning(ENT_Player player)
	{
		if ((Object)(object)player == (Object)null || IsChoking || slipWarningActive || player.hands == null || player.hands.Length <= 2)
		{
			return false;
		}
		Hand val = player.hands[2];
		if (val == null || (!val.IsHolding() && !val.IsHanging()))
		{
			return false;
		}
		slipWarningActive = true;
		slipWarnTimer = 0.45f;
		PlayAudioClip2D(chokeGrabSound, 0.55f);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"[PillMod] 3-я рука судорожно дёргается — сейчас сама отпустит зацеп!");
		return true;
	}

	private void ExecuteBetrayalSlip(ENT_Player player)
	{
		if (!((Object)(object)player == (Object)null) && player.hands != null && player.hands.Length > 2)
		{
			Hand val = player.hands[2];
			if (val != null)
			{
				player.StopInteraction(2, "", true);
				val.SetHandWait(1.35f);
				betrayalLockTimer = 1.35f;
				slipCooldownCountdown = Random.Range(18f, 28f);
				currentHangDuration = 0f;
				PlayAudioClip2D(struggleHitSound, 0.85f);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"[PillMod] 3-я рука предательски расцепилась со стены!");
			}
		}
	}

	private bool ForceDropThirdHandItem(ENT_Player player, bool tossForward)
	{
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: 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_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: 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_0138: 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_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: 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_0156: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)player == (Object)null || (Object)(object)Inventory.instance == (Object)null || Inventory.instance.itemHands == null || Inventory.instance.itemHands.Length <= 2)
		{
			return false;
		}
		ItemHand val = Inventory.instance.itemHands[2];
		if (val == null || val.currentItem == null)
		{
			return false;
		}
		Item currentItem = val.currentItem;
		Transform val2 = (((Object)(object)player.cam != (Object)null) ? ((Component)player.cam).transform : ((Component)player).transform);
		Vector3 val3 = val2.position + val2.forward * 0.75f - val2.up * 0.15f;
		if (!Inventory.instance.DropItemFromHand(val3, 2, false, true, false) && val.currentItem != null)
		{
			Inventory.instance.DropItemIntoWorld(currentItem, val3, true);
		}
		if (tossForward && currentItem != null)
		{
			Item_Object dropObject = currentItem.GetDropObject(false);
			if ((Object)(object)dropObject != (Object)null)
			{
				Rigidbody component = ((Component)dropObject).GetComponent<Rigidbody>();
				if ((Object)(object)component != (Object)null)
				{
					Vector3 val4 = val2.forward * 0.8f + val2.right * Random.Range(-0.5f, 0.5f) + Vector3.up * 0.35f;
					Vector3 normalized = ((Vector3)(ref val4)).normalized;
					component.AddForce(normalized * 4.5f, (ForceMode)1);
				}
			}
		}
		return true;
	}

	private void UpdateSentientEyePokeBehavior(ENT_Player player)
	{
		if ((Object)(object)player == (Object)null || ((GameEntity)player).dead || ((Object)(object)CL_GameManager.gMan != (Object)null && CL_GameManager.gMan.isPaused) || player.hands == null || player.hands.Length <= 2)
		{
			return;
		}
		Hand val = player.hands[2];
		if (val == null)
		{
			return;
		}
		if (val.IsHolding() || val.IsHanging() || slipWarningActive || IsBetrayalLocked || stealWarningActive || bagGrabWarningActive || rogueDropWarningActive || rogueUseWarningActive || handSlapWarningActive || Inventory.IsShowingInventory())
		{
			if (eyePokeWarningActive)
			{
				eyePokeWarningActive = false;
				eyePokeWarnTimer = 0f;
				eyePokeTargetEye = -1;
			}
		}
		else if (eyePokeWarningActive)
		{
			ApplyGentleHandTwitch(val, 0.045f);
			eyePokeWarnTimer -= Time.deltaTime;
			if (eyePokeWarnTimer <= 0f)
			{
				int targetEye = eyePokeTargetEye;
				eyePokeWarningActive = false;
				eyePokeTargetEye = -1;
				ExecuteEyePoke(player, targetEye);
			}
		}
	}

	public bool TriggerEyePokeWarning(ENT_Player player)
	{
		if ((Object)(object)player == (Object)null || IsChoking || eyePokeWarningActive)
		{
			return false;
		}
		if (player.hands == null || player.hands.Length <= 2)
		{
			return false;
		}
		bool flag = leftEyeBlindTimer <= 0.5f;
		bool flag2 = rightEyeBlindTimer <= 0.5f;
		if (!flag && !flag2)
		{
			return false;
		}
		if (flag && flag2)
		{
			eyePokeTargetEye = ((!(Random.value < 0.5f)) ? 1 : 0);
		}
		else
		{
			eyePokeTargetEye = ((!flag) ? 1 : 0);
		}
		eyePokeWarningActive = true;
		eyePokeWarnTimer = 0.38f;
		PlayAudioClip2D(chokeGrabSound, 0.45f);
		((BaseUnityPlugin)this).Logger.LogInfo((object)("[PillMod] 3-я рука замахнулась ударить в " + ((eyePokeTargetEye == 0) ? "левый" : "правый") + " глаз!"));
		return true;
	}

	private void ExecuteEyePoke(ENT_Player player, int targetEye)
	{
		if ((Object)(object)player == (Object)null || player.hands == null || player.hands.Length <= 2 || targetEye < 0 || targetEye > 1)
		{
			return;
		}
		Hand val = player.hands[2];
		if (val == null)
		{
			return;
		}
		float num = ComputeSentientChaosMultiplier(player);
		float num2 = Mathf.Clamp01((num - 1f) / 9f);
		float num3 = Mathf.Lerp(4f, 14f, num2);
		if (targetEye == 0)
		{
			leftEyeBlindTimer = Mathf.Max(leftEyeBlindTimer, num3);
		}
		else
		{
			rightEyeBlindTimer = Mathf.Max(rightEyeBlindTimer, num3);
		}
		eyePokeLungeDir = ((targetEye == 0) ? (-1f) : 1f);
		eyePokeLungeTimer = 0.24f;
		ApplyGentleHandTwitch(val, 0.08f);
		PlayAudioClip2D(struggleHitSound, 0.95f);
		if ((Object)(object)CL_UIManager.instance != (Object)null)
		{
			try
			{
				CL_UIManager.instance.SetVignette("hurt", 0.38f);
			}
			catch
			{
			}
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("[PillMod] 3-я рука ударила игрока в {0} глаз! Ослепление на {1:F1} сек (множитель {2:F1}x).", (targetEye == 0) ? "левый" : "правый", num3, num));
	}

	private void EnsureEyeBlindOverlay()
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected O, but got Unknown
		if (!((Object)(object)eyeBlindCanvas != (Object)null) || !((Object)(object)leftEyeBlindImage != (Object)null) || !((Object)(object)rightEyeBlindImage != (Object)null))
		{
			GameObject val = new GameObject("SomethingCapsule_EyeBlindCanvas");
			Object.DontDestroyOnLoad((Object)(object)val);
			eyeBlindCanvas = val.AddComponent<Canvas>();
			eyeBlindCanvas.renderMode = (RenderMode)0;
			eyeBlindCanvas.sortingOrder = 12;
			leftEyeBlindImage = CreateHalfEyeOverlayImage(val.transform, "LeftEyeBlindOverlay", isLeftEye: true);
			rightEyeBlindImage = CreateHalfEyeOverlayImage(val.transform, "RightEyeBlindOverlay", isLeftEye: false);
			((Behaviour)eyeBlindCanvas).enabled = false;
		}
	}

	private Image CreateHalfEyeOverlayImage(Transform parent, string name, bool isLeftEye)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: 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_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject(name);
		val.transform.SetParent(parent, false);
		Image obj = val.AddComponent<Image>();
		((Graphic)obj).raycastTarget = false;
		((Graphic)obj).material = null;
		obj.type = (Type)0;
		obj.preserveAspect = false;
		obj.sprite = CreateHalfEyeBlindSprite(isLeftEye);
		((Graphic)obj).color = new Color(0f, 0f, 0f, 0f);
		RectTransform rectTransform = ((Graphic)obj).rectTransform;
		rectTransform.anchorMin = Vector2.zero;
		rectTransform.anchorMax = Vector2.one;
		rectTransform.offsetMin = Vector2.zero;
		rectTransform.offsetMax = Vector2.zero;
		rectTransform.pivot = new Vector2(0.5f, 0.5f);
		return obj;
	}

	private Sprite CreateHalfEyeBlindSprite(bool isLeftEye)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Expected O, but got Unknown
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		int num = 256;
		int num2 = 64;
		Texture2D val = new Texture2D(num, num2, (TextureFormat)4, false);
		Color[] array = (Color[])(object)new Color[num * num2];
		for (int i = 0; i < num2; i++)
		{
			float num3 = (float)i / (float)(num2 - 1) * 2f - 1f;
			float num4 = num3 * num3 * 0.06f;
			for (int j = 0; j < num; j++)
			{
				float num5 = (float)j / (float)(num - 1);
				float num6 = (isLeftEye ? num5 : (1f - num5));
				float num7 = 0.44f + num4;
				float num8 = 0.6f + num4;
				float num9;
				if (num6 <= num7)
				{
					num9 = 1f;
				}
				else if (num6 >= num8)
				{
					num9 = 0f;
				}
				else
				{
					float num10 = (num6 - num7) / (num8 - num7);
					num9 = 1f - num10 * num10 * (3f - 2f * num10);
				}
				array[i * num + j] = new Color(0f, 0f, 0f, num9);
			}
		}
		val.SetPixels(array);
		((Texture)val).filterMode = (FilterMode)1;
		((Texture)val).wrapMode = (TextureWrapMode)1;
		val.Apply();
		return Sprite.Create(val, new Rect(0f, 0f, (float)num, (float)num2), new Vector2(0.5f, 0.5f), 100f);
	}

	private void UpdateEyeBlindOverlay()
	{
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0224: Unknown result type (might be due to invalid IL or missing references)
		if (leftEyeBlindTimer <= 0f && rightEyeBlindTimer <= 0f && leftEyeBlindAlpha <= 0.002f && rightEyeBlindAlpha <= 0.002f)
		{
			if ((Object)(object)eyeBlindCanvas != (Object)null)
			{
				((Behaviour)eyeBlindCanvas).enabled = false;
			}
			return;
		}
		EnsureEyeBlindOverlay();
		if ((Object)(object)eyeBlindCanvas == (Object)null || (Object)(object)leftEyeBlindImage == (Object)null || (Object)(object)rightEyeBlindImage == (Object)null)
		{
			return;
		}
		if (!((Object)(object)CL_GameManager.gMan != (Object)null) || !CL_GameManager.gMan.isPaused)
		{
			if (leftEyeBlindTimer > 0f)
			{
				leftEyeBlindTimer = Mathf.Max(0f, leftEyeBlindTimer - Time.deltaTime);
			}
			if (rightEyeBlindTimer > 0f)
			{
				rightEyeBlindTimer = Mathf.Max(0f, rightEyeBlindTimer - Time.deltaTime);
			}
		}
		float num = ((leftEyeBlindTimer > 1f) ? 0.99f : Mathf.Clamp01(leftEyeBlindTimer));
		float num2 = ((rightEyeBlindTimer > 1f) ? 0.99f : Mathf.Clamp01(rightEyeBlindTimer));
		float num3 = ((num > leftEyeBlindAlpha) ? 18f : 4.5f);
		float num4 = ((num2 > rightEyeBlindAlpha) ? 18f : 4.5f);
		leftEyeBlindAlpha = Mathf.Lerp(leftEyeBlindAlpha, num, Time.unscaledDeltaTime * num3);
		rightEyeBlindAlpha = Mathf.Lerp(rightEyeBlindAlpha, num2, Time.unscaledDeltaTime * num4);
		if (leftEyeBlindAlpha < 0.004f && num == 0f)
		{
			leftEyeBlindAlpha = 0f;
		}
		if (rightEyeBlindAlpha < 0.004f && num2 == 0f)
		{
			rightEyeBlindAlpha = 0f;
		}
		((Graphic)leftEyeBlindImage).color = new Color(0f, 0f, 0f, leftEyeBlindAlpha);
		((Behaviour)leftEyeBlindImage).enabled = leftEyeBlindAlpha > 0.002f;
		((Graphic)rightEyeBlindImage).color = new Color(0f, 0f, 0f, rightEyeBlindAlpha);
		((Behaviour)rightEyeBlindImage).enabled = rightEyeBlindAlpha > 0.002f;
		((Behaviour)eyeBlindCanvas).enabled = ((Behaviour)leftEyeBlindImage).enabled || ((Behaviour)rightEyeBlindImage).enabled;
	}

	private void UpdateSentientHandSlapBehavior(ENT_Player player)
	{
		if ((Object)(object)player == (Object)null || ((GameEntity)player).dead || ((Object)(object)CL_GameManager.gMan != (Object)null && CL_GameManager.gMan.isPaused) || player.hands == null || player.hands.Length <= 2)
		{
			return;
		}
		Hand val = player.hands[2];
		if (val == null)
		{
			return;
		}
		if (val.IsHolding() || val.IsHanging() || slipWarningActive || IsBetrayalLocked || stealWarningActive || bagGrabWarningActive || rogueDropWarningActive || rogueUseWarningActive || Inventory.IsShowingInventory())
		{
			if (handSlapWarningActive)
			{
				handSlapWarningActive = false;
				handSlapWarnTimer = 0f;
				handSlapTargetIdx = -1;
			}
		}
		else if (handSlapWarningActive)
		{
			ApplyGentleHandTwitch(val, 0.045f);
			handSlapWarnTimer -= Time.deltaTime;
			if (handSlapWarnTimer <= 0f)
			{
				int targetIdx = handSlapTargetIdx;
				handSlapWarningActive = false;
				handSlapTargetIdx = -1;
				ExecuteHandSlap(player, targetIdx);
			}
		}
	}

	public bool TriggerHandSlapWarning(ENT_Player player)
	{
		if ((Object)(object)player == (Object)null || IsChoking || handSlapWarningActive)
		{
			return false;
		}
		if (player.hands == null || player.hands.Length <= 2)
		{
			return false;
		}
		Hand val = player.hands[0];
		Hand val2 = player.hands[1];
		bool flag = val != null && val.GetGripStrengthPercent() > 0.05f;
		bool flag2 = val2 != null && val2.GetGripStrengthPercent() > 0.05f;
		if (!flag && !flag2)
		{
			return false;
		}
		if (flag && flag2)
		{
			handSlapTargetIdx = ((!(Random.value < 0.5f)) ? 1 : 0);
		}
		else
		{
			handSlapTargetIdx = ((!flag) ? 1 : 0);
		}
		handSlapWarningActive = true;
		handSlapWarnTimer = 0.4f;
		PlayAudioClip2D(chokeGrabSound, 0.45f);
		((BaseUnityPlugin)this).Logger.LogInfo((object)("[PillMod] 3-я рука замахнулась ударить по " + ((handSlapTargetIdx == 0) ? "левой" : "правой") + " руке!"));
		return true;
	}

	private void ExecuteHandSlap(ENT_Player player, int targetIdx)
	{
		if (!((Object)(object)player == (Object)null) && player.hands != null && player.hands.Length > 2 && targetIdx >= 0 && targetIdx <= 1)
		{
			Hand val = player.hands[targetIdx];
			Hand val2 = player.hands[2];
			if (val != null && val2 != null)
			{
				float num = ComputeSentientChaosMultiplier(player);
				float num2 = Mathf.Clamp01((num - 1f) / 9f);
				float num3 = Mathf.Lerp(0.3f, 0.85f, num2);
				float num4 = val.GetGripStrengthMax() * num3;
				val.DamageGripStrength(num4);
				handSlapLungeDir = ((targetIdx == 0) ? (-1f) : 1f);
				handSlapLungeTimer = 0.22f;
				ApplyGentleHandTwitch(val, 0.11f);
				ApplyGentleHandTwitch(val2, 0.075f);
				PlayAudioClip2D(struggleHitSound, 0.9f);
				handSlapCountdown = Random.Range(26f, 36f);
				((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("[PillMod] 3-я рука ударила по {0} руке! Потрачено {1}% стамины (множитель {2:F1}x).", (targetIdx == 0) ? "левой" : "правой", Mathf.RoundToInt(num3 * 100f), num));
			}
		}
	}

	private bool CanRogueUseThirdHandItem(ENT_Player player, out HandItem handItem)
	{
		handItem = null;
		if ((Object)(object)player == (Object)null || ((GameEntity)player).dead || IsChoking)
		{
			return false;
		}
		if (player.hands == null || player.hands.Length <= 2)
		{
			return false;
		}
		Hand val = player.hands[2];
		if (val == null)
		{
			return false;
		}
		HandItem handItem2 = val.GetHandItem();
		if ((Object)(object)handItem2 == (Object)null || !handItem2.active || handItem2.used || handItem2.IsCurrentlyInteracting())
		{
			return false;
		}
		if (handItem2 is HandItem_Note)
		{
			return false;
		}
		if (handItem2 is PillHandItem && !CanEatMorePills)
		{
			return false;
		}
		if (handItem2.item != null && handItem2.item.HasTag("unpurchased"))
		{
			return false;
		}
		if (!handItem2.canUseWhileHanging && player.IsHanging())
		{
			return false;
		}
		handItem = handItem2;
		return true;
	}

	private void UpdateSentientRogueUseBehavior(ENT_Player player)
	{
		if ((Object)(object)player == (Object)null || ((Object)(object)CL_GameManager.gMan != (Object)null && CL_GameManager.gMan.isPaused))
		{
			return;
		}
		if (rogueUseStopTimer > 0f)
		{
			rogueUseStopTimer -= Time.deltaTime;
			if (rogueUseStopTimer <= 0f)
			{
				if ((Object)(object)rogueUseStopTarget != (Object)null && (Object)(object)((Component)rogueUseStopTarget).gameObject != (Object)null)
				{
					try
					{
						rogueUseStopTarget.StopUse();
					}
					catch
					{
					}
				}
				rogueUseStopTarget = null;
			}
		}
		if (((GameEntity)player).dead || player.hands == null || player.hands.Length <= 2)
		{
			return;
		}
		HandItem handItem;
		bool flag = CanRogueUseThirdHandItem(player, out handItem);
		if (!flag || rogueDropWarningActive || slipWarningActive || stealWarningActive || bagGrabWarningActive)
		{
			rogueUseWarningActive = false;
			rogueUseWarnTimer = 0f;
			if (!flag)
			{
				rogueUseCountdown = Random.Range(24f, 34f);
			}
		}
		else if (rogueUseWarningActive)
		{
			ApplyGentleHandTwitch(player.hands[2], 0.045f);
			rogueUseWarnTimer -= Time.deltaTime;
			if (rogueUseWarnTimer <= 0f)
			{
				rogueUseWarningActive = false;
				ExecuteRogueItemUse(player);
			}
		}
	}

	public bool TriggerRogueItemUseWarning(ENT_Player player)
	{
		if (rogueUseWarningActive || rogueDropWarningActive || slipWarningActive || stealWarningActive || bagGrabWarningActive)
		{
			return false;
		}
		if (!CanRogueUseThirdHandItem(player, out var handItem))
		{
			return false;
		}
		rogueUseWarningActive = true;
		rogueUseWarnTimer = 0.55f;
		PlayAudioClip2D(chokeGrabSound, 0.45f);
		string text = ((handItem.item != null) ? handItem.item.itemName : ((Object)handItem).name);
		((BaseUnityPlugin)this).Logger.LogInfo((object)("[PillMod] 3-я рука собралась сама использовать предмет '" + text + "'!"));
		return true;
	}

	private void ExecuteRogueItemUse(ENT_Player player)
	{
		if (CanRogueUseThirdHandItem(player, out var handItem))
		{
			string text = ((handItem.item != null) ? handItem.item.itemName : ((Object)handItem).name);
			try
			{
				handItem.TryUse();
				rogueUseStopTarget = handItem;
				rogueUseStopTimer = 0.25f;
				ApplyGentleHandTwitch(player.hands[2], 0.07f);
				((BaseUnityPlugin)this).Logger.LogInfo((object)("[PillMod] 3-я рука самовольно использовала предмет '" + text + "'!"));
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("[PillMod] Ошибка самовольного использования '" + text + "': " + ex.Message));
			}
			rogueUseCountdown = Random.Range(24f, 34f);
		}
	}

	private void UpdateSentientRogueDropBehavior(ENT_Player player)
	{
		if ((Object)(object)player == (Object)null || ((GameEntity)player).dead || ((Object)(object)CL_GameManager.gMan != (Object)null && CL_GameManager.gMan.isPaused) || (Object)(object)Inventory.instance == (Object)null || Inventory.instance.itemHands == null || Inventory.instance.itemHands.Length <= 2)
		{
			return;
		}
		ItemHand val = Inventory.instance.itemHands[2];
		if (val == null || val.currentItem == null)
		{
			rogueDropWarningActive = false;
			rogueDropWarnTimer = 0f;
			rogueDropCountdown = Random.Range(26f, 34f);
		}
		else
		{
			if (!rogueDropWarningActive)
			{
				return;
			}
			if (player.hands[2] != null)
			{
				ApplyGentleHandTwitch(player.hands[2], 0.045f);
			}
			rogueDropWarnTimer -= Time.deltaTime;
			if (rogueDropWarnTimer <= 0f)
			{
				rogueDropWarningActive = false;
				if (ForceDropThirdHandItem(player, tossForward: true))
				{
					PlayAudioClip2D(struggleHitSound, 0.7f);
					((BaseUnityPlugin)this).Logger.LogInfo((object)"[PillMod] 3-я рука сама выкинула предмет на пол!");
				}
			}
		}
	}

	public bool TriggerRogueItemDropWarning(ENT_Player player)
	{
		if ((Object)(object)p