Decompiled source of Armaments v1.0.1

EdnKrs.Armament.dll

Decompiled a year ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Agents;
using Armament.ArmorPiercingFragmentation;
using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using FX_EffectSystem;
using GameData;
using Gear;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using Player;
using SNetwork;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("EdnKrs.Armament")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("EdnKrs.Armament")]
[assembly: AssemblyTitle("EdnKrs.Armament")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace Armament
{
	internal static class ModuleInfo
	{
		public const string GUID = "EdnKrs.Armament";

		public const string Name = "Armament";

		public const string Version = "1.1.0";
	}
	[BepInPlugin("EdnKrs.Armament", "Armament", "1.1.0")]
	internal class Injection : BasePlugin
	{
		private static Harmony? harmony;

		public override void Load()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			harmony = new Harmony("EdnKrs.Armament");
			new Harmony("Armament").PatchAll();
		}
	}
	internal static class Logging
	{
		private static readonly ManualLogSource _logger;

		static Logging()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			_logger = new ManualLogSource("Armament");
			Logger.Sources.Add((ILogSource)(object)_logger);
		}

		private static string Format(object msg)
		{
			return msg.ToString();
		}

		public static void Info(object data)
		{
			_logger.LogMessage((object)Format(data));
		}

		public static void Verbose(object data)
		{
		}

		public static void Debug(object data)
		{
			_logger.LogDebug((object)Format(data));
		}

		public static void Error(object data)
		{
			_logger.LogError((object)Format(data));
		}
	}
}
namespace Armament.ShellcasingsBulletHoles
{
	[HarmonyPatch]
	public class ShellcasingsBulletHolesPatches
	{
		[HarmonyPatch(typeof(WeaponShellManager), "SetupPools")]
		[HarmonyPostfix]
		public static void SetupPools(WeaponShellManager __instance)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			for (int i = 0; i < ((Il2CppArrayBase<GameObjectPool>)(object)__instance.m_shellPools).Length; i++)
			{
				((Il2CppArrayBase<GameObjectPool>)(object)__instance.m_shellPools)[i] = new GameObjectPool();
			}
			int num = 60;
			((Il2CppArrayBase<GameObjectPool>)(object)__instance.m_shellPools)[1].Setup(__instance.m_shell_9mm_prefab, num, (GameObjectPoolType)1, "Shell_9x18mm_Pool");
			((Il2CppArrayBase<GameObjectPool>)(object)__instance.m_shellPools)[2].Setup(__instance.m_shell_45_ACP_prefab, num, (GameObjectPoolType)1, "Shell_45_ACP_Pool");
			((Il2CppArrayBase<GameObjectPool>)(object)__instance.m_shellPools)[3].Setup(__instance.m_shell_338_prefab, num, (GameObjectPoolType)1, "Shell_338_Pool");
			((Il2CppArrayBase<GameObjectPool>)(object)__instance.m_shellPools)[4].Setup(__instance.m_shell_12_Gauge_prefab, num, (GameObjectPoolType)1, "Shell_Mos_590_Pool");
			for (int j = 1; j < ((Il2CppArrayBase<GameObjectPool>)(object)__instance.m_shellPools).Length; j++)
			{
				((Il2CppArrayBase<GameObjectPool>)(object)__instance.m_shellPools)[j].GetRootObject().transform.SetParent(__instance.m_root.transform);
				List<GameObject> list = new List<GameObject>();
				Enumerator<GameObject> enumerator = ((Il2CppArrayBase<GameObjectPool>)(object)__instance.m_shellPools)[j].GetAllObjects().GetEnumerator();
				while (enumerator.MoveNext())
				{
					GameObject current = enumerator.Current;
					list.Add(current);
				}
				for (int k = 0; k < list.Count; k++)
				{
					list[k].AddComponent<DisableAfterDelay>().delay = 60f;
				}
			}
		}

