Decompiled source of Walkie Talkies v0.1.1

plugins/WalkieTalkies.dll

Decompiled 6 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Dissonance;
using Dissonance.Audio.Capture;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Mirror;
using NAudio.Wave;
using Shared;
using Steamworks;
using TMPro;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("WalkieTalkies")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WalkieTalkies")]
[assembly: AssemblyTitle("WalkieTalkies")]
[assembly: AssemblyVersion("1.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 Shared
{
	internal static class ModHandshake
	{
		[HarmonyPatch(typeof(SteamLobby), "OnLobbyCreated")]
		private static class PublishPatch
		{
			private static void Postfix(SteamLobby __instance)
			{
				Publish(__instance);
			}
		}

		[HarmonyPatch(typeof(SteamLobby), "RefreshModdedLobbyData")]
		private static class RefreshPatch
		{
			private static void Postfix(SteamLobby __instance)
			{
				Publish(__instance);
			}
		}

		[HarmonyPatch(typeof(SteamLobby), "HostIsInLobby")]
		private static class JoinCheckPatch
		{
			private static bool Prefix(CSteamID lobby, ref bool __result)
			{
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				if (!IsLeader(_ownGuid))
				{
					return true;
				}
				string lobbyData = SteamMatchmaking.GetLobbyData(lobby, "cmods2");
				string text = LocalToken();
				if (lobbyData == text)
				{
					return true;
				}
				_pendingReason = Describe(lobbyData, text);
				Debug.LogWarning((object)("[Lobby check] refusing to join: " + _pendingReason));
				__result = false;
				return false;
			}
		}

		[HarmonyPatch(typeof(SteamLobby), "FailConnect")]
		private static class FailMessagePatch
		{
			private static void Prefix(ref string messageKey)
			{
				if (_pendingReason != null && !(messageKey != "Error_JoinFailed"))
				{
					messageKey = _pendingReason;
					_pendingReason = null;
				}
			}
		}

		internal const string GuidPrefix = "crackmods.";

		private const string LobbyKey = "cmods2";

		private static string _ownGuid;

		private static string _pendingReason;

		internal static string LocalToken()
		{
			List<string> list = new List<string>();
			foreach (KeyValuePair<string, PluginInfo> item in Chainloader.PluginInfos.OrderBy((KeyValuePair<string, PluginInfo> k) => k.Key))
			{
				if (item.Key.StartsWith("crackmods."))
				{
					string text = item.Key.Substring("crackmods.".Length) + "=" + item.Value.Metadata.Version;
					object instance = item.Value.Instance;
					PropertyInfo propertyInfo = ((instance != null) ? AccessTools.Property(instance.GetType(), "HandshakeExtra") : null);
					if (propertyInfo != null && propertyInfo.GetGetMethod() != null && propertyInfo.GetGetMethod().IsStatic)
					{
						text = text + "+" + propertyInfo.GetValue(null, null);
					}
					list.Add(text);
				}
			}
			return string.Join(";", list.ToArray());
		}

		private static bool IsLeader(string ownGuid)
		{
			string text = (from k in Chainloader.PluginInfos.Keys
				where k.StartsWith("crackmods.")
				orderby k
				select k).FirstOrDefault();
			if (text != null)
			{
				return text == ownGuid;
			}
			return true;
		}

		internal static void Install(string ownGuid)
		{
			_ownGuid = ownGuid;
		}

		private static void Publish(SteamLobby lobby)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			if (IsLeader(_ownGuid) && !((Object)(object)lobby == (Object)null) && ((CSteamID)(ref lobby.currentLobbyID)).IsValid())
			{
				string text = LocalToken();
				SteamMatchmaking.SetLobbyData(lobby.currentLobbyID, "cmods2", text);
				Debug.Log((object)("[Lobby check] lobby mods: " + text));
			}
		}

		internal static string Describe(string host, string local)
		{
			Dictionary<string, string> dictionary = Parse(host);
			Dictionary<string, string> dictionary2 = Parse(local);
			List<string> list = new List<string>();
			foreach (string item in from k in dictionary.Keys.Union(dictionary2.Keys)
				orderby k
				select k)
			{
				dictionary.TryGetValue(item, out var value);
				dictionary2.TryGetValue(item, out var value2);
				if (!(value == value2))
				{
					list.Add(item + ": host " + (value ?? "doesn't have it") + ", you " + (value2 ?? "don't have it"));
				}
			}
			return "Your mods don't match the host's. " + string.Join(". ", list.ToArray());
			static Dictionary<string, string> Parse(string s)
			{
				return (from p in (s ?? "").Split(new char[1] { ';' })
					where p.Contains("=")
					select p).ToDictionary((string p) => p.Substring(0, p.IndexOf('=')), (string p) => p.Substring(p.IndexOf('=') + 1));
			}
		}
	}
	[Serializable]
	internal class IconSettings
	{
		public float yaw = 55f;

		public float pitch = 22f;

		public float fov = 20f;

		public float light = 1.6f;

		public float lightYaw = 200f;

		public float lightPitch = 40f;

		public int size = 512;

		public bool square = true;

		public float margin = 0.12f;
	}
	internal static class ItemIcon
	{
		private const int Layer = 31;

		private static readonly Vector3 Stage = new Vector3(0f, -1000f, 0f);

		internal static Sprite Render(Transform visual, IconSettings s, string pngPath)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//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_00eb: 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_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: 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_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Expected O, but got Unknown
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: 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_0262: 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)
			GameObject val = Object.Instantiate<GameObject>(((Component)visual).gameObject, Stage, Quaternion.identity);
			((Object)val).name = "Icon Model";
			GameObject val2 = new GameObject("Icon Camera");
			GameObject val3 = new GameObject("Icon Light");
			RenderTexture val4 = new RenderTexture(s.size, s.size, 24, (RenderTextureFormat)0)
			{
				antiAliasing = 4
			};
			try
			{
				Bounds val5 = Prepare(val);
				Camera obj = val2.AddComponent<Camera>();
				((Behaviour)obj).enabled = false;
				obj.cullingMask = int.MinValue;
				obj.clearFlags = (CameraClearFlags)2;
				obj.fieldOfView = s.fov;
				obj.targetTexture = val4;
				Vector3 val6 = Quaternion.Euler(0f - s.pitch, s.yaw, 0f) * Vector3.forward;
				Vector3 extents = ((Bounds)(ref val5)).extents;
				float num = ((Vector3)(ref extents)).magnitude / Mathf.Sin(s.fov * 0.5f * ((float)Math.PI / 180f));
				((Component)obj).transform.position = ((Bounds)(ref val5)).center + val6 * num;
				((Component)obj).transform.LookAt(((Bounds)(ref val5)).center);
				extents = ((Bounds)(ref val5)).extents;
				obj.nearClipPlane = Mathf.Max(0.01f, num - ((Vector3)(ref extents)).magnitude * 2f);
				extents = ((Bounds)(ref val5)).extents;
				obj.farClipPlane = num + ((Vector3)(ref extents)).magnitude * 2f;
				Light obj2 = val3.AddComponent<Light>();
				obj2.type = (LightType)1;
				obj2.cullingMask = int.MinValue;
				obj2.intensity = s.light;
				obj2.shadows = (LightShadows)0;
				val3.transform.rotation = Quaternion.Euler(s.lightPitch, s.yaw + s.lightYaw, 0f);
				Color[] array = Shoot(obj, val4, Color.black);
				Color[] array2 = Shoot(obj, val4, Color.white);
				Texture2D val7 = new Texture2D(s.size, s.size, (TextureFormat)4, false);
				Color[] array3 = (Color[])(object)new Color[array.Length];
				for (int i = 0; i < array3.Length; i++)
				{
					float num2 = Mathf.Clamp01(1f - (array2[i].r - array[i].r + (array2[i].g - array[i].g) + (array2[i].b - array[i].b)) / 3f);
					array3[i] = (Color)((num2 > 0.004f) ? new Color(array[i].r / num2, array[i].g / num2, array[i].b / num2, num2) : Color.clear);
				}
				val7.SetPixels(array3);
				Texture2D val8 = Crop(val7, array3, s.size, 8, s.square, s.margin);
				Object.Destroy((Object)(object)val7);
				if (pngPath != null)
				{
					try
					{
						Directory.CreateDirectory(Path.GetDirectoryName(pngPath));
						File.WriteAllBytes(pngPath, ImageConversion.EncodeToPNG(val8));
					}
					catch (IOException)
					{
					}
				}
				return Sprite.Create(val8, new Rect(0f, 0f, (float)((Texture)val8).width, (float)((Texture)val8).height), new Vector2(0.5f, 0.5f), 100f);
			}
			finally
			{
				Object.Destroy((Object)(object)val);
				Object.Destroy((Object)(object)val2);
				Object.Destroy((Object)(object)val3);
				val4.Release();
				Object.Destroy((Object)(object)val4);
			}
		}

		private static Bounds Prepare(GameObject copy)
		{
			//IL_0053: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			Transform[] componentsInChildren = copy.GetComponentsInChildren<Transform>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				((Component)componentsInChildren[i]).gameObject.layer = 31;
			}
			Collider[] componentsInChildren2 = copy.GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				componentsInChildren2[i].enabled = false;
			}
			Renderer[] componentsInChildren3 = copy.GetComponentsInChildren<Renderer>(true);
			Bounds bounds = default(Bounds);
			((Bounds)(ref bounds))..ctor(copy.transform.position, Vector3.zero);
			Renderer[] array = componentsInChildren3;
			foreach (Renderer val in array)
			{
				if (val.enabled)
				{
					val.lightProbeUsage = (LightProbeUsage)0;
					val.shadowCastingMode = (ShadowCastingMode)0;
					if (((Bounds)(ref bounds)).size == Vector3.zero)
					{
						bounds = val.bounds;
					}
					else
					{
						((Bounds)(ref bounds)).Encapsulate(val.bounds);
					}
				}
			}
			return bounds;
		}

		private static Color[] Shoot(Camera cam, RenderTexture rt, Color background)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			cam.backgroundColor = background;
			StandardRequest val = new StandardRequest
			{
				destination = rt
			};
			if (RenderPipeline.SupportsRenderRequest<StandardRequest>(cam, val))
			{
				RenderPipeline.SubmitRenderRequest<StandardRequest>(cam, val);
			}
			else
			{
				cam.Render();
			}
			RenderTexture active = RenderTexture.active;
			RenderTexture.active = rt;
			Texture2D val2 = new Texture2D(((Texture)rt).width, ((Texture)rt).height, (TextureFormat)4, false);
			val2.ReadPixels(new Rect(0f, 0f, (float)((Texture)rt).width, (float)((Texture)rt).height), 0, 0, false);
			RenderTexture.active = active;
			Color[] pixels = val2.GetPixels();
			Object.Destroy((Object)val2);
			return pixels;
		}

		private static Texture2D Crop(Texture2D full, Color[] px, int size, int pad, bool square, float margin)
		{
			//IL_00e3: 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_00ea: Expected O, but got Unknown
			int num = size;
			int num2 = size;
			int num3 = -1;
			int num4 = -1;
			for (int i = 0; i < size; i++)
			{
				for (int j = 0; j < size; j++)
				{
					if (px[i * size + j].a > 0.02f)
					{
						num = Mathf.Min(num, j);
						num3 = Mathf.Max(num3, j);
						num2 = Mathf.Min(num2, i);
						num4 = Mathf.Max(num4, i);
					}
				}
			}
			if (num3 < 0)
			{
				return full;
			}
			num = Mathf.Max(0, num - pad);
			num2 = Mathf.Max(0, num2 - pad);
			num3 = Mathf.Min(size - 1, num3 + pad);
			num4 = Mathf.Min(size - 1, num4 + pad);
			int num5 = num3 - num + 1;
			int num6 = num4 - num2 + 1;
			int num7 = (square ? Mathf.CeilToInt((float)Mathf.Max(num5, num6) * (1f + 2f * margin)) : 0);
			Texture2D val = (square ? new Texture2D(num7, num7, (TextureFormat)4, false) : new Texture2D(num5, num6, (TextureFormat)4, false));
			if (square)
			{
				val.SetPixels((Color[])(object)new Color[num7 * num7]);
			}
			val.SetPixels(square ? ((num7 - num5) / 2) : 0, square ? ((num7 - num6) / 2) : 0, num5, num6, full.GetPixels(num, num2, num5, num6));
			val.Apply();
			return val;
		}
	}
	internal static class PaletteMesh
	{
		internal static Vector4 Tangent(Vector3 normal)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Vector3.Cross(normal, (Mathf.Abs(normal.y) < 0.99f) ? Vector3.up : Vector3.right);
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			return new Vector4(normalized.x, normalized.y, normalized.z, 1f);
		}

		internal static List<Vector4> Tangents(IList<Vector3> normals)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			List<Vector4> list = new List<Vector4>(normals.Count);
			foreach (Vector3 normal in normals)
			{
				list.Add(Tangent(normal));
			}
			return list;
		}
	}
	internal static class LegacyConfig
	{
		internal static void Adopt(BaseUnityPlugin plugin)
		{
			try
			{
				string configFilePath = plugin.Config.ConfigFilePath;
				string directoryName = Path.GetDirectoryName(configFilePath);
				if (File.Exists(configFilePath) || directoryName == null || !Directory.Exists(directoryName))
				{
					return;
				}
				string fileName = Path.GetFileName(configFilePath);
				if (fileName.StartsWith("crackmods"))
				{
					string text = "crack" + fileName.Substring("crackmods".Length);
					string text2 = Directory.GetFiles(directoryName, "com.*." + text).FirstOrDefault();
					if (text2 != null)
					{
						File.Move(text2, configFilePath);
						plugin.Config.Reload();
					}
				}
			}
			catch (IOException)
			{
			}
		}
	}
}
namespace WalkieTalkies
{
	[HarmonyPatch]
	internal static class Controls
	{
		private const string OffKey = "walkieOff";

