Decompiled source of ZapGun v1.0.0

plugins/ZapGun.dll

Decompiled 15 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
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 ZapGun.Model;

[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("ZapGun")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ZapGun")]
[assembly: AssemblyTitle("ZapGun")]
[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.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;
		}

		public static float Dot(V3 a, V3 b)
		{
			return a.x * b.x + a.y * b.y + a.z * b.z;
		}

		public static V3 Cross(V3 a, V3 b)
		{
			return new V3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
		}
	}
	public struct V2
	{
		public float x;

		public float y;

		public V2(float x, float y)
		{
			this.x = x;
			this.y = y;
		}
	}
	public struct UvRect
	{
		public float u0;

		public float v0;

		public float u1;

		public float v1;

		public V2 Center => Map(0.5f, 0.5f);

		public UvRect(float u0, float v0, float u1, float v1)
		{
			this.u0 = u0;
			this.v0 = v0;
			this.u1 = u1;
			this.v1 = v1;
		}

		public V2 Map(float s, float t)
		{
			return new V2(u0 + (u1 - u0) * s, v0 + (v1 - v0) * t);
		}
	}
	public class MeshData
	{
		public readonly List<V3> Positions = new List<V3>();

		public readonly List<V3> Normals = new List<V3>();

		public readonly List<V2> Uvs = new List<V2>();

		public readonly List<int>[] Submeshes;

		public MeshData(int submeshCount)
		{
			Submeshes = new List<int>[submeshCount];
			for (int i = 0; i < submeshCount; i++)
			{
				Submeshes[i] = new List<int>();
			}
		}

		public int AddVertex(V3 p, V3 n, V2 uv)
		{
			Positions.Add(p);
			Normals.Add(n.Normalized);
			Uvs.Add(uv);
			return Positions.Count - 1;
		}

		public void Tri(int sub, int a, int b, int c)
		{
			V3 v = Positions[a];
			V3 v2 = Positions[b];
			V3 a2 = V3.Cross(b: Positions[c] - v, a: v2 - v);
			if (!(a2.Length < 1E-12f))
			{
				V3 b2 = Normals[a] + Normals[b] + Normals[c];
				if (V3.Dot(a2, b2) < 0f)
				{
					int num = b;
					b = c;
					c = num;
				}
				Submeshes[sub].Add(a);
				Submeshes[sub].Add(b);
				Submeshes[sub].Add(c);
			}
		}

		public void Quad(int sub, int a, int b, int c, int d)
		{
			Tri(sub, a, b, c);
			Tri(sub, a, c, d);
		}

		public void Bounds(out V3 min, out V3 max)
		{
			min = new V3(float.MaxValue, float.MaxValue, float.MaxValue);
			max = new V3(float.MinValue, float.MinValue, float.MinValue);
			foreach (V3 position in Positions)
			{
				min = new V3(Math.Min(min.x, position.x), Math.Min(min.y, position.y), Math.Min(min.z, position.z));
				max = new V3(Math.Max(max.x, position.x), Math.Max(max.y, position.y), Math.Max(max.z, position.z));
			}
		}
	}
	public static class TvGeometry
	{
		public enum Control
		{
			ChannelUp,
			ChannelDown,
			Volume,
			Power,
			Shuffle,
			Brightness
		}

		public enum Face
		{
			Front,
			Back,
			Left,
			Right,
			Top,
			Bottom
		}

		public struct Ring
		{
			public V3 C;

			public float Hw;

			public float Hh;

			public float R;

			public const int CornerSeg = 6;

			public int Count => 28;

			public Ring(V3 c, float hw, float hh, float r)
			{
				C = c;
				Hw = hw;
				Hh = hh;
				R = Math.Min(r, Math.Min(hw, hh));
			}

			public V3 Point(int i, out V3 outward)
			{
				int num = i / 7;
				int num2 = i % 7;
				double num3 = (double)num * Math.PI / 2.0 + (double)num2 * (Math.PI / 2.0) / 6.0;
				float num4 = ((num == 0 || num == 3) ? 1 : (-1));
				float num5 = ((num == 0 || num == 1) ? 1 : (-1));
				V3 v = new V3(num4 * (Hw - R), num5 * (Hh - R), 0f);
				outward = new V3((float)Math.Cos(num3), (float)Math.Sin(num3), 0f);
				return C + v + outward * R;
			}
		}

		public const int SubBody = 0;

		public const int SubScreen = 1;

		public const float Width = 0.72f;

		public const float Height = 0.48f;

		public const float FrontDepth = 0.3f;

		public const float BackDepth = 0.2f;

		public const float FootHeight = 0.025f;

		public const float Corner = 0.035f;

		public const float ScreenCx = 0.10500002f;

		public const float ScreenCy = 0.035f;

		public const float ScreenHalfW = 0.205f;

		public const float ScreenHalfH = 0.165f;

		public const float SliderHalfTravel = 0.06f;

		public const float LeverOnAngle = 32f;

		public const float LeverOffAngle = -32f;

		public static float BodyBottom => 0.025f;

		public static float BodyCenterY => 0.265f;

		public static float FrontZ => 0.15f;

		public static float CenterZ => 0f;

		public static float ColumnX => -0.251f;

		public static float SubColLeft => ColumnX + 0.052f;

		public static float SubColRight => ColumnX - 0.052f;

		public static V3 LedPos => ControlPos(Control.Power) + new V3(0f, 0.045f, 0f);

		public static V3 ControlPos(Control c)
		{
			float bodyCenterY = BodyCenterY;
			float frontZ = FrontZ;
			return c switch
			{
				Control.ChannelUp => new V3(SubColLeft, bodyCenterY + 0.168f, frontZ), 
				Control.ChannelDown => new V3(SubColLeft, bodyCenterY + 0.124f, frontZ), 
				Control.Volume => new V3(SubColRight, bodyCenterY + 0.15f, frontZ), 
				Control.Brightness => new V3(ColumnX, bodyCenterY + 0.03f, frontZ), 
				Control.Shuffle => new V3(SubColRight, bodyCenterY - 0.09f, frontZ), 
				_ => new V3(SubColLeft, bodyCenterY - 0.09f, frontZ), 
			};
		}

		public static float ControlHitRadius(Control c)
		{
			if (c != Control.Volume)
			{
				return 0.024f;
			}
			return 0.04f;
		}

		public static MeshData BuildControl(Control c)
		{
			MeshData meshData = new MeshData(1);
			switch (c)
			{
			case Control.ChannelUp:
				RoundedBox(meshData, new V3(0f, 0f, 0.007f), new V3(0.02f, 0.017f, 0.007f), 0.005f, 2, (Face f) => (f != Face.Front) ? TvTexture.ButtonCream : TvTexture.ButtonUp);
				break;
			case Control.ChannelDown:
				RoundedBox(meshData, new V3(0f, 0f, 0.007f), new V3(0.02f, 0.017f, 0.007f), 0.005f, 2, (Face f) => (f != Face.Front) ? TvTexture.ButtonCream : TvTexture.ButtonDown);
				break;
			case Control.Volume:
				Cylinder(meshData, V3.Zero, 0.028f, 0.02f, 24, TvTexture.DialDark, TvTexture.DialFace);
				break;
			case Control.Brightness:
				RoundedBox(meshData, new V3(0f, 0f, 0.006f), new V3(0.008f, 0.014f, 0.006f), 0.003f, 2, (Face f) => (f != Face.Front) ? TvTexture.ButtonCream : TvTexture.SliderKnob);
				break;
			case Control.Shuffle:
				RoundedBox(meshData, new V3(0f, 0f, 0.003f), new V3(0.012f, 0.018f, 0.003f), 0.002f, 2, (Face _) => TvTexture.DialDark);
				break;
			default:
				RoundedBox(meshData, new V3(0f, 0f, 0.008f), new V3(0.02f, 0.016f, 0.008f), 0.005f, 2, (Face _) => TvTexture.ButtonRed);
				break;
			}
			return meshData;
		}

		public static MeshData BuildShuffleLever(float tiltDeg = 0f)
		{
			MeshData meshData = new MeshData(1);
			RoundedBox(meshData, new V3(0f, 0f, 0.014f), new V3(0.0045f, 0.0045f, 0.012f), 0.0025f, 2, (Face _) => TvTexture.ButtonCream);
			float cs;
			float sn;
			if (tiltDeg != 0f)
			{
				double num = (double)tiltDeg * Math.PI / 180.0;
				cs = (float)Math.Cos(num);
				sn = (float)Math.Sin(num);
				for (int num2 = 0; num2 < meshData.Positions.Count; num2++)
				{
					meshData.Positions[num2] = Rot(meshData.Positions[num2]);
					meshData.Normals[num2] = Rot(meshData.Normals[num2]);
				}
			}
			return meshData;
			V3 Rot(V3 p)
			{
				return new V3(p.x, p.y * cs - p.z * sn, p.y * sn + p.z * cs);
			}
		}

		public static MeshData BuildLed()
		{
			MeshData meshData = new MeshData(1);
			Cylinder(meshData, V3.Zero, 0.006f, 0.004f, 12, TvTexture.Led, TvTexture.Led);
			return meshData;
		}

		public static void Append(MeshData dst, MeshData src, V3 o)
		{
			int count = dst.Positions.Count;
			for (int i = 0; i < src.Positions.Count; i++)
			{
				dst.AddVertex(src.Positions[i] + o, src.Normals[i], src.Uvs[i]);
			}
			for (int j = 0; j < src.Submeshes.Length; j++)
			{
				foreach (int item in src.Submeshes[j])
				{
					dst.Submeshes[0].Add(count + item);
				}
			}
		}

		public static MeshData Build(bool includeControls = true)
		{
			MeshData meshData = new MeshData(2);
			float bodyCenterY = BodyCenterY;
			RoundedBox(meshData, new V3(0f, bodyCenterY, 0f), new V3(0.36f, 0.24f, 0.15f), 0.035f, 4, (Face face) => (face != Face.Front) ? TvTexture.Plastic : TvTexture.FrontPanel);
			float num = -0.14500001f;
			float z = num - 0.2f;
			Loft(meshData, new Ring(new V3(0f, bodyCenterY - 0.005f, num), 0.3f, 0.2f, 0.05f), new Ring(new V3(0f, bodyCenterY - 0.02f, num - 0.11000001f), 0.235f, 0.17f, 0.05f), TvTexture.Plastic);
			Loft(meshData, new Ring(new V3(0f, bodyCenterY - 0.02f, num - 0.11000001f), 0.235f, 0.17f, 0.05f), new Ring(new V3(0f, bodyCenterY - 0.035f, z), 0.15f, 0.105f, 0.045f), TvTexture.Plastic);
			Cap(meshData, new Ring(new V3(0f, bodyCenterY - 0.035f, z), 0.15f, 0.105f, 0.045f), new V3(0f, 0f, -1f), TvTexture.BackVents);
			FlatPanel(meshData, new V3(0f, bodyCenterY + 0.183f, num - 0.075f), 0.17f, 0.06f, new V3(0f, 1f, 0.12f).Normalized, TvTexture.TopVents);
			float frontZ = FrontZ;
			V3 v = new V3(0.10500002f, bodyCenterY + 0.035f, frontZ);
			float num2 = 0.247f;
			float num3 = 0.207f;
			float num4 = 0.227f;
			float num5 = 0.187f;
			Loft(meshData, new Ring(v + new V3(0f, 0f, -0.002f), num2, num3, 0.045f), new Ring(v + new V3(0f, 0f, 0.02f), num2 - 0.004f, num3 - 0.004f, 0.043f), TvTexture.BezelLip);
			FrameOnFace(meshData, v + new V3(0f, 0f, 0.02f), num4, num5, 0.04f, num2 - 0.004f, num3 - 0.004f, 0.043f, TvTexture.BezelLip);
			Loft(meshData, new Ring(v + new V3(0f, 0f, 0.02f), num4, num5, 0.04f), new Ring(v + new V3(0f, 0f, 0.0039999997f), 0.20899999f, 0.169f, 0.035f), TvTexture.Bezel, inward: true);
			Screen(meshData, v + new V3(0f, 0f, 0.003f), 0.213f, 0.17300001f, 0.012f);
			if (includeControls)
			{
				foreach (Control value in Enum.GetValues(typeof(Control)))
				{
					MeshData src = BuildControl(value);
					Append(meshData, src, ControlPos(value));
				}
			}
			if (includeControls)
			{
				Append(meshData, BuildLed(), LedPos);
			}
			if (includeControls)
			{
				Append(meshData, BuildShuffleLever(32f), ControlPos(Control.Shuffle) + new V3(0f, 0f, 0.004f));
			}
			float y = 0.505f;
			V3 v2 = new V3(0f, y, -0.04f);
			RoundedBox(meshData, v2 + new V3(0f, 0.012f, 0f), new V3(0.04f, 0.014f, 0.03f), 0.012f, 3, (Face _) => TvTexture.DialDark);
			float[] array = new float[2] { 1f, -1f };
			foreach (float num7 in array)
			{
				V3 normalized = new V3(0.53f * num7, 0.84f, -0.12f).Normalized;
				V3 v3 = v2 + new V3(0.018f * num7, 0.022f, 0f);
				V3 v4 = v3 + normalized * 0.34f;
				Rod(meshData, v3, v4, 0.0045f, 10, TvTexture.Metal);
				RoundedBox(meshData, v4, new V3(0.009f, 0.009f, 0.009f), 0.0089f, 3, (Face _) => TvTexture.Metal);
			}
			float num8 = 0.29000002f;
			float num9 = 71f / (226f * MathF.PI);
			V3[] array2 = new V3[4]
			{
				new V3(0f - num8, 0f, num9),
				new V3(num8, 0f, num9),
				new V3((0f - num8) * 0.8f, 0f, 0f - num9),
				new V3(num8 * 0.8f, 0f, 0f - num9)
			};
			foreach (V3 v5 in array2)
			{
				RoundedBox(meshData, v5 + new V3(0f, 0.0165f, 0f), new V3(0.035f, 0.0165f, 0.03f), 0.006f, 2, (Face _) => TvTexture.Rubber);
			}
			return meshData;
		}

		public static void Rod(MeshData m, V3 a, V3 b, float radius, int seg, UvRect uv)
		{
			V3 normalized = (b - a).Normalized;
			V3 normalized2 = V3.Cross(b: (Math.Abs(normalized.y) < 0.9f) ? new V3(0f, 1f, 0f) : new V3(1f, 0f, 0f), a: normalized).Normalized;
			V3 normalized3 = V3.Cross(normalized, normalized2).Normalized;
			int[] array = new int[seg + 1];
			int[] array2 = new int[seg + 1];
			for (int i = 0; i <= seg; i++)
			{
				double num = (double)(i * 2) * Math.PI / (double)seg;
				V3 v = normalized2 * (float)Math.Cos(num) + normalized3 * (float)Math.Sin(num);
				array[i] = m.AddVertex(a + v * radius, v, uv.Map((float)i / (float)seg, 0f));
				array2[i] = m.AddVertex(b + v * radius, v, uv.Map((float)i / (float)seg, 1f));
			}
			for (int j = 0; j < seg; j++)
			{
				m.Quad(0, array[j], array[j + 1], array2[j + 1], array2[j]);
			}
		}

		public static void RoundedBox(MeshData m, V3 c, V3 h, float r, int seg, Func<Face, UvRect> uvFor)
		{
			r = Math.Min(r, Math.Min(h.x, Math.Min(h.y, h.z)) * 0.99f);
			V3 inner = new V3(h.x - r, h.y - r, h.z - r);
			float[] us = Axis(h.x, inner.x);
			float[] vs = Axis(h.y, inner.y);
			float[] array = Axis(h.z, inner.z);
			DoFace(Face.Front, new V3(0f, 0f, 1f), (float u, float v) => new V3(0f - u, v, h.z), us, vs, h.x, h.y);
			DoFace(Face.Back, new V3(0f, 0f, -1f), (float u, float v) => new V3(u, v, 0f - h.z), us, vs, h.x, h.y);
			DoFace(Face.Right, new V3(1f, 0f, 0f), (float u, float v) => new V3(h.x, v, u), array, vs, h.z, h.y);
			DoFace(Face.Left, new V3(-1f, 0f, 0f), (float u, float v) => new V3(0f - h.x, v, 0f - u), array, vs, h.z, h.y);
			DoFace(Face.Top, new V3(0f, 1f, 0f), (float u, float v) => new V3(u, h.y, 0f - v), us, array, h.x, h.z);
			DoFace(Face.Bottom, new V3(0f, -1f, 0f), (float u, float v) => new V3(u, 0f - h.y, v), us, array, h.x, h.z);
			float[] Axis(float half, float inn)
			{
				List<float> list = new List<float>();
				for (int i = 0; i <= seg; i++)
				{
					list.Add(0f - half + (half - inn) * (float)(1.0 - Math.Cos((double)i * Math.PI / 2.0 / (double)seg)));
				}
				for (int num = seg; num >= 0; num--)
				{
					list.Add(half - (half - inn) * (float)(1.0 - Math.Cos((double)num * Math.PI / 2.0 / (double)seg)));
				}
				return list.ToArray();
			}
			void DoFace(Face f, V3 n, Func<float, float, V3> pt, float[] array3, float[] array4, float uHalf, float vHalf)
			{
				UvRect uvRect = uvFor(f);
				int[,] array2 = new int[array3.Length, array4.Length];
				for (int i = 0; i < array3.Length; i++)
				{
					for (int j = 0; j < array4.Length; j++)
					{
						V3 v = pt(array3[i], array4[j]);
						V3 v2 = new V3(Clamp(v.x, inner.x), Clamp(v.y, inner.y), Clamp(v.z, inner.z));
						V3 v3 = v - v2;
						V3 v4 = ((v3.Length > 1E-07f) ? v3.Normalized : n);
						V3 v5 = v2 + v4 * r;
						array2[i, j] = m.AddVertex(c + v5, v4, uvRect.Map((array3[i] + uHalf) / (2f * uHalf), (array4[j] + vHalf) / (2f * vHalf)));
					}
				}
				for (int k = 0; k < array3.Length - 1; k++)
				{
					for (int l = 0; l < array4.Length - 1; l++)
					{
						m.Quad(0, array2[k, l], array2[k + 1, l], array2[k + 1, l + 1], array2[k, l + 1]);
					}
				}
			}
		}

		private static float Clamp(float v, float lim)
		{
			if (!(v < 0f - lim))
			{
				if (!(v > lim))
				{
					return v;
				}
				return lim;
			}
			return 0f - lim;
		}

		public static void Loft(MeshData m, Ring a, Ring b, UvRect uv, bool inward = false)
		{
			int count = a.Count;
			int[] array = new int[count + 1];
			int[] array2 = new int[count + 1];
			V3 normalized = (b.C - a.C).Normalized;
			for (int i = 0; i <= count; i++)
			{
				V3 outward;
				V3 v = a.Point(i % count, out outward);
				V3 outward2;
				V3 v2 = b.Point(i % count, out outward2);
				V3 a2 = v2 - v;
				V3 v3 = outward - normalized * V3.Dot(outward, a2.Normalized) * 0f;
				V3 b2 = V3.Cross(new V3(0f, 0f, 1f), outward);
				v3 = V3.Cross(a2, b2).Normalized;
				if (V3.Dot(v3, outward) < 0f)
				{
					v3 = -v3;
				}
				if (inward)
				{
					v3 = -v3;
				}
				float s = (float)i / (float)count;
				array[i] = m.AddVertex(v, v3, uv.Map(s, 0f));
				array2[i] = m.AddVertex(v2, v3, uv.Map(s, 1f));
			}
			for (int j = 0; j < count; j++)
			{
				m.Quad(0, array[j], array[j + 1], array2[j + 1], array2[j]);
			}
		}

		public static void Cap(MeshData m, Ring r, V3 normal, UvRect uv)
		{
			int a = m.AddVertex(r.C, normal, uv.Center);
			int count = r.Count;
			int[] array = new int[count];
			for (int i = 0; i < count; i++)
			{
				V3 outward;
				V3 p = r.Point(i, out outward);
				float num = (p.x - r.C.x) / (2f * r.Hw) + 0.5f;
				if (normal.z > 0f)
				{
					num = 1f - num;
				}
				array[i] = m.AddVertex(p, normal, uv.Map(num, (p.y - r.C.y) / (2f * r.Hh) + 0.5f));
			}
			for (int j = 0; j < count; j++)
			{
				m.Tri(0, a, array[j], array[(j + 1) % count]);
			}
		}

		public static void FrameOnFace(MeshData m, V3 c, float ihw, float ihh, float ir, float ohw, float ohh, float or, UvRect uv)
		{
			Ring ring = new Ring(c, ihw, ihh, ir);
			Ring ring2 = new Ring(c, ohw, ohh, or);
			int count = ring.Count;
			V3 n = new V3(0f, 0f, 1f);
			int[] array = new int[count];
			int[] array2 = new int[count];
			for (int i = 0; i < count; i++)
			{
				array[i] = m.AddVertex(ring.Point(i, out var outward), n, uv.Map((float)i / (float)count, 0f));
				array2[i] = m.AddVertex(ring2.Point(i, out outward), n, uv.Map((float)i / (float)count, 1f));
			}
			for (int j = 0; j < count; j++)
			{
				m.Quad(0, array[j], array[(j + 1) % count], array2[(j + 1) % count], array2[j]);
			}
		}

		public static void FlatPanel(MeshData m, V3 c, float hw, float hh, V3 normal, UvRect uv)
		{
			V3 v = new V3(1f, 0f, 0f);
			V3 normalized = V3.Cross(normal, v).Normalized;
			int a = m.AddVertex(c - v * hw - normalized * hh, normal, uv.Map(0f, 0f));
			int b = m.AddVertex(c + v * hw - normalized * hh, normal, uv.Map(1f, 0f));
			int c2 = m.AddVertex(c + v * hw + normalized * hh, normal, uv.Map(1f, 1f));
			int d = m.AddVertex(c - v * hw + normalized * hh, normal, uv.Map(0f, 1f));
			m.Quad(0, a, b, c2, d);
		}

		public static void Cylinder(MeshData m, V3 baseC, float radius, float length, int seg, UvRect side, UvRect face)
		{
			V3 v = new V3(0f, 0f, 1f);
			int[] array = new int[seg + 1];
			int[] array2 = new int[seg + 1];
			int[] array3 = new int[seg];
			for (int i = 0; i <= seg; i++)
			{
				double num = (double)(i * 2) * Math.PI / (double)seg;
				V3 v2 = new V3((float)Math.Cos(num), (float)Math.Sin(num), 0f);
				array[i] = m.AddVertex(baseC + v2 * radius, v2, side.Map((float)i / (float)seg, 0f));
				array2[i] = m.AddVertex(baseC + v2 * (radius * 0.9f) + v * length, v2, side.Map((float)i / (float)seg, 1f));
			}
			for (int j = 0; j < seg; j++)
			{
				m.Quad(0, array[j], array[j + 1], array2[j + 1], array2[j]);
			}
			int a = m.AddVertex(baseC + v * length, v, face.Center);
			for (int k = 0; k < seg; k++)
			{
				double num2 = (double)(k * 2) * Math.PI / (double)seg;
				V3 v3 = new V3((float)Math.Cos(num2), (float)Math.Sin(num2), 0f);
				array3[k] = m.AddVertex(baseC + v3 * (radius * 0.9f) + v * length, v, face.Map(0.5f + 0.5f * (float)Math.Cos(num2), 0.5f + 0.5f * (float)Math.Sin(num2)));
			}
			for (int l = 0; l < seg; l++)
			{
				m.Tri(0, a, array3[l], array3[(l + 1) % seg]);
			}
		}

		public static void Screen(MeshData m, V3 c, float hw, float hh, float bulge)
		{
			int[,] array = new int[25, 25];
			for (int i = 0; i <= 24; i++)
			{
				for (int j = 0; j <= 24; j++)
				{
					float num = -1f + 2f * (float)i / 24f;
					float num2 = -1f + 2f * (float)j / 24f;
					float num3 = Math.Max(Math.Abs(num), Math.Abs(num2));
					float num4 = (float)Math.Pow(Math.Pow(Math.Abs(num), 6.0) + Math.Pow(Math.Abs(num2), 6.0), 1.0 / 6.0);
					float num5 = ((num4 > 1E-06f) ? (num3 / num4) : 1f);
					float num6 = num * num5;
					float num7 = num2 * num5;
					float num8 = (num6 * num6 + num7 * num7) / 2f;
					float z = bulge * (1f - num8);
					V3 p = c + new V3(num6 * hw, num7 * hh, z);
					V3 normalized = new V3(bulge * num6 / hw, bulge * num7 / hh, 1f).Normalized;
					array[i, j] = m.AddVertex(p, normalized, new V2((1f - num6) / 2f, (num7 + 1f) / 2f));
				}
			}
			for (int k = 0; k < 24; k++)
			{
				for (int l = 0; l < 24; l++)
				{
					m.Quad(1, array[k, l], array[k + 1, l], array[k + 1, l + 1], array[k, l + 1]);
				}
			}
		}
	}
	public sealed class TvLayout
	{
		public int Id;

		public Func<TvGeometry.Control, V3> Pos;

		public Func<TvGeometry.Control, float> HitRadius;

		public Func<TvGeometry.Control, MeshData> BuildControl = TvGeometry.BuildControl;

		public V3 LedPos;

		public float SliderHalfTravel;

		public float ControlScale = 1f;

		public V3 SpeakerPos;

		public int RenderWidth;

		public int RenderHeight;

		public static readonly TvLayout Crt = new TvLayout
		{
			Id = 0,
			Pos = TvGeometry.ControlPos,
			HitRadius = (TvGeometry.Control c) => (c != TvGeometry.Control.Brightness) ? TvGeometry.ControlHitRadius(c) : 0.02f,
			LedPos = TvGeometry.LedPos,
			SliderHalfTravel = 0.06f,
			SpeakerPos = new V3(0f, TvGeometry.BodyCenterY, 0.1f),
			RenderWidth = 640,
			RenderHeight = 480
		};

		public static readonly TvLayout Flat = new TvLayout
		{
			Id = 1,
			Pos = FlatGeometry.ControlPos,
			BuildControl = FlatGeometry.BuildControl,
			HitRadius = (TvGeometry.Control c) => (c != TvGeometry.Control.Brightness) ? FlatGeometry.ControlHitRadius(c) : 0.027999999f,
			LedPos = FlatGeometry.LedPos,
			SliderHalfTravel = 0.084f,
			ControlScale = 1.4f,
			SpeakerPos = new V3(0f, FlatGeometry.ScreenCy, 0f),
			RenderWidth = 1280,
			RenderHeight = 720
		};

		public static TvLayout Get(int id)
		{
			if (id != 1)
			{
				return Crt;
			}
			return Flat;
		}
	}
	public static class TvTexture
	{
		public const int Size = 1024;

		private const float S = 1024f;

		private const int FpX = 0;

		private const int FpY = 512;

		private const int FpW = 768;

		private const int FpH = 512;

		public static readonly UvRect FrontPanel = Px(0, 512, 768, 1024);

		public static readonly UvRect Plastic = Px(256, 0, 512, 256);

		public static readonly UvRect BackVents = Px(0, 256, 128, 384);

		public static readonly UvRect TopVents = Px(128, 256, 256, 384);

		public static readonly UvRect Bezel = Px(256, 256, 320, 320);

		public static readonly UvRect BezelLip = Px(320, 256, 384, 320);

		public static readonly UvRect DialDark = Sw(384, 256);

		public static readonly UvRect DialFace = Px(416, 256, 448, 288);

		public static readonly UvRect ButtonRed = Sw(448, 256);

		public static readonly UvRect ButtonCream = Sw(480, 256);

		public static readonly UvRect ButtonAmber = Sw(384, 288);

		public static readonly UvRect Led = Sw(416, 288);

		public static readonly UvRect Rubber = Sw(448, 288);

		public static readonly UvRect ButtonUp = Px(384, 320, 416, 352);

		public static readonly UvRect ButtonDown = Px(416, 320, 448, 352);

		public static readonly UvRect Metal = Sw(448, 320);

		public static readonly UvRect SliderKnob = Px(480, 320, 512, 352);

		public static readonly UvRect ButtonLeft = Px(512, 0, 544, 32);

		public static readonly UvRect ButtonRight = Px(544, 0, 576, 32);

		private const int ChinX = 978;

		private const int ChinW = 46;

		private const int ChinLen = 1024;

		public static readonly UvRect Chin = Px(978, 0, 1024, 1024);

		private static readonly byte[] Grey = new byte[3] { 112, 112, 108 };

		private static readonly byte[] DarkGrey = new byte[3] { 46, 46, 46 };

		private static readonly byte[] Darker = new byte[3] { 30, 30, 30 };

		private static readonly byte[] Slot = new byte[3] { 20, 20, 20 };

		private static readonly byte[] LabelCol = new byte[3] { 205, 200, 185 };

		private static readonly string Glyphs = "A:01110100011000111111100011000110001|B:11110100011000111110100011000111110|C:01110100011000010000100001000101110|D:11110100011000110001100011000111110|E:11111100001000011110100001000011111|F:11111100001000011110100001000010000|G:01110100011000010111100011000101111|H:10001100011000111111100011000110001|I:01110001000010000100001000010001110|K:10001100101010011000101001001010001|L:10000100001000010000100001000011111|M:10001110111010110101100011000110001|N:10001110011010110011100011000110001|O:01110100011000110001100011000101110|P:11110100011000111110100001000010000|R:11110100011000111110101001001010001|S:01111100001000001110000010000111110|T:11111001000010000100001000010000100|U:10001100011000110001100011000101110|V:10001100011000110001100010101000100|W:10001100011000110101101011010101010|X:10001100010101000100010101000110001|Y:10001100010101000100001000010000100|Z:11111000010001000100010001000011111|8:01110100011000101110100011000101110|-:00000000000000011111000000000000000| :00000000000000000000000000000000000";

		private static UvRect Px(int x0, int y0, int x1, int y1)
		{
			return new UvRect((float)x0 / 1024f, (float)y0 / 1024f, (float)x1 / 1024f, (float)y1 / 1024f);
		}

		private static UvRect Sw(int x0, int y0)
		{
			return Px(x0 + 6, y0 + 6, x0 + 26, y0 + 26);
		}

		public static byte[] Build(string brand = "VIDEOMATIC")
		{
			byte[] array = new byte[4194304];
			Random rng = new Random(1234);
			Fill(array, 0, 0, 1024, 1024, Grey, rng, 7);
			Scuffs(array, 256, 0, 512, 256, rng, 40);
			Scuffs(array, 0, 512, 768, 1024, rng, 45);
			PaintFrontPanel(array, brand);
			PaintChin(array, brand, rng);
			Fill(array, 0, 256, 128, 384, Grey, rng, 7);
			for (int i = 0; i < 9; i++)
			{
				Rect(array, 14, 270 + i * 12, 114, 275 + i * 12, Slot);
			}
			Fill(array, 128, 256, 256, 384, Grey, rng, 7);
			for (int j = 0; j < 12; j++)
			{
				Rect(array, 138 + j * 9, 266, 142 + j * 9, 374, Slot);
			}
			Fill(array, 256, 256, 320, 320, DarkGrey, rng, 4);
			Fill(array, 320, 256, 384, 320, Darker, rng, 3);
			Fill(array, 384, 256, 416, 288, new byte[3] { 38, 38, 38 }, rng, 3);
			Fill(array, 416, 256, 448, 288, new byte[3] { 52, 52, 52 }, rng, 3);
			Rect(array, 430, 270, 434, 286, new byte[3] { 220, 220, 210 });
			Fill(array, 448, 256, 480, 288, new byte[3] { 150, 45, 40 }, rng, 4);
			Fill(array, 480, 256, 512, 288, new byte[3] { 200, 192, 168 }, rng, 4);
			Fill(array, 384, 288, 416, 320, new byte[3] { 190, 140, 50 }, rng, 4);
			Fill(array, 416, 288, 448, 320, new byte[3] { 255, 60, 40 }, rng, 0);
			Fill(array, 448, 288, 480, 320, new byte[3] { 24, 24, 24 }, rng, 2);
			Fill(array, 384, 320, 448, 352, new byte[3] { 200, 192, 168 }, rng, 4);
			Triangle(array, 400, 336, 7, up: true, new byte[3] { 45, 42, 38 });
			Triangle(array, 432, 336, 7, up: false, new byte[3] { 45, 42, 38 });
			Fill(array, 512, 0, 576, 32, new byte[3] { 200, 192, 168 }, rng, 4);
			TriangleSide(array, 528, 16, 7, right: false, new byte[3] { 45, 42, 38 });
			TriangleSide(array, 560, 16, 7, right: true, new byte[3] { 45, 42, 38 });
			Fill(array, 448, 320, 480, 352, new byte[3] { 176, 176, 172 }, rng, 6);
			Fill(array, 480, 320, 512, 352, new byte[3] { 200, 192, 168 }, rng, 4);
			Rect(array, 494, 324, 498, 348, new byte[3] { 60, 56, 50 });
			return array;
		}

		private static void PaintChin(byte[] px, string brand, Random rng)
		{
			float ppmA = 1024f / FlatGeometry.PanelW;
			float ppmH = 255.55554f;
			for (int i = 0; i < 1024; i++)
			{
				for (int j = 0; j < 46; j++)
				{
					int num = rng.Next(-2, 3);
					CSet(i, j, new byte[3]
					{
						C(58 + num),
						C(58 + num),
						C(60 + num)
					});
				}
			}
			byte[] col = new byte[3] { 200, 198, 190 };
			int num2 = A(0f);
			CText(brand, num2 - 20, 16, 2, col);
			int num3 = num2 + brand.Length * 12 / 2 + 10;
			for (int k = num3 - 4; k < num3 + 30; k++)
			{
				for (int l = 13; l < 33; l++)
				{
					CSet(k, l, new byte[3] { 150, 30, 30 });
				}
			}
			CText("8K", num3 + 13, 16, 2, new byte[3] { 240, 236, 230 });
			byte[] lab = new byte[3] { 232, 228, 216 };
			V3 v = FlatGeometry.ControlPos(TvGeometry.Control.ChannelUp);
			V3 v2 = FlatGeometry.ControlPos(TvGeometry.Control.ChannelDown);
			Label("CH", (v.x + v2.x) / 2f);
			Label("VOL", FlatGeometry.ControlPos(TvGeometry.Control.Volume).x);
			Label("BRIGHT", FlatGeometry.ControlPos(TvGeometry.Control.Brightness).x);
			Label("RANDOM", FlatGeometry.ControlPos(TvGeometry.Control.Shuffle).x);
			Label("POWER", FlatGeometry.ControlPos(TvGeometry.Control.Power).x);
			V3 v3 = FlatGeometry.ControlPos(TvGeometry.Control.Volume);
			for (int m = 0; m <= 8; m++)
			{
				double num4 = (225.0 - (double)m * 270.0 / 8.0) * Math.PI / 180.0;
				for (float num5 = 0.0462f; num5 < 0.055999998f; num5 += 0.0005f)
				{
					CSet(A(v3.x) + (int)Math.Round(Math.Cos(num4) * (double)num5 * (double)ppmA), H(v3.y) + (int)Math.Round(Math.Sin(num4) * (double)num5 * (double)ppmH), lab);
				}
			}
			V3 v4 = FlatGeometry.ControlPos(TvGeometry.Control.Brightness);
			float num6 = 0.0952f;
			int num7 = A(v4.x + num6);
			int num8 = A(v4.x - num6);
			int num9 = H(v4.y);
			for (int n = num7; n <= num8; n++)
			{
				for (int num10 = num9 - 2; num10 <= num9 + 2; num10++)
				{
					CSet(n, num10, Slot);
				}
			}
			int A(float worldX)
			{
				return (int)Math.Round((0f - worldX + FlatGeometry.PanelW / 2f) * ppmA);
			}
			void CSet(int a, int h, byte[] array)
			{
				if (a >= 0 && a < 1024 && h >= 0 && h < 46)
				{
					Set(px, 978 + h, a, array[0], array[1], array[2]);
				}
			}
			void CText(string s, int a, int h, int scale, byte[] col2)
			{
				s = s.ToUpperInvariant();
				a -= (s.Length * 6 * scale - scale) / 2;
				string text = s;
				for (int num11 = 0; num11 < text.Length; num11++)
				{
					string text2 = Glyph(text[num11]);
					if (text2 != null)
					{
						for (int num12 = 0; num12 < 7; num12++)
						{
							for (int num13 = 0; num13 < 5; num13++)
							{
								if (text2[num12 * 5 + num13] == '1')
								{
									for (int num14 = 0; num14 < scale; num14++)
									{
										for (int num15 = 0; num15 < scale; num15++)
										{
											CSet(a + num13 * scale + num14, h + (6 - num12) * scale + num15, col2);
										}
									}
								}
							}
						}
					}
					a += 6 * scale;
				}
			}
			int H(float worldY)
			{
				return (int)Math.Round((worldY - 0.14f) * ppmH);
			}
			void Label(string t, float wx)
			{
				CText(t, A(wx), 3, 1, lab);
			}
		}

		private static void PaintFrontPanel(byte[] px, string brand)
		{
			float ppm = 1066.6666f;
			float num = TvGeometry.BodyCenterY + 0.035f - 0.165f - 0.042f;
			Label(brand, 0.10500002f, (0.025f + num) / 2f, 4);
			V3 v = TvGeometry.ControlPos(TvGeometry.Control.ChannelDown);
			V3 v2 = TvGeometry.ControlPos(TvGeometry.Control.Volume);
			V3 v3 = TvGeometry.ControlPos(TvGeometry.Control.Brightness);
			V3 v4 = TvGeometry.ControlPos(TvGeometry.Control.Power);
			V3 v5 = TvGeometry.ControlPos(TvGeometry.Control.Shuffle);
			Label("CH", v.x, v.y - 0.031f, 2);
			Label("VOL", v2.x, v2.y - 0.052f, 2);
			Label("BRIGHT", v3.x, v3.y - 0.026f, 2);
			Label("POWER", v4.x, v4.y - 0.031f, 2);
			Label("RANDOM", v5.x, v5.y - 0.032f, 2);
			for (int i = 0; i <= 8; i++)
			{
				double num2 = (225.0 - (double)i * 270.0 / 8.0) * Math.PI / 180.0;
				for (float num3 = 0.033f; num3 < 0.04f; num3 += 0.0006f)
				{
					for (int j = -1; j <= 1; j++)
					{
						Set(px, X(v2.x) + (int)Math.Round(Math.Cos(num2) * (double)num3 * (double)ppm) + j, Y(v2.y) + (int)Math.Round(Math.Sin(num2) * (double)num3 * (double)ppm), LabelCol[0], LabelCol[1], LabelCol[2]);
					}
				}
			}
			float num4 = 0.067999996f;
			int num5 = X(v3.x + num4);
			int num6 = X(v3.x - num4);
			int num7 = Y(v3.y);
			Rect(px, num5, num7 - 4, num6, num7 + 4, Slot);
			Rect(px, num5 - 2, num7 - 9, num5 + 1, num7 + 9, Slot);
			Rect(px, num6 - 1, num7 - 9, num6 + 2, num7 + 9, Slot);
			for (int k = 0; k <= 6; k++)
			{
				int num8 = X(v3.x + 0.06f - (float)k * 0.06f / 3f);
				int num9 = ((k == 0 || k == 6) ? 9 : 5);
				Rect(px, num8 - 1, num7 - 14 - num9, num8 + 1, num7 - 14, LabelCol);
			}
			float num10 = TvGeometry.BodyCenterY - 0.16f;
			for (int l = 0; l < 5; l++)
			{
				int num11 = Y(num10 - (float)l * 0.012f);
				Rect(px, X(TvGeometry.ColumnX + 0.08f), num11 - 2, X(TvGeometry.ColumnX - 0.08f), num11 + 2, Slot);
			}
			void Label(string t, float wx, float wy, int scale)
			{
				Text(px, t, X(wx), Y(wy) - 7 * scale / 2, scale, LabelCol, centre: true);
			}
			int X(float worldX)
			{
				return (int)Math.Round((0f - worldX + 0.36f) * ppm);
			}
			int Y(float worldY)
			{
				return 512 + (int)Math.Round((worldY - 0.025f) * ppm);
			}
		}

		public static byte[] BuildScreenOff(int size = 64)
		{
			byte[] array = new byte[size * size * 4];
			for (int i = 0; i < size; i++)
			{
				for (int j = 0; j < size; j++)
				{
					float num = ((float)j + 0.5f) / (float)size - 0.5f;
					float num2 = ((float)i + 0.5f) / (float)size - 0.5f;
					float num3 = 1f - Math.Min(1f, (num * num + num2 * num2) * 2.2f);
					byte b = (byte)(38f + 30f * num3);
					int num4 = (i * size + j) * 4;
					array[num4] = (byte)(b - 2);
					array[num4 + 1] = (byte)(b + 2);
					array[num4 + 2] = b;
					array[num4 + 3] = byte.MaxValue;
				}
			}
			return array;
		}

		private static void Set(byte[] px, int x, int y, byte r, byte g, byte b)
		{
			if (x >= 0 && y >= 0 && x < 1024 && y < 1024)
			{
				int num = (y * 1024 + x) * 4;
				px[num] = r;
				px[num + 1] = g;
				px[num + 2] = b;
				px[num + 3] = byte.MaxValue;
			}
		}

		internal static byte C(int v)
		{
			return (byte)((v >= 0) ? ((v > 255) ? 255u : ((uint)v)) : 0u);
		}

		internal static void Fill(byte[] px, int x0, int y0, int x1, int y1, byte[] col, Random rng, int noise)
		{
			for (int i = y0; i < y1; i++)
			{
				for (int j = x0; j < x1; j++)
				{
					int num = ((noise != 0) ? rng.Next(-noise, noise + 1) : 0);
					Set(px, j, i, C(col[0] + num), C(col[1] + num), C(col[2] + num));
				}
			}
		}

		internal static void Rect(byte[] px, int x0, int y0, int x1, int y1, byte[] col)
		{
			for (int i = y0; i < y1; i++)
			{
				for (int j = x0; j < x1; j++)
				{
					Set(px, j, i, col[0], col[1], col[2]);
				}
			}
		}

		internal static void Scuffs(byte[] px, int x0, int y0, int x1, int y1, Random rng, int count)
		{
			for (int i = 0; i < count; i++)
			{
				int num = rng.Next(x0, x1);
				int num2 = rng.Next(y0, y1);
				int num3 = rng.Next(4, 16);
				int num4 = rng.Next(-14, 10);
				double num5 = rng.NextDouble() * Math.PI;
				for (int j = 0; j < num3; j++)
				{
					int num6 = num + (int)(Math.Cos(num5) * (double)j);
					int num7 = num2 + (int)(Math.Sin(num5) * (double)j);
					if (num6 >= x0 && num6 < x1 && num7 >= y0 && num7 < y1)
					{
						int num8 = (num7 * 1024 + num6) * 4;
						px[num8] = C(px[num8] + num4);
						px[num8 + 1] = C(px[num8 + 1] + num4);
						px[num8 + 2] = C(px[num8 + 2] + num4);
					}
				}
			}
		}

		private static void TriangleSide(byte[] px, int cx, int cy, int r, bool right, byte[] col)
		{
			for (int i = -r; i <= r; i++)
			{
				int num = (right ? i : (-i));
				int num2 = (r - num) * 3 / 4;
				for (int j = -num2; j <= num2; j++)
				{
					Set(px, cx + i, cy + j, col[0], col[1], col[2]);
				}
			}
		}

		private static void Triangle(byte[] px, int cx, int cy, int r, bool up, byte[] col)
		{
			for (int i = -r; i <= r; i++)
			{
				int num = (up ? i : (-i));
				int num2 = (r - num) * 3 / 4;
				for (int j = -num2; j <= num2; j++)
				{
					Set(px, cx + j, cy + i, col[0], col[1], col[2]);
				}
			}
		}

		internal static string Glyph(char c)
		{
			int num = Glyphs.IndexOf(c + ":", StringComparison.Ordinal);
			if (num >= 0)
			{
				return Glyphs.Substring(num + 2, 35);
			}
			return null;
		}

		internal static void Text(byte[] px, string s, int x, int y, int scale, byte[] col, bool centre)
		{
			s = s.ToUpperInvariant();
			int num = s.Length * 6 * scale - scale;
			if (centre)
			{
				x -= num / 2;
			}
			string text = s;
			for (int i = 0; i < text.Length; i++)
			{
				string text2 = Glyph(text[i]);
				if (text2 != null)
				{
					for (int j = 0; j < 7; j++)
					{
						for (int k = 0; k < 5; k++)
						{
							if (text2[j * 5 + k] != '1')
							{
								continue;
							}
							for (int l = 0; l < scale; l++)
							{
								for (int m = 0; m < scale; m++)
								{
									Set(px, x + k * scale + l, y + (6 - j) * scale + m, col[0], col[1], col[2]);
								}
							}
						}
					}
				}
				x += 6 * scale;
			}
		}
	}
}
namespace ZapGun
{
	[HarmonyPatch]
	internal static class Patches
	{
		[HarmonyPatch(typeof(ItemManager), "GetPurchasedItems")]
		[HarmonyPrefix]
		private static void GiveTestZapGun()
		{
			if (!Plugin.StartWithZapGun.Value || !Object.op_Implicit((Object)(object)StatsManager.instance))
			{
				return;
			}
			string key = "Item Zap Gun";
			if (StatsManager.instance.itemDictionary.ContainsKey(key))
			{
				Dictionary<string, int> itemsPurchased = StatsManager.instance.itemsPurchased;
				if (!itemsPurchased.TryGetValue(key, out var value) || value < 1)
				{
					itemsPurchased[key] = 1;
				}
			}
		}
	}
	[BepInPlugin("bigbootyteam.zapgun", "ZapGun", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "bigbootyteam.zapgun";

		public const string Name = "ZapGun";

		public const string Version = "1.0.0";

		internal static ManualLogSource Log;

		internal static ConfigEntry<float> Range;

		internal static ConfigEntry<float> LockAngle;

		internal static ConfigEntry<float> BreakAngle;

		internal static ConfigEntry<float> Wobble;

		internal static ConfigEntry<float> BatterySeconds;

		internal static ConfigEntry<float> ScanSeconds;

		internal static ConfigEntry<float> OverheatSeconds;

		internal static ConfigEntry<float> Shake;

		internal static ConfigEntry<float> DamagePerSecond;

		internal static ConfigEntry<bool> ZapPlayers;

		internal static ConfigEntry<bool> StunHeavyEnemies;

		internal static ConfigEntry<float> PriceMultiplier;

		internal static ConfigEntry<bool> StartWithZapGun;

		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_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Expected O, but got Unknown
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Expected O, but got Unknown
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Range = ((BaseUnityPlugin)this).Config.Bind<float>("Zap", "Range", 12f, new ConfigDescription("How far the beam reaches (metres).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(4f, 30f), Array.Empty<object>()));
			LockAngle = ((BaseUnityPlugin)this).Config.Bind<float>("Zap", "LockAngle", 20f, new ConfigDescription("How close to your crosshair a target must be to lock on (degrees).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(5f, 45f), Array.Empty<object>()));
			BreakAngle = ((BaseUnityPlugin)this).Config.Bind<float>("Zap", "BreakAngle", 35f, new ConfigDescription("How far your aim can drift off the target before the beam snaps (degrees).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 90f), Array.Empty<object>()));
			Wobble = ((BaseUnityPlugin)this).Config.Bind<float>("Zap", "WobbleStrength", 1f, new ConfigDescription("How hard the beam yanks your aim around. 0 = no wobble.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 3f), Array.Empty<object>()));
			BatterySeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Zap", "BatterySeconds", 12f, new ConfigDescription("Seconds of zapping on a full battery.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(3f, 60f), Array.Empty<object>()));
			ScanSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Zap", "ScanSeconds", 0.8f, new ConfigDescription("How long the gun scans before it locks on (stops spamming).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 3f), Array.Empty<object>()));
			OverheatSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Zap", "OverheatSeconds", 3f, new ConfigDescription("How long the gun is out of action after the beam snaps.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 15f), Array.Empty<object>()));
			Shake = ((BaseUnityPlugin)this).Config.Bind<float>("Zap", "ScreenShake", 1f, new ConfigDescription("Screen shake strength while zapping. 0 = off.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 3f), Array.Empty<object>()));
			DamagePerSecond = ((BaseUnityPlugin)this).Config.Bind<float>("Zap", "DamagePerSecond", 20f, new ConfigDescription("Damage per second to an enemy while the beam holds (players only get knocked over). 0 = stun only.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 200f), Array.Empty<object>()));
			ZapPlayers = ((BaseUnityPlugin)this).Config.Bind<bool>("Zap", "ZapPlayers", true, "Can the beam lock onto other players? Zapped players are knocked over (no damage).");
			StunHeavyEnemies = ((BaseUnityPlugin)this).Config.Bind<bool>("Zap", "StunHeavyEnemies", true, "Can the beam stun heavy enemies? The very heaviest are always immune.");
			PriceMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Item", "PriceMultiplier", 1f, new ConfigDescription("Shop price relative to REPO's stun gun (the host's setting is used).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 10f), Array.Empty<object>()));
			StartWithZapGun = ((BaseUnityPlugin)this).Config.Bind<bool>("Testing", "StartWithZapGun", false, "If true (host only), every run starts with a free zap gun in the truck.");
			new Harmony("bigbootyteam.zapgun").PatchAll(typeof(Patches));
			try
			{
				ZapPrefabBuilder.BuildAndRegister();
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Failed to build the zap gun: " + ex));
			}
		}
	}
	public class ZapController : MonoBehaviour
	{
		public const int BeamPoints = 18;