		[HarmonyPatch(typeof(FX_Decal), "PostInstantiateInitialize")]
		[HarmonyPostfix]
		public static void PostInstantiateInitialize(FX_Decal __instance)
		{
			__instance.m_uniqueLifeTime = (((FX_EffectContent)__instance).m_lifeTime + Random.value * __instance.m_lifeVariation) * 2f;
			if (__instance.m_feedMaterialLife)
			{
				__instance.m_instancedMaterialRef = Object.Instantiate<Material>(__instance.m_decal.m_decalMaterial);
				__instance.m_decal.m_decalMaterial = __instance.m_instancedMaterialRef;
				__instance.m_fadeoutMod = 1f / __instance.m_uniqueLifeTime * (1f / __instance.m_feedMaterialLifeStartAt);
				__instance.m_decal.m_decalMaterial.SetFloat(FX_Decal.s_decalLifeIDHash, __instance.m_fadeoutMod);
			}
		}
	}
}
namespace Armament.SentryGuns
{
	[HarmonyPatch]
	internal class SentryGunsPatches
	{
		[HarmonyPatch(typeof(SentryGunInstance_Firing_Bullets), "FireBullet")]
		[HarmonyPrefix]
		public static bool FireBullet(SentryGunInstance_Firing_Bullets __instance, bool doDamage, bool targetIsTagged)
		{
			//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: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: 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_0375: Unknown result type (might be due to invalid IL or missing references)
			//IL_037f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0384: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: 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_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0312: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: 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_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: 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_0252: Unknown result type (might be due to invalid IL or missing references)
			SentryGunInstance_Firing_Bullets.s_weaponRayData = new WeaponHitData
			{
				randomSpread = __instance.m_archetypeData.HipFireSpread,
				fireDir = __instance.MuzzleAlign.forward
			};
			Vector3 val = default(Vector3);
			if (__instance.m_archetypeData.Sentry_FireTowardsTargetInsteadOfForward && __instance.m_core.TryGetTargetAimPos(ref val))
			{
				WeaponHitData s_weaponRayData = SentryGunInstance_Firing_Bullets.s_weaponRayData;
				Vector3 val2 = val - __instance.MuzzleAlign.position;
				s_weaponRayData.fireDir = ((Vector3)(ref val2)).normalized;
			}
			WeaponHitData s_weaponRayData2 = SentryGunInstance_Firing_Bullets.s_weaponRayData;
			if (Weapon.CastWeaponRay(__instance.MuzzleAlign, ref s_weaponRayData2, LayerManager.MASK_SENTRYGUN_RAY))
			{
				SentryGunInstance_Firing_Bullets.s_weaponRayData = s_weaponRayData2;
				WeaponHitData s_weaponRayData3 = SentryGunInstance_Firing_Bullets.s_weaponRayData;
				ArchetypeDataBlock archetypeData = __instance.m_archetypeData;
				PlayerAgent owner = SentryGunInstance_Firing_Bullets.s_weaponRayData.owner;
				RaycastHit rayHit = SentryGunInstance_Firing_Bullets.s_weaponRayData.rayHit;
				s_weaponRayData3.damage = archetypeData.GetSentryDamage(owner, ((RaycastHit)(ref rayHit)).distance, targetIsTagged);
				SentryGunInstance_Firing_Bullets.s_weaponRayData.staggerMulti = __instance.m_archetypeData.GetSentryStaggerDamage(targetIsTagged);
				SentryGunInstance_Firing_Bullets.s_weaponRayData.precisionMulti = __instance.m_archetypeData.PrecisionDamageMulti;
				SentryGunInstance_Firing_Bullets.s_weaponRayData.damageFalloff = __instance.m_archetypeData.DamageFalloff * 3.118503f;
				SentryGunInstance_Firing_Bullets.s_weaponRayData.vfxBulletHit = __instance.m_vfxBulletHit;
				if (__instance.m_archetypeData.PiercingBullets)
				{
					int num = 5;
					int num2 = 0;
					bool flag = false;
					float num3 = 0f;
					int num4 = 0;
					Vector3 val3 = __instance.MuzzleAlign.position;
					while (!flag && num2 < num && SentryGunInstance_Firing_Bullets.s_weaponRayData.maxRayDist > 0f && num4 < __instance.m_archetypeData.PiercingDamageCountLimit)
					{
						if (Weapon.CastWeaponRay(__instance.MuzzleAlign, ref s_weaponRayData2, val3, LayerManager.MASK_SENTRYGUN_RAY))
						{
							SentryGunInstance_Firing_Bullets.s_weaponRayData = s_weaponRayData2;
							if (BulletWeapon.BulletHit(SentryGunInstance_Firing_Bullets.s_weaponRayData, doDamage, 0f, 0u, true))
							{
								num4++;
							}
							rayHit = SentryGunInstance_Firing_Bullets.s_weaponRayData.rayHit;
							FX_Manager.EffectTargetPosition = ((RaycastHit)(ref rayHit)).point;
							rayHit = SentryGunInstance_Firing_Bullets.s_weaponRayData.rayHit;
							flag = !CustomExtensions.IsInLayerMask(((Component)((RaycastHit)(ref rayHit)).collider).gameObject, LayerMask.op_Implicit(LayerManager.MASK_BULLETWEAPON_PIERCING_PASS));
							rayHit = SentryGunInstance_Firing_Bullets.s_weaponRayData.rayHit;
							val3 = ((RaycastHit)(ref rayHit)).point + SentryGunInstance_Firing_Bullets.s_weaponRayData.fireDir * 0.1f;
							float num5 = num3;
							rayHit = SentryGunInstance_Firing_Bullets.s_weaponRayData.rayHit;
							num3 = num5 + ((RaycastHit)(ref rayHit)).distance;
							WeaponHitData s_weaponRayData4 = SentryGunInstance_Firing_Bullets.s_weaponRayData;
							float maxRayDist = s_weaponRayData4.maxRayDist;
							rayHit = SentryGunInstance_Firing_Bullets.s_weaponRayData.rayHit;
							s_weaponRayData4.maxRayDist = maxRayDist - ((RaycastHit)(ref rayHit)).distance;
						}
						else
						{
							flag = true;
							FX_Manager.EffectTargetPosition = __instance.MuzzleAlign.position + __instance.MuzzleAlign.forward * 50f;
						}
						num2++;
					}
				}
				else if (Weapon.CastWeaponRay(__instance.MuzzleAlign, ref s_weaponRayData2, LayerManager.MASK_SENTRYGUN_RAY))
				{
					SentryGunInstance_Firing_Bullets.s_weaponRayData = s_weaponRayData2;
					BulletWeapon.BulletHit(SentryGunInstance_Firing_Bullets.s_weaponRayData, doDamage, 0f, 0u, true);
					rayHit = SentryGunInstance_Firing_Bullets.s_weaponRayData.rayHit;
					FX_Manager.EffectTargetPosition = ((RaycastHit)(ref rayHit)).point;
				}
				else
				{
					FX_Manager.EffectTargetPosition = __instance.MuzzleAlign.position + __instance.MuzzleAlign.forward * 50f;
				}
			}
			Action onBulletFired = __instance.OnBulletFired;
			if (onBulletFired != null)
			{
				onBulletFired.Invoke();
			}
			((FX_EffectBase)SentryGunInstance_Firing_Bullets.s_tracerPool.AquireEffect()).Play((FX_Trigger)null, __instance.MuzzleAlign.position, Quaternion.LookRotation(SentryGunInstance_Firing_Bullets.s_weaponRayData.fireDir));
			EX_SpriteMuzzleFlash muzzleFlash = __instance.m_muzzleFlash;
			if (muzzleFlash != null)
			{
				muzzleFlash.Play();
			}
			__instance.m_fireBulletTimer = Clock.Time + __instance.m_archetypeData.GetSentryShotDelay(__instance.m_core.Owner, targetIsTagged);
			return false;
		}

