Decompiled source of MHz176 v0.1.1

plugins/MHz176.dll

Decompiled 43 minutes ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using REPOLib.Modules;
using REPOLib.Objects.Sdk;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.Events;
using UnityEngine.Rendering;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MHz176
{
	internal static class Assets
	{
		private const int SoundRate = 24000;

		private static readonly Dictionary<string, Mesh> meshes = new Dictionary<string, Mesh>();

		private static readonly Dictionary<string, AudioClip> sounds = new Dictionary<string, AudioClip>();

		private static readonly int[] AdpcmSteps = new int[89]
		{
			7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
			19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
			50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
			130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
			337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
			876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
			2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
			5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
			15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
		};

		private static readonly int[] AdpcmIndex = new int[8] { -1, -1, -1, -1, 2, 4, 6, 8 };

		private static AudioMixerGroup mixer;

		private static AudioMixerGroup Mixer
		{
			get
			{
				if (Object.op_Implicit((Object)(object)mixer) || !Object.op_Implicit((Object)(object)AudioManager.instance) || !Object.op_Implicit((Object)(object)AudioManager.instance.SoundMasterGroup))
				{
					return mixer;
				}
				AudioMixerGroup[] array = AudioManager.instance.SoundMasterGroup.audioMixer.FindMatchingGroups("Sound Effects");
				mixer = ((array.Length != 0) ? array[0] : AudioManager.instance.SoundMasterGroup);
				return mixer;
			}
		}

		internal static byte[] Bytes(string name)
		{
			using Stream stream = typeof(Assets).Assembly.GetManifestResourceStream("MHz176." + name);
			if (stream == null)
			{
				throw new FileNotFoundException("Embedded asset missing: " + name);
			}
			byte[] array = new byte[stream.Length];
			for (int i = 0; i < array.Length; i += stream.Read(array, i, array.Length - i))
			{
			}
			return array;
		}

		internal static Mesh LoadMesh(string name)
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: 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_0146: Expected O, but got Unknown
			if (meshes.TryGetValue(name, out var value) && Object.op_Implicit((Object)(object)value))
			{
				return value;
			}
			byte[] array = Bytes(name + ".mesh");
			int num = BitConverter.ToInt32(array, 0);
			int num2 = BitConverter.ToInt32(array, 4);
			int num3 = 8;
			Vector3[] array2 = (Vector3[])(object)new Vector3[num];
			Vector3[] array3 = (Vector3[])(object)new Vector3[num];
			Vector2[] array4 = (Vector2[])(object)new Vector2[num];
			int[] array5 = new int[num2];
			int num4 = 0;
			while (num4 < num)
			{
				array2[num4] = new Vector3(F(array, num3), F(array, num3 + 4), F(array, num3 + 8));
				num4++;
				num3 += 12;
			}
			int num5 = 0;
			while (num5 < num)
			{
				array3[num5] = new Vector3(F(array, num3), F(array, num3 + 4), F(array, num3 + 8));
				num5++;
				num3 += 12;
			}
			int num6 = 0;
			while (num6 < num)
			{
				array4[num6] = new Vector2(F(array, num3), F(array, num3 + 4));
				num6++;
				num3 += 8;
			}
			int num7 = 0;
			while (num7 < num2)
			{
				array5[num7] = BitConverter.ToInt32(array, num3);
				num7++;
				num3 += 4;
			}
			Mesh val = new Mesh
			{
				name = name
			};
			if (num > 65535)
			{
				val.indexFormat = (IndexFormat)1;
			}
			val.vertices = array2;
			val.normals = array3;
			val.uv = array4;
			val.triangles = array5;
			val.RecalculateBounds();
			return meshes[name] = val;
		}

		private static float F(byte[] b, int o)
		{
			return BitConverter.ToSingle(b, o);
		}

		internal static Texture2D LoadTexture(string name)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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_002d: Expected O, but got Unknown
			//IL_002f: Expected O, but got Unknown
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true)
			{
				name = name,
				wrapMode = (TextureWrapMode)1
			};
			ImageConversion.LoadImage(val, Bytes(name + ".png"));
			return val;
		}

		internal static Texture2D LoadPalette(string name)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_0036: Expected O, but got Unknown
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false)
			{
				name = name,
				wrapMode = (TextureWrapMode)1,
				filterMode = (FilterMode)0
			};
			ImageConversion.LoadImage(val, Bytes(name + ".png"));
			return val;
		}

		internal static AudioClip LoadSound(string name)
		{
			if (sounds.TryGetValue(name, out var value) && Object.op_Implicit((Object)(object)value))
			{
				return value;
			}
			float[] array;
			if (Has(name + ".adpcm"))
			{
				array = Adpcm(Bytes(name + ".adpcm"));
			}
			else
			{
				byte[] array2 = Bytes(name + ".pcm");
				array = new float[array2.Length / 2];
				for (int i = 0; i < array.Length; i++)
				{
					array[i] = (float)BitConverter.ToInt16(array2, i * 2) / 32768f;
				}
			}
			value = AudioClip.Create(name, array.Length, 1, 24000, false);
			value.SetData(array, 0);
			return sounds[name] = value;
		}

		private static bool Has(string name)
		{
			return typeof(Assets).Assembly.GetManifestResourceInfo("MHz176." + name) != null;
		}

		private static float[] Adpcm(byte[] b)
		{
			int num = BitConverter.ToInt32(b, 0);
			float[] array = new float[num];
			int num2 = 0;
			int num3 = 0;
			for (int i = 0; i < num; i++)
			{
				int num4 = (b[4 + (i >> 1)] >> (i & 1) * 4) & 0xF;
				int num5 = AdpcmSteps[num3];
				int num6 = num5 >> 3;
				if ((num4 & 4) != 0)
				{
					num6 += num5;
				}
				if ((num4 & 2) != 0)
				{
					num6 += num5 >> 1;
				}
				if ((num4 & 1) != 0)
				{
					num6 += num5 >> 2;
				}
				num2 = Mathf.Clamp(((num4 & 8) != 0) ? (num2 - num6) : (num2 + num6), -32768, 32767);
				num3 = Mathf.Clamp(num3 + AdpcmIndex[num4 & 7], 0, 88);
				array[i] = (float)num2 / 32768f;
			}
			return array;
		}

		private static AudioSource Source(string label, AudioClip clip, Transform parent, float volume, float maxDistance)
		{
			//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)
			GameObject val = new GameObject("MHz176 " + label + " " + (Object.op_Implicit((Object)(object)clip) ? ((Object)clip).name : "?"));
			val.transform.SetParent(parent, false);
			AudioSource obj = val.AddComponent<AudioSource>();
			obj.clip = clip;
			obj.volume = volume;
			obj.spatialBlend = 1f;
			obj.rolloffMode = (AudioRolloffMode)1;
			obj.minDistance = 1.5f;
			obj.maxDistance = maxDistance;
			obj.dopplerLevel = 0f;
			obj.outputAudioMixerGroup = Mixer;
			return obj;
		}

		internal static void Play(AudioClip clip, Transform follow, float volume = 1f, float maxDistance = 15f)
		{
			if (Object.op_Implicit((Object)(object)clip))
			{
				AudioSource obj = Source("Sound", clip, follow, volume, maxDistance);
				obj.Play();
				Object.Destroy((Object)(object)((Component)obj).gameObject, clip.length + 0.2f);
			}
		}

		internal static AudioSource Loop(AudioClip clip, Transform follow, float volume = 1f, float maxDistance = 15f)
		{
			AudioSource val = Source("Loop", clip, follow, volume, maxDistance);
			val.loop = true;
			if (Object.op_Implicit((Object)(object)clip))
			{
				val.time = Random.Range(0f, clip.length);
				val.Play();
			}
			return val;
		}

		internal static Material MakeMaterial(Material baseMat, string name, Texture2D albedo, float smoothness = 0.15f)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_00e3: 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)
			Material val = (Object.op_Implicit((Object)(object)baseMat) ? new Material(baseMat) : new Material(Shader.Find("Standard")));
			((Object)val).name = name;
			string[] array = new string[4] { "_BaseTexture", "_MainTex", "_BaseMap", "_AlbedoTexture" };
			foreach (string text in array)
			{
				if (val.HasProperty(text))
				{
					val.SetTexture(text, (Texture)(object)albedo);
				}
			}
			array = new string[2] { "_NormalTexture", "_BumpMap" };
			foreach (string text2 in array)
			{
				if (val.HasProperty(text2))
				{
					val.SetTexture(text2, (Texture)null);
				}
			}
			array = new string[3] { "_BaseColor", "_Color", "_AlbedoColor" };
			foreach (string text3 in array)
			{
				if (val.HasProperty(text3))
				{
					val.SetColor(text3, Color.white);
				}
			}
			array = new string[4] { "_MetallicTexture", "_SmoothnessTexture", "_MetallicGlossMap", "_SpecGlossMap" };
			foreach (string text4 in array)
			{
				if (val.HasProperty(text4))
				{
					val.SetTexture(text4, (Texture)null);
				}
			}
			val.DisableKeyword("_METALLICGLOSSMAP");
			val.DisableKeyword("_SPECGLOSSMAP");
			val.DisableKeyword("_NORMALMAP");
			if (val.HasProperty("_SmoothnessTextureChannel"))
			{
				val.SetFloat("_SmoothnessTextureChannel", 0f);
			}
			if (val.HasProperty("_GlossMapScale"))
			{
				val.SetFloat("_GlossMapScale", 1f);
			}
			if (val.HasProperty("_Metallic"))
			{
				val.SetFloat("_Metallic", 0f);
			}
			array = new string[2] { "_Smoothness", "_Glossiness" };
			foreach (string text5 in array)
			{
				if (val.HasProperty(text5))
				{
					val.SetFloat(text5, smoothness);
				}
			}
			if (val.HasProperty("_EmissionColor"))
			{
				val.SetColor("_EmissionColor", Color.black);
			}
			if (val.HasProperty("_EmissionTexture"))
			{
				val.SetTexture("_EmissionTexture", (Texture)null);
			}
			if (val.HasProperty("_TilingX"))
			{
				val.SetFloat("_TilingX", 1f);
				val.SetFloat("_TilingY", 1f);
			}
			if (val.HasProperty("_OffsetX"))
			{
				val.SetFloat("_OffsetX", 0f);
				val.SetFloat("_OffsetY", 0f);
			}
			return val;
		}
	}
	internal static class Builder
	{
		public const string PrefabName = "Enemy - 1.76 MHz";

		public static EnemySetup Setup;

		private static bool tried;

		internal const float Radius = 0.65f;

		internal const float Hover = 1.5f;

		internal static readonly Color[] Glitch = (Color[])(object)new Color[6]
		{
			new Color(0.95f, 0.2f, 0.18f),
			new Color(0.25f, 0.9f, 0.45f),
			new Color(0.3f, 0.4f, 1f),
			new Color(0.9f, 0.3f, 0.85f),
			new Color(0.3f, 0.9f, 0.95f),
			new Color(0.9f, 0.9f, 0.9f)
		};

		public static void BuildAndRegister(EnemyDirector director)
		{
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Expected O, but got Unknown
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Expected O, but got Unknown
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Expected O, but got Unknown
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0328: Expected O, but got Unknown
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Expected O, but got Unknown
			//IL_0336: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Expected O, but got Unknown
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			//IL_034c: Expected O, but got Unknown
			//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c3: Expected O, but got Unknown
			//IL_0447: Unknown result type (might be due to invalid IL or missing references)
			if (tried)
			{
				return;
			}
			tried = true;
			EnemySetup val = director.enemiesDifficulty1.Concat(director.enemiesDifficulty2).Concat(director.enemiesDifficulty3).FirstOrDefault((Func<EnemySetup, bool>)((EnemySetup s) => Object.op_Implicit((Object)(object)s) && ((Object)s).name.Contains("Robe")));
			if ((Object)(object)val == (Object)null)
			{
				throw new Exception("Could not find REPO's Robe enemy to build on. The game may have been updated.");
			}
			GameObject? obj = val.spawnObjects.Select((PrefabRef r) => ((PrefabRef<GameObject>)(object)r)?.Prefab).FirstOrDefault((Func<GameObject, bool>)((GameObject p) => Object.op_Implicit((Object)(object)p) && Object.op_Implicit((Object)(object)p.GetComponent<EnemyParent>())));
			if ((Object)(object)obj == (Object)null)
			{
				throw new Exception("The Robe enemy has no prefab.");
			}
			GameObject val2 = new GameObject("1.76 MHz Prefabs");
			val2.SetActive(false);
			((Object)val2).hideFlags = (HideFlags)61;
			Object.DontDestroyOnLoad((Object)(object)val2);
			GameObject val3 = Object.Instantiate<GameObject>(obj, val2.transform);
			((Object)val3).name = "Enemy - 1.76 MHz";
			EnemyParent component = val3.GetComponent<EnemyParent>();
			Enemy componentInChildren = val3.GetComponentInChildren<Enemy>(true);
			EnemyRigidbody componentInChildren2 = val3.GetComponentInChildren<EnemyRigidbody>(true);
			if (!Object.op_Implicit((Object)(object)componentInChildren) || !Object.op_Implicit((Object)(object)componentInChildren2))
			{
				throw new Exception("The Robe prefab is missing its Enemy or EnemyRigidbody.");
			}
			Material baseMat = (from r in val3.GetComponentsInChildren<Renderer>(true)
				where !(r is ParticleSystemRenderer)
				select r.sharedMaterial).FirstOrDefault((Func<Material, bool>)((Material m) => Object.op_Implicit((Object)(object)m)));
			MonoBehaviour[] componentsInChildren = val3.GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val4 in componentsInChildren)
			{
				if (Object.op_Implicit((Object)(object)val4) && ((object)val4).GetType().Name.StartsWith("EnemyRobe"))
				{
					Object.DestroyImmediate((Object)(object)val4);
				}
			}
			Animator[] componentsInChildren2 = val3.GetComponentsInChildren<Animator>(true);
			for (int num = 0; num < componentsInChildren2.Length; num++)
			{
				((Behaviour)componentsInChildren2[num]).enabled = false;
			}
			Renderer[] componentsInChildren3 = val3.GetComponentsInChildren<Renderer>(true);
			for (int num = 0; num < componentsInChildren3.Length; num++)
			{
				componentsInChildren3[num].enabled = false;
			}
			Light[] componentsInChildren4 = val3.GetComponentsInChildren<Light>(true);
			for (int num = 0; num < componentsInChildren4.Length; num++)
			{
				((Behaviour)componentsInChildren4[num]).enabled = false;
			}
			AudioSource[] componentsInChildren5 = val3.GetComponentsInChildren<AudioSource>(true);
			for (int num = 0; num < componentsInChildren5.Length; num++)
			{
				componentsInChildren5[num].playOnAwake = false;
			}
			EnemyStateDespawn component2 = ((Component)componentInChildren).GetComponent<EnemyStateDespawn>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				component2.StuckDespawn = false;
				component2.ChaseDespawn = false;
			}
			EnemyStateSpawn component3 = ((Component)componentInChildren).GetComponent<EnemyStateSpawn>();
			if (Object.op_Implicit((Object)(object)component3))
			{
				component3.OnSpawn = new UnityEvent();
			}
			EnemyVision component4 = ((Component)componentInChildren).GetComponent<EnemyVision>();
			if (Object.op_Implicit((Object)(object)component4))
			{
				component4.onVisionTriggered = new UnityEvent();
			}
			EnemyStateInvestigate component5 = ((Component)componentInChildren).GetComponent<EnemyStateInvestigate>();
			if (Object.op_Implicit((Object)(object)component5))
			{
				component5.onInvestigateTriggered = new UnityEvent();
			}
			EnemyHealth component6 = ((Component)componentInChildren).GetComponent<EnemyHealth>();
			if (Object.op_Implicit((Object)(object)component6))
			{
				component6.onHurt = new UnityEvent();
				component6.onDeathStart = new UnityEvent();
				component6.onDeath = new UnityEvent();
				component6.onObjectHurt = new UnityEvent();
				component6.health = Plugin.Health.Value;
				component6.impactHurt = true;
				component6.impactLightDamage = 0;
				component6.impactMediumDamage = 5;
				component6.impactHeavyDamage = 20;
			}
			FieldInfo[] fields = typeof(EnemyRigidbody).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (FieldInfo fieldInfo in fields)
			{
				if (fieldInfo.FieldType == typeof(UnityEvent))
				{
					fieldInfo.SetValue(componentInChildren2, (object?)new UnityEvent());
				}
			}
			RebuildBody(componentInChildren2);
			ParticleSystem[] parts;
			GameObject val5 = BuildModel(baseMat, ((Component)componentInChildren2).transform, out parts);
			if (Object.op_Implicit((Object)(object)component6))
			{
				component6.meshParent = val5.transform;
			}
			MhzAI mhzAI = ((Component)componentInChildren).gameObject.AddComponent<MhzAI>();
			mhzAI.model = val5.transform;
			mhzAI.parts = parts;
			component.enemyName = "1.76 MHz";
			component.enemyNameLocalized = null;
			component.difficulty = (Difficulty)(Mathf.Clamp(Plugin.Difficulty.Value, 1, 3) - 1);
			component.SpawnedTimeMin = 99999f;
			component.SpawnedTimeMax = 99999f;
			component.DespawnedTimeMin = 99999f;
			component.DespawnedTimeMax = 99999f;
			Setup = Object.Instantiate<EnemySetup>(val);
			((Object)Setup).name = "Enemy - 1.76 MHz";
			RarityPreset val6 = ScriptableObject.CreateInstance<RarityPreset>();
			((Object)val6).name = "Rarity - 1.76 MHz";
			val6.chance = Plugin.Rarity.Value;
			Setup.rarityPreset = val6;
			Object.DontDestroyOnLoad((Object)(object)Setup);
			Object.DontDestroyOnLoad((Object)(object)val6);
			EnemyContent val7 = ScriptableObject.CreateInstance<EnemyContent>();
			AccessTools.Field(typeof(EnemyContent), "_setup").SetValue(val7, Setup);
			AccessTools.Field(typeof(EnemyContent), "_spawnObjects").SetValue(val7, new List<GameObject> { val3 });
			Enemies.RegisterEnemy(val7);
			Plugin.Log.LogInfo((object)$"Registered 1.76 MHz (difficulty tier {Plugin.Difficulty.Value}).");
		}

		private static void RebuildBody(EnemyRigidbody erb)
		{
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)erb).transform;
			int num = -1;
			Collider[] componentsInChildren = ((Component)transform).GetComponentsInChildren<Collider>(true);
			foreach (Collider val in componentsInChildren)
			{
				if (val.isTrigger || (Object)(object)val == (Object)(object)erb.playerCollision || !((Component)val).CompareTag("Phys Grab Object"))
				{
					continue;
				}
				if (num < 0)
				{
					num = ((Component)val).gameObject.layer;
				}
				GameObject gameObject = ((Component)val).gameObject;
				Object.DestroyImmediate((Object)(object)val);
				if (!Object.op_Implicit((Object)(object)gameObject.GetComponent<Collider>()))
				{
					PhysGrabObjectCollider component = gameObject.GetComponent<PhysGrabObjectCollider>();
					if (Object.op_Implicit((Object)(object)component))
					{
						Object.DestroyImmediate((Object)(object)component);
					}
				}
			}
			if (num < 0)
			{
				num = LayerMask.NameToLayer("PhysGrabObject");
			}
			GameObject val2 = new GameObject("1.76 MHz Body")
			{
				layer = num,
				tag = "Phys Grab Object"
			};
			val2.transform.SetParent(transform, false);
			val2.AddComponent<SphereCollider>().radius = 0.65f;
			val2.AddComponent<PhysGrabObjectCollider>();
			erb.gravity = false;
			erb.stunFromFall = false;
			erb.grabStun = false;
			erb.grabTimeMax = 60f;
			Transform val3 = (Object.op_Implicit((Object)(object)erb.enemy) ? ((Component)erb.enemy).transform : null);
			if (Object.op_Implicit((Object)(object)erb.followTarget) && Object.op_Implicit((Object)(object)val3) && erb.followTarget.IsChildOf(val3))
			{
				erb.followTarget.position = val3.position + Vector3.up * 1.5f;
			}
			Rigidbody component2 = ((Component)transform).GetComponent<Rigidbody>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				component2.linearDamping = 4f;
				component2.centerOfMass = Vector3.zero;
			}
		}

		private static GameObject BuildModel(Material baseMat, Transform body, out ParticleSystem[] parts)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			int layer = ((Component)body).gameObject.layer;
			GameObject val = new GameObject("1.76 MHz Model")
			{
				layer = layer
			};
			val.transform.SetParent(body, false);
			parts = (ParticleSystem[])(object)new ParticleSystem[4]
			{
				Particles(val.transform, "Static", "mhz_static0", 30f, 0.25f, 0.6f, 0.1f, 0.24f, 0.65f, line: false, layer, grey: true),
				Particles(val.transform, "Pixels", "mhz_fleck", 45f, 0.12f, 0.4f, 0.03f, 0.09f, 0.68249995f, line: false, layer, grey: false),
				Particles(val.transform, "Lines", "mhz_line", 10f, 0.06f, 0.18f, 0.3f, 0.8f, 0.585f, line: true, layer, grey: false),
				Particles(val.transform, "Core", "mhz_static2", 30f, 0.15f, 0.35f, 0.22f, 0.42f, 0.19500001f, line: false, layer, grey: true)
			};
			MainModule main = parts[3].main;
			((MainModule)(ref main)).startColor = new MinMaxGradient(new Color(1f, 1f, 1f, 0.95f), new Color(0.8f, 0.82f, 0.9f, 0.85f));
			return val;
		}

		internal static ParticleSystem Particles(Transform parent, string name, string tex, float rate, float lifeMin, float lifeMax, float sizeMin, float sizeMax, float radius, bool line, int layer, bool grey)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Expected O, but got Unknown
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: 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_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: 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_01e5: 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_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Expected O, but got Unknown
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: 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_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name)
			{
				layer = layer
			};
			val.transform.SetParent(parent, false);
			ParticleSystem val2 = val.AddComponent<ParticleSystem>();
			val2.Stop(true, (ParticleSystemStopBehavior)0);
			MainModule main = val2.main;
			((MainModule)(ref main)).loop = true;
			((MainModule)(ref main)).playOnAwake = true;
			((MainModule)(ref main)).maxParticles = 400;
			((MainModule)(ref main)).startLifetime = new MinMaxCurve(lifeMin, lifeMax);
			((MainModule)(ref main)).startSpeed = new MinMaxCurve(0f, 0.08f);
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)0;
			if (line)
			{
				((MainModule)(ref main)).startSize3D = true;
				((MainModule)(ref main)).startSizeX = new MinMaxCurve(sizeMin, sizeMax);
				((MainModule)(ref main)).startSizeY = new MinMaxCurve(0.03f, 0.06f);
				((MainModule)(ref main)).startSizeZ = MinMaxCurve.op_Implicit(1f);
			}
			else
			{
				((MainModule)(ref main)).startSize = new MinMaxCurve(sizeMin, sizeMax);
			}
			if (grey)
			{
				((MainModule)(ref main)).startColor = new MinMaxGradient(new Color(0.75f, 0.75f, 0.8f, 0.55f), new Color(0.45f, 0.45f, 0.5f, 0.35f));
			}
			else
			{
				Gradient val3 = new Gradient
				{
					mode = (GradientMode)1
				};
				GradientColorKey[] array = (GradientColorKey[])(object)new GradientColorKey[Glitch.Length];
				for (int i = 0; i < Glitch.Length; i++)
				{
					array[i] = new GradientColorKey(Glitch[i], ((float)i + 1f) / (float)Glitch.Length);
				}
				val3.SetKeys(array, (GradientAlphaKey[])(object)new GradientAlphaKey[2]
				{
					new GradientAlphaKey(1f, 0f),
					new GradientAlphaKey(1f, 1f)
				});
				MinMaxGradient startColor = default(MinMaxGradient);
				((MinMaxGradient)(ref startColor))..ctor(val3);
				((MinMaxGradient)(ref startColor)).mode = (ParticleSystemGradientMode)4;
				((MainModule)(ref main)).startColor = startColor;
			}
			EmissionModule emission = val2.emission;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(rate);
			ShapeModule shape = val2.shape;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
			((ShapeModule)(ref shape)).radius = radius;
			((ShapeModule)(ref shape)).radiusThickness = 1f;
			ColorOverLifetimeModule colorOverLifetime = val2.colorOverLifetime;
			((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
			Gradient val4 = new Gradient();
			val4.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
			{
				new GradientColorKey(Color.white, 0f),
				new GradientColorKey(Color.white, 1f)
			}, (GradientAlphaKey[])(object)new GradientAlphaKey[5]
			{
				new GradientAlphaKey(0f, 0f),
				new GradientAlphaKey(1f, 0.1f),
				new GradientAlphaKey(0.2f, 0.4f),
				new GradientAlphaKey(1f, 0.6f),
				new GradientAlphaKey(0f, 1f)
			});
			((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(val4);
			ParticleSystemRenderer component = val.GetComponent<ParticleSystemRenderer>();
			((Renderer)component).sharedMaterial = Fx.Mat(tex);
			component.renderMode = (ParticleSystemRenderMode)0;
			((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
			val2.Play();
			return val2;
		}
	}
	internal static class Fx
	{
		private static readonly Dictionary<string, Material> mats = new Dictionary<string, Material>();

		private static readonly string[] TexProps = new string[4] { "_MainTex", "_BaseMap", "_BaseTexture", "_AlbedoTexture" };

		private static Material template;

		private static bool templateTried;

		private static Material Template
		{
			get
			{
				if (templateTried)
				{
					return template;
				}
				templateTried = true;
				List<Material> list = new List<Material>();
				string[] array = new string[4] { "Items/Item Gun Laser", "Items/Item Gun Handgun", "Items/Item Gun Shotgun", "Items/Item Melee Stun Baton" };
				for (int i = 0; i < array.Length; i++)
				{
					GameObject val = Resources.Load<GameObject>(array[i]);
					if (!Object.op_Implicit((Object)(object)val))
					{
						continue;
					}
					ItemGun component = val.GetComponent<ItemGun>();
					List<GameObject> list2 = new List<GameObject> { val };
					if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.muzzleFlashPrefab))
					{
						list2.Add(component.muzzleFlashPrefab);
					}
					if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.bulletPrefab))
					{
						list2.Add(component.bulletPrefab);
					}
					foreach (GameObject item in list2)
					{
						ParticleSystemRenderer[] componentsInChildren = item.GetComponentsInChildren<ParticleSystemRenderer>(true);
						for (int j = 0; j < componentsInChildren.Length; j++)
						{
							Material sharedMaterial = ((Renderer)componentsInChildren[j]).sharedMaterial;
							if (Object.op_Implicit((Object)(object)sharedMaterial) && Object.op_Implicit((Object)(object)sharedMaterial.shader) && sharedMaterial.shader.isSupported && HasTex(sharedMaterial) && !list.Contains(sharedMaterial))
							{
								list.Add(sharedMaterial);
							}
						}
					}
				}
				if (list.Count == 0)
				{
					Plugin.Log.LogWarning((object)"No REPO particle material found, building one.");
					return null;
				}
				list.Sort((Material a, Material b) => Score(b).CompareTo(Score(a)));
				template = list[0];
				Plugin.Log.LogDebug((object)("Effects draw with REPO's \"" + ((Object)template).name + "\" (shader " + ((Object)template.shader).name + ")."));
				return template;
				static int Score(Material m)
				{
					int num = 0;
					if (((Object)m.shader).name.Contains("Unlit"))
					{
						num += 4;
					}
					if (m.HasProperty("_DstBlend") && Mathf.Approximately(m.GetFloat("_DstBlend"), 1f))
					{
						num += 2;
					}
					if (((Object)m.shader).name.Contains("Surface"))
					{
						num -= 4;
					}
					return num;
				}
			}
		}

		private static bool HasTex(Material m)
		{
			string[] texProps = TexProps;
			foreach (string text in texProps)
			{
				if (m.HasProperty(text))
				{
					return true;
				}
			}
			return false;
		}

		internal static Material Mat(string tex)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Expected O, but got Unknown
			//IL_0072: 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_00a5: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: 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_02a3: Unknown result type (might be due to invalid IL or missing references)
			if (mats.TryGetValue(tex, out var value) && Object.op_Implicit((Object)(object)value))
			{
				return value;
			}
			Texture2D val = Assets.LoadPalette(tex);
			if (Object.op_Implicit((Object)(object)Template))
			{
				value = new Material(Template)
				{
					name = "1.76 MHz FX " + tex
				};
				string[] texProps = TexProps;
				foreach (string text in texProps)
				{
					if (value.HasProperty(text))
					{
						value.SetTexture(text, (Texture)(object)val);
						value.SetTextureScale(text, Vector2.one);
						value.SetTextureOffset(text, Vector2.zero);
					}
				}
				Shader shader = value.shader;
				for (int j = 0; j < shader.GetPropertyCount(); j++)
				{
					if ((int)shader.GetPropertyType(j) == 0)
					{
						string propertyName = shader.GetPropertyName(j);
						if (!propertyName.Contains("Emission"))
						{
							Color color = value.GetColor(propertyName);
							float num = Mathf.Max(color.r, Mathf.Max(color.g, color.b));
							value.SetColor(propertyName, new Color(num, num, num, color.a));
						}
					}
				}
				if (value.HasProperty("_TilingX"))
				{
					value.SetFloat("_TilingX", 1f);
					value.SetFloat("_TilingY", 1f);
				}
				if (value.HasProperty("_OffsetX"))
				{
					value.SetFloat("_OffsetX", 0f);
					value.SetFloat("_OffsetY", 0f);
				}
				if (value.HasProperty("_EmissionColor"))
				{
					value.SetColor("_EmissionColor", Color.black);
				}
				if (value.HasProperty("_EmissionMap"))
				{
					value.SetTexture("_EmissionMap", (Texture)null);
				}
				value.DisableKeyword("_EMISSION");
				if (value.HasProperty("_Mode"))
				{
					value.SetFloat("_Mode", 2f);
				}
				if (value.HasProperty("_SrcBlend"))
				{
					value.SetFloat("_SrcBlend", 5f);
				}
				if (value.HasProperty("_DstBlend"))
				{
					value.SetFloat("_DstBlend", 10f);
				}
				value.EnableKeyword("_ALPHABLEND_ON");
				value.DisableKeyword("_ALPHAPREMULTIPLY_ON");
				if (value.HasProperty("_ColorMode"))
				{
					value.SetFloat("_ColorMode", 0f);
				}
				value.DisableKeyword("_COLOROVERLAY_ON");
				value.DisableKeyword("_COLORCOLOR_ON");
				value.DisableKeyword("_COLORADDSUBDIFF_ON");
				if (value.HasProperty("_Color"))
				{
					value.SetColor("_Color", Color.white);
				}
				if (value.HasProperty("_TintColor"))
				{
					value.SetColor("_TintColor", new Color(0.5f, 0.5f, 0.5f, 0.5f));
				}
				value.renderQueue = 3100;
				return mats[tex] = value;
			}
			value = new Material(Shader.Find("Particles/Standard Unlit") ?? Shader.Find("Sprites/Default"))
			{
				name = "1.76 MHz FX " + tex,
				mainTexture = (Texture)(object)val
			};
			if (value.HasProperty("_Mode"))
			{
				value.SetFloat("_Mode", 2f);
				value.SetFloat("_SrcBlend", 5f);
				value.SetFloat("_DstBlend", 10f);
				value.SetFloat("_ZWrite", 0f);
				value.EnableKeyword("_ALPHABLEND_ON");
				value.SetOverrideTag("RenderType", "Transparent");
			}
			value.renderQueue = 3100;
			return mats[tex] = value;
		}
	}
	public class MhzAI : MonoBehaviour
	{
		private class Screen : MonoBehaviour
		{
			private static Screen instance;

			private static readonly HashSet<MhzAI> by = new HashSet<MhzAI>();

			private static Texture2D[] frames;

			private AudioSource hiss;

			private float strength;

			private float nextFrame;

			private int f;

			internal static void Set(MhzAI m, bool on)
			{
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_0039: Expected O, but got Unknown
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				if (on)
				{
					by.Add(m);
				}
				else
				{
					by.Remove(m);
				}
				if (!Object.op_Implicit((Object)(object)instance))
				{
					GameObject val = new GameObject("MHz176 Screen");
					Object.DontDestroyOnLoad((Object)val);
					((Object)val).hideFlags = (HideFlags)61;
					instance = val.AddComponent<Screen>();
				}
			}

			internal static void Remove(MhzAI m)
			{
				by.Remove(m);
			}

			private void Update()
			{
				by.RemoveWhere((MhzAI m) => !Object.op_Implicit((Object)(object)m));
				bool flag = by.Count > 0;
				strength = Mathf.MoveTowards(strength, flag ? 1f : 0f, Time.deltaTime * 1.5f);
				if (flag && !Object.op_Implicit((Object)(object)hiss) && Object.op_Implicit((Object)(object)PlayerAvatar.instance))
				{
					hiss = Assets.Loop(Assets.LoadSound("mhz_static"), ((Component)PlayerAvatar.instance).transform, 0f, 5f);
				}
				if (Object.op_Implicit((Object)(object)hiss))
				{
					hiss.volume = 0.35f * strength * Plugin.Volume.Value;
					if (strength <= 0f)
					{
						Object.Destroy((Object)(object)((Component)hiss).gameObject);
						hiss = null;
					}
				}
			}

			private void OnGUI()
			{
				//IL_0092: 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_00e7: 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)
				if (strength <= 0.01f || Plugin.ScreenStatic.Value <= 0f)
				{
					return;
				}
				if (frames == null)
				{
					frames = (Texture2D[])(object)new Texture2D[4];
					for (int i = 0; i < 4; i++)
					{
						frames[i] = Assets.LoadTexture("mhz_screen" + i);
						((Texture)frames[i]).wrapMode = (TextureWrapMode)0;
					}
				}
				if (Time.time >= nextFrame)
				{
					nextFrame = Time.time + 0.06f;
					f = Random.Range(0, 4);
				}
				Color color = GUI.color;
				GUI.color = new Color(1f, 1f, 1f, strength * Plugin.ScreenStatic.Value * Random.Range(0.6f, 1f));
				GUI.DrawTextureWithTexCoords(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), (Texture)(object)frames[f], new Rect(Random.value, Random.value, 3f, 3f * (float)Screen.height / (float)Screen.width));
				GUI.color = color;
			}
		}

		[SerializeField]
		internal Transform model;

		[SerializeField]
		internal ParticleSystem[] parts;

		private static readonly float[] Rates = new float[4] { 30f, 45f, 10f, 30f };

		private static readonly float[] AwakeMore = new float[4] { 1.3f, 3f, 3f, 1f };

		private Light glow;

		private const float AwakeSize = 1.8f;

		private float grow = 1f;

		private float[] baseRadius;

		private MinMaxCurve[] baseSize;

		private Enemy enemy;

		private PhotonView view;

		private bool awake;

		private int spread;

		private Vector3 center;

		private readonly HashSet<Module> rooms = new HashSet<Module>();

		private AudioSource broadcast;

		private float awakeSince;

		private float nextFlicker;

		private float nextMurmur;

		private int murmurs;

		private int frame;

		private float wakeAt;

		private float nextSpread;

		private float holding;

		private bool triggered;

		private readonly Dictionary<Module, GameObject> shells = new Dictionary<Module, GameObject>();

		private readonly Dictionary<Module, Vector3> roomMid = new Dictionary<Module, Vector3>();

		private const float Inset = 0.15f;

		private const float Tile = 3f;

		private static Material noiseMat;

		private static float nextNoise;

		private float hurtTimer;

		private Vector3 At
		{
			get
			{
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				if (!Object.op_Implicit((Object)(object)model))
				{
					return ((Component)this).transform.position;
				}
				return model.position;
			}
		}

		private static Material NoiseMat
		{
			get
			{
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_004a: Expected O, but got Unknown
				if (Object.op_Implicit((Object)(object)noiseMat))
				{
					return noiseMat;
				}
				Texture2D val = Assets.LoadTexture("mhz_noise");
				((Texture)val).wrapMode = (TextureWrapMode)0;
				noiseMat = new Material(Fx.Mat("mhz_fleck"))
				{
					name = "1.76 MHz Room Noise",
					mainTexture = (Texture)(object)val
				};
				string[] array = new string[2] { "_MainTex", "_BaseMap" };
				foreach (string text in array)
				{
					if (noiseMat.HasProperty(text))
					{
						noiseMat.SetTexture(text, (Texture)(object)val);
					}
				}
				return noiseMat;
			}
		}

		private void Awake()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			enemy = ((Component)this).GetComponent<Enemy>();
			view = ((Component)this).GetComponent<PhotonView>();
			EnemyStateSpawn component = ((Component)this).GetComponent<EnemyStateSpawn>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.OnSpawn.AddListener(new UnityAction(OnSpawn));
			}
			EnemyHealth component2 = ((Component)this).GetComponent<EnemyHealth>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				component2.onDeath.AddListener(new UnityAction(OnDeath));
				component2.onHurt.AddListener(new UnityAction(OnHurt));
			}
		}

		private void OnEnable()
		{
			if (Object.op_Implicit((Object)(object)view))
			{
				view.RefreshRpcMonoBehaviourCache();
			}
			Quiet();
			triggered = false;
			wakeAt = Time.time + Random.Range(Plugin.WakeMin.Value, Plugin.WakeMax.Value);
			nextMurmur = Time.time + 30f;
		}

		private void OnDisable()
		{
			Quiet();
			Screen.Remove(this);
		}

		public void OnSpawn()
		{
			if (SemiFunc.IsMasterClientOrSingleplayer())
			{
				SemiFunc.EnemySpawn(enemy);
				wakeAt = Time.time + Random.Range(Plugin.WakeMin.Value, Plugin.WakeMax.Value);
			}
		}

		public void OnHurt()
		{
			if (SemiFunc.IsMasterClientOrSingleplayer() && !awake)
			{
				Wake();
			}
		}

		public void OnDeath()
		{
			Send("Mhz_CalmRPC", (RpcTarget)0);
			if (SemiFunc.IsMasterClientOrSingleplayer() && Object.op_Implicit((Object)(object)enemy.EnemyParent))
			{
				enemy.EnemyParent.Despawn();
			}
		}

		private void Update()
		{
			if (SemiFunc.IsMasterClientOrSingleplayer())
			{
				Host();
			}
			Local();
			Visuals();
			FlickerNoise();
		}

		private void Host()
		{
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			if (!SemiFunc.RunIsLevel() || !Object.op_Implicit((Object)(object)LevelGenerator.Instance) || !LevelGenerator.Instance.Generated)
			{
				return;
			}
			float time = Time.time;
			if (!triggered && Halfway())
			{
				triggered = true;
				RoundDirector instance = RoundDirector.instance;
				if (Object.op_Implicit((Object)(object)instance) && instance.extractionPoints == 1)
				{
					wakeAt = time + Plugin.SingleDelay.Value;
				}
				else if (!awake)
				{
					Wake();
				}
			}
			if (triggered && !awake && time >= wakeAt)
			{
				Wake();
			}
			if (awake && time >= nextSpread)
			{
				nextSpread = time + Plugin.SpreadSeconds.Value;
				Send("Mhz_SpreadRPC", (RpcTarget)0, spread + 1, center);
			}
			PhysGrabObject val = ((Object.op_Implicit((Object)(object)enemy) && Object.op_Implicit((Object)(object)enemy.Rigidbody)) ? enemy.Rigidbody.physGrabObject : null);
			bool flag = Object.op_Implicit((Object)(object)val) && val.playerGrabbing.Count > 0;
			holding = (flag ? (holding + Time.deltaTime) : 0f);
			if (awake && holding >= Plugin.AppeaseSeconds.Value)
			{
				holding = 0f;
				Plugin.Log.LogInfo((object)"1.76 MHz: calmed.");
				Send("Mhz_CalmRPC", (RpcTarget)0);
				wakeAt = time + Random.Range(Plugin.WakeMin.Value, Plugin.WakeMax.Value);
			}
		}

		private static bool Halfway()
		{
			RoundDirector instance = RoundDirector.instance;
			if (Object.op_Implicit((Object)(object)instance) && instance.extractionPoints > 0)
			{
				return instance.extractionPointsCompleted >= instance.extractionPoints / 2;
			}
			return false;
		}

		private void Wake()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			Plugin.Log.LogInfo((object)"1.76 MHz: wakes.");
			nextSpread = Time.time + 1f;
			Send("Mhz_WakeRPC", (RpcTarget)0, At);
		}

		private void Send(string rpc, RpcTarget to, params object[] args)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			if (SemiFunc.IsMultiplayer() && Object.op_Implicit((Object)(object)view))
			{
				view.RPC(rpc, to, args);
			}
			else
			{
				((object)this).GetType().GetMethod(rpc).Invoke(this, args);
			}
		}

		[PunRPC]
		public void Mhz_WakeRPC(Vector3 from)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			awake = true;
			awakeSince = Time.time;
			spread = 0;
			center = from;
			rooms.Clear();
			if (!Object.op_Implicit((Object)(object)broadcast))
			{
				broadcast = Assets.Loop(Assets.LoadSound("mhz_active"), Object.op_Implicit((Object)(object)model) ? model : ((Component)this).transform, 0.15f * Plugin.Volume.Value, 12f);
			}
		}

		[PunRPC]
		public void Mhz_SpreadRPC(int n, Vector3 from)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			if (!awake)
			{
				Mhz_WakeRPC(from);
			}
			spread = n;
			center = from;
			Rooms();
		}

		[PunRPC]
		public void Mhz_CalmRPC()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			bool num = awake;
			Quiet();
			PlayerAvatar instance = PlayerAvatar.instance;
			if (num && Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)model) && Vector3.Distance(((Component)instance).transform.position, model.position) < 8f)
			{
				Tell.Local("The voice falls silent.");
			}
		}

		private void Quiet()
		{
			awake = false;
			spread = 0;
			rooms.Clear();
			Shells();
			if (Object.op_Implicit((Object)(object)broadcast))
			{
				Object.Destroy((Object)(object)((Component)broadcast).gameObject);
				broadcast = null;
			}
			holding = 0f;
		}

		private void Rooms()
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: 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_00d8: 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_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			rooms.Clear();
			List<Module> list = new List<Module>();
			Dictionary<Module, Vector3> mid = roomMid;
			mid.Clear();
			HashSet<Module> home = new HashSet<Module>();
			Module[] array = Object.FindObjectsOfType<Module>();
			Bounds bounds = default(Bounds);
			foreach (Module val in array)
			{
				if (!Object.op_Implicit((Object)(object)val))
				{
					continue;
				}
				bool flag = false;
				bool flag2 = false;
				((Bounds)(ref bounds))..ctor(((Component)val).transform.position, Vector3.zero);
				RoomVolume[] componentsInChildren = ((Component)val).GetComponentsInChildren<RoomVolume>();
				foreach (RoomVolume obj in componentsInChildren)
				{
					if (obj.Truck)
					{
						flag = true;
					}
					Collider[] componentsInChildren2 = ((Component)obj).GetComponentsInChildren<Collider>();
					foreach (Collider val2 in componentsInChildren2)
					{
						if (!flag2)
						{
							bounds = val2.bounds;
							flag2 = true;
						}
						else
						{
							((Bounds)(ref bounds)).Encapsulate(val2.bounds);
						}
						Vector3 val3 = val2.ClosestPoint(center) - center;
						if (((Vector3)(ref val3)).sqrMagnitude < 0.0001f)
						{
							home.Add(val);
						}
					}
				}
				if (!flag)
				{
					list.Add(val);
					mid[val] = ((Bounds)(ref bounds)).center;
				}
			}
			list.Sort(delegate(Module a, Module b)
			{
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_004c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_0073: Unknown result type (might be due to invalid IL or missing references)
				//IL_0078: Unknown result type (might be due to invalid IL or missing references)
				//IL_0087: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a1: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
				int num2 = home.Contains(b).CompareTo(home.Contains(a));
				if (num2 != 0)
				{
					return num2;
				}
				num2 = Vector3.Distance(mid[a], center).CompareTo(Vector3.Distance(mid[b], center));
				if (num2 != 0)
				{
					return num2;
				}
				num2 = mid[a].x.CompareTo(mid[b].x);
				return (num2 == 0) ? mid[a].z.CompareTo(mid[b].z) : num2;
			});
			for (int num = 0; num < spread && num < list.Count; num++)
			{
				rooms.Add(list[num]);
			}
			Shells();
		}

		private void Shells()
		{
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Expected O, but got Unknown
			//IL_0486: Unknown result type (might be due to invalid IL or missing references)
			//IL_048b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0498: Expected O, but got Unknown
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: 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_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: 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_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: 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_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: 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_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: 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_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: 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_02ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0304: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: 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_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0320: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: 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_0355: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_035c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0391: Unknown result type (might be due to invalid IL or missing references)
			//IL_0395: Unknown result type (might be due to invalid IL or missing references)
			//IL_039f: 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_03ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_03af: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03be: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03da: Unknown result type (might be due to invalid IL or missing references)
			//IL_03df: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0444: Unknown result type (might be due to invalid IL or missing references)
			//IL_0446: Unknown result type (might be due to invalid IL or missing references)
			//IL_0448: 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_0417: Unknown result type (might be due to invalid IL or missing references)
			//IL_041c: Unknown result type (might be due to invalid IL or missing references)
			//IL_041e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0422: Unknown result type (might be due to invalid IL or missing references)
			//IL_0432: Unknown result type (might be due to invalid IL or missing references)
			//IL_0437: Unknown result type (might be due to invalid IL or missing references)
			//IL_043c: Unknown result type (might be due to invalid IL or missing references)
			foreach (GameObject value in shells.Values)
			{
				if (Object.op_Implicit((Object)(object)value))
				{
					Object.Destroy((Object)(object)value);
				}
			}
			shells.Clear();
			if (rooms.Count == 0)
			{
				return;
			}
			List<Collider> list = new List<Collider>();
			foreach (Module room in rooms)
			{
				if (!Object.op_Implicit((Object)(object)room))
				{
					continue;
				}
				RoomVolume[] componentsInChildren = ((Component)room).GetComponentsInChildren<RoomVolume>();
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					Collider[] componentsInChildren2 = ((Component)componentsInChildren[i]).GetComponentsInChildren<Collider>();
					foreach (Collider item in componentsInChildren2)
					{
						list.Add(item);
					}
				}
			}
			int num = 0;
			Vector3 val5 = default(Vector3);
			Vector3 val6 = default(Vector3);
			Vector3 val7 = default(Vector3);
			foreach (Module room2 in rooms)
			{
				if (!Object.op_Implicit((Object)(object)room2))
				{
					continue;
				}
				GameObject val = new GameObject("1.76 MHz Room Static");
				List<Vector3> list2 = new List<Vector3>();
				List<Vector2> list3 = new List<Vector2>();
				List<int> list4 = new List<int>();
				RoomVolume[] componentsInChildren = ((Component)room2).GetComponentsInChildren<RoomVolume>();
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					Collider[] componentsInChildren2 = ((Component)componentsInChildren[i]).GetComponentsInChildren<Collider>();
					foreach (Collider val2 in componentsInChildren2)
					{
						BoxCollider val3 = (BoxCollider)(object)((val2 is BoxCollider) ? val2 : null);
						Vector3 val4;
						if (val3 != null)
						{
							Transform transform = ((Component)val3).transform;
							val4 = transform.TransformPoint(val3.center);
							val5 = transform.TransformVector(new Vector3(val3.size.x * 0.5f, 0f, 0f));
							val6 = transform.TransformVector(new Vector3(0f, val3.size.y * 0.5f, 0f));
							val7 = transform.TransformVector(new Vector3(0f, 0f, val3.size.z * 0.5f));
						}
						else
						{
							Bounds bounds = val2.bounds;
							Vector3 extents = ((Bounds)(ref bounds)).extents;
							bounds = val2.bounds;
							val4 = ((Bounds)(ref bounds)).center;
							((Vector3)(ref val5))..ctor(extents.x, 0f, 0f);
							((Vector3)(ref val6))..ctor(0f, extents.y, 0f);
							((Vector3)(ref val7))..ctor(0f, 0f, extents.z);
						}
						(Vector3, Vector3, Vector3)[] array = new(Vector3, Vector3, Vector3)[5]
						{
							(val5, val7, val6),
							(-val5, val7, val6),
							(val7, val5, val6),
							(-val7, val5, val6),
							(val6, val5, val7)
						};
						for (int k = 0; k < array.Length; k++)
						{
							(Vector3, Vector3, Vector3) tuple = array[k];
							Vector3 item2 = tuple.Item1;
							Vector3 item3 = tuple.Item2;
							Vector3 item4 = tuple.Item3;
							Vector3 normalized = ((Vector3)(ref item2)).normalized;
							Vector3 val8 = val4 + item2 + normalized * 0.5f;
							bool flag = false;
							foreach (Collider item5 in list)
							{
								if (Object.op_Implicit((Object)(object)item5) && (Object)(object)item5 != (Object)(object)val2)
								{
									Vector3 val9 = item5.ClosestPoint(val8) - val8;
									if (((Vector3)(ref val9)).sqrMagnitude < 0.0001f)
									{
										flag = true;
										break;
									}
								}
							}
							if (!flag)
							{
								Vector3 u = item3 - ((Vector3)(ref item3)).normalized * 0.15f;
								Vector3 v = item4 - ((Vector3)(ref item4)).normalized * 0.15f;
								Vector3 val10 = val4 + item2 - normalized * 0.15f;
								if (item2 != val6)
								{
									float magnitude = ((Vector3)(ref item4)).magnitude;
									float num2 = magnitude - 0.15f;
									float num3 = 0f - magnitude - 0.6f;
									v = ((Vector3)(ref item4)).normalized * ((num2 - num3) * 0.5f);
									val10 += ((Vector3)(ref item4)).normalized * ((num2 + num3) * 0.5f);
								}
								AddFace(list2, list3, list4, val10, u, v);
								num++;
							}
						}
					}
				}
				Mesh val11 = new Mesh
				{
					name = "1.76 MHz Room Static"
				};
				if (list2.Count > 65000)
				{
					val11.indexFormat = (IndexFormat)1;
				}
				val11.SetVertices(list2);
				val11.SetUVs(0, list3);
				val11.SetTriangles(list4, 0);
				val11.RecalculateNormals();
				val11.RecalculateBounds();
				val.AddComponent<MeshFilter>().sharedMesh = val11;
				MeshRenderer obj = val.AddComponent<MeshRenderer>();
				((Renderer)obj).sharedMaterial = NoiseMat;
				((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
				((Renderer)obj).receiveShadows = false;
				shells[room2] = val;
			}
			Plugin.Log.LogInfo((object)$"1.76 MHz: {rooms.Count} room(s) reached, wrapped in {num} face(s) of static.");
		}

		private static void AddFace(List<Vector3> verts, List<Vector2> uvs, List<int> tris, Vector3 c, Vector3 u, Vector3 v)
		{
			//IL_0030: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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_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)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			float num = ((Vector3)(ref u)).magnitude * 2f / 3f;
			float num2 = ((Vector3)(ref v)).magnitude * 2f / 3f;
			int count = verts.Count;
			verts.Add(c - u - v);
			verts.Add(c + u - v);
			verts.Add(c + u + v);
			verts.Add(c - u + v);
			uvs.Add(new Vector2(0f, 0f));
			uvs.Add(new Vector2(num, 0f));
			uvs.Add(new Vector2(num, num2));
			uvs.Add(new Vector2(0f, num2));
			tris.AddRange(new int[12]
			{
				count,
				count + 2,
				count + 1,
				count,
				count + 3,
				count + 2,
				count,
				count + 1,
				count + 2,
				count,
				count + 2,
				count + 3
			});
		}

		private static void FlickerNoise()
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: 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_0125: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)noiseMat) || Time.time < nextNoise)
			{
				return;
			}
			nextNoise = Time.time + 0.05f;
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(Random.value, Random.value);
			Vector2 val2 = new Vector2((Random.value < 0.5f) ? 1f : (-1f), 1f) * 0.6f;
			string[] array = new string[2] { "_MainTex", "_BaseMap" };
			foreach (string text in array)
			{
				if (noiseMat.HasProperty(text))
				{
					noiseMat.SetTextureOffset(text, val);
					noiseMat.SetTextureScale(text, val2);
				}
			}
			Color val3 = default(Color);
			((Color)(ref val3))..ctor(1f, 1f, 1f, Random.Range(0.3f, 0.55f));
			if (noiseMat.HasProperty("_Color"))
			{
				noiseMat.SetColor("_Color", val3);
			}
			if (noiseMat.HasProperty("_TintColor"))
			{
				noiseMat.SetColor("_TintColor", val3 * 0.5f);
			}
		}

		private void OnDestroy()
		{
			foreach (GameObject value in shells.Values)
			{
				if (Object.op_Implicit((Object)(object)value))
				{
					Object.Destroy((Object)(object)value);
				}
			}
			shells.Clear();
		}

		private bool InStatic(PlayerAvatar p)
		{
			if (!Object.op_Implicit((Object)(object)p) || !Object.op_Implicit((Object)(object)p.RoomVolumeCheck) || rooms.Count == 0)
			{
				return false;
			}
			foreach (RoomVolume currentRoom in p.RoomVolumeCheck.CurrentRooms)
			{
				if (Object.op_Implicit((Object)(object)currentRoom) && Object.op_Implicit((Object)(object)currentRoom.Module) && rooms.Contains(currentRoom.Module))
				{
					return true;
				}
			}
			return false;
		}

		private void Local()
		{
			Tell.Tick();
			PlayerAvatar instance = PlayerAvatar.instance;
			bool flag = awake && Object.op_Implicit((Object)(object)instance) && !instance.deadSet && !instance.isDisabled && SemiFunc.RunIsLevel() && InStatic(instance);
			Screen.Set(this, flag);
			if (flag)
			{
				hurtTimer += Time.deltaTime;
				if (hurtTimer >= Plugin.DamageSeconds.Value)
				{
					hurtTimer = 0f;
					if (Plugin.Damage.Value > 0 && Object.op_Implicit((Object)(object)instance.playerHealth))
					{
						instance.playerHealth.Hurt(Plugin.Damage.Value, false, -1, false);
					}
				}
			}
			else
			{
				hurtTimer = 0f;
			}
			PhysGrabObject val = ((Object.op_Implicit((Object)(object)enemy) && Object.op_Implicit((Object)(object)enemy.Rigidbody)) ? enemy.Rigidbody.physGrabObject : null);
			if (awake && Object.op_Implicit((Object)(object)val) && val.grabbedLocal && Object.op_Implicit((Object)(object)ItemInfoUI.instance) && Tell.ShowingNow == null)
			{
				ItemInfoUI.instance.ItemInfoText((ItemAttributes)null, "Hold on to it...", false);
			}
			if (!awake && Time.time >= nextMurmur && Object.op_Implicit((Object)(object)model))
			{
				nextMurmur = Time.time + 30f;
				murmurs++;
				Assets.Play(Assets.LoadSound("mhz_default"), model, 0.6f * Plugin.Volume.Value, 12f);
				if (murmurs % 3 == 0)
				{
					Assets.Play(Assets.LoadSound("mhz_default2"), model, 0.6f * Plugin.Volume.Value, 14f);
				}
			}
		}

		private void Visuals()
		{
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: 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_0316: 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_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0351: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: 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_0263: 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_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: 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_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)broadcast))
			{
				float num = Time.time - awakeSince;
				broadcast.volume = Mathf.Min(1f, 0.1f + 0.015f * num) * Plugin.Volume.Value;
				broadcast.maxDistance = Mathf.Min(80f, 12f + num);
			}
			if (parts == null || parts.Length == 0 || !(Time.time >= nextFlicker))
			{
				return;
			}
			nextFlicker = Time.time + (awake ? 0.05f : 0.1f);
			frame = (frame + 1 + Random.Range(0, 2)) % 4;
			ParticleSystemRenderer val = (Object.op_Implicit((Object)(object)parts[0]) ? ((Component)parts[0]).GetComponent<ParticleSystemRenderer>() : null);
			if (Object.op_Implicit((Object)(object)val))
			{
				((Renderer)val).sharedMaterial = Fx.Mat("mhz_static" + frame);
			}
			grow = Mathf.MoveTowards(grow, awake ? 1.8f : 1f, 0.05f);
			if (baseRadius == null)
			{
				baseRadius = new float[parts.Length];
				baseSize = (MinMaxCurve[])(object)new MinMaxCurve[parts.Length];
				for (int i = 0; i < parts.Length; i++)
				{
					if (Object.op_Implicit((Object)(object)parts[i]))
					{
						float[] array = baseRadius;
						int num2 = i;
						ShapeModule shape = parts[i].shape;
						array[num2] = ((ShapeModule)(ref shape)).radius;
						MainModule main = parts[i].main;
						baseSize[i] = (((MainModule)(ref main)).startSize3D ? ((MainModule)(ref main)).startSizeX : ((MainModule)(ref main)).startSize);
					}
				}
			}
			MinMaxCurve val3 = default(MinMaxCurve);
			for (int j = 0; j < parts.Length && j < Rates.Length; j++)
			{
				if (Object.op_Implicit((Object)(object)parts[j]))
				{
					EmissionModule emission = parts[j].emission;
					((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(Rates[j] * (awake ? AwakeMore[j] : 1f) * grow * 1.5f * ((Random.value < 0.15f) ? 0.2f : 1f));
					ShapeModule shape2 = parts[j].shape;
					((ShapeModule)(ref shape2)).radius = baseRadius[j] * grow;
					MainModule main2 = parts[j].main;
					MinMaxCurve val2 = baseSize[j];
					((MinMaxCurve)(ref val3))..ctor(((MinMaxCurve)(ref val2)).constantMin * grow, ((MinMaxCurve)(ref val2)).constantMax * grow);
					if (((MainModule)(ref main2)).startSize3D)
					{
						((MainModule)(ref main2)).startSizeX = val3;
					}
					else
					{
						((MainModule)(ref main2)).startSize = val3;
					}
				}
			}
			if (Object.op_Implicit((Object)(object)model))
			{
				model.localPosition = (awake ? (Random.insideUnitSphere * 0.04f) : Vector3.zero);
			}
			if (!Object.op_Implicit((Object)(object)glow) && Object.op_Implicit((Object)(object)model))
			{
				glow = new GameObject("1.76 MHz Glow").AddComponent<Light>();
				((Component)glow).transform.SetParent(model, false);
				glow.type = (LightType)2;
				glow.range = 5f;
				glow.shadows = (LightShadows)0;
			}
			if (Object.op_Implicit((Object)(object)glow))
			{
				glow.color = Builder.Glitch[Random.Range(0, Builder.Glitch.Length)];
				glow.range = (awake ? 9f : 5f);
				glow.intensity = (awake ? 4f : 1.2f) * Random.Range(0.6f, 1f);
			}
		}
	}
	[HarmonyPatch]
	internal static class Patches
	{
		[HarmonyPatch(typeof(EnemyDirector), "Awake")]
		[HarmonyPrefix]
		[HarmonyPriority(800)]
		private static void BuildBeforeDirector(EnemyDirector __instance)
		{
			try
			{
				Builder.BuildAndRegister(__instance);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Failed to build 1.76 MHz: " + ex));
			}
		}

		[HarmonyPatch(typeof(EnemyDirector), "AmountSetup")]
		[HarmonyPostfix]
		private static void Force(EnemyDirector __instance)
		{
			if (Plugin.AlwaysSpawn.Value && !((Object)(object)Builder.Setup == (Object)null))
			{
				List<EnemySetup> enemyList = __instance.enemyList;
				int enemyListIndex = __instance.enemyListIndex;
				if (enemyListIndex < enemyList.Count)
				{
					enemyList[enemyListIndex] = Builder.Setup;
					return;
				}
				enemyList.Add(Builder.Setup);
				__instance.totalAmount++;
			}
		}
	}
	internal static class Tell
	{
		private static string showing;

		private static float until;

		internal static string ShowingNow
		{
			get
			{
				if (showing == null || !(Time.time < until))
				{
					return null;
				}
				return showing;
			}
		}

		internal static void Local(string text, float seconds = 3f)
		{
			if (Object.op_Implicit((Object)(object)ItemInfoUI.instance))
			{
				showing = text;
				until = Time.time + seconds;
				ItemInfoUI.instance.ItemInfoText((ItemAttributes)null, text, false);
			}
		}

		internal static void Tick()
		{
			string showingNow = ShowingNow;
			if (showingNow != null && Object.op_Implicit((Object)(object)ItemInfoUI.instance))
			{
				ItemInfoUI.instance.ItemInfoText((ItemAttributes)null, showingNow, false);
			}
		}
	}
	[BepInPlugin("bigbootyteam.mhz176", "MHz176", "0.1.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "bigbootyteam.mhz176";

		public const string Name = "MHz176";

		public const string Version = "0.1.1";

		internal static ManualLogSource Log;

		internal static ConfigEntry<int> Health;

		internal static ConfigEntry<int> Damage;

		internal static ConfigEntry<int> Difficulty;

		internal static ConfigEntry<float> Rarity;

		internal static ConfigEntry<float> WakeMin;

		internal static ConfigEntry<float> WakeMax;

		internal static ConfigEntry<float> SpreadSeconds;

		internal static ConfigEntry<float> DamageSeconds;

		internal static ConfigEntry<float> AppeaseSeconds;

		internal static ConfigEntry<float> ScreenStatic;

		internal static ConfigEntry<float> Volume;

		internal static ConfigEntry<float> SingleDelay;

		internal static ConfigEntry<bool> AlwaysSpawn;

		private void Awake()
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Expected O, but got Unknown
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Expected O, but got Unknown
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Expected O, but got Unknown
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Expected O, but got Unknown
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Expected O, but got Unknown
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Health = ((BaseUnityPlugin)this).Config.Bind<int>("1.76 MHz", "MaxHealth", 500, new ConfigDescription("How much damage it takes to destroy it. Hurting it wakes it.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(100, 50000), Array.Empty<object>()));
			WakeMin = ((BaseUnityPlugin)this).Config.Bind<float>("1.76 MHz", "WakeAfterMin", 90f, "It first wakes when half the level's extraction points are done (with one, after OneExtractionDelay). Calmed after that, it wakes again after at least this many seconds.");
			SingleDelay = ((BaseUnityPlugin)this).Config.Bind<float>("1.76 MHz", "OneExtractionDelay", 30f, "In a level with only one extraction point, it sleeps this many seconds after the level starts before it wakes.");
			WakeMax = ((BaseUnityPlugin)this).Config.Bind<float>("1.76 MHz", "WakeAfterMax", 180f, "Calmed, it wakes again after at most this many seconds.");
			SpreadSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("1.76 MHz", "SpreadSeconds", 20f, "Awake, its static reaches one more room this often: its own first, then the next nearest (Lob Corp: 20 s).");
			Damage = ((BaseUnityPlugin)this).Config.Bind<int>("1.76 MHz", "Damage", 2, new ConfigDescription("Damage to anyone in a room full of static, every DamageSeconds.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 50), Array.Empty<object>()));
			DamageSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("1.76 MHz", "HurtEverySeconds", 5f, "How often the static hurts.");
			AppeaseSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("1.76 MHz", "AppeaseSeconds", 3f, "Hold onto it this long and it falls quiet: all its static goes, until it wakes again.");
			ScreenStatic = ((BaseUnityPlugin)this).Config.Bind<float>("1.76 MHz", "ScreenStatic", 0.3f, new ConfigDescription("How strongly the static shows on your screen in a room it has reached.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			Volume = ((BaseUnityPlugin)this).Config.Bind<float>("1.76 MHz", "Volume", 1f, new ConfigDescription("Loudness of its sounds.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>()));
			Difficulty = ((BaseUnityPlugin)this).Config.Bind<int>("Spawning", "DifficultyTier", 1, new ConfigDescription("Which enemy tier it spawns in (1 = weakest, 3 = strongest).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 3), Array.Empty<object>()));
			Rarity = ((BaseUnityPlugin)this).Config.Bind<float>("Spawning", "Rarity", 60f, new ConfigDescription("How likely it is to be picked in its tier (most vanilla enemies use 100).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 100f), Array.Empty<object>()));
			AlwaysSpawn = ((BaseUnityPlugin)this).Config.Bind<bool>("Testing", "AlwaysSpawn", false, "If true, every level has 1.76 MHz.");
			new Harmony("bigbootyteam.mhz176").PatchAll(typeof(Patches));
			Log.LogInfo((object)"MHz176 0.1.1 loaded.");
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}