Decompiled source of vonguns v1.1.0

BepInEx/plugins/vonguns/vonguns.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Audio;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyVersion("0.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 VonGuns
{
	public static class Fx
	{
		private static Mesh flashMesh;

		private static readonly Queue<GameObject> casings = new Queue<GameObject>();

		private static Material tracerMat;

		private static Mesh FlashMesh()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_005d: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Expected O, but got Unknown
			if ((Object)(object)flashMesh != (Object)null)
			{
				return flashMesh;
			}
			List<Vector3> v = new List<Vector3>();
			List<int> t = new List<int>();
			for (int i = 0; i < 3; i++)
			{
				Vector3 val = Quaternion.AngleAxis(60f * (float)i, Vector3.forward) * Vector3.right * 0.045f;
				Quad(-val, val, val * 0.15f + Vector3.forward * 0.2f, -val * 0.15f + Vector3.forward * 0.2f);
			}
			Quad(new Vector3(-0.05f, -0.05f, 0.01f), new Vector3(0.05f, -0.05f, 0.01f), new Vector3(0.05f, 0.05f, 0.01f), new Vector3(-0.05f, 0.05f, 0.01f));
			flashMesh = new Mesh
			{
				name = "VG_FlashMesh"
			};
			flashMesh.SetVertices(v);
			flashMesh.SetTriangles(t, 0);
			flashMesh.RecalculateBounds();
			return flashMesh;
			void Quad(Vector3 a, Vector3 b, Vector3 c, Vector3 d)
			{
				//IL_001c: 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_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				int count = v.Count;
				v.AddRange((IEnumerable<Vector3>)(object)new Vector3[4] { a, b, c, d });
				t.AddRange(new int[12]
				{
					count,
					count + 1,
					count + 2,
					count,
					count + 2,
					count + 3,
					count,
					count + 2,
					count + 1,
					count,
					count + 3,
					count + 2
				});
			}
		}

		public static void Flash(Vector3 at, Vector3 forward, float scale)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: 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_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("VG_MuzzleFlash");
			val.transform.position = at;
			val.transform.rotation = Quaternion.LookRotation(forward) * Quaternion.AngleAxis(Random.Range(0f, 360f), Vector3.forward);
			val.transform.localScale = Vector3.one * scale * Random.Range(0.8f, 1.25f);
			val.AddComponent<MeshFilter>().sharedMesh = FlashMesh();
			MeshRenderer obj = val.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterial = ModAssets.Emissive();
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			Light obj2 = new GameObject("VG_FlashLight").AddComponent<Light>();
			((Component)obj2).transform.SetParent(val.transform, false);
			obj2.type = (LightType)2;
			obj2.color = new Color(1f, 0.7f, 0.35f);
			obj2.range = 5f;
			obj2.intensity = 6f;
			Object.Destroy((Object)(object)val, 0.045f);
		}

		public static void Tracer(Vector3 from, Vector3 to)
		{
			//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_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_003d: 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_004b: 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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Expected O, but got Unknown
			if (!(Random.value > 0.5f))
			{
				if ((Object)(object)tracerMat == (Object)null)
				{
					tracerMat = ModAssets.Emissive();
				}
				GameObject val = new GameObject("VG_Tracer");
				LineRenderer obj = val.AddComponent<LineRenderer>();
				obj.positionCount = 2;
				Vector3 val2 = to - from;
				float magnitude = ((Vector3)(ref val2)).magnitude;
				Vector3 val3 = from + ((Vector3)(ref val2)).normalized * Mathf.Min(1.5f, magnitude * 0.2f);
				obj.SetPosition(0, val3);
				obj.SetPosition(1, Vector3.Lerp(val3, to, Random.Range(0.35f, 0.9f)));
				((Renderer)obj).material = tracerMat;
				obj.startWidth = 0.012f;
				obj.endWidth = 0.004f;
				((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
				Object.Destroy((Object)val, 0.03f);
			}
		}

		public static void Casing(Vector3 at, Vector3 outward, string key)
		{
			//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_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: 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)
			Camera val = (((Object)(object)GameNetworkManager.Instance != (Object)null && (Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null) ? GameNetworkManager.Instance.localPlayerController.gameplayCamera : null);
			if (!((Object)(object)val != (Object)null) || !(Vector3.Distance(((Component)val).transform.position, at) > 25f))
			{
				GameObject val2;
				if (casings.Count >= 30)
				{
					val2 = casings.Dequeue();
				}
				else
				{
					val2 = GameObject.CreatePrimitive((PrimitiveType)2);
					((Object)val2).name = "VG_Casing";
					val2.layer = 2;
					Object.DestroyImmediate((Object)(object)val2.GetComponent<Collider>());
					val2.AddComponent<CapsuleCollider>().direction = 1;
					((Renderer)val2.GetComponent<MeshRenderer>()).sharedMaterial = ModAssets.Brass();
					((Renderer)val2.GetComponent<MeshRenderer>()).shadowCastingMode = (ShadowCastingMode)0;
					Rigidbody obj = val2.AddComponent<Rigidbody>();
					obj.mass = 0.01f;
					obj.interpolation = (RigidbodyInterpolation)0;
					obj.collisionDetectionMode = (CollisionDetectionMode)0;
				}
				float num = ((key == "arp") ? 0.045f : ((key == "draco") ? 0.039f : 0.019f));
				float num2 = ((key == "glock") ? 0.0095f : 0.011f);
				val2.transform.localScale = new Vector3(num2, num * 0.5f, num2);
				val2.transform.position = at;
				val2.transform.rotation = Random.rotation;
				val2.SetActive(true);
				Rigidbody component = val2.GetComponent<Rigidbody>();
				component.velocity = ((Vector3)(ref outward)).normalized * Random.Range(2.2f, 3.4f) + Random.insideUnitSphere * 0.4f;
				component.angularVelocity = Random.insideUnitSphere * 25f;
				casings.Enqueue(val2);
				Runner.Run(HideLater(val2));
			}
		}

		private static IEnumerator HideLater(GameObject go)
		{
			yield return (object)new WaitForSeconds(2.5f);
			if ((!((Object)(object)go != (Object)null) || casings.Contains(go)) && (Object)(object)go != (Object)null)
			{
				go.SetActive(false);
			}
		}
	}
	public class GunItem : GrabbableObject
	{
		public string gunKey;

		public int rounds = -1;

		[NonSerialized]
		public float lastDropTime;

		private RigAnimator anim;

		private AudioSource audio;

		private AudioSource tailAudio;

		private AudioSource loopAudio;

		private bool looping;

		private float lastShotTime;

		private float lastRejectLog;

		private float lastShotLog;

		private Transform muzzle;

		private Transform port;

		private bool triggerHeld;

		private bool firing;

		private bool reloading;

		private float nextShot;

		private float noiseTimer;

		private Coroutine reloadRoutine;

		private static readonly FieldRef<PlayerControllerB, float> CameraUp = AccessTools.FieldRefAccess<PlayerControllerB, float>("cameraUp");

		public Vector3? debugAim;

		private Coroutine fxRoutine;

		public GunDef Def { get; private set; }

		private bool HeldByMe
		{
			get
			{
				if (((NetworkBehaviour)this).IsOwner && base.isHeld && !base.isPocketed && (Object)(object)base.playerHeldBy != (Object)null)
				{
					return (Object)(object)base.playerHeldBy == (Object)(object)GameNetworkManager.Instance.localPlayerController;
				}
				return false;
			}
		}

		private Vector3 MuzzlePos
		{
			get
			{
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)muzzle != (Object)null))
				{
					return ((Component)this).transform.position;
				}
				return muzzle.position;
			}
		}

		private Vector3 Forward
		{
			get
			{
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)anim != (Object)null))
				{
					return ((Component)this).transform.forward;
				}
				return -((Component)anim).transform.right;
			}
		}

		public override void Start()
		{
			Def = Guns.ByKey(gunKey);
			((GrabbableObject)this).Start();
			if (rounds < 0 && Def != null)
			{
				rounds = Def.MagSize;
			}
			anim = ((Component)this).GetComponentInChildren<RigAnimator>();
			audio = ((Component)this).GetComponent<AudioSource>();
			Setup(audio, 90f);
			tailAudio = ((Component)this).gameObject.AddComponent<AudioSource>();
			Setup(tailAudio, 140f);
			loopAudio = ((Component)this).gameObject.AddComponent<AudioSource>();
			Setup(loopAudio, 120f);
			loopAudio.loop = true;
			muzzle = (((Object)(object)anim != (Object)null) ? anim.Bone("Flash") : null);
			port = (((Object)(object)anim != (Object)null) ? anim.Bone("Casing") : null);
		}

		private static void Setup(AudioSource s, float range)
		{
			s.playOnAwake = false;
			s.spatialBlend = 1f;
			s.rolloffMode = (AudioRolloffMode)1;
			s.minDistance = 6f;
			s.maxDistance = range;
			s.dopplerLevel = 0f;
			if ((Object)(object)Guns.SfxGroup != (Object)null)
			{
				s.outputAudioMixerGroup = Guns.SfxGroup;
			}
		}

		public override void LateUpdate()
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: 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_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: 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_0143: 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_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: 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_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).LateUpdate();
			if ((Object)(object)anim == (Object)null || Def == null || Def.FpScale == null)
			{
				return;
			}
			int num;
			float num2;
			if (HeldByMe)
			{
				num = (((Object)(object)base.parentObject != (Object)null) ? 1 : 0);
				if (num != 0)
				{
					num2 = Mathf.Clamp(Def.FpScale.Value, 0.5f, 3f);
					goto IL_006a;
				}
			}
			else
			{
				num = 0;
			}
			num2 = 1f;
			goto IL_006a;
			IL_006a:
			float num3 = num2;
			if (((Component)anim).transform.localScale.x != num3)
			{
				((Component)anim).transform.localScale = Vector3.one * num3;
			}
			if (num != 0)
			{
				Transform transform = ((Component)base.playerHeldBy.gameplayCamera).transform;
				Vector3 val = Guns.ParseV3(Def.FpOffset.Value);
				Vector3 val2 = Guns.ParseV3(Def.FpRotation.Value);
				((Component)this).transform.rotation = Quaternion.AngleAxis(val2.y, transform.up) * Quaternion.AngleAxis(val2.x, transform.right) * Quaternion.AngleAxis(val2.z, transform.forward) * ((Component)this).transform.rotation;
				Transform transform2 = ((Component)this).transform;
				transform2.position += transform.right * val.x + transform.up * val.y + transform.forward * val.z;
			}
		}

		public override int GetItemDataToSave()
		{
			return Mathf.Max(0, rounds);
		}

		public override void LoadItemSaveData(int saveData)
		{
			((GrabbableObject)this).LoadItemSaveData(saveData);
			rounds = saveData;
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (ModConfig.DebugKeys.Value)
			{
				Plugin.Log.LogInfo((object)string.Format("[input] {0} #{1} trigger {2}", ((Object)this).name, ((NetworkBehaviour)this).NetworkObjectId, buttonDown ? "down" : "up"));
			}
			if (!HeldByMe || Def == null)
			{
				if (buttonDown && Time.time - lastRejectLog > 2f)
				{
					lastRejectLog = Time.time;
					Plugin.Log.LogWarning((object)($"{((Object)this).name}: trigger ignored (def {Def != null}, owner {((NetworkBehaviour)this).IsOwner}, held {base.isHeld}, pocketed {base.isPocketed}, " + "holder " + (((Object)(object)base.playerHeldBy != (Object)null) ? base.playerHeldBy.playerUsername : "none") + ")"));
				}
				return;
			}
			triggerHeld = buttonDown;
			if (!buttonDown || reloading)
			{
				return;
			}
			if (rounds <= 0)
			{
				DryFire();
				Net.Send(new Msg
				{
					Op = Op.DryFire,
					Id = ((NetworkBehaviour)this).NetworkObjectId
				});
				if (FindAmmoSlot() < 0)
				{
					HUDManager.Instance.DisplayTip("Out of ammo", "Buy a " + Def.AmmoName + " in the store (type " + Def.AmmoKeyword + ").", true, false, "LC_Tip1");
				}
			}
			else if (!firing)
			{
				nextShot = Time.time;
			}
		}

		public override void Update()
		{
			((GrabbableObject)this).Update();
			if ((Object)(object)loopAudio != (Object)null)
			{
				if (looping && !((NetworkBehaviour)this).IsOwner && Time.time - lastShotTime > Mathf.Max(0.35f, Def.Cycle * 3f))
				{
					StopLoop();
				}
				if (!looping && loopAudio.isPlaying)
				{
					AudioSource obj = loopAudio;
					obj.volume -= Time.deltaTime / 0.035f;
					if (loopAudio.volume <= 0f)
					{
						loopAudio.Stop();
					}
				}
			}
			if (Def == null || !HeldByMe)
			{
				if (firing && ((NetworkBehaviour)this).IsOwner)
				{
					EndBurst();
				}
				triggerHeld = false;
				return;
			}
			PlayerControllerB playerHeldBy = base.playerHeldBy;
			if (!playerHeldBy.isTypingChat && !playerHeldBy.inTerminalMenu && (!((Object)(object)playerHeldBy.quickMenuManager != (Object)null) || !playerHeldBy.quickMenuManager.isMenuOpen) && Keyboard.current != null && ((ButtonControl)Keyboard.current.rKey).wasPressedThisFrame)
			{
				TryReload();
			}
			if (triggerHeld && !reloading && rounds > 0 && !playerHeldBy.isPlayerDead)
			{
				firing = true;
				if (nextShot < Time.time - Def.Cycle)
				{
					nextShot = Time.time;
				}
				int num = 0;
				while (Time.time >= nextShot && rounds > 0 && num++ < 4)
				{
					FireOne();
					nextShot += Def.Cycle;
				}
				if (rounds <= 0)
				{
					EndBurst();
					DryFire();
				}
			}
			else if (firing)
			{
				EndBurst();
			}
		}

		private void FireOne()
		{
			//IL_003c: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_040f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0411: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			rounds--;
			PlayerControllerB playerHeldBy = base.playerHeldBy;
			Transform transform = ((Component)playerHeldBy.gameplayCamera).transform;
			Vector3 val;
			if (!debugAim.HasValue)
			{
				val = transform.forward;
			}
			else
			{
				Vector3 val2 = debugAim.Value - transform.position;
				val = ((Vector3)(ref val2)).normalized;
			}
			Vector3 dir = val;
			dir = Spread(dir, Def.SpreadDeg);
			int b = -1;
			Vector3 val3 = transform.position + dir * ModConfig.Range.Value;
			int num = StartOfRound.Instance.collidersAndRoomMaskAndDefault | 0x80000 | 8;
			RaycastHit[] array = (from h in Physics.RaycastAll(transform.position, dir, ModConfig.Range.Value, num, (QueryTriggerInteraction)2)
				orderby ((RaycastHit)(ref h)).distance
				select h).ToArray();
			if (ModConfig.DebugKeys.Value && Time.time - lastShotLog > 0.3f && (lastShotLog = Time.time) > 0f)
			{
				Plugin.Log.LogInfo((object)("[shot] " + string.Join(" | ", array.Take(6).Select(delegate(RaycastHit h)
				{
					string text = string.Format("{0} L{1}{2} {3:F1}m ", ((Object)((RaycastHit)(ref h)).collider).name, ((Component)((RaycastHit)(ref h)).collider).gameObject.layer, ((RaycastHit)(ref h)).collider.isTrigger ? " trig" : "", ((RaycastHit)(ref h)).distance);
					PlayerControllerB componentInParent2 = ((Component)((RaycastHit)(ref h)).collider).GetComponentInParent<PlayerControllerB>();
					return text + ((componentInParent2 != null) ? ("player:" + componentInParent2.playerUsername) : "");
				}))));
			}
			RaycastHit[] array2 = array;
			IHittable val5 = default(IHittable);
			for (int num2 = 0; num2 < array2.Length; num2++)
			{
				RaycastHit val4 = array2[num2];
				if (((Component)((RaycastHit)(ref val4)).collider).transform.IsChildOf(((Component)playerHeldBy).transform) || ((Component)((RaycastHit)(ref val4)).collider).transform.IsChildOf(((Component)this).transform))
				{
					continue;
				}
				EnemyAICollisionDetect component = ((Component)((RaycastHit)(ref val4)).collider).GetComponent<EnemyAICollisionDetect>();
				if ((Object)(object)component != (Object)null)
				{
					if (!((Object)(object)component.mainScript == (Object)null) && !component.mainScript.isEnemyDead)
					{
						bool flag = ((IHittable)component).Hit(ModConfig.EnemyDamage.Value, dir, playerHeldBy, true, -1);
						if (ModConfig.DebugKeys.Value)
						{
							Plugin.Log.LogInfo((object)$"[shot] hit {component.mainScript.enemyType.enemyName} -> {flag}, hp now {component.mainScript.enemyHP}");
						}
						val3 = ((RaycastHit)(ref val4)).point;
						break;
					}
					continue;
				}
				PlayerControllerB componentInParent = ((Component)((RaycastHit)(ref val4)).collider).GetComponentInParent<PlayerControllerB>();
				if ((Object)(object)componentInParent != (Object)null)
				{
					if (!((Object)(object)componentInParent == (Object)(object)playerHeldBy) && !componentInParent.isPlayerDead && componentInParent.isPlayerControlled && (((Component)((RaycastHit)(ref val4)).collider).gameObject.layer == 3 || !((RaycastHit)(ref val4)).collider.isTrigger))
					{
						b = Net.PlayerIndex(componentInParent);
						val3 = ((RaycastHit)(ref val4)).point;
						break;
					}
				}
				else if (!((RaycastHit)(ref val4)).collider.isTrigger)
				{
					if (((Component)((RaycastHit)(ref val4)).collider).TryGetComponent<IHittable>(ref val5))
					{
						val5.Hit(ModConfig.EnemyDamage.Value, dir, playerHeldBy, true, -1);
					}
					val3 = ((RaycastHit)(ref val4)).point;
					break;
				}
			}
			float num3 = Def.RecoilDeg * ModConfig.Recoil.Value * Random.Range(0.7f, 1.2f);
			CameraUp.Invoke(playerHeldBy) = Mathf.Clamp(CameraUp.Invoke(playerHeldBy) - num3, -85f, 85f);
			if ((noiseTimer -= Def.Cycle) <= 0f)
			{
				noiseTimer = 0.25f;
				RoundManager.Instance.PlayAudibleNoise(((Component)this).transform.position, 40f, 0.9f, 0, base.isInShipRoom && StartOfRound.Instance.hangarDoorsClosed, 0);
			}
			ShotFx(val3);
			UpdateTips();
			Net.Send(new Msg
			{
				Op = Op.Shot,
				Id = ((NetworkBehaviour)this).NetworkObjectId,
				A = rounds,
				B = b,
				V = val3
			});
		}

		private static Vector3 Spread(Vector3 dir, float deg)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_001d: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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_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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = Random.insideUnitCircle * Mathf.Tan(deg * (MathF.PI / 180f));
			Vector3 val2 = Vector3.Cross(Vector3.up, dir);
			Vector3 val3 = ((Vector3)(ref val2)).normalized;
			if (((Vector3)(ref val3)).sqrMagnitude < 0.01f)
			{
				val3 = Vector3.right;
			}
			Vector3 val4 = Vector3.Cross(dir, val3);
			val2 = dir + val3 * val.x + val4 * val.y;
			return ((Vector3)(ref val2)).normalized;
		}

		private void EndBurst()
		{
			firing = false;
			TailFx();
			Net.Send(new Msg
			{
				Op = Op.ShotEnd,
				Id = ((NetworkBehaviour)this).NetworkObjectId
			});
		}

		private int FindAmmoSlot()
		{
			if ((Object)(object)base.playerHeldBy == (Object)null)
			{
				return -1;
			}
			GrabbableObject[] itemSlots = base.playerHeldBy.ItemSlots;
			for (int i = 0; i < itemSlots.Length; i++)
			{
				if (itemSlots[i] is AmmoItem ammoItem && ammoItem.gunKey == gunKey)
				{
					return i;
				}
			}
			if (base.playerHeldBy.ItemOnlySlot is AmmoItem ammoItem2 && ammoItem2.gunKey == gunKey)
			{
				return 50;
			}
			return -1;
		}

		private void TryReload()
		{
			if (reloading || Def == null || rounds >= Def.MagSize)
			{
				return;
			}
			if (FindAmmoSlot() < 0)
			{
				HUDManager.Instance.DisplayTip("No ammo", "You need a " + Def.AmmoName + " (buy one in the store: " + Def.AmmoKeyword + ").", true, false, "LC_Tip1");
			}
			else
			{
				if (firing)
				{
					EndBurst();
				}
				reloadRoutine = ((MonoBehaviour)this).StartCoroutine(Reload());
			}
		}

		private IEnumerator Reload()
		{
			reloading = true;
			triggerHeld = false;
			ReloadFx();
			Net.Send(new Msg
			{
				Op = Op.Reload,
				Id = ((NetworkBehaviour)this).NetworkObjectId
			});
			yield return (object)new WaitForSeconds(Def.MagInAt + 0.08f);
			int num = (HeldByMe ? FindAmmoSlot() : (-1));
			if (num >= 0)
			{
				GrabbableObject val = ((num == 50) ? base.playerHeldBy.ItemOnlySlot : base.playerHeldBy.ItemSlots[num]);
				bool num2 = num == base.playerHeldBy.currentItemSlot;
				base.playerHeldBy.DestroyItemInSlotAndSync(num);
				if (!num2 && (Object)(object)val != (Object)null)
				{
					base.playerHeldBy.carryWeight = Mathf.Clamp(base.playerHeldBy.carryWeight - (val.itemProperties.weight - 1f), 1f, 10f);
				}
				rounds = Def.MagSize;
				Net.Send(new Msg
				{
					Op = Op.Ammo,
					Id = ((NetworkBehaviour)this).NetworkObjectId,
					A = rounds
				});
				UpdateTips();
			}
			yield return (object)new WaitForSeconds(Mathf.Max(0f, Def.ReloadTime - Def.MagInAt - 0.08f));
			reloading = false;
			reloadRoutine = null;
		}

		private void CancelReload()
		{
			if (reloadRoutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(reloadRoutine);
			}
			reloadRoutine = null;
			if (reloading && (Object)(object)anim != (Object)null)
			{
				anim.Stop();
			}
			reloading = false;
			if (fxRoutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(fxRoutine);
			}
		}

		public override void PocketItem()
		{
			CancelReload();
			if (firing && ((NetworkBehaviour)this).IsOwner)
			{
				EndBurst();
			}
			((GrabbableObject)this).PocketItem();
		}

		public override void OnHitGround()
		{
			((GrabbableObject)this).OnHitGround();
			lastDropTime = Time.time;
		}

		public override void DiscardItem()
		{
			CancelReload();
			if (firing && ((NetworkBehaviour)this).IsOwner)
			{
				EndBurst();
			}
			triggerHeld = false;
			((GrabbableObject)this).DiscardItem();
		}

		public override void EquipItem()
		{
			((GrabbableObject)this).EquipItem();
			UpdateTips();
		}

		public override void GrabItem()
		{
			((GrabbableObject)this).GrabItem();
			if (!Net.IsHost)
			{
				Net.Send(new Msg
				{
					Op = Op.AmmoAsk,
					Id = ((NetworkBehaviour)this).NetworkObjectId
				});
			}
		}

		public override void SetControlTipsForItem()
		{
			UpdateTips();
		}

		private void UpdateTips()
		{
			if (HeldByMe && Def != null)
			{
				string[] array = new string[3]
				{
					$"Fire ({rounds}/{Def.MagSize}) : [LMB]",
					"Reload : [R]",
					"Drop : [G]"
				};
				HUDManager.Instance.ChangeControlTipMultiple(array, true, base.itemProperties);
			}
		}

		private void ShotFx(Vector3 end)
		{
			//IL_0050: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)anim != (Object)null)
			{
				anim.Play("Fire", 0.4f / Mathf.Max(0.02f, Def.Cycle), 0f);
			}
			lastShotTime = Time.time;
			StartLoop();
			Fx.Flash(MuzzlePos, Forward, Def.FlashScale);
			Fx.Tracer(MuzzlePos, end);
			if ((Object)(object)port != (Object)null)
			{
				Fx.Casing(port.position, ((Component)anim).transform.TransformDirection(new Vector3(0f, 0.6f, 1f)), Def.Key);
			}
		}

		private void StartLoop()
		{
			if (!looping && !((Object)(object)loopAudio == (Object)null))
			{
				AudioClip loop = Def.Loop;
				if (!((Object)(object)loop == (Object)null))
				{
					looping = true;
					loopAudio.clip = loop;
					loopAudio.pitch = Mathf.Clamp((float)Def.Rpm() / Mathf.Max(1f, Def.LoopRpm), 0.5f, 2f);
					loopAudio.volume = ModConfig.Volume.Value;
					loopAudio.time = 0f;
					loopAudio.Play();
				}
			}
		}

		private void StopLoop()
		{
			looping = false;
		}

		private void TailFx()
		{
			StopLoop();
			AudioClip tail = Def.Tail;
			if ((Object)(object)tail != (Object)null && (Object)(object)tailAudio != (Object)null)
			{
				tailAudio.PlayOneShot(tail, ModConfig.Volume.Value * 0.85f);
			}
		}

		private void DryFire()
		{
			AudioClip val = ModAssets.Sound("dry_fire");
			if ((Object)(object)val != (Object)null && (Object)(object)audio != (Object)null)
			{
				audio.PlayOneShot(val, 0.8f);
			}
		}

		private void ReloadFx()
		{
			if ((Object)(object)anim != (Object)null)
			{
				anim.Play("Reload", 1f, 0.1f);
			}
			if (fxRoutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(fxRoutine);
			}
			fxRoutine = ((MonoBehaviour)this).StartCoroutine(ReloadSounds());
		}

		private IEnumerator ReloadSounds()
		{
			float num = 0f;
			(float, AudioClip)[] array = new(float, AudioClip)[3]
			{
				(Def.MagOutAt, Def.MagOut),
				(Def.MagInAt, Def.MagIn),
				(Def.RackAt, Def.Rack)
			};
			for (int i = 0; i < array.Length; i++)
			{
				var (at, clip) = array[i];
				yield return (object)new WaitForSeconds(at - num);
				num = at;
				if ((Object)(object)clip != (Object)null && (Object)(object)audio != (Object)null)
				{
					audio.PlayOneShot(clip, 1f);
				}
			}
			fxRoutine = null;
		}

		public static void Apply(Msg m)
		{
			//IL_00f5: 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_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			GunItem gunItem = Net.Find<GunItem>(m.Id);
			if ((Object)(object)gunItem == (Object)null || gunItem.Def == null)
			{
				return;
			}
			if (ModConfig.DebugKeys.Value && (m.Op != Op.Shot || Time.time - gunItem.lastShotTime > 0.5f))
			{
				Plugin.Log.LogInfo((object)$"[net] {m.Op} for {gunItem.Def.Name} #{m.Id} (rounds {m.A}, hit player {m.B}, owner here: {((NetworkBehaviour)gunItem).IsOwner})");
			}
			switch (m.Op)
			{
			case Op.Shot:
			{
				gunItem.rounds = m.A;
				if (!((NetworkBehaviour)gunItem).IsOwner)
				{
					gunItem.ShotFx(m.V);
				}
				PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
				if (m.B >= 0 && (Object)(object)localPlayerController != (Object)null && (Object)(object)StartOfRound.Instance.allPlayerScripts[m.B] == (Object)(object)localPlayerController && !localPlayerController.isPlayerDead)
				{
					int value = ModConfig.PlayerDamage.Value;
					Vector3 val = m.V - gunItem.MuzzlePos;
					localPlayerController.DamagePlayer(value, true, true, (CauseOfDeath)7, 0, false, ((Vector3)(ref val)).normalized * 8f);
				}
				break;
			}
			case Op.ShotEnd:
				if (!((NetworkBehaviour)gunItem).IsOwner)
				{
					gunItem.TailFx();
				}
				break;
			case Op.Reload:
				if (!((NetworkBehaviour)gunItem).IsOwner)
				{
					gunItem.ReloadFx();
				}
				break;
			case Op.Ammo:
				gunItem.rounds = m.A;
				gunItem.UpdateTips();
				break;
			case Op.DryFire:
				if (!((NetworkBehaviour)gunItem).IsOwner)
				{
					gunItem.DryFire();
				}
				break;
			case Op.AmmoAsk:
				if (Net.IsHost)
				{
					Net.Send(new Msg
					{
						Op = Op.Ammo,
						Id = ((NetworkBehaviour)gunItem).NetworkObjectId,
						A = gunItem.rounds
					});
				}
				break;
			}
		}

		public void DebugFireAt(Vector3 target, float seconds)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			if (HeldByMe)
			{
				((MonoBehaviour)this).StartCoroutine(DebugBurst(target, seconds));
			}
		}

		private IEnumerator DebugBurst(Vector3 target, float seconds)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			debugAim = target;
			((GrabbableObject)this).ItemActivate(true, true);
			yield return (object)new WaitForSeconds(seconds);
			((GrabbableObject)this).ItemActivate(false, false);
			debugAim = null;
		}

		public void DebugReload()
		{
			TryReload();
		}

		public string DebugState()
		{
			return $"{Def?.Name} rounds {rounds}/{Def?.MagSize} reloading={reloading} firing={firing}";
		}
	}
	public class AmmoItem : GrabbableObject
	{
		public string gunKey;
	}
	public class GunDef
	{
		public string Key;

		public string Name;

		public string AmmoName;

		public string Keyword;

		public string AmmoKeyword;

		public string VanillaHold;

		public int MagSize;

		public int ItemId;

		public float Weight;

		public float AmmoWeight;

		public float SpreadDeg;

		public float RecoilDeg;

		public float FlashScale;

		public float ReloadTime;

		public float MagOutAt;

		public float MagInAt;

		public float RackAt;

		public Func<int> Rpm;

		public Func<int> Price;

		public Func<int> AmmoPrice;

		public string DefaultHoldPos;

		public string DefaultHoldRot;

		public ConfigEntry<string> HoldPos;

		public ConfigEntry<string> HoldRot;

		public ConfigEntry<string> FpOffset;

		public ConfigEntry<string> FpRotation;

		public string DefaultFpRotation = "0,0,0";

		public ConfigEntry<float> FpScale;

		public string DefaultFpOffset = "0,0,0";

		public float DefaultFpScale = 1.3f;

		public Item Item;

		public Item AmmoItem;

		public float LoopRpm;

		public string[] GunWords;

		public string[] AmmoWords;

		public TerminalNode GunAsk;

		public TerminalNode AmmoAsk;

		public float Cycle => 60f / (float)Mathf.Max(60, Rpm());

		public AudioClip Loop => ModAssets.Sound(Key + "_loop");

		public AudioClip Tail => ModAssets.Sound(Key + "_tail");

		public AudioClip MagOut => ModAssets.Sound(Key + "_mag_out");

		public AudioClip MagIn => ModAssets.Sound(Key + "_mag_in");

		public AudioClip Rack => ModAssets.Sound((Key == "glock") ? "glock_rack" : (Key + "_charge"));

		public void BindConfig(ConfigFile cfg)
		{
			HoldPos = cfg.Bind<string>("Holding", Name + "Position", DefaultHoldPos, "Held offset of the " + Name + " (x,y,z).");
			HoldRot = cfg.Bind<string>("Holding", Name + "Rotation", DefaultHoldRot, "Held rotation of the " + Name + " (degrees x,y,z).");
			FpOffset = cfg.Bind<string>("Holding", Name + "FirstPersonOffset", DefaultFpOffset, "Extra shift of the " + Name + " in your own view only (metres: right, up, forward).");
			FpRotation = cfg.Bind<string>("Holding", Name + "FirstPersonAngle", DefaultFpRotation, "Extra tilt of the " + Name + " in your own view only (degrees: pitch, yaw, roll).");
			FpScale = cfg.Bind<float>("Holding", Name + "FirstPersonScale", DefaultFpScale, "Size of the " + Name + " in your own view only (other players always see it at real size).");
		}
	}
	public static class Guns
	{
		public static readonly List<GunDef> All = new List<GunDef>
		{
			new GunDef
			{
				Key = "glock",
				Name = "Glock",
				AmmoName = "Glock Drum",
				Keyword = "glock",
				AmmoKeyword = "glockdrum",
				VanillaHold = "Zap gun",
				LoopRpm = 1182f,
				GunWords = new string[2] { "pistol", "switch" },
				AmmoWords = new string[1] { "drum" },
				MagSize = 50,
				ItemId = 8301,
				Weight = 1.04f,
				AmmoWeight = 1.02f,
				SpreadDeg = 2.2f,
				RecoilDeg = 0.9f,
				FlashScale = 0.8f,
				ReloadTime = 2.4f,
				MagOutAt = 0.15f,
				MagInAt = 1.25f,
				RackAt = 1.55f,
				Rpm = () => ModConfig.GlockRpm.Value,
				Price = () => ModConfig.GlockPrice.Value,
				AmmoPrice = () => ModConfig.GlockAmmoPrice.Value,
				DefaultFpOffset = "0.03,0.015,0.12",
				DefaultFpRotation = "2,-15,-6",
				DefaultFpScale = 1.3f,
				DefaultHoldPos = "0.046,-0.348,-0.177",
				DefaultHoldRot = "0.1,12.2,272.6"
			},
			new GunDef
			{
				Key = "arp",
				Name = "ARP",
				AmmoName = "ARP Dual Drum",
				Keyword = "arp",
				AmmoKeyword = "arpdrum",
				VanillaHold = "Shotgun",
				LoopRpm = 760f,
				GunWords = new string[2] { "ar", "rifle" },
				AmmoWords = new string[2] { "dualdrum", "dual" },
				MagSize = 100,
				ItemId = 8302,
				Weight = 1.09f,
				AmmoWeight = 1.04f,
				SpreadDeg = 1.3f,
				RecoilDeg = 0.7f,
				FlashScale = 1.15f,
				ReloadTime = 3.2f,
				MagOutAt = 0.2f,
				MagInAt = 1.8f,
				RackAt = 2.29f,
				Rpm = () => ModConfig.ArpRpm.Value,
				Price = () => ModConfig.ArpPrice.Value,
				AmmoPrice = () => ModConfig.ArpAmmoPrice.Value,
				DefaultFpOffset = "0.02,0.04,0.16",
				DefaultFpRotation = "0,-7,-4",
				DefaultFpScale = 1.3f,
				DefaultHoldPos = "0.008,0.137,-0.012",
				DefaultHoldRot = "1.7,6.1,270.8"
			},
			new GunDef
			{
				Key = "draco",
				Name = "Draco",
				AmmoName = "Draco Mag",
				Keyword = "draco",
				AmmoKeyword = "dracomag",
				VanillaHold = "Shotgun",
				LoopRpm = 652f,
				GunWords = new string[1] { "ak" },
				AmmoWords = new string[3] { "mag", "akmag", "magazine" },
				MagSize = 30,
				ItemId = 8303,
				Weight = 1.07f,
				AmmoWeight = 1.01f,
				SpreadDeg = 1.6f,
				RecoilDeg = 1.4f,
				FlashScale = 1.3f,
				ReloadTime = 2.8f,
				MagOutAt = 0.2f,
				MagInAt = 1.35f,
				RackAt = 1.9f,
				Rpm = () => ModConfig.DracoRpm.Value,
				Price = () => ModConfig.DracoPrice.Value,
				AmmoPrice = () => ModConfig.DracoAmmoPrice.Value,
				DefaultFpOffset = "0.02,0.04,0.16",
				DefaultFpRotation = "0,-7,-4",
				DefaultFpScale = 1.3f,
				DefaultHoldPos = "0.008,0.138,-0.012",
				DefaultHoldRot = "1.7,6.0,270.8"
			}
		};

		public static readonly List<Item> Items = new List<Item>();

		public static readonly List<GameObject> NetworkPrefabs = new List<GameObject>();

		private static GameObject prefabParent;

		public const int LayerProps = 6;

		public const int LayerScanNode = 22;

		public static AudioMixerGroup SfxGroup;

		private static readonly string[] AmmoIntent = new string[13]
		{
			"drum", "drums", "mag", "mags", "magazine", "magazines", "ammo", "rounds", "clip", "clips",
			"dual", "dualdrum", "akmag"
		};

		public static GunDef ByKey(string key)
		{
			return All.FirstOrDefault((GunDef g) => g.Key == key);
		}

		public static Vector3 ParseV3(string s)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return V3(s);
		}

		public static void Register()
		{
			foreach (GunDef item in All)
			{
				item.Item = MakeItem<GunItem>(item.Name, "VG_" + item.Key, ModAssets.Model(item.Key), item.ItemId, item.Price(), item.Weight, rigged: true);
				item.Item.holdButtonUse = true;
				item.Item.automaticallySetUsingPower = false;
				item.Item.saveItemVariable = true;
				item.Item.isDefensiveWeapon = true;
				item.Item.isConductiveMetal = true;
				item.Item.toolTips = new string[3] { "Fire : [LMB]", "Reload : [R]", "Drop : [G]" };
				item.Item.spawnPrefab.GetComponent<GunItem>().gunKey = item.Key;
				item.AmmoItem = MakeItem<AmmoItem>(item.AmmoName, "VG_" + item.Key + "_ammo", ModAssets.Model(item.Key + "_ammo"), item.ItemId + 10, item.AmmoPrice(), item.AmmoWeight, rigged: false);
				item.AmmoItem.toolTips = new string[2]
				{
					"Ammo for the " + item.Name,
					"Drop : [G]"
				};
				item.AmmoItem.disallowUtilitySlot = true;
				item.AmmoItem.spawnPrefab.GetComponent<AmmoItem>().gunKey = item.Key;
			}
			ApplyHoldOffsets();
		}

		public static void ApplyHoldOffsets()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			foreach (GunDef item in All)
			{
				if (!((Object)(object)item.Item == (Object)null) && item.HoldPos != null)
				{
					item.Item.positionOffset = V3(item.HoldPos.Value);
					item.Item.rotationOffset = V3(item.HoldRot.Value);
				}
			}
		}

		private static Vector3 V3(string s)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			string[] p = (s ?? "").Split(',');
			return new Vector3(F(0), F(1), F(2));
			float F(int i)
			{
				if (p.Length <= i || !float.TryParse(p[i].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
				{
					return 0f;
				}
				return result;
			}
		}

		private static GameObject CreateNetworkPrefab(string name)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//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_0024: Expected O, but got Unknown
			if ((Object)(object)prefabParent == (Object)null)
			{
				prefabParent = new GameObject("VonGunsPrefabs")
				{
					hideFlags = (HideFlags)61
				};
				prefabParent.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)prefabParent);
			}
			GameObject val = new GameObject(name);
			val.transform.SetParent(prefabParent.transform);
			NetworkObject val2 = val.AddComponent<NetworkObject>();
			val2.AutoObjectParentSync = false;
			uint num;
			using (MD5 mD = MD5.Create())
			{
				num = BitConverter.ToUInt32(mD.ComputeHash(Encoding.UTF8.GetBytes("vonguns" + name)), 0);
			}
			typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).SetValue(val2, num);
			NetworkPrefabs.Add(val);
			return val;
		}

		public static void RegisterNetworkPrefabs()
		{
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null)
			{
				return;
			}
			foreach (GameObject networkPrefab in NetworkPrefabs)
			{
				if (!singleton.NetworkConfig.Prefabs.Contains(networkPrefab))
				{
					singleton.AddNetworkPrefab(networkPrefab);
				}
			}
			Plugin.Log.LogInfo((object)$"Registered {NetworkPrefabs.Count} network prefabs");
		}

		public static void AddItemsToGame(StartOfRound sor)
		{
			foreach (Item item in Items)
			{
				if (!sor.allItemsList.itemsList.Contains(item))
				{
					sor.allItemsList.itemsList.Add(item);
				}
			}
		}

		private static Item MakeItem<T>(string displayName, string prefabName, JimModel model, int id, int price, float weight, bool rigged) where T : GrabbableObject
		{
			//IL_00bb: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Expected O, but got Unknown
			//IL_0171: 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_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: 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_0298: Unknown result type (might be due to invalid IL or missing references)
			Item val = ScriptableObject.CreateInstance<Item>();
			((Object)val).name = prefabName + "_Item";
			val.itemName = displayName;
			val.itemId = id;
			val.isScrap = false;
			val.creditsWorth = price;
			val.requiresBattery = false;
			val.minValue = (val.maxValue = 0);
			val.weight = weight;
			val.twoHanded = false;
			val.twoHandedAnimation = false;
			val.canBeGrabbedBeforeGameStart = true;
			val.itemSpawnsOnGround = true;
			val.spawnPositionTypes = new List<ItemGroup>();
			val.highestSalePercentage = 80;
			val.syncGrabFunction = false;
			val.syncUseFunction = false;
			val.allowDroppingAheadOfPlayer = true;
			val.canBeInspected = false;
			val.restingRotation = (Vector3)(rigged ? new Vector3(90f, 0f, 0f) : Vector3.zero);
			val.rotationOffset = Vector3.zero;
			val.positionOffset = Vector3.zero;
			val.meshVariants = (Mesh[])(object)new Mesh[0];
			val.materialVariants = (Material[])(object)new Material[0];
			val.clinkAudios = (AudioClip[])(object)new AudioClip[0];
			val.toolTips = new string[1] { "Drop : [G]" };
			GameObject val2 = CreateNetworkPrefab(prefabName);
			val2.tag = "PhysicsProp";
			val2.layer = 6;
			Rigidbody obj = val2.AddComponent<Rigidbody>();
			obj.isKinematic = true;
			obj.useGravity = false;
			val2.AddComponent<AudioSource>().playOnAwake = false;
			GameObject val3 = new GameObject("Model")
			{
				layer = 6
			};
			val3.transform.SetParent(val2.transform, false);
			Bounds bounds = default(Bounds);
			((Bounds)(ref bounds))..ctor(Vector3.zero, Vector3.one * 0.2f);
			MeshRenderer mainObjectRenderer = null;
			if (model != null)
			{
				bounds = model.Mesh.bounds;
				if (rigged)
				{
					val3.AddComponent<RigAnimator>().Build(model, 6);
				}
				else
				{
					val3.AddComponent<MeshFilter>().sharedMesh = model.Mesh;
					mainObjectRenderer = val3.AddComponent<MeshRenderer>();
					val3.AddComponent<MaterialBinder>().modelName = model.Name;
				}
			}
			BoxCollider obj2 = val2.AddComponent<BoxCollider>();
			obj2.center = ((Bounds)(ref bounds)).center;
			obj2.size = Vector3.Max(((Bounds)(ref bounds)).size, Vector3.one * 0.08f);
			val.verticalOffset = (rigged ? (((Bounds)(ref bounds)).extents.z + 0.02f) : (((Bounds)(ref bounds)).extents.y - ((Bounds)(ref bounds)).center.y + 0.02f));
			T val4 = val2.AddComponent<T>();
			((GrabbableObject)val4).itemProperties = val;
			((GrabbableObject)val4).grabbable = true;
			((GrabbableObject)val4).mainObjectRenderer = mainObjectRenderer;
			((GrabbableObject)val4).grabbableToEnemies = true;
			AddScanNode(val2.transform, displayName, rigged ? "Weapon" : "Ammo", ((Bounds)(ref bounds)).center);
			val.spawnPrefab = val2;
			Items.Add(val);
			return val;
		}

		private static void AddScanNode(Transform parent, string header, string sub, Vector3 at)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("ScanNode")
			{
				layer = 22
			};
			val.transform.SetParent(parent, false);
			val.transform.localPosition = at;
			try
			{
				val.tag = "DoNotSet";
			}
			catch
			{
			}
			BoxCollider obj2 = val.AddComponent<BoxCollider>();
			((Collider)obj2).isTrigger = true;
			obj2.size = Vector3.one * 0.4f;
			Rigidbody obj3 = val.AddComponent<Rigidbody>();
			obj3.isKinematic = true;
			obj3.useGravity = false;
			ScanNodeProperties obj4 = val.AddComponent<ScanNodeProperties>();
			obj4.headerText = header;
			obj4.subText = sub;
			obj4.nodeType = 0;
			obj4.minRange = 1;
			obj4.maxRange = 13;
			obj4.requiresLineOfSight = true;
			obj4.creatureScanID = -1;
		}

		public static void BorrowVanillaBits(StartOfRound sor)
		{
			List<Item> list = sor.allItemsList.itemsList;
			Item val = V("Shotgun");
			if ((Object)(object)val != (Object)null && (Object)(object)val.spawnPrefab != (Object)null)
			{
				ShotgunItem component = val.spawnPrefab.GetComponent<ShotgunItem>();
				if ((Object)(object)component != (Object)null && (Object)(object)component.gunShootAudio != (Object)null)
				{
					SfxGroup = component.gunShootAudio.outputAudioMixerGroup;
				}
			}
			Item val2 = V("Ammo") ?? V("Shotgun shell");
			foreach (GunDef item in All)
			{
				Item val3 = V(item.VanillaHold) ?? val;
				if ((Object)(object)val3 != (Object)null)
				{
					item.Item.grabAnim = val3.grabAnim;
					item.Item.twoHandedAnimation = val3.twoHandedAnimation;
					item.Item.grabSFX = val3.grabSFX ?? val?.grabSFX;
					item.Item.dropSFX = val3.dropSFX;
					item.Item.pocketSFX = val3.pocketSFX;
					item.Item.throwSFX = val3.throwSFX;
					item.Item.itemIcon = ModAssets.Icon(item.Key) ?? (((Object)(object)val != (Object)null) ? val.itemIcon : val3.itemIcon);
				}
				Item val4 = val2 ?? val3;
				if ((Object)(object)val4 != (Object)null)
				{
					item.AmmoItem.grabSFX = val4.grabSFX ?? val3?.grabSFX;
					item.AmmoItem.dropSFX = val4.dropSFX ?? val3?.dropSFX;
					item.AmmoItem.pocketSFX = val4.pocketSFX ?? val3?.pocketSFX;
					item.AmmoItem.itemIcon = ModAssets.Icon(item.Key + "_ammo") ?? val4.itemIcon;
				}
				Plugin.Log.LogInfo((object)$"{item.Name}: hold anim '{item.Item.grabAnim}' from {val3?.itemName}, ammo look from {val4?.itemName}, grab sfx {(Object)(object)item.Item.grabSFX != (Object)null}/{(Object)(object)item.AmmoItem.grabSFX != (Object)null}");
			}
			Item V(string n)
			{
				return ((IEnumerable<Item>)list).FirstOrDefault((Func<Item, bool>)((Item i) => (Object)(object)i != (Object)null && i.itemName == n));
			}
		}

		public static void AddToStore(Terminal t)
		{
			//IL_033e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0344: Expected O, but got Unknown
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_035c: Expected O, but got Unknown
			//IL_049d: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a7: Expected O, but got Unknown
			TerminalKeyword val = ((IEnumerable<TerminalKeyword>)t.terminalNodes.allKeywords).FirstOrDefault((Func<TerminalKeyword, bool>)((TerminalKeyword k) => k.word == "buy"));
			TerminalKeyword val2 = ((IEnumerable<TerminalKeyword>)t.terminalNodes.allKeywords).FirstOrDefault((Func<TerminalKeyword, bool>)((TerminalKeyword k) => k.word == "confirm"));
			TerminalKeyword deny = ((IEnumerable<TerminalKeyword>)t.terminalNodes.allKeywords).FirstOrDefault((Func<TerminalKeyword, bool>)((TerminalKeyword k) => k.word == "deny"));
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || (Object)(object)deny == (Object)null)
			{
				Plugin.Log.LogError((object)"Store keywords not found; guns not added to the store");
				return;
			}
			TerminalNode val3 = ((IEnumerable<CompatibleNoun>)((IEnumerable<CompatibleNoun>)val.compatibleNouns).FirstOrDefault((Func<CompatibleNoun, bool>)((CompatibleNoun c) => (Object)(object)c.result != (Object)null && c.result.buyItemIndex >= 0 && c.result.terminalOptions != null && c.result.terminalOptions.Length >= 2))?.result.terminalOptions).FirstOrDefault((Func<CompatibleNoun, bool>)((CompatibleNoun o) => (Object)(object)o.noun == (Object)(object)deny))?.result;
			List<Item> list = t.buyableItemsList.ToList();
			List<TerminalKeyword> list2 = t.terminalNodes.allKeywords.ToList();
			List<CompatibleNoun> list3 = val.compatibleNouns.ToList();
			foreach (GunDef item4 in All)
			{
				(Item, string, string)[] array = new(Item, string, string)[2]
				{
					(item4.Item, item4.Keyword, item4.Name + "s"),
					(item4.AmmoItem, item4.AmmoKeyword, item4.AmmoName + "s")
				};
				for (int num = 0; num < array.Length; num++)
				{
					(Item, string, string) tuple = array[num];
					Item item = tuple.Item1;
					string item2 = tuple.Item2;
					string item3 = tuple.Item3;
					bool flag = (Object)(object)item == (Object)(object)item4.Item;
					if ((Object)(object)item == (Object)null || list.Contains(item))
					{
						continue;
					}
					item.creditsWorth = (((Object)(object)item == (Object)(object)item4.Item) ? item4.Price() : item4.AmmoPrice());
					list.Add(item);
					int buyItemIndex = list.Count - 1;
					TerminalNode val4 = ScriptableObject.CreateInstance<TerminalNode>();
					((Object)val4).name = "VG_buy_" + item2 + "_done";
					val4.displayText = "Ordered [variableAmount] " + item3 + ". Your new balance is [playerCredits].\n\nOur contractors enjoy fast, free shipping while on the job! Any purchased items will arrive hourly at your approximate location.\n\n";
					val4.clearPreviousText = true;
					val4.maxCharactersToType = 15;
					val4.buyItemIndex = buyItemIndex;
					val4.itemCost = item.creditsWorth;
					val4.playSyncedClip = 0;
					TerminalNode val5 = ScriptableObject.CreateInstance<TerminalNode>();
					((Object)val5).name = "VG_buy_" + item2;
					val5.displayText = "You have requested to order " + item3 + ". Amount: [variableAmount].\nTotal cost of items: [totalCost].\n\nPlease CONFIRM or DENY.\n\n";
					val5.clearPreviousText = true;
					val5.maxCharactersToType = 35;
					val5.buyItemIndex = buyItemIndex;
					val5.itemCost = item.creditsWorth;
					val5.isConfirmationNode = true;
					val5.overrideOptions = true;
					val5.terminalOptions = (CompatibleNoun[])(object)new CompatibleNoun[2]
					{
						new CompatibleNoun(val2, val4),
						new CompatibleNoun(deny, val3 ?? MakeDeny())
					};
					if (flag)
					{
						item4.GunAsk = val5;
					}
					else
					{
						item4.AmmoAsk = val5;
					}
					foreach (string w in new string[1] { item2 }.Concat(flag ? item4.GunWords : item4.AmmoWords))
					{
						TerminalKeyword kw = ((IEnumerable<TerminalKeyword>)list2).FirstOrDefault((Func<TerminalKeyword, bool>)((TerminalKeyword k) => k.word == w));
						if (!((Object)(object)kw != (Object)null) || ((Object)kw).name.StartsWith("VG_"))
						{
							if ((Object)(object)kw == (Object)null)
							{
								kw = ScriptableObject.CreateInstance<TerminalKeyword>();
								((Object)kw).name = "VG_" + w;
								kw.word = w;
								kw.isVerb = false;
								list2.Add(kw);
							}
							kw.defaultVerb = val;
							list3.RemoveAll((CompatibleNoun n) => (Object)(object)n.noun == (Object)(object)kw);
							list3.Add(new CompatibleNoun(kw, val5));
						}
					}
				}
			}
			t.buyableItemsList = list.ToArray();
			t.terminalNodes.allKeywords = list2.ToArray();
			val.compatibleNouns = list3.ToArray();
			Plugin.Log.LogInfo((object)$"Added the guns to the store ({t.buyableItemsList.Length} store items)");
		}

		public static TerminalNode MatchOrder(Terminal t)
		{
			if ((Object)(object)t.currentNode != (Object)null && t.currentNode.overrideOptions)
			{
				return null;
			}
			string text = t.screenText.text;
			int num = Mathf.Clamp(t.textAdded, 0, text.Length);
			StringBuilder stringBuilder = new StringBuilder();
			string text2 = text.Substring(text.Length - num).ToLowerInvariant();
			foreach (char c in text2)
			{
				stringBuilder.Append(char.IsPunctuation(c) ? ' ' : c);
			}
			List<string> list = stringBuilder.ToString().Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries).ToList();
			if (list.Count < 2 || list.Contains("info"))
			{
				return null;
			}
			int num2 = 1;
			string text3 = list.FirstOrDefault((string source) => source.All(char.IsDigit));
			if (text3 != null && int.TryParse(text3, out var result))
			{
				num2 = Mathf.Clamp(result, 0, 10);
			}
			list.RemoveAll(delegate(string text4)
			{
				switch (text4)
				{
				default:
					return text4.All(char.IsDigit);
				case "buy":
				case "order":
				case "purchase":
					return true;
				}
			});
			if (list.Count == 0)
			{
				return null;
			}
			GunDef gunDef = null;
			foreach (string w in list)
			{
				gunDef = All.FirstOrDefault((GunDef g) => w == g.Keyword || g.GunWords.Contains(w) || (w.Length >= 3 && g.Keyword.StartsWith(w)));
				if (gunDef != null)
				{
					break;
				}
			}
			if (!list.Any((string text4) => AmmoIntent.Contains(text4) || All.Any((GunDef g) => g.AmmoKeyword == text4 || g.AmmoWords.Contains(text4))))
			{
				return null;
			}
			if (gunDef == null)
			{
				if (list.Contains("dual") || list.Contains("dualdrum"))
				{
					gunDef = ByKey("arp");
				}
				else if (list.Any((string text4) => text4.StartsWith("mag") || text4 == "akmag"))
				{
					gunDef = ByKey("draco");
				}
				else if (list.Any((string text4) => text4.StartsWith("drum")))
				{
					gunDef = ByKey("glock");
				}
			}
			if ((Object)(object)gunDef?.AmmoAsk == (Object)null)
			{
				return null;
			}
			t.playerDefinedAmount = num2;
			Plugin.Log.LogInfo((object)string.Format("Store: '{0}' -> {1} x {2}", string.Join(" ", list), num2, gunDef.AmmoName));
			return gunDef.AmmoAsk;
		}

		private static TerminalNode MakeDeny()
		{
			TerminalNode obj = ScriptableObject.CreateInstance<TerminalNode>();
			obj.displayText = "Cancelled order.\n\n";
			obj.clearPreviousText = true;
			return obj;
		}
	}
	public class JimModel
	{
		public class Bone
		{
			public string Name;

			public int Parent;

			public Vector3 LocalPosition;

			public Quaternion LocalRotation;
		}

		public class Clip
		{
			public string Name;

			public float Fps;

			public int Frames;

			public bool Loop;

			public Vector3[] Positions;

			public Quaternion[] Rotations;

			public float Length
			{
				get
				{
					if (Frames <= 1)
					{
						return 0f;
					}
					return (float)(Frames - 1) / Fps;
				}
			}
		}

		public class Submesh
		{
			public bool Emissive;

			public Color Colour;

			public float EmissionStrength;
		}

		public string Name;

		public Mesh Mesh;

		public Texture2D Albedo;

		public List<Submesh> Submeshes = new List<Submesh>();

		public List<Bone> Bones = new List<Bone>();

		public Matrix4x4[] BindPoses;

		public Dictionary<string, Clip> Clips = new Dictionary<string, Clip>();

		public bool Skinned => Bones.Count > 0;

		public static JimModel Load(string path, string name)
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: 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_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)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: 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_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c8: Expected O, but got Unknown
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_0381: Unknown result type (might be due to invalid IL or missing references)
			//IL_0386: Unknown result type (might be due to invalid IL or missing references)
			JimModel jimModel = new JimModel
			{
				Name = name
			};
			using BinaryReader binaryReader = new BinaryReader(File.OpenRead(path));
			if (Encoding.ASCII.GetString(binaryReader.ReadBytes(4)) != "JIM1")
			{
				throw new InvalidDataException(path + " is not a JIM1 file");
			}
			int num = binaryReader.ReadInt32();
			Vector3[] array = (Vector3[])(object)new Vector3[num];
			Vector3[] array2 = (Vector3[])(object)new Vector3[num];
			Vector2[] array3 = (Vector2[])(object)new Vector2[num];
			for (int i = 0; i < num; i++)
			{
				array[i] = ReadV3(binaryReader);
			}
			for (int j = 0; j < num; j++)
			{
				array2[j] = ReadV3(binaryReader);
			}
			for (int k = 0; k < num; k++)
			{
				array3[k] = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
			}
			BoneWeight[] array4 = null;
			if (binaryReader.ReadInt32() == 1)
			{
				array4 = (BoneWeight[])(object)new BoneWeight[num];
				for (int l = 0; l < num; l++)
				{
					int boneIndex = binaryReader.ReadInt32();
					int boneIndex2 = binaryReader.ReadInt32();
					int boneIndex3 = binaryReader.ReadInt32();
					int boneIndex4 = binaryReader.ReadInt32();
					BoneWeight[] array5 = array4;
					int num2 = l;
					BoneWeight val = default(BoneWeight);
					((BoneWeight)(ref val)).boneIndex0 = boneIndex;
					((BoneWeight)(ref val)).boneIndex1 = boneIndex2;
					((BoneWeight)(ref val)).boneIndex2 = boneIndex3;
					((BoneWeight)(ref val)).boneIndex3 = boneIndex4;
					((BoneWeight)(ref val)).weight0 = binaryReader.ReadSingle();
					((BoneWeight)(ref val)).weight1 = binaryReader.ReadSingle();
					((BoneWeight)(ref val)).weight2 = binaryReader.ReadSingle();
					((BoneWeight)(ref val)).weight3 = binaryReader.ReadSingle();
					array5[num2] = val;
				}
			}
			int num3 = binaryReader.ReadInt32();
			List<int[]> list = new List<int[]>();
			for (int m = 0; m < num3; m++)
			{
				Submesh submesh = new Submesh
				{
					Emissive = (binaryReader.ReadInt32() == 1)
				};
				submesh.Colour = new Color(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
				submesh.EmissionStrength = binaryReader.ReadSingle();
				int num4 = binaryReader.ReadInt32();
				int[] array6 = new int[num4];
				for (int n = 0; n < num4; n++)
				{
					array6[n] = binaryReader.ReadInt32();
				}
				jimModel.Submeshes.Add(submesh);
				list.Add(array6);
			}
			int num5 = binaryReader.ReadInt32();
			jimModel.BindPoses = (Matrix4x4[])(object)new Matrix4x4[num5];
			for (int num6 = 0; num6 < num5; num6++)
			{
				Bone item = new Bone
				{
					Name = ReadStr(binaryReader),
					Parent = binaryReader.ReadInt32(),
					LocalPosition = ReadV3(binaryReader),
					LocalRotation = ReadQ(binaryReader)
				};
				Matrix4x4 val2 = default(Matrix4x4);
				for (int num7 = 0; num7 < 4; num7++)
				{
					for (int num8 = 0; num8 < 4; num8++)
					{
						((Matrix4x4)(ref val2))[num7, num8] = binaryReader.ReadSingle();
					}
				}
				jimModel.BindPoses[num6] = val2;
				jimModel.Bones.Add(item);
			}
			int num9 = binaryReader.ReadInt32();
			for (int num10 = 0; num10 < num9; num10++)
			{
				Clip clip = new Clip
				{
					Name = ReadStr(binaryReader),
					Fps = binaryReader.ReadSingle(),
					Frames = binaryReader.ReadInt32(),
					Loop = (binaryReader.ReadInt32() == 1)
				};
				int num11 = clip.Frames * num5;
				clip.Positions = (Vector3[])(object)new Vector3[num11];
				clip.Rotations = (Quaternion[])(object)new Quaternion[num11];
				for (int num12 = 0; num12 < num11; num12++)
				{
					clip.Positions[num12] = ReadV3(binaryReader);
					clip.Rotations[num12] = ReadQ(binaryReader);
				}
				jimModel.Clips[clip.Name] = clip;
			}
			Mesh val3 = new Mesh
			{
				name = name
			};
			if (num > 65000)
			{
				val3.indexFormat = (IndexFormat)1;
			}
			val3.vertices = array;
			val3.normals = array2;
			val3.uv = array3;
			if (array4 != null)
			{
				val3.boneWeights = array4;
				val3.bindposes = jimModel.BindPoses;
			}
			val3.subMeshCount = num3;
			for (int num13 = 0; num13 < num3; num13++)
			{
				val3.SetTriangles(list[num13], num13);
			}
			val3.RecalculateBounds();
			val3.RecalculateTangents();
			jimModel.Mesh = val3;
			return jimModel;
		}

		private static Vector3 ReadV3(BinaryReader r)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
		}

		private static Quaternion ReadQ(BinaryReader r)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			return new Quaternion(r.ReadSingle(), r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
		}

		private static string ReadStr(BinaryReader r)
		{
			int count = r.ReadInt32();
			return Encoding.UTF8.GetString(r.ReadBytes(count));
		}
	}
	public static class ModAssets
	{
		public static readonly Dictionary<string, JimModel> Models = new Dictionary<string, JimModel>();

		public static readonly Dictionary<string, AudioClip> Sounds = new Dictionary<string, AudioClip>();

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

		private static readonly Dictionary<string, Material[]> materialCache = new Dictionary<string, Material[]>();

		private static string dir;

		private static int pending;

		private static Material emissive;

		private static Material brass;

		public static Sprite Icon(string name)
		{
			if (!Icons.TryGetValue(name, out var value))
			{
				return null;
			}
			return value;
		}

		public static void Load(string assetDir)
		{
			//IL_008a: 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_00a8: Expected O, but got Unknown
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			dir = assetDir;
			string[] array = new string[6] { "glock", "arp", "draco", "glock_ammo", "arp_ammo", "draco_ammo" };
			for (int i = 0; i < array.Length; i++)
			{
				LoadModel(array[i]);
			}
			string path = Path.Combine(dir, "icons");
			if (Directory.Exists(path))
			{
				array = Directory.GetFiles(path, "*.png");
				foreach (string path2 in array)
				{
					Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false)
					{
						name = "VG_icon_" + Path.GetFileNameWithoutExtension(path2)
					};
					ImageConversion.LoadImage(val, File.ReadAllBytes(path2));
					((Texture)val).wrapMode = (TextureWrapMode)1;
					Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
					((Object)val2).name = ((Object)val).name;
					Icons[Path.GetFileNameWithoutExtension(path2)] = val2;
				}
			}
			string text = Path.Combine(dir, "sounds");
			if (!Directory.Exists(text))
			{
				Plugin.Log.LogError((object)("Missing sounds folder " + text));
				return;
			}
			array = Directory.GetFiles(text, "*.wav");
			foreach (string path3 in array)
			{
				pending++;
				Runner.Run(LoadAudio(path3));
			}
		}

		public static AudioClip Sound(string name)
		{
			if (!Sounds.TryGetValue(name, out var value))
			{
				return null;
			}
			return value;
		}

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

		private static void LoadModel(string name)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			try
			{
				JimModel jimModel = JimModel.Load(Path.Combine(dir, name + ".jim"), name);
				string path = Path.Combine(dir, name + "_albedo.png");
				if (File.Exists(path))
				{
					Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true)
					{
						name = name + "_albedo"
					};
					ImageConversion.LoadImage(val, File.ReadAllBytes(path));
					((Texture)val).wrapMode = (TextureWrapMode)1;
					((Texture)val).anisoLevel = 4;
					jimModel.Albedo = val;
				}
				Models[name] = jimModel;
				Plugin.Log.LogInfo((object)$"Loaded model {name}: {jimModel.Mesh.vertexCount} verts, {jimModel.Bones.Count} bones, {jimModel.Clips.Count} clips");
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Failed to load model {name}: {arg}");
			}
		}

		private static IEnumerator LoadAudio(string path)
		{
			UnityWebRequest req = UnityWebRequestMultimedia.GetAudioClip(new Uri(path).AbsoluteUri, (AudioType)20);
			try
			{
				((DownloadHandlerAudioClip)req.downloadHandler).streamAudio = false;
				yield return req.SendWebRequest();
				if ((int)req.result != 1)
				{
					Plugin.Log.LogError((object)("Could not load " + Path.GetFileName(path) + ": " + req.error));
				}
				else
				{
					AudioClip content = DownloadHandlerAudioClip.GetContent(req);
					((Object)content).name = Path.GetFileNameWithoutExtension(path);
					Sounds[((Object)content).name] = content;
				}
			}
			finally
			{
				((IDisposable)req)?.Dispose();
			}
			if (--pending == 0)
			{
				Plugin.Log.LogInfo((object)$"vonguns ready: {Models.Count} models, {Sounds.Count} sounds, {Icons.Count} icons");
			}
		}

		public static Material[] MaterialsFor(JimModel model, float smoothness)
		{
			//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_0086: Expected O, but got Unknown
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			if (model == null)
			{
				return (Material[])(object)new Material[0];
			}
			if (materialCache.TryGetValue(model.Name, out var value) && value.Length != 0 && (Object)(object)value[0] != (Object)null)
			{
				return value;
			}
			Shader val = Shader.Find("HDRP/Lit");
			if ((Object)(object)val == (Object)null)
			{
				return (Material[])(object)new Material[0];
			}
			Material[] array = (Material[])(object)new Material[model.Submeshes.Count];
			for (int i = 0; i < array.Length; i++)
			{
				Material val2 = new Material(val)
				{
					name = $"{model.Name}_{i}"
				};
				if ((Object)(object)model.Albedo != (Object)null)
				{
					val2.SetTexture("_BaseColorMap", (Texture)(object)model.Albedo);
					val2.SetColor("_BaseColor", Color.white);
				}
				else
				{
					val2.SetColor("_BaseColor", model.Submeshes[i].Colour);
				}
				val2.SetFloat("_Smoothness", smoothness);
				val2.SetFloat("_Metallic", 0.15f);
				try
				{
					HDMaterial.ValidateMaterial(val2);
				}
				catch
				{
				}
				array[i] = val2;
			}
			materialCache[model.Name] = array;
			return array;
		}

		public static Material Emissive()
		{
			//IL_001d: 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_0032: Expected O, but got Unknown
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)emissive != (Object)null)
			{
				return emissive;
			}
			emissive = new Material(Shader.Find("HDRP/Unlit"))
			{
				name = "VG_Flash"
			};
			Color val = default(Color);
			((Color)(ref val))..ctor(1f, 0.62f, 0.25f);
			emissive.SetColor("_UnlitColor", val);
			emissive.SetColor("_EmissiveColor", ((Color)(ref val)).linear * 60f);
			try
			{
				HDMaterial.ValidateMaterial(emissive);
			}
			catch
			{
			}
			return emissive;
		}

		public static Material Brass()
		{
			//IL_001d: 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_0032: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)brass != (Object)null)
			{
				return brass;
			}
			brass = new Material(Shader.Find("HDRP/Lit"))
			{
				name = "VG_Brass"
			};
			brass.SetColor("_BaseColor", new Color(0.78f, 0.58f, 0.22f));
			brass.SetFloat("_Metallic", 1f);
			brass.SetFloat("_Smoothness", 0.7f);
			try
			{
				HDMaterial.ValidateMaterial(brass);
			}
			catch
			{
			}
			return brass;
		}
	}
	public class MaterialBinder : MonoBehaviour
	{
		public string modelName;

		public float smoothness = 0.35f;

		private void Awake()
		{
			Material[] array = ModAssets.MaterialsFor(ModAssets.Model(modelName), smoothness);
			Renderer component = ((Component)this).GetComponent<Renderer>();
			if ((Object)(object)component != (Object)null && array.Length != 0)
			{
				component.sharedMaterials = array;
			}
		}
	}
	public static class ModConfig
	{
		public static ConfigEntry<int> GlockPrice;

		public static ConfigEntry<int> GlockAmmoPrice;

		public static ConfigEntry<int> ArpPrice;

		public static ConfigEntry<int> ArpAmmoPrice;

		public static ConfigEntry<int> DracoPrice;

		public static ConfigEntry<int> DracoAmmoPrice;

		public static ConfigEntry<int> GlockRpm;

		public static ConfigEntry<int> ArpRpm;

		public static ConfigEntry<int> DracoRpm;

		public static ConfigEntry<int> EnemyDamage;

		public static ConfigEntry<int> PlayerDamage;

		public static ConfigEntry<float> Range;

		public static ConfigEntry<float> Volume;

		public static ConfigEntry<float> Recoil;

		public static ConfigEntry<bool> DebugKeys;

		public static ConfigEntry<string> HoldTarget;

		private static ConfigFile file;

		public static void Bind(ConfigFile cfg)
		{
			file = cfg;
			GlockPrice = cfg.Bind<int>("Store", "GlockPrice", 250, "Price of the Glock.");
			GlockAmmoPrice = cfg.Bind<int>("Store", "GlockDrumPrice", 40, "Price of a 50 rd Glock drum.");
			ArpPrice = cfg.Bind<int>("Store", "ArpPrice", 550, "Price of the ARP.");
			ArpAmmoPrice = cfg.Bind<int>("Store", "ArpDrumPrice", 60, "Price of a 100 rd ARP dual drum.");
			DracoPrice = cfg.Bind<int>("Store", "DracoPrice", 400, "Price of the Draco.");
			DracoAmmoPrice = cfg.Bind<int>("Store", "DracoMagPrice", 40, "Price of a 30 rd Draco mag.");
			GlockRpm = cfg.Bind<int>("Guns", "GlockFireRate", 1180, "Glock (switch) rounds per minute. 1180 matches its recording; other values pitch the sound.");
			ArpRpm = cfg.Bind<int>("Guns", "ArpFireRate", 760, "ARP rounds per minute. 760 matches its recording (M16).");
			DracoRpm = cfg.Bind<int>("Guns", "DracoFireRate", 650, "Draco rounds per minute. 650 matches its recording (AK).");
			EnemyDamage = cfg.Bind<int>("Guns", "EnemyDamagePerBullet", 1, "Damage each bullet does to monsters (a shovel hit is 1).");
			PlayerDamage = cfg.Bind<int>("Guns", "PlayerDamagePerBullet", 20, "Friendly fire damage per bullet (players have 100 health).");
			Range = cfg.Bind<float>("Guns", "Range", 120f, "How far bullets go, in metres.");
			Recoil = cfg.Bind<float>("Guns", "RecoilScale", 1f, "Camera kick multiplier (0 = no recoil).");
			Volume = cfg.Bind<float>("Guns", "Volume", 1f, "Gunshot volume (0-1).");
			DebugKeys = cfg.Bind<bool>("Debug", "EnableDebugHotkeys", false, "Testing keys while hosting: F6 spawn all guns + ammo, F7 spawn a monster ahead, F1 auto-fire at the nearest monster, F8 log, F9 land, F10 enter/leave the facility, Page Down open the terminal, F2 reload this config.");
			HoldTarget = cfg.Bind<string>("Debug", "HoldTarget", "0.14,-0.17,0.20", "Testing (F12): where the held gun goes, camera space right,up,forward.");
			foreach (GunDef item in Guns.All)
			{
				item.BindConfig(cfg);
			}
		}

		public static void Reload()
		{
			ConfigFile obj = file;
			if (obj != null)
			{
				obj.Reload();
			}
			Guns.ApplyHoldOffsets();
		}
	}
	public enum Op : byte
	{
		Shot = 1,
		ShotEnd,
		Reload,
		Ammo,
		DryFire,
		AmmoAsk
	}
	public struct Msg
	{
		public Op Op;

		public ulong Id;

		public int A;

		public int B;

		public Vector3 V;
	}
	public static class Net
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static HandleNamedMessageDelegate <0>__Receive;
		}

		private const string Channel = "vonguns.v1";

		private static NetworkManager NM => NetworkManager.Singleton;

		public static bool IsHost
		{
			get
			{
				if ((Object)(object)NM != (Object)null)
				{
					return NM.IsServer;
				}
				return false;
			}
		}

		public static void Register()
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			if (!((Object)(object)NM == (Object)null) && NM.CustomMessagingManager != null)
			{
				NM.CustomMessagingManager.UnregisterNamedMessageHandler("vonguns.v1");
				CustomMessagingManager customMessagingManager = NM.CustomMessagingManager;
				object obj = <>O.<0>__Receive;
				if (obj == null)
				{
					HandleNamedMessageDelegate val = Receive;
					<>O.<0>__Receive = val;
					obj = (object)val;
				}
				customMessagingManager.RegisterNamedMessageHandler("vonguns.v1", (HandleNamedMessageDelegate)obj);
			}
		}

		public static void Send(Msg m)
		{
			NetworkManager nM = NM;
			if ((Object)(object)nM == (Object)null || !nM.IsListening)
			{
				return;
			}
			if (nM.IsServer)
			{
				SendTo(m, nM.ConnectedClientsIds.Where((ulong id) => id != 0));
			}
			else
			{
				SendTo(m, new ulong[1]);
			}
		}

		private unsafe static void SendTo(Msg m, IEnumerable<ulong> ids)
		{
			//IL_0028: 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_003f: 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_0056: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			List<ulong> list = ids.ToList();
			if (list.Count == 0)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(48, (Allocator)2, -1);
			try
			{
				byte op = (byte)m.Op;
				((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref op, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref m.Id, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref m.A, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref m.B, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe(ref m.V);
				if (list.Count == 1)
				{
					NM.CustomMessagingManager.SendNamedMessage("vonguns.v1", list[0], val, (NetworkDelivery)3);
				}
				else
				{
					NM.CustomMessagingManager.SendNamedMessage("vonguns.v1", (IReadOnlyList<ulong>)list, val, (NetworkDelivery)3);
				}
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private static void Receive(ulong sender, FastBufferReader r)
		{
			//IL_001b: 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_003a: 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_0051: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Msg m = default(Msg);
				byte op = default(byte);
				((FastBufferReader)(ref r)).ReadValueSafe<byte>(ref op, default(ForPrimitives));
				m.Op = (Op)op;
				((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref m.Id, default(ForPrimitives));
				((FastBufferReader)(ref r)).ReadValueSafe<int>(ref m.A, default(ForPrimitives));
				((FastBufferReader)(ref r)).ReadValueSafe<int>(ref m.B, default(ForPrimitives));
				((FastBufferReader)(ref r)).ReadValueSafe(ref m.V);
				if (IsHost && sender != 0L)
				{
					SendTo(m, NM.ConnectedClientsIds.Where((ulong id) => id != sender && id != 0));
				}
				GunItem.Apply(m);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("vonguns network message failed: " + ex));
			}
		}

		public static T Find<T>(ulong id) where T : Component
		{
			if ((Object)(object)NM == (Object)null || NM.SpawnManager == null)
			{
				return default(T);
			}
			if (!NM.SpawnManager.SpawnedObjects.TryGetValue(id, out var value) || !((Object)(object)value != (Object)null))
			{
				return default(T);
			}
			return ((Component)value).GetComponent<T>();
		}

		public static int PlayerIndex(PlayerControllerB p)
		{
			if (!((Object)(object)p == (Object)null))
			{
				return Array.IndexOf(StartOfRound.Instance.allPlayerScripts, p);
			}
			return -1;
		}
	}
	[HarmonyPatch]
	internal static class Patches
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameNetworkManager), "Start")]
		private static void GameNetworkManagerStart()
		{
			Guns.RegisterNetworkPrefabs();
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		private static void StartOfRoundAwake(StartOfRound __instance)
		{
			Guns.AddItemsToGame(__instance);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "Start")]
		private static void StartOfRoundStart(StartOfRound __instance)
		{
			Net.Register();
			Guns.BorrowVanillaBits(__instance);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Terminal), "ParsePlayerSentence")]
		private static bool ParsePlayerSentence(Terminal __instance, ref TerminalNode __result)
		{
			TerminalNode val = null;
			try
			{
				val = Guns.MatchOrder(__instance);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("store order parse: " + ex));
			}
			if ((Object)(object)val == (Object)null)
			{
				return true;
			}
			__result = val;
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(GrabbableObject), "UseItemOnClient")]
		private static void UseItemOnClient(GrabbableObject __instance, bool buttonDown)
		{
			if (ModConfig.DebugKeys.Value && __instance is GunItem)
			{
				Plugin.Log.LogInfo((object)($"[use] #{((NetworkBehaviour)__instance).NetworkObjectId} down {buttonDown} owner {((NetworkBehaviour)__instance).IsOwner} cooldown {__instance.useCooldown}/{__instance.currentUseCooldown} " + $"beingUsed {__instance.isBeingUsed} battery {__instance.itemProperties.requiresBattery}/{__instance.insertedBattery?.empty} " + $"ownerId {((NetworkBehaviour)__instance).OwnerClientId} local {NetworkManager.Singleton.LocalClientId}"));
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Terminal), "Awake")]
		private static void TerminalAwake(Terminal __instance)
		{
			Guns.AddToStore(__instance);
		}
	}
	[BepInPlugin("TheGoonburgers.vonguns", "vonguns", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "TheGoonburgers.vonguns";

		public const string Name = "vonguns";

		public const string Version = "1.0.0";

		public static Plugin Instance { get; private set; }

		public static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			ModConfig.Bind(((BaseUnityPlugin)this).Config);
			Runner.Create();
			ModAssets.Load(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "assets"));
			Guns.Register();
			new Harmony("TheGoonburgers.vonguns").PatchAll(typeof(Plugin).Assembly);
			Log.LogInfo((object)"vonguns 1.0.0 loaded: Glock, ARP, Draco");
		}
	}
	public class RigAnimator : MonoBehaviour
	{
		public string modelName;

		public Transform[] bones;

		public SkinnedMeshRenderer smr;

		private JimModel model;

		private JimModel.Clip idle;

		private JimModel.Clip oneShot;

		private float oneShotTime;

		private float oneShotSpeed = 1f;

		private Vector3[] fromPos;

		private Quaternion[] fromRot;

		private float blend = 1f;

		private float blendTime = 0.12f;

		public void Build(JimModel m, int layer)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Expected O, but got Unknown
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: 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_0099: Unknown result type (might be due to invalid IL or missing references)
			modelName = m.Name;
			Transform transform = new GameObject("Armature").transform;
			transform.SetParent(((Component)this).transform, false);
			bones = (Transform[])(object)new Transform[m.Bones.Count];
			for (int i = 0; i < bones.Length; i++)
			{
				JimModel.Bone bone = m.Bones[i];
				Transform transform2 = new GameObject(bone.Name).transform;
				transform2.SetParent((bone.Parent >= 0) ? bones[bone.Parent] : transform, false);
				transform2.localPosition = bone.LocalPosition;
				transform2.localRotation = bone.LocalRotation;
				bones[i] = transform2;
			}
			GameObject val = new GameObject("GunMesh")
			{
				layer = layer
			};
			val.transform.SetParent(((Component)this).transform, false);
			smr = val.AddComponent<SkinnedMeshRenderer>();
			smr.sharedMesh = m.Mesh;
			smr.bones = bones;
			smr.rootBone = transform;
			smr.updateWhenOffscreen = true;
			Bounds bounds = m.Mesh.bounds;
			((Renderer)smr).localBounds = new Bounds(((Bounds)(ref bounds)).center, ((Bounds)(ref bounds)).size + Vector3.one * 0.4f);
			val.AddComponent<MaterialBinder>().modelName = m.Name;
		}

		public Transform Bone(string name)
		{
			if (bones == null)
			{
				return null;
			}
			Transform[] array = bones;
			foreach (Transform val in array)
			{
				if ((Object)(object)val != (Object)null && ((Object)val).name == name)
				{
					return val;
				}
			}
			return null;
		}

		private void Awake()
		{
			model = ModAssets.Model(modelName);
			if (bones != null)
			{
				fromPos = (Vector3[])(object)new Vector3[bones.Length];
				fromRot = (Quaternion[])(object)new Quaternion[bones.Length];
			}
			if (model != null)
			{
				model.Clips.TryGetValue("Idle", out idle);
			}
		}

		public void Play(string clip, float speed = 1f, float blendSeconds = 0.12f)
		{
			if (model != null && model.Clips.TryGetValue(clip, out var value))
			{
				if (blendSeconds > 0f)
				{
					CapturePose();
				}
				else
				{
					blend = 1f;
				}
				blendTime = Mathf.Max(0.001f, blendSeconds);
				oneShot = value;
				oneShotTime = 0f;
				oneShotSpeed = speed;
			}
		}

		public void Stop()
		{
			CapturePose();
			oneShot = null;
		}

		private void CapturePose()
		{
			//IL_0024: 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_003d: 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)
			if (bones != null && fromPos != null)
			{
				for (int i = 0; i < bones.Length; i++)
				{
					fromPos[i] = bones[i].localPosition;
					fromRot[i] = bones[i].localRotation;
				}
				blend = 0f;
			}
		}

		private void LateUpdate()
		{
			if (bones == null || model == null)
			{
				return;
			}
			if (oneShot != null)
			{
				oneShotTime += Time.deltaTime * oneShotSpeed;
				if (oneShotTime >= oneShot.Length)
				{
					oneShot = null;
					if (idle != null)
					{
						Sample(idle, 0f);
					}
				}
				else
				{
					Sample(oneShot, oneShotTime);
				}
			}
			else if (idle != null && blend < 1f)
			{
				Sample(idle, 0f);
			}
		}

		private void Sample(JimModel.Clip clip, float time)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			int num = bones.Length;
			float num2 = Mathf.Clamp(time * clip.Fps, 0f, (float)(clip.Frames - 1));
			int num3 = Mathf.FloorToInt(num2);
			int num4 = Mathf.Min(num3 + 1, clip.Frames - 1);
			float num5 = num2 - (float)num3;
			blend = Mathf.Min(1f, blend + Time.deltaTime / blendTime);
			for (int i = 0; i < num; i++)
			{
				Vector3 val = Vector3.Lerp(clip.Positions[num3 * num + i], clip.Positions[num4 * num + i], num5);
				Quaternion val2 = Quaternion.Slerp(clip.Rotations[num3 * num + i], clip.Rotations[num4 * num + i], num5);
				if (blend < 1f && fromPos != null)
				{
					val = Vector3.Lerp(fromPos[i], val, blend);
					val2 = Quaternion.Slerp(fromRot[i], val2, blend);
				}
				bones[i].localPosition = val;
				bones[i].localRotation = val2;
			}