		[HarmonyPatch(typeof(SentryGunInstance_Firing_Bullets), "UpdateFireShotgunSemi")]
		[HarmonyPrefix]
		public static void UpdateFireShotgunSemi(SentryGunInstance_Firing_Bullets __instance, bool isMaster, bool targetIsTagged)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			if (Clock.Time > __instance.m_fireBulletTimer)
			{
				EX_SpriteMuzzleFlash muzzleFlash = __instance.m_muzzleFlash;
				if (muzzleFlash != null)
				{
					muzzleFlash.Play();
				}
				ShellTypes val = (ShellTypes)4;
				float num = 0.8487f;
				float num2 = Random.Range(1f, 6f);
				Transform shellEjectAlign = __instance.ShellEjectAlign;
				Vector3 zero = Vector3.zero;
				bool flag = false;
				WeaponShellManager.EjectShell(val, num, num2, shellEjectAlign, zero, flag);
			}
		}

		[HarmonyPatch(typeof(SentryGunInstance_Firing_Bullets), "UpdateFireSemi")]
		[HarmonyPrefix]
		public static void UpdateFireSemi(SentryGunInstance_Firing_Bullets __instance, bool isMaster, bool targetIsTagged)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			if (Clock.Time > __instance.m_fireBulletTimer)
			{
				ShellTypes val = (ShellTypes)3;
				float num = 2.11534f;
				float num2 = Random.Range(1f, 5f);
				Transform shellEjectAlign = __instance.ShellEjectAlign;
				Vector3 zero = Vector3.zero;
				bool flag = false;
				WeaponShellManager.EjectShell(val, num, num2, shellEjectAlign, zero, flag);
			}
		}

		[HarmonyPatch(typeof(SentryGunInstance_Firing_Bullets), "UpdateFireAuto")]
		[HarmonyPrefix]
		public static void UpdateFireAuto(SentryGunInstance_Firing_Bullets __instance, bool isMaster, bool targetIsTagged)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			if (Clock.Time > __instance.m_fireBulletTimer)
			{
				ShellTypes val = (ShellTypes)3;
				float num = 0.78f;
				float num2 = Random.Range(1f, 3f);
				Transform shellEjectAlign = __instance.ShellEjectAlign;
				Vector3 zero = Vector3.zero;
				bool flag = false;
				WeaponShellManager.EjectShell(val, num, num2, shellEjectAlign, zero, flag);
			}
		}

		[HarmonyPatch(typeof(ArchetypeDataBlock), "GetSentryDamage")]
		[HarmonyPostfix]
		public static void GetSentryDamage(ArchetypeDataBlock __instance, PlayerAgent owner, float distance, bool targetIsTagged, ref float __result)
		{
			__result = ((AgentModifierManager.ApplyModifier((Agent)(object)owner, (AgentModifier)103, __result) > 2.1f) ? (AgentModifierManager.ApplyModifier((Agent)(object)owner, (AgentModifier)103, __result) / ArmorPiercingFragmentationPatches.ArmorDmgMult * Random.Range(2.5f, 2.910603f)) : (AgentModifierManager.ApplyModifier((Agent)(object)owner, (AgentModifier)103, __result) * Random.Range(2.5f, 2.910603f)));
		}
	}
}
namespace Armament.ReloadImprovements
{
	[HarmonyPatch]
	internal class RLDImprovementPatches
	{
		private static Dictionary<InventorySlot, float> AmmoMaxCapLookup = new Dictionary<InventorySlot, float>
		{
			{
				(InventorySlot)1,
				0f
			},
			{
				(InventorySlot)2,
				0f
			}
		};

