Decompiled source of The Boiled One v1.0.1

BoiledOne.dll

Decompiled 4 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using Dissonance;
using GameNetcodeStuff;
using HarmonyLib;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace BoiledOneMod;

[BepInPlugin("aj.boiledone.visual", "Boiled One Visual", "0.3.3")]
public sealed class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(EnemyAI), "EnableEnemyMesh")]
	private static class VisibilityPatch
	{
		private static void Postfix(EnemyAI __instance, bool __0)
		{
			if (__instance is DressGirlAI && !__instance.overrideSettingEnemyMeshes)
			{
				((Component)__instance).GetComponent<BoiledVisual>()?.SetVisible(__0);
				if (!__0)
				{
					((Component)__instance).GetComponent<BoiledHauntAudio>()?.StopHaunt();
				}
			}
		}
	}

	[HarmonyPatch(typeof(DressGirlAI), "BeginChasing")]
	private static class ChasePatch
	{
		private static void Postfix(DressGirlAI __instance)
		{
			((Component)__instance).GetComponent<BoiledHauntAudio>()?.SyncChase();
			if (((EnemyAI)__instance).currentBehaviourStateIndex == 1)
			{
				((Component)__instance).GetComponent<BoiledVisual>()?.SetVisible(visible: true);
			}
		}
	}

	[HarmonyPatch(typeof(DressGirlAI), "Start")]
	private static class SpawnPatch
	{
		private static void Prefix(DressGirlAI __instance)
		{
			SilenceGirl(__instance);
		}

		private static void Postfix(DressGirlAI __instance)
		{
			if (!Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<BoiledHauntAudio>()))
			{
				((Component)__instance).gameObject.AddComponent<BoiledHauntAudio>().Initialize(__instance);
			}
			if (!Object.op_Implicit((Object)(object)Prefab) || Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<BoiledVisual>()))
			{
				return;
			}
			try
			{
				((Component)__instance).gameObject.AddComponent<BoiledVisual>().Initialize(__instance);
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)Instance).Logger.LogError((object)ex);
				BoiledVisual component = ((Component)__instance).GetComponent<BoiledVisual>();
				if (Object.op_Implicit((Object)(object)component))
				{
					Object.Destroy((Object)(object)component);
				}
			}
		}
	}

	[HarmonyPatch(typeof(EnemyAI), "PlayAudioOfCurrentState")]
	private static class StateAudioPatch
	{
		private static bool Prefix(EnemyAI __instance)
		{
			return !(__instance is DressGirlAI);
		}
	}

	[HarmonyPatch]
	private static class AnimationAudioPatch
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			MethodInfo[] methods = typeof(PlayAudioAnimationEvent).GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (MethodInfo methodInfo in methods)
			{
				if (methodInfo.Name.StartsWith("PlayAudio", StringComparison.Ordinal))
				{
					yield return methodInfo;
				}
			}
		}

		private static bool Prefix(PlayAudioAnimationEvent __instance)
		{
			return !Object.op_Implicit((Object)(object)((Component)__instance).GetComponentInParent<DressGirlAI>());
		}
	}

	[HarmonyPatch(typeof(DressGirlAI), "SetHauntStarePosition")]
	private static class HauntSoundPatch
	{
		private static void Prefix(DressGirlAI __instance)
		{
			SilenceGirl(__instance);
		}

		private static void Postfix(DressGirlAI __instance)
		{
			((Component)__instance).GetComponent<BoiledHauntAudio>()?.PlayHaunt();
		}
	}

	[HarmonyPatch(typeof(DressGirlAI), "StopChasing")]
	private static class StopChaseSoundPatch
	{
		private static void Postfix(DressGirlAI __instance)
		{
			if (!ComaManager.Holds(__instance))
			{
				((Component)__instance).GetComponent<BoiledHauntAudio>()?.StopAudio();
			}
		}
	}

	internal static Plugin Instance;

	internal static GameObject Prefab;

	internal ConfigEntry<float> Scale;

	internal ConfigEntry<float> YOffset;

	internal ConfigEntry<float> Yaw;

	internal ConfigEntry<float> Height;

	private AssetBundle bundle;

	private Harmony harmony;

	internal static AudioClip Silence;

	internal static readonly List<AudioClip> Trumpets = new List<AudioClip>();

	internal static bool AudioLoaded;

	internal static AudioClip ChaseSpeech;

	internal ConfigEntry<float> TrumpetVolume;

	internal ConfigEntry<float> ChaseVolume;

	private readonly Random soundRandom = new Random();

	private int previousTrumpet = -1;

	private void Awake()
	{
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Expected O, but got Unknown
		Instance = this;
		Scale = ((BaseUnityPlugin)this).Config.Bind<float>("Visual", "ScaleMultiplier", 1f, "Multiplier on the authored prefab size.");
		Height = ((BaseUnityPlugin)this).Config.Bind<float>("Visual", "TargetHeightMeters", 1.93f, "Proportional height using a 1.8m reference player; converted to the game's 2.5-unit standing controller height.");
		YOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Visual", "VerticalOffset", 0f, "Vertical adjustment in meters.");
		Yaw = ((BaseUnityPlugin)this).Config.Bind<float>("Visual", "YawOffset", 0f, "Facing adjustment in degrees.");
		InitializeHauntingAudio();
		try
		{
			bundle = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "boiledoneassets"));
			if (!Object.op_Implicit((Object)(object)bundle))
			{
				throw new Exception("Cannot load boiledoneassets next to the plugin DLL");
			}
			Prefab = bundle.LoadAsset<GameObject>("Assets/BoiledOne/Prefabs/BoiledOneVisual.prefab");
			if (!Object.op_Implicit((Object)(object)Prefab))
			{
				throw new Exception("BoiledOneVisual prefab missing from asset bundle");
			}
			harmony = new Harmony("aj.boiledone.visual");
			harmony.PatchAll(typeof(Plugin).Assembly);
			((Component)this).gameObject.AddComponent<ComaManager>();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Boiled One visual, audio and pseudocoma ready (0.3.3).");
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)ex);
		}
	}

	internal void Report(string message)
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)message);
	}

	private void InitializeHauntingAudio()
	{
		TrumpetVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "HauntingVolume", 1f, "Trumpet volume, 0 to 1.");
		ChaseVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "ChaseVolume", 1f, "Chase speech volume, 0 to 1.");
		Silence = AudioClip.Create("BoiledOne_Silence", 441, 1, 44100, false);
		((MonoBehaviour)this).StartCoroutine(LoadTrumpets());
		((MonoBehaviour)this).StartCoroutine(LoadChaseSpeech());
	}

	private IEnumerator LoadChaseSpeech()
	{
		string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "HauntingSounds", "chase-speech.mp3");
		if (!File.Exists(text))
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Missing chase speech: " + text));
			yield break;
		}
		UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip(new Uri(text).AbsoluteUri, (AudioType)13);
		try
		{
			yield return request.SendWebRequest();
			if ((int)request.result != 1)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Cannot load chase speech: " + request.error));
				yield break;
			}
			AudioClip content = DownloadHandlerAudioClip.GetContent(request);
			if (!Object.op_Implicit((Object)(object)content) || content.samples == 0)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Chase speech is empty.");
				yield break;
			}
			ChaseSpeech = content;
			((Object)content).name = "BoiledOne_ChaseSpeech";
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Boiled One chase speech loaded.");
		}
		finally
		{
			((IDisposable)request)?.Dispose();
		}
	}

	private IEnumerator LoadTrumpets()
	{
		string folder = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "HauntingSounds");
		for (int i = 1; i <= 7; i++)
		{
			string path = Path.Combine(folder, "trumpet-" + i.ToString("00") + ".mp3");
			if (!File.Exists(path))
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Missing haunting clip: " + path));
				continue;
			}
			UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip(new Uri(path).AbsoluteUri, (AudioType)13);
			try
			{
				yield return request.SendWebRequest();
				if ((int)request.result != 1)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)("Cannot load " + Path.GetFileName(path) + ": " + request.error));
					continue;
				}
				AudioClip content = DownloadHandlerAudioClip.GetContent(request);
				if (!Object.op_Implicit((Object)(object)content) || content.samples == 0)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)("Empty haunting clip: " + path));
					continue;
				}
				((Object)content).name = "BoiledOne_Trumpet_" + i.ToString("00");
				Trumpets.Add(content);
			}
			finally
			{
				((IDisposable)request)?.Dispose();
			}
		}
		AudioLoaded = true;
		((BaseUnityPlugin)this).Logger.LogInfo((object)("Boiled One loaded " + Trumpets.Count + "/7 haunting trumpets."));
	}

	internal AudioClip NextTrumpet()
	{
		int count = Trumpets.Count;
		int num;
		switch (count)
		{
		case 0:
			return null;
		case 1:
			num = 0;
			break;
		default:
			if (previousTrumpet < 0)
			{
				num = soundRandom.Next(count);
				break;
			}
			num = soundRandom.Next(count - 1);
			if (num >= previousTrumpet)
			{
				num++;
			}
			break;
		}
		previousTrumpet = num;
		((BaseUnityPlugin)this).Logger.LogDebug((object)("Haunting sound: " + ((Object)Trumpets[num]).name));
		return Trumpets[num];
	}

	private static void SilenceGirl(DressGirlAI girl)
	{
		girl.appearStaringSFX = (AudioClip[])(object)new AudioClip[1] { Silence };
		girl.skipWalkSFX = Silence;
		girl.breathingSFX = Silence;
		if (Object.op_Implicit((Object)(object)((EnemyAI)girl).creatureVoice))
		{
			((EnemyAI)girl).creatureVoice.Stop();
			((EnemyAI)girl).creatureVoice.mute = true;
		}
		if (Object.op_Implicit((Object)(object)((EnemyAI)girl).creatureSFX))
		{
			((EnemyAI)girl).creatureSFX.Stop();
			((EnemyAI)girl).creatureSFX.mute = true;
		}
		PlayAudioAnimationEvent[] componentsInChildren = ((Component)girl).GetComponentsInChildren<PlayAudioAnimationEvent>(true);
		foreach (PlayAudioAnimationEvent val in componentsInChildren)
		{
			val.audioClip = (val.audioClip2 = (val.audioClip3 = Silence));
			val.randomClips = (AudioClip[])(object)new AudioClip[1] { Silence };
			val.randomClips2 = (AudioClip[])(object)new AudioClip[1] { Silence };
		}
	}
}
public sealed class BoiledVisual : MonoBehaviour
{
	private DressGirlAI girl;

