Decompiled source of AirConditionerAlive v0.2.22

AirConditionerAlive.dll

Decompiled 2 days ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace AirConditionerAlive
{
	[BepInPlugin("mrwasheewashee.airconditioneralive", "Air Conditioner Alive", "0.2.22")]
	public sealed class AirConditionerModelSwap : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(AirConditioning), "Start")]
		private static class AirConditionerPlacementPatch
		{
			private static void Postfix(AirConditioning __instance)
			{
				//IL_005d: 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)
				if ((Object)(object)_active == (Object)null)
				{
					return;
				}
				Transform val = ((Component)__instance).transform;
				while ((Object)(object)val != (Object)null && !IsCeilingAirConditioner(((Object)val).name) && !IsWallAirConditionerA(((Object)val).name) && !IsWallAirConditionerB(((Object)val).name))
				{
					val = val.parent;
				}
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				Scene scene = ((Component)val).gameObject.scene;
				if (!((Scene)(ref scene)).IsValid() || IsInsideReplacement(val))
				{
					return;
				}
				if (IsCeilingAirConditioner(((Object)val).name))
				{
					if ((Object)(object)_active._replacementCeiling != (Object)null && (Object)(object)val.Find("ACAlive_CeilingReplacement") == (Object)null)
					{
						_active.TryReplaceCeiling(val);
					}
				}
				else
				{
					_active.ScanWallUnits((Transform[])(object)new Transform[1] { val });
				}
			}
		}

		private static AirConditionerModelSwap _active;

		private Harmony _placementHarmony;

		private AssetBundle _bundle;

		private AssetBundle _ceilingBundle;

		private GameObject _replacementB;

		private GameObject _replacementCeiling;

		private float _nextScan;

		private AudioClip _hum;

		private AudioClip _airCurtainSound;

		private static Material _airMaterial;

		private void Awake()
		{
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Expected O, but got Unknown
			_hum = MakeHum();
			_airCurtainSound = MakeAirCurtainSound();
			string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			string text = Path.Combine(directoryName, "airconditioner");
			if (File.Exists(text))
			{
				_bundle = AssetBundle.LoadFromFile(text);
				if ((Object)(object)_bundle == (Object)null)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)"Could not load airconditioner bundle.");
				}
				else
				{
					GameObject[] array = _bundle.LoadAllAssets<GameObject>();
					foreach (GameObject val in array)
					{
						if (((Object)val).name == "AirConditionerReplacement")
						{
							_replacementB = val;
						}
					}
					if ((Object)(object)_replacementB == (Object)null)
					{
						((BaseUnityPlugin)this).Logger.LogError((object)"Bundle has no prefab named AirConditionerReplacement.");
					}
					else
					{
						((BaseUnityPlugin)this).Logger.LogInfo((object)("Replacement AC model loaded from " + text));
					}
				}
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("No B model bundle at " + text));
			}
			string text2 = Path.Combine(directoryName, "ceilingairconditioner");
			if (File.Exists(text2))
			{
				_ceilingBundle = AssetBundle.LoadFromFile(text2);
				if ((Object)(object)_ceilingBundle == (Object)null)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)"Could not load ceilingairconditioner bundle.");
				}
				else
				{
					GameObject[] array = _ceilingBundle.LoadAllAssets<GameObject>();
					foreach (GameObject val2 in array)
					{
						if (((Object)val2).name == "CeilingAirConditionerReplacement")
						{
							_replacementCeiling = val2;
						}
					}
					if ((Object)(object)_replacementCeiling == (Object)null)
					{
						((BaseUnityPlugin)this).Logger.LogError((object)"Ceiling bundle has no prefab named CeilingAirConditionerReplacement.");
					}
					else
					{
						((BaseUnityPlugin)this).Logger.LogInfo((object)("Ceiling AC model loaded from " + text2));
					}
				}
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("No ceiling model bundle at " + text2));
			}
			if ((Object)(object)_replacementCeiling != (Object)null || (Object)(object)_replacementB != (Object)null || (Object)(object)_airCurtainSound != (Object)null)
			{
				_active = this;
				_placementHarmony = new Harmony("mrwasheewashee.airconditioneralive.placement");
				_placementHarmony.PatchAll(typeof(AirConditionerModelSwap).Assembly);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Air conditioner placement hook ready");
			}
		}

		private void OnDestroy()
		{
			if (_placementHarmony != null)
			{
				_placementHarmony.UnpatchSelf();
			}
			if ((Object)(object)_active == (Object)(object)this)
			{
				_active = null;
			}
		}

		private void Update()
		{
			if (!(Time.unscaledTime < _nextScan))
			{
				_nextScan = Time.unscaledTime + 5f;
				ScanWallUnits(Object.FindObjectsByType<Transform>((FindObjectsSortMode)0));
			}
		}

		private void ScanWallUnits(Transform[] units)
		{
			//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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: 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_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: 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_021f: 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_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			foreach (Transform val in units)
			{
				Scene scene;
				if (IsWallAirConditionerA(((Object)val).name))
				{
					scene = ((Component)val).gameObject.scene;
					if (((Scene)(ref scene)).IsValid() && !IsInsideReplacement(val) && (Object)(object)((Component)val).GetComponent<AirCurtainCycle>() == (Object)null)
					{
						TrySetUpAirCurtain(val);
					}
				}
				else
				{
					if ((Object)(object)_replacementB == (Object)null || !IsWallAirConditionerB(((Object)val).name))
					{
						continue;
					}
					scene = ((Component)val).gameObject.scene;
					if (!((Scene)(ref scene)).IsValid() || IsInsideReplacement(val) || (Object)(object)val.Find("ACAlive_Replacement") != (Object)null)
					{
						continue;
					}
					try
					{
						Renderer[] componentsInChildren = ((Component)val).GetComponentsInChildren<Renderer>(true);
						if (!TryGetBounds(componentsInChildren, out var bounds))
						{
							continue;
						}
						GameObject val2 = Object.Instantiate<GameObject>(_replacementB, val, false);
						((Object)val2).name = "ACAlive_Replacement";
						val2.transform.localPosition = Vector3.zero;
						val2.transform.localRotation = Quaternion.identity;
						val2.transform.localScale = Vector3.one;
						Collider[] componentsInChildren2 = val2.GetComponentsInChildren<Collider>(true);
						for (int j = 0; j < componentsInChildren2.Length; j++)
						{
							componentsInChildren2[j].enabled = false;
						}
						Renderer[] componentsInChildren3 = val2.GetComponentsInChildren<Renderer>(true);
						Renderer[] array = componentsInChildren3;
						for (int j = 0; j < array.Length; j++)
						{
							array[j].enabled = true;
						}
						if (!TryGetBounds(componentsInChildren3, out var bounds2))
						{
							Object.Destroy((Object)(object)val2);
							((BaseUnityPlugin)this).Logger.LogWarning((object)"B replacement has no visible mesh; kept the original model.");
							continue;
						}
						float num = LargestDimension(((Bounds)(ref bounds)).size);
						float num2 = LargestDimension(((Bounds)(ref bounds2)).size);
						float num3 = Mathf.Clamp(num / num2, 0.01f, 100f);
						val2.transform.localScale = Vector3.one * num3;
						if (!TryGetBounds(componentsInChildren3, out bounds2))
						{
							Object.Destroy((Object)(object)val2);
							((BaseUnityPlugin)this).Logger.LogWarning((object)"B replacement bounds vanished after scaling; kept the original model.");
							continue;
						}
						Transform transform = val2.transform;
						transform.position += ((Bounds)(ref bounds)).center - ((Bounds)(ref bounds2)).center;
						if (!PrepareMaterials(componentsInChildren3))
						{
							Object.Destroy((Object)(object)val2);
							((BaseUnityPlugin)this).Logger.LogWarning((object)"URP/Lit shader was unavailable; kept the original B model.");
							continue;
						}
						((BaseUnityPlugin)this).Logger.LogInfo((object)("B bounds: original " + ((object)((Bounds)(ref bounds)).size/*cast due to .constrained prefix*/).ToString() + " at " + ((object)((Bounds)(ref bounds)).center/*cast due to .constrained prefix*/).ToString() + ", replacement " + ((object)((Bounds)(ref bounds2)).size/*cast due to .constrained prefix*/).ToString() + " at " + ((object)((Bounds)(ref bounds2)).center/*cast due to .constrained prefix*/).ToString() + ", scale " + num3 + ", renderers " + componentsInChildren3.Length));
						AudioSource val3 = CreateAudio(val, 0.08f);
						ParticleSystem val4 = CreateAirflow(val, bounds, airCurtain: false);
						Animator componentInChildren = val2.GetComponentInChildren<Animator>(true);
						if (!val2.AddComponent<AirConditionerCycle>().Initialize(componentInChildren, val3, val4, delegate(string message)
						{
							((BaseUnityPlugin)this).Logger.LogInfo((object)message);
						}))
						{
							if ((Object)(object)val4 != (Object)null)
							{
								Object.Destroy((Object)(object)((Component)val4).gameObject);
							}
							Object.Destroy((Object)(object)val3);
							Object.Destroy((Object)(object)val2);
							((BaseUnityPlugin)this).Logger.LogWarning((object)"B animation clip was unavailable; kept the original model.");
						}
						else
						{
							array = componentsInChildren;
							for (int j = 0; j < array.Length; j++)
							{
								array[j].enabled = false;
							}
							((BaseUnityPlugin)this).Logger.LogInfo((object)("Replaced model on " + ((Object)val).name));
						}
					}
					catch (Exception ex)
					{
						((BaseUnityPlugin)this).Logger.LogError((object)("Could not replace " + ((Object)val).name + ": " + ex));
					}
				}
			}
		}

		private void TrySetUpAirCurtain(Transform unit)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			AudioSource val = null;
			ParticleSystem val2 = null;
			try
			{
				if (TryGetBounds(((Component)unit).GetComponentsInChildren<Renderer>(true), out var bounds))
				{
					val2 = CreateAirflow(unit, bounds, airCurtain: true);
					val = CreateAudio(unit, 0.12f);
					val.clip = _airCurtainSound;
					((Component)unit).gameObject.AddComponent<AirCurtainCycle>().Initialize(val, val2, delegate(string message)
					{
						((BaseUnityPlugin)this).Logger.LogInfo((object)message);
					});
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Air curtain ready on " + ((Object)unit).name));
				}
			}
			catch (Exception ex)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)val2).gameObject);
				}
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
				((BaseUnityPlugin)this).Logger.LogError((object)("Could not set up air curtain on " + ((Object)unit).name + ": " + ex));
			}
		}

		private void TryReplaceCeiling(Transform unit)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: 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_016e: 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_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: 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_021f: 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_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: 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_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = null;
			AudioSource val2 = null;
			ParticleSystem[] array = null;
			try
			{
				Renderer[] componentsInChildren = ((Component)unit).GetComponentsInChildren<Renderer>(true);
				if (TryGetBounds(componentsInChildren, out var bounds))
				{
					val = Object.Instantiate<GameObject>(_replacementCeiling, unit, false);
					((Object)val).name = "ACAlive_CeilingReplacement";
					val.transform.localPosition = Vector3.zero;
					val.transform.localRotation = Quaternion.identity;
					val.transform.localScale = Vector3.one;
					Collider[] componentsInChildren2 = val.GetComponentsInChildren<Collider>(true);
					for (int i = 0; i < componentsInChildren2.Length; i++)
					{
						componentsInChildren2[i].enabled = false;
					}
					Renderer[] componentsInChildren3 = val.GetComponentsInChildren<Renderer>(true);
					Renderer[] array2 = componentsInChildren3;
					for (int i = 0; i < array2.Length; i++)
					{
						array2[i].enabled = true;
					}
					val2 = CreateAudio(unit, 0.08f);
					Animator componentInChildren = val.GetComponentInChildren<Animator>(true);
					CeilingAirConditionerCycle ceilingAirConditionerCycle = val.AddComponent<CeilingAirConditionerCycle>();
					if (!ceilingAirConditionerCycle.Initialize(componentInChildren, val2, delegate(string message)
					{
						((BaseUnityPlugin)this).Logger.LogInfo((object)message);
					}))
					{
						throw new Exception("Ceiling animation clip is unavailable.");
					}
					if (!TryGetBounds(componentsInChildren3, out var bounds2))
					{
						throw new Exception("Ceiling prefab has no visible mesh.");
					}
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Ceiling closed bounds: original " + ((object)((Bounds)(ref bounds)).size/*cast due to .constrained prefix*/).ToString() + " at " + ((object)((Bounds)(ref bounds)).center/*cast due to .constrained prefix*/).ToString() + ", replacement " + ((object)((Bounds)(ref bounds2)).size/*cast due to .constrained prefix*/).ToString() + " at " + ((object)((Bounds)(ref bounds2)).center/*cast due to .constrained prefix*/).ToString()));
					float num = Mathf.Clamp(LargestDimension(((Bounds)(ref bounds)).size) / LargestDimension(((Bounds)(ref bounds2)).size), 0.01f, 100f);
					val.transform.localScale = Vector3.one * num;
					if (!TryGetBounds(componentsInChildren3, out bounds2))
					{
						throw new Exception("Ceiling replacement bounds vanished.");
					}
					Transform transform = val.transform;
					transform.position += ((Bounds)(ref bounds)).center - ((Bounds)(ref bounds2)).center;
					if (!TryGetBounds(componentsInChildren3, out bounds2))
					{
						throw new Exception("Ceiling alignment failed.");
					}
					if (LargestDimension(((Bounds)(ref bounds2)).size) > 3f)
					{
						throw new Exception("Ceiling replacement exceeds 3 metres; kept the original model. Bounds: " + ((object)((Bounds)(ref bounds2)).size/*cast due to .constrained prefix*/).ToString() + ", scale " + num);
					}
					if (!PrepareMaterials(componentsInChildren3, replaceImportedShader: true))
					{
						throw new Exception("URP/Lit shader unavailable.");
					}
					array = CreateCeilingAirflow(unit, val, bounds);
					ceilingAirConditionerCycle.SetAirflow(array);
					array2 = componentsInChildren;
					for (int i = 0; i < array2.Length; i++)
					{
						array2[i].enabled = false;
					}
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Replaced ceiling AC on " + ((Object)unit).name + ", scale " + num + ", bounds " + ((object)((Bounds)(ref bounds2)).size/*cast due to .constrained prefix*/).ToString() + " at " + ((object)((Bounds)(ref bounds2)).center/*cast due to .constrained prefix*/).ToString() + ", vents " + array.Length + ", renderers " + componentsInChildren3.Length));
				}
			}
			catch (Exception ex)
			{
				if (array != null)
				{
					ParticleSystem[] array3 = array;
					foreach (ParticleSystem val3 in array3)
					{
						if ((Object)(object)val3 != (Object)null)
						{
							Object.Destroy((Object)(object)((Component)val3).gameObject);
						}
					}
				}
				if ((Object)(object)val2 != (Object)null)
				{
					Object.Destroy((Object)(object)val2);
				}
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
				((BaseUnityPlugin)this).Logger.LogError((object)("Could not replace ceiling AC on " + ((Object)unit).name + ": " + ex));
			}
		}

		private AudioSource CreateAudio(Transform unit, float volume)
		{
			AudioSource obj = ((Component)unit).gameObject.AddComponent<AudioSource>();
			obj.clip = _hum;
			obj.loop = true;
			obj.playOnAwake = false;
			obj.spatialBlend = 1f;
			obj.rolloffMode = (AudioRolloffMode)1;
			obj.minDistance = 1f;
			obj.maxDistance = 7f;
			obj.volume = volume;
			return obj;
		}

		private static bool IsWallAirConditionerA(string name)
		{
			if (!string.Equals(name, "245_WallAirConditionerA", StringComparison.OrdinalIgnoreCase))
			{
				return string.Equals(name, "245_WallAirConditionerA(Clone)", StringComparison.OrdinalIgnoreCase);
			}
			return true;
		}

		private static bool IsWallAirConditionerB(string name)
		{
			if (!string.Equals(name, "246_WallAirConditionerB", StringComparison.OrdinalIgnoreCase))
			{
				return string.Equals(name, "246_WallAirConditionerB(Clone)", StringComparison.OrdinalIgnoreCase);
			}
			return true;
		}

		private static bool IsCeilingAirConditioner(string name)
		{
			if (!string.Equals(name, "247_CeilingAirConditioner", StringComparison.OrdinalIgnoreCase))
			{
				return string.Equals(name, "247_CeilingAirConditioner(Clone)", StringComparison.OrdinalIgnoreCase);
			}
			return true;
		}

		private static bool IsInsideReplacement(Transform candidate)
		{
			Transform parent = candidate.parent;
			while ((Object)(object)parent != (Object)null)
			{
				if (((Object)parent).name == "ACAlive_Replacement" || ((Object)parent).name == "ACAlive_CeilingReplacement")
				{
					return true;
				}
				parent = parent.parent;
			}
			return false;
		}

		private static bool TryGetBounds(Renderer[] renderers, out Bounds bounds)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			bounds = default(Bounds);
			bool flag = false;
			foreach (Renderer val in renderers)
			{
				if ((Object)(object)val == (Object)null || !val.enabled)
				{
					continue;
				}
				Bounds bounds2 = val.bounds;
				if (!(LargestDimension(((Bounds)(ref bounds2)).size) < 0.001f))
				{
					if (flag)
					{
						((Bounds)(ref bounds)).Encapsulate(bounds2);
						continue;
					}
					bounds = bounds2;
					flag = true;
				}
			}
			return flag;
		}

		private static float LargestDimension(Vector3 size)
		{
			//IL_0000: 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_000c: Unknown result type (might be due to invalid IL or missing references)
			return Mathf.Max(size.x, Mathf.Max(size.y, size.z));
		}

		private unsafe ParticleSystem CreateAirflow(Transform unit, Bounds bounds, bool airCurtain)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_0058: 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_006c: 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_0088: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: 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_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: 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_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: 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_0143: 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_015f: 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_0178: 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_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0312: Unknown result type (might be due to invalid IL or missing references)
			//IL_0327: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_033f: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_036e: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_037f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0389: Unknown result type (might be due to invalid IL or missing references)
			//IL_0390: Expected O, but got Unknown
			//IL_039a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03db: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0402: Unknown result type (might be due to invalid IL or missing references)
			//IL_0407: Unknown result type (might be due to invalid IL or missing references)
			//IL_0418: Unknown result type (might be due to invalid IL or missing references)
			//IL_041d: Unknown result type (might be due to invalid IL or missing references)
			//IL_042b: Unknown result type (might be due to invalid IL or missing references)
			if (!EnsureAirMaterial())
			{
				return null;
			}
			GameObject val = new GameObject("ACAlive_Airflow");
			val.transform.SetParent(unit, false);
			Vector3 right = unit.right;
			Vector3 up = unit.up;
			Vector3 forward = unit.forward;
			Vector3 extents = ((Bounds)(ref bounds)).extents;
			float num = 2f * (Mathf.Abs(right.x) * extents.x + Mathf.Abs(right.y) * extents.y + Mathf.Abs(right.z) * extents.z);
			float num2 = 2f * (Mathf.Abs(up.x) * extents.x + Mathf.Abs(up.y) * extents.y + Mathf.Abs(up.z) * extents.z);
			float num3 = 2f * (Mathf.Abs(forward.x) * extents.x + Mathf.Abs(forward.y) * extents.y + Mathf.Abs(forward.z) * extents.z);
			Vector3 val2 = forward;
			Vector3 val3;
			if (airCurtain)
			{
				val.transform.position = ((Bounds)(ref bounds)).center - up * (num2 * 0.47f);
				val.transform.rotation = Quaternion.LookRotation(-up, forward);
				ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
				val3 = val.transform.position;
				string? text = ((object)(*(Vector3*)(&val3))/*cast due to .constrained prefix*/).ToString();
				val3 = -up;
				logger.LogInfo((object)("A air curtain at " + text + " toward " + ((object)(*(Vector3*)(&val3))/*cast due to .constrained prefix*/).ToString()));
			}
			else
			{
				val.transform.position = ((Bounds)(ref bounds)).center - up * (num2 * 0.43f) + val2 * (num3 * 0.75f);
				Transform transform = val.transform;
				val3 = val2 * 0.86f - up * 0.3f;
				transform.rotation = Quaternion.LookRotation(((Vector3)(ref val3)).normalized, up);
				ManualLogSource logger2 = ((BaseUnityPlugin)this).Logger;
				val3 = val.transform.position;
				string? text2 = ((object)(*(Vector3*)(&val3))/*cast due to .constrained prefix*/).ToString();
				val3 = val2;
				logger2.LogInfo((object)("B airflow at " + text2 + " toward " + ((object)(*(Vector3*)(&val3))/*cast due to .constrained prefix*/).ToString()));
			}
			ParticleSystem val4 = val.AddComponent<ParticleSystem>();
			MainModule main = val4.main;
			((MainModule)(ref main)).playOnAwake = false;
			((MainModule)(ref main)).loop = true;
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
			((MainModule)(ref main)).startLifetime = (airCurtain ? new MinMaxCurve(0.75f, 1.1f) : new MinMaxCurve(0.55f, 0.9f));
			((MainModule)(ref main)).startSpeed = (airCurtain ? new MinMaxCurve(0.8f, 1.25f) : new MinMaxCurve(0.55f, 0.9f));
			((MainModule)(ref main)).startSize = (airCurtain ? new MinMaxCurve(0.018f, 0.035f) : new MinMaxCurve(0.025f, 0.04f));
			((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(new Color(0.68f, 0.9f, 1f, 0.22f));
			((MainModule)(ref main)).maxParticles = 48;
			EmissionModule emission = val4.emission;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(airCurtain ? 22f : 16f);
			ShapeModule shape = val4.shape;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)5;
			((ShapeModule)(ref shape)).scale = new Vector3(num * 0.8f, 0.015f, 0.015f);
			ColorOverLifetimeModule colorOverLifetime = val4.colorOverLifetime;
			((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
			Gradient val5 = new Gradient();
			val5.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
			{
				new GradientColorKey(Color.white, 0f),
				new GradientColorKey(Color.white, 1f)
			}, (GradientAlphaKey[])(object)new GradientAlphaKey[4]
			{
				new GradientAlphaKey(0f, 0f),
				new GradientAlphaKey(1f, 0.2f),
				new GradientAlphaKey(0.35f, 0.6f),
				new GradientAlphaKey(0f, 1f)
			});
			((ColorOverLifetimeModule)(ref colorOverLifetime)).color = new MinMaxGradient(val5);
			ParticleSystemRenderer component = val.GetComponent<ParticleSystemRenderer>();
			((Renderer)component).sharedMaterial = _airMaterial;
			component.renderMode = (ParticleSystemRenderMode)1;
			component.lengthScale = 1.8f;
			component.velocityScale = 0.15f;
			val4.Stop(true, (ParticleSystemStopBehavior)0);
			return val4;
		}

		private bool EnsureAirMaterial()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Expected O, but got Unknown
			//IL_01a4: 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)
			if ((Object)(object)_airMaterial == (Object)null)
			{
				Shader val = Shader.Find("Universal Render Pipeline/Particles/Unlit");
				if ((Object)(object)val == (Object)null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"URP particle shader unavailable; airflow particles disabled.");
					return false;
				}
				_airMaterial = new Material(val);
				((Object)_airMaterial).name = "ACAlive Soft Air";
				_airMaterial.SetFloat("_Surface", 1f);
				_airMaterial.SetFloat("_Blend", 0f);
				_airMaterial.SetInt("_SrcBlend", 5);
				_airMaterial.SetInt("_DstBlend", 10);
				_airMaterial.SetInt("_ZWrite", 0);
				_airMaterial.renderQueue = 3000;
				_airMaterial.EnableKeyword("_SURFACE_TYPE_TRANSPARENT");
				Texture2D val2 = new Texture2D(32, 32, (TextureFormat)4, false);
				((Object)val2).name = "ACAlive Air Wisp";
				((Texture)val2).wrapMode = (TextureWrapMode)1;
				((Texture)val2).filterMode = (FilterMode)1;
				Color[] array = (Color[])(object)new Color[1024];
				for (int i = 0; i < 32; i++)
				{
					for (int j = 0; j < 32; j++)
					{
						float num = ((float)j - 15.5f) / 15.5f;
						float num2 = ((float)i - 15.5f) / 15.5f;
						float num3 = Mathf.Pow(Mathf.Clamp01(1f - num * num - num2 * num2), 2f);
						array[i * 32 + j] = new Color(1f, 1f, 1f, num3);
					}
				}
				val2.SetPixels(array);
				val2.Apply(false, true);
				_airMaterial.SetTexture("_BaseMap", (Texture)(object)val2);
				_airMaterial.SetColor("_BaseColor", Color.white);
			}
			return true;
		}

		private unsafe ParticleSystem[] CreateCeilingAirflow(Transform unit, GameObject model, Bounds bounds)
		{
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00de: 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_00e7: 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_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: 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_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Expected O, but got Unknown
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_0320: Expected O, but got Unknown
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: 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_034a: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: 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_037c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0381: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0435: Unknown result type (might be due to invalid IL or missing references)
			//IL_043a: Unknown result type (might be due to invalid IL or missing references)
			//IL_045b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0460: Unknown result type (might be due to invalid IL or missing references)
			if (!EnsureAirMaterial())
			{
				return (ParticleSystem[])(object)new ParticleSystem[0];
			}
			string[] array = new string[4] { "SubMesh_0.002", "SubMesh_0.003", "SubMesh_0.004", "SubMesh_0.007" };
			ParticleSystem[] array2 = (ParticleSystem[])(object)new ParticleSystem[array.Length];
			Transform[] componentsInChildren = model.GetComponentsInChildren<Transform>(true);
			for (int i = 0; i < array.Length; i++)
			{
				Transform val = null;
				Transform[] array3 = componentsInChildren;
				foreach (Transform val2 in array3)
				{
					if (((Object)val2).name == array[i])
					{
						val = val2;
						break;
					}
				}
				if ((Object)(object)val == (Object)null)
				{
					throw new Exception("Missing ceiling vent " + array[i]);
				}
				Renderer component = ((Component)val).GetComponent<Renderer>();
				if ((Object)(object)component == (Object)null)
				{
					throw new Exception("Ceiling vent has no renderer: " + array[i]);
				}
				Vector3 up = unit.up;
				Bounds bounds2 = component.bounds;
				Vector3 center = ((Bounds)(ref bounds2)).center;
				Vector3 val3 = Vector3.ProjectOnPlane(center - ((Bounds)(ref bounds)).center, up);
				Vector3 normalized = ((Vector3)(ref val3)).normalized;
				if (((Vector3)(ref normalized)).sqrMagnitude < 0.01f)
				{
					throw new Exception("Cannot determine ceiling vent direction: " + array[i]);
				}
				val3 = Vector3.Cross(up, normalized);
				Vector3 normalized2 = ((Vector3)(ref val3)).normalized;
				bounds2 = component.bounds;
				Vector3 extents = ((Bounds)(ref bounds2)).extents;
				float num = 2f * (Mathf.Abs(normalized2.x) * extents.x + Mathf.Abs(normalized2.y) * extents.y + Mathf.Abs(normalized2.z) * extents.z);
				GameObject val4 = new GameObject("ACAlive_CeilingAirflow_" + (i + 1));
				val4.transform.SetParent(model.transform, false);
				val4.transform.position = center - up * 0.015f;
				Transform transform = val4.transform;
				val3 = -up * 0.45f + normalized * 0.65f;
				transform.rotation = Quaternion.LookRotation(((Vector3)(ref val3)).normalized, up);
				ParticleSystem val5 = val4.AddComponent<ParticleSystem>();
				MainModule main = val5.main;
				((MainModule)(ref main)).playOnAwake = false;
				((MainModule)(ref main)).loop = true;
				((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
				((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.5f, 0.75f);
				((MainModule)(ref main)).startSpeed = new MinMaxCurve(0.5f, 0.85f);
				((MainModule)(ref main)).startSize = new MinMaxCurve(0.018f, 0.032f);
				((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(new Color(0.68f, 0.9f, 1f, 0.2f));
				((MainModule)(ref main)).maxParticles = 24;
				EmissionModule emission = val5.emission;
				((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(10f);
				ShapeModule shape = val5.shape;
				((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)5;
				((ShapeModule)(ref shape)).scale = new Vector3(Mathf.Clamp(num * 0.75f, 0.2f, 0.55f), 0.012f, 0.012f);
				ColorOverLifetimeModule colorOverLifetime = val5.colorOverLifetime;
				((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
				Gradient val6 = new Gradient();
				val6.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
				{
					new GradientColorKey(Color.white, 0f),
					new GradientColorKey(Color.white, 1f)
				}, (GradientAlphaKey[])(object)new GradientAlphaKey[4]
				{
					new GradientAlphaKey(0f, 0f),
					new GradientAlphaKey(1f, 0.2f),
					new GradientAlphaKey(0.35f, 0.65f),
					new GradientAlphaKey(0f, 1f)
				});
				((ColorOverLifetimeModule)(ref colorOverLifetime)).color = new MinMaxGradient(val6);
				ParticleSystemRenderer component2 = val4.GetComponent<ParticleSystemRenderer>();
				((Renderer)component2).sharedMaterial = _airMaterial;
				component2.renderMode = (ParticleSystemRenderMode)1;
				component2.lengthScale = 1f;
				component2.velocityScale = 0.08f;
				val5.Stop(true, (ParticleSystemStopBehavior)0);
				array2[i] = val5;
				ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
				string[] obj = new string[6]
				{
					"Ceiling vent ",
					(i + 1).ToString(),
					" airflow at ",
					null,
					null,
					null
				};
				val3 = val4.transform.position;
				obj[3] = ((object)(*(Vector3*)(&val3))/*cast due to .constrained prefix*/).ToString();
				obj[4] = " toward ";
				val3 = val4.transform.forward;
				obj[5] = ((object)(*(Vector3*)(&val3))/*cast due to .constrained prefix*/).ToString();
				logger.LogInfo((object)string.Concat(obj));
			}
			return array2;
		}

		private static bool PrepareMaterials(Renderer[] renderers, bool replaceImportedShader = false)
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: 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)
			Shader val = Shader.Find("Universal Render Pipeline/Lit");
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			foreach (Renderer val2 in renderers)
			{
				Material[] array = val2.sharedMaterials;
				if (array.Length == 0)
				{
					array = (Material[])(object)new Material[1];
				}
				bool flag = false;
				for (int j = 0; j < array.Length; j++)
				{
					Material val3 = array[j];
					if (!replaceImportedShader && (Object)(object)val3 != (Object)null && (Object)(object)val3.shader != (Object)null && ((Object)val3.shader).name.StartsWith("Universal Render Pipeline/", StringComparison.Ordinal))
					{
						continue;
					}
					Material val4 = new Material(val);
					if ((Object)(object)val3 != (Object)null)
					{
						if (val3.HasProperty("_BaseMap"))
						{
							val4.SetTexture("_BaseMap", val3.GetTexture("_BaseMap"));
						}
						else if (val3.HasProperty("_MainTex"))
						{
							val4.SetTexture("_BaseMap", val3.GetTexture("_MainTex"));
						}
						if (val3.HasProperty("_BaseColor"))
						{
							val4.SetColor("_BaseColor", val3.GetColor("_BaseColor"));
						}
						else if (val3.HasProperty("_Color"))
						{
							val4.SetColor("_BaseColor", val3.GetColor("_Color"));
						}
						if (val3.HasProperty("_BumpMap"))
						{
							val4.SetTexture("_BumpMap", val3.GetTexture("_BumpMap"));
							val4.EnableKeyword("_NORMALMAP");
						}
						if (val3.HasProperty("_EmissionColor"))
						{
							val4.SetColor("_EmissionColor", val3.GetColor("_EmissionColor"));
							val4.EnableKeyword("_EMISSION");
						}
					}
					array[j] = val4;
					flag = true;
				}
				if (flag)
				{
					val2.sharedMaterials = array;
				}
			}
			return true;
		}

		private static AudioClip MakeHum()
		{
			float[] array = new float[44100];
			for (int i = 0; i < 44100; i++)
			{
				float num = (float)i / 22050f;
				array[i] = 0.32f * Mathf.Sin((float)Math.PI * 120f * num) + 0.1f * Mathf.Sin((float)Math.PI * 240f * num);
			}
			AudioClip obj = AudioClip.Create("AC fan hum", 44100, 1, 22050, false);
			obj.SetData(array, 0);
			return obj;
		}

		private static AudioClip MakeAirCurtainSound()
		{
			float[] array = new float[176400];
			float[] array2 = new float[181912];
			Random random = new Random(245);
			float num = 0f;
			float num2 = 0f;
			for (int i = 0; i < array2.Length; i++)
			{
				float num3 = (float)(random.NextDouble() * 2.0 - 1.0);
				num += 0.015f * (num3 - num);
				num2 += 0.22f * (num3 - num2);
				array2[i] = 0.34f * (num2 - num) + 0.14f * num + 0.025f * num3;
			}
			for (int j = 0; j < 5512; j++)
			{
				float num4 = (float)Math.PI / 2f * (float)j / 5511f;
				array2[j] = array2[176400 + j] * Mathf.Cos(num4) + array2[j] * Mathf.Sin(num4);
			}
			for (int k = 0; k < 176400; k++)
			{
				float num5 = (float)k / 22050f;
				float num6 = 0.04f * Mathf.Sin((float)Math.PI * 194f * num5) + 0.015f * Mathf.Sin((float)Math.PI * 388f * num5);
				array[k] = array2[k] + num6;
			}
			AudioClip obj = AudioClip.Create("Air curtain airflow", 176400, 1, 22050, false);
			obj.SetData(array, 0);
			return obj;
		}
	}
	public sealed class AirCurtainCycle : MonoBehaviour
	{
		private AudioSource _audio;

		private ParticleSystem _airflow;

		private Action<string> _log;

		private bool _running;

		public void Initialize(AudioSource audio, ParticleSystem airflow, Action<string> log)
		{
			_audio = audio;
			_airflow = airflow;
			_log = log;
			_audio.Stop();
			if ((Object)(object)_airflow != (Object)null)
			{
				_airflow.Stop(true, (ParticleSystemStopBehavior)0);
			}
		}

		private void Update()
		{
			if ((Object)(object)_audio == (Object)null)
			{
				return;
			}
			bool flag = (Object)(object)GameData.Instance != (Object)null && GameData.Instance.NetworkisSupermarketOpen;
			if (flag == _running)
			{
				return;
			}
			_running = flag;
			if (_running)
			{
				_audio.Play();
				if ((Object)(object)_airflow != (Object)null)
				{
					_airflow.Play();
				}
				_log("A air curtain on with store");
			}
			else
			{
				_audio.Stop();
				if ((Object)(object)_airflow != (Object)null)
				{
					_airflow.Stop(true, (ParticleSystemStopBehavior)1);
				}
				_log("A air curtain off with store");
			}
		}
	}
	public sealed class CeilingAirConditionerCycle : MonoBehaviour
	{
		private enum Phase
		{
			Closed,
			Opening,
			Open,
			Closing
		}

		private AnimationClip _clip;

		private GameObject _animationRoot;

		private AudioSource _audio;

		private ParticleSystem[] _airflow = (ParticleSystem[])(object)new ParticleSystem[0];

		private Action<string> _log;

		private Phase _phase;

		private float _frame = 1f;

		private float _framesPerSecond;

		public bool Initialize(Animator animator, AudioSource audio, Action<string> log)
		{
			if ((Object)(object)animator == (Object)null || (Object)(object)animator.runtimeAnimatorController == (Object)null)
			{
				return false;
			}
			AnimationClip[] animationClips = animator.runtimeAnimatorController.animationClips;
			foreach (AnimationClip val in animationClips)
			{
				if (!((Object)(object)val == (Object)null) && !(val.length <= 0f))
				{
					_clip = val;
					break;
				}
			}
			if ((Object)(object)_clip == (Object)null)
			{
				return false;
			}
			_animationRoot = ((Component)animator).gameObject;
			_audio = audio;
			_log = log;
			_framesPerSecond = ((_clip.frameRate > 0f) ? _clip.frameRate : 24f);
			if (_clip.length < 118f / _framesPerSecond)
			{
				return false;
			}
			((Behaviour)animator).enabled = false;
			_audio.Stop();
			_phase = Phase.Closed;
			Sample();
			_log("Ceiling animation ready: " + ((Object)_clip).name + ", " + _clip.length + "s at " + _framesPerSecond + " fps");
			return true;
		}

		public void SetAirflow(ParticleSystem[] airflow)
		{
			_airflow = (ParticleSystem[])(((object)airflow) ?? ((object)new ParticleSystem[0]));
		}

		private void Update()
		{
			if ((Object)(object)_clip == (Object)null)
			{
				return;
			}
			bool flag = (Object)(object)GameData.Instance != (Object)null && GameData.Instance.NetworkisSupermarketOpen;
			if (flag && (_phase == Phase.Closed || _phase == Phase.Closing))
			{
				float num = ((_phase == Phase.Closing) ? Mathf.Clamp01((120f - _frame) / 60f) : 0f);
				_frame = 1f + 59f * num;
				_phase = Phase.Opening;
				_audio.Play();
				ParticleSystem[] airflow = _airflow;
				foreach (ParticleSystem val in airflow)
				{
					if ((Object)(object)val != (Object)null)
					{
						val.Play();
					}
				}
				_log("Ceiling opening with store");
			}
			else if (!flag && (_phase == Phase.Opening || _phase == Phase.Open))
			{
				float num2 = ((_phase == Phase.Opening) ? Mathf.Clamp01((_frame - 1f) / 59f) : 1f);
				_frame = 120f - 60f * num2;
				_phase = Phase.Closing;
				_audio.Stop();
				ParticleSystem[] airflow = _airflow;
				foreach (ParticleSystem val2 in airflow)
				{
					if ((Object)(object)val2 != (Object)null)
					{
						val2.Stop(true, (ParticleSystemStopBehavior)1);
					}
				}
				_log("Ceiling closing with store");
			}
			float num3 = Time.deltaTime * _framesPerSecond;
			if (_phase == Phase.Opening)
			{
				_frame += num3;
				if (_frame >= 60f)
				{
					_frame = 60f;
					_phase = Phase.Open;
				}
			}
			else if (_phase == Phase.Closing)
			{
				_frame += num3;
				if (_frame >= 120f)
				{
					_frame = 120f;
					_phase = Phase.Closed;
				}
			}
			Sample();
		}

		private void Sample()
		{
			float num = Mathf.Clamp((_frame - 1f) / _framesPerSecond, 0f, _clip.length);
			_clip.SampleAnimation(_animationRoot, num);
		}
	}
	public sealed class AirConditionerCycle : MonoBehaviour
	{
		private enum Phase
		{
			Closed,
			Opening,
			Running,
			Closing
		}

		private AnimationClip _clip;

		private GameObject _animationRoot;

		private AudioSource _audio;

		private ParticleSystem _airflow;

		private Action<string> _log;

		private Phase _phase;

		private float _frame = 1f;

		private float _framesPerSecond;

		public bool Initialize(Animator animator, AudioSource audio, ParticleSystem airflow, Action<string> log)
		{
			if ((Object)(object)animator == (Object)null || (Object)(object)animator.runtimeAnimatorController == (Object)null)
			{
				return false;
			}
			AnimationClip[] animationClips = animator.runtimeAnimatorController.animationClips;
			foreach (AnimationClip val in animationClips)
			{
				if (!((Object)(object)val == (Object)null) && !(val.length <= 0f))
				{
					_clip = val;
					break;
				}
			}
			if ((Object)(object)_clip == (Object)null)
			{
				return false;
			}
			_animationRoot = ((Component)animator).gameObject;
			_audio = audio;
			_airflow = airflow;
			_log = log;
			_framesPerSecond = ((_clip.frameRate > 0f) ? _clip.frameRate : 30f);
			((Behaviour)animator).enabled = false;
			_audio.Stop();
			if ((Object)(object)_airflow != (Object)null)
			{
				_airflow.Stop(true, (ParticleSystemStopBehavior)0);
			}
			_phase = Phase.Closed;
			Sample();
			_log("B animation ready: " + ((Object)_clip).name + ", " + _clip.length + "s at " + _framesPerSecond + " fps");
			return true;
		}

		private void Update()
		{
			if ((Object)(object)_clip == (Object)null)
			{
				return;
			}
			bool flag = (Object)(object)GameData.Instance != (Object)null && GameData.Instance.NetworkisSupermarketOpen;
			if (flag && (_phase == Phase.Closed || _phase == Phase.Closing))
			{
				_phase = Phase.Opening;
				_frame = 1f;
				_audio.Play();
				if ((Object)(object)_airflow != (Object)null)
				{
					_airflow.Play();
				}
				_log("B opening with store");
			}
			else if (!flag && (_phase == Phase.Opening || _phase == Phase.Running))
			{
				_phase = Phase.Closing;
				_frame = 300f;
				_audio.Stop();
				if ((Object)(object)_airflow != (Object)null)
				{
					_airflow.Stop(true, (ParticleSystemStopBehavior)1);
				}
				_log("B closing with store");
			}
			float num = Time.deltaTime * _framesPerSecond;
			if (_phase == Phase.Opening)
			{
				_frame += num;
				if (_frame >= 60f)
				{
					_frame = 60f;
					_phase = Phase.Running;
				}
			}
			else if (_phase == Phase.Running)
			{
				_frame += num;
				if (_frame >= 180f)
				{
					_frame = 60f + Mathf.Repeat(_frame - 60f, 120f);
				}
			}
			else if (_phase == Phase.Closing)
			{
				_frame += num;
				if (_frame >= 360f)
				{
					_frame = 360f;
					_phase = Phase.Closed;
				}
			}
			Sample();
		}

		private void Sample()
		{
			float num = Mathf.Clamp((_frame - 1f) / _framesPerSecond, 0f, _clip.length);
			_clip.SampleAnimation(_animationRoot, num);
		}
	}
}