		private static InventorySlotAmmo? StandardAmmo;

		private static InventorySlotAmmo? SpeacialAmmo;

		private static bool NeedRestoredStandardAmmoMaxCap = false;

		private static bool NeedRestoredSpecialAmmoMaxCap = false;

		private static float AmmoStandardResourcePackMaxCap => GameDataBlockBase<PlayerDataBlock>.GetBlock(1u).AmmoStandardResourcePackMaxCap;

		private static float AmmoSpecialResourcePackMaxCap => GameDataBlockBase<PlayerDataBlock>.GetBlock(1u).AmmoSpecialResourcePackMaxCap;

		[HarmonyPatch(typeof(PlayerAmmoStorage), "GetClipBulletsFromPack")]
		[HarmonyPrefix]
		public static bool GetClipBulletsFromPack(PlayerAmmoStorage __instance, ref int __result, int currentClip, AmmoType ammoType)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected I4, but got Unknown
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			PlayerAmmoStorage __instance2 = __instance;
			InventorySlotAmmo val = ((Il2CppArrayBase<InventorySlotAmmo>)(object)__instance2.m_ammoStorage)[(int)ammoType];
			float costOfBullet = val.CostOfBullet;
			int num = val.BulletClipSize - currentClip;
			if (num < 1)
			{
				__result = currentClip;
				return false;
			}
			ItemEquippable wieldedItem = PlayerManager.PlayerAgentsInLevel.Find(Predicate<PlayerAgent>.op_Implicit((Func<PlayerAgent, bool>)((PlayerAgent p) => p.PlayerSlotIndex == __instance2.m_playerBackpack.Owner.PlayerSlot.index))).Inventory.WieldedItem;
			if ((Object)wieldedItem != (Object)null && !ShouldExcludeWeapon(((GameDataBlockBase<ArchetypeDataBlock>)(object)wieldedItem.ArchetypeData).persistentID) && currentClip > 0)
			{
				num++;
			}
			float num2 = (float)num * val.CostOfBullet;
			float ammoInPack = val.AmmoInPack;
			int num3 = Mathf.RoundToInt(Mathf.Min(num2, ammoInPack) / costOfBullet);
			int bulletsInPack = val.BulletsInPack;
			val.AmmoInPack -= (float)num3 * costOfBullet;
			val.OnBulletsUpdateCallback?.Invoke(val.BulletsInPack);
			currentClip += Mathf.Min(num3, bulletsInPack);
			__instance2.NeedsSync = true;
			__instance2.UpdateSlotAmmoUI(val, currentClip);
			__result = currentClip;
			return false;
		}