	private Renderer[] originals;

	private Renderer[] replacements;

	private bool[] previousForceOff;

	private GameObject visual;

	private Transform holder;

	private bool requestedVisible;

	private readonly List<Mesh> bakedMeshes = new List<Mesh>();

	private float authoredHeight;

	private Vector3 groundCenter;

	internal GameObject CreateScare(Camera camera)
	{
		//IL_0054: 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_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)holder) || !Object.op_Implicit((Object)(object)camera) || authoredHeight <= 0f)
		{
			return null;
		}
		GameObject val = Object.Instantiate<GameObject>(((Component)holder).gameObject, ((Component)camera).transform, false);
		((Object)val).name = "BoiledOneFinalScare";
		val.SetActive(true);
		val.transform.localScale = Vector3.one * (2.5f / authoredHeight);
		val.transform.localRotation = Quaternion.Euler(0f, Plugin.Instance.Yaw.Value, 0f);
		val.transform.localPosition = new Vector3(0f, -2.1f, 0.7f);
		MeshRenderer[] componentsInChildren = val.GetComponentsInChildren<MeshRenderer>(true);
		foreach (MeshRenderer obj in componentsInChildren)
		{
			((Renderer)obj).enabled = true;
			((Renderer)obj).forceRenderingOff = false;
			((Component)obj).gameObject.layer = 19;
		}
		return val;
	}

	public void SetVisible(bool visible)
	{
		requestedVisible = visible;
	}