		public Transform muzzle;

		public LineRenderer beam;

		public GameObject impact;

		public AudioSource buzz;

		public AudioSource sfx;

		public MeshRenderer bodyRenderer;

		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 static readonly FieldRef<PlayerAvatar, bool> PlayerIsLocal = AccessTools.FieldRefAccess<PlayerAvatar, bool>("isLocal");

		private static readonly FieldRef<PlayerAvatar, bool> PlayerIsDisabled = AccessTools.FieldRefAccess<PlayerAvatar, bool>("isDisabled");

		private static readonly FieldRef<PlayerAvatar, PlayerTumble> PlayerTumbleRef = AccessTools.FieldRefAccess<PlayerAvatar, PlayerTumble>("tumble");

		private static readonly FieldRef<Enemy, EnemyStateStunned> EnemyStunned = AccessTools.FieldRefAccess<Enemy, EnemyStateStunned>("StateStunned");

		private static readonly FieldRef<Enemy, bool> EnemyHasStunned = AccessTools.FieldRefAccess<Enemy, bool>("HasStateStunned");

		private static readonly FieldRef<Enemy, EnemyHealth> EnemyHealthRef = AccessTools.FieldRefAccess<Enemy, EnemyHealth>("Health");

		private static readonly FieldRef<Enemy, bool> EnemyHasHealth = AccessTools.FieldRefAccess<Enemy, bool>("HasHealth");