		private static bool ShouldExcludeWeapon(uint persistentID)
		{
			uint[] array = new uint[10] { 23u, 33u, 34u, 37u, 38u, 43u, 45u, 66u, 72u, 81u };
			uint[] array2 = array;
			foreach (uint num in array2)
			{
				if (persistentID == num)
				{
					return true;
				}
			}
			return false;
		}

		[HarmonyPatch(typeof(BulletWeapon), "ClipIsFull")]
		[HarmonyPrefix]
		private static bool ClipIsFull(BulletWeapon __instance, out bool __result)
		{
			__result = __instance.m_clip >= ((ItemEquippable)__instance).ClipSize;
			return false;
		}

		[HarmonyPatch(typeof(PlayerBackpackManager), "ReceiveAmmoGive")]
		[HarmonyPrefix]
		private static void ReceiveAmmoGive(ref pAmmoGive data)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			bool flag = false;
			bool flag2 = false;
			float num = 0f;
			float num2 = 0f;
			SNet_Player val = default(SNet_Player);
			if (((pPlayer)(ref data.targetPlayer)).TryGetPlayer(ref val) && val.IsLocal)
			{
				BackpackItem val2 = default(BackpackItem);
				if (PlayerBackpackManager.LocalBackpack.TryGetBackpackItem((InventorySlot)1, ref val2))
				{
					BulletWeapon val3 = ((Il2CppObjectBase)val2.Instance).TryCast<BulletWeapon>();
					float num3 = (float)(((ItemEquippable)val3).ClipSize - val3.m_clip) * ((ItemEquippable)val3).ArchetypeData.CostOfBullet;
					StandardAmmo = PlayerBackpackManager.LocalBackpack.AmmoStorage.StandardAmmo;
					AmmoMaxCapLookup[(InventorySlot)1] = StandardAmmo.AmmoMaxCap;
					InventorySlotAmmo? standardAmmo = StandardAmmo;
					standardAmmo.AmmoMaxCap += num3;
					NeedRestoredStandardAmmoMaxCap = true;
					num = data.ammoStandardRel * AmmoStandardResourcePackMaxCap + StandardAmmo.AmmoInPack - StandardAmmo.AmmoMaxCap;
					flag = num > 0f;
				}
				if (PlayerBackpackManager.LocalBackpack.TryGetBackpackItem((InventorySlot)2, ref val2))
				{
					BulletWeapon val4 = ((Il2CppObjectBase)val2.Instance).TryCast<BulletWeapon>();
					float num4 = (float)(((ItemEquippable)val4).ClipSize - val4.m_clip) * ((ItemEquippable)val4).ArchetypeData.CostOfBullet;
					SpeacialAmmo = PlayerBackpackManager.LocalBackpack.AmmoStorage.SpecialAmmo;
					AmmoMaxCapLookup[(InventorySlot)2] = SpeacialAmmo.AmmoMaxCap;
					InventorySlotAmmo? speacialAmmo = SpeacialAmmo;
					speacialAmmo.AmmoMaxCap += num4;
					NeedRestoredSpecialAmmoMaxCap = true;
					num2 = data.ammoSpecialRel * AmmoSpecialResourcePackMaxCap + SpeacialAmmo.AmmoInPack - SpeacialAmmo.AmmoMaxCap;
					flag2 = num2 > 0f;
				}
				if (flag && !flag2)
				{
					data.ammoSpecialRel += num / AmmoStandardResourcePackMaxCap;
				}
				else if (!flag && flag2)
				{
					data.ammoStandardRel += num2 / AmmoSpecialResourcePackMaxCap;
				}
			}
		}

		[HarmonyPatch(typeof(PlayerBackpackManager), "ReceiveAmmoGive")]
		[HarmonyPostfix]
		private static void ReceiveAmmoGive(pAmmoGive data)
		{
			SNet_Player val = default(SNet_Player);
			if (((pPlayer)(ref data.targetPlayer)).TryGetPlayer(ref val) && val.IsLocal)
			{
				BackpackItem val2 = default(BackpackItem);
				if (PlayerBackpackManager.LocalBackpack.TryGetBackpackItem((InventorySlot)1, ref val2))
				{
					StandardAmmo.AmmoMaxCap = AmmoMaxCapLookup[(InventorySlot)1];
					PlayerBackpackManager.LocalBackpack.AmmoStorage.UpdateSlotAmmoUI((InventorySlot)1);
					NeedRestoredStandardAmmoMaxCap = false;
				}
				if (PlayerBackpackManager.LocalBackpack.TryGetBackpackItem((InventorySlot)2, ref val2))
				{
					SpeacialAmmo.AmmoMaxCap = AmmoMaxCapLookup[(InventorySlot)2];
					PlayerBackpackManager.LocalBackpack.AmmoStorage.UpdateSlotAmmoUI((InventorySlot)2);
					NeedRestoredSpecialAmmoMaxCap = false;
				}
			}
		}
	}
}
namespace Armament.MuzzleProjectileAlignment
{
	[HarmonyPatch]
	internal class FirePatches
	{
		private static BulletWeapon? weapon;

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPrefix]
		private static void CastWeaponRay(ref Transform alignTransform, ref WeaponHitData weaponRayData, ref Vector3 originPos, int altRayCastMask)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)weapon == (Object)null))
			{
				Vector3 position = ((ItemEquippable)weapon).MuzzleAlign.position;
				position = ((Item)weapon).Owner.FPSCamera.Position;
				alignTransform = ((ItemEquippable)weapon).MuzzleAlign;
				WeaponHitData obj = weaponRayData;
				Vector3 fireDir;
				if (((ItemEquippable)weapon).FPItemHolder.ItemAimTrigger)
				{
					Vector3 val = ((Item)weapon).Owner.FPSCamera.CameraRayPos - position;
					fireDir = ((Vector3)(ref val)).normalized;
				}
				else
				{
					fireDir = ((ItemEquippable)weapon).MuzzleAlign.forward;
				}
				obj.fireDir = fireDir;
			}
		}

		[HarmonyPatch(typeof(BulletWeapon), "Fire")]
		[HarmonyPrefix]
		private static void Pre_Fire(BulletWeapon __instance, bool resetRecoilSimilarity = true)
		{
			weapon = __instance;
		}

		[HarmonyPatch(typeof(BulletWeapon), "Fire")]
		[HarmonyPostfix]
		private static void Post_Fire(BulletWeapon __instance)
		{
			weapon = null;
		}

		[HarmonyPatch(typeof(Shotgun), "Fire")]
		[HarmonyPrefix]
		private static void Pre_Shotgun_Fire(Shotgun __instance)
		{
			weapon = (BulletWeapon?)(object)__instance;
		}

		[HarmonyPatch(typeof(Shotgun), "Fire")]
		[HarmonyPostfix]
		private static void Post_Shotgun_Fire(Shotgun __instance)
		{
			weapon = null;
		}
	}
}
namespace Armament.ArmorPiercingFragmentation
{
	[HarmonyPatch]
	public class ArmorPiercingFragmentationPatches
	{
		public static ItemEquippable? wieldedItem;