	public void Initialize(DressGirlAI owner)
	{
		//IL_00bc: 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)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Expected O, but got Unknown
		//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_01d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_021a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0228: Unknown result type (might be due to invalid IL or missing references)
		//IL_02af: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0300: Unknown result type (might be due to invalid IL or missing references)
		//IL_0309: Unknown result type (might be due to invalid IL or missing references)
		//IL_0310: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0401: Unknown result type (might be due to invalid IL or missing references)
		//IL_040b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0410: Unknown result type (might be due to invalid IL or missing references)
		//IL_0421: Unknown result type (might be due to invalid IL or missing references)
		//IL_0426: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_04db: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0336: Unknown result type (might be due to invalid IL or missing references)
		//IL_033b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0340: Unknown result type (might be due to invalid IL or missing references)
		//IL_0345: Unknown result type (might be due to invalid IL or missing references)
		//IL_0354: Unknown result type (might be due to invalid IL or missing references)
		//IL_0356: Unknown result type (might be due to invalid IL or missing references)
		//IL_035b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0360: Unknown result type (might be due to invalid IL or missing references)
		//IL_0379: Unknown result type (might be due to invalid IL or missing references)
		//IL_0367: Unknown result type (might be due to invalid IL or missing references)
		//IL_0369: Unknown result type (might be due to invalid IL or missing references)
		girl = owner;
		originals = (from r in ((Component)owner).GetComponentsInChildren<Renderer>(true)
			where r is SkinnedMeshRenderer || r is MeshRenderer
			select r).ToArray();
		if (originals.Length == 0)
		{
			throw new Exception("Ghost Girl has no mesh renderers");
		}
		previousForceOff = originals.Select((Renderer r) => r.forceRenderingOff).ToArray();
		requestedVisible = originals.Any((Renderer r) => Object.op_Implicit((Object)(object)r) && r.enabled && ((Component)r).gameObject.activeInHierarchy && ((Component)r).gameObject.layer == 19);
		holder = new GameObject("BoiledOneVisualAnchor").transform;
		visual = Object.Instantiate<GameObject>(Plugin.Prefab, holder, false);
		visual.transform.localPosition = Vector3.zero;
		Animator[] componentsInChildren = visual.GetComponentsInChildren<Animator>(true);
		for (int num = 0; num < componentsInChildren.Length; num++)
		{
			((Behaviour)componentsInChildren[num]).enabled = false;
		}
		Collider[] componentsInChildren2 = visual.GetComponentsInChildren<Collider>(true);
		for (int num = 0; num < componentsInChildren2.Length; num++)
		{
			componentsInChildren2[num].enabled = false;
		}
		List<Renderer> list = new List<Renderer>();
		SkinnedMeshRenderer[] componentsInChildren3 = visual.GetComponentsInChildren<SkinnedMeshRenderer>(true);
		foreach (SkinnedMeshRenderer val in componentsInChildren3)
		{
			Mesh val2 = new Mesh
			{
				name = "BoiledOneFixedPose"
			};
			bakedMeshes.Add(val2);
			val.BakeMesh(val2, false);
			if (val2.vertexCount == 0)
			{
				throw new Exception("Cannot bake Boiled One mesh");
			}
			val2.RecalculateBounds();
			GameObject val3 = new GameObject("BoiledOneFixedMesh");
			val3.transform.SetParent(((Component)val).transform, false);
			val3.AddComponent<MeshFilter>().sharedMesh = val2;
			MeshRenderer val4 = val3.AddComponent<MeshRenderer>();
			((Renderer)val4).sharedMaterials = ((Renderer)val).sharedMaterials;
			((Renderer)val4).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)val4).receiveShadows = ((Renderer)val).receiveShadows;
			((Renderer)val4).renderingLayerMask = ((Renderer)val).renderingLayerMask;
			((Renderer)val4).lightProbeUsage = ((Renderer)val).lightProbeUsage;
			((Renderer)val4).reflectionProbeUsage = ((Renderer)val).reflectionProbeUsage;
			((Renderer)val).enabled = false;
			list.Add((Renderer)(object)val4);
		}
		MeshRenderer[] componentsInChildren4 = visual.GetComponentsInChildren<MeshRenderer>(true);
		foreach (MeshRenderer item in componentsInChildren4)
		{
			if (!list.Contains((Renderer)(object)item))
			{
				list.Add((Renderer)(object)item);
			}
		}
		replacements = list.ToArray();
		if (replacements.Length == 0)
		{
			throw new Exception("Boiled One has no usable renderers");
		}
		Bounds val5 = default(Bounds);
		bool flag = true;
		Renderer[] array = replacements;
		foreach (Renderer val6 in array)
		{
			MeshFilter component = ((Component)val6).GetComponent<MeshFilter>();
			if (!Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)component.sharedMesh))
			{
				continue;
			}
			Bounds bounds = component.sharedMesh.bounds;
			for (int num2 = 0; num2 < 8; num2++)
			{
				Vector3 val7 = ((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)(((num2 & 1) != 0) ? 1 : (-1)), (float)(((num2 & 2) != 0) ? 1 : (-1)), (float)(((num2 & 4) != 0) ? 1 : (-1))));
				val7 = holder.InverseTransformPoint(((Component)val6).transform.TransformPoint(val7));
				if (flag)
				{
					((Bounds)(ref val5))..ctor(val7, Vector3.zero);
					flag = false;
				}
				else
				{
					((Bounds)(ref val5)).Encapsulate(val7);
				}
			}
		}
		authoredHeight = ((Bounds)(ref val5)).size.y;
		if (flag || authoredHeight < 1E-05f || float.IsNaN(authoredHeight) || float.IsInfinity(authoredHeight))
		{
			throw new Exception("Boiled One geometry has invalid height");
		}
		groundCenter = new Vector3(((Bounds)(ref val5)).center.x, ((Bounds)(ref val5)).min.y, ((Bounds)(ref val5)).center.z);
		visual.transform.localPosition = -groundCenter;
		array = replacements;
		for (int num = 0; num < array.Length; num++)
		{
			array[num].enabled = false;
		}
		LateUpdate();
		Plugin.Instance.Report("Boiled One fixed pose ready; authored height=" + authoredHeight + " units; requested height=" + Plugin.Instance.Height.Value + "m equivalent; applied height=" + authoredHeight * holder.localScale.y + " game units; enemy scale=" + ((object)((Component)owner).transform.lossyScale/*cast due to .constrained prefix*/).ToString());
	}

	private void LateUpdate()
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		//IL_0080: 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_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)girl) || !Object.op_Implicit((Object)(object)visual) || originals == null || authoredHeight <= 0f)
		{
			return;
		}
		holder.position = ((Component)girl).transform.position + Vector3.up * Plugin.Instance.YOffset.Value;
		holder.rotation = Quaternion.Euler(0f, ((Component)girl).transform.eulerAngles.y + 180f + Plugin.Instance.Yaw.Value, 0f);
		PlayerControllerB val = (Object.op_Implicit((Object)(object)GameNetworkManager.Instance) ? GameNetworkManager.Instance.localPlayerController : null);
		float num = ((Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.thisController)) ? Mathf.Abs(((Component)val.thisController).transform.lossyScale.y) : 1f);
		float num2 = Mathf.Clamp(Plugin.Instance.Height.Value, 0.1f, 20f) * (2.5f * num / 1.8f);
		holder.localScale = Vector3.one * (num2 / authoredHeight) * Mathf.Clamp(Plugin.Instance.Scale.Value, 0.01f, 20f);
		bool flag = requestedVisible && !ComaManager.Holds(girl) && !((EnemyAI)girl).isEnemyDead && Object.op_Implicit((Object)(object)GameNetworkManager.Instance) && Object.op_Implicit((Object)(object)GameNetworkManager.Instance.localPlayerController) && (Object)(object)girl.hauntingPlayer == (Object)(object)GameNetworkManager.Instance.localPlayerController;
		Renderer[] array = originals;
		foreach (Renderer val2 in array)
		{
			if (Object.op_Implicit((Object)(object)val2))
			{
				val2.forceRenderingOff = true;
			}
		}
		array = replacements;
		foreach (Renderer obj in array)
		{
			((Component)obj).gameObject.layer = (flag ? 19 : 23);
			obj.enabled = flag;
		}
	}

	private void OnDisable()
	{
		if (Object.op_Implicit((Object)(object)holder))
		{
			((Component)holder).gameObject.SetActive(false);
		}
	}

	private void OnEnable()
	{
		if (Object.op_Implicit((Object)(object)holder))
		{
			((Component)holder).gameObject.SetActive(true);
		}
	}

	private void OnDestroy()
	{
		if (originals != null && previousForceOff != null)
		{
			for (int i = 0; i < originals.Length; i++)
			{
				if (Object.op_Implicit((Object)(object)originals[i]))
				{
					originals[i].forceRenderingOff = previousForceOff[i];
				}
			}
		}
		if (Object.op_Implicit((Object)(object)holder))
		{
			Object.Destroy((Object)(object)((Component)holder).gameObject);
		}
		foreach (Mesh bakedMesh in bakedMeshes)
		{
			if (Object.op_Implicit((Object)(object)bakedMesh))
			{
				Object.Destroy((Object)(object)bakedMesh);
			}
		}
	}
}
public sealed class BoiledHauntAudio : MonoBehaviour
{
	private DressGirlAI girl;

	private AudioSource trumpet;

	private bool pending;

	private bool chasing;

	private bool speechStarted;

	private AudioSource[] originalSources;

