Decompiled source of DeadButEmployed v1.5.4

BepInEx/plugins/DeadButEmployed/DeathExtended.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Dissonance;
using DunGen;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.Utilities;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyFileVersion("1.5.4.0")]
[assembly: AssemblyInformationalVersion("1.5.4")]
[assembly: TargetFramework(".NETStandard,Version=v2.1")]
[assembly: AssemblyVersion("1.5.4.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace DeathExtended
{
	[BepInPlugin("com.deathextended.deadbutemployed", "DeadButEmployed", "1.5.4")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Id = "com.deathextended.deadbutemployed";

		public const string Name = "DeadButEmployed";

		public const string Version = "1.5.4";

		private Harmony harmony;

		private HideFlags bootstrapFlags;

		internal static RoundLifecycle Runtime { get; private set; }

		private void Awake()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				ModConfig modConfig = new ModConfig(((BaseUnityPlugin)this).Config);
				if (!modConfig.Enabled)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)"DeadButEmployed 1.5.4 is disabled in the configuration.");
					return;
				}
				Scene activeScene = SceneManager.GetActiveScene();
				if (!((Scene)(ref activeScene)).isLoaded)
				{
					bootstrapFlags = (HideFlags)(0x34 & ~((Object)((Component)this).gameObject).hideFlags);
					GameObject gameObject = ((Component)this).gameObject;
					((Object)gameObject).hideFlags = (HideFlags)(((Object)gameObject).hideFlags | bootstrapFlags);
					SceneManager.sceneLoaded += OnFirstSceneLoaded;
				}
				Runtime = new RoundLifecycle(modConfig, ((BaseUnityPlugin)this).Logger);
				harmony = new Harmony("com.deathextended.deadbutemployed");
				harmony.PatchAll(typeof(Plugin).Assembly);
				((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("{0} {1} initialized with {2} patches (Unity {3}).", "DeadButEmployed", "1.5.4", harmony.GetPatchedMethods().Count(), Application.unityVersion));
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)string.Format("{0} initialization failed: {1}", "DeadButEmployed", arg));
				ShutDown();
			}
		}

		private void OnFirstSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			ReleaseBootstrapFlags();
		}

		private void ReleaseBootstrapFlags()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			SceneManager.sceneLoaded -= OnFirstSceneLoaded;
			if ((int)bootstrapFlags != 0 && Object.op_Implicit((Object)(object)((Component)this).gameObject))
			{
				GameObject gameObject = ((Component)this).gameObject;
				((Object)gameObject).hideFlags = (HideFlags)(((Object)gameObject).hideFlags & ~bootstrapFlags);
			}
			bootstrapFlags = (HideFlags)0;
		}

		private void Update()
		{
			Runtime?.Tick();
		}

		private void LateUpdate()
		{
			Runtime?.LateTick();
		}

		private void OnDestroy()
		{
			ShutDown();
		}

		private void ShutDown()
		{
			ReleaseBootstrapFlags();
			RoundLifecycle runtime = Runtime;
			Runtime = null;
			try
			{
				runtime?.Dispose();
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)string.Format("{0} could not dispose its runtime: {1}", "DeadButEmployed", arg));
			}
			try
			{
				Harmony obj = harmony;
				if (obj != null)
				{
					obj.UnpatchSelf();
				}
			}
			catch (Exception arg2)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)string.Format("{0} could not remove its patches: {1}", "DeadButEmployed", arg2));
			}
			harmony = null;
		}
	}
	internal sealed class ModConfig
	{
		private readonly ConfigFile file;

		private readonly ConfigEntry<bool> enabled;

		private readonly ConfigEntry<bool> requireAll;

		private readonly ConfigEntry<bool> noise;

		private readonly ConfigEntry<bool> customWall;

		private readonly ConfigEntry<bool> customTerminal;

		private readonly ConfigEntry<bool> contracts;

		private readonly ConfigEntry<bool> deferred;

		private readonly ConfigEntry<float> speed;

		private readonly ConfigEntry<float> boost;

		private readonly ConfigEntry<float> energy;

		private readonly ConfigEntry<float> regen;

		private readonly ConfigEntry<float> recovery;

		private readonly ConfigEntry<float> lightSeconds;

		private readonly ConfigEntry<int> cap;

		private readonly ConfigEntry<bool>[] abilities = new ConfigEntry<bool>[7];

		private readonly ConfigEntry<float>[] costs = new ConfigEntry<float>[7];

		private readonly ConfigEntry<float>[] cooldowns = new ConfigEntry<float>[7];

		private readonly ConfigEntry<float>[] ranges = new ConfigEntry<float>[7];

		public readonly ConfigEntry<float> Sensitivity;

		public readonly ConfigEntry<float> HudScale;

		public readonly ConfigEntry<float> HudOpacity;

		public readonly ConfigEntry<float> Effects;

		public readonly ConfigEntry<bool> Debug;

		public readonly ConfigEntry<bool> GhostVoice;

		public readonly ConfigEntry<int> PositionRate;

		public readonly ConfigEntry<string> Language;

		public readonly ConfigEntry<string> ThrowCarriedItem;

		public readonly ConfigEntry<string> ActivateCarriedItem;

		public readonly ConfigEntry<string>[] Bindings = new ConfigEntry<string>[7];

		public readonly ConfigEntry<Key> Toggle;

		public readonly ConfigEntry<Key> Forward;

		public readonly ConfigEntry<Key> Back;

		public readonly ConfigEntry<Key> Left;

		public readonly ConfigEntry<Key> Right;

		public readonly ConfigEntry<Key> Sprint;

		public readonly ConfigEntry<Key> Preset;

		public readonly ConfigEntry<Key> Custom;

		public readonly ConfigEntry<Key> NightVision;

		public readonly ConfigEntry<Key> GhostVoiceKey;

		public bool Enabled => enabled.Value;

		public ModConfig(ConfigFile file)
		{
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Expected O, but got Unknown
			//IL_0335: Unknown result type (might be due to invalid IL or missing references)
			//IL_033f: Expected O, but got Unknown
			//IL_04ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0509: Expected O, but got Unknown
			//IL_052e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0538: Expected O, but got Unknown
			this.file = file;
			enabled = file.Bind<bool>("General", "EnableGhostMode", true, (ConfigDescription)null);
			requireAll = file.Bind<bool>("Compatibility", "RequireAllClients", true, (ConfigDescription)null);
			speed = Number("GhostMovement", "Speed", 7f, 1f, 22f);
			boost = Number("GhostMovement", "BoostMultiplier", 1.8f, 1f, 3f);
			energy = Number("GhostEnergy", "MaximumAndStartingEnergy", 100f, 1f, 500f);
			regen = Number("GhostEnergy", "RegenerationPerSecond", 2f, 0f, 30f);
			recovery = Number("GhostEnergy", "RecoveryDelay", 3f, 0f, 60f);
			Rule(Ability.Door, "Doors", 10f, 3f, 5f, "Interact");
			Rule(Ability.Knock, "DoorKnocking", 5f, 3f, 5f, "MouseRight");
			Rule(Ability.Light, "Lights", 15f, 60f, 8f, "F");
			Rule(Ability.Wall, "WallMessages", 20f, 60f, 8f, "T");
			Rule(Ability.Terminal, "Terminal", 30f, 30f, 5f, "Y");
			Rule(Ability.Teleport, "GhostMovement", 0f, 30f, 5f, "R", "Teleport");
			Rule(Ability.Carry, "GhostInventory", 0f, 15f, 3.5f, "Q");
			ThrowCarriedItem = file.Bind<string>("Input", "UseCarriedItem", "MouseRight", "Throw the item in the ghost inventory.");
			ActivateCarriedItem = file.Bind<string>("Input", "ActivateCarriedItem", "MouseLeft", "Use the held tool or noisemaker.");
			noise = file.Bind<bool>("DoorKnocking", "EnableEnemyNoiseReaction", true, (ConfigDescription)null);
			lightSeconds = file.Bind<float>("Lights", "Duration", 5f, new ConfigDescription("Flicker duration in seconds.", (AcceptableValueBase)(object)new AcceptableValueList<float>(new float[1] { 5f }), Array.Empty<object>()));
			customWall = file.Bind<bool>("WallMessages", "EnableCustomText", true, (ConfigDescription)null);
			customTerminal = file.Bind<bool>("Terminal", "AllowCustomTerminalMessages", false, (ConfigDescription)null);
			contracts = file.Bind<bool>("Contracts", "EnableContracts", true, (ConfigDescription)null);
			cap = file.Bind<int>("Economy", "MaxRewardPerRound", 100, new ConfigDescription("Team credits per round.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10000), Array.Empty<object>()));
			deferred = file.Bind<bool>("Economy", "RewardAtRoundEnd", true, (ConfigDescription)null);
			Toggle = KeyBind("Toggle", (Key)21);
			NightVision = KeyBind("NightVision", (Key)28);
			GhostVoiceKey = KeyBind("GhostVoice", (Key)36);
			GhostVoice = file.Bind<bool>("GhostVoice", "EnableRandomWindows", false, "Allow the living to hear you only while holding the ghost voice key during a window.");
			Forward = KeyBind("Forward", (Key)37);
			Back = KeyBind("Backward", (Key)33);
			Left = KeyBind("Left", (Key)15);
			Right = KeyBind("Right", (Key)18);
			Sprint = KeyBind("Sprint", (Key)51);
			Preset = KeyBind("NextPreset", (Key)3);
			Custom = KeyBind("ComposeModifier", (Key)53);
			Sensitivity = Number("Input", "MouseSensitivity", 0.13f, 0.01f, 1f);
			HudScale = Number("HUD", "Scale", 1f, 0.65f, 1.55f);
			HudOpacity = Number("HUD", "Opacity", 0.92f, 0.2f, 1f);
			Effects = Number("HUD", "EffectIntensity", 1f, 0f, 1f);
			Language = file.Bind<string>("Localization", "Language", "en", new ConfigDescription("UI language.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[2] { "en", "ru" }), Array.Empty<object>()));
			PositionRate = file.Bind<int>("Networking", "LocalPositionRate", 10, new ConfigDescription("Maximum outbound movement samples per second.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(5, 10), Array.Empty<object>()));
			Debug = file.Bind<bool>("Debug", "EnableDebugLogging", false, (ConfigDescription)null);
		}

		private ConfigEntry<Key> KeyBind(string name, Key key)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			return file.Bind<Key>("Input", name, key, (ConfigDescription)null);
		}

		private ConfigEntry<float> Number(string section, string name, float value, float min, float max)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			return file.Bind<float>(section, name, value, new ConfigDescription(name, (AcceptableValueBase)(object)new AcceptableValueRange<float>(min, max), Array.Empty<object>()));
		}

		private void Rule(Ability ability, string section, float cost, float cooldown, float range, string key, string prefix = "")
		{
			int num = (int)ability;
			abilities[num] = file.Bind<bool>(section, prefix + "Enabled", true, (ConfigDescription)null);
			costs[num] = Number(section, prefix + "EnergyCost", cost, 0f, 500f);
			string name = ((ability == Ability.Carry) ? "PickupCooldown" : (prefix + "Cooldown"));
			cooldowns[num] = Number(section, name, cooldown, (ability == Ability.Wall || ability == Ability.Light) ? 60 : 0, 180f);
			ranges[num] = Number(section, prefix + "Range", range, 1f, 25f);
			if (ability != Ability.Door)
			{
				Bindings[num] = file.Bind<string>("Input", ability.ToString(), key, "Input System Key name, MouseLeft or MouseRight.");
			}
		}

		public Balance Snapshot()
		{
			Balance balance = new Balance
			{
				Enabled = enabled.Value,
				RequireAll = requireAll.Value,
				Noise = noise.Value,
				CustomWall = customWall.Value,
				CustomTerminal = customTerminal.Value,
				Contracts = contracts.Value,
				Deferred = deferred.Value,
				Speed = Balance.Clamp(speed.Value, 1f, 22f, 7f),
				Boost = Balance.Clamp(boost.Value, 1f, 3f, 1.8f),
				MaxEnergy = Balance.Clamp(energy.Value, 1f, 500f, 100f),
				Regeneration = Balance.Clamp(regen.Value, 0f, 30f, 2f),
				Recovery = Balance.Clamp(recovery.Value, 0f, 60f, 3f),
				WallSeconds = 15f,
				LightSeconds = lightSeconds.Value,
				Cap = cap.Value
			};
			for (int i = 0; i < balance.Rules.Length; i++)
			{
				balance.Rules[i] = new AbilityRule(abilities[i].Value, costs[i].Value, cooldowns[i].Value, ranges[i].Value);
			}
			return balance;
		}
	}
	internal enum GhostMode : byte
	{
		Alive,
		VanillaSpectator,
		GhostActive,
		RoundTransition,
		Disabled
	}
	internal enum Ability : byte
	{
		Door,
		Knock,
		Light,
		Wall,
		Terminal,
		Teleport,
		Carry
	}
	internal enum Failure : byte
	{
		None,
		Unavailable,
		Target,
		Energy,
		Cooldown,
		Position,
		Limit,
		Locked
	}
	internal enum ContractKind : byte
	{
		Warning,
		Containment,
		LostAndFound,
		Signal,
		Correspondence
	}
	internal enum ContractStatus : byte
	{
		Active,
		Completed,
		Failed,
		Expired,
		Rewarded
	}
	internal readonly struct AbilityRule
	{
		public readonly bool Enabled;

		public readonly float Cost;

		public readonly float Cooldown;

		public readonly float Range;

		public AbilityRule(bool enabled, float cost, float cooldown, float range)
		{
			Enabled = enabled;
			Cost = Balance.Clamp(cost, 0f, 500f, 0f);
			Cooldown = Balance.Clamp(cooldown, 0f, 180f, 3f);
			Range = Balance.Clamp(range, 1f, 25f, 5f);
		}
	}
	internal sealed class Balance
	{
		public bool Enabled;

		public bool RequireAll;

		public bool Noise;

		public bool CustomWall;

		public bool CustomTerminal;

		public bool Contracts;

		public bool Deferred;

		public float Speed;

		public float Boost;

		public float MaxEnergy;

		public float Regeneration;

		public float Recovery;

		public float WallSeconds;

		public float LightSeconds;

		public int Cap;

		public readonly AbilityRule[] Rules = new AbilityRule[7];

		public AbilityRule this[Ability ability] => Rules[(uint)ability];

		public static float Clamp(float value, float minimum, float maximum, float fallback)
		{
			if (!Finite(value))
			{
				value = fallback;
			}
			return Math.Max(minimum, Math.Min(maximum, value));
		}

		public static bool Finite(float value)
		{
			if (!float.IsNaN(value))
			{
				return !float.IsInfinity(value);
			}
			return false;
		}
	}
	internal sealed class GhostEnergy
	{
		private readonly double[] readyAt = new double[7];

		private readonly Balance rules;

		private double regenerationAt;

		private double updated;

		public float Value { get; private set; }

		public GhostEnergy(Balance rules, double now)
		{
			this.rules = rules;
			Value = rules.MaxEnergy;
			updated = now;
		}

		public void Advance(double now)
		{
			if (!(now <= updated))
			{
				Value = Math.Min(rules.MaxEnergy, Value + (float)Math.Max(0.0, now - Math.Max(updated, regenerationAt)) * rules.Regeneration);
				updated = now;
			}
		}

		public Failure Check(Ability ability, double now)
		{
			Advance(now);
			AbilityRule abilityRule = rules[ability];
			if (!abilityRule.Enabled)
			{
				return Failure.Unavailable;
			}
			if (readyAt[(uint)ability] > now)
			{
				return Failure.Cooldown;
			}
			if (!(Value < abilityRule.Cost))
			{
				return Failure.None;
			}
			return Failure.Energy;
		}

		public void Commit(Ability ability, double now)
		{
			AbilityRule abilityRule = rules[ability];
			Value -= abilityRule.Cost;
			readyAt[(uint)ability] = now + (double)abilityRule.Cooldown;
			if (abilityRule.Cost > 0f)
			{
				regenerationAt = now + (double)rules.Recovery;
			}
		}

		public void StartCooldown(Ability ability, double now)
		{
			readyAt[(uint)ability] = now + (double)rules[ability].Cooldown;
		}

		public float Remaining(Ability ability, double now)
		{
			return (float)Math.Max(0.0, readyAt[(uint)ability] - now);
		}
	}
	internal static class GhostState
	{
		public static GhostMode Resolve(bool dead, bool playing, bool ready, bool active)
		{
			if (!dead)
			{
				return GhostMode.Alive;
			}
			if (!playing)
			{
				return GhostMode.RoundTransition;
			}
			if (!ready)
			{
				return GhostMode.Disabled;
			}
			if (!active)
			{
				return GhostMode.VanillaSpectator;
			}
			return GhostMode.GhostActive;
		}
	}
	internal sealed class Contract
	{
		public readonly uint Id;

		public readonly uint Round;

		public readonly ContractKind Kind;

		public readonly ushort Reward;

		public ContractStatus Status;

		public ushort Award;

		public ulong? MarkedItem;

		public ulong? Recipient;

		public int Progress
		{
			get
			{
				if (Status != ContractStatus.Active)
				{
					if (Status != ContractStatus.Completed && Status != ContractStatus.Rewarded)
					{
						return 0;
					}
					return Target;
				}
				if (!MarkedItem.HasValue && !Recipient.HasValue)
				{
					return 0;
				}
				return 1;
			}
		}

		public int Target
		{
			get
			{
				if (Kind != ContractKind.LostAndFound && Kind != ContractKind.Correspondence)
				{
					return 1;
				}
				return 2;
			}
		}

		public Contract(uint id, uint round, ContractKind kind)
		{
			Id = id;
			Round = round;
			Kind = kind;
			int num;
			switch (kind)
			{
			default:
				num = 10;
				break;
			case ContractKind.Containment:
			case ContractKind.LostAndFound:
				num = 20;
				break;
			case ContractKind.Warning:
				num = 15;
				break;
			}
			Reward = (ushort)num;
		}
	}
	internal sealed class RewardLedger
	{
		private readonly HashSet<uint> reserved = new HashSet<uint>();

		public int Total { get; private set; }

		public int Reserve(Contract contract, int cap)
		{
			if (contract.Status != ContractStatus.Completed || !reserved.Add(contract.Id))
			{
				return 0;
			}
			int num = Math.Max(0, Math.Min(contract.Reward, cap - Total));
			Total += num;
			return num;
		}

		public void Reset()
		{
			reserved.Clear();
			Total = 0;
		}
	}
	internal sealed class RoundLifecycle
	{
		private readonly ManualLogSource log;

		private readonly GhostController ghost;

		private readonly GhostAbilities abilities;

		public RoundLifecycle(ModConfig config, ManualLogSource log)
		{
			this.log = log;
			ghost = new GhostController(config, log);
			abilities = new GhostAbilities(config, log, ghost);
		}

		public void CaptureGhostAppearance(PlayerControllerB player)
		{
			try
			{
				abilities.CaptureAppearance(player);
			}
			catch (Exception ex)
			{
				log.LogDebug((object)("Could not snapshot the player model: " + ex.Message));
			}
		}

		public bool ControlsGhost(PlayerControllerB player)
		{
			return ghost.Controls(player);
		}

		public bool UsesGhostMenuKey(PlayerControllerB player, Key key)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			if (ghost.Controls(player))
			{
				if (!abilities.WallUiOpen)
				{
					if (abilities.IsPresetKey(key))
					{
						return ghost.CanUseInput(player);
					}
					return false;
				}
				return true;
			}
			return false;
		}

		public void Tick()
		{
			abilities.Tick();
		}

		public void LateTick()
		{
			abilities.UpdateLampLights();
		}

		public void Dispose()
		{
			StopGhost();
			abilities.Dispose();
		}

		public void UpdateGhost(PlayerControllerB player)
		{
			GameNetworkManager instance = GameNetworkManager.Instance;
			if (!Object.op_Implicit((Object)(object)instance) || (Object)(object)instance.localPlayerController != (Object)(object)player)
			{
				return;
			}
			try
			{
				ghost.Tick(player, !abilities.WallUiOpen, abilities.LocalConfirmed);
				abilities.UpdateLocal(player);
			}
			catch (Exception arg)
			{
				log.LogError((object)$"Ghost Mode stopped after an error: {arg}");
				StopGhost();
			}
		}

		public void StopGhost()
		{
			try
			{
				ghost.Stop();
				abilities.ExitLocal();
			}
			catch (Exception arg)
			{
				log.LogError((object)$"Ghost Mode could not restore the player completely: {arg}");
			}
		}

		public void GameInitialized(GameNetworkManager game)
		{
			if ((Object)(object)GameNetworkManager.Instance == (Object)(object)game)
			{
				log.LogInfo((object)$"Lethal Company v{game.gameVersionNum} detected.");
			}
		}

		public void PlayerDied(PlayerControllerB player, bool wasDead, CauseOfDeath cause, bool insideFactory)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			GameNetworkManager instance = GameNetworkManager.Instance;
			if (Object.op_Implicit((Object)(object)instance) && (Object)(object)instance.localPlayerController == (Object)(object)player && !wasDead && player.isPlayerDead)
			{
				ghost.RecordDeath(cause, insideFactory);
				log.LogInfo((object)"Local player died.");
			}
		}

		public void PlayerRevived(PlayerControllerB player, bool wasDead)
		{
			if (wasDead && Object.op_Implicit((Object)(object)player) && !player.isPlayerDead)
			{
				log.LogInfo((object)"Local player returned to life.");
			}
		}
	}
	internal static class AbilityWorld
	{
		private static readonly int InteractableLayers = LayerMask.GetMask(new string[5] { "InteractableObject", "Props", "PhysicsObject", "Railing", "MapHazards" });

		private static readonly FieldRef<DoorLock, NavMeshObstacle> NavMesh = AccessTools.FieldRefAccess<DoorLock, NavMeshObstacle>("navMeshObstacle");

		private static readonly FieldRef<DoorLock, bool> DoorOpened = AccessTools.FieldRefAccess<DoorLock, bool>("isDoorOpened");

		private static readonly Action<AnimatedObjectTrigger, bool, bool, int> AnimateDoor = AccessTools.MethodDelegate<Action<AnimatedObjectTrigger, bool, bool, int>>(AccessTools.Method(typeof(AnimatedObjectTrigger), "UpdateAnimClientRpc", new Type[3]
		{
			typeof(bool),
			typeof(bool),
			typeof(int)
		}, (Type[])null), (object)null, true);

		public static bool Aim(StartOfRound round, Vector3 origin, Vector3 direction, float range, out RaycastHit hit, bool includeTraversal = false)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			int num = GhostMotor.CollisionMask(round) | InteractableLayers;
			RaycastHit[] array = Physics.RaycastAll(origin, direction, range, num, (QueryTriggerInteraction)2);
			hit = default(RaycastHit);
			float num2 = float.PositiveInfinity;
			RaycastHit[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				RaycastHit val = array2[i];
				Collider collider = ((RaycastHit)(ref val)).collider;
				if (Object.op_Implicit((Object)(object)collider) && !(((RaycastHit)(ref val)).distance >= num2) && (!collider.isTrigger || IsHazard(collider) || Object.op_Implicit((Object)(object)FindDoor(collider)) || Object.op_Implicit((Object)(object)((Component)collider).GetComponentInParent<GrabbableObject>()) || (includeTraversal && (Object.op_Implicit((Object)(object)((Component)collider).GetComponentInParent<EntranceTeleport>()) || Object.op_Implicit((Object)(object)FindLadder(collider)) || GhostElevator.IsButton(collider) || GhostShipControls.IsButton(round, collider)))))
				{
					hit = val;
					num2 = ((RaycastHit)(ref val)).distance;
				}
			}
			return Object.op_Implicit((Object)(object)((RaycastHit)(ref hit)).collider);
		}

		public static InteractTrigger FindLadder(Collider target)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)target))
			{
				return null;
			}
			InteractTrigger componentInParent = ((Component)target).GetComponentInParent<InteractTrigger>();
			if (Object.op_Implicit((Object)(object)componentInParent))
			{
				if (!componentInParent.isLadder)
				{
					return null;
				}
				return componentInParent;
			}
			Transform parent = ((Component)target).transform.parent;
			if (Object.op_Implicit((Object)(object)parent))
			{
				InteractTrigger val = default(InteractTrigger);
				foreach (Transform item in parent)
				{
					if (((Component)item).TryGetComponent<InteractTrigger>(ref val) && val.isLadder)
					{
						return val;
					}
				}
			}
			return null;
		}

		public static DoorLock FindDoor(Collider target)
		{
			DoorLock componentInParent = ((Component)target).GetComponentInParent<DoorLock>();
			if (Object.op_Implicit((Object)(object)componentInParent))
			{
				return componentInParent;
			}
			InteractTrigger componentInParent2 = ((Component)target).GetComponentInParent<InteractTrigger>();
			if (!Object.op_Implicit((Object)(object)componentInParent2) || componentInParent2.onInteract == null)
			{
				return null;
			}
			for (int i = 0; i < ((UnityEventBase)componentInParent2.onInteract).GetPersistentEventCount(); i++)
			{
				Object persistentTarget = ((UnityEventBase)componentInParent2.onInteract).GetPersistentTarget(i);
				DoorLock val = (DoorLock)(object)((persistentTarget is DoorLock) ? persistentTarget : null);
				if (val != null && ((Object)(object)val.doorTrigger == (Object)(object)componentInParent2 || (Object)(object)val.doorTriggerB == (Object)(object)componentInParent2))
				{
					return val;
				}
			}
			return null;
		}

		public static bool ToggleDoor(Collider target)
		{
			if (!Object.op_Implicit((Object)(object)target) || IsHazard(target))
			{
				return false;
			}
			DoorLock val = FindDoor(target);
			if (!Object.op_Implicit((Object)(object)val) || !((NetworkBehaviour)val).IsSpawned || IsDoorLocked(val))
			{
				return false;
			}
			AnimatedObjectTrigger val2 = default(AnimatedObjectTrigger);
			if (!((Component)val).TryGetComponent<AnimatedObjectTrigger>(ref val2) || !((NetworkBehaviour)val2).IsSpawned || !val2.isBool || !Object.op_Implicit((Object)(object)val2.triggerAnimator) || val2.onTriggerBool == null)
			{
				return false;
			}
			bool flag = (val2.boolValue = !val2.boolValue);
			val2.triggerAnimator.SetBool(val2.animationString, flag);
			if (Object.op_Implicit((Object)(object)NavMesh.Invoke(val)) && Object.op_Implicit((Object)(object)val.doorTrigger))
			{
				val.SetDoorAsOpen(flag);
			}
			else
			{
				DoorOpened.Invoke(val) = flag;
			}
			AnimateDoor(val2, flag, arg3: false, -1);
			return true;
		}

		public static bool IsDoorLocked(DoorLock door)
		{
			if (Object.op_Implicit((Object)(object)door))
			{
				if (!door.isLocked && !door.isPickingLock)
				{
					if (Object.op_Implicit((Object)(object)door.twinDoor))
					{
						if (!door.twinDoor.isLocked)
						{
							return door.twinDoor.isPickingLock;
						}
						return true;
					}
					return false;
				}
				return true;
			}
			return false;
		}

		public static bool IsDoorOpen(DoorLock door)
		{
			AnimatedObjectTrigger val = default(AnimatedObjectTrigger);
			if (Object.op_Implicit((Object)(object)door) && ((Component)door).TryGetComponent<AnimatedObjectTrigger>(ref val))
			{
				return val.boolValue;
			}
			return false;
		}

		public static bool AimWall(StartOfRound round, Vector3 eye, Vector3 direction, float range, out RaycastHit hit)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			if (!Physics.Raycast(eye, direction, ref hit, range, GhostMotor.CollisionMask(round), (QueryTriggerInteraction)1))
			{
				return false;
			}
			Collider collider = ((RaycastHit)(ref hit)).collider;
			if (Mathf.Abs(((RaycastHit)(ref hit)).normal.y) <= 0.35f && (!Object.op_Implicit((Object)(object)collider.attachedRigidbody) || collider.attachedRigidbody.isKinematic) && !IsHazard(collider) && !Object.op_Implicit((Object)(object)FindDoor(collider)) && !Object.op_Implicit((Object)(object)((Component)collider).GetComponentInParent<EntranceTeleport>()))
			{
				return !Object.op_Implicit((Object)(object)((Component)collider).GetComponentInParent<GrabbableObject>());
			}
			return false;
		}

		private static bool IsHazard(Collider collider)
		{
			if (!Object.op_Implicit((Object)(object)((Component)collider).GetComponentInParent<Landmine>()))
			{
				return Object.op_Implicit((Object)(object)((Component)collider).GetComponentInParent<Turret>());
			}
			return true;
		}

		internal static void SetItemPosition(GrabbableObject item, Vector3 destination, bool sync = true)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			((Component)item).transform.position = destination;
			item.startFallingPosition = ((Component)item).transform.localPosition;
			item.targetFloorPosition = ((Component)item).transform.localPosition;
			item.fallTime = 1f;
			item.hasHitGround = true;
			item.reachedFloorTarget = true;
			if (sync)
			{
				Physics.SyncTransforms();
			}
		}
	}
	internal static class BloodLettering
	{
		private static readonly Color32 FreshBlood = new Color32((byte)174, (byte)25, (byte)35, byte.MaxValue);

		private static readonly Color32 DarkBlood = new Color32((byte)92, (byte)7, (byte)14, byte.MaxValue);

		public static void Apply(TextMeshPro text, uint seed)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_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_0068: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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)
			((TMP_Text)text).fontStyle = (FontStyles)1;
			((Graphic)text).color = Color.white;
			((TMP_Text)text).enableVertexGradient = true;
			((TMP_Text)text).colorGradient = new VertexGradient(Color32.op_Implicit(FreshBlood), Color32.op_Implicit(new Color32((byte)135, (byte)14, (byte)25, byte.MaxValue)), Color32.op_Implicit(DarkBlood), Color32.op_Implicit(new Color32((byte)113, (byte)9, (byte)20, byte.MaxValue)));
			((TMP_Text)text).OnPreRenderText += delegate(TMP_TextInfo info)
			{
				TiltLetters(info, seed);
			};
			((TMP_Text)text).ForceMeshUpdate(false, false);
			bool flag = false;
			for (int num = 0; num < ((TMP_Text)text).textInfo.characterCount; num++)
			{
				TMP_CharacterInfo val = ((TMP_Text)text).textInfo.characterInfo[num];
				if (val.isVisible && (!flag || (num + seed) % 3 == 0L))
				{
					AddDrip(text, val, num, seed);
					flag = true;
				}
			}
		}

		private static void TiltLetters(TMP_TextInfo info, uint seed)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: 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_00b9: 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_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_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < info.characterCount; i++)
			{
				TMP_CharacterInfo val = info.characterInfo[i];
				if (val.isVisible)
				{
					Vector3[] vertices = info.meshInfo[val.materialReferenceIndex].vertices;
					int vertexIndex = val.vertexIndex;
					Vector3 val2 = (vertices[vertexIndex] + vertices[vertexIndex + 2]) * 0.5f;
					float num = ((float)((i + seed) % 7) - 3f) * 1.2f;
					Quaternion val3 = Quaternion.Euler(0f, 0f, num);
					float num2 = ((float)((i * 3 + seed) % 5) - 2f) * 0.003f;
					for (int j = 0; j < 4; j++)
					{
						vertices[vertexIndex + j] = val2 + val3 * (vertices[vertexIndex + j] - val2) + Vector3.up * num2;
					}
				}
			}
		}

		private static void AddDrip(TextMeshPro lettering, TMP_CharacterInfo letter, int index, uint seed)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: 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_00f2: 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_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: 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_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Blood drip");
			val.transform.SetParent(lettering.transform, false);
			float num = 0.35f + (float)((index * 7 + seed) % 6) * 0.11f;
			Vector3 val2 = Vector3.Lerp(letter.bottomLeft, letter.bottomRight, 0.42f);
			val.transform.localPosition = val2 + new Vector3(0f, -0.04f * num, -0.001f);
			val.transform.localScale = new Vector3(0.23f, num, 1f);
			TextMeshPro obj = val.AddComponent<TextMeshPro>();
			((TMP_Text)obj).font = ((TMP_Text)lettering).font;
			((TMP_Text)obj).text = "|";
			((TMP_Text)obj).fontStyle = (FontStyles)1;
			((TMP_Text)obj).alignment = (TextAlignmentOptions)514;
			((TMP_Text)obj).fontSize = 0.95f;
			((TMP_Text)obj).rectTransform.sizeDelta = new Vector2(0.2f, 0.16f);
			((Graphic)obj).color = Color.white;
			((TMP_Text)obj).enableVertexGradient = true;
			((TMP_Text)obj).colorGradient = new VertexGradient(Color32.op_Implicit(FreshBlood), Color32.op_Implicit(FreshBlood), Color32.op_Implicit(DarkBlood), Color32.op_Implicit(DarkBlood));
		}
	}
	internal sealed class GhostAbilities : IDisposable
	{
		private sealed class GhostPeer
		{
			public readonly GhostEnergy Energy;

			public PlayerControllerB Player;

			public bool Active;

			public uint Generation;

			public uint LastPose;

			public uint LastAction;

			public uint PresenceRevision;

			public uint CarryPoseRevision;

			public Vector3 Position;

			public float Heading;

			public double Updated;

			public double NextEntrance;

			public double NextCorrection;

			public double NextReveal;

			public double RevealUntil;

			public double NextVoiceWindow;

			public double VoiceWindowUntil;

			public bool AllowsVoice;

			public bool VoiceRelaying;

			public bool SpawnedFromPit;

			public GhostElevator.CabinAnchor Platform;

			public GhostPeer(GhostEnergy energy)
			{
				Energy = energy;
			}

			public bool IsCurrent(ulong id)
			{
				if (Active && Object.op_Implicit((Object)(object)Player) && ((NetworkBehaviour)Player).IsSpawned && Player.isPlayerDead)
				{
					return Player.actualClientId == id;
				}
				return false;
			}
		}

		private const float MaxEyeHeight = 2.8f;

		private const double RevealInterval = 120.0;

		private const double FirstRevealDelay = 3.0;

		private const double RevealLength = 1.5;

		private const double VoiceWindowLength = 4.0;

		private readonly ModConfig config;

		private readonly GhostHud hud = new GhostHud();

		private readonly ManualLogSource log;

		private readonly NetworkHandler network;

		private readonly WallMessages walls = new WallMessages();

		private readonly GhostCarry carry = new GhostCarry();

		private readonly GhostVoice voice = new GhostVoice();

		private readonly Random voiceRandom = new Random();

		private readonly GhostLampFlicker lamps = new GhostLampFlicker();

		private readonly GhostSilhouettes silhouettes = new GhostSilhouettes();

		private readonly WallWriting writer = new WallWriting();

		private readonly WallWheel wheel = new WallWheel();

		private readonly GhostController ghost;

		private readonly Dictionary<ulong, GhostPeer> ghosts = new Dictionary<ulong, GhostPeer>();

		private StartOfRound round;

		private Balance rules;

		private bool playing;

		private bool serverPlaying;

		private bool allReady;

		private bool advertised;

		private uint epoch;

		private uint generation;

		private uint localGhost;

		private uint poseSequence;

		private uint actionSequence;

		private uint presenceRevision;

		private double nextPose;

		private double nextNotice;

		private double nextRegistration;

		private double nextHint;

		private double localVoiceUntil;

		private double feedbackUntil;

		private string feedback;

		private double pickupReadyAt;

		private bool localConfirmed;

		private bool correctionWasFromPit;

		private Vector3? correction;

		private bool voiceKeyWasHeld;

		private byte preset;

		private Packet pendingEntrance;

		public bool LocalConfirmed => localConfirmed;

		public bool WallUiOpen
		{
			get
			{
				if (!writer.Opened)
				{
					return wheel.Opened;
				}
				return true;
			}
		}

		public GhostAbilities(ModConfig config, ManualLogSource log, GhostController ghost)
		{
			this.config = config;
			this.log = log;
			this.ghost = ghost;
			network = new NetworkHandler(this);
		}

		public void CaptureAppearance(PlayerControllerB player)
		{
			if (playing && config.Enabled)
			{
				silhouettes.Capture(player);
			}
		}

		public void UpdateLampLights()
		{
			double serverTime = network.ServerTime;
			lamps.Tick(serverTime);
			carry.Tick(serverTime);
			voice.Tick(serverTime);
		}

		public bool IsPresetKey(Key key)
		{
			//IL_0000: 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)
			return key == config.Preset.Value;
		}

		public void Tick()
		{
			network.Tick();
			StartOfRound instance = StartOfRound.Instance;
			bool flag = Object.op_Implicit((Object)(object)instance) && instance.shipHasLanded && !instance.inShipPhase && !instance.allPlayersDead && !instance.newGameIsLoading;
			if ((Object)(object)round != (Object)(object)instance || flag != playing)
			{
				round = instance;
				playing = flag;
				ClearRound();
				advertised = false;
			}
			if (network.Server)
			{
				if (!advertised)
				{
					epoch++;
					if (epoch == 0)
					{
						epoch++;
					}
					rules = config.Snapshot();
					serverPlaying = playing;
					allReady = network.AllReady;
					advertised = true;
					network.Broadcast(RoundStatus());
				}
				else if (allReady != network.AllReady)
				{
					allReady = network.AllReady;
					network.Broadcast(RoundStatus());
				}
				foreach (KeyValuePair<ulong, GhostPeer> ghost in ghosts)
				{
					GhostPeer value = ghost.Value;
					if (!value.IsCurrent(ghost.Key))
					{
						Retire(ghost.Key, value);
					}
					else
					{
						UpdateTimedEffects(ghost.Key, value);
					}
				}
			}
			if (CanSeeGhosts() || LocalAlive())
			{
				silhouettes.Tick(network.ServerTime);
			}
			else
			{
				silhouettes.Clear();
			}
			walls.Expire(network.ServerTime);
		}

		public void UpdateLocal(PlayerControllerB player)
		{
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_034c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0487: Unknown result type (might be due to invalid IL or missing references)
			//IL_048c: Unknown result type (might be due to invalid IL or missing references)
			//IL_049f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a6: Unknown result type (might be due to invalid IL or missing references)
			if (!ghost.Controls(player))
			{
				ExitLocal();
				return;
			}
			bool flag = config.Language.Value == "ru";
			if (!playing || !serverPlaying || rules == null || !network.HostAcknowledged)
			{
				ExitLocal();
				if (ghost.CanUseInput(player))
				{
					ShowHint(flag ? "Подключение к хосту…" : "Waiting for a compatible host…");
				}
				return;
			}
			if (localGhost == 0)
			{
				localGhost = ++generation;
				nextRegistration = 0.0;
				nextPose = 0.0;
			}
			double unscaledTimeAsDouble = Time.unscaledTimeAsDouble;
			if (!localConfirmed && unscaledTimeAsDouble >= nextRegistration)
			{
				nextRegistration = unscaledTimeAsDouble + 0.9;
				network.ToHost(new Packet
				{
					Type = Message.Toggle,
					Round = epoch,
					Flag = true,
					Ready = config.GhostVoice.Value,
					Number = localGhost,
					Position = GhostWorld.PointOf(ghost.EntryPosition),
					Direction = GhostWorld.PointOf(GhostMotor.DeathPosition(player)),
					Value = ghost.Heading
				});
			}
			if (!localConfirmed)
			{
				if (ghost.CanUseInput(player))
				{
					ShowHint((unscaledTimeAsDouble < feedbackUntil) ? feedback : (flag ? "Хост проверяет появление призрака…" : "Waiting for ghost spawn confirmation…"));
				}
				else
				{
					hud.Hide();
				}
				return;
			}
			if (correction.HasValue)
			{
				ghost.SynchronizePosition(correction.Value, correctionWasFromPit);
				correction = null;
				nextPose = 0.0;
			}
			if (pendingEntrance != null)
			{
				ghost.PassEntrance(pendingEntrance);
				pendingEntrance = null;
				nextPose = 0.0;
			}
			bool flag2 = VoiceHeld(player);
			if (unscaledTimeAsDouble >= nextPose || flag2 != voiceKeyWasHeld)
			{
				nextPose = unscaledTimeAsDouble + 1.0 / (double)config.PositionRate.Value;
				SendPose(player, flag2 == voiceKeyWasHeld);
				voiceKeyWasHeld = flag2;
			}
			if (!ghost.CanUseInput(player))
			{
				writer.Close();
				wheel.Close();
				hud.Hide();
				return;
			}
			if (WallUiOpen)
			{
				hud.Hide();
			}
			else if (unscaledTimeAsDouble >= nextHint)
			{
				nextHint = unscaledTimeAsDouble + 0.1;
				UpdateHint(player, flag, unscaledTimeAsDouble);
			}
			if (writer.Opened)
			{
				if (writer.Tick(out var submitted))
				{
					SendAction(player, Ability.Wall, submitted, 0);
				}
				return;
			}
			if (wheel.Opened)
			{
				if (wheel.Tick(ref preset))
				{
					SendAction(player, Ability.Wall, string.Empty, 0);
				}
				return;
			}
			if (KeyPressed(config.Preset.Value))
			{
				preset = (byte)((preset + 1) % WallMessages.Presets.Length);
				Notify("Wall message: " + WallMessages.Presets[preset]);
			}
			if (flag2)
			{
				return;
			}
			if (carry.CanUseItem(network.LocalId) && BindingPressed(config.ActivateCarriedItem.Value))
			{
				SendAction(player, Ability.Carry, string.Empty, 2);
				return;
			}
			if (carry.HasItem(network.LocalId) && BindingPressed(config.ThrowCarriedItem.Value))
			{
				SendAction(player, Ability.Carry, string.Empty, 1);
				return;
			}
			if (BindingPressed(config.Bindings[6].Value))
			{
				SendAction(player, Ability.Carry, string.Empty, 0);
				return;
			}
			ButtonControl val = Binding(config.Bindings[3].Value);
			if (val != null && val.wasPressedThisFrame)
			{
				OpenWallUi(val);
			}
			else
			{
				if (ghost.UsedLadderThisFrame)
				{
					return;
				}
				Transform transform = ((Component)player.gameplayCamera).transform;
				if (player.playerActions != null)
				{
					MovementActions movement = player.playerActions.Movement;
					if (((MovementActions)(ref movement)).Interact.WasPressedThisFrame() && AimDoor(transform.position, transform.forward, out var _, out var _))
					{
						SendAction(player, Ability.Door, string.Empty, 0);
						return;
					}
				}
				if (BindingPressed(config.Bindings[2].Value))
				{
					SendAction(player, Ability.Light, string.Empty, 0);
				}
			}
		}

		private bool AimDoor(Vector3 eye, Vector3 direction, out EntranceTeleport entrance, out RaycastHit hit)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			float range = rules[Ability.Door].Range;
			entrance = null;
			if (AbilityWorld.Aim(round, eye, direction, range, out hit, includeTraversal: true))
			{
				entrance = ((Component)((RaycastHit)(ref hit)).collider).GetComponentInParent<EntranceTeleport>();
				if (Object.op_Implicit((Object)(object)entrance) || Object.op_Implicit((Object)(object)AbilityWorld.FindDoor(((RaycastHit)(ref hit)).collider)) || GhostElevator.IsButton(((RaycastHit)(ref hit)).collider) || GhostShipControls.IsButton(round, ((RaycastHit)(ref hit)).collider))
				{
					return true;
				}
			}
			entrance = GhostEntrance.FindTarget(round, eye, direction, range);
			return Object.op_Implicit((Object)(object)entrance);
		}

		private void UpdateHint(PlayerControllerB player, bool ru, double now)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: 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_0352: Unknown result type (might be due to invalid IL or missing references)
			//IL_0358: 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)
			Transform transform = ((Component)player.gameplayCamera).transform;
			string text = "";
			RaycastHit hit2;
			if (AimDoor(transform.position, transform.forward, out var entrance, out var hit))
			{
				DoorLock val = ((!Object.op_Implicit((Object)(object)entrance)) ? AbilityWorld.FindDoor(((RaycastHit)(ref hit)).collider) : null);
				string text2 = GhostHud.InteractLabel(player);
				if (AbilityWorld.IsDoorLocked(val))
				{
					text = (ru ? "Дверь заперта" : "Door locked");
				}
				else if (HasRule(Ability.Door))
				{
					text = text2 + "  " + ((!Object.op_Implicit((Object)(object)entrance)) ? ((!Object.op_Implicit((Object)(object)val)) ? (ru ? "Использовать" : "Use") : ((!AbilityWorld.IsDoorOpen(val)) ? (ru ? "Открыть" : "Open") : (ru ? "Закрыть" : "Close"))) : (ru ? "Пройти" : "Enter / exit"));
				}
			}
			else if (Object.op_Implicit((Object)(object)((RaycastHit)(ref hit)).collider) && ((RaycastHit)(ref hit)).distance <= 3f && Object.op_Implicit((Object)(object)AbilityWorld.FindLadder(((RaycastHit)(ref hit)).collider)))
			{
				text = GhostHud.InteractLabel(player) + "  " + (ru ? "Лестница" : "Use ladder");
			}
			else if (HasRule(Ability.Carry) && !carry.HasItem(network.LocalId) && AbilityWorld.Aim(round, transform.position, transform.forward, rules[Ability.Carry].Range, out hit2) && GhostCarry.CanTake(((RaycastHit)(ref hit2)).collider))
			{
				text = KeyFor(Ability.Carry) + "  " + (ru ? "Подобрать" : "Pick up");
				if (now < pickupReadyAt)
				{
					text += $" ({Math.Ceiling(pickupReadyAt - now)}s)";
				}
			}
			RaycastHit hit3;
			if (carry.HasItem(network.LocalId))
			{
				string text3 = KeyFor(Ability.Carry) + "  " + (ru ? "Бросить вниз" : "Drop") + "    " + GhostHud.BindingLabel(config.ThrowCarriedItem.Value) + "  " + (ru ? "Кинуть" : "Throw") + "   " + $"{Mathf.CeilToInt((float)carry.Remaining(network.LocalId, network.ServerTime))}s";
				if (carry.CanUseItem(network.LocalId))
				{
					text3 = text3 + "    " + GhostHud.BindingLabel(config.ActivateCarriedItem.Value) + "  " + (ru ? "Использовать" : "Use item");
				}
				text = ((text.Length == 0) ? text3 : (text + "\n" + text3));
			}
			else if (text.Length == 0 && HasRule(Ability.Wall) && AbilityWorld.AimWall(round, transform.position, transform.forward, rules[Ability.Wall].Range, out hit3))
			{
				text = KeyFor(Ability.Wall) + "  " + (ru ? "Надписи" : "Wall messages");
				if (rules.CustomWall)
				{
					text = text + $"    {config.Custom.Value}+{KeyFor(Ability.Wall)}  " + (ru ? "Свой текст" : "Custom text");
				}
			}
			if (!allReady && rules.RequireAll)
			{
				text = (ru ? "Ожидание совместимой версии у игроков" : "Waiting for compatible players");
			}
			if (now < feedbackUntil && !string.IsNullOrEmpty(feedback))
			{
				text = ((text.Length == 0) ? feedback : (text + "\n" + feedback));
			}
			ShowHint(text);
			bool HasRule(Ability type)
			{
				if (rules[type].Enabled)
				{
					if (!allReady)
					{
						if (!rules.RequireAll)
						{
							return type == Ability.Door;
						}
						return false;
					}
					return true;
				}
				return false;
			}
			string KeyFor(Ability type)
			{
				return GhostHud.BindingLabel(config.Bindings[(uint)type].Value);
			}
		}

		private void ShowHint(string text)
		{
			hud.Show(text, config.HudScale.Value, config.HudOpacity.Value, config.Language.Value == "ru");
		}

		private void OpenWallUi(ButtonControl button)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Invalid comparison between Unknown and I4
			if (!allReady || rules == null || !rules[Ability.Wall].Enabled)
			{
				Notify("Wall messages are unavailable in this lobby.");
			}
			else if (KeyHeld(config.Custom.Value) || ((int)config.Custom.Value == 53 && KeyHeld((Key)54)))
			{
				if (!rules.CustomWall)
				{
					Notify("Custom wall text is disabled by the host.");
				}
				else if (!writer.Open())
				{
					Notify("The wall editor is unavailable.");
				}
			}
			else if (!wheel.Open(button, preset))
			{
				Notify("The wall message wheel is unavailable.");
			}
		}

		private bool VoiceHeld(PlayerControllerB player)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			if (config.GhostVoice.Value && localVoiceUntil > network.ServerTime && !WallUiOpen && ghost.CanUseInput(player))
			{
				return KeyHeld(config.GhostVoiceKey.Value);
			}
			return false;
		}

		private void SendPose(PlayerControllerB player, bool sequenced)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			network.ToHost(new Packet
			{
				Type = Message.GhostPositionUpdate,
				Round = epoch,
				Number = localGhost,
				Motion = ++poseSequence,
				Position = GhostWorld.PointOf(((Component)player.thisController).transform.position),
				Value = ghost.Heading,
				Flag = VoiceHeld(player)
			}, sequenced);
		}

		private void SendAction(PlayerControllerB player, Ability ability, string text, byte doorMode = 0)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			SendPose(player, sequenced: false);
			Transform transform = ((Component)player.gameplayCamera).transform;
			network.ToHost(new Packet
			{
				Type = Message.InteractionRequest,
				Round = epoch,
				Number = localGhost,
				Motion = ++actionSequence,
				Ability = ability,
				Target = poseSequence,
				Position = GhostWorld.PointOf(transform.position),
				Direction = GhostWorld.PointOf(transform.forward),
				Preset = ((ability == Ability.Wall) ? preset : doorMode),
				Text = text
			});
		}

		public void ExitLocal()
		{
			writer.Close();
			wheel.Close();
			hud.Hide();
			uint num = localGhost;
			localGhost = 0u;
			localConfirmed = false;
			correction = null;
			feedbackUntil = 0.0;
			localVoiceUntil = 0.0;
			voiceKeyWasHeld = false;
			pendingEntrance = null;
			if (num != 0)
			{
				silhouettes.Clear();
				network.ToHost(new Packet
				{
					Type = Message.Toggle,
					Round = epoch,
					Number = num
				});
			}
		}

		public void ReceiveFromClient(ulong sender, Packet message)
		{
			if (!network.Server || !playing || !config.Enabled || message.Round != epoch)
			{
				return;
			}
			PlayerControllerB val = FindDeadPlayer(sender);
			if (Object.op_Implicit((Object)(object)val))
			{
				if (!ghosts.TryGetValue(sender, out var value))
				{
					value = new GhostPeer(new GhostEnergy(rules, Time.unscaledTimeAsDouble));
					ghosts.Add(sender, value);
				}
				switch (message.Type)
				{
				case Message.Toggle:
					UpdateMode(sender, val, value, message);
					break;
				case Message.GhostPositionUpdate:
					UpdatePose(sender, val, value, message);
					break;
				case Message.InteractionRequest:
					UseAbility(sender, value, message);
					break;
				case Message.GhostStateSync:
					break;
				}
			}
		}

		public void ReceiveFromHost(Packet message)
		{
			//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			switch (message.Type)
			{
			case Message.ConfigSync:
				if (!network.Server)
				{
					rules = message.Balance;
				}
				break;
			case Message.RoundStateSync:
				if (!network.Server && message.Round != 0 && message.Round >= epoch)
				{
					if (epoch != message.Round || serverPlaying != message.Flag)
					{
						ClearRound();
					}
					epoch = message.Round;
					serverPlaying = message.Flag;
					allReady = message.Ready;
				}
				break;
			case Message.GhostStateSync:
				if (message.Round == epoch && message.Until > 0.0 && playing && serverPlaying && LocalAlive() && (!message.Flag || message.Until > network.ServerTime))
				{
					silhouettes.Apply(message, message.Flag ? FindDeadPlayer(message.Target) : null);
				}
				else if (message.Round == epoch && message.Until == 0.0 && message.Number == localGhost && message.Target != network.LocalId && CanSeeGhosts())
				{
					silhouettes.Apply(message, message.Flag ? FindDeadPlayer(message.Target) : null);
				}
				break;
			case Message.GhostVoiceWindow:
				if (message.Round == epoch && playing && serverPlaying)
				{
					if (message.Flag && message.Target == network.LocalId && localGhost != 0 && config.GhostVoice.Value)
					{
						localVoiceUntil = message.Until;
						Notify("Voice window open. Hold " + ((object)config.GhostVoiceKey.Value/*cast due to .constrained prefix*/).ToString() + " and use your normal voice chat.");
					}
					else if (!message.Flag && LocalAlive())
					{
						voice.Apply(message);
					}
				}
				break;
			case Message.GhostModeResult:
				if (message.Round == epoch && localGhost != 0 && message.Number == localGhost && !localConfirmed)
				{
					localConfirmed = message.Flag;
					if (localConfirmed)
					{
						correction = GhostWorld.VectorOf(message.Position);
						correctionWasFromPit = message.Ready;
						nextPose = 0.0;
					}
					else
					{
						nextRegistration = Time.unscaledTimeAsDouble + 1.5;
						Feedback((config.Language.Value == "ru") ? "Хост не нашёл безопасное место появления" : "Host could not find a safe spawn");
					}
				}
				break;
			case Message.GhostPositionCorrection:
				if (message.Round == epoch && localGhost != 0 && message.Number == localGhost && localConfirmed)
				{
					correction = GhostWorld.VectorOf(message.Position);
					correctionWasFromPit = false;
				}
				break;
			case Message.GhostEntrance:
				if (message.Round == epoch && localGhost != 0 && message.Number == localGhost)
				{
					correction = null;
					pendingEntrance = message;
				}
				break;
			case Message.CooldownSync:
				if (message.Round == epoch && message.Ability == Ability.Carry)
				{
					pickupReadyAt = Time.unscaledTimeAsDouble + (double)Math.Max(0f, message.Value);
					nextHint = 0.0;
				}
				break;
			case Message.CarryPose:
				if (message.Round == epoch && playing && serverPlaying)
				{
					carry.Move(message);
				}
				break;
			case Message.InteractionResult:
				if (message.Round == epoch)
				{
					Report(message);
				}
				break;
			case Message.WorldEffect:
				if (message.Round != epoch || !playing || !serverPlaying)
				{
					break;
				}
				if (message.Ability == Ability.Wall)
				{
					walls.Show(message, network.ServerTime);
				}
				else if (message.Ability == Ability.Light)
				{
					lamps.Show(message, network.ServerTime);
				}
				else if (message.Ability == Ability.Carry)
				{
					string text = carry.Apply(message, network.ServerTime);
					if (text != null && message.Actor == network.LocalId)
					{
						Notify("Carrying " + text + " for 10 seconds.");
					}
				}
				break;
			case Message.Toggle:
			case Message.GhostPositionUpdate:
			case Message.InteractionRequest:
			case Message.EnergySync:
			case Message.ContractSync:
			case Message.ContractProgress:
			case Message.RewardNotification:
			case Message.TerminalReceipt:
				break;
			}
		}

		public void SyncPeer(ulong sender)
		{
			network.ToClient(sender, new Packet
			{
				Type = Message.ConfigSync,
				Round = epoch,
				Balance = (rules ?? config.Snapshot())
			});
			if (!advertised)
			{
				return;
			}
			network.ToClient(sender, RoundStatus());
			foreach (Packet item in walls.ActiveEffects())
			{
				network.ToClient(sender, item);
			}
			foreach (Packet item2 in lamps.ActiveEffects(network.ServerTime))
			{
				network.ToClient(sender, item2);
			}
			foreach (Packet item3 in carry.ActiveEffects())
			{
				network.ToClient(sender, item3);
			}
		}

		public void Disconnected(ulong sender)
		{
			if (ghosts.TryGetValue(sender, out var value))
			{
				Retire(sender, value);
				ghosts.Remove(sender);
			}
		}

		public void ResetSession()
		{
			ClearRound();
			epoch = 0u;
			allReady = false;
			advertised = false;
			serverPlaying = false;
		}

		public void Dispose()
		{
			network.Dispose();
			ResetSession();
			hud.Dispose();
		}

		public void Info(string message)
		{
			log.LogInfo((object)message);
		}

		public void Debug(string message)
		{
			if (config.Debug.Value)
			{
				log.LogDebug((object)message);
			}
		}

		private Packet RoundStatus()
		{
			return new Packet
			{
				Type = Message.RoundStateSync,
				Round = epoch,
				Flag = serverPlaying,
				Ready = allReady
			};
		}

		private void ClearRound()
		{
			hud.Hide();
			localConfirmed = false;
			correction = null;
			feedbackUntil = 0.0;
			ghosts.Clear();
			walls.Clear();
			lamps.Clear();
			carry.Clear();
			pickupReadyAt = 0.0;
			voice.Clear();
			localVoiceUntil = 0.0;
			voiceKeyWasHeld = false;
			writer.Close();
			wheel.Close();
			silhouettes.Reset();
			localGhost = (generation = (poseSequence = (actionSequence = (presenceRevision = 0u))));
			pendingEntrance = null;
		}

		private PlayerControllerB FindDeadPlayer(ulong sender)
		{
			if (!Object.op_Implicit((Object)(object)round) || round.allPlayerScripts == null)
			{
				return null;
			}
			PlayerControllerB[] allPlayerScripts = round.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if (Object.op_Implicit((Object)(object)val) && ((NetworkBehaviour)val).IsSpawned && val.isPlayerDead && val.actualClientId == sender)
				{
					return val;
				}
			}
			return null;
		}

		private static bool LocalAlive()
		{
			GameNetworkManager instance = GameNetworkManager.Instance;
			PlayerControllerB val = (Object.op_Implicit((Object)(object)instance) ? instance.localPlayerController : null);
			if (Object.op_Implicit((Object)(object)val) && val.isPlayerControlled)
			{
				return !val.isPlayerDead;
			}
			return false;
		}

		private bool CanSeeGhosts()
		{
			if (localGhost == 0 || !playing || !serverPlaying || !Object.op_Implicit((Object)(object)round) || !network.HostAcknowledged)
			{
				return false;
			}
			GameNetworkManager instance = GameNetworkManager.Instance;
			PlayerControllerB val = (Object.op_Implicit((Object)(object)instance) ? instance.localPlayerController : null);
			if (Object.op_Implicit((Object)(object)val) && val.isPlayerDead && Object.op_Implicit((Object)(object)val.gameplayCamera))
			{
				return (Object)(object)round.activeCamera == (Object)(object)val.gameplayCamera;
			}
			return false;
		}

		private void UpdateMode(ulong sender, PlayerControllerB player, GhostPeer state, Packet message)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			if (!message.Flag)
			{
				if (state.Generation == message.Number)
				{
					Retire(sender, state);
				}
				return;
			}
			if (message.Number <= state.Generation)
			{
				if (state.IsCurrent(sender) && message.Number == state.Generation)
				{
					ReplySpawn(sender, message.Number, accepted: true, state.Position, state.SpawnedFromPit);
				}
				return;
			}
			Vector3 proposed = GhostWorld.VectorOf(message.Position);
			if (!AcceptSpawn(sender, player, proposed, GhostWorld.VectorOf(message.Direction), out var spawn, out var fromPit))
			{
				ReplySpawn(sender, message.Number, accepted: false, default(Vector3), fromPit: false);
				return;
			}
			state.Active = true;
			state.Player = player;
			state.Generation = message.Number;
			state.LastPose = (state.LastAction = 0u);
			state.Position = spawn;
			state.SpawnedFromPit = fromPit;
			state.Platform.Track(spawn);
			state.Heading = Mathf.Repeat(message.Value, 360f);
			state.Updated = Time.unscaledTimeAsDouble;
			state.AllowsVoice = message.Ready;
			if (state.NextReveal == 0.0)
			{
				state.NextReveal = network.ServerTime + 3.0;
			}
			if (state.AllowsVoice && state.NextVoiceWindow == 0.0)
			{
				state.NextVoiceWindow = NextVoiceTime(network.ServerTime);
			}
			ReplySpawn(sender, message.Number, accepted: true, spawn, fromPit);
			SyncPickupCooldown(sender, state, Time.unscaledTimeAsDouble);
			PublishPresence(sender, state, sequenced: false);
			foreach (KeyValuePair<ulong, GhostPeer> ghost in ghosts)
			{
				if (ghost.Key != sender && ghost.Value.IsCurrent(ghost.Key))
				{
					SendPresence(sender, state.Generation, ghost.Key, ghost.Value, sequenced: false);
				}
			}
		}

		private void ReplySpawn(ulong sender, uint number, bool accepted, Vector3 position, bool fromPit)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			network.ToClient(sender, new Packet
			{
				Type = Message.GhostModeResult,
				Round = epoch,
				Number = number,
				Flag = accepted,
				Ready = fromPit,
				Position = GhostWorld.PointOf(position)
			});
		}

		private bool AcceptSpawn(ulong sender, PlayerControllerB player, Vector3 proposed, Vector3 reportedDeath, out Vector3 spawn, out bool fromPit)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: 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: Invalid comparison between Unknown and I4
			//IL_0152: 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_0164: 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_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: 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_0109: 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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			spawn = default(Vector3);
			fromPit = false;
			bool num = sender == network.LocalId;
			CauseOfDeath val = (num ? ghost.DeathCause : player.causeOfDeath);
			Vector3 val2 = (num ? GhostMotor.DeathPosition(player) : player.placeOfDeath);
			Vector3 val3;
			if (!num)
			{
				if ((int)val == 2 && GhostMotor.IsPit(reportedDeath) && GhostEntrance.TryMainEntrance(player, round, out var position))
				{
					val3 = proposed - position;
					if (((Vector3)(ref val3)).sqrMagnitude <= 1f)
					{
						spawn = position;
						fromPit = true;
						return true;
					}
				}
				Vector3 val4 = reportedDeath - val2;
				if (val4.x * val4.x + val4.z * val4.z <= 9f && Mathf.Abs(val4.y) <= 12f)
				{
					val2 = reportedDeath;
				}
			}
			if (GhostMotor.TryResolveSpawn(player, round, val2, val, out spawn, out fromPit))
			{
				val3 = proposed - spawn;
				if (((Vector3)(ref val3)).sqrMagnitude <= (fromPit ? 1f : 9f))
				{
					spawn = proposed;
				}
				else
				{
					Debug($"Reconciled ghost spawn for {sender}: {proposed} -> {spawn}.");
				}
				return true;
			}
			Debug($"Rejected ghost spawn for {sender}: {val}, last death position {val2}, reported {reportedDeath}, spawn {proposed}.");
			return false;
		}

		private void UpdatePose(ulong sender, PlayerControllerB player, GhostPeer state, Packet message)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: 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_00b7: 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_00c6: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: 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_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			if (!state.IsCurrent(sender) || (Object)(object)state.Player != (Object)(object)player || state.Generation != message.Number || message.Motion <= state.LastPose)
			{
				return;
			}
			double unscaledTimeAsDouble = Time.unscaledTimeAsDouble;
			float num = Mathf.Clamp((float)(unscaledTimeAsDouble - state.Updated), 0f, 0.5f);
			Vector3 val = GhostWorld.VectorOf(message.Position);
			Vector3 val2 = state.Position + state.Platform.Displacement;
			Vector3 val3 = val - val2;
			float num2 = Balance.Clamp(player.movementSpeed, 1f, 15f, 4.6f) * 1.8f;
			float num3 = 0.8f + num * num2;
			if (val3.x * val3.x + val3.z * val3.z > num3 * num3 || Mathf.Abs(val3.y) > 1f + num * 30f || Physics.Linecast(val2 + Vector3.up * 0.85f, val + Vector3.up * 0.85f, GhostMotor.CollisionMask(round), (QueryTriggerInteraction)1))
			{
				if (unscaledTimeAsDouble - state.Updated > 0.7 && unscaledTimeAsDouble >= state.NextCorrection)
				{
					state.NextCorrection = unscaledTimeAsDouble + 0.8;
					Debug($"Reconciled stale ghost position for {sender}: {val} -> {val2}.");
					network.ToClient(sender, new Packet
					{
						Type = Message.GhostPositionCorrection,
						Round = epoch,
						Number = state.Generation,
						Position = GhostWorld.PointOf(val2)
					});
				}
				return;
			}
			state.Position = val;
			state.Platform.Track(val);
			state.Heading = Mathf.Repeat(message.Value, 360f);
			state.LastPose = message.Motion;
			state.Updated = unscaledTimeAsDouble;
			PublishPresence(sender, state, sequenced: true);
			PublishCarriedItem(sender, state);
			double serverTime = network.ServerTime;
			if (state.AllowsVoice && state.VoiceWindowUntil > serverTime && message.Flag)
			{
				PublishVoice(sender, state, Math.Min(state.VoiceWindowUntil, serverTime + 0.28));
			}
			else if (state.VoiceRelaying)
			{
				PublishVoice(sender, state, 0.0);
			}
		}

		private void Retire(ulong sender, GhostPeer state)
		{
			if (state.Active)
			{
				DropItem(sender, state);
				state.Active = false;
				PublishPresence(sender, state, sequenced: false);
				state.RevealUntil = (state.VoiceWindowUntil = 0.0);
				if (state.VoiceRelaying)
				{
					PublishVoice(sender, state, 0.0);
				}
			}
		}

		private void PublishPresence(ulong subject, GhostPeer state, bool sequenced)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			if (!network.Server)
			{
				return;
			}
			state.PresenceRevision = ++presenceRevision;
			if (state.RevealUntil > network.ServerTime)
			{
				network.Broadcast(new Packet
				{
					Type = Message.GhostStateSync,
					Round = epoch,
					Target = subject,
					Motion = state.PresenceRevision,
					Position = GhostWorld.PointOf(state.Position),
					Value = state.Heading,
					Flag = state.Active,
					Until = state.RevealUntil
				}, sequenced);
			}
			foreach (KeyValuePair<ulong, GhostPeer> ghost in ghosts)
			{
				if (ghost.Key != subject && ghost.Value.IsCurrent(ghost.Key))
				{
					SendPresence(ghost.Key, ghost.Value.Generation, subject, state, sequenced);
				}
			}
		}

		private void SendPresence(ulong viewer, uint viewerGeneration, ulong subject, GhostPeer state, bool sequenced)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			network.ToClient(viewer, new Packet
			{
				Type = Message.GhostStateSync,
				Round = epoch,
				Number = viewerGeneration,
				Target = subject,
				Motion = state.PresenceRevision,
				Flag = state.Active,
				Position = GhostWorld.PointOf(state.Position),
				Value = state.Heading
			}, sequenced);
		}

		private void UpdateTimedEffects(ulong subject, GhostPeer state)
		{
			double serverTime = network.ServerTime;
			if (carry.ShouldDrop(subject, serverTime))
			{
				DropItem(subject, state);
			}
			if (serverTime >= state.NextReveal)
			{
				state.NextReveal = serverTime + 120.0;
				state.RevealUntil = serverTime + 1.5;
				PublishPresence(subject, state, sequenced: false);
			}
			if (state.AllowsVoice && serverTime >= state.NextVoiceWindow)
			{
				state.NextVoiceWindow = NextVoiceTime(serverTime);
				state.VoiceWindowUntil = serverTime + 4.0;
				network.ToClient(subject, new Packet
				{
					Type = Message.GhostVoiceWindow,
					Round = epoch,
					Target = subject,
					Flag = true,
					Until = state.VoiceWindowUntil
				});
			}
		}

		private double NextVoiceTime(double now)
		{
			return now + 90.0 + voiceRandom.NextDouble() * 60.0;
		}

		private void PublishVoice(ulong subject, GhostPeer state, double until)
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			state.VoiceRelaying = until > 0.0;
			network.Broadcast(new Packet
			{
				Type = Message.GhostVoiceWindow,
				Round = epoch,
				Target = subject,
				Until = until,
				Motion = ++presenceRevision,
				Position = GhostWorld.PointOf(state.Position)
			}, state.VoiceRelaying);
		}

		private void DropItem(ulong subject, GhostPeer state)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			ReleaseItem(subject, state, state.Position + state.Platform.Displacement + Vector3.up * 0.65f, Vector3.zero);
		}

		private bool ReleaseItem(ulong subject, GhostPeer state, Vector3 position, Vector3 direction)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			Packet packet = carry.Release(subject, round, position, direction, network.ServerTime);
			if (packet == null)
			{
				return false;
			}
			network.Broadcast(packet);
			double unscaledTimeAsDouble = Time.unscaledTimeAsDouble;
			state.Energy.StartCooldown(Ability.Carry, unscaledTimeAsDouble);
			SyncPickupCooldown(subject, state, unscaledTimeAsDouble);
			return true;
		}

		private void SyncPickupCooldown(ulong subject, GhostPeer state, double now)
		{
			network.ToClient(subject, new Packet
			{
				Type = Message.CooldownSync,
				Round = epoch,
				Ability = Ability.Carry,
				Value = state.Energy.Remaining(Ability.Carry, now)
			});
		}

		private void PublishCarriedItem(ulong subject, GhostPeer state)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			if (carry.HasItem(subject))
			{
				Packet packet = carry.Move(subject, round, state.Position + state.Platform.Displacement, state.Heading, ++state.CarryPoseRevision);
				if (packet != null)
				{
					network.Broadcast(packet, sequenced: true);
				}
			}
		}

		private void UseAbility(ulong sender, GhostPeer state, Packet message)
		{
			Ability ability = message.Ability;
			if ((ability == Ability.Door || ability == Ability.Wall || ability == Ability.Light || ability == Ability.Carry) && state.Generation == message.Number && message.Motion > state.LastAction)
			{
				state.LastAction = message.Motion;
				double unscaledTimeAsDouble = Time.unscaledTimeAsDouble;
				bool flag = network.AllReady || (!rules.RequireAll && ability == Ability.Door);
				Failure failure = ((!state.IsCurrent(sender)) ? Failure.Position : ((!flag) ? Failure.Unavailable : Failure.None));
				bool passage = false;
				if (failure == Failure.None)
				{
					failure = Execute(sender, state, message, unscaledTimeAsDouble, out passage);
				}
				if (failure == Failure.None && !passage)
				{
					state.Energy.Commit(ability, unscaledTimeAsDouble);
				}
				if (!passage || failure != Failure.None)
				{
					network.ToClient(sender, new Packet
					{
						Type = Message.InteractionResult,
						Round = epoch,
						Ability = ability,
						Failure = failure,
						Value = ((failure == Failure.Cooldown) ? state.Energy.Remaining(ability, unscaledTimeAsDouble) : state.Energy.Value)
					});
				}
			}
		}

		private Failure Execute(ulong sender, GhostPeer state, Packet message, double now, out bool passage)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: 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_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			passage = false;
			Vector3 val = GhostWorld.VectorOf(message.Position);
			Vector3 val2 = GhostWorld.VectorOf(message.Direction);
			Vector3 val3 = state.Position + state.Platform.Displacement;
			Vector3 val4 = val - val3;
			if (now - state.Updated > 1.6 || val4.y < 0.1f || val4.y > 2.8f || val4.x * val4.x + val4.z * val4.z > 3.24f || ((Vector3)(ref val2)).sqrMagnitude < 0.9f || ((Vector3)(ref val2)).sqrMagnitude > 1.1f || Physics.Linecast(val3 + Vector3.up * 0.85f, val, GhostMotor.CollisionMask(round), (QueryTriggerInteraction)1))
			{
				return Failure.Position;
			}
			Ability ability = message.Ability;
			float range = rules[ability].Range;
			((Vector3)(ref val2)).Normalize();
			switch (ability)
			{
			case Ability.Door:
			{
				if (!AimDoor(val, val2, out var entrance, out var hit))
				{
					return Failure.Target;
				}
				if (Object.op_Implicit((Object)(object)entrance))
				{
					passage = true;
					return UseEntrance(sender, state, message, entrance, now);
				}
				if (GhostElevator.IsButton(((RaycastHit)(ref hit)).collider))
				{
					passage = true;
					if (!GhostElevator.TryUse(((RaycastHit)(ref hit)).collider, val3))
					{
						return Failure.Target;
					}
					return Failure.None;
				}
				if (AbilityWorld.IsDoorLocked(AbilityWorld.FindDoor(((RaycastHit)(ref hit)).collider)))
				{
					return Failure.Locked;
				}
				Failure failure = state.Energy.Check(ability, now);
				if (failure != Failure.None)
				{
					return failure;
				}
				if (!GhostShipControls.TryUse(round, ((RaycastHit)(ref hit)).collider) && !AbilityWorld.ToggleDoor(((RaycastHit)(ref hit)).collider))
				{
					return Failure.Target;
				}
				return Failure.None;
			}
			case Ability.Carry:
			{
				if (!carry.HasItem(sender))
				{
					break;
				}
				passage = true;
				if (message.Preset == 2)
				{
					Packet packet = carry.Use(sender, state.Player, round, val, val2, network.ServerTime);
					if (packet == null)
					{
						return Failure.Target;
					}
					network.Broadcast(packet);
					return Failure.None;
				}
				bool flag = message.Preset == 1;
				if (message.Preset != 0 && !flag)
				{
					return Failure.Target;
				}
				if (!ReleaseItem(sender, state, flag ? val : (val3 + Vector3.up * 0.65f), flag ? val2 : Vector3.zero))
				{
					return Failure.Target;
				}
				return Failure.None;
			}
			}
			Failure failure2 = state.Energy.Check(ability, now);
			if (failure2 != Failure.None)
			{
				return failure2;
			}
			bool num;
			RaycastHit hit2;
			switch (ability)
			{
			case Ability.Light:
				return FlickerLamp(val, val2);
			default:
				num = AbilityWorld.Aim(round, val, val2, range, out hit2, ability == Ability.Door);
				break;
			case Ability.Wall:
				num = AbilityWorld.AimWall(round, val, val2, range, out hit2);
				break;
			}
			if (!num)
			{
				return Failure.Target;
			}
			switch (message.Ability)
			{
			case Ability.Carry:
			{
				if (message.Preset != 0)
				{
					return Failure.Target;
				}
				Packet packet2 = carry.Take(sender, ((RaycastHit)(ref hit2)).collider, epoch, network.ServerTime);
				if (packet2 == null)
				{
					return Failure.Target;
				}
				network.Broadcast(packet2);
				PublishCarriedItem(sender, state);
				return Failure.None;
			}
			case Ability.Wall:
			{
				string result = string.Empty;
				if (!string.IsNullOrEmpty(message.Text) && (!rules.CustomWall || !WallText.TryNormalize(message.Text, out result)))
				{
					return Failure.Target;
				}
				if (!walls.TryWrite(sender, epoch, hit2, message.Preset, result, network.ServerTime + (double)rules.WallSeconds, out var effect))
				{
					return Failure.Limit;
				}
				network.Broadcast(effect);
				return Failure.None;
			}
			default:
				return Failure.Unavailable;
			}
		}

		private Failure FlickerLamp(Vector3 eye, Vector3 direction)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			if (!lamps.TryTarget(eye, direction, rules[Ability.Light].Range, round.collidersAndRoomMaskAndDefault, network.ServerTime, out var position))
			{
				return Failure.Target;
			}
			network.Broadcast(new Packet
			{
				Type = Message.WorldEffect,
				Ability = Ability.Light,
				Round = epoch,
				Position = GhostWorld.PointOf(position),
				Until = network.ServerTime + (double)rules.LightSeconds
			});
			return Failure.None;
		}

		private Failure UseEntrance(ulong sender, GhostPeer state, Packet request, EntranceTeleport entrance, double now)
		{
			//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_0057: Unknown result type (might be due to invalid IL or missing references)
			if (now < state.NextEntrance || request.Target > uint.MaxValue || !GhostEntrance.TryPass(state.Player, round, entrance, out var passage))
			{
				return Failure.Target;
			}
			state.NextEntrance = now + 0.6;
			state.Position = GhostWorld.VectorOf(passage.Position);
			state.Platform.Track(state.Position);
			state.Heading = passage.Value;
			state.Updated = now;
			state.LastPose = Math.Max(state.LastPose, (uint)request.Target);
			passage.Round = epoch;
			passage.Number = state.Generation;
			network.ToClient(sender, passage);
			PublishPresence(sender, state, sequenced: false);
			PublishCarriedItem(sender, state);
			GhostEntrance.Animate(entrance);
			return Failure.None;
		}

		private void Report(Packet message)
		{
			bool flag = config.Language.Value == "ru";
			switch (message.Failure)
			{
			case Failure.Locked:
				Feedback(flag ? "Дверь заперта" : "Door locked");
				break;
			case Failure.Position:
				Feedback(flag ? "Хост проверяет позицию" : "Host is checking your position");
				break;
			case Failure.Cooldown:
				Feedback((flag ? "Готово через " : "Ready in ") + Mathf.CeilToInt(message.Value) + "s");
				break;
			case Failure.Unavailable:
				Feedback(flag ? "Действие недоступно в этом лобби" : "Action unavailable in this lobby");
				break;
			case Failure.Energy:
				Feedback(flag ? "Недостаточно энергии" : "Not enough energy");
				break;
			case Failure.Target:
				Feedback(flag ? "Цель недоступна" : "Target unavailable");
				break;
			}
			string text = ((message.Ability == Ability.Wall) ? "Wall message" : ((message.Ability == Ability.Light) ? "Lamp flicker" : ((message.Ability == Ability.Carry) ? "Pick up" : "Door")));
			switch (message.Failure)
			{
			case Failure.None:
				Notify($"{text} used. Energy: {Mathf.FloorToInt(message.Value)}.");
				break;
			case Failure.Cooldown:
				Notify($"{text} ready in {Mathf.CeilToInt(message.Value)}s.");
				break;
			case Failure.Energy:
				Notify("Not enough ghost energy.");
				break;
			case Failure.Locked:
				Notify(flag ? "Дверь заперта." : "Door locked.");
				break;
			case Failure.Position:
				Notify("Wait for the host to confirm your position, or re-enter Ghost Mode.");
				break;
			case Failure.Limit:
				Notify("Too many active wall messages.");
				break;
			case Failure.Unavailable:
				Notify(text + " is unavailable in this lobby.");
				break;
			default:
				Notify("No valid target for " + text.ToLowerInvariant() + ".");
				break;
			}
		}

		private void Feedback(string message)
		{
			feedback = message;
			feedbackUntil = Time.unscaledTimeAsDouble + 2.0;
			nextHint = 0.0;
		}

		private void Notify(string message)
		{
			if (!(Time.unscaledTimeAsDouble < nextNotice))
			{
				nextNotice = Time.unscaledTimeAsDouble + 0.8;
				if (Object.op_Implicit((Object)(object)HUDManager.Instance))
				{
					HUDManager.Instance.DisplayTip("Ghost Mode", message, false, false, "LC_Tip1");
				}
				Debug(message);
			}
		}

		internal static bool BindingPressed(string binding)
		{
			ButtonControl obj = Binding(binding);
			if (obj == null)
			{
				return false;
			}
			return obj.wasPressedThisFrame;
		}

		private static ButtonControl Binding(string binding)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Invalid comparison between Unknown and I4
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Invalid comparison between Unknown and I4
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			if (string.Equals(binding, "MouseLeft", StringComparison.OrdinalIgnoreCase))
			{
				Mouse current = Mouse.current;
				if (current == null)
				{
					return null;
				}
				return current.leftButton;
			}
			if (string.Equals(binding, "MouseRight", StringComparison.OrdinalIgnoreCase))
			{
				Mouse current2 = Mouse.current;
				if (current2 == null)
				{
					return null;
				}
				return current2.rightButton;
			}
			Keyboard current3 = Keyboard.current;
			if (current3 == null || !Enum.TryParse<Key>(binding, ignoreCase: true, out Key result) || (int)result <= 0 || (int)result >= 106)
			{
				return null;
			}
			return (ButtonControl)(object)current3[result];
		}

		private static bool KeyHeld(Key key)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			Keyboard current = Keyboard.current;
			if (current != null && (int)key > 0 && (int)key < 106)
			{
				return ((ButtonControl)current[key]).isPressed;
			}
			return false;
		}

		private static bool KeyPressed(Key key)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			Keyboard current = Keyboard.current;
			if (current != null && (int)key > 0 && (int)key < 106)
			{
				return ((ButtonControl)current[key]).wasPressedThisFrame;
			}
			return false;
		}
	}
	internal sealed class GhostAvatar : IDisposable
	{
		private sealed class Part : IDisposable
		{
			private readonly Mesh mesh;

			private readonly bool ownsMesh;

			private readonly Vector3 position;

			private readonly Vector3 scale;

			private readonly Quaternion rotation;

			private readonly Material[] originals;

			private readonly MaterialPropertyBlock[] overrides;

			private readonly MaterialPropertyBlock sharedOverrides;

			private Part(PlayerControllerB player, Renderer renderer, Mesh mesh, bool ownsMesh, bool fitToRenderedBounds)
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_0048: 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_0055: Unknown result type (might be due to invalid IL or missing references)
				//IL_005a: Unknown result type (might be due to invalid IL or missing references)
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				//IL_006b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0070: Unknown result type (might be due to invalid IL or missing references)
				//IL_0141: Unknown result type (might be due to invalid IL or missing references)
				//IL_0147: Expected O, but got Unknown
				//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_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_0090: 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_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_00cb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d0: Unknown result type (might be du