		private float damageCarry;

		private static readonly FieldRef<EnemyParent, Enemy> ParentEnemy = AccessTools.FieldRefAccess<EnemyParent, Enemy>("Enemy");

		private static AudioClip scanClip;

		private static AudioClip hissClip;

		private static AudioClip snapClip;

		private static AudioClip dudClip;

		private PhotonView photonView;

		private PhysGrabObject physGrabObject;

		private ItemToggle itemToggle;

		private ItemBattery battery;

		private ItemEquippable equippable;

		private MaterialPropertyBlock mpb;

		private bool zapping;

		private Enemy targetEnemy;

		private PlayerAvatar targetPlayer;

		private int ownerActor;

		private float overheat;

		private bool scanning;

		private float scanTime;

		private float cooldown;

		private float losLostTime;

		private float zapTime;

		private float seedX;

		private float seedY;

		private float jitterTimer;

		private float sparkTimer;

		private readonly Vector3[] jitter = (Vector3[])(object)new Vector3[18];

		private float hostTick;

		private bool LocallyHeld
		{
			get
			{
				if (Object.op_Implicit((Object)(object)physGrabObject) && HeldByLocalPlayer.Invoke(physGrabObject))
				{
					if (Object.op_Implicit((Object)(object)equippable))
					{
						return !IsEquipped.Invoke(equippable);
					}
					return true;
				}
				return false;
			}
		}

