Decompiled source of Wraith v1.0.0

WraithMod.dll

Decompiled 28 minutes ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace WraithMod
{
	[BepInPlugin("SoulMods.Wraith", "Wraith", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "SoulMods.Wraith";

		public const string Name = "Wraith";

		public const string Version = "1.0.0";

		public static ManualLogSource Log;

		public static Plugin Instance;

		public static ConfigEntry<string> SpawnMoons;

		public static ConfigEntry<int> SpawnRarity;

		public static ConfigEntry<float> PowerLevel;

		public static ConfigEntry<int> Damage;

		public static ConfigEntry<float> CloseHearingRange;

		public static ConfigEntry<float> TouchSenseRange;

		public static ConfigEntry<float> VanishDistance;

		public static ConfigEntry<float> JumpNoiseRange;

		public static ConfigEntry<float> ItemNoiseRange;

		public static ConfigEntry<float> HuntSpeed;

		public static ConfigEntry<float> DriftSpeed;

		public static ConfigEntry<float> FleeSpeed;

		public static ConfigEntry<float> FleeSeconds;

		public static ConfigEntry<float> HearingMultiplier;

		public static ConfigEntry<float> FlashlightRange;

		public static ConfigEntry<float> FlashlightAngle;

		public static ConfigEntry<float> WhisperVolume;

		public static ConfigEntry<float> WhisperRange;

		public static ConfigEntry<float> EyeBrightness;

		public static ConfigEntry<float> EyeLightLumens;

		private void Awake()
		{
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			SpawnMoons = ((BaseUnityPlugin)this).Config.Bind<string>("Spawning", "Moons", "Vow:30,Offense:20,Adamance:40,Rend:15,Titan:10,Embrion:50", "Moons the Wraith can spawn on, comma-separated, each with an optional rarity: Vow:30,Rend:15. A name without a rarity uses the Rarity setting below. All (or All:25) means every other moon. Empty = it never spawns on its own. The host's setting is the one that counts.");
			SpawnRarity = ((BaseUnityPlugin)this).Config.Bind<int>("Spawning", "Rarity", 20, "Default spawn weight for moons listed without their own rarity (vanilla enemies are roughly 1-100).");
			PowerLevel = ((BaseUnityPlugin)this).Config.Bind<float>("Spawning", "PowerLevel", 2f, "How much of the moon's indoor enemy budget one Wraith uses.");
			Damage = ((BaseUnityPlugin)this).Config.Bind<int>("Behaviour", "Damage", 45, "Damage per hit. A hit that would leave you at 0 kills.");
			CloseHearingRange = ((BaseUnityPlugin)this).Config.Bind<float>("Behaviour", "CloseHearingRange", 8f, "Within this distance (m) it also hears normal walking steps. Further away only sprinting carries.");
			TouchSenseRange = ((BaseUnityPlugin)this).Config.Bind<float>("Behaviour", "TouchSenseRange", 2f, "Within this distance (m) it senses you even if you stand completely still.");
			VanishDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Behaviour", "VanishDistance", 20f, "After hitting someone it vanishes to a spot at least this far (m) from them and forgets them.");
			JumpNoiseRange = ((BaseUnityPlugin)this).Config.Bind<float>("Behaviour", "JumpNoiseRange", 18f, "How far (m) the sound of a jump carries.");
			ItemNoiseRange = ((BaseUnityPlugin)this).Config.Bind<float>("Behaviour", "ItemNoiseRange", 80f, "How far (m) it hears noise-making items: horns, toys, boombox, whoopie cushion, radar booster. Half that if the item is in a pocket. A boombox it has already reached is ignored afterwards.");
			HuntSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Behaviour", "HuntSpeed", 6.5f, "Speed (m/s) when gliding toward a noise. Players sprint at about 7.");
			DriftSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Behaviour", "DriftSpeed", 2.2f, "Speed (m/s) when drifting around with nothing heard.");
			FleeSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Behaviour", "FleeSpeed", 10f, "Speed (m/s) when fleeing a flashlight.");
			FleeSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Behaviour", "FleeSeconds", 10f, "How long it flees after being lit up.");
			HearingMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Behaviour", "HearingMultiplier", 1.5f, "Multiplies how far away it hears each sound (1 = same as vanilla enemies).");
			FlashlightRange = ((BaseUnityPlugin)this).Config.Bind<float>("Behaviour", "FlashlightRange", 15f, "How close (m) a flashlight must be to scare it.");
			FlashlightAngle = ((BaseUnityPlugin)this).Config.Bind<float>("Behaviour", "FlashlightAngle", 18f, "How directly (degrees from the centre of your view) the light must point at it.");
			WhisperVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Sound", "WhisperVolume", 0.45f, "Volume of the whisper bursts (0-1).");
			WhisperRange = ((BaseUnityPlugin)this).Config.Bind<float>("Sound", "WhisperRange", 20f, "Distance (m) at which the whispers fade to silence.");
			EyeBrightness = ((BaseUnityPlugin)this).Config.Bind<float>("Look", "EyeGlow", 6f, "How strongly the eyes glow. Too high turns them white; too low and they look dull.");
			EyeLightLumens = ((BaseUnityPlugin)this).Config.Bind<float>("Look", "EyeLightLumens", 120f, "Brightness of the blue light the eyes cast in front of it.");
			new Harmony("SoulMods.Wraith").PatchAll();
			Log.LogInfo((object)"Wraith 1.0.0 loaded");
		}
	}
	public class WraithAI : EnemyAI
	{
		public static readonly List<WraithAI> Instances = new List<WraithAI>();

		public const int StateDrift = 0;

		public const int StateHunt = 1;

		public const int StateFlee = 2;

		private Vector3 _moveTarget;

		private float _stateTimer;

		private Vector3 _lastHeardPos;

		private float _lastHeardTime = -999f;

		private float _syncTimer;

		private float _heatDecayTimer;

		private float _senseTimer;

		private bool _searching;

		private int _huntingBoomboxId;

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

		private readonly Dictionary<Vector3Int, float> _heat = new Dictionary<Vector3Int, float>();

		private const float HeatCell = 4f;

		private Renderer[] _renderers;

		private Light _eyeLight;

		private ScanNodeProperties _scanNode;

		private AudioSource _whisper;

		private AudioSource _sfx;

		private Vector3 _smoothVel;

		private Vector3 _lastPos;

		private float _hitCooldown;

		private float _fleeReportCooldown;

		private int _lastSeenState = -1;

		private float _burstTimer;

		private bool _burstOn;

		private bool _visible = true;

		private Vector3 Chest => ((Component)this).transform.position + Vector3.up * 1.5f;

		private Vector3 Head => ((Component)this).transform.position + Vector3.up * 2.2f;

		public override void Start()
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_0172: 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_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			base.enemyBehaviourStates = (EnemyBehaviourState[])(object)new EnemyBehaviourState[3]
			{
				new EnemyBehaviourState
				{
					name = "Drift"
				},
				new EnemyBehaviourState
				{
					name = "Hunt"
				},
				new EnemyBehaviourState
				{
					name = "Flee"
				}
			};
			base.currentBehaviourState = base.enemyBehaviourStates[0];
			base.updatePositionThreshold = 0.25f;
			((EnemyAI)this).Start();
			if ((Object)(object)base.agent != (Object)null)
			{
				((Behaviour)base.agent).enabled = false;
			}
			base.ventAnimationFinished = true;
			Transform val = ((Component)this).transform.Find("WraithModel");
			_renderers = (Renderer[])(((Object)(object)val != (Object)null) ? ((Array)((Component)val).GetComponentsInChildren<Renderer>(true)) : ((Array)new Renderer[0]));
			_eyeLight = ((Component)this).GetComponentInChildren<Light>(true);
			_whisper = MakeSource("Whisper", WraithAudio.Whisper, loop: true);
			_whisper.volume = 0f;
			_whisper.time = Random.Range(0f, WraithAudio.Whisper.length * 0.9f);
			_whisper.Play();
			_burstTimer = Random.Range(1f, 4f);
			_sfx = MakeSource("Sfx", null, loop: false);
			_scanNode = ((Component)this).GetComponentInChildren<ScanNodeProperties>(true);
			if ((Object)(object)_scanNode != (Object)null)
			{
				_scanNode.creatureScanID = WraithBestiary.FileId;
			}
			_lastPos = ((Component)this).transform.position;
			Instances.Add(this);
			if (((NetworkBehaviour)this).IsOwner)
			{
				_moveTarget = ((Component)this).transform.position;
				PickDriftTarget();
			}
			Plugin.Log.LogInfo((object)$"Wraith spawned at {((Component)this).transform.position} (owner: {((NetworkBehaviour)this).IsOwner})");
		}

		public override void OnDestroy()
		{
			Instances.Remove(this);
			((EnemyAI)this).OnDestroy();
		}

		private AudioSource MakeSource(string name, AudioClip clip, bool loop)
		{
			//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_0018: 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)
			GameObject val = new GameObject(name);
			val.transform.SetParent(((Component)this).transform, false);
			val.transform.localPosition = new Vector3(0f, 2f, 0f);
			AudioSource obj = val.AddComponent<AudioSource>();
			obj.clip = clip;
			obj.loop = loop;
			obj.spatialBlend = 1f;
			obj.rolloffMode = (AudioRolloffMode)1;
			obj.minDistance = 2f;
			obj.maxDistance = Plugin.WhisperRange.Value;
			obj.dopplerLevel = 0f;
			obj.playOnAwake = false;
			return obj;
		}

		public override void Update()
		{
			//IL_0026: 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_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_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			if (!base.isEnemyDead)
			{
				float deltaTime = Time.deltaTime;
				if (((NetworkBehaviour)this).IsOwner)
				{
					HostTick(deltaTime);
				}
				else if (Vector3.Distance(((Component)this).transform.position, base.serverPosition) > 8f)
				{
					((Component)this).transform.position = base.serverPosition;
					_lastPos = base.serverPosition;
					_smoothVel = Vector3.zero;
				}
				else
				{
					((Component)this).transform.position = Vector3.SmoothDamp(((Component)this).transform.position, base.serverPosition, ref _smoothVel, base.syncMovementSpeed);
				}
				FaceTravelDirection(deltaTime);
				LocalTick(deltaTime);
			}
		}

		private void FaceTravelDirection(float dt)
		{
			//IL_0006: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Component)this).transform.position - _lastPos;
			_lastPos = ((Component)this).transform.position;
			val.y = 0f;
			if (!(((Vector3)(ref val)).sqrMagnitude < 0.0001f))
			{
				Quaternion val2 = Quaternion.LookRotation(((Vector3)(ref val)).normalized, Vector3.up);
				((Component)this).transform.rotation = Quaternion.Slerp(((Component)this).transform.rotation, val2, 6f * dt);
			}
		}

		private void HostTick(float dt)
		{
			//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)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			_stateTimer += dt;
			float num;
			switch (base.currentBehaviourStateIndex)
			{
			case 1:
			{
				float num2 = Time.time - _lastHeardTime;
				if (num2 < 0.5f || !_searching)
				{
					num = Plugin.HuntSpeed.Value;
					_moveTarget = _lastHeardPos;
					if (num2 < 0.5f)
					{
						_searching = false;
					}
					if (Vector3.Distance(((Component)this).transform.position, _lastHeardPos) < 1.2f)
					{
						_searching = true;
						if (_huntingBoomboxId != 0)
						{
							_ignoredBoomboxes.Add(_huntingBoomboxId);
							_huntingBoomboxId = 0;
							_lastHeardTime = Time.time;
						}
					}
				}
				else
				{
					num = Plugin.DriftSpeed.Value * 1.4f;
					if (Vector3.Distance(((Component)this).transform.position, _moveTarget) < 1f)
					{
						_moveTarget = RandomNodeAround(_lastHeardPos, 3f, 10f);
					}
				}
				if (num2 > 8f)
				{
					_searching = false;
					SetState(0);
					PickDriftTarget();
				}
				break;
			}
			case 2:
				num = Plugin.FleeSpeed.Value;
				if (_stateTimer > Plugin.FleeSeconds.Value)
				{
					SetState(0);
					PickDriftTarget();
				}
				break;
			default:
				num = Plugin.DriftSpeed.Value;
				if (Vector3.Distance(((Component)this).transform.position, _moveTarget) < 1.5f || _stateTimer > 25f)
				{
					PickDriftTarget();
				}
				break;
			}
			((Component)this).transform.position = Vector3.MoveTowards(((Component)this).transform.position, _moveTarget, num * dt);
			_syncTimer -= dt;
			if (_syncTimer <= 0f)
			{
				((EnemyAI)this).SyncPositionToClients();
				_syncTimer = 0.1f;
			}
			_heatDecayTimer -= dt;
			if (_heatDecayTimer <= 0f)
			{
				_heatDecayTimer = 1f;
				DecayHeat();
			}
			_senseTimer -= dt;
			if (_senseTimer <= 0f)
			{
				_senseTimer = 0.25f;
				SenseNearbyPlayers();
			}
		}

		private void SetState(int state)
		{
			_stateTimer = 0f;
			if (base.currentBehaviourStateIndex != state)
			{
				((EnemyAI)this).SwitchToBehaviourState(state);
			}
		}

		private void PickDriftTarget()
		{
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: 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_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: 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_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			_stateTimer = 0f;
			if (base.allAINodes == null || base.allAINodes.Length == 0)
			{
				base.allAINodes = GameObject.FindGameObjectsWithTag("AINode");
			}
			if (_heat.Count > 0 && Random.value < 0.4f)
			{
				Vector3Int val = default(Vector3Int);
				float num = 0f;
				foreach (KeyValuePair<Vector3Int, float> item in _heat)
				{
					Vector3Int key = item.Key;
					float num2 = (float)((Vector3Int)(ref key)).x + 0.5f;
					key = item.Key;
					float num3 = (float)((Vector3Int)(ref key)).y + 0.5f;
					key = item.Key;
					if (!(Vector3.Distance(new Vector3(num2, num3, (float)((Vector3Int)(ref key)).z + 0.5f) * 4f, ((Component)this).transform.position) < 8f) && item.Value > num)
					{
						num = item.Value;
						val = item.Key;
					}
				}
				if (num > 0.4f)
				{
					Vector3 val2 = new Vector3((float)((Vector3Int)(ref val)).x + 0.5f, (float)((Vector3Int)(ref val)).y + 0.5f, (float)((Vector3Int)(ref val)).z + 0.5f) * 4f;
					float dist;
					Vector3 val3 = NearestNode(val2, out dist);
					_moveTarget = ((val3 != Vector3.zero) ? val3 : val2);
					return;
				}
			}
			_moveTarget = RandomNodeAround(((Component)this).transform.position, 10f, 45f);
		}

		private Vector3 RandomNodeAround(Vector3 center, float minD, float maxD)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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_002b: 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_00aa: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			if (base.allAINodes == null || base.allAINodes.Length == 0)
			{
				Vector3 insideUnitSphere = Random.insideUnitSphere;
				return center + ((Vector3)(ref insideUnitSphere)).normalized * minD;
			}
			Vector3 result = center;
			float num = 0f;
			for (int i = 0; i < 40; i++)
			{
				GameObject val = base.allAINodes[Random.Range(0, base.allAINodes.Length)];
				if (!((Object)(object)val == (Object)null))
				{
					float num2 = Vector3.Distance(val.transform.position, center);
					if (num2 >= minD && num2 <= maxD)
					{
						return val.transform.position;
					}
					if (num2 > num && num2 > 3f)
					{
						num = num2;
						result = val.transform.position;
					}
				}
			}
			return result;
		}

		private Vector3 NearestNode(Vector3 pos, out float dist)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			dist = float.MaxValue;
			Vector3 result = Vector3.zero;
			if (base.allAINodes == null)
			{
				return result;
			}
			GameObject[] allAINodes = base.allAINodes;
			foreach (GameObject val in allAINodes)
			{
				if (!((Object)(object)val == (Object)null))
				{
					Vector3 val2 = val.transform.position - pos;
					float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
					if (sqrMagnitude < dist)
					{
						dist = sqrMagnitude;
						result = val.transform.position;
					}
				}
			}
			dist = Mathf.Sqrt(dist);
			return result;
		}

		private void AddHeat(Vector3 pos, float amount)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			Vector3Int key = default(Vector3Int);
			((Vector3Int)(ref key))..ctor(Mathf.FloorToInt(pos.x / 4f), Mathf.FloorToInt(pos.y / 4f), Mathf.FloorToInt(pos.z / 4f));
			_heat.TryGetValue(key, out var value);
			_heat[key] = Mathf.Min(value + amount, 10f);
		}

		private void DecayHeat()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			foreach (Vector3Int item in new List<Vector3Int>(_heat.Keys))
			{
				float num = _heat[item] * 0.96f;
				if (num < 0.05f)
				{
					_heat.Remove(item);
				}
				else
				{
					_heat[item] = num;
				}
			}
		}

		public void HostHearNoise(Vector3 pos, float range, float loudness, int noiseId)
		{
			//IL_001b: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)this).IsOwner || base.isEnemyDead || base.currentBehaviourStateIndex == 2)
			{
				return;
			}
			float num = Vector3.Distance(pos, ((Component)this).transform.position);
			if ((noiseId == 6 || noiseId == 7) && loudness < 0.5f && num > Plugin.CloseHearingRange.Value)
			{
				return;
			}
			float num2 = Mathf.Max(range, 8f) * Plugin.HearingMultiplier.Value;
			if (num > num2)
			{
				return;
			}
			NearestNode(pos, out var dist);
			if (!(dist > 18f))
			{
				AddHeat(pos, loudness);
				_lastHeardPos = pos;
				_lastHeardTime = Time.time;
				_huntingBoomboxId = 0;
				if (base.currentBehaviourStateIndex != 1)
				{
					SetState(1);
				}
			}
		}

		public void HostHearItemNoise(Vector3 pos, bool pocketed, int boomboxId)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)this).IsOwner || base.isEnemyDead || base.currentBehaviourStateIndex == 2 || (boomboxId != 0 && _ignoredBoomboxes.Contains(boomboxId)))
			{
				return;
			}
			float num = Plugin.ItemNoiseRange.Value * (pocketed ? 0.5f : 1f);
			if (Vector3.Distance(pos, ((Component)this).transform.position) > num)
			{
				return;
			}
			NearestNode(pos, out var dist);
			if (!(dist > 18f))
			{
				AddHeat(pos, 1f);
				_lastHeardPos = pos;
				_lastHeardTime = Time.time;
				_huntingBoomboxId = boomboxId;
				if (base.currentBehaviourStateIndex != 1)
				{
					SetState(1);
				}
			}
		}

		private void SenseNearbyPlayers()
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			if (base.currentBehaviourStateIndex == 2 || (Object)(object)StartOfRound.Instance == (Object)null)
			{
				return;
			}
			float value = Plugin.TouchSenseRange.Value;
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if ((Object)(object)val == (Object)null || !val.isPlayerControlled || val.isPlayerDead || !val.isInsideFactory)
				{
					continue;
				}
				Vector3 val2 = ((Component)val).transform.position - ((Component)this).transform.position;
				if (Mathf.Abs(val2.y) > 2.5f)
				{
					continue;
				}
				val2.y = 0f;
				if (!(((Vector3)(ref val2)).magnitude > value))
				{
					_lastHeardPos = ((Component)val).transform.position;
					_lastHeardTime = Time.time;
					if (base.currentBehaviourStateIndex != 1)
					{
						SetState(1);
					}
					break;
				}
			}
		}

		public void HostOnHit(Vector3 playerPos)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: 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_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)this).IsOwner)
			{
				return;
			}
			Vector3 val = Vector3.zero;
			float value = Plugin.VanishDistance.Value;
			if (base.allAINodes != null && base.allAINodes.Length != 0)
			{
				float num = float.MinValue;
				for (int i = 0; i < 60; i++)
				{
					GameObject val2 = base.allAINodes[Random.Range(0, base.allAINodes.Length)];
					if (!((Object)(object)val2 == (Object)null))
					{
						float num2 = Vector3.Distance(val2.transform.position, playerPos);
						float num3 = ((num2 >= value) ? (100f - Mathf.Abs(num2 - (value + 12f))) : num2);
						if (num3 > num)
						{
							num = num3;
							val = val2.transform.position;
						}
					}
				}
			}
			if (val == Vector3.zero)
			{
				Vector3 val3 = ((Component)this).transform.position - playerPos;
				val = playerPos + ((Vector3)(ref val3)).normalized * (value + 5f);
			}
			((Component)this).transform.position = val;
			base.serverPosition = ((Component)this).transform.position;
			((EnemyAI)this).SyncPositionToClients();
			_syncTimer = 0.1f;
			_lastHeardTime = -999f;
			foreach (Vector3Int item in new List<Vector3Int>(_heat.Keys))
			{
				Vector3Int current = item;
				if (Vector3.Distance(new Vector3((float)((Vector3Int)(ref current)).x + 0.5f, (float)((Vector3Int)(ref current)).y + 0.5f, (float)((Vector3Int)(ref current)).z + 0.5f) * 4f, playerPos) < 15f)
				{
					_heat.Remove(current);
				}
			}
			SetState(0);
			PickDriftTarget();
		}

		public void HostFlee(Vector3 fromPos)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_00b6: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)this).IsOwner || base.currentBehaviourStateIndex == 2)
			{
				return;
			}
			Vector3 position = ((Component)this).transform.position;
			Vector3 val = ((Component)this).transform.position - fromPos;
			Vector3 moveTarget = position + ((Vector3)(ref val)).normalized * 30f;
			float num = 0f;
			if (base.allAINodes != null && base.allAINodes.Length != 0)
			{
				for (int i = 0; i < 40; i++)
				{
					GameObject val2 = base.allAINodes[Random.Range(0, base.allAINodes.Length)];
					if (!((Object)(object)val2 == (Object)null))
					{
						float num2 = Vector3.Distance(val2.transform.position, fromPos);
						if (num2 > num)
						{
							num = num2;
							moveTarget = val2.transform.position;
						}
					}
				}
			}
			_moveTarget = moveTarget;
			SetState(2);
		}

		private void LocalTick(float dt)
		{
			if (_hitCooldown > 0f)
			{
				_hitCooldown -= dt;
			}
			if (_fleeReportCooldown > 0f)
			{
				_fleeReportCooldown -= dt;
			}
			if (_lastSeenState != base.currentBehaviourStateIndex)
			{
				if (base.currentBehaviourStateIndex == 2 && _lastSeenState != -1 && (Object)(object)_sfx != (Object)null)
				{
					_sfx.pitch = 1f;
					_sfx.PlayOneShot(WraithAudio.Shriek, 1f);
				}
				_lastSeenState = base.currentBehaviourStateIndex;
			}
			UpdateWhisper(dt);
			UpdateVisibility();
			PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null);
			if (!((Object)(object)val == (Object)null) && !val.isPlayerDead && val.isPlayerControlled)
			{
				TryHitLocalPlayer(val);
				CheckFlashlight(val);
			}
		}

		private void UpdateWhisper(float dt)
		{
			if (!((Object)(object)_whisper == (Object)null))
			{
				bool flag = base.currentBehaviourStateIndex == 1;
				_burstTimer -= dt;
				if (_burstTimer <= 0f)
				{
					_burstOn = !_burstOn;
					_burstTimer = (_burstOn ? Random.Range(2.5f, 5f) : (flag ? Random.Range(2f, 6f) : Random.Range(5f, 15f)));
				}
				if (flag && !_burstOn && _burstTimer > 6f)
				{
					_burstTimer = Random.Range(0.5f, 2f);
				}
				float num = (_burstOn ? Plugin.WhisperVolume.Value : 0f);
				_whisper.volume = Mathf.MoveTowards(_whisper.volume, num, dt * 0.8f);
				float num2 = (flag ? 1.12f : 0.95f);
				_whisper.pitch = Mathf.MoveTowards(_whisper.pitch, num2, dt * 0.3f);
			}
		}

		private void UpdateVisibility()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			Camera val = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.activeCamera : null);
			bool flag = false;
			if ((Object)(object)val != (Object)null)
			{
				Vector3 position = ((Component)val).transform.position;
				int collidersAndRoomMaskAndDefault = StartOfRound.Instance.collidersAndRoomMaskAndDefault;
				if (Vector3.Distance(position, Chest) < 70f)
				{
					flag = !Physics.Linecast(position, Chest, collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1) || !Physics.Linecast(position, Head, collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1) || !Physics.Linecast(position, ((Component)this).transform.position + Vector3.up * 0.6f, collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1);
				}
			}
			if (flag == _visible)
			{
				return;
			}
			_visible = flag;
			Renderer[] renderers = _renderers;
			foreach (Renderer val2 in renderers)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					val2.enabled = flag;
				}
			}
			if ((Object)(object)_eyeLight != (Object)null)
			{
				((Behaviour)_eyeLight).enabled = flag;
			}
			if ((Object)(object)_scanNode != (Object)null)
			{
				((Component)_scanNode).gameObject.SetActive(flag);
			}
		}

		private void TryHitLocalPlayer(PlayerControllerB player)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
			if (_hitCooldown > 0f || base.currentBehaviourStateIndex != 1 || !player.isInsideFactory)
			{
				return;
			}
			Vector3 val = ((Component)player).transform.position - ((Component)this).transform.position;
			float y = val.y;
			val.y = 0f;
			if (!(((Vector3)(ref val)).magnitude > 1.4f) && !(y < -0.8f) && !(y > 2.4f))
			{
				_hitCooldown = 1.8f;
				int num = Plugin.Damage.Value;
				if (player.health <= num)
				{
					num = 100;
				}
				player.DamagePlayer(num, true, true, (CauseOfDeath)6, 0, false, ((Vector3)(ref val)).normalized * 6f);
				player.sprintMeter = 0f;
				if ((Object)(object)_sfx != (Object)null)
				{
					_sfx.pitch = 0.6f;
					_sfx.PlayOneShot(WraithAudio.Shriek, 0.8f);
				}
				WraithNet.ReportHit(this, ((Component)player).transform.position);
			}
		}

		private void CheckFlashlight(PlayerControllerB player)
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			if (_fleeReportCooldown > 0f || base.currentBehaviourStateIndex == 2 || !_visible || (Object)(object)player.gameplayCamera == (Object)null)
			{
				return;
			}
			bool flag = false;
			GrabbableObject currentlyHeldObjectServer = player.currentlyHeldObjectServer;
			FlashlightItem val = (FlashlightItem)(object)((currentlyHeldObjectServer is FlashlightItem) ? currentlyHeldObjectServer : null);
			if (val != null && ((GrabbableObject)val).isBeingUsed && !((GrabbableObject)val).isPocketed)
			{
				flag = true;
			}
			if ((Object)(object)player.helmetLight != (Object)null && ((Behaviour)player.helmetLight).enabled)
			{
				flag = true;
			}
			if (!flag)
			{
				return;
			}
			Transform transform = ((Component)player.gameplayCamera).transform;
			Vector3 val2 = Chest - transform.position;
			if (!(((Vector3)(ref val2)).magnitude > Plugin.FlashlightRange.Value))
			{
				float num = Vector3.Angle(transform.forward, val2);
				Vector3 val3 = Head - transform.position;
				float num2 = Vector3.Angle(transform.forward, val3);
				if (!(Mathf.Min(num, num2) > Plugin.FlashlightAngle.Value))
				{
					_fleeReportCooldown = 1f;
					WraithNet.ReportFlee(((Component)player).transform.position);
				}
			}
		}
	}
	public static class WraithAudio
	{
		private class Lcg
		{
			private uint _s;

			public Lcg(uint seed)
			{
				_s = seed;
			}

			public float Next()
			{
				_s = _s * 1664525 + 1013904223;
				return (float)_s / 4.2949673E+09f;
			}

			public float Bi()
			{
				return Next() * 2f - 1f;
			}
		}

		private class Bpf
		{
			private float b0;

			private float b2;

			private float a1;

			private float a2;

			private float x1;

			private float x2;

			private float y1;

			private float y2;

			public void Set(float freq, float q)
			{
				float num = MathF.PI * 2f * Mathf.Clamp(freq, 20f, 19845f) / 44100f;
				float num2 = Mathf.Sin(num) / (2f * q);
				float num3 = 1f + num2;
				b0 = num2 / num3;
				b2 = (0f - num2) / num3;
				a1 = -2f * Mathf.Cos(num) / num3;
				a2 = (1f - num2) / num3;
			}

			public float Run(float x)
			{
				float result = b0 * x + b2 * x2 - a1 * y1 - a2 * y2;
				x2 = x1;
				x1 = x;
				y2 = y1;
				y1 = result;
				return result;
			}
		}

		private const int Rate = 44100;

		private static AudioClip _whisper;

		private static AudioClip _shriek;

		private static readonly float[][] Vowels = new float[5][]
		{
			new float[3] { 800f, 1200f, 2500f },
			new float[3] { 400f, 2000f, 2600f },
			new float[3] { 300f, 2300f, 3000f },
			new float[3] { 500f, 900f, 2400f },
			new float[3] { 330f, 800f, 2300f }
		};

		public static AudioClip Whisper => _whisper ?? (_whisper = ToClip("WraithWhisper", MakeWhisper()));

		public static AudioClip Shriek => _shriek ?? (_shriek = ToClip("WraithShriek", MakeShriek()));

		private static AudioClip ToClip(string name, float[] data)
		{
			AudioClip obj = AudioClip.Create(name, data.Length, 1, 44100, false);
			obj.SetData(data, 0);
			return obj;
		}

		private static float[] MakeWhisper()
		{
			int num = 441000;
			float[] array = new float[num];
			Voice(array, 101u, 1f, 1f, 0f);
			Voice(array, 202u, 0.84f, 0.65f, 0.37f);
			Voice(array, 303u, 1.17f, 0.42f, 0.81f);
			Undertone(array, 404u);
			float[] array2 = Reverb(array);
			float[] array3 = new float[num];
			float num2 = 0.0001f;
			for (int i = 0; i < num; i++)
			{
				array3[i] = array[i] * 0.62f + array2[i] * 0.55f;
				num2 = Mathf.Max(num2, Mathf.Abs(array3[i]));
			}
			for (int j = 0; j < num; j++)
			{
				array3[j] = array3[j] / num2 * 0.8f;
			}
			return array3;
		}

		private static void Voice(float[] buf, uint seed, float formantScale, float gain, float startOffsetSec)
		{
			int num = buf.Length;
			Lcg lcg = new Lcg(seed);
			Bpf bpf = new Bpf();
			Bpf bpf2 = new Bpf();
			Bpf bpf3 = new Bpf();
			Bpf bpf4 = new Bpf();
			int num2 = (int)(startOffsetSec * 44100f);
			int i = 0;
			int num3 = (int)(lcg.Next() * 5f);
			int num23;
			for (; i < num - 22050; i += num23)
			{
				int num4 = 2 + (int)(lcg.Next() * 3f);
				for (int j = 0; j < num4; j++)
				{
					int num5 = 1 + (int)(lcg.Next() * 3f);
					for (int k = 0; k < num5; k++)
					{
						float num6 = lcg.Next();
						float num7 = ((num6 < 0.3f) ? 6200f : ((num6 < 0.55f) ? 3000f : ((num6 < 0.8f) ? 1500f : 0f)));
						int num8 = ((num7 > 0f) ? ((int)(44100f * (0.06f + lcg.Next() * 0.08f))) : 0);
						if (num7 > 0f)
						{
							bpf4.Set(num7 * formantScale, 1.6f);
						}
						for (int l = 0; l < num8; l++)
						{
							float num9 = Mathf.Sin((float)l / (float)num8 * MathF.PI) * 0.55f;
							int num10 = (num2 + l) % num;
							buf[num10] += bpf4.Run(lcg.Bi()) * num9 * gain;
						}
						num2 += num8;
						i += num8;
						int num11 = (int)(lcg.Next() * 5f);
						int num12 = (int)(44100f * (0.22f + lcg.Next() * 0.38f));
						float num13 = 0.7f + lcg.Next() * 0.3f;
						for (int m = 0; m < num12; m++)
						{
							float num14 = (float)m / (float)num12;
							if ((m & 0x3F) == 0)
							{
								float num15 = Mathf.SmoothStep(0f, 1f, num14);
								bpf.Set(Mathf.Lerp(Vowels[num3][0], Vowels[num11][0], num15) * formantScale, 9f);
								bpf2.Set(Mathf.Lerp(Vowels[num3][1], Vowels[num11][1], num15) * formantScale, 11f);
								bpf3.Set(Mathf.Lerp(Vowels[num3][2], Vowels[num11][2], num15) * formantScale, 13f);
							}
							float num16 = Mathf.Min(1f, num14 / 0.18f);
							float num17 = Mathf.Min(1f, (1f - num14) / 0.35f);
							float num18 = num16 * num17 * num13;
							float x = lcg.Bi();
							float num19 = bpf.Run(x) * 1f + bpf2.Run(x) * 0.7f + bpf3.Run(x) * 0.35f;
							int num20 = (num2 + m) % num;
							buf[num20] += num19 * num18 * gain * 2.2f;
						}
						num3 = num11;
						num2 += num12;
						i += num12;
						int num21 = (int)(44100f * (0.03f + lcg.Next() * 0.06f));
						num2 += num21;
						i += num21;
					}
					int num22 = (int)(44100f * (0.12f + lcg.Next() * 0.25f));
					num2 += num22;
					i += num22;
				}
				num23 = (int)(44100f * (0.6f + lcg.Next() * 0.9f));
				num2 += num23;
			}
		}

		private static void Undertone(float[] buf, uint seed)
		{
			int num = buf.Length;
			Lcg lcg = new Lcg(seed);
			Bpf bpf = new Bpf();
			bpf.Set(260f, 0.9f);
			for (int i = 0; i < num; i++)
			{
				float num2 = (float)i / 44100f;
				float num3 = 0.55f + 0.45f * Mathf.Sin(MathF.PI * 2f * num2 / 10f * 2f);
				float num4 = bpf.Run(lcg.Bi()) * 0.9f;
				float num5 = Mathf.Sin(MathF.PI * 110f * num2) * 0.05f * (0.7f + 0.3f * Mathf.Sin(1.8849558f * num2));
				buf[i] += (num4 + num5) * num3 * 0.35f;
			}
		}

		private static float[] Reverb(float[] dry, bool loop = true)
		{
			int num = dry.Length;
			int[] array = new int[4] { 1557, 1617, 1491, 1422 };
			int[] array2 = new int[2] { 225, 556 };
			float[][] array3 = new float[4][];
			int[] array4 = new int[4];
			float[] array5 = new float[4];
			for (int i = 0; i < 4; i++)
			{
				array3[i] = new float[(int)((float)array[i] * 1.6f)];
			}
			float[][] array6 = new float[2][];
			int[] array7 = new int[2];
			for (int j = 0; j < 2; j++)
			{
				array6[j] = new float[array2[j]];
			}
			float[] array8 = new float[num];
			for (int k = ((!loop) ? 1 : 0); k < 2; k++)
			{
				for (int l = 0; l < num; l++)
				{
					float num2 = dry[l] * 0.3f;
					float num3 = 0f;
					for (int m = 0; m < 4; m++)
					{
						float[] array9 = array3[m];
						float num4 = array9[array4[m]];
						array5[m] = num4 * 0.7f + array5[m] * 0.3f;
						array9[array4[m]] = num2 + array5[m] * 0.84f;
						array4[m] = (array4[m] + 1) % array9.Length;
						num3 += num4;
					}
					float num5 = num3;
					for (int n = 0; n < 2; n++)
					{
						float[] array10 = array6[n];
						float num6 = array10[array7[n]];
						float num7 = 0f - num5 + num6;
						array10[array7[n]] = num5 + num6 * 0.5f;
						array7[n] = (array7[n] + 1) % array10.Length;
						num5 = num7;
					}
					if (k == 1)
					{
						array8[l] = num5;
					}
				}
			}
			return array8;
		}

		private static float[] MakeShriek()
		{
			int num = 39690;
			int num2 = 74970;
			float[] array = new float[num2];
			Lcg lcg = new Lcg(777u);
			Bpf bpf = new Bpf();
			Bpf bpf2 = new Bpf();
			Bpf bpf3 = new Bpf();
			for (int i = 0; i < num; i++)
			{
				float num3 = (float)i / (float)num;
				if ((i & 0x3F) == 0)
				{
					bpf.Set(Mathf.Lerp(7200f, 5200f, num3), 2.2f);
					bpf2.Set(Mathf.Lerp(4200f, 3000f, num3), 1.1f);
					bpf3.Set(Mathf.Lerp(1600f, 1100f, num3), 1.4f);
				}
				float x = lcg.Bi();
				float num4 = bpf.Run(x) * 1f + bpf2.Run(x) * 0.7f + bpf3.Run(x) * 0.25f;
				float num5 = Mathf.Min(1f, num3 / 0.025f) * (0.85f + 0.15f * Mathf.Sin(num3 * MathF.PI)) * Mathf.Pow(1f - num3, 1.8f);
				float num6 = 0.85f + 0.15f * Mathf.Sin(MathF.PI * 46f * (float)i / 44100f);
				array[i] = num4 * num5 * num6;
			}
			float[] array2 = Reverb(array, loop: false);
			float[] array3 = new float[num2];
			float num7 = 0.0001f;
			for (int j = 0; j < num2; j++)
			{
				array3[j] = array[j] * 0.8f + array2[j] * 0.5f;
				num7 = Mathf.Max(num7, Mathf.Abs(array3[j]));
			}
			for (int k = 0; k < num2; k++)
			{
				array3[k] = array3[k] / num7 * 0.85f;
			}
			return array3;
		}
	}
	[HarmonyPatch]
	public static class WraithBestiary
	{
		public static int FileId = -1;

		private const string SaveKey = "WraithMod_Scanned";

		private const string FileText = "WRAITH\n\nSigurd's danger level: 80%\n\nScientific name: Umbra auditor\n\nNo one has recovered a body, a sample, or a clear photograph. It appears in interiors only, as a tall hooded shape that drifts through walls and floors as if they were not there. It has no eyes in any working sense. It hunts by sound.\n\nIt is drawn to running, jumping, slammed doors, dropped equipment, raised voices and radio chatter, and it remembers where the noise was. Up close it will hear ordinary footsteps. It does not seem to hear a crew member who stands perfectly still - unless it is close enough to touch them.\n\nSigurd's note: you hear it before you see it. Whispering, coming and going. If the whispers get louder, STOP MOVING. A flashlight held straight on it makes it shriek and leave for a while. Hitting it with a shovel does nothing. I tried.\n\n";

		[HarmonyPatch(typeof(Terminal), "Start")]
		[HarmonyPostfix]
		private static void AddEntry(Terminal __instance)
		{
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Expected O, but got Unknown
			try
			{
				if (__instance.enemyFiles.Any((TerminalNode n) => (Object)(object)n != (Object)null && n.creatureName == "Wraith"))
				{
					FileId = __instance.enemyFiles.FindIndex((TerminalNode n) => (Object)(object)n != (Object)null && n.creatureName == "Wraith");
				}
				else
				{
					TerminalNode val = ScriptableObject.CreateInstance<TerminalNode>();
					((Object)val).name = "WraithFile";
					val.creatureName = "Wraith";
					val.displayText = "WRAITH\n\nSigurd's danger level: 80%\n\nScientific name: Umbra auditor\n\nNo one has recovered a body, a sample, or a clear photograph. It appears in interiors only, as a tall hooded shape that drifts through walls and floors as if they were not there. It has no eyes in any working sense. It hunts by sound.\n\nIt is drawn to running, jumping, slammed doors, dropped equipment, raised voices and radio chatter, and it remembers where the noise was. Up close it will hear ordinary footsteps. It does not seem to hear a crew member who stands perfectly still - unless it is close enough to touch them.\n\nSigurd's note: you hear it before you see it. Whispering, coming and going. If the whispers get louder, STOP MOVING. A flashlight held straight on it makes it shriek and leave for a while. Hitting it with a shovel does nothing. I tried.\n\n";
					val.clearPreviousText = true;
					val.maxCharactersToType = 35;
					FileId = __instance.enemyFiles.Count;
					val.creatureFileID = FileId;
					__instance.enemyFiles.Add(val);
					TerminalKeyword val2 = ((IEnumerable<TerminalKeyword>)__instance.terminalNodes.allKeywords).FirstOrDefault((Func<TerminalKeyword, bool>)((TerminalKeyword k) => (Object)(object)k != (Object)null && k.word == "info"));
					TerminalKeyword val3 = ScriptableObject.CreateInstance<TerminalKeyword>();
					((Object)val3).name = "WraithKeyword";
					val3.word = "wraith";
					val3.isVerb = false;
					val3.defaultVerb = val2;
					__instance.terminalNodes.allKeywords = __instance.terminalNodes.allKeywords.Concat((IEnumerable<TerminalKeyword>)(object)new TerminalKeyword[1] { val3 }).ToArray();
					if ((Object)(object)val2 != (Object)null)
					{
						List<CompatibleNoun> list = new List<CompatibleNoun>((IEnumerable<CompatibleNoun>)(((object)val2.compatibleNouns) ?? ((object)new CompatibleNoun[0])))
						{
							new CompatibleNoun(val3, val)
						};
						val2.compatibleNouns = list.ToArray();
					}
					else
					{
						Plugin.Log.LogWarning((object)"Bestiary: couldn't find the terminal's INFO command");
					}
				}
				if (((NetworkBehaviour)__instance).IsServer && !StartOfRound.Instance.isChallengeFile && ES3.Load<bool>("WraithMod_Scanned", GameNetworkManager.Instance.currentSaveFileName, false) && !__instance.scannedEnemyIDs.Contains(FileId))
				{
					__instance.scannedEnemyIDs.Add(FileId);
				}
				Plugin.Log.LogInfo((object)$"Bestiary entry added (file #{FileId})");
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Bestiary entry failed: " + ex));
			}
		}

		[HarmonyPatch(typeof(GameNetworkManager), "SaveGameValues")]
		[HarmonyPostfix]
		private static void SaveUnlock(GameNetworkManager __instance)
		{
			try
			{
				if (FileId < 0 || (Object)(object)NetworkManager.Singleton == (Object)null || !NetworkManager.Singleton.IsServer)
				{
					return;
				}
				Terminal val = Object.FindObjectOfType<Terminal>();
				if (!((Object)(object)val == (Object)null))
				{
					string currentSaveFileName = __instance.currentSaveFileName;
					bool flag = val.scannedEnemyIDs.Contains(FileId);
					ES3.Save<bool>("WraithMod_Scanned", flag, currentSaveFileName);
					int[] array = val.scannedEnemyIDs.Where((int id) => id != FileId).ToArray();
					if (array.Length != 0)
					{
						ES3.Save<int[]>("EnemyScans", array, currentSaveFileName);
					}
					else if (ES3.KeyExists("EnemyScans", currentSaveFileName))
					{
						ES3.DeleteKey("EnemyScans", currentSaveFileName);
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Saving the bestiary unlock failed: " + ex));
			}
		}
	}
	public static class WraithModel
	{
		private delegate Vector3 Shape(int ring, int seg, float angle, float radius, float y);

		private class MeshBuilder
		{
			private readonly List<Vector3> _tris = new List<Vector3>();

			public void Tri(Vector3 a, Vector3 b, Vector3 c)
			{
				//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_001e: Unknown result type (might be due to invalid IL or missing references)
				_tris.Add(a);
				_tris.Add(b);
				_tris.Add(c);
			}

			public void AddGrid(List<Vector3> v, int rows, int seg, Func<int, int, bool> skip)
			{
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_0052: Unknown result type (might be due to invalid IL or missing references)
				//IL_005a: 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)
				int num = seg + 1;
				for (int i = 0; i < rows - 1; i++)
				{
					for (int j = 0; j < seg; j++)
					{
						if (skip == null || !skip(i, j))
						{
							int num2 = i * num + j;
							int index = num2 + 1;
							int num3 = num2 + num;
							int index2 = num3 + 1;
							Tri(v[num2], v[num3], v[index]);
							Tri(v[index], v[num3], v[index2]);
						}
					}
				}
			}

			public void AddTube(List<Vector3> pts, Func<int, float> radius, int sides)
			{
				//IL_0033: 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_003f: 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_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				//IL_004d: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0051: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
				//IL_01cc: 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_0064: Unknown result type (might be due to invalid IL or missing references)
				//IL_0070: Unknown result type (might be due to invalid IL or missing references)
				//IL_0075: 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_007e: 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_0082: 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_0135: Unknown result type (might be due to invalid IL or missing references)
				//IL_0146: Unknown result type (might be due to invalid IL or missing references)
				//IL_0155: Unknown result type (might be due to invalid IL or missing references)
				//IL_016a: Unknown result type (might be due to invalid IL or missing references)
				//IL_017b: Unknown result type (might be due to invalid IL or missing references)
				//IL_018c: Unknown result type (might be due to invalid IL or missing references)
				//IL_01db: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
				//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
				//IL_020f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0224: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_00d7: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
				List<Vector3[]> list = new List<Vector3[]>();
				for (int i = 0; i < pts.Count; i++)
				{
					Vector3 val = ((i < pts.Count - 1) ? (pts[i + 1] - pts[i]) : (pts[i] - pts[i - 1]));
					Vector3 normalized = ((Vector3)(ref val)).normalized;
					val = Vector3.Cross(normalized, (Mathf.Abs(normalized.y) > 0.9f) ? Vector3.forward : Vector3.up);
					Vector3 normalized2 = ((Vector3)(ref val)).normalized;
					Vector3 val2 = Vector3.Cross(normalized2, normalized);
					Vector3[] array = (Vector3[])(object)new Vector3[sides];
					float num = radius(i);
					for (int j = 0; j < sides; j++)
					{
						float num2 = (float)j / (float)sides * MathF.PI * 2f;
						array[j] = pts[i] + (normalized2 * Mathf.Cos(num2) + val2 * Mathf.Sin(num2)) * num;
					}
					list.Add(array);
				}
				for (int k = 0; k < list.Count - 1; k++)
				{
					for (int l = 0; l < sides; l++)
					{
						int num3 = (l + 1) % sides;
						Tri(list[k][l], list[k + 1][l], list[k][num3]);
						Tri(list[k][num3], list[k + 1][l], list[k + 1][num3]);
					}
				}
				Vector3 a = pts[0];
				Vector3 a2 = pts[pts.Count - 1];
				for (int m = 0; m < sides; m++)
				{
					int num4 = (m + 1) % sides;
					Tri(a, list[0][m], list[0][num4]);
					Tri(a2, list[list.Count - 1][num4], list[list.Count - 1][m]);
				}
			}

			public void AddRibbon(List<Vector3> pts, Func<int, float> width)
			{
				//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_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_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)
				//IL_005a: Unknown result type (might be due to invalid IL or missing references)
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0065: Unknown result type (might be due to invalid IL or missing references)
				//IL_006a: Unknown result type (might be due to invalid IL or missing references)
				//IL_006f: 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_0080: Unknown result type (might be due to invalid IL or missing references)
				//IL_0085: Unknown result type (might be due to invalid IL or missing references)
				//IL_008a: Unknown result type (might be due to invalid IL or missing references)
				//IL_008d: Unknown result type (might be due to invalid IL or missing references)
				//IL_008e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0090: Unknown result type (might be due to invalid IL or missing references)
				//IL_0098: Unknown result type (might be due to invalid IL or missing references)
				//IL_009a: Unknown result type (might be due to invalid IL or missing references)
				//IL_009c: Unknown result type (might be due to invalid IL or missing references)
				for (int i = 0; i < pts.Count - 1; i++)
				{
					float num = width(i) * 0.5f;
					float num2 = width(i + 1) * 0.5f;
					Vector3 a = pts[i] + Vector3.left * num;
					Vector3 val = pts[i] + Vector3.right * num;
					Vector3 b = pts[i + 1] + Vector3.left * num2;
					Vector3 c = pts[i + 1] + Vector3.right * num2;
					Tri(a, b, val);
					Tri(val, b, c);
				}
			}

			public Mesh ToMesh()
			{
				//IL_002f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_0059: Unknown result type (might be due to invalid IL or missing references)
				//IL_009a: Unknown result type (might be due to invalid IL or missing references)
				//IL_009f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ac: Expected O, but got Unknown
				int count = _tris.Count;
				List<Vector3> list = new List<Vector3>(count * 2);
				list.AddRange(_tris);
				for (int i = 0; i < count; i += 3)
				{
					list.Add(_tris[i]);
					list.Add(_tris[i + 2]);
					list.Add(_tris[i + 1]);
				}
				int[] array = new int[count];
				int[] array2 = new int[count];
				for (int j = 0; j < count; j++)
				{
					array[j] = j;
					array2[j] = count + j;
				}
				Mesh val = new Mesh
				{
					name = "WraithLowPoly"
				};
				if (list.Count > 65000)
				{
					val.indexFormat = (IndexFormat)1;
				}
				val.SetVertices(list);
				val.subMeshCount = 2;
				val.SetTriangles(array, 0);
				val.SetTriangles(array2, 1);
				val.RecalculateNormals();
				val.RecalculateBounds();
				return val;
			}
		}

		public const float Height = 2.6f;

		private const float Scale = 0.8813559f;

		public static readonly Color EyeColor = new Color(0.22f, 0.62f, 1f, 1f);

		private static Shader _lit;

		public static GameObject Build(string name = "WraithModel")
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: 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_02b9: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			Material val2 = MakeLit(new Color(0.055f, 0.055f, 0.06f, 1f), 0.08f);
			Material val3 = MakeLit(new Color(0.012f, 0.012f, 0.014f, 1f), 0f);
			Material val4 = MakeLit(new Color(0.36f, 0.34f, 0.29f, 1f), 0.15f);
			Material sharedMaterial = MakeLit(Color.black, 0f);
			Material sharedMaterial2 = MakeEye();
			Transform transform = new GameObject("Scaler").transform;
			transform.SetParent(val.transform, false);
			transform.localScale = Vector3.one * 0.8813559f;
			Transform transform2 = new GameObject("Body").transform;
			transform2.SetParent(transform, false);
			transform2.localPosition = new Vector3(0f, 0.32f, 0f);
			MakeMeshChild(transform2, "Cloak", BuildCloak(), val2, val3);
			MakeMeshChild(transform2, "Ribcage", BuildRibcage(), val4, val4);
			Transform transform3 = new GameObject("Tatters").transform;
			transform3.SetParent(transform2, false);
			BuildTatters(transform3, val2, val3);
			Transform transform4 = new GameObject("HoodPivot").transform;
			transform4.SetParent(transform2, false);
			transform4.localPosition = new Vector3(0f, 2.26f, 0.16f);
			transform4.localRotation = Quaternion.Euler(18f, 0f, 0f);
			MakeMeshChild(transform4, "Hood", BuildHood(), val2, val3);
			GameObject obj = GameObject.CreatePrimitive((PrimitiveType)0);
			Strip(obj);
			((Object)obj).name = "Void";
			obj.transform.SetParent(transform4, false);
			obj.transform.localPosition = new Vector3(0f, -0.02f, 0.02f);
			obj.transform.localScale = new Vector3(0.36f, 0.44f, 0.32f);
			obj.GetComponent<Renderer>().sharedMaterial = sharedMaterial;
			Transform transform5 = new GameObject("Eyes").transform;
			transform5.SetParent(transform4, false);
			transform5.localPosition = new Vector3(0f, 0.065f, 0.188f);
			for (int i = -1; i <= 1; i += 2)
			{
				GameObject val5 = new GameObject((i < 0) ? "EyeL" : "EyeR");
				val5.transform.SetParent(transform5, false);
				val5.transform.localPosition = new Vector3(0.1f * (float)i, 0f, 0f);
				val5.transform.localRotation = Quaternion.Euler(0f, 0f, -14f * (float)i);
				val5.AddComponent<MeshFilter>().sharedMesh = EyeMesh();
				MeshRenderer obj2 = val5.AddComponent<MeshRenderer>();
				((Renderer)obj2).sharedMaterial = sharedMaterial2;
				((Renderer)obj2).shadowCastingMode = (ShadowCastingMode)0;
			}
			AddEyeLight(transform5);
			for (int j = -1; j <= 1; j += 2)
			{
				BuildArm(transform2, j, val2, val3, val4);
			}
			val.AddComponent<WraithIdle>();
			return val;
		}

		private static Mesh BuildCloak()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: 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)
			Vector2[] array = (Vector2[])(object)new Vector2[8]
			{
				new Vector2(0.5f, 0f),
				new Vector2(0.52f, 0.3f),
				new Vector2(0.47f, 0.75f),
				new Vector2(0.4f, 1.2f),
				new Vector2(0.37f, 1.55f),
				new Vector2(0.4f, 1.85f),
				new Vector2(0.3f, 2.05f),
				new Vector2(0.15f, 2.22f)
			};
			float topY = array[^1].y;
			MeshBuilder meshBuilder = new MeshBuilder();
			List<Vector3> v = RingGrid(array, 12, delegate(int ring, int s, float a, float radius, float y)
			{
				//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
				float num = y / topY;
				float num2 = Mathf.Lerp(1f, 1.3f, Mathf.SmoothStep(0.55f, 0.85f, num));
				float num3 = Mathf.Lerp(1f, 0.8f, Mathf.SmoothStep(0.55f, 0.85f, num));
				float num4 = Mathf.Pow(num, 2.2f) * 0.22f;
				float num5 = radius * (1f + ((s % 2 == 0) ? 0.05f : (-0.03f)) * (1f - num));
				float num6 = y;
				if (ring == 0)
				{
					num6 += Hash(s) * 0.22f;
				}
				return new Vector3(Mathf.Cos(a) * num5 * num2, num6, Mathf.Sin(a) * num5 * num3 + num4);
			});
			meshBuilder.AddGrid(v, array.Length, 12, delegate(int ring, int s)
			{
				float num = ((float)s + 0.5f) / 12f * MathF.PI * 2f;
				bool num2 = Mathf.Abs(Mathf.DeltaAngle(num * 57.29578f, 90f)) < 40f;
				bool flag = ring == 3 || ring == 4;
				bool flag2 = ring == 2 && Mathf.Abs(Mathf.DeltaAngle(num * 57.29578f, 90f)) < 15f;
				return (num2 && flag) || flag2;
			});
			return meshBuilder.ToMesh();
		}

		private static Mesh BuildRibcage()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			MeshBuilder meshBuilder = new MeshBuilder();
			List<Vector3> list = new List<Vector3>();
			for (int i = 0; i <= 5; i++)
			{
				float num = 1.15f + (float)i * 0.19f;
				list.Add(new Vector3(0f, num, -0.09f + Mathf.Sin((float)i * 0.9f) * 0.015f));
			}
			meshBuilder.AddTube(list, (int num10) => 0.035f, 5);
			for (int num2 = 0; num2 < 5; num2++)
			{
				float num3 = 1.82f - (float)num2 * 0.1f;
				float num4 = 0.21f + Mathf.Sin((float)(num2 + 1) / 6f * MathF.PI) * 0.04f;
				float num5 = 0.19f;
				for (int num6 = -1; num6 <= 1; num6 += 2)
				{
					List<Vector3> list2 = new List<Vector3>();
					for (int num7 = 0; num7 <= 5; num7++)
					{
						float num8 = (float)num7 / 5f;
						float num9 = Mathf.Lerp(-MathF.PI / 2f, 1.1309735f, num8);
						list2.Add(new Vector3((float)num6 * num4 * Mathf.Cos(num9), num3 - num8 * 0.07f, 0.08f + num5 * Mathf.Sin(num9)));
					}
					meshBuilder.AddTube(list2, (int num10) => 0.018f, 4);
				}
			}
			meshBuilder.AddTube(new List<Vector3>
			{
				new Vector3(0f, 1.86f, 0.26999998f),
				new Vector3(0f, 1.52f, 0.25f)
			}, (int num10) => 0.022f, 4);
			return meshBuilder.ToMesh();
		}

		private static void BuildTatters(Transform parent, Material outside, Material inside)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: 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)
			for (int i = 0; i < 14; i++)
			{
				float num = ((float)i + Hash(i + 50) * 0.6f) / 14f * MathF.PI * 2f;
				float num2 = 0.47f;
				Transform transform = new GameObject("Tatter" + i).transform;
				transform.SetParent(parent, false);
				transform.localPosition = new Vector3(Mathf.Cos(num) * num2, 0.18f, Mathf.Sin(num) * num2 * 0.95f);
				transform.localRotation = Quaternion.Euler(0f, (0f - num) * 57.29578f + 90f, 0f);
				float num3 = 0.35f + Hash(i + 7) * 0.55f;
				float width = 0.07f + Hash(i + 21) * 0.07f;
				MeshBuilder meshBuilder = new MeshBuilder();
				List<Vector3> list = new List<Vector3>();
				for (int j = 0; j <= 3; j++)
				{
					float num4 = (float)j / 3f;
					list.Add(new Vector3(0f, (0f - num3) * num4, num4 * num4 * 0.08f));
				}
				meshBuilder.AddRibbon(list, (int k) => width * (1f - (float)k / 3f * 0.75f));
				MakeMeshChild(transform, "Strip", meshBuilder.ToMesh(), outside, inside);
			}
		}

		private static Mesh BuildHood()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_0135: Unknown result type (might be due to invalid IL or missing references)
			Vector2[] array = (Vector2[])(object)new Vector2[5]
			{
				new Vector2(0f, -0.3f),
				new Vector2(0.18f, -0.24f),
				new Vector2(0.27f, -0.08f),
				new Vector2(0.29f, 0.1f),
				new Vector2(0.25f, 0.28f)
			};
			List<Vector3> list = new List<Vector3>();
			for (int i = 0; i < array.Length; i++)
			{
				for (int j = 0; j <= 10; j++)
				{
					float num = (float)(j % 10) / 10f * MathF.PI * 2f + MathF.PI / 2f;
					float num2 = Mathf.Cos(num) * array[i].x;
					float num3 = Mathf.Sin(num) * array[i].x * 1.25f;
					float num4 = array[i].y;
					if (num3 > 0f)
					{
						num4 += 0.17f * (num3 / 0.36f) * Mathf.Clamp01((num4 + 0.1f) / 0.38f);
					}
					if (num3 < -0.05f && i == array.Length - 1)
					{
						num4 -= 0.09f;
					}
					list.Add(new Vector3(num2, num3, num4));
				}
			}
			MeshBuilder meshBuilder = new MeshBuilder();
			meshBuilder.AddGrid(list, array.Length, 10, null);
			return meshBuilder.ToMesh();
		}

		private static void BuildArm(Transform body, int side, Material cloak, Material cloakInner, Material bone)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: 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_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0370: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_0377: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = new GameObject((side < 0) ? "ShoulderL" : "ShoulderR").transform;
			transform.SetParent(body, false);
			transform.localPosition = new Vector3(0.45f * (float)side, 1.86f, 0.15f);
			transform.localRotation = Quaternion.Euler(-10f, 0f, 10f * (float)side);
			Vector2[] sleeveProfile = (Vector2[])(object)new Vector2[3]
			{
				new Vector2(0.12f, 0f),
				new Vector2(0.12f, -0.25f),
				new Vector2(0.15f, -0.42f)
			};
			MeshBuilder meshBuilder = new MeshBuilder();
			meshBuilder.AddGrid(RingGrid(sleeveProfile, 8, delegate(int ring, int s, float a, float radius, float y)
			{
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				float num5 = ((ring == sleeveProfile.Length - 1) ? (y - Hash(s + 300 + side * 40) * 0.16f) : y);
				return new Vector3(Mathf.Cos(a) * radius, num5, Mathf.Sin(a) * radius);
			}), sleeveProfile.Length, 8, null);
			MakeMeshChild(transform, "Sleeve", meshBuilder.ToMesh(), cloak, cloakInner);
			MeshBuilder meshBuilder2 = new MeshBuilder();
			meshBuilder2.AddTube(new List<Vector3>
			{
				new Vector3(0f, -0.1f, 0f),
				new Vector3(0f, -0.6f, 0.02f)
			}, (int i) => 0.028f, 5);
			meshBuilder2.AddTube(new List<Vector3>
			{
				new Vector3(0f, -0.58f, 0f),
				new Vector3(0f, -0.66f, 0.04f)
			}, (int i) => 0.042f, 5);
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(0f, -0.63f, 0.03f);
			Vector3 val2 = val + Quaternion.Euler(-30f, 0f, 0f) * new Vector3(0f, -0.55f, 0f);
			meshBuilder2.AddTube(new List<Vector3>
			{
				val + new Vector3(-0.018f, 0f, 0f),
				val2 + new Vector3(-0.012f, 0f, 0f)
			}, (int i) => 0.016f, 4);
			meshBuilder2.AddTube(new List<Vector3>
			{
				val + new Vector3(0.018f, 0f, 0f),
				val2 + new Vector3(0.012f, 0f, 0f)
			}, (int i) => 0.014f, 4);
			Vector3 val3 = default(Vector3);
			for (int num = -1; num <= 1; num++)
			{
				float num2 = 0.32f + ((num == 0) ? 0.06f : 0f);
				List<Vector3> list = new List<Vector3>();
				for (int num3 = 0; num3 <= 3; num3++)
				{
					float num4 = (float)num3 / 3f;
					((Vector3)(ref val3))..ctor((float)num * 0.03f + (float)num * 0.03f * num4, (0f - num2) * num4, num4 * num4 * 0.13f);
					list.Add(val2 + Quaternion.Euler(-30f, 0f, 0f) * val3);
				}
				meshBuilder2.AddTube(list, (int k) => Mathf.Lerp(0.016f, 0.002f, (float)k / 3f), 4);
			}
			MakeMeshChild(transform, "Bones", meshBuilder2.ToMesh(), bone, bone);
		}

		private static Mesh EyeMesh()
		{
			//IL_0074: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			MeshBuilder meshBuilder = new MeshBuilder();
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(-0.045f, 0f, 0f);
			Vector3 val2 = default(Vector3);
			((Vector3)(ref val2))..ctor(0.045f, 0f, 0f);
			Vector3 val3 = default(Vector3);
			((Vector3)(ref val3))..ctor(0f, 0.017f, 0.005f);
			Vector3 val4 = default(Vector3);
			((Vector3)(ref val4))..ctor(0f, -0.017f, 0.005f);
			Vector3 c = default(Vector3);
			((Vector3)(ref c))..ctor(0f, 0f, 0.014f);
			meshBuilder.Tri(val, val3, c);
			meshBuilder.Tri(val3, val2, c);
			meshBuilder.Tri(val2, val4, c);
			meshBuilder.Tri(val4, val, c);
			return meshBuilder.ToMesh();
		}

		private static List<Vector3> RingGrid(Vector2[] profile, int seg, Shape shape)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			for (int i = 0; i < profile.Length; i++)
			{
				for (int j = 0; j <= seg; j++)
				{
					int num = j % seg;
					float angle = (float)num / (float)seg * MathF.PI * 2f;
					list.Add(shape(i, num, angle, profile[i].x, profile[i].y));
				}
			}
			return list;
		}

		private static float Hash(int i)
		{
			float num = Mathf.Sin((float)i * 127.1f + 311.7f) * 43758.547f;
			return num - Mathf.Floor(num);
		}

		private static GameObject MakeMeshChild(Transform parent, string name, Mesh mesh, Material outside, Material inside)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.AddComponent<MeshFilter>().sharedMesh = mesh;
			MeshRenderer val2 = val.AddComponent<MeshRenderer>();
			((Renderer)val2).sharedMaterials = (Material[])(object)new Material[2] { outside, inside };
			((Renderer)val2).shadowCastingMode = (ShadowCastingMode)1;
			return val;
		}

		private static void Strip(GameObject go)
		{
			Collider component = go.GetComponent<Collider>();
			if ((Object)(object)component != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component);
			}
		}

		private static Material MakeLit(Color color, float smoothness)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			//IL_0085: 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)
			if ((Object)(object)_lit == (Object)null)
			{
				_lit = Shader.Find("HDRP/Lit") ?? Shader.Find("Standard");
				Plugin.Log.LogInfo((object)("Wraith lit shader: " + (((Object)(object)_lit != (Object)null) ? ((Object)_lit).name : "none")));
			}
			Material val = new Material(_lit)
			{
				name = "Wraith_Lit"
			};
			if (val.HasProperty("_BaseColor"))
			{
				val.SetColor("_BaseColor", color);
			}
			if (val.HasProperty("_Color"))
			{
				val.SetColor("_Color", color);
			}
			if (val.HasProperty("_Smoothness"))
			{
				val.SetFloat("_Smoothness", smoothness);
			}
			if (val.HasProperty("_Metallic"))
			{
				val.SetFloat("_Metallic", 0f);
			}
			return val;
		}

		private static Material MakeEye()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			Color val = EyeColor * (Plugin.EyeBrightness.Value * 4f);
			Material val2 = MakeLit(EyeColor, 0.3f);
			((Object)val2).name = "Wraith_Eye";
			val2.EnableKeyword("_EMISSION");
			if (val2.HasProperty("_EmissiveColor"))
			{
				val2.SetColor("_EmissiveColor", val);
			}
			if (val2.HasProperty("_EmissionColor"))
			{
				val2.SetColor("_EmissionColor", val);
			}
			if (val2.HasProperty("_UseEmissiveIntensity"))
			{
				val2.SetFloat("_UseEmissiveIntensity", 0f);
			}
			if (val2.HasProperty("_EmissiveExposureWeight"))
			{
				val2.SetFloat("_EmissiveExposureWeight", 1f);
			}
			return val2;
		}

		private static void AddEyeLight(Transform eyes)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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)
			GameObject val = new GameObject("EyeLight");
			val.transform.SetParent(eyes, false);
			val.transform.localPosition = new Vector3(0f, 0f, 0.15f);
			val.transform.localRotation = Quaternion.identity;
			Light val2 = val.AddComponent<Light>();
			val2.type = (LightType)0;
			val2.spotAngle = 110f;
			val2.color = new Color(0.35f, 0.7f, 1f);
			val2.range = 3.5f;
			val2.shadows = (LightShadows)0;
			HDAdditionalLightData val3 = val.AddComponent<HDAdditionalLightData>();
			try
			{
				val3.SetSpotAngle(110f, 0f);
				val3.SetIntensity(Plugin.EyeLightLumens.Value, (LightUnit)0);
				val3.SetRange(3.5f);
				val3.affectsVolumetric = true;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Eye light setup: " + ex.Message));
				val2.intensity = Plugin.EyeLightLumens.Value;
			}
		}
	}
	public class WraithIdle : MonoBehaviour
	{
		private Transform _body;

		private Transform _shoulderL;

		private Transform _shoulderR;

		private Quaternion _restL;

		private Quaternion _restR;

		private readonly List<Transform> _tatters = new List<Transform>();

		private readonly List<Quaternion> _tatterRest = new List<Quaternion>();

		private Light _eyeLight;

		private float _baseIntensity;

		private float _seed;

		private void Start()
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			_body = ((Component)this).transform.Find("Scaler/Body");
			_shoulderL = _body.Find("ShoulderL");
			_shoulderR = _body.Find("ShoulderR");
			_restL = _shoulderL.localRotation;
			_restR = _shoulderR.localRotation;
			foreach (Transform item in _body.Find("Tatters"))
			{
				Transform val = item;
				_tatters.Add(val);
				_tatterRest.Add(val.localRotation);
			}
			_eyeLight = ((Component)this).GetComponentInChildren<Light>();
			if ((Object)(object)_eyeLight != (Object)null)
			{
				_baseIntensity = _eyeLight.intensity;
			}
			_seed = Random.value * 100f;
		}

		private void Update()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			float num = Time.time + _seed;
			_body.localPosition = new Vector3(0f, 0.32f + Mathf.Sin(num * 1.1f) * 0.06f, 0f);
			_body.localRotation = Quaternion.Euler(Mathf.Sin(num * 0.7f) * 1.5f, 0f, Mathf.Sin(num * 0.9f) * 1.2f);
			_shoulderL.localRotation = _restL * Quaternion.Euler(Mathf.Sin(num * 0.8f) * 5f, 0f, 0f);
			_shoulderR.localRotation = _restR * Quaternion.Euler(Mathf.Sin(num * 0.8f + 1.7f) * 5f, 0f, 0f);
			for (int i = 0; i < _tatters.Count; i++)
			{
				float num2 = num * 1.3f + (float)i * 0.9f;
				_tatters[i].localRotation = _tatterRest[i] * Quaternion.Euler(-8f + Mathf.Sin(num2) * 9f, 0f, Mathf.Sin(num2 * 0.7f) * 6f);
			}
			if ((Object)(object)_eyeLight != (Object)null)
			{
				_eyeLight.intensity = _baseIntensity * (0.85f + 0.15f * Mathf.PerlinNoise(num * 3f, 0.5f));
			}
		}
	}
	public static class WraithRegistry
	{
		public static EnemyType WraithType;

		public static GameObject Prefab;

		private const string PrefabKey = "SoulMods.Wraith.WraithPrefab";

		public static void CreatePrefab(NetworkManager nm)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)Prefab != (Object)null))
			{
				GameObject val = new GameObject("WraithMod_Templates");
				val.SetActive(false);
				((Object)val).hideFlags = (HideFlags)61;
				Object.DontDestroyOnLoad((Object)(object)val);
				GameObject val2 = new GameObject("Wraith");
				val2.transform.SetParent(val.transform, false);
				SetGlobalObjectIdHash(val2.AddComponent<NetworkObject>(), StableHash("SoulMods.Wraith.WraithPrefab"));
				((Behaviour)val2.AddComponent<NavMeshAgent>()).enabled = false;
				GameObject val3 = WraithModel.Build();
				val3.transform.SetParent(val2.transform, false);
				GameObject val4 = new GameObject("ScanNode");
				val4.transform.SetParent(val2.transform, false);
				val4.transform.localPosition = new Vector3(0f, 1.5f, 0f);
				val4.layer = 22;
				BoxCollider obj = val4.AddComponent<BoxCollider>();
				((Collider)obj).isTrigger = true;
				obj.size = new Vector3(0.8f, 2.2f, 0.8f);
				ScanNodeProperties obj2 = val4.AddComponent<ScanNodeProperties>();
				obj2.headerText = "Wraith";
				obj2.subText = "Danger: unkillable";
				obj2.nodeType = 1;
				obj2.minRange = 1;
				obj2.maxRange = 22;
				obj2.requiresLineOfSight = true;
				obj2.creatureScanID = -1;
				WraithType = ScriptableObject.CreateInstance<EnemyType>();
				((Object)WraithType).name = "WraithEnemyType";
				WraithType.enemyName = "Wraith";
				WraithType.enemyPrefab = val2;
				WraithType.PowerLevel = Plugin.PowerLevel.Value;
				WraithType.MaxCount = 1;
				WraithType.probabilityCurve = AnimationCurve.Constant(0f, 1f, 1f);
				WraithType.numberSpawnedFalloff = AnimationCurve.Constant(0f, 1f, 1f);
				WraithType.useNumberSpawnedFalloff = false;
				WraithType.isOutsideEnemy = false;
				WraithType.isDaytimeEnemy = false;
				WraithType.canDie = false;
				WraithType.canBeStunned = false;
				WraithType.canBeDestroyed = false;
				WraithType.canSeeThroughFog = true;
				WraithType.doorSpeedMultiplier = 1f;
				WraithType.stunTimeMultiplier = 1f;
				WraithType.loudnessMultiplier = 1f;
				WraithType.miscAnimations = (MiscAnimation[])(object)new MiscAnimation[0];
				WraithType.audioClips = (AudioClip[])(object)new AudioClip[0];
				WraithAI wraithAI = val2.AddComponent<WraithAI>();
				((EnemyAI)wraithAI).enemyType = WraithType;
				((EnemyAI)wraithAI).eye = val3.transform.Find("Scaler/Body/HoodPivot/Eyes");
				((EnemyAI)wraithAI).AIIntervalTime = 0.2f;
				((EnemyAI)wraithAI).exitVentAnimationTime = 0f;
				((EnemyAI)wraithAI).syncMovementSpeed = 0.12f;
				((EnemyAI)wraithAI).enemyHP = 999;
				nm.AddNetworkPrefab(val2);
				Prefab = val2;
				Plugin.Log.LogInfo((object)"Wraith prefab registered with Netcode");
			}
		}

		private static void SetGlobalObjectIdHash(NetworkObject obj, uint hash)
		{
			FieldInfo? field = typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field == null)
			{
				throw new MissingFieldException("NetworkObject.GlobalObjectIdHash");
			}
			field.SetValue(obj, hash);
		}

		private static uint StableHash(string s)
		{
			uint num = 2166136261u;
			foreach (char c in s)
			{
				num ^= c;
				num *= 16777619;
			}
			return num;
		}

		public static void ApplyToLevel(SelectableLevel level)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			if (!((Object)(object)WraithType == (Object)null) && !((Object)(object)level == (Object)null))
			{
				level.Enemies.RemoveAll((SpawnableEnemyWithRarity e) => e != null && (Object)(object)e.enemyType == (Object)(object)WraithType);
				int num = RarityFor(level);
				if (num > 0)
				{
					level.Enemies.Add(new SpawnableEnemyWithRarity(WraithType, num));
					Plugin.Log.LogInfo((object)$"Wraith can spawn on {level.PlanetName} (rarity {num})");
				}
			}
		}

		private static int RarityFor(SelectableLevel level)
		{
			string text = Normalize(level.PlanetName);
			string text2 = Normalize(level.sceneName);
			int result = 0;
			string[] array = (Plugin.SpawnMoons.Value ?? "").Split(',');
			foreach (string text3 in array)
			{
				string[] array2 = text3.Split(':');
				string text4 = Normalize(array2[0]);
				if (text4.Length != 0)
				{