Decompiled source of SupplyChain v1.0.3

SupplyChain.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using MonoMod.RuntimeDetour;
using On.RoR2;
using R2API;
using RoR2;
using RoR2.Artifacts;
using RoR2.ExpansionManagement;
using SupplyChain.Artifacts;
using SupplyChain.Items;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SupplyChain")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+c0e0dab0372575b8db9f15a77693342c03073c1a")]
[assembly: AssemblyProduct("SupplyChain")]
[assembly: AssemblyTitle("SupplyChain")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SupplyChain
{
	internal static class Assets
	{
		private static GameObject prefabHolder;

		internal static Transform PrefabHolder
		{
			get
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Expected O, but got Unknown
				if (!Object.op_Implicit((Object)(object)prefabHolder))
				{
					prefabHolder = new GameObject("SupplyChainPrefabHolder");
					Object.DontDestroyOnLoad((Object)(object)prefabHolder);
					prefabHolder.SetActive(false);
				}
				return prefabHolder.transform;
			}
		}

		internal static void SetItemTier(ItemDef def, ItemTier tier)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: 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)
			typeof(ItemDef).GetField("deprecatedTier", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.SetValue(def, tier);
			RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, (Action)delegate
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				ItemTierDef itemTierDef = ItemTierCatalog.GetItemTierDef(tier);
				if (Object.op_Implicit((Object)(object)itemTierDef))
				{
					typeof(ItemDef).GetField("_itemTierDef", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(def, itemTierDef);
				}
			});
		}

		internal static ItemDef CreateItemDef(string name, string tokenBase, ItemTier tier, Sprite icon, GameObject model, ItemTag[] tags, bool canRemove = true)
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			ItemDef val = ScriptableObject.CreateInstance<ItemDef>();
			((Object)val).name = name;
			val.nameToken = tokenBase + "_NAME";
			val.pickupToken = tokenBase + "_PICKUP";
			val.descriptionToken = tokenBase + "_DESC";
			val.loreToken = tokenBase + "_LORE";
			val.canRemove = canRemove;
			val.hidden = false;
			val.tags = tags;
			val.pickupIconSprite = icon;
			val.pickupModelPrefab = model;
			SetItemTier(val, tier);
			return val;
		}

		private static byte[] ReadResource(string resourceName)
		{
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
			if (stream == null)
			{
				return null;
			}
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			return memoryStream.ToArray();
		}

		internal static Texture2D LoadRawTexture(string resourceName, int size)
		{
			//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_0037: Expected O, but got Unknown
			try
			{
				byte[] array = ReadResource(resourceName);
				if (array == null || array.Length != size * size * 4)
				{
					return null;
				}
				Texture2D val = new Texture2D(size, size, (TextureFormat)4, false)
				{
					wrapMode = (TextureWrapMode)1
				};
				val.LoadRawTextureData(array);
				val.Apply();
				return val;
			}
			catch (Exception arg)
			{
				Log.Error($"Failed to load texture '{resourceName}': {arg}");
				return null;
			}
		}

		internal static Sprite LoadSprite(string resourceName, int size)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = LoadRawTexture(resourceName, size);
			return Object.op_Implicit((Object)(object)val) ? Sprite.Create(val, new Rect(0f, 0f, (float)size, (float)size), new Vector2(0.5f, 0.5f)) : null;
		}

		internal static Material CreatePickupMaterial(Color color, Texture2D mainTexture, Color emission)
		{
			//IL_0006: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/LunarCoin/PickupLunarCoin.prefab").WaitForCompletion();
			Renderer val2 = (Object.op_Implicit((Object)(object)val) ? val.GetComponentInChildren<Renderer>(true) : null);
			Material val3 = ((Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)val2.sharedMaterial)) ? new Material(val2.sharedMaterial) : new Material(Shader.Find("Standard")));
			string[] array = new string[5] { "_MainTex", "_NormalTex", "_BumpMap", "_EmTex", "_EmissionMap" };
			foreach (string text in array)
			{
				if (val3.HasProperty(text))
				{
					val3.SetTexture(text, (Texture)(object)((!(text == "_MainTex")) ? null : (Object.op_Implicit((Object)(object)mainTexture) ? mainTexture : Texture2D.whiteTexture)));
				}
			}
			if (val3.HasProperty("_Color"))
			{
				val3.color = color;
			}
			if (val3.HasProperty("_EmColor"))
			{
				val3.SetColor("_EmColor", emission);
			}
			return val3;
		}

		internal static Mesh LoadObjMesh(string resourceName)
		{
			//IL_023a: 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_0248: Expected O, but got Unknown
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			byte[] array = ReadResource(resourceName);
			if (array == null)
			{
				return null;
			}
			List<Vector3> positions = new List<Vector3>();
			List<Vector2> texCoords = new List<Vector2>();
			List<Vector3> objNormals = new List<Vector3>();
			Dictionary<(int, int, int), int> vertexMap = new Dictionary<(int, int, int), int>();
			List<Vector3> vertices = new List<Vector3>();
			List<Vector2> uvs = new List<Vector2>();
			List<Vector3> normals = new List<Vector3>();
			List<int> list = new List<int>();
			using (StreamReader streamReader = new StreamReader(new MemoryStream(array)))
			{
				string text;
				while ((text = streamReader.ReadLine()) != null)
				{
					string[] array2 = text.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
					if (array2.Length == 0)
					{
						continue;
					}
					switch (array2[0])
					{
					case "v":
						positions.Add(new Vector3(0f - float.Parse(array2[1], CultureInfo.InvariantCulture), float.Parse(array2[2], CultureInfo.InvariantCulture), float.Parse(array2[3], CultureInfo.InvariantCulture)));
						break;
					case "vt":
						texCoords.Add(new Vector2(float.Parse(array2[1], CultureInfo.InvariantCulture), float.Parse(array2[2], CultureInfo.InvariantCulture)));
						break;
					case "vn":
						objNormals.Add(new Vector3(0f - float.Parse(array2[1], CultureInfo.InvariantCulture), float.Parse(array2[2], CultureInfo.InvariantCulture), float.Parse(array2[3], CultureInfo.InvariantCulture)));
						break;
					case "f":
					{
						int item = ResolveVertex(array2[1]);
						int item2 = ResolveVertex(array2[2]);
						for (int i = 3; i < array2.Length; i++)
						{
							int num = ResolveVertex(array2[i]);
							list.Add(item);
							list.Add(num);
							list.Add(item2);
							item2 = num;
						}
						break;
					}
					}
				}
			}
			Mesh val = new Mesh
			{
				indexFormat = (IndexFormat)1
			};
			val.SetVertices(vertices);
			val.SetUVs(0, uvs);
			val.SetNormals(normals);
			val.SetTriangles(list, 0);
			val.RecalculateBounds();
			return val;
			int ResolveVertex(string token)
			{
				//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
				//IL_0115: Unknown result type (might be due to invalid IL or missing references)
				//IL_0105: Unknown result type (might be due to invalid IL or missing references)
				//IL_013a: Unknown result type (might be due to invalid IL or missing references)
				//IL_012a: Unknown result type (might be due to invalid IL or missing references)
				string[] array3 = token.Split('/');
				int num2 = int.Parse(array3[0], CultureInfo.InvariantCulture);
				int num3 = ((array3.Length > 1 && array3[1].Length > 0) ? int.Parse(array3[1], CultureInfo.InvariantCulture) : 0);
				int num4 = ((array3.Length > 2 && array3[2].Length > 0) ? int.Parse(array3[2], CultureInfo.InvariantCulture) : 0);
				if (num2 < 0)
				{
					num2 += positions.Count + 1;
				}
				if (num3 < 0)
				{
					num3 += texCoords.Count + 1;
				}
				if (num4 < 0)
				{
					num4 += objNormals.Count + 1;
				}
				(int, int, int) key = (num2, num3, num4);
				if (vertexMap.TryGetValue(key, out var value))
				{
					return value;
				}
				value = vertices.Count;
				vertices.Add(positions[num2 - 1]);
				uvs.Add((num3 > 0) ? texCoords[num3 - 1] : Vector2.zero);
				normals.Add((num4 > 0) ? objNormals[num4 - 1] : Vector3.up);
				vertexMap[key] = value;
				return value;
			}
		}

		internal static GameObject CreatePickupModel(string name, string objResource, string textureResource, int textureSize, float targetSize, Func<GameObject> fallback = null)
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Mesh val = LoadObjMesh(objResource);
				if ((Object)(object)val == (Object)null)
				{
					Log.Warning("Model resource '" + objResource + "' missing; using fallback model for " + name + ".");
					return (fallback != null) ? fallback() : MysteryModel();
				}
				Texture2D mainTexture = LoadRawTexture(textureResource, textureSize);
				GameObject val2 = new GameObject(name);
				val2.transform.SetParent(PrefabHolder);
				val2.AddComponent<MeshFilter>().mesh = val;
				((Renderer)val2.AddComponent<MeshRenderer>()).material = CreatePickupMaterial(Color.white, mainTexture, Color.black);
				float[] array = new float[3];
				Bounds bounds = val.bounds;
				array[0] = ((Bounds)(ref bounds)).size.x;
				bounds = val.bounds;
				array[1] = ((Bounds)(ref bounds)).size.y;
				bounds = val.bounds;
				array[2] = ((Bounds)(ref bounds)).size.z;
				float num = Mathf.Max(array);
				if (num > 0f)
				{
					val2.transform.localScale = Vector3.one * (targetSize / num);
				}
				return val2;
			}
			catch (Exception arg)
			{
				Log.Error($"Failed to build pickup model {name}: {arg}");
				return (fallback != null) ? fallback() : MysteryModel();
			}
		}

		internal static GameObject MysteryModel()
		{
			//IL_0006: 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)
			return Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Mystery/PickupMystery.prefab").WaitForCompletion();
		}
	}
	internal static class ChestHooks
	{
		private class ChestOpener : MonoBehaviour
		{
			internal CharacterMaster master;
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static hook_OnInteractionBegin <0>__TrackOpener;

			public static hook_GetInteractability <1>__GateDropshippingChests;

			public static hook_ItemDrop <2>__OnChestItemDrop;
		}

		private static int bonusDropsThisStage;

		private static int commandChoicesThisStage;

		internal static void Init()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			object obj = <>O.<0>__TrackOpener;
			if (obj == null)
			{
				hook_OnInteractionBegin val = TrackOpener;
				<>O.<0>__TrackOpener = val;
				obj = (object)val;
			}
			PurchaseInteraction.OnInteractionBegin += (hook_OnInteractionBegin)obj;
			object obj2 = <>O.<1>__GateDropshippingChests;
			if (obj2 == null)
			{
				hook_GetInteractability val2 = GateDropshippingChests;
				<>O.<1>__GateDropshippingChests = val2;
				obj2 = (object)val2;
			}
			PurchaseInteraction.GetInteractability += (hook_GetInteractability)obj2;
			object obj3 = <>O.<2>__OnChestItemDrop;
			if (obj3 == null)
			{
				hook_ItemDrop val3 = OnChestItemDrop;
				<>O.<2>__OnChestItemDrop = val3;
				obj3 = (object)val3;
			}
			ChestBehavior.ItemDrop += (hook_ItemDrop)obj3;
			Stage.onServerStageBegin += delegate
			{
				bonusDropsThisStage = 0;
				commandChoicesThisStage = 0;
			};
		}

		private static bool IsMoneyChest(PurchaseInteraction self)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			return Object.op_Implicit((Object)(object)self) && (int)self.costType == 1 && Object.op_Implicit((Object)(object)((Component)self).GetComponent<ChestBehavior>());
		}

		private static Interactability GateDropshippingChests(orig_GetInteractability orig, PurchaseInteraction self, Interactor activator)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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 (IsMoneyChest(self) && Object.op_Implicit((Object)(object)activator))
			{
				CharacterBody component = ((Component)activator).GetComponent<CharacterBody>();
				if (Object.op_Implicit((Object)(object)component) && Dropshipping.Held(component.master))
				{
					return (Interactability)1;
				}
			}
			return orig.Invoke(self, activator);
		}

		private static void TrackOpener(orig_OnInteractionBegin orig, PurchaseInteraction self, Interactor activator)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			if (NetworkServer.active && (int)self.costType == 1 && Object.op_Implicit((Object)(object)activator))
			{
				ChestBehavior component = ((Component)self).GetComponent<ChestBehavior>();
				if (Object.op_Implicit((Object)(object)component))
				{
					CharacterBody component2 = ((Component)activator).GetComponent<CharacterBody>();
					CharacterMaster val = (Object.op_Implicit((Object)(object)component2) ? component2.master : null);
					if (Object.op_Implicit((Object)(object)val))
					{
						if (Dropshipping.Held(val))
						{
							return;
						}
						ChestOpener chestOpener = ((Component)component).GetComponent<ChestOpener>();
						if (!Object.op_Implicit((Object)(object)chestOpener))
						{
							chestOpener = ((Component)component).gameObject.AddComponent<ChestOpener>();
						}
						chestOpener.master = val;
					}
				}
			}
			orig.Invoke(self, activator);
		}

		private static void OnChestItemDrop(orig_ItemDrop orig, ChestBehavior self)
		{
			//IL_0075: 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_008a: Invalid comparison between Unknown and I4
			//IL_008d: 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_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: 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_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: 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_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_0344: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active || !Object.op_Implicit((Object)(object)Run.instance))
			{
				orig.Invoke(self);
				return;
			}
			ChestOpener component = ((Component)self).GetComponent<ChestOpener>();
			CharacterMaster val = (Object.op_Implicit((Object)(object)component) ? component.master : null);
			Inventory val2 = (Object.op_Implicit((Object)(object)val) ? val.inventory : null);
			if (!Object.op_Implicit((Object)(object)val2))
			{
				orig.Invoke(self);
				return;
			}
			PickupDef val3 = PickupCatalog.GetPickupDef(self.dropPickup);
			if (val3 == null || (int)val3.itemIndex == -1 || !SupplyChainPlugin.IsStandardTier(val3.itemTier))
			{
				orig.Invoke(self);
				return;
			}
			if (ArtifactOfDiversification.Enabled && val2.GetItemCount(val3.itemIndex) >= ArtifactOfDiversification.RerollThreshold.Value)
			{
				self.Roll();
				PickupDef pickupDef = PickupCatalog.GetPickupDef(self.dropPickup);
				Log.Info("Diversification reroll: " + val3.internalName + " -> " + (pickupDef?.internalName ?? "?"));
				val3 = pickupDef ?? val3;
			}
			int itemCount = val2.GetItemCount(RecallNotice.Def);
			int itemCount2 = val2.GetItemCount(LoadedDice.Def);
			if (itemCount > 0)
			{
				if (bonusDropsThisStage < RecallNotice.StageCapFor(itemCount))
				{
					PickupIndex val4 = PickFromList(VoidTierDownListForTier(val3.itemTier));
					if (val4 != PickupIndex.none)
					{
						bonusDropsThisStage++;
						SpawnBonus(self, val4);
					}
				}
			}
			else if (itemCount2 > 0)
			{
				int num = LoadedDice.StageCapBase.Value + (itemCount2 - 1);
				if (bonusDropsThisStage < num)
				{
					float num2 = HyperbolicChance(LoadedDice.BonusChanceBase.Value, LoadedDice.BonusChancePerStack.Value, LoadedDice.BonusChanceMax.Value, itemCount2);
					if (Run.instance.treasureRng.nextNormalizedFloat < num2)
					{
						PickupIndex val5 = PickFromList(TierDownListForTier(val3.itemTier));
						if (val5 != PickupIndex.none)
						{
							bonusDropsThisStage++;
							SpawnBonus(self, val5);
						}
					}
				}
			}
			int itemCount3 = val2.GetItemCount(PurchaseOrder.Def);
			if (itemCount3 > 0 && commandChoicesThisStage < PurchaseOrder.StageCapFor(itemCount3))
			{
				float num3 = HyperbolicChance(PurchaseOrder.ChanceBase.Value, PurchaseOrder.ChancePerStack.Value, PurchaseOrder.ChanceMax.Value, itemCount3);
				if (Run.instance.treasureRng.nextNormalizedFloat < num3 && SpawnCommandChoice(self, val3.itemTier))
				{
					commandChoicesThisStage++;
				}
			}
			int itemCount4 = val2.GetItemCount(BulkOrder.Def);
			if (itemCount4 > 0)
			{
				float num4 = HyperbolicChance(BulkOrder.ExtraChanceBase.Value, BulkOrder.ExtraChancePerStack.Value, BulkOrder.ExtraChanceMax.Value, itemCount4);
				if (Run.instance.treasureRng.nextNormalizedFloat < num4)
				{
					PickupIndex val6 = PickFromList(Run.instance.availableTier1DropList);
					if (val6 != PickupIndex.none)
					{
						SpawnBonus(self, val6);
					}
				}
			}
			orig.Invoke(self);
		}

		internal static float HyperbolicChance(float baseChance, float perStack, float max, int stacks)
		{
			if (stacks <= 0)
			{
				return 0f;
			}
			return baseChance + (max - baseChance) * (1f - 1f / (1f + perStack * (float)(stacks - 1)));
		}

		private static List<PickupIndex> TierDownListForTier(ItemTier tier)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected I4, but got Unknown
			return (tier - 1) switch
			{
				1 => Run.instance.availableTier2DropList, 
				0 => Run.instance.availableTier1DropList, 
				3 => Run.instance.availableTier3DropList, 
				_ => Run.instance.availableTier1DropList, 
			};
		}

		private static List<PickupIndex> TierListForTier(ItemTier tier)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected I4, but got Unknown
			return (tier - 1) switch
			{
				1 => Run.instance.availableTier3DropList, 
				0 => Run.instance.availableTier2DropList, 
				3 => Run.instance.availableTier3DropList, 
				_ => Run.instance.availableTier1DropList, 
			};
		}

		private static List<PickupIndex> VoidTierDownListForTier(ItemTier tier)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected I4, but got Unknown
			return (tier - 1) switch
			{
				1 => Run.instance.availableVoidTier2DropList, 
				0 => Run.instance.availableVoidTier1DropList, 
				3 => Run.instance.availableVoidTier3DropList, 
				_ => Run.instance.availableVoidTier1DropList, 
			};
		}

		private static PickupIndex PickFromList(List<PickupIndex> list)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			if (list == null || list.Count == 0)
			{
				return PickupIndex.none;
			}
			for (int i = 0; i < 8; i++)
			{
				PickupIndex val = list[Run.instance.treasureRng.RangeInt(0, list.Count)];
				if (!SupplyChainPlugin.BundlePickups.Contains(val))
				{
					return val;
				}
			}
			return PickupIndex.none;
		}

		private static void SpawnBonus(ChestBehavior chest, PickupIndex pickup)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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)
			Transform val = (Object.op_Implicit((Object)(object)chest.dropTransform) ? chest.dropTransform : ((Component)chest).gameObject.transform);
			PickupDropletController.CreatePickupDroplet(pickup, val.position + Vector3.up * 1.5f, val.forward * chest.dropForwardVelocityStrength + Vector3.up * chest.dropUpVelocityStrength);
		}

		private static bool SpawnCommandChoice(ChestBehavior chest, ItemTier tier)
		{
			//IL_002a: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			GameObject commandCubePrefab = CommandArtifactManager.commandCubePrefab;
			if (!Object.op_Implicit((Object)(object)commandCubePrefab))
			{
				Log.Warning("Command cube prefab unavailable; Purchase Order choice skipped.");
				return false;
			}
			List<PickupIndex> list = TierListForTier(tier);
			if (list == null || list.Count == 0)
			{
				return false;
			}
			List<PickupIndex> list2 = new List<PickupIndex>(list.Count);
			foreach (PickupIndex item in list)
			{
				if (!SupplyChainPlugin.BundlePickups.Contains(item))
				{
					list2.Add(item);
				}
			}
			if (list2.Count == 0)
			{
				return false;
			}
			Option[] optionsServer = PickupPickerController.GenerateOptionsFromArray(list2.ToArray());
			Transform val = (Object.op_Implicit((Object)(object)chest.dropTransform) ? chest.dropTransform : ((Component)chest).gameObject.transform);
			GameObject val2 = Object.Instantiate<GameObject>(commandCubePrefab, val.position + Vector3.up * 1.5f, Quaternion.identity);
			PickupPickerController component = val2.GetComponent<PickupPickerController>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.SetOptionsServer(optionsServer);
			}
			NetworkServer.Spawn(val2);
			Log.Info($"Purchase Order: offered a {tier} command choice ({list2.Count} options).");
			return true;
		}
	}
	internal static class GiveMoneyCompat
	{
		internal delegate void Orig(CharacterMaster self, uint amount, bool bypassStatManager);

		internal delegate void Handler(Orig orig, CharacterMaster self, uint amount, bool bypassStatManager);

		private delegate void OrigLegacy(CharacterMaster self, uint amount);

		private static readonly List<Hook> hooks = new List<Hook>();

		internal static void Add(Handler handler)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Expected O, but got Unknown
			MethodInfo method = typeof(CharacterMaster).GetMethod("GiveMoney", BindingFlags.Instance | BindingFlags.Public, null, new Type[2]
			{
				typeof(uint),
				typeof(bool)
			}, null);
			if (method != null)
			{
				hooks.Add(new Hook((MethodBase)method, (Delegate)handler));
				return;
			}
			MethodInfo method2 = typeof(CharacterMaster).GetMethod("GiveMoney", BindingFlags.Instance | BindingFlags.Public, null, new Type[1] { typeof(uint) }, null);
			if (method2 == null)
			{
				Log.Error("CharacterMaster.GiveMoney not found; gold income hooks are disabled.");
				return;
			}
			Action<OrigLegacy, CharacterMaster, uint> action = delegate(OrigLegacy orig, CharacterMaster self, uint amount)
			{
				handler(delegate(CharacterMaster master, uint value, bool _)
				{
					orig(master, value);
				}, self, amount, bypassStatManager: false);
			};
			hooks.Add(new Hook((MethodBase)method2, (Delegate)action));
		}
	}
	internal static class InventoryCompat
	{
		private static Func<Inventory, ItemIndex, int> getPermanent;

		private static bool resolved;

		internal static int GetPermanentCount(Inventory inventory, ItemIndex itemIndex)
		{
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			if (!resolved)
			{
				resolved = true;
				MethodInfo method = typeof(Inventory).GetMethod("GetItemCountPermanent", BindingFlags.Instance | BindingFlags.Public, null, new Type[1] { typeof(ItemIndex) }, null);
				if (method != null)
				{
					getPermanent = (Func<Inventory, ItemIndex, int>)method.CreateDelegate(typeof(Func<Inventory, ItemIndex, int>));
				}
				else
				{
					Log.Warning("Inventory.GetItemCountPermanent not found; falling back to GetItemCount.");
				}
			}
			return (getPermanent != null) ? getPermanent(inventory, itemIndex) : inventory.GetItemCount(itemIndex);
		}
	}
	internal static class Log
	{
		private static ManualLogSource _logSource;

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

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

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

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

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

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}
	}
	internal static class PickupCompat
	{
		private static Func<GenericPickupController, PickupIndex> getPickupIndex;

		private static bool resolved;

		internal static PickupIndex GetPickupIndex(GenericPickupController controller)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			if (!resolved)
			{
				resolved = true;
				getPickupIndex = Resolve();
			}
			return (getPickupIndex != null) ? getPickupIndex(controller) : PickupIndex.none;
		}

		private static Func<GenericPickupController, PickupIndex> Resolve()
		{
			MethodInfo methodInfo = typeof(GenericPickupController).GetProperty("pickupIndex", BindingFlags.Instance | BindingFlags.Public)?.GetGetMethod();
			if (methodInfo != null && methodInfo.ReturnType == typeof(PickupIndex))
			{
				return (Func<GenericPickupController, PickupIndex>)methodInfo.CreateDelegate(typeof(Func<GenericPickupController, PickupIndex>));
			}
			FieldInfo field = typeof(GenericPickupController).GetField("pickupIndex", BindingFlags.Instance | BindingFlags.Public);
			if (field != null && field.FieldType == typeof(PickupIndex))
			{
				return (GenericPickupController controller) => (PickupIndex)field.GetValue(controller);
			}
			Log.Warning("GenericPickupController.pickupIndex not found; Dropshipping cannot identify pickups.");
			return null;
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("Isaac_Cummings.SupplyChain", "SupplyChain", "1.0.3")]
	public class SupplyChainPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "Isaac_Cummings.SupplyChain";

		public const string PluginAuthor = "Isaac_Cummings";

		public const string PluginName = "SupplyChain";

		public const string PluginVersion = "1.0.3";

		internal static readonly HashSet<PickupIndex> BundlePickups = new HashSet<PickupIndex>();

		internal static readonly HashSet<ItemIndex> AmplifiableItems = new HashSet<ItemIndex>();

		public void Awake()
		{
			Log.Init(((BaseUnityPlugin)this).Logger);
			Safe("Bulk Order", delegate
			{
				BulkOrder.Init(((BaseUnityPlugin)this).Config);
			});
			Safe("Loaded Dice", delegate
			{
				LoadedDice.Init(((BaseUnityPlugin)this).Config);
			});
			Safe("Standing Order", delegate
			{
				StandingOrder.Init(((BaseUnityPlugin)this).Config);
			});
			Safe("Force Multiplier", delegate
			{
				ForceMultiplier.Init(((BaseUnityPlugin)this).Config);
			});
			Safe("Pyramid Scheme", delegate
			{
				PyramidScheme.Init(((BaseUnityPlugin)this).Config);
			});
			Safe("Purchase Order", delegate
			{
				PurchaseOrder.Init(((BaseUnityPlugin)this).Config);
			});
			Safe("Dropshipping", delegate
			{
				Dropshipping.Init(((BaseUnityPlugin)this).Config);
			});
			Safe("Recall Notice", delegate
			{
				RecallNotice.Init(((BaseUnityPlugin)this).Config);
			});
			Safe("Artifact of Diversification", delegate
			{
				ArtifactOfDiversification.Init(((BaseUnityPlugin)this).Config);
			});
			Safe("chest hooks", ChestHooks.Init);
			RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(BuildIndexSets));
			Log.Info("SupplyChain loaded.");
		}

		private static void Safe(string feature, Action init)
		{
			try
			{
				init();
			}
			catch (Exception arg)
			{
				Log.Error($"{feature} failed to initialize and is disabled: {arg}");
			}
		}

		internal static bool IsStandardTier(ItemTier tier)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Invalid comparison between Unknown and I4
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Invalid comparison between Unknown and I4
			return (int)tier == 0 || (int)tier == 1 || (int)tier == 2 || (int)tier == 4;
		}

		internal static bool IsCopyableTier(ItemTier tier)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			if ((int)tier <= 4 || tier - 6 <= 3)
			{
				return true;
			}
			return false;
		}

		private static void BuildIndexSets()
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Invalid comparison between Unknown and I4
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: 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_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Invalid comparison between Unknown and I4
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Invalid comparison between Unknown and I4
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Invalid comparison between Unknown and I4
			ItemDef[] array = (ItemDef[])(object)new ItemDef[8]
			{
				BulkOrder.Def,
				LoadedDice.Def,
				StandingOrder.Def,
				ForceMultiplier.Def,
				PyramidScheme.Def,
				PurchaseOrder.Def,
				Dropshipping.Def,
				RecallNotice.Def
			};
			foreach (ItemDef val in array)
			{
				if (Object.op_Implicit((Object)(object)val) && (int)val.itemIndex != -1)
				{
					PickupIndex val2 = PickupCatalog.FindPickupIndex(val.itemIndex);
					if (val2 != PickupIndex.none)
					{
						BundlePickups.Add(val2);
					}
				}
			}
			for (int j = 0; j < ItemCatalog.itemCount; j++)
			{
				ItemIndex val3 = (ItemIndex)j;
				ItemDef itemDef = ItemCatalog.GetItemDef(val3);
				if (Object.op_Implicit((Object)(object)itemDef) && !itemDef.hidden && ((int)itemDef.tier == 0 || (int)itemDef.tier == 1 || (int)itemDef.tier == 2 || (int)itemDef.tier == 4) && (Object)(object)itemDef != (Object)(object)ForceMultiplier.Def && (Object)(object)itemDef != (Object)(object)StandingOrder.Def)
				{
					AmplifiableItems.Add(val3);
				}
			}
			Log.Info($"SupplyChain index sets: {BundlePickups.Count} bundle pickups, {AmplifiableItems.Count} amplifiable items.");
		}
	}
}
namespace SupplyChain.Items
{
	internal static class BulkOrder
	{
		internal static ItemDef Def;