		private bool HasBattery
		{
			get
			{
				if (Object.op_Implicit((Object)(object)battery))
				{
					return battery.batteryLife > 0.01f;
				}
				return true;
			}
		}

		private bool IAmOwner
		{
			get
			{
				if (SemiFunc.IsMultiplayer())
				{
					if (PhotonNetwork.LocalPlayer != null)
					{
						return PhotonNetwork.LocalPlayer.ActorNumber == ownerActor;
					}
					return false;
				}
				return true;
			}
		}

		private float TargetWeight
		{
			get
			{
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				if (!Object.op_Implicit((Object)(object)targetPlayer))
				{
					if (!Object.op_Implicit((Object)(object)targetEnemy))
					{
						return 1f;
					}
					return 1f + 0.25f * (float)targetEnemy.Type;
				}
				return 0.7f;
			}
		}

		private void Awake()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			photonView = ((Component)this).GetComponent<PhotonView>();
			physGrabObject = ((Component)this).GetComponent<PhysGrabObject>();
			itemToggle = ((Component)this).GetComponent<ItemToggle>();
			battery = ((Component)this).GetComponent<ItemBattery>();
			equippable = ((Component)this).GetComponent<ItemEquippable>();
			mpb = new MaterialPropertyBlock();
			seedX = Random.value * 100f;
			seedY = Random.value * 100f + 50f;
			if (!Object.op_Implicit((Object)(object)scanClip))
			{
				scanClip = ZapConvert.ScanSound(Plugin.ScanSeconds.Value);
				hissClip = ZapConvert.HissSound();
				snapClip = ZapConvert.SnapSound();
				dudClip = ZapConvert.DudSound();
			}
		}