		public static bool fromSentry;

		public static float ArmorDmgMult;

		[HarmonyPatch(typeof(SentryGunInstance_Firing_Bullets), "UpdateFireSemi")]
		[HarmonyPrefix]
		public static void PreUpdateFireSemi(SentryGunInstance_Firing_Bullets __instance, bool isMaster, bool targetIsTagged)
		{
			if (Clock.Time > __instance.m_fireBulletTimer)
			{
				fromSentry = true;
			}
		}

		[HarmonyPatch(typeof(SentryGunInstance_Firing_Bullets), "UpdateFireSemi")]
		[HarmonyPostfix]
		public static void PostUpdateFireSemi(SentryGunInstance_Firing_Bullets __instance, bool isMaster, bool targetIsTagged)
		{
			fromSentry = false;
		}

		[HarmonyPatch(typeof(SentryGunInstance_Firing_Bullets), "UpdateFireAuto")]
		[HarmonyPrefix]
		public static void PreUpdateFireAuto(SentryGunInstance_Firing_Bullets __instance, bool isMaster, bool targetIsTagged)
		{
			if (Clock.Time > __instance.m_fireBulletTimer)
			{
				fromSentry = true;
			}
		}

		[HarmonyPatch(typeof(SentryGunInstance_Firing_Bullets), "UpdateFireBurst")]
		[HarmonyPrefix]
		public static bool UpdateFireBurst(SentryGunInstance_Firing_Bullets __instance, bool isMaster, bool targetIsTagged)
		{
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: 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)
			if (!(Clock.Time > __instance.m_burstTimer))
			{
				return true;
			}
			fromSentry = true;
			if (__instance.m_burstClipCurr > 0)
			{
				if (__instance.m_burstClipCurr == __instance.m_archetypeData.BurstShotCount)
				{
					__instance.TriggerBurstFireAudio();
				}
				if (Clock.Time > __instance.m_fireBulletTimer && __instance.m_core.Ammo >= __instance.m_core.CostOfBullet)
				{
					__instance.FireBullet(isMaster, targetIsTagged);
					__instance.UpdateAmmo(-1);
					int burstClipCurr = __instance.m_burstClipCurr;
					__instance.m_burstClipCurr = burstClipCurr - 1;
					ShellTypes val = (ShellTypes)3;
					float num = 1f;
					float num2 = Random.Range(1f, 4f);
					Transform shellEjectAlign = __instance.ShellEjectAlign;
					Vector3 zero = Vector3.zero;
					bool flag = false;
					WeaponShellManager.EjectShell(val, num, num2, shellEjectAlign, zero, flag);
				}
			}
			else
			{
				__instance.m_burstTimer = Clock.Time + __instance.m_archetypeData.BurstDelay;
				__instance.m_burstClipCurr = __instance.m_archetypeData.BurstShotCount;
			}
			return false;
		}