	public void Initialize(DressGirlAI owner)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Expected O, but got Unknown
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Invalid comparison between Unknown and I4
		girl = owner;
		originalSources = ((Component)owner).GetComponentsInChildren<AudioSource>(true);
		GameObject val = new GameObject("BoiledOneHauntingAudio");
		val.transform.SetParent(((Component)owner).transform, false);
		trumpet = val.AddComponent<AudioSource>();
		trumpet.playOnAwake = false;
		trumpet.loop = false;
		trumpet.spatialBlend = 1f;
		trumpet.dopplerLevel = 0f;
		trumpet.rolloffMode = (AudioRolloffMode)1;
		trumpet.minDistance = 5f;
		trumpet.maxDistance = 60f;
		if (Object.op_Implicit((Object)(object)((EnemyAI)owner).creatureVoice))
		{
			trumpet.outputAudioMixerGroup = ((EnemyAI)owner).creatureVoice.outputAudioMixerGroup;
			trumpet.minDistance = ((EnemyAI)owner).creatureVoice.minDistance;
			trumpet.maxDistance = ((EnemyAI)owner).creatureVoice.maxDistance;
			trumpet.rolloffMode = ((EnemyAI)owner).creatureVoice.rolloffMode;
			if ((int)trumpet.rolloffMode == 2)
			{
				trumpet.SetCustomCurve((AudioSourceCurveType)0, ((EnemyAI)owner).creatureVoice.GetCustomCurve((AudioSourceCurveType)0));
			}
		}
		MuteOriginalEffects();
	}

	private void MuteOriginalEffects()
	{
		if (!Object.op_Implicit((Object)(object)girl) || originalSources == null)
		{
			return;
		}
		AudioSource[] array = originalSources;
		foreach (AudioSource val in array)
		{
			if (Object.op_Implicit((Object)(object)val) && !((Object)(object)val == (Object)(object)girl.heartbeatMusic))
			{
				val.mute = true;
				if (val.isPlaying)
				{
					val.Stop();
				}
			}
		}
	}

	private void LateUpdate()
	{
		MuteOriginalEffects();
		SyncChase();
	}

	private bool CanHear()
	{
		if (Object.op_Implicit((Object)(object)girl) && !((EnemyAI)girl).isEnemyDead && Object.op_Implicit((Object)(object)GameNetworkManager.Instance) && Object.op_Implicit((Object)(object)GameNetworkManager.Instance.localPlayerController) && !GameNetworkManager.Instance.localPlayerController.isPlayerDead)
		{
			return (Object)(object)girl.hauntingPlayer == (Object)(object)GameNetworkManager.Instance.localPlayerController;
		}
		return false;
	}

	public void PlayHaunt()
	{
		if (!CanHear() || ComaManager.Holds(girl) || ((EnemyAI)girl).currentBehaviourStateIndex == 1)
		{
			return;
		}
		if (!Plugin.AudioLoaded)
		{
			pending = true;
			return;
		}
		pending = false;
		AudioClip val = Plugin.Instance.NextTrumpet();
		if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)trumpet))
		{
			trumpet.Stop();
			trumpet.clip = val;
			trumpet.volume = Mathf.Clamp01(Plugin.Instance.TrumpetVolume.Value);
			trumpet.Play();
		}
	}

	public void StopAudio()
	{
		pending = false;
		chasing = false;
		speechStarted = false;
		if (Object.op_Implicit((Object)(object)trumpet))
		{
			trumpet.Stop();
		}
	}

	public void StopHaunt()
	{
		pending = false;
		if (!chasing && Object.op_Implicit((Object)(object)trumpet))
		{
			trumpet.Stop();
		}
	}

	public void SyncChase()
	{
		if (!CanHear() || (!ComaManager.Holds(girl) && ((EnemyAI)girl).currentBehaviourStateIndex != 1))
		{
			if (chasing)
			{
				StopAudio();
			}
			return;
		}
		if (!chasing)
		{
			StopAudio();
			chasing = true;
		}
		if (!speechStarted && Object.op_Implicit((Object)(object)Plugin.ChaseSpeech) && Object.op_Implicit((Object)(object)trumpet))
		{
			speechStarted = true;
			trumpet.clip = Plugin.ChaseSpeech;
			trumpet.volume = Mathf.Clamp01(Plugin.Instance.ChaseVolume.Value);
			trumpet.Play();
		}
	}

	private void Update()
	{
		if (Object.op_Implicit((Object)(object)girl) && Object.op_Implicit((Object)(object)((EnemyAI)girl).creatureSFX))
		{
			((EnemyAI)girl).creatureSFX.mute = true;
		}
		if (Object.op_Implicit((Object)(object)girl) && Object.op_Implicit((Object)(object)((EnemyAI)girl).creatureVoice))
		{
			((EnemyAI)girl).creatureVoice.mute = true;
		}
		if (!CanHear())
		{
			StopAudio();
			return;
		}
		SyncChase();
		if (pending && Plugin.AudioLoaded)
		{
			PlayHaunt();
		}
	}

	private void OnDisable()
	{
		StopAudio();
	}

	private void OnDestroy()
	{
		if (Object.op_Implicit((Object)(object)trumpet))
		{
			Object.Destroy((Object)(object)((Component)trumpet).gameObject);
		}
	}
}
public sealed class ComaManager : MonoBehaviour
{
	[HarmonyPatch(typeof(DressGirlAI), "OnCollideWithPlayer")]
	private static class CapturePatch
	{
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			MethodInfo kill = AccessTools.Method(typeof(PlayerControllerB), "KillPlayer", (Type[])null, (Type[])null);
			int replaced = 0;
			foreach (CodeInstruction instruction in instructions)
			{
				if (CodeInstructionExtensions.Calls(instruction, kill))
				{
					CodeInstruction val = new CodeInstruction(OpCodes.Ldarg_0, (object)null);
					val.labels.AddRange(instruction.labels);
					instruction.labels.Clear();
					yield return val;
					instruction.opcode = OpCodes.Call;
					instruction.operand = AccessTools.Method(typeof(ComaManager), "Capture", (Type[])null, (Type[])null);
					replaced++;
				}
				yield return instruction;
			}
			if (replaced != 1)
			{
				throw new InvalidOperationException("Expected one Ghost Girl kill call, found " + replaced);
			}
		}
	}

	[HarmonyPatch(typeof(DressGirlAI), "Update")]
	private static class HoldCaptor
	{
		private static bool Prefix(DressGirlAI __instance)
		{
			return !Holds(__instance);
		}
	}

	[HarmonyPatch(typeof(PlayerControllerB), "KillPlayer")]
	private static class PreventEarlyDeath
	{
		private static bool Prefix(PlayerControllerB __instance)
		{
			if (Has(__instance))
			{
				if (Object.op_Implicit((Object)(object)Instance))
				{
					return Instance.finishing;
				}
				return false;
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(PlayerControllerB), "DamagePlayer")]
	private static class PreventDamage
	{
		private static bool Prefix(PlayerControllerB __instance)
		{
			return !Has(__instance);
		}
	}

	[HarmonyPatch(typeof(EnemyAI), "PlayerIsTargetable")]
	private static class Untargetable
	{
		private static bool Prefix(PlayerControllerB __0, ref bool __result)
		{
			if (!Has(__0))
			{
				return true;
			}
			__result = false;
			return false;
		}
	}

	[HarmonyPatch(typeof(PlayerControllerB), "IVisibleThreat.IsThreatDead")]
	private static class IgnoreThreat
	{
		private static void Postfix(PlayerControllerB __instance, ref bool __result)
		{
			if (Has(__instance))
			{
				__result = true;
			}
		}
	}

	[HarmonyPatch(typeof(EnemyAI), "MeetsStandardPlayerCollisionConditions")]
	private static class IgnoreCollision
	{
		private static void Postfix(ref PlayerControllerB __result)
		{
			if (Has(__result))
			{
				__result = null;
			}
		}
	}

	[HarmonyPatch]
	private static class BlockEnemyContact
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			HashSet<MethodBase> hashSet = new HashSet<MethodBase>();
			int num = 0;
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				Type[] types;
				try
				{
					types = assembly.GetTypes();
				}
				catch (ReflectionTypeLoadException ex)
				{
					types = ex.Types;
				}
				catch (Exception)
				{
					num++;
					continue;
				}
				Type[] array = types;
				foreach (Type type in array)
				{
					if (type == null)
					{
						continue;
					}
					try
					{
						if (typeof(EnemyAI).IsAssignableFrom(type))
						{
							MethodInfo method = type.GetMethod("OnCollideWithPlayer", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(Collider) }, null);
							if (method != null && !method.IsAbstract && !method.ContainsGenericParameters)
							{
								hashSet.Add(method);
							}
						}
					}
					catch (Exception)
					{
						num++;
					}
				}
			}
			Plugin.Instance.Report("Coma contact protection: " + hashSet.Count + " methods; skipped " + num + " unloadable types/assemblies.");
			return hashSet;
		}

		private static bool Prefix(Collider __0)
		{
			if (Object.op_Implicit((Object)(object)__0))
			{
				return !Has(((Component)__0).GetComponentInParent<PlayerControllerB>());
			}
			return true;
		}
	}

	[HarmonyPatch]
	private static class FilterSight
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			yield return AccessTools.Method(typeof(EnemyAI), "CheckLineOfSightForPlayer", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(EnemyAI), "CheckLineOfSightForClosestPlayer", (Type[])null, (Type[])null);
		}

		private static void Postfix(ref PlayerControllerB __result)
		{
			if (Has(__result))
			{
				__result = null;
			}
		}
	}

	[HarmonyPatch]
	private static class BlockActions
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			return ((IEnumerable<string>)new string[13]
			{
				"Jump_performed", "Crouch_performed", "Interact_performed", "ActivateItem_performed", "ScrollMouse_performed", "UseUtilitySlot_performed", "InspectItem_performed", "QEItemInteract_performed", "ItemSecondaryUse_performed", "ItemTertiaryUse_performed",
				"Discard_performed", "Emote1_performed", "Emote2_performed"
			}).Select((Func<string, MethodBase>)((string n) => AccessTools.Method(typeof(PlayerControllerB), n, (Type[])null, (Type[])null)));
		}

		private static bool Prefix(PlayerControllerB __instance)
		{
			return !Has(__instance);
		}
	}

	[HarmonyPatch(typeof(PlayerControllerB), "Look_performed")]
	private static class ComaLook
	{
		private static bool Prefix(PlayerControllerB __instance, CallbackContext __0)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			if (!Has(__instance) || !Object.op_Implicit((Object)(object)Instance) || (Object)(object)Instance.victim != (Object)(object)__instance)
			{
				return true;
			}
			if (__instance.quickMenuManager.isMenuOpen)
			{
				return false;
			}
			Vector2 val = ((CallbackContext)(ref __0)).ReadValue<Vector2>() * 0.035f;
			Instance.look.x = Mathf.Clamp(Instance.look.x + val.x, -7f, 7f);
			Instance.look.y = Mathf.Clamp(Instance.look.y + val.y, -5f, 5f);
			return false;
		}
	}

	[HarmonyPatch(typeof(DissonanceComms), "set_IsMuted")]
	private static class KeepVoiceMuted
	{
		private static void Prefix(ref bool __0)
		{
			if (Object.op_Implicit((Object)(object)Instance) && Object.op_Implicit((Object)(object)Instance.victim))
			{
				__0 = true;
			}
		}
	}

	[HarmonyPatch(typeof(StartOfRound), "ReviveDeadPlayers")]
	private static class ResetOnRound
	{
		private static void Prefix()
		{
			if (Object.op_Implicit((Object)(object)Instance))
			{
				Instance.ResetAll();
			}
		}
	}

	internal static ComaManager Instance;

	private const string Request = "aj.boiledone.coma.request.v1";

	private const string State = "aj.boiledone.coma.state.v1";

	private readonly Dictionary<ulong, float> affected = new Dictionary<ulong, float>();

	private NetworkManager network;

	private PlayerControllerB victim;

	private DressGirlAI captor;

	private float started;

	private bool finishing;

	private bool scared;

	private bool oldMove;

	private bool oldLook;

	private bool oldInteract;

	private bool oldMute;

	private DissonanceComms comms;

	private Vector3 anchor;

	private Transform anchorParent;

	private Quaternion bodyRotation;

	private Quaternion cameraRotation;

	private Vector2 look;

	private GameObject scare;

	private WhiteComaScene whiteScene;

	private float oldAgentSpeed;

	private static readonly FieldRef<PlayerControllerB, bool> Jumping = AccessTools.FieldRefAccess<PlayerControllerB, bool>("isJumping");

	internal static bool Has(PlayerControllerB p)
	{
		if (Object.op_Implicit((Object)(object)p) && Object.op_Implicit((Object)(object)Instance))
		{
			return Instance.affected.ContainsKey(p.playerClientId);
		}
		return false;
	}

	internal static bool Holds(DressGirlAI g)
	{
		if (Object.op_Implicit((Object)(object)Instance) && Object.op_Implicit((Object)(object)Instance.victim))
		{
			return (Object)(object)Instance.captor == (Object)(object)g;
		}
		return false;
	}

	private void Awake()
	{
		Instance = this;
	}

	private void Update()
	{
		//IL_0278: Unknown result type (might be due to invalid IL or missing references)
		//IL_0280: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Expected O, but got Unknown
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Expected O, but got Unknown
		NetworkManager singleton = NetworkManager.Singleton;
		if ((Object)(object)network != (Object)(object)singleton || (Object.op_Implicit((Object)(object)network) && !network.IsListening))
		{
			ResetAll();
			Unregister();
		}
		if (!Object.op_Implicit((Object)(object)network) && Object.op_Implicit((Object)(object)singleton) && singleton.IsListening && singleton.CustomMessagingManager != null)
		{
			network = singleton;
			network.CustomMessagingManager.RegisterNamedMessageHandler("aj.boiledone.coma.request.v1", new HandleNamedMessageDelegate(ReceiveRequest));
			network.CustomMessagingManager.RegisterNamedMessageHandler("aj.boiledone.coma.state.v1", new HandleNamedMessageDelegate(ReceiveState));
		}
		ulong[] array = affected.Keys.ToArray();
		foreach (ulong num in array)
		{
			PlayerControllerB val = Player(num);
			if (!Object.op_Implicit((Object)(object)val) || val.isPlayerDead || !val.isPlayerControlled || Time.unscaledTime > affected[num])
			{
				affected.Remove(num);
			}
		}
		if (!Object.op_Implicit((Object)(object)victim))
		{
			return;
		}
		if (victim.isPlayerDead || !victim.isPlayerControlled || !Object.op_Implicit((Object)(object)network) || !network.IsListening)
		{
			EndLocal();
			return;
		}
		LockBody();
		if (Object.op_Implicit((Object)(object)comms))
		{
			comms.IsMuted = true;
		}
		float num2 = Time.unscaledTime - started;
		if (!scared && num2 >= 29.55f)
		{
			scared = true;
			try
			{
				if (whiteScene != null)
				{
					scare = whiteScene.Model;
				}
				else if (Object.op_Implicit((Object)(object)captor))
				{
					scare = ((Component)captor).GetComponent<BoiledVisual>()?.CreateScare(victim.gameplayCamera);
				}
				AudioClip val2 = Plugin.Instance.NextTrumpet();
				if (Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)scare))
				{
					AudioSource obj = scare.AddComponent<AudioSource>();
					obj.spatialBlend = 0f;
					obj.volume = 0.8f;
					obj.PlayOneShot(val2);
				}
			}
			catch (Exception ex)
			{
				Plugin.Instance.Report("Jumpscare failed; coma timer will still finish: " + ex.Message);
			}
		}
		if (num2 >= 30f)
		{
			PlayerControllerB val3 = victim;
			finishing = true;
			try
			{
				val3.KillPlayer(Vector3.zero, true, (CauseOfDeath)0, 0, Vector3.zero, false);
			}
			finally
			{
				finishing = false;
				EndLocal();
			}
			Plugin.Instance.Report("Boiled One pseudocoma finished: 30 seconds.");
		}
	}

	private static PlayerControllerB Player(ulong id)
	{
		if (!Object.op_Implicit((Object)(object)StartOfRound.Instance))
		{
			return null;
		}
		return ((IEnumerable<PlayerControllerB>)StartOfRound.Instance.allPlayerScripts).FirstOrDefault((Func<PlayerControllerB, bool>)((PlayerControllerB p) => Object.op_Implicit((Object)(object)p) && p.playerClientId == id));
	}

	private void ReceiveRequest(ulong sender, FastBufferReader reader)
	{
		//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_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)network) && network.IsServer && ((FastBufferReader)(ref reader)).TryBeginRead(9))
		{
			ulong id = default(ulong);
			((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref id, default(ForPrimitives));
			bool active = default(bool);
			((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref active, default(ForPrimitives));
			PlayerControllerB val = Player(id);
			if (Object.op_Implicit((Object)(object)val) && val.actualClientId == sender)
			{
				Apply(id, active);
				Broadcast(id, active);
			}
		}
	}

	private void ReceiveState(ulong sender, FastBufferReader reader)
	{
		//IL_0015: 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_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		if (sender == 0L && ((FastBufferReader)(ref reader)).TryBeginRead(9))
		{
			ulong id = default(ulong);
			((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref id, default(ForPrimitives));
			bool active = default(bool);
			((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref active, default(ForPrimitives));
			Apply(id, active);
		}
	}

	private void Apply(ulong id, bool active)
	{
		if (active)
		{
			affected[id] = Time.unscaledTime + 35f;
		}
		else
		{
			affected.Remove(id);
		}
	}

	private unsafe void Send(string name, ulong recipient, ulong id, bool active)
	{
		//IL_0011: 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_0023: 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_003c: Unknown result type (might be due to invalid IL or missing references)
		FastBufferWriter val = default(FastBufferWriter);
		((FastBufferWriter)(ref val))..ctor(16, (Allocator)2, -1);
		try
		{
			((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref id, default(ForPrimitives));
			((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref active, default(ForPrimitives));
			network.CustomMessagingManager.SendNamedMessage(name, recipient, val, (NetworkDelivery)3);
		}
		finally
		{
			((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
		}
	}

	private void Broadcast(ulong id, bool active)
	{
		foreach (ulong connectedClientsId in network.ConnectedClientsIds)
		{
			if (connectedClientsId != network.LocalClientId)
			{
				Send("aj.boiledone.coma.state.v1", connectedClientsId, id, active);
			}
		}
	}

	private void Publish(ulong id, bool active)
	{
		Apply(id, active);
		if (Object.op_Implicit((Object)(object)network) && network.IsListening)
		{
			if (network.IsServer)
			{
				Broadcast(id, active);
			}
			else
			{
				Send("aj.boiledone.coma.request.v1", 0uL, id, active);
			}
		}
	}

	internal void Begin(PlayerControllerB p, DressGirlAI girl)
	{
		//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_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)p) && !p.isPlayerDead && ((NetworkBehaviour)p).IsOwner && !Has(p))
		{
			victim = p;
			captor = girl;
			oldAgentSpeed = (Object.op_Implicit((Object)(object)((EnemyAI)girl).agent) ? ((EnemyAI)girl).agent.speed : 0f);
			if (Object.op_Implicit((Object)(object)((EnemyAI)girl).agent))
			{
				((EnemyAI)girl).agent.speed = 0f;
			}
			started = Time.unscaledTime;
			scared = false;
			look = Vector2.zero;
			oldMove = p.disableMoveInput;
			oldLook = p.disableLookInput;
			oldInteract = p.disableInteract;
			anchorParent = ((Component)p).transform.parent;
			anchor = ((Component)p).transform.localPosition;
			bodyRotation = p.thisPlayerBody.rotation;
			cameraRotation = ((Component)p.gameplayCamera).transform.localRotation;
			comms = (Object.op_Implicit((Object)(object)StartOfRound.Instance) ? StartOfRound.Instance.voiceChatModule : null);
			oldMute = Object.op_Implicit((Object)(object)comms) && comms.IsMuted;
			if (Object.op_Implicit((Object)(object)comms))
			{
				comms.IsMuted = true;
			}
			Publish(p.playerClientId, active: true);
			LockBody();
			((Component)girl).GetComponent<BoiledVisual>()?.SetVisible(visible: false);
			whiteScene = new WhiteComaScene();
			try
			{
				whiteScene.Begin(p, ((Component)girl).GetComponent<BoiledVisual>());
			}
			catch (Exception ex)
			{
				whiteScene.Dispose();
				whiteScene = null;
				Plugin.Instance.Report("White coma scene unavailable; retaining coma controls: " + ex.Message);
			}
			Plugin.Instance.Report("Boiled One pseudocoma started for player " + p.playerClientId + ".");
		}
	}

	private void LockBody()
	{
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0058: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: 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)
		if (Object.op_Implicit((Object)(object)victim))
		{
			victim.disableMoveInput = true;
			victim.disableLookInput = true;
			victim.disableInteract = true;
			victim.moveInputVector = Vector2.zero;
			victim.externalForces = Vector3.zero;
			victim.externalForceAutoFade = Vector3.zero;
			victim.isSprinting = false;
			Jumping.Invoke(victim) = false;
			victim.fallValue = 0f;
			victim.fallValueUncapped = 0f;
			((Component)victim).transform.position = (Object.op_Implicit((Object)(object)anchorParent) ? anchorParent.TransformPoint(anchor) : anchor);
			victim.thisPlayerBody.rotation = bodyRotation;
		}
	}

	private void LateUpdate()
	{
		//IL_0016: 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_0030: 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_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)victim))
		{
			LockBody();
			look *= Mathf.Exp(-3.5f * Time.unscaledDeltaTime);
			((Component)victim.gameplayCamera).transform.localRotation = cameraRotation * Quaternion.Euler(0f - look.y, look.x, 0f);
			whiteScene?.Tick(Time.unscaledTime - started);
		}
	}

	private void EndLocal()
	{
		//IL_007d: 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)
		if (whiteScene != null)
		{
			whiteScene.Dispose();
			whiteScene = null;
			scare = null;
		}
		if (Object.op_Implicit((Object)(object)victim))
		{
			victim.disableMoveInput = oldMove;
			victim.disableLookInput = oldLook;
			victim.disableInteract = oldInteract;
			if (!victim.isPlayerDead)
			{
				victim.thisPlayerBody.rotation = bodyRotation;
				((Component)victim.gameplayCamera).transform.localRotation = cameraRotation;
			}
			Publish(victim.playerClientId, active: false);
		}
		victim = null;
		if (Object.op_Implicit((Object)(object)comms))
		{
			comms.IsMuted = oldMute;
		}
		if (Object.op_Implicit((Object)(object)captor))
		{
			if (Object.op_Implicit((Object)(object)((EnemyAI)captor).agent))
			{
				((EnemyAI)captor).agent.speed = oldAgentSpeed;
			}
			((Component)captor).GetComponent<BoiledHauntAudio>()?.StopAudio();
		}
		if (Object.op_Implicit((Object)(object)scare))
		{
			Object.Destroy((Object)(object)scare);
		}
		victim = null;
		captor = null;
		comms = null;
	}

	internal void ResetAll()
	{
		EndLocal();
		affected.Clear();
	}

	private void Unregister()
	{
		if (Object.op_Implicit((Object)(object)network) && network.CustomMessagingManager != null)
		{
			network.CustomMessagingManager.UnregisterNamedMessageHandler("aj.boiledone.coma.request.v1");
			network.CustomMessagingManager.UnregisterNamedMessageHandler("aj.boiledone.coma.state.v1");
		}
		network = null;
	}

	private void OnDestroy()
	{
		ResetAll();
		Unregister();
		if ((Object)(object)Instance == (Object)(object)this)
		{
			Instance = null;
		}
	}

	internal static void Capture(PlayerControllerB p, Vector3 force, bool body, CauseOfDeath cause, int animation, Vector3 offset, bool drop, DressGirlAI girl)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)Instance))
		{
			Instance.Begin(p, girl);
		}
		else
		{
			p.KillPlayer(force, body, cause, animation, offset, drop);
		}
	}
}
internal sealed class WhiteComaScene : IDisposable
{
	private Camera camera;

	private HDAdditionalCameraData hd;

	private int mask;

	private int layer;

	private int firstPersonMask;

	private CameraClearFlags clearFlags;

	private Color background;

	private Color hdBackground;

	private LayerMask volumeMask;

	private ClearColorMode clearMode;

	private readonly Dictionary<GameObject, int> layers = new Dictionary<GameObject, int>();

	private readonly List<Material> materials = new List<Material>();

	private GameObject volumeObject;

	private GameObject model;

	private GameObject stage;

	private VolumeProfile profile;

	private Vector3 standingPosition;

	private Vector3 faceLocal;

	private Quaternion stageRotation;

	private Vector3 stagePosition;

	private bool saved;

	private readonly HashSet<GameObject> firstPersonObjects = new HashSet<GameObject>();

	internal GameObject Model => model;

	internal void Begin(PlayerControllerB player, BoiledVisual visual)
	{
		//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)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_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)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Expected O, but got Unknown
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_021e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_0233: Unknown result type (might be due to invalid IL or missing references)
		//IL_0239: Unknown result type (might be due to invalid IL or missing references)
		//IL_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_024e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Unknown result type (might be due to invalid IL or missing references)
		//IL_0258: Unknown result type (might be due to invalid IL or missing references)
		//IL_0269: Unknown result type (might be due to invalid IL or missing references)
		//IL_026e: Unknown result type (might be due to invalid IL or missing references)
		//IL_026f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0274: Unknown result type (might be due to invalid IL or missing references)
		//IL_0285: Unknown result type (might be due to invalid IL or missing references)
		//IL_0295: Unknown result type (might be due to invalid IL or missing references)
		//IL_029f: Expected O, but got Unknown
		if (!Object.op_Implicit((Object)(object)player) || !Object.op_Implicit((Object)(object)visual))
		{
			throw new InvalidOperationException("Coma visual unavailable.");
		}
		camera = player.gameplayCamera;
		layer = FindUnusedLayer();
		hd = ((Component)camera).GetComponent<HDAdditionalCameraData>();
		mask = camera.cullingMask;
		clearFlags = camera.clearFlags;
		background = camera.backgroundColor;
		if (Object.op_Implicit((Object)(object)hd))
		{
			volumeMask = hd.volumeLayerMask;
			clearMode = hd.clearColorMode;
			hdBackground = hd.backgroundColorHDR;
		}
		saved = true;
		KeepFirstPerson(player.localArmsTransform);
		if (Object.op_Implicit((Object)(object)player.thisPlayerModelArms))
		{
			KeepFirstPerson(((Component)player.thisPlayerModelArms).transform);
		}
		Keep(player.playerHudUIContainer);
		Keep(player.localVisor);
		if (Object.op_Implicit((Object)(object)player.currentlyHeldObjectServer))
		{
			Keep(((Component)player.currentlyHeldObjectServer).transform);
		}
		Keep(((Component)camera).transform);
		if (Object.op_Implicit((Object)(object)HUDManager.Instance))
		{
			Keep(((Component)HUDManager.Instance).transform);
		}
		stage = new GameObject("BoiledOneWhiteStage");
		stagePosition = ((Component)camera).transform.position;
		stageRotation = ((Component)camera).transform.rotation;
		stage.transform.SetPositionAndRotation(stagePosition, stageRotation);
		model = visual.CreateScare(camera);
		if (!Object.op_Implicit((Object)(object)model))
		{
			throw new InvalidOperationException("Cannot create coma model.");
		}
		model.transform.SetParent(stage.transform, false);
		Transform[] componentsInChildren = model.GetComponentsInChildren<Transform>(true);
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			((Component)componentsInChildren[i]).gameObject.layer = layer;
		}
		SetUnlitMaterials();
		faceLocal = MeasureFace();
		Vector3 val = model.transform.localRotation * Vector3.Scale(faceLocal, model.transform.localScale);
		standingPosition = new Vector3(0f, 0f, 2.2f) - val;
		model.transform.localPosition = standingPosition;
		volumeObject = new GameObject("BoiledOneWhiteVolume");
		volumeObject.layer = layer;
		Volume obj = volumeObject.AddComponent<Volume>();
		obj.isGlobal = true;
		obj.priority = 10000f;
		profile = ScriptableObject.CreateInstance<VolumeProfile>();
		((VolumeParameter<bool>)(object)profile.Add<Fog>(false).enabled).Override(false);
		Exposure obj2 = profile.Add<Exposure>(false);
		((VolumeParameter<ExposureMode>)(object)obj2.mode).Override((ExposureMode)0);
		((VolumeParameter<float>)(object)obj2.fixedExposure).Override(0f);
		obj.sharedProfile = profile;
		ApplyCamera();
	}

	private static int FindUnusedLayer()
	{
		HashSet<int> hashSet = new HashSet<int>(from r in Object.FindObjectsOfType<Renderer>(true)
			select ((Component)r).gameObject.layer);
		Canvas[] array = Object.FindObjectsOfType<Canvas>(true);
		foreach (Canvas val in array)
		{
			hashSet.Add(((Component)val).gameObject.layer);
		}
		Terrain[] activeTerrains = Terrain.activeTerrains;
		foreach (Terrain val2 in activeTerrains)
		{
			hashSet.Add(((Component)val2).gameObject.layer);
		}
		for (int num2 = 31; num2 >= 8; num2--)
		{
			if (!hashSet.Contains(num2))
			{
				return num2;
			}
		}
		throw new InvalidOperationException("No free presentation layer for the white scene.");
	}

	private void KeepFirstPerson(Transform root)
	{
		if (Object.op_Implicit((Object)(object)root))
		{
			Renderer[] componentsInChildren = ((Component)root).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				firstPersonObjects.Add(((Component)val).gameObject);
				firstPersonMask |= 1 << ((Component)val).gameObject.layer;
			}
		}
	}

	private Vector3 MeasureFace()
	{
		//IL_0002: 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_01af: 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_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: 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_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		Bounds val = default(Bounds);
		Bounds val2 = default(Bounds);
		bool flag = false;
		bool flag2 = false;
		MeshRenderer[] componentsInChildren = model.GetComponentsInChildren<MeshRenderer>(true);
		foreach (MeshRenderer val3 in componentsInChildren)
		{
			MeshFilter component = ((Component)val3).GetComponent<MeshFilter>();
			if (!Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)component.sharedMesh))
			{
				continue;
			}
			Mesh sharedMesh = component.sharedMesh;
			Vector3[] vertices = sharedMesh.vertices;
			Material[] sharedMaterials = ((Renderer)val3).sharedMaterials;
			for (int j = 0; j < sharedMesh.subMeshCount; j++)
			{
				bool flag3 = j < sharedMaterials.Length && Object.op_Implicit((Object)(object)sharedMaterials[j]) && ((Object)sharedMaterials[j]).name.IndexOf("eye", StringComparison.OrdinalIgnoreCase) >= 0;
				int[] indices = sharedMesh.GetIndices(j);
				foreach (int num in indices)
				{
					Vector3 val4 = model.transform.InverseTransformPoint(((Component)val3).transform.TransformPoint(vertices[num]));
					if (!flag)
					{
						((Bounds)(ref val))..ctor(val4, Vector3.zero);
						flag = true;
					}
					else
					{
						((Bounds)(ref val)).Encapsulate(val4);
					}
					if (flag3)
					{
						if (!flag2)
						{
							((Bounds)(ref val2))..ctor(val4, Vector3.zero);
							flag2 = true;
						}
						else
						{
							((Bounds)(ref val2)).Encapsulate(val4);
						}
					}
				}
			}
		}
		if (!flag)
		{
			throw new InvalidOperationException("No readable coma geometry.");
		}
		if (!flag2)
		{
			return new Vector3(((Bounds)(ref val)).center.x, ((Bounds)(ref val)).min.y + ((Bounds)(ref val)).size.y * 0.85f, ((Bounds)(ref val)).center.z);
		}
		return ((Bounds)(ref val2)).center;
	}

	private void Keep(Transform root)
	{
		if (!Object.op_Implicit((Object)(object)root))
		{
			return;
		}
		Transform[] componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(true);
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			GameObject gameObject = ((Component)componentsInChildren[i]).gameObject;
			if (!firstPersonObjects.Contains(gameObject) && (Object.op_Implicit((Object)(object)gameObject.GetComponent<Renderer>()) || Object.op_Implicit((Object)(object)gameObject.GetComponent<Canvas>()) || Object.op_Implicit((Object)(object)gameObject.GetComponent<CanvasRenderer>())))
			{
				if (!layers.ContainsKey(gameObject))
				{
					layers.Add(gameObject, gameObject.layer);
				}
				gameObject.layer = layer;
			}
		}
	}

	private void ApplyCamera()
	{
		//IL_002f: 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_0058: 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_007f: 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)
		camera.cullingMask = (1 << layer) | firstPersonMask;
		camera.clearFlags = (CameraClearFlags)2;
		camera.backgroundColor = Color.white;
		if (Object.op_Implicit((Object)(object)hd))
		{
			hd.clearColorMode = (ClearColorMode)1;
			hd.backgroundColorHDR = Color.white;
			hd.volumeLayerMask = LayerMask.op_Implicit(((LayerMask)(ref volumeMask)).value | (1 << layer));
		}
	}

	private void SetUnlitMaterials()
	{
		Shader shader = Shader.Find("HDRP/Unlit");
		MeshRenderer[] componentsInChildren = model.GetComponentsInChildren<MeshRenderer>(true);
		foreach (MeshRenderer obj in componentsInChildren)
		{
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)obj).receiveShadows = false;
			((Renderer)obj).sharedMaterials = ((IEnumerable<Material>)((Renderer)obj).sharedMaterials).Select((Func<Material, Material>)delegate(Material original)
			{
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Expected O, but got Unknown
				//IL_005d: 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_0062: Unknown result type (might be due to invalid IL or missing references)
				//IL_0110: Unknown result type (might be due to invalid IL or missing references)
				//IL_0091: Unknown result type (might be due to invalid IL or missing references)
				if (!Object.op_Implicit((Object)(object)original))
				{
					return original;
				}
				Material val = new Material(original);
				materials.Add(val);
				Texture val2 = (original.HasProperty("_BaseColorMap") ? original.GetTexture("_BaseColorMap") : original.mainTexture);
				Color val3 = (original.HasProperty("_BaseColor") ? original.GetColor("_BaseColor") : Color.white);
				if (Object.op_Implicit((Object)(object)shader))
				{
					val.shader = shader;
					val.SetTexture("_UnlitColorMap", val2);
					val.SetColor("_UnlitColor", val3);
					val.SetFloat("_EmissiveExposureWeight", 0f);
					if (original.HasProperty("_AlphaCutoffEnable"))
					{
						bool flag = original.GetFloat("_AlphaCutoffEnable") > 0.5f;
						val.SetFloat("_AlphaCutoffEnable", flag ? 1f : 0f);
						if (flag)
						{
							val.EnableKeyword("_ALPHATEST_ON");
						}
						else
						{
							val.DisableKeyword("_ALPHATEST_ON");
						}
					}
				}
				else
				{
					val.SetTexture("_EmissiveColorMap", val2);
					val.SetColor("_EmissiveColor", val3);
					val.SetFloat("_EmissiveExposureWeight", 0f);
					val.EnableKeyword("_EMISSIVE_COLOR_MAP");
				}
				return val;
			}).ToArray();
		}
	}

	internal void Tick(float elapsed)
	{
		//IL_00c1: 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_00f9: 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)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)camera) || !Object.op_Implicit((Object)(object)model))
		{
			return;
		}
		ApplyCamera();
		foreach (KeyValuePair<GameObject, int> layer in layers)
		{
			if (Object.op_Implicit((Object)(object)layer.Key))
			{
				layer.Key.layer = this.layer;
			}
		}
		if (elapsed < 29.55f)
		{
			stage.transform.SetPositionAndRotation(stagePosition, stageRotation);
			model.transform.localPosition = standingPosition;
			return;
		}
		stage.transform.SetPositionAndRotation(((Component)camera).transform.position, ((Component)camera).transform.rotation);
		float num = Mathf.Clamp01((elapsed - 29.55f) / 0.1f);
		Vector3 val = model.transform.localRotation * Vector3.Scale(faceLocal, model.transform.localScale);
		model.transform.localPosition = Vector3.Lerp(standingPosition, new Vector3(0f, 0f, 0.62f) - val, num);
	}

	public void Dispose()
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_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_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		if (saved && Object.op_Implicit((Object)(object)camera))
		{
			camera.cullingMask = mask;
			camera.clearFlags = clearFlags;
			camera.backgroundColor = background;
			if (Object.op_Implicit((Object)(object)hd))
			{
				hd.clearColorMode = clearMode;
				hd.backgroundColorHDR = hdBackground;
				hd.volumeLayerMask = volumeMask;
			}
		}
		foreach (KeyValuePair<GameObject, int> layer in layers)
		{
			if (Object.op_Implicit((Object)(object)layer.Key))
			{
				layer.Key.layer = layer.Value;
			}
		}
		layers.Clear();
		if (Object.op_Implicit((Object)(object)stage))
		{
			Object.Destroy((Object)(object)stage);
		}
		else if (Object.op_Implicit((Object)(object)model))
		{
			Object.Destroy((Object)(object)model);
		}
		if (Object.op_Implicit((Object)(object)volumeObject))
		{
			Object.Destroy((Object)(object)volumeObject);
		}
		if (Object.op_Implicit((Object)(object)profile))
		{
			foreach (VolumeComponent component in profile.components)
			{
				Object.Destroy((Object)(object)component);
			}
			Object.Destroy((Object)(object)profile);
		}
		foreach (Material material in materials)
		{
			if (Object.op_Implicit((Object)(object)material))
			{
				Object.Destroy((Object)(object)material);
			}
		}
		materials.Clear();
		saved = false;
	}
}