		private static Megaphone AsWalkie(HeldItem item)
		{
			Megaphone val = (Megaphone)(object)((item is Megaphone) ? item : null);
			if (val == null || !((Object)(object)((Component)val).GetComponent<Walkie>() != (Object)null))
			{
				return null;
			}
			return val;
		}

		[HarmonyPatch(typeof(HeldItem), "OnSecondaryUseStart")]
		[HarmonyPrefix]
		private static bool Power(HeldItem __instance)
		{
			Megaphone val = AsWalkie(__instance);
			if ((Object)(object)val == (Object)null)
			{
				return true;
			}
			if (!((NetworkBehaviour)val).isOwned)
			{
				return false;
			}
			bool flag = !Net.IsOn(val);
			if (!flag)
			{
				((HeldItem)val).OnUseStop();
			}
			Net.Request(val, flag);
			Radio.Instance?.Click(val);
			return false;
		}

		[HarmonyPatch(typeof(Megaphone), "OnUseStart")]
		[HarmonyPrefix]
		private static bool Talk(Megaphone __instance)
		{
			if (!((Object)(object)AsWalkie((HeldItem)(object)__instance) == (Object)null))
			{
				return Net.IsOn(__instance);
			}
			return true;
		}

		[HarmonyPatch(typeof(Megaphone), "GetActionPrompts")]
		[HarmonyPostfix]
		private static void Prompts(Megaphone __instance, List<string> list, GameplayActions input)
		{
			if (!((Object)(object)AsWalkie((HeldItem)(object)__instance) == (Object)null))
			{
				list.Add(InputPromptHelper.Prompt(((GameplayActions)(ref input)).RightHandUse, Net.IsOn(__instance) ? "Walkie_PowerOff" : "Walkie_PowerOn"));
			}
		}