		internal static ConfigEntry<float> ExtraChanceBase;

		internal static ConfigEntry<float> ExtraChancePerStack;

		internal static ConfigEntry<float> ExtraChanceMax;

		internal static void Init(ConfigFile config)
		{
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Expected O, but got Unknown
			ExtraChanceBase = config.Bind<float>("BulkOrder", "ExtraChanceBase", 0.07f, "Chance for a gold chest to contain an extra white item, with one stack.");
			ExtraChancePerStack = config.Bind<float>("BulkOrder", "ExtraChancePerStack", 0.07f, "Hyperbolic growth rate toward the max chance per additional stack.");
			ExtraChanceMax = config.Bind<float>("BulkOrder", "ExtraChanceMax", 0.3f, "Maximum chance.");
			Def = Assets.CreateItemDef("BulkOrder", "BULK_ORDER", (ItemTier)0, Assets.LoadSprite("SupplyChain.icon_bulk_order.rgba", 128), Assets.CreatePickupModel("PickupBulkOrder", "SupplyChain.models.bulk_order.obj", "SupplyChain.models.bulk_order.rgba", 512, 0.6f), (ItemTag[])(object)new ItemTag[2]
			{
				(ItemTag)3,
				(ItemTag)4
			});
			ItemAPI.Add(new CustomItem(Def, new ItemDisplayRuleDict((ItemDisplayRule[])null)));
			int num = Mathf.RoundToInt(ExtraChanceBase.Value * 100f);
			int num2 = Mathf.RoundToInt(ExtraChanceMax.Value * 100f);
			LanguageAPI.Add("BULK_ORDER_NAME", "Bulk Order");
			LanguageAPI.Add("BULK_ORDER_PICKUP", "Chests sometimes ship with a free white item.");
			LanguageAPI.Add("BULK_ORDER_DESC", $"Gold-cost chests have a <style=cIsUtility>{num}% <style=cStack>(up to {num2}% with more stacks)</style></style> chance " + "to contain an additional <style=cIsUtility>common item</style>.");
			LanguageAPI.Add("BULK_ORDER_LORE", "Buy nine crates, the tenth crate ships free. Contents of tenth crate not guaranteed, inspected, or in some cases identified.");
		}
	}
	internal static class Dropshipping
	{
		private class DropshipLedger : MonoBehaviour
		{
			internal int credits;
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static hook_AttemptGrant <0>__CountCollection;
		}