		private void Start()
		{
			if (Object.op_Implicit((Object)(object)itemToggle))
			{
				ToggleDisabled.Invoke(itemToggle) = true;
			}
			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");
				AudioMixerGroup outputAudioMixerGroup = ((array.Length != 0) ? array[0] : AudioManager.instance.SoundMasterGroup);
				if (Object.op_Implicit((Object)(object)buzz))
				{
					buzz.outputAudioMixerGroup = outputAudioMixerGroup;
				}
				if (Object.op_Implicit((Object)(object)sfx))
				{
					sfx.outputAudioMixerGroup = outputAudioMixerGroup;
				}
			}
		}

		private void OnDisable()
		{
			scanning = false;
			SetVisuals(on: false);
		}

		private void Update()
		{
			if (overheat > 0f)
			{
				overheat -= Time.deltaTime;
			}
			if (cooldown > 0f)
			{
				cooldown -= Time.deltaTime;
			}
			HolderLogic();
			HostLogic();
			DrawBeam();
			DrawOverheat();
		}

		private void HolderLogic()
		{
			bool flag = LocallyHeld && Object.op_Implicit((Object)(object)PlayerController.instance) && InputDisableTimer.Invoke(PlayerController.instance) <= 0f && SemiFunc.InputHold((InputKey)2);
			if (zapping)
			{
				if (IAmOwner)
				{
					if (!flag)
					{
						SendStop(overheated: false);
						cooldown = 0.4f;
					}
					else if (!HasBattery)
					{
						SendStop(overheated: false);
					}
					else if (!TargetStillValid())
					{
						SendStop(overheated: true);
					}
					else
					{
						Wobble();
						Shake(holder: true);
					}
				}
				return;
			}
			if (!flag || overheat > 0f || cooldown > 0f)
			{
				if (scanning)
				{
					StopScan();
				}
				if (flag && overheat > 0f && SemiFunc.InputDown((InputKey)2))
				{
					Fizz();
				}
				return;
			}
			if (!HasBattery)
			{
				if (SemiFunc.InputDown((InputKey)2))
				{
					Fizz();
				}
				return;
			}
			if (!scanning)
			{
				scanning = true;
				scanTime = 0f;
				if (Object.op_Implicit((Object)(object)sfx) && Object.op_Implicit((Object)(object)scanClip))
				{
					sfx.pitch = 1f;
					sfx.PlayOneShot(scanClip, 0.7f);
				}
			}
			scanTime += Time.deltaTime;
			if (Object.op_Implicit((Object)(object)GameDirector.instance) && Object.op_Implicit((Object)(object)GameDirector.instance.CameraShake))
			{
				GameDirector.instance.CameraShake.Shake(0.4f, 0.1f);
			}
			if (!(scanTime < Plugin.ScanSeconds.Value))
			{
				StopScan();
				if (FindTarget(out var bestEnemy, out var bestPlayer))
				{
					SendStart(bestEnemy, bestPlayer);
					return;
				}
				Fizz();
				cooldown = 0.6f;
			}
		}

		private void StopScan()
		{
			scanning = false;
			if (Object.op_Implicit((Object)(object)sfx) && sfx.isPlaying)
			{
				sfx.Stop();
			}
		}

		private bool FindTarget(out Enemy bestEnemy, out PlayerAvatar bestPlayer)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			bestEnemy = null;
			bestPlayer = null;
			Camera main = Camera.main;
			if (!Object.op_Implicit((Object)(object)main))
			{
				return false;
			}
			Vector3 position = ((Component)main).transform.position;
			Vector3 forward = ((Component)main).transform.forward;
			float bestAngle = Plugin.LockAngle.Value;
			if (Object.op_Implicit((Object)(object)EnemyDirector.instance) && EnemyDirector.instance.enemiesSpawned != null)
			{
				foreach (EnemyParent item in EnemyDirector.instance.enemiesSpawned)
				{
					if (Object.op_Implicit((Object)(object)item))
					{
						Enemy val = ParentEnemy.Invoke(item);
						if (Object.op_Implicit((Object)(object)val) && ((Behaviour)val).isActiveAndEnabled && Object.op_Implicit((Object)(object)val.CenterTransform) && Consider(position, forward, val.CenterTransform.position, ((Component)item).transform, ref bestAngle))
						{
							bestEnemy = val;
							bestPlayer = null;
						}
					}
				}
			}
			if (Plugin.ZapPlayers.Value && Object.op_Implicit((Object)(object)GameDirector.instance))
			{
				foreach (PlayerAvatar player in GameDirector.instance.PlayerList)
				{
					if (Object.op_Implicit((Object)(object)player) && !PlayerIsLocal.Invoke(player) && !PlayerIsDisabled.Invoke(player) && Consider(position, forward, PlayerPoint(player), ((Component)player).transform, ref bestAngle))
					{
						bestPlayer = player;
						bestEnemy = null;
					}
				}
			}
			if (!Object.op_Implicit((Object)(object)bestEnemy))
			{
				return Object.op_Implicit((Object)(object)bestPlayer);
			}
			return true;
		}

		private bool Consider(Vector3 eye, Vector3 fwd, Vector3 point, Transform root, ref float bestAngle)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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)
			Vector3 val = point - eye;
			float magnitude = ((Vector3)(ref val)).magnitude;
			if (magnitude > Plugin.Range.Value || magnitude < 0.2f)
			{
				return false;
			}
			float num = Vector3.Angle(fwd, val);
			if (num >= bestAngle || !InSight(eye, point, root))
			{
				return false;
			}
			bestAngle = num;
			return true;
		}

		private bool InSight(Vector3 eye, Vector3 point, Transform targetRoot)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = point - eye;
			float magnitude = ((Vector3)(ref val)).magnitude;
			RaycastHit[] array = Physics.RaycastAll(eye, val / magnitude, magnitude, -1, (QueryTriggerInteraction)1);
			for (int i = 0; i < array.Length; i++)
			{
				RaycastHit val2 = array[i];
				Transform transform = ((Component)((RaycastHit)(ref val2)).collider).transform;
				if (!transform.IsChildOf(((Component)this).transform) && (!Object.op_Implicit((Object)(object)targetRoot) || !transform.IsChildOf(targetRoot)) && !(((RaycastHit)(ref val2)).distance > magnitude - 0.35f))
				{
					PlayerAvatar componentInParent = ((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<PlayerAvatar>();
					if (componentInParent == null || !PlayerIsLocal.Invoke(componentInParent))
					{
						return false;
					}
				}
			}
			return true;
		}

		private bool TargetStillValid()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			if (!TargetAlive())
			{
				return false;
			}
			Camera main = Camera.main;
			if (!Object.op_Implicit((Object)(object)main))
			{
				return false;
			}
			Vector3 position = ((Component)main).transform.position;
			Vector3 val = TargetPoint();
			Vector3 val2 = val - position;
			if (((Vector3)(ref val2)).magnitude > Plugin.Range.Value + 3f)
			{
				return false;
			}
			if (Vector3.Angle(((Component)main).transform.forward, val2) > Plugin.BreakAngle.Value)
			{
				return false;
			}
			if (InSight(position, val, TargetRoot()))
			{
				losLostTime = 0f;
			}
			else if ((losLostTime += Time.deltaTime) > 0.4f)
			{
				return false;
			}
			return true;
		}

		private void Wobble()
		{
			if (Object.op_Implicit((Object)(object)CameraAim.Instance) && !(Plugin.Wobble.Value <= 0f))
			{
				zapTime += Time.deltaTime;
				float num = Mathf.Clamp01(zapTime / 0.5f);
				float num2 = Time.time * 0.85f;
				float num3 = (Mathf.PerlinNoise(num2, seedX) - 0.5f) * 2f * 75f;
				float num4 = (Mathf.PerlinNoise(seedY, num2) - 0.5f) * 2f * 45f;
				float num5 = Plugin.Wobble.Value * TargetWeight * num * Time.deltaTime;
				CameraAim.Instance.AdditiveAimX(num3 * num5);
				CameraAim.Instance.AdditiveAimY(num4 * num5);
			}
		}

		private void Shake(bool holder)
		{
			if (Object.op_Implicit((Object)(object)GameDirector.instance) && !(Plugin.Shake.Value <= 0f))
			{
				float value = Plugin.Shake.Value;
				if (holder && Object.op_Implicit((Object)(object)GameDirector.instance.CameraShake))
				{
					GameDirector.instance.CameraShake.Shake(1.2f * value * TargetWeight, 0.1f);
				}
			}
		}

		private void Fizz()
		{
			if (Object.op_Implicit((Object)(object)sfx) && Object.op_Implicit((Object)(object)dudClip))
			{
				sfx.PlayOneShot(dudClip, 0.5f);
			}
		}

		private void HostLogic()
		{
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			if (!SemiFunc.IsMasterClientOrSingleplayer() || !zapping)
			{
				return;
			}
			if (!TargetAlive() || (Object.op_Implicit((Object)(object)physGrabObject) && !physGrabObject.grabbed) || !HasBattery)
			{
				SendStop(overheated: false);
				return;
			}
			if (Object.op_Implicit((Object)(object)battery))
			{
				battery.batteryLife = Mathf.Max(0f, battery.batteryLife - 100f / Plugin.BatterySeconds.Value * Time.deltaTime);
			}
			hostTick -= Time.deltaTime;
			if (hostTick > 0f)
			{
				return;
			}
			hostTick = 0.25f;
			if (Object.op_Implicit((Object)(object)targetEnemy))
			{
				if (CanStun(targetEnemy) && EnemyHasStunned.Invoke(targetEnemy))
				{
					EnemyStunned.Invoke(targetEnemy).Set(1f);
				}
				damageCarry += Plugin.DamagePerSecond.Value * 0.25f;
				int num = Mathf.FloorToInt(damageCarry);
				if (num > 0 && EnemyHasHealth.Invoke(targetEnemy) && Object.op_Implicit((Object)(object)EnemyHealthRef.Invoke(targetEnemy)))
				{
					damageCarry -= num;
					Vector3 val;
					if (!Object.op_Implicit((Object)(object)muzzle))
					{
						val = Vector3.zero;
					}
					else
					{
						Vector3 val2 = ((Component)targetEnemy).transform.position - muzzle.position;
						val = ((Vector3)(ref val2)).normalized;
					}
					Vector3 val3 = val;
					EnemyHealthRef.Invoke(targetEnemy).Hurt(num, val3);
				}
			}
			else if (Object.op_Implicit((Object)(object)targetPlayer))
			{
				PlayerTumble val4 = PlayerTumbleRef.Invoke(targetPlayer);
				if (Object.op_Implicit((Object)(object)val4))
				{
					val4.TumbleRequest(true, false);
					val4.TumbleOverrideTime(1.2f);
				}
			}
		}

		private bool CanStun(Enemy e)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			if ((int)e.Type >= 4)
			{
				return false;
			}
			if ((int)e.Type >= 3 && !Plugin.StunHeavyEnemies.Value)
			{
				return false;
			}
			return true;
		}

		private void SendStart(Enemy enemy, PlayerAvatar player)
		{
			int num = ((SemiFunc.IsMultiplayer() && PhotonNetwork.LocalPlayer != null) ? PhotonNetwork.LocalPlayer.ActorNumber : 0);
			StartLocal(enemy, player, num);
			if (SemiFunc.IsMultiplayer() && Object.op_Implicit((Object)(object)photonView) && photonView.ViewID != 0)
			{
				PhotonView val = (Object.op_Implicit((Object)(object)enemy) ? ((Component)enemy).GetComponentInParent<PhotonView>() : ((Component)player).GetComponent<PhotonView>());
				if (Object.op_Implicit((Object)(object)val))
				{
					photonView.RPC("ZapGun_StartRPC", (RpcTarget)1, new object[3]
					{
						val.ViewID,
						(Object)(object)player != (Object)null,
						num
					});
				}
			}
		}

		private void SendStop(bool overheated)
		{
			if (zapping)
			{
				StopLocal(overheated);
				if (SemiFunc.IsMultiplayer() && Object.op_Implicit((Object)(object)photonView) && photonView.ViewID != 0)
				{
					photonView.RPC("ZapGun_StopRPC", (RpcTarget)1, new object[1] { overheated });
				}
			}
		}

		[PunRPC]
		private void ZapGun_StartRPC(int targetViewId, bool isPlayer, int actor)
		{
			PhotonView val = PhotonView.Find(targetViewId);
			if (Object.op_Implicit((Object)(object)val))
			{
				Enemy val2 = null;
				PlayerAvatar val3 = null;
				if (isPlayer)
				{
					val3 = ((Component)val).GetComponent<PlayerAvatar>() ?? ((Component)val).GetComponentInChildren<PlayerAvatar>();
				}
				else
				{
					val2 = ((Component)val).GetComponentInChildren<Enemy>(true) ?? ((Component)val).GetComponentInParent<Enemy>();
				}
				if (Object.op_Implicit((Object)(object)val2) || Object.op_Implicit((Object)(object)val3))
				{
					StartLocal(val2, val3, actor);
				}
			}
		}

		[PunRPC]
		private void ZapGun_StopRPC(bool overheated)
		{
			StopLocal(overheated);
		}

		private void StartLocal(Enemy enemy, PlayerAvatar player, int actor)
		{
			zapping = true;
			targetEnemy = enemy;
			targetPlayer = player;
			ownerActor = actor;
			zapTime = 0f;
			losLostTime = 0f;
			hostTick = 0f;
			sparkTimer = 0f;
			if (SemiFunc.IsMasterClientOrSingleplayer() && Object.op_Implicit((Object)(object)enemy))
			{
				enemy.Freeze(0.15f);
			}
		}

		private void StopLocal(bool overheated)
		{
			zapping = false;
			targetEnemy = null;
			targetPlayer = null;
			if (!overheated)
			{
				return;
			}
			overheat = Plugin.OverheatSeconds.Value;
			if (Object.op_Implicit((Object)(object)sfx))
			{
				if (Object.op_Implicit((Object)(object)snapClip))
				{
					sfx.PlayOneShot(snapClip, 0.9f);
				}
				if (Object.op_Implicit((Object)(object)hissClip))
				{
					sfx.PlayOneShot(hissClip, 0.6f);
				}
			}
		}

		private bool TargetAlive()
		{
			if (Object.op_Implicit((Object)(object)targetEnemy))
			{
				if (((Behaviour)targetEnemy).isActiveAndEnabled)
				{
					return Object.op_Implicit((Object)(object)targetEnemy.CenterTransform);
				}
				return false;
			}
			if (Object.op_Implicit((Object)(object)targetPlayer))
			{
				if (((Behaviour)targetPlayer).isActiveAndEnabled)
				{
					return !PlayerIsDisabled.Invoke(targetPlayer);
				}
				return false;
			}
			return false;
		}

		private Vector3 TargetPoint()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)targetEnemy))
			{
				return PlayerPoint(targetPlayer);
			}
			return targetEnemy.CenterTransform.position;
		}

		private Transform TargetRoot()
		{
			if (Object.op_Implicit((Object)(object)targetEnemy))
			{
				EnemyParent componentInParent = ((Component)targetEnemy).GetComponentInParent<EnemyParent>();
				return ((componentInParent != null) ? ((Component)componentInParent).transform : null) ?? ((Component)targetEnemy).transform;
			}
			if (!Object.op_Implicit((Object)(object)targetPlayer))
			{
				return null;
			}
			return ((Component)targetPlayer).transform;
		}

		private static Vector3 PlayerPoint(PlayerAvatar p)
		{
			//IL_004a: 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_0059: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)p.PlayerVisionTarget) && Object.op_Implicit((Object)(object)p.PlayerVisionTarget.VisionTransform))
			{
				return p.PlayerVisionTarget.VisionTransform.position - Vector3.up * 0.35f;
			}
			return ((Component)p).transform.position + Vector3.up * 1f;
		}

		private void DrawBeam()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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_0043: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: 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_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: 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_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: 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)
			if (!zapping || !TargetAlive() || !Object.op_Implicit((Object)(object)muzzle))
			{
				SetVisuals(on: false);
				return;
			}
			Vector3 position = muzzle.position;
			Vector3 val = TargetPoint();
			float num = Vector3.Distance(position, val);
			Vector3 val2 = position + muzzle.forward * num * 0.45f;
			jitterTimer -= Time.deltaTime;
			if (jitterTimer <= 0f)
			{
				jitterTimer = 0.035f;
				for (int i = 0; i < 18; i++)
				{
					jitter[i] = Random.insideUnitSphere;
				}
			}
			for (int j = 0; j < 18; j++)
			{
				float num2 = (float)j / 17f;
				Vector3 val3 = (1f - num2) * (1f - num2) * position + 2f * (1f - num2) * num2 * val2 + num2 * num2 * val;
				val3 += jitter[j] * 0.06f * Mathf.Sin(num2 * MathF.PI) * Mathf.Min(1f, num * 0.3f);
				beam.SetPosition(j, val3);
			}
			if (Object.op_Implicit((Object)(object)beam))
			{
				((Renderer)beam).enabled = true;
			}
			if (Object.op_Implicit((Object)(object)buzz) && !buzz.isPlaying)
			{
				buzz.time = Random.Range(0f, 0.9f);
				buzz.Play();
			}
			if (Object.op_Implicit((Object)(object)buzz))
			{
				buzz.pitch = 1f + Mathf.PerlinNoise(Time.time * 3f, 7f) * 0.15f;
			}
			if (Object.op_Implicit((Object)(object)GameDirector.instance) && Object.op_Implicit((Object)(object)GameDirector.instance.CameraShake) && Plugin.Shake.Value > 0f)
			{
				GameDirector.instance.CameraShake.ShakeDistance(0.6f * Plugin.Shake.Value, 2f, 8f, val, 0.1f);
			}
			if (!Object.op_Implicit((Object)(object)impact))
			{
				return;
			}
			if (!impact.activeSelf)
			{
				impact.SetActive(true);
			}
			impact.transform.position = val;
			sparkTimer -= Time.deltaTime;
			if (sparkTimer <= 0f)
			{
				sparkTimer = 0.35f;
				ParticleSystem[] componentsInChildren = impact.GetComponentsInChildren<ParticleSystem>(true);
				for (int k = 0; k < componentsInChildren.Length; k++)
				{
					componentsInChildren[k].Play(true);
				}
			}
		}

		private void DrawOverheat()
		{
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)bodyRenderer))
			{
				((Renderer)bodyRenderer).GetPropertyBlock(mpb);
				if (overheat > 0f)
				{
					float num = 0.6f + 0.4f * Mathf.Sin(Time.time * 10f);
					float num2 = Mathf.Clamp01(overheat / 1f);
					mpb.SetColor("_EmissionColor", Color.Lerp(Color.white * 1.6f, new Color(4f, 0.35f, 0.1f) * num, num2));
				}
				else
				{
					mpb.SetColor("_EmissionColor", Color.white * 1.6f);
				}
				((Renderer)bodyRenderer).SetPropertyBlock(mpb);
			}
		}

		private void SetVisuals(bool on)
		{
			if (Object.op_Implicit((Object)(object)beam) && ((Renderer)beam).enabled != on)
			{
				((Renderer)beam).enabled = on;
			}
			if (Object.op_Implicit((Object)(object)impact) && impact.activeSelf != on)
			{
				impact.SetActive(on);
			}
			if (Object.op_Implicit((Object)(object)buzz) && !on && buzz.isPlaying)
			{
				buzz.Stop();
			}
		}
	}
	internal static class ZapConvert
	{
		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_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: 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,
				vertices = array,
				normals = array2,
				uv = array3,
				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)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			Texture2D val = new Texture2D(size, size, (TextureFormat)4, true)
			{
				name = name
			};
			val.SetPixelData<byte>(rgba, 0, 0);
			((Texture)val).wrapMode = (TextureWrapMode)0;
			((Texture)val).filterMode = (FilterMode)1;
			val.Apply(true, true);
			((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 0x20);
			return val;
		}

		public static Texture2D Solid(Color32 c, string name, bool linear = false)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(4, 4, (TextureFormat)4, false, linear)
			{
				name = name
			};
			Color32[] array = (Color32[])(object)new Color32[16];
			for (int i = 0; i < 16; i++)
			{
				array[i] = c;
			}
			val.SetPixels32(array);
			val.Apply(false, true);
			((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 0x20);
			return val;
		}

		private static AudioClip Make(string name, float[] data)
		{
			//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)
			AudioClip obj = AudioClip.Create(name, data.Length, 1, 44100, false);
			obj.SetData(data, 0);
			((Object)obj).hideFlags = (HideFlags)(((Object)obj).hideFlags | 0x20);
			return obj;
		}

		public static AudioClip ScanSound(float seconds)
		{
			int num = Mathf.Max(2205, (int)(44100f * Mathf.Max(0.1f, seconds)));
			float[] array = new float[num];
			float num2 = 0f;
			for (int i = 0; i < num; i++)
			{
				float num3 = (float)i / (float)num;
				float num4 = Mathf.Lerp(220f, 900f, num3 * num3) * (1f + 0.04f * Mathf.Sin((float)i * 0.004f));
				num2 += MathF.PI * 2f * num4 / 44100f;
				float num5 = Mathf.Min(1f, num3 * 8f) * 0.4f;
				array[i] = num5 * (Mathf.Sin(num2) * 0.7f + Mathf.Sign(Mathf.Sin(num2 * 0.5f)) * 0.15f);
			}
			return Make("ZapGun Scan", array);
		}

		public static AudioClip SnapSound()
		{
			int num = 11025;
			float[] array = new float[num];
			Random random = new Random(3);
			for (int i = 0; i < num; i++)
			{
				float num2 = (float)i / (float)num;
				array[i] = (float)(random.NextDouble() * 2.0 - 1.0) * Mathf.Exp((0f - num2) * 18f) * 0.9f;
			}
			return Make("ZapGun Snap", array);
		}

		public static AudioClip HissSound()
		{
			int num = 88200;
			float[] array = new float[num];
			Random random = new Random(4);
			float num2 = 0f;
			for (int i = 0; i < num; i++)
			{
				float num3 = (float)i / (float)num;
				float num4 = (float)(random.NextDouble() * 2.0 - 1.0);
				float num5 = num4 - num2;
				num2 = num4;
				array[i] = num5 * 0.35f * (1f - num3) * Mathf.Min(1f, num3 * 20f);
			}
			return Make("ZapGun Hiss", array);
		}

		public static AudioClip DudSound()
		{
			int num = 5512;
			float[] array = new float[num];
			for (int i = 0; i < num; i++)
			{
				float num2 = (float)i / 44100f;
				array[i] = Mathf.Sign(Mathf.Sin(MathF.PI * 140f * num2)) * 0.3f * Mathf.Exp((0f - num2) * 30f);
			}
			return Make("ZapGun Dud", array);
		}

		public static AudioClip ZapSound()
		{
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			float[] array = new float[44100];
			Random random = new Random(9);
			float num = 0f;
			for (int i = 0; i < array.Length; i++)
			{
				float num2 = (float)i / 44100f;
				float num3 = 2f * (num2 * 120f - Mathf.Floor(num2 * 120f + 0.5f));
				float num4 = 0.35f * num3 + 0.15f * Mathf.Sin(MathF.PI * 480f * num2);
				if (random.NextDouble() < 0.0015)
				{
					num = 1f;
				}
				num *= 0.985f;
				float num5 = (float)(random.NextDouble() * 2.0 - 1.0) * (0.08f + 0.5f * num);
				array[i] = num4 + num5;
			}
			for (int j = 0; j < 2205; j++)
			{
				float num6 = (float)j / 2205f;
				array[array.Length - 2205 + j] = array[array.Length - 2205 + j] * (1f - num6) + array[j] * num6;
			}
			AudioClip obj = AudioClip.Create("ZapGun Buzz", array.Length, 1, 44100, false);
			obj.SetData(array, 0);
			((Object)obj).hideFlags = (HideFlags)(((Object)obj).hideFlags | 0x20);
			return obj;
		}
	}
	internal static class ZapPrefabBuilder
	{
		private const string BaseResourcePath = "Items/Item Gun Stun";

		public const string PrefabName = "Item Zap Gun";

		private static readonly Vector3 MeshOffset = new Vector3(0f, 0f, 0.06f);

		public static void BuildAndRegister()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Expected O, but got Unknown
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: 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_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_032d: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0370: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0445: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = Resources.Load<GameObject>("Items/Item Gun Stun");
			if ((Object)(object)obj == (Object)null)
			{
				throw new Exception("Base item \"Items/Item Gun Stun\" 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 stun gun not found.");
			}
			GameObject val2 = new GameObject("ZapGun Prefabs");
			val2.SetActive(false);
			((Object)val2).hideFlags = (HideFlags)61;
			Object.DontDestroyOnLoad((Object)(object)val2);
			GameObject val3 = Object.Instantiate<GameObject>(obj, val2.transform);
			((Object)val3).name = "Item Zap Gun";
			Transform transform = val3.transform;
			int layer = val3.layer;
			MeshRenderer? obj2 = ((IEnumerable<MeshRenderer>)val3.GetComponentsInChildren<MeshRenderer>(true)).FirstOrDefault((Func<MeshRenderer, bool>)((MeshRenderer r) => ((Object)r).name == "Gun"));
			object obj3 = ((obj2 != null) ? ((Renderer)obj2).sharedMaterial : null);
			if (obj3 == null)
			{
				MeshRenderer componentInChildren = val3.GetComponentInChildren<MeshRenderer>(true);
				obj3 = ((componentInChildren != null) ? ((Renderer)componentInChildren).sharedMaterial : null);
			}
			if ((Object)obj3 == (Object)null)
			{
				throw new Exception("Could not find the stun gun's material.");
			}
			Material val4 = new Material((Material)obj3)
			{
				name = "ZapGun Body"
			};
			val4.SetTexture("_BaseTexture", (Texture)(object)ZapConvert.ToTexture(ZapTexture.Build(), 256, "ZapGun Atlas"));
			val4.SetColor("_BaseColor", Color.white);
			val4.SetTexture("_EmissionTexture", (Texture)(object)ZapConvert.ToTexture(ZapTexture.BuildEmission(), 256, "ZapGun Glow"));
			val4.SetColor("_EmissionColor", Color.white * 1.6f);
			val4.SetTexture("_NormalTexture", (Texture)(object)ZapConvert.Solid(new Color32((byte)128, (byte)128, byte.MaxValue, byte.MaxValue), "ZapGun Flat Normal", linear: true));
			if (val4.HasProperty("_TilingX"))
			{
				val4.SetFloat("_TilingX", 1f);
				val4.SetFloat("_TilingY", 1f);
			}
			if (val4.HasProperty("_OffsetX"))
			{
				val4.SetFloat("_OffsetX", 0f);
				val4.SetFloat("_OffsetY", 0f);
			}
			Transform val5 = transform.Find("Mesh");
			if (Object.op_Implicit((Object)(object)val5))
			{
				Renderer[] componentsInChildren = ((Component)val5).GetComponentsInChildren<Renderer>(true);
				for (int num = 0; num < componentsInChildren.Length; num++)
				{
					componentsInChildren[num].enabled = false;
				}
			}
			GameObject obj4 = NewChild(transform, "Zap Mesh", layer, MeshOffset);
			obj4.AddComponent<MeshFilter>().sharedMesh = ZapConvert.ToMesh(ZapGeometry.Build(), "ZapGun Model");
			MeshRenderer val6 = obj4.AddComponent<MeshRenderer>();
			((Renderer)val6).sharedMaterial = val4;
			ItemLight componentInChildren2 = val3.GetComponentInChildren<ItemLight>(true);
			if (Object.op_Implicit((Object)(object)componentInChildren2))
			{
				componentInChildren2.meshRenderers = new List<MeshRenderer> { val6 };
			}
			Vector3 val7 = MeshOffset + ZapConvert.V(ZapGeometry.Muzzle);
			Transform val8 = transform.Find("Gun Muzzle");
			if (Object.op_Implicit((Object)(object)val8))
			{
				val8.localPosition = val7;
			}
			Transform transform2 = NewChild(transform, "Zap Muzzle", layer, val7).transform;
			LineRenderer val9 = val3.GetComponentsInChildren<LineRenderer>(true).FirstOrDefault();
			LineRenderer val10;
			if (Object.op_Implicit((Object)(object)val9))
			{
				GameObject obj5 = Object.Instantiate<GameObject>(((Component)val9).gameObject, transform);
				((Object)obj5).name = "Zap Beam";
				obj5.SetActive(true);
				val10 = obj5.GetComponent<LineRenderer>();
			}
			else
			{
				val10 = NewChild(transform, "Zap Beam", layer, Vector3.zero).AddComponent<LineRenderer>();
				((Renderer)val10).sharedMaterial = val4;
			}
			((Component)val10).transform.localPosition = Vector3.zero;
			((Component)val10).transform.localRotation = Quaternion.identity;
			((Component)val10).transform.localScale = Vector3.one;
			val10.useWorldSpace = true;
			val10.positionCount = 18;
			val10.startWidth = 0.035f;
			val10.endWidth = 0.02f;
			val10.startColor = new Color(0.6f, 0.95f, 1f);
			val10.endColor = new Color(0.4f, 0.85f, 1f);
			((Renderer)val10).enabled = false;
			Transform val11 = ((IEnumerable<Transform>)((Component)transform).GetComponentsInChildren<Transform>(true)).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name == "Extra Particles"));
			GameObject val12 = null;
			if (Object.op_Implicit((Object)(object)val11))
			{
				val12 = Object.Instantiate<GameObject>(((Component)val11).gameObject, transform);
				((Object)val12).name = "Zap Impact";
				val12.SetActive(false);
			}
			GameObject obj6 = NewChild(transform, "Zap Speaker", layer, val7);
			AudioSource val13 = obj6.AddComponent<AudioSource>();
			val13.playOnAwake = false;
			val13.loop = true;
			val13.clip = ZapConvert.ZapSound();
			val13.spatialBlend = 1f;
			val13.rolloffMode = (AudioRolloffMode)1;
			val13.minDistance = 1.5f;
			val13.maxDistance = 18f;
			val13.dopplerLevel = 0f;
			val13.volume = 0.55f;
			AudioSource val14 = obj6.AddComponent<AudioSource>();
			val14.playOnAwake = false;
			val14.spatialBlend = 1f;
			val14.rolloffMode = (AudioRolloffMode)1;
			val14.minDistance = 1.5f;
			val14.maxDistance = 18f;
			val14.dopplerLevel = 0f;
			ZapController zapController = val3.AddComponent<ZapController>();
			zapController.sfx = val14;
			zapController.bodyRenderer = val6;
			zapController.muzzle = transform2;
			zapController.beam = val10;
			zapController.impact = val12;
			zapController.buzz = val13;
			Item val15 = Object.Instantiate<Item>(val);
			((Object)val15).name = "Item Zap Gun";
			val15.itemName = "Zap Gun";
			val15.itemNameLocalized = null;
			val15.description = "Hold Interact to lock an arc onto whatever's in front of you. Keep it steady.";
			Value val16 = ScriptableObject.CreateInstance<Value>();
			((Object)val16).name = "Value - Zap Gun";
			val16.valueMin = val.value.valueMin * Plugin.PriceMultiplier.Value;
			val16.valueMax = val.value.valueMax * Plugin.PriceMultiplier.Value;
			val15.value = val16;
			Object.DontDestroyOnLoad((Object)(object)val15);
			Object.DontDestroyOnLoad((Object)(object)val16);
			val3.GetComponent<ItemAttributes>().item = val15;
			if (Items.RegisterItem(val3.GetComponent<ItemAttributes>()) == null)
			{
				throw new Exception("REPOLib refused to register the zap gun (see REPOLib errors above).");
			}
			Plugin.Log.LogInfo((object)"Registered the Zap Gun item.");
		}

		private 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;
		}
	}
}
namespace ZapGun.Model
{
	public static class ZapGeometry
	{
		public static readonly V3 Muzzle = new V3(0f, 0f, 0.5f);