		[HarmonyPatch(typeof(SentryGunInstance_Firing_Bullets), "UpdateFireAuto")]
		[HarmonyPostfix]
		public static void PostUpdateFireAuto(SentryGunInstance_Firing_Bullets __instance, bool isMaster, bool targetIsTagged)
		{
			fromSentry = false;
		}

		[HarmonyPatch(typeof(SentryGunInstance_Firing_Bullets), "UpdateFireBurst")]
		[HarmonyPostfix]
		public static void PostUpdateFireBurst(SentryGunInstance_Firing_Bullets __instance, bool isMaster, bool targetIsTagged)
		{
			fromSentry = false;
		}

		[HarmonyPatch(typeof(SentryGunInstance_Firing_Bullets), "UpdateFireShotgunSemi")]
		[HarmonyPrefix]
		public static void PreUpdateFireShotgunSemi(SentryGunInstance_Firing_Bullets __instance, bool isMaster, bool targetIsTagged)
		{
			if (Clock.Time > __instance.m_fireBulletTimer)
			{
				fromSentry = true;
			}
		}

		[HarmonyPatch(typeof(SentryGunInstance_Firing_Bullets), "UpdateFireShotgunSemi")]
		[HarmonyPostfix]
		public static void PostUpdateFireShotgunSemi(SentryGunInstance_Firing_Bullets __instance, bool isMaster, bool targetIsTagged)
		{
			fromSentry = false;
		}

