Decompiled source of Valhalla Arsenal v1.0.0

ValhallaArsenal.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json.Linq;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("ValhallaArsenal")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ValhallaArsenal")]
[assembly: AssemblyTitle("ValhallaArsenal")]
[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 ValhallaArsenal
{
	internal static class GlbLoader
	{
		private sealed class Ctx
		{
			private readonly JObject _j;

			private readonly byte[] _bin;

			private readonly Dictionary<int, Texture2D> _textures = new Dictionary<int, Texture2D>();

			private readonly Dictionary<int, Material> _materials = new Dictionary<int, Material>();

			private readonly Dictionary<int, (Mesh mesh, int[] mats)> _meshes = new Dictionary<int, (Mesh, int[])>();

			internal Ctx(JObject j, byte[] bin)
			{
				_j = j;
				_bin = bin;
			}

			internal GameObject Build(string name)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Expected O, but got Unknown
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_001d: Expected O, but got Unknown
				//IL_0051: 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_0060: Expected O, but got Unknown
				//IL_008a: Unknown result type (might be due to invalid IL or missing references)
				GameObject val = new GameObject(name);
				JArray val2 = (JArray)_j["scenes"];
				JToken obj = _j["scene"];
				int num = ((obj != null) ? Extensions.Value<int>((IEnumerable<JToken>)obj) : 0);
				JArray val3 = ((val2 == null) ? ((JArray)null) : ((JArray)val2[num][(object)"nodes"]));
				if (val3 == null)
				{
					val3 = new JArray();
					for (int i = 0; i < ((JContainer)(JArray)_j["nodes"]).Count; i++)
					{
						val3.Add(JToken.op_Implicit(i));
					}
				}
				foreach (JToken item in val3)
				{
					BuildNode(Extensions.Value<int>((IEnumerable<JToken>)item), val.transform);
				}
				return val;
			}

			private void BuildNode(int index, Transform parent)
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Expected O, but got Unknown
				//IL_004d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0053: Expected O, but got Unknown
				//IL_0079: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_021c: Unknown result type (might be due to invalid IL or missing references)
				//IL_00af: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00be: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00da: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_011c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0123: Unknown result type (might be due to invalid IL or missing references)
				//IL_012a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0132: Unknown result type (might be due to invalid IL or missing references)
				//IL_0142: Unknown result type (might be due to invalid IL or missing references)
				//IL_014a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0152: Unknown result type (might be due to invalid IL or missing references)
				//IL_0159: Unknown result type (might be due to invalid IL or missing references)
				//IL_0160: Unknown result type (might be due to invalid IL or missing references)
				//IL_0170: Unknown result type (might be due to invalid IL or missing references)
				//IL_0269: Unknown result type (might be due to invalid IL or missing references)
				JObject val = (JObject)_j["nodes"][(object)index];
				JToken obj = val["name"];
				GameObject val2 = new GameObject(((obj != null) ? Extensions.Value<string>((IEnumerable<JToken>)obj) : null) ?? ("node" + index));
				val2.transform.SetParent(parent, false);
				JToken obj2 = val["matrix"];
				JArray val3 = (JArray)(object)((obj2 is JArray) ? obj2 : null);
				if (val3 != null)
				{
					Matrix4x4 val4 = default(Matrix4x4);
					for (int i = 0; i < 16; i++)
					{
						((Matrix4x4)(ref val4))[i % 4, i / 4] = Extensions.Value<float>((IEnumerable<JToken>)val3[i]);
					}
					Vector3 val5 = Vector4.op_Implicit(((Matrix4x4)(ref val4)).GetColumn(3));
					Quaternion val6 = Quaternion.LookRotation(Vector4.op_Implicit(((Matrix4x4)(ref val4)).GetColumn(2)), Vector4.op_Implicit(((Matrix4x4)(ref val4)).GetColumn(1)));
					Vector4 column = ((Matrix4x4)(ref val4)).GetColumn(0);
					float magnitude = ((Vector4)(ref column)).magnitude;
					column = ((Matrix4x4)(ref val4)).GetColumn(1);
					float magnitude2 = ((Vector4)(ref column)).magnitude;
					column = ((Matrix4x4)(ref val4)).GetColumn(2);
					Vector3 localScale = default(Vector3);
					((Vector3)(ref localScale))..ctor(magnitude, magnitude2, ((Vector4)(ref column)).magnitude);
					val2.transform.localPosition = new Vector3(val5.x, val5.y, 0f - val5.z);
					val2.transform.localRotation = new Quaternion(0f - val6.x, 0f - val6.y, val6.z, val6.w);
					val2.transform.localScale = localScale;
				}
				else
				{
					JToken obj3 = val["translation"];
					JArray val7 = (JArray)(object)((obj3 is JArray) ? obj3 : null);
					if (val7 != null)
					{
						val2.transform.localPosition = new Vector3(Extensions.Value<float>((IEnumerable<JToken>)val7[0]), Extensions.Value<float>((IEnumerable<JToken>)val7[1]), 0f - Extensions.Value<float>((IEnumerable<JToken>)val7[2]));
					}
					JToken obj4 = val["rotation"];
					JArray val8 = (JArray)(object)((obj4 is JArray) ? obj4 : null);
					if (val8 != null)
					{
						val2.transform.localRotation = new Quaternion(0f - Extensions.Value<float>((IEnumerable<JToken>)val8[0]), 0f - Extensions.Value<float>((IEnumerable<JToken>)val8[1]), Extensions.Value<float>((IEnumerable<JToken>)val8[2]), Extensions.Value<float>((IEnumerable<JToken>)val8[3]));
					}
					JToken obj5 = val["scale"];
					JArray val9 = (JArray)(object)((obj5 is JArray) ? obj5 : null);
					if (val9 != null)
					{
						val2.transform.localScale = new Vector3(Extensions.Value<float>((IEnumerable<JToken>)val9[0]), Extensions.Value<float>((IEnumerable<JToken>)val9[1]), Extensions.Value<float>((IEnumerable<JToken>)val9[2]));
					}
				}
				if (val["mesh"] != null)
				{
					var (sharedMesh, array) = GetMesh(Extensions.Value<int>((IEnumerable<JToken>)val["mesh"]));
					val2.AddComponent<MeshFilter>().sharedMesh = sharedMesh;
					MeshRenderer val10 = val2.AddComponent<MeshRenderer>();
					Material[] array2 = (Material[])(object)new Material[array.Length];
					for (int j = 0; j < array.Length; j++)
					{
						array2[j] = GetMaterial(array[j]);
					}
					((Renderer)val10).sharedMaterials = array2;
				}
				JToken obj6 = val["children"];
				JArray val11 = (JArray)(object)((obj6 is JArray) ? obj6 : null);
				if (val11 == null)
				{
					return;
				}
				foreach (JToken item in val11)
				{
					BuildNode(Extensions.Value<int>((IEnumerable<JToken>)item), val2.transform);
				}
			}

			private (Mesh, int[]) GetMesh(int index)
			{
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Expected O, but got Unknown
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0077: Unknown result type (might be due to invalid IL or missing references)
				//IL_007e: Expected O, but got Unknown
				//IL_0307: Unknown result type (might be due to invalid IL or missing references)
				//IL_030c: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00af: Expected O, but got Unknown
				//IL_0340: Expected O, but got Unknown
				//IL_0106: Unknown result type (might be due to invalid IL or missing references)
				//IL_0194: Unknown result type (might be due to invalid IL or missing references)
				//IL_0176: Unknown result type (might be due to invalid IL or missing references)
				//IL_0211: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
				if (_meshes.TryGetValue(index, out (Mesh, int[]) value))
				{
					return value;
				}
				JObject val = (JObject)_j["meshes"][(object)index];
				List<Vector3> list = new List<Vector3>();
				List<Vector3> list2 = new List<Vector3>();
				List<Vector2> list3 = new List<Vector2>();
				List<int[]> list4 = new List<int[]>();
				List<int> list5 = new List<int>();
				foreach (JObject item in (JArray)val["primitives"])
				{
					JObject val2 = item;
					JToken obj = val2["mode"];
					if (((obj != null) ? Extensions.Value<int>((IEnumerable<JToken>)obj) : 4) != 4)
					{
						continue;
					}
					JObject val3 = (JObject)val2["attributes"];
					if (val3["POSITION"] == null)
					{
						continue;
					}
					int count = list.Count;
					int comps;
					float[] array = ReadFloats(Extensions.Value<int>((IEnumerable<JToken>)val3["POSITION"]), out comps);
					for (int i = 0; i < array.Length / comps; i++)
					{
						list.Add(new Vector3(array[i * comps], array[i * comps + 1], 0f - array[i * comps + 2]));
					}
					int num = array.Length / comps;
					if (val3["NORMAL"] != null)
					{
						int comps2;
						float[] array2 = ReadFloats(Extensions.Value<int>((IEnumerable<JToken>)val3["NORMAL"]), out comps2);
						for (int j = 0; j < num; j++)
						{
							list2.Add(new Vector3(array2[j * comps2], array2[j * comps2 + 1], 0f - array2[j * comps2 + 2]));
						}
					}
					else
					{
						for (int k = 0; k < num; k++)
						{
							list2.Add(Vector3.up);
						}
					}
					if (val3["TEXCOORD_0"] != null)
					{
						int comps3;
						float[] array3 = ReadFloats(Extensions.Value<int>((IEnumerable<JToken>)val3["TEXCOORD_0"]), out comps3);
						for (int l = 0; l < num; l++)
						{
							list3.Add(new Vector2(array3[l * comps3], 1f - array3[l * comps3 + 1]));
						}
					}
					else
					{
						for (int m = 0; m < num; m++)
						{
							list3.Add(Vector2.zero);
						}
					}
					int[] array4;
					if (val2["indices"] != null)
					{
						array4 = ReadInts(Extensions.Value<int>((IEnumerable<JToken>)val2["indices"]));
					}
					else
					{
						array4 = new int[num];
						for (int n = 0; n < num; n++)
						{
							array4[n] = n;
						}
					}
					int[] array5 = new int[array4.Length - array4.Length % 3];
					for (int num2 = 0; num2 < array5.Length; num2 += 3)
					{
						array5[num2] = array4[num2] + count;
						array5[num2 + 1] = array4[num2 + 2] + count;
						array5[num2 + 2] = array4[num2 + 1] + count;
					}
					list4.Add(array5);
					JToken obj2 = val2["material"];
					list5.Add((obj2 != null) ? Extensions.Value<int>((IEnumerable<JToken>)obj2) : (-1));
				}
				Mesh val4 = new Mesh();
				JToken obj3 = val["name"];
				((Object)val4).name = ((obj3 != null) ? Extensions.Value<string>((IEnumerable<JToken>)obj3) : null) ?? ("mesh" + index);
				Mesh val5 = val4;
				if (list.Count > 65000)
				{
					val5.indexFormat = (IndexFormat)1;
				}
				val5.SetVertices(list);
				val5.SetNormals(list2);
				val5.SetUVs(0, list3);
				val5.subMeshCount = list4.Count;
				for (int num3 = 0; num3 < list4.Count; num3++)
				{
					val5.SetTriangles(list4[num3], num3);
				}
				val5.RecalculateBounds();
				(Mesh, int[]) tuple = (val5, list5.ToArray());
				_meshes[index] = tuple;
				return tuple;
			}

			private Material GetMaterial(int index)
			{
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_017f: Unknown result type (might be due to invalid IL or missing references)
				//IL_004c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0051: Unknown result type (might be due to invalid IL or missing references)
				//IL_016d: Unknown result type (might be due to invalid IL or missing references)
				if (_materials.TryGetValue(index, out var value))
				{
					return value;
				}
				Color white = Color.white;
				Texture2D tex = null;
				float num = 0f;
				float num2 = 0.7f;
				bool blend = false;
				if (index >= 0)
				{
					JObject val = (JObject)_j["materials"][(object)index];
					JToken obj = val["pbrMetallicRoughness"];
					JObject val2 = (JObject)(object)((obj is JObject) ? obj : null);
					if (val2 != null)
					{
						JToken obj2 = val2["baseColorFactor"];
						JArray val3 = (JArray)(object)((obj2 is JArray) ? obj2 : null);
						if (val3 != null)
						{
							((Color)(ref white))..ctor(Extensions.Value<float>((IEnumerable<JToken>)val3[0]), Extensions.Value<float>((IEnumerable<JToken>)val3[1]), Extensions.Value<float>((IEnumerable<JToken>)val3[2]), Extensions.Value<float>((IEnumerable<JToken>)val3[3]));
						}
						if (val2["baseColorTexture"] != null)
						{
							tex = GetTexture(Extensions.Value<int>((IEnumerable<JToken>)val2["baseColorTexture"][(object)"index"]));
						}
						JToken obj3 = val2["metallicFactor"];
						num = ((obj3 != null) ? Extensions.Value<float>((IEnumerable<JToken>)obj3) : 1f);
						JToken obj4 = val2["roughnessFactor"];
						num2 = ((obj4 != null) ? Extensions.Value<float>((IEnumerable<JToken>)obj4) : 1f);
						if (val2["metallicRoughnessTexture"] != null)
						{
							num *= 0.35f;
							num2 = Mathf.Min(num2, 0.6f);
						}
					}
					JToken obj5 = val["alphaMode"];
					blend = ((obj5 != null) ? Extensions.Value<string>((IEnumerable<JToken>)obj5) : null) == "BLEND" && white.a < 0.99f;
				}
				Material val4 = GunAssets.MakeMaterial(white, tex, num, 1f - num2, blend);
				_materials[index] = val4;
				return val4;
			}

			private Texture2D GetTexture(int index)
			{
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Expected O, but got Unknown
				//IL_006f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0075: Expected O, but got Unknown
				//IL_009e: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a4: Expected O, but got Unknown
				if (_textures.TryGetValue(index, out var value))
				{
					return value;
				}
				JObject val = (JObject)_j["textures"][(object)index];
				Texture2D val2 = null;
				if (val["source"] != null)
				{
					JObject val3 = (JObject)_j["images"][(object)Extensions.Value<int>((IEnumerable<JToken>)val["source"])];
					if (val3["bufferView"] != null)
					{
						byte[] data = ViewBytes(Extensions.Value<int>((IEnumerable<JToken>)val3["bufferView"]));
						val2 = new Texture2D(2, 2, (TextureFormat)4, true);
						if (!GunAssets.LoadImage(val2, data))
						{
							Object.Destroy((Object)(object)val2);
							val2 = null;
						}
						else
						{
							((Texture)val2).wrapMode = (TextureWrapMode)0;
							((Texture)val2).anisoLevel = 4;
							val2.Apply(true, true);
						}
					}
				}
				_textures[index] = val2;
				return val2;
			}

			private byte[] ViewBytes(int view)
			{
				//IL_001b: 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)
				JObject val = (JObject)_j["bufferViews"][(object)view];
				JToken obj = val["byteOffset"];
				int srcOffset = ((obj != null) ? Extensions.Value<int>((IEnumerable<JToken>)obj) : 0);
				int num = Extensions.Value<int>((IEnumerable<JToken>)val["byteLength"]);
				byte[] array = new byte[num];
				Buffer.BlockCopy(_bin, srcOffset, array, 0, num);
				return array;
			}

			private static int Components(string type)
			{
				return type switch
				{
					"SCALAR" => 1, 
					"VEC2" => 2, 
					"VEC3" => 3, 
					"VEC4" => 4, 
					"MAT4" => 16, 
					_ => 1, 
				};
			}

			private static int ComponentSize(int ct)
			{
				switch (ct)
				{
				default:
					return 1;
				case 5122:
				case 5123:
					return 2;
				case 5125:
				case 5126:
					return 4;
				}
			}

			private float[] ReadFloats(int accessor, out int comps)
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Expected O, but got Unknown
				//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
				JObject val = (JObject)_j["accessors"][(object)accessor];
				comps = Components(Extensions.Value<string>((IEnumerable<JToken>)val["type"]));
				int num = Extensions.Value<int>((IEnumerable<JToken>)val["count"]);
				int num2 = Extensions.Value<int>((IEnumerable<JToken>)val["componentType"]);
				JToken obj = val["normalized"];
				bool flag = obj != null && Extensions.Value<bool>((IEnumerable<JToken>)obj);
				float[] array = new float[num * comps];
				if (val["bufferView"] == null)
				{
					return array;
				}
				JObject val2 = (JObject)_j["bufferViews"][(object)Extensions.Value<int>((IEnumerable<JToken>)val["bufferView"])];
				JToken obj2 = val2["byteOffset"];
				int num3 = ((obj2 != null) ? Extensions.Value<int>((IEnumerable<JToken>)obj2) : 0);
				JToken obj3 = val["byteOffset"];
				int num4 = num3 + ((obj3 != null) ? Extensions.Value<int>((IEnumerable<JToken>)obj3) : 0);
				int num5 = ComponentSize(num2);
				JToken obj4 = val2["byteStride"];
				int num6 = ((obj4 != null) ? Extensions.Value<int>((IEnumerable<JToken>)obj4) : (num5 * comps));
				for (int i = 0; i < num; i++)
				{
					for (int j = 0; j < comps; j++)
					{
						int num7 = num4 + i * num6 + j * num5;
						float num8;
						switch (num2)
						{
						case 5126:
							num8 = BitConverter.ToSingle(_bin, num7);
							break;
						case 5123:
							num8 = (int)BitConverter.ToUInt16(_bin, num7);
							if (flag)
							{
								num8 /= 65535f;
							}
							break;
						case 5122:
							num8 = BitConverter.ToInt16(_bin, num7);
							if (flag)
							{
								num8 = Mathf.Max(num8 / 32767f, -1f);
							}
							break;
						case 5121:
							num8 = (int)_bin[num7];
							if (flag)
							{
								num8 /= 255f;
							}
							break;
						case 5120:
							num8 = (sbyte)_bin[num7];
							if (flag)
							{
								num8 = Mathf.Max(num8 / 127f, -1f);
							}
							break;
						default:
							num8 = BitConverter.ToUInt32(_bin, num7);
							break;
						}
						array[i * comps + j] = num8;
					}
				}
				return array;
			}

			private int[] ReadInts(int accessor)
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Expected O, but got Unknown
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0072: Unknown result type (might be due to invalid IL or missing references)
				JObject val = (JObject)_j["accessors"][(object)accessor];
				int num = Extensions.Value<int>((IEnumerable<JToken>)val["count"]);
				int num2 = Extensions.Value<int>((IEnumerable<JToken>)val["componentType"]);
				JObject val2 = (JObject)_j["bufferViews"][(object)Extensions.Value<int>((IEnumerable<JToken>)val["bufferView"])];
				JToken obj = val2["byteOffset"];
				int num3 = ((obj != null) ? Extensions.Value<int>((IEnumerable<JToken>)obj) : 0);
				JToken obj2 = val["byteOffset"];
				int num4 = num3 + ((obj2 != null) ? Extensions.Value<int>((IEnumerable<JToken>)obj2) : 0);
				int num5 = ComponentSize(num2);
				JToken obj3 = val2["byteStride"];
				int num6 = ((obj3 != null) ? Extensions.Value<int>((IEnumerable<JToken>)obj3) : num5);
				int[] array = new int[num];
				for (int i = 0; i < num; i++)
				{
					int num7 = num4 + i * num6;
					array[i] = num2 switch
					{
						5123 => BitConverter.ToUInt16(_bin, num7), 
						5125 => (int)BitConverter.ToUInt32(_bin, num7), 
						_ => _bin[num7], 
					};
				}
				return array;
			}
		}

		internal static GameObject Load(byte[] glb, string name)
		{
			if (glb == null || glb.Length < 20 || BitConverter.ToUInt32(glb, 0) != 1179937895)
			{
				throw new InvalidDataException("not a GLB file");
			}
			int i = 12;
			JObject val = null;
			byte[] array = null;
			int num;
			for (; i + 8 <= glb.Length; i += 8 + num)
			{
				num = BitConverter.ToInt32(glb, i);
				switch (BitConverter.ToUInt32(glb, i + 4))
				{
				case 1313821514u:
					val = JObject.Parse(Encoding.UTF8.GetString(glb, i + 8, num));
					break;
				case 5130562u:
					array = new byte[num];
					Buffer.BlockCopy(glb, i + 8, array, 0, num);
					break;
				}
			}
			if (val == null)
			{
				throw new InvalidDataException("GLB has no JSON chunk");
			}
			return new Ctx(val, array).Build(name);
		}
	}
	internal static class GunAssets
	{
		private static readonly Dictionary<string, GameObject> Templates = new Dictionary<string, GameObject>();

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

		private static readonly Dictionary<string, Sprite> Icons = new Dictionary<string, Sprite>();

		private static Material _particleAdd;

		private static Material _particleAlpha;

		private static Material _brass;

		private static Transform _holder;

		private static AudioClip _boom;

		private static AudioClip _click;

		private static AudioClip _whoosh;

		private static Texture2D _dot;

		private static MethodInfo _loadImage;

		private static AudioMixerGroup _sfxGroup;

		private static bool _sfxSearched;

		internal static Transform Holder
		{
			get
			{
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Expected O, but got Unknown
				if (Object.op_Implicit((Object)(object)_holder))
				{
					return _holder;
				}
				GameObject val = new GameObject("ValhallaArsenalTemplates");
				val.SetActive(false);
				Object.DontDestroyOnLoad((Object)val);
				_holder = val.transform;
				return _holder;
			}
		}

		internal static Material Brass
		{
			get
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				if (!Object.op_Implicit((Object)(object)_brass))
				{
					return _brass = MakeMaterial(new Color(0.85f, 0.65f, 0.3f), null, 0.9f, 0.6f, blend: false);
				}
				return _brass;
			}
		}

		internal static AudioClip Boom
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)_boom))
				{
					return _boom = SynthBoom();
				}
				return _boom;
			}
		}

		internal static AudioClip Click
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)_click))
				{
					return _click = SynthClick();
				}
				return _click;
			}
		}

		internal static AudioClip Whoosh
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)_whoosh))
				{
					return _whoosh = SynthWhoosh();
				}
				return _whoosh;
			}
		}

		internal static AudioMixerGroup SfxGroup
		{
			get
			{
				if (_sfxSearched || !Object.op_Implicit((Object)(object)ZNetScene.instance))
				{
					return _sfxGroup;
				}
				_sfxSearched = true;
				string[] array = new string[4] { "sfx_wood_destroyed", "sfx_rock_hit", "sfx_build_hammer_wood", "sfx_arrow_hit" };
				foreach (string text in array)
				{
					GameObject prefab = ZNetScene.instance.GetPrefab(text);
					AudioSource val = (Object.op_Implicit((Object)(object)prefab) ? prefab.GetComponentInChildren<AudioSource>(true) : null);
					if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.outputAudioMixerGroup))
					{
						_sfxGroup = val.outputAudioMixerGroup;
						break;
					}
				}
				return _sfxGroup;
			}
		}

		private static byte[] Resource(string name)
		{
			using Stream stream = typeof(GunAssets).Assembly.GetManifestResourceStream(name);
			if (stream == null)
			{
				return null;
			}
			MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			return memoryStream.ToArray();
		}

		private static GameObject Template(string model)
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			if (Templates.TryGetValue(model, out var value) && Object.op_Implicit((Object)(object)value))
			{
				return value;
			}
			try
			{
				value = GlbLoader.Load(Resource(model + ".glb"), model);
			}
			catch (Exception ex)
			{
				GunsPlugin.Error("Failed to load " + model + ".glb: " + ex);
				value = GameObject.CreatePrimitive((PrimitiveType)3);
				Object.DestroyImmediate((Object)(object)value.GetComponent<Collider>());
				value.transform.localScale = new Vector3(0.06f, 0.1f, 0.8f);
			}
			((Object)value).name = model;
			value.transform.SetParent(Holder, false);
			Templates[model] = value;
			return value;
		}

		internal static GameObject NewModel(string model, Transform parent)
		{
			GameObject obj = Object.Instantiate<GameObject>(Template(model), parent, false);
			((Object)obj).name = model;
			obj.SetActive(true);
			return obj;
		}

		internal static Transform FindDeep(Transform t, string name)
		{
			if (!Object.op_Implicit((Object)(object)t))
			{
				return null;
			}
			if (((Object)t).name == name)
			{
				return t;
			}
			for (int i = 0; i < t.childCount; i++)
			{
				Transform val = FindDeep(t.GetChild(i), name);
				if (Object.op_Implicit((Object)(object)val))
				{
					return val;
				}
			}
			return null;
		}

		internal static GameObject NewAmmoModel(AmmoDef a, Transform parent)
		{
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Expected O, but got Unknown
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			if (a.Rocket)
			{
				GameObject val = NewModel("rpg7", null);
				Transform val2 = FindDeep(val.transform, "Warhead");
				GameObject val3 = (Object.op_Implicit((Object)(object)val2) ? Object.Instantiate<GameObject>(((Component)val2).gameObject) : GameObject.CreatePrimitive((PrimitiveType)1));
				Object.Destroy((Object)(object)val);
				((Object)val3).name = "PG7V";
				val3.transform.SetParent(parent, false);
				val3.transform.localPosition = Vector3.zero;
				val3.transform.localRotation = Quaternion.identity;
				Collider[] componentsInChildren = val3.GetComponentsInChildren<Collider>();
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					Object.Destroy((Object)(object)componentsInChildren[i]);
				}
				return val3;
			}
			GameObject val4 = new GameObject("Rounds");
			val4.transform.SetParent(parent, false);
			for (int j = 0; j < 6; j++)
			{
				GameObject obj = GameObject.CreatePrimitive((PrimitiveType)2);
				Object.DestroyImmediate((Object)(object)obj.GetComponent<Collider>());
				obj.transform.SetParent(val4.transform, false);
				obj.transform.localScale = new Vector3(0.012f, 0.028f, 0.012f);
				obj.transform.localPosition = new Vector3((float)(j % 3 - 1) * 0.014f, 0.028f, ((float)(j / 3) - 0.5f) * 0.014f);
				obj.GetComponent<Renderer>().sharedMaterial = Brass;
			}
			return val4;
		}

		internal static Bounds LocalBounds(Transform space, GameObject model)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_003e: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_007c: 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_008b: 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)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			Bounds result = default(Bounds);
			bool flag = false;
			MeshFilter[] componentsInChildren = model.GetComponentsInChildren<MeshFilter>(true);
			foreach (MeshFilter val in componentsInChildren)
			{
				if (!Object.op_Implicit((Object)(object)val.sharedMesh))
				{
					continue;
				}
				Bounds bounds = val.sharedMesh.bounds;
				Matrix4x4 val2 = space.worldToLocalMatrix * ((Component)val).transform.localToWorldMatrix;
				for (int j = 0; j < 8; j++)
				{
					Vector3 val3 = ((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)(j & 1), (float)((j >> 1) & 1), (float)((j >> 2) & 1)) * 2f - Vector3.one);
					Vector3 val4 = ((Matrix4x4)(ref val2)).MultiplyPoint3x4(val3);
					if (!flag)
					{
						((Bounds)(ref result))..ctor(val4, Vector3.zero);
					}
					else
					{
						((Bounds)(ref result)).Encapsulate(val4);
					}
					flag = true;
				}
			}
			return result;
		}

		internal static Material MakeMaterial(Color color, Texture2D tex, float metallic, float gloss, bool blend)
		{
			//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_0042: Expected O, but got Unknown
			Shader val = Shader.Find("Standard");
			if (!Object.op_Implicit((Object)(object)val) || !val.isSupported)
			{
				val = Shader.Find("Legacy Shaders/Diffuse");
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				val = GameShader();
			}
			Material val2 = new Material(val)
			{
				color = color
			};
			if (Object.op_Implicit((Object)(object)tex))
			{
				val2.mainTexture = (Texture)(object)tex;
			}
			if (((Object)val).name == "Standard")
			{
				val2.SetFloat("_Metallic", Mathf.Clamp01(metallic));
				val2.SetFloat("_Glossiness", Mathf.Clamp(gloss, 0.05f, 0.85f));
				if (blend)
				{
					val2.SetFloat("_Mode", 3f);
					val2.SetInt("_SrcBlend", 1);
					val2.SetInt("_DstBlend", 10);
					val2.SetInt("_ZWrite", 0);
					val2.EnableKeyword("_ALPHAPREMULTIPLY_ON");
					val2.renderQueue = 3000;
				}
			}
			return val2;
		}

		private static Shader GameShader()
		{
			GameObject val = (Object.op_Implicit((Object)(object)ObjectDB.instance) ? ObjectDB.instance.GetItemPrefab("Club") : null);
			Renderer val2 = (Object.op_Implicit((Object)(object)val) ? val.GetComponentInChildren<Renderer>(true) : null);
			if (!Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)val2.sharedMaterial))
			{
				return Shader.Find("Sprites/Default");
			}
			return val2.sharedMaterial.shader;
		}

		internal static Material ParticleMaterial(bool additive)
		{
			//IL_00a7: 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_00b8: Expected O, but got Unknown
			ref Material reference = ref additive ? ref _particleAdd : ref _particleAlpha;
			if (Object.op_Implicit((Object)(object)reference))
			{
				return reference;
			}
			string[] obj = ((!additive) ? new string[4] { "Legacy Shaders/Particles/Alpha Blended", "Particles/Alpha Blended", "Mobile/Particles/Alpha Blended", "Sprites/Default" } : new string[4] { "Legacy Shaders/Particles/Additive", "Particles/Additive", "Mobile/Particles/Additive", "Sprites/Default" });
			Shader val = null;
			string[] array = obj;
			for (int i = 0; i < array.Length; i++)
			{
				val = Shader.Find(array[i]);
				if (Object.op_Implicit((Object)(object)val) && val.isSupported)
				{
					break;
				}
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				val = GameShader();
			}
			reference = new Material(val)
			{
				mainTexture = (Texture)(object)SoftDot()
			};
			return reference;
		}

		private static Texture2D SoftDot()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)_dot))
			{
				return _dot;
			}
			_dot = new Texture2D(64, 64, (TextureFormat)4, false)
			{
				wrapMode = (TextureWrapMode)1
			};
			Color32[] array = (Color32[])(object)new Color32[4096];
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					float num = ((float)j + 0.5f) / 64f * 2f - 1f;
					float num2 = ((float)i + 0.5f) / 64f * 2f - 1f;
					float num3 = Mathf.Clamp01(1f - Mathf.Sqrt(num * num + num2 * num2));
					array[i * 64 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)(num3 * num3 * 255f));
				}
			}
			_dot.SetPixels32(array);
			_dot.Apply();
			return _dot;
		}

		internal static AudioClip Clip(string name)
		{
			return Clip(name, 0f);
		}

		internal static AudioClip Clip(string name, float maxLen)
		{
			string text = ((maxLen > 0f) ? (name + "@" + maxLen) : name);
			if (Clips.TryGetValue(text, out var value))
			{
				return value;
			}
			try
			{
				value = LoadWav(Resource(name + ".wav"), text, maxLen);
			}
			catch (Exception ex)
			{
				GunsPlugin.Warn(name + ".wav: " + ex.Message);
			}
			Clips[text] = value;
			return value;
		}

		private static AudioClip LoadWav(byte[] wav, string name, float maxLen)
		{
			if (wav == null)
			{
				return null;
			}
			int num = 1;
			int num2 = 44100;
			int num3 = 16;
			int i = 12;
			int num4 = -1;
			int num5 = 0;
			int num6;
			for (; i + 8 <= wav.Length; i += 8 + num6 + (num6 & 1))
			{
				string text = Encoding.ASCII.GetString(wav, i, 4);
				num6 = BitConverter.ToInt32(wav, i + 4);
				if (text == "fmt ")
				{
					num = BitConverter.ToInt16(wav, i + 10);
					num2 = BitConverter.ToInt32(wav, i + 12);
					num3 = BitConverter.ToInt16(wav, i + 22);
				}
				else if (text == "data")
				{
					num4 = i + 8;
					num5 = Math.Min(num6, wav.Length - num4);
					break;
				}
			}
			if (num4 < 0 || num3 != 16)
			{
				return null;
			}
			int num7 = num5 / (2 * num);
			float[] array = new float[num7];
			for (int j = 0; j < num7; j++)
			{
				float num8 = 0f;
				for (int k = 0; k < num; k++)
				{
					num8 += (float)BitConverter.ToInt16(wav, num4 + (j * num + k) * 2) / 32768f;
				}
				array[j] = num8 / (float)num;
			}
			if (maxLen > 0f && (float)num7 > maxLen * (float)num2)
			{
				int num9 = (int)(maxLen * (float)num2);
				int num10 = Math.Min(num9 / 2, (int)(0.12f * (float)num2));
				float[] array2 = new float[num9];
				Array.Copy(array, array2, num9);
				for (int l = 0; l < num10; l++)
				{
					array2[num9 - 1 - l] *= (float)l / (float)num10;
				}
				array = array2;
			}
			return MakeClip(name, array, num2);
		}

		private static AudioClip MakeClip(string name, float[] samples, int rate)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			int pos = 0;
			return AudioClip.Create(name, samples.Length, 1, rate, false, (PCMReaderCallback)delegate(float[] buffer)
			{
				int num = Mathf.Min(buffer.Length, samples.Length - pos);
				if (num > 0)
				{
					Array.Copy(samples, pos, buffer, 0, num);
				}
				for (int i = Mathf.Max(num, 0); i < buffer.Length; i++)
				{
					buffer[i] = 0f;
				}
				pos += Mathf.Max(num, 0);
			});
		}

		internal static bool LoadImage(Texture2D tex, byte[] data)
		{
			if (_loadImage == null)
			{
				_loadImage = typeof(ImageConversion).GetMethod("LoadImage", new Type[3]
				{
					typeof(Texture2D),
					typeof(byte[]),
					typeof(bool)
				});
			}
			if (_loadImage != null)
			{
				return (bool)_loadImage.Invoke(null, new object[3] { tex, data, false });
			}
			return false;
		}

		private static void Normalize(float[] d, float peak)
		{
			float num = 0.0001f;
			foreach (float num2 in d)
			{
				num = Mathf.Max(num, Mathf.Abs(num2));
			}
			float num3 = peak / num;
			for (int j = 0; j < d.Length; j++)
			{
				d[j] *= num3;
			}
		}

		private static AudioClip SynthBoom()
		{
			int num = 132300;
			float[] array = new float[num];
			Random random = new Random(11);
			float num2 = 0f;
			float num3 = 0f;
			for (int i = 0; i < num; i++)
			{
				float num4 = (float)i / 44100f;
				float num5 = (float)random.NextDouble() * 2f - 1f;
				num2 += (num5 - num2) * 0.08f;
				num3 += (num2 - num3) * 0.04f;
				array[i] = num5 * Mathf.Exp((0f - num4) * 60f) * 0.9f + Mathf.Sin((float)Math.PI * 2f * (55f - 25f * num4) * num4) * Mathf.Exp((0f - num4) * 4f) * 0.9f + num3 * 6f * Mathf.Exp((0f - num4) * 1.3f);
			}
			Normalize(array, 0.95f);
			return MakeClip("guns_boom", array, 44100);
		}

		private static AudioClip SynthClick()
		{
			int num = 3675;
			float[] array = new float[num];
			Random random = new Random(4);
			for (int i = 0; i < num; i++)
			{
				float num2 = (float)i / 44100f;
				array[i] = ((float)random.NextDouble() * 2f - 1f) * Mathf.Exp((0f - num2) * 300f) + Mathf.Sin((float)Math.PI * 4800f * num2) * Mathf.Exp((0f - num2) * 120f) * 0.5f;
			}
			Normalize(array, 0.7f);
			return MakeClip("guns_click", array, 44100);
		}

		private static AudioClip SynthWhoosh()
		{
			int num = 44100;
			float[] array = new float[num];
			Random random = new Random(8);
			float num2 = 0f;
			for (int i = 0; i < num; i++)
			{
				float num3 = (float)random.NextDouble() * 2f - 1f;
				num2 += (num3 - num2) * 0.25f;
				array[i] = num2 * (0.8f + 0.2f * Mathf.Sin((float)i * 0.0021f));
			}
			Normalize(array, 0.6f);
			return MakeClip("guns_whoosh", array, 44100);
		}

		internal static AudioSource AddSource(GameObject go, AudioClip clip, bool loop, float minDist, float maxDist)
		{
			AudioSource val = go.AddComponent<AudioSource>();
			val.clip = clip;
			val.loop = loop;
			val.spatialBlend = 1f;
			val.rolloffMode = (AudioRolloffMode)1;
			val.minDistance = minDist;
			val.maxDistance = maxDist;
			val.dopplerLevel = 0.3f;
			val.playOnAwake = false;
			if (Object.op_Implicit((Object)(object)SfxGroup))
			{
				val.outputAudioMixerGroup = SfxGroup;
			}
			return val;
		}

		internal static AudioSource Play(AudioClip clip, Vector3 pos, Transform follow, float volume, float maxDist, float pitchJitter = 0.04f)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)clip))
			{
				return null;
			}
			GameObject val = new GameObject("GunSfx");
			val.transform.position = pos;
			if (Object.op_Implicit((Object)(object)follow))
			{
				val.transform.SetParent(follow, true);
			}
			AudioSource val2 = AddSource(val, clip, loop: false, 2f, maxDist);
			val2.volume = Mathf.Clamp01(volume * Cfg.Volume.Value);
			val2.pitch = 1f + Random.Range(0f - pitchJitter, pitchJitter);
			val2.Play();
			Object.Destroy((Object)(object)val, clip.length / Mathf.Max(val2.pitch, 0.5f) + 0.2f);
			return val2;
		}

		internal static Sprite Icon(string key, Func<GameObject> make, Vector3 euler, Color fallback)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (Icons.TryGetValue(key, out var value) && Object.op_Implicit((Object)(object)value))
			{
				return value;
			}
			value = RenderIcon(make(), euler) ?? FlatIcon(fallback);
			Icons[key] = value;
			return value;
		}

		private static Sprite RenderIcon(GameObject model, Vector3 euler)
		{
			//IL_0022: 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_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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Expected O, but got Unknown
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Expected O, but got Unknown
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Expected O, but got Unknown
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = null;
			GameObject val2 = null;
			RenderTexture val3 = null;
			try
			{
				Vector3 val4 = default(Vector3);
				((Vector3)(ref val4))..ctor(0f, -5000f, 0f);
				model.transform.position = val4;
				model.transform.rotation = Quaternion.Euler(euler);
				Bounds bounds = default(Bounds);
				((Bounds)(ref bounds))..ctor(val4, Vector3.zero);
				bool flag = false;
				Renderer[] componentsInChildren = model.GetComponentsInChildren<Renderer>();
				foreach (Renderer val5 in componentsInChildren)
				{
					if (!flag)
					{
						bounds = val5.bounds;
					}
					else
					{
						((Bounds)(ref bounds)).Encapsulate(val5.bounds);
					}
					flag = true;
				}
				Transform[] componentsInChildren2 = model.GetComponentsInChildren<Transform>(true);
				for (int i = 0; i < componentsInChildren2.Length; i++)
				{
					((Component)componentsInChildren2[i]).gameObject.layer = 31;
				}
				val = new GameObject("GunIconCam");
				Camera val6 = val.AddComponent<Camera>();
				((Behaviour)val6).enabled = false;
				val6.clearFlags = (CameraClearFlags)2;
				val6.backgroundColor = new Color(0f, 0f, 0f, 0f);
				val6.cullingMask = int.MinValue;
				val6.orthographic = true;
				val6.orthographicSize = Mathf.Max(((Bounds)(ref bounds)).extents.x, ((Bounds)(ref bounds)).extents.y) * 1.08f;
				Transform transform = ((Component)val6).transform;
				Vector3 center = ((Bounds)(ref bounds)).center;
				Vector3 forward = Vector3.forward;
				Vector3 extents = ((Bounds)(ref bounds)).extents;
				transform.position = center - forward * (((Vector3)(ref extents)).magnitude + 1f);
				val6.nearClipPlane = 0.01f;
				extents = ((Bounds)(ref bounds)).extents;
				val6.farClipPlane = ((Vector3)(ref extents)).magnitude * 2f + 2f;
				val2 = new GameObject("GunIconLight");
				Light obj = val2.AddComponent<Light>();
				obj.type = (LightType)1;
				obj.intensity = 1.4f;
				obj.cullingMask = int.MinValue;
				val2.transform.rotation = Quaternion.Euler(40f, 30f, 0f);
				val3 = (val6.targetTexture = RenderTexture.GetTemporary(128, 128, 24, (RenderTextureFormat)0));
				Color ambientLight = RenderSettings.ambientLight;
				RenderSettings.ambientLight = new Color(0.6f, 0.6f, 0.6f);
				val6.Render();
				RenderSettings.ambientLight = ambientLight;
				RenderTexture active = RenderTexture.active;
				RenderTexture.active = val3;
				Texture2D val7 = new Texture2D(128, 128, (TextureFormat)4, false);
				val7.ReadPixels(new Rect(0f, 0f, 128f, 128f), 0, 0);
				val7.Apply();
				RenderTexture.active = active;
				int num = 0;
				Color32[] pixels = val7.GetPixels32();
				for (int i = 0; i < pixels.Length; i++)
				{
					if (pixels[i].a > 10)
					{
						num++;
					}
				}
				return (num < 120) ? null : Sprite.Create(val7, new Rect(0f, 0f, 128f, 128f), new Vector2(0.5f, 0.5f));
			}
			catch (Exception ex)
			{
				GunsPlugin.Warn("Icon render failed: " + ex.Message);
				return null;
			}
			finally
			{
				if (Object.op_Implicit((Object)(object)val3))
				{
					RenderTexture.ReleaseTemporary(val3);
				}
				if (Object.op_Implicit((Object)(object)val))
				{
					Object.Destroy((Object)(object)val);
				}
				if (Object.op_Implicit((Object)(object)val2))
				{
					Object.Destroy((Object)(object)val2);
				}
				Object.Destroy((Object)(object)model);
			}
		}

		private static Sprite FlatIcon(Color c)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false);
			Color32[] array = (Color32[])(object)new Color32[4096];
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					array[i * 64 + j] = (Color32)(((Mathf.Abs(i - 32) < 5 && j > 6 && j < 58) || (j > 18 && j < 26 && i > 14 && i < 32)) ? Color32.op_Implicit(c) : new Color32((byte)0, (byte)0, (byte)0, (byte)0));
				}
			}
			val.SetPixels32(array);
			val.Apply();
			return Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f));
		}
	}
	internal class GunController : MonoBehaviour
	{
		internal const string MagKey = "guns_mag";

		internal static GunController Instance;

		internal static float AdsWeight;

		private static int _hitMask;

		private GunDef _gun;

		private ItemData _item;

		private float _nextShot;

		private float _lastShot = -10f;

		private float _reloadStart;

		private float _reloadLen;

		private float _hitMarker;

		private float _nextSync;

		private float _noAmmoMsg;

		private bool _reloading;

		private bool _ads;

		private readonly List<(float at, string clip)> _reloadSfx = new List<(float, string)>();

		private int _sfxIndex;

		private GUIStyle _big;

		private GUIStyle _small;

		internal static int HitMask
		{
			get
			{
				if (_hitMask == 0)
				{
					return _hitMask = LayerMask.GetMask(new string[12]
					{
						"Default", "static_solid", "Default_small", "piece", "piece_nonsolid", "terrain", "vehicle", "character", "character_net", "character_ghost",
						"character_noenv", "hitbox"
					});
				}
				return _hitMask;
			}
		}

		internal static bool HoldingGun(Player p)
		{
			if (Object.op_Implicit((Object)(object)p))
			{
				return GunDefs.For(((Humanoid)p).GetCurrentWeapon()) != null;
			}
			return false;
		}

		private void Awake()
		{
			Instance = this;
		}

		internal static int Mag(ItemData item)
		{
			if (item == null || !item.m_customData.TryGetValue("guns_mag", out var value) || !int.TryParse(value, out var result))
			{
				return 0;
			}
			return result;
		}

		private static void SetMag(ItemData item, int n)
		{
			if (item != null)
			{
				item.m_customData["guns_mag"] = n.ToString();
			}
		}

		private static bool UiBlocks(Player p)
		{
			if (!InventoryGui.IsVisible() && !Menu.IsVisible() && !Console.IsVisible() && !Minimap.IsOpen() && !TextInput.IsVisible() && !StoreGui.IsVisible() && !Hud.IsPieceSelectionVisible() && !Hud.InRadial() && (!Object.op_Implicit((Object)(object)Chat.instance) || !Chat.instance.HasFocus()) && !((Character)p).InPlaceMode() && !((Character)p).IsDead() && !p.IsSleeping())
			{
				return ((Character)p).InCutscene();
			}
			return true;
		}

		private void Update()
		{
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			ItemData val = (Object.op_Implicit((Object)(object)localPlayer) ? ((Humanoid)localPlayer).GetCurrentWeapon() : null);
			GunDef gunDef = GunDefs.For(val);
			if (gunDef != _gun || val != _item)
			{
				CancelReload();
				_gun = gunDef;
				_item = val;
				if (gunDef != null)
				{
					PlaySfx("equip", localPlayer, 0.8f);
				}
			}
			if (gunDef == null || !Object.op_Implicit((Object)(object)localPlayer))
			{
				AdsWeight = Mathf.MoveTowards(AdsWeight, 0f, Time.deltaTime * 6f);
				GunPose.LocalAim = false;
				GunPose.LocalReload = -1f;
				return;
			}
			bool flag = UiBlocks(localPlayer);
			_ads = !flag && !_reloading && !((Character)localPlayer).IsSwimming() && (ZInput.GetButton("Block") || ZInput.GetButton("JoyBlock"));
			AdsWeight = Mathf.MoveTowards(AdsWeight, _ads ? 1f : 0f, Time.deltaTime * 6f);
			bool num;
			if (!flag && !((Character)localPlayer).IsSwimming())
			{
				if (ZInput.GetKeyDown(Cfg.KeyReload.Value, true))
				{
					TryReload(localPlayer);
				}
				if (!gunDef.Auto)
				{
					if (!ZInput.GetButtonDown("Attack"))
					{
						num = ZInput.GetButtonDown("JoyAttack");
						goto IL_0163;
					}
				}
				else if (!ZInput.GetButton("Attack"))
				{
					num = ZInput.GetButton("JoyAttack");
					goto IL_0163;
				}
				goto IL_0168;
			}
			goto IL_01f7;
			IL_0168:
			if (!_reloading && Time.time >= _nextShot)
			{
				if (Mag(val) > 0)
				{
					Shoot(localPlayer, gunDef, val);
				}
				else
				{
					_nextShot = Time.time + 0.25f;
					GunAssets.Play(GunAssets.Click, ((Component)localPlayer).transform.position + Vector3.up * 1.3f, ((Component)localPlayer).transform, 0.8f, 15f);
					if (Cfg.AutoReload.Value)
					{
						TryReload(localPlayer);
					}
				}
			}
			goto IL_01f7;
			IL_0163:
			if (num)
			{
				goto IL_0168;
			}
			goto IL_01f7;
			IL_01f7:
			if (_reloading)
			{
				UpdateReload(localPlayer, gunDef, val);
			}
			bool flag2 = _ads || Time.time - _lastShot < 0.9f;
			if (flag2 && !flag)
			{
				localPlayer.FaceLookDirection();
			}
			Vector3 val2 = (Object.op_Implicit((Object)(object)GameCamera.instance) ? ((Component)GameCamera.instance).transform.forward : ((Component)localPlayer).transform.forward);
			GunPose.LocalAim = flag2;
			GunPose.LocalPitch = Mathf.Asin(Mathf.Clamp(val2.y, -1f, 1f)) * 57.29578f;
			GunPose.LocalReload = (_reloading ? Mathf.Clamp01((Time.time - _reloadStart) / _reloadLen) : (-1f));
			GunPose.LocalLoaded = Mag(val) > 0;
			SyncZdo(localPlayer);
		}

		private void SyncZdo(Player p)
		{
			if (Time.time < _nextSync)
			{
				return;
			}
			_nextSync = Time.time + 0.1f;
			ZNetView component = ((Component)p).GetComponent<ZNetView>();
			if (Object.op_Implicit((Object)(object)component) && component.IsValid())
			{
				ZDO zDO = component.GetZDO();
				if (zDO.GetBool("guns_aim", false) != GunPose.LocalAim)
				{
					zDO.Set("guns_aim", GunPose.LocalAim);
				}
				if (Mathf.Abs(zDO.GetFloat("guns_pitch", 0f) - GunPose.LocalPitch) > 1f)
				{
					zDO.Set("guns_pitch", GunPose.LocalPitch);
				}
				float localReload = GunPose.LocalReload;
				if (Mathf.Abs(zDO.GetFloat("guns_rel", -1f) - localReload) > 0.02f)
				{
					zDO.Set("guns_rel", localReload);
				}
				if (zDO.GetBool("guns_loaded", true) != GunPose.LocalLoaded)
				{
					zDO.Set("guns_loaded", GunPose.LocalLoaded);
				}
			}
		}

		private void Shoot(Player p, GunDef gun, ItemData item)
		{
			//IL_007d: 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_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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: 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_0152: 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_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: 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_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0335: Unknown result type (might be due to invalid IL or missing references)
			SetMag(item, Mag(item) - 1);
			_lastShot = Time.time;
			_nextShot = Time.time + 60f / Mathf.Max(gun.Rpm.Value, 1f);
			p.FaceLookDirection();
			GunPose gunPose = GunPose.Of(p);
			Vector3 val = (Object.op_Implicit((Object)(object)gunPose) ? gunPose.MuzzlePos : (((Character)p).m_eye.position + ((Component)p).transform.forward * 0.6f));
			Quaternion val2 = (Object.op_Implicit((Object)(object)gunPose) ? gunPose.GunRotation : ((Component)p).transform.rotation);
			Transform val3 = (Object.op_Implicit((Object)(object)GameCamera.instance) ? ((Component)GameCamera.instance).transform : ((Character)p).m_eye);
			float num = Mathf.Lerp(gun.SpreadHip, gun.SpreadAim, AdsWeight);
			Vector3 val4 = ((Character)p).GetVelocity();
			if (((Vector3)(ref val4)).magnitude > 1.5f)
			{
				num += 1.2f * (1f - AdsWeight * 0.6f);
			}
			if (((Character)p).IsCrouching())
			{
				num *= 0.7f;
			}
			Vector3 val5 = Spread(val3.forward, num);
			if (gun.IsLauncher)
			{
				RaycastHit result;
				Vector3 val6 = (Trace(p, val3.position, val5, gun.Range, out result) ? ((RaycastHit)(ref result)).point : (val3.position + val5 * gun.Range));
				Vector3 val7 = (Object.op_Implicit((Object)(object)gunPose) ? gunPose.WarheadPos : val);
				val4 = val6 - val7;
				Vector3 normalized = ((Vector3)(ref val4)).normalized;
				Rocket.Launch(val7, normalized, p, authority: true, 0L);
				GunNet.SendRocket(val7, normalized);
				GunFx.FireSound(gun, val7, null);
				GunFx.MuzzleFlash(val7, normalized, 1.8f);
				GunFx.Backblast(val7 - normalized * 1.1f, -normalized);
			}
			else
			{
				RaycastHit result2;
				bool flag = Trace(p, val3.position, val5, gun.Range, out result2);
				Vector3 end = (flag ? ((RaycastHit)(ref result2)).point : (val3.position + val5 * gun.Range));
				if (flag)
				{
					Damage(p, gun, result2, val5);
				}
				bool tracer = Random.value < Cfg.TracerChance.Value;
				GunFx.Shot(gun, val, val2, end, flag, flag ? ((RaycastHit)(ref result2)).normal : (-val5), tracer);
				GunFx.Casing(val - val2 * Vector3.forward * 0.45f, val2);
				GunNet.SendShot(gun, end, flag, flag ? ((RaycastHit)(ref result2)).normal : (-val5), tracer);
			}
			float num2 = gun.Recoil * (_ads ? 0.55f : 1f);
			p.SetMouseLook(new Vector2(Random.Range(-0.4f, 0.4f) * num2, num2 * Random.Range(0.8f, 1.2f)));
			if (Object.op_Implicit((Object)(object)gunPose))
			{
				gunPose.Kick(gun.IsLauncher ? 1f : 0.6f);
			}
			if (Object.op_Implicit((Object)(object)GameCamera.instance) && gun.IsLauncher)
			{
				GameCamera.instance.AddShake(((Component)p).transform.position, 10f, 1.2f, false);
			}
		}

		private static Vector3 Spread(Vector3 dir, float deg)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0022: 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_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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_0045: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			if (deg <= 0f)
			{
				return dir;
			}
			Vector2 val = Random.insideUnitCircle * Mathf.Tan(deg * ((float)Math.PI / 180f));
			Quaternion val2 = Quaternion.LookRotation(dir);
			Vector3 val3 = dir + val2 * new Vector3(val.x, val.y, 0f);
			return ((Vector3)(ref val3)).normalized;
		}

		private static bool Trace(Player p, Vector3 origin, Vector3 dir, float range, out RaycastHit result)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			result = default(RaycastHit);
			RaycastHit[] array = Physics.RaycastAll(origin, dir, range, HitMask, (QueryTriggerInteraction)1);
			Array.Sort(array, (RaycastHit a, RaycastHit b) => ((RaycastHit)(ref a)).distance.CompareTo(((RaycastHit)(ref b)).distance));
			Vector3 position = ((Character)p).m_eye.position;
			RaycastHit[] array2 = array;
			for (int num = 0; num < array2.Length; num++)
			{
				RaycastHit val = array2[num];
				if (!(Vector3.Dot(((RaycastHit)(ref val)).point - position, dir) < 0.3f) && !((Object)(object)((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<Character>() == (Object)(object)p))
				{
					result = val;
					return true;
				}
			}
			return false;
		}

		private void Damage(Player p, GunDef gun, RaycastHit h, Vector3 dir)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			IDestructible componentInParent = ((Component)((RaycastHit)(ref h)).collider).GetComponentInParent<IDestructible>();
			if (componentInParent != null)
			{
				float distance = ((RaycastHit)(ref h)).distance;
				float num = Mathf.Lerp(1f, 0.5f, Mathf.InverseLerp(gun.Range * 0.4f, gun.Range, distance));
				HitData val = new HitData();
				val.m_damage.m_pierce = gun.Damage.Value * num;
				val.m_point = ((RaycastHit)(ref h)).point;
				val.m_dir = dir;
				val.m_pushForce = 6f;
				val.m_ranged = true;
				val.m_blockable = true;
				val.m_dodgeable = true;
				val.m_toolTier = 2;
				val.m_skill = (SkillType)14;
				val.m_ignorePVP = Cfg.IgnorePvP.Value;
				val.SetAttacker((Character)(object)p);
				componentInParent.Damage(val);
				if (componentInParent is Character)
				{
					_hitMarker = Time.time;
					((Character)p).RaiseSkill((SkillType)14, 0.2f);
				}
			}
		}

		private int AmmoCount(Player p, GunDef gun)
		{
			AmmoDef ammoDef = GunDefs.AmmoFor(gun);
			if (ammoDef != null)
			{
				return ((Humanoid)p).GetInventory().CountItems(ammoDef.Display, -1, true);
			}
			return 0;
		}

		private void TryReload(Player p)
		{
			if (_gun == null || _reloading || Mag(_item) >= _gun.MagSize.Value)
			{
				return;
			}
			if (AmmoCount(p, _gun) <= 0)
			{
				if (Time.time > _noAmmoMsg)
				{
					_noAmmoMsg = Time.time + 2f;
					((Character)p).Message((MessageType)2, "No " + GunDefs.AmmoFor(_gun)?.Display, 0, (Sprite)null, false);
				}
				return;
			}
			_reloading = true;
			_reloadStart = Time.time;
			_reloadLen = Mathf.Max(0.3f, _gun.ReloadTime.Value);
			_reloadSfx.Clear();
			_sfxIndex = 0;
			if (_gun.IsLauncher)
			{
				_reloadSfx.Add((0.64f, "rpg_load"));
				_reloadSfx.Add((0.8f, "rpg_load_lock"));
				return;
			}
			_reloadSfx.Add((0.16f, "mag_out"));
			_reloadSfx.Add((0.66f, "mag_in"));
			if (Mag(_item) == 0)
			{
				_reloadSfx.Add((0.8f, (Random.value < 0.5f) ? "bolt_back_a" : "bolt_back_b"));
				_reloadSfx.Add((0.88f, "bolt_forward"));
			}
			_reloadSfx.Add((0.97f, "ready"));
		}

		private void UpdateReload(Player p, GunDef gun, ItemData item)
		{
			float num = (Time.time - _reloadStart) / _reloadLen;
			while (_sfxIndex < _reloadSfx.Count && num >= _reloadSfx[_sfxIndex].at)
			{
				PlaySfx(_reloadSfx[_sfxIndex++].clip, p, 1f);
			}
			if (num < 1f)
			{
				return;
			}
			_reloading = false;
			AmmoDef ammoDef = GunDefs.AmmoFor(gun);
			if (ammoDef == null)
			{
				return;
			}
			Inventory inventory = ((Humanoid)p).GetInventory();
			int num2 = gun.MagSize.Value - Mag(item);
			int num3 = 0;
			foreach (ItemData item2 in new List<ItemData>(inventory.GetAllItems()))
			{
				if (num3 >= num2)
				{
					break;
				}
				if (!(item2.m_shared.m_name != ammoDef.Display))
				{
					int num4 = Mathf.Min(item2.m_stack, num2 - num3);
					inventory.RemoveItem(item2, num4);
					num3 += num4;
				}
			}
			SetMag(item, Mag(item) + num3);
		}

		private void CancelReload()
		{
			_reloading = false;
			_reloadSfx.Clear();
		}

		private static void PlaySfx(string clip, Player p, float volume)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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)
			GunAssets.Play(GunAssets.Clip(clip), ((Component)p).transform.position + Vector3.up * 1.3f, ((Component)p).transform, volume, 30f);
			GunNet.SendSfx(clip);
		}

		private void OnGUI()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Expected O, but got Unknown
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0312: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0358: 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)
			if ((int)Event.current.type != 7 || _gun == null || !Object.op_Implicit((Object)(object)Player.m_localPlayer) || (Object.op_Implicit((Object)(object)Hud.instance) && !Hud.instance.IsVisible()))
			{
				return;
			}
			float num = (float)Screen.height / 1080f;
			if (_big == null || _big.fontSize != Mathf.RoundToInt(44f * num))
			{
				_big = new GUIStyle(GUI.skin.label)
				{
					fontSize = Mathf.RoundToInt(44f * num),
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)8
				};
				_small = new GUIStyle(_big)
				{
					fontSize = Mathf.RoundToInt(22f * num)
				};
			}
			Player localPlayer = Player.m_localPlayer;
			int num2 = Mag(_item);
			int num3 = AmmoCount(localPlayer, _gun);
			float num4 = Screen.width;
			float num5 = Screen.height;
			Rect r = default(Rect);
			((Rect)(ref r))..ctor(num4 - 420f * num, num5 - 210f * num, 380f * num, 60f * num);
			Shadow(r, num2 + " / " + num3, _big, (Color)((num2 == 0) ? new Color(1f, 0.4f, 0.3f) : Color.white));
			Shadow(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y - 34f * num, ((Rect)(ref r)).width, 30f * num), _gun.Display, _small, new Color(1f, 0.85f, 0.6f));
			if (_reloading)
			{
				float num6 = Mathf.Clamp01((Time.time - _reloadStart) / _reloadLen);
				GUI.color = new Color(0f, 0f, 0f, 0.6f);
				GUI.DrawTexture(new Rect(((Rect)(ref r)).xMax - 200f * num, ((Rect)(ref r)).yMax + 6f * num, 200f * num, 6f * num), (Texture)(object)Texture2D.whiteTexture);
				GUI.color = new Color(1f, 0.8f, 0.4f, 0.95f);
				GUI.DrawTexture(new Rect(((Rect)(ref r)).xMax - 200f * num, ((Rect)(ref r)).yMax + 6f * num, 200f * num * num6, 6f * num), (Texture)(object)Texture2D.whiteTexture);
				GUI.color = Color.white;
			}
			if (Time.time - _hitMarker < 0.15f)
			{
				float num7 = num4 / 2f;
				float num8 = num5 / 2f;
				float num9 = 9f * num;
				float num10 = 7f * num;
				Matrix4x4 matrix = GUI.matrix;
				GUI.color = new Color(1f, 1f, 1f, 0.9f);
				float[] array = new float[4] { 45f, 135f, 225f, 315f };
				foreach (float num11 in array)
				{
					GUI.matrix = matrix;
					GUIUtility.RotateAroundPivot(num11, new Vector2(num7, num8));
					GUI.DrawTexture(new Rect(num7 + num9, num8 - 1f, num10, 2f), (Texture)(object)Texture2D.whiteTexture);
				}
				GUI.matrix = matrix;
				GUI.color = Color.white;
			}
		}

		private static void Shadow(Rect r, string text, GUIStyle st, Color c)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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)
			st.normal.textColor = new Color(0f, 0f, 0f, 0.8f);
			GUI.Label(new Rect(((Rect)(ref r)).x + 2f, ((Rect)(ref r)).y + 2f, ((Rect)(ref r)).width, ((Rect)(ref r)).height), text, st);
			st.normal.textColor = c;
			GUI.Label(r, text, st);
		}
	}
	internal enum GunKind
	{
		Rifle,
		Launcher
	}
	internal sealed class GunDef
	{
		internal byte Index;

		internal string Id;

		internal string Display;

		internal string Desc;

		internal string Model;

		internal string AmmoId;

		internal GunKind Kind;

		internal bool Auto;

		internal string[] FireSounds;

		internal float Weight;

		internal float SpreadHip;

		internal float SpreadAim;

		internal float Recoil;

		internal float Range;

		internal ConfigEntry<float> Damage;

		internal ConfigEntry<float> Rpm;

		internal ConfigEntry<float> ReloadTime;

		internal ConfigEntry<int> MagSize;

		internal ConfigEntry<int> StationLevel;

		internal ConfigEntry<string> Recipe;

		internal ConfigEntry<string> Station;

		internal bool IsLauncher => Kind == GunKind.Launcher;
	}
	internal sealed class AmmoDef
	{
		internal string Id;

		internal string Display;

		internal string Desc;

		internal float Weight;

		internal int Stack;

		internal bool Rocket;

		internal ConfigEntry<string> Recipe;

		internal ConfigEntry<string> Station;

		internal ConfigEntry<int> Amount;

		internal ConfigEntry<int> StationLevel;
	}
	internal static class GunDefs
	{
		internal static readonly List<GunDef> Guns = new List<GunDef>();

		internal static readonly List<AmmoDef> Ammo = new List<AmmoDef>();

		private static readonly Dictionary<string, GunDef> ById = new Dictionary<string, GunDef>();

		private static readonly Dictionary<int, GunDef> ByHash = new Dictionary<int, GunDef>();

		internal static GunDef ByIndex(int i)
		{
			if (i < 0 || i >= Guns.Count)
			{
				return null;
			}
			return Guns[i];
		}

		internal static GunDef For(ItemData item)
		{
			if (item == null)
			{
				return null;
			}
			if (Object.op_Implicit((Object)(object)item.m_dropPrefab) && ById.TryGetValue(((Object)item.m_dropPrefab).name, out var value))
			{
				return value;
			}
			foreach (GunDef gun in Guns)
			{
				if (item.m_shared != null && item.m_shared.m_name == gun.Display)
				{
					return gun;
				}
			}
			return null;
		}

		internal static GunDef ForHash(int hash)
		{
			if (!ByHash.TryGetValue(hash, out var value))
			{
				return null;
			}
			return value;
		}

		internal static void Bind(ConfigFile c)
		{
			Add(c, new GunDef
			{
				Id = "GunAK74M",
				Display = "AK-74M",
				Model = "ak74",
				AmmoId = "Ammo545",
				Kind = GunKind.Rifle,
				Auto = true,
				Desc = "5.45 mm assault rifle. Full auto, hard hitting, kicks up.\nLMB fire · RMB aim · R reload",
				FireSounds = new string[1] { "ak74_fire" },
				Weight = 3.6f,
				SpreadHip = 2.6f,
				SpreadAim = 0.35f,
				Recoil = 1.1f,
				Range = 260f
			}, 34f, 600f, 2.6f, 30, "Iron:20,FineWood:6,LeatherScraps:4,Resin:6", "forge", 2);
			Add(c, new GunDef
			{
				Id = "GunM4",
				Display = "M4 carbine",
				Model = "m4",
				AmmoId = "Ammo556",
				Kind = GunKind.Rifle,
				Auto = true,
				Desc = "5.56 mm carbine. Faster fire, softer recoil, very accurate.\nLMB fire · RMB aim · R reload",
				FireSounds = new string[1] { "m4_fire" },
				Weight = 3.1f,
				SpreadHip = 2.2f,
				SpreadAim = 0.25f,
				Recoil = 0.75f,
				Range = 300f
			}, 28f, 750f, 2.3f, 30, "Iron:22,Bronze:6,LeatherScraps:4,Resin:6", "forge", 3);
			Add(c, new GunDef
			{
				Id = "GunRPG7",
				Display = "RPG-7",
				Model = "rpg7",
				AmmoId = "RocketPG7V",
				Kind = GunKind.Launcher,
				Auto = false,
				Desc = "Rocket-propelled grenade launcher with PG-7V rockets. Area blast hits creatures, buildings, trees and rock.\nLMB fire · RMB aim · R reload",
				FireSounds = new string[2] { "rpg_launch_a", "rpg_launch_b" },
				Weight = 6.3f,
				SpreadHip = 1.2f,
				SpreadAim = 0.2f,
				Recoil = 3.5f,
				Range = 600f
			}, 0f, 20f, 3.2f, 1, "Iron:30,FineWood:10,LeatherScraps:6,SurtlingCore:2", "forge", 3);
			AddAmmo(c, new AmmoDef
			{
				Id = "Ammo545",
				Display = "5.45x39 rounds",
				Desc = "Ammunition for the AK-74M.",
				Weight = 0.01f,
				Stack = 300
			}, "Copper:1,Coal:4", "forge", 1, 30);
			AddAmmo(c, new AmmoDef
			{
				Id = "Ammo556",
				Display = "5.56x45 rounds",
				Desc = "Ammunition for the M4 carbine.",
				Weight = 0.01f,
				Stack = 300
			}, "Tin:1,Coal:4", "forge", 1, 30);
			AddAmmo(c, new AmmoDef
			{
				Id = "RocketPG7V",
				Display = "PG-7V rocket",
				Desc = "Rocket for the RPG-7.",
				Weight = 2.2f,
				Stack = 5,
				Rocket = true
			}, "Iron:2,Coal:10,SurtlingCore:1", "forge", 2, 1);
		}

		private static void Add(ConfigFile c, GunDef g, float dmg, float rpm, float reload, int mag, string recipe, string station, int level)
		{
			string display = g.Display;
			g.Index = (byte)Guns.Count;
			if (g.IsLauncher)
			{
				g.Damage = c.Bind<float>(display, "Damage", dmg, "Not used for the RPG-7: see the [RPG-7] blast settings.");
			}
			else
			{
				g.Damage = c.Bind<float>(display, "Damage", dmg, "Pierce damage per bullet (falls to 50% at max range).");
			}
			g.Rpm = c.Bind<float>(display, "FireRate", rpm, "Rounds per minute.");
			g.ReloadTime = c.Bind<float>(display, "ReloadTime", reload, "Reload time, seconds.");
			g.MagSize = c.Bind<int>(display, "MagSize", mag, "Rounds per magazine.");
			g.Recipe = c.Bind<string>(display, "Recipe", recipe, "Item:Amount separated by commas (prefab names).");
			g.Station = c.Bind<string>(display, "Station", station, "Crafting station (forge, piece_workbench, ... or empty for none).");
			g.StationLevel = c.Bind<int>(display, "StationLevel", level, "Required station level.");
			Guns.Add(g);
			ById[g.Id] = g;
			ByHash[StringExtensionMethods.GetStableHashCode(g.Id)] = g;
		}

		private static void AddAmmo(ConfigFile c, AmmoDef a, string recipe, string station, int level, int amount)
		{
			string display = a.Display;
			a.Recipe = c.Bind<string>(display, "Recipe", recipe, "Item:Amount separated by commas (prefab names).");
			a.Station = c.Bind<string>(display, "Station", station, "Crafting station.");
			a.StationLevel = c.Bind<int>(display, "StationLevel", level, "Required station level.");
			a.Amount = c.Bind<int>(display, "CraftAmount", amount, "Items made per craft.");
			Ammo.Add(a);
		}

		internal static AmmoDef AmmoFor(GunDef g)
		{
			return Ammo.Find((AmmoDef a) => a.Id == g.AmmoId);
		}
	}
	internal static class GunExplosion
	{
		private class FlashFade : MonoBehaviour
		{
			private Light _l;

			private float _t;

			private void Awake()
			{
				_l = ((Component)this).GetComponent<Light>();
			}

			private void Update()
			{
				_t += Time.deltaTime;
				if (Object.op_Implicit((Object)(object)_l))
				{
					_l.intensity = 9f * Mathf.Exp((0f - _t) * 6f) + ((_t < 1.5f) ? (1.2f * Mathf.PerlinNoise(_t * 12f, 0f) * (1.5f - _t)) : 0f);
				}
			}
		}

		private static GameObject _vanilla;

		private static bool _searched;

		internal static void Detonate(Vector3 point, Player attacker)
		{
			//IL_0000: 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)
			ApplyDamage(point, attacker);
			GunNet.SendBoom(point);
		}

		private static void ApplyDamage(Vector3 point, Player attacker)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: 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_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Expected O, but got Unknown
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			float value = Cfg.BlastRadius.Value;
			float value2 = Cfg.BlastDamage.Value;
			float value3 = Cfg.BlastChop.Value;
			int mask = LayerMask.GetMask(new string[2] { "terrain", "static_solid" });
			HashSet<Component> hashSet = new HashSet<Component>();
			Collider[] array = Physics.OverlapSphere(point, value, -1, (QueryTriggerInteraction)1);
			foreach (Collider val in array)
			{
				if (!Object.op_Implicit((Object)(object)val))
				{
					continue;
				}
				IDestructible componentInParent = ((Component)val).GetComponentInParent<IDestructible>();
				Component val2 = (Component)(object)((componentInParent is Component) ? componentInParent : null);
				if (val2 == null || !hashSet.Add(val2))
				{
					continue;
				}
				MeshCollider val3 = (MeshCollider)(object)((val is MeshCollider) ? val : null);
				Vector3 val4;
				if (val3 == null || val3.convex)
				{
					val4 = val.ClosestPoint(point);
				}
				else
				{
					Bounds bounds = val.bounds;
					val4 = ((Bounds)(ref bounds)).ClosestPoint(point);
				}
				Vector3 val5 = val4;
				float num = Vector3.Distance(point, val5);
				float num2 = Mathf.Clamp01(1f - Mathf.Pow(num / value, 1.4f));
				if (!(num2 <= 0f))
				{
					Vector3 val6 = val5 - point;
					if (((Vector3)(ref val6)).magnitude > 0.3f && Physics.Raycast(point, ((Vector3)(ref val6)).normalized, ((Vector3)(ref val6)).magnitude - 0.2f, mask, (QueryTriggerInteraction)1))
					{
						num2 *= 0.5f;
					}
					HitData val7 = new HitData();
					val7.m_damage.m_blunt = value2 * 0.45f * num2;
					val7.m_damage.m_pierce = value2 * 0.35f * num2;
					val7.m_damage.m_fire = value2 * 0.2f * num2;
					val7.m_damage.m_chop = value3 * num2;
					val7.m_damage.m_pickaxe = value3 * num2;
					val7.m_point = val5;
					val7.m_dir = ((((Vector3)(ref val6)).sqrMagnitude > 0.001f) ? ((Vector3)(ref val6)).normalized : Vector3.up);
					val7.m_pushForce = 80f * num2;
					val7.m_staggerMultiplier = 3f;
					val7.m_toolTier = 4;
					val7.m_blockable = false;
					val7.m_dodgeable = false;
					val7.m_ranged = true;
					val7.m_ignorePVP = Cfg.IgnorePvP.Value;
					if (Object.op_Implicit((Object)(object)attacker))
					{
						val7.SetAttacker((Character)(object)attacker);
					}
					try
					{
						componentInParent.Damage(val7);
					}
					catch (Exception ex)
					{
						GunsPlugin.Warn("Blast damage on " + ((Object)val2).name + ": " + ex.Message);
					}
				}
			}
			array = Physics.OverlapSphere(point, value * 1.2f, -1, (QueryTriggerInteraction)1);
			foreach (Collider val8 in array)
			{
				Rigidbody val9 = (Object.op_Implicit((Object)(object)val8) ? val8.attachedRigidbody : null);
				if (Object.op_Implicit((Object)(object)val9) && !val9.isKinematic && !Object.op_Implicit((Object)(object)((Component)val9).GetComponent<Character>()))
				{
					val9.AddExplosionForce(12f * val9.mass, point, value * 1.2f, 0.6f, (ForceMode)1);
				}
			}
		}

		private static GameObject VanillaFx()
		{
			if (_searched || !Object.op_Implicit((Object)(object)ZNetScene.instance))
			{
				return _vanilla;
			}
			_searched = true;
			string text = "";
			if (text.Length > 0)
			{
				_vanilla = ZNetScene.instance.GetPrefab(text);
				if (!Object.op_Implicit((Object)(object)_vanilla))
				{
					GunsPlugin.Warn("VanillaEffectPrefab '" + text + "' not found");
				}
				if (Object.op_Implicit((Object)(object)_vanilla) && Object.op_Implicit((Object)(object)_vanilla.GetComponent<ZNetView>()))
				{
					_vanilla = null;
				}
				if (Object.op_Implicit((Object)(object)_vanilla))
				{
					return _vanilla;
				}
			}
			string[] array = new string[6] { "fx_siegebomb_explosion", "fx_fireball_staff_explosion", "fx_goblinking_meteor_hit", "fx_Fader_Meteor_Hit", "fx_DvergerMage_Fire_hit", "fx_fireball_explosion" };
			List<string> list = new List<string>();
			foreach (GameObject prefab in ZNetScene.instance.m_prefabs)
			{
				if (Object.op_Implicit((Object)(object)prefab) && !Object.op_Implicit((Object)(object)prefab.GetComponent<ZNetView>()))
				{
					string text2 = ((Object)prefab).name.ToLowerInvariant();
					if ((text2.StartsWith("fx_") || text2.StartsWith("vfx_")) && (text2.Contains("explo") || text2.Contains("meteor_hit") || text2.Contains("bomb")))
					{
						list.Add(((Object)prefab).name);
					}
				}
			}
			GunsPlugin.Log("Vanilla explosion candidates: " + string.Join(", ", list));
			string[] array2 = array;
			foreach (string n in array2)
			{
				string text3 = list.Find((string f) => f.Equals(n, StringComparison.OrdinalIgnoreCase));
				if (text3 != null)
				{
					_vanilla = ZNetScene.instance.GetPrefab(text3);
					break;
				}
			}
			if (!Object.op_Implicit((Object)(object)_vanilla))
			{
				string text4 = list.Find((string f) => f.ToLowerInvariant().Contains("explo"));
				if (text4 != null)
				{
					_vanilla = ZNetScene.instance.GetPrefab(text4);
				}
			}
			if (Object.op_Implicit((Object)(object)_vanilla))
			{
				GunsPlugin.Log("Using vanilla explosion effect " + ((Object)_vanilla).name);
			}
			return _vanilla;
		}

		internal static void Visual(Vector3 point)
		{
			//IL_0029: 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_0034: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Expected O, but got Unknown
			//IL_000f: 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_010d: Expected O, but got Unknown
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = VanillaFx();
			if (Object.op_Implicit((Object)(object)val))
			{
				Object.Destroy((Object)(object)Object.Instantiate<GameObject>(val, point, Quaternion.identity), 12f);
			}
			GameObject val2 = new GameObject("FPVExplosion");
			val2.transform.position = point;
			Light obj = val2.AddComponent<Light>();
			obj.type = (LightType)2;
			obj.color = new Color(1f, 0.65f, 0.3f);
			obj.range = 26f;
			obj.intensity = 9f;
			obj.shadows = (LightShadows)0;
			val2.AddComponent<FlashFade>();
			Fireball(val2.transform);
			Smoke(val2.transform);
			Sparks(val2.transform);
			Dust(val2.transform);
			AudioSource obj2 = GunAssets.AddSource(val2, GunAssets.Boom, loop: false, 8f, 260f);
			obj2.volume = 1f;
			obj2.dopplerLevel = 0f;
			obj2.Play();
			if (Object.op_Implicit((Object)(object)GameCamera.instance))
			{
				GameCamera.instance.AddShake(point, 45f, 5f, false);
			}
			Object.Destroy((Object)val2, 9f);
		}

		private static ParticleSystem NewSystem(Transform parent, string name, bool additive)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			ParticleSystem obj = val.AddComponent<ParticleSystem>();
			obj.Stop(true, (ParticleSystemStopBehavior)0);
			MainModule main = obj.main;
			((MainModule)(ref main)).loop = false;
			((MainModule)(ref main)).playOnAwake = false;
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
			EmissionModule emission = obj.emission;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(0f);
			ParticleSystemRenderer component = val.GetComponent<ParticleSystemRenderer>();
			((Renderer)component).sharedMaterial = GunAssets.ParticleMaterial(additive);
			((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
			return obj;
		}

		private static Gradient Fade(Color a, Color b, float peak)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			Gradient val = new Gradient();
			val.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
			{
				new GradientColorKey(a, 0f),
				new GradientColorKey(b, 1f)
			}, (GradientAlphaKey[])(object)new GradientAlphaKey[3]
			{
				new GradientAlphaKey(peak, 0f),
				new GradientAlphaKey(peak * 0.7f, 0.4f),
				new GradientAlphaKey(0f, 1f)
			});
			return val;
		}

		private static void Fireball(Transform parent)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_00a7: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: 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_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			ParticleSystem obj = NewSystem(parent, "Fire", additive: true);
			MainModule main = obj.main;
			((MainModule)(ref main)).duration = 0.3f;
			((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.35f, 0.8f);
			((MainModule)(ref main)).startSpeed = new MinMaxCurve(3f, 11f);
			((MainModule)(ref main)).startSize = new MinMaxCurve(1.5f, 3.6f);
			((MainModule)(ref main)).startColor = new MinMaxGradient(new Color(1f, 0.85f, 0.45f), new Color(1f, 0.45f, 0.1f));
			((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(-0.15f);
			ShapeModule shape = obj.shape;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
			((ShapeModule)(ref shape)).radius = 0.4f;
			ColorOverLifetimeModule colorOverLifetime = obj.colorOverLifetime;
			((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
			((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(Fade(new Color(1f, 0.8f, 0.4f), new Color(0.6f, 0.12f, 0.02f), 1f));
			SizeOverLifetimeModule sizeOverLifetime = obj.sizeOverLifetime;
			((SizeOverLifetimeModule)(ref sizeOverLifetime)).enabled = true;
			((SizeOverLifetimeModule)(ref sizeOverLifetime)).size = new MinMaxCurve(1f, AnimationCurve.EaseInOut(0f, 0.6f, 1f, 1.6f));
			LimitVelocityOverLifetimeModule limitVelocityOverLifetime = obj.limitVelocityOverLifetime;
			((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).enabled = true;
			((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).limit = MinMaxCurve.op_Implicit(2f);
			((LimitVelocityOverLifetimeModule)(ref limitVelocityOverLifetime)).dampen = 0.25f;
			obj.Play();
			obj.Emit(45);
		}

		private static void Smoke(Transform parent)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid