Decompiled source of OGWoodenDoll v1.3.0

BepInEx/plugins/OGWoodenDoll/OGWoodenDoll.dll

Decompiled 4 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using OGWoodenDoll.NetcodePatcher;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("OGWoodenDoll")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyInformationalVersion("1.3.0")]
[assembly: AssemblyProduct("OGWoodenDoll")]
[assembly: AssemblyTitle("OGWoodenDoll")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.3.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace OGWoodenDoll
{
	internal sealed class DollAnimator
	{
		private readonly DollData data;

		private readonly Transform[] bones;

		private readonly int boneCount;

		private readonly ClipData idle;

		private readonly ClipData walk;

		private readonly ClipData run;

		private readonly bool[] overlayMask;

		private bool running;

		private ClipData overlay;

		private float overlayTime;

		private readonly Quaternion[] current;

		private readonly Quaternion[] fadeFrom;

		private readonly Quaternion[] scratchA;

		private readonly Quaternion[] scratchB;

		private Vector3 currentHips;

		private Vector3 fadeFromHips;

		private float fade = 1f;

		private float fadeDuration = 0.2f;

		private bool locomotion = true;

		private ClipData action;

		private float actionTime;

		private float idleTime;

		private float walkPhase;

		private float walkWeight;

		public bool InLocomotion => locomotion;

		public float ActionTime => actionTime;

		public event Action<int> Footstep;

		public DollAnimator(DollData data, Transform[] bones)
		{
			this.data = data;
			this.bones = bones;
			boneCount = bones.Length;
			idle = data.Clips["idle"];
			walk = data.Clips["walk"];
			run = data.Clips["run"];
			overlayMask = new bool[boneCount];
			for (int i = 0; i < boneCount; i++)
			{
				string text = data.BoneNames[i];
				overlayMask[i] = text == "Spine" || text == "Neck" || text.StartsWith("Shoulder") || text.StartsWith("UpperArm") || text.StartsWith("Forearm") || text.StartsWith("Hand");
			}
			current = (Quaternion[])(object)new Quaternion[boneCount];
			fadeFrom = (Quaternion[])(object)new Quaternion[boneCount];
			scratchA = (Quaternion[])(object)new Quaternion[boneCount];
			scratchB = (Quaternion[])(object)new Quaternion[boneCount];
			Sample(idle, 0f, current, out currentHips);
			idleTime = Random.value * idle.Length;
		}

		public float ClipLength(string clip)
		{
			return data.Clips[clip].Length;
		}

		public void PlayLocomotion(float fadeTime)
		{
			if (!locomotion)
			{
				BeginFade(fadeTime);
				locomotion = true;
				action = null;
				walkWeight = 0f;
				walkPhase = 0.25f;
			}
		}

		public void SetRunning(bool value)
		{
			if (running != value)
			{
				if (locomotion)
				{
					BeginFade(0.2f);
				}
				running = value;
			}
		}

		public void PlayOverlay(string clip, float fadeTime)
		{
			BeginFade(fadeTime);
			overlay = data.Clips[clip];
			overlayTime = 0f;
		}

		public void StopOverlay(float fadeTime)
		{
			if (overlay != null)
			{
				BeginFade(fadeTime);
				overlay = null;
			}
		}

		public void Play(string clip, float fadeTime)
		{
			BeginFade(fadeTime);
			overlay = null;
			locomotion = false;
			action = data.Clips[clip];
			actionTime = 0f;
		}

		public void SetFadeStartRotation(int bone, Quaternion localRotation)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			fadeFrom[bone] = localRotation;
		}

		private void BeginFade(float duration)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			Array.Copy(current, fadeFrom, boneCount);
			fadeFromHips = currentHips;
			fade = 0f;
			fadeDuration = Mathf.Max(duration, 0.0001f);
		}

		public static float StrideLength(float speed, bool running)
		{
			if (!running)
			{
				return Mathf.Lerp(1.2f, 1.9f, Mathf.InverseLerp(1f, 4.6f, speed));
			}
			return Mathf.Lerp(1.9f, 2.5f, Mathf.InverseLerp(4f, 7f, speed));
		}

		public void Tick(float deltaTime, float groundSpeed, bool allowFootsteps)
		{
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			Vector3 hips;
			if (locomotion)
			{
				float num = Mathf.Clamp01((groundSpeed - 0.15f) / 0.6f);
				walkWeight = Mathf.MoveTowards(walkWeight, num, deltaTime * 5f);
				idleTime += deltaTime;
				float num2 = walkPhase;
				walkPhase += groundSpeed / StrideLength(groundSpeed, running) * deltaTime;
				int num3 = Mathf.FloorToInt(num2 * 2f);
				int num4 = Mathf.FloorToInt(walkPhase * 2f);
				if (num4 != num3 && walkWeight > 0.5f && allowFootsteps && this.Footstep != null)
				{
					this.Footstep(num4 & 1);
				}
				if (walkPhase > 64f)
				{
					walkPhase -= 64f;
				}
				Sample(idle, idleTime, scratchA, out hips);
				if (walkWeight > 0.001f)
				{
					Sample(running ? run : walk, walkPhase, scratchB, out var hips2);
					for (int i = 0; i < boneCount; i++)
					{
						scratchA[i] = Quaternion.Slerp(scratchA[i], scratchB[i], walkWeight);
					}
					hips = Vector3.Lerp(hips, hips2, walkWeight);
				}
			}
			else
			{
				actionTime += deltaTime;
				Sample(action, actionTime, scratchA, out hips);
			}
			if (overlay != null)
			{
				overlayTime += deltaTime;
				Sample(overlay, overlayTime, scratchB, out var _);
				for (int j = 0; j < boneCount; j++)
				{
					if (overlayMask[j])
					{
						scratchA[j] = scratchB[j];
					}
				}
			}
			if (fade < 1f)
			{
				fade = Mathf.Min(1f, fade + deltaTime / fadeDuration);
				float num5 = fade * fade * (3f - 2f * fade);
				for (int k = 0; k < boneCount; k++)
				{
					current[k] = Quaternion.Slerp(fadeFrom[k], scratchA[k], num5);
				}
				currentHips = Vector3.Lerp(fadeFromHips, hips, num5);
			}
			else
			{
				Array.Copy(scratchA, current, boneCount);
				currentHips = hips;
			}
			bones[0].localPosition = currentHips;
			for (int l = 0; l < boneCount; l++)
			{
				bones[l].localRotation = current[l];
			}
		}

		private void Sample(ClipData clip, float time, Quaternion[] rotations, out Vector3 hips)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			clip.GetFramePair(time, out var frame, out var frame2, out var blend);
			float[] hipsPositions = clip.HipsPositions;
			hips = Vector3.Lerp(new Vector3(hipsPositions[frame * 3], hipsPositions[frame * 3 + 1], hipsPositions[frame * 3 + 2]), new Vector3(hipsPositions[frame2 * 3], hipsPositions[frame2 * 3 + 1], hipsPositions[frame2 * 3 + 2]), blend);
			float[] rotations2 = clip.Rotations;
			int num = frame * boneCount * 4;
			int num2 = frame2 * boneCount * 4;
			Quaternion val = default(Quaternion);
			Quaternion val2 = default(Quaternion);
			for (int i = 0; i < boneCount; i++)
			{
				((Quaternion)(ref val))..ctor(rotations2[num], rotations2[num + 1], rotations2[num + 2], rotations2[num + 3]);
				((Quaternion)(ref val2))..ctor(rotations2[num2], rotations2[num2 + 1], rotations2[num2 + 2], rotations2[num2 + 3]);
				rotations[i] = Quaternion.Slerp(val, val2, blend);
				num += 4;
				num2 += 4;
			}
		}
	}
	internal static class DollAssets
	{
		public static DollData Data;

		public static Texture2D WoodTexture;

		public static Texture2D HeadTexture;

		public static AudioClip StepClip;

		public static AudioClip AttackClip;

		public static AudioClip DeathClip;

		public static AudioClip GrabClip;

		public static AudioClip WalkingClip;

		public static AudioClip SilentClip;

		public static void Load(string pluginDirectory)
		{
			using (Stream stream = OpenResource("doll.bin"))
			{
				Data = DollData.Read(stream);
			}
			WoodTexture = LoadTexture("wood.jpg", (TextureWrapMode)0, (TextureWrapMode)0);
			HeadTexture = LoadTexture("head.jpg", (TextureWrapMode)0, (TextureWrapMode)1);
			StepClip = LoadWav(pluginDirectory, "step.wav");
			AttackClip = LoadWav(pluginDirectory, "attack.wav");
			DeathClip = LoadWav(pluginDirectory, "death.wav");
			GrabClip = LoadWav(pluginDirectory, "grab.wav");
			WalkingClip = LoadWav(pluginDirectory, "walking.wav");
			SilentClip = AudioClip.Create("OGWoodenDoll_silence", 441, 1, 44100, false);
			SilentClip.SetData(new float[441], 0);
			Object.DontDestroyOnLoad((Object)(object)SilentClip);
		}

		private static Stream OpenResource(string file)
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string[] manifestResourceNames = executingAssembly.GetManifestResourceNames();
			foreach (string text in manifestResourceNames)
			{
				if (text.EndsWith(file, StringComparison.OrdinalIgnoreCase))
				{
					return executingAssembly.GetManifestResourceStream(text);
				}
			}
			throw new FileNotFoundException("Embedded resource missing: " + file);
		}

		private static Texture2D LoadTexture(string file, TextureWrapMode wrapU, TextureWrapMode wrapV)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Expected O, but got Unknown
			//IL_008e: Expected O, but got Unknown
			byte[] array;
			using (Stream stream = OpenResource(file))
			{
				using MemoryStream memoryStream = new MemoryStream();
				stream.CopyTo(memoryStream);
				array = memoryStream.ToArray();
			}
			Texture2D val = new Texture2D(2, 2, (TextureFormat)3, true);
			if (!ImageConversion.LoadImage(val, array, true))
			{
				throw new InvalidDataException("Could not decode " + file);
			}
			((Object)val).name = "OGWoodenDoll_" + Path.GetFileNameWithoutExtension(file);
			((Texture)val).wrapModeU = wrapU;
			((Texture)val).wrapModeV = wrapV;
			((Texture)val).filterMode = (FilterMode)2;
			((Texture)val).anisoLevel = 4;
			Object.DontDestroyOnLoad((Object)val);
			return val;
		}

		private static AudioClip LoadWav(string pluginDirectory, string file)
		{
			try
			{
				string text = Path.Combine(pluginDirectory, "Audio", file);
				if (!File.Exists(text))
				{
					text = Path.Combine(pluginDirectory, file);
				}
				if (!File.Exists(text))
				{
					string[] files = Directory.GetFiles(pluginDirectory, file, SearchOption.AllDirectories);
					text = ((files.Length != 0) ? files[0] : null);
				}
				if (text == null)
				{
					Plugin.Log.LogError((object)("Sound file " + file + " was not found under " + pluginDirectory + "; the doll will be silent for it."));
					return null;
				}
				WavFile wavFile = WavFile.Read(File.ReadAllBytes(text));
				float duration = wavFile.Duration;
				wavFile = wavFile.TrimSilence();
				AudioClip val = AudioClip.Create("OGWoodenDoll_" + Path.GetFileNameWithoutExtension(file), wavFile.FrameCount, wavFile.Channels, wavFile.SampleRate, false);
				val.SetData(wavFile.Samples, 0);
				Object.DontDestroyOnLoad((Object)(object)val);
				Plugin.Debug(file + ": " + duration.ToString("0.00") + " s on disk, " + wavFile.Duration.ToString("0.00") + " s of sound");
				return val;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Could not load " + file + ": " + ex.Message));
				return null;
			}
		}
	}
	internal sealed class DollAttack
	{
		private const float StrikeArc = 80f;

		private const float ReachSlack = 0.35f;

		private readonly OGWoodenDollAI ai;

		private readonly ModConfig cfg;

		private readonly DollMovement movement;

		private readonly ClipData clip;

		private readonly List<float> strikeTimes = new List<float>();

		private int nextStrike;

		private float elapsed;

		public float CooldownUntil { get; private set; }

		public float Length => clip.Length;

		public bool Finished => elapsed >= clip.Length;

		public bool Ready => Time.time >= CooldownUntil;

		public DollAttack(OGWoodenDollAI ai, ModConfig cfg, DollMovement movement, ClipData clip)
		{
			this.ai = ai;
			this.cfg = cfg;
			this.movement = movement;
			this.clip = clip;
		}

		public bool InRange(PlayerControllerB player)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			if (!DollMovement.IsAlive(player))
			{
				return false;
			}
			Vector3 val = ((Component)player).transform.position - ((Component)ai).transform.position;
			if (Mathf.Abs(val.y) > 2.2f)
			{
				return false;
			}
			val.y = 0f;
			if (((Vector3)(ref val)).magnitude <= cfg.AttackRange.Value)
			{
				return movement.HasLineOfSight(((Component)ai).transform.position + Vector3.up * 1.2f, ((Component)player).transform.position + Vector3.up * 1f);
			}
			return false;
		}

		public void Begin()
		{
			elapsed = 0f;
			nextStrike = 0;
			strikeTimes.Clear();
			List<float> list = new List<float>();
			ClipEvent[] events = clip.Events;
			for (int i = 0; i < events.Length; i++)
			{
				ClipEvent clipEvent = events[i];
				if (clipEvent.Kind == 2)
				{
					list.Add(clipEvent.Time);
				}
			}
			int num = Mathf.Min(cfg.MaxHitsPerAttack.Value, list.Count);
			for (int j = 0; j < num; j++)
			{
				int index = Mathf.Clamp(Mathf.RoundToInt((float)j * (float)list.Count / (float)num), 0, list.Count - 1);
				if (!strikeTimes.Contains(list[index]))
				{
					strikeTimes.Add(list[index]);
				}
			}
		}

		public void Tick(float deltaTime)
		{
			elapsed += deltaTime;
			while (nextStrike < strikeTimes.Count && elapsed >= strikeTimes[nextStrike])
			{
				nextStrike++;
				ResolveStrike();
			}
		}

		public void End()
		{
			CooldownUntil = Time.time + cfg.AttackCooldown.Value;
			nextStrike = strikeTimes.Count;
		}

		private void ResolveStrike()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			if (((EnemyAI)ai).isEnemyDead || ai.State != DollState.Attacking)
			{
				return;
			}
			Vector3 position = ((Component)ai).transform.position;
			Vector3 val = position + Vector3.up * 1.2f;
			int value = cfg.StrikeDamage.Value;
			float num = cfg.AttackRange.Value + 0.35f;
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val2 in allPlayerScripts)
			{
				if (!DollMovement.IsAlive(val2))
				{
					continue;
				}
				Vector3 val3 = ((Component)val2).transform.position - position;
				if (!(Mathf.Abs(val3.y) > 2.2f))
				{
					val3.y = 0f;
					if (!(((Vector3)(ref val3)).magnitude > num) && (!(((Vector3)(ref val3)).sqrMagnitude > 0.04f) || !(Vector3.Angle(((Component)ai).transform.forward, val3) > 80f)) && movement.HasLineOfSight(val, ((Component)val2).transform.position + Vector3.up * 1f))
					{
						Vector3 val4 = ((((Vector3)(ref val3)).sqrMagnitude > 0.0001f) ? ((Vector3)(ref val3)).normalized : ((Component)ai).transform.forward);
						Plugin.Debug("strike hits player " + val2.playerClientId + " for " + value);
						ai.StrikePlayerClientRpc((int)val2.playerClientId, value, val4 * cfg.FlingForce.Value + Vector3.up * cfg.FlingUpForce.Value);
					}
				}
			}
		}
	}
	internal sealed class DollAudio
	{
		public const string FootstepObjectName = "Footsteps";

		private readonly AudioSource body;

		private readonly AudioSource voice;

		private readonly AudioSource steps;

		private bool attackPlaying;

		private float attackRemaining;

		private float nextAttackRepeat;

		private bool deathPlayed;

		private float attackVolume = 0.35f;

		public DollAudio(AudioSource body, AudioSource voice, AudioSource steps)
		{
			this.body = body;
			this.voice = voice;
			this.steps = steps;
		}

		public void PlayFootstep(int foot)
		{
			if (!((Object)(object)steps == (Object)null) && !((Object)(object)DollAssets.StepClip == (Object)null))
			{
				steps.pitch = ((foot == 0) ? 0.96f : 1.04f) + Random.Range(-0.04f, 0.04f);
				steps.PlayOneShot(DollAssets.StepClip, 1f);
			}
		}

		public void StartAttack(float sequenceLength, float volume)
		{
			attackVolume = Mathf.Clamp01(volume);
			if (!((Object)(object)body == (Object)null) && !((Object)(object)DollAssets.AttackClip == (Object)null))
			{
				body.Stop();
				body.clip = DollAssets.AttackClip;
				body.loop = false;
				body.pitch = 1f;
				body.volume = attackVolume;
				body.Play();
				attackPlaying = true;
				attackRemaining = sequenceLength;
				nextAttackRepeat = DollAssets.AttackClip.length;
			}
		}

		public void Tick(float deltaTime)
		{
			if (!attackPlaying)
			{
				return;
			}
			attackRemaining -= deltaTime;
			nextAttackRepeat -= deltaTime;
			if (attackRemaining <= 0.25f)
			{
				body.volume = Mathf.MoveTowards(body.volume, 0f, deltaTime * 5f * attackVolume);
				if (attackRemaining <= 0f)
				{
					StopAttack();
				}
			}
			else if (nextAttackRepeat <= 0f && !body.isPlaying)
			{
				body.volume = attackVolume;
				body.Play();
				nextAttackRepeat = DollAssets.AttackClip.length;
			}
		}

		public void StopAttack()
		{
			if (attackPlaying)
			{
				attackPlaying = false;
				if ((Object)(object)body != (Object)null)
				{
					body.Stop();
					body.volume = 1f;
				}
			}
		}

		public void PlayHit()
		{
			if (!((Object)(object)voice == (Object)null) && !((Object)(object)DollAssets.StepClip == (Object)null))
			{
				voice.pitch = 1.45f;
				voice.PlayOneShot(DollAssets.StepClip, 1f);
			}
		}

		public void PlayGrab()
		{
			if (!((Object)(object)voice == (Object)null) && !((Object)(object)DollAssets.GrabClip == (Object)null))
			{
				voice.pitch = 1f;
				voice.PlayOneShot(DollAssets.GrabClip, 0.6f);
			}
		}

		public void PlayWalking()
		{
			if (!((Object)(object)voice == (Object)null) && !((Object)(object)DollAssets.WalkingClip == (Object)null) && !deathPlayed)
			{
				voice.pitch = 1f;
				voice.PlayOneShot(DollAssets.WalkingClip, 0.6f);
			}
		}

		public void PlayDeath()
		{
			if (!deathPlayed)
			{
				deathPlayed = true;
				StopAttack();
				if ((Object)(object)steps != (Object)null)
				{
					steps.Stop();
				}
				if (!((Object)(object)voice == (Object)null) && !((Object)(object)DollAssets.DeathClip == (Object)null))
				{
					voice.Stop();
					voice.pitch = 1f;
					voice.clip = DollAssets.DeathClip;
					voice.loop = false;
					voice.Play();
				}
			}
		}

		public void StopAll()
		{
			StopAttack();
			if ((Object)(object)steps != (Object)null)
			{
				steps.Stop();
			}
			if ((Object)(object)voice != (Object)null)
			{
				voice.Stop();
			}
		}
	}
	public sealed class PartData
	{
		public int BoneIndex;

		public int Material;

		public float[] Positions;

		public float[] Normals;

		public float[] Uvs;

		public int[] Indices;
	}
	public struct ClipEvent
	{
		public const int Step = 1;

		public const int Strike = 2;

		public const int Release = 3;

		public float Time;

		public int Kind;

		public int Arg;
	}
	public sealed class ClipData
	{
		public string Name;

		public float Length;

		public float Fps;

		public bool Loop;

		public int FrameCount;

		public float[] HipsPositions;

		public float[] Rotations;

		public ClipEvent[] Events;

		public void GetFramePair(float time, out int frame0, out int frame1, out float blend)
		{
			float num = time * Fps;
			if (Loop)
			{
				float num2 = (float)Math.Floor(num);
				blend = num - num2;
				frame0 = (int)(num2 % (float)FrameCount);
				if (frame0 < 0)
				{
					frame0 += FrameCount;
				}
				frame1 = (frame0 + 1) % FrameCount;
				return;
			}
			if (num < 0f)
			{
				num = 0f;
			}
			if (num > (float)(FrameCount - 1))
			{
				num = FrameCount - 1;
			}
			frame0 = (int)Math.Floor(num);
			frame1 = Math.Min(frame0 + 1, FrameCount - 1);
			blend = num - (float)frame0;
		}
	}
	public sealed class DollData
	{
		public const int MaterialWood = 0;

		public const int MaterialShoe = 1;

		public const int MaterialHead = 2;

		public const int MaterialPin = 3;

		public string[] BoneNames;

		public int[] BoneParents;

		public float[] BoneRestPositions;

		public PartData[] Parts;

		public Dictionary<string, ClipData> Clips;

		public int BoneCount => BoneNames.Length;

		public int FindBone(string name)
		{
			return Array.IndexOf(BoneNames, name);
		}

		public static DollData Read(Stream stream)
		{
			using BinaryReader binaryReader = new BinaryReader(stream, Encoding.UTF8);
			if (new string(binaryReader.ReadChars(4)) != "OGWD")
			{
				throw new InvalidDataException("Not an OGWoodenDoll data file.");
			}
			uint num = binaryReader.ReadUInt32();
			if (num != 1)
			{
				throw new InvalidDataException("Unsupported doll data version " + num + ".");
			}
			DollData dollData = new DollData();
			int num2 = (int)binaryReader.ReadUInt32();
			dollData.BoneNames = new string[num2];
			dollData.BoneParents = new int[num2];
			dollData.BoneRestPositions = new float[num2 * 3];
			for (int i = 0; i < num2; i++)
			{
				dollData.BoneNames[i] = ReadString(binaryReader);
				dollData.BoneParents[i] = binaryReader.ReadInt32();
				for (int j = 0; j < 3; j++)
				{
					dollData.BoneRestPositions[i * 3 + j] = binaryReader.ReadSingle();
				}
			}
			dollData.Parts = new PartData[binaryReader.ReadUInt32()];
			for (int k = 0; k < dollData.Parts.Length; k++)
			{
				PartData partData = new PartData();
				partData.BoneIndex = binaryReader.ReadInt32();
				partData.Material = binaryReader.ReadInt32();
				int num3 = (int)binaryReader.ReadUInt32();
				int num4 = (int)binaryReader.ReadUInt32();
				partData.Positions = ReadFloats(binaryReader, num3 * 3);
				partData.Normals = ReadFloats(binaryReader, num3 * 3);
				partData.Uvs = ReadFloats(binaryReader, num3 * 2);
				partData.Indices = new int[num4];
				for (int l = 0; l < num4; l++)
				{
					partData.Indices[l] = binaryReader.ReadInt32();
				}
				dollData.Parts[k] = partData;
			}
			int num5 = (int)binaryReader.ReadUInt32();
			dollData.Clips = new Dictionary<string, ClipData>(num5);
			for (int m = 0; m < num5; m++)
			{
				ClipData clipData = new ClipData();
				clipData.Name = ReadString(binaryReader);
				clipData.Length = binaryReader.ReadSingle();
				clipData.Fps = binaryReader.ReadSingle();
				clipData.Loop = binaryReader.ReadUInt32() != 0;
				clipData.FrameCount = (int)binaryReader.ReadUInt32();
				clipData.HipsPositions = new float[clipData.FrameCount * 3];
				clipData.Rotations = new float[clipData.FrameCount * num2 * 4];
				for (int n = 0; n < clipData.FrameCount; n++)
				{
					for (int num6 = 0; num6 < 3; num6++)
					{
						clipData.HipsPositions[n * 3 + num6] = binaryReader.ReadSingle();
					}
					int num7 = n * num2 * 4;
					for (int num8 = 0; num8 < num2 * 4; num8++)
					{
						clipData.Rotations[num7 + num8] = binaryReader.ReadSingle();
					}
				}
				clipData.Events = new ClipEvent[binaryReader.ReadUInt32()];
				for (int num9 = 0; num9 < clipData.Events.Length; num9++)
				{
					clipData.Events[num9].Time = binaryReader.ReadSingle();
					clipData.Events[num9].Kind = binaryReader.ReadInt32();
					clipData.Events[num9].Arg = binaryReader.ReadInt32();
				}
				dollData.Clips[clipData.Name] = clipData;
			}
			return dollData;
		}

		private static string ReadString(BinaryReader r)
		{
			int count = r.ReadUInt16();
			return Encoding.UTF8.GetString(r.ReadBytes(count));
		}

		private static float[] ReadFloats(BinaryReader r, int count)
		{
			byte[] array = r.ReadBytes(count * 4);
			float[] array2 = new float[count];
			Buffer.BlockCopy(array, 0, array2, 0, array.Length);
			return array2;
		}
	}
	internal sealed class DollDeathController
	{
		private readonly OGWoodenDollAI ai;

		private float elapsed;

		public bool Started { get; private set; }

		public DollDeathController(OGWoodenDollAI ai)
		{
			this.ai = ai;
		}

		public void Begin(DollAnimator animator, DollAudio audio, int headBone, Transform headPivot)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			if (Started)
			{
				return;
			}
			Started = true;
			elapsed = 0f;
			ai.SetLocalState(DollState.Dying);
			audio?.PlayDeath();
			if (animator != null)
			{
				animator.Play("death", 0.15f);
				if ((Object)(object)headPivot != (Object)null)
				{
					animator.SetFadeStartRotation(headBone, headPivot.localRotation);
				}
			}
			if ((Object)(object)ai.collisionCollider != (Object)null)
			{
				ai.collisionCollider.enabled = false;
			}
			if ((Object)(object)ai.scanCollider != (Object)null)
			{
				ai.scanCollider.enabled = false;
			}
		}

		public void Tick(float deltaTime, float clipLength)
		{
			if (Started && ai.State != DollState.Dead)
			{
				elapsed += deltaTime;
				if (elapsed >= clipLength)
				{
					ai.SetLocalState(DollState.Dead);
				}
			}
		}
	}
	internal sealed class DollGrabController
	{
		private readonly OGWoodenDollAI ai;

		private float cooldownUntil;

		private float heldHeight;

		public PlayerControllerB Held { get; private set; }

		public bool HeldIsValid
		{
			get
			{
				if ((Object)(object)Held != (Object)null && Held.isPlayerControlled && !Held.isPlayerDead)
				{
					return (Object)(object)Held.inAnimationWithEnemy == (Object)(object)ai;
				}
				return false;
			}
		}

		public DollGrabController(OGWoodenDollAI ai)
		{
			this.ai = ai;
		}

		public bool Available(ModConfig cfg)
		{
			if (cfg.EnableGrab.Value && (Object)(object)Held == (Object)null)
			{
				return Time.time >= cooldownUntil;
			}
			return false;
		}

		public bool CanGrab(PlayerControllerB player, ModConfig cfg)
		{
			if (Available(cfg) && DollMovement.IsAlive(player) && !player.inSpecialInteractAnimation && (Object)(object)player.inAnimationWithEnemy == (Object)null)
			{
				return !player.isClimbingLadder;
			}
			return false;
		}

		public void StartCooldown(float seconds)
		{
			cooldownUntil = Time.time + seconds;
		}

		public void Attach(PlayerControllerB player)
		{
			if (!((Object)(object)player == (Object)null) && !((Object)(object)Held == (Object)(object)player))
			{
				Detach();
				Held = player;
				heldHeight = 0.6f;
				player.inSpecialInteractAnimation = true;
				player.inAnimationWithEnemy = (EnemyAI)(object)ai;
				player.isCrouching = false;
			}
		}

		public PlayerControllerB Detach()
		{
			PlayerControllerB held = Held;
			Held = null;
			if ((Object)(object)held != (Object)null && (Object)(object)held.inAnimationWithEnemy == (Object)(object)ai)
			{
				held.inSpecialInteractAnimation = false;
				held.inAnimationWithEnemy = null;
			}
			return held;
		}

		public void LateTick(float deltaTime, float holdHeight)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Held == (Object)null)
			{
				return;
			}
			if (!Held.isPlayerControlled || Held.isPlayerDead)
			{
				Detach();
				return;
			}
			Vector3 position = ((Component)ai).transform.position;
			float num = holdHeight;
			RaycastHit val = default(RaycastHit);
			if ((Object)(object)StartOfRound.Instance != (Object)null && Physics.Raycast(position + Vector3.up * 0.8f, Vector3.up, ref val, 10f, StartOfRound.Instance.collidersAndRoomMask, (QueryTriggerInteraction)1))
			{
				float num2 = (((Object)(object)Held.thisController != (Object)null) ? Held.thisController.height : 2.5f);
				num = Mathf.Min(num, ((RaycastHit)(ref val)).point.y - position.y - num2 - 0.1f);
			}
			num = Mathf.Max(num, 0.2f);
			heldHeight = Mathf.MoveTowards(heldHeight, num, deltaTime * 5f);
			((Component)Held).transform.position = position + Vector3.up * heldHeight;
			if ((Object)(object)GameNetworkManager.Instance != (Object)null && (Object)(object)Held == (Object)(object)GameNetworkManager.Instance.localPlayerController)
			{
				Held.ResetFallGravity();
				Held.externalForceAutoFade = Vector3.zero;
			}
		}
	}
	internal sealed class DollMovement
	{
		public const float DefaultPlayerWalkSpeed = 4.6f;

		private readonly OGWoodenDollAI ai;

		private readonly ModConfig cfg;

		private bool hasFacing;

		private float facingYaw;

		public float WanderSpeed => PlayerWalkSpeed() * cfg.NormalSpeedMultiplier.Value;

		public float RunSpeed => PlayerWalkSpeed() * cfg.RunSpeedMultiplier.Value;

		public DollMovement(OGWoodenDollAI ai, ModConfig cfg)
		{
			this.ai = ai;
			this.cfg = cfg;
		}

		public static float PlayerWalkSpeed()
		{
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance != (Object)null && instance.allPlayerScripts != null)
			{
				PlayerControllerB[] allPlayerScripts = instance.allPlayerScripts;
				foreach (PlayerControllerB val in allPlayerScripts)
				{
					if ((Object)(object)val != (Object)null && val.movementSpeed > 0.5f)
					{
						return val.movementSpeed;
					}
				}
			}
			return 4.6f;
		}

		public void Move(float speed, float stoppingDistance)
		{
			hasFacing = false;
			if (!((Object)(object)((EnemyAI)ai).agent == (Object)null) && ((Behaviour)((EnemyAI)ai).agent).enabled)
			{
				((EnemyAI)ai).agent.updateRotation = true;
				((EnemyAI)ai).agent.speed = speed;
				((EnemyAI)ai).agent.stoppingDistance = stoppingDistance;
			}
		}

		public void MoveFacingManually(float speed, float stoppingDistance)
		{
			Move(speed, stoppingDistance);
			if ((Object)(object)((EnemyAI)ai).agent != (Object)null && ((Behaviour)((EnemyAI)ai).agent).enabled)
			{
				((EnemyAI)ai).agent.updateRotation = false;
			}
		}

		public void Halt()
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)ai).StopSearch(((EnemyAI)ai).currentSearch, true);
			((EnemyAI)ai).movingTowardsTargetPlayer = false;
			((EnemyAI)ai).moveTowardsDestination = false;
			if (!((Object)(object)((EnemyAI)ai).agent == (Object)null) && ((Behaviour)((EnemyAI)ai).agent).enabled)
			{
				((EnemyAI)ai).agent.speed = 0f;
				((EnemyAI)ai).agent.velocity = Vector3.zero;
				((EnemyAI)ai).agent.updateRotation = false;
				if (((EnemyAI)ai).agent.isOnNavMesh)
				{
					((EnemyAI)ai).agent.ResetPath();
				}
			}
		}

		public void FaceYaw(float yaw)
		{
			hasFacing = true;
			facingYaw = yaw;
		}

		public void ClearFacing()
		{
			hasFacing = false;
		}

		public void FacePosition(Vector3 position, float yawOffset)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = position - ((Component)ai).transform.position;
			val.y = 0f;
			if (!(((Vector3)(ref val)).sqrMagnitude < 0.0001f))
			{
				Quaternion val2 = Quaternion.LookRotation(val);
				FaceYaw(((Quaternion)(ref val2)).eulerAngles.y + yawOffset);
			}
		}

		public void Tick(float deltaTime)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if (hasFacing)
			{
				Vector3 eulerAngles = ((Component)ai).transform.eulerAngles;
				eulerAngles.y = Mathf.MoveTowardsAngle(eulerAngles.y, facingYaw, 420f * deltaTime);
				((Component)ai).transform.eulerAngles = eulerAngles;
			}
		}

		public static bool IsAlive(PlayerControllerB player)
		{
			if ((Object)(object)player != (Object)null && player.isPlayerControlled)
			{
				return !player.isPlayerDead;
			}
			return false;
		}

		public bool HasLineOfSight(Vector3 from, Vector3 to)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return !Physics.Linecast(from, to, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1);
		}

		private static Vector3 AimPoint(PlayerControllerB player)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)player.gameplayCamera != (Object)null))
			{
				return ((Component)player).transform.position + Vector3.up * 1.5f;
			}
			return ((Component)player.gameplayCamera).transform.position;
		}

		public bool CanDetect(PlayerControllerB player)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			if (!IsAlive(player) || !((EnemyAI)ai).PlayerIsTargetable(player, false, false, true))
			{
				return false;
			}
			Vector3 position = ((EnemyAI)ai).eye.position;
			Vector3 val = AimPoint(player) - position;
			if (((Vector3)(ref val)).magnitude > cfg.DetectionRange.Value)
			{
				return false;
			}
			float value = cfg.DetectionFOV.Value;
			if (value < 359.5f)
			{
				Vector3 val2 = default(Vector3);
				((Vector3)(ref val2))..ctor(val.x, 0f, val.z);
				if (((Vector3)(ref val2)).sqrMagnitude > 0.01f && Vector3.Angle(((Component)ai).transform.forward, val2) > value * 0.5f)
				{
					return false;
				}
			}
			return HasLineOfSight(position, AimPoint(player));
		}

		public bool CanKeepSightOf(PlayerControllerB player)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			if (!IsAlive(player) || !((EnemyAI)ai).PlayerIsTargetable(player, false, false, true))
			{
				return false;
			}
			Vector3 position = ((EnemyAI)ai).eye.position;
			Vector3 val = AimPoint(player);
			Vector3 val2 = val - position;
			if (((Vector3)(ref val2)).magnitude > cfg.DetectionRange.Value * 2f)
			{
				return false;
			}
			return HasLineOfSight(position, val);
		}

		public PlayerControllerB NearestDetectable()
		{
			return Nearest(allowKeptSight: false);
		}

		public PlayerControllerB NearestEngageable()
		{
			return Nearest(allowKeptSight: true);
		}

		private PlayerControllerB Nearest(bool allowKeptSight)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB result = null;
			float num = float.MaxValue;
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if (CanDetect(val) || (allowKeptSight && CanKeepSightOf(val)))
				{
					Vector3 val2 = ((Component)val).transform.position - ((Component)ai).transform.position;
					float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
					if (sqrMagnitude < num)
					{
						num = sqrMagnitude;
						result = val;
					}
				}
			}
			return result;
		}
	}
	internal static class DollRig
	{
		public const string ModelRootName = "Model";

		private static Material[] materials;

		private static bool materialsReady;

		private static readonly List<MeshRenderer> prefabRenderers = new List<MeshRenderer>();

		private static readonly List<int> prefabMaterialIndex = new List<int>();

		public static Transform Build(Transform parent, DollData data)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Expected O, but got Unknown
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = new GameObject("Model").transform;
			transform.SetParent(parent, false);
			Transform[] array = (Transform[])(object)new Transform[data.BoneCount];
			for (int i = 0; i < data.BoneCount; i++)
			{
				Transform transform2 = new GameObject(data.BoneNames[i]).transform;
				transform2.SetParent((data.BoneParents[i] < 0) ? transform : array[data.BoneParents[i]], false);
				transform2.localPosition = new Vector3(data.BoneRestPositions[i * 3], data.BoneRestPositions[i * 3 + 1], data.BoneRestPositions[i * 3 + 2]);
				((Component)transform2).gameObject.layer = ((Component)parent).gameObject.layer;
				array[i] = transform2;
			}
			for (int j = 0; j < data.Parts.Length; j++)
			{
				PartData partData = data.Parts[j];
				Mesh val = new Mesh();
				((Object)val).name = "OGWoodenDoll_" + data.BoneNames[partData.BoneIndex] + "_" + partData.Material;
				int num = partData.Positions.Length / 3;
				Vector3[] array2 = (Vector3[])(object)new Vector3[num];
				Vector3[] array3 = (Vector3[])(object)new Vector3[num];
				Vector2[] array4 = (Vector2[])(object)new Vector2[num];
				for (int k = 0; k < num; k++)
				{
					array2[k] = new Vector3(partData.Positions[k * 3], partData.Positions[k * 3 + 1], partData.Positions[k * 3 + 2]);
					array3[k] = new Vector3(partData.Normals[k * 3], partData.Normals[k * 3 + 1], partData.Normals[k * 3 + 2]);
					array4[k] = new Vector2(partData.Uvs[k * 2], partData.Uvs[k * 2 + 1]);
				}
				val.vertices = array2;
				val.normals = array3;
				val.uv = array4;
				val.triangles = partData.Indices;
				val.RecalculateTangents();
				val.RecalculateBounds();
				Object.DontDestroyOnLoad((Object)(object)val);
				GameObject val2 = new GameObject("Mesh_" + partData.Material)
				{
					layer = ((Component)parent).gameObject.layer
				};
				val2.transform.SetParent(array[partData.BoneIndex], false);
				val2.AddComponent<MeshFilter>().sharedMesh = val;
				MeshRenderer val3 = val2.AddComponent<MeshRenderer>();
				prefabRenderers.Add(val3);
				prefabMaterialIndex.Add(partData.Material);
				((Renderer)val3).shadowCastingMode = (ShadowCastingMode)1;
				((Renderer)val3).receiveShadows = true;
			}
			EnsureMaterials();
			return transform;
		}

		public static Transform[] Bind(Transform enemyRoot, DollData data)
		{
			Transform val = enemyRoot.Find("Model");
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			Transform[] componentsInChildren = ((Component)val).GetComponentsInChildren<Transform>(true);
			Transform[] array = (Transform[])(object)new Transform[data.BoneCount];
			for (int i = 0; i < array.Length; i++)
			{
				Transform[] array2 = componentsInChildren;
				foreach (Transform val2 in array2)
				{
					if (((Object)val2).name == data.BoneNames[i])
					{
						array[i] = val2;
						break;
					}
				}
				if ((Object)(object)array[i] == (Object)null)
				{
					return null;
				}
			}
			return array;
		}

		public static void EnsureMaterials()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			if (materialsReady)
			{
				return;
			}
			Shader val = FindLitShader();
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Debug("HDRP/Lit not available yet; materials will be created when the round scene loads.");
				return;
			}
			materials = (Material[])(object)new Material[4];
			for (int i = 0; i < materials.Length; i++)
			{
				materials[i] = new Material(val);
				Object.DontDestroyOnLoad((Object)(object)materials[i]);
			}
			((Object)materials[0]).name = "OGWoodenDoll_Wood";
			((Object)materials[1]).name = "OGWoodenDoll_Shoe";
			((Object)materials[2]).name = "OGWoodenDoll_Head";
			((Object)materials[3]).name = "OGWoodenDoll_Pin";
			Setup(materials[0], DollAssets.WoodTexture, Color.white, 0.62f);
			Setup(materials[2], DollAssets.HeadTexture, Color.white, 0.62f);
			Setup(materials[1], null, new Color(0.19f, 0.11f, 0.075f), 0.45f);
			Setup(materials[3], null, new Color(0.13f, 0.09f, 0.07f), 0.35f);
			for (int j = 0; j < prefabRenderers.Count; j++)
			{
				if ((Object)(object)prefabRenderers[j] != (Object)null)
				{
					((Renderer)prefabRenderers[j]).sharedMaterial = materials[prefabMaterialIndex[j]];
				}
			}
			materialsReady = true;
		}

		private static Shader FindLitShader()
		{
			Shader val = Shader.Find("HDRP/Lit");
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			Material[] array = Resources.FindObjectsOfTypeAll<Material>();
			foreach (Material val2 in array)
			{
				if ((Object)(object)val2 != (Object)null && (Object)(object)val2.shader != (Object)null && ((Object)val2.shader).name == "HDRP/Lit")
				{
					return val2.shader;
				}
			}
			return null;
		}

		private static void Setup(Material m, Texture2D texture, Color color, float smoothness)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			SetColor(m, "_BaseColor", color);
			SetColor(m, "_Color", color);
			if ((Object)(object)texture != (Object)null)
			{
				if (m.HasProperty("_BaseColorMap"))
				{
					m.SetTexture("_BaseColorMap", (Texture)(object)texture);
				}
				if (m.HasProperty("_MainTex"))
				{
					m.SetTexture("_MainTex", (Texture)(object)texture);
				}
			}
			if (m.HasProperty("_Smoothness"))
			{
				m.SetFloat("_Smoothness", smoothness);
			}
			if (m.HasProperty("_Metallic"))
			{
				m.SetFloat("_Metallic", 0f);
			}
			m.enableInstancing = true;
		}

		private static void SetColor(Material m, string property, Color color)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			if (m.HasProperty(property))
			{
				m.SetColor(property, color);
			}
		}
	}
	internal sealed class DollTwerkController
	{
		public const float TurnAwayAngle = 150f;

		private readonly ModConfig cfg;

		private float nextAllowedTime;

		private float endTime;

		public bool Available
		{
			get
			{
				if (cfg.EnableTwerking.Value)
				{
					return Time.time >= nextAllowedTime;
				}
				return false;
			}
		}

		public bool Finished => Time.time >= endTime;

		public DollTwerkController(ModConfig cfg)
		{
			this.cfg = cfg;
		}

		public void Begin()
		{
			endTime = Time.time + cfg.TwerkDuration.Value;
			nextAllowedTime = endTime + cfg.TwerkCooldown.Value;
		}

		public bool RollTaunt()
		{
			if (!cfg.EnableTwerking.Value || Time.time < nextAllowedTime || Random.value >= 0.5f)
			{
				return false;
			}
			Plugin.Debug("cannot reach its target: taunting");
			endTime = Time.time + cfg.TwerkDuration.Value;
			nextAllowedTime = endTime + cfg.TwerkCooldown.Value;
			return true;
		}
	}
	internal static class EnemyRegistration
	{
		public const int EnemiesLayer = 19;

		public const int ScanNodeLayer = 22;

		public const float Height = 2f;

		public static EnemyType EnemyType;

		public static GameObject Prefab;

		public static TerminalNode InfoNode;

		public static void Register()
		{
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0430: Unknown result type (might be due to invalid IL or missing references)
			//IL_0435: Unknown result type (might be due to invalid IL or missing references)
			//IL_044d: Expected O, but got Unknown
			ModConfig settings = Plugin.Settings;
			GameObject val = NetworkPrefabs.CreateNetworkPrefab("OGWoodenDoll");
			val.tag = "Enemy";
			val.layer = 19;
			NavMeshAgent obj = val.AddComponent<NavMeshAgent>();
			obj.radius = 0.4f;
			obj.height = 2f;
			obj.baseOffset = 0f;
			obj.speed = 3f;
			obj.acceleration = 26f;
			obj.angularSpeed = 300f;
			obj.stoppingDistance = 0f;
			obj.autoBraking = true;
			obj.obstacleAvoidanceType = (ObstacleAvoidanceType)1;
			obj.avoidancePriority = 45;
			AudioSource creatureSFX = CreateSource(val, 1f, 22f);
			AudioSource creatureVoice = CreateSource(Child(val, "Voice", new Vector3(0f, 1.6f, 0f)), 1f, 26f);
			AudioSource footstepSource = CreateSource(Child(val, "Footsteps", new Vector3(0f, 0.1f, 0f)), 0.8f, 18f);
			GameObject val2 = Child(val, "Eye", new Vector3(0f, 1.55f, 0.15f));
			DollRig.Build(val.transform, DollAssets.Data);
			GameObject val3 = Child(val, "Collision", Vector3.zero);
			val3.tag = "Enemy";
			CapsuleCollider val4 = val3.AddComponent<CapsuleCollider>();
			((Collider)val4).isTrigger = true;
			val4.direction = 1;
			val4.center = new Vector3(0f, 1f, 0f);
			val4.height = 2f;
			val4.radius = 0.42f;
			Rigidbody obj2 = val3.AddComponent<Rigidbody>();
			obj2.isKinematic = true;
			obj2.useGravity = false;
			GameObject obj3 = Child(val, "ScanNode", new Vector3(0f, 1.7f, 0f));
			obj3.layer = 22;
			BoxCollider val5 = obj3.AddComponent<BoxCollider>();
			val5.size = new Vector3(0.5f, 0.5f, 0.5f);
			ScanNodeProperties val6 = obj3.AddComponent<ScanNodeProperties>();
			val6.headerText = "OG Wooden Doll";
			val6.subText = "It has seen you";
			val6.minRange = 1;
			val6.maxRange = 14;
			val6.requiresLineOfSight = true;
			val6.nodeType = 1;
			val6.creatureScanID = -1;
			EnemyType val7 = ScriptableObject.CreateInstance<EnemyType>();
			((Object)val7).name = "OGWoodenDollType";
			val7.enemyName = "OGWoodenDoll";
			val7.enemyPrefab = val;
			val7.isOutsideEnemy = false;
			val7.isDaytimeEnemy = false;
			val7.probabilityCurve = AnimationCurve.Constant(0f, 1f, 1f);
			val7.numberSpawnedFalloff = AnimationCurve.Constant(0f, 1f, 1f);
			val7.useNumberSpawnedFalloff = false;
			val7.spawnInGroupsOf = 1;
			val7.PowerLevel = 1f;
			val7.MaxCount = (settings.EnemyEnabled.Value ? settings.MaxSpawnCount.Value : 0);
			val7.canDie = true;
			val7.canBeDestroyed = false;
			val7.destroyOnDeath = false;
			val7.canBeStunned = false;
			val7.stunTimeMultiplier = 1f;
			val7.stunGameDifficultyMultiplier = 0f;
			val7.doorSpeedMultiplier = 1.2f;
			val7.loudnessMultiplier = 1f;
			val7.pushPlayerForce = 0f;
			val7.pushPlayerDistance = 0f;
			val7.timeToPlayAudio = 0f;
			val7.normalizedTimeInDayToLeave = 1f;
			val7.audioClips = (AudioClip[])(object)new AudioClip[0];
			Object.DontDestroyOnLoad((Object)(object)val7);
			OGWoodenDollAI oGWoodenDollAI = val.AddComponent<OGWoodenDollAI>();
			((EnemyAI)oGWoodenDollAI).enemyType = val7;
			((EnemyAI)oGWoodenDollAI).creatureSFX = creatureSFX;
			((EnemyAI)oGWoodenDollAI).creatureVoice = creatureVoice;
			oGWoodenDollAI.footstepSource = footstepSource;
			((EnemyAI)oGWoodenDollAI).eye = val2.transform;
			((EnemyAI)oGWoodenDollAI).dieSFX = DollAssets.SilentClip;
			((EnemyAI)oGWoodenDollAI).AIIntervalTime = 0.2f;
			((EnemyAI)oGWoodenDollAI).updatePositionThreshold = 0.3f;
			((EnemyAI)oGWoodenDollAI).syncMovementSpeed = 0.2f;
			((EnemyAI)oGWoodenDollAI).exitVentAnimationTime = 1f;
			((EnemyAI)oGWoodenDollAI).enemyHP = settings.ShovelHitsToKill.Value;
			oGWoodenDollAI.collisionCollider = (Collider)(object)val4;
			oGWoodenDollAI.scanCollider = (Collider)(object)val5;
			oGWoodenDollAI.scanNode = val6;
			EnemyBehaviourState[] array = (EnemyBehaviourState[])(object)new EnemyBehaviourState[14];
			for (int i = 0; i < array.Length; i++)
			{
				int num = i;
				EnemyBehaviourState val8 = new EnemyBehaviourState();
				DollState dollState = (DollState)i;
				val8.name = dollState.ToString();
				array[num] = val8;
			}
			((EnemyAI)oGWoodenDollAI).enemyBehaviourStates = array;
			val3.AddComponent<EnemyAICollisionDetect>().mainScript = (EnemyAI)(object)oGWoodenDollAI;
			Utilities.FixMixerGroups(val);
			int num2 = (settings.EnemyEnabled.Value ? settings.SpawnRarity.Value : 0);
			InfoNode = ScriptableObject.CreateInstance<TerminalNode>();
			((Object)InfoNode).name = "OGWoodenDollInfo";
			InfoNode.creatureName = "OG Wooden Doll";
			InfoNode.clearPreviousText = true;
			InfoNode.maxCharactersToType = 35;
			InfoNode.displayText = "OG WOODEN DOLL\n\nSigurd's danger level: 40%\n\nScientific name: Pupa lignea spectans\n\nA two-metre jointed doll turned from golden-brown wood. Nobody has found the strings. It shuffles around the facility on stiff little legs, and once it can see you its head turns your way and stays there - all the way round, if it has to be.\n\nIt only comes for you once it has seen you with its body facing you, so stay behind it or out of sight. When it does come, it runs. Up close it either flails both arms hard enough to send you across the room, or picks you up, carries you off over its head and throws you away. Now and then, right after it spots someone, it stops, turns its back and dances. It keeps staring while it does. Nobody knows why. Use the time.\n\nFour good hits with a shovel will drop it.\n\n";
			Object.DontDestroyOnLoad((Object)(object)InfoNode);
			Enemies.RegisterEnemy(val7, num2, (LevelTypes)(-1), (SpawnType)0, InfoNode, (TerminalKeyword)null);
			EnemyType = val7;
			Prefab = val;
			Plugin.Log.LogInfo((object)("Registered OGWoodenDoll (indoor, rarity " + num2 + ", max " + val7.MaxCount + ")."));
		}

		private static GameObject Child(GameObject parent, string name, Vector3 localPosition)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			GameObject val = new GameObject(name)
			{
				layer = parent.layer
			};
			val.transform.SetParent(parent.transform, false);
			val.transform.localPosition = localPosition;
			return val;
		}

		private static AudioSource CreateSource(GameObject go, float volume, float maxDistance)
		{
			AudioSource obj = go.AddComponent<AudioSource>();
			obj.playOnAwake = false;
			obj.loop = false;
			obj.spatialBlend = 1f;
			obj.dopplerLevel = 0f;
			obj.rolloffMode = (AudioRolloffMode)1;
			obj.minDistance = 2f;
			obj.maxDistance = maxDistance;
			obj.volume = volume;
			return obj;
		}
	}
	internal sealed class HeadTrackingController
	{
		public const float SwitchMargin = 0.75f;

		private const float HeadCentreAbovePivot = 0.3f;

		private readonly Transform root;

		private readonly Transform headPivot;

		public bool Enabled = true;

		public float RotationSpeed = 180f;

		public float MaxYaw = 180f;

		public float MaxPitch = 30f;

		public float Range;

		private float yaw;

		private float pitch;

		public PlayerControllerB Target { get; private set; }

		public HeadTrackingController(Transform root, Transform headPivot)
		{
			this.root = root;
			this.headPivot = headPivot;
		}

		public void SetTarget(PlayerControllerB player)
		{
			Target = player;
		}

		public static bool IsWatchable(PlayerControllerB player)
		{
			if ((Object)(object)player != (Object)null && player.isPlayerControlled)
			{
				return !player.isPlayerDead;
			}
			return false;
		}

		public void Tick(float deltaTime)
		{
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			if (!Enabled)
			{
				return;
			}
			float target = 0f;
			float target2 = 0f;
			PlayerControllerB target3 = Target;
			if (IsWatchable(target3))
			{
				Vector3 val = headPivot.position + root.up * 0.3f;
				Vector3 val2 = (((Object)(object)target3.gameplayCamera != (Object)null) ? ((Component)target3.gameplayCamera).transform.position : (((Component)target3).transform.position + Vector3.up * 1.6f)) - val;
				if (((Vector3)(ref val2)).sqrMagnitude > 0.0004f && (Range <= 0f || ((Vector3)(ref val2)).magnitude <= Range))
				{
					Vector3 val3 = Quaternion.Inverse(root.rotation) * val2;
					target = Mathf.Atan2(val3.x, val3.z) * 57.29578f;
					float num = Mathf.Sqrt(val3.x * val3.x + val3.z * val3.z);
					target2 = (0f - Mathf.Atan2(val3.y, num)) * 57.29578f;
				}
			}
			float maxStep = RotationSpeed * deltaTime;
			yaw = HeadYawSolver.Step(yaw, target, MaxYaw, maxStep);
			pitch = HeadYawSolver.StepPitch(pitch, target2, MaxPitch, maxStep);
			headPivot.rotation = root.rotation * Quaternion.Euler(pitch, yaw, 0f);
		}
	}
	public static class HeadYawSolver
	{
		public const float SeamHysteresis = 25f;

		public static float Step(float current, float target, float maxYaw, float maxStep)
		{
			maxYaw = Clamp(maxYaw, 0f, 180f);
			target = Clamp(WrapSigned(target), 0f - maxYaw, maxYaw);
			current = Clamp(current, 0f - maxYaw, maxYaw);
			if (maxYaw >= 179f && Math.Abs(target - current) > 180f && 180f - Math.Abs(target) < 25f)
			{
				target = ((current >= 0f) ? maxYaw : (0f - maxYaw));
			}
			float value = target - current;
			if (Math.Abs(value) <= maxStep)
			{
				return target;
			}
			return current + (float)Math.Sign(value) * maxStep;
		}

		public static float StepPitch(float current, float target, float maxPitch, float maxStep)
		{
			target = Clamp(target, 0f - maxPitch, maxPitch);
			float value = target - current;
			if (Math.Abs(value) <= maxStep)
			{
				return target;
			}
			return current + (float)Math.Sign(value) * maxStep;
		}

		public static float WrapSigned(float degrees)
		{
			degrees %= 360f;
			if (degrees > 180f)
			{
				degrees -= 360f;
			}
			if (degrees <= -180f)
			{
				degrees += 360f;
			}
			return degrees;
		}

		public static int ChooseTarget(float[] distances, int current, float switchMargin)
		{
			int num = -1;
			for (int i = 0; i < distances.Length; i++)
			{
				if (IsValid(distances[i]) && (num < 0 || distances[i] < distances[num]))
				{
					num = i;
				}
			}
			if (num < 0)
			{
				return -1;
			}
			if (current >= 0 && current < distances.Length && IsValid(distances[current]) && distances[current] - distances[num] < switchMargin)
			{
				return current;
			}
			return num;
		}

		private static bool IsValid(float d)
		{
			if (d >= 0f && !float.IsInfinity(d))
			{
				return !float.IsNaN(d);
			}
			return false;
		}

		private static float Clamp(float v, float lo, float hi)
		{
			if (!(v < lo))
			{
				if (!(v > hi))
				{
					return v;
				}
				return hi;
			}
			return lo;
		}
	}
	public sealed class ModConfig
	{
		public readonly ConfigEntry<bool> EnemyEnabled;

		public readonly ConfigEntry<int> SpawnRarity;

		public readonly ConfigEntry<int> MaxSpawnCount;

		public readonly ConfigEntry<float> NormalSpeedMultiplier;

		public readonly ConfigEntry<float> RunSpeedMultiplier;

		public readonly ConfigEntry<float> DetectionRange;

		public readonly ConfigEntry<float> DetectionFOV;

		public readonly ConfigEntry<float> LoseSightSeconds;

		public readonly ConfigEntry<float> AttackRange;

		public readonly ConfigEntry<int> StrikeDamage;

		public readonly ConfigEntry<int> MaxHitsPerAttack;

		public readonly ConfigEntry<float> AttackCooldown;

		public readonly ConfigEntry<float> FlingForce;

		public readonly ConfigEntry<float> FlingUpForce;

		public readonly ConfigEntry<float> AttackVolume;

		public readonly ConfigEntry<bool> EnableGrab;

		public readonly ConfigEntry<float> GrabCarrySeconds;

		public readonly ConfigEntry<float> GrabHoldHeight;

		public readonly ConfigEntry<float> GrabCooldown;

		public readonly ConfigEntry<int> ThrowDamage;

		public readonly ConfigEntry<float> ThrowForce;

		public readonly ConfigEntry<float> ThrowUpForce;

		public readonly ConfigEntry<float> WalkingSoundChance;

		public readonly ConfigEntry<bool> EnableTwerking;

		public readonly ConfigEntry<float> StareWeight;

		public readonly ConfigEntry<float> TwerkWeight;

		public readonly ConfigEntry<float> FlailWeight;

		public readonly ConfigEntry<float> GrabWeight;

		public readonly ConfigEntry<float> StareSeconds;

		public readonly ConfigEntry<float> PointChance;

		public readonly ConfigEntry<float> TwerkDuration;

		public readonly ConfigEntry<float> TwerkCooldown;

		public readonly ConfigEntry<int> ShovelHitsToKill;

		public readonly ConfigEntry<bool> EnableHeadTracking;

		public readonly ConfigEntry<float> HeadRotationSpeed;

		public readonly ConfigEntry<float> MaxHeadYaw;

		public readonly ConfigEntry<float> MaxHeadPitch;

		public readonly ConfigEntry<float> HeadTrackingRange;

		public readonly ConfigEntry<bool> HeadRequiresLineOfSight;

		public readonly ConfigEntry<bool> EnableDebugLogs;

		public readonly ConfigEntry<bool> DebugSpawnOnLanding;

		public readonly ConfigEntry<int> ConfigVersion;

		public const int CurrentConfigVersion = 4;

		public ModConfig(ConfigFile file)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Expected O, but got Unknown
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Expected O, but got Unknown
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Expected O, but got Unknown
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Expected O, but got Unknown
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Expected O, but got Unknown
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Expected O, but got Unknown
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Expected O, but got Unknown
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Expected O, but got Unknown
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Expected O, but got Unknown
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Expected O, but got Unknown
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Expected O, but got Unknown
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Expected O, but got Unknown
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Expected O, but got Unknown
			//IL_0398: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a2: Expected O, but got Unknown
			//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03db: Expected O, but got Unknown
			//IL_040a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0414: Expected O, but got Unknown
			//IL_0439: Unknown result type (might be due to invalid IL or missing references)
			//IL_0443: Expected O, but got Unknown
			//IL_0472: Unknown result type (might be due to invalid IL or missing references)
			//IL_047c: Expected O, but got Unknown
			//IL_04ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b5: Expected O, but got Unknown
			//IL_04e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ee: Expected O, but got Unknown
			//IL_051d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0527: Expected O, but got Unknown
			//IL_0556: Unknown result type (might be due to invalid IL or missing references)
			//IL_0560: Expected O, but got Unknown
			//IL_058f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0599: Expected O, but got Unknown
			//IL_05c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d2: Expected O, but got Unknown
			//IL_0601: Unknown result type (might be due to invalid IL or missing references)
			//IL_060b: Expected O, but got Unknown
			//IL_0656: Unknown result type (might be due to invalid IL or missing references)
			//IL_0660: Expected O, but got Unknown
			//IL_068f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0699: Expected O, but got Unknown
			//IL_06bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c7: Expected O, but got Unknown
			//IL_0712: Unknown result type (might be due to invalid IL or missing references)
			//IL_071c: Expected O, but got Unknown
			//IL_074b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0755: Expected O, but got Unknown
			//IL_0784: Unknown result type (might be due to invalid IL or missing references)
			//IL_078e: Expected O, but got Unknown
			//IL_07bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c7: Expected O, but got Unknown
			EnemyEnabled = file.Bind<bool>("Spawning", "EnemyEnabled", true, "Whether the doll can spawn. When false it stays registered (so lobbies with different settings still connect) but never spawns.");
			SpawnRarity = file.Bind<int>("Spawning", "SpawnRarity", 20, new ConfigDescription("Spawn weight among indoor enemies on every moon.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>()));
			MaxSpawnCount = file.Bind<int>("Spawning", "MaxSpawnCount", 2, new ConfigDescription("Maximum number of dolls alive at once.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 20), Array.Empty<object>()));
			NormalSpeedMultiplier = file.Bind<float>("Movement", "NormalSpeedMultiplier", 0.65f, new ConfigDescription("Wandering speed as a multiple of the player's walking (not sprinting) speed.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 3f), Array.Empty<object>()));
			RunSpeedMultiplier = file.Bind<float>("Movement", "RunSpeedMultiplier", 1.4f, new ConfigDescription("Running speed once aggressive (chasing, attacking, searching, carrying a player) as a multiple of the player's walking speed. Players sprint at about 2.25.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 4f), Array.Empty<object>()));
			WalkingSoundChance = file.Bind<float>("Movement", "WalkingSoundChance", 0.05f, new ConfigDescription("Chance (0-1), rolled every 10 seconds while the doll wanders, to play walking.wav. 0.05 is roughly once every three minutes.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			DetectionRange = file.Bind<float>("Detection", "DetectionRange", 15f, new ConfigDescription("How far the doll can spot a player, in metres. With the defaults this equals HeadTrackingRange: if it is staring at you, it is coming for you.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 60f), Array.Empty<object>()));
			DetectionFOV = file.Bind<float>("Detection", "DetectionFOV", 360f, new ConfigDescription("Field of view of the body, in degrees. 360 = it notices you in any direction (its head turns all the way round). Lower it to make sneaking up behind it possible.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 360f), Array.Empty<object>()));
			LoseSightSeconds = file.Bind<float>("Detection", "LoseSightSeconds", 10f, new ConfigDescription("Seconds it keeps hunting a player it can no longer see before it goes back to wandering.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 120f), Array.Empty<object>()));
			AttackRange = file.Bind<float>("Attack", "AttackRange", 2f, new ConfigDescription("Distance at which the doll starts an attack (flail or grab), and the reach of each strike, in metres.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 6f), Array.Empty<object>()));
			StrikeDamage = file.Bind<int>("Attack", "StrikeDamage", 25, new ConfigDescription("Damage per arm strike that lands.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			MaxHitsPerAttack = file.Bind<int>("Attack", "MaxHitsPerAttack", 2, new ConfigDescription("How many of the swings in one flailing sequence can deal damage.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
			AttackCooldown = file.Bind<float>("Attack", "AttackCooldown", 1f, new ConfigDescription("Seconds after a flailing sequence before the next one can start.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 30f), Array.Empty<object>()));
			FlingForce = file.Bind<float>("Attack", "FlingForce", 26f, new ConfigDescription("How hard a strike that lands sends the player flying away from the doll. 0 disables it.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			FlingUpForce = file.Bind<float>("Attack", "FlingUpForce", 9f, new ConfigDescription("Upward part of the fling.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 60f), Array.Empty<object>()));
			AttackVolume = file.Bind<float>("Attack", "AttackVolume", 0.35f, new ConfigDescription("Volume of the attack sound (0-1). This one is read from each player's own file.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			EnableGrab = file.Bind<bool>("Grab", "EnableGrab", true, "Whether the doll may grab a player, carry them off overhead and throw them, instead of flailing.");
			GrabCarrySeconds = file.Bind<float>("Grab", "GrabCarrySeconds", 3f, new ConfigDescription("How long it runs away with the player before throwing them.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 20f), Array.Empty<object>()));
			GrabHoldHeight = file.Bind<float>("Grab", "GrabHoldHeight", 1.95f, new ConfigDescription("Height of the carried player's feet above the floor, in metres. Lowered automatically under low ceilings.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.2f, 4f), Array.Empty<object>()));
			GrabCooldown = file.Bind<float>("Grab", "GrabCooldown", 4f, new ConfigDescription("Seconds after a throw before the same doll can grab again.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 300f), Array.Empty<object>()));
			ThrowDamage = file.Bind<int>("Grab", "ThrowDamage", 40, new ConfigDescription("Damage dealt when the player is thrown.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			ThrowForce = file.Bind<float>("Grab", "ThrowForce", 40f, new ConfigDescription("Forward force of the throw.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 150f), Array.Empty<object>()));
			ThrowUpForce = file.Bind<float>("Grab", "ThrowUpForce", 10f, new ConfigDescription("Upward force of the throw.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 60f), Array.Empty<object>()));
			StareWeight = file.Bind<float>("Behaviour", "StareWeight", 1f, new ConfigDescription("Relative chance that it just stands and stares (sometimes pointing). Never twice in a row. 0 = never.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
			TwerkWeight = file.Bind<float>("Behaviour", "TwerkWeight", 1f, new ConfigDescription("Relative chance that it twerks. Skipped while TwerkCooldown is running. 0 = never.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
			FlailWeight = file.Bind<float>("Behaviour", "FlailWeight", 1f, new ConfigDescription("Relative chance that it runs at the player to flail. 0 = never.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
			GrabWeight = file.Bind<float>("Behaviour", "GrabWeight", 1f, new ConfigDescription("Relative chance that it runs at the player to grab. Skipped while GrabCooldown is running. 0 = never.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
			StareSeconds = file.Bind<float>("Behaviour", "StareSeconds", 10f, new ConfigDescription("How long a stare lasts.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 60f), Array.Empty<object>()));
			PointChance = file.Bind<float>("Behaviour", "PointChance", 0.5f, new ConfigDescription("Chance (0-1) that a stare comes with one arm pointed at the player.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			EnableTwerking = file.Bind<bool>("Twerk", "EnableTwerking", true, "Whether the doll may twerk.");
			TwerkDuration = file.Bind<float>("Twerk", "TwerkDuration", 2.5f, new ConfigDescription("Length of the dance in seconds.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 20f), Array.Empty<object>()));
			TwerkCooldown = file.Bind<float>("Twerk", "TwerkCooldown", 8f, new ConfigDescription("Minimum seconds between two dances of the same doll.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 600f), Array.Empty<object>()));
			ShovelHitsToKill = file.Bind<int>("Health", "ShovelHitsToKill", 4, new ConfigDescription("Health, measured in shovel hits.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
			EnableHeadTracking = file.Bind<bool>("HeadTracking", "EnableHeadTracking", true, "Whether the head turns to stare at the nearest living player.");
			HeadRotationSpeed = file.Bind<float>("HeadTracking", "HeadRotationSpeed", 180f, new ConfigDescription("Head turning speed in degrees per second.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 1440f), Array.Empty<object>()));
			MaxHeadYaw = file.Bind<float>("HeadTracking", "MaxHeadYaw", 180f, new ConfigDescription("How far the head can turn left or right of the body's forward direction, in degrees. 180 lets it look straight backwards.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 180f), Array.Empty<object>()));
			MaxHeadPitch = file.Bind<float>("HeadTracking", "MaxHeadPitch", 30f, new ConfigDescription("How far the head can tilt up or down, in degrees.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 80f), Array.Empty<object>()));
			HeadTrackingRange = file.Bind<float>("HeadTracking", "HeadTrackingRange", 15f, new ConfigDescription("Maximum distance at which the head follows a player, in metres. 0 = unlimited.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1000f), Array.Empty<object>()));
			HeadRequiresLineOfSight = file.Bind<bool>("HeadTracking", "HeadRequiresLineOfSight", true, "True: the head faces forward until the doll has a clear view of a player, then stares at the closest one it can see (in any direction). False: it stares at the closest player even through walls.");
			EnableDebugLogs = file.Bind<bool>("Debug", "EnableDebugLogs", false, "Log state changes, twerk rolls and strikes.");
			DebugSpawnOnLanding = file.Bind<bool>("Debug", "DebugSpawnOnLanding", false, "Testing aid: the host spawns one doll at the indoor AI node nearest the main entrance every time the ship lands.");
			ConfigVersion = file.Bind<int>("Internal", "ConfigVersion", 0, "Used by the mod to apply new default values after an update. Do not edit.");
			if (ConfigVersion.Value < 4)
			{
				ConfigEntryBase[] array = (ConfigEntryBase[])(object)((ConfigVersion.Value >= 3) ? new ConfigEntryBase[2]
				{
					(ConfigEntryBase)RunSpeedMultiplier,
					(ConfigEntryBase)TwerkCooldown
				} : new ConfigEntryBase[7]
				{
					(ConfigEntryBase)RunSpeedMultiplier,
					(ConfigEntryBase)DetectionRange,
					(ConfigEntryBase)DetectionFOV,
					(ConfigEntryBase)AttackCooldown,
					(ConfigEntryBase)GrabCooldown,
					(ConfigEntryBase)HeadTrackingRange,
					(ConfigEntryBase)TwerkCooldown
				});
				foreach (ConfigEntryBase obj in array)
				{
					obj.BoxedValue = obj.DefaultValue;
				}
				ConfigVersion.Value = 4;
				file.Save();
			}
		}
	}
	public enum DollState
	{
		Wandering,
		Alert,
		Twerking,
		Chasing,
		Attacking,
		Searching,
		Grabbing,
		Carrying,
		Throwing,
		ChasingToGrab,
		Staring,
		Pointing,
		Dying,
		Dead
	}
	public class OGWoodenDollAI : EnemyAI
	{
		private enum Behaviour
		{
			None,
			Stare,
			Twerk,
			Flail,
			Grab
		}

		private const float AlertDuration = 0.35f;

		private const float HeadTargetInterval = 0.2f;

		private const float HeadSightMemory = 1f;

		private const float WalkingSoundInterval = 10f;

		public AudioSource footstepSource;

		public Collider collisionCollider;

		public Collider scanCollider;

		public ScanNodeProperties scanNode;

		private ModConfig cfg;

		private Transform[] bones;

		private int headBone;

		private DollAnimator animator;

		private HeadTrackingController head;

		private DollAudio sound;

		private DollDeathController death;

		private DollGrabController grab;

		private float holdHeight = 1.95f;

		private DollMovement movement;

		private DollAttack attack;

		private DollTwerkController twerk;

		private readonly AISearchRoutine roamSearch = new AISearchRoutine();

		private readonly AISearchRoutine lookSearch = new AISearchRoutine();

		private float stateTimer;

		private float lastSeenTime;

		private Vector3 lastKnownPosition;

		private bool reachedLastKnown;

		private float headTargetTimer;

		private int headTargetId = -1;

		private float[] headDistances;

		private float[] headLastSeen;

		private float walkingSoundTimer;

		private bool throwReleased;

		private PlayerControllerB huntedPlayer;

		private float stuckTimer;

		private float flankUntil;

		private float carryStallTimer;

		private Behaviour lastBehaviour;

		private Vector3 lastPosition;

		private float groundSpeed;

		private bool deathHandled;

		private int presentedState;

		private int syncedHeadTarget = -1;

		private bool hasSyncedHeadSettings;

		private bool syncedHeadEnabled;

		private float syncedHeadSpeed;

		private float syncedHeadYaw;

		private float syncedHeadPitch;

		private float syncedHeadRange;

		internal DollState State => (DollState)base.currentBehaviourStateIndex;

		private bool IsChasing
		{
			get
			{
				if (State != DollState.Chasing)
				{
					return State == DollState.ChasingToGrab;
				}
				return true;
			}
		}

		public override void Start()
		{
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).Start();
			cfg = Plugin.Settings;
			bones = DollRig.Bind(((Component)this).transform, DollAssets.Data);
			if (bones == null)
			{
				Plugin.Log.LogError((object)"OGWoodenDoll: rig not found on the spawned enemy.");
				return;
			}
			headBone = DollAssets.Data.FindBone("HeadPivot");
			animator = new DollAnimator(DollAssets.Data, bones);
			animator.Footstep += OnFootstep;
			head = new HeadTrackingController(((Component)this).transform, bones[headBone]);
			sound = new DollAudio(base.creatureSFX, base.creatureVoice, footstepSource);
			death = new DollDeathController(this);
			grab = new DollGrabController(this);
			lastPosition = ((Component)this).transform.position;
			if ((Object)(object)scanNode != (Object)null && (Object)(object)EnemyRegistration.InfoNode != (Object)null && EnemyRegistration.InfoNode.creatureFileID > 0)
			{
				scanNode.creatureScanID = EnemyRegistration.InfoNode.creatureFileID;
			}
			if (((NetworkBehaviour)this).IsServer)
			{
				movement = new DollMovement(this, cfg);
				attack = new DollAttack(this, cfg, movement, DollAssets.Data.Clips["attack"]);
				twerk = new DollTwerkController(cfg);
				lookSearch.searchWidth = 25f;
				base.enemyHP = Mathf.Max(1, cfg.ShovelHitsToKill.Value);
				hasSyncedHeadSettings = true;
				syncedHeadEnabled = cfg.EnableHeadTracking.Value;
				syncedHeadSpeed = cfg.HeadRotationSpeed.Value;
				syncedHeadYaw = cfg.MaxHeadYaw.Value;
				syncedHeadPitch = cfg.MaxHeadPitch.Value;
				syncedHeadRange = cfg.HeadTrackingRange.Value;
				holdHeight = cfg.GrabHoldHeight.Value;
				walkingSoundTimer = 10f;
				ApplyHeadSettings();
				SyncSettingsClientRpc(cfg.EnableHeadTracking.Value, cfg.HeadRotationSpeed.Value, cfg.MaxHeadYaw.Value, cfg.MaxHeadPitch.Value, cfg.HeadTrackingRange.Value, base.enemyHP, holdHeight);
				BeginWandering();
			}
			else
			{
				ApplyHeadSettings();
				head.SetTarget(PlayerById(syncedHeadTarget));
				if (State != DollState.Wandering && State < DollState.Dying)
				{
					Present(State);
				}
			}
		}

		public override void Update()
		{
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).Update();
			if (animator == null)
			{
				return;
			}
			float deltaTime = Time.deltaTime;
			sound.Tick(deltaTime);
			if (base.isEnemyDead || deathHandled)
			{
				death.Tick(deltaTime, animator.ClipLength("death"));
			}
			else
			{
				if (!((NetworkBehaviour)this).IsServer || movement == null)
				{
					return;
				}
				stateTimer += deltaTime;
				movement.Tick(deltaTime);
				UpdateHeadTarget(deltaTime);
				switch (State)
				{
				case DollState.Alert:
					if (DollMovement.IsAlive(base.targetPlayer))
					{
						movement.FacePosition(((Component)base.targetPlayer).transform.position, 0f);
					}
					if (stateTimer >= 0.35f)
					{
						ResumeAggression();
					}
					break;
				case DollState.Staring:
				case DollState.Pointing:
					if (DollMovement.IsAlive(base.targetPlayer))
					{
						movement.FacePosition(((Component)base.targetPlayer).transform.position, 0f);
					}
					if (stateTimer >= cfg.StareSeconds.Value)
					{
						ResumeAggression();
					}
					break;
				case DollState.Twerking:
					if (DollMovement.IsAlive(base.targetPlayer))
					{
						movement.FacePosition(((Component)base.targetPlayer).transform.position, 150f);
					}
					if (twerk.Finished)
					{
						ResumeAggression();
					}
					break;
				case DollState.Attacking:
					if (DollMovement.IsAlive(base.targetPlayer))
					{
						movement.FacePosition(((Component)base.targetPlayer).transform.position, 0f);
					}
					attack.Tick(deltaTime);
					if (attack.Finished)
					{
						attack.End();
						ResumeAggression();
					}
					break;
				case DollState.Grabbing:
					if (!grab.HeldIsValid)
					{
						AbortGrab();
					}
					else if (stateTimer >= animator.ClipLength("grab"))
					{
						BeginCarry();
					}
					break;
				case DollState.Carrying:
					if (!grab.HeldIsValid)
					{
						AbortGrab();
						break;
					}
					if (stateTimer >= cfg.GrabCarrySeconds.Value)
					{
						BeginThrow();
						break;
					}
					carryStallTimer = ((groundSpeed < 0.6f) ? (carryStallTimer + deltaTime) : 0f);
					if (carryStallTimer > 0.5f)
					{
						carryStallTimer = 0f;
						RunTo(RoundManager.Instance.GetRandomNavMeshPositionInRadius(((Component)this).transform.position, 25f, default(NavMeshHit)), "carry stalled, new escape point");
					}
					break;
				case DollState.Throwing:
					if (!throwReleased && stateTimer >= ThrowReleaseTime())
					{
						throwReleased = true;
						ThrowHeldPlayer();
					}
					if (stateTimer >= animator.ClipLength("throw"))
					{
						attack.End();
						grab.StartCooldown(cfg.GrabCooldown.Value);
						ResumeAggression();
					}
					break;
				case DollState.Chasing:
				case DollState.Searching:
				case DollState.ChasingToGrab:
					break;
				}
			}
		}

		private void LateUpdate()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			if (animator == null)
			{
				return;
			}
			float deltaTime = Time.deltaTime;
			Vector3 position = ((Component)this).transform.position;
			Vector3 val = position - lastPosition;
			val.y = 0f;
			lastPosition = position;
			float num = ((deltaTime > 0.0001f) ? (((Vector3)(ref val)).magnitude / deltaTime) : 0f);
			if (num > 20f)
			{
				num = 0f;
			}
			groundSpeed = Mathf.Lerp(groundSpeed, num, 1f - Mathf.Exp(-12f * deltaTime));
			int num2;
			int num3;
			if (!base.isEnemyDead)
			{
				num2 = (deathHandled ? 1 : 0);
				if (num2 == 0)
				{
					num3 = ((State == DollState.Wandering || IsChasing || State == DollState.Searching || State == DollState.Attacking || State == DollState.Carrying) ? 1 : 0);
					goto IL_00cb;
				}
			}
			else
			{
				num2 = 1;
			}
			num3 = 0;
			goto IL_00cb;
			IL_00cb:
			bool flag = (byte)num3 != 0;
			animator.Tick(deltaTime, flag ? groundSpeed : 0f, flag);
			if (num2 == 0)
			{
				head.Tick(deltaTime);
			}
			grab.LateTick(deltaTime, holdHeight);
		}

		public override void OnDestroy()
		{
			if (sound != null)
			{
				sound.StopAll();
			}
			if (grab != null)
			{
				grab.Detach();
			}
			((EnemyAI)this).OnDestroy();
		}

		private void OnFootstep(int foot)
		{
			sound.PlayFootstep(foot);
		}

		public override void DoAIInterval()
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).DoAIInterval();
			if (base.isEnemyDead || deathHandled || movement == null || (Object)(object)StartOfRound.Instance == (Object)null)
			{
				return;
			}
			switch (State)
			{
			case DollState.Wandering:
			{
				if (!roamSearch.inProgress)
				{
					((EnemyAI)this).StartSearch(((Component)this).transform.position, roamSearch);
				}
				PlayerControllerB val3 = movement.NearestDetectable();
				if ((Object)(object)val3 != (Object)null)
				{
					BeginAlert(val3);
					break;
				}
				walkingSoundTimer -= base.AIIntervalTime;
				if (walkingSoundTimer <= 0f)
				{
					walkingSoundTimer = 10f;
					if (groundSpeed > 0.5f && Random.value < cfg.WalkingSoundChance.Value)
					{
						PlayWalkingSoundClientRpc();
					}
				}
				break;
			}
			case DollState.Chasing:
			case DollState.ChasingToGrab:
			{
				PlayerControllerB val2 = movement.NearestEngageable();
				if ((Object)(object)val2 == (Object)null)
				{
					BeginSearch();
					break;
				}
				NoteSeen(val2);
				bool flag = attack.InRange(val2);
				if (flag && attack.Ready)
				{
					if (State == DollState.ChasingToGrab && grab.CanGrab(val2, cfg))
					{
						BeginGrab(val2);
					}
					else
					{
						BeginAttack();
					}
					break;
				}
				if (flag)
				{
					movement.FacePosition(((Component)val2).transform.position, 0f);
					stuckTimer = 0f;
				}
				else
				{
					movement.ClearFacing();
					stuckTimer = ((groundSpeed < 0.4f) ? (stuckTimer + base.AIIntervalTime) : 0f);
					if (stuckTimer > 1.2f)
					{
						stuckTimer = 0f;
						if (twerk.RollTaunt())
						{
							lastBehaviour = Behaviour.Twerk;
							BeginTwerk();
							break;
						}
						flankUntil = Time.time + 2.5f;
						RunTo(RoundManager.Instance.GetRandomNavMeshPositionInRadius(((Component)val2).transform.position, 8f, default(NavMeshHit)), "cannot reach target, flanking");
					}
				}
				if (Time.time >= flankUntil)
				{
					((EnemyAI)this).SetMovingTowardsTargetPlayer(val2);
				}
				break;
			}
			case DollState.Staring:
			case DollState.Pointing:
			{
				PlayerControllerB val4 = movement.NearestEngageable();
				if ((Object)(object)val4 == (Object)null)
				{
					BeginSearch();
				}
				else
				{
					NoteSeen(val4);
				}
				break;
			}
			case DollState.Searching:
			{
				PlayerControllerB val = movement.NearestDetectable();
				if ((Object)(object)val != (Object)null)
				{
					NoteSeen(val);
					BeginChase();
					break;
				}
				if (Time.time - lastSeenTime >= cfg.LoseSightSeconds.Value)
				{
					BeginWandering();
					break;
				}
				if (DollMovement.IsAlive(huntedPlayer) && ((EnemyAI)this).PlayerIsTargetable(huntedPlayer, false, false, true))
				{
					((EnemyAI)this).SetMovingTowardsTargetPlayer(huntedPlayer);
					break;
				}
				if (base.movingTowardsTargetPlayer)
				{
					base.movingTowardsTargetPlayer = false;
					((EnemyAI)this).SetDestinationToPosition(lastKnownPosition, false);
				}
				if (!reachedLastKnown && (Vector3.Distance(((Component)this).transform.position, lastKnownPosition) < 2f || stateTimer > 5f))
				{
					reachedLastKnown = true;
					((EnemyAI)this).StartSearch(lastKnownPosition, lookSearch);
				}
				break;
			}
			}
		}

		private void NoteSeen(PlayerControllerB player)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			base.targetPlayer = player;
			lastSeenTime = Time.time;
			lastKnownPosition = ((Component)player).transform.position;
		}

		private void HostSetState(DollState state)
		{
			stateTimer = 0f;
			if (State != state)
			{
				Plugin.Debug(State.ToString() + " -> " + state);
				SetLocalState(state);
				Present(state);
				SetStateClientRpc((int)state);
			}
		}

		private void BeginWandering()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			base.targetPlayer = null;
			base.movingTowardsTargetPlayer = false;
			((EnemyAI)this).StopSearch(base.currentSearch, true);
			movement.Move(movement.WanderSpeed, 0f);
			HostSetState(DollState.Wandering);
			((EnemyAI)this).StartSearch(((Component)this).transform.position, roamSearch);
		}

		private void BeginAlert(PlayerControllerB player)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			NoteSeen(player);
			movement.Halt();
			movement.FacePosition(((Component)player).transform.position, 0f);
			HostSetState(DollState.Alert);
		}

		private void BeginTwerk()
		{
			movement.Halt();
			HostSetState(DollState.Twerking);
		}

		private void BeginStare()
		{
			movement.Halt();
			bool flag = Random.value < cfg.PointChance.Value;
			Plugin.Debug(flag ? "stares and points" : "stares");
			HostSetState(flag ? DollState.Pointing : DollState.Staring);
		}

		private void ResumeAggression()
		{
			PlayerControllerB val = movement.NearestEngageable();
			if ((Object)(object)val == (Object)null)
			{
				BeginSearch();
				return;
			}
			NoteSeen(val);
			lastBehaviour = PickBehaviour(allowPassive: true);
			switch (last