Decompiled source of EpicGuns v0.5.0

BepInEx/plugins/EpicGuns/EpicGuns.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("EpicGuns")]
[assembly: AssemblyProduct("EpicGuns")]
[assembly: AssemblyTitle("EpicGuns")]
[assembly: AssemblyFileVersion("0.5.0.0")]
[assembly: AssemblyInformationalVersion("0.5.0")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyVersion("0.5.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 EpicGuns
{
	internal static class BulletModel
	{
		internal static void ReplaceBoltVisual(GameObject projectile)
		{
			//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_00bc: Expected O, but got Unknown
			//IL_00d6: 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_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Expected O, but got Unknown
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			if (Application.isBatchMode)
			{
				return;
			}
			Renderer[] componentsInChildren = projectile.GetComponentsInChildren<Renderer>(true);
			Material val = null;
			Material val2 = null;
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				if ((Object)(object)val == (Object)null && componentsInChildren[i] is MeshRenderer && (Object)(object)componentsInChildren[i].sharedMaterial != (Object)null)
				{
					val = componentsInChildren[i].sharedMaterial;
				}
				if ((Object)(object)val2 == (Object)null && !(componentsInChildren[i] is MeshRenderer) && (Object)(object)componentsInChildren[i].sharedMaterial != (Object)null)
				{
					val2 = componentsInChildren[i].sharedMaterial;
				}
			}
			for (int j = 0; j < componentsInChildren.Length; j++)
			{
				componentsInChildren[j].enabled = false;
			}
			if (!((Object)(object)val == (Object)null))
			{
				Material val3 = new Material(val)
				{
					name = "EpicGuns_Brass"
				};
				SetColor(val3, "_Color", new Color(0.64f, 0.31f, 0.055f, 1f));
				SetColor(val3, "_BaseColor", new Color(0.64f, 0.31f, 0.055f, 1f));
				SetFloat(val3, "_Metallic", 0.72f);
				SetFloat(val3, "_Glossiness", 0.5f);
				GameObject obj = GameObject.CreatePrimitive((PrimitiveType)1);
				((Object)obj).name = "EpicGuns_45ACP_BulletVisual";
				obj.transform.SetParent(projectile.transform, false);
				obj.transform.localPosition = Vector3.zero;
				obj.transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
				obj.transform.localScale = new Vector3(0.009f, 0.024f, 0.009f);
				obj.layer = projectile.layer;
				Collider component = obj.GetComponent<Collider>();
				if ((Object)(object)component != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)component);
				}
				obj.GetComponent<Renderer>().sharedMaterial = val3;
				Material val4 = new Material(((Object)(object)val2 != (Object)null) ? val2 : val)
				{
					name = "EpicGuns_Tracer"
				};
				Color val5 = default(Color);
				((Color)(ref val5))..ctor(1f, 0.32f, 0.035f, 1f);
				SetColor(val4, "_Color", val5);
				SetColor(val4, "_BaseColor", val5);
				SetColor(val4, "_EmissionColor", val5 * 3.4f);
				val4.EnableKeyword("_EMISSION");
				SetFloat(val4, "_Metallic", 0f);
				SetFloat(val4, "_Glossiness", 0.85f);
				TrailRenderer obj2 = projectile.AddComponent<TrailRenderer>();
				((Object)obj2).name = "EpicGuns_45ACP_Tracer";
				((Renderer)obj2).sharedMaterial = val4;
				obj2.time = EpicGunsConfig.TracerLifetime.Value;
				obj2.startWidth = EpicGunsConfig.TracerWidth.Value;
				obj2.endWidth = 0.001f;
				obj2.minVertexDistance = 0.04f;
				obj2.startColor = val5;
				obj2.endColor = new Color(1f, 0.08f, 0f, 0f);
				obj2.numCornerVertices = 2;
				obj2.numCapVertices = 2;
				obj2.emitting = EpicGunsConfig.TracersEnabled.Value;
				projectile.AddComponent<BulletTracerController>();
			}
		}

		private static void SetColor(Material material, string property, Color value)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			if (material.HasProperty(property))
			{
				material.SetColor(property, value);
			}
		}

		private static void SetFloat(Material material, string property, float value)
		{
			if (material.HasProperty(property))
			{
				material.SetFloat(property, value);
			}
		}
	}
	internal sealed class BulletTracerController : MonoBehaviour
	{
		private TrailRenderer _trail;

		private void Awake()
		{
			_trail = ((Component)this).GetComponent<TrailRenderer>();
			ApplySettings();
		}

		private void OnEnable()
		{
			if ((Object)(object)_trail == (Object)null)
			{
				_trail = ((Component)this).GetComponent<TrailRenderer>();
			}
			if ((Object)(object)_trail != (Object)null)
			{
				_trail.Clear();
			}
			ApplySettings();
		}

		private void ApplySettings()
		{
			if (!((Object)(object)_trail == (Object)null))
			{
				_trail.time = EpicGunsConfig.TracerLifetime.Value;
				_trail.startWidth = EpicGunsConfig.TracerWidth.Value;
				_trail.emitting = EpicGunsConfig.TracersEnabled.Value;
			}
		}
	}
	internal static class EpicGunAssets
	{
		private static string _assetDirectory;

		internal static void Initialize(string pluginLocation, ManualLogSource logger)
		{
			_assetDirectory = Path.Combine(Path.GetDirectoryName(pluginLocation) ?? Paths.PluginPath, "assets");
			logger.LogInfo((object)("EpicGuns asset directory: " + _assetDirectory));
		}

		internal static Sprite LoadSprite(string fileName)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			if (Application.isBatchMode)
			{
				return null;
			}
			try
			{
				string text = ResolvePath(fileName);
				if (text == null)
				{
					return null;
				}
				byte[] array = File.ReadAllBytes(text);
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false)
				{
					name = "EpicGuns_" + Path.GetFileNameWithoutExtension(fileName)
				};
				if (!ImageConversion.LoadImage(val, array, false))
				{
					Object.Destroy((Object)(object)val);
					return null;
				}
				((Texture)val).wrapMode = (TextureWrapMode)1;
				((Texture)val).filterMode = (FilterMode)1;
				return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
			}
			catch
			{
				return null;
			}
		}

		internal static AudioClip LoadWave(string fileName, string clipName, ManualLogSource logger)
		{
			if (Application.isBatchMode)
			{
				return null;
			}
			string text = ResolvePath(fileName);
			if (text == null)
			{
				logger.LogWarning((object)("Missing EpicGuns audio asset: " + fileName));
				return null;
			}
			try
			{
				using FileStream fileStream = File.OpenRead(text);
				using BinaryReader binaryReader = new BinaryReader(fileStream);
				if (new string(binaryReader.ReadChars(4)) != "RIFF")
				{
					throw new InvalidDataException("Not RIFF");
				}
				binaryReader.ReadInt32();
				if (new string(binaryReader.ReadChars(4)) != "WAVE")
				{
					throw new InvalidDataException("Not WAVE");
				}
				short num = 0;
				short num2 = 0;
				int num3 = 0;
				short num4 = 0;
				byte[] array = null;
				while (fileStream.Position + 8 <= fileStream.Length)
				{
					string text2 = new string(binaryReader.ReadChars(4));
					int num5 = binaryReader.ReadInt32();
					long val = fileStream.Position + num5 + (num5 & 1);
					if (text2 == "fmt ")
					{
						num = binaryReader.ReadInt16();
						num2 = binaryReader.ReadInt16();
						num3 = binaryReader.ReadInt32();
						binaryReader.ReadInt32();
						binaryReader.ReadInt16();
						num4 = binaryReader.ReadInt16();
					}
					else if (text2 == "data")
					{
						array = binaryReader.ReadBytes(num5);
					}
					fileStream.Position = Math.Min(val, fileStream.Length);
				}
				if (num != 1 || num2 < 1 || num3 < 8000 || num4 != 16 || array == null)
				{
					throw new InvalidDataException("Expected 16-bit PCM WAV");
				}
				int num6 = array.Length / 2;
				float[] array2 = new float[num6];
				for (int i = 0; i < num6; i++)
				{
					short num7 = (short)(array[i * 2] | (array[i * 2 + 1] << 8));
					array2[i] = (float)num7 / 32768f;
				}
				AudioClip obj = AudioClip.Create(clipName, num6 / num2, (int)num2, num3, false);
				obj.SetData(array2, 0);
				logger.LogInfo((object)("Loaded EpicGuns pistol report from " + text));
				return obj;
			}
			catch (Exception ex)
			{
				logger.LogWarning((object)("Could not load EpicGuns audio: " + ex.Message));
				return null;
			}
		}

		private static string ResolvePath(string fileName)
		{
			if (!string.IsNullOrEmpty(_assetDirectory))
			{
				string text = Path.Combine(_assetDirectory, fileName);
				if (File.Exists(text))
				{
					return text;
				}
			}
			string text2 = Path.Combine(Paths.PluginPath, "EpicGuns", "assets", fileName);
			if (!File.Exists(text2))
			{
				return null;
			}
			return text2;
		}
	}
	internal static class EpicGunsConfig
	{
		internal static ConfigEntry<float> FireRate;

		internal static ConfigEntry<float> WeaponPierce;

		internal static ConfigEntry<float> AmmoPierce;

		internal static ConfigEntry<float> ProjectileSpeed;

		internal static ConfigEntry<float> StaminaPerShot;

		internal static ConfigEntry<bool> DisableFiringPushback;

		internal static ConfigEntry<float> FiringPushback;

		internal static ConfigEntry<float> ShotVolume;

		internal static ConfigEntry<bool> TracersEnabled;

		internal static ConfigEntry<float> TracerLifetime;

		internal static ConfigEntry<float> TracerWidth;

		internal static ConfigEntry<bool> OneHandedAimPose;

		internal static ConfigEntry<float> ArmExtension;

		internal static ConfigEntry<float> ElbowOut;

		internal static ConfigEntry<float> ElbowDown;

		internal static ConfigEntry<float> AimYawOffset;

		internal static ConfigEntry<float> AimPitchOffset;

		internal static ConfigEntry<float> AimRollOffset;

		internal static void Bind(EpicGunsPlugin plugin)
		{
			FireRate = BindSynced(plugin, "1911 - Balance", "FireRate", 1f, "Base shots per second. The Bows skill can make the reload slightly faster.", 0.2f, 10f);
			WeaponPierce = BindSynced(plugin, "1911 - Balance", "WeaponPierce", 22f, "Pierce damage supplied by the 1911 before ammunition damage.", 0f, 250f);
			AmmoPierce = BindSynced(plugin, "1911 - Balance", "AmmoPierce", 18f, "Pierce damage supplied by each .45 ACP round.", 0f, 250f);
			ProjectileSpeed = BindSynced(plugin, "1911 - Balance", "ProjectileSpeed", 82f, "Projectile launch speed in metres per second.", 10f, 250f);
			StaminaPerShot = BindSynced(plugin, "1911 - Balance", "StaminaPerShot", 5f, "Stamina spent for each shot.", 0f, 50f);
			DisableFiringPushback = BindSynced(plugin, "Firearms - Recoil", "DisableFiringPushback", value: true, "Stops EpicGuns firearms from physically pushing the player backward when fired.");
			FiringPushback = BindSynced(plugin, "Firearms - Recoil", "FiringPushback", 0f, "Backward shove strength used only when DisableFiringPushback is false.", 0f, 20f);
			ShotVolume = BindLocal(plugin, "Audio", "ShotVolume", 0.76f, "Local volume of the 1911 gunshot.", 0f, 1f);
			TracersEnabled = BindLocal(plugin, "Bullet Tracers", "Enabled", value: true, "Adds a short glowing orange tracer behind EpicGuns projectiles.");
			TracerLifetime = BindLocal(plugin, "Bullet Tracers", "Lifetime", 0.075f, "How many seconds the tracer remains visible. At the default bullet speed, 0.075 is roughly a six-metre streak.", 0.01f, 0.3f);
			TracerWidth = BindLocal(plugin, "Bullet Tracers", "Width", 0.018f, "Width of the tracer streak in metres.", 0.003f, 0.08f);
			OneHandedAimPose = BindLocal(plugin, "One-handed Aim Pose", "Enabled", value: true, "Aligns the pistol in the right hand and relaxes the empty left arm. Equipped off-hand items retain their normal pose.");
			ArmExtension = BindLocal(plugin, "One-handed Aim Pose", "ArmExtension", 0.94f, "How straight the aiming arm is. Lower values bend the elbow more.", 0.6f, 0.99f);
			ElbowOut = BindLocal(plugin, "One-handed Aim Pose", "ElbowOut", 0.34f, "Moves the aiming elbow outward from the body.", -1f, 1f);
			ElbowDown = BindLocal(plugin, "One-handed Aim Pose", "ElbowDown", 0.72f, "Moves the aiming elbow downward.", -1f, 1f);
			AimYawOffset = BindLocal(plugin, "One-handed Aim Pose", "AimYawOffset", 0f, "Fine adjustment in degrees if the pistol points left or right of the crosshair.", -45f, 45f);
			AimPitchOffset = BindLocal(plugin, "One-handed Aim Pose", "AimPitchOffset", 0f, "Fine adjustment in degrees if the pistol points above or below the crosshair.", -45f, 45f);
			AimRollOffset = BindLocal(plugin, "One-handed Aim Pose", "AimRollOffset", 0f, "Fine adjustment in degrees for wrist roll.", -90f, 90f);
		}

		internal static void SubscribeBalanceChanges(EventHandler handler)
		{
			FireRate.SettingChanged += handler;
			WeaponPierce.SettingChanged += handler;
			AmmoPierce.SettingChanged += handler;
			ProjectileSpeed.SettingChanged += handler;
			StaminaPerShot.SettingChanged += handler;
			DisableFiringPushback.SettingChanged += handler;
			FiringPushback.SettingChanged += handler;
		}

		internal static void UnsubscribeBalanceChanges(EventHandler handler)
		{
			FireRate.SettingChanged -= handler;
			WeaponPierce.SettingChanged -= handler;
			AmmoPierce.SettingChanged -= handler;
			ProjectileSpeed.SettingChanged -= handler;
			StaminaPerShot.SettingChanged -= handler;
			DisableFiringPushback.SettingChanged -= handler;
			FiringPushback.SettingChanged -= handler;
		}

		private static ConfigEntry<T> BindSynced<T>(EpicGunsPlugin plugin, string section, string key, T value, string description)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			ConfigurationManagerAttributes val = new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			};
			return ((BaseUnityPlugin)plugin).Config.Bind<T>(section, key, value, new ConfigDescription(description + " [Synced with server]", (AcceptableValueBase)null, new object[1] { val }));
		}

		private static ConfigEntry<float> BindSynced(EpicGunsPlugin plugin, string section, string key, float value, string description, float minimum, float maximum)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			ConfigurationManagerAttributes val = new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			};
			return ((BaseUnityPlugin)plugin).Config.Bind<float>(section, key, value, new ConfigDescription(description + " [Synced with server]", (AcceptableValueBase)(object)new AcceptableValueRange<float>(minimum, maximum), new object[1] { val }));
		}

		private static ConfigEntry<T> BindLocal<T>(EpicGunsPlugin plugin, string section, string key, T value, string description)
		{
			return ((BaseUnityPlugin)plugin).Config.Bind<T>(section, key, value, description);
		}

		private static ConfigEntry<float> BindLocal(EpicGunsPlugin plugin, string section, string key, float value, string description, float minimum, float maximum)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			return ((BaseUnityPlugin)plugin).Config.Bind<float>(section, key, value, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<float>(minimum, maximum), Array.Empty<object>()));
		}
	}
	[BepInPlugin("com.triston.epicguns", "EpicGuns", "0.5.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public sealed class EpicGunsPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.triston.epicguns";

		public const string PluginName = "EpicGuns";

		public const string PluginVersion = "0.5.0";

		public const string PistolPrefab = "EpicGuns_1911";

		public const string AmmoPrefab = "EpicGuns_45ACP";

		public const string AmmoType = "$epicguns_ammo_45acp";

		internal static EpicGunsPlugin Instance;

		internal static AudioClip GunshotClip;

		private Harmony _harmony;

		private SharedData _pistolShared;

		private SharedData _ammoShared;

		private void Awake()
		{
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			Instance = this;
			EpicGunsConfig.Bind(this);
			EpicGunsConfig.SubscribeBalanceChanges(OnBalanceConfigChanged);
			EpicGunAssets.Initialize(((BaseUnityPlugin)this).Info.Location, ((BaseUnityPlugin)this).Logger);
			LongGuns.Initialize(this, ((BaseUnityPlugin)this).Logger);
			SpecialAmmo.Bind(this);
			FirearmAudio.Initialize(this, ((BaseUnityPlugin)this).Logger);
			LocalizationManager.Instance.AddToken("epicguns_1911", "1911", false);
			LocalizationManager.Instance.AddToken("epicguns_1911_desc", "A hard-hitting sidearm chambered in .45 ACP. Uses Bow skill and Bow-category magic effects.", false);
			LocalizationManager.Instance.AddToken("epicguns_45acp", ".45 ACP", false);
			LocalizationManager.Instance.AddToken("epicguns_45acp_desc", "Heavy pistol cartridges for the 1911.", false);
			LocalizationManager.Instance.AddToken("epicguns_ammo_45acp", ".45 ACP", false);
			GunshotClip = EpicGunAssets.LoadWave("1911_gunshot.wav", "EpicGuns_1911_Gunshot", ((BaseUnityPlugin)this).Logger);
			_harmony = new Harmony("com.triston.epicguns");
			_harmony.PatchAll();
			ItemManager.OnVanillaItemsAvailable += RegisterItems;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"EpicGuns 0.5.0 loaded. Waiting for vanilla item prefabs.");
		}

		private void OnDestroy()
		{
			ItemManager.OnVanillaItemsAvailable -= RegisterItems;
			EpicGunsConfig.UnsubscribeBalanceChanges(OnBalanceConfigChanged);
			SpecialAmmo.Shutdown();
			LongGuns.Shutdown();
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
		}

		private void RegisterItems()
		{
			ItemManager.OnVanillaItemsAvailable -= RegisterItems;
			try
			{
				RegisterAmmo();
				RegisterPistol();
				LongGuns.Register(((BaseUnityPlugin)this).Logger);
				SpecialAmmo.Register();
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Registered 1911, Pump Action, M16, and eight ammunition types. Epic Loot category: Bows.");
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("EpicGuns item registration failed: " + ex));
			}
		}

		private void RegisterAmmo()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			ItemConfig val = new ItemConfig();
			val.Name = "$epicguns_45acp";
			val.Description = "$epicguns_45acp_desc";
			val.Amount = 20;
			val.CraftingStation = CraftingStations.Forge;
			val.MinStationLevel = 1;
			val.StackSize = 200;
			val.Weight = 0.02f;
			val.Requirements = (RequirementConfig[])(object)new RequirementConfig[3]
			{
				new RequirementConfig("Copper", 1, 0, true),
				new RequirementConfig("Coal", 2, 0, true),
				new RequirementConfig("Resin", 1, 0, true)
			};
			ItemConfig val2 = val;
			Sprite val3 = EpicGunAssets.LoadSprite("45acp_icon.png");
			if ((Object)(object)val3 != (Object)null)
			{
				val2.Icon = val3;
			}
			CustomItem val4 = new CustomItem("EpicGuns_45ACP", "BoltBone", val2);
			SharedData val5 = (_ammoShared = val4.ItemDrop.m_itemData.m_shared);
			val5.m_itemType = (ItemType)9;
			if ((Object)(object)val3 != (Object)null)
			{
				val5.m_icons = (Sprite[])(object)new Sprite[1] { val3 };
			}
			val5.m_ammoType = "$epicguns_ammo_45acp";
			val5.m_maxStackSize = 200;
			val5.m_weight = 0.02f;
			val5.m_damages = default(DamageTypes);
			val5.m_damages.m_pierce = EpicGunsConfig.AmmoPierce.Value;
			val5.m_attackForce = 8f;
			val5.m_teleportable = true;
			if (val5.m_attack != null)
			{
				val5.m_attack.m_projectileVel = 0f;
				val5.m_attack.m_projectileVelMin = 0f;
				val5.m_attack.m_projectileAccuracy = 0f;
				val5.m_attack.m_projectileAccuracyMin = 0f;
				val5.m_attack.m_attackHitNoise = 8f;
				CreateBulletProjectile(val5);
			}
			ItemManager.Instance.AddItem(val4);
			((BaseUnityPlugin)this).Logger.LogInfo((object)".45 ACP recipe: 20 rounds from 1 Copper, 2 Coal, and 1 Resin at a level 1 Forge.");
		}

		private void RegisterPistol()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Expected O, but got Unknown
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Expected O, but got Unknown
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Expected O, but got Unknown
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Expected O, but got Unknown
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Expected O, but got Unknown
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Expected O, but got Unknown
			ItemConfig val = new ItemConfig();
			val.Name = "$epicguns_1911";
			val.Description = "$epicguns_1911_desc";
			val.Amount = 1;
			val.CraftingStation = CraftingStations.Forge;
			val.RepairStation = CraftingStations.Forge;
			val.MinStationLevel = 1;
			val.StackSize = 1;
			val.Weight = 1.8f;
			val.Requirements = (RequirementConfig[])(object)new RequirementConfig[3]
			{
				new RequirementConfig("Bronze", 8, 4, true),
				new RequirementConfig("FineWood", 4, 2, true),
				new RequirementConfig("DeerHide", 2, 1, true)
			};
			ItemConfig val2 = val;
			Sprite val3 = EpicGunAssets.LoadSprite("1911_icon.png");
			if ((Object)(object)val3 != (Object)null)
			{
				val2.Icon = val3;
			}
			CustomItem val4 = new CustomItem("EpicGuns_1911", "CrossbowArbalest", val2);
			SharedData shared = val4.ItemDrop.m_itemData.m_shared;
			shared.m_itemType = (ItemType)4;
			shared.m_attachOverride = (ItemType)3;
			shared.m_animationState = (AnimationState)1;
			if ((Object)(object)val3 != (Object)null)
			{
				shared.m_icons = (Sprite[])(object)new Sprite[1] { val3 };
			}
			shared.m_skillType = (SkillType)8;
			shared.m_ammoType = "$epicguns_ammo_45acp";
			shared.m_weight = 1.8f;
			shared.m_maxQuality = 4;
			shared.m_useDurability = true;
			shared.m_maxDurability = 250f;
			shared.m_durabilityPerLevel = 50f;
			shared.m_useDurabilityDrain = 1f;
			shared.m_canBeReparied = true;
			shared.m_damages = default(DamageTypes);
			shared.m_damages.m_pierce = EpicGunsConfig.WeaponPierce.Value;
			shared.m_damagesPerLevel = default(DamageTypes);
			shared.m_damagesPerLevel.m_pierce = 4f;
			shared.m_attackForce = 24f;
			shared.m_backstabBonus = 2f;
			shared.m_blockable = true;
			shared.m_dodgeable = true;
			shared.m_startEffect = new EffectList();
			shared.m_holdStartEffect = new EffectList();
			shared.m_triggerEffect = new EffectList();
			Attack attack = shared.m_attack;
			_pistolShared = shared;
			attack.m_attackStamina = EpicGunsConfig.StaminaPerShot.Value;
			attack.m_attackStartNoise = 35f;
			attack.m_attackHitNoise = 65f;
			attack.m_projectileVel = EpicGunsConfig.ProjectileSpeed.Value;
			attack.m_projectileVelMin = EpicGunsConfig.ProjectileSpeed.Value;
			attack.m_projectileAccuracy = 0.65f;
			attack.m_projectileAccuracyMin = 0.65f;
			attack.m_randomVelocity = false;
			attack.m_skillAccuracy = false;
			attack.m_projectiles = 1;
			attack.m_projectileBursts = 1;
			attack.m_requiresReload = true;
			attack.m_reloadTime = 1f / EpicGunsConfig.FireRate.Value;
			attack.m_reloadAnimation = string.Empty;
			attack.m_attackAnimation = "spear_poke";
			attack.m_recoilPushback = (EpicGunsConfig.DisableFiringPushback.Value ? 0f : EpicGunsConfig.FiringPushback.Value);
			attack.m_attackRange = 0.72f;
			attack.m_attackHeight = 1.28f;
			attack.m_attackOffset = 0.18f;
			attack.m_bowDraw = false;
			attack.m_startEffect = new EffectList();
			attack.m_triggerEffect = new EffectList();
			attack.m_burstEffect = FirearmAudio.Create("EpicGuns_1911_ShotSound", FirearmSoundKind.Pistol);
			PistolModel.ReplaceCrossbowVisual(val4.ItemPrefab, ((BaseUnityPlugin)this).Logger);
			ItemManager.Instance.AddItem(val4);
			((BaseUnityPlugin)this).Logger.LogInfo((object)("1911 stats: Bow item / Bows skill / .45 ACP / configurable damage and fire rate / right-arm pistol aim / firing pushback " + ((attack.m_recoilPushback <= 0f) ? "disabled." : (attack.m_recoilPushback.ToString("0.##") + "."))));
		}

		private void OnBalanceConfigChanged(object sender, EventArgs args)
		{
			ApplyConfiguredBalance();
		}

		private void ApplyConfiguredBalance()
		{
			LongGuns.Apply(null, EventArgs.Empty);
			SpecialAmmo.Apply(null, EventArgs.Empty);
			if (_ammoShared != null)
			{
				_ammoShared.m_damages.m_pierce = EpicGunsConfig.AmmoPierce.Value;
			}
			if (_pistolShared != null && _pistolShared.m_attack != null)
			{
				_pistolShared.m_damages.m_pierce = EpicGunsConfig.WeaponPierce.Value;
				Attack attack = _pistolShared.m_attack;
				attack.m_attackStamina = EpicGunsConfig.StaminaPerShot.Value;
				attack.m_projectileVel = EpicGunsConfig.ProjectileSpeed.Value;
				attack.m_projectileVelMin = EpicGunsConfig.ProjectileSpeed.Value;
				attack.m_reloadTime = 1f / EpicGunsConfig.FireRate.Value;
				attack.m_recoilPushback = (EpicGunsConfig.DisableFiringPushback.Value ? 0f : EpicGunsConfig.FiringPushback.Value);
			}
		}

		private static void CreateBulletProjectile(SharedData ammoShared)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			GameObject attackProjectile = ammoShared.m_attack.m_attackProjectile;
			if (!((Object)(object)attackProjectile == (Object)null))
			{
				GameObject val = PrefabManager.Instance.CreateClonedPrefab("EpicGuns_45ACP_Projectile", attackProjectile);
				BulletModel.ReplaceBoltVisual(val);
				PrefabManager.Instance.AddPrefab(new CustomPrefab(val, false));
				ammoShared.m_attack.m_attackProjectile = val;
			}
		}

		internal static bool Is1911(ItemData item)
		{
			if (item != null)
			{
				if (!((Object)(object)item.m_dropPrefab != (Object)null) || !((Object)item.m_dropPrefab).name.StartsWith("EpicGuns_1911", StringComparison.Ordinal))
				{
					return item.m_shared.m_name == "$epicguns_1911";
				}
				return true;
			}
			return false;
		}

		internal static bool IsEpicGun(ItemData item)
		{
			if (item != null)
			{
				if (!((Object)(object)item.m_dropPrefab != (Object)null) || !((Object)item.m_dropPrefab).name.StartsWith("EpicGuns_", StringComparison.Ordinal))
				{
					return item.m_shared.m_name.StartsWith("$epicguns_", StringComparison.Ordinal);
				}
				return true;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(Humanoid), "EquipItem")]
	internal static class FirearmRightHandPatch
	{
		private static void Prefix(ItemData item, out ItemType __state)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Invalid comparison between Unknown and I4
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected I4, but got Unknown
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			__state = (ItemType)0;
			if (EpicGunsPlugin.IsEpicGun(item) && (int)item.m_shared.m_itemType == 4)
			{
				__state = (ItemType)(int)item.m_shared.m_itemType;
				item.m_shared.m_itemType = (ItemType)(LongGuns.IsLongGun(item) ? 14 : 3);
			}
		}

		private static void Postfix(ItemData item, ItemType __state)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			RestoreItemType(item, __state);
		}

		private static Exception Finalizer(ItemData item, ItemType __state, Exception __exception)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			RestoreItemType(item, __state);
			return __exception;
		}

		private static void RestoreItemType(ItemData item, ItemType originalType)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			if (item != null && (int)originalType != 0)
			{
				item.m_shared.m_itemType = originalType;
			}
		}
	}
	internal enum FirearmSoundKind
	{
		Pistol,
		Shotgun,
		Rifle,
		PumpOpen,
		PumpClose
	}
	internal static class FirearmAudio
	{
		internal static AudioClip PumpOpenClip;

		internal static AudioClip PumpCloseClip;

		internal static EffectList PumpOpenEffect;

		internal static EffectList PumpCloseEffect;

		internal static ConfigEntry<float> PumpVolume;

		internal static ConfigEntry<bool> PumpEnabled;

		internal static void Initialize(EpicGunsPlugin plugin, ManualLogSource logger)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			PumpVolume = ((BaseUnityPlugin)plugin).Config.Bind<float>("Audio", "PumpVolume", 0.7f, new ConfigDescription("Local volume of the Pump Action's two-part reload sound.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			PumpEnabled = ((BaseUnityPlugin)plugin).Config.Bind<bool>("Audio", "PumpSoundEnabled", true, "Local pump cycling sounds at reload start and completion.");
			PumpOpenClip = EpicGunAssets.LoadWave("pump_open.wav", "EpicGuns_PumpOpen", logger);
			PumpCloseClip = EpicGunAssets.LoadWave("pump_close.wav", "EpicGuns_PumpClose", logger);
		}

		internal static void RegisterPump()
		{
			PumpOpenEffect = Create("EpicGuns_Pump_OpenSound", FirearmSoundKind.PumpOpen);
			PumpCloseEffect = Create("EpicGuns_Pump_CloseSound", FirearmSoundKind.PumpClose);
		}

		internal static EffectList Create(string name, FirearmSoundKind kind)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			GameObject val = PrefabManager.Instance.CreateEmptyPrefab(name, true);
			Object.DestroyImmediate((Object)(object)val.GetComponent<Collider>());
			Object.DestroyImmediate((Object)(object)val.GetComponent<MeshRenderer>());
			Object.DestroyImmediate((Object)(object)val.GetComponent<MeshFilter>());
			val.GetComponent<ZNetView>().m_persistent = false;
			val.AddComponent<FirearmSound>().Kind = kind;
			TimedDestruction obj = val.AddComponent<TimedDestruction>();
			obj.m_timeout = 2f;
			obj.m_triggerOnAwake = true;
			PrefabManager.Instance.AddPrefab(new CustomPrefab(val, false));
			EffectList val2 = new EffectList();
			val2.m_effectPrefabs = (EffectData[])(object)new EffectData[1]
			{
				new EffectData
				{
					m_prefab = val,
					m_enabled = true
				}
			};
			return val2;
		}
	}
	internal sealed class FirearmSound : MonoBehaviour
	{
		public FirearmSoundKind Kind;

		private void Start()
		{
			if (Application.isBatchMode)
			{
				return;
			}
			AudioClip val;
			float value;
			switch (Kind)
			{
			case FirearmSoundKind.Pistol:
				val = EpicGunsPlugin.GunshotClip;
				value = EpicGunsConfig.ShotVolume.Value;
				break;
			case FirearmSoundKind.Shotgun:
				val = LongGuns.ShotgunClip;
				value = LongGunConfig.Shotgun.Volume.Value;
				break;
			case FirearmSoundKind.Rifle:
				val = LongGuns.RifleClip;
				value = LongGunConfig.Rifle.Volume.Value;
				break;
			default:
				if (!FirearmAudio.PumpEnabled.Value)
				{
					return;
				}
				val = ((Kind == FirearmSoundKind.PumpOpen) ? FirearmAudio.PumpOpenClip : FirearmAudio.PumpCloseClip);
				value = FirearmAudio.PumpVolume.Value;
				break;
			}
			if (!((Object)(object)val == (Object)null))
			{
				AudioSource obj = ((Component)this).gameObject.AddComponent<AudioSource>();
				obj.clip = val;
				obj.volume = value;
				obj.pitch = Random.Range(0.98f, 1.02f);
				obj.spatialBlend = 1f;
				obj.minDistance = 5f;
				obj.maxDistance = ((Kind >= FirearmSoundKind.PumpOpen) ? 25 : 100);
				obj.rolloffMode = (AudioRolloffMode)0;
				obj.dopplerLevel = 0f;
				obj.Play();
			}
		}
	}
	[HarmonyPatch(typeof(Player), "QueueReloadAction")]
	internal static class PumpReloadStartPatch
	{
		private static void Postfix(List<MinorActionData> ___m_actionQueue)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Invalid comparison between Unknown and I4
			foreach (MinorActionData item in ___m_actionQueue)
			{
				if ((int)item.m_type == 2 && item.m_time == 0f && LongGuns.IsShotgun(item.m_item))
				{
					item.m_startEffect = FirearmAudio.PumpOpenEffect;
					item.m_doneAnimation = string.Empty;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Player), "UpdateActionQueue")]
	internal static class PumpReloadFinishPatch
	{
		private static void Prefix(List<MinorActionData> ___m_actionQueue, out MinorActionData __state)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Invalid comparison between Unknown and I4
			__state = ((___m_actionQueue.Count > 0) ? ___m_actionQueue[0] : null);
			if (__state != null && ((int)__state.m_type != 2 || !LongGuns.IsShotgun(__state.m_item)))
			{
				__state = null;
			}
		}

		private static void Postfix(Player __instance, MinorActionData __state, List<MinorActionData> ___m_actionQueue)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			if (__state != null && Completed(__state.m_time, __state.m_duration, ___m_actionQueue.Contains(__state)) && ((Humanoid)__instance).GetCurrentWeapon() == __state.m_item && ((Humanoid)__instance).IsWeaponLoaded())
			{
				EffectList pumpCloseEffect = FirearmAudio.PumpCloseEffect;
				if (pumpCloseEffect != null)
				{
					pumpCloseEffect.Create(((Character)__instance).GetCenterPoint(), Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID));
				}
			}
		}

		internal static bool Completed(float elapsed, float duration, bool stillQueued)
		{
			if (elapsed > duration)
			{
				return !stillQueued;
			}
			return false;
		}
	}
	internal sealed class LongGunSettings
	{
		internal ConfigEntry<float> Damage;

		internal ConfigEntry<float> UpgradeDamage;

		internal ConfigEntry<float> Speed;

		internal ConfigEntry<float> Spread;

		internal ConfigEntry<float> Reload;

		internal ConfigEntry<float> Stamina;

		internal ConfigEntry<float> Durability;

		internal ConfigEntry<float> Volume;

		internal ConfigEntry<int> Count;

		internal ConfigEntry<float> BurstInterval;

		internal ConfigEntry<int> Bronze;

		internal ConfigEntry<int> Tin;

		internal ConfigEntry<int> Iron;

		internal ConfigEntry<int> Wood;

		internal ConfigEntry<int> Leather;

		internal ConfigEntry<int> UpgradeMetal;
	}
	internal static class LongGunConfig
	{
		internal static LongGunSettings Shotgun;

		internal static LongGunSettings Rifle;

		internal static ConfigEntry<float> FireBonus;

		internal static ConfigEntry<float> ShellDamage;

		internal static ConfigEntry<float> RifleAmmoDamage;

		internal static ConfigEntry<int> ShellBatch;

		internal static ConfigEntry<int> BuckCopper;

		internal static ConfigEntry<int> BuckCoal;

		internal static ConfigEntry<int> DragonCopper;

		internal static ConfigEntry<int> DragonCoal;

		internal static ConfigEntry<int> RifleBatch;

		internal static ConfigEntry<int> RifleCopper;

		internal static ConfigEntry<int> RifleCoal;

		internal static ConfigEntry<int> RifleIron;

		internal static ConfigEntry<bool> Flames;

		internal static ConfigEntry<float> FlameWidth;

		internal static ConfigEntry<float> FlameLifetime;

		internal static event EventHandler Changed;

		internal static void Bind(EpicGunsPlugin plugin)
		{
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: Expected O, but got Unknown
			//IL_036c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Expected O, but got Unknown
			Shotgun = Weapon(plugin, "Shotgun", 40f, 6f, 65f, 6f, 1.8f, 10f, 300f, 12);
			Rifle = Weapon(plugin, "Assault Rifle", 18f, 3f, 110f, 1.4f, 1.1f, 6f, 400f, 3);
			Rifle.BurstInterval = Float(plugin, "Assault Rifle", "BurstInterval", 0.12f, "Seconds between rounds in a burst.", 0.06f, 0.5f);
			Shotgun.Bronze = Int(plugin, "Shotgun Recipe", "Bronze", 15, 1, 200);
			Shotgun.Tin = Int(plugin, "Shotgun Recipe", "Tin", 15, 1, 200);
			Shotgun.UpgradeMetal = Int(plugin, "Shotgun Recipe", "BronzePerUpgradeLevel", 5, 1, 100);
			Rifle.Iron = Int(plugin, "Assault Rifle Recipe", "Iron", 20, 1, 200);
			Rifle.Wood = Int(plugin, "Assault Rifle Recipe", "FineWood", 10, 1, 200);
			Rifle.Leather = Int(plugin, "Assault Rifle Recipe", "LeatherScraps", 5, 1, 200);
			Rifle.UpgradeMetal = Int(plugin, "Assault Rifle Recipe", "IronPerUpgradeLevel", 10, 1, 100);
			ShellDamage = Float(plugin, "12 Gauge Ammo", "PiercePerShell", 20f, "Total shell pierce divided across all pellets; added to weapon damage.", 0f, 500f);
			FireBonus = Float(plugin, "12 Gauge Ammo", "DragonFireBonus", 0.25f, "Extra fire as a fraction of the shot's pierce damage, including quality and damage modifiers.", 0f, 2f);
			ShellBatch = Int(plugin, "12 Gauge Ammo", "CraftAmount", 10, 1, 200);
			BuckCopper = Int(plugin, "12 Gauge Ammo", "BuckshotCopper", 1, 1, 100);
			BuckCoal = Int(plugin, "12 Gauge Ammo", "BuckshotCoal", 1, 1, 100);
			DragonCopper = Int(plugin, "12 Gauge Ammo", "DragonBreathCopper", 2, 1, 100);
			DragonCoal = Int(plugin, "12 Gauge Ammo", "DragonBreathCoal", 2, 1, 100);
			RifleAmmoDamage = Float(plugin, "Rifle Ammo", "PiercePerRound", 10f, "Pierce added to each rifle bullet.", 0f, 500f);
			RifleBatch = Int(plugin, "Rifle Ammo", "CraftAmount", 30, 1, 200);
			RifleCopper = Int(plugin, "Rifle Ammo", "Copper", 1, 1, 100);
			RifleCoal = Int(plugin, "Rifle Ammo", "Coal", 2, 1, 100);
			RifleIron = Int(plugin, "Rifle Ammo", "Iron", 1, 1, 100);
			Flames = ((BaseUnityPlugin)plugin).Config.Bind<bool>("Dragon Breath Visuals", "Enabled", true, "Local flame trail effects; does not change fire damage.");
			FlameWidth = ((BaseUnityPlugin)plugin).Config.Bind<float>("Dragon Breath Visuals", "Width", 0.12f, new ConfigDescription("Flame width in metres.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.02f, 0.4f), Array.Empty<object>()));
			FlameLifetime = ((BaseUnityPlugin)plugin).Config.Bind<float>("Dragon Breath Visuals", "Lifetime", 0.14f, new ConfigDescription("Flame trail duration in seconds.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.03f, 0.3f), Array.Empty<object>()));
		}

		private static LongGunSettings Weapon(EpicGunsPlugin p, string name, float damage, float upgrade, float speed, float spread, float reload, float stamina, float durability, int count)
		{
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Expected O, but got Unknown
			return new LongGunSettings
			{
				Damage = Float(p, name, "WeaponPierce", damage, "Weapon pierce. Shotgun value is the whole shot, not each pellet.", 0f, 1000f),
				UpgradeDamage = Float(p, name, "PiercePerQuality", upgrade, "Extra weapon pierce per quality level.", 0f, 100f),
				Speed = Float(p, name, "ProjectileSpeed", speed, "Projectile speed in metres per second.", 10f, 250f),
				Spread = Float(p, name, "SpreadDegrees", spread, "Maximum random spread per axis in degrees.", 0f, 25f),
				Reload = Float(p, name, "ReloadSeconds", reload, "Base reload between shots/bursts. Bows skill also affects reload.", 0.3f, 10f),
				Stamina = Float(p, name, "StaminaPerTrigger", stamina, "Stamina consumed per shot/burst.", 0f, 100f),
				Durability = Float(p, name, "Durability", durability, "Base weapon durability.", 10f, 2000f),
				Count = Int(p, name, (name == "Shotgun") ? "PelletCount" : "BurstRounds", count, 1, (name == "Shotgun") ? 24 : 6),
				Volume = ((BaseUnityPlugin)p).Config.Bind<float>("Audio", name.Replace(" ", "") + "Volume", 0.8f, new ConfigDescription("Local gunshot volume.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()))
			};
		}

		private static ConfigEntry<float> Float(EpicGunsPlugin p, string section, string key, float value, string description, float min, float max)
		{
			return Bind(p, section, key, value, description, (AcceptableValueBase)(object)new AcceptableValueRange<float>(min, max));
		}

		private static ConfigEntry<int> Int(EpicGunsPlugin p, string section, string key, int value, int min, int max)
		{
			return Bind(p, section, key, value, "Crafting count or projectile count, as named.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(min, max));
		}

		private static ConfigEntry<T> Bind<T>(EpicGunsPlugin p, string section, string key, T value, string description, AcceptableValueBase range)
		{
			//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_002c: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			ConfigEntry<T> obj = ((BaseUnityPlugin)p).Config.Bind<T>(section, key, value, new ConfigDescription(description + " [Synced with server]", range, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			obj.SettingChanged += delegate(object sender, EventArgs args)
			{
				LongGunConfig.Changed?.Invoke(sender, args);
			};
			return obj;
		}
	}
	internal static class LongGunModel
	{
		internal static void Replace(GameObject prefab, bool rifle, ManualLogSource logger)
		{
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a19: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a1e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a40: Unknown result type (might be due to invalid IL or missing references)
			//IL_09d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_09f2: Unknown result type (might be due to invalid IL or missing references)
			if (Application.isBatchMode)
			{
				return;
			}
			Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true);
			Material val = null;
			Renderer[] array = componentsInChildren;
			foreach (Renderer val2 in array)
			{
				if (val2 is MeshRenderer && (Object)(object)val2.sharedMaterial != (Object)null)
				{
					val = val2.sharedMaterial;
					break;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				logger.LogWarning((object)"No mesh material for long gun; keeping fallback model.");
				return;
			}
			array = componentsInChildren;
			for (int i = 0; i < array.Length; i++)
			{
				array[i].enabled = false;
			}
			Transform val3 = prefab.transform;
			Transform[] componentsInChildren2 = prefab.GetComponentsInChildren<Transform>(true);
			foreach (Transform val4 in componentsInChildren2)
			{
				if (((Object)val4).name == "attach")
				{
					val3 = val4;
					break;
				}
			}
			GameObject val5 = new GameObject("EpicGuns_LongGun_Model");
			val5.transform.SetParent(val3, false);
			val5.transform.localPosition = new Vector3(0f, 0.08f, 0.03f);
			Material m = Mat(val, "BluedSteel", new Color(0.09f, 0.11f, 0.13f), 0.8f);
			Material val6 = Mat(val, "DarkMetal", new Color(0.025f, 0.03f, 0.035f), 0.5f);
			Material val7 = Mat(val, "Walnut", new Color(0.27f, 0.105f, 0.035f), 0.05f);
			Material val8 = Mat(val, "BronzeFittings", new Color(0.55f, 0.31f, 0.095f), 0.8f);
			Transform transform = val5.transform;
			Box(transform, "Receiver", 0f, 0.035f, 0.07f, 0.064f, 0.085f, 0.24f, m);
			Box(transform, "TopCover", 0f, 0.084f, 0.065f, 0.058f, 0.02f, 0.23f, val6);
			Box(transform, "EjectionPort", 0.033f, 0.051f, 0.1f, 0.003f, 0.035f, 0.075f, val6);
			Box(transform, "Bolt", 0.035f, 0.05f, 0.08f, 0.003f, 0.022f, 0.036f, m);
			if (rifle)
			{
				Box(transform, "ChargingHandle", 0f, 0.07f, -0.064f, 0.076f, 0.012f, 0.019f, val6);
			}
			else
			{
				Box(transform, "ChargingHandle", 0.05f, 0.045f, 0.065f, 0.035f, 0.013f, 0.016f, m);
			}
			Box(transform, "Grip", 0f, -0.055f, -0.025f, 0.045f, 0.13f, 0.055f, rifle ? val6 : val7, -17f);
			Box(transform, "StockNeck", 0f, rifle ? 0.038f : 0.003f, -0.1f, 0.043f, 0.059f, 0.13f, rifle ? val6 : val7, (!rifle) ? (-8) : 0);
			Box(transform, "Stock", 0f, rifle ? 0.008f : (-0.025f), -0.23f, 0.059f, 0.11f, 0.22f, rifle ? val6 : val7, (!rifle) ? (-8) : 0);
			Box(transform, "ButtPad", 0f, rifle ? 0.008f : (-0.04f), -0.342f, 0.064f, 0.12f, 0.016f, val6, (!rifle) ? (-8) : 0);
			Box(transform, "Trigger", 0f, -0.035f, 0.035f, 0.008f, 0.034f, 0.01f, val8, -15f);
			Box(transform, "GuardFront", 0f, -0.04f, 0.079f, 0.009f, 0.05f, 0.009f, m, 12f);
			Box(transform, "GuardBase", 0f, -0.067f, 0.04f, 0.009f, 0.009f, 0.077f, m);
			Cylinder(transform, "Barrel", 0f, 0.052f, 0.37f, 0.033f, 0.4f, m);
			Cylinder(transform, "MuzzleCrown", 0f, 0.052f, 0.575f, 0.038f, 0.015f, m);
			Cylinder(transform, "Bore", 0f, 0.052f, 0.584f, 0.025f, 0.001f, val6);
			if (!rifle)
			{
				Box(transform, "FrontSight", 0f, 0.08f, 0.545f, 0.012f, 0.027f, 0.02f, val8);
				Box(transform, "RearSight", 0f, 0.102f, -0.012f, 0.032f, 0.02f, 0.014f, val6);
			}
			if (rifle)
			{
				Cylinder(transform, "Handguard", 0f, 0.045f, 0.286f, 0.074f, 0.215f, val6);
				for (int j = 0; j < 12; j++)
				{
					Cylinder(transform, "HandguardRib" + j, 0f, 0.045f, 0.19f + (float)j * 0.017f, 0.078f, 0.003f, m);
				}
				Box(transform, "CarryHandleRear", 0f, 0.112f, -0.015f, 0.029f, 0.054f, 0.022f, m);
				Box(transform, "CarryHandleFront", 0f, 0.11f, 0.118f, 0.026f, 0.05f, 0.022f, m, -18f);
				Box(transform, "CarryHandleBridge", 0f, 0.143f, 0.05f, 0.032f, 0.015f, 0.155f, m);
				Box(transform, "RearAperture", 0f, 0.155f, -0.014f, 0.025f, 0.012f, 0.013f, val6);
				Box(transform, "FrontTowerRear", 0f, 0.099f, 0.435f, 0.013f, 0.104f, 0.012f, m, 20f);
				Box(transform, "FrontTowerFront", 0f, 0.099f, 0.471f, 0.013f, 0.104f, 0.012f, m, -20f);
				Box(transform, "FrontPost", 0f, 0.153f, 0.453f, 0.009f, 0.024f, 0.014f, val6);
				Cylinder(transform, "FlashHider", 0f, 0.052f, 0.585f, 0.037f, 0.038f, val6);
				for (int k = 0; k < 4; k++)
				{
					Box(transform, "FlashHiderSlot" + k, 0.019f, 0.052f, 0.574f + (float)k * 0.007f, 0.001f, 0.009f, 0.003f, m);
				}
				Box(transform, "MagazineWell", 0f, -0.035f, 0.12f, 0.055f, 0.048f, 0.091f, val6, 2f);
				for (int l = 0; l < 4; l++)
				{
					Box(transform, "MagazineSegment" + l, 0f, -0.075f - (float)l * 0.037f, 0.121f + (float)(l * l) * 0.0015f, 0.037f, 0.045f, 0.07f, m, -l * 3);
					for (int n = -1; n <= 1; n += 2)
					{
						Box(transform, "MagazineRib" + n + l, (float)n * 0.02f, -0.075f - (float)l * 0.037f, 0.121f + (float)(l * l) * 0.0015f, 0.003f, 0.037f, 0.009f, val6, -l * 3);
					}
				}
			}
			else
			{
				Cylinder(transform, "MagazineTube", 0f, 0.003f, 0.32f, 0.034f, 0.3f, val6);
				Cylinder(transform, "MagazineCap", 0f, 0.003f, 0.478f, 0.037f, 0.018f, val8);
				Cylinder(transform, "Pump", 0f, 0.003f, 0.285f, 0.073f, 0.165f, val7);
				for (int num = 0; num < 9; num++)
				{
					Cylinder(transform, "PumpRib" + num, 0f, 0.003f, 0.215f + (float)num * 0.017f, 0.077f, 0.005f, val6);
				}
				for (int num2 = -1; num2 <= 1; num2 += 2)
				{
					Box(transform, "PumpRail" + num2, (float)num2 * 0.025f, 0.01f, 0.175f, 0.008f, 0.012f, 0.18f, m);
				}
			}
			for (int num3 = -1; num3 <= 1; num3 += 2)
			{
				for (int num4 = 0; num4 < 3; num4++)
				{
					Part(transform, "ReceiverPin", (PrimitiveType)0, new Vector3((float)num3 * 0.034f, 0.023f, (float)num4 * 0.065f), new Vector3(0.007f, 0.009f, 0.009f), Vector3.zero, val8);
				}
			}
			GameObject val9 = new GameObject("EpicGuns_SupportGrip");
			val9.transform.SetParent(transform, false);
			val9.transform.localPosition = new Vector3(0f, -0.036f, 0.25f);
			prefab.AddComponent<PistolVisualSafety>().Configure(val5, componentsInChildren, logger);
		}

		private static Material Mat(Material source, string name, Color color, float metal)
		{
			//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_0018: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			Material val = new Material(source)
			{
				name = "EpicGuns_" + name
			};
			if (val.HasProperty("_MainTex"))
			{
				val.SetTexture("_MainTex", (Texture)(object)Texture2D.whiteTexture);
			}
			string[] array = new string[2] { "_Color", "_BaseColor" };
			foreach (string text in array)
			{
				if (val.HasProperty(text))
				{
					val.SetColor(text, color);
				}
			}
			if (val.HasProperty("_Metallic"))
			{
				val.SetFloat("_Metallic", metal);
			}
			if (val.HasProperty("_Glossiness"))
			{
				val.SetFloat("_Glossiness", 0.42f);
			}
			return val;
		}

		private static void Box(Transform t, string n, float x, float y, float z, float w, float h, float d, Material m, float angle = 0f)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			Part(t, n, (PrimitiveType)3, new Vector3(x, y, z), new Vector3(w, h, d), new Vector3(angle, 0f, 0f), m);
		}

		private static void Cylinder(Transform t, string n, float x, float y, float z, float diameter, float length, Material m)
		{
			//IL_0007: 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_002c: Unknown result type (might be due to invalid IL or missing references)
			Part(t, n, (PrimitiveType)2, new Vector3(x, y, z), new Vector3(diameter, length / 2f, diameter), new Vector3(90f, 0f, 0f), m);
		}

		private static void Part(Transform parent, string name, PrimitiveType type, Vector3 position, Vector3 scale, Vector3 rotation, Material material)
		{
			//IL_0000: 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_002c: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = GameObject.CreatePrimitive(type);
			((Object)obj).name = name;
			obj.transform.SetParent(parent, false);
			obj.transform.localPosition = position;
			obj.transform.localScale = scale;
			obj.transform.localRotation = Quaternion.Euler(rotation);
			obj.layer = ((Component)parent).gameObject.layer;
			Object.DestroyImmediate((Object)(object)obj.GetComponent<Collider>());
			obj.GetComponent<Renderer>().sharedMaterial = material;
		}
	}
	internal sealed class FlamePelletVisual : MonoBehaviour
	{
		private static Material _flameMaterial;

		internal static void Configure(GameObject projectile)
		{
			if (!Application.isBatchMode)
			{
				BulletTracerController component = projectile.GetComponent<BulletTracerController>();
				if ((Object)(object)component != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)component);
				}
				projectile.AddComponent<FlamePelletVisual>();
			}
		}

		private void Start()
		{
			//IL_01a7: 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_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: 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_0207: 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_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: 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_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: 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_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Expected O, but got Unknown
			//IL_029c: 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_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: 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_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: 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_006d: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//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_00e6: Unknown result type (might be due to invalid IL or missing references)
			if (Application.isBatchMode)
			{
				return;
			}
			TrailRenderer component = ((Component)this).GetComponent<TrailRenderer>();
			if ((Object)(object)component != (Object)null)
			{
				component.emitting = false;
			}
			if (!LongGunConfig.Flames.Value)
			{
				return;
			}
			if ((Object)(object)_flameMaterial == (Object)null)
			{
				Shader val = Shader.Find("Legacy Shaders/Particles/Additive") ?? Shader.Find("Sprites/Default");
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				_flameMaterial = new Material(val);
				Texture2D val2 = new Texture2D(32, 32, (TextureFormat)4, false);
				((Texture)val2).wrapMode = (TextureWrapMode)1;
				for (int i = 0; i < 32; i++)
				{
					for (int j = 0; j < 32; j++)
					{
						Vector2 val3 = new Vector2(((float)j - 15.5f) / 16f, ((float)i - 15.5f) / 16f);
						float num = Mathf.Pow(Mathf.Clamp01(1f - ((Vector2)(ref val3)).magnitude), 2f);
						val2.SetPixel(j, i, new Color(1f, 1f, 1f, num));
					}
				}
				val2.Apply();
				_flameMaterial.mainTexture = (Texture)(object)val2;
			}
			if ((Object)(object)component != (Object)null)
			{
				((Renderer)component).sharedMaterial = _flameMaterial;
				component.time = LongGunConfig.FlameLifetime.Value;
				component.startWidth = LongGunConfig.FlameWidth.Value;
				component.endWidth = 0.008f;
				component.startColor = new Color(1f, 0.8f, 0.2f, 1f);
				component.endColor = new Color(1f, 0.1f, 0f, 0f);
				component.emitting = true;
			}
			GameObject val4 = new GameObject("FlameWisps");
			val4.transform.SetParent(((Component)this).transform, false);
			ParticleSystem val5 = val4.AddComponent<ParticleSystem>();
			val5.Stop(true, (ParticleSystemStopBehavior)0);
			MainModule main = val5.main;
			((MainModule)(ref main)).startLifetime = MinMaxCurve.op_Implicit(0.18f);
			((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(0.7f);
			((MainModule)(ref main)).startSize = MinMaxCurve.op_Implicit(LongGunConfig.FlameWidth.Value * 1.3f);
			((MainModule)(ref main)).maxParticles = 16;
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
			((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(new Color(1f, 0.42f, 0.035f, 0.8f));
			EmissionModule emission = val5.emission;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(35f);
			ShapeModule shape = val5.shape;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)0;
			((ShapeModule)(ref shape)).radius = 0.025f;
			ColorOverLifetimeModule colorOverLifetime = val5.colorOverLifetime;
			((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
			Gradient val6 = new Gradient();
			val6.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
			{
				new GradientColorKey(Color.yellow, 0f),
				new GradientColorKey(Color.red, 1f)
			}, (GradientAlphaKey[])(object)new GradientAlphaKey[2]
			{
				new GradientAlphaKey(0.9f, 0f),
				new GradientAlphaKey(0f, 1f)
			});
			((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(val6);
			((Renderer)((Component)val5).GetComponent<ParticleSystemRenderer>()).sharedMaterial = _flameMaterial;
			val5.Play();
		}
	}
	internal static class LongGuns
	{
		internal const string Shotgun = "EpicGuns_Shotgun";

		internal const string Rifle = "EpicGuns_AssaultRifle";

		internal const string Buckshot = "EpicGuns_Buckshot";

		internal const string Dragon = "EpicGuns_DragonBreath";

		internal const string RifleAmmo = "EpicGuns_RifleAmmo";

		private const string ShellType = "$epicguns_12g";

		private const string RifleType = "$epicguns_rifleammo";

		private static readonly Dictionary<string, CustomItem> Items = new Dictionary<string, CustomItem>();

		internal static AudioClip ShotgunClip;

		internal static AudioClip RifleClip;

		internal static bool IsShotgun(ItemData item)
		{
			return item?.m_shared.m_name == "$epicguns_shotgun";
		}

		internal static bool IsRifle(ItemData item)
		{
			return item?.m_shared.m_name == "$epicguns_assaultrifle";
		}

		internal static bool IsLongGun(ItemData item)
		{
			if (!IsShotgun(item))
			{
				return IsRifle(item);
			}
			return true;
		}

		internal static void Initialize(EpicGunsPlugin plugin, ManualLogSource logger)
		{
			LongGunConfig.Bind(plugin);
			LongGunConfig.Changed += Apply;
			Token("shotgun", "Pump Action");
			Token("shotgun_desc", "A bronze-fitted pump shotgun. Uses Bows skill. Damage shown is for the entire shot, divided across all pellets.");
			Token("assaultrifle", "M16");
			Token("assaultrifle_desc", "A Swamp-tier M16 chambered in 556. Fires a configurable automatic burst with one cartridge consumed per bullet. Uses Bows skill.");
			Token("12g", "12 Gauge");
			Token("buckshot", "12 Gauge Buckshot");
			Token("buckshot_desc", "A spread of lead pellets. Shell damage is divided across the whole shot.");
			Token("dragonbreath", "12 Gauge Dragon's Breath");
			Token("dragonbreath_desc", "Flaming pellets. Adds configurable bonus fire damage to the shot's pierce damage (25% by default).");
			Token("rifleammo", "556");
			Token("rifleammo_desc", "Standard 556 cartridges for the M16.");
			ShotgunClip = EpicGunAssets.LoadWave("shotgun_gunshot.wav", "EpicGuns_Shotgun_Report", logger);
			RifleClip = EpicGunAssets.LoadWave("rifle_gunshot.wav", "EpicGuns_Rifle_Report", logger);
		}

		internal static void Shutdown()
		{
			LongGunConfig.Changed -= Apply;
		}

		private static void Token(string key, string text)
		{
			LocalizationManager.Instance.AddToken("epicguns_" + key, text, false);
		}

		internal static void Register(ManualLogSource logger)
		{
			RegisterAmmo("EpicGuns_Buckshot", "buckshot", "$epicguns_12g", fire: false, rifle: false);
			RegisterAmmo("EpicGuns_DragonBreath", "dragonbreath", "$epicguns_12g", fire: true, rifle: false);
			RegisterAmmo("EpicGuns_RifleAmmo", "rifleammo", "$epicguns_rifleammo", fire: false, rifle: true);
			RegisterWeapon("EpicGuns_Shotgun", "shotgun", rifle: false, logger);
			RegisterWeapon("EpicGuns_AssaultRifle", "assaultrifle", rifle: true, logger);
			FirearmAudio.RegisterPump();
			Apply(null, EventArgs.Empty);
		}

		private static ItemConfig Config(string key, string icon, bool weapon, bool rifle)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: 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_002c: 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_0048: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			return new ItemConfig
			{
				Name = "$epicguns_" + key,
				Description = "$epicguns_" + key + "_desc",
				CraftingStation = CraftingStations.Forge,
				RepairStation = (weapon ? CraftingStations.Forge : null),
				MinStationLevel = ((!rifle) ? 1 : 2),
				Amount = 1,
				StackSize = (weapon ? 1 : 200),
				Weight = (weapon ? 4f : 0.03f),
				Icon = EpicGunAssets.LoadSprite(icon),
				Requirements = Requirements(key)
			};
		}

		private static RequirementConfig[] Requirements(string key)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Expected O, but got Unknown
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Expected O, but got Unknown
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Expected O, but got Unknown
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Expected O, but got Unknown
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Expected O, but got Unknown
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Expected O, but got Unknown
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Expected O, but got Unknown
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Expected O, but got Unknown
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Expected O, but got Unknown
			LongGunSettings shotgun = LongGunConfig.Shotgun;
			LongGunSettings rifle = LongGunConfig.Rifle;
			return key switch
			{
				"shotgun" => (RequirementConfig[])(object)new RequirementConfig[2]
				{
					new RequirementConfig("Bronze", shotgun.Bronze.Value, shotgun.UpgradeMetal.Value, true),
					new RequirementConfig("Tin", shotgun.Tin.Value, 0, true)
				}, 
				"assaultrifle" => (RequirementConfig[])(object)new RequirementConfig[3]
				{
					new RequirementConfig("Iron", rifle.Iron.Value, rifle.UpgradeMetal.Value, true),
					new RequirementConfig("FineWood", rifle.Wood.Value, 5, true),
					new RequirementConfig("LeatherScraps", rifle.Leather.Value, 2, true)
				}, 
				"buckshot" => (RequirementConfig[])(object)new RequirementConfig[2]
				{
					new RequirementConfig("Copper", LongGunConfig.BuckCopper.Value, 0, true),
					new RequirementConfig("Coal", LongGunConfig.BuckCoal.Value, 0, true)
				}, 
				"dragonbreath" => (RequirementConfig[])(object)new RequirementConfig[2]
				{
					new RequirementConfig("Copper", LongGunConfig.DragonCopper.Value, 0, true),
					new RequirementConfig("Coal", LongGunConfig.DragonCoal.Value, 0, true)
				}, 
				_ => (RequirementConfig[])(object)new RequirementConfig[3]
				{
					new RequirementConfig("Iron", LongGunConfig.RifleIron.Value, 0, true),
					new RequirementConfig("Copper", LongGunConfig.RifleCopper.Value, 0, true),
					new RequirementConfig("Coal", LongGunConfig.RifleCoal.Value, 0, true)
				}, 
			};
		}

		private static void RegisterAmmo(string name, string key, string type, bool fire, bool rifle)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_0055: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Expected O, but got Unknown
			ItemConfig val = Config(key, key + "_icon.png", weapon: false, rifle);
			val.Amount = (rifle ? LongGunConfig.RifleBatch.Value : LongGunConfig.ShellBatch.Value);
			CustomItem val2 = new CustomItem(name, "BoltBone", val);
			SharedData shared = val2.ItemDrop.m_itemData.m_shared;
			shared.m_itemType = (ItemType)9;
			shared.m_ammoType = type;
			shared.m_damages = default(DamageTypes);
			shared.m_damagesPerLevel = default(DamageTypes);
			shared.m_attackForce = 0f;
			shared.m_teleportable = true;
			Attack attack = shared.m_attack;
			attack.m_projectileVel = (attack.m_projectileVelMin = (attack.m_projectileAccuracy = (attack.m_projectileAccuracyMin = 0f)));
			attack.m_attackHitNoise = 0f;
			GameObject val3 = PrefabManager.Instance.CreateClonedPrefab(name + "_Projectile", attack.m_attackProjectile);
			Projectile component = val3.GetComponent<Projectile>();
			component.m_gravity = 0.3f;
			component.m_rayRadius = (rifle ? 0.015f : 0.025f);
			component.m_ttl = (rifle ? 2f : 0.75f);
			component.m_respawnItemOnHit = false;
			component.m_stayAfterHitDynamic = (component.m_stayAfterHitStatic = false);
			component.m_spawnOnHit = null;
			component.m_aoe = 0f;
			BulletModel.ReplaceBoltVisual(val3);
			if (fire)
			{
				FlamePelletVisual.Configure(val3);
			}
			PrefabManager.Instance.AddPrefab(new CustomPrefab(val3, false));
			attack.m_attackProjectile = val3;
			Items.Add(name, val2);
			ItemManager.Instance.AddItem(val2);
		}

		private static void RegisterWeapon(string name, string key, bool rifle, ManualLogSource logger)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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_0091: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Expected O, but got Unknown
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Expected O, but got Unknown
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Expected O, but got Unknown
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Expected O, but got Unknown
			CustomItem val = new CustomItem(name, "CrossbowArbalest", Config(key, key + "_icon.png", weapon: true, rifle));
			SharedData shared = val.ItemDrop.m_itemData.m_shared;
			shared.m_itemType = (ItemType)4;
			shared.m_attachOverride = (ItemType)3;
			shared.m_animationState = (AnimationState)1;
			shared.m_skillType = (SkillType)8;
			shared.m_ammoType = (rifle ? "$epicguns_rifleammo" : "$epicguns_12g");
			shared.m_maxQuality = 4;
			shared.m_useDurability = true;
			shared.m_canBeReparied = true;
			shared.m_durabilityPerLevel = 50f;
			shared.m_useDurabilityDrain = 1f;
			shared.m_damages = default(DamageTypes);
			shared.m_damagesPerLevel = default(DamageTypes);
			shared.m_attackForce = (rifle ? 12 : 30);
			shared.m_backstabBonus = 2f;
			shared.m_blockable = (shared.m_dodgeable = true);
			shared.m_startEffect = new EffectList();
			shared.m_holdStartEffect = new EffectList();
			shared.m_triggerEffect = new EffectList();
			Attack attack = shared.m_attack;
			attack.m_requiresReload = true;
			attack.m_reloadAnimation = string.Empty;
			attack.m_attackAnimation = "spear_poke";
			attack.m_bowDraw = (attack.m_skillAccuracy = (attack.m_randomVelocity = false));
			attack.m_perBurstResourceUsage = false;
			attack.m_destroyPreviousProjectile = false;
			attack.m_attackRange = 0.85f;
			attack.m_attackHeight = 1.28f;
			attack.m_attackOffset = 0.18f;
			attack.m_attackStartNoise = 45f;
			attack.m_attackHitNoise = 70f;
			attack.m_startEffect = new EffectList();
			attack.m_triggerEffect = new EffectList();
			attack.m_burstEffect = SoundEffect(name, rifle);
			LongGunModel.Replace(val.ItemPrefab, rifle, logger);
			Items.Add(name, val);
			ItemManager.Instance.AddItem(val);
		}

		private static EffectList SoundEffect(string name, bool rifle)
		{
			return FirearmAudio.Create(name + "_ShotSound", (!rifle) ? FirearmSoundKind.Shotgun : FirearmSoundKind.Rifle);
		}

		internal static void Apply(object sender, EventArgs args)
		{
			foreach (KeyValuePair<string, CustomItem> item in Items)
			{
				CustomItem value = item.Value;
				SharedData shared = value.ItemDrop.m_itemData.m_shared;
				bool flag = item.Key == "EpicGuns_Shotgun" || item.Key == "EpicGuns_AssaultRifle";
				bool flag2 = item.Key == "EpicGuns_AssaultRifle" || item.Key == "EpicGuns_RifleAmmo";
				if (flag)
				{
					LongGunSettings longGunSettings = (flag2 ? LongGunConfig.Rifle : LongGunConfig.Shotgun);
					shared.m_damages.m_pierce = longGunSettings.Damage.Value;
					shared.m_damagesPerLevel.m_pierce = longGunSettings.UpgradeDamage.Value;
					shared.m_maxDurability = longGunSettings.Durability.Value;
					Attack attack = shared.m_attack;
					attack.m_attackStamina = longGunSettings.Stamina.Value;
					attack.m_projectileVel = (attack.m_projectileVelMin = longGunSettings.Speed.Value);
					attack.m_projectileAccuracy = (attack.m_projectileAccuracyMin = longGunSettings.Spread.Value);
					attack.m_reloadTime = longGunSettings.Reload.Value;
					attack.m_projectiles = (flag2 ? 1 : longGunSettings.Count.Value);
					attack.m_projectileBursts = ((!flag2) ? 1 : longGunSettings.Count.Value);
					attack.m_burstInterval = (flag2 ? longGunSettings.BurstInterval.Value : 0f);
					attack.m_recoilPushback = (EpicGunsConfig.DisableFiringPushback.Value ? 0f : EpicGunsConfig.FiringPushback.Value);
				}
				else
				{
					shared.m_damages.m_pierce = (flag2 ? LongGunConfig.RifleAmmoDamage.Value : LongGunConfig.ShellDamage.Value);
				}
				CustomRecipe recipe = value.Recipe;
				Recipe val = ((recipe != null) ? recipe.Recipe : null);
				if (!((Object)(object)val == (Object)null))
				{
					val.m_amount = (flag ? 1 : (flag2 ? LongGunConfig.RifleBatch.Value : LongGunConfig.ShellBatch.Value));
					RequirementConfig[] array = Requirements(shared.m_name.Substring("$epicguns_".Length));
					for (int i = 0; i < val.m_resources.Length && i < array.Length; i++)
					{
						val.m_resources[i].m_amount = array[i].Amount;
						val.m_resources[i].m_amountPerLevel = array[i].AmountPerLevel;
					}
				}
			}
		}
	}
	[HarmonyPatch(typeof(Projectile), "Setup")]
	internal static class ShotgunDamagePatch
	{
		[HarmonyPriority(0)]
		private static void Prefix(HitData hitData, ItemData item, ItemData ammo)
		{
			if (LongGuns.IsShotgun(item) && hitData != null)
			{
				float num = LongGunConfig.Shotgun.Count.Value;
				((DamageTypes)(ref hitData.m_damage)).Modify(1f / num);
				hitData.m_pushForce /= num;
				hitData.m_skillRaiseAmount /= num;
				if (ammo?.m_shared.m_name == "$epicguns_dragonbreath")
				{
					hitData.m_damage.m_fire += hitData.m_damage.m_pierce * LongGunConfig.FireBonus.Value;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Attack), "FireProjectileBurst")]
	internal static class RifleAmmoPatch
	{
		private static readonly MethodInfo UseAmmo = AccessTools.Method(typeof(Attack), "UseAmmo", (Type[])null, (Type[])null);

		private static bool Prefix(Attack __instance, ItemData ___m_weapon, int ___m_projectileBurstsFired, ref ItemData ___m_lastUsedAmmo)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			if (!LongGuns.IsRifle(___m_weapon) || ___m_projectileBurstsFired == 0)
			{
				return true;
			}
			object[] array = new object[1];
			if (!(bool)UseAmmo.Invoke(__instance, array))
			{
				__instance.Stop();
				return false;
			}
			___m_lastUsedAmmo = (ItemData)array[0];
			return true;
		}
	}
	[HarmonyPatch(typeof(Attack), "Update")]
	internal static class RifleBurstLifetimePatch
	{
		private static void Prefix(ItemData ___m_weapon, Character ___m_character, bool ___m_projectileAttackStarted, int ___m_projectileBurstsFired, bool ___m_abortAttack, Attack __instance, ref bool ___m_wasInAttack, out bool __state)
		{
			__state = (LongGuns.IsRifle(___m_weapon) & ___m_wasInAttack) && ___m_projectileAttackStarted && ___m_projectileBurstsFired < __instance.m_projectileBursts && !___m_abortAttack && !___m_character.IsStaggering() && !___m_character.InAttack();
			if (__state)
			{
				___m_wasInAttack = false;
			}
		}

		private static void Postfix(bool __state, bool ___m_attackDone, ref bool ___m_wasInAttack)
		{
			if (__state && !___m_attackDone)
			{
				___m_wasInAttack = true;
			}
		}
	}
	[DefaultExecutionOrder(10000)]
	internal sealed class PistolAimController : MonoBehaviour
	{
		private static readonly FieldRef<Humanoid, ItemData> LeftItem = AccessTools.FieldRefAccess<Humanoid, ItemData>("m_leftItem");

		private Player _player;

		private Animator _animator;

		private Transform _upperArm;

		private Transform _lowerArm;

		private Transform _hand;

		private Transform _leftUpperArm;

		private Transform _leftLowerArm;

		private Transform _leftHand;

		private Transform _model;

		private Transform[] _posedBones;

		private Quaternion[] _animatedRotations;

		private bool _poseApplied;

		private void Awake()
		{
			_player = ((Component)this).GetComponent<Player>();
		}

		private void Update()
		{
			RestorePose();
		}

		private void OnDisable()
		{
			RestorePose();
		}

		private void RestorePose()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			if (!_poseApplied)
			{
				return;
			}
			for (int i = 0; i < _posedBones.Length; i++)
			{
				if ((Object)(object)_posedBones[i] != (Object)null)
				{
					_posedBones[i].localRotation = _animatedRotations[i];
				}
			}
			_poseApplied = false;
		}

		private void LateUpdate()
		{
			//IL_00ff: 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_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: 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)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: 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_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: 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_040a: Unknown result type (might be due to invalid IL or missing references)
			//IL_040f: Unknown result type (might be due to invalid IL or missing references)
			//IL_041f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0429: Unknown result type (might be due to invalid IL or missing references)
			//IL_042e: Unknown result type (might be due to invalid IL or missing references)
			//IL_043e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0448: Unknown result type (might be due to invalid IL or missing references)
			//IL_044d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0452: Unknown result type (might be due to invalid IL or missing references)
			//IL_0456: Unknown result type (might be due to invalid IL or missing references)
			//IL_045b: Unknown result type (might be due to invalid IL or missing references)
			//IL_046f: Unknown result type (might be due to invalid IL or missing references)
			//IL_047c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: Unknown result type (might be due to invalid IL or missing references)
			//IL_0358: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0365: Unknown result type (might be due to invalid IL or missing references)
			//IL_0370: Unknown result type (might be due to invalid IL or missing references)
			//IL_0380: Unknown result type (might be due to invalid IL or missing references)
			//IL_038b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03db: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_player == (Object)null || !EpicGunsConfig.OneHandedAimPose.Value || (!EpicGunsPlugin.Is1911(((Humanoid)_player).GetCurrentWeapon()) && !LongGuns.IsLongGun(((Humanoid)_player).GetCurrentWeapon())) || !FindArmBones())
			{
				return;
			}
			bool flag = LongGuns.IsLongGun(((Humanoid)_player).GetCurrentWeapon());
			string text = (flag ? "EpicGuns_LongGun_Model" : "EpicGuns_1911_Model");
			VisEquipment visEquipment = ((Humanoid)_player).GetVisEquipment();
			if ((Object)(object)visEquipment == (Object)null || (Object)(object)visEquipment.m_rightHand == (Object)null)
			{
				return;
			}
			if ((Object)(object)_model == (Object)null || ((Object)_model).name != text || !_model.IsChildOf(visEquipment.m_rightHand))
			{
				_model = FindNamed(visEquipment.m_rightHand, text);
			}
			if ((Object)(object)_model == (Object)null || !((Component)_model).gameObject.activeInHierarchy)
			{
				return;
			}
			Vector3 val = ((Humanoid)_player).GetAimDir(_upperArm.position);
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			if (((Vector3)(ref normalized)).sqrMagnitude < 0.5f)
			{
				return;
			}
			val = Quaternion.AngleAxis(EpicGunsConfig.AimYawOffset.Value, ((Component)_player).transform.up) * Quaternion.AngleAxis(EpicGunsConfig.AimPitchOffset.Value, ((Component)_player).transform.right) * normalized;
			normalized = ((Vector3)(ref val)).normalized;
			for (int i = 0; i < _posedBones.Length; i++)
			{
				if ((Object)(object)_posedBones[i] != (Object)null)
				{
					_animatedRotations[i] = _posedBones[i].localRotation;
				}
			}
			_poseApplied = true;
			Vector3 poleDirection = ((Component)_player).transform.right * EpicGunsConfig.ElbowOut.Value - ((Component)_player).transform.up * EpicGunsConfig.ElbowDown.Value;
			PoseArm(_upperArm, _lowerArm, _hand, normalized, poleDirection, flag ? 0.65f : EpicGunsConfig.ArmExtension.Value);
			val = Vector3.ProjectOnPlane(((Component)_player).transform.up, normalized);
			Vector3 val2 = ((Vector3)(ref val)).normalized;
			if (((Vector3)(ref val2)).sqrMagnitude < 0.01f)
			{
				val2 = ((Component)_player).transform.forward;
			}
			Quaternion val3 = Quaternion.LookRotation(normalized, val2) * Quaternion.AngleAxis(EpicGunsConfig.AimRollOffset.Value, Vector3.forward);
			_hand.rotation = val3 * Quaternion.Inverse(_model.rotation) * _hand.rotation;
			if (LeftItem.Invoke((Humanoid)(object)_player) != null || ((Character)_player).IsBlocking() || !((Object)(object)_leftUpperArm != (Object)null) || !((Object)(object)_leftLowerArm != (Object)null) || !((Object)(object)_leftHand != (Object)null))
			{
				return;
			}
			if (flag)
			{
				Transform val4 = FindNamed(_model, "EpicGuns_SupportGrip");
				if ((Object)(object)val4 != (Object)null)
				{
					Vector3 val5 = val4.position - _leftUpperArm.position;
					float num = Vector3.Distance(_leftUpperArm.position, _leftLowerArm.position) + Vector3.Distance(_leftLowerArm.position, _leftHand.position);
					PoseArm(_leftUpperArm, _leftLowerArm, _leftHand, ((Vector3)(ref val5)).normalized, -((Component)_player).transform.up - ((Component)_player).transform.right * 0.4f, ((Vector3)(ref val5)).magnitude / Mathf.Max(0.01f, num));
				}
			}
			else
			{
				val = -((Component)_player).transform.up - ((Component)_player).transform.right * 0.12f + ((Component)_player).transform.forward * 0.08f;
				Vector3 normalized2 = ((Vector3)(ref val)).normalized;
				PoseArm(_leftUpperArm, _leftLowerArm, _leftHand, normalized2, ((Component)_player).transform.forward, 0.96f);
			}
		}

		private static void PoseArm(Transform upper, Transform lower, Transform hand, Vector3 direction, Vector3 poleDirection, float extension)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: 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_00e2: 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_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_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: 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_0109: 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_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: 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_013d: 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_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			float num = Vector3.Distance(upper.position, lower.position);
			float num2 = Vector3.Distance(lower.position, hand.position);
			if (!(num < 0.01f) && !(num2 < 0.01f))
			{
				float num3 = Mathf.Clamp((num + num2) * extension, Mathf.Abs(num - num2) + 0.001f, num + num2 - 0.001f);
				Vector3 val = Vector3.ProjectOnPlane(poleDirection, direction);
				Vector3 normalized = ((Vector3)(ref val)).normalized;
				if (((Vector3)(ref normalized)).sqrMagnitude < 0.01f)
				{
					val = Vector3.Cross(direction, (Mathf.Abs(direction.y) < 0.9f) ? Vector3.up : Vector3.right);
					normalized = ((Vector3)(ref val)).normalized;
				}
				Vector3 position = upper.position;
				float num4 = (num * num - num2 * num2 + num3 * num3) / (2f * num3);
				float num5 = Mathf.Sqrt(Mathf.Max(0f, num * num - num4 * num4));
				Vector3 val2 = position + direction * num4 + normalized * num5;
				upper.rotation = Quaternion.FromToRotation(lower.position - position, val2 - position) * upper.rotation;
				lower.rotation = Quaternion.FromToRotation(hand.position - lower.position, position + direction * num3 - lower.position) * lower.rotation;
			}
		}

		private bool FindArmBones()
		{
			if ((Object)(object)_upperArm != (Object)null && (Object)(object)_lowerArm != (Object)null && (Object)(object)_hand != (Object)null)
			{
				return true;
			}
			_animator = ((Component)this).GetComponentInChildren<Animator>();
			if ((Object)(object)_animator == (Object)null)
			{
				return false;
			}
			_upperArm = FindBone((HumanBodyBones)14, "RightArm");
			_lowerArm = FindBone((HumanBodyBones)16, "RightForeArm");
			_hand = FindBone((HumanBodyBones)18, "RightHand");
			_leftUpperArm = FindBone((HumanBodyBones)13, "LeftArm");
			_leftLowerArm = FindBone((HumanBodyBones)15, "LeftForeArm");
			_leftHand = FindBone((HumanBodyBones)17, "LeftHand");
			if ((Object)(object)_upperArm == (Object)null || (Object)(object)_lowerArm == (Object)null || (Object)(object)_hand == (Object)null)
			{
				return false;
			}
			_posedBones = (Transform[])(object)new Transform[6] { _upperArm, _lowerArm, _hand, _leftUpperArm, _leftLowerArm, _leftHand };
			_animatedRotations = (Quaternion[])(object)new Quaternion[_posedBones.Length];
			return true;
		}

		private Transform FindBone(HumanBodyBones bone, string fallback)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			Transform val = (_animator.isHuman ? _animator.GetBoneTransform(bone) : null);
			if (!((Object)(object)val != (Object)null))
			{
				return FindNamed(((Component)_animator).transform, fallback);
			}
			return val;
		}

		private static Transform FindNamed(Transform root, string name)
		{
			Transform[] componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				if (((Object)val).name == name)
				{
					return val;
				}
			}
			return null;
		}
	}
	[HarmonyPatch(typeof(Player), "Awake")]
	internal static class PlayerAwakePatch
	{
		private static void Postfix(Player __instance)
		{
			if (!Application.isBatchMode && (Object)(object)((Component)__instance).GetComponent<PistolAimController>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<PistolAimController>();
			}
		}
	}
	internal static class PistolModel
	{
		internal static void ReplaceCrossbowVisual(GameObject prefab, ManualLogSource logger)
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			//IL_00a4: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: 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_01c9: 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_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0322: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: Unknown result type (might be due to invalid IL or missing references)
			//IL_036c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_0382: Unknown result type (might be due to invalid IL or missing refe