Decompiled source of AmmoLocker v2.0.0

AmmoLocker.dll

Decompiled 6 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using On.RoR2;
using On.RoR2.Skills;
using On.RoR2.UI;
using R2API;
using R2API.Utils;
using RoR2;
using RoR2.ContentManagement;
using RoR2.Skills;
using RoR2.UI;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Events;
using UnityEngine.Networking;

[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyCompany("AmmoLocker")]
[assembly: AssemblyProduct("AmmoLocker")]
[assembly: AssemblyTitle("AmmoLocker")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[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
{
	[Microsoft.CodeAnalysis.Embedded]
	[CompilerGenerated]
	[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 AmmoLocker
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("Cedev.AmmoLocker", "AmmoLocker", "2.0.0")]
	[R2APISubmoduleDependency(new string[] { "DeployableAPI", "LanguageAPI", "CommandHelper" })]
	public class AmmoLocker : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static GetDeployableSameSlotLimit <>9__21_1;

			public static hook_RecalculateStats <>9__21_2;

			public static hook_RecalculateMaxStock <>9__21_5;

			public static hook_OnFixedUpdate <>9__21_6;

			public static hook_Awake <>9__21_7;

			internal int <Awake>b__21_1(CharacterMaster master, int multiplier)
			{
				return ammoLockerMaxDeployed;
			}

			internal void <Awake>b__21_2(orig_RecalculateStats orig, CharacterBody self)
			{
				orig.Invoke(self);
				if (self.HasBuff(shoringDef))
				{
					self.barrierDecayRate = 0f;
				}
			}

			internal void <Awake>b__21_5(orig_RecalculateMaxStock orig, GenericSkill self)
			{
				orig.Invoke(self);
				if ((Object)(object)self.characterBody != (Object)null && self.characterBody.HasBuff(overchargeDef))
				{
					self.maxStock += Math.Max(1, self.rechargeStock);
				}
			}

			internal void <Awake>b__21_6(orig_OnFixedUpdate orig, ReloadSkillDef self, GenericSkill genericSkill)
			{
				int baseMaxStock = ((SkillDef)self).baseMaxStock;
				((SkillDef)self).baseMaxStock = genericSkill.maxStock;
				orig.Invoke(self, genericSkill);
				((SkillDef)self).baseMaxStock = baseMaxStock;
			}

			internal void <Awake>b__21_7(orig_Awake orig, CrosshairController self)
			{
				//IL_0049: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
				//IL_007b: Unknown result type (might be due to invalid IL or missing references)
				//IL_007c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0057: 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)
				Log.LogInfo(string.Format("CrosshairController {0} Awake on {0}", ((Object)self).name, ((Object)((Component)self).gameObject).name));
				orig.Invoke(self);
				if (((Object)((Component)self).gameObject).name.StartsWith("Bandit2Crosshair"))
				{
					for (int i = 0; i < self.skillStockSpriteDisplays.Length; i++)
					{
						SkillStockSpriteDisplay val = self.skillStockSpriteDisplays[i];
						if ((int)val.skillSlot == 0 && val.maximumStockCountToBeValid >= 4)
						{
							val.maximumStockCountToBeValid = Math.Max(99, val.maximumStockCountToBeValid);
						}
						self.skillStockSpriteDisplays[i] = val;
					}
				}
				else if (((Object)((Component)self).gameObject).name.StartsWith("CaptainSupplyDropCrosshair"))
				{
					for (int j = 0; j < self.skillStockSpriteDisplays.Length; j++)
					{
						SkillStockSpriteDisplay val2 = self.skillStockSpriteDisplays[j];
						val2.maximumStockCountToBeValid = Math.Max(99, val2.maximumStockCountToBeValid);
						self.skillStockSpriteDisplays[j] = val2;
					}
				}
			}
		}

		public const string PluginGUID = "Cedev.AmmoLocker";

		public const string PluginAuthor = "Cedev";

		public const string PluginName = "AmmoLocker";

		public const string PluginVersion = "2.0.0";

		public static BuffDef shoringDef;

		public static BuffDef overchargeDef;

		public static EquipmentDef ammoLockerDef;

		public static DeployableSlot ammoLockerSlot;

		public static float ammoLockerCooldown;

		public static float ammoLockerBuffDuration;

		public static float ammoLockerRange;

		public static float ammoLockerBarrier;

		public static float ammoLockerScale;

		public static float ammoLockerSpacing;

		public static int ammoLockerMaxDeployed;

		public static int ammoLockerMaxLockers;

		public static bool ammoLockerEnigmaCompatible;

		public static bool ammoLockerCanBeRandomlyTriggered;

		public static GameObject ammoLockerPrefab;

		public static Texture2D skinSwatches;

		public static Random random;

		public void Awake()
		{
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: 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_01a2: Expected O, but got Unknown
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Expected O, but got Unknown
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Expected O, but got Unknown
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Expected O, but got Unknown
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Expected O, but got Unknown
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Expected O, but got Unknown
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Expected O, but got Unknown
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			ammoLockerCooldown = ((BaseUnityPlugin)this).Config.Bind<float>("Ammo Locker", "ammoLockerCooldown", 60f, (ConfigDescription)null).Value;
			ammoLockerBuffDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Ammo Locker", "ammoLockerBuffDuration", 20f, (ConfigDescription)null).Value;
			ammoLockerRange = ((BaseUnityPlugin)this).Config.Bind<float>("Ammo Locker", "ammoLockerRange", 1000f, (ConfigDescription)null).Value;
			ammoLockerBarrier = ((BaseUnityPlugin)this).Config.Bind<float>("Ammo Locker", "ammoLockerBarrier", 0.25f, (ConfigDescription)null).Value;
			ammoLockerSpacing = ((BaseUnityPlugin)this).Config.Bind<float>("Ammo Locker", "ammoLockerSpacing", 1f, (ConfigDescription)null).Value;
			ammoLockerScale = ((BaseUnityPlugin)this).Config.Bind<float>("Ammo Locker", "ammoLockerScale", 1.05f, (ConfigDescription)null).Value;
			ammoLockerMaxDeployed = ((BaseUnityPlugin)this).Config.Bind<int>("Ammo Locker", "ammoLockerMaxDeployed", 4, (ConfigDescription)null).Value;
			ammoLockerMaxLockers = ((BaseUnityPlugin)this).Config.Bind<int>("Ammo Locker", "ammoLockerMaxLockers", 8, (ConfigDescription)null).Value;
			ammoLockerEnigmaCompatible = ((BaseUnityPlugin)this).Config.Bind<bool>("Ammo Locker", "ammoLockerEnigmaCompatible", false, (ConfigDescription)null).Value;
			ammoLockerCanBeRandomlyTriggered = ((BaseUnityPlugin)this).Config.Bind<bool>("Ammo Locker", "ammoLockerCanBeRandomlyTriggered", false, (ConfigDescription)null).Value;
			PluginContent.LoadContentAsync("Cedev.AmmoLocker", async delegate(ContentPack contentPack, IProgress progress)
			{
				Task<AssetBundle> bundle = progress.Step(PluginContent.LoadAssetBundle(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "assets")));
				Task<Texture2D> task = progress.Step(bundle.LoadAsync<Texture2D>("Assets/Icons/texBuffShoring.png"));
				Task<Texture2D> texOverchargeBuff = progress.Step(bundle.LoadAsync<Texture2D>("Assets/Icons/texBuffOvercharge.png"));
				Task<Texture2D> texAmmoLockerIcon = progress.Step(bundle.LoadAsync<Texture2D>("Assets/Icons/texAmmoLockerIcon.png"));
				Task<GameObject> padlockPrefab = progress.Step(bundle.LoadAsync<GameObject>("Assets/Prefabs/padlock.prefab"));
				Task<GameObject> ammoLockerPrefabStep = progress.Step(bundle.LoadAsync<GameObject>("Assets/Prefabs/locker.prefab"));
				Task<Texture2D> texSkinSwatches = progress.Step(bundle.LoadAsync<Texture2D>("Assets/Icons/texSkinSwatches.png"));
				shoringDef = ScriptableObject.CreateInstance<BuffDef>();
				((Object)shoringDef).name = "CHEEESYBUFFS_SHORING_NAME";
				shoringDef.canStack = false;
				BuffDef val8 = shoringDef;
				val8.iconSprite = (await task).ToSprite();
				contentPack.buffDefs.Add((BuffDef[])(object)new BuffDef[1] { shoringDef });
				overchargeDef = ScriptableObject.CreateInstance<BuffDef>();
				((Object)overchargeDef).name = "CHEEESYBUFFS_OVERCHARGE_NAME";
				overchargeDef.canStack = false;
				val8 = overchargeDef;
				val8.iconSprite = (await texOverchargeBuff).ToSprite();
				contentPack.buffDefs.Add((BuffDef[])(object)new BuffDef[1] { overchargeDef });
				ammoLockerDef = ScriptableObject.CreateInstance<EquipmentDef>();
				((Object)ammoLockerDef).name = "CHEESEBOARD_AMMOLOCKER_EQUIPMENT_NAME";
				ammoLockerDef.nameToken = "CHEESEBOARD_AMMOLOCKER_EQUIPMENT_NAME";
				ammoLockerDef.pickupToken = "CHEESEBOARD_AMMOLOCKER_EQUIPMENT_PICKUP";
				ammoLockerDef.descriptionToken = "CHEESEBOARD_AMMOLOCKER_EQUIPMENT_DESC";
				ammoLockerDef.loreToken = "CHEESEBOARD_AMMOLOCKER_EQUIPMENT_LORE";
				EquipmentDef val9 = ammoLockerDef;
				val9.pickupIconSprite = (await texAmmoLockerIcon).ToSprite();
				val9 = ammoLockerDef;
				val9.pickupModelPrefab = await padlockPrefab;
				ammoLockerDef.canDrop = true;
				ammoLockerDef.colorIndex = (ColorIndex)5;
				ammoLockerDef.enigmaCompatible = ammoLockerEnigmaCompatible;
				ammoLockerDef.canBeRandomlyTriggered = ammoLockerCanBeRandomlyTriggered;
				ammoLockerDef.cooldown = ammoLockerCooldown;
				contentPack.equipmentDefs.Add((EquipmentDef[])(object)new EquipmentDef[1] { ammoLockerDef });
				ammoLockerPrefab = await ammoLockerPrefabStep;
				ammoLockerPrefab.AddComponent<AmmoLockerInteraction>();
				ammoLockerPrefab.AddComponent<InteractionProcFilter>();
				Log.LogInfo($"Ammo locker prefab NetworkInstance asset ID: {ammoLockerPrefab.GetComponent<NetworkIdentity>().assetId}");
				contentPack.networkedObjectPrefabs.Add((GameObject[])(object)new GameObject[1] { ammoLockerPrefab });
				skinSwatches = await texSkinSwatches;
			});
			object obj = <>c.<>9__21_1;
			if (obj == null)
			{
				GetDeployableSameSlotLimit val = (CharacterMaster master, int multiplier) => ammoLockerMaxDeployed;
				<>c.<>9__21_1 = val;
				obj = (object)val;
			}
			ammoLockerSlot = DeployableAPI.RegisterDeployableSlot((GetDeployableSameSlotLimit)obj);
			random = new Random();
			object obj2 = <>c.<>9__21_2;
			if (obj2 == null)
			{
				hook_RecalculateStats val2 = delegate(orig_RecalculateStats orig, CharacterBody self)
				{
					orig.Invoke(self);
					if (self.HasBuff(shoringDef))
					{
						self.barrierDecayRate = 0f;
					}
				};
				<>c.<>9__21_2 = val2;
				obj2 = (object)val2;
			}
			CharacterBody.RecalculateStats += (hook_RecalculateStats)obj2;
			CharacterBody.OnBuffFirstStackGained += (hook_OnBuffFirstStackGained)delegate(orig_OnBuffFirstStackGained orig, CharacterBody self, BuffDef buff)
			{
				orig.Invoke(self, buff);
				if ((Object)(object)buff == (Object)(object)overchargeDef)
				{
					RecalulateSkillStocks(self);
				}
			};
			CharacterBody.OnBuffFinalStackLost += (hook_OnBuffFinalStackLost)delegate(orig_OnBuffFinalStackLost orig, CharacterBody self, BuffDef buff)
			{
				orig.Invoke(self, buff);
				if ((Object)(object)buff == (Object)(object)overchargeDef)
				{
					RecalulateSkillStocks(self);
				}
			};
			object obj3 = <>c.<>9__21_5;
			if (obj3 == null)
			{
				hook_RecalculateMaxStock val3 = delegate(orig_RecalculateMaxStock orig, GenericSkill self)
				{
					orig.Invoke(self);
					if ((Object)(object)self.characterBody != (Object)null && self.characterBody.HasBuff(overchargeDef))
					{
						self.maxStock += Math.Max(1, self.rechargeStock);
					}
				};
				<>c.<>9__21_5 = val3;
				obj3 = (object)val3;
			}
			GenericSkill.RecalculateMaxStock += (hook_RecalculateMaxStock)obj3;
			object obj4 = <>c.<>9__21_6;
			if (obj4 == null)
			{
				hook_OnFixedUpdate val4 = delegate(orig_OnFixedUpdate orig, ReloadSkillDef self, GenericSkill genericSkill)
				{
					int baseMaxStock = ((SkillDef)self).baseMaxStock;
					((SkillDef)self).baseMaxStock = genericSkill.maxStock;
					orig.Invoke(self, genericSkill);
					((SkillDef)self).baseMaxStock = baseMaxStock;
				};
				<>c.<>9__21_6 = val4;
				obj4 = (object)val4;
			}
			ReloadSkillDef.OnFixedUpdate += (hook_OnFixedUpdate)obj4;
			object obj5 = <>c.<>9__21_7;
			if (obj5 == null)
			{
				hook_Awake val5 = delegate(orig_Awake orig, CrosshairController self)
				{
					//IL_0049: Unknown result type (might be due to invalid IL or missing references)
					//IL_004e: Unknown result type (might be due to invalid IL or missing references)
					//IL_004f: Unknown result type (might be due to invalid IL or missing references)
					//IL_0050: Unknown result type (might be due to invalid IL or missing references)
					//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
					//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
					//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
					//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
					//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
					//IL_007b: Unknown result type (might be due to invalid IL or missing references)
					//IL_007c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0057: 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)
					Log.LogInfo(string.Format("CrosshairController {0} Awake on {0}", ((Object)self).name, ((Object)((Component)self).gameObject).name));
					orig.Invoke(self);
					if (((Object)((Component)self).gameObject).name.StartsWith("Bandit2Crosshair"))
					{
						for (int i = 0; i < self.skillStockSpriteDisplays.Length; i++)
						{
							SkillStockSpriteDisplay val6 = self.skillStockSpriteDisplays[i];
							if ((int)val6.skillSlot == 0 && val6.maximumStockCountToBeValid >= 4)
							{
								val6.maximumStockCountToBeValid = Math.Max(99, val6.maximumStockCountToBeValid);
							}
							self.skillStockSpriteDisplays[i] = val6;
						}
					}
					else if (((Object)((Component)self).gameObject).name.StartsWith("CaptainSupplyDropCrosshair"))
					{
						for (int j = 0; j < self.skillStockSpriteDisplays.Length; j++)
						{
							SkillStockSpriteDisplay val7 = self.skillStockSpriteDisplays[j];
							val7.maximumStockCountToBeValid = Math.Max(99, val7.maximumStockCountToBeValid);
							self.skillStockSpriteDisplays[j] = val7;
						}
					}
				};
				<>c.<>9__21_7 = val5;
				obj5 = (object)val5;
			}
			CrosshairController.Awake += (hook_Awake)obj5;
			EquipmentSlot.PerformEquipmentAction += (hook_PerformEquipmentAction)delegate(orig_PerformEquipmentAction orig, EquipmentSlot self, EquipmentDef equipmentDef)
			{
				if ((Object)(object)equipmentDef == (Object)(object)ammoLockerDef)
				{
					FireAmmoLocker(self, equipmentDef);
					return true;
				}
				return orig.Invoke(self, equipmentDef);
			};
			CommandHelper.AddToConsoleWhenReady();
			Log.LogInfo("Awake done.");
		}

		private void RecalulateSkillStocks(CharacterBody self)
		{
			GenericSkill[] allSkills = self.skillLocator.allSkills;
			for (int i = 0; i < allSkills.Length; i++)
			{
				allSkills[i].RecalculateMaxStock();
			}
		}

		public GameObject MakeAmmoLockers(EquipmentSlot self, Vector3 position, Quaternion rotation)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: 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_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: 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_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Expected O, but got Unknown
			GameObject lockers = new GameObject();
			lockers.transform.position = position;
			lockers.transform.rotation = rotation;
			Deployable val = lockers.AddComponent<Deployable>();
			val.onUndeploy = (UnityEvent)(((object)val.onUndeploy) ?? ((object)new UnityEvent()));
			val.onUndeploy.AddListener((UnityAction)delegate
			{
				Object.Destroy((Object)(object)lockers);
			});
			self.characterBody.master.AddDeployable(val, ammoLockerSlot);
			List<CharacterBody> list = new List<CharacterBody>();
			List<CharacterBody> list2 = new List<CharacterBody>();
			CharacterBody characterBody = self.characterBody;
			TeamIndex? obj;
			if (characterBody == null)
			{
				obj = null;
			}
			else
			{
				TeamComponent teamComponent = characterBody.teamComponent;
				obj = ((teamComponent != null) ? new TeamIndex?(teamComponent.teamIndex) : null);
			}
			foreach (TeamComponent teamMember in TeamComponent.GetTeamMembers((TeamIndex)(((int?)obj) ?? (-1))))
			{
				CharacterBody body = teamMember.body;
				if (body != null && body.isPlayerControlled)
				{
					list.Add(teamMember.body);
				}
				else if (Object.op_Implicit((Object)(object)teamMember.body))
				{
					list2.Insert((int)(random.NextDouble() * (double)(list2.Count + 1)), teamMember.body);
				}
			}
			list.AddRange(list2.Take(ammoLockerMaxLockers - list.Count));
			Log.LogInfo($"Making ammo lockers for {list.Count} players");
			for (int i = 0; i < list.Count; i++)
			{
				CharacterBody body2 = list[i];
				Vector3 val2 = ammoLockerScale * ammoLockerSpacing * (Vector3.right * (float)(list.Count - 1) / 2f + Vector3.left * (float)i);
				GameObject playerLocker = Object.Instantiate<GameObject>(ammoLockerPrefab, position + rotation * val2, rotation);
				playerLocker.transform.localScale = ammoLockerScale * Vector3.one;
				NetworkServer.Spawn(playerLocker);
				val.onUndeploy.AddListener((UnityAction)delegate
				{
					Object.Destroy((Object)(object)playerLocker);
				});
				playerLocker.GetComponent<AmmoLockerInteraction>().SetCharacterBodies(self.characterBody, body2);
			}
			return lockers;
		}

		public void FireAmmoLocker(EquipmentSlot self, EquipmentDef equipmentDef)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			Log.LogInfo("Firing ammo locker");
			RaycastHit val = default(RaycastHit);
			if (Physics.Raycast(self.GetAimRay(), ref val, ammoLockerRange, LayerMask.op_Implicit(((LayerIndex)(ref LayerIndex.world)).mask), (QueryTriggerInteraction)1))
			{
				Log.LogInfo("Making ammo lockers");
				MakeAmmoLockers(self, ((RaycastHit)(ref val)).point, Util.QuaternionSafeLookRotation(self.characterBody.corePosition - ((RaycastHit)(ref val)).point, ((RaycastHit)(ref val)).normal));
			}
		}
	}
	public class AmmoLockerInteraction : NetworkBehaviour, IInteractable, IDisplayNameProvider
	{
		[SyncVar]
		public bool available = true;

		[SyncVar]
		public NetworkInstanceId characterBodyNetId;

		private static int kRpcRpcSetPortrait;

		private static int kRpcRpcOnInteraction;

		public bool Networkavailable
		{
			get
			{
				return available;
			}
			[param: In]
			set
			{
				((NetworkBehaviour)this).SetSyncVar<bool>(value, ref available, 1u);
			}
		}

		public NetworkInstanceId NetworkcharacterBodyNetId
		{
			get
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				return characterBodyNetId;
			}
			[param: In]
			set
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				((NetworkBehaviour)this).SetSyncVar<NetworkInstanceId>(value, ref characterBodyNetId, 2u);
			}
		}

		private void Awake()
		{
			Collider[] componentsInChildren = ((Component)this).gameObject.GetComponentsInChildren<Collider>();
			foreach (Collider val in componentsInChildren)
			{
				(((Component)val).gameObject.GetComponent<EntityLocator>() ?? ((Component)val).gameObject.AddComponent<EntityLocator>()).entity = ((Component)this).gameObject;
			}
		}

		[Server]
		public void SetCharacterBodies(CharacterBody owner, CharacterBody body)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active)
			{
				Debug.LogWarning((object)"[Server] function 'System.Void AmmoLocker.AmmoLockerInteraction::SetCharacterBodies(RoR2.CharacterBody,RoR2.CharacterBody)' called on client");
				return;
			}
			Log.LogDebug($"SetCharacterBodies {owner}, {body}");
			NetworkcharacterBodyNetId = ((NetworkBehaviour)body).netId;
			CallRpcSetPortrait(((NetworkBehaviour)owner).netId, ((NetworkBehaviour)body).netId);
		}

		public static CharacterBody GetCharacterBody(NetworkInstanceId netId)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = ClientScene.FindLocalObject(netId);
			if (obj == null)
			{
				return null;
			}
			return obj.GetComponent<CharacterBody>();
		}

		[ClientRpc]
		public void RpcSetPortrait(NetworkInstanceId ownerNetId, NetworkInstanceId characterNetId)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			Log.LogDebug($"RpcSetPortrait {ownerNetId}, {characterNetId}");
			Texture2D val = SkinCatalog.FindCurrentSkinDefForBodyInstance(((Component)GetCharacterBody(ownerNetId)).gameObject)?.icon?.ToTexture2D(AmmoLocker.skinSwatches);
			CharacterBody characterBody = GetCharacterBody(characterNetId);
			Renderer[] componentsInChildren = ((Component)this).gameObject.GetComponentsInChildren<Renderer>();
			foreach (Renderer val2 in componentsInChildren)
			{
				Log.LogDebug($"Renderer on {((Component)val2).gameObject}");
				Material[] materials = val2.materials;
				Material[] array = materials;
				foreach (Material val3 in array)
				{
					Log.LogDebug($"Material {((Object)val3).name}");
					if ((Object)(object)characterBody.portraitIcon != (Object)null && ((Object)val3).name.StartsWith("Portrait"))
					{
						Log.LogDebug($"Setting portrait mainTexture to {characterBody.portraitIcon}");
						val3.mainTexture = characterBody.portraitIcon;
					}
					else if ((Object)(object)val != (Object)null && ((Object)val3).name.StartsWith("Skin"))
					{
						Log.LogDebug($"Setting skin mainTexture to {val}");
						val3.mainTexture = (Texture)(object)val;
					}
				}
				val2.materials = materials;
			}
		}

		public string GetContextString([NotNull] Interactor activator)
		{
			return Language.GetString("CHEESEBOARD_AMMOLOCKER_CONTEXT");
		}

		public Interactability GetInteractability([NotNull] Interactor activator)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			if (available)
			{
				CharacterBody component = ((Component)activator).GetComponent<CharacterBody>();
				NetworkInstanceId? val = ((component != null) ? new NetworkInstanceId?(((NetworkBehaviour)component).netId) : null);
				NetworkInstanceId val2 = characterBodyNetId;
				if (val.HasValue && (!val.HasValue || val.GetValueOrDefault() == val2))
				{
					return (Interactability)2;
				}
			}
			return (Interactability)0;
		}

		public void OnInteractionBegin([NotNull] Interactor activator)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			if (available)
			{
				CharacterBody component = ((Component)activator).GetComponent<CharacterBody>();
				if ((Object)(object)component != (Object)null)
				{
					Networkavailable = false;
					component.AddTimedBuffAuthority(AmmoLocker.overchargeDef.buffIndex, AmmoLocker.ammoLockerBuffDuration);
					component.AddTimedBuffAuthority(AmmoLocker.shoringDef.buffIndex, AmmoLocker.ammoLockerBuffDuration);
					component.healthComponent.AddBarrierAuthority(component.healthComponent.fullBarrier * AmmoLocker.ammoLockerBarrier);
					CallRpcOnInteraction(((NetworkBehaviour)component).netId);
				}
			}
		}

		[ClientRpc]
		public void RpcOnInteraction(NetworkInstanceId bodyId)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			Log.LogDebug("RpcOnInteraction");
			CharacterBody characterBody = GetCharacterBody(bodyId);
			SkillLocator val = ((characterBody != null) ? characterBody.skillLocator : null);
			if ((Object)(object)val != (Object)null)
			{
				GenericSkill[] allSkills = val.allSkills;
				for (int i = 0; i < allSkills.Length; i++)
				{
					allSkills[i].Reset();
				}
			}
			((Component)this).gameObject.GetComponentInChildren<Animator>().Play("Base Layer.Opening");
		}

		public bool ShouldIgnoreSpherecastForInteractibility([NotNull] Interactor activator)
		{
			return false;
		}

		public bool ShouldShowOnScanner()
		{
			return false;
		}

		public string GetDisplayName()
		{
			return Language.GetString("CHEESEBOARD_AMMOLOCKER_NAME");
		}

		private void UNetVersion()
		{
		}

		protected static void InvokeRpcRpcSetPortrait(NetworkBehaviour obj, NetworkReader reader)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkClient.active)
			{
				Debug.LogError((object)"RPC RpcSetPortrait called on server.");
			}
			else
			{
				((AmmoLockerInteraction)(object)obj).RpcSetPortrait(reader.ReadNetworkId(), reader.ReadNetworkId());
			}
		}

		protected static void InvokeRpcRpcOnInteraction(NetworkBehaviour obj, NetworkReader reader)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkClient.active)
			{
				Debug.LogError((object)"RPC RpcOnInteraction called on server.");
			}
			else
			{
				((AmmoLockerInteraction)(object)obj).RpcOnInteraction(reader.ReadNetworkId());
			}
		}

		public void CallRpcSetPortrait(NetworkInstanceId ownerNetId, NetworkInstanceId characterNetId)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active)
			{
				Debug.LogError((object)"RPC Function RpcSetPortrait called on client.");
				return;
			}
			NetworkWriter val = new NetworkWriter();
			val.Write((short)0);
			val.Write((short)2);
			val.WritePackedUInt32((uint)kRpcRpcSetPortrait);
			val.Write(((Component)this).GetComponent<NetworkIdentity>().netId);
			val.Write(ownerNetId);
			val.Write(characterNetId);
			((NetworkBehaviour)this).SendRPCInternal(val, 0, "RpcSetPortrait");
		}

		public void CallRpcOnInteraction(NetworkInstanceId bodyId)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active)
			{
				Debug.LogError((object)"RPC Function RpcOnInteraction called on client.");
				return;
			}
			NetworkWriter val = new NetworkWriter();
			val.Write((short)0);
			val.Write((short)2);
			val.WritePackedUInt32((uint)kRpcRpcOnInteraction);
			val.Write(((Component)this).GetComponent<NetworkIdentity>().netId);
			val.Write(bodyId);
			((NetworkBehaviour)this).SendRPCInternal(val, 0, "RpcOnInteraction");
		}

		static AmmoLockerInteraction()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			kRpcRpcSetPortrait = 38177051;
			NetworkBehaviour.RegisterRpcDelegate(typeof(AmmoLockerInteraction), kRpcRpcSetPortrait, new CmdDelegate(InvokeRpcRpcSetPortrait));
			kRpcRpcOnInteraction = -865747407;
			NetworkBehaviour.RegisterRpcDelegate(typeof(AmmoLockerInteraction), kRpcRpcOnInteraction, new CmdDelegate(InvokeRpcRpcOnInteraction));
			NetworkCRC.RegisterBehaviour("AmmoLockerInteraction", 0);
		}

		public override bool OnSerialize(NetworkWriter writer, bool forceAll)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			if (forceAll)
			{
				writer.Write(available);
				writer.Write(characterBodyNetId);
				return true;
			}
			bool flag = false;
			if ((((NetworkBehaviour)this).syncVarDirtyBits & (true ? 1u : 0u)) != 0)
			{
				if (!flag)
				{
					writer.WritePackedUInt32(((NetworkBehaviour)this).syncVarDirtyBits);
					flag = true;
				}
				writer.Write(available);
			}
			if ((((NetworkBehaviour)this).syncVarDirtyBits & 2u) != 0)
			{
				if (!flag)
				{
					writer.WritePackedUInt32(((NetworkBehaviour)this).syncVarDirtyBits);
					flag = true;
				}
				writer.Write(characterBodyNetId);
			}
			if (!flag)
			{
				writer.WritePackedUInt32(((NetworkBehaviour)this).syncVarDirtyBits);
			}
			return flag;
		}

		public override void OnDeserialize(NetworkReader reader, bool initialState)
		{
			//IL_0014: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			if (initialState)
			{
				available = reader.ReadBoolean();
				characterBodyNetId = reader.ReadNetworkId();
				return;
			}
			int num = (int)reader.ReadPackedUInt32();
			if (((uint)num & (true ? 1u : 0u)) != 0)
			{
				available = reader.ReadBoolean();
			}
			if (((uint)num & 2u) != 0)
			{
				characterBodyNetId = reader.ReadNetworkId();
			}
		}
	}
	public static class ConsoleCommands
	{
		[ConCommand(/*Could not decode attribute arguments.*/)]
		public static void DropDebugItems(ConCommandArgs args)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			PlayerCharacterMasterController.instances[0].master.GetBody();
			Transform transform = PlayerCharacterMasterController.instances[0].master.GetBodyObject().transform;
			PickupDropletController.CreatePickupDroplet(PickupCatalog.FindPickupIndex(AmmoLocker.ammoLockerDef.equipmentIndex), transform.position, transform.forward * 20f);
			PickupDropletController.CreatePickupDroplet(PickupCatalog.FindPickupIndex(Items.Firework.itemIndex), transform.position, transform.forward * 40f);
			PickupDropletController.CreatePickupDroplet(PickupCatalog.FindPickupIndex(Items.Squid.itemIndex), transform.position, transform.forward * 60f);
			PickupDropletController.CreatePickupDroplet(PickupCatalog.FindPickupIndex(Items.EquipmentMagazineVoid.itemIndex), transform.position, transform.forward * 80f);
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		public static void ListCrosshairs(ConCommandArgs args)
		{
			//IL_007f: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			foreach (CrosshairManager instances in CrosshairManager.instancesList)
			{
				Log.LogMessage($"Found CrosshairManager {((Object)instances).name} attached to {((Object)((Component)instances).gameObject).name}");
				if ((Object)(object)instances.crosshairController != (Object)null)
				{
					CrosshairController crosshairController = instances.crosshairController;
					Log.LogMessage($"Found CrosshairController {((Object)crosshairController).name} attached to {((Object)((Component)crosshairController).gameObject).name}");
					SkillStockSpriteDisplay[] skillStockSpriteDisplays = crosshairController.skillStockSpriteDisplays;
					foreach (SkillStockSpriteDisplay val in skillStockSpriteDisplays)
					{
						Log.LogMessage($"SkillStockSpriteDisplay skillSlot: {val.skillSlot}, requiredSkillDef: {val.requiredSkillDef?.skillName}, minStock: {val.minimumStockCountToBeValid}, maxStock: {val.maximumStockCountToBeValid}");
					}
				}
			}
		}
	}
	public static class Log
	{
		internal static ManualLogSource _logSource;

		public static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void LogDebug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void LogError(object data)
		{
			_logSource.LogError(data);
		}

		internal static void LogFatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void LogInfo(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void LogMessage(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void LogWarning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	public class PluginContentPack : IContentPackProvider
	{
		public ContentPack contentPack;

		private Func<ContentPack, IProgress, Task> loadContent;

		public string identifier { get; set; }

		public PluginContentPack(string identifier, Func<ContentPack, IProgress, Task> loadContent)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			this.identifier = identifier;
			contentPack = new ContentPack();
			this.loadContent = loadContent;
			ContentManager.collectContentPackProviders += (CollectContentPackProvidersDelegate)delegate(AddContentPackProviderDelegate addContentPack)
			{
				addContentPack.Invoke((IContentPackProvider)(object)this);
			};
		}

		public IEnumerator FinalizeAsync(FinalizeAsyncArgs args)
		{
			args.ReportProgress(1f);
			yield break;
		}

		public IEnumerator GenerateContentPackAsync(GetContentPackAsyncArgs args)
		{
			contentPack.identifier = identifier;
			ContentPack.Copy(contentPack, args.output);
			args.ReportProgress(1f);
			yield break;
		}

		public IEnumerator LoadStaticContentAsync(LoadStaticContentAsyncArgs args)
		{
			Progress progress = new Progress();
			progress.OnProgress += delegate(double x)
			{
				args.ReportProgress((float)x);
			};
			Task task = Task.Run(async delegate
			{
				await loadContent(contentPack, progress);
			});
			while (!task.IsCompleted)
			{
				yield return null;
			}
			if (task.IsFaulted)
			{
				Log.LogError(task.Exception);
			}
		}
	}
	public interface IAwaitable<out T>
	{
		IAwaiter<T> GetAwaiter();
	}
	public interface IAwaiter<out T> : INotifyCompletion
	{
		bool IsCompleted { get; }

		T GetResult();
	}
	public class UnityTask<T> : IAwaitable<T>, IAwaiter<T>, INotifyCompletion where T : AsyncOperation
	{
		private readonly T unityAsyncOperation;

		public bool IsCompleted => ((AsyncOperation)unityAsyncOperation).isDone;

		public UnityTask(T unityAsyncOperation)
		{
			this.unityAsyncOperation = unityAsyncOperation;
		}

		public T GetResult()
		{
			return unityAsyncOperation;
		}

		public void OnCompleted(Action continuation)
		{
			((AsyncOperation)unityAsyncOperation).completed += delegate
			{
				continuation();
			};
		}

		public IAwaiter<T> GetAwaiter()
		{
			return this;
		}
	}
	public static class PluginContent
	{
		public static void LoadContentAsync(string identifier, Func<ContentPack, IProgress, Task> loadContent)
		{
			new PluginContentPack(identifier, loadContent);
		}

		public static void Add<T>(this NamedAssetCollection<T> assetCollection, params T[] items)
		{
			assetCollection.Add(items);
		}

		public static Task<T> LoadAsync<T>(string key)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			Log.LogInfo($"Loading addressable asset {key}");
			return Addressables.LoadAssetAsync<T>((object)key).Task;
		}

		public static Task<T> LoadLegacyAsync<T>(string name)
		{
			Log.LogInfo($"Loading legacy asset {name}");
			return LoadAsync<T>(LegacyResourcesAPI.GetPathGuidString(name));
		}

		public static UnityTask<T> Awaitable<T>(this T asyncOperation) where T : AsyncOperation
		{
			return new UnityTask<T>(asyncOperation);
		}

		public static async Task<T> LoadAsync<T>(this AssetBundle bundle, string name) where T : Object
		{
			Log.LogInfo($"Loading {name} from bundle");
			AssetBundleRequest val = await bundle.LoadAssetAsync(name).Awaitable<AssetBundleRequest>();
			Log.LogInfo($"Loaded {name} from bundle: {val.asset}");
			return (T)(object)val.asset;
		}

		public static async Task<T> LoadAsync<T>(this Task<AssetBundle> bundle, string name) where T : Object
		{
			return await (await bundle).LoadAsync<T>(name);
		}

		public static async Task<AssetBundle> LoadAssetBundle(string path)
		{
			Log.LogInfo($"Loading AssetBundle {path}");
			AssetBundleCreateRequest val = await AssetBundle.LoadFromFileAsync(path).Awaitable<AssetBundleCreateRequest>();
			Log.LogInfo($"Loaded AssetBundle {path}: {val.assetBundle}");
			return val.assetBundle;
		}

		public static Sprite ToSprite(this Texture2D texture)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			return Sprite.Create(texture, new Rect(0f, 0f, (float)((Texture)texture).width, (float)((Texture)texture).height), new Vector2(0.5f, 0.5f));
		}

		public static int Round(this float x)
		{
			return (int)Math.Round(x);
		}

		public static Texture2D ToTexture2D(this Sprite sprite, params Texture2D[] fallbackSources)
		{
			//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_013d: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected O, but got Unknown
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: 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_0111: Unknown result type (might be due to invalid IL or missing references)
			Rect val = sprite.rect;
			if (((Rect)(ref val)).x.Round() == 0)
			{
				val = sprite.rect;
				if (((Rect)(ref val)).y.Round() == 0)
				{
					val = sprite.rect;
					if (((Rect)(ref val)).width.Round() == ((Texture)sprite.texture).width)
					{
						val = sprite.rect;
						if (((Rect)(ref val)).height.Round() == ((Texture)sprite.texture).height)
						{
							return sprite.texture;
						}
					}
				}
			}
			val = sprite.rect;
			int num = ((Rect)(ref val)).width.Round();
			val = sprite.rect;
			Texture2D val2 = new Texture2D(num, ((Rect)(ref val)).height.Round());
			((Object)val2).name = ((Object)sprite).name;
			List<Texture2D> list = new List<Texture2D>();
			list.Add(sprite.texture);
			list.AddRange(fallbackSources);
			foreach (Texture2D item in list)
			{
				try
				{
					val = sprite.textureRect;
					int num2 = ((Rect)(ref val)).x.Round();
					val = sprite.textureRect;
					int num3 = ((Rect)(ref val)).y.Round();
					val = sprite.textureRect;
					int num4 = ((Rect)(ref val)).width.Round();
					val = sprite.textureRect;
					Color[] pixels = item.GetPixels(num2, num3, num4, ((Rect)(ref val)).height.Round());
					val2.SetPixels(pixels);
					val2.Apply();
					return val2;
				}
				catch (UnityException val3)
				{
					Log.LogDebug((object)val3);
				}
			}
			return null;
		}
	}
	public interface IProgress
	{
		Task<T> Step<T>(Task<T> step, double weight = 1.0);
	}
	public class Progress : IProgress
	{
		public delegate void ProgressHandler(double progress);

		private double weightExpected;

		private double weightCompleted;

		public event ProgressHandler OnProgress;

		public Progress()
		{
			weightExpected = 0.0;
			weightCompleted = 0.0;
		}

		private void Expect(double weight)
		{
			Interlocking.Add(ref weightExpected, weight);
		}

		private void Complete(double weight)
		{
			double num = Interlocking.Add(ref weightCompleted, weight);
			if (weightExpected > 0.0)
			{
				this.OnProgress(num / weightExpected);
			}
		}

		public async Task<T> Step<T>(Task<T> step, double weight = 1.0)
		{
			Expect(weight);
			T result = await step;
			Complete(weight);
			return result;
		}
	}
	public static class ProgressExtensions
	{
		public static async Task<T> SelectMany<T, W>(this Task<W> first, Func<W, Task<T>> then)
		{
			return await then(await first);
		}

		public static Task<T> After<W, T>(this IProgress progress, Task<W> first, Func<W, Task<T>> then, double weight = 1.0)
		{
			return progress.Step(first.SelectMany(then), weight);
		}
	}
	public static class Interlocking
	{
		public delegate T CompareExchanger<T>(ref T location, T value, T comparand);

		public static T AtomicModify<T>(CompareExchanger<T> compareExchange, ref T location, Func<T, T> update) where T : IEquatable<T>
		{
			T val = location;
			T val2;
			while (true)
			{
				val2 = update(val);
				T val3 = compareExchange(ref location, val2, val);
				if (val3.Equals(val))
				{
					break;
				}
				val = val3;
			}
			return val2;
		}

		public static double Add(ref double location, double value)
		{
			return AtomicModify(Interlocked.CompareExchange, ref location, (double x) => x + value);
		}
	}
	public class RenderWaiter : MonoBehaviour
	{
		private SemaphoreSlim semaphore = new SemaphoreSlim(0, 1);

		public void OnPostRender()
		{
			semaphore.Release();
		}

		public async Task Wait()
		{
			await semaphore.WaitAsync();
		}
	}
	public static class RenderSprite
	{
		private static int position;

		public static async Task<RenderTexture> Render(this Sprite sprite)
		{
			Rect rect = sprite.rect;
			int num = ((Rect)(ref rect)).width.Round();
			rect = sprite.rect;
			int num2 = ((Rect)(ref rect)).height.Round();
			int num3 = Interlocked.Add(ref position, num + 10) - num / 2;
			GameObject gameObject = new GameObject();
			try
			{
				gameObject.layer = 31;
				gameObject.transform.position = Vector3.left * (float)num3;
				SpriteRenderer val = gameObject.AddComponent<SpriteRenderer>();
				val.sprite = sprite;
				((Component)val).transform.localScale = Vector3.one * sprite.pixelsPerUnit;
				Camera val2 = gameObject.AddComponent<Camera>();
				((Behaviour)val2).enabled = false;
				val2.cullingMask = 31;
				val2.orthographic = true;
				Bounds bounds = ((Renderer)val).bounds;
				float x = ((Bounds)(ref bounds)).size.x;
				bounds = ((Renderer)val).bounds;
				val2.aspect = x / ((Bounds)(ref bounds)).size.y;
				bounds = ((Renderer)val).bounds;
				val2.orthographicSize = ((Bounds)(ref bounds)).size.y / 2f;
				Transform transform = ((Component)val2).transform;
				bounds = ((Renderer)val).bounds;
				transform.position = ((Bounds)(ref bounds)).center + Vector3.forward;
				Transform transform2 = ((Component)val2).transform;
				bounds = ((Renderer)val).bounds;
				transform2.LookAt(((Bounds)(ref bounds)).center, Vector3.up);
				RenderTexture renderTexture = (val2.targetTexture = new RenderTexture(num, num2, 0));
				RenderWaiter renderWaiter = gameObject.AddComponent<RenderWaiter>();
				val2.Render();
				await renderWaiter.Wait();
				return renderTexture;
			}
			finally
			{
				Object.DestroyImmediate((Object)(object)gameObject);
			}
		}
	}
	public static class StockTracer
	{
		private static int tracingStocks;

		[ConCommand(/*Could not decode attribute arguments.*/)]
		public static void TraceStock(ConCommandArgs args)
		{
			if (Interlocked.Exchange(ref tracingStocks, 1) == 0)
			{
				Tracer.Instance.Format((GenericSkill gs) => $"{gs} {{stacks: {gs.stock}/{gs.maxStock}}}");
				Tracer.Instance.Filter((GenericSkill gs) => Object.op_Implicit((Object)(object)gs.characterBody) && gs.characterBody.isPlayerControlled);
				GenericSkill.AddOneStock += LogStock<hook_AddOneStock>();
				GenericSkill.ApplyAmmoPack += LogStock<hook_ApplyAmmoPack>();
				GenericSkill.AssignSkill += LogStock<hook_AssignSkill>();
				GenericSkill.DeductStock += LogStock<hook_DeductStock>();
				GenericSkill.RemoveAllStocks += LogStock<hook_RemoveAllStocks>();
				GenericSkill.Reset += LogStock<hook_Reset>();
				GenericSkill.RestockContinuous += LogStock<hook_RestockContinuous>();
				GenericSkill.RestockSteplike += LogStock<hook_RestockSteplike>();
				GenericSkill.Start += LogStock<hook_Start>();
				GenericSkill.OnExecute += LogStock<hook_OnExecute>();
				SkillDef.OnExecute += LogStock<hook_OnExecute>();
				GenericSkill.RecalculateMaxStock += LogStock<hook_RecalculateMaxStock>();
			}
		}

		private static T LogStock<T>()
		{
			return Tracing.Trace<T>(Tracer.Instance);
		}
	}
	public static class Tracing
	{
		public static TDelegate Trace<TDelegate>(ITrace tracer)
		{
			MethodInfo method = typeof(TDelegate).GetMethod("Invoke");
			ParameterExpression[] array = (from x in method.GetParameters()
				select Expression.Parameter(x.ParameterType, x.Name)).ToArray();
			ParameterExpression[] array2 = array.Skip(1).ToArray();
			ConstantExpression instance = Expression.Constant(tracer);
			MethodInfo method2 = typeof(ITrace).GetMethod("Enter");
			MethodInfo method3 = typeof(ITraceScope).GetMethod("Exception");
			MethodInfo method4 = typeof(ITraceScope).GetMethod("Return");
			MethodInfo method5 = typeof(IDisposable).GetMethod("Dispose");
			ParameterExpression parameterExpression = Expression.Variable(typeof(ITraceScope), "scope");
			ParameterExpression expression = array[0];
			Expression[] arguments = array2;
			Expression expression2 = Expression.Invoke(expression, arguments);
			if (method.ReturnType != typeof(void))
			{
				ParameterExpression parameterExpression2 = Expression.Variable(method.ReturnType, "result");
				expression2 = Expression.Block(Sanity.Vars(parameterExpression2), Expression.Assign(parameterExpression2, expression2), Expression.Call(parameterExpression, method4, parameterExpression2.ConvertTo<object>()), parameterExpression2);
			}
			ParameterExpression parameterExpression3 = Expression.Parameter(typeof(Exception), "e");
			return Expression.Lambda<TDelegate>(Expression.Block(Sanity.Vars(parameterExpression), Expression.Assign(parameterExpression, Expression.Call(instance, method2, array[0], array2.ToArrayExpression<object>())), Expression.TryCatchFinally(expression2, Expression.Call(parameterExpression, method5), Expression.MakeCatchBlock(typeof(Exception), parameterExpression3, Expression.Block(Expression.Call(parameterExpression, method3, parameterExpression3), Expression.Throw(parameterExpression3, method.ReturnType)), Expression.Constant(true)))), array).Compile();
		}
	}
	public static class Sanity
	{
		public static ParameterExpression[] Vars(params ParameterExpression[] vars)
		{
			return vars;
		}

		public static Expression ToArrayExpression<T>(this IEnumerable<Expression> expressions)
		{
			return Expression.NewArrayInit(typeof(T), expressions.Select(ConvertTo<T>));
		}

		public static Expression ConvertTo<T>(this Expression expr)
		{
			return Expression.Convert(expr, typeof(T));
		}
	}
	public interface ITraceScope : IDisposable
	{
		void Exception(Exception e);

		void Return(object obj);
	}
	public interface ITrace
	{
		ITraceScope Enter(object target, params object[] args);
	}
	public class TraceScope : ITraceScope, IDisposable
	{
		private readonly Action onExit;

		private readonly Func<object, object> formatter;

		private readonly string spaces;

		private readonly object target;

		private readonly object[] args;

		public TraceScope(Action onExit, Func<object, object> formatter, int indentation, object target, object[] args)
		{
			this.onExit = onExit;
			this.formatter = formatter;
			spaces = new string(' ', 2 * indentation);
			this.target = target;
			this.args = args;
			Log.LogDebug(string.Format("{0}Enter {1}({2})", spaces, target, string.Join(", ", args.Select(formatter))));
		}

		public void Dispose()
		{
			Log.LogDebug(string.Format("{0}Exit {1}({2})", spaces, target, string.Join(", ", args.Select(formatter))));
			onExit();
		}

		public void Exception(Exception e)
		{
			Log.LogDebug(e);
		}

		public void Return(object obj)
		{
			Log.LogDebug($"{spaces}Return: {formatter(obj)}");
		}
	}
	public class NullScope : ITraceScope, IDisposable
	{
		public static NullScope Instance = new NullScope();

		void ITraceScope.Exception(Exception e)
		{
		}

		void ITraceScope.Return(object obj)
		{
		}

		void IDisposable.Dispose()
		{
		}
	}
	public class Tracer : ITrace
	{
		public static Tracer Instance = new Tracer();

		public int indentation;

		public List<Func<object, bool>> Filters;

		public List<Func<object, object>> Formatters;

		public Tracer()
		{
			indentation = 0;
			Filters = new List<Func<object, bool>>();
			Formatters = new List<Func<object, object>>();
		}

		public ITraceScope Enter(object target, params object[] args)
		{
			if (args.Any((object x) => Filters.Any((Func<object, bool> f) => f(x))))
			{
				indentation++;
				return new TraceScope(delegate
				{
					indentation--;
				}, FormatArg, indentation, target, args);
			}
			return NullScope.Instance;
		}

		public object FormatArg(object arg)
		{
			if (arg == null)
			{
				return "null";
			}
			foreach (Func<object, object> formatter in Formatters)
			{
				object obj = formatter(arg);
				if (obj != null)
				{
					return obj;
				}
			}
			return arg;
		}

		public void Format<T>(Func<T, object> formatter)
		{
			Formatters.Add((object x) => (!(x is T)) ? null : formatter((T)x));
		}

		public void Filter<T>(Func<T, bool> filter)
		{
			Filters.Add((object x) => x is T && filter((T)x));
		}
	}
}