		internal static ItemDef Def;

		internal static ConfigEntry<int> PlayersPerCopyDivisor;

		internal static ConfigEntry<bool> CopyLunarAndVoid;

		private static bool granting;

		private static bool loggedFailure;

		internal static void Init(ConfigFile config)
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Expected O, but got Unknown
			PlayersPerCopyDivisor = config.Bind<int>("Dropshipping", "PlayersPerCopyDivisor", 2, "You receive one copy for every (player count / this) items teammates collect. Default 2.");
			CopyLunarAndVoid = config.Bind<bool>("Dropshipping", "CopyLunarAndVoid", true, "Whether lunar and void items teammates collect also count and get copied. If false, only standard tiers (white/green/red/boss).");
			Def = Assets.CreateItemDef("Dropshipping", "DROPSHIPPING", (ItemTier)3, Assets.LoadSprite("SupplyChain.icon_dropshipping.rgba", 128), Assets.CreatePickupModel("PickupDropshipping", "SupplyChain.models.dropshipping.obj", "SupplyChain.models.dropshipping.rgba", 512, 0.6f), (ItemTag[])(object)new ItemTag[2]
			{
				(ItemTag)3,
				(ItemTag)4
			});
			ItemAPI.Add(new CustomItem(Def, new ItemDisplayRuleDict((ItemDisplayRule[])null)));
			int num = Mathf.Max(1, PlayersPerCopyDivisor.Value);
			LanguageAPI.Add("DROPSHIPPING_NAME", "Dropshipping");
			LanguageAPI.Add("DROPSHIPPING_PICKUP", "You can no longer open chests — but a cut of everything your teammates collect is drop-shipped to you.");
			LanguageAPI.Add("DROPSHIPPING_DESC", "<style=cDeath>You can no longer open gold chests.</style> In exchange, for every " + $"<style=cIsUtility>(player count / {num}) items your teammates collect</style>, " + "a <style=cIsUtility>copy is drop-shipped to you</style> <style=cStack>(throttle divided per stack, up to copying everything)</style>. <style=cDeath>Useless without teammates.</style>");
			LanguageAPI.Add("DROPSHIPPING_LORE", "The genius of dropshipping is that you never touch the product. You never warehouse it, never inspect it, never pry open a single crate. You stand between the supplier and the customer and take a cut of everything that passes between them — and in this particular arrangement, you are also, somehow, the customer.");
			object obj = <>O.<0>__CountCollection;
			if (obj == null)
			{
				hook_AttemptGrant val = CountCollection;
				<>O.<0>__CountCollection = val;
				obj = (object)val;
			}
			GenericPickupController.AttemptGrant += (hook_AttemptGrant)obj;
		}

