Decompiled source of AllMapValuables v1.0.0

AllMapValuables.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;

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

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 REPOJP.AllMapValuables
{
	[BepInPlugin("REPOJP.AllMapValuables", "AllMapValuables", "1.0.0")]
	public sealed class AllMapValuablesPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "REPOJP.AllMapValuables";

		public const string PluginName = "AllMapValuables";

		public const string PluginVersion = "1.0.0";

		internal static AllMapValuablesPlugin Instance;

		internal static ManualLogSource Log;

		private Harmony harmony;

		private ConfigEntry<bool> enableMod;

		private ConfigEntry<bool> enableVerboseLog;

		private ConfigEntry<bool> fallbackToVanillaOnError;

		private readonly Dictionary<string, ConfigEntry<int>> levelWeightConfigs = new Dictionary<string, ConfigEntry<int>>(StringComparer.OrdinalIgnoreCase);

		private void Awake()
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			enableMod = ((BaseUnityPlugin)this).Config.Bind<bool>("A General", "EnableMod", true, "Enable or disable this mod / このMODの有効無効");
			enableVerboseLog = ((BaseUnityPlugin)this).Config.Bind<bool>("A General", "EnableVerboseLog", false, "Enable verbose debug log / 詳細デバッグログ有効");
			fallbackToVanillaOnError = ((BaseUnityPlugin)this).Config.Bind<bool>("A General", "FallbackToVanillaOnError", true, "Fall back to vanilla valuable generation when an error occurs / エラー時バニラ生成へ自動復帰");
			harmony = new Harmony("REPOJP.AllMapValuables");
			harmony.PatchAll();
		}

		private void OnDestroy()
		{
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		internal bool IsEnabled()
		{
			return enableMod != null && enableMod.Value;
		}

		internal bool IsVerboseLogEnabled()
		{
			return enableVerboseLog != null && enableVerboseLog.Value;
		}

		internal bool IsFallbackToVanillaOnErrorEnabled()
		{
			return fallbackToVanillaOnError != null && fallbackToVanillaOnError.Value;
		}

		internal void EnsureLevelWeightConfigs()
		{
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Expected O, but got Unknown
			if ((Object)(object)RunManager.instance == (Object)null)
			{
				return;
			}
			List<Level> list = new List<Level>();
			if (RunManager.instance.levels != null)
			{
				foreach (Level level in RunManager.instance.levels)
				{
					if ((Object)(object)level != (Object)null)
					{
						list.Add(level);
					}
				}
			}
			if ((Object)(object)RunManager.instance.levelCurrent != (Object)null && !list.Contains(RunManager.instance.levelCurrent))
			{
				list.Add(RunManager.instance.levelCurrent);
			}
			foreach (Level item in list)
			{
				string levelName = GetLevelName(item);
				if (!string.IsNullOrWhiteSpace(levelName) && !IsExcludedLevelName(levelName) && !levelWeightConfigs.ContainsKey(levelName))
				{
					levelWeightConfigs[levelName] = ((BaseUnityPlugin)this).Config.Bind<int>("B Level Valuable Weights", levelName, 1, new ConfigDescription($"Spawn weight for valuables from level \"{levelName}\" / このマップ由来貴重品の生成重み", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 10), Array.Empty<object>()));
				}
			}
		}

		internal int GetLevelWeight(Level level)
		{
			EnsureLevelWeightConfigs();
			string levelName = GetLevelName(level);
			if (string.IsNullOrWhiteSpace(levelName))
			{
				return 1;
			}
			if (IsExcludedLevelName(levelName))
			{
				return 1;
			}
			if (levelWeightConfigs.TryGetValue(levelName, out ConfigEntry<int> value) && value != null)
			{
				return Mathf.Clamp(value.Value, 1, 10);
			}
			return 1;
		}

		internal static string GetLevelName(Level level)
		{
			if ((Object)(object)level == (Object)null)
			{
				return string.Empty;
			}
			return string.IsNullOrWhiteSpace(((Object)level).name) ? string.Empty : ((Object)level).name.Trim();
		}

		internal static bool IsExcludedLevelName(string levelName)
		{
			if (string.IsNullOrWhiteSpace(levelName))
			{
				return true;
			}
			string text = levelName.Trim();
			if (text.StartsWith("Level - ", StringComparison.OrdinalIgnoreCase))
			{
				text = text.Substring("Level - ".Length).Trim();
			}
			return string.Equals(text, "Splash Screen", StringComparison.OrdinalIgnoreCase) || string.Equals(text, "Main Menu", StringComparison.OrdinalIgnoreCase) || string.Equals(text, "Lobby Menu", StringComparison.OrdinalIgnoreCase);
		}

		internal static void WriteInfo(string message)
		{
			if (Log != null)
			{
				Log.LogInfo((object)message);
			}
		}

		internal static void WriteWarning(string message)
		{
			if (Log != null)
			{
				Log.LogWarning((object)message);
			}
		}

		internal static void WriteError(string message)
		{
			if (Log != null)
			{
				Log.LogError((object)message);
			}
		}
	}
	[HarmonyPatch(typeof(ValuableDirector), "SetupHost")]
	internal static class ValuableDirectorSetupHostPatch
	{
		private sealed class WeightedPrefabRef
		{
			public PrefabRef PrefabRef;

			public string ResourcePath;

			public int Weight;

			public string SourceLevelName;
		}

		private sealed class WeightedPoolSet
		{
			public readonly List<WeightedPrefabRef> TinyWeighted = new List<WeightedPrefabRef>();

			public readonly List<WeightedPrefabRef> SmallWeighted = new List<WeightedPrefabRef>();

			public readonly List<WeightedPrefabRef> MediumWeighted = new List<WeightedPrefabRef>();

			public readonly List<WeightedPrefabRef> BigWeighted = new List<WeightedPrefabRef>();

			public readonly List<WeightedPrefabRef> WideWeighted = new List<WeightedPrefabRef>();

			public readonly List<WeightedPrefabRef> TallWeighted = new List<WeightedPrefabRef>();

			public readonly List<WeightedPrefabRef> VeryTallWeighted = new List<WeightedPrefabRef>();

			public readonly Dictionary<string, WeightedPrefabRef> TinyUniqueMap = new Dictionary<string, WeightedPrefabRef>(StringComparer.OrdinalIgnoreCase);

			public readonly Dictionary<string, WeightedPrefabRef> SmallUniqueMap = new Dictionary<string, WeightedPrefabRef>(StringComparer.OrdinalIgnoreCase);

			public readonly Dictionary<string, WeightedPrefabRef> MediumUniqueMap = new Dictionary<string, WeightedPrefabRef>(StringComparer.OrdinalIgnoreCase);

			public readonly Dictionary<string, WeightedPrefabRef> BigUniqueMap = new Dictionary<string, WeightedPrefabRef>(StringComparer.OrdinalIgnoreCase);

			public readonly Dictionary<string, WeightedPrefabRef> WideUniqueMap = new Dictionary<string, WeightedPrefabRef>(StringComparer.OrdinalIgnoreCase);

			public readonly Dictionary<string, WeightedPrefabRef> TallUniqueMap = new Dictionary<string, WeightedPrefabRef>(StringComparer.OrdinalIgnoreCase);

			public readonly Dictionary<string, WeightedPrefabRef> VeryTallUniqueMap = new Dictionary<string, WeightedPrefabRef>(StringComparer.OrdinalIgnoreCase);

			public List<PrefabRef> TinyUnique = new List<PrefabRef>();

			public List<PrefabRef> SmallUnique = new List<PrefabRef>();

			public List<PrefabRef> MediumUnique = new List<PrefabRef>();

			public List<PrefabRef> BigUnique = new List<PrefabRef>();

			public List<PrefabRef> WideUnique = new List<PrefabRef>();

			public List<PrefabRef> TallUnique = new List<PrefabRef>();

			public List<PrefabRef> VeryTallUnique = new List<PrefabRef>();

			public bool IsCompletelyEmpty()
			{
				return TinyWeighted.Count == 0 && SmallWeighted.Count == 0 && MediumWeighted.Count == 0 && BigWeighted.Count == 0 && WideWeighted.Count == 0 && TallWeighted.Count == 0 && VeryTallWeighted.Count == 0;
			}
		}

		[CompilerGenerated]
		private sealed class <CustomSetupHost>d__32 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public ValuableDirector director;

			private WeightedPoolSet <poolSet>5__1;

			private List<ValuableVolume> <allVolumes>5__2;

			private List<ValuableVolume> <tinyVolumes>5__3;

			private List<ValuableVolume> <smallVolumes>5__4;

			private List<ValuableVolume> <mediumVolumes>5__5;

			private List<ValuableVolume> <bigVolumes>5__6;

			private List<ValuableVolume> <wideVolumes>5__7;

			private List<ValuableVolume> <tallVolumes>5__8;

			private List<ValuableVolume> <veryTallVolumes>5__9;

			private string <valuableDebugName>5__10;

			private int <totalMaxAmount>5__11;

			private int[] <maxAmounts>5__12;

			private string[] <paths>5__13;

			private int[] <chances>5__14;

			private List<ValuableVolume>[] <volumeLists>5__15;

			private List<WeightedPrefabRef>[] <weightedPools>5__16;

			private int[] <volumeIndex>5__17;

			private int <index>5__18;

			private float <highestRoll>5__19;

			private int <selectedCategoryIndex>5__20;

			private ValuableVolume <targetVolume>5__21;

			private WeightedPrefabRef <selectedValuable>5__22;

			private int <i>5__23;

			private int <roll>5__24;

			private PhotonView <photonView>5__25;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <CustomSetupHost>d__32(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<poolSet>5__1 = null;
				<allVolumes>5__2 = null;
				<tinyVolumes>5__3 = null;
				<smallVolumes>5__4 = null;
				<mediumVolumes>5__5 = null;
				<bigVolumes>5__6 = null;
				<wideVolumes>5__7 = null;
				<tallVolumes>5__8 = null;
				<veryTallVolumes>5__9 = null;
				<valuableDebugName>5__10 = null;
				<maxAmounts>5__12 = null;
				<paths>5__13 = null;
				<chances>5__14 = null;
				<volumeLists>5__15 = null;
				<weightedPools>5__16 = null;
				<volumeIndex>5__17 = null;
				<targetVolume>5__21 = null;
				<selectedValuable>5__22 = null;
				<photonView>5__25 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0cd5: Unknown result type (might be due to invalid IL or missing references)
				//IL_0cdf: Expected O, but got Unknown
				//IL_0d37: Unknown result type (might be due to invalid IL or missing references)
				//IL_0d41: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					SetFieldValue(SetupCompleteField, director, false);
					SetFieldValue(ValuableTargetAmountField, director, 0);
					SetFieldValue(TotalCurrentValueField, director, 0f);
					SetFieldValue(ValuableSpawnPlayerReadyField, director, 0);
					SetFieldValue(SwitchSetupPlayerReadyField, director, 0);
					SetFieldValue(SwitchSetupPlayerReadyListField, director, new List<Player>());
					CalculateMaxAmounts(director);
					<poolSet>5__1 = BuildWeightedPoolSet();
					SetFieldValue(TinyValuablesField, director, <poolSet>5__1.TinyUnique);
					SetFieldValue(SmallValuablesField, director, <poolSet>5__1.SmallUnique);
					SetFieldValue(MediumValuablesField, director, <poolSet>5__1.MediumUnique);
					SetFieldValue(BigValuablesField, director, <poolSet>5__1.BigUnique);
					SetFieldValue(WideValuablesField, director, <poolSet>5__1.WideUnique);
					SetFieldValue(TallValuablesField, director, <poolSet>5__1.TallUnique);
					SetFieldValue(VeryTallValuablesField, director, <poolSet>5__1.VeryTallUnique);
					<allVolumes>5__2 = Object.FindObjectsOfType<ValuableVolume>(false).ToList();
					<tinyVolumes>5__3 = <allVolumes>5__2.FindAll((ValuableVolume x) => (int)x.VolumeType == 0);
					<smallVolumes>5__4 = <allVolumes>5__2.FindAll((ValuableVolume x) => (int)x.VolumeType == 1);
					<mediumVolumes>5__5 = <allVolumes>5__2.FindAll((ValuableVolume x) => (int)x.VolumeType == 2);
					<bigVolumes>5__6 = <allVolumes>5__2.FindAll((ValuableVolume x) => (int)x.VolumeType == 3);
					<wideVolumes>5__7 = <allVolumes>5__2.FindAll((ValuableVolume x) => (int)x.VolumeType == 4);
					<tallVolumes>5__8 = <allVolumes>5__2.FindAll((ValuableVolume x) => (int)x.VolumeType == 5);
					<veryTallVolumes>5__9 = <allVolumes>5__2.FindAll((ValuableVolume x) => (int)x.VolumeType == 6);
					ListExtension.Shuffle<ValuableVolume>((IList<ValuableVolume>)<tinyVolumes>5__3);
					ListExtension.Shuffle<ValuableVolume>((IList<ValuableVolume>)<smallVolumes>5__4);
					ListExtension.Shuffle<ValuableVolume>((IList<ValuableVolume>)<mediumVolumes>5__5);
					ListExtension.Shuffle<ValuableVolume>((IList<ValuableVolume>)<bigVolumes>5__6);
					ListExtension.Shuffle<ValuableVolume>((IList<ValuableVolume>)<wideVolumes>5__7);
					ListExtension.Shuffle<ValuableVolume>((IList<ValuableVolume>)<tallVolumes>5__8);
					ListExtension.Shuffle<ValuableVolume>((IList<ValuableVolume>)<veryTallVolumes>5__9);
					SetFieldValue(TinyVolumesField, director, <tinyVolumes>5__3);
					SetFieldValue(SmallVolumesField, director, <smallVolumes>5__4);
					SetFieldValue(MediumVolumesField, director, <mediumVolumes>5__5);
					SetFieldValue(BigVolumesField, director, <bigVolumes>5__6);
					SetFieldValue(WideVolumesField, director, <wideVolumes>5__7);
					SetFieldValue(TallVolumesField, director, <tallVolumes>5__8);
					SetFieldValue(VeryTallVolumesField, director, <veryTallVolumes>5__9);
					<valuableDebugName>5__10 = GetValuableDebugName(director);
					if (string.Equals(<valuableDebugName>5__10, "All", StringComparison.OrdinalIgnoreCase))
					{
						SetFieldValue(TotalMaxAmountField, director, <allVolumes>5__2.Count);
						SetFieldValue(TotalMaxValueField, director, 99999f);
						SetFieldValue(TinyMaxAmountField, director, <tinyVolumes>5__3.Count);
						SetFieldValue(SmallMaxAmountField, director, <smallVolumes>5__4.Count);
						SetFieldValue(MediumMaxAmountField, director, <mediumVolumes>5__5.Count);
						SetFieldValue(BigMaxAmountField, director, <bigVolumes>5__6.Count);
						SetFieldValue(WideMaxAmountField, director, <wideVolumes>5__7.Count);
						SetFieldValue(TallMaxAmountField, director, <tallVolumes>5__8.Count);
						SetFieldValue(VeryTallMaxAmountField, director, <veryTallVolumes>5__9.Count);
					}
					if (string.Equals(<valuableDebugName>5__10, "None", StringComparison.OrdinalIgnoreCase) || <poolSet>5__1.IsCompletelyEmpty())
					{
						SetFieldValue(TotalMaxAmountField, director, 0);
						SetFieldValue(TinyMaxAmountField, director, 0);
						SetFieldValue(SmallMaxAmountField, director, 0);
						SetFieldValue(MediumMaxAmountField, director, 0);
						SetFieldValue(BigMaxAmountField, director, 0);
						SetFieldValue(WideMaxAmountField, director, 0);
						SetFieldValue(TallMaxAmountField, director, 0);
						SetFieldValue(VeryTallMaxAmountField, director, 0);
					}
					<totalMaxAmount>5__11 = GetFieldValue<int>(TotalMaxAmountField, director);
					<maxAmounts>5__12 = new int[7]
					{
						GetFieldValue<int>(TinyMaxAmountField, director),
						GetFieldValue<int>(SmallMaxAmountField, director),
						GetFieldValue<int>(MediumMaxAmountField, director),
						GetFieldValue<int>(BigMaxAmountField, director),
						GetFieldValue<int>(WideMaxAmountField, director),
						GetFieldValue<int>(TallMaxAmountField, director),
						GetFieldValue<int>(VeryTallMaxAmountField, director)
					};
					<paths>5__13 = new string[7]
					{
						GetFieldValue<string>(AccessTools.Field(typeof(ValuableDirector), "tinyPath"), director),
						GetFieldValue<string>(AccessTools.Field(typeof(ValuableDirector), "smallPath"), director),
						GetFieldValue<string>(AccessTools.Field(typeof(ValuableDirector), "mediumPath"), director),
						GetFieldValue<string>(AccessTools.Field(typeof(ValuableDirector), "bigPath"), director),
						GetFieldValue<string>(AccessTools.Field(typeof(ValuableDirector), "widePath"), director),
						GetFieldValue<string>(AccessTools.Field(typeof(ValuableDirector), "tallPath"), director),
						GetFieldValue<string>(AccessTools.Field(typeof(ValuableDirector), "veryTallPath"), director)
					};
					<chances>5__14 = new int[7] { director.tinyChance, director.smallChance, director.mediumChance, director.bigChance, director.wideChance, director.tallChance, director.veryTallChance };
					<volumeLists>5__15 = new List<ValuableVolume>[7] { <tinyVolumes>5__3, <smallVolumes>5__4, <mediumVolumes>5__5, <bigVolumes>5__6, <wideVolumes>5__7, <tallVolumes>5__8, <veryTallVolumes>5__9 };
					<weightedPools>5__16 = new List<WeightedPrefabRef>[7] { <poolSet>5__1.TinyWeighted, <poolSet>5__1.SmallWeighted, <poolSet>5__1.MediumWeighted, <poolSet>5__1.BigWeighted, <poolSet>5__1.WideWeighted, <poolSet>5__1.TallWeighted, <poolSet>5__1.VeryTallWeighted };
					<volumeIndex>5__17 = new int[7];
					if ((Object)(object)AllMapValuablesPlugin.Instance != (Object)null && AllMapValuablesPlugin.Instance.IsVerboseLogEnabled())
					{
						AllMapValuablesPlugin.WriteInfo($"Pool Summary | Tiny:{<poolSet>5__1.TinyWeighted.Count} Small:{<poolSet>5__1.SmallWeighted.Count} Medium:{<poolSet>5__1.MediumWeighted.Count} Big:{<poolSet>5__1.BigWeighted.Count} Wide:{<poolSet>5__1.WideWeighted.Count} Tall:{<poolSet>5__1.TallWeighted.Count} VeryTall:{<poolSet>5__1.VeryTallWeighted.Count}");
					}
					<index>5__18 = 0;
					goto IL_0c1c;
				case 1:
					<>1__state = -1;
					<targetVolume>5__21 = null;
					<selectedValuable>5__22 = null;
					goto IL_0c0a;
				case 2:
					<>1__state = -1;
					goto IL_0cf0;
				case 3:
					{
						<>1__state = -1;
						break;
					}
					IL_0c1c:
					if (<index>5__18 < <totalMaxAmount>5__11)
					{
						<highestRoll>5__19 = -1f;
						<selectedCategoryIndex>5__20 = -1;
						<i>5__23 = 0;
						while (<i>5__23 < <volumeLists>5__15.Length)
						{
							if (<volumeIndex>5__17[<i>5__23] < <maxAmounts>5__12[<i>5__23] && <volumeIndex>5__17[<i>5__23] < <volumeLists>5__15[<i>5__23].Count && <weightedPools>5__16[<i>5__23] != null && <weightedPools>5__16[<i>5__23].Count != 0)
							{
								<roll>5__24 = Random.Range(0, <chances>5__14[<i>5__23]);
								if ((float)<roll>5__24 > <highestRoll>5__19)
								{
									<highestRoll>5__19 = <roll>5__24;
									<selectedCategoryIndex>5__20 = <i>5__23;
								}
							}
							<i>5__23++;
						}
						if (<selectedCategoryIndex>5__20 != -1)
						{
							<targetVolume>5__21 = <volumeLists>5__15[<selectedCategoryIndex>5__20][<volumeIndex>5__17[<selectedCategoryIndex>5__20]];
							<selectedValuable>5__22 = PickWeightedPrefab(<weightedPools>5__16[<selectedCategoryIndex>5__20]);
							if (<selectedValuable>5__22 == null || <selectedValuable>5__22.PrefabRef == null)
							{
								<volumeIndex>5__17[<selectedCategoryIndex>5__20]++;
								goto IL_0c0a;
							}
							SpawnMethod.Invoke(director, new object[3]
							{
								<selectedValuable>5__22.PrefabRef,
								<targetVolume>5__21,
								<paths>5__13[<selectedCategoryIndex>5__20]
							});
							<volumeIndex>5__17[<selectedCategoryIndex>5__20]++;
							<>2__current = null;
							<>1__state = 1;
							return true;
						}
					}
					if (GameManager.instance.gameMode == 1)
					{
						<photonView>5__25 = ((Component)director).GetComponent<PhotonView>();
						if ((Object)(object)<photonView>5__25 != (Object)null)
						{
							<photonView>5__25.RPC("ValuablesTargetSetRPC", (RpcTarget)0, new object[1] { GetFieldValue<int>(ValuableTargetAmountField, director) });
						}
						<photonView>5__25 = null;
					}
					SetFieldValue(ValuableSpawnPlayerReadyField, director, GetFieldValue<int>(ValuableSpawnPlayerReadyField, director) + 1);
					goto IL_0cf0;
					IL_0cf0:
					if (GameManager.instance.gameMode == 1 && GetFieldValue<int>(ValuableSpawnPlayerReadyField, director) < PhotonNetwork.CurrentRoom.PlayerCount)
					{
						<>2__current = (object)new WaitForSeconds(0.1f);
						<>1__state = 2;
						return true;
					}
					director.VolumesAndSwitchSetup();
					break;
					IL_0c0a:
					<index>5__18++;
					goto IL_0c1c;
				}
				if (GameManager.instance.gameMode == 1 && GetFieldValue<int>(SwitchSetupPlayerReadyField, director) < PhotonNetwork.CurrentRoom.PlayerCount)
				{
					<>2__current = (object)new WaitForSeconds(0.1f);
					<>1__state = 3;
					return true;
				}
				SetFieldValue(SetupCompleteField, director, true);
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private static readonly MethodInfo SpawnMethod = AccessTools.Method(typeof(ValuableDirector), "Spawn", (Type[])null, (Type[])null);

		private static readonly FieldInfo ValuableDebugField = AccessTools.Field(typeof(ValuableDirector), "valuableDebug");

		private static readonly FieldInfo SetupCompleteField = AccessTools.Field(typeof(ValuableDirector), "setupComplete");

		private static readonly FieldInfo ValuableSpawnPlayerReadyField = AccessTools.Field(typeof(ValuableDirector), "valuableSpawnPlayerReady");

		private static readonly FieldInfo ValuableTargetAmountField = AccessTools.Field(typeof(ValuableDirector), "valuableTargetAmount");

		private static readonly FieldInfo SwitchSetupPlayerReadyField = AccessTools.Field(typeof(ValuableDirector), "switchSetupPlayerReady");

		private static readonly FieldInfo SwitchSetupPlayerReadyListField = AccessTools.Field(typeof(ValuableDirector), "switchSetupPlayerReadyList");

		private static readonly FieldInfo TotalMaxValueField = AccessTools.Field(typeof(ValuableDirector), "totalMaxValue");

		private static readonly FieldInfo TotalCurrentValueField = AccessTools.Field(typeof(ValuableDirector), "totalCurrentValue");

		private static readonly FieldInfo TotalMaxAmountField = AccessTools.Field(typeof(ValuableDirector), "totalMaxAmount");

		private static readonly FieldInfo TinyMaxAmountField = AccessTools.Field(typeof(ValuableDirector), "tinyMaxAmount");

		private static readonly FieldInfo SmallMaxAmountField = AccessTools.Field(typeof(ValuableDirector), "smallMaxAmount");

		private static readonly FieldInfo MediumMaxAmountField = AccessTools.Field(typeof(ValuableDirector), "mediumMaxAmount");

		private static readonly FieldInfo BigMaxAmountField = AccessTools.Field(typeof(ValuableDirector), "bigMaxAmount");

		private static readonly FieldInfo WideMaxAmountField = AccessTools.Field(typeof(ValuableDirector), "wideMaxAmount");

		private static readonly FieldInfo TallMaxAmountField = AccessTools.Field(typeof(ValuableDirector), "tallMaxAmount");

		private static readonly FieldInfo VeryTallMaxAmountField = AccessTools.Field(typeof(ValuableDirector), "veryTallMaxAmount");

		private static readonly FieldInfo TinyValuablesField = AccessTools.Field(typeof(ValuableDirector), "tinyValuables");

		private static readonly FieldInfo SmallValuablesField = AccessTools.Field(typeof(ValuableDirector), "smallValuables");

		private static readonly FieldInfo MediumValuablesField = AccessTools.Field(typeof(ValuableDirector), "mediumValuables");

		private static readonly FieldInfo BigValuablesField = AccessTools.Field(typeof(ValuableDirector), "bigValuables");

		private static readonly FieldInfo WideValuablesField = AccessTools.Field(typeof(ValuableDirector), "wideValuables");

		private static readonly FieldInfo TallValuablesField = AccessTools.Field(typeof(ValuableDirector), "tallValuables");

		private static readonly FieldInfo VeryTallValuablesField = AccessTools.Field(typeof(ValuableDirector), "veryTallValuables");

		private static readonly FieldInfo TinyVolumesField = AccessTools.Field(typeof(ValuableDirector), "tinyVolumes");

		private static readonly FieldInfo SmallVolumesField = AccessTools.Field(typeof(ValuableDirector), "smallVolumes");

		private static readonly FieldInfo MediumVolumesField = AccessTools.Field(typeof(ValuableDirector), "mediumVolumes");

		private static readonly FieldInfo BigVolumesField = AccessTools.Field(typeof(ValuableDirector), "bigVolumes");

		private static readonly FieldInfo WideVolumesField = AccessTools.Field(typeof(ValuableDirector), "wideVolumes");

		private static readonly FieldInfo TallVolumesField = AccessTools.Field(typeof(ValuableDirector), "tallVolumes");

		private static readonly FieldInfo VeryTallVolumesField = AccessTools.Field(typeof(ValuableDirector), "veryTallVolumes");

		private static bool Prefix(ValuableDirector __instance, ref IEnumerator __result)
		{
			if ((Object)(object)AllMapValuablesPlugin.Instance == (Object)null || !AllMapValuablesPlugin.Instance.IsEnabled())
			{
				return true;
			}
			if (!PhotonNetwork.IsMasterClient && (Object)(object)GameManager.instance != (Object)null && GameManager.instance.gameMode == 1)
			{
				return true;
			}
			try
			{
				AllMapValuablesPlugin.Instance.EnsureLevelWeightConfigs();
				__result = CustomSetupHost(__instance);
				return false;
			}
			catch (Exception ex)
			{
				AllMapValuablesPlugin.WriteError("Failure: Failed to start custom valuable generation / カスタム貴重品生成開始失敗\n" + ex);
				return AllMapValuablesPlugin.Instance.IsFallbackToVanillaOnErrorEnabled();
			}
		}

		[IteratorStateMachine(typeof(<CustomSetupHost>d__32))]
		private static IEnumerator CustomSetupHost(ValuableDirector director)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <CustomSetupHost>d__32(0)
			{
				director = director
			};
		}

		private static void CalculateMaxAmounts(ValuableDirector director)
		{
			if (SemiFunc.RunGetDifficultyMultiplier2() > 0f && !SemiFunc.RunIsArena())
			{
				float num = SemiFunc.RunGetDifficultyMultiplier2();
				SetFieldValue(TotalMaxValueField, director, (float)Mathf.RoundToInt(director.totalMaxValueCurve2.Evaluate(num)));
				SetFieldValue(TinyMaxAmountField, director, Mathf.RoundToInt(director.tinyMaxAmountCurve2.Evaluate(num)));
				SetFieldValue(SmallMaxAmountField, director, Mathf.RoundToInt(director.smallMaxAmountCurve2.Evaluate(num)));
				SetFieldValue(MediumMaxAmountField, director, Mathf.RoundToInt(director.mediumMaxAmountCurve2.Evaluate(num)));
				SetFieldValue(BigMaxAmountField, director, Mathf.RoundToInt(director.bigMaxAmountCurve2.Evaluate(num)));
				SetFieldValue(WideMaxAmountField, director, Mathf.RoundToInt(director.wideMaxAmountCurve2.Evaluate(num)));
				SetFieldValue(TallMaxAmountField, director, Mathf.RoundToInt(director.tallMaxAmountCurve2.Evaluate(num)));
				SetFieldValue(VeryTallMaxAmountField, director, Mathf.RoundToInt(director.veryTallMaxAmountCurve2.Evaluate(num)));
			}
			else
			{
				float num2 = SemiFunc.RunGetDifficultyMultiplier1();
				if (SemiFunc.RunIsArena())
				{
					num2 = 0.75f;
				}
				SetFieldValue(TotalMaxValueField, director, (float)Mathf.RoundToInt(director.totalMaxValueCurve1.Evaluate(num2)));
				SetFieldValue(TinyMaxAmountField, director, Mathf.RoundToInt(director.tinyMaxAmountCurve1.Evaluate(num2)));
				SetFieldValue(SmallMaxAmountField, director, Mathf.RoundToInt(director.smallMaxAmountCurve1.Evaluate(num2)));
				SetFieldValue(MediumMaxAmountField, director, Mathf.RoundToInt(director.mediumMaxAmountCurve1.Evaluate(num2)));
				SetFieldValue(BigMaxAmountField, director, Mathf.RoundToInt(director.bigMaxAmountCurve1.Evaluate(num2)));
				SetFieldValue(WideMaxAmountField, director, Mathf.RoundToInt(director.wideMaxAmountCurve1.Evaluate(num2)));
				SetFieldValue(TallMaxAmountField, director, Mathf.RoundToInt(director.tallMaxAmountCurve1.Evaluate(num2)));
				SetFieldValue(VeryTallMaxAmountField, director, Mathf.RoundToInt(director.veryTallMaxAmountCurve1.Evaluate(num2)));
			}
			if (SemiFunc.RunIsArena())
			{
				SetFieldValue(TotalMaxAmountField, director, GetFieldValue<int>(TotalMaxAmountField, director) / 2);
				SetFieldValue(TinyMaxAmountField, director, GetFieldValue<int>(TinyMaxAmountField, director) / 3);
				SetFieldValue(SmallMaxAmountField, director, GetFieldValue<int>(SmallMaxAmountField, director) / 3);
				SetFieldValue(MediumMaxAmountField, director, GetFieldValue<int>(MediumMaxAmountField, director) / 3);
				SetFieldValue(BigMaxAmountField, director, GetFieldValue<int>(BigMaxAmountField, director) / 3);
				SetFieldValue(WideMaxAmountField, director, GetFieldValue<int>(WideMaxAmountField, director) / 2);
				SetFieldValue(TallMaxAmountField, director, GetFieldValue<int>(TallMaxAmountField, director) / 2);
				SetFieldValue(VeryTallMaxAmountField, director, GetFieldValue<int>(VeryTallMaxAmountField, director) / 2);
			}
		}

		private static WeightedPoolSet BuildWeightedPoolSet()
		{
			WeightedPoolSet weightedPoolSet = new WeightedPoolSet();
			if ((Object)(object)AllMapValuablesPlugin.Instance == (Object)null || (Object)(object)RunManager.instance == (Object)null)
			{
				return weightedPoolSet;
			}
			List<Level> list = new List<Level>();
			if (RunManager.instance.levels != null)
			{
				foreach (Level level in RunManager.instance.levels)
				{
					if ((Object)(object)level != (Object)null)
					{
						list.Add(level);
					}
				}
			}
			if ((Object)(object)RunManager.instance.levelCurrent != (Object)null && !list.Contains(RunManager.instance.levelCurrent))
			{
				list.Add(RunManager.instance.levelCurrent);
			}
			foreach (Level item in list)
			{
				string levelName = AllMapValuablesPlugin.GetLevelName(item);
				if (AllMapValuablesPlugin.IsExcludedLevelName(levelName) || (Object)(object)item == (Object)null || item.ValuablePresets == null || item.ValuablePresets.Count == 0)
				{
					continue;
				}
				int levelWeight = AllMapValuablesPlugin.Instance.GetLevelWeight(item);
				foreach (LevelValuables valuablePreset in item.ValuablePresets)
				{
					if (!((Object)(object)valuablePreset == (Object)null))
					{
						AddWeightedPrefabs(weightedPoolSet.TinyWeighted, weightedPoolSet.TinyUniqueMap, valuablePreset.tiny, levelWeight, levelName);
						AddWeightedPrefabs(weightedPoolSet.SmallWeighted, weightedPoolSet.SmallUniqueMap, valuablePreset.small, levelWeight, levelName);
						AddWeightedPrefabs(weightedPoolSet.MediumWeighted, weightedPoolSet.MediumUniqueMap, valuablePreset.medium, levelWeight, levelName);
						AddWeightedPrefabs(weightedPoolSet.BigWeighted, weightedPoolSet.BigUniqueMap, valuablePreset.big, levelWeight, levelName);
						AddWeightedPrefabs(weightedPoolSet.WideWeighted, weightedPoolSet.WideUniqueMap, valuablePreset.wide, levelWeight, levelName);
						AddWeightedPrefabs(weightedPoolSet.TallWeighted, weightedPoolSet.TallUniqueMap, valuablePreset.tall, levelWeight, levelName);
						AddWeightedPrefabs(weightedPoolSet.VeryTallWeighted, weightedPoolSet.VeryTallUniqueMap, valuablePreset.veryTall, levelWeight, levelName);
					}
				}
			}
			weightedPoolSet.TinyUnique = weightedPoolSet.TinyUniqueMap.Values.Select((WeightedPrefabRef x) => x.PrefabRef).ToList();
			weightedPoolSet.SmallUnique = weightedPoolSet.SmallUniqueMap.Values.Select((WeightedPrefabRef x) => x.PrefabRef).ToList();
			weightedPoolSet.MediumUnique = weightedPoolSet.MediumUniqueMap.Values.Select((WeightedPrefabRef x) => x.PrefabRef).ToList();
			weightedPoolSet.BigUnique = weightedPoolSet.BigUniqueMap.Values.Select((WeightedPrefabRef x) => x.PrefabRef).ToList();
			weightedPoolSet.WideUnique = weightedPoolSet.WideUniqueMap.Values.Select((WeightedPrefabRef x) => x.PrefabRef).ToList();
			weightedPoolSet.TallUnique = weightedPoolSet.TallUniqueMap.Values.Select((WeightedPrefabRef x) => x.PrefabRef).ToList();
			weightedPoolSet.VeryTallUnique = weightedPoolSet.VeryTallUniqueMap.Values.Select((WeightedPrefabRef x) => x.PrefabRef).ToList();
			return weightedPoolSet;
		}

		private static void AddWeightedPrefabs(List<WeightedPrefabRef> weightedList, Dictionary<string, WeightedPrefabRef> uniqueMap, List<PrefabRef> source, int levelWeight, string levelName)
		{
			if (source == null || source.Count == 0)
			{
				return;
			}
			foreach (PrefabRef item in source)
			{
				if (item == null || !item.IsValid())
				{
					continue;
				}
				string resourcePath = item.ResourcePath;
				if (!string.IsNullOrWhiteSpace(resourcePath))
				{
					if (uniqueMap.TryGetValue(resourcePath, out WeightedPrefabRef value))
					{
						value.Weight += Mathf.Clamp(levelWeight, 1, 10);
						continue;
					}
					value = new WeightedPrefabRef();
					value.PrefabRef = item;
					value.ResourcePath = resourcePath;
					value.Weight = Mathf.Clamp(levelWeight, 1, 10);
					value.SourceLevelName = levelName;
					uniqueMap.Add(resourcePath, value);
					weightedList.Add(value);
				}
			}
		}

		private static WeightedPrefabRef PickWeightedPrefab(List<WeightedPrefabRef> weightedPool)
		{
			if (weightedPool == null || weightedPool.Count == 0)
			{
				return null;
			}
			int num = 0;
			foreach (WeightedPrefabRef item in weightedPool)
			{
				if (item != null && item.PrefabRef != null && item.Weight > 0)
				{
					num += item.Weight;
				}
			}
			if (num <= 0)
			{
				return null;
			}
			int num2 = Random.Range(0, num);
			int num3 = 0;
			foreach (WeightedPrefabRef item2 in weightedPool)
			{
				if (item2 != null && item2.PrefabRef != null && item2.Weight > 0)
				{
					num3 += item2.Weight;
					if (num2 < num3)
					{
						return item2;
					}
				}
			}
			return weightedPool[weightedPool.Count - 1];
		}

		private static string GetValuableDebugName(ValuableDirector director)
		{
			object value = ValuableDebugField.GetValue(director);
			return (value == null) ? string.Empty : value.ToString();
		}

		private static T GetFieldValue<T>(FieldInfo fieldInfo, object instance)
		{
			object value = fieldInfo.GetValue(instance);
			if (value == null)
			{
				return default(T);
			}
			return (T)value;
		}

		private static void SetFieldValue(FieldInfo fieldInfo, object instance, object value)
		{
			fieldInfo.SetValue(instance, value);
		}
	}
}