Decompiled source of M2Browning v1.0.0

M2Browning\M2Browning.dll

Decompiled 27 minutes 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.Events;
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 M2Browning
{
	public static class BigGame
	{
		private static readonly Dictionary<ulong, int> hits = new Dictionary<ulong, int>();

		public static bool IsGiant(EnemyAI ai)
		{
			return ai is ForestGiantAI;
		}

		public static bool IsOldBird(EnemyAI ai)
		{
			return ai is RadMechAI;
		}

		public static bool IsBig(EnemyAI ai)
		{
			if (!IsGiant(ai))
			{
				return IsOldBird(ai);
			}
			return true;
		}

		public static void Reset()
		{
			hits.Clear();
		}

		public static void AllowGiantDeaths(StartOfRound sor)
		{
			SelectableLevel[] levels = sor.levels;
			foreach (SelectableLevel val in levels)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				List<SpawnableEnemyWithRarity>[] array = new List<SpawnableEnemyWithRarity>[3] { val.Enemies, val.OutsideEnemies, val.DaytimeEnemies };
				foreach (List<SpawnableEnemyWithRarity> list in array)
				{
					if (list == null)
					{
						continue;
					}
					foreach (SpawnableEnemyWithRarity item in list)
					{
						EnemyType val2 = item?.enemyType;
						if (!((Object)(object)val2?.enemyPrefab == (Object)null) && (Object)(object)val2.enemyPrefab.GetComponent<ForestGiantAI>() != (Object)null && !val2.canDie)
						{
							val2.canDie = true;
							Plugin.Log.LogInfo((object)(val2.enemyName + ": can now die (to the M2)"));
						}
					}
				}
			}
		}

		public static EnemyType FindType<T>(StartOfRound sor) where T : EnemyAI
		{
			SelectableLevel[] levels = sor.levels;
			foreach (SelectableLevel val in levels)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				List<SpawnableEnemyWithRarity>[] array = new List<SpawnableEnemyWithRarity>[3] { val.Enemies, val.OutsideEnemies, val.DaytimeEnemies };
				foreach (List<SpawnableEnemyWithRarity> list in array)
				{
					if (list == null)
					{
						continue;
					}
					foreach (SpawnableEnemyWithRarity item in list)
					{
						if ((Object)(object)item?.enemyType?.enemyPrefab != (Object)null && (Object)(object)item.enemyType.enemyPrefab.GetComponent<T>() != (Object)null)
						{
							return item.enemyType;
						}
					}
				}
			}
			return null;
		}

		public static void HostOnBigHit(ulong enemyId, int bullets)
		{
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			EnemyAI val = Net.Find<EnemyAI>(enemyId);
			if ((Object)(object)val == (Object)null || val.isEnemyDead || !IsBig(val))
			{
				return;
			}
			hits.TryGetValue(enemyId, out var value);
			value += Mathf.Max(1, bullets);
			hits[enemyId] = value;
			int num = (IsOldBird(val) ? ModConfig.OldBirdBullets.Value : ModConfig.GiantBullets.Value);
			if (value % 10 == 0 || value >= num)
			{
				Plugin.Log.LogInfo((object)$"{val.enemyType.enemyName} hit by the M2: {value}/{num}");
			}
			if (value >= num)
			{
				hits.Remove(enemyId);
				Plugin.Log.LogInfo((object)$"M2 killed {val.enemyType.enemyName} with {value} bullets");
				if (IsOldBird(val))
				{
					FastBufferWriter w = Net.Begin(Op.Boom);
					Vector3 val2 = ((Component)val).transform.position + Vector3.up * 2.5f;
					((FastBufferWriter)(ref w)).WriteValueSafe(ref val2);
					Net.SendToAll(w, ulong.MaxValue);
					Runner.Run(DespawnSoon(val));
				}
				else
				{
					val.enemyType.canDie = true;
					val.KillEnemyServerRpc(false);
				}
			}
		}

		private static IEnumerator DespawnSoon(EnemyAI ai)
		{
			yield return (object)new WaitForSeconds(0.12f);
			if (!((Object)(object)ai == (Object)null))
			{
				try
				{
					ai.KillEnemyServerRpc(true);
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("Old Bird kill RPC failed: " + ex.Message));
				}
				yield return null;
				if ((Object)(object)ai != (Object)null && (Object)(object)((NetworkBehaviour)ai).NetworkObject != (Object)null && ((NetworkBehaviour)ai).NetworkObject.IsSpawned)
				{
					((NetworkBehaviour)ai).NetworkObject.Despawn(true);
				}
			}
		}

		public static void OnBoom(Vector3 pos)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Landmine.SpawnExplosion(pos, true, 3f, 8f, 40, 20f, (GameObject)null, false);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Explosion failed: " + ex.Message));
			}
		}
	}
	public static class Content
	{
		public const string UpgradeName = "M2 Browning";

		public const int AmmoItemId = 7201;

		public const int LayerProps = 6;

		public const int LayerInteractable = 9;

		public const int LayerScanNode = 22;

		public static Item AmmoItem;

		public static GameObject TurretPrefab;

		public static UnlockableItem Unlockable;

		public static int UnlockableIndex = -1;

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

		private static GameObject prefabParent;

		public static void Register()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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_005c: 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_0073: Expected O, but got Unknown
			AmmoItem = MakeAmmoItem();
			TurretPrefab = M2Turret.BuildPrefab(CreateNetworkPrefab("M2Browning_Turret"));
			Unlockable = new UnlockableItem
			{
				unlockableName = "M2 Browning",
				prefabObject = TurretPrefab,
				unlockableType = 1,
				alwaysInStock = true,
				IsPlaceable = false,
				canBeStored = false,
				maxNumber = 1,
				spawnPrefab = true,
				luckValue = 0f
			};
		}

		public 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("M2BrowningPrefabs")
				{
					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("M2Browning" + name)), 0);
			}
			typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).SetValue(val2, num);
			NetworkPrefabList.Add(val);
			return val;
		}

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

		public static void AddToGame(StartOfRound sor)
		{
			if (!sor.allItemsList.itemsList.Contains(AmmoItem))
			{
				sor.allItemsList.itemsList.Add(AmmoItem);
			}
			List<UnlockableItem> unlockables = sor.unlockablesList.unlockables;
			UnlockableIndex = unlockables.FindIndex((UnlockableItem u) => u != null && u.unlockableName == "M2 Browning");
			if (UnlockableIndex < 0)
			{
				unlockables.Add(Unlockable);
				UnlockableIndex = unlockables.Count - 1;
			}
			else
			{
				unlockables[UnlockableIndex].prefabObject = TurretPrefab;
			}
			Plugin.Log.LogInfo((object)$"M2 upgrade is unlockable #{UnlockableIndex}");
		}

		public static void AddToStore(Terminal t)
		{
			if (!t.buyableItemsList.Contains(AmmoItem))
			{
				t.buyableItemsList = t.buyableItemsList.Concat((IEnumerable<Item>)(object)new Item[1] { AmmoItem }).ToArray();
			}
		}

		public static void SetupTerminal(Terminal t)
		{
			//IL_0375: Unknown result type (might be due to invalid IL or missing references)
			//IL_037b: Expected O, but got Unknown
			//IL_038b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0391: Expected O, but got Unknown
			//IL_0401: Unknown result type (might be due to invalid IL or missing references)
			//IL_0407: Expected O, but got Unknown
			//IL_0417: Unknown result type (might be due to invalid IL or missing references)
			//IL_041d: Expected O, but got Unknown
			//IL_0494: Unknown result type (might be due to invalid IL or missing references)
			//IL_049e: Expected O, but got Unknown
			//IL_04bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c5: Expected O, but got Unknown
			TerminalKeyword[] allKeywords = t.terminalNodes.allKeywords;
			TerminalKeyword buy = ((IEnumerable<TerminalKeyword>)allKeywords).FirstOrDefault((Func<TerminalKeyword, bool>)((TerminalKeyword k) => k.word == "buy"));
			TerminalKeyword confirm = ((IEnumerable<TerminalKeyword>)allKeywords).FirstOrDefault((Func<TerminalKeyword, bool>)((TerminalKeyword k) => k.word == "confirm"));
			TerminalKeyword val = ((IEnumerable<TerminalKeyword>)allKeywords).FirstOrDefault((Func<TerminalKeyword, bool>)((TerminalKeyword k) => k.word == "deny"));
			if ((Object)(object)buy == (Object)null || (Object)(object)confirm == (Object)null || (Object)(object)val == (Object)null)
			{
				Plugin.Log.LogError((object)"Terminal keywords buy/confirm/deny not found; the M2 can't be bought");
				return;
			}
			int num = Array.IndexOf(t.buyableItemsList, AmmoItem);
			int unlockableIndex = UnlockableIndex;
			CompatibleNoun val2 = ((IEnumerable<CompatibleNoun>)buy.compatibleNouns).FirstOrDefault((Func<CompatibleNoun, bool>)((CompatibleNoun n) => (Object)(object)n.result != (Object)null && n.result.buyItemIndex >= 0 && n.result.isConfirmationNode && (Object)(object)Confirm(n.result, confirm) != (Object)null));
			CompatibleNoun val3 = ((IEnumerable<CompatibleNoun>)buy.compatibleNouns).FirstOrDefault((Func<CompatibleNoun, bool>)((CompatibleNoun n) => (Object)(object)n.result != (Object)null && n.result.shipUnlockableID >= 0 && (Object)(object)Confirm(n.result, confirm) != (Object)null && StartOfRound.Instance.unlockablesList.unlockables[n.result.shipUnlockableID].unlockableType == 1));
			if (val2 == null || val3 == null)
			{
				Plugin.Log.LogError((object)$"No vanilla purchase nodes to copy (item {val2 != null}, upgrade {val3 != null}); the M2 can't be bought. Buy nouns:");
				{
					foreach (CompatibleNoun item in buy.compatibleNouns.Take(60))
					{
						TerminalNode result = item.result;
						string text = ((result?.terminalOptions == null) ? "-" : string.Join("/", result.terminalOptions.Select((CompatibleNoun o) => (o.noun?.word ?? "null") + (((Object)(object)o.noun == (Object)(object)confirm) ? "*" : ""))));
						Plugin.Log.LogError((object)$"  {item.noun?.word} -> {((result != null) ? ((Object)result).name : null)} item={result?.buyItemIndex} unlock={result?.shipUnlockableID} confirmNode={result?.isConfirmationNode} opts={text}");
					}
					return;
				}
			}
			int value = ModConfig.UpgradePrice.Value;
			Plugin.Log.LogInfo((object)("Copying purchase nodes from '" + val2.noun.word + "' and '" + val3.noun.word + "'"));
			TerminalNode val4 = Clone(val3.result, "M2Browning_BuyUpgrade");
			val4.shipUnlockableID = unlockableIndex;
			val4.itemCost = value;
			val4.displayText = "You have requested to order the M2 Browning .50 cal for the roof of the ship.\nTotal cost of item: [totalCost].\n\nPlease CONFIRM or DENY.\n\n";
			TerminalNode val5 = Clone(Confirm(val3.result, confirm), "M2Browning_ConfirmUpgrade");
			val5.shipUnlockableID = unlockableIndex;
			val5.itemCost = value;
			val5.buyUnlockable = true;
			val5.displayText = "Ordered the M2 Browning! Your new balance is [playerCredits].\n\nIt's mounted on the roof above the door. Stand at the door, look up at it and press [E].\nBuy ammo cans with AMMO and load them at the same spot.\n\n";
			val4.terminalOptions = (CompatibleNoun[])(object)new CompatibleNoun[2]
			{
				new CompatibleNoun(confirm, val5),
				new CompatibleNoun(val, Deny(val3.result, val))
			};
			TerminalNode val6 = Clone(val2.result, "M2Browning_BuyAmmo");
			val6.buyItemIndex = num;
			val6.displayText = "You have requested to order M2 ammo cans (100 rounds of .50 BMG each). Amount: [variableAmount].\nTotal cost of items: [totalCost].\n\nPlease CONFIRM or DENY.\n\n";
			TerminalNode val7 = Clone(Confirm(val2.result, confirm), "M2Browning_ConfirmAmmo");
			val7.buyItemIndex = num;
			val7.displayText = "Ordered [variableAmount] M2 ammo cans. 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";
			val6.terminalOptions = (CompatibleNoun[])(object)new CompatibleNoun[2]
			{
				new CompatibleNoun(confirm, val7),
				new CompatibleNoun(val, Deny(val2.result, val))
			};
			List<TerminalKeyword> kwList = allKeywords.ToList();
			List<CompatibleNoun> list = new List<CompatibleNoun>(buy.compatibleNouns.Where((CompatibleNoun n) => (Object)(object)n.noun == (Object)null || !((Object)n.noun).name.StartsWith("M2Browning_")));
			string[] array = new string[2] { "m2", "browning" };
			foreach (string word in array)
			{
				list.Add(new CompatibleNoun(Noun(word), val4));
			}
			list.Add(new CompatibleNoun(Noun("ammo"), val6));
			buy.compatibleNouns = list.ToArray();
			t.terminalNodes.allKeywords = kwList.ToArray();
			AddStoreLine(t, value);
			Plugin.Log.LogInfo((object)$"Terminal ready: 'm2' = upgrade #{unlockableIndex} (${value}), 'ammo' = store item #{num} (${AmmoItem.creditsWorth})");
			TerminalKeyword Noun(string text2)
			{
				TerminalKeyword val8 = ((IEnumerable<TerminalKeyword>)kwList).FirstOrDefault((Func<TerminalKeyword, bool>)((TerminalKeyword x) => x.word == text2));
				if ((Object)(object)val8 == (Object)null)
				{
					val8 = ScriptableObject.CreateInstance<TerminalKeyword>();
					((Object)val8).name = "M2Browning_" + text2;
					val8.word = text2;
					kwList.Add(val8);
				}
				val8.isVerb = false;
				val8.defaultVerb = buy;
				val8.compatibleNouns = (CompatibleNoun[])(object)new CompatibleNoun[0];
				return val8;
			}
		}

		private static TerminalNode Confirm(TerminalNode n, TerminalKeyword confirm)
		{
			return n.terminalOptions?.FirstOrDefault((Func<CompatibleNoun, bool>)((CompatibleNoun o) => (Object)(object)o.noun == (Object)(object)confirm))?.result;
		}

		private static TerminalNode Deny(TerminalNode n, TerminalKeyword deny)
		{
			return n.terminalOptions?.FirstOrDefault((Func<CompatibleNoun, bool>)((CompatibleNoun o) => (Object)(object)o.noun == (Object)(object)deny))?.result;
		}

		private static TerminalNode Clone(TerminalNode n, string name)
		{
			TerminalNode obj = Object.Instantiate<TerminalNode>(n);
			((Object)obj).name = name;
			return obj;
		}

		private static void AddStoreLine(Terminal t, int price)
		{
			string item = $"* M2 Browning .50 Cal  //  Price: ${price}";
			foreach (TerminalNode item2 in (from n in t.terminalNodes.allKeywords.Select((TerminalKeyword k) => k.specialKeywordResult).Concat(t.terminalNodes.allKeywords.Where((TerminalKeyword k) => k.compatibleNouns != null).SelectMany((TerminalKeyword k) => k.compatibleNouns.Select((CompatibleNoun n) => n.result)))
				where (Object)(object)n != (Object)null && n.displayText != null && n.displayText.Contains("[buyableItemsList]")
				select n).Distinct().ToList())
			{
				List<string> list = (from l in item2.displayText.Split('\n')
					where !l.Contains("M2 Browning")
					select l).ToList();
				int num = list.FindLastIndex((string l) => l.Contains("Teleporter") || l.Contains("Signal Translator") || l.Contains("Loud horn"));
				if (num < 0)
				{
					num = list.FindIndex((string l) => l.Contains("[buyableItemsList]"));
				}
				if (num < 0)
				{
					list.Add(item);
				}
				else
				{
					list.Insert(num + 1, item);
				}
				item2.displayText = string.Join("\n", list);
				Plugin.Log.LogInfo((object)("Store page updated (" + ((Object)item2).name + ")"));
			}
		}

		private static Item MakeAmmoItem()
		{
			//IL_00d3: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Expected O, but got Unknown
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: 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_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			Item val = ScriptableObject.CreateInstance<Item>();
			((Object)val).name = "M2Browning_AmmoCan_Item";
			val.itemName = "M2 ammo can";
			val.itemId = 7201;
			val.isScrap = false;
			val.creditsWorth = ModConfig.AmmoPrice.Value;
			val.requiresBattery = false;
			val.minValue = 0;
			val.maxValue = 0;
			val.weight = 1.22f;
			val.twoHanded = false;
			val.twoHandedAnimation = false;
			val.grabAnim = null;
			val.toolTips = new string[1] { "Load into the M2 at the ship door : [E]" };
			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.isConductiveMetal = true;
			val.disallowUtilitySlot = true;
			val.restingRotation = Vector3.zero;
			val.rotationOffset = new Vector3(-90f, 0f, -90f);
			val.positionOffset = new Vector3(0f, 0.04f, 0f);
			val.meshVariants = (Mesh[])(object)new Mesh[0];
			val.materialVariants = (Material[])(object)new Material[0];
			val.clinkAudios = (AudioClip[])(object)new AudioClip[0];
			GameObject val2 = CreateNetworkPrefab("M2Browning_AmmoCan");
			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("Mesh")
			{
				layer = 6
			};
			val3.transform.SetParent(val2.transform, false);
			MeshFilter val4 = val3.AddComponent<MeshFilter>();
			MeshRenderer mainObjectRenderer = val3.AddComponent<MeshRenderer>();
			Bounds bounds = default(Bounds);
			((Bounds)(ref bounds))..ctor(Vector3.zero, Vector3.one * 0.3f);
			if (ModAssets.AmmoCan != null)
			{
				val4.sharedMesh = ModAssets.AmmoCan.Mesh;
				bounds = ModAssets.AmmoCan.Mesh.bounds;
				val3.AddComponent<MaterialBinder>().modelName = ModAssets.AmmoCan.Name;
			}
			BoxCollider obj2 = val2.AddComponent<BoxCollider>();
			obj2.center = ((Bounds)(ref bounds)).center;
			obj2.size = Vector3.Max(((Bounds)(ref bounds)).size, Vector3.one * 0.15f);
			val.verticalOffset = ((Bounds)(ref bounds)).extents.y - ((Bounds)(ref bounds)).center.y + 0.02f;
			AmmoCanItem ammoCanItem = val2.AddComponent<AmmoCanItem>();
			((GrabbableObject)ammoCanItem).itemProperties = val;
			((GrabbableObject)ammoCanItem).grabbable = true;
			((GrabbableObject)ammoCanItem).mainObjectRenderer = mainObjectRenderer;
			((GrabbableObject)ammoCanItem).grabbableToEnemies = true;
			AddScanNode(val2.transform, "M2 ammo can", "100 rounds .50 BMG", 0, 0, Mathf.Max(((Bounds)(ref bounds)).extents.y, 0.3f));
			val.spawnPrefab = val2;
			return val;
		}

		public static ScanNodeProperties AddScanNode(Transform parent, string header, string sub, int type, int value, float height)
		{
			//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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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)
			GameObject val = new GameObject("ScanNode")
			{
				layer = 22
			};
			val.transform.SetParent(parent, false);
			val.transform.localPosition = Vector3.up * height * 0.5f;
			try
			{
				val.tag = "DoNotSet";
			}
			catch
			{
			}
			BoxCollider obj2 = val.AddComponent<BoxCollider>();
			((Collider)obj2).isTrigger = true;
			obj2.size = Vector3.one * 0.6f;
			Rigidbody obj3 = val.AddComponent<Rigidbody>();
			obj3.isKinematic = true;
			obj3.useGravity = false;
			ScanNodeProperties obj4 = val.AddComponent<ScanNodeProperties>();
			obj4.headerText = header;
			obj4.subText = sub;
			obj4.nodeType = type;
			obj4.scrapValue = value;
			obj4.minRange = 1;
			obj4.maxRange = 20;
			obj4.requiresLineOfSight = true;
			obj4.creatureScanID = -1;
			return obj4;
		}

		public static void BorrowVanillaItemBits(StartOfRound sor)
		{
			List<Item> source = sor.allItemsList.itemsList.Where((Item i) => (Object)(object)i != (Object)null && (Object)(object)i != (Object)(object)AmmoItem).ToList();
			Item val = ((IEnumerable<Item>)source).FirstOrDefault((Func<Item, bool>)((Item i) => i.itemName == "Ammo" && (Object)(object)i.itemIcon != (Object)null)) ?? ((IEnumerable<Item>)source).FirstOrDefault((Func<Item, bool>)((Item i) => !i.isScrap && (Object)(object)i.itemIcon != (Object)null && i.itemName == "Boombox")) ?? ((IEnumerable<Item>)source).FirstOrDefault((Func<Item, bool>)((Item i) => !i.isScrap && (Object)(object)i.itemIcon != (Object)null));
			if (!((Object)(object)val == (Object)null))
			{
				if ((Object)(object)AmmoItem.itemIcon == (Object)null)
				{
					AmmoItem.itemIcon = val.itemIcon;
				}
				Item val2 = ((IEnumerable<Item>)source).FirstOrDefault((Func<Item, bool>)((Item i) => i.itemName == "Toolbox" && (Object)(object)i.dropSFX != (Object)null)) ?? val;
				if ((Object)(object)AmmoItem.grabSFX == (Object)null)
				{
					AmmoItem.grabSFX = val2.grabSFX;
				}
				if ((Object)(object)AmmoItem.dropSFX == (Object)null)
				{
					AmmoItem.dropSFX = val2.dropSFX;
				}
				if ((Object)(object)AmmoItem.pocketSFX == (Object)null)
				{
					AmmoItem.pocketSFX = val2.pocketSFX;
				}
				if ((Object)(object)AmmoItem.throwSFX == (Object)null)
				{
					AmmoItem.throwSFX = val2.throwSFX;
				}
			}
		}
	}
	public class AmmoCanItem : PhysicsProp
	{
	}
	public static class DebugKeys
	{
		private static IEnumerator RestoreNest(EnemyType type, bool value)
		{
			yield return (object)new WaitForSeconds(2f);
			type.requireNestObjectsToSpawn = value;
		}

		public static void Tick()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_006f: 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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: 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_01e7: 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_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: 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_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: 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_0279: Unknown result type (might be due to invalid IL or missing references)
			if (!ModConfig.DebugKeys.Value)
			{
				return;
			}
			Keyboard current = Keyboard.current;
			if (current == null)
			{
				return;
			}
			StartOfRound instance = StartOfRound.Instance;
			PlayerControllerB local = Net.Local;
			if ((Object)(object)local == (Object)null)
			{
				return;
			}
			LocalKeys(current, instance, local);
			if (!Net.IsHost)
			{
				return;
			}
			if (((ButtonControl)current.numpad1Key).wasPressedThisFrame)
			{
				Vector3 val = ((Component)local).transform.position + ((Component)local).transform.forward * 1.2f + Vector3.up * 0.5f;
				GameObject obj = Object.Instantiate<GameObject>(Content.AmmoItem.spawnPrefab, val, Quaternion.identity, instance.propsContainer);
				obj.GetComponent<GrabbableObject>().fallTime = 0f;
				obj.GetComponent<NetworkObject>().Spawn(false);
				Plugin.Log.LogInfo((object)"[debug] spawned an ammo can");
			}
			if (((ButtonControl)current.numpad2Key).wasPressedThisFrame)
			{
				Terminal val2 = Object.FindObjectOfType<Terminal>();
				if ((Object)(object)val2 != (Object)null)
				{
					val2.groupCredits += 1000;
					val2.SyncGroupCreditsServerRpc(val2.groupCredits, val2.numberOfItemsInDropship);
					Plugin.Log.LogInfo((object)$"[debug] credits now {val2.groupCredits}");
				}
			}
			if ((((ButtonControl)current.numpad3Key).wasPressedThisFrame || ((ButtonControl)current.numpad4Key).wasPressedThisFrame) && instance.shipHasLanded)
			{
				bool wasPressedThisFrame = ((ButtonControl)current.numpad4Key).wasPressedThisFrame;
				EnemyType val3 = (wasPressedThisFrame ? BigGame.FindType<RadMechAI>(instance) : BigGame.FindType<ForestGiantAI>(instance));
				M2Turret instance2 = M2Turret.Instance;
				Vector3 val4 = (((Object)(object)instance2 != (Object)null) ? ((Component)instance2).transform.position : ((Component)local).transform.position);
				Vector3 val5 = (((Object)(object)instance2 != (Object)null) ? ((Component)instance2).transform.forward : ((Component)local).transform.forward);
				Vector3 navMeshPosition = RoundManager.Instance.GetNavMeshPosition(val4 + val5 * (wasPressedThisFrame ? 40f : 30f), default(NavMeshHit), 15f, -1);
				if ((Object)(object)val3 == (Object)null)
				{
					Plugin.Log.LogWarning((object)"[debug] enemy type not found");
				}
				else
				{
					bool requireNestObjectsToSpawn = val3.requireNestObjectsToSpawn;
					val3.requireNestObjectsToSpawn = false;
					RoundManager instance3 = RoundManager.Instance;
					Quaternion val6 = Quaternion.LookRotation(-val5);
					instance3.SpawnEnemyGameObject(navMeshPosition, ((Quaternion)(ref val6)).eulerAngles.y, -1, val3);
					Runner.Run(RestoreNest(val3, requireNestObjectsToSpawn));
					Plugin.Log.LogInfo((object)$"[debug] spawned {val3.enemyName} at {navMeshPosition}");
				}
			}
			if (((ButtonControl)current.numpad5Key).wasPressedThisFrame && instance.inShipPhase)
			{
				Plugin.Log.LogInfo((object)"[debug] landing the ship");
				instance.StartGameServerRpc();
			}
			if (((ButtonControl)current.numpad0Key).wasPressedThisFrame && instance.shipHasLanded && !instance.shipIsLeaving)
			{
				Plugin.Log.LogInfo((object)"[debug] making the ship take off");
				instance.ShipLeaveAutomatically(false);
			}
		}

		private static void LocalKeys(Keyboard kb, StartOfRound sor, PlayerControllerB me)
		{
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: 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_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			if (((ButtonControl)kb.numpad6Key).wasPressedThisFrame)
			{
				M2Turret instance = M2Turret.Instance;
				IEnumerable<string> values = from e in Object.FindObjectsOfType<EnemyAI>()
					where BigGame.IsBig(e)
					select $"{e.enemyType.enemyName}#{((NetworkBehaviour)e).NetworkObjectId} dead={e.isEnemyDead} canDie={e.enemyType.canDie} hp={e.enemyHP}";
				ManualLogSource log = Plugin.Log;
				string[] obj = new string[8]
				{
					"[debug] M2 ",
					((Object)(object)instance == (Object)null) ? "not spawned" : $"gunner={instance.gunner} ammo={instance.ammo} heat={instance.heat:F2} overheated={instance.overheated} at {((Component)instance).transform.position}",
					"; ",
					$"me {((Component)me).transform.position} eye {((Component)me.gameplayCamera).transform.position.y - ((Component)me).transform.position.y:F2} hp={me.health}; ",
					"audio ",
					null,
					null,
					null
				};
				object obj2;
				if (!((Object)(object)instance != (Object)null) || !((Object)(object)instance.fireAudio != (Object)null))
				{
					obj2 = "-";
				}
				else
				{
					string text = instance.fireAudio.isPlaying.ToString();
					AudioClip clip = instance.fireAudio.clip;
					obj2 = text + "/" + ((clip != null) ? ((Object)clip).name : null);
				}
				obj[5] = (string)obj2;
				obj[6] = "; big enemies: ";
				obj[7] = string.Join(", ", values);
				log.LogInfo((object)string.Concat(obj));
			}
			if (((ButtonControl)kb.numpad8Key).wasPressedThisFrame && !me.inTerminalMenu)
			{
				Terminal val = Object.FindObjectOfType<Terminal>();
				InteractTrigger val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<InteractTrigger>() : null);
				if ((Object)(object)val2 != (Object)null)
				{
					val2.Interact(me.thisPlayerBody);
				}
				Plugin.Log.LogInfo((object)"[debug] opening the terminal");
			}
			if (((ButtonControl)kb.numpad9Key).wasPressedThisFrame && (Object)(object)M2Turret.Instance != (Object)null)
			{
				M2Turret.Instance.debugTrack = !M2Turret.Instance.debugTrack;
				Plugin.Log.LogInfo((object)$"[debug] tracking the nearest Keeper/Old Bird: {M2Turret.Instance.debugTrack}");
			}
			if (((ButtonControl)kb.numpad7Key).wasPressedThisFrame && (Object)(object)M2Turret.Instance != (Object)null)
			{
				Transform manSpot = M2Turret.Instance.manSpot;
				Vector3 val3 = manSpot.position - manSpot.forward * 1f - Vector3.up * 1f;
				Quaternion val4 = Quaternion.LookRotation(manSpot.forward);
				me.TeleportPlayer(val3, true, ((Quaternion)(ref val4)).eulerAngles.y, false, true);
				Plugin.Log.LogInfo((object)"[debug] teleported to the M2 spot");
			}
		}
	}
	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 enum StateReason : byte
	{
		Sync,
		Mounted,
		Dismounted,
		Loaded,
		Ammo
	}
	public class M2Turret : MonoBehaviour
	{
		public const int HitId = 50050;

		public const float PivotHeight = 1.55f;

		private const float EyeAboveBore = 0.3f;

		public static readonly Vector3 MuzzleLocal = new Vector3(0f, 0.06f, 1.52f);

		private const float MinPitch = -35f;

		private const float MaxPitch = 65f;

		private const string SaveKey = "M2Browning_Ammo";

		public Transform yawPart;

		public Transform pitchPart;

		public Transform muzzle;

		public Transform manSpot;

		public MeshRenderer barrelRenderer;

		public AudioSource fireAudio;

		public AudioSource sfxAudio;

		public Light flashLight;

		public MeshRenderer flashRenderer;

		public InteractTrigger trigger;

		public int gunner = -1;

		public int ammo;

		public float heat;

		public bool overheated;

		private bool firingVisual;

		private float curYaw;

		private float curPitch;

		private float targetYaw;

		private float targetPitch;

		private bool localGunning;

		private bool localFiring;

		private float mountedAt;

		private float shotTimer;

		private float sendTimer;

		private float aimTimer;

		private float hudTimer;

		private float noiseTimer;

		private float shakeTimer;

		private float visualShotTimer;

		private int pendingShots;

		private int shotCount;

		private float lastSentYaw = 999f;

		private float lastSentPitch = 999f;

		private float feetDrop;

		private InputAction fireAction;

		private InputAction interactAction;

		private int hostAmmo;

		private float hostSyncTimer;

		private Material barrelMat;

		private static Material tracerMat;

		private readonly List<LineRenderer> tracers = new List<LineRenderer>();

		private int tracerNext;

		private BoxCollider spotBox;

		private static readonly RaycastHit[] hitBuffer = (RaycastHit[])(object)new RaycastHit[48];

		private string lastHitName = "";

		public bool debugTrack;

		public static M2Turret Instance { get; private set; }

		public static bool IsLocalGunner(PlayerControllerB p)
		{
			if ((Object)(object)Instance != (Object)null && Instance.localGunning && (Object)(object)p != (Object)null)
			{
				return (Object)(object)p == (Object)(object)Net.Local;
			}
			return false;
		}

		public static GameObject BuildPrefab(GameObject root)
		{
			//IL_0017: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: 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_00d3: 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_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Expected O, but got Unknown
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_0320: Expected O, but got Unknown
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Expected O, but got Unknown
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Expected O, but got Unknown
			//IL_0337: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Expected O, but got Unknown
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			//IL_034c: Expected O, but got Unknown
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Expected O, but got Unknown
			M2Turret m2Turret = root.AddComponent<M2Turret>();
			Mesh(root.transform, "Mount", ModAssets.Mount, Vector3.zero, unique: false);
			m2Turret.yawPart = new GameObject("Yaw").transform;
			m2Turret.yawPart.SetParent(root.transform, false);
			m2Turret.yawPart.localPosition = new Vector3(0f, 1.55f, 0f);
			m2Turret.pitchPart = new GameObject("Pitch").transform;
			m2Turret.pitchPart.SetParent(m2Turret.yawPart, false);
			Mesh(m2Turret.pitchPart, "Gun", ModAssets.Gun, Vector3.zero, unique: false);
			m2Turret.barrelRenderer = Mesh(m2Turret.pitchPart, "Barrel", ModAssets.Barrel, Vector3.zero, unique: true);
			m2Turret.muzzle = new GameObject("Muzzle").transform;
			m2Turret.muzzle.SetParent(m2Turret.pitchPart, false);
			m2Turret.muzzle.localPosition = MuzzleLocal;
			m2Turret.flashLight = ((Component)m2Turret.muzzle).gameObject.AddComponent<Light>();
			m2Turret.flashLight.type = (LightType)2;
			m2Turret.flashLight.color = new Color(1f, 0.72f, 0.35f);
			m2Turret.flashLight.range = 9f;
			m2Turret.flashLight.intensity = 0f;
			((Behaviour)m2Turret.flashLight).enabled = false;
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)0);
			Object.DestroyImmediate((Object)(object)val.GetComponent<Collider>());
			((Object)val).name = "Flash";
			val.transform.SetParent(m2Turret.muzzle, false);
			val.transform.localPosition = new Vector3(0f, 0f, 0.12f);
			val.transform.localScale = new Vector3(0.16f, 0.16f, 0.34f);
			m2Turret.flashRenderer = val.GetComponent<MeshRenderer>();
			((Renderer)m2Turret.flashRenderer).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)m2Turret.flashRenderer).enabled = false;
			m2Turret.fireAudio = ((Component)m2Turret.muzzle).gameObject.AddComponent<AudioSource>();
			Setup3D(m2Turret.fireAudio, 4f, 160f);
			m2Turret.sfxAudio = ((Component)m2Turret.yawPart).gameObject.AddComponent<AudioSource>();
			Setup3D(m2Turret.sfxAudio, 2f, 30f);
			GameObject val2 = new GameObject("ManSpot")
			{
				layer = 9
			};
			try
			{
				val2.tag = "InteractTrigger";
			}
			catch
			{
			}
			val2.transform.SetParent(root.transform, false);
			BoxCollider obj2 = val2.AddComponent<BoxCollider>();
			((Collider)obj2).isTrigger = true;
			obj2.size = new Vector3(2.6f, 1.8f, 1.4f);
			m2Turret.manSpot = val2.transform;
			InteractTrigger val3 = val2.AddComponent<InteractTrigger>();
			val3.hoverTip = "Man the M2 : [E]";
			val3.disabledHoverTip = "M2 in use";
			val3.interactable = true;
			val3.oneHandedItemAllowed = true;
			val3.twoHandedItemAllowed = true;
			val3.interactCooldown = true;
			val3.cooldownTime = 0.6f;
			val3.timeToHold = 0.5f;
			val3.disableTriggerMesh = true;
			val3.onInteract = new InteractEvent();
			val3.onInteractEarly = new InteractEvent();
			val3.onInteractEarlyOtherClients = new InteractEvent();
			val3.onStopInteract = new InteractEvent();
			val3.onCancelAnimation = new InteractEvent();
			val3.holdingInteractEvent = new InteractEventFloat();
			m2Turret.trigger = val3;
			Content.AddScanNode(m2Turret.yawPart, "M2 Browning", "Man it at the ship door", 0, 0, 0.6f);
			return root;
		}

		private static MeshRenderer Mesh(Transform parent, string name, JimModel model, Vector3 pos, bool unique)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.transform.localPosition = pos;
			MeshFilter val2 = val.AddComponent<MeshFilter>();
			MeshRenderer result = val.AddComponent<MeshRenderer>();
			if (model != null)
			{
				val2.sharedMesh = model.Mesh;
				MaterialBinder materialBinder = val.AddComponent<MaterialBinder>();
				materialBinder.modelName = model.Name;
				materialBinder.unique = unique;
			}
			return result;
		}

		private static void Setup3D(AudioSource s, float min, float max)
		{
			s.playOnAwake = false;
			s.spatialBlend = 1f;
			s.rolloffMode = (AudioRolloffMode)1;
			s.minDistance = min;
			s.maxDistance = max;
			s.dopplerLevel = 0f;
		}

		private void Awake()
		{
			NetworkObject component = ((Component)this).GetComponent<NetworkObject>();
			Instance = this;
			Plugin.Log.LogInfo((object)$"M2 object created (host {Net.IsHost}, spawned {(Object)(object)component != (Object)null && component.IsSpawned})");
		}

		private void Start()
		{
			//IL_0087: 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_00c6: Expected O, but got Unknown
			Instance = this;
			try
			{
				Place();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Could not place the M2: " + ex));
			}
			barrelMat = (((Object)(object)barrelRenderer != (Object)null && ((Renderer)barrelRenderer).sharedMaterials.Length != 0) ? ((Renderer)barrelRenderer).sharedMaterials[0] : null);
			if ((Object)(object)flashRenderer != (Object)null)
			{
				((Renderer)flashRenderer).sharedMaterial = ModAssets.EmissiveUnlit(new Color(1f, 0.75f, 0.3f), 60f);
			}
			if ((Object)(object)trigger != (Object)null)
			{
				if (trigger.onInteract == null)
				{
					trigger.onInteract = new InteractEvent();
				}
				((UnityEvent<PlayerControllerB>)(object)trigger.onInteract).AddListener((UnityAction<PlayerControllerB>)OnTriggerInteract);
				Terminal val = Object.FindObjectOfType<Terminal>();
				InteractTrigger val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<InteractTrigger>() : null);
				if ((Object)(object)val2 != (Object)null)
				{
					trigger.hoverIcon = (trigger.disabledHoverIcon = val2.hoverIcon);
				}
			}
			InputActionAsset val3 = (((Object)(object)IngamePlayerSettings.Instance != (Object)null && (Object)(object)IngamePlayerSettings.Instance.playerInput != (Object)null) ? IngamePlayerSettings.Instance.playerInput.actions : null);
			fireAction = ((val3 != null) ? val3.FindAction("ActivateItem", false) : null);
			interactAction = ((val3 != null) ? val3.FindAction("Interact", false) : null);
			if (fireAction == null || interactAction == null)
			{
				Plugin.Log.LogError((object)"Could not find the game's fire/interact inputs");
			}
			if (Net.IsHost)
			{
				hostAmmo = ModConfig.StartingRounds.Value;
				try
				{
					string currentSaveFileName = GameNetworkManager.Instance.currentSaveFileName;
					if (ES3.KeyExists("M2Browning_Ammo", currentSaveFileName))
					{
						hostAmmo = ES3.Load<int>("M2Browning_Ammo", currentSaveFileName, hostAmmo);
					}
				}
				catch (Exception ex2)
				{
					Plugin.Log.LogWarning((object)("Could not read saved M2 ammo: " + ex2.Message));
				}
				ammo = hostAmmo;
				HostBroadcast(StateReason.Sync);
			}
			Plugin.Log.LogInfo((object)$"M2 ready on the roof (ammo {ammo})");
		}

		private void OnDestroy()
		{
			if (localGunning)
			{
				ReleaseLocalPlayer(null);
			}
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
		}

		private void Place()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: 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_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			StartOfRound instance = StartOfRound.Instance;
			Transform elevatorTransform = instance.elevatorTransform;
			Transform shipDoorNode = instance.shipDoorNode;
			Transform middleOfShipNode = instance.middleOfShipNode;
			((Component)this).transform.SetParent(elevatorTransform, true);
			Vector3 val = shipDoorNode.position - middleOfShipNode.position;
			val.y = 0f;
			val = ((((Vector3)(ref val)).sqrMagnitude > 0.01f) ? ((Vector3)(ref val)).normalized : (-elevatorTransform.forward));
			Vector3 val2 = Vector3.Cross(Vector3.up, val);
			Vector3 val3 = ModConfig.V3(ModConfig.MountOffset.Value);
			Vector3 val4 = shipDoorNode.position - val * ModConfig.MountInset.Value + val2 * val3.x + val * val3.z;
			RaycastHit val5 = default(RaycastHit);
			Vector3 point = default(Vector3);
			if (Physics.Raycast(val4 + Vector3.up * 15f, Vector3.down, ref val5, 30f, instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1) && ((RaycastHit)(ref val5)).point.y > shipDoorNode.position.y + 1.2f)
			{
				point = ((RaycastHit)(ref val5)).point;
			}
			else
			{
				((Vector3)(ref point))..ctor(val4.x, shipDoorNode.position.y + 3.4f, val4.z);
				ManualLogSource log = Plugin.Log;
				Collider collider = ((RaycastHit)(ref val5)).collider;
				log.LogWarning((object)$"Roof not found by raycast (hit {((collider != null) ? ((Object)collider).name : null)} at {((RaycastHit)(ref val5)).point}); using a fixed height");
			}
			((Component)this).transform.position = point + Vector3.up * val3.y;
			((Component)this).transform.rotation = Quaternion.LookRotation(val, Vector3.up);
			Vector3 val6 = ModConfig.V3(ModConfig.TriggerOffset.Value);
			manSpot.position = shipDoorNode.position + val2 * val6.x + Vector3.up * val6.y + val * val6.z;
			manSpot.rotation = ((Component)this).transform.rotation;
			ManualLogSource log2 = Plugin.Log;
			object[] obj = new object[4]
			{
				((Component)this).transform.position,
				shipDoorNode.position,
				null,
				null
			};
			Collider collider2 = ((RaycastHit)(ref val5)).collider;
			obj[2] = ((collider2 != null) ? ((Object)collider2).name : null);
			obj[3] = manSpot.position;
			log2.LogInfo((object)string.Format("M2 placed: roof {0} (door node {1}, roof hit {2}), man spot {3}", obj));
		}

		private void OnTriggerInteract(PlayerControllerB p)
		{
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00d0: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)p == (Object)null || (Object)(object)p != (Object)(object)Net.Local)
			{
				return;
			}
			if (p.currentlyHeldObjectServer is AmmoCanItem ammoCanItem)
			{
				if (ammo >= ModConfig.MaxRounds.Value)
				{
					HUDManager.Instance.DisplayTip("M2 full", $"It already holds {ammo} rounds.", false, false, "LC_Tip1");
					return;
				}
				ulong networkObjectId = ((NetworkBehaviour)ammoCanItem).NetworkObjectId;
				int num = Array.IndexOf(p.ItemSlots, (GrabbableObject)(object)ammoCanItem);
				if (num >= 0)
				{
					p.DestroyItemInSlotAndSync(num);
				}
				else
				{
					p.DiscardHeldObject(false, (NetworkObject)null, default(Vector3), true);
				}
				FastBufferWriter w = Net.Begin(Op.LoadAmmo);
				int num2 = Net.PlayerIndex(p);
				((FastBufferWriter)(ref w)).WriteValueSafe<int>(ref num2, default(ForPrimitives));
				ulong num3 = ((num >= 0) ? 0 : networkObjectId);
				((FastBufferWriter)(ref w)).WriteValueSafe<ulong>(ref num3, default(ForPrimitives));
				Net.SendToHost(w);
			}
			else if (CanMountNow(p))
			{
				FastBufferWriter w2 = Net.Begin(Op.MountRequest);
				int num2 = Net.PlayerIndex(p);
				((FastBufferWriter)(ref w2)).WriteValueSafe<int>(ref num2, default(ForPrimitives));
				Net.SendToHost(w2);
			}
		}

		private static bool CanMountNow(PlayerControllerB p)
		{
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)p != (Object)null && !p.isPlayerDead && p.isPlayerControlled && instance.shipHasLanded && !instance.shipIsLeaving)
			{
				return !instance.inShipPhase;
			}
			return false;
		}

		private void UpdateTrigger()
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)trigger == (Object)null))
			{
				PlayerControllerB local = Net.Local;
				if ((Object)(object)spotBox == (Object)null)
				{
					spotBox = ((Component)manSpot).GetComponent<BoxCollider>();
				}
				if ((Object)(object)spotBox != (Object)null)
				{
					bool flag = (Object)(object)local != (Object)null && !local.isPlayerDead && !localGunning && Vector3.Distance(((Component)local).transform.position, StartOfRound.Instance.shipDoorNode.position) < 4.5f;
					((Collider)spotBox).enabled = flag && ((Component)local.gameplayCamera).transform.forward.y > 0.2f;
				}
				bool flag2 = StartOfRound.Instance.shipHasLanded && !StartOfRound.Instance.shipIsLeaving;
				if ((Object)(object)local != (Object)null && local.currentlyHeldObjectServer is AmmoCanItem)
				{
					trigger.interactable = true;
					trigger.hoverTip = $"Load ammo can ({ammo} rds) : [E]";
				}
				else if (!flag2)
				{
					trigger.interactable = false;
					trigger.disabledHoverTip = "M2 (land first)";
				}
				else if (gunner >= 0 && gunner != Net.PlayerIndex(local))
				{
					trigger.interactable = false;
					trigger.disabledHoverTip = "M2 in use";
				}
				else
				{
					trigger.interactable = !localGunning;
					trigger.hoverTip = ((ammo > 0) ? $"Man the M2 ({ammo} rds) : [E]" : "Man the M2 (no ammo) : [E]");
				}
			}
		}

		public void HostOnMountRequest(int p)
		{
			PlayerControllerB p2 = Net.Player(p);
			bool flag = gunner < 0 || gunner == p || !GunnerValid(Net.Player(gunner));
			if (CanMountNow(p2) && flag)
			{
				gunner = p;
				HostBroadcast(StateReason.Mounted);
			}
			else
			{
				HostBroadcast(StateReason.Sync);
			}
		}

		public void HostOnDismount(int p)
		{
			if (gunner == p)
			{
				gunner = -1;
				firingVisual = false;
				HostBroadcast(StateReason.Dismounted);
			}
		}

		public void HostOnShots(int n)
		{
			if (n > 0)
			{
				if (ModConfig.DebugKeys.Value)
				{
					Plugin.Log.LogInfo((object)$"[debug] host: gunner {gunner} fired {n} rounds");
				}
				hostAmmo = Mathf.Max(0, hostAmmo - n);
				if (hostAmmo == 0)
				{
					HostBroadcast(StateReason.Ammo);
				}
			}
		}

		public void HostOnLoadAmmo(int p, ulong dropCanId)
		{
			if (dropCanId != 0L)
			{
				Runner.Run(DespawnDroppedCan(dropCanId));
			}
			hostAmmo = Mathf.Min(ModConfig.MaxRounds.Value, hostAmmo + ModConfig.RoundsPerCan.Value);
			Plugin.Log.LogInfo((object)$"Player {p} loaded an ammo can: {hostAmmo} rounds");
			HostBroadcast(StateReason.Loaded);
		}

		private static IEnumerator DespawnDroppedCan(ulong id)
		{
			yield return (object)new WaitForSeconds(0.6f);
			AmmoCanItem ammoCanItem = Net.Find<AmmoCanItem>(id);
			if ((Object)(object)ammoCanItem != (Object)null && (Object)(object)((GrabbableObject)ammoCanItem).playerHeldBy == (Object)null && ((NetworkBehaviour)ammoCanItem).NetworkObject.IsSpawned)
			{
				((NetworkBehaviour)ammoCanItem).NetworkObject.Despawn(true);
			}
		}

		private void HostBroadcast(StateReason reason)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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_0027: 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_003d: 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_0053: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			FastBufferWriter w = Net.Begin(Op.State);
			((FastBufferWriter)(ref w)).WriteValueSafe<int>(ref gunner, default(ForPrimitives));
			((FastBufferWriter)(ref w)).WriteValueSafe<int>(ref hostAmmo, default(ForPrimitives));
			((FastBufferWriter)(ref w)).WriteValueSafe<float>(ref heat, default(ForPrimitives));
			((FastBufferWriter)(ref w)).WriteValueSafe<bool>(ref overheated, default(ForPrimitives));
			byte b = (byte)reason;
			((FastBufferWriter)(ref w)).WriteValueSafe<byte>(ref b, default(ForPrimitives));
			Net.SendToAll(w, ulong.MaxValue);
		}

		private static bool GunnerValid(PlayerControllerB p)
		{
			if ((Object)(object)p != (Object)null && p.isPlayerControlled)
			{
				return !p.isPlayerDead;
			}
			return false;
		}

		public void HostSaveAmmo()
		{
			try
			{
				ES3.Save<int>("M2Browning_Ammo", hostAmmo, GameNetworkManager.Instance.currentSaveFileName);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not save M2 ammo: " + ex.Message));
			}
		}

		public void OnShipLeaving()
		{
			if (localGunning)
			{
				ReleaseLocalPlayer(true);
			}
			if (Net.IsHost && gunner >= 0)
			{
				gunner = -1;
				HostBroadcast(StateReason.Dismounted);
			}
		}

		public void OnState(int newGunner, int hostAmmo, float hostHeat, bool hostOverheated, StateReason reason)
		{
			int num = Net.PlayerIndex(Net.Local);
			gunner = newGunner;
			if (localGunning)
			{
				ammo = ((reason == StateReason.Loaded || reason == StateReason.Mounted) ? Mathf.Max(0, hostAmmo - pendingShots) : Mathf.Min(ammo, hostAmmo));
				if (reason == StateReason.Loaded)
				{
					PlaySfx(ModAssets.Clunk, 0.8f);
				}
			}
			else
			{
				ammo = hostAmmo;
				if (!firingVisual)
				{
					heat = hostHeat;
					overheated = hostOverheated;
				}
				if (reason == StateReason.Loaded)
				{
					PlaySfx(ModAssets.Clunk, 0.8f);
				}
			}
			if (gunner < 0)
			{
				SetFiringVisual(on: false);
			}
			if (gunner == num && num >= 0 && !localGunning && reason == StateReason.Mounted)
			{
				BeginLocalGunner();
			}
			else if (localGunning && gunner != num)
			{
				ReleaseLocalPlayer(null);
			}
		}

		public void OnAim(float yaw, float pitch)
		{
			if (!localGunning)
			{
				targetYaw = yaw;
				targetPitch = pitch;
			}
		}

		public void OnFire(bool on, float syncedHeat)
		{
			if (!localGunning)
			{
				heat = syncedHeat;
				overheated = !on && syncedHeat >= 0.99f;
				if (overheated)
				{
					PlaySfx(ModAssets.Hiss, 1f);
				}
				SetFiringVisual(on);
			}
		}

		public static void OnHitPlayer(int target, int damage, Vector3 dir)
		{
			//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)
			PlayerControllerB local = Net.Local;
			if (!((Object)(object)local == (Object)null) && Net.PlayerIndex(local) == target && !local.isPlayerDead)
			{
				local.DamagePlayer(damage, true, true, (CauseOfDeath)7, 0, false, dir * 25f);
			}
		}

		private void BeginLocalGunner()
		{
			//IL_0083: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB local = Net.Local;
			if (!((Object)(object)local == (Object)null))
			{
				localGunning = true;
				localFiring = false;
				mountedAt = Time.time;
				shotTimer = 1f / Mathf.Max(1f, ModConfig.RoundsPerSecond.Value);
				pendingShots = 0;
				curYaw = (targetYaw = 0f);
				curPitch = (targetPitch = 0f);
				float num = ((Component)local.gameplayCamera).transform.position.y - ((Component)local).transform.position.y;
				feetDrop = Mathf.Clamp(num - (1.55f + MuzzleLocal.y + 0.3f), 0f, 0.6f);
				Plugin.Log.LogInfo((object)$"Gunner eye height {num:F2} m, standing {feetDrop:F2} m low");
				local.TeleportPlayer(GunnerFeet(0f), false, 0f, false, true);
				local.inSpecialInteractAnimation = true;
				local.disableMoveInput = true;
				PlaySfx(ModAssets.Clunk, 1f);
				UpdateHud(force: true);
				Plugin.Log.LogInfo((object)"You are on the M2");
			}
		}

		private void ReleaseLocalPlayer(bool? intoShip)
		{
			//IL_007a: 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)
			PlayerControllerB local = Net.Local;
			bool num = localFiring;
			localGunning = false;
			localFiring = false;
			if (num)
			{
				SetFiringVisual(on: false);
				SendFire(on: false);
			}
			FlushShots();
			if ((Object)(object)local != (Object)null)
			{
				local.inSpecialInteractAnimation = false;
				local.disableMoveInput = false;
				local.ResetFallGravity();
				if (intoShip.HasValue && !local.isPlayerDead)
				{
					local.TeleportPlayer(intoShip.Value ? StartOfRound.Instance.middleOfShipNode.position : GroundOutsideDoor(), false, 0f, false, true);
				}
			}
			if ((Object)(object)HUDManager.Instance != (Object)null)
			{
				HUDManager.Instance.ClearControlTips();
			}
		}

		private void LeaveGun(bool intoShip)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			int num = Net.PlayerIndex(Net.Local);
			ReleaseLocalPlayer(intoShip);
			FastBufferWriter w = Net.Begin(Op.Dismount);
			((FastBufferWriter)(ref w)).WriteValueSafe<int>(ref num, default(ForPrimitives));
			Net.SendToHost(w);
		}

		private Vector3 GunnerFeet(float yaw)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Component)this).transform.rotation * Quaternion.Euler(0f, yaw, 0f) * Vector3.forward;
			return ((Component)this).transform.position - val * ModConfig.GunnerDistance.Value + Vector3.up * (0.05f - feetDrop);
		}

		private Vector3 GroundOutsideDoor()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_0043: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			StartOfRound instance = StartOfRound.Instance;
			Vector3 forward = ((Component)this).transform.forward;
			Vector3 val = instance.shipDoorNode.position + forward * 1.8f;
			RaycastHit val2 = default(RaycastHit);
			if (Physics.Raycast(val + Vector3.up * 2f, Vector3.down, ref val2, 8f, instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
			{
				return ((RaycastHit)(ref val2)).point + Vector3.up * 0.1f;
			}
			return val;
		}

		private void Update()
		{
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			float deltaTime = Time.deltaTime;
			float num = Mathf.Max(1f, ModConfig.RoundsPerSecond.Value);
			if (firingVisual)
			{
				heat += deltaTime / Mathf.Max(0.5f, ModConfig.SecondsToOverheat.Value);
			}
			else
			{
				heat -= deltaTime / Mathf.Max(0.5f, ModConfig.SecondsToCool.Value);
			}
			heat = Mathf.Clamp01(heat);
			if (heat <= 0f)
			{
				overheated = false;
			}
			if (!localGunning)
			{
				curYaw = Mathf.LerpAngle(curYaw, targetYaw, deltaTime * 14f);
				curPitch = Mathf.Lerp(curPitch, targetPitch, deltaTime * 14f);
				ApplyAim();
				if (firingVisual)
				{
					visualShotTimer += deltaTime;
					while (visualShotTimer >= 1f / num)
					{
						visualShotTimer -= 1f / num;
						if (++shotCount % 2 == 0)
						{
							VisualTracer(pitchPart.forward);
						}
					}
				}
			}
			UpdateVisuals(deltaTime);
			UpdateTrigger();
			if (Net.IsHost)
			{
				if (gunner >= 0 && (!GunnerValid(Net.Player(gunner)) || StartOfRound.Instance.shipIsLeaving))
				{
					gunner = -1;
					HostBroadcast(StateReason.Dismounted);
				}
				hostSyncTimer += deltaTime;
				if (hostSyncTimer > 2f)
				{
					hostSyncTimer = 0f;
					HostBroadcast(StateReason.Sync);
				}
			}
		}

		private void LateUpdate()
		{
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: 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_0103: 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_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: 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_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: 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_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
			if (!localGunning)
			{
				return;
			}
			PlayerControllerB local = Net.Local;
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)local == (Object)null || local.isPlayerDead || !local.isPlayerControlled)
			{
				LeaveGun(intoShip: false);
				return;
			}
			if (instance.shipIsLeaving || !instance.shipHasLanded)
			{
				LeaveGun(intoShip: true);
				return;
			}
			bool flag = ((Object)(object)local.quickMenuManager != (Object)null && local.quickMenuManager.isMenuOpen) || local.isTypingChat;
			if (!flag && interactAction != null && interactAction.WasPressedThisFrame() && Time.time - mountedAt > 0.4f)
			{
				LeaveGun(intoShip: false);
				return;
			}
			float deltaTime = Time.deltaTime;
			if (debugTrack && ModConfig.DebugKeys.Value)
			{
				DebugTrackTarget();
			}
			Vector3 val = ((Component)this).transform.InverseTransformDirection(((Component)local.gameplayCamera).transform.forward);
			curYaw = Mathf.Atan2(val.x, val.z) * 57.29578f;
			curPitch = Mathf.Clamp(Mathf.Asin(Mathf.Clamp(val.y, -1f, 1f)) * 57.29578f, -35f, 65f);
			ApplyAim();
			local.inSpecialInteractAnimation = true;
			local.disableMoveInput = true;
			((Component)local).transform.position = GunnerFeet(curYaw);
			local.fallValue = 0f;
			local.fallValueUncapped = 0f;
			aimTimer += deltaTime;
			if (aimTimer > 0.05f && (Mathf.Abs(Mathf.DeltaAngle(curYaw, lastSentYaw)) > 0.3f || Mathf.Abs(curPitch - lastSentPitch) > 0.3f))
			{
				aimTimer = 0f;
				lastSentYaw = curYaw;
				lastSentPitch = curPitch;
				FastBufferWriter w = Net.Begin(Op.Aim);
				((FastBufferWriter)(ref w)).WriteValueSafe<float>(ref curYaw, default(ForPrimitives));
				((FastBufferWriter)(ref w)).WriteValueSafe<float>(ref curPitch, default(ForPrimitives));
				Net.Broadcast(w);
			}
			float num = 1f / Mathf.Max(1f, ModConfig.RoundsPerSecond.Value);
			bool flag2 = !flag && fireAction != null && fireAction.IsPressed();
			if (flag2 && overheated)
			{
				if (localFiring)
				{
					StopLocalFire();
				}
			}
			else if (flag2 && ammo <= 0)
			{
				if (localFiring)
				{
					StopLocalFire();
				}
				if (fireAction.WasPressedThisFrame())
				{
					PlaySfx(ModAssets.DryClick, 1f);
				}
			}
			else if (flag2)
			{
				if (!localFiring)
				{
					localFiring = true;
					SetFiringVisual(on: true);
					SendFire(on: true);
				}
				shotTimer += deltaTime;
				while (shotTimer >= num && ammo > 0)
				{
					shotTimer -= num;
					FireOneShot(local);
				}
				if (heat >= 1f)
				{
					overheated = true;
					StopLocalFire();
					PlaySfx(ModAssets.Hiss, 1f);
					HUDManager.Instance.DisplayTip("M2 OVERHEATED", "Let go of the trigger and let the barrel cool down.", true, false, "LC_Tip1");
				}
				else if (ammo <= 0)
				{
					StopLocalFire();
					PlaySfx(ModAssets.DryClick, 1f);
					HUDManager.Instance.DisplayTip("M2 out of ammo", "Load an ammo can at the ship door.", true, false, "LC_Tip1");
				}
				noiseTimer += deltaTime;
				if (noiseTimer > 0.4f)
				{
					noiseTimer = 0f;
					RoundManager.Instance.PlayAudibleNoise(muzzle.position, 60f, 1f, 0, false, 0);
				}
				shakeTimer += deltaTime;
				if (shakeTimer > 0.22f)
				{
					shakeTimer = 0f;
					HUDManager.Instance.ShakeCamera((ScreenShakeType)0);
				}
			}
			else if (localFiring)
			{
				StopLocalFire();
			}
			if (!localFiring)
			{
				shotTimer = Mathf.Min(shotTimer + deltaTime, num);
			}
			sendTimer += deltaTime;
			if (sendTimer > 0.25f)
			{
				sendTimer = 0f;
				FlushShots();
			}
			hudTimer += deltaTime;
			if (hudTimer > 0.15f)
			{
				hudTimer = 0f;
				UpdateHud(force: false);
			}
		}

		private void StopLocalFire()
		{
			localFiring = false;
			SetFiringVisual(on: false);
			SendFire(on: false);
			FlushShots();
		}

		private void SendFire(bool on)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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)
			FastBufferWriter w = Net.Begin(Op.Fire);
			((FastBufferWriter)(ref w)).WriteValueSafe<bool>(ref on, default(ForPrimitives));
			float num = (overheated ? 1f : heat);
			((FastBufferWriter)(ref w)).WriteValueSafe<float>(ref num, default(ForPrimitives));
			Net.Broadcast(w);
		}

		private void FlushShots()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_002e: Unknown result type (might be due to invalid IL or missing references)
			if (pendingShots > 0)
			{
				FastBufferWriter w = Net.Begin(Op.Shots);
				((FastBufferWriter)(ref w)).WriteValueSafe<int>(ref pendingShots, default(ForPrimitives));
				pendingShots = 0;
				Net.SendToHost(w);
			}
		}

		private void UpdateHud(bool force)
		{
			if (!((Object)(object)HUDManager.Instance == (Object)null))
			{
				int num = Mathf.RoundToInt(heat * 10f);
				string text = (overheated ? "OVERHEATED" : (new string('#', num) + new string('-', 10 - num)));
				HUDManager.Instance.ChangeControlTipMultiple(new string[4]
				{
					"Fire : [LMB]",
					"Get off : [E]",
					$"Ammo : {ammo}",
					"Heat : " + text
				}, false, (Item)null);
			}
		}

		private void FireOneShot(PlayerControllerB shooter)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: 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_028f: Unknown result type (might be due to invalid IL or missing references)
			ammo--;
			pendingShots++;
			shotCount++;
			Vector3 position = ((Component)shooter.gameplayCamera).transform.position;
			Vector2 val = Random.insideUnitCircle * ModConfig.Spread.Value;
			Vector3 val2 = Quaternion.AngleAxis(val.x, pitchPart.up) * Quaternion.AngleAxis(val.y, pitchPart.right) * pitchPart.forward;
			float value = ModConfig.Range.Value;
			int num = StartOfRound.Instance.collidersAndRoomMaskAndDefault | 0x80000 | 8;
			int count = Physics.RaycastNonAlloc(position, val2, hitBuffer, value, num, (QueryTriggerInteraction)2);
			Vector3 val3 = position + val2 * value;
			bool flag = false;
			foreach (RaycastHit item in from h in hitBuffer.Take(count)
				where (Object)(object)((RaycastHit)(ref h)).collider != (Object)null
				orderby ((RaycastHit)(ref h)).distance
				select h)
			{
				RaycastHit current = item;
				if (((Component)((RaycastHit)(ref current)).collider).transform.IsChildOf(((Component)shooter).transform))
				{
					continue;
				}
				EnemyAICollisionDetect component = ((Component)((RaycastHit)(ref current)).collider).GetComponent<EnemyAICollisionDetect>();
				lastHitName = ((Object)((RaycastHit)(ref current)).collider).name;
				if ((Object)(object)component != (Object)null && (Object)(object)component.mainScript != (Object)null)
				{
					lastHitName = component.mainScript.enemyType.enemyName;
					if (!component.mainScript.isEnemyDead)
					{
						HitEnemy(component, val2, shooter);
						val3 = ((RaycastHit)(ref current)).point;
						flag = true;
						break;
					}
					continue;
				}
				PlayerControllerB componentInParent = ((Component)((RaycastHit)(ref current)).collider).GetComponentInParent<PlayerControllerB>();
				if ((Object)(object)componentInParent != (Object)null && (Object)(object)componentInParent != (Object)(object)shooter && ((Component)((RaycastHit)(ref current)).collider).gameObject.layer == 3)
				{
					if (componentInParent.isPlayerControlled && !componentInParent.isPlayerDead && ModConfig.FriendlyFire.Value)
					{
						FastBufferWriter w = Net.Begin(Op.HitPlayer);
						int num2 = Net.PlayerIndex(componentInParent);
						((FastBufferWriter)(ref w)).WriteValueSafe<int>(ref num2, default(ForPrimitives));
						num2 = ModConfig.PlayerDamagePerBullet.Value;
						((FastBufferWriter)(ref w)).WriteValueSafe<int>(ref num2, default(ForPrimitives));
						((FastBufferWriter)(ref w)).WriteValueSafe(ref val2);
						Net.Broadcast(w);
						val3 = ((RaycastHit)(ref current)).point;
						flag = true;
						break;
					}
				}
				else if (!((RaycastHit)(ref current)).collider.isTrigger)
				{
					val3 = ((RaycastHit)(ref current)).point;
					flag = true;
					break;
				}
			}
			if (ModConfig.DebugKeys.Value && shotCount % 10 == 0)
			{
				Plugin.Log.LogInfo((object)string.Format("[debug] shot {0}: hit {1} at {2}", shotCount, flag ? lastHitName : "nothing", val3));
			}
			if (shotCount % 2 == 0)
			{
				Tracer(muzzle.position, val3);
			}
			if (flag)
			{
				Runner.Run(ImpactFlash(val3));
			}
		}

		private void DebugTrackTarget()
		{
			//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_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: 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_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB me = Net.Local;
			EnemyAI val = (from e in Object.FindObjectsOfType<EnemyAI>()
				where (Object)(object)e != (Object)null && !e.isEnemyDead && BigGame.IsBig(e)
				orderby Vector3.Distance(((Component)e).transform.position, ((Component)me).transform.position)
				select e).FirstOrDefault();
			if ((Object)(object)val == (Object)null)
			{
				PlayerControllerB val2 = (from pl in StartOfRound.Instance.allPlayerScripts
					where (Object)(object)pl != (Object)null && (Object)(object)pl != (Object)(object)me && pl.isPlayerControlled && !pl.isPlayerDead
					orderby Vector3.Distance(((Component)pl).transform.position, ((Component)me).transform.position)
					select pl).FirstOrDefault();
				if ((Object)(object)val2 != (Object)null)
				{
					DebugAimAt(((Component)val2).transform.position + Vector3.up * 1.2f, log: false);
				}
			}
			else
			{
				EnemyAICollisionDetect componentInChildren = ((Component)val).GetComponentInChildren<EnemyAICollisionDetect>();
				Collider val3 = ((componentInChildren != null) ? ((Component)componentInChildren).GetComponent<Collider>() : null);
				Vector3 target;
				if (!((Object)(object)val3 != (Object)null))
				{
					target = ((Component)val).transform.position + Vector3.up * 3f;
				}
				else
				{
					Bounds bounds = val3.bounds;
					target = ((Bounds)(ref bounds)).center;
				}
				DebugAimAt(target, log: false);
			}
		}

		public void DebugAimAt(Vector3 target, bool log = true)
		{
			//IL_0018: 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_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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB local = Net.Local;
			if (localGunning && !((Object)(object)local == (Object)null))
			{
				Vector3 val = target - ((Component)local.gameplayCamera).transform.position;
				float num = Mathf.Atan2(val.x, val.z) * 57.29578f;
				float num2 = (0f - Mathf.Asin(Mathf.Clamp(((Vector3)(ref val)).normalized.y, -1f, 1f))) * 57.29578f;
				local.thisPlayerBody.rotation = Quaternion.Euler(0f, num, 0f);
				Traverse.Create((object)local).Field("cameraUp").SetValue((object)num2);
				Vector3 localEulerAngles = ((Component)local.gameplayCamera).transform.localEulerAngles;
				((Component)local.gameplayCamera).transform.localEulerAngles = new Vector3(num2, 0f, localEulerAngles.z);
				if (log)
				{
					Plugin.Log.LogInfo((object)$"[debug] aiming at {target} (yaw {num:F0}, pitch {num2:F0})");
				}
			}
		}

		private void HitEnemy(EnemyAICollisionDetect det, Vector3 dir, PlayerControllerB shooter)
		{
			//IL_0065: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			EnemyAI mainScript = det.mainScript;
			if (BigGame.IsBig(mainScript))
			{
				mainScript.HitEnemyOnLocalClient(0, dir, shooter, true, 50050);
				FastBufferWriter w = Net.Begin(Op.BigHit);
				ulong networkObjectId = ((NetworkBehaviour)mainScript).NetworkObjectId;
				((FastBufferWriter)(ref w)).WriteValueSafe<ulong>(ref networkObjectId, default(ForPrimitives));
				int num = 1;
				((FastBufferWriter)(ref w)).WriteValueSafe<int>(ref num, default(ForPrimitives));
				Net.SendToHost(w);
			}
			else
			{
				((IHittable)det).Hit(ModConfig.EnemyDamagePerBullet.Value, dir, shooter, true, 50050);
			}
		}

		private void ApplyAim()
		{
			//IL_0016: 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)
			yawPart.localRotation = Quaternion.Euler(0f, curYaw, 0f);
			pitchPart.localRotation = Quaternion.Euler(0f - curPitch, 0f, 0f);
		}

		private void SetFiringVisual(bool on)
		{
			if (firingVisual == on)
			{
				return;
			}
			firingVisual = on;
			visualShotTimer = 0f;
			if (on)
			{
				if ((Object)(object)ModAssets.FireLoop != (Object)null)
				{
					fireAudio.clip = ModAssets.FireLoop;
					fireAudio.loop = true;
					fireAudio.volume = ModConfig.FireVolume.Value;
					fireAudio.time = 0f;
					fireAudio.Play();
				}
				return;
			}
			fireAudio.Stop();
			fireAudio.loop = false;
			if ((Object)(object)ModAssets.FireTail != (Object)null)
			{
				fireAudio.PlayOneShot(ModAssets.FireTail, ModConfig.FireVolume.Value);
			}
			if ((Object)(object)flashLight != (Object)null)
			{
				((Behaviour)flashLight).enabled = false;
			}
			if ((Object)(object)flashRenderer != (Object)null)