Decompiled source of RepoTV v1.1.2

plugins/RepoTV.dll

Decompiled a day ago
using System;
using System.Collections;
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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using REPOLib.Modules;
using RepoTV.Model;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.Rendering;
using UnityEngine.Video;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RepoTV")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RepoTV")]
[assembly: AssemblyTitle("RepoTV")]
[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 RepoTV
{
	internal static class CartPrefabBuilder
	{
		private const string BaseResourcePath = "Items/Item Cart Medium";

		public const string PrefabName = "Item TV Cart";

		private static readonly Quaternion AvToCart = Quaternion.Euler(0f, 90f, 0f);

		private static Vector3 R(Vector3 v)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(v.z, v.y, 0f - v.x);
		}

		private static Vector3 RS(Vector3 s)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(s.z, s.y, s.x);
		}

		public static void BuildAndRegister()
		{
			//IL_0141: 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_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: 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_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: 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_02b0: 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_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: 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_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_042d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0438: Unknown result type (might be due to invalid IL or missing references)
			//IL_0462: Unknown result type (might be due to invalid IL or missing references)
			//IL_047c: 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_03ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_050d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0519: Unknown result type (might be due to invalid IL or missing references)
			//IL_054f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0556: Expected O, but got Unknown
			//IL_0583: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_06dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0615: Unknown result type (might be due to invalid IL or missing references)
			//IL_0632: Unknown result type (might be due to invalid IL or missing references)
			//IL_0637: Unknown result type (might be due to invalid IL or missing references)
			//IL_063b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0656: Unknown result type (might be due to invalid IL or missing references)
			//IL_0715: Unknown result type (might be due to invalid IL or missing references)
			//IL_0726: Unknown result type (might be due to invalid IL or missing references)
			//IL_072b: Unknown result type (might be due to invalid IL or missing references)
			//IL_074b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0750: Unknown result type (might be due to invalid IL or missing references)
			//IL_0754: Unknown result type (might be due to invalid IL or missing references)
			//IL_076f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0790: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0672: Unknown result type (might be due to invalid IL or missing references)
			//IL_0679: Expected O, but got Unknown
			//IL_082e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0840: Unknown result type (might be due to invalid IL or missing references)
			//IL_0850: Unknown result type (might be due to invalid IL or missing references)
			//IL_0885: Unknown result type (might be due to invalid IL or missing references)
			//IL_0887: Unknown result type (might be due to invalid IL or missing references)
			//IL_0899: Unknown result type (might be due to invalid IL or missing references)
			//IL_080b: Unknown result type (might be due to invalid IL or missing references)
			//IL_068e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0693: Unknown result type (might be due to invalid IL or missing references)
			//IL_0697: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a8: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)TvPrefabBuilder.BodyMat == (Object)null)
			{
				throw new Exception("TV materials missing (the TV item failed to build).");
			}
			GameObject obj = Resources.Load<GameObject>("Items/Item Cart Medium");
			if ((Object)(object)obj == (Object)null)
			{
				throw new Exception("Base item \"Items/Item Cart Medium\" not found. The game may have been updated.");
			}
			Item val = obj.GetComponent<ItemAttributes>()?.item;
			if ((Object)(object)val == (Object)null)
			{
				throw new Exception("Base Item asset for the Medium Cart not found.");
			}
			GameObject val2 = Object.Instantiate<GameObject>(obj, TvPrefabBuilder.Holder.transform);
			((Object)val2).name = "Item TV Cart";
			int layer = val2.layer;
			Transform transform = val2.transform;
			float num = -0.5f;
			float num2 = 0.92f;
			float num3 = 0.64f;
			float num4 = -0.3f;
			float num5 = 0.36f;
			float num6 = 0.025f;
			float num7 = 0.12f;
			float num8 = num3;
			float num9 = num2;
			Renderer[] componentsInChildren = val2.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val3 in componentsInChildren)
			{
				if (!IsUnder(((Component)val3).transform, transform, "Cart Handle"))
				{
					val3.enabled = false;
				}
			}
			Transform val4 = transform.Find("Screen");
			if (Object.op_Implicit((Object)(object)val4))
			{
				Light[] componentsInChildren2 = ((Component)val4).GetComponentsInChildren<Light>(true);
				for (int i = 0; i < componentsInChildren2.Length; i++)
				{
					((Behaviour)componentsInChildren2[i]).enabled = false;
				}
			}
			Vector3 val5 = UnityConvert.V(CartGeometry.TvOffset);
			float num10 = 0.505f;
			(string, Vector3, Vector3)[] array = new(string, Vector3, Vector3)[7]
			{
				("Front Lip", new Vector3(0f, num4 + num7 / 2f, num3 / 2f - 0.01f), new Vector3(num2, num7, 0.02f)),
				("Back Lip", new Vector3(0f, num4 + num7 / 2f, (0f - num3) / 2f + 0.01f), new Vector3(num2, num7, 0.02f)),
				("Left Lip", new Vector3(num2 / 2f - 0.01f, num4 + num7 / 2f, 0f), new Vector3(0.02f, num7, num3)),
				("Right Lip", new Vector3((0f - num2) / 2f + 0.01f, num4 + num7 / 2f, 0f), new Vector3(0.02f, num7, num3)),
				("Top Shelf", new Vector3(0f, num5 - num6 / 2f, 0f), new Vector3(num2, num6, num3)),
				("TV Body", val5 + new Vector3(0f, num10 / 2f, 0.01f), new Vector3(0.72f, num10, 0.32000002f)),
				("TV Back", val5 + new Vector3(0f, TvGeometry.BodyCenterY - 0.02f, -0.25f), new Vector3(0.48f, 0.36f, 0.2f))
			};
			List<Transform> list = (from Transform t in (IEnumerable)transform
				where ((Object)t).name.Contains("Cart Wall Collider")
				select t).ToList();
			if (list.Count == 0)
			{
				throw new Exception("Medium Cart has no wall colliders; the game may have changed.");
			}
			while (list.Count < array.Length)
			{
				GameObject val6 = Object.Instantiate<GameObject>(((Component)list[0]).gameObject, transform);
				((Object)val6).name = ((Object)list[0]).name;
				list.Add(val6.transform);
			}
			for (int num11 = 0; num11 < list.Count; num11++)
			{
				if (num11 < array.Length)
				{
					PlaceBox(list[num11], R(array[num11].Item2), RS(array[num11].Item3));
				}
				else
				{
					Object.DestroyImmediate((Object)(object)((Component)list[num11]).gameObject);
				}
			}
			PlaceBox(transform.Find("Inside"), new Vector3(0f, num4 - num6 / 2f, 0f), new Vector3(num8, num6, num9));
			PlaceBox(transform.Find("Phys Object Collider"), new Vector3(0f, num4 - num6 - 0.01f, 0f), new Vector3(num8 - 0.04f, 0.02f, num9 - 0.04f));
			Transform val7 = transform.Find("In Cart");
			if (Object.op_Implicit((Object)(object)val7))
			{
				val7.localPosition = new Vector3(0f, (num4 + num5 - num6) / 2f, 0f);
				val7.localRotation = Quaternion.identity;
				val7.localScale = new Vector3(num8 - 0.04f, num5 - num6 - num4 - 0.02f, num9 - 0.04f);
				BoxCollider component = ((Component)val7).GetComponent<BoxCollider>();
				if (Object.op_Implicit((Object)(object)component))
				{
					component.center = Vector3.zero;
					component.size = Vector3.one;
				}
			}
			float[] array2 = new float[3] { -0.2f, 0f, 0.2f };
			int num12 = 0;
			foreach (Transform item2 in transform)
			{
				Transform val8 = item2;
				if (((Object)val8).name.Contains("Capsule"))
				{
					val8.localPosition = new Vector3(array2[Mathf.Min(num12, 2)], num + 0.25f, 0f);
					val8.localScale = new Vector3(0.5f, (num9 - 0.04f) / 2f, 0.5f);
					num12++;
				}
			}
			Vector3 val9 = default(Vector3);
			((Vector3)(ref val9))..ctor(0f, num5 + 0.1f, (0f - num9) / 2f - 0.04f);
			Transform val10 = transform.Find("Cart Handle");
			Quaternion val11;
			if (Object.op_Implicit((Object)(object)val10))
			{
				val10.localPosition = val9;
				val11 = new Quaternion(0f, 1f, 0.07f, 0f);
				val10.localRotation = ((Quaternion)(ref val11)).normalized;
				val10.localScale = new Vector3(2.1f, 0.64f, 0.64f);
				foreach (Transform item3 in val10)
				{
					Transform val12 = item3;
					if (((Object)val12).name.StartsWith("Grab"))
					{
						Vector3 localPosition = val12.localPosition;
						val12.localPosition = new Vector3(localPosition.x, 0f, 0f);
					}
				}
			}
			TvPrefabBuilder.SetLocal(transform.Find("Cart Grab Point"), val9 + new Vector3(0f, 0f, -0.01f));
			Transform val13 = transform.Find("Grab Area");
			if (Object.op_Implicit((Object)(object)val13))
			{
				val13.localPosition = val9 + new Vector3(0f, 0f, 0.04f);
				val11 = new Quaternion(0.23f, 0f, 0f, 0.97f);
				val13.localRotation = ((Quaternion)(ref val11)).normalized;
				val13.localScale = new Vector3(0.7f, 0.26f, 0.17f);
			}
			if (Object.op_Implicit((Object)(object)val4))
			{
				val4.localPosition = new Vector3(0f, num4, 0f);
			}
			Transform val14 = transform.Find("Thrust Effect");
			if (Object.op_Implicit((Object)(object)val14))
			{
				val14.localPosition = new Vector3(0f, num + 0.17f, 0f);
				val14.localScale = new Vector3(num8, num9, 0.15f);
			}
			ItemVolume componentInChildren = val2.GetComponentInChildren<ItemVolume>(true);
			if (Object.op_Implicit((Object)(object)componentInChildren))
			{
				((Component)componentInChildren).transform.localPosition = new Vector3(0f, 0.1f, 0f);
			}
			TvPrefabBuilder.NewChild(transform, "Center of Mass", layer, new Vector3(0f, num + 0.3f, 0f));
			GameObject obj2 = TvPrefabBuilder.NewChild(transform, "AV Cart Mesh", layer, Vector3.zero);
			obj2.transform.localRotation = AvToCart;
			obj2.AddComponent<MeshFilter>().sharedMesh = UnityConvert.ToMesh(CartGeometry.Build(), "RepoTV AV Cart");
			((Renderer)obj2.AddComponent<MeshRenderer>()).sharedMaterial = TvPrefabBuilder.BodyMat;
			TvPrefabBuilder.AddTv(val2, transform, R(val5), layer).tvRoot.localRotation = AvToCart;
			Item item = TvPrefabBuilder.CloneItem(val, "Item TV Cart", "TV Cart", "A school AV cart with a TV strapped on top. Push it around and haul loot on the bottom shelf.");
			val2.GetComponent<ItemAttributes>().item = item;
			if (Items.RegisterItem(val2.GetComponent<ItemAttributes>()) == null)
			{
				throw new Exception("REPOLib refused to register the TV Cart (see REPOLib errors above).");
			}
			Plugin.Log.LogInfo((object)"Registered the TV Cart item.");
		}

		private static void PlaceBox(Transform part, Vector3 centre, Vector3 size)
		{
			//IL_000a: 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_007e: 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_003b: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)part))
			{
				return;
			}
			part.localPosition = centre;
			part.localRotation = Quaternion.identity;
			Transform val = part.Find("Semi Box Collider");
			if (Object.op_Implicit((Object)(object)val))
			{
				part.localScale = Vector3.one;
				val.localPosition = Vector3.zero;
				val.localRotation = Quaternion.identity;
				val.localScale = size;
				BoxCollider component = ((Component)val).GetComponent<BoxCollider>();
				if (Object.op_Implicit((Object)(object)component))
				{
					component.center = Vector3.zero;
					component.size = Vector3.one;
				}
			}
			else
			{
				part.localScale = size;
			}
		}

		private static bool IsUnder(Transform t, Transform root, string childName)
		{
			Transform val = t;
			while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)root)
			{
				if ((Object)(object)val.parent == (Object)(object)root && ((Object)val).name == childName)
				{
					return true;
				}
				val = val.parent;
			}
			return false;
		}
	}
	internal static class FlatPrefabBuilder
	{
		public const string ShopPrefabName = "Item 8K TV";

		public const string LootPrefabName = "Valuable 8K TV";

		private const string LootBasePath = "Valuables/05 Wide/Valuable Arctic Sample Cooler Wide";

		internal static PrefabRef LootRef;

		private static (string, Vector3, Vector3)[] Boxes(Vector3 o)
		{
			//IL_001f: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: 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_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_00e0: 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_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			float num = 0.14f;
			float panelTop = FlatGeometry.PanelTop;
			float num2 = 1.4f;
			return new(string, Vector3, Vector3)[4]
			{
				("8K Panel Collider", o + new Vector3(0f, (num + panelTop) / 2f, 0f), new Vector3(FlatGeometry.PanelW, panelTop - num, 0.08f)),
				("8K Back Collider", o + new Vector3(0f, FlatGeometry.ScreenCy - 0.05f * num2, -0.035f - 0.025f * num2), new Vector3(0.9f, 0.56f, 0.06f) * num2),
				("8K Base Collider", o + new Vector3(0f, 0.012f * num2, 0f), new Vector3(0.66f, 0.024f, 0.26f) * num2),
				("8K Neck Collider", o + new Vector3(0f, (0.024f * num2 + num + 0.06f * num2) / 2f, 0f - 0.035f * num2), new Vector3(0.1f * num2, num + 0.036f * num2, 0.03f * num2))
			};
		}

		public static void BuildShopItem()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: 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_0107: Unknown result type (might be due to invalid IL or missing references)
			float num = (0.14f + FlatGeometry.PanelTop) / 2f;
			TvPrefabBuilder.BuildTrackerTv(new TvPrefabBuilder.TrackerTvSpec
			{
				PrefabName = "Item 8K TV",
				DisplayName = "8K TV",
				Description = "A 105 inch 8K flat-screen. Absolutely enormous. Plays whatever is in your Television Videos folders.",
				Layout = TvLayout.Flat,
				Body = FlatGeometry.Build(includeControls: false),
				Boxes = Boxes(Vector3.zero),
				Centre = new Vector3(0f, num, 0f),
				GrabPoint = new Vector3(0f, num, 0.03f),
				IconPos = new Vector3(1.7f, 1.5f, 3.1f),
				FreeGrab = true,
				SlotHalfHeight = 0.43f,
				CenterOfMass = new Vector3(0f, 0.35f, 0f),
				Mass = Plugin.FlatMass.Value,
				ShopSlot = (itemVolume)3,
				SpawnRotation = Quaternion.Euler(0f, 90f, 0f)
			});
		}

		public static void BuildLoot()
		{
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: 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_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)TvPrefabBuilder.BodyMat == (Object)null)
			{
				throw new Exception("TV materials missing (the TV item failed to build).");
			}
			GameObject obj = Resources.Load<GameObject>("Valuables/05 Wide/Valuable Arctic Sample Cooler Wide");
			if ((Object)(object)obj == (Object)null)
			{
				throw new Exception("Base valuable \"Valuables/05 Wide/Valuable Arctic Sample Cooler Wide\" not found. The game may have been updated.");
			}
			GameObject val = Object.Instantiate<GameObject>(obj, TvPrefabBuilder.Holder.transform);
			((Object)val).name = "Valuable 8K TV";
			int layer = val.layer;
			Transform transform = val.transform;
			Transform val2 = transform.Find("Object");
			BoxCollider? obj2 = ((IEnumerable<BoxCollider>)val.GetComponentsInChildren<BoxCollider>(true)).FirstOrDefault((Func<BoxCollider, bool>)((BoxCollider b) => !((Collider)b).isTrigger));
			GameObject val3 = ((obj2 != null) ? ((Component)obj2).gameObject : null);
			if ((Object)(object)val3 == (Object)null)
			{
				throw new Exception("Base valuable has no collider to copy.");
			}
			val3.transform.SetParent(transform, false);
			if (Object.op_Implicit((Object)(object)val2))
			{
				Object.DestroyImmediate((Object)(object)((Component)val2).gameObject);
			}
			Vector3 val4 = default(Vector3);
			((Vector3)(ref val4))..ctor(0f, 0f, 0.5f);
			(string, Vector3, Vector3)[] array = Boxes(val4);
			for (int num = 0; num < array.Length; num++)
			{
				GameObject obj3 = ((num == 0) ? val3 : Object.Instantiate<GameObject>(val3, transform));
				((Object)obj3).name = array[num].Item1;
				obj3.transform.localPosition = array[num].Item2;
				obj3.transform.localRotation = Quaternion.identity;
				obj3.transform.localScale = array[num].Item3;
				BoxCollider component = obj3.GetComponent<BoxCollider>();
				component.center = Vector3.zero;
				component.size = Vector3.one;
			}
			TvPrefabBuilder.AddTv(val, transform, val4, layer, TvLayout.Flat, FlatGeometry.Build(includeControls: false));
			TvPrefabBuilder.NewChild(transform, "Center of Mass", layer, val4 + new Vector3(0f, 0.35f, 0f));
			if ((LootRef = Valuables.RegisterValuable(val.GetComponent<ValuableObject>())) == null)
			{
				throw new Exception("REPOLib refused to register the 8K TV valuable (see REPOLib errors above).");
			}
			Plugin.Log.LogInfo((object)"Registered the 8K TV as loot (spawns in Wide spots in every level).");
		}
	}
	[HarmonyPatch]
	internal static class InputPatches
	{
		internal static bool ScrollCaptured => Time.frameCount - TvController.ScrollCaptureFrame <= 1;

		private static bool GrabCaptured
		{
			get
			{
				if (!TvController.BypassInputPatch)
				{
					return Time.frameCount - TvController.GrabCaptureFrame <= 1;
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(InputManager), "KeyPullAndPush")]
		[HarmonyPostfix]
		private static void KeyPullAndPush(ref float __result)
		{
			if (ScrollCaptured)
			{
				__result = 0f;
			}
		}

		[HarmonyPatch(typeof(InputManager), "KeyPullAndPushAnalog")]
		[HarmonyPostfix]
		private static void KeyPullAndPushAnalog(ref bool __result, ref float axis)
		{
			if (ScrollCaptured)
			{
				__result = false;
				axis = 0f;
			}
		}

		[HarmonyPatch(typeof(InputManager), "KeyDown")]
		[HarmonyPostfix]
		private static void KeyDown(InputKey key, ref bool __result)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			if (__result && (int)key == 10 && GrabCaptured)
			{
				__result = false;
			}
		}

		[HarmonyPatch(typeof(InputManager), "KeyHold")]
		[HarmonyPostfix]
		private static void KeyHold(InputKey key, ref bool __result)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			if (__result && (int)key == 10 && GrabCaptured)
			{
				__result = false;
			}
		}

		[HarmonyPatch(typeof(ItemManager), "GetPurchasedItems")]
		[HarmonyPrefix]
		private static void GiveTestTv()
		{
			if (!Plugin.StartWithTV.Value || !Object.op_Implicit((Object)(object)StatsManager.instance))
			{
				return;
			}
			Dictionary<string, int> itemsPurchased = StatsManager.instance.itemsPurchased;
			string[] array = new string[1] { "Item Television" };
			foreach (string key in array)
			{
				if (StatsManager.instance.itemDictionary.ContainsKey(key) && (!itemsPurchased.TryGetValue(key, out var value) || value < 1))
				{
					itemsPurchased[key] = 1;
				}
			}
		}
	}
	[BepInPlugin("zackkkk.repotv", "RepoTV", "1.1.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "zackkkk.repotv";

		public const string Name = "RepoTV";

		public const string Version = "1.1.2";

		internal static ManualLogSource Log;

		internal static ConfigEntry<float> DefaultVolume;

		internal static ConfigEntry<float> MaxVolume;

		internal static ConfigEntry<float> HearingDistance;

		internal static ConfigEntry<float> Mass;

		internal static ConfigEntry<float> AngularDamping;

		internal static ConfigEntry<float> LinearDamping;

		internal static ConfigEntry<float> PriceMultiplier;

		internal static ConfigEntry<float> ScreenBrightness;

		internal static ConfigEntry<bool> ShuffleOnFirstPowerOn;

		internal static ConfigEntry<bool> StartWithTV;

		internal static ConfigEntry<bool> EnableTvCart;

		internal static ConfigEntry<bool> Enable8KTV;

		internal static ConfigEntry<bool> FlatscreenLoot;

		internal static ConfigEntry<float> FlatMass;

		private void Awake()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Expected O, but got Unknown
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Expected O, but got Unknown
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Expected O, but got Unknown
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Expected O, but got Unknown
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Expected O, but got Unknown
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Expected O, but got Unknown
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Expected O, but got Unknown
			//IL_02df: 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)
			Log = ((BaseUnityPlugin)this).Logger;
			DefaultVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "DefaultVolume", 0.5f, new ConfigDescription("Volume knob position when a TV spawns (0-1).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			MaxVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "MaxVolume", 1f, new ConfigDescription("Loudness of the TV when the knob is turned all the way up (0-1).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			HearingDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "HearingDistance", 20f, new ConfigDescription("How far away (metres) the TV can be heard.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 60f), Array.Empty<object>()));
			ScreenBrightness = ((BaseUnityPlugin)this).Config.Bind<float>("Video", "ScreenBrightness", 0.55f, new ConfigDescription("Base picture brightness (the BRIGHT slider on the TV scales this x0.4 to x1.6). Lower it if REPO's bloom washes videos out.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.2f, 1.5f), Array.Empty<object>()));
			Mass = ((BaseUnityPlugin)this).Config.Bind<float>("Item", "Mass", 2.4f, new ConfigDescription("How heavy the TV is to carry. REPO's scale: Light 0.5-0.8, Medium 1-3.5, Heavy 4-6, Very Heavy 8.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 15f), Array.Empty<object>()));
			AngularDamping = ((BaseUnityPlugin)this).Config.Bind<float>("Item", "SpinDamping", 6f, new ConfigDescription("How quickly the TV stops spinning when carried or knocked.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 20f), Array.Empty<object>()));
			LinearDamping = ((BaseUnityPlugin)this).Config.Bind<float>("Item", "DriftDamping", 1.5f, new ConfigDescription("How quickly the TV stops sliding/drifting.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
			PriceMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Item", "PriceMultiplier", 1f, new ConfigDescription("Shop price relative to the base item (host's setting is used).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 10f), Array.Empty<object>()));
			EnableTvCart = ((BaseUnityPlugin)this).Config.Bind<bool>("Item", "EnableTvCart", true, "Adds the TV Cart (a pushable AV cart with a TV on top) to the shop. Everyone in the lobby should use the same setting.");
			Enable8KTV = ((BaseUnityPlugin)this).Config.Bind<bool>("Item", "Enable8KTV", true, "Adds the 75 inch 8K TV to the shop. Everyone in the lobby should use the same setting.");
			FlatscreenLoot = ((BaseUnityPlugin)this).Config.Bind<bool>("Item", "FlatscreenLoot", true, "The 8K TV also spawns as loot in levels (a valuable you can sell, which still works as a TV). Everyone in the lobby should use the same setting.");
			FlatMass = ((BaseUnityPlugin)this).Config.Bind<float>("Item", "FlatMass", 4f, new ConfigDescription("How heavy the shop 8K TV is to carry (REPO's Heavy is 4).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 15f), Array.Empty<object>()));
			StartWithTV = ((BaseUnityPlugin)this).Config.Bind<bool>("Testing", "StartWithTV", false, "If true (host only), every run starts with a free CRT TV in the truck, like the starting cart.");
			ShuffleOnFirstPowerOn = ((BaseUnityPlugin)this).Config.Bind<bool>("Videos", "StartOnRandomChannel", true, "If true, a TV that is switched on for the first time starts on a random video instead of the first one.");
			VideoLibrary.Scan();
			Log.LogInfo((object)$"Colour space: {QualitySettings.activeColorSpace}");
			new Harmony("zackkkk.repotv").PatchAll(typeof(InputPatches));
			try
			{
				TvPrefabBuilder.BuildAndRegister();
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Failed to build the TV item: " + ex));
			}
			if (Enable8KTV.Value)
			{
				try
				{
					FlatPrefabBuilder.BuildShopItem();
				}
				catch (Exception ex2)
				{
					Log.LogError((object)("Failed to build the 8K TV item: " + ex2));
				}
			}
			if (FlatscreenLoot.Value)
			{
				try
				{
					FlatPrefabBuilder.BuildLoot();
				}
				catch (Exception ex3)
				{
					Log.LogError((object)("Failed to build the 8K TV loot: " + ex3));
				}
			}
			if (EnableTvCart.Value)
			{
				try
				{
					CartPrefabBuilder.BuildAndRegister();
				}
				catch (Exception ex4)
				{
					Log.LogError((object)("Failed to build the TV Cart item: " + ex4));
				}
			}
		}
	}
	public class TvController : MonoBehaviour
	{
		public Transform tvRoot;

		public int layoutId;

		public MeshRenderer bodyRenderer;

		public Transform channelUp;

		public Transform channelDown;

		public Transform volumeKnob;

		public Transform powerButton;

		public Transform shuffleSwitch;

		public Transform shuffleLever;

		public Transform brightnessKnob;

		public MeshRenderer ledRenderer;

		public Material ledOnMaterial;

		public Material ledOffMaterial;

		public VideoPlayer videoPlayer;

		public AudioSource audioSource;

		public AudioSource staticSource;

		internal static int ScrollCaptureFrame = -100;

		internal static int GrabCaptureFrame = -100;

		internal static bool BypassInputPatch;

		private const float InteractRange = 3f;

		private const float VolumeStep = 0.05f;

		private const float KnobSweep = 135f;

		private const float StaticLoudness = 0.35f;

		private const double StartLead = 0.53;

		private static readonly FieldRef<PlayerController, float> InputDisableTimer = AccessTools.FieldRefAccess<PlayerController, float>("InputDisableTimer");

		private static readonly FieldRef<PhysGrabObject, bool> HeldByLocalPlayer = AccessTools.FieldRefAccess<PhysGrabObject, bool>("heldByLocalPlayer");

		private static readonly FieldRef<ItemToggle, bool> ToggleDisabled = AccessTools.FieldRefAccess<ItemToggle, bool>("disabled");

		private static readonly FieldRef<ItemEquippable, bool> IsEquipped = AccessTools.FieldRefAccess<ItemEquippable, bool>("isEquipped");

		private PhotonView photonView;

		private ItemToggle itemToggle;

		private PhysGrabObject physGrabObject;

		private ItemEquippable itemEquippable;

		private Material screenMaterial;

		private RenderTexture renderTexture;

		private bool powered;

		private string currentVideo;

		private double videoStartTime;

		private float volume;

		private bool everPlayed;

		private bool shuffle;

		private readonly List<string> history = new List<string>();

		private float leverAngle = -32f;

		private float brightness = 0.5f;

		private bool brightnessDirty;

		private float brightnessSendTimer;

		private float lastPlayMessageTime = -100f;

		private bool awaitingPlay;

		private float awaitingTimer;

		private bool waitingForStart;

		private bool noSignal;

		private bool preparing;

		private float volumeSendTimer;

		private bool volumeDirty;

		private TvGeometry.Control? aimed;

		private float channelUpPress;

		private float channelDownPress;

		private float powerPress;

		private float channelSpin;

		private bool ownPower;

		private float lastTint = -1f;

		private TvLayout Layout => TvLayout.Get(layoutId);

		private bool IsPoweredState
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)itemToggle))
				{
					return ownPower;
				}
				return itemToggle.toggleState;
			}
		}

		private float PictureBrightness => Plugin.ScreenBrightness.Value * Mathf.Lerp(0.4f, 1.6f, brightness);

		private void Awake()
		{
			photonView = ((Component)this).GetComponent<PhotonView>();
			itemToggle = ((Component)this).GetComponent<ItemToggle>();
			if (!Object.op_Implicit((Object)(object)tvRoot))
			{
				tvRoot = ((Component)this).transform;
			}
			physGrabObject = ((Component)this).GetComponent<PhysGrabObject>();
			itemEquippable = ((Component)this).GetComponent<ItemEquippable>();
			volume = Plugin.DefaultVolume.Value;
		}

		private void Start()
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Expected O, but got Unknown
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Expected O, but got Unknown
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Expected O, but got Unknown
			if (Object.op_Implicit((Object)(object)itemToggle))
			{
				ToggleDisabled.Invoke(itemToggle) = true;
			}
			Material[] materials = ((Renderer)bodyRenderer).materials;
			screenMaterial = ((materials.Length > 1) ? materials[1] : null);
			renderTexture = new RenderTexture(Layout.RenderWidth, Layout.RenderHeight, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)2)
			{
				name = "RepoTV Screen RT",
				useMipMap = true,
				autoGenerateMips = true,
				filterMode = (FilterMode)2,
				anisoLevel = 4
			};
			renderTexture.Create();
			videoPlayer.targetTexture = renderTexture;
			videoPlayer.prepareCompleted += new EventHandler(OnPrepared);
			videoPlayer.loopPointReached += new EventHandler(OnVideoEnded);
			videoPlayer.errorReceived += (ErrorEventHandler)delegate(VideoPlayer vp, string msg)
			{
				Plugin.Log.LogWarning((object)("Video error on \"" + currentVideo + "\": " + msg));
				noSignal = true;
				preparing = false;
			};
			if (Object.op_Implicit((Object)(object)AudioManager.instance) && Object.op_Implicit((Object)(object)AudioManager.instance.SoundMasterGroup))
			{
				AudioMixerGroup[] array = AudioManager.instance.SoundMasterGroup.audioMixer.FindMatchingGroups("Sound Effects");
				audioSource.outputAudioMixerGroup = ((array.Length != 0) ? array[0] : AudioManager.instance.SoundMasterGroup);
				if (Object.op_Implicit((Object)(object)staticSource))
				{
					staticSource.outputAudioMixerGroup = audioSource.outputAudioMixerGroup;
				}
			}
			ApplyVolume();
			ApplyScreen();
		}

		private void OnDestroy()
		{
			if (Object.op_Implicit((Object)(object)renderTexture))
			{
				renderTexture.Release();
				Object.Destroy((Object)(object)renderTexture);
			}
		}

		private void Update()
		{
			bool isPoweredState = IsPoweredState;
			if (isPoweredState != powered)
			{
				OnPowerChanged(isPoweredState);
			}
			if (waitingForStart && powered && NetTime() >= videoStartTime)
			{
				waitingForStart = false;
				videoPlayer.Play();
			}
			if (awaitingPlay)
			{
				awaitingTimer += Time.deltaTime;
				if (awaitingTimer > 1f && SemiFunc.IsMasterClientOrSingleplayer())
				{
					awaitingPlay = false;
					BroadcastPlay(currentVideo ?? PickStartVideo());
				}
			}
			HandleLocalInput();
			SendVolumeIfDirty();
			Animate();
			ApplyScreen();
		}

		private void HandleLocalInput()
		{
			aimed = null;
			if ((Object.op_Implicit((Object)(object)itemEquippable) && IsEquipped.Invoke(itemEquippable)) || !Object.op_Implicit((Object)(object)PlayerController.instance) || InputDisableTimer.Invoke(PlayerController.instance) > 0f)
			{
				return;
			}
			aimed = FindAimedControl();
			if (aimed == TvGeometry.Control.Volume || aimed == TvGeometry.Control.Brightness)
			{
				ScrollCaptureFrame = Time.frameCount;
				float num = (Object.op_Implicit((Object)(object)InputManager.instance) ? InputManager.instance.GetScrollY(false) : 0f);
				if (num != 0f && aimed == TvGeometry.Control.Volume)
				{
					volume = Mathf.Clamp01(volume + Mathf.Sign(num) * 0.05f);
					volumeDirty = true;
					ApplyVolume();
				}
				else if (num != 0f)
				{
					brightness = Mathf.Clamp01(brightness + Mathf.Sign(num) * 0.05f);
					brightnessDirty = true;
				}
			}
			bool flag = Object.op_Implicit((Object)(object)PhysGrabber.instance) && PhysGrabber.instance.grabbed;
			bool flag2 = false;
			if (aimed.HasValue && !flag)
			{
				GrabCaptureFrame = Time.frameCount;
				BypassInputPatch = true;
				try
				{
					flag2 = SemiFunc.InputDown((InputKey)10);
				}
				finally
				{
					BypassInputPatch = false;
				}
			}
			if ((!flag2 && !SemiFunc.InputDown((InputKey)2)) || (flag2 && (aimed == TvGeometry.Control.Volume || aimed == TvGeometry.Control.Brightness)))
			{
				return;
			}
			switch (aimed)
			{
			case TvGeometry.Control.ChannelUp:
				PressChannel(1);
				return;
			case TvGeometry.Control.ChannelDown:
				PressChannel(-1);
				return;
			case TvGeometry.Control.Power:
				PressPower();
				return;
			case TvGeometry.Control.Shuffle:
				PressShuffle();
				return;
			case TvGeometry.Control.Volume:
			case TvGeometry.Control.Brightness:
				return;
			}
			if (Object.op_Implicit((Object)(object)physGrabObject) && HeldByLocalPlayer.Invoke(physGrabObject))
			{
				PressPower();
			}
		}

		private TvGeometry.Control? FindAimedControl()
		{
			//IL_0021: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: 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_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: 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_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: 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)
			Camera main = Camera.main;
			if (!Object.op_Implicit((Object)(object)main))
			{
				return null;
			}
			Ray val = default(Ray);
			((Ray)(ref val))..ctor(((Component)main).transform.position, ((Component)main).transform.forward);
			float x = tvRoot.lossyScale.x;
			TvGeometry.Control? result = null;
			float num = float.MaxValue;
			foreach (TvGeometry.Control value in Enum.GetValues(typeof(TvGeometry.Control)))
			{
				int num2 = ((value != TvGeometry.Control.Brightness) ? 1 : 9);
				for (int i = 0; i < num2; i++)
				{
					float num3 = ((num2 == 1) ? 0f : (Mathf.Lerp(-1f, 1f, (float)i / ((float)num2 - 1f)) * (Layout.SliderHalfTravel + 0.008f * Layout.ControlScale)));
					Vector3 val2 = tvRoot.TransformPoint(UnityConvert.V(Layout.Pos(value)) + new Vector3(num3, 0f, 0.012f * Layout.ControlScale));
					float num4 = Layout.HitRadius(value) * x;
					Vector3 val3 = val2 - ((Ray)(ref val)).origin;
					float num5 = Vector3.Dot(val3, ((Ray)(ref val)).direction);
					if (!(num5 < 0f) && !(num5 > 3f))
					{
						Vector3 val4 = val3 - ((Ray)(ref val)).direction * num5;
						if (!(((Vector3)(ref val4)).sqrMagnitude > num4 * num4) && num5 < num)
						{
							num = num5;
							result = value;
						}
					}
				}
			}
			if (!result.HasValue)
			{
				return null;
			}
			RaycastHit val5 = default(RaycastHit);
			if (Physics.Raycast(val, ref val5, num, -1, (QueryTriggerInteraction)1) && ((RaycastHit)(ref val5)).distance < num - 0.06f && !((Component)((RaycastHit)(ref val5)).collider).transform.IsChildOf(((Component)this).transform))
			{
				return null;
			}
			return result;
		}

		private void PressPower()
		{
			powerPress = 0.15f;
			bool flag = !IsPoweredState;
			if (Object.op_Implicit((Object)(object)itemToggle))
			{
				itemToggle.ToggleItem(flag, SemiFunc.PhotonViewIDPlayerAvatarLocal());
			}
			else if (SemiFunc.IsMultiplayer() && Object.op_Implicit((Object)(object)photonView) && photonView.ViewID != 0)
			{
				photonView.RPC("RepoTV_PowerRPC", (RpcTarget)0, new object[1] { flag });
			}
			else
			{
				RepoTV_PowerRPC(flag);
			}
			if (flag)
			{
				BroadcastPlay(currentVideo ?? PickStartVideo());
			}
		}

		private void PressChannel(int dir)
		{
			if (dir > 0)
			{
				channelUpPress = 0.15f;
			}
			else
			{
				channelDownPress = 0.15f;
			}
			if (!powered)
			{
				Click();
			}
			else
			{
				BroadcastPlay(NextVideo(dir));
			}
		}

		private string NextVideo(int dir)
		{
			if (!shuffle)
			{
				return VideoLibrary.Step(currentVideo, dir);
			}
			if (dir < 0 && history.Count >= 2)
			{
				return history[history.Count - 2];
			}
			int num = Mathf.Min(8, VideoLibrary.Count / 2);
			HashSet<string> hashSet = new HashSet<string>(history.GetRange(Mathf.Max(0, history.Count - num), Mathf.Min(num, history.Count)));
			if (currentVideo != null)
			{
				hashSet.Add(currentVideo);
			}
			return VideoLibrary.RandomAvoiding(hashSet);
		}

		private void PressShuffle()
		{
			bool flag = !shuffle;
			if (SemiFunc.IsMultiplayer() && Object.op_Implicit((Object)(object)photonView) && photonView.ViewID != 0)
			{
				photonView.RPC("RepoTV_ShuffleRPC", (RpcTarget)0, new object[1] { flag });
			}
			else
			{
				RepoTV_ShuffleRPC(flag);
			}
		}

		[PunRPC]
		private void RepoTV_ShuffleRPC(bool on)
		{
			shuffle = on;
			Click();
		}

		[PunRPC]
		private void RepoTV_PowerRPC(bool on)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if (ownPower == on)
			{
				return;
			}
			ownPower = on;
			try
			{
				Sound obj = ((!on) ? AssetManager.instance?.soundDeviceTurnOff : AssetManager.instance?.soundDeviceTurnOn);
				if (obj != null)
				{
					obj.Play(tvRoot.position, 1f, 1f, 1f, 1f);
				}
			}
			catch
			{
			}
		}

		private string PickStartVideo()
		{
			if (everPlayed || !Plugin.ShuffleOnFirstPowerOn.Value)
			{
				return VideoLibrary.First;
			}
			return VideoLibrary.Random();
		}

		private void Click()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				AssetManager instance = AssetManager.instance;
				if (instance != null)
				{
					Sound soundDeviceTurnOff = instance.soundDeviceTurnOff;
					if (soundDeviceTurnOff != null)
					{
						soundDeviceTurnOff.Play(tvRoot.position, 0.4f, 1f, 1f, 1f);
					}
				}
			}
			catch
			{
			}
		}

		private static double NetTime()
		{
			if (!SemiFunc.IsMultiplayer())
			{
				return Time.realtimeSinceStartupAsDouble;
			}
			return PhotonNetwork.Time;
		}

		private void BroadcastPlay(string video)
		{
			double num = NetTime() + 0.53;
			if (SemiFunc.IsMultiplayer() && Object.op_Implicit((Object)(object)photonView) && photonView.ViewID != 0)
			{
				photonView.RPC("RepoTV_PlayRPC", (RpcTarget)0, new object[2]
				{
					video ?? "",
					num
				});
			}
			else
			{
				PlayLocal(video, num);
			}
		}

		[PunRPC]
		private void RepoTV_PlayRPC(string video, double startTime)
		{
			PlayLocal(string.IsNullOrEmpty(video) ? null : video, startTime);
		}

		private void SendVolumeIfDirty()
		{
			volumeSendTimer -= Time.deltaTime;
			brightnessSendTimer -= Time.deltaTime;
			if (brightnessDirty && brightnessSendTimer <= 0f)
			{
				brightnessDirty = false;
				brightnessSendTimer = 0.12f;
				if (SemiFunc.IsMultiplayer() && Object.op_Implicit((Object)(object)photonView) && photonView.ViewID != 0)
				{
					photonView.RPC("RepoTV_BrightnessRPC", (RpcTarget)1, new object[1] { brightness });
				}
			}
			if (volumeDirty && !(volumeSendTimer > 0f))
			{
				volumeDirty = false;
				volumeSendTimer = 0.12f;
				if (SemiFunc.IsMultiplayer() && Object.op_Implicit((Object)(object)photonView) && photonView.ViewID != 0)
				{
					photonView.RPC("RepoTV_VolumeRPC", (RpcTarget)1, new object[1] { volume });
				}
			}
		}

		[PunRPC]
		private void RepoTV_BrightnessRPC(float b)
		{
			brightness = Mathf.Clamp01(b);
		}

		[PunRPC]
		private void RepoTV_VolumeRPC(float v)
		{
			volume = Mathf.Clamp01(v);
			ApplyVolume();
		}

		private void OnPowerChanged(bool on)
		{
			powered = on;
			if (on)
			{
				if (currentVideo != null && Time.time - lastPlayMessageTime < 2f)
				{
					StartVideo();
				}
				else
				{
					awaitingPlay = true;
					awaitingTimer = 0f;
				}
			}
			else
			{
				awaitingPlay = false;
				preparing = false;
				waitingForStart = false;
				if (videoPlayer.isPlaying || videoPlayer.isPrepared)
				{
					videoPlayer.Stop();
				}
				audioSource.Stop();
				if (Object.op_Implicit((Object)(object)staticSource))
				{
					staticSource.Stop();
				}
			}
			if (Object.op_Implicit((Object)(object)ledRenderer))
			{
				((Renderer)ledRenderer).sharedMaterial = (on ? ledOnMaterial : ledOffMaterial);
			}
		}

		private void PlayLocal(string video, double startTime)
		{
			currentVideo = video;
			videoStartTime = startTime;
			lastPlayMessageTime = Time.time;
			if (video != null)
			{
				if (history.Count >= 2 && history[history.Count - 2] == video)
				{
					history.RemoveAt(history.Count - 1);
				}
				else if (history.Count == 0 || history[history.Count - 1] != video)
				{
					history.Add(video);
				}
				if (history.Count > 50)
				{
					history.RemoveAt(0);
				}
			}
			awaitingPlay = false;
			if (powered)
			{
				Click();
				channelSpin += 1f;
				StartVideo();
			}
		}

		private void StartVideo()
		{
			everPlayed = true;
			waitingForStart = false;
			string text = VideoLibrary.PathFor(currentVideo);
			noSignal = text == null;
			if (noSignal)
			{
				if (videoPlayer.isPlaying)
				{
					videoPlayer.Stop();
				}
				if (currentVideo != null)
				{
					Plugin.Log.LogInfo((object)("No local copy of \"" + currentVideo + "\"; showing static."));
				}
			}
			else
			{
				videoPlayer.Stop();
				videoPlayer.url = text;
				videoPlayer.controlledAudioTrackCount = 1;
				videoPlayer.EnableAudioTrack((ushort)0, true);
				videoPlayer.SetTargetAudioSource((ushort)0, audioSource);
				preparing = true;
				videoPlayer.Prepare();
			}
		}

		private void OnPrepared(VideoPlayer vp)
		{
			preparing = false;
			if (!powered)
			{
				vp.Stop();
				return;
			}
			double num = NetTime() - videoStartTime;
			ApplyVolume();
			if (num < 0.0)
			{
				vp.time = 0.0;
				waitingForStart = true;
				return;
			}
			double length = vp.length;
			if (length > 0.5)
			{
				num %= length;
			}
			vp.time = num;
			vp.Play();
		}

		private void OnVideoEnded(VideoPlayer vp)
		{
			if (powered && SemiFunc.IsMasterClientOrSingleplayer())
			{
				BroadcastPlay(NextVideo(1));
			}
		}

		private void ApplyVolume()
		{
			if (Object.op_Implicit((Object)(object)audioSource))
			{
				audioSource.volume = volume * Plugin.MaxVolume.Value;
			}
			if (Object.op_Implicit((Object)(object)staticSource))
			{
				staticSource.volume = volume * Plugin.MaxVolume.Value * 0.35f;
			}
		}

		private void ApplyScreen()
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: 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)
			if (!Object.op_Implicit((Object)(object)screenMaterial))
			{
				return;
			}
			bool flag = powered && !noSignal && !preparing && !waitingForStart && videoPlayer.isPlaying;
			if (!powered)
			{
				screenMaterial.mainTexture = (Texture)(object)TvPrefabBuilder.ScreenOff;
				SetScreenTint(1f);
				screenMaterial.mainTextureScale = Vector2.one;
				screenMaterial.mainTextureOffset = Vector2.zero;
				return;
			}
			if (flag)
			{
				if (Object.op_Implicit((Object)(object)staticSource) && staticSource.isPlaying)
				{
					staticSource.Stop();
				}
				screenMaterial.mainTexture = (Texture)(object)renderTexture;
				SetScreenTint(PictureBrightness);
				screenMaterial.mainTextureScale = Vector2.one;
				screenMaterial.mainTextureOffset = Vector2.zero;
				return;
			}
			if (Object.op_Implicit((Object)(object)staticSource) && !staticSource.isPlaying)
			{
				staticSource.time = Random.Range(0f, 0.9f);
				staticSource.Play();
			}
			screenMaterial.mainTexture = (Texture)(object)TvPrefabBuilder.Static;
			SetScreenTint(PictureBrightness * 0.8f);
			screenMaterial.mainTextureScale = new Vector2(2f, 2f);
			screenMaterial.mainTextureOffset = new Vector2(Random.value, Random.value);
		}

		private void SetScreenTint(float b)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			if (!Mathf.Approximately(b, lastTint) && screenMaterial.HasProperty("_Color"))
			{
				lastTint = b;
				screenMaterial.SetColor("_Color", new Color(b, b, b, 1f));
			}
		}

		private void Animate()
		{
			//IL_00d8: 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_0124: 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_018a: 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_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			float deltaTime = Time.deltaTime;
			channelUpPress = Mathf.Max(0f, channelUpPress - deltaTime);
			channelDownPress = Mathf.Max(0f, channelDownPress - deltaTime);
			powerPress = Mathf.Max(0f, powerPress - deltaTime);
			SetButton(channelUp, TvGeometry.Control.ChannelUp, channelUpPress);
			SetButton(channelDown, TvGeometry.Control.ChannelDown, channelDownPress);
			SetButton(powerButton, TvGeometry.Control.Power, powerPress);
			float num = (shuffle ? 32f : (-32f));
			leverAngle = Mathf.MoveTowards(leverAngle, num, 600f * deltaTime);
			if (Object.op_Implicit((Object)(object)shuffleLever))
			{
				shuffleLever.localRotation = Quaternion.Euler(leverAngle, 0f, 0f);
			}
			float controlScale = Layout.ControlScale;
			float num2 = ((aimed == TvGeometry.Control.Shuffle) ? 1.12f : 1f) * controlScale;
			if (Object.op_Implicit((Object)(object)shuffleSwitch))
			{
				shuffleSwitch.localScale = Vector3.one * num2;
			}
			if (Object.op_Implicit((Object)(object)shuffleLever))
			{
				shuffleLever.localScale = Vector3.one * num2;
			}
			float num3 = Mathf.Lerp(-135f, 135f, volume);
			volumeKnob.localRotation = Quaternion.Euler(0f, 0f, num3);
			volumeKnob.localScale = Vector3.one * (((aimed == TvGeometry.Control.Volume) ? 1.1f : 1f) * controlScale);
			if (Object.op_Implicit((Object)(object)brightnessKnob))
			{
				Vector3 val = UnityConvert.V(Layout.Pos(TvGeometry.Control.Brightness));
				brightnessKnob.localPosition = val + new Vector3(Layout.SliderHalfTravel * (1f - 2f * brightness), 0f, 0f);
				brightnessKnob.localScale = Vector3.one * (((aimed == TvGeometry.Control.Brightness) ? 1.15f : 1f) * controlScale);
			}
		}

		private void SetButton(Transform t, TvGeometry.Control c, float press)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)t))
			{
				float controlScale = Layout.ControlScale;
				Vector3 val = UnityConvert.V(Layout.Pos(c));
				t.localPosition = val - new Vector3(0f, 0f, (press > 0f) ? (0.005f * controlScale) : 0f);
				t.localScale = Vector3.one * (((aimed == c) ? 1.12f : 1f) * controlScale);
			}
		}
	}
	internal static class TvPrefabBuilder
	{
		internal class TrackerTvSpec
		{
			public string PrefabName;

			public string DisplayName;

			public string Description;

			public TvLayout Layout;

			public MeshData Body;

			public (string name, Vector3 centre, Vector3 size)[] Boxes;

			public Vector3 Centre;

			public Vector3 GrabPoint;

			public Vector3 IconPos;

			public float Mass;

			public itemVolume? ShopSlot;

			public Quaternion SpawnRotation = Quaternion.identity;

			public bool FreeGrab;

			public float SlotHalfHeight;

			public Vector3? CenterOfMass;
		}

		private const string BaseResourcePath = "Items/Item Valuable Tracker";

		public const string PrefabName = "Item Television";

		internal static GameObject Holder;

		public static Texture2D Atlas;

		public static Texture2D ScreenOff;

		public static Texture2D Static;

		public static AudioClip StaticClip;

		internal static Material BodyMat;

		internal static Material ScreenMat;

		internal static Material LedOnMat;

		internal static Material LedOffMat;

		private static GameObject trackerPrefab;

		private static Item trackerItem;

		private static void InitShared()
		{
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: 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_0141: Expected O, but got Unknown
			trackerPrefab = Resources.Load<GameObject>("Items/Item Valuable Tracker");
			if ((Object)(object)trackerPrefab == (Object)null)
			{
				throw new Exception("Base item \"Items/Item Valuable Tracker\" not found. The game may have been updated.");
			}
			trackerItem = trackerPrefab.GetComponent<ItemAttributes>()?.item;
			if ((Object)(object)trackerItem == (Object)null)
			{
				trackerItem = ((IEnumerable<Item>)Resources.LoadAll<Item>("")).FirstOrDefault((Func<Item, bool>)((Item i) => Object.op_Implicit((Object)(object)i) && ((Object)i).name == "Item Valuable Tracker"));
			}
			if ((Object)(object)trackerItem == (Object)null)
			{
				throw new Exception("Base Item asset for the Valuable Tracker not found.");
			}
			Atlas = UnityConvert.ToTexture(TvTexture.Build(), 1024, "RepoTV Atlas");
			ScreenOff = UnityConvert.ToTexture(TvTexture.BuildScreenOff(), 64, "RepoTV Screen Off", mips: false);
			Static = UnityConvert.Static(96, 72);
			StaticClip = UnityConvert.StaticSound();
			Object[] array = (Object[])(object)new Object[4]
			{
				(Object)Atlas,
				(Object)ScreenOff,
				(Object)Static,
				(Object)StaticClip
			};
			foreach (Object obj in array)
			{
				obj.hideFlags = (HideFlags)(obj.hideFlags | 0x20);
			}
			Holder = new GameObject("RepoTV Prefabs");
			Holder.SetActive(false);
			((Object)Holder).hideFlags = (HideFlags)61;
			Object.DontDestroyOnLoad((Object)(object)Holder);
			MeshRenderer[] componentsInChildren = trackerPrefab.GetComponentsInChildren<MeshRenderer>(true);
			MeshRenderer? obj2 = ((IEnumerable<MeshRenderer>)componentsInChildren).FirstOrDefault((Func<MeshRenderer, bool>)((MeshRenderer r) => ((Object)r).name == "Valuable Tracker Mesh"));
			Material val = ((obj2 != null) ? ((Renderer)obj2).sharedMaterial : null);
			MeshRenderer? obj3 = ((IEnumerable<MeshRenderer>)componentsInChildren).FirstOrDefault((Func<MeshRenderer, bool>)((MeshRenderer r) => ((Object)r).name == "Display"));
			Material baseDisplay = ((obj3 != null) ? ((Renderer)obj3).sharedMaterial : null);
			if ((Object)(object)val == (Object)null)
			{
				throw new Exception("Could not find the base item's material.");
			}
			BuildMaterials(val, baseDisplay);
		}

		public static void BuildAndRegister()
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_00e1: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: 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_0152: Unknown result type (might be due to invalid IL or missing references)
			InitShared();
			float bodyCenterY = TvGeometry.BodyCenterY;
			float num = 0.505f;
			float num2 = -0.15f;
			TrackerTvSpec trackerTvSpec = new TrackerTvSpec();
			trackerTvSpec.PrefabName = "Item Television";
			trackerTvSpec.DisplayName = "Television";
			trackerTvSpec.Description = "An old CRT television. Plays whatever is in your Television Videos folders.";
			trackerTvSpec.Layout = TvLayout.Crt;
			trackerTvSpec.Body = TvGeometry.Build(includeControls: false);
			trackerTvSpec.Boxes = new(string, Vector3, Vector3)[2]
			{
				("TV Body Collider", new Vector3(0f, num / 2f, 0.01f), new Vector3(0.72f, num, 0.32000002f)),
				("TV Back Collider", new Vector3(0f, bodyCenterY - 0.02f, num2 - 0.1f), new Vector3(0.48f, 0.36f, 0.2f))
			};
			trackerTvSpec.Centre = new Vector3(0f, bodyCenterY, -0.0875f);
			trackerTvSpec.GrabPoint = new Vector3(0f, bodyCenterY, 0.02f);
			trackerTvSpec.IconPos = new Vector3(0.55f, 0.62f, 1.15f);
			trackerTvSpec.Mass = Plugin.Mass.Value;
			trackerTvSpec.ShopSlot = (itemVolume)2;
			trackerTvSpec.SlotHalfHeight = 0.47f;
			trackerTvSpec.CenterOfMass = new Vector3(0f, 0.15f, -0.05f);
			BuildTrackerTv(trackerTvSpec);
		}

		internal static void BuildTrackerTv(TrackerTvSpec spec)
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: 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_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: 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_0253: 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_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_036c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0373: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(trackerPrefab, Holder.transform);
			((Object)val).name = spec.PrefabName;
			int layer = val.layer;
			TvPrefabBuilder.DestroyComponent<ItemTracker>(val);
			TvPrefabBuilder.DestroyComponent<ItemBattery>(val);
			string[] array = new string[3] { "Mesh", "Nozzle", "Item Battery" };
			foreach (string text in array)
			{
				Transform val2 = val.transform.Find(text);
				if (Object.op_Implicit((Object)(object)val2))
				{
					Object.DestroyImmediate((Object)(object)((Component)val2).gameObject);
				}
			}
			TvController tvController = AddTv(val, val.transform, Vector3.zero, layer, spec.Layout, spec.Body);
			Transform val3 = val.transform.Find("Colliders");
			GameObject gameObject = ((Component)((Component)val3).GetComponentsInChildren<BoxCollider>(true).First()).gameObject;
			foreach (Transform item in ((IEnumerable)val3).Cast<Transform>().ToList())
			{
				if ((Object)(object)((Component)item).gameObject != (Object)(object)gameObject)
				{
					Object.DestroyImmediate((Object)(object)((Component)item).gameObject);
				}
			}
			for (int j = 0; j < spec.Boxes.Length; j++)
			{
				SetBox(((j == 0) ? gameObject : Object.Instantiate<GameObject>(gameObject, val3)).transform, spec.Boxes[j].name, spec.Boxes[j].centre, spec.Boxes[j].size);
			}
			Transform val4 = val.transform.Find("Force Grab Point");
			if (spec.FreeGrab && Object.op_Implicit((Object)(object)val4))
			{
				Object.DestroyImmediate((Object)(object)((Component)val4).gameObject);
			}
			else
			{
				SetLocal(val4, spec.GrabPoint);
			}
			SetLocal(val.transform.Find("Item Light"), spec.Centre);
			Transform val5 = val.transform.Find("SemiIcon Maker");
			if (Object.op_Implicit((Object)(object)val5))
			{
				val5.localPosition = spec.IconPos;
				val5.localRotation = Quaternion.LookRotation(spec.Centre - spec.IconPos);
			}
			ItemVolume componentInChildren = val.GetComponentInChildren<ItemVolume>(true);
			if (Object.op_Implicit((Object)(object)componentInChildren))
			{
				((Component)componentInChildren).transform.localPosition = (Vector3)((spec.SlotHalfHeight > 0f) ? new Vector3(spec.Centre.x, spec.SlotHalfHeight - 0.02f, spec.Centre.z) : spec.Centre);
				if (spec.ShopSlot.HasValue)
				{
					componentInChildren.itemVolume = spec.ShopSlot.Value;
				}
			}
			if (spec.CenterOfMass.HasValue)
			{
				(val.transform.Find("Center of Mass") ?? NewChild(val.transform, "Center of Mass", layer, Vector3.zero).transform).localPosition = spec.CenterOfMass.Value;
			}
			ItemLight componentInChildren2 = val.GetComponentInChildren<ItemLight>(true);
			if (Object.op_Implicit((Object)(object)componentInChildren2))
			{
				componentInChildren2.meshRenderers = new List<MeshRenderer> { tvController.bodyRenderer };
			}
			Rigidbody component = val.GetComponent<Rigidbody>();
			component.mass = spec.Mass;
			NotValuableObject component2 = val.GetComponent<NotValuableObject>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				PhysAttribute val6 = ScriptableObject.CreateInstance<PhysAttribute>();
				((Object)val6).name = "PhysAttribute " + spec.DisplayName;
				val6.mass = spec.Mass;
				((Object)val6).hideFlags = (HideFlags)(((Object)val6).hideFlags | 0x20);
				component2.physAttributePreset = val6;
			}
			component.angularDamping = Plugin.AngularDamping.Value;
			component.linearDamping = Plugin.LinearDamping.Value;
			ItemToggle component3 = val.GetComponent<ItemToggle>();
			component3.autoTurnOffWhenEquipped = true;
			component3.playSound = true;
			Item val7 = CloneItem(trackerItem, spec.PrefabName, spec.DisplayName, spec.Description);
			if (spec.ShopSlot.HasValue)
			{
				val7.itemVolume = spec.ShopSlot.Value;
			}
			val7.spawnRotationOffset = spec.SpawnRotation;
			val.GetComponent<ItemAttributes>().item = val7;
			if (Items.RegisterItem(val.GetComponent<ItemAttributes>()) == null)
			{
				throw new Exception("REPOLib refused to register " + spec.DisplayName + " (see REPOLib errors above).");
			}
			Plugin.Log.LogInfo((object)("Registered the " + spec.DisplayName + " item."));
		}

		private static void BuildMaterials(Material baseBody, Material baseDisplay)
		{
			//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_0012: Expected O, but got Unknown
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Expected O, but got Unknown
			//IL_015f: 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_018a: Expected O, but got Unknown
			//IL_01a2: 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_0203: Unknown result type (might be due to invalid IL or missing references)
			Material val = new Material(baseBody)
			{
				name = "RepoTV Body"
			};
			val.SetTexture("_BaseTexture", (Texture)(object)Atlas);
			val.SetColor("_BaseColor", Color.white);
			val.SetTexture("_EmissionTexture", (Texture)(object)UnityConvert.Solid(new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue), "RepoTV Black"));
			val.SetColor("_EmissionColor", Color.black);
			val.SetTexture("_NormalTexture", (Texture)(object)UnityConvert.Solid(new Color32((byte)128, (byte)128, byte.MaxValue, byte.MaxValue), "RepoTV Flat Normal", linear: true));
			val.SetFloat("_TilingX", 1f);
			val.SetFloat("_TilingY", 1f);
			val.SetFloat("_OffsetX", 0f);
			val.SetFloat("_OffsetY", 0f);
			val.SetColor("_FresnelColor", new Color(0.12f, 0.12f, 0.11f));
			val.SetColor("_FresnelEmissionColor", new Color(0.02f, 0.02f, 0.02f));
			val.SetFloat("_Smoothness", 0.35f);
			BodyMat = val;
			ScreenMat = MakeScreenMaterial(baseDisplay, val);
			LedOffMat = new Material(val)
			{
				name = "RepoTV LED Off"
			};
			LedOffMat.SetTexture("_BaseTexture", (Texture)(object)UnityConvert.Solid(new Color32((byte)60, (byte)14, (byte)10, byte.MaxValue), "RepoTV LED Off"));
			LedOnMat = new Material(val)
			{
				name = "RepoTV LED On"
			};
			LedOnMat.SetTexture("_BaseTexture", (Texture)(object)UnityConvert.Solid(new Color32(byte.MaxValue, (byte)60, (byte)40, byte.MaxValue), "RepoTV LED On"));
			LedOnMat.SetTexture("_EmissionTexture", (Texture)(object)UnityConvert.Solid(new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue), "RepoTV White"));
			LedOnMat.SetColor("_EmissionColor", new Color(3f, 0.3f, 0.15f));
		}

		internal static TvController AddTv(GameObject item, Transform parent, Vector3 localPos, int layer, TvLayout layout = null, MeshData bodyMesh = null)
		{
			//IL_0053: 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_00ee: 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_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: 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_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			layout = layout ?? TvLayout.Crt;
			bodyMesh = bodyMesh ?? TvGeometry.Build(includeControls: false);
			float cs = layout.ControlScale;
			Transform transform = NewChild(parent, "TV", layer, localPos).transform;
			GameObject bodyGo = NewChild(transform, "TV Mesh", layer, Vector3.zero);
			bodyGo.AddComponent<MeshFilter>().sharedMesh = UnityConvert.ToMesh(bodyMesh, "RepoTV Body " + layout.Id);
			MeshRenderer val = bodyGo.AddComponent<MeshRenderer>();
			((Renderer)val).sharedMaterials = (Material[])(object)new Material[2] { BodyMat, ScreenMat };
			MeshRenderer r;
			Transform channelUp = MakePart("Channel Up", layout.BuildControl(TvGeometry.Control.ChannelUp), P(TvGeometry.Control.ChannelUp), BodyMat, out r);
			Transform channelDown = MakePart("Channel Down", layout.BuildControl(TvGeometry.Control.ChannelDown), P(TvGeometry.Control.ChannelDown), BodyMat, out r);
			Transform volumeKnob = MakePart("Volume Knob", layout.BuildControl(TvGeometry.Control.Volume), P(TvGeometry.Control.Volume), BodyMat, out r);
			Transform powerButton = MakePart("Power Button", layout.BuildControl(TvGeometry.Control.Power), P(TvGeometry.Control.Power), BodyMat, out r);
			MakePart("Power LED", TvGeometry.BuildLed(), UnityConvert.V(layout.LedPos), LedOffMat, out var r2);
			Transform brightnessKnob = MakePart("Brightness Slider", layout.BuildControl(TvGeometry.Control.Brightness), P(TvGeometry.Control.Brightness), BodyMat, out r);
			Vector3 val2 = P(TvGeometry.Control.Shuffle);
			Transform shuffleSwitch = MakePart("Random Switch", layout.BuildControl(TvGeometry.Control.Shuffle), val2, BodyMat, out r);
			Transform val3 = MakePart("Random Lever", TvGeometry.BuildShuffleLever(), val2 + new Vector3(0f, 0f, 0.004f * cs), BodyMat, out r);
			val3.localRotation = Quaternion.Euler(-32f, 0f, 0f);
			GameObject obj = NewChild(transform, "TV Speaker", layer, UnityConvert.V(layout.SpeakerPos));
			AudioSource val4 = obj.AddComponent<AudioSource>();
			ConfigureSource(val4);
			VideoPlayer val5 = obj.AddComponent<VideoPlayer>();
			val5.playOnAwake = false;
			val5.source = (VideoSource)1;
			val5.renderMode = (VideoRenderMode)2;
			val5.audioOutputMode = (VideoAudioOutputMode)1;
			val5.isLooping = false;
			val5.skipOnDrop = true;
			val5.waitForFirstFrame = true;
			val5.aspectRatio = (VideoAspectRatio)3;
			AudioSource val6 = NewChild(obj.transform, "TV Static", layer, Vector3.zero).AddComponent<AudioSource>();
			ConfigureSource(val6);
			val6.loop = true;
			val6.clip = StaticClip;
			TvController tvController = item.AddComponent<TvController>();
			tvController.tvRoot = transform;
			tvController.layoutId = layout.Id;
			tvController.staticSource = val6;
			tvController.bodyRenderer = val;
			tvController.channelUp = channelUp;
			tvController.channelDown = channelDown;
			tvController.volumeKnob = volumeKnob;
			tvController.powerButton = powerButton;
			tvController.shuffleSwitch = shuffleSwitch;
			tvController.brightnessKnob = brightnessKnob;
			tvController.shuffleLever = val3;
			tvController.ledRenderer = r2;
			tvController.ledOnMaterial = LedOnMat;
			tvController.ledOffMaterial = LedOffMat;
			tvController.videoPlayer = val5;
			tvController.audioSource = val4;
			return tvController;
			Transform MakePart(string name, MeshData data, Vector3 pos, Material mat, out MeshRenderer reference)
			{
				//IL_0014: 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_005b: Unknown result type (might be due to invalid IL or missing references)
				GameObject val7 = NewChild(bodyGo.transform, name, layer, pos);
				val7.AddComponent<MeshFilter>().sharedMesh = UnityConvert.ToMesh(data, "RepoTV " + name);
				reference = val7.AddComponent<MeshRenderer>();
				((Renderer)reference).sharedMaterial = mat;
				val7.transform.localScale = Vector3.one * cs;
				return val7.transform;
			}
			Vector3 P(TvGeometry.Control c)
			{
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				return UnityConvert.V(layout.Pos(c));
			}
		}

		private static void ConfigureSource(AudioSource s)
		{
			s.playOnAwake = false;
			s.spatialBlend = 1f;
			s.rolloffMode = (AudioRolloffMode)1;
			s.minDistance = 1.5f;
			s.maxDistance = Plugin.HearingDistance.Value;
			s.dopplerLevel = 0f;
		}

		internal static Item CloneItem(Item baseItem, string assetName, string displayName, string description)
		{
			Item obj = Object.Instantiate<Item>(baseItem);
			((Object)obj).name = assetName;
			obj.itemName = displayName;
			obj.itemNameLocalized = null;
			obj.description = description;
			obj.physicalItem = true;
			Value val = ScriptableObject.CreateInstance<Value>();
			((Object)val).name = "Value - " + displayName;
			val.valueMin = baseItem.value.valueMin * Plugin.PriceMultiplier.Value;
			val.valueMax = baseItem.value.valueMax * Plugin.PriceMultiplier.Value;
			obj.value = val;
			Object.DontDestroyOnLoad((Object)(object)obj);
			Object.DontDestroyOnLoad((Object)(object)val);
			return obj;
		}

		private static Material MakeScreenMaterial(Material baseDisplay, Material body)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_00e4: 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_00ea: Expected O, but got Unknown
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			Material val;
			if ((Object)(object)baseDisplay != (Object)null)
			{
				val = new Material(baseDisplay)
				{
					name = "RepoTV Screen"
				};
				val.DisableKeyword("_ALPHABLEND_ON");
				if (val.HasProperty("_SrcBlend"))
				{
					val.SetFloat("_SrcBlend", 1f);
				}
				if (val.HasProperty("_DstBlend"))
				{
					val.SetFloat("_DstBlend", 0f);
				}
				if (val.HasProperty("_ZWrite"))
				{
					val.SetFloat("_ZWrite", 1f);
				}
				if (val.HasProperty("_Mode"))
				{
					val.SetFloat("_Mode", 0f);
				}
				val.renderQueue = 2000;
				if (val.HasProperty("_Color"))
				{
					val.SetColor("_Color", Color.white);
				}
			}
			else
			{
				Shader val2 = Shader.Find("Unlit/Texture");
				val = (((Object)(object)val2 != (Object)null) ? new Material(val2) : new Material(body));
				((Object)val).name = "RepoTV Screen";
			}
			val.mainTexture = (Texture)(object)ScreenOff;
			return val;
		}

		internal static MeshRenderer FindRenderer(GameObject root, string name)
		{
			return ((IEnumerable<MeshRenderer>)root.GetComponentsInChildren<MeshRenderer>(true)).FirstOrDefault((Func<MeshRenderer, bool>)((MeshRenderer r) => ((Object)r).name == name));
		}

		internal static void DestroyComponent<T>(GameObject go) where T : Component
		{
			T component = go.GetComponent<T>();
			if (Object.op_Implicit((Object)(object)component))
			{
				Object.DestroyImmediate((Object)(object)component);
			}
		}

		internal static GameObject NewChild(Transform parent, string name, int layer, Vector3 localPos)
		{
			//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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			GameObject val = new GameObject(name)
			{
				layer = layer
			};
			val.transform.SetParent(parent, false);
			val.transform.localPosition = localPos;
			return val;
		}

		internal static void SetLocal(Transform t, Vector3 p)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)t))
			{
				t.localPosition = p;
			}
		}

		private static void SetBox(Transform t, string name, Vector3 centre, Vector3 size)
		{
			//IL_0008: 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_001a: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			((Object)t).name = name;
			t.localPosition = centre;
			t.localRotation = Quaternion.identity;
			t.localScale = size;
			BoxCollider component = ((Component)t).GetComponent<BoxCollider>();
			component.center = Vector3.zero;
			component.size = Vector3.one;
		}
	}
	internal static class UnityConvert
	{
		public static Vector3 V(V3 v)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(v.x, v.y, v.z);
		}

		public static Mesh ToMesh(MeshData d, string name)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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_00a4: Expected O, but got Unknown
			int count = d.Positions.Count;
			Vector3[] array = (Vector3[])(object)new Vector3[count];
			Vector3[] array2 = (Vector3[])(object)new Vector3[count];
			Vector2[] array3 = (Vector2[])(object)new Vector2[count];
			for (int i = 0; i < count; i++)
			{
				array[i] = V(d.Positions[i]);
				array2[i] = V(d.Normals[i]);
				array3[i] = new Vector2(d.Uvs[i].x, d.Uvs[i].y);
			}
			Mesh val = new Mesh
			{
				name = name
			};
			if (count > 65000)
			{
				val.indexFormat = (IndexFormat)1;
			}
			val.vertices = array;
			val.normals = array2;
			val.uv = array3;
			val.subMeshCount = d.Submeshes.Length;
			for (int j = 0; j < d.Submeshes.Length; j++)
			{
				val.SetTriangles(d.Submeshes[j], j);
			}
			val.RecalculateBounds();
			val.RecalculateTangents();
			val.UploadMeshData(true);
			return val;
		}

		public static Texture2D ToTexture(byte[] rgba, int size, string name, bool mips = true, bool linear = false)
		{
			//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_0012: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			Texture2D val = new Texture2D(size, size, (TextureFormat)4, mips, linear)
			{
				name = name
			};
			val.SetPixelData<byte>(rgba, 0, 0);
			((Texture)val).wrapMode = (TextureWrapMode)0;
			((Texture)val).filterMode = (FilterMode)1;
			((Texture)val).anisoLevel = 4;
			val.Apply(mips, true);
			return val;
		}

		public static Texture2D Solid(Color32 c, string name, bool linear = false)
		{
			//IL_0010: 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_0037: Unknown result type (might be due to invalid IL or missing references)
			byte[] array = new byte[64];
			for (int i = 0; i < 16; i++)
			{
				array[i * 4] = c.r;
				array[i * 4 + 1] = c.g;
				array[i * 4 + 2] = c.b;
				array[i * 4 + 3] = c.a;
			}
			return ToTexture(array, 4, name, mips: false, linear);
		}

		public static AudioClip StaticSound()
		{
			float[] array = new float[44100];
			Random random = new Random(1337);
			float num = 0f;
			for (int i = 0; i < array.Length; i++)
			{
				float num2 = (float)(random.NextDouble() * 2.0 - 1.0);
				num += (num2 - num) * 0.45f;
				float num3 = 0.04f * Mathf.Sin(MathF.PI * 120f * (float)i / 44100f);
				array[i] = num * 0.55f + num3;
			}
			for (int j = 0; j < 2205; j++)
			{
				float num4 = (float)j / 2205f;
				array[array.Length - 2205 + j] = array[array.Length - 2205 + j] * (1f - num4) + array[j] * num4;
			}
			AudioClip obj = AudioClip.Create("RepoTV Static", array.Length, 1, 44100, false);
			obj.SetData(array, 0);
			return obj;
		}

		public static Texture2D Static(int w, int h)
		{
			//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_0015: Expected O, but got Unknown
			//IL_0047: 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)
			Texture2D val = new Texture2D(w, h, (TextureFormat)4, false)
			{
				name = "RepoTV Static"
			};
			Color32[] array = (Color32[])(object)new Color32[w * h];
			Random random = new Random(77);
			for (int i = 0; i < array.Length; i++)
			{
				byte b = (byte)random.Next(20, 235);
				array[i] = new Color32(b, b, b, byte.MaxValue);
			}
			val.SetPixels32(array);
			((Texture)val).wrapMode = (TextureWrapMode)0;
			((Texture)val).filterMode = (FilterMode)0;
			val.Apply(false, true);
			return val;
		}
	}
	public static class VideoLibrary
	{
		public const string FolderName = "Television Videos";

		private static readonly string[] Extensions = new string[4] { ".mp4", ".webm", ".m4v", ".mov" };

		private static readonly List<string> names = new List<string>();

		private static readonly Dictionary<string, string> paths = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

		public static IReadOnlyList<string> Names => names;

		public static int Count => names.Count;

		public static string First
		{
			get
			{
				if (names.Count <= 0)
				{
					return null;
				}
				return names[0];
			}
		}

		public static void Scan()
		{
			names.Clear();
			paths.Clear();
			try
			{
				string[] directories = Directory.GetDirectories(Paths.PluginPath, "Television Videos", SearchOption.AllDirectories);
				for (int i = 0; i < directories.Length; i++)
				{
					string[] files = Directory.GetFiles(directories[i]);
					foreach (string text in files)
					{
						if (Extensions.Contains(Path.GetExtension(text).ToLowerInvariant()))
						{
							string fileName = Path.GetFileName(text);
							if (!paths.ContainsKey(fileName))
							{
								paths[fileName] = text;
								names.Add(fileName);
							}
						}
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Error while scanning for videos: " + ex));
			}
			names.Sort(StringComparer.OrdinalIgnoreCase);
			Plugin.Log.LogInfo((object)string.Format("Found {0} video(s) in \"{1}\" folders.", names.Count, "Television Videos"));
		}

		public static string PathFor(string name)
		{
			if (name == null || !paths.TryGetValue(name, out var value))
			{
				return null;
			}
			return value;
		}

		public static string Step(string current, int dir)
		{
			if (names.Count == 0)
			{
				return current;
			}
			int num = ((current == null) ? (-1) : names.FindIndex((string n) => string.Equals(n, current, StringComparison.OrdinalIgnoreCase)));
			if (num < 0)
			{
				if (dir < 0)
				{
					return names[names.Count - 1];
				}
				return names[0];
			}
			return names[((num + dir) % names.Count + names.Count) % names.Count];
		}

		public static string Random()
		{
			if (names.Count <= 0)
			{
				return null;
			}
			return names[Random.Range(0, names.Count)];
		}

		public static string RandomAvoiding(ICollection<string> avoid)
		{
			if (names.Count == 0)
			{
				return null;
			}
			List<string> list = names.Where((string n) => !avoid.Contains(n)).ToList();
			if (list.Count == 0)
			{
				list = names.ToList();
			}
			return list[Random.Range(0, list.Count)];
		}
	}
}
namespace RepoTV.Model
{
	public static class CartGeometry
	{
		public const float GroundY = -0.5f;

		public const float Width = 0.92f;

		public const float Depth = 0.64f;

		public const float LowerShelfY = -0.3f;

		public const float TopShelfY = 0.36f;

		public const float ShelfThickness = 0.025f;

		public const float LipHeight = 0.12f;

		public const float TvZ = 0.08f;

		public static V3 TvOffset => new V3(0f, 0.36f, 0.08f);

		public static MeshData Build()
		{
			MeshData meshData = new MeshData(1);
			float num = 0.46f;
			float num2 = 0.32f;
			float num3 = num - 0.025f;
			float num4 = num2 - 0.025f;
			float num5 = 0.038f;
			float num6 = -0.5f + 2f * num5 + 0.03f;
			float[] array = new float[2] { -1f, 1f };
			foreach (float num7 in array)
			{
				float[] array2 = new float[2] { -1f, 1f };
				foreach (float num8 in array2)
				{
					float num9 = num7 * num3;
					float num10 = num8 * num4;
					float num11 = (0.36f - num6) / 2f;
					TvGeometry.RoundedBox(meshData, new V3(num9, num6 + num11, num10), new V3(0.016f, num11, 0.016f), 0.006f, 2, (TvGeometry.Face _) => TvTexture.DialDark);
					TvGeometry.RoundedBox(meshData, new V3(num9, num6 - 0.006f, num10), new V3(0.028f, 0.006f, 0.028f), 0.003f, 1, (TvGeometry.Face _) => TvTexture.Rubber);
					float num12 = -0.5f + num5;
					float[] array3 = new float[2] { -1f, 1f };
					foreach (float num14 in array3)
					{
						TvGeometry.RoundedBox(meshData, new V3(num9 + num14 * 0.02f, (num12 + num6) / 2f, num10 - 0.012f), new V3(0.004f, (num6 - num12) / 2f + 0.006f, 0.012f), 0.002f, 1, (TvGeometry.Face _) => TvTexture.Metal);
					}
					Wheel(meshData, new V3(num9, num12, num10 - 0.012f), num5, 0.03f);
				}
			}
			Shelf(meshData, -0.3f, num, num2, 0.12f);
			Shelf(meshData, 0.36f, num, num2, 0.02f);
			float num15 = 0.865f;
			float x = -0.2f;
			float num16 = 0.234f;
			float num17 = -0.07400001f;
			TvGeometry.RoundedBox(meshData, new V3(x, num15 + 0.004f, (num16 + num17) / 2f), new V3(0.022f, 0.004f, (num16 - num17) / 2f), 0.002f, 1, (TvGeometry.Face _) => TvTexture.Rubber);
			TvGeometry.RoundedBox(meshData, new V3(x, (num15 + 0.36f) / 2f, num17), new V3(0.022f, (num15 - 0.36f) / 2f, 0.004f), 0.002f, 1, (TvGeometry.Face _) => TvTexture.Rubber);
			TvGeometry.RoundedBox(meshData, new V3(x, 0.51f, num17 - 0.006f), new V3(0.03f, 0.02f, 0.004f), 0.002f, 1, (TvGeometry.Face _) => TvTexture.Metal);
			return meshData;
		}

		private static void Shelf(MeshData m, float topY, float hw, float hd, float lip)
		{
			float num = 0.025f;
			TvGeometry.RoundedBox(m, new V3(0f, topY - num / 2f, 0f), new V3(hw, num / 2f, hd), 0.006f, 2, (TvGeometry.Face _) => TvTexture.BezelLip);
			TvGeometry.RoundedBox(m, new V3(0f, topY + lip / 2f, hd - 0.008f), new V3(hw, lip / 2f, 0.008f), 0.003f, 1, (TvGeometry.Face _) => TvTexture.BezelLip);
			TvGeometry.RoundedBox(m, new V3(0f, topY + lip / 2f, 0f - hd + 0.008f), new V3(hw, lip / 2f, 0.008f), 0.003f, 1, (TvGeometry.Face _) => TvTexture.BezelLip);
			TvGeometry.RoundedBox(m, new V3(hw - 0.008f, topY + lip / 2f, 0f), new V3(0.008f, lip / 2f, hd), 0.003f, 1, (TvGeometry.Face _) => TvTexture.BezelLip);
			TvGeometry.RoundedBox(m, new V3(0f - hw + 0.008f, topY + lip / 2f, 0f), new V3(0.008f, lip / 2f, hd), 0.003f, 1, (TvGeometry.Face _) => TvTexture.BezelLip);
		}

		private static void Wheel(MeshData m, V3 c, float r, float width)
		{
			V3 v = c + new V3((0f - width) / 2f, 0f, 0f);
			V3 v2 = c + new V3(width / 2f, 0f, 0f);
			TvGeometry.Rod(m, v, v2, r, 16, TvTexture.Rubber);
			(V3, float)[] array = new(V3, float)[2]
			{
				(v, -1f),
				(v2, 1f)
			};
			for (int i = 0; i < array.Length; i++)
			{
				(V3, float) tuple = array[i];
				V3 item = tuple.Item1;
				float item2 = tuple.Item2;
				V3 n = new V3(item2, 0f, 0f);
				int a = m.AddVertex(item, n, TvTexture.Metal.Center);
				int num = 16;
				int[] array2 = new int[num];
				for (int j = 0; j < num; j++)
				{
					double num2 = (double)(j * 2) * Math.PI / (double)num;
					array2[j] = m.AddVertex(item + new V3(0f, (float)Math.Cos(num2) * r, (float)Math.Sin(num2) * r), n, TvTexture.Rubber.Center);
				}
				for (int k = 0; k < num; k++)
				{
					m.Tri(0, a, array2[k], array2[(k + 1) % num]);
				}
			}
		}
	}
	public static class FlatGeometry
	{
		public const float S = 1.4f;

		public const float ScreenW = 2.324f;

		public const float ScreenH = 1.3076f;

		public const float Bezel = 0.0168f;

		public const float ChinH = 0.18f;

		public const float PanelDepth = 0.07f;

		public const float PanelBottom = 0.14f;

		public const float PanelZ = 0f;

		public const float ControlScale = 1.4f;

		public const float SliderHalfTravel = 0.084f;

		public static float PanelW => 2.3576f;

		public static float ScreenCy => 0.9738f;

		public static float PanelTop => ScreenCy + 0.6538f + 0.0168f;

		public static float FrontZ => 0.035f;

		public static float ChinCy => 0.23f;

		public static float ControlY => 0.2444f;

		public static V3 LedPos => new V3(-1.115f, ControlY, FrontZ);

		public static V3 ControlPos(TvGeometry.Control c)
		{
			float controlY = ControlY;
			float frontZ = FrontZ;
			return c switch
			{
				TvGeometry.Control.ChannelDown => new V3(-0.38f, controlY, frontZ), 
				TvGeometry.Control.ChannelUp => new V3(-0.45f, controlY, frontZ), 
				TvGeometry.Control.Volume => new V3(-0.58f, controlY, frontZ), 
				TvGeometry.Control.Brightness => new V3(-0.77f, controlY, frontZ), 
				TvGeometry.Control.Shuffle => new V3(-0.94f, controlY, frontZ), 
				_ => new V3(-1.05f, controlY, frontZ), 
			};
		}

		public static MeshData BuildControl(TvGeometry.Control c)
		{
			if (c != TvGeometry.Control.ChannelUp && c != TvGeometry.Control.ChannelDown)
			{
				return TvGeometry.BuildControl(c);
			}
			MeshData meshData = new MeshData(1);
			UvRect face = ((c == TvGeometry.Control.ChannelUp) ? TvTexture.ButtonRight : TvTexture.ButtonLeft);
			TvGeometry.RoundedBox(meshData, new V3(0f, 0f, 0.007f), new V3(0.02f, 0.017f, 0.007f), 0.005f, 2, (TvGeometry.Face f) => (f != TvGeometry.Face.Front) ? TvTexture.ButtonCream : face);
			return meshData;
		}

		public static float ControlHitRadius(TvGeometry.Control c)
		{
			return TvGeometry.ControlHitRadius(c) * 1.4f;
		}

		public static MeshData Build(bool includeControls = true)
		{
			MeshData meshData = new MeshData(2);
			float num = PanelW / 2f;
			float y = (PanelTop - 0.14f) / 2f;
			float y2 = (PanelTop + 0.14f) / 2f;
			TvGeometry.RoundedBox(meshData, new V3(0f, y2, 0f), new V3(num, y, 0.035f), 0.0112000005f, 2, (TvGeometry.Face _) => TvTexture.BezelLip);
			TvGeometry.RoundedBox(meshData, new V3(0f, ScreenCy - 0.07f, -0.07f), new V3(0.45f, 0.28f, 0.03f) * 1.4f, 0.027999999f, 3, (TvGeometry.Face _) => TvTexture.Bezel);
			float z = FrontZ + 0.0008f;
			ChinQuad(meshData, new V3(0f, ChinCy, z), num - 0.002f, 0.08800001f);
			float z2 = FrontZ + 0.0015f;
			float num2 = 1.162f;
			float num3 = 0.6538f;
			V3 n = new V3(0f, 0f, 1f);
			int a = meshData.AddVertex(new V3(num2, ScreenCy - num3, z2), n, new V2(0f, 0f));
			int b = meshData.AddVertex(new V3(0f - num2, ScreenCy - num3, z2), n, new V2(1f, 0f));
			int c = meshData.AddVertex(new V3(0f - num2, ScreenCy + num3, z2), n, new V2(1f, 1f));
			int d = meshData.AddVertex(new V3(num2, ScreenCy + num3, z2), n, new V2(0f, 1f));
			meshData.Quad(1, a, b, c, d);
			TvGeometry.RoundedBox(meshData, new V3(0f, 0.0168f, 0f), new V3(0.33f, 0.012f, 0.13f) * 1.4f, 0.0139999995f, 2, (TvGeometry.Face _) => TvTexture.DialDark);
			float num4 = 0.0336f;
			float num5 = 0.224f;
			TvGeometry.RoundedBox(meshData, new V3(0f, (num4 + num5) / 2f, -0.049f), new V3(0.07f, (num5 - num4) / 2f, 0.021f), 0.0084f, 2, (TvGeometry.Face _) => TvTexture.DialDark);
			if (includeControls)
			{
				foreach (TvGeometry.Control value in Enum.GetValues(typeof(TvGeometry.Control)))
				{
					TvGeometry.Append(meshData, Scaled(BuildControl(value), 1.4f), ControlPos(value));
				}
				TvGeometry.Append(meshData, Scaled(TvGeometry.BuildLed(), 1.4f), LedPos);
				TvGeometry.Append(meshData, Scaled(TvGeometry.BuildShuffleLever(32f), 1.4f), ControlPos(TvGeometry.Control.Shuffle) + new V3(0f, 0f, 0.0056000003f));
			}
			return meshData;
		}

		private static void ChinQuad(MeshData m, V3 c, float hw, float hh)
		{
			UvRect chin = TvTexture.Chin;
			V3 n = new V3(0f, 0f, 1f);
			int a = m.AddVertex(c + new V3(hw, 0f - hh, 0f), n, chin.Map(0f, 0f));
			int b = m.AddVertex(c + new V3(0f - hw, 0f - hh, 0f), n, chin.Map(0f, 1f));
			int c2 = m.AddVertex(c + new V3(0f - hw, hh, 0f), n, chin.Map(1f, 1f));
			int d = m.AddVertex(c + new V3(hw, hh, 0f), n, chin.Map(1f, 0f));
			m.Quad(0, a, b, c2, d);
		}

		public static MeshData Scaled(MeshData src, float s)
		{
			MeshData meshData = new MeshData(src.Submeshes.Length);
			for (int i = 0; i < src.Positions.Count; i++)
			{
				meshData.AddVertex(src.Positions[i] * s, src.Normals[i], src.Uvs[i]);
			}
			for (int j = 0; j < src.Submeshes.Length; j++)
			{
				meshData.Submeshes[j].AddRange(src.Submeshes[j]);
			}
			return meshData;
		}
	}
	public struct V3
	{
		public float x;

		public float y;

		public float z;

		public static readonly V3 Zero = new V3(0f, 0f, 0f);

		public float Length => (float)Math.Sqrt(x * x + y * y + z * z);

		public V3 Normalized
		{
			get
			{
				float length = Length;
				if (!(length > 1E-08f))
				{
					return new V3(0f, 1f, 0f);
				}
				return this * (1f / length);
			}
		}

		public V3(float x, float y, float z)
		{
			this.x = x;
			this.y = y;
			this.z = z;
		}

		public static V3 operator +(V3 a, V3 b)
		{
			return new V3(a.x + b.x, a.y + b.y, a.z + b.z);
		}

		public static V3 operator -(V3 a, V3 b)
		{
			return new V3(a.x - b.x, a.y - b.y, a.z - b.z);
		}

		public static V3 operator -(V3 a)
		{
			return new V3(0f - a.x, 0f - a.y, 0f - a.z);
		}

		public static V3 operator *(V3 a, float s)
		{
			return new V3(a.x * s, a.y * s, a.z * s);
		}

		public static V3 operator *(float s, V3 a)
		{
			return a * s;
		}

		pu