Decompiled source of HuntMod v0.5.6

BepInEx\plugins\HuntMod\HuntMod.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using ExitGames.Client.Photon;
using HarmonyLib;
using HuntMod.Core;
using PEAKLib.Core;
using PEAKLib.Items;
using Peak;
using Peak.Afflictions;
using Photon.Pun;
using Photon.Realtime;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.TextCore;
using UnityEngine.UI;
using Zorro.Core;
using Zorro.Core.Serizalization;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace HuntMod.Core
{
	public sealed class AuthorityInbox
	{
		private int master;

		private bool allowNewSession = true;

		private HuntSnapshot current;

		public HuntSnapshot Current
		{
			get
			{
				if (current != null)
				{
					return current.Clone();
				}
				return null;
			}
		}

		public void SetMaster(int actor)
		{
			if (master != actor)
			{
				master = actor;
				allowNewSession = true;
			}
		}

		public void Reset()
		{
			master = 0;
			allowNewSession = true;
			current = null;
		}

		public bool Accept(int actualSender, HuntSnapshot next)
		{
			if (next == null || actualSender <= 0 || actualSender != master || next.HostActor != actualSender)
			{
				return false;
			}
			if (current != null)
			{
				if (next.Session == current.Session)
				{
					if (next.AuthorityTerm < current.AuthorityTerm || (next.AuthorityTerm == current.AuthorityTerm && next.Revision < current.Revision))
					{
						return false;
					}
					if (next.HostActor != current.HostActor && next.AuthorityTerm <= current.AuthorityTerm)
					{
						return false;
					}
				}
				else if (!allowNewSession)
				{
					return false;
				}
			}
			current = next.Clone();
			allowNewSession = false;
			return true;
		}
	}
	public struct CampfireObservation
	{
		public bool Available;

		public bool Current;

		public bool Active;

		public bool Lit;

		public int ViewId;

		public int AdvanceToSegment;

		public HuntPosition Position;
	}
	public static class CampfireRules
	{
		public static bool OutsideProtection(HuntPlayer player, HuntPosition position)
		{
			if (player == null || !player.Connected || player.PendingRevive || !player.CampProtected || !position.IsFinite || !player.CampProtectionPosition.IsFinite)
			{
				return false;
			}
			double num = position.X - player.CampProtectionPosition.X;
			double num2 = position.Y - player.CampProtectionPosition.Y;
			double num3 = position.Z - player.CampProtectionPosition.Z;
			return num * num + num2 * num2 + num3 * num3 > 900.0;
		}

		public static bool Playing(HuntSnapshot state)
		{
			if (state != null && !state.FlowOnly)
			{
				if (state.Phase != HuntPhase.Active)
				{
					return state.Phase == HuntPhase.HunterDelay;
				}
				return true;
			}
			return false;
		}

		public static bool CurrentExit(HuntSnapshot state, string nativeRun, int segment, CampfireObservation camp)
		{
			if (Playing(state) && !string.IsNullOrEmpty(nativeRun) && segment >= 0 && segment < 5 && state.StageKey == nativeRun + ":" + segment && camp.Available && camp.Current && camp.Active && camp.ViewId > 0 && camp.Position.IsFinite)
			{
				return camp.AdvanceToSegment == segment + 1;
			}
			return false;
		}

		public static bool TryProtection(HuntSnapshot state, string nativeRun, int segment, CampfireObservation camp, int actor, HuntPosition position, out double distance)
		{
			distance = double.PositiveInfinity;
			if (!CurrentExit(state, nativeRun, segment, camp) || camp.Lit || !position.IsFinite)
			{
				return false;
			}
			HuntPlayer huntPlayer = state.Find(actor);
			if (huntPlayer == null || !huntPlayer.Connected || huntPlayer.PendingRevive || huntPlayer.Team == HuntTeam.None || (huntPlayer.CampProtected && huntPlayer.CampProtectionStage >= state.Stage))
			{
				return false;
			}
			double num = position.X - camp.Position.X;
			double num2 = position.Y - camp.Position.Y;
			double num3 = position.Z - camp.Position.Z;
			distance = Math.Sqrt(num * num + num2 * num2 + num3 * num3);
			return distance <= 10.0;
		}
	}
	public sealed class CampfireEvidence
	{
		public readonly string NativeRun;

		public readonly string StageKey;

		public readonly string NextStageKey;

		public readonly int SourceSegment;

		public readonly int NextSegment;

		public readonly int ViewId;

		private readonly Guid session;

		private readonly int term;

		private readonly int run;

		private readonly int round;

		private readonly int stage;

		private CampfireEvidence(HuntSnapshot state, string nativeRun, int segment, CampfireObservation camp)
		{
			session = state.Session;
			term = state.AuthorityTerm;
			run = state.Run;
			round = state.Round;
			stage = state.Stage;
			NativeRun = nativeRun;
			SourceSegment = segment;
			NextSegment = camp.AdvanceToSegment;
			ViewId = camp.ViewId;
			StageKey = state.StageKey;
			NextStageKey = nativeRun + ":" + NextSegment;
		}

		public static CampfireEvidence Capture(HuntSnapshot state, string nativeRun, int segment, CampfireObservation camp, bool advancesSegment)
		{
			if (!advancesSegment || camp.Lit || !CampfireRules.CurrentExit(state, nativeRun, segment, camp))
			{
				return null;
			}
			return new CampfireEvidence(state, nativeRun, segment, camp);
		}

		public bool Complete(HuntSnapshot state, string nativeRun, int nativeSegment, CampfireObservation camp)
		{
			if (CampfireRules.Playing(state) && state.Session == session && state.AuthorityTerm == term && state.Run == run && state.Round == round && state.Stage == stage && state.StageKey == StageKey && nativeRun == NativeRun && (nativeSegment == SourceSegment || nativeSegment == NextSegment) && camp.Available && camp.Active && camp.Lit && camp.ViewId == ViewId)
			{
				return camp.AdvanceToSegment == NextSegment;
			}
			return false;
		}

		internal bool ResultScope(HuntSnapshot state)
		{
			if (state != null && state.Enabled && !state.FlowOnly && state.Phase != HuntPhase.Suspended && state.Session == session && state.AuthorityTerm == term && state.Run == run && state.Stage == stage + 1)
			{
				return state.StageKey == NextStageKey;
			}
			return false;
		}
	}
	public enum CampMapProgress
	{
		None,
		Waiting,
		Arrived,
		Unexpected
	}
	public sealed class CampMapTransition
	{
		private CampfireEvidence pending;

		public bool Expect(CampfireEvidence proof, HuntSnapshot result)
		{
			if (proof == null || !proof.ResultScope(result))
			{
				return false;
			}
			pending = proof;
			return true;
		}

		public void Clear()
		{
			pending = null;
		}

		public CampMapProgress Observe(HuntSnapshot state, string nativeRun, int nativeSegment, bool revealed)
		{
			if (pending == null)
			{
				return CampMapProgress.None;
			}
			if (!pending.ResultScope(state) || nativeRun != pending.NativeRun)
			{
				Clear();
				return CampMapProgress.None;
			}
			if (nativeSegment == pending.SourceSegment || (nativeSegment == pending.NextSegment && !revealed))
			{
				return CampMapProgress.Waiting;
			}
			if (nativeSegment != pending.NextSegment)
			{
				return CampMapProgress.Unexpected;
			}
			Clear();
			return CampMapProgress.Arrived;
		}
	}
	public enum HuntSoundKind : byte
	{
		SurvivorBurst,
		SurvivorKnife,
		SurvivorDart,
		HunterKnife
	}
	public sealed class HuntSoundCue
	{
		public long Sequence;

		public int Stage;

		public int ReviveVersion;

		public double At;

		public HuntSoundKind Kind;

		public HuntSoundCue Clone()
		{
			return (HuntSoundCue)MemberwiseClone();
		}
	}
	public static class CombatSoundRules
	{
		public const int MaxCues = 16;

		public const double MaximumAge = 3.0;

		internal static void Emit(HuntSnapshot state, HuntPlayer receiver, HuntSoundKind kind, double now)
		{
			receiver.SoundCues.Add(new HuntSoundCue
			{
				Sequence = ++receiver.SoundSequence,
				Stage = state.Stage,
				ReviveVersion = receiver.ReviveVersion,
				At = now,
				Kind = kind
			});
			while (receiver.SoundCues.Count > 16)
			{
				receiver.SoundCues.RemoveAt(0);
			}
		}
	}
	public sealed class OwnerCombatSoundTracker
	{
		private Guid session;

		private int actor;

		private int term;

		private int run;

		private int round;

		private int stage;

		private int revive;

		private long consumed;

		private readonly List<HuntSoundCue> pending = new List<HuntSoundCue>();

		public void CancelPending()
		{
			pending.Clear();
		}

		private static bool Audience(HuntPlayer p, HuntSoundKind kind, bool alive)
		{
			switch (kind)
			{
			case HuntSoundKind.HunterKnife:
				if (alive && !p.PendingRevive)
				{
					return p.Team == HuntTeam.Hunters;
				}
				return false;
			case HuntSoundKind.SurvivorBurst:
				if (alive && !p.PendingRevive)
				{
					return p.Role == HuntRole.Survivor;
				}
				return false;
			default:
				if (p.Role != HuntRole.Survivor)
				{
					if (p.Role == HuntRole.FalseHunter)
					{
						return p.PendingRevive;
					}
					return false;
				}
				return true;
			}
		}

		public List<HuntSoundKind> Poll(HuntSnapshot state, int owner, double now, bool alive)
		{
			List<HuntSoundKind> list = new List<HuntSoundKind>();
			HuntPlayer huntPlayer = state?.Find(owner);
			if (!CampfireRules.Playing(state) || huntPlayer == null || !huntPlayer.Connected || huntPlayer.Team == HuntTeam.None || double.IsNaN(now) || double.IsInfinity(now))
			{
				CancelPending();
				return list;
			}
			if (session != state.Session || actor != owner || term != state.AuthorityTerm || run != state.Run || round != state.Round || stage != state.Stage || revive != huntPlayer.ReviveVersion)
			{
				CancelPending();
				consumed = 0L;
				session = state.Session;
				actor = owner;
				term = state.AuthorityTerm;
				run = state.Run;
				round = state.Round;
				stage = state.Stage;
				revive = huntPlayer.ReviveVersion;
			}
			foreach (HuntSoundCue soundCue in huntPlayer.SoundCues)
			{
				if (soundCue.Sequence > consumed)
				{
					consumed = soundCue.Sequence;
					if (soundCue.Stage == stage && soundCue.ReviveVersion == revive && !(soundCue.At > now + 0.1) && !(now - soundCue.At > 3.0) && Audience(huntPlayer, soundCue.Kind, alive))
					{
						pending.Add(soundCue.Clone());
					}
				}
			}
			int num = 0;
			while (num < pending.Count)
			{
				HuntSoundCue huntSoundCue = pending[num];
				double at = huntSoundCue.At;
				if (!Audience(huntPlayer, huntSoundCue.Kind, alive) || now - huntSoundCue.At > 3.0 || (huntSoundCue.Kind == HuntSoundKind.SurvivorBurst && now >= huntPlayer.BurstUntil))
				{
					pending.RemoveAt(num);
					continue;
				}
				if (now < at)
				{
					num++;
					continue;
				}
				list.Add(huntSoundCue.Kind);
				pending.RemoveAt(num);
			}
			return list;
		}
	}
	public sealed class EffectJournal
	{
		private Guid session;

		private readonly HashSet<string> pending = new HashSet<string>();

		private readonly HashSet<string> complete = new HashSet<string>();

		public void SetSession(Guid value)
		{
			if (!(value == session))
			{
				session = value;
				pending.Clear();
				complete.Clear();
			}
		}

		public string Key(int actor, string effect, int version)
		{
			return session.ToString("N") + ":" + actor + ":" + effect + ":" + version;
		}

		private bool Current(string key)
		{
			if (!string.IsNullOrEmpty(key))
			{
				return key.StartsWith(session.ToString("N") + ":", StringComparison.Ordinal);
			}
			return false;
		}

		public bool TryBegin(string key)
		{
			if (!Current(key) || complete.Contains(key))
			{
				return false;
			}
			return pending.Add(key);
		}

		public bool Confirm(string key)
		{
			if (!Current(key) || !pending.Remove(key))
			{
				return false;
			}
			complete.Add(key);
			return true;
		}

		public void RetryAfterFailure(string key)
		{
			if (Current(key) && !complete.Contains(key))
			{
				pending.Remove(key);
			}
		}

		public bool IsComplete(string key)
		{
			if (Current(key))
			{
				return complete.Contains(key);
			}
			return false;
		}
	}
	public sealed class HuntEffectReceipt
	{
		public Guid Session;

		public int AuthorityTerm;

		public int Run;

		public int Round;

		public int Stage;

		public long Sequence;

		public int InventoryVersion = -1;

		public int LoadoutVersion = -1;

		public int ReviveVersion = -1;

		public int RevivePreparedVersion = -1;

		public int ReviveFailedVersion = -1;

		public int PetrifyVersion = -1;

		public int PetrifyEpoch = -1;

		public int PetrifyAmount = -1;

		public HuntEffectReceipt Clone()
		{
			return (HuntEffectReceipt)MemberwiseClone();
		}
	}
	public sealed class EffectReceiptInbox
	{
		private readonly Dictionary<int, HuntEffectReceipt> receipts = new Dictionary<int, HuntEffectReceipt>();

		public void Clear()
		{
			receipts.Clear();
		}

		private static bool Scope(HuntEffectReceipt receipt, HuntSnapshot state)
		{
			if (receipt != null && state != null && receipt.Session == state.Session && receipt.AuthorityTerm == state.AuthorityTerm && receipt.Run == state.Run && receipt.Round == state.Round)
			{
				return receipt.Stage == state.Stage;
			}
			return false;
		}

		public bool Accept(int authenticatedActor, HuntEffectReceipt receipt, HuntSnapshot state)
		{
			if (state == null || !state.Enabled || state.FlowOnly || state.Phase == HuntPhase.Suspended || !Scope(receipt, state))
			{
				return false;
			}
			HuntPlayer huntPlayer = state.Find(authenticatedActor);
			if (huntPlayer == null || !huntPlayer.Connected || receipt.Sequence <= 0 || receipt.InventoryVersion < -1 || receipt.LoadoutVersion < -1 || receipt.ReviveVersion < -1 || receipt.RevivePreparedVersion < -1 || receipt.ReviveFailedVersion < -1 || receipt.InventoryVersion > huntPlayer.InventoryResetVersion || receipt.LoadoutVersion > huntPlayer.LoadoutVersion || receipt.ReviveVersion > huntPlayer.ReviveVersion || receipt.RevivePreparedVersion > huntPlayer.ReviveVersion || receipt.ReviveFailedVersion > huntPlayer.ReviveVersion)
			{
				return false;
			}
			if (receipt.ReviveVersion >= 0 && receipt.ReviveFailedVersion >= 0)
			{
				return false;
			}
			if (receipt.PetrifyVersion < -1 || receipt.PetrifyVersion > huntPlayer.PetrifyVersion || receipt.PetrifyEpoch < -1 || receipt.PetrifyEpoch > huntPlayer.PetrifyEpoch || receipt.PetrifyAmount < -1 || receipt.PetrifyAmount > 100)
			{
				return false;
			}
			if ((receipt.PetrifyVersion >= 0 || receipt.PetrifyEpoch >= 0 || receipt.PetrifyAmount >= 0) && (receipt.PetrifyVersion < 0 || receipt.PetrifyEpoch < 0 || receipt.PetrifyAmount < 0))
			{
				return false;
			}
			if (receipts.TryGetValue(authenticatedActor, out var value) && Scope(value, state) && receipt.Sequence <= value.Sequence)
			{
				return false;
			}
			receipts[authenticatedActor] = receipt.Clone();
			return true;
		}

		private HuntEffectReceipt Read(int actor, HuntSnapshot state)
		{
			if (!receipts.TryGetValue(actor, out var value) || !Scope(value, state))
			{
				return null;
			}
			return value;
		}

		public bool InventoryReady(int actor, HuntSnapshot state)
		{
			HuntEffectReceipt huntEffectReceipt = Read(actor, state);
			HuntPlayer huntPlayer = state?.Find(actor);
			if (huntEffectReceipt != null && huntPlayer != null)
			{
				return huntEffectReceipt.InventoryVersion == huntPlayer.InventoryResetVersion;
			}
			return false;
		}

		public bool LoadoutReady(int actor, HuntSnapshot state)
		{
			HuntEffectReceipt huntEffectReceipt = Read(actor, state);
			HuntPlayer huntPlayer = state?.Find(actor);
			if (huntEffectReceipt != null && huntPlayer != null)
			{
				return huntEffectReceipt.LoadoutVersion == huntPlayer.LoadoutVersion;
			}
			return false;
		}

		public bool ReviveReady(int actor, HuntSnapshot state)
		{
			HuntEffectReceipt huntEffectReceipt = Read(actor, state);
			HuntPlayer huntPlayer = state?.Find(actor);
			if (huntEffectReceipt != null && huntPlayer != null)
			{
				return huntEffectReceipt.ReviveVersion == huntPlayer.ReviveVersion;
			}
			return false;
		}

		public bool RevivePrepared(int actor, HuntSnapshot state)
		{
			HuntEffectReceipt huntEffectReceipt = Read(actor, state);
			HuntPlayer huntPlayer = state?.Find(actor);
			if (huntEffectReceipt != null && huntPlayer != null && huntPlayer.PendingRevive)
			{
				return huntEffectReceipt.RevivePreparedVersion == huntPlayer.ReviveVersion;
			}
			return false;
		}

		public bool ReviveFailed(int actor, HuntSnapshot state)
		{
			HuntEffectReceipt huntEffectReceipt = Read(actor, state);
			HuntPlayer huntPlayer = state?.Find(actor);
			if (huntEffectReceipt != null && huntPlayer != null && huntPlayer.PendingRevive)
			{
				return huntEffectReceipt.ReviveFailedVersion == huntPlayer.ReviveVersion;
			}
			return false;
		}

		public bool PetrifyReady(int actor, HuntSnapshot state)
		{
			HuntEffectReceipt huntEffectReceipt = Read(actor, state);
			HuntPlayer huntPlayer = state?.Find(actor);
			if (huntEffectReceipt != null && huntPlayer != null && huntPlayer.PetrifyInitialized && huntEffectReceipt.PetrifyEpoch == huntPlayer.PetrifyEpoch && huntEffectReceipt.PetrifyVersion == huntPlayer.PetrifyVersion)
			{
				return huntEffectReceipt.PetrifyAmount == PetrifyAuthority.NativeAmount(huntPlayer.Petrify);
			}
			return false;
		}
	}
	public enum EvolutionSource
	{
		AncientChest,
		ScoutStatue,
		FirstCamp,
		FiveBoxes,
		TenTeamBoxes,
		EightyStone
	}
	public sealed class EvolutionOffer
	{
		public long Id;

		public HuntTeam Team;

		public EvolutionSource Source;

		public int Choices;

		public EvolutionOffer Clone()
		{
			return (EvolutionOffer)MemberwiseClone();
		}
	}
	public static class EvolutionRules
	{
		public const int MaxPending = 128;

		public const int MaxObjects = 1024;

		public static bool Playing(HuntSnapshot s)
		{
			if (s != null && !s.FlowOnly && s.Run > 0)
			{
				return CampfireRules.Playing(s);
			}
			return false;
		}

		public static string SourceName(EvolutionSource source)
		{
			return source switch
			{
				EvolutionSource.AncientChest => "古老宝箱", 
				EvolutionSource.ScoutStatue => "童军雕像", 
				EvolutionSource.FirstCamp => "首个到达篝火", 
				EvolutionSource.FiveBoxes => "个人累计开启5个箱子", 
				EvolutionSource.TenTeamBoxes => "求生合计开启10个箱子", 
				_ => "累计造成80点石化", 
			};
		}

		public static void ClearCards(HuntPlayer p)
		{
			p.EvolutionEpoch++;
			p.EvolutionCards = 0;
			p.EvolutionOffers.Clear();
		}

		public static void Reset(HuntSnapshot s, bool newRun)
		{
			s.SurvivorTeamBoxes = 0;
			s.EvolutionCampStage = 0;
			if (newRun)
			{
				s.EvolutionNextId = 0L;
				s.EvolutionOpened.Clear();
			}
			foreach (HuntPlayer player in s.Players)
			{
				ClearCards(player);
				player.EvolutionBoxes = 0;
				player.EvolutionStone = 0f;
			}
		}

		public static bool Grant(HuntSnapshot s, HuntPlayer p, EvolutionSource source, bool random)
		{
			if (p == null || !p.Connected || p.Team == HuntTeam.None || p.EvolutionOffers.Count >= 128)
			{
				return false;
			}
			p.EvolutionOffers.Add(new EvolutionOffer
			{
				Id = ++s.EvolutionNextId,
				Team = p.Team,
				Source = source,
				Choices = (random ? 1 : ((p.Role == HuntRole.Survivor) ? 2 : 3))
			});
			return true;
		}

		public static bool Open(HuntSnapshot s, int actor, int view, EvolutionSource? special)
		{
			HuntPlayer huntPlayer = s.Find(actor);
			if (!Playing(s) || view <= 0 || huntPlayer == null || !huntPlayer.Connected || !huntPlayer.Loaded || huntPlayer.PendingRevive || huntPlayer.Team == HuntTeam.None)
			{
				return false;
			}
			if (special.HasValue && special.Value != EvolutionSource.AncientChest && special.Value != EvolutionSource.ScoutStatue)
			{
				return false;
			}
			string item = view.ToString(CultureInfo.InvariantCulture);
			if (s.EvolutionOpened.Count >= 1024 || s.EvolutionOpened.Contains(item))
			{
				return false;
			}
			s.EvolutionOpened.Add(item);
			if (special.HasValue)
			{
				Grant(s, huntPlayer, special.Value, random: false);
			}
			else if (huntPlayer.Role == HuntRole.Survivor)
			{
				huntPlayer.EvolutionBoxes++;
				s.SurvivorTeamBoxes++;
				if (huntPlayer.EvolutionBoxes % 5 == 0)
				{
					Grant(s, huntPlayer, EvolutionSource.FiveBoxes, random: true);
				}
				if (s.SurvivorTeamBoxes % 10 == 0)
				{
					foreach (HuntPlayer player in s.Players)
					{
						if (player.Team == HuntTeam.Hunters)
						{
							Grant(s, player, EvolutionSource.TenTeamBoxes, random: true);
						}
					}
				}
			}
			return true;
		}

		public static void Camp(HuntSnapshot s, HuntPlayer p)
		{
			if (Playing(s) && p.Role == HuntRole.Survivor && s.EvolutionCampStage != s.Stage)
			{
				s.EvolutionCampStage = s.Stage;
				Grant(s, p, EvolutionSource.FirstCamp, random: false);
			}
		}

		public static void Damage(HuntSnapshot s, HuntPlayer attacker, float actual)
		{
			if (Playing(s) && attacker != null && attacker.Team == HuntTeam.Hunters && !(actual <= 0f) && !float.IsNaN(actual) && !float.IsInfinity(actual))
			{
				attacker.EvolutionStone += actual;
				while (attacker.EvolutionStone >= 80f)
				{
					attacker.EvolutionStone -= 80f;
					Grant(s, attacker, EvolutionSource.EightyStone, random: false);
				}
			}
		}

		public static bool Choose(HuntSnapshot s, HuntPlayer p, long id, int option, bool skip)
		{
			if (!Playing(s) || p == null || p.PendingRevive || p.Team == HuntTeam.None || p.EvolutionOffers.Count == 0)
			{
				return false;
			}
			EvolutionOffer evolutionOffer = p.EvolutionOffers[0];
			if (evolutionOffer.Id != id || evolutionOffer.Team != p.Team || (!skip && (option < 0 || option >= evolutionOffer.Choices)))
			{
				return false;
			}
			p.EvolutionOffers.RemoveAt(0);
			if (!skip)
			{
				p.EvolutionCards++;
			}
			return true;
		}
	}
	public sealed class EvolutionChoiceVisibility
	{
		private Guid session;

		private int run;

		private int epoch;

		private long offer;

		public bool Visible { get; private set; }

		public bool Observe(Guid nextSession, int nextRun, int nextEpoch, long nextOffer)
		{
			if (session == nextSession && run == nextRun && epoch == nextEpoch && offer == nextOffer)
			{
				return false;
			}
			session = nextSession;
			run = nextRun;
			epoch = nextEpoch;
			offer = nextOffer;
			Visible = false;
			return true;
		}

		public void Open()
		{
			if (offer > 0)
			{
				Visible = true;
			}
		}

		public void Defer()
		{
			Visible = false;
		}
	}
	public sealed class FinaleEvidence
	{
		private Guid session;

		private int term;

		private int run;

		private int round;

		private int stage;

		private int actor;

		private string stageKey;

		private FlareIgnition ignition;

		private static bool Playing(HuntSnapshot s)
		{
			if (s != null && !s.FlowOnly)
			{
				if (s.Phase != HuntPhase.Active)
				{
					return s.Phase == HuntPhase.HunterDelay;
				}
				return true;
			}
			return false;
		}

		public static FinaleEvidence Capture(HuntSnapshot state, FlareIgnition ignition, bool alreadySummoned)
		{
			if (ignition == null || !ignition.InRound(state) || !Playing(state) || alreadySummoned)
			{
				return null;
			}
			HuntPlayer huntPlayer = state.Find(ignition.Actor);
			if (huntPlayer == null || !huntPlayer.Connected)
			{
				return null;
			}
			FinaleEvidence finaleEvidence = new FinaleEvidence();
			finaleEvidence.session = state.Session;
			finaleEvidence.term = state.AuthorityTerm;
			finaleEvidence.run = state.Run;
			finaleEvidence.round = state.Round;
			finaleEvidence.stage = state.Stage;
			finaleEvidence.stageKey = state.StageKey;
			finaleEvidence.actor = ignition.Actor;
			finaleEvidence.ignition = ignition;
			return finaleEvidence;
		}

		public bool Complete(HuntSnapshot state, bool summoned, out int igniter)
		{
			igniter = 0;
			if (!summoned || !Playing(state) || state.Session != session || state.AuthorityTerm != term || state.Run != run || state.Round != round || state.Stage != stage || state.StageKey != stageKey)
			{
				return false;
			}
			HuntPlayer huntPlayer = state.Find(actor);
			if (huntPlayer == null || !huntPlayer.Connected || ignition == null || !ignition.InRound(state))
			{
				return false;
			}
			igniter = actor;
			return true;
		}
	}
	public enum FlareSignalKind : byte
	{
		Request = 1,
		Permit,
		Completed,
		Rejected,
		Summit
	}
	public sealed class HuntFlareSignal
	{
		public Guid Session;

		public Guid Identity;

		public int AuthorityTerm;

		public int Run;

		public int Round;

		public int Stage;

		public int ViewId;

		public long Sequence;

		public long RequestId;

		public FlareSignalKind Kind;

		public bool Valid
		{
			get
			{
				if (Session != Guid.Empty && AuthorityTerm > 0 && Run > 0 && Round > 0 && Stage > 0 && ViewId > 0 && Sequence > 0 && RequestId > 0 && Enum.IsDefined(typeof(FlareSignalKind), Kind))
				{
					if (Kind != FlareSignalKind.Summit)
					{
						return Identity != Guid.Empty;
					}
					return Identity == Guid.Empty;
				}
				return false;
			}
		}

		public HuntFlareSignal Clone()
		{
			return (HuntFlareSignal)MemberwiseClone();
		}

		public bool InScope(HuntSnapshot s)
		{
			if (s != null && Session == s.Session && AuthorityTerm == s.AuthorityTerm && Run == s.Run && Round == s.Round)
			{
				return Stage == s.Stage;
			}
			return false;
		}

		public bool SameRequest(HuntFlareSignal other)
		{
			if (other != null && Session == other.Session && AuthorityTerm == other.AuthorityTerm && Run == other.Run && Round == other.Round && Stage == other.Stage && RequestId == other.RequestId && Identity == other.Identity)
			{
				return ViewId == other.ViewId;
			}
			return false;
		}
	}
	public struct NativeFlareBinding
	{
		public bool Valid;

		public bool Active;

		public Guid Identity;

		public int ViewId;

		public int HolderActor;

		public int OwnerActor;
	}
	public sealed class FlareIgnition
	{
		public readonly Guid Identity;

		public readonly Guid Session;

		public readonly int Actor;

		public readonly int AuthorityTerm;

		public readonly int Run;

		public readonly int Round;

		public readonly int Stage;

		public readonly HuntTeam Team;

		internal FlareIgnition(HuntSnapshot s, Guid identity, int actor, HuntTeam team)
		{
			Identity = identity;
			Actor = actor;
			Team = team;
			Session = s.Session;
			AuthorityTerm = s.AuthorityTerm;
			Run = s.Run;
			Round = s.Round;
			Stage = s.Stage;
		}

		public bool InRound(HuntSnapshot s)
		{
			if (Identity != Guid.Empty && Actor > 0 && (Team == HuntTeam.Hunters || Team == HuntTeam.Survivors) && s != null && s.Session == Session && s.AuthorityTerm == AuthorityTerm && s.Run == Run && s.Round == Round)
			{
				return s.Stage >= Stage;
			}
			return false;
		}
	}
	public sealed class FlareIgnitionLedger
	{
		private sealed class Pending
		{
			internal HuntFlareSignal Signal;

			internal int Actor;

			internal HuntTeam Team;

			internal bool Completed;

			internal double Until;
		}

		private readonly Dictionary<Guid, Pending> pending = new Dictionary<Guid, Pending>();

		private readonly Dictionary<Guid, FlareIgnition> records = new Dictionary<Guid, FlareIgnition>();

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

		private Guid session;

		private int term;

		private int run;

		private int round;

		public List<Guid> PendingIdentities => new List<Guid>(pending.Keys);

		public void Clear()
		{
			pending.Clear();
			records.Clear();
			sequences.Clear();
			session = Guid.Empty;
			term = (run = (round = 0));
		}

		private static bool Clock(double now)
		{
			if (!double.IsNaN(now) && !double.IsInfinity(now))
			{
				return now >= 0.0;
			}
			return false;
		}

		public void Scope(HuntSnapshot s, double now)
		{
			if (s == null || s.FlowOnly || !s.Enabled || s.Phase == HuntPhase.Lobby || s.Phase == HuntPhase.Suspended)
			{
				Clear();
				return;
			}
			if (session != s.Session || term != s.AuthorityTerm || run != s.Run || round != s.Round)
			{
				Clear();
				session = s.Session;
				term = s.AuthorityTerm;
				run = s.Run;
				round = s.Round;
			}
			foreach (Guid item in new List<Guid>(pending.Keys))
			{
				if (!pending[item].Signal.InScope(s) || !Clock(now) || now > pending[item].Until)
				{
					pending.Remove(item);
				}
			}
		}

		public bool Authorize(int sender, HuntFlareSignal signal, HuntSnapshot s, NativeFlareBinding native, double now)
		{
			Scope(s, now);
			if (!Clock(now) || !CampfireRules.Playing(s) || signal == null || !signal.Valid || !signal.InScope(s) || signal.Kind != FlareSignalKind.Request || signal.RequestId != signal.Sequence)
			{
				return false;
			}
			if (sequences.TryGetValue(sender, out var value) && signal.Sequence <= value)
			{
				return false;
			}
			sequences[sender] = signal.Sequence;
			HuntPlayer huntPlayer = s.Find(sender);
			if (huntPlayer == null || !huntPlayer.Connected || !huntPlayer.Loaded || huntPlayer.PendingRevive || huntPlayer.Team == HuntTeam.None || s.Locked(sender, now) || !native.Valid || native.Active || native.Identity != signal.Identity || native.ViewId != signal.ViewId || native.HolderActor != sender || native.OwnerActor != sender || records.ContainsKey(signal.Identity) || pending.ContainsKey(signal.Identity))
			{
				return false;
			}
			pending.Add(signal.Identity, new Pending
			{
				Signal = signal.Clone(),
				Actor = sender,
				Team = huntPlayer.Team,
				Until = now + 10.0
			});
			return true;
		}

		public bool Complete(int sender, HuntFlareSignal signal, HuntSnapshot s, double now)
		{
			Scope(s, now);
			if (!Clock(now) || !CampfireRules.Playing(s) || signal == null || !signal.Valid || !signal.InScope(s) || signal.Kind != FlareSignalKind.Completed || !pending.TryGetValue(signal.Identity, out var value) || value.Actor != sender || !value.Signal.SameRequest(signal) || value.Completed)
			{
				return false;
			}
			if (sequences.TryGetValue(sender, out var value2) && signal.Sequence <= value2)
			{
				return false;
			}
			sequences[sender] = signal.Sequence;
			value.Completed = true;
			return true;
		}

		public bool ObserveLit(HuntSnapshot s, Guid identity, bool actuallyLit, double now)
		{
			Scope(s, now);
			if (!actuallyLit || !CampfireRules.Playing(s) || !pending.TryGetValue(identity, out var value) || !value.Completed)
			{
				return false;
			}
			records.Add(identity, new FlareIgnition(s, identity, value.Actor, value.Team));
			pending.Remove(identity);
			return true;
		}

		public FlareIgnition Find(HuntSnapshot s, Guid identity)
		{
			if (!records.TryGetValue(identity, out var value) || !value.InRound(s))
			{
				return null;
			}
			return value;
		}
	}
	public static class SummitRules
	{
		public static bool SameMap(HuntSnapshot s, string nativeRun, int segment)
		{
			if (s != null && !string.IsNullOrEmpty(nativeRun) && segment == 4)
			{
				return s.StageKey == nativeRun + ":" + segment;
			}
			return false;
		}

		public static bool CanEnter(HuntSnapshot s, int actor, bool atPeak)
		{
			HuntPlayer huntPlayer = s?.Find(actor);
			if (atPeak && CampfireRules.Playing(s) && huntPlayer != null && huntPlayer.Connected && !huntPlayer.PendingRevive && huntPlayer.Role == HuntRole.Survivor)
			{
				return !huntPlayer.SummitProtected;
			}
			return false;
		}
	}
	public enum FlowTransition
	{
		None,
		BeginExpedition,
		AdvanceStage,
		ReturnToLobby,
		RestartExpedition
	}
	public static class FlowLifecycle
	{
		public static FlowTransition Decide(HuntSnapshot state, bool airport, bool ready, string nativeRun, string stageKey)
		{
			if (state == null || !state.Enabled || state.Phase == HuntPhase.Suspended)
			{
				return FlowTransition.None;
			}
			if (airport)
			{
				if (state.Phase != HuntPhase.Lobby)
				{
					return FlowTransition.ReturnToLobby;
				}
				return FlowTransition.None;
			}
			if (!ready || string.IsNullOrEmpty(nativeRun) || string.IsNullOrEmpty(stageKey))
			{
				return FlowTransition.None;
			}
			if (state.Phase == HuntPhase.Lobby)
			{
				return FlowTransition.BeginExpedition;
			}
			if (!state.StageKey.StartsWith(nativeRun + ":", StringComparison.Ordinal))
			{
				return FlowTransition.RestartExpedition;
			}
			if ((state.Phase == HuntPhase.Active || state.Phase == HuntPhase.HunterDelay) && stageKey != state.StageKey)
			{
				return FlowTransition.AdvanceStage;
			}
			return FlowTransition.None;
		}
	}
	public struct HuntHudView
	{
		public bool Knife;

		public bool Dart;

		public bool Slowed;

		public bool ClimbCost;

		public bool HunterAura;

		public bool SurvivorAura;

		public double CooldownRemaining;

		public double KnifeCooldownRemaining;

		public float CooldownFraction;

		public float KnifeCooldownFraction;

		public float HunterAuraProgress;

		public float SurvivorAuraProgress;

		public float KnifeProgress => 1f - KnifeCooldownFraction;

		public string KnifeText
		{
			get
			{
				if (!(KnifeCooldownRemaining > 0.0))
				{
					return "猎刀";
				}
				return Math.Ceiling(KnifeCooldownRemaining) + "s";
			}
		}

		public float DartProgress => 1f - CooldownFraction;

		public string DartText
		{
			get
			{
				if (!(CooldownRemaining > 0.0))
				{
					return "吹箭";
				}
				return Math.Ceiling(CooldownRemaining) + "s";
			}
		}
	}
	public static class HuntHudPresentation
	{
		public static HuntHudView Read(HuntSnapshot s, int actor, double now, bool nativeOwnerAvailable)
		{
			HuntHudView result = default(HuntHudView);
			if (!nativeOwnerAvailable || !CampfireRules.Playing(s) || double.IsNaN(now) || double.IsInfinity(now) || now < 0.0)
			{
				return result;
			}
			HuntPlayer huntPlayer = s.Find(actor);
			if (huntPlayer == null || !huntPlayer.Connected || huntPlayer.PendingRevive || huntPlayer.Team == HuntTeam.None)
			{
				return result;
			}
			result.Dart = huntPlayer.WantsDart;
			result.Knife = huntPlayer.WantsKnife;
			if (result.Knife)
			{
				result.KnifeCooldownRemaining = Math.Max(0.0, Math.Min(10.0, huntPlayer.KnifeReadyAt - now));
				result.KnifeCooldownFraction = (float)(result.KnifeCooldownRemaining / 10.0);
			}
			result.HunterAura = huntPlayer.Team == HuntTeam.Hunters;
			result.SurvivorAura = huntPlayer.Role == HuntRole.Survivor;
			result.HunterAuraProgress = (float)huntPlayer.ActiveHunterAllianceLayers(now) / 2f;
			result.SurvivorAuraProgress = (float)huntPlayer.ActiveSurvivorBondLayers(now) / 3f;
			if (result.Dart)
			{
				double num = huntPlayer.DartReadyAt - now;
				if (!double.IsNaN(num) && !double.IsInfinity(num))
				{
					result.CooldownRemaining = Math.Max(0.0, Math.Min(60.0, num));
				}
				result.CooldownFraction = (float)(result.CooldownRemaining / 60.0);
			}
			result.Slowed = LocalCombatEffects.Walking(s, actor, now) < 1f;
			result.ClimbCost = LocalCombatEffects.ClimbingCost(s, actor, now) > 1f;
			return result;
		}

		public static string Identity(HuntSnapshot s, int actor)
		{
			HuntPlayer huntPlayer = s?.Find(actor);
			if (!CampfireRules.Playing(s) || huntPlayer == null || !huntPlayer.Connected || huntPlayer.PendingRevive || huntPlayer.Team == HuntTeam.None)
			{
				return "";
			}
			return "【" + HuntText.Role(huntPlayer.Role) + "】";
		}
	}
	public sealed class HuntEngine
	{
		private readonly HuntSnapshot state;

		private readonly HuntRules rules;

		private ICombatWorld world;

		private readonly Random random;

		private readonly HashSet<string> completedStages = new HashSet<string>();

		private readonly HashSet<string> visitedStages = new HashSet<string>();

		private readonly PetrifyAuthority petrification = new PetrifyAuthority();

		private readonly HuntTraceAuthority traces = new HuntTraceAuthority();

		private readonly PropUseJournal props = new PropUseJournal();

		private double nextAuraSampleAt;

		public HuntSnapshot Snapshot => state.Clone();

		public HuntPhase Phase => state.Phase;

		public long Revision => state.Revision;

		public bool Enabled => state.Enabled;

		public int HostActor => state.HostActor;

		public HuntEngine(int hostActor, HuntRules rules, ICombatWorld world, int seed)
		{
			if (hostActor <= 0 || rules == null || world == null)
			{
				throw new ArgumentException("Invalid host or dependency");
			}
			this.rules = rules;
			this.world = world;
			random = new Random(seed);
			state = new HuntSnapshot
			{
				Session = Guid.NewGuid(),
				HostActor = hostActor,
				AuthorityTerm = 1,
				Phase = HuntPhase.Disabled
			};
		}

		private HuntEngine(HuntSnapshot prior, int newHost, HuntRules rules, ICombatWorld world, int seed)
		{
			this.rules = rules;
			this.world = world;
			random = new Random(seed);
			state = prior.Clone();
			state.HostActor = newHost;
			state.AuthorityTerm++;
			state.Revision++;
			state.Traces.Clear();
			if (state.Enabled)
			{
				state.Phase = HuntPhase.Suspended;
			}
		}

		public static HuntEngine SuspendForNewHost(HuntSnapshot prior, int newHost, HuntRules rules, ICombatWorld world, int seed)
		{
			if (prior == null || newHost <= 0 || rules == null || world == null)
			{
				throw new ArgumentException("Invalid migration");
			}
			return new HuntEngine(prior, newHost, rules, world, seed);
		}

		public bool SetCombatWorld(int issuer, ICombatWorld value)
		{
			if (!Host(issuer) || state.Enabled || value == null)
			{
				return false;
			}
			world = value;
			return true;
		}

		public bool SetFlowOnly(int issuer, bool value)
		{
			if (!Host(issuer) || state.Enabled)
			{
				return false;
			}
			state.FlowOnly = value;
			state.Revision++;
			return true;
		}

		public CommandResult Suspend(int issuer, double now)
		{
			Clock(now);
			if (!Host(issuer) || !state.Enabled)
			{
				return No("host-only-or-disabled");
			}
			state.Phase = HuntPhase.Suspended;
			return Yes();
		}

		private double Clock(double now)
		{
			if (double.IsNaN(now) || double.IsInfinity(now) || now < 0.0)
			{
				throw new ArgumentOutOfRangeException("now");
			}
			if (now > state.ServerTime)
			{
				state.ServerTime = now;
			}
			return state.ServerTime;
		}

		private CommandResult No(string code)
		{
			return new CommandResult(accepted: false, code, state.Revision, duplicate: false);
		}

		private CommandResult Yes()
		{
			HuntTraceRules.Prune(state, state.ServerTime);
			state.Revision++;
			return new CommandResult(accepted: true, "ok", state.Revision, duplicate: false);
		}

		private bool Host(int actor)
		{
			if (actor == state.HostActor)
			{
				return actor > 0;
			}
			return false;
		}

		public CommandResult UpsertPlayer(int issuer, int actor, string name, bool connected, bool loaded, double now)
		{
			Clock(now);
			if (!Host(issuer) || actor <= 0)
			{
				return No("host-only");
			}
			HuntPlayer huntPlayer = state.Find(actor);
			if (huntPlayer == null)
			{
				if (state.Players.Count >= 256)
				{
					return No("player-limit");
				}
				HuntPlayer huntPlayer2 = new HuntPlayer();
				huntPlayer2.Actor = actor;
				huntPlayer2.Name = SafeName(name);
				huntPlayer = huntPlayer2;
				if (state.Phase != HuntPhase.Disabled && state.Phase != HuntPhase.Lobby && state.Phase != HuntPhase.AwaitingVote)
				{
					huntPlayer.Role = HuntRole.Spectator;
				}
				state.Players.Add(huntPlayer);
				state.Players.Sort((HuntPlayer a, HuntPlayer b) => a.Actor.CompareTo(b.Actor));
			}
			else if (huntPlayer.Connected == connected && huntPlayer.Loaded == loaded && huntPlayer.Name == SafeName(name))
			{
				return No("unchanged");
			}
			huntPlayer.Name = SafeName(name);
			huntPlayer.Connected = connected;
			huntPlayer.Loaded = loaded;
			return Yes();
		}

		private static string SafeName(string name)
		{
			name = name ?? "";
			if (name.Length <= 40)
			{
				return name;
			}
			return name.Substring(0, 40);
		}

		public CommandResult SetEnabled(int issuer, bool enabled, double now)
		{
			Clock(now);
			if (!Host(issuer))
			{
				return No("host-only");
			}
			if (enabled == state.Enabled)
			{
				return No("unchanged");
			}
			state.Phase = (enabled ? HuntPhase.Lobby : HuntPhase.Disabled);
			state.Votes.Clear();
			state.EligibleVoters.Clear();
			state.HuntersReleaseAt = 0.0;
			state.VoteClosesAt = 0.0;
			state.ResultClosesAt = 0.0;
			state.BackpackVoteId = 0;
			foreach (HuntPlayer player in state.Players)
			{
				ResetPlayer(player, clearInventory: true, cancelNative: true);
			}
			EvolutionRules.Reset(state, newRun: true);
			return Yes();
		}

		public CommandResult BeginExpedition(int issuer, string firstStage, double now)
		{
			Clock(now);
			if (!Host(issuer))
			{
				return No("host-only");
			}
			if (state.Phase != HuntPhase.Lobby && state.Phase != HuntPhase.Finished)
			{
				return No("wrong-phase");
			}
			if (!ValidStage(firstStage))
			{
				return No("stage-key-required-or-too-long");
			}
			state.Run++;
			state.Round = 1;
			state.Stage = 1;
			state.StageKey = firstStage;
			state.Winner = HuntTeam.None;
			state.BackpackVoteId = 0;
			state.HunterScore = (state.SurvivorScore = 0);
			state.ResultClosesAt = 0.0;
			state.Phase = HuntPhase.AwaitingVote;
			state.Votes.Clear();
			state.EligibleVoters.Clear();
			completedStages.Clear();
			visitedStages.Clear();
			visitedStages.Add(firstStage);
			foreach (HuntPlayer player in state.Players)
			{
				ResetPlayer(player, clearInventory: true, cancelNative: true);
			}
			EvolutionRules.Reset(state, newRun: true);
			return Yes();
		}

		private void ResetPlayer(HuntPlayer p, bool clearInventory, bool cancelNative = false)
		{
			p.SoundCues.Clear();
			p.SoundSequence = 0L;
			p.Role = HuntRole.Unassigned;
			ResetPetrify(p, 0f, initialized: false);
			p.DeathCurseTotal = 0f;
			p.CampProtected = (p.SummitProtected = false);
			p.CampProtectionStage = 0;
			p.BurstUntil = (p.PendingBurstAt = (p.DebuffUntil = (p.KnifeReadyAt = (p.DartReadyAt = (p.SoilUntil = 0.0)))));
			ResetAura(p, staminaGrants: true);
			p.LoadoutVersion++;
			if (cancelNative)
			{
				p.PendingRevive = false;
				p.ReviveVersion++;
			}
			if (clearInventory)
			{
				p.InventoryResetVersion++;
			}
		}

		private static void ResetAura(HuntPlayer p, bool staminaGrants)
		{
			p.HunterAllianceLayers = (p.SurvivorBondLayers = 0);
			p.HunterAllianceUntil = (p.SurvivorBondUntil = 0.0);
			if (staminaGrants)
			{
				p.SurvivorBondStaminaGrants = 0;
			}
		}

		private static bool ValidStage(string value)
		{
			if (!string.IsNullOrWhiteSpace(value) && value.Length <= 64)
			{
				return value.IndexOfAny(new char[3] { '\r', '\n', '\0' }) < 0;
			}
			return false;
		}

		public CommandResult OpenVote(int issuer, double now)
		{
			now = Clock(now);
			if (!Host(issuer))
			{
				return No("host-only");
			}
			if (state.Phase != HuntPhase.AwaitingVote)
			{
				return No("wrong-phase");
			}
			List<HuntPlayer> list = state.Players.FindAll((HuntPlayer p) => p.Connected);
			if (list.Count < 1)
			{
				return No("need-one-player");
			}
			if (list.Exists((HuntPlayer p) => !p.Loaded || p.PendingRevive))
			{
				return No("waiting-for-loaded-peers");
			}
			state.VoteId++;
			state.Votes.Clear();
			state.EligibleVoters.Clear();
			foreach (HuntPlayer item in list)
			{
				state.EligibleVoters.Add(item.Actor);
				item.Role = HuntRole.Unassigned;
			}
			state.VoteClosesAt = now + rules.VoteSeconds;
			state.Phase = HuntPhase.Voting;
			return Yes();
		}

		public CommandResult Execute(int authenticatedActor, HuntCommand command, double now)
		{
			now = Clock(now);
			if (command == null)
			{
				return No("empty-command");
			}
			if (command.Session != state.Session || command.AuthorityTerm != state.AuthorityTerm || command.Run != state.Run || command.Round != state.Round || command.Stage != state.Stage)
			{
				return No("stale-session-or-stage");
			}
			HuntPlayer huntPlayer = state.Find(authenticatedActor);
			if (huntPlayer == null || !huntPlayer.Connected || !huntPlayer.Loaded)
			{
				return No("unknown-or-unready-peer");
			}
			if (command.Sequence <= 0)
			{
				return No("bad-sequence");
			}
			if (command.Sequence <= huntPlayer.LastCommandSequence)
			{
				return new CommandResult(accepted: false, "already-processed", state.Revision, duplicate: true);
			}
			huntPlayer.LastCommandSequence = command.Sequence;
			state.Revision++;
			if (command.Kind == CommandKind.OpenVote)
			{
				return OpenVote(authenticatedActor, now);
			}
			if (command.Kind == CommandKind.EvolutionPick || command.Kind == CommandKind.EvolutionSkip)
			{
				if (!EvolutionRules.Choose(state, huntPlayer, command.CastId, command.TargetActor, command.Kind == CommandKind.EvolutionSkip))
				{
					return No("evolution-offer-expired");
				}
				return Yes();
			}
			if (command.Kind == CommandKind.EvolutionBegin || command.Kind == CommandKind.EvolutionOpen || command.Kind == CommandKind.EvolutionCancel)
			{
				if (!EvolutionRules.Playing(state) || state.Locked(authenticatedActor, now) || huntPlayer.Team == HuntTeam.None || command.TargetActor <= 0)
				{
					return No("evolution-interaction-unavailable");
				}
				return Yes();
			}
			if (command.Kind == CommandKind.Vote)
			{
				if (state.Phase != HuntPhase.Voting || command.VoteId != state.VoteId || now >= state.VoteClosesAt || !state.EligibleVoters.Contains(authenticatedActor))
				{
					return No("vote-closed-or-ineligible");
				}
				state.Votes[authenticatedActor] = command.Agree;
				if (AllVoted())
				{
					FinishVote(now);
				}
				return Yes();
			}
			if (command.Kind != CommandKind.KnifeHit && command.Kind != CommandKind.DartShot)
			{
				return No("unknown-command");
			}
			if (state.FlowOnly)
			{
				return No("flow-test-no-combat");
			}
			if (state.Phase != HuntPhase.Active && state.Phase != HuntPhase.HunterDelay)
			{
				return No("not-playing");
			}
			if (state.Locked(authenticatedActor, now) || huntPlayer.Team != HuntTeam.Hunters)
			{
				return No("attacker-locked-or-wrong-team");
			}
			if (command.Kind == CommandKind.DartShot)
			{
				return FireDart(huntPlayer, command.TargetActor, now);
			}
			return SwingKnife(huntPlayer, command.TargetActor, now);
		}

		private bool NativeBlocks(HuntPlayer target, double now)
		{
			if (!(world is INativeCombatProtectionWorld nativeCombatProtectionWorld) || !nativeCombatProtectionWorld.NativeInvincible(target.Actor))
			{
				return false;
			}
			StartBurst(target, now);
			return true;
		}

		private CommandResult SwingKnife(HuntPlayer sender, int reportedTarget, double now)
		{
			if (!sender.WantsKnife || now < sender.KnifeReadyAt)
			{
				return No("no-knife-or-cooldown");
			}
			int actualTarget = reportedTarget;
			if (!((world is IKnifeCombatWorld knifeCombatWorld) ? knifeCombatWorld.ValidateKnifeSwing(sender.Actor, out actualTarget, out var reason) : world.ValidateAttack(sender.Actor, reportedTarget, HuntWeapon.Knife, out reason)))
			{
				return No("native-validation:" + (reason ?? "denied"));
			}
			sender.KnifeReadyAt = now + 10.0;
			HuntPlayer huntPlayer = state.Find(actualTarget);
			if (huntPlayer == null || !huntPlayer.Connected || !huntPlayer.Loaded || huntPlayer.Role != HuntRole.Survivor || huntPlayer.PendingRevive || huntPlayer.Actor == sender.Actor)
			{
				return Yes();
			}
			if (NativeBlocks(huntPlayer, now) || state.Protected(huntPlayer.Actor, now))
			{
				return Yes();
			}
			if (!world.TryGetPosition(huntPlayer.Actor, out var position) || !position.IsFinite)
			{
				return Yes();
			}
			float petrify = huntPlayer.Petrify;
			ApplyPetrify(huntPlayer, (sender.ActiveHunterAllianceLayers(now) >= 2) ? 50f : 40f, position, now);
			EvolutionRules.Damage(state, sender, huntPlayer.Petrify - petrify);
			if (huntPlayer.Petrify > petrify)
			{
				CombatSoundRules.Emit(state, huntPlayer, HuntSoundKind.SurvivorKnife, now);
				CombatSoundRules.Emit(state, sender, HuntSoundKind.HunterKnife, now);
			}
			return Yes();
		}

		private CommandResult FireDart(HuntPlayer sender, int reportedTarget, double now)
		{
			if (!sender.WantsDart || now < sender.DartReadyAt)
			{
				return No("no-dart-or-cooldown");
			}
			if (!world.ValidateDartShot(sender.Actor, reportedTarget, out var actualTarget, out var reason))
			{
				return No("native-shot-validation:" + (reason ?? "denied"));
			}
			sender.DartReadyAt = now + 60.0;
			HuntPlayer huntPlayer = state.Find(actualTarget);
			if (huntPlayer == null || huntPlayer.Actor == sender.Actor || !huntPlayer.Connected || !huntPlayer.Loaded || huntPlayer.Role != HuntRole.Survivor || huntPlayer.PendingRevive)
			{
				return Yes();
			}
			if (NativeBlocks(huntPlayer, now) || state.Protected(huntPlayer.Actor, now))
			{
				return Yes();
			}
			if (!world.TryGetPosition(huntPlayer.Actor, out var position) || !position.IsFinite)
			{
				return Yes();
			}
			float petrify = huntPlayer.Petrify;
			ApplyPetrify(huntPlayer, 10f, position, now);
			EvolutionRules.Damage(state, sender, huntPlayer.Petrify - petrify);
			huntPlayer.DebuffUntil = now + 5.0;
			if (huntPlayer.Petrify > petrify)
			{
				CombatSoundRules.Emit(state, huntPlayer, HuntSoundKind.SurvivorDart, now);
			}
			return Yes();
		}

		private bool AllVoted()
		{
			foreach (int eligibleVoter in state.EligibleVoters)
			{
				HuntPlayer huntPlayer = state.Find(eligibleVoter);
				if (huntPlayer != null && huntPlayer.Connected && !state.Votes.ContainsKey(eligibleVoter))
				{
					return false;
				}
			}
			return true;
		}

		private void FinishVote(double now)
		{
			state.BackpackVoteId = 0;
			List<int> list = state.EligibleVoters.FindAll(delegate(int actor)
			{
				HuntPlayer huntPlayer = state.Find(actor);
				return huntPlayer != null && huntPlayer.Connected && huntPlayer.Loaded;
			});
			if (list.Count < 1)
			{
				state.Phase = HuntPhase.AwaitingVote;
				state.Votes.Clear();
				return;
			}
			List<int> list2 = new List<int>();
			List<int> list3 = new List<int>();
			foreach (int item in list)
			{
				if (state.Votes.TryGetValue(item, out var value) && value)
				{
					list2.Add(item);
				}
				else
				{
					list3.Add(item);
				}
			}
			Shuffle(list2);
			Shuffle(list3);
			int num = ((list.Count < 6) ? 1 : 2);
			List<int> list4 = new List<int>();
			foreach (int item2 in list2)
			{
				if (list4.Count < num)
				{
					list4.Add(item2);
				}
			}
			foreach (int item3 in list3)
			{
				if (list4.Count < num)
				{
					list4.Add(item3);
				}
			}
			foreach (HuntPlayer player in state.Players)
			{
				if (!list.Contains(player.Actor))
				{
					if (player.Connected)
					{
						player.Role = HuntRole.Spectator;
					}
					continue;
				}
				player.Role = ((!list4.Contains(player.Actor)) ? HuntRole.Survivor : HuntRole.Hunter);
				player.CampProtected = (player.SummitProtected = false);
				player.CampProtectionStage = 0;
				player.BurstUntil = (player.PendingBurstAt = (player.DebuffUntil = (player.KnifeReadyAt = (player.DartReadyAt = (player.SoilUntil = 0.0)))));
				player.LoadoutVersion++;
				ResetAura(player, staminaGrants: true);
			}
			state.BackpackVoteId = state.VoteId;
			state.Phase = HuntPhase.HunterDelay;
			state.HuntersReleaseAt = now + 30.0;
		}

		private void Shuffle(List<int> list)
		{
			for (int num = list.Count - 1; num > 0; num--)
			{
				int index = random.Next(num + 1);
				int value = list[num];
				list[num] = list[index];
				list[index] = value;
			}
		}

		public void Tick(double now)
		{
			now = Clock(now);
			if (state.Phase == HuntPhase.Voting && (now >= state.VoteClosesAt || AllVoted()))
			{
				FinishVote(now);
				state.Revision++;
			}
			if (state.Phase == HuntPhase.HunterDelay && now >= state.HuntersReleaseAt)
			{
				state.Phase = HuntPhase.Active;
				foreach (HuntPlayer player in state.Players)
				{
					if (player.CampProtectionStage < state.Stage)
					{
						player.CampProtected = false;
						player.CampProtectionStage = 0;
					}
				}
				state.Revision++;
			}
			foreach (HuntPlayer player2 in state.Players)
			{
				if (player2.PendingBurstAt > 0.0)
				{
					if (!CampfireRules.Playing(state) || !player2.Connected || player2.PendingRevive || player2.Role != HuntRole.Survivor)
					{
						player2.PendingBurstAt = 0.0;
						state.Revision++;
					}
					else if (now >= player2.PendingBurstAt)
					{
						StartBurst(player2, player2.PendingBurstAt);
						state.Revision++;
					}
				}
			}
		}

		public bool RefreshTraces(int issuer, IHuntTraceWorld observations, double now)
		{
			if (!Host(issuer))
			{
				return false;
			}
			now = Clock(now);
			bool flag = traces.Step(state, observations, now);
			if (flag)
			{
				state.Revision++;
			}
			return flag;
		}

		public CommandResult RefreshProximityAuras(int issuer, IList<HuntAuraObservation> observations, double now)
		{
			now = Clock(now);
			if (!Host(issuer))
			{
				return No("host-only");
			}
			if (state.Phase != HuntPhase.Active || state.FlowOnly)
			{
				return No("not-active");
			}
			if (now < nextAuraSampleAt)
			{
				return No("aura-sample-too-soon");
			}
			nextAuraSampleAt = now + 3.0;
			Dictionary<int, HuntPosition> dictionary = new Dictionary<int, HuntPosition>();
			if (observations != null)
			{
				foreach (HuntAuraObservation observation in observations)
				{
					HuntPlayer huntPlayer = state.Find(observation.Actor);
					if (huntPlayer != null && huntPlayer.Connected && huntPlayer.Loaded && !huntPlayer.PendingRevive && huntPlayer.Team != HuntTeam.None)
					{
						HuntPosition position = observation.Position;
						if (position.IsFinite && !dictionary.ContainsKey(observation.Actor))
						{
							dictionary.Add(observation.Actor, observation.Position);
						}
					}
				}
			}
			foreach (HuntPlayer player in state.Players)
			{
				if (player.HunterAllianceUntil <= now)
				{
					player.HunterAllianceLayers = 0;
					player.HunterAllianceUntil = 0.0;
				}
				if (player.SurvivorBondUntil <= now)
				{
					player.SurvivorBondLayers = 0;
					player.SurvivorBondUntil = 0.0;
				}
				if (!player.Connected || !player.Loaded || player.PendingRevive || player.Team == HuntTeam.None || !dictionary.TryGetValue(player.Actor, out var value))
				{
					ResetAura(player, staminaGrants: false);
					continue;
				}
				int num = 0;
				int num2 = 0;
				foreach (KeyValuePair<int, HuntPosition> item in dictionary)
				{
					if (item.Key == player.Actor)
					{
						continue;
					}
					HuntPlayer huntPlayer2 = state.Find(item.Key);
					if (huntPlayer2 != null)
					{
						double num3 = value.X - item.Value.X;
						double num4 = value.Y - item.Value.Y;
						double num5 = value.Z - item.Value.Z;
						double num6 = num3 * num3 + num4 * num4 + num5 * num5;
						if (player.Team == HuntTeam.Hunters && huntPlayer2.Team == HuntTeam.Hunters && num6 <= 225.0)
						{
							num++;
						}
						else if (player.Role == HuntRole.Survivor && huntPlayer2.Role == HuntRole.Survivor && num6 <= 100.0)
						{
							num2++;
						}
					}
				}
				if (player.Team == HuntTeam.Hunters)
				{
					if (num > 0)
					{
						player.HunterAllianceLayers = Math.Min(2, num);
						player.HunterAllianceUntil = now + 4.0;
					}
				}
				else if (player.Role == HuntRole.Survivor)
				{
					if (num2 > 0)
					{
						player.SurvivorBondLayers = Math.Min(3, num2);
						player.SurvivorBondUntil = now + 4.0;
					}
					if (num2 >= 3 && player.SurvivorBondStaminaGrants < int.MaxValue)
					{
						player.SurvivorBondStaminaGrants++;
					}
				}
			}
			return Yes();
		}

		public CommandResult BallImpact(int issuer, int thrower, int target, HuntPropKind kind, Guid identity, string expectedStage, double now)
		{
			now = Clock(now);
			if (!Host(issuer))
			{
				return No("host-only");
			}
			if (!CampfireRules.Playing(state) || expectedStage != state.StageKey || !PropRules.Ball(kind))
			{
				return No("stale-ball-impact");
			}
			HuntPlayer huntPlayer = state.Find(thrower);
			HuntPlayer huntPlayer2 = state.Find(target);
			if (huntPlayer == null || !huntPlayer.Connected || huntPlayer.Team == HuntTeam.None)
			{
				return No("ball-source-unavailable");
			}
			if (target != 0 && (huntPlayer2 == null || !huntPlayer2.Connected || huntPlayer2.PendingRevive || huntPlayer2.Team == HuntTeam.None))
			{
				return No("ball-target-unavailable");
			}
			if (!props.Take(state, identity))
			{
				return No("ball-already-spent-or-invalid");
			}
			if (huntPlayer2 != null && !huntPlayer.PendingRevive && !state.Protected(huntPlayer2.Actor, now) && kind == HuntPropKind.SoilBall)
			{
				huntPlayer2.SoilUntil = now + 10.0;
			}
			return Yes();
		}

		private void SetPetrifyBalance(HuntPlayer p, float amount)
		{
			p.Petrify = Math.Max(0f, Math.Min(100f, amount));
			p.PetrifyVersion++;
			petrification.Remember(p);
		}

		private void ResetPetrify(HuntPlayer p, float amount, bool initialized)
		{
			p.PetrifyEpoch++;
			p.PetrifyVersion++;
			p.Petrify = amount;
			p.PetrifyInitialized = initialized;
			petrification.Reset(p);
		}

		private void ApplyPetrify(HuntPlayer target, float amount, HuntPosition position, double now, bool singleGain = true)
		{
			float petrify = target.Petrify;
			SetPetrifyBalance(target, target.Petrify + amount);
			if (singleGain && target.Role == HuntRole.Survivor && target.Petrify - petrify >= 35f)
			{
				QueueBurst(target, now);
			}
			if (target.Petrify >= 100f)
			{
				if (target.Role == HuntRole.FalseHunter)
				{
					target.DeathCurseTotal += 10f;
				}
				target.CampProtected = (target.SummitProtected = false);
				target.CampProtectionStage = 0;
				EvolutionRules.ClearCards(target);
				target.Role = HuntRole.FalseHunter;
				target.PendingRevive = true;
				target.ReviveVersion++;
				target.PendingBurstAt = (target.BurstUntil = 0.0);
				target.RevivePosition = position.Above(2f);
				target.LoadoutVersion++;
			}
		}

		private static void QueueBurst(HuntPlayer target, double now)
		{
			if (!target.PendingRevive && target.Role == HuntRole.Survivor && now >= target.BurstUntil && target.PendingBurstAt == 0.0)
			{
				target.PendingBurstAt = now + 1.0;
			}
		}

		private void StartBurst(HuntPlayer target, double now)
		{
			target.PendingBurstAt = 0.0;
			target.BurstUntil = now + 5.0;
			CombatSoundRules.Emit(state, target, HuntSoundKind.SurvivorBurst, now);
		}

		public CommandResult NativePetrify(int issuer, int targetActor, float points, double now)
		{
			now = Clock(now);
			if (!Host(issuer))
			{
				return No("host-only");
			}
			if (state.FlowOnly)
			{
				return No("flow-test-no-combat");
			}
			if (state.Phase != HuntPhase.Active && state.Phase != HuntPhase.HunterDelay)
			{
				return No("not-playing");
			}
			HuntPlayer huntPlayer = state.Find(targetActor);
			if (huntPlayer == null || !huntPlayer.Connected || !huntPlayer.Loaded || huntPlayer.Role != HuntRole.Survivor || huntPlayer.PendingRevive || state.Protected(huntPlayer.Actor, now) || points <= 0f || float.IsNaN(points) || float.IsInfinity(points))
			{
				return No("status-rejected");
			}
			if (!world.TryGetPosition(targetActor, out var position) || !position.IsFinite)
			{
				return No("position-unavailable");
			}
			ApplyPetrify(huntPlayer, points, position, now);
			return Yes();
		}

		public CommandResult ConfirmRevive(int issuer, int actor, int run, int token, double now)
		{
			Clock(now);
			if (!Host(issuer))
			{
				return No("host-only");
			}
			HuntPlayer huntPlayer = state.Find(actor);
			if (run != state.Run || huntPlayer == null || !huntPlayer.PendingRevive || huntPlayer.ReviveVersion != token)
			{
				return No("stale-revive");
			}
			huntPlayer.PendingRevive = false;
			ResetPetrify(huntPlayer, 0f, initialized: true);
			return Yes();
		}

		public CommandResult NativeDeath(int issuer, int actor, double now)
		{
			Clock(now);
			if (!Host(issuer))
			{
				return No("host-only");
			}
			if (state.FlowOnly)
			{
				return No("flow-test-no-combat");
			}
			if (state.Phase != HuntPhase.Active && state.Phase != HuntPhase.HunterDelay)
			{
				return No("not-playing");
			}
			HuntPlayer huntPlayer = state.Find(actor);
			if (huntPlayer == null || !huntPlayer.Connected || (huntPlayer.Role != HuntRole.Survivor && huntPlayer.Role != HuntRole.Hunter && huntPlayer.Role != HuntRole.FalseHunter) || huntPlayer.PendingRevive)
			{
				return No("not-participant-or-already-converting");
			}
			if (!world.TryGetPosition(actor, out var position) || !position.IsFinite || !position.Above(2f).IsFinite)
			{
				return No("position-unavailable");
			}
			if (huntPlayer.Role == HuntRole.FalseHunter)
			{
				huntPlayer.DeathCurseTotal += 10f;
			}
			huntPlayer.CampProtected = (huntPlayer.SummitProtected = false);
			huntPlayer.CampProtectionStage = 0;
			EvolutionRules.ClearCards(huntPlayer);
			huntPlayer.Role = HuntRole.FalseHunter;
			huntPlayer.PendingRevive = true;
			huntPlayer.PendingBurstAt = (huntPlayer.BurstUntil = 0.0);
			huntPlayer.ReviveVersion++;
			huntPlayer.RevivePosition = position.Above(2f);
			huntPlayer.LoadoutVersion++;
			return Yes();
		}

		public CommandResult NativeReviveDeath(int issuer, int actor, int run, int token, double now)
		{
			Clock(now);
			if (!Host(issuer))
			{
				return No("host-only");
			}
			if (state.FlowOnly)
			{
				return No("flow-test-no-combat");
			}
			if (state.Phase != HuntPhase.Active && state.Phase != HuntPhase.HunterDelay && state.Phase != HuntPhase.AwaitingVote)
			{
				return No("not-playing");
			}
			HuntPlayer huntPlayer = state.Find(actor);
			if (run != state.Run || huntPlayer == null || !huntPlayer.Connected || !huntPlayer.PendingRevive || huntPlayer.ReviveVersion != token)
			{
				return No("stale-revive");
			}
			if (!world.TryGetPosition(actor, out var position) || !position.IsFinite || !position.Above(2f).IsFinite)
			{
				return No("position-unavailable");
			}
			huntPlayer.DeathCurseTotal += 10f;
			ResetPetrify(huntPlayer, 0f, initialized: true);
			huntPlayer.ReviveVersion++;
			huntPlayer.RevivePosition = position.Above(2f);
			huntPlayer.LoadoutVersion++;
			return Yes();
		}

		public CommandResult ConvertFalseHunter(int issuer, int actor, double now)
		{
			now = Clock(now);
			if (!Host(issuer))
			{
				return No("host-only");
			}
			if (!state.Enabled || state.FlowOnly)
			{
				return No("full-mode-only");
			}
			if (state.Phase != HuntPhase.Active && state.Phase != HuntPhase.HunterDelay)
			{
				return No("not-playing");
			}
			HuntPlayer huntPlayer = state.Find(actor);
			if (huntPlayer == null || !huntPlayer.Connected || !huntPlayer.Loaded || huntPlayer.PendingRevive || huntPlayer.Role != HuntRole.FalseHunter)
			{
				return No("not-false-hunter");
			}
			EvolutionRules.ClearCards(huntPlayer);
			huntPlayer.Role = HuntRole.Survivor;
			ResetPetrify(huntPlayer, 0f, initialized: true);
			huntPlayer.PendingRevive = false;
			huntPlayer.LoadoutVersion++;
			state.Revision++;
			return Yes();
		}

		public CommandResult ObserveNativePetrify(int issuer, int authenticatedActor, HuntPetrifyReport report, double now)
		{
			now = Clock(now);
			if (!Host(issuer))
			{
				return No("host-only");
			}
			if (state.FlowOnly || !state.Enabled || state.Phase == HuntPhase.Lobby || state.Phase == HuntPhase.Suspended || state.Phase == HuntPhase.Finished)
			{
				return No("native-status-inactive");
			}
			HuntPlayer huntPlayer = state.Find(authenticatedActor);
			if (huntPlayer == null || !huntPlayer.Connected || report == null || !report.InScope(state))
			{
				return No("stale-native-status");
			}
			HuntPosition position = default(HuntPosition);
			if (!report.Baseline && (!world.TryGetPosition(authenticatedActor, out position) || !position.IsFinite))
			{
				return No("position-unavailable");
			}
			PetrifyDecision petrifyDecision = petrification.Observe(huntPlayer, report, state.Protected(huntPlayer.Actor, now));
			if (petrifyDecision == null)
			{
				return No("native-status-proof-rejected");
			}
			huntPlayer.PetrifyNativeAck = report.Sequence;
			if (petrifyDecision.Baseline)
			{
				huntPlayer.PetrifyInitialized = true;
				SetPetrifyBalance(huntPlayer, report.After);
				petrification.Reset(huntPlayer);
			}
			else if (petrifyDecision.Delta > 0 && huntPlayer.Team != HuntTeam.None)
			{
				if (petrifyDecision.Burst && huntPlayer.Role == HuntRole.Survivor)
				{
					QueueBurst(huntPlayer, now);
				}
				ApplyPetrify(huntPlayer, petrifyDecision.Delta, position, now, singleGain: false);
			}
			else if (petrifyDecision.Delta != 0)
			{
				SetPetrifyBalance(huntPlayer, huntPlayer.Petrify + (float)petrifyDecision.Delta);
			}
			return Yes();
		}

		public CommandResult ReturnToLobby(int issuer, double now)
		{
			Clock(now);
			if (!Host(issuer) || !state.Enabled)
			{
				return No("host-only-or-disabled");
			}
			state.Phase = HuntPhase.Lobby;
			state.StageKey = "";
			state.Votes.Clear();
			state.EligibleVoters.Clear();
			state.HuntersReleaseAt = (state.VoteClosesAt = (state.ResultClosesAt = 0.0));
			foreach (HuntPlayer player in state.Players)
			{
				ResetPlayer(player, clearInventory: true, cancelNative: true);
			}
			EvolutionRules.Reset(state, newRun: true);
			return Yes();
		}

		public CommandResult EnterSafeCamp(int issuer, int actor, double distance, bool isLit, string stageKey, double now)
		{
			return EnterSafeCamp(issuer, actor, distance, isLit, stageKey, default(HuntPosition), now);
		}

		public CommandResult EnterSafeCamp(int issuer, int actor, double distance, bool isLit, string stageKey, HuntPosition campPosition, double now)
		{
			Clock(now);
			if (!Host(issuer))
			{
				return No("host-only");
			}
			if (state.FlowOnly)
			{
				return No("flow-test-no-camp-protection");
			}
			if ((state.Phase != HuntPhase.Active && state.Phase != HuntPhase.HunterDelay) || stageKey != state.StageKey)
			{
				return No("wrong-stage");
			}
			HuntPlayer huntPlayer = state.Find(actor);
			if (huntPlayer == null || !huntPlayer.Connected || huntPlayer.PendingRevive || huntPlayer.Team == HuntTeam.None || (huntPlayer.CampProtected && huntPlayer.CampProtectionStage >= state.Stage) || isLit || !campPosition.IsFinite || double.IsNaN(distance) || distance < 0.0 || distance > 10.0)
			{
				return No("not-safe-camp");
			}
			huntPlayer.CampProtected = true;
			huntPlayer.CampProtectionStage = state.Stage;
			huntPlayer.CampProtectionPosition = campPosition;
			EvolutionRules.Camp(state, huntPlayer);
			return Yes();
		}

		public CommandResult LeaveSafeCamp(int issuer, int actor, HuntPosition position, string stageKey, double now)
		{
			Clock(now);
			if (!Host(issuer))
			{
				return No("host-only");
			}
			if (!CampfireRules.Playing(state) || stageKey != state.StageKey)
			{
				return No("wrong-stage");
			}
			HuntPlayer huntPlayer = state.Find(actor);
			if (!CampfireRules.OutsideProtection(huntPlayer, position))
			{
				return No("inside-camp-protection");
			}
			huntPlayer.CampProtected = false;
			huntPlayer.CampProtectionStage = 0;
			return Yes();
		}

		public CommandResult EvolutionOpened(int issuer, int actor, int view, EvolutionSource? special, string expectedStage, double now)
		{
			Clock(now);
			if (!Host(issuer) || expectedStage != state.StageKey)
			{
				return No("host-only-or-stale-evolution");
			}
			if (!EvolutionRules.Open(state, actor, view, special))
			{
				return No("evolution-object-already-used");
			}
			return Yes();
		}

		private void ScoreCurrentStage()
		{
			ScoreCurrentStage((state.SurvivorCount <= 0) ? HuntTeam.Hunters : HuntTeam.Survivors);
		}

		private void ScoreCurrentStage(HuntTeam pointWinner)
		{
			string item = state.Run + ":" + state.Stage + ":" + state.StageKey;
			if (completedStages.Add(item))
			{
				if (pointWinner == HuntTeam.Survivors)
				{
					state.SurvivorScore++;
				}
				else
				{
					state.HunterScore++;
				}
			}
		}

		public CommandResult EnterSummit(int issuer, int actor, bool nativeAtPeak, string expectedStage, double now)
		{
			Clock(now);
			if (!Host(issuer))
			{
				return No("host-only");
			}
			if (expectedStage != state.StageKey || !SummitRules.CanEnter(state, actor, nativeAtPeak))
			{
				return No("not-summit-survivor");
			}
			state.Find(actor).SummitProtected = true;
			return Yes();
		}

		public CommandResult AdvanceStage(int issuer, string expectedCurrent, string nextStage, double now)
		{
			now = Clock(now);
			if (!Host(issuer))
			{
				return No("host-only");
			}
			if ((state.Phase != HuntPhase.Active && state.Phase != HuntPhase.HunterDelay) || expectedCurrent != state.StageKey || !ValidStage(nextStage) || nextStage == state.StageKey)
			{
				return No("stale-stage-event");
			}
			if (visitedStages.Contains(nextStage))
			{
				return No("stage-already-completed");
			}
			visitedStages.Add(nextStage);
			state.EvolutionOpened.Clear();
			foreach (HuntPlayer player in state.Players)
			{
				player.SummitProtected = false;
				ResetAura(player, staminaGrants: true);
			}
			bool flag = state.SurvivorCount == 0;
			ScoreCurrentStage();
			state.Stage++;
			state.StageKey = nextStage;
			state.BackpackVoteId = 0;
			foreach (HuntPlayer player2 in state.Players)
			{
				player2.PendingBurstAt = 0.0;
			}
			if (flag)
			{
				EvolutionRules.Reset(state, newRun: false);
				state.Round++;
				state.Phase = HuntPhase.AwaitingVote;
				state.Votes.Clear();
				state.EligibleVoters.Clear();
				foreach (HuntPlayer player3 in state.Players)
				{
					ResetPlayer(player3, clearInventory: true);
				}
			}
			else
			{
				state.Phase = HuntPhase.HunterDelay;
				state.HuntersReleaseAt = now + 30.0;
			}
			return Yes();
		}

		public CommandResult FinishByFlare(int issuer, FlareIgnition ignition, string expectedStage, double now)
		{
			return FinishByFlare(issuer, ignition, expectedStage, now, now);
		}

		public CommandResult FinishByFlare(int issuer, FlareIgnition ignition, string expectedStage, double now, double summonedAt)
		{
			Clock(now);
			if (!Host(issuer))
			{
				return No("host-only");
			}
			if (state.FlowOnly)
			{
				return No("flow-test-no-finale");
			}
			if (double.IsNaN(summonedAt) || double.IsInfinity(summonedAt) || summonedAt < 0.0 || summonedAt > now)
			{
				return No("invalid-native-summon-time");
			}
			if ((state.Phase != HuntPhase.Active && state.Phase != HuntPhase.HunterDelay) || expectedStage != state.StageKey)
			{
				return No("stale-finale");
			}
			HuntPlayer huntPlayer = ((ignition == null) ? null : state.Find(ignition.Actor));
			if (ignition == null || !ignition.InRound(state) || huntPlayer == null || !huntPlayer.Connected || (ignition.Team != HuntTeam.Hunters && ignition.Team != HuntTeam.Survivors))
			{
				return No("unknown-flare-owner");
			}
			HuntTeam pointWinner = ((state.SurvivorCount == 0) ? HuntTeam.Hunters : ignition.Team);
			ScoreCurrentStage(pointWinner);
			state.Winner = ((state.HunterScore != state.SurvivorScore) ? ((state.HunterScore > state.SurvivorScore) ? HuntTeam.Hunters : HuntTeam.Survivors) : HuntTeam.None);
			state.ResultClosesAt = summonedAt + 30.0;
			state.Phase = HuntPhase.Finished;
			return Yes();
		}
	}
	public sealed class HunterStartBackpackLedger
	{
		public const double SpawnWindowSeconds = 10.0;

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

		private bool hasScope;

		private Guid session;

		private int authorityTerm;

		private int run;

		private int round;

		private int stage;

		private string stageKey = "";

		private double releaseAt;

		public IList<int> PendingActors(HuntSnapshot state, double now)
		{
			List<int> list = new List<int>();
			if (!InWindow(state, now))
			{
				return list;
			}
			Scope(state);
			foreach (HuntPlayer player in state.Players)
			{
				if (Eligible(player) && !completed.Contains(player.Actor))
				{
					list.Add(player.Actor);
				}
			}
			return list;
		}

		public bool Confirm(HuntSnapshot state, int actor, double now)
		{
			if (!InWindow(state, now))
			{
				return false;
			}
			Scope(state);
			HuntPlayer player = state.Find(actor);
			if (Eligible(player))
			{
				return completed.Add(actor);
			}
			return false;
		}

		public void Clear()
		{
			completed.Clear();
			hasScope = false;
			session = Guid.Empty;
			authorityTerm = (run = (round = (stage = 0)));
			stageKey = "";
			releaseAt = 0.0;
		}

		private static bool Eligible(HuntPlayer player)
		{
			if (player != null && player.Actor > 0 && player.Connected && player.Loaded && !player.PendingRevive)
			{
				return player.Team == HuntTeam.Hunters;
			}
			return false;
		}

		private static bool InWindow(HuntSnapshot state, double now)
		{
			if (state != null && state.Enabled && !state.FlowOnly && state.Phase == HuntPhase.Active && state.Session != Guid.Empty && state.AuthorityTerm > 0 && state.Run > 0 && state.Round > 0 && state.Stage > 0 && !string.IsNullOrEmpty(state.StageKey) && state.BackpackVoteId > 0 && state.BackpackVoteId == state.VoteId && SpecialChecks.Time(now) && SpecialChecks.Time(state.HuntersReleaseAt) && now >= state.HuntersReleaseAt)
			{
				return now - state.HuntersReleaseAt <= 10.0;
			}
			return false;
		}

		private void Scope(HuntSnapshot state)
		{
			if (!hasScope || !(session == state.Session) || authorityTerm != state.AuthorityTerm || run != state.Run || round != state.Round || stage != state.Stage || !(stageKey == state.StageKey) || !releaseAt.Equals(state.HuntersReleaseAt))
			{
				hasScope = true;
				session = state.Session;
				authorityTerm = state.AuthorityTerm;
				run = state.Run;
				round = state.Round;
				stage = state.Stage;
				stageKey = state.StageKey;
				releaseAt = state.HuntersReleaseAt;
				completed.Clear();
			}
		}
	}
	public interface IHuntTraceWorld
	{
		bool TryGetTracePosition(int actor, out HuntPosition position);
	}
	public sealed class HuntTrace
	{
		public Guid Session;

		public int AuthorityTerm;

		public int Run;

		public int Round;

		public int Stage;

		public int ViewerActor;

		public int ViewerLoadoutVersion;

		public int ViewerReviveVersion;

		public string StageKey = "";

		public HuntPosition Position;

		public double SampledAt;

		public double ExpiresAt;

		public bool Valid
		{
			get
			{
				if (Session != Guid.Empty && AuthorityTerm > 0 && Run > 0 && Round > 0 && Stage > 0 && ViewerActor > 0 && ViewerLoadoutVersion >= 0 && ViewerReviveVersion >= 0 && !string.IsNullOrEmpty(StageKey) && Position.IsFinite && !double.IsNaN(SampledAt) && !double.IsInfinity(SampledAt) && SampledAt >= 0.0 && !double.IsNaN(ExpiresAt) && !double.IsInfinity(ExpiresAt) && ExpiresAt > SampledAt)
				{
					return ExpiresAt == SampledAt + 10.0;
				}
				return false;
			}
		}

		public bool InScope(HuntSnapshot s)
		{
			if (s != null && Session == s.Session && AuthorityTerm == s.AuthorityTerm && Run == s.Run && Round == s.Round && Stage == s.Stage)
			{
				return StageKey == s.StageKey;
			}
			return false;
		}

		public HuntTrace Clone()
		{
			return (HuntTrace)MemberwiseClone();
		}
	}
	public static class HuntTraceRules
	{
		public static bool CanReceive(HuntSnapshot s, HuntTrace trace)
		{
			HuntPlayer huntPlayer = ((s == null || trace == null) ? null : s.Find(trace.ViewerActor));
			if (CampfireRules.Playing(s) && trace != null && trace.Valid && trace.InScope(s) && huntPlayer != null && huntPlayer.Connected && !huntPlayer.PendingRevive && huntPlayer.Team == HuntTeam.Hunters && huntPlayer.LoadoutVersion == trace.ViewerLoadoutVersion)
			{
				return huntPlayer.ReviveVersion == trace.ViewerReviveVersion;
			}
			return false;
		}

		public static HuntTrace Read(HuntSnapshot s, int viewer, double now)
		{
			if (s == null || double.IsNaN(now) || double.IsInfinity(now) || now < 0.0)
			{
				return null;
			}
			foreach (HuntTrace trace in s.Traces)
			{
				if (trace.ViewerActor == viewer && CanReceive(s, trace) && now >= trace.SampledAt && now < trace.ExpiresAt)
				{
					return trace;
				}
			}
			return null;
		}

		public static bool Prune(HuntSnapshot s, double now)
		{
			int count = s.Traces.Count;
			s.Traces.RemoveAll((HuntTrace t) => !CanReceive(s, t) || now >= t.ExpiresAt);
			return s.Traces.Count != count;
		}

		public static HuntSnapshot ForViewer(HuntSnapshot s, int viewer)
		{
			HuntSnapshot copy = s.Clone();
			copy.Traces.RemoveAll((HuntTrace t) => t.ViewerActor != viewer || !CanReceive(copy, t) || copy.ServerTime >= t.ExpiresAt);
			return copy;
		}
	}
	internal sealed class HuntTraceAuthority
	{
		private Guid session;

		private int term;

		private int run;

		private int round;

		private int stage;

		private string stageKey = "";

		private double nextSample;

		internal bool Step(HuntSnapshot state, IHuntTraceWorld world, double now)
		{
			bool flag = HuntTraceRules.Prune(state, now);
			if (!CampfireRules.Playing(state))
			{
				session = Guid.Empty;
				nextSample = 0.0;
				return flag;
			}
			if (session != state.Session || term != state.AuthorityTerm || run != state.Run || round != state.Round || stage != state.Stage || stageKey != state.StageKey)
			{
				flag = flag || state.Traces.Count > 0;
				state.Traces.Clear();
				nextSample = 0.0;
				session = state.Session;
				term = state.AuthorityTerm;
				run = state.Run;
				round = state.Round;
				stage = state.Stage;
				stageKey = state.StageKey;
			}
			if (now < nextSample)
			{
				return flag;
			}
			nextSample = now + 10.0;
			flag = flag || state.Traces.Count > 0;
			state.Traces.Clear();
			if (world == null)
			{
				return flag;
			}
			Dictionary<int, HuntPosition> dictionary = new Dictionary<int, HuntPosition>();
			foreach (HuntPlayer player in state.Players)
			{
				if (player.Connected && player.Loaded && !player.PendingRevive && player.Team != HuntTeam.None && world.TryGetTracePosition(player.Actor, out var position) && position.IsFinite)
				{
					dictionary.Add(player.Actor, position);
				}
			}
			foreach (HuntPlayer player2 in state.Players)
			{
				if (player2.Team != HuntTeam.Hunters || !dictionary.TryGetValue(player2.Actor, out var value))
				{
					continue;
				}
				double num = double.PositiveInfinity;
				int num2 = int.MaxValue;
				HuntPosition position2 = default(HuntPosition);
				foreach (HuntPlayer player3 in state.Players)
				{
					if (player3.Role == HuntRole.Survivor && dictionary.TryGetValue(player3.Actor, out var value2))
					{
						double num3 = (double)value2.X - (double)value.X;
						double num4 = (double)value2.Y - (double)value.Y;
						double num5 = (double)value2.Z - (double)value.Z;
						double num6 = num3 * num3 + num4 * num4 + num5 * num5;
						if (num6 < num || (num6 == num && player3.Actor < num2))
						{
							num = num6;
							num2 = player3.Actor;
							position2 = value2;
						}
					}
				}
				if (num2 != int.MaxValue)
				{
					state.Traces.Add(new HuntTrace
					{
						Session = state.Session,
						AuthorityTerm = state.AuthorityTerm,
						Run = state.Run,
						Round = state.Round,
						Stage = state.Stage,
						StageKey = state.StageKey,
						ViewerActor = player2.Actor,
						ViewerLoadoutVersion = player2.LoadoutVersion,
						ViewerReviveVersion = player2.ReviveVersion,
						Position = position2,
						SampledAt = now,
						ExpiresAt = nextSample
					});
				}
			}
			if (!flag)
			{
				return state.Traces.Count > 0;
			}
			return true;
		}
	}
	public struct TraceMarkerView
	{
		public bool Visible;

		public bool Edge;

		public bool Behind;

		public float X;

		public float Y;

		public float Angle;
	}
	public static class TraceMarkerLayout
	{
		private static bool Finite(float n)
		{
			if (!float.IsNaN(n))
			{
				return !float.IsInfinity(n);
			}
			return false;
		}

		public static TraceMarkerView Project(float viewportX, float viewportY, float depth, float width, float height, float margin)
		{
			TraceMarkerView result = default(TraceMarkerView);
			if (!Finite(viewportX) || !Finite(viewportY) || !Finite(depth) || !Finite(width) || !Finite(height) || !Finite(margin) || margin < 0f || width <= margin * 2f || height <= margin * 2f)
			{
				return result;
			}
			double num = (double)width * 0.5;
			double num2 = (double)height * 0.5;
			double num3 = (double)viewportX * (double)width;
			double num4 = (double)viewportY * (double)height;
			result.Behind = depth <= 0f;
			if (result.Behind)
			{
				num3 = (double)width - num3;
				num4 = (double)height - num4;
			}
			double num5 = num3 - num;
			double num6 = num4 - num2;
			result.Edge = result.Behind || num3 < (double)margin || num3 > (double)(width - margin) || num4 < (double)margin || num4 > (double)(height - margin);
			if (result.Edge)
			{
				if (result.Behind)
				{
					if (num5 * num5 + num6 * num6 < 1.0)
					{
						num5 = 0.0;
						num6 = -1.0;
					}
					num6 = 0.0 - Math.Abs(num6) - 1.0;
				}
				double num7 = Math.Min((num - (double)margin) / Math.Max(0.001, Math.Abs(num5)), (num2 - (double)margin) / Math.Max(0.001, Math.Abs(num6)));
				num3 = num + num5 * num7;
				num4 = num2 + num6 * num7;
			}
			result.Visible = true;
			result.X = (float)num3;
			result.Y = (float)num4;
			result.Angle = (float)(Math.Atan2(num6, num5) * 180.0 / Math.PI - 90.0);
			return result;
		}
	}
	public enum HuntPhase
	{
		Disabled,
		Lobby,
		AwaitingVote,
		Voting,
		HunterDelay,
		Active,
		Suspended,
		Finished
	}
	public enum HuntRole
	{
		Unassigned,
		Survivor,
		Hunter,
		FalseHunter,
		Spectator
	}
	public enum HuntTeam
	{
		None,
		Hunters,
		Survivors
	}
	public enum HuntWeapon
	{
		Knife,
		Dart
	}
	public enum CommandKind
	{
		Vote,
		KnifeHit,
		DartShot,
		OpenVote,
		EvolutionBegin,
		EvolutionOpen,
		EvolutionCancel,
		EvolutionPick,
		EvolutionSkip
	}
	public struct HuntPosition
	{
		public float X;

		public float Y;

		public float Z;

		public bool IsFinite
		{
			get
			{
				if (Finite(X) && Finite(Y))
				{
					return Finite(Z);
				}
				return false;
			}
		}

		public HuntPosition(float x, float y, float z)
		{
			X = x;
			Y = y;
			Z = z;
		}

		public HuntPosition Above(float meters)
		{
			return new HuntPosition(X, Y + meters, Z);
		}

		private static bool Finite(float x)
		{
			if (!float.IsNaN(x) && !float.IsInfinity(x))
			{
				return Math.Abs(x) < 1000000f;
			}
			return false;
		}
	}
	public struct HuntAuraObservation
	{
		public int Actor;

		public HuntPosition Position;

		public HuntAuraObservation(int actor, HuntPosition position)
		{
			Actor = actor;
			Position = position;
		}
	}
	public sealed class HuntRules
	{
		public const int Protocol = 22;

		public const float KnifePetrify = 40f;

		public const float DartPetrify = 10f;

		public const float PetrifyMaximum = 100f;

		public const float BurstPetrifyThreshold = 35f;

		public const float BurstMovementMultiplier = 1.8f;

		public const float HunterAllianceMovementMultiplier = 1.2f;

		public const float SurvivorBondClimbSpeedMultiplier = 0.8f;

		public const float SurvivorBondRegenMultiplier = 1.3f;

		public const float SurvivorBondExtraStaminaPerPulse = 0.005f;

		public const double ProximityAuraIntervalSeconds = 3.0;

		public const double ProximityAuraDurationSeconds = 4.0;

		public const double HunterAllianceRadius = 15.0;

		public const double SurvivorBondRadius = 10.0;

		public const double ProtectionSeconds = 5.0;

		public const double BurstDelaySeconds = 1.0;

		public const double KnifeCooldownSeconds = 10.0;

		public const double DartCooldownSeconds = 60.0;

		public const double HunterDelaySeconds = 30.0;

		public const float DartDistance = 50f;

		public const float SafeCampDistance = 10f;

		public const float SafeCampExitDistance = 30f;

		public const float ReviveHeight = 2f;

		public const float SlowedMovementMultiplier = 0.5f;

		public const float ClimbCostMultiplier = 1.5f;

		public const float SurvivorIdleClimbCostMultiplier = 5f;

		public const float FalseHunterDeathCurse = 10f;

		public const double KnifeCastSeconds = 0.7;

		public const double DartCastSeconds = 1.0;

		public const double ResultDisplaySeconds = 30.0;

		public const double TraceIntervalSeconds = 10.0;

		public readonly double VoteSeconds;

		public HuntRules(double voteSeconds)
		{
			if (double.IsNaN(voteSeconds) || double.IsInfinity(voteSeconds) || voteSeconds < 1.0 || voteSeconds > 120.0)
			{
				throw new ArgumentOutOfRangeException("voteSeconds");
			}
			VoteSeconds = voteSeconds;
		}

		public HuntRules()
			: this(20.0)
		{
		}
	}
	public sealed class HuntPlayer
	{
		public int Actor;

		public string Name = "";

		public bool Connected;

		public bool Loaded;

		public bool PendingRevive;

		public bool CampProtected;

		public bool SummitProtected;

		public int CampProtectionStage;

		public HuntPosition CampProtectionPosition;

		public HuntRole Role;

		public float Petrify;

		public int PetrifyVersion;

		public int PetrifyEpoch;

		public bool PetrifyInitialized;

		public long PetrifyNativeAck;

		public float DeathCurseTotal;

		public double BurstUntil;

		public double PendingBurstAt;

		public double DebuffUntil;

		public double KnifeReadyAt;

		public double DartReadyAt;

		public double SoilUntil;

		public int HunterAllianceLayers;

		public int SurvivorBondLayers;

		public int SurvivorBondStaminaGrants;

		public double HunterAllianceUntil;

		public double SurvivorBondUntil;

		public int LoadoutVersion;

		public int ReviveVersion;

		public int InventoryResetVersion;

		public long LastCommandSequence;

		public HuntPosition RevivePosition;

		public int EvolutionEpoch;

		public int EvolutionBoxes;

		public int EvolutionCards;

		public float EvolutionStone;

		public List<EvolutionOffer> EvolutionOffers = new List<EvolutionOffer>();

		public long SoundSequence;

		public List<HuntSoundCue> SoundCues = new List<HuntSoundCue>();

		public HuntTeam Team
		{
			get
			{
				if (Role != HuntRole.Survivor)
				{
					if (Role != HuntRole.Hunter && Role != HuntRole.FalseHunter)
					{
						return HuntTeam.None;
					}
					return HuntTeam.Hunters;
				}
				return HuntTeam.Survivors;
			}
		}

		public bool WantsKnife
		{
			get
			{
				if (Role != HuntRole.Hunter)
				{
					return Role == HuntRole.FalseHunter;
				}
				return true;
			}
		}

		public bool WantsDart => Role == HuntRole.Hunter;

		public bool Protected(double now)
		{
			if (!SummitProtected && (Team == HuntTeam.None || !CampProtected))
			{
				return now < BurstUntil;
			}
			return true;
		}

		public bool InfiniteStamina(double now)
		{
			return now < BurstUntil;
		}

		public int ActiveHunterAllianceLayers(double now)
		{
			if (!(now < HunterAllianceUntil))
			{
				return 0;
			}
			return HunterAllianceLayers;
		}

		public int ActiveSurvivorBondLayers(double now)
		{
			if (!(now < SurvivorBondUntil))
			{
				return 0;
			}
			return SurvivorBondLayers;
		}

		public float MoveMultiplier(double now)
		{
			float num = ((now < DebuffUntil) ? 0.5f : ((now < SoilUntil) ? 0.5f : 1f));
			float num2 = ((Role == HuntRole.Survivor && !PendingRevive && now < BurstUntil) ? 1.8f : ((Team == HuntTeam.Hunters && ActiveHunterAllianceLayers(now) > 0) ? 1.2f : 1f));
			return num * num2;
		}

		public float ClimbMultiplier(double now)
		{
			if (!(now < DebuffUntil) && !(now < SoilUntil))
			{
				return 1f;
			}
			return 1.5f;
		}

		public float ClimbSpeedMultiplier(double now)
		{
			if (Role != HuntRole.Survivor || PendingRevive || ActiveSurvivorBondLayers(now) < 2)
			{
				return 1f;
			}
			return 0.8f;
		}

		public float StaminaRegenMultiplier(double now)
		{
			if (Role != HuntRole.Survivor || PendingRevive || ActiveSurvivorBondLayers(now) < 1)
			{
				return 1f;
			}
			return 1.3f;
		}

		public HuntPlayer Clone()
		{
			HuntPlayer huntPlayer = (HuntPlayer)MemberwiseClone();
			huntPlayer.EvolutionOffers = new List<EvolutionOffer>();
			foreach (EvolutionOffer evolutionOffer in EvolutionOffers)
			{
				huntPlayer.EvolutionOffers.Add(evolutionOffer.Clone());
			}
			huntPlayer.SoundCues = new List<HuntSoundCue>();
			foreach (HuntSoundCue soundCue in SoundCues)
			{
				huntPlayer.SoundCues.Add(soundCue.Clone());
			}
			return huntPlayer;
		}
	}
	public sealed class HuntSnapshot
	{
		public Guid Session;

		public int HostActor;

		public int AuthorityTerm;

		public int Run;

		public int Round;

		public int Stage;

		public int VoteId;

		public int BackpackVoteId;

		public long Revision;

		public HuntPhase Phase;

		public bool FlowOnly;

		public string StageKey = "";

		public double ServerTime;

		public double VoteClosesAt;

		public double HuntersReleaseAt;

		public double ResultClosesAt;

		public int HunterScore;

		public int SurvivorScore;

		public HuntTeam Winner;

		public readonly List<HuntPlayer> Players = new List<HuntPlayer>();

		public readonly List<HuntTrace> Traces = new List<HuntTrace>();

		public long EvolutionNextId;

		public int SurvivorTeamBoxes;

		public int EvolutionCampStage;

		public readonly List<string> EvolutionOpened = new List<string>();

		public readonly Dictionary<int, bool> Votes = new Dictionary<int, bool>();

		public readonly List<int> EligibleVoters = new List<int>();

		public bool Enabled => Phase != HuntPhase.Disabled;

		public int SurvivorCount => Players.FindAll((HuntPlayer p) => p.Connected && p.Role == HuntRole.Survivor && !p.PendingRevive).Count;

		public HuntPlayer Find(int actor)
		{
			return Players.Find((HuntPlayer p) => p.Actor == actor);
		}

		public bool HunterDelayProtected(int actor, double now)
		{
			HuntPlayer huntPlayer = Find(actor);
			if (Enabled && !FlowOnly && Phase == HuntPhase.HunterDelay && !double.IsNaN(now) && !double.IsInfinity(now) && now >= 0.0 && now < HuntersReleaseAt && huntPlayer != null && huntPlayer.Connected && !huntPlayer.PendingRevive)
			{
				return huntPlayer.Team == HuntTeam.Hunters;
			}
			return false;
		}

		public bool Protected(int actor, double now)
		{
			HuntPlayer huntPlayer = Find(actor);
			if (huntPlayer != null)
			{
				if (!huntPlayer.Protected(now))
				{
					return HunterDelayProtected(actor, now);
				}
				return true;
			}
			return false;
		}

		public bool Locked(int actor, double now)
		{
			HuntPlayer huntPlayer = Find(actor);
			if (!Enabled || Phase == HuntPhase.Lobby || Phase == HuntPhase.Finished || huntPlayer == null || !huntPlayer.Connected)
			{
				return false;
			}
			if (Phase == HuntPhase.AwaitingVote || Phase == HuntPhase.Voting || Phase == HuntPhase.Suspended)
			{
				return true;
			}
			if (huntPlayer.Loaded && !huntPlayer.PendingRevive && huntPlayer.Role != HuntRole.Spectator && huntPlayer.Role != HuntRole.Unassigned)
			{
				if (huntPlayer.Team == HuntTeam.Hunters)
				{
					return now < HuntersReleaseAt;
				}
				return false;
			}
			return true;
		}

		public HuntSnapshot Clone()
		{
			HuntSnapshot huntSnapshot = new HuntSnapshot();
			huntSnapshot.Session = Session;
			huntSnapshot.HostActor = HostActor;
			huntSnapshot.AuthorityTerm = AuthorityTerm;
			huntSnapshot.Run = Run;
			huntSnapshot.Round = Round;
			huntSnapshot.Stage = Stage;
			huntSnapshot.VoteId = VoteId;
			huntSnapshot.BackpackVoteId = BackpackVoteId;
			huntSnapshot.Revision = Revision;
			huntSnapshot.Phase = Phase;
			huntSnapshot.FlowOnly = FlowOnly;
			huntSnapshot.StageKey = StageKey;
			huntSnapshot.ServerTime = ServerTime;
			huntSnapshot.VoteClosesAt = VoteClosesAt;
			huntSnapshot.HuntersReleaseAt = HuntersReleaseAt;
			huntSnapshot.ResultClosesAt = ResultClosesAt;
			huntSnapshot.HunterScore = HunterScore;
			huntSnapshot.SurvivorScore = SurvivorScore;
			huntSnapshot.Winner = Winner;
			HuntSnapshot huntSnapshot2 = huntSnapshot;
			foreach (HuntPlayer player in Players)
			{
				huntSnapshot2.Players.Add(player.Clone());
			}
			huntSnapshot2.EvolutionNextId = EvolutionNextId;
			huntSnapshot2.SurvivorTeamBoxes = SurvivorTeamBoxes;
			huntSnapshot2.EvolutionCampStage = EvolutionCampStage;
			huntSnapshot2.EvolutionOpened.AddRange(EvolutionOpened);
			foreach (HuntTrace trace in Traces)
			{
				huntSnapshot2.Traces.Add(trace.Clone());
			}
			foreach (KeyValuePair<int, bool> vote in Votes)
			{
				huntSnapshot2.Votes.Add(vote.Key, vote.Value);
			}
			huntSnapshot2.EligibleVoters.AddRange(EligibleVoters);
			return huntSnapshot2;
		}
	}
	public sealed class HuntCommand
	{
		public Guid Session;

		public int AuthorityTerm;

		public int Run;

		public int Round;

		public int Stage;

		public int VoteId;

		public int TargetActor;

		public long Sequence;

		public long CastId;

		public CommandKind Kind;

		public bool Agree;
	}
	public sealed class CommandResult
	{
		public readonly bool Accepted;

		public readonly bool Duplicate;

		public readonly string Code;

		public readonly long Revision;

		public CommandResult(bool accepted, string code, long revision, bool duplicate)
		{
			Accepted = accepted;
			Code = code;
			Revision = revision;
			Duplicate = duplicate;
		}
	}
	public interface ICombatWorld
	{
		bool ValidateAttack(int attacker, int target, HuntWeapon weapon, out string reason);

		bool ValidateDartShot(int attacker, int reportedTarget, out int actualTarget, out string reason);

		bool TryGetPosition(int actor, out HuntPosition position);
	}
	public interface IKnifeCombatWorld
	{
		bool ValidateKnifeSwing(int attacker, out int actualTarget, out string reason);
	}
	public interface INativeCombatProtectionWorld
	{
		bool NativeInvincible(int actor);
	}
	public sealed class OwnedCurseLedger
	{
		private float observed;

		private float requested;

		private float owned;

		private float before;

		private float target;

		private float wanted;

		private bool initialized;

		private bool pending;

		public float Contribution => owned;

		public float Plan(float desired, float current)
		{
			Validate(desired, native: false);
			Validate(current, native: true);
			if (initialized && current < observed)
			{
				owned = Math.Max(0f, owned - (observed - current));
			}
			initialized = true;
			observed = current;
			wanted = desired;
			before = current;
			float num = desired - requested;
			if (num < 0f)
			{
				num = 0f - Math.Min(0f - num, Math.Min(owned, current));
			}
			target = Math.Max(0f, Math.Min(100f, current + num));
			pending = true;
			return target;
		}

		public void Confirm(float actual)
		{
			Validate(actual, native: true);
			if (!pending)
			{
				throw new InvalidOperationException("No curse adjustment planned");
			}
			float num = target - before;
			float val = actual - before;
			if (num > 0f)
			{
				val = Math.Max(0f, Math.Min(num, val));
				owned += val;
				requested = wanted - (num - val);
			}
			else if (num < 0f)
			{
				val = Math.Min(0f, Math.Max(num, val));
				owned = Math.Max(0f, owned + val);
				requested = wanted + Math.Max(0f, 0f - num + val);
			}
			else
			{
				requested = wanted;
			}
			observed = actual;
			pending = false;
		}

		private static void Validate(float value, bool native)
		{
			if (float.IsNaN(value) || float.IsInfinity(value) || value < 0f || (native && value > 100f))
			{
				throw new ArgumentOutOfRangeException("value");
			}
		}
	}
	public sealed class OwnerPetrifySync
	{
		private Guid session;

		private int term;

		private int run;

		private int epoch = -1;

		private int actor;

		private int appliedVersion = -1;

		private int clearedRevive = -1;

		private int observed;

		private int owned;

		private long sequence;

		private bool observedOnce;

		private HuntPetrifyReport pending;

		public int Contribution => owned;

		private static bool Active(HuntSnapshot s)
		{
			if (s != null && !s.FlowOnly && s.Run > 0 && s.Phase != HuntPhase.Disabled && s.Phase != HuntPhase.Lobby && s.Phase != HuntPhase.Suspended)
			{
				return s.Phase != HuntPhase.Finished;
			}
			return false;
		}

		private HuntPlayer Ensure(HuntSnapshot s, int owner, int current)
		{
			HuntPlayer huntPlayer = (Active(s) ? s.Find(owner) : null);
			if (huntPlayer == null || !huntPlayer.Connected)
			{
				return null;
			}
			sequence = Math.Max(sequence, huntPlayer.PetrifyNativeAck);
			if (session != s.Session || term != s.AuthorityTerm || run != s.Run || epoch != huntPlayer.PetrifyEpoch || actor != owner)
			{
				session = s.Session;
				term = s.AuthorityTerm;
				run = s.Run;
				epoch = huntPlayer.PetrifyEpoch;
				actor = owner;
				pending = null;
				appliedVersion = -1;
				clearedRevive = -1;
			}
			if (!observedOnce)
			{
				observedOnce = true;
				observed = current;
			}
			return huntPlayer;
		}

		private void Observe(int current)
		{
			if (current < 0 || current > 100)
			{
				throw new ArgumentOutOfRangeException("current");
			}
			if (observedOnce && current < observed)
			{
				owned = Math.Max(0, owned - (observed - current));
			}
			observed = current;
			observedOnce = true;
		}

		private void MakeReport(HuntPlayer p, int before, int after, bool baseline)
		{
			pending = new HuntPetrifyReport
			{
				Session = session,
				AuthorityTerm = term,
				Run = run,
				Epoch = epoch,
				BaseVersion = ((appliedVersion < 0) ? p.PetrifyVersion : appliedVersion),
				Before = before,
				After = after,
				Baseline = baseline,
				Sequence = ++sequence
			};
		}

		public void NativeChanged(HuntSnapshot s, int owner, int before, int after)
		{
			HuntPlayer huntPlayer = Ensure(s, owner, before);
			Observe(before);
			Observe(after);
			if (huntPlayer == null || huntPlayer.PendingRevive || before == after)
			{
				return;
			}
			if (!huntPlayer.PetrifyInitialized)
			{
				MakeReport(huntPlayer, after, after, baseline: true);
				return;
			}
			if (pending == null || pending.Baseline)
			{
				MakeReport(huntPlayer, before, after, baseline: false);
			}
			else
			{
				pending.After = after;
				pending.Sequence = ++sequence;
			}
			pending.LargestGain = Math.Max(pending.LargestGain, Math.Max(0, after - before));
		}

		public int? Plan(HuntSnapshot s, int owner, int current, bool dead, bool warping)
		{
			HuntPlayer huntPlayer = Ensure(s, owner, current);
			if (huntPlayer == null)
			{
				Observe(current);
				return null;
			}
			if (current != observed)
			{
				NativeChanged(s, owner, observed, current);
			}
			else
			{
				Observe(current);
			}
			if (huntPlayer.PendingRevive)
			{
				pending = null;
				if (!dead && !warping && huntPlayer.Petrify >= 100f && clearedRevive != huntPlayer.ReviveVersion && current != 100)
				{
					return 100;
				}
				return null;
			}
			if (dead || warping)
			{
				return null;
			}
			if (!huntPlayer.PetrifyInitialized)
			{
				if (pending == null || !pending.Baseline || pending.After != current || pending.BaseVersion != huntPlayer.PetrifyVersion)
				{
					MakeReport(huntPlayer, current, current, baseline: true);
				}
				return null;
			}
			if (pending != null && pending.Baseline)
			{
				pending = null;
				appliedVersion = huntPlayer.PetrifyVersion;
				int num = PetrifyAuthority.NativeAmount(huntPlayer.Petrify);
				if (current != num)
				{
					MakeReport(huntPlayer, num, current, baseline: false);
					return null;
				}
			}
			if (pending != null)
			{
				if (huntPlayer.PetrifyNativeAck < pending.Sequence)
				{
					return null;
				}
				pending = null;
			}
			int num2 = PetrifyAuthority.NativeAmount(huntPlayer.Petrify);
			if (current == num2)
			{
				appliedVersion = huntPlayer.PetrifyVersion;
				return null;
			}
			return num2;
		}

		public void ConfirmWrite(HuntSnapshot s, int owner, int before, int wanted, int actual)
		{
			HuntPlayer huntPlayer = Ensure(s, owner, before);
			Observe(before);
			if (actual < 0 || actual > 100)
			{
				throw new ArgumentOutOfRangeException("actual");
			}
			owned = Math.Min(owned, actual);
			observed = actual;
			observedOnce = true;
			if (actual > before)
			{
				owned = Math.Min(actual, owned + Math.Min(actual - before, Math.Max(0, wanted - before)));
			}
			if (huntPlayer != null && actual == wanted)
			{
				appliedVersion = huntPlayer.PetrifyVersion;
			}
		}

		public HuntPetrifyReport Report(HuntSnapshot s, int owner, int viewId)
		{
			HuntPlayer huntPlayer = (Active(s) ? s.Find(owner) : null);
			if (pending == null || huntPlayer == null || session != s.Session || term != s.AuthorityTerm || run != s.Run || actor != owner || epoch != huntPlayer.PetrifyEpoch || huntPlayer.PendingRevive)
			{
				return null;
			}
			HuntPetrifyReport huntPetrifyReport = pending.Clone();
			huntPetrifyReport.Round = s.Round;
			huntPetrifyReport.Stage = s.Stage;
			huntPetrifyReport.ViewId = viewId;
			return huntPetrifyReport;
		}

		public bool Applied(HuntSnapshot s, int owner, int current)
		{
			HuntPlayer huntPlayer = (Active(s) ? s.Find(owner) : null);
			if (huntPlayer != null && huntPlayer.PetrifyInitialized && !huntPlayer.PendingRevive && pending == null && session == s.Session && term == s.AuthorityTerm && run == s.Run && epoch == huntPlayer.PetrifyEpoch && appliedVersion == huntPlayer.PetrifyVersion)
			{
				return current == PetrifyAuthority.NativeAmount(huntPlayer.Petrify);
			}
			return false;
		}

		public void ReviveStarted(int reviveVersion)
		{
			clearedRevive = reviveVersion;
			pending = null;
		}

		public int CleanupTarget(int current)
		{
			Observe(current);
			return Math.Max(0, current - owned);
		}

		public void ResetOwner()
		{
			session = Guid.Empty;
			epoch = -1;
			pending = null;
			appliedVersion = (clearedRevive = -1);
			owned = 0;
			observedOnce = false;
		}
	}
	public static class LocalCombatEffects
	{
		public static HuntPlayer Player(HuntSnapshot s, int actor, double now)
		{
			if (s == null || s.FlowOnly || (s.Phase != HuntPhase.Active && s.Phase != HuntPhase.HunterDelay && s.Phase != HuntPhase.Finished) || double.IsNaN(now) || double.IsInfinity(now) || now < 0.0)
			{
				return null;
			}
			HuntPlayer huntPlayer = s.Find(actor);
			if (huntPlayer == null || !huntPlayer.Connected || huntPlayer.Team == HuntTeam.None || (s.Phase == HuntPhase.Finished && !huntPlayer.SummitProtected))
			{
				return null;
			}
			return huntPlayer;
		}

		public static bool BurstProtected(HuntSnapshot s, int actor, double now)
		{
			HuntPlayer huntPlayer = Player(s, actor, now);
			if (huntPlayer != null && s.Phase != HuntPhase.Finished)
			{
				return now < huntPlayer.BurstUntil;
			}
			return false;
		}

		public static bool StoneProtected(HuntSnapshot s, int actor, double now)
		{
			HuntPlayer huntPlayer = Player(s, actor, now);
			if (huntPlayer != null)
			{
				if (s.Phase != HuntPhase.Finished)
				{
					return s.Protected(actor, now);
				}
				return huntPlayer.SummitProtected;
			}
			return false;
		}

		public static bool DamageProtected(HuntSnapshot s, int