		private static bool ShouldSkipSentryLogic()
		{
			return fromSentry;
		}

		[HarmonyPatch(typeof(Dam_EnemyDamageLimb), "BulletDamage")]
		[HarmonyPrefix]
		public static void Pre_BulletDamage(float dam, Agent sourceAgent, Vector3 position, Vector3 direction, Vector3 normal, bool allowDirectionalBonus, float staggerMulti, float precisionMulti)
		{
			if (!ShouldSkipSentryLogic())
			{
				wieldedItem = ((Il2CppObjectBase)sourceAgent).TryCast<PlayerAgent>().Inventory.WieldedItem;
			}
		}

		[HarmonyPatch(typeof(Dam_EnemyDamageLimb), "BulletDamage")]
		[HarmonyPostfix]
		public static void Post_BulletDamage(Dam_EnemyDamageLimb __instance, float dam, Agent sourceAgent, Vector3 position, Vector3 direction, Vector3 normal, bool allowDirectionalBonus, float staggerMulti, float precisionMulti)
		{
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)wieldedItem != (Object)null && (Object)(object)sourceAgent != (Object)null && sourceAgent.IsLocallyOwned && wieldedItem.ArchetypeData != null && (((GameDataBlockBase<ArchetypeDataBlock>)(object)wieldedItem.ArchetypeData).persistentID == 27 || ((GameDataBlockBase<ArchetypeDataBlock>)(object)wieldedItem.ArchetypeData).persistentID == 29 || ((GameDataBlockBase<ArchetypeDataBlock>)(object)wieldedItem.ArchetypeData).persistentID == 30 || ((GameDataBlockBase<ArchetypeDataBlock>)(object)wieldedItem.ArchetypeData).persistentID == 37 || ((GameDataBlockBase<ArchetypeDataBlock>)(object)wieldedItem.ArchetypeData).persistentID == 67 || ((GameDataBlockBase<ArchetypeDataBlock>)(object)wieldedItem.ArchetypeData).persistentID == 81))
			{
				__instance.ShowHitIndicator(dam > dam, false, position, false);
			}
			wieldedItem = null;
		}

		[HarmonyPatch(typeof(Dam_EnemyDamageLimb), "ApplyWeakspotAndArmorModifiers")]
		[HarmonyPrefix]
		public static bool ApplyWeakspotAndArmorModifiers(Dam_EnemyDamageLimb __instance, ref float __result, float dam, float precisionMulti = 1f)
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Invalid comparison between Unknown and I4
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Invalid comparison between Unknown and I4
			ArmorDmgMult = __instance.m_armorDamageMulti;
			if ((Object)(object)wieldedItem == (Object)null || ShouldSkipSentryLogic())
			{
				return true;
			}
			if (wieldedItem.ArchetypeData != null)
			{
				uint persistentID = ((GameDataBlockBase<ArchetypeDataBlock>)(object)wieldedItem.ArchetypeData).persistentID;
				if (persistentID == 27 || persistentID == 29 || persistentID == 37 || persistentID == 67 || persistentID == 81)
				{
					__result = dam * (((int)__instance.m_type == 1) ? Mathf.Max(__instance.m_weakspotDamageMulti * precisionMulti, 1f) : __instance.m_weakspotDamageMulti) * (__instance.m_armorDamageMulti / __instance.m_armorDamageMulti);
					return false;
				}
				if (persistentID == 30)
				{
					__result = dam * ((__instance.m_healthMax > 6000f) ? (__instance.m_healthMax / dam * 12f) : 1f);
					return false;
				}
				if (persistentID == 22 || persistentID == 49 || persistentID == 59)
				{
					__result = Random.Range(1f, 1.15f) * (dam * (((int)__instance.m_type == 1) ? Mathf.Max(__instance.m_weakspotDamageMulti * precisionMulti, 1f) : __instance.m_weakspotDamageMulti)) * __instance.m_armorDamageMulti;
					return false;
				}
			}
			return true;
		}
	}
}