		internal static bool Held(CharacterMaster master)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Invalid comparison between Unknown and I4
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			return Object.op_Implicit((Object)(object)master) && Object.op_Implicit((Object)(object)master.inventory) && (Object)(object)Def != (Object)null && (int)Def.itemIndex != -1 && master.inventory.GetItemCount(Def.itemIndex) > 0;
		}

		private static int PlayerCount()
		{
			int num = 0;
			foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
			{
				if (Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)instance.master))
				{
					num++;
				}
			}
			return num;
		}

		internal static int CopyThreshold(int playerCount, int stacks)
		{
			int num = Mathf.Max(1, PlayersPerCopyDivisor.Value) * Mathf.Max(1, stacks);
			return Mathf.Max(1, playerCount / num);
		}

		private static void CountCollection(orig_AttemptGrant orig, GenericPickupController self, CharacterBody body)
		{
			orig.Invoke(self, body);
			try
			{
				Count(self, body);
			}
			catch (Exception arg)
			{
				if (!loggedFailure)
				{
					loggedFailure = true;
					Log.Error($"Dropshipping: counting a pickup failed (pickups are unaffected): {arg}");
				}
			}
		}

		private static void Count(GenericPickupController self, CharacterBody body)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Invalid comparison between Unknown and I4
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Invalid comparison between Unknown and I4
			//IL_0193: 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)
			if (!NetworkServer.active || granting || !Object.op_Implicit((Object)(object)self) || !Object.op_Implicit((Object)(object)body))
			{
				return;
			}
			CharacterMaster master = body.master;
			if (!Object.op_Implicit((Object)(object)master) || !Object.op_Implicit((Object)(object)master.playerCharacterMasterController))
			{
				return;
			}
			PickupIndex pickupIndex = PickupCompat.GetPickupIndex(self);
			PickupDef pickupDef = PickupCatalog.GetPickupDef(pickupIndex);
			if (pickupDef == null || (int)pickupDef.itemIndex == -1)
			{
				return;
			}
			ItemDef itemDef = ItemCatalog.GetItemDef(pickupDef.itemIndex);
			if (!Object.op_Implicit((Object)(object)itemDef) || itemDef.hidden || !SupplyChainPlugin.IsCopyableTier(itemDef.tier) || SupplyChainPlugin.BundlePickups.Contains(pickupIndex) || (!CopyLunarAndVoid.Value && IsLunarOrVoid(itemDef.tier)))
			{
				return;
			}
			int playerCount = PlayerCount();
			granting = true;
			try
			{
				foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
				{
					CharacterMaster val = (Object.op_Implicit((Object)(object)instance) ? instance.master : null);
					if (!Object.op_Implicit((Object)(object)val) || (Object)(object)val == (Object)(object)master || !Object.op_Implicit((Object)(object)val.inventory))
					{
						continue;
					}
					int num = (((Object)(object)Def != (Object)null && (int)Def.itemIndex != -1) ? val.inventory.GetItemCount(Def.itemIndex) : 0);
					if (num > 0)
					{
						int num2 = CopyThreshold(playerCount, num);
						DropshipLedger dropshipLedger = ((Component)val).GetComponent<DropshipLedger>();
						if (!Object.op_Implicit((Object)(object)dropshipLedger))
						{
							dropshipLedger = ((Component)val).gameObject.AddComponent<DropshipLedger>();
						}
						dropshipLedger.credits++;
						if (dropshipLedger.credits >= num2)
						{
							dropshipLedger.credits -= num2;
							val.inventory.GiveItem(pickupDef.itemIndex, 1);
							Log.Info($"Dropshipping: copied {pickupDef.internalName} to {Util.GetBestMasterName(val)} (x{num} stacks, 1 per {num2} collected).");
						}
					}
				}
			}
			finally
			{
				granting = false;
			}
		}

		private static bool IsLunarOrVoid(ItemTier tier)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Invalid comparison between Unknown and I4
			if ((int)tier == 3 || tier - 6 <= 3)
			{
				return true;
			}
			return false;
		}
	}
	internal static class ForceMultiplier
	{
		private delegate int orig_GetItemCountEffective(Inventory self, ItemIndex itemIndex);

		internal static ItemDef Def;

		internal static ConfigEntry<float> BoostPerStack;

		internal static void Init(ConfigFile config)
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			BoostPerStack = config.Bind<float>("ForceMultiplier", "BoostPerStack", 0.1f, "Fractional bonus stacks applied to all other standard-tier items, per stack. Rounded down per item.");
			Def = Assets.CreateItemDef("ForceMultiplier", "FORCE_MULTIPLIER", (ItemTier)2, Assets.LoadSprite("SupplyChain.icon_force_multiplier.rgba", 128), Assets.CreatePickupModel("PickupForceMultiplier", "SupplyChain.models.force_multiplier.obj", "SupplyChain.models.force_multiplier.rgba", 512, 0.7f), (ItemTag[])(object)new ItemTag[2]
			{
				(ItemTag)3,
				(ItemTag)4
			});
			ItemAPI.Add(new CustomItem(Def, new ItemDisplayRuleDict((ItemDisplayRule[])null)));
			int num = Mathf.RoundToInt(BoostPerStack.Value * 100f);
			LanguageAPI.Add("FORCE_MULTIPLIER_NAME", "Force Multiplier");
			LanguageAPI.Add("FORCE_MULTIPLIER_PICKUP", "Deep stacks run deeper.");
			LanguageAPI.Add("FORCE_MULTIPLIER_DESC", $"All other standard items behave as if you had <style=cIsUtility>{num}% <style=cStack>(+{num}% per stack)</style> more stacks</style>, " + "rounded <style=cStack>down</style> per item. Lunar and void items are unaffected.");
			LanguageAPI.Add("FORCE_MULTIPLIER_LORE", "\"The audit found that the quartermaster had been reporting each pallet as one-point-one pallets. The audit also found that, somehow, the math held up under fire.\"");
			MethodInfo method = typeof(Inventory).GetMethod("GetItemCountEffective", BindingFlags.Instance | BindingFlags.Public, null, new Type[1] { typeof(ItemIndex) }, null);
			new Hook((MethodBase)method, typeof(ForceMultiplier).GetMethod("AmplifyCount", BindingFlags.Static | BindingFlags.NonPublic));
		}

		private static int AmplifyCount(orig_GetItemCountEffective orig, Inventory self, ItemIndex itemIndex)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Invalid comparison between Unknown and I4
			//IL_0049: 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)
			int num = orig(self, itemIndex);
			if (num <= 0 || (Object)(object)Def == (Object)null || (int)Def.itemIndex == -1 || !SupplyChainPlugin.AmplifiableItems.Contains(itemIndex))
			{
				return num;
			}
			int num2 = orig(self, Def.itemIndex);
			if (num2 <= 0)
			{
				return num;
			}
			return num + (int)((float)num * BoostPerStack.Value * (float)num2);
		}
	}
	internal static class LoadedDice
	{
		internal static ItemDef Def;

		internal static ConfigEntry<float> BonusChanceBase;

		internal static ConfigEntry<float> BonusChancePerStack;

		internal static ConfigEntry<float> BonusChanceMax;

		internal static ConfigEntry<int> StageCapBase;

		internal static void Init(ConfigFile config)
		{
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Expected O, but got Unknown
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Expected O, but got Unknown
			BonusChanceBase = config.Bind<float>("LoadedDice", "BonusChanceBase", 0.15f, "Chance for a gold chest to drop a bonus item one tier below its contents, with one stack.");
			BonusChancePerStack = config.Bind<float>("LoadedDice", "BonusChancePerStack", 0.1f, "Hyperbolic growth rate toward the max chance per additional stack.");
			BonusChanceMax = config.Bind<float>("LoadedDice", "BonusChanceMax", 0.4f, "Maximum chance.");
			StageCapBase = config.Bind<int>("LoadedDice", "StageCapBase", 2, "Maximum bonus drops per stage with one stack (+1 per additional stack). Recall Notice has its own separate cap.");
			Def = Assets.CreateItemDef("LoadedDice", "LOADED_DICE", (ItemTier)1, Assets.LoadSprite("SupplyChain.icon_loaded_dice.rgba", 128), Assets.CreatePickupModel("PickupLoadedDice", "SupplyChain.models.loaded_dice.obj", "SupplyChain.models.loaded_dice.rgba", 512, 0.55f), (ItemTag[])(object)new ItemTag[2]
			{
				(ItemTag)3,
				(ItemTag)4
			});
			ItemAPI.Add(new CustomItem(Def, new ItemDisplayRuleDict((ItemDisplayRule[])null)));
			int num = Mathf.RoundToInt(BonusChanceBase.Value * 100f);
			int num2 = Mathf.RoundToInt(BonusChanceMax.Value * 100f);
			LanguageAPI.Add("LOADED_DICE_NAME", "Loaded Dice");
			LanguageAPI.Add("LOADED_DICE_PICKUP", "Chests sometimes pay out twice... the house set a daily limit.");
			LanguageAPI.Add("LOADED_DICE_DESC", $"Gold-cost chests have a <style=cIsUtility>{num}% <style=cStack>(up to {num2}% with more stacks)</style></style> chance to drop a " + "<style=cIsUtility>bonus item one tier below their contents</style>. " + $"At most <style=cIsUtility>{StageCapBase.Value} <style=cStack>(+1 per stack)</style></style> bonus drops per stage. " + "<style=cIsVoid>Corruptible</style>.");
			LanguageAPI.Add("LOADED_DICE_LORE", "Confiscated from the estate of a casino magnate. The pips rearrange themselves when nobody is looking, which the courts ruled was technically not cheating because nobody was looking.");
		}
	}
	internal static class PurchaseOrder
	{
		internal static ItemDef Def;

		internal static ConfigEntry<float> ChanceBase;

		internal static ConfigEntry<float> ChancePerStack;

		internal static ConfigEntry<float> ChanceMax;

		internal static ConfigEntry<int> StageCapBase;

		internal static ConfigEntry<int> StacksPerExtraCap;

		internal static void Init(ConfigFile config)
		{
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Expected O, but got Unknown
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Expected O, but got Unknown
			ChanceBase = config.Bind<float>("PurchaseOrder", "ChanceBase", 0.1f, "Chance for a gold chest to also offer a Command-style choice of its tier, with one stack.");
			ChancePerStack = config.Bind<float>("PurchaseOrder", "ChancePerStack", 0.1f, "Hyperbolic growth rate toward the max chance per additional stack.");
			ChanceMax = config.Bind<float>("PurchaseOrder", "ChanceMax", 0.35f, "Maximum chance.");
			StageCapBase = config.Bind<int>("PurchaseOrder", "StageCapBase", 1, "Maximum command choices offered per stage with one stack.");
			StacksPerExtraCap = config.Bind<int>("PurchaseOrder", "StacksPerExtraCap", 2, "Additional stacks required to raise the per-stage cap by 1.");
			Def = Assets.CreateItemDef("PurchaseOrder", "PURCHASE_ORDER", (ItemTier)1, Assets.LoadSprite("SupplyChain.icon_purchase_order.rgba", 128), Assets.CreatePickupModel("PickupPurchaseOrder", "SupplyChain.models.purchase_order.obj", "SupplyChain.models.purchase_order.rgba", 512, 0.55f), (ItemTag[])(object)new ItemTag[2]
			{
				(ItemTag)3,
				(ItemTag)4
			});
			ItemAPI.Add(new CustomItem(Def, new ItemDisplayRuleDict((ItemDisplayRule[])null)));
			int num = Mathf.RoundToInt(ChanceBase.Value * 100f);
			int num2 = Mathf.RoundToInt(ChanceMax.Value * 100f);
			LanguageAPI.Add("PURCHASE_ORDER_NAME", "Purchase Order");
			LanguageAPI.Add("PURCHASE_ORDER_PICKUP", "Chests sometimes let you order exactly what you want.");
			LanguageAPI.Add("PURCHASE_ORDER_DESC", $"Gold-cost chests have a <style=cIsUtility>{num}% <style=cStack>(up to {num2}% with more stacks)</style></style> chance to also offer a " + "<style=cIsUtility>choice of any item</style> of the chest's tier, like an <style=cIsUtility>Artifact of Command</style> essence. " + $"At most <style=cIsUtility>{StageCapBase.Value} <style=cStack>(+1 per {StacksPerExtraCap.Value} stacks)</style></style> per stage.");
			LanguageAPI.Add("PURCHASE_ORDER_LORE", "Most procurement is a matter of taking what the warehouse sends and filing a complaint later. A purchase order inverts the relationship: you specify the part number, the quantity, and the delivery date, and the void obliges. The void has never once disputed an invoice, which the accounting department finds more unsettling than reassuring.");
		}

		internal static int StageCapFor(int stacks)
		{
			if (stacks <= 0)
			{
				return 0;
			}
			return StageCapBase.Value + (stacks - 1) / Mathf.Max(1, StacksPerExtraCap.Value);
		}
	}
	internal static class PyramidScheme
	{
		private class PyramidTracker : MonoBehaviour
		{
			internal int knownStacks;
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static hook_OnInventoryChanged <0>__DetectPickup;

			public static GiveMoneyCompat.Handler <1>__PayUpline;
		}

		internal static ItemDef Def;

		internal static ConfigEntry<float> TithePerStack;

		private static bool granting;

		internal static void Init(ConfigFile config)
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			TithePerStack = config.Bind<float>("PyramidScheme", "TithePerStack", 0.2f, "Fraction of gold income paid upline (lost) per stack, multiplicative.");
			Def = Assets.CreateItemDef("PyramidScheme", "PYRAMID_SCHEME", (ItemTier)3, Assets.LoadSprite("SupplyChain.icon_pyramid_scheme.rgba", 128), Assets.CreatePickupModel("PickupPyramidScheme", "SupplyChain.models.pyramid_scheme.obj", "SupplyChain.models.pyramid_scheme.rgba", 512, 0.65f), (ItemTag[])(object)new ItemTag[2]
			{
				(ItemTag)3,
				(ItemTag)4
			});
			ItemAPI.Add(new CustomItem(Def, new ItemDisplayRuleDict((ItemDisplayRule[])null)));
			int num = Mathf.RoundToInt(TithePerStack.Value * 100f);
			LanguageAPI.Add("PYRAMID_SCHEME_NAME", "Pyramid Scheme");
			LanguageAPI.Add("PYRAMID_SCHEME_PICKUP", "Gain +1 stack of everything you own... <style=cDeath>but your income pays the upline, forever.</style>");
			LanguageAPI.Add("PYRAMID_SCHEME_DESC", "On pickup, gain <style=cIsUtility>+1 stack of every item you own</style>. " + $"Afterwards, <style=cDeath>{num}% of your gold income <style=cStack>(stacks multiplicatively)</style> is paid upline</style>. " + "The upline does not pay back.");
			LanguageAPI.Add("PYRAMID_SCHEME_LORE", "It's not what you think. It's a reverse funnel system. The structure is more of a triangle, really. Your downline practically builds itself once you stop being so negative. Anyway — about your buy-in.");
			object obj = <>O.<0>__DetectPickup;
			if (obj == null)
			{
				hook_OnInventoryChanged val = DetectPickup;
				<>O.<0>__DetectPickup = val;
				obj = (object)val;
			}
			CharacterMaster.OnInventoryChanged += (hook_OnInventoryChanged)obj;
			GiveMoneyCompat.Add(PayUpline);
		}

		private static void DetectPickup(orig_OnInventoryChanged orig, CharacterMaster self)
		{
			//IL_007a: 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_003c: Invalid comparison between Unknown and I4
			//IL_00bd: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Expected O, but got Unknown
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self);
			if (!NetworkServer.active || granting || !Object.op_Implicit((Object)(object)self.inventory) || (Object)(object)Def == (Object)null || (int)Def.itemIndex == -1)
			{
				return;
			}
			PyramidTracker pyramidTracker = ((Component)self).GetComponent<PyramidTracker>();
			if (!Object.op_Implicit((Object)(object)pyramidTracker))
			{
				pyramidTracker = ((Component)self).gameObject.AddComponent<PyramidTracker>();
			}
			int permanentCount = InventoryCompat.GetPermanentCount(self.inventory, Def.itemIndex);
			int num = permanentCount - pyramidTracker.knownStacks;
			pyramidTracker.knownStacks = permanentCount;
			if (num <= 0)
			{
				return;
			}
			granting = true;
			try
			{
				int num2 = 0;
				for (int i = 0; i < ItemCatalog.itemCount; i++)
				{
					ItemIndex val = (ItemIndex)i;
					if (val != Def.itemIndex)
					{
						ItemDef itemDef = ItemCatalog.GetItemDef(val);
						if (Object.op_Implicit((Object)(object)itemDef) && !itemDef.hidden && SupplyChainPlugin.IsCopyableTier(itemDef.tier) && InventoryCompat.GetPermanentCount(self.inventory, val) > 0)
						{
							self.inventory.GiveItem(val, num);
							num2++;
						}
					}
				}
				Log.Info($"Pyramid Scheme paid out +{num} stack(s) of {num2} item(s) for {Util.GetBestMasterName(self)}");
				Chat.SendBroadcastChat((ChatMessageBase)new SimpleChatMessage
				{
					baseToken = $"<color=#79c7ec>{Util.GetBestMasterName(self)} joined a pyramid scheme: +{num} stack(s) of {num2} item(s). The upline thanks them.</color>"
				});
			}
			finally
			{
				granting = false;
			}
		}

		private static void PayUpline(GiveMoneyCompat.Orig orig, CharacterMaster self, uint amount, bool bypassStatManager)
		{
			//IL_004c: 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_0034: Invalid comparison between Unknown and I4
			if (NetworkServer.active && amount != 0 && !bypassStatManager && Object.op_Implicit((Object)(object)self.inventory) && (Object)(object)Def != (Object)null && (int)Def.itemIndex != -1)
			{
				int permanentCount = InventoryCompat.GetPermanentCount(self.inventory, Def.itemIndex);
				if (permanentCount > 0)
				{
					amount = (uint)Math.Round((double)amount * Math.Pow(1.0 - (double)Mathf.Clamp01(TithePerStack.Value), permanentCount));
				}
			}
			orig(self, amount, bypassStatManager);
		}
	}
	internal static class RecallNotice
	{
		internal static ItemDef Def;

		internal static ConfigEntry<int> StageCapBase;

		internal static ConfigEntry<int> StacksPerExtraCap;

		internal static ConfigEntry<int> StageCapMax;

		internal static void Init(ConfigFile config)
		{
			//IL_00ae: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Expected O, but got Unknown
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			StageCapBase = config.Bind<int>("RecallNotice", "StageCapBase", 1, "Guaranteed void bonus drops per stage with one stack. Recall has its own cap, separate from Loaded Dice's.");
			StacksPerExtraCap = config.Bind<int>("RecallNotice", "StacksPerExtraCap", 2, "Additional stacks required to raise the per-stage cap by 1 (slower than Loaded Dice's +1/stack).");
			StageCapMax = config.Bind<int>("RecallNotice", "StageCapMax", 3, "Hard ceiling on guaranteed void bonus drops per stage, regardless of stacks.");
			Def = Assets.CreateItemDef("RecallNotice", "RECALL_NOTICE", (ItemTier)7, Assets.LoadSprite("SupplyChain.icon_recall_notice.rgba", 128), Assets.CreatePickupModel("PickupRecallNotice", "SupplyChain.models.recall_notice.obj", "SupplyChain.models.recall_notice.rgba", 512, 0.6f), (ItemTag[])(object)new ItemTag[2]
			{
				(ItemTag)3,
				(ItemTag)4
			});
			Def.requiredExpansion = Addressables.LoadAssetAsync<ExpansionDef>((object)"RoR2/DLC1/Common/DLC1.asset").WaitForCompletion();
			ItemAPI.Add(new CustomItem(Def, new ItemDisplayRuleDict((ItemDisplayRule[])null)));
			ItemRelationshipProvider val = ScriptableObject.CreateInstance<ItemRelationshipProvider>();
			((Object)val).name = "SupplyChainContagiousItems";
			val.relationshipType = Addressables.LoadAssetAsync<ItemRelationshipType>((object)"RoR2/DLC1/Common/ContagiousItem.asset").WaitForCompletion();
			val.relationships = (Pair[])(object)new Pair[1]
			{
				new Pair
				{
					itemDef1 = LoadedDice.Def,
					itemDef2 = Def
				}
			};
			ContentAddition.AddItemRelationshipProvider(val);
			LanguageAPI.Add("RECALL_NOTICE_NAME", "Recall Notice");
			LanguageAPI.Add("RECALL_NOTICE_PICKUP", "Chests ship a guaranteed void replacement — one tier down, and rationed. <style=cIsVoid>Corrupts all Loaded Dice</style>.");
			LanguageAPI.Add("RECALL_NOTICE_DESC", "Gold-cost chests drop a <style=cIsVoid>guaranteed void item one tier below their contents</style>, " + $"at most <style=cIsUtility>{StageCapBase.Value} <style=cStack>(+1 per {StacksPerExtraCap.Value} stacks, max {StageCapMax.Value})</style></style> per stage. " + "<style=cIsVoid>Corrupts all Loaded Dice</style>.");
			LanguageAPI.Add("RECALL_NOTICE_LORE", "URGENT PRODUCT RECALL\nAffected units: all\nDefect: contents replaced during shipping\nRemedy: none. Replacement parts have already been delivered. Please do not attempt to return them.\n\nADDENDUM: shipping volume reduced following complaints that there was simply too much of a good thing.");
		}

		internal static int StageCapFor(int stacks)
		{
			if (stacks <= 0)
			{
				return 0;
			}
			int num = StageCapBase.Value + (stacks - 1) / Mathf.Max(1, StacksPerExtraCap.Value);
			return Mathf.Min(num, StageCapMax.Value);
		}
	}
	internal static class StandingOrder
	{
		internal static ItemDef Def;

		internal static ConfigEntry<int> ItemsPerStack;

		internal static void Init(ConfigFile config)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Expected O, but got Unknown
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			ItemsPerStack = config.Bind<int>("StandingOrder", "ItemsPerStack", 1, "Number of lowest-count items topped up by +1 stack each stage, per stack of this item.");
			Def = Assets.CreateItemDef("StandingOrder", "STANDING_ORDER", (ItemTier)2, Assets.LoadSprite("SupplyChain.icon_standing_order.rgba", 128), Assets.CreatePickupModel("PickupStandingOrder", "SupplyChain.models.standing_order.obj", "SupplyChain.models.standing_order.rgba", 512, 0.7f), (ItemTag[])(object)new ItemTag[2]
			{
				(ItemTag)3,
				(ItemTag)4
			});
			ItemAPI.Add(new CustomItem(Def, new ItemDisplayRuleDict((ItemDisplayRule[])null)));
			LanguageAPI.Add("STANDING_ORDER_NAME", "Standing Order");
			LanguageAPI.Add("STANDING_ORDER_PICKUP", "Automatically restock your scarcest items each stage.");
			LanguageAPI.Add("STANDING_ORDER_DESC", "At the start of each stage, gain <style=cIsUtility>+1 stack</style> of your " + $"<style=cIsUtility>{ItemsPerStack.Value} <style=cStack>(+{ItemsPerStack.Value} per stack)</style> lowest-count item(s)</style>. " + "Lunar, void, and hidden items are not restocked.");
			LanguageAPI.Add("STANDING_ORDER_LORE", "PROCUREMENT DIRECTIVE 7-C: Inventory levels shall be maintained. Shortfalls shall be remedied. Questions about where the materiel comes from shall be directed to the office of not asking that.");
			Stage.onServerStageBegin += OnStageBegin;
		}

		private static void OnStageBegin(Stage stage)
		{
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active)
			{
				return;
			}
			foreach (PlayerCharacterMasterController instance in PlayerCharacterMasterController.instances)
			{
				CharacterMaster master = instance.master;
				Inventory val = (Object.op_Implicit((Object)(object)master) ? master.inventory : null);
				if (!Object.op_Implicit((Object)(object)val))
				{
					continue;
				}
				int itemCount = val.GetItemCount(Def);
				if (itemCount <= 0)
				{
					continue;
				}
				int count = itemCount * ItemsPerStack.Value;
				List<(ItemIndex, int)> list = new List<(ItemIndex, int)>();
				foreach (ItemIndex amplifiableItem in SupplyChainPlugin.AmplifiableItems)
				{
					int permanentCount = InventoryCompat.GetPermanentCount(val, amplifiableItem);
					if (permanentCount > 0)
					{
						list.Add((amplifiableItem, permanentCount));
					}
				}
				foreach (var item in (from e in list
					orderby e.count, (int)e.index
					select e).Take(count))
				{
					val.GiveItem(item.Item1, 1);
					ItemDef itemDef = ItemCatalog.GetItemDef(item.Item1);
					Log.Info("Standing Order restocked " + (((itemDef != null) ? ((Object)itemDef).name : null) ?? "?") + " for " + Util.GetBestMasterName(master));
				}
			}
		}
	}
}
namespace SupplyChain.Artifacts
{
	internal static class ArtifactOfDiversification
	{
		internal static ArtifactDef Def;