		[HarmonyPatch(typeof(HeldItem), "GetItemSaveData")]
		[HarmonyPostfix]
		private static void Save(HeldItem __instance, ref Dictionary<string, string> __result)
		{
			Megaphone val = AsWalkie(__instance);
			if (!((Object)(object)val == (Object)null) && !Net.IsOn(val))
			{
				(__result ?? (__result = new Dictionary<string, string>()))["walkieOff"] = "1";
			}
		}

		[HarmonyPatch(typeof(HeldItem), "ApplyItemSaveData")]
		[HarmonyPostfix]
		private static void Load(HeldItem __instance, Dictionary<string, string> data)
		{
			Megaphone val = AsWalkie(__instance);
			if ((Object)(object)val != (Object)null && NetworkServer.active && data != null && data.ContainsKey("walkieOff"))
			{
				Net.ServerSet(val, on: false);
			}
		}
	}
	internal sealed class Monitor : MonoBehaviour, IMicrophoneSubscriber
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static PCMReaderCallback <>9__11_0;

			internal void <Create>b__11_0(float[] data)
			{
				for (int i = 0; i < data.Length; i++)
				{
					data[i] = 1f;
				}
			}
		}

		private const float MaxBuffer = 0.4f;

		private readonly object _lock = new object();

		private float[] _ring = new float[48000];

		private int _read;

		private int _count;

		private int _micRate = 48000;

		private int _outRate;

		private double _phase;

		private volatile bool _live;

		private DissonanceComms _comms;

		private AudioSource _source;

		internal static Monitor Create(AudioMixerGroup group)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			GameObject val = new GameObject("Walkie Monitor");
			Object.DontDestroyOnLoad((Object)val);
			AudioSource val2 = val.AddComponent<AudioSource>();
			Monitor monitor = val.AddComponent<Monitor>();
			val.AddComponent<AudioHighPassFilter>().cutoffFrequency = 500f;
			val.AddComponent<AudioLowPassFilter>().cutoffFrequency = 3200f;
			val.AddComponent<AudioDistortionFilter>().distortionLevel = 0.55f;
			int outputSampleRate = AudioSettings.outputSampleRate;
			object obj = <>c.<>9__11_0;
			if (obj == null)
			{
				PCMReaderCallback val3 = delegate(float[] data)
				{
					for (int i = 0; i < data.Length; i++)
					{
						data[i] = 1f;
					}
				};
				<>c.<>9__11_0 = val3;
				obj = (object)val3;
			}
			AudioClip clip = AudioClip.Create("Walkie Monitor Carrier", outputSampleRate, 1, outputSampleRate, false, (PCMReaderCallback)obj);
			val2.clip = clip;
			val2.loop = true;
			val2.outputAudioMixerGroup = group;
			val2.spatialBlend = 1f;
			val2.rolloffMode = (AudioRolloffMode)1;
			val2.minDistance = 1f;
			val2.maxDistance = 22f;
			monitor._source = val2;
			monitor._outRate = outputSampleRate;
			return monitor;
		}

		internal void Follow(Vector3? spot)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			Subscribe();
			_live = spot.HasValue;
			if (spot.HasValue)
			{
				((Component)this).transform.position = spot.Value;
			}
			_source.volume = Plugin.VoiceVolume.Value;
			if (_live && !_source.isPlaying)
			{
				_source.Play();
			}
			else if (!_live && _source.isPlaying)
			{
				_source.Stop();
				lock (_lock)
				{
					_count = 0;
				}
			}
		}

		private void Subscribe()
		{
			if (!((Object)(object)_comms != (Object)null))
			{
				_comms = Object.FindFirstObjectByType<DissonanceComms>();
				if ((Object)(object)_comms != (Object)null)
				{
					_comms.SubscribeToRecordedAudio((IMicrophoneSubscriber)(object)this);
				}
			}
		}

		public void ReceiveMicrophoneData(ArraySegment<float> buffer, WaveFormat format)
		{
			if (!_live)
			{
				return;
			}
			lock (_lock)
			{
				int num = Mathf.Max(1, format.Channels);
				_micRate = format.SampleRate;
				int num2 = Mathf.Max(1024, (int)((float)_micRate * 0.4f));
				if (_ring.Length < num2)
				{
					_ring = new float[num2];
					_read = (_count = 0);
				}
				for (int i = buffer.Offset; i + num <= buffer.Offset + buffer.Count; i += num)
				{
					if (_count == _ring.Length)
					{
						_read = (_read + 1) % _ring.Length;
						_count--;
					}
					_ring[(_read + _count) % _ring.Length] = buffer.Array[i];
					_count++;
				}
			}
		}

		public void Reset()
		{
			lock (_lock)
			{
				_count = 0;
			}
		}

		private void OnAudioFilterRead(float[] data, int channels)
		{
			double num = (double)_micRate / (double)_outRate;
			lock (_lock)
			{
				for (int i = 0; i < data.Length; i += channels)
				{
					float num2 = 0f;
					if (_count > 1)
					{
						float num3 = _ring[_read];
						float num4 = _ring[(_read + 1) % _ring.Length];
						num2 = num3 + (num4 - num3) * (float)_phase;
						_phase += num;
						while (_phase >= 1.0 && _count > 1)
						{
							_phase -= 1.0;
							_read = (_read + 1) % _ring.Length;
							_count--;
						}
					}
					for (int j = 0; j < channels; j++)
					{
						data[i + j] *= num2;
					}
				}
			}
		}

		private void OnDestroy()
		{
			if ((Object)(object)_comms != (Object)null)
			{
				_comms.UnsubscribeFromRecordedAudio((IMicrophoneSubscriber)(object)this);
			}
		}
	}
	public struct PowerMsg : NetworkMessage
	{
		public uint Walkie;

		public bool On;
	}
	internal static class Net
	{
		private static readonly HashSet<uint> off = new HashSet<uint>();

		private static readonly HashSet<int> synced = new HashSet<int>();

		private static bool _server;

		private static bool _client;

		internal static bool IsOn(Megaphone w)
		{
			if ((Object)(object)w != (Object)null)
			{
				return !off.Contains(((NetworkBehaviour)w).netId);
			}
			return false;
		}

		public static void Init()
		{
			Writer<PowerMsg>.write = delegate(NetworkWriter w, PowerMsg m)
			{
				NetworkWriterExtensions.WriteUInt(w, m.Walkie);
				NetworkWriterExtensions.WriteBool(w, m.On);
			};
			Reader<PowerMsg>.read = (NetworkReader r) => new PowerMsg
			{
				Walkie = NetworkReaderExtensions.ReadUInt(r),
				On = NetworkReaderExtensions.ReadBool(r)
			};
		}

		public static void Tick()
		{
			if (NetworkServer.active != _server && (_server = NetworkServer.active))
			{
				NetworkServer.ReplaceHandler<PowerMsg>((Action<NetworkConnectionToClient, PowerMsg>)OnRequest, true);
			}
			if (NetworkClient.active != _client && (_client = NetworkClient.active))
			{
				NetworkClient.ReplaceHandler<PowerMsg>((Action<PowerMsg>)delegate(PowerMsg m)
				{
					Set(m.Walkie, m.On);
				}, true);
			}
			if (!_server && !_client)
			{
				off.Clear();
			}
			if (!_server)
			{
				synced.Clear();
				return;
			}
			synced.RemoveWhere((int id) => !NetworkServer.connections.ContainsKey(id));
			foreach (NetworkConnectionToClient value in NetworkServer.connections.Values)
			{
				if (value == null || (object)value == NetworkServer.localConnection || !((NetworkConnection)value).isReady || !synced.Add(value.connectionId))
				{
					continue;
				}
				foreach (uint item in off)
				{
					((NetworkConnection)value).Send<PowerMsg>(new PowerMsg
					{
						Walkie = item,
						On = false
					}, 0);
				}
			}
		}

		private static void Set(uint id, bool on)
		{
			if (on)
			{
				off.Remove(id);
			}
			else
			{
				off.Add(id);
			}
		}

		internal static void Request(Megaphone w, bool on)
		{
			Set(((NetworkBehaviour)w).netId, on);
			if (NetworkClient.active)
			{
				NetworkClient.Send<PowerMsg>(new PowerMsg
				{
					Walkie = ((NetworkBehaviour)w).netId,
					On = on
				}, 0);
			}
		}

		private static void OnRequest(NetworkConnectionToClient conn, PowerMsg m)
		{
			if (NetworkServer.spawned.TryGetValue(m.Walkie, out var value) && !((Object)(object)value == (Object)null))
			{
				Megaphone component = ((Component)value).GetComponent<Megaphone>();
				Player val = (((Object)(object)component != (Object)null && (Object)(object)((HeldItem)component).Holder != (Object)null) ? ((Component)((HeldItem)component).Holder).GetComponentInParent<Player>() : null);
				if (!((Object)(object)component == (Object)null) && !((Object)(object)((Component)value).GetComponent<Walkie>() == (Object)null) && !((Object)(object)val == (Object)null) && ((NetworkBehaviour)val).connectionToClient == conn)
				{
					ServerSet(component, m.On);
				}
			}
		}

		internal static void ServerSet(Megaphone w, bool on)
		{
			Set(((NetworkBehaviour)w).netId, on);
			NetworkServer.SendToAll<PowerMsg>(new PowerMsg
			{
				Walkie = ((NetworkBehaviour)w).netId,
				On = on
			}, 0, false);
		}
	}
	[BepInPlugin("crackmods.walkie", "Walkie-Talkies", "0.1.1")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "crackmods.walkie";

		public const string Name = "Walkie-Talkies";

		public const string Version = "0.1.1";

		internal static ManualLogSource Log;

		internal static ConfigEntry<float> VoiceVolume;

		internal static ConfigEntry<float> StaticVolume;

		private void Awake()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_009f: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			LegacyConfig.Adopt((BaseUnityPlugin)(object)this);
			Log = ((BaseUnityPlugin)this).Logger;
			VoiceVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Walkie", "VoiceVolume", 1f, new ConfigDescription("How loud voices come through your walkie. Only affects what you hear.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1.5f), Array.Empty<object>()));
			StaticVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Walkie", "StaticVolume", 0.5f, new ConfigDescription("How loud the squelch and the static under incoming talk are. Only affects what you hear.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			ModHandshake.Install("crackmods.walkie");
			Net.Init();
			new Harmony("crackmods.walkie").PatchAll(typeof(Plugin).Assembly);
			GameObject val = new GameObject("WalkieTalkies")
			{
				hideFlags = (HideFlags)61
			};
			Object.DontDestroyOnLoad((Object)val);
			val.AddComponent<Radio>();
			Log.LogInfo((object)"Walkie-Talkies 0.1.1 loaded");
		}
	}
	internal sealed class Radio : MonoBehaviour
	{
		internal sealed class Speaker : MonoBehaviour
		{
			private Megaphone _walkie;

			private AudioSource _blip;

			private AudioSource _hiss;

			internal void Init(Megaphone walkie, AudioClip hiss, AudioMixerGroup group)
			{
				_walkie = walkie;
				_blip = Source(group);
				_hiss = Source(group);
				_hiss.clip = hiss;
				_hiss.loop = true;
			}

			private AudioSource Source(AudioMixerGroup group)
			{
				AudioSource obj = ((Component)this).gameObject.AddComponent<AudioSource>();
				obj.outputAudioMixerGroup = group;
				obj.spatialBlend = 1f;
				obj.rolloffMode = (AudioRolloffMode)1;
				obj.minDistance = 1f;
				obj.maxDistance = 22f;
				obj.playOnAwake = false;
				return obj;
			}

			internal void Play(AudioClip clip, float level)
			{
				if ((Object)(object)clip != (Object)null)
				{
					_blip.PlayOneShot(clip, Plugin.StaticVolume.Value * 0.6f * level);
				}
			}

			internal void Hiss(bool on)
			{
				_hiss.volume = Plugin.StaticVolume.Value * 0.12f;
				if (on && !_hiss.isPlaying && (Object)(object)_hiss.clip != (Object)null)
				{
					_hiss.Play();
				}
				else if (!on && _hiss.isPlaying)
				{
					_hiss.Stop();
				}
			}

			private void LateUpdate()
			{
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)_walkie != (Object)null)
				{
					((Component)this).transform.position = Spot(_walkie);
				}
			}
		}

		private const float Range = 22f;

		internal static readonly VoiceEffectProfile Profile = MakeProfile();

		internal static readonly Dictionary<PlayerVoiceChat, Megaphone> Routes = new Dictionary<PlayerVoiceChat, Megaphone>();

		private static readonly FieldRef<Megaphone, bool> Predicted = AccessTools.FieldRefAccess<Megaphone, bool>("predictedActive");

		private static readonly Func<AudioClip, float[], int, bool> SetData = (Func<AudioClip, float[], int, bool>)Delegate.CreateDelegate(typeof(Func<AudioClip, float[], int, bool>), typeof(AudioClip).GetMethod("SetData", new Type[2]
		{
			typeof(float[]),
			typeof(int)
		}));

		private readonly Dictionary<Megaphone, Speaker> _speakers = new Dictionary<Megaphone, Speaker>();

		private readonly HashSet<Megaphone> _keyed = new HashSet<Megaphone>();

		private readonly List<Megaphone> _on = new List<Megaphone>();

		private readonly List<Megaphone> _talking = new List<Megaphone>();

		private AudioClip _open;

		private AudioClip _close;

		private AudioClip _static;

		private Material _green;

		private Material _red;

		private Material _yellow;

		private Monitor _monitor;

		internal static Radio Instance;

		private const int ScreenChars = 8;

		private static AudioMixerGroup _sfx;

		private void Awake()
		{
			Instance = this;
		}

		internal void Click(Megaphone w)
		{
			Speak(w).Play(Clip(ref _open, "squelch_open"), 0.25f);
		}

		private static VoiceEffectProfile MakeProfile()
		{
			VoiceEffectProfile obj = ScriptableObject.CreateInstance<VoiceEffectProfile>();
			((Object)obj).name = "Walkie Radio";
			obj.useHighPass = true;
			obj.highPassCutoff = 500f;
			obj.useLowPass = true;
			obj.lowPassCutoff = 3200f;
			obj.useDistortion = true;
			obj.distortionLevel = 0.55f;
			Object.DontDestroyOnLoad((Object)(object)obj);
			return obj;
		}

		internal static Player Owner(Megaphone w)
		{
			if (!((Object)(object)w != (Object)null) || !((Object)(object)((HeldItem)w).Holder != (Object)null))
			{
				return null;
			}
			return ((Component)((HeldItem)w).Holder).GetComponentInParent<Player>();
		}

		internal static Vector3 Spot(Megaphone w)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			if (!((HeldItem)w).IsPocketed || !((Object)(object)((HeldItem)w).Holder != (Object)null))
			{
				return ((Component)w).transform.position;
			}
			return ((Component)((HeldItem)w).Holder).transform.position;
		}

		private static bool Talking(Megaphone w)
		{
			if ((Object)(object)Owner(w) != (Object)null && Net.IsOn(w))
			{
				if (!((NetworkBehaviour)w).isOwned)
				{
					return w.NetworkisActive;
				}
				return Predicted.Invoke(w);
			}
			return false;
		}

		private void Update()
		{
			Net.Tick();
			Profile.volume = Plugin.VoiceVolume.Value;
			_on.Clear();
			_talking.Clear();
			foreach (Megaphone item in Walkie.All)
			{
				if (!((Object)(object)item == (Object)null))
				{
					if (Net.IsOn(item))
					{
						_on.Add(item);
					}
					if (Talking(item))
					{
						_talking.Add(item);
					}
				}
			}
			Keying();
			Route();
			foreach (Megaphone w in _on)
			{
				Speak(w).Hiss(_talking.Any((Megaphone t) => (Object)(object)t != (Object)(object)w));
			}
			foreach (KeyValuePair<Megaphone, Speaker> item2 in _speakers.Where((KeyValuePair<Megaphone, Speaker> kv) => (Object)(object)kv.Key == (Object)null || !Net.IsOn(kv.Key)).ToList())
			{
				item2.Value.Hiss(on: false);
				if ((Object)(object)item2.Key == (Object)null)
				{
					Object.Destroy((Object)(object)((Component)item2.Value).gameObject);
					_speakers.Remove(item2.Key);
				}
			}
			foreach (Megaphone item3 in Walkie.All)
			{
				if (!((Object)(object)item3 == (Object)null))
				{
					Lamp(item3);
					Screen(item3);
				}
			}
		}

		private void Keying()
		{
			foreach (Megaphone w in Walkie.All)
			{
				if ((Object)(object)w == (Object)null)
				{
					continue;
				}
				bool flag = _talking.Contains(w);
				if (flag == _keyed.Contains(w))
				{
					continue;
				}
				if (flag)
				{
					_keyed.Add(w);
				}
				else
				{
					_keyed.Remove(w);
				}
				if (flag)
				{
					Speak(w).Play(Clip(ref _open, "squelch_open"), 0.35f);
				}
				foreach (Megaphone item in _on.Where((Megaphone r) => (Object)(object)r != (Object)(object)w))
				{
					Speak(item).Play(flag ? Clip(ref _open, "squelch_open") : Clip(ref _close, "squelch_close"), 1f);
				}
			}
			_keyed.RemoveWhere((Megaphone val) => (Object)(object)val == (Object)null);
		}

		private void Route()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: 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_02ca: Unknown result type (might be due to invalid IL or missing references)
			Player me = Player.Local;
			Vector3 ear = (((Object)(object)Camera.main != (Object)null) ? ((Component)Camera.main).transform.position : (((Object)(object)me != (Object)null) ? ((Component)me).transform.position : Vector3.zero));
			HashSet<PlayerVoiceChat> live = new HashSet<PlayerVoiceChat>();
			foreach (Megaphone t in _talking)
			{
				Player val = Owner(t);
				if ((Object)(object)val == (Object)null || (Object)(object)val == (Object)(object)me)
				{
					continue;
				}
				PlayerVoiceChat componentInParent = ((Component)((HeldItem)t).Holder).GetComponentInParent<PlayerVoiceChat>();
				if ((Object)(object)componentInParent == (Object)null)
				{
					continue;
				}
				Megaphone val2 = _on.Where((Megaphone r) => (Object)(object)r != (Object)(object)t).OrderBy(delegate(Megaphone r)
				{
					//IL_0001: Unknown result type (might be due to invalid IL or missing references)
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0011: Unknown result type (might be due to invalid IL or missing references)
					Vector3 val5 = Spot(r) - ear;
					return ((Vector3)(ref val5)).sqrMagnitude;
				}).FirstOrDefault();
				Vector3 val3 = ((Component)val).transform.position - ear;
				float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude;
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				val3 = Spot(val2) - ear;
				if (!(((Vector3)(ref val3)).sqrMagnitude >= sqrMagnitude))
				{
					live.Add(componentInParent);
					if (!Routes.ContainsKey(componentInParent))
					{
						componentInParent.SetVoiceOverride(Profile, false, 22f);
					}
					Routes[componentInParent] = val2;
				}
			}
			foreach (PlayerVoiceChat item in Routes.Keys.Where((PlayerVoiceChat v) => !live.Contains(v)).ToList())
			{
				Routes.Remove(item);
				if ((Object)(object)item != (Object)null)
				{
					item.ClearVoiceOverride();
				}
			}
			Megaphone mine = ((IEnumerable<Megaphone>)_talking).FirstOrDefault((Func<Megaphone, bool>)((Megaphone w) => (Object)(object)me != (Object)null && (Object)(object)Owner(w) == (Object)(object)me));
			Megaphone val4 = (((Object)(object)mine == (Object)null) ? null : _on.Where(delegate(Megaphone r)
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)r != (Object)(object)mine)
				{
					Vector3 val5 = Spot(r) - ear;
					return ((Vector3)(ref val5)).sqrMagnitude < 484f;
				}
				return false;
			}).OrderBy(delegate(Megaphone r)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				Vector3 val5 = Spot(r) - ear;
				return ((Vector3)(ref val5)).sqrMagnitude;
			}).FirstOrDefault());
			(_monitor ?? (_monitor = Monitor.Create(SfxGroup()))).Follow(((Object)(object)val4 != (Object)null) ? new Vector3?(Spot(val4)) : ((Vector3?)null));
		}

		private void Screen(Megaphone w)
		{
			Transform val = ((Component)w).transform.Find("Display");
			TMP_Text val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<TMP_Text>() : null);
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			string text;
			if (!Net.IsOn(w))
			{
				text = "";
			}
			else if (_talking.Contains(w))
			{
				text = "TX";
			}
			else
			{
				Megaphone val3 = ((IEnumerable<Megaphone>)_talking).FirstOrDefault((Func<Megaphone, bool>)((Megaphone o) => (Object)(object)o != (Object)(object)w));
				PlayerController val4 = ((!((Object)(object)val3 != (Object)null)) ? null : Owner(val3)?.playerController);
				text = (((Object)(object)val3 == (Object)null) ? "READY" : Scroll("RX " + (((Object)(object)val4 != (Object)null) ? val4.steamName : "").ToUpperInvariant()));
			}
			WalkieMesh.Fit(val2);
			if (val2.text != text)
			{
				val2.text = text;
			}
		}

		private static string Scroll(string s)
		{
			if (s.Length <= 8)
			{
				return s;
			}
			string text = s + "   ";
			int startIndex = (int)(Time.unscaledTime / 0.3f) % text.Length;
			return (text + text).Substring(startIndex, 8);
		}

		private void Lamp(Megaphone w)
		{
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ((Component)w).transform.Find("LED");
			MeshRenderer val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<MeshRenderer>() : null);
			if (!((Object)(object)val2 == (Object)null))
			{
				if ((Object)(object)_green == (Object)null)
				{
					_green = Indicator("MAT_Indicator_Green");
				}
				if ((Object)(object)_red == (Object)null)
				{
					_red = Indicator("MAT_Indicator_Red");
				}
				if ((Object)(object)_yellow == (Object)null && (Object)(object)_green != (Object)null)
				{
					_yellow = Tint(_green, new Color(1f, 0.78f, 0.08f));
				}
				Material sharedMaterial = ((Renderer)((Component)((Component)w).transform.Find("SM_Megaphone")).GetComponent<MeshRenderer>()).sharedMaterial;
				bool flag = _talking.Any((Megaphone t) => (Object)(object)t != (Object)(object)w);
				Material val3 = ((!Net.IsOn(w)) ? sharedMaterial : (_talking.Contains(w) ? _red : (flag ? _yellow : _green)));
				if ((Object)(object)val3 == (Object)null)
				{
					val3 = _green ?? sharedMaterial;
				}
				if ((Object)(object)((Renderer)val2).sharedMaterial != (Object)(object)val3)
				{
					((Renderer)val2).sharedMaterial = val3;
				}
			}
		}

		private static Material Indicator(string name)
		{
			return ((IEnumerable<Material>)Resources.FindObjectsOfTypeAll<Material>()).FirstOrDefault((Func<Material, bool>)((Material m) => ((Object)m).name == name));
		}

		private static Material Tint(Material source, Color c)
		{
			//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_001d: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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_007f: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			Material val = new Material(source)
			{
				name = ((Object)source).name + " (Yellow)"
			};
			string[] array = new string[2] { "_BaseColor", "_Color" };
			foreach (string text in array)
			{
				if (val.HasProperty(text))
				{
					val.SetColor(text, c);
				}
			}
			if (val.HasProperty("_EmissionColor"))
			{
				Color color = source.GetColor("_EmissionColor");
				val.SetColor("_EmissionColor", c * Mathf.Max(color.r, Mathf.Max(color.g, color.b)));
			}
			return val;
		}

		private Speaker Speak(Megaphone w)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			if (_speakers.TryGetValue(w, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			GameObject val = new GameObject("Walkie Speaker");
			Object.DontDestroyOnLoad((Object)val);
			value = val.AddComponent<Speaker>();
			value.Init(w, Clip(ref _static, "static"), SfxGroup());
			return _speakers[w] = value;
		}

		private AudioClip Clip(ref AudioClip field, string name)
		{
			if (!((Object)(object)field != (Object)null))
			{
				return field = Load(name);
			}
			return field;
		}

		private static AudioMixerGroup SfxGroup()
		{
			if ((Object)(object)_sfx != (Object)null)
			{
				return _sfx;
			}
			return _sfx = (from d in Resources.FindObjectsOfTypeAll<SoundDefinition>()
				where (Object)(object)d.mixerGroup != (Object)null
				group d by d.mixerGroup into g
				orderby g.Count() descending
				select g.Key).FirstOrDefault();
		}

		private static AudioClip Load(string name)
		{
			using Stream stream = typeof(Radio).Assembly.GetManifestResourceStream("WalkieTalkies." + name + ".pcm.gz");
			if (stream == null)
			{
				Plugin.Log.LogWarning((object)("Missing sound '" + name + "'"));
				return null;
			}
			MemoryStream memoryStream = new MemoryStream();
			using (GZipStream gZipStream = new GZipStream(stream, CompressionMode.Decompress))
			{
				gZipStream.CopyTo(memoryStream);
			}
			byte[] array = memoryStream.ToArray();
			float[] array2 = new float[array.Length / 2];
			for (int i = 0; i < array2.Length; i++)
			{
				array2[i] = (float)(short)(array[2 * i] | (array[2 * i + 1] << 8)) / 32768f;
			}
			AudioClip val = AudioClip.Create("Walkie " + name, array2.Length, 1, 22050, false);
			SetData(val, array2, 0);
			return val;
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal static class VoicePositionPatch
	{
		private static void Postfix(PlayerVoiceChat __instance, ref Vector3 __result)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			if (Radio.Routes.TryGetValue(__instance, out var value) && (Object)(object)value != (Object)null)
			{
				__result = Radio.Spot(value);
			}
		}
	}
	[HarmonyPatch(typeof(Megaphone), "ApplyOverride")]
	internal static class MegaphoneOverridePatch
	{
		private static bool Prefix(Megaphone __instance)
		{
			return (Object)(object)((Component)__instance).GetComponent<Walkie>() == (Object)null;
		}
	}
	internal sealed class Walkie : MonoBehaviour
	{
		internal static readonly List<Megaphone> All = new List<Megaphone>();

		internal Megaphone Item;

		private void Awake()
		{
			All.Add(Item = ((Component)this).GetComponent<Megaphone>());
		}

		private void OnDestroy()
		{
			All.Remove(Item);
		}
	}
	[HarmonyPatch]
	internal static class WalkiePrefab
	{
		internal const uint AssetId = 2353691649u;

		private const string Catalogs = "Shop Catalogs";

		private const string Catalog = "Shop_Catalog_Tier1";

		private const int PriceCents = 1999;

		private const int PerDay = 2;

		private static readonly FieldRef<HeldItem, string> NameKey = AccessTools.FieldRefAccess<HeldItem, string>("itemNameKey");

		private static readonly FieldRef<HeldItem, Sprite> Icon = AccessTools.FieldRefAccess<HeldItem, Sprite>("icon");

		private static readonly FieldRef<Megaphone, VoiceEffectProfile> Effect = AccessTools.FieldRefAccess<Megaphone, VoiceEffectProfile>("megaphoneEffect");

		private static GameObject _template;

		internal static GameObject Template => _template;

		internal static ShopItemData Item { get; private set; }

		private static ShopItemData MegaphoneItem => Resources.LoadAll<ShopCatalog>("Shop Catalogs").SelectMany((ShopCatalog c) => c.items).FirstOrDefault((Func<ShopItemData, bool>)((ShopItemData i) => (Object)(object)i != (Object)null && (Object)(object)i.spawnPrefab != (Object)null && (Object)(object)i.spawnPrefab.GetComponent<Megaphone>() != (Object)null));

		private static TMP_Text RadioDisplay()
		{
			return (from r in (from i in Resources.LoadAll<ShopCatalog>("Shop Catalogs").SelectMany((ShopCatalog c) => c.items)
					where (Object)(object)i != (Object)null && (Object)(object)i.spawnPrefab != (Object)null
					select i.spawnPrefab.GetComponent<Radio>()).Concat(Resources.FindObjectsOfTypeAll<Radio>())
				where (Object)(object)r != (Object)null
				select ((Component)r).GetComponentInChildren<TMP_Text>(true)).FirstOrDefault((Func<TMP_Text, bool>)((TMP_Text t) => (Object)(object)t != (Object)null));
		}

		internal static void Ensure()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			if ((Object)(object)_template != (Object)null)
			{
				return;
			}
			ShopItemData megaphoneItem = MegaphoneItem;
			if ((Object)(object)megaphoneItem == (Object)null)
			{
				Plugin.Log.LogError((object)"No megaphone in the store catalogs; walkies can't be built");
				return;
			}
			GameObject val = new GameObject("Walkie Templates");
			val.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)val);
			_template = Object.Instantiate<GameObject>(megaphoneItem.spawnPrefab, val.transform, false);
			((Object)_template).name = "PF_Item_Walkie";
			Traverse.Create((object)_template.GetComponent<NetworkIdentity>()).Field("_assetId").SetValue((object)0u);
			_template.AddComponent<Walkie>();
			Megaphone component = _template.GetComponent<Megaphone>();
			NameKey.Invoke((HeldItem)(object)component) = "Walkie_Name";
			Effect.Invoke(component) = Radio.Profile;
			WalkieMesh.Apply(_template);
			WalkieMesh.AddScreen(_template.transform, RadioDisplay());
			NetworkClient.RegisterPrefab(_template, 2353691649u);
			try
			{
				IconSettings s = new IconSettings
				{
					yaw = 200f,
					pitch = 12f,
					fov = 20f,
					size = 512
				};
				string pngPath = Path.Combine(Paths.CachePath, "WalkieTalkies_icon.png");
				Icon.Invoke((HeldItem)(object)component) = ItemIcon.Render(_template.transform.Find("SM_Megaphone"), s, pngPath);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Couldn't render the walkie icon: " + ex.Message));
			}
			Plugin.Log.LogInfo((object)"Walkie prefab registered");
		}

		[HarmonyPatch(typeof(NetworkClient), "PrepareToSpawnSceneObjects")]
		[HarmonyPrefix]
		private static void BeforeClientSpawns()
		{
			Ensure();
		}

		[HarmonyPatch(typeof(NetworkServer), "SpawnObjects")]
		[HarmonyPrefix]
		private static void BeforeServerSpawns()
		{
			Ensure();
		}

		[HarmonyPatch(typeof(ShopApp), "Awake")]
		[HarmonyPrefix]
		private static void AddToCatalog()
		{
			Ensure();
			ShopItemData megaphoneItem = MegaphoneItem;
			ShopCatalog[] source = Resources.LoadAll<ShopCatalog>("Shop Catalogs");
			ShopCatalog val = ((IEnumerable<ShopCatalog>)source).FirstOrDefault((Func<ShopCatalog, bool>)((ShopCatalog c) => c.catalogName == "Shop_Catalog_Tier1")) ?? source.OrderBy((ShopCatalog c) => c.catalogName).FirstOrDefault();
			if (!((Object)(object)val == (Object)null) && !((Object)(object)_template == (Object)null))
			{
				if ((Object)(object)Item == (Object)null)
				{
					Item = Object.Instantiate<ShopItemData>(megaphoneItem);
					((Object)Item).name = "Shop_Walkie";
					Item.itemName = "Walkie_Name";
					Item.tagline = "Walkie_Tagline";
					Item.features = new string[3] { "Walkie_Feature1", "Walkie_Feature2", "Walkie_Feature3" };
					Item.footnote = null;
					Item.price = 1999;
					Item.maxPurchases = 2;
					Item.resetDaily = true;
					Item.icon = Icon.Invoke((HeldItem)(object)_template.GetComponent<Megaphone>()) ?? megaphoneItem.icon;
					Item.spawnPrefab = _template;
					Object.DontDestroyOnLoad((Object)(object)Item);
				}
				if (!val.items.Contains(Item))
				{
					val.items = val.items.Append(Item).ToArray();
				}
			}
		}
	}
	[HarmonyPatch(typeof(LocalizationManager), "GetText", new Type[]
	{
		typeof(string),
		typeof(Random),
		typeof(string)
	})]
	internal static class Texts
	{
		internal const string Name = "Walkie_Name";

		internal const string Tagline = "Walkie_Tagline";

		internal const string Feature1 = "Walkie_Feature1";

		internal const string Feature2 = "Walkie_Feature2";

		internal const string Feature3 = "Walkie_Feature3";

		internal const string PowerOn = "Walkie_PowerOn";

		internal const string PowerOff = "Walkie_PowerOff";

		private static readonly Dictionary<string, string> english = new Dictionary<string, string>
		{
			["Walkie_Name"] = "Walkie-Talkie",
			["Walkie_Tagline"] = "Talk to the crew from anywhere.",
			["Walkie_Feature1"] = "Hold it and use it to talk",
			["Walkie_Feature2"] = "Every switched-on walkie plays it",
			["Walkie_Feature3"] = "Works anywhere in the facility",
			["Walkie_PowerOn"] = "Switch on",
			["Walkie_PowerOff"] = "Switch off"
		};

		private static void Postfix(string key, ref string __result)
		{
			if (key != null && english.TryGetValue(key, out var value))
			{
				__result = value;
			}
		}
	}
	internal static class WalkieMesh
	{
		private static readonly Vector2 Orange = new Vector2(0.3f, 0.875f);

		private static readonly Vector2 Black = new Vector2(0.17f, 0.04f);

		private static readonly Vector2 Charcoal = new Vector2(0.52f, 0.21f);

		private static readonly Vector2 Steel = new Vector2(0.33f, 0.04f);

		private static readonly Vector2 Red = new Vector2(0.39f, 0.42f);

		internal static readonly Vector3 BodyCentre = new Vector3(0f, 0.05f, 0f);

		internal static readonly Vector3 BodySize = new Vector3(0.14f, 0.32f, 0.08f);

		private static readonly List<Vector3> verts = new List<Vector3>();

		private static readonly List<Vector3> normals = new List<Vector3>();

		private static readonly List<Vector4> tangents = new List<Vector4>();

		private static readonly List<Vector2> uvs = new List<Vector2>();

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

		internal static readonly Vector3 LedCentre = new Vector3(0f, 0.187f, -0.041f);

		internal static readonly Vector3 ScreenCentre = new Vector3(0f, 0.12f, -0.041f);

		private const string LcdFont = "digital-7 (mono) SDF";

		internal const float FontSize = 2.4f;

		internal static void Apply(GameObject root)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00da: Unknown result type (might be due to invalid IL or missing references)
			Transform val = root.transform.Find("SM_Megaphone");
			val.localPosition = Vector3.zero;
			val.localRotation = Quaternion.identity;
			((Component)val).GetComponent<MeshFilter>().sharedMesh = Build();
			Matte(((Component)val).GetComponent<MeshRenderer>());
			AddLed(root.transform, ((Renderer)((Component)val).GetComponent<MeshRenderer>()).sharedMaterial);
			BoxCollider component = root.GetComponent<BoxCollider>();
			if ((Object)(object)component != (Object)null)
			{
				component.center = BodyCentre + new Vector3(0f, 0.02f, 0f);
				component.size = BodySize + new Vector3(0.01f, 0.05f, 0.01f);
			}
			Transform val2 = root.transform.Find("Primary");
			if ((Object)(object)val2 != (Object)null)
			{
				val2.localPosition = new Vector3(0.078f, -0.06f, -0.01f);
			}
		}

		private static void Matte(MeshRenderer r)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			if ((Object)(object)r == (Object)null || (Object)(object)((Renderer)r).sharedMaterial == (Object)null)
			{
				return;
			}
			Material val = new Material(((Renderer)r).sharedMaterial)
			{
				name = ((Object)((Renderer)r).sharedMaterial).name + " (Walkie)"
			};
			string[] array = new string[2] { "_Smoothness", "_Glossiness" };
			foreach (string text in array)
			{
				if (val.HasProperty(text))
				{
					val.SetFloat(text, 0.35f);
				}
			}
			((Renderer)r).sharedMaterial = val;
		}

		internal static void AddScreen(Transform root, TMP_Text style)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: 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_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: 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)
			GameObject val = new GameObject("Display", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(root, false);
			val.transform.localPosition = ScreenCentre + new Vector3(0f, 0f, -0.0055f);
			float num = (((Object)(object)style != (Object)null) ? (style.transform.lossyScale.x / Mathf.Max(0.0001f, style.transform.root.lossyScale.x)) : 0.11f);
			val.transform.localScale = Vector3.one * num;
			TextMeshPro val2 = val.AddComponent<TextMeshPro>();
			((TMP_Text)val2).rectTransform.sizeDelta = new Vector2(0.095f, 0.055f) / num;
			TMP_FontAsset val3 = (TMP_FontAsset)(((Object)(object)style != (Object)null && (Object)(object)style.font != (Object)null) ? ((object)style.font) : ((object)(((IEnumerable<TMP_FontAsset>)Resources.FindObjectsOfTypeAll<TMP_FontAsset>()).FirstOrDefault((Func<TMP_FontAsset, bool>)((TMP_FontAsset f) => ((Object)f).name == "digital-7 (mono) SDF")) ?? TMP_Settings.defaultFontAsset)));
			if ((Object)(object)val3 != (Object)null)
			{
				((TMP_Text)val2).font = val3;
				((TMP_Text)val2).fontSharedMaterial = ((TMP_Asset)val3).material;
			}
			((Graphic)val2).color = (((Object)(object)style != (Object)null) ? new Color(((Graphic)style).color.r, ((Graphic)style).color.g, ((Graphic)style).color.b, 1f) : new Color(0.62f, 1f, 0.55f, 1f));
			((TMP_Text)val2).alignment = (TextAlignmentOptions)514;
			((TMP_Text)val2).textWrappingMode = (TextWrappingModes)0;
			Fit((TMP_Text)(object)val2);
			((TMP_Text)val2).text = "";
			Plugin.Log.LogInfo((object)("Walkie screen: " + (((object)style)?.GetType().Name ?? "no radio display") + " font '" + ((val3 != null) ? ((Object)val3).name : null) + "', " + $"scale {num:0.###}"));
		}

		internal static void Fit(TMP_Text text)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			if (text.enableAutoSizing)
			{
				text.enableAutoSizing = false;
			}
			if (!Mathf.Approximately(text.fontSize, 2.4f))
			{
				text.fontSize = 2.4f;
			}
			if ((int)text.overflowMode != 0)
			{
				text.overflowMode = (TextOverflowModes)0;
			}
		}

		private static void AddLed(Transform root, Material dark)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("LED");
			val.transform.SetParent(root, false);
			val.transform.localPosition = LedCentre;
			val.AddComponent<MeshFilter>().sharedMesh = Finish("SM_Walkie_LED", delegate
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				Box(Vector3.zero, new Vector3(0.022f, 0.012f, 0.01f), 0f, Black);
			});
			((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterial = dark;
		}

		private static Mesh Build()
		{
			return Finish("SM_Walkie", Parts);
		}

		private static Mesh Finish(string name, Action parts)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			verts.Clear();
			normals.Clear();
			tangents.Clear();
			uvs.Clear();
			tris.Clear();
			parts();
			Mesh val = new Mesh
			{
				name = name
			};
			val.SetVertices(verts);
			val.SetNormals(normals);
			val.SetTangents(tangents);
			val.SetUVs(0, uvs);
			val.SetTriangles(tris, 0);
			val.RecalculateBounds();
			return val;
		}

		private static void Parts()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_006e: 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_009b: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			Box(BodyCentre, BodySize, 0.016f, Orange);
			Box(ScreenCentre, new Vector3(0.1f, 0.065f, 0.008f), 0f, Charcoal);
			Box(new Vector3(0f, -0.03f, -0.041f), new Vector3(0.09f, 0.09f, 0.008f), 0f, Black);
			Box(new Vector3(-0.073f, 0.07f, 0f), new Vector3(0.01f, 0.07f, 0.04f), 0f, Red);
			Box(new Vector3(0f, 0.08f, 0.045f), new Vector3(0.05f, 0.12f, 0.01f), 0f, Black);
			Cylinder(new Vector3(-0.04f, 0.21f, 0f), 0.012f, 0.21f, 8, Black);
			Cylinder(new Vector3(-0.04f, 0.41f, 0f), 0.017f, 0.035f, 8, Black);
			Cylinder(new Vector3(0.035f, 0.21f, 0f), 0.019f, 0.03f, 10, Steel);
		}

		private static void Box(Vector3 centre, Vector3 size, float c, Vector2 uv)
		{
			//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_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_0083: 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_00b0: 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_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_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: 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_01ce: 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_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: 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_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: 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_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: 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_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = size * 0.5f;
			Vector3 val2 = val - Vector3.one * c;
			float[] array;
			for (int i = 0; i < 3; i++)
			{
				int num = (i + 1) % 3;
				int num2 = (i + 2) % 3;
				array = new float[2] { -1f, 1f };
				foreach (float num3 in array)
				{
					Face(centre, uv, P(i, num3 * ((Vector3)(ref val))[i], num, ((Vector3)(ref val2))[num], num2, ((Vector3)(ref val2))[num2]), P(i, num3 * ((Vector3)(ref val))[i], num, 0f - ((Vector3)(ref val2))[num], num2, ((Vector3)(ref val2))[num2]), P(i, num3 * ((Vector3)(ref val))[i], num, 0f - ((Vector3)(ref val2))[num], num2, 0f - ((Vector3)(ref val2))[num2]), P(i, num3 * ((Vector3)(ref val))[i], num, ((Vector3)(ref val2))[num], num2, 0f - ((Vector3)(ref val2))[num2]));
					float[] array2 = new float[2] { -1f, 1f };
					foreach (float num4 in array2)
					{
						Face(centre, uv, P(i, num3 * ((Vector3)(ref val))[i], num, num4 * ((Vector3)(ref val2))[num], num2, ((Vector3)(ref val2))[num2]), P(i, num3 * ((Vector3)(ref val))[i], num, num4 * ((Vector3)(ref val2))[num], num2, 0f - ((Vector3)(ref val2))[num2]), P(i, num3 * ((Vector3)(ref val2))[i], num, num4 * ((Vector3)(ref val))[num], num2, 0f - ((Vector3)(ref val2))[num2]), P(i, num3 * ((Vector3)(ref val2))[i], num, num4 * ((Vector3)(ref val))[num], num2, ((Vector3)(ref val2))[num2]));
					}
				}
			}
			array = new float[2] { -1f, 1f };
			foreach (float num5 in array)
			{
				float[] array2 = new float[2] { -1f, 1f };
				foreach (float num6 in array2)
				{
					float[] array3 = new float[2] { -1f, 1f };
					foreach (float num7 in array3)
					{
						Face(centre, uv, new Vector3(num5 * val.x, num6 * val2.y, num7 * val2.z), new Vector3(num5 * val2.x, num6 * val.y, num7 * val2.z), new Vector3(num5 * val2.x, num6 * val2.y, num7 * val.z));
					}
				}
			}
		}

		private static Vector3 P(int a, float va, int b, float vb, int d, float vd)
		{
			//IL_0002: 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)
			Vector3 result = default(Vector3);
			((Vector3)(ref result))[a] = va;
			((Vector3)(ref result))[b] = vb;
			((Vector3)(ref result))[d] = vd;
			return result;
		}

		private static void Cylinder(Vector3 bottom, float r, float height, int n, Vector2 uv)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_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_0069: 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_0074: 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_007a: 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_0086: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: 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_0103: 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_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = bottom + Vector3.up * height * 0.5f;
			Vector3[] array = (Vector3[])(object)new Vector3[n];
			Vector3[] array2 = (Vector3[])(object)new Vector3[n];
			Vector3 val2 = default(Vector3);
			for (int i = 0; i < n; i++)
			{
				float num = (float)i * (float)Math.PI * 2f / (float)n;
				((Vector3)(ref val2))..ctor(Mathf.Cos(num) * r, 0f, Mathf.Sin(num) * r);
				array[i] = bottom + val2 + Vector3.up * height - val;
				array2[i] = bottom + val2 - val;
			}
			for (int j = 0; j < n; j++)
			{
				int num2 = (j + 1) % n;
				Face(val, uv, array2[j], array2[num2], array[num2], array[j]);
			}
			Face(val, uv, array);
			Face(val, uv, array2);
		}

		private static void Face(Vector3 centre, Vector2 uv, params Vector3[] pts)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			if (pts.Length < 3)
			{
				return;
			}
			Vector3 val = Vector3.zero;
			Vector3[] array = pts;
			foreach (Vector3 val2 in array)
			{
				val += val2;
			}
			val /= (float)pts.Length;
			Vector3 val3 = Vector3.Cross(pts[1] - pts[0], pts[2] - pts[0]);
			if (!(((Vector3)(ref val3)).sqrMagnitude < 1E-12f))
			{
				if (Vector3.Dot(val3, val) < 0f)
				{
					Array.Reverse((Array)pts);
					val3 = -val3;
				}
				((Vector3)(ref val3)).Normalize();
				Vector4 item = PaletteMesh.Tangent(val3);
				int count = verts.Count;
				array = pts;
				foreach (Vector3 val4 in array)
				{
					verts.Add(centre + val4);
					normals.Add(val3);
					tangents.Add(item);
					uvs.Add(uv);
				}
				for (int j = 1; j + 1 < pts.Length; j++)
				{
					tris.Add(count);
					tris.Add(count + j);
					tris.Add(count + j + 1);
				}
			}
		}
	}
}