		public static MeshData Build()
		{
			MeshData meshData = new MeshData(1);
			TvGeometry.RoundedBox(meshData, new V3(0f, 0f, 0.1f), new V3(0.045f, 0.055f, 0.16f), 0.018f, 3, (TvGeometry.Face f) => (f != TvGeometry.Face.Top) ? ZapTexture.Paint : ZapTexture.Vents);
			SidePanel(meshData, new V3(0.0465f, 0f, 0.1f), 1, 0.11f, 0.028f, ZapTexture.Label);
			SidePanel(meshData, new V3(-0.0465f, 0f, 0.1f), -1, 0.11f, 0.028f, ZapTexture.Label);
			TvGeometry.RoundedBox(meshData, new V3(0f, 0f, 0.245f), new V3(0.047f, 0.057f, 0.012f), 0.01f, 2, (TvGeometry.Face _) => ZapTexture.Hazard);
			TvGeometry.RoundedBox(meshData, new V3(0f, 0.07f, 0.03f), new V3(0.03f, 0.016f, 0.075f), 0.008f, 2, (TvGeometry.Face _) => ZapTexture.Dark);
			int i;
			for (i = 0; i < 3; i++)
			{
				TvGeometry.RoundedBox(meshData, new V3(0f, 0.087f, -0.01f + (float)i * 0.03f), new V3(0.012f, 0.002f, 0.009f), 0.0015f, 1, (TvGeometry.Face _) => (i != 0) ? ZapTexture.LedGreen : ZapTexture.LedRed);
			}
			MeshData meshData2 = new MeshData(1);
			TvGeometry.RoundedBox(meshData2, new V3(0f, -0.07f, 0f), new V3(0.024f, 0.07f, 0.033f), 0.012f, 3, (TvGeometry.Face _) => ZapTexture.Rubber);
			Append(meshData, RotateX(meshData2, 15f), new V3(0f, -0.035f, -0.02f));
			TvGeometry.RoundedBox(meshData, new V3(0f, -0.072f, 0.06f), new V3(0.006f, 0.022f, 0.006f), 0.003f, 1, (TvGeometry.Face _) => ZapTexture.Rubber);
			TvGeometry.RoundedBox(meshData, new V3(0f, -0.1f, 0.055f), new V3(0.012f, 0.004f, 0.045f), 0.003f, 1, (TvGeometry.Face _) => ZapTexture.Dark);
			TvGeometry.RoundedBox(meshData, new V3(0f, -0.08f, 0.098f), new V3(0.012f, 0.024f, 0.004f), 0.003f, 1, (TvGeometry.Face _) => ZapTexture.Dark);
			TvGeometry.Cylinder(meshData, new V3(0f, 0f, 0.26f), 0.022f, 0.16f, 18, ZapTexture.Steel, ZapTexture.Steel);
			for (int num = 0; num < 3; num++)
			{
				TvGeometry.Cylinder(meshData, new V3(0f, 0f, 0.275f + (float)num * 0.04f), 0.042f, 0.022f, 22, ZapTexture.Copper, ZapTexture.Copper);
			}
			TvGeometry.Cylinder(meshData, new V3(0f, 0f, 0.42f), 0.03f, 0.012f, 20, ZapTexture.Dark, ZapTexture.Glow);
			float[] array = new float[2] { 1f, -1f };
			foreach (float num3 in array)
			{
				V3 a = new V3(0.024f * num3, 0f, 0.425f);
				V3 v = new V3(0.012f * num3, 0f, Muzzle.z