		internal static ConfigEntry<int> RerollThreshold;

		internal static bool Enabled => Object.op_Implicit((Object)(object)Def) && Object.op_Implicit((Object)(object)RunArtifactManager.instance) && RunArtifactManager.instance.IsArtifactEnabled(Def);

		internal static void Init(ConfigFile config)
		{
			RerollThreshold = config.Bind<int>("ArtifactOfDiversification", "RerollThreshold", 5, "Chest drops reroll once if the opener already owns at least this many stacks of the rolled item.");
			Def = ScriptableObject.CreateInstance<ArtifactDef>();
			Def.cachedName = "ArtifactOfDiversification";
			Def.nameToken = "ARTIFACT_DIVERSIFICATION_NAME";
			Def.descriptionToken = "ARTIFACT_DIVERSIFICATION_DESC";
			Def.smallIconSelectedSprite = Assets.LoadSprite("SupplyChain.icon_artifact_diversification_enabled.rgba", 128);
			Def.smallIconDeselectedSprite = Assets.LoadSprite("SupplyChain.icon_artifact_diversification_disabled.rgba", 128);
			ContentAddition.AddArtifactDef(Def);
			LanguageAPI.Add("ARTIFACT_DIVERSIFICATION_NAME", "Artifact of Diversification");
			LanguageAPI.Add("ARTIFACT_DIVERSIFICATION_DESC", $"Chests reroll their contents once when they would drop an item you already own {RerollThreshold.Value}+ stacks of.");
		}
	}
}