Decompiled source of VarianceAPI v3.0.0

plugins/VarianceAPI.Runtime.dll

Decompiled 8 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using DebugToolkit;
using EntityStates;
using EntityStates.Gup;
using HG;
using HG.Coroutines;
using HG.Reflection;
using IL.EntityStates.Gup;
using IL.RoR2;
using MSU;
using MSU.Config;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.RoR2.UI;
using R2API;
using R2API.AddressReferencedAssets;
using R2API.ScriptableObjects;
using R2API.Utils;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RoR2;
using RoR2.AddressableAssets;
using RoR2.CharacterAI;
using RoR2.ConVar;
using RoR2.ContentManagement;
using RoR2.ExpansionManagement;
using RoR2.Navigation;
using RoR2.Skills;
using RoR2.UI;
using RoR2BepInExPack.GameAssetPathsBetter;
using RoR2BepInExPack.Utilities;
using Unity;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.UI;
using VAPI;
using VAPI.AddressReferencedAssets;
using VAPI.Rules;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: OptIn]
[assembly: InternalsVisibleTo("VarianceAPI.Editor")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace EntityStates
{
	public sealed class GoToMain : EntityState
	{
		public override void FixedUpdate()
		{
			((EntityState)this).FixedUpdate();
			if (((EntityState)this).isAuthority)
			{
				base.outer.SetNextStateToMain();
			}
		}
	}
}
namespace VAPI
{
	[Serializable]
	public struct CataloguedVariantReference
	{
		[SerializeField]
		[Tooltip("The direct reference to a CharacterVariantDef")]
		private CharacterVariantDef? _characterVariantDef;

		[SerializeField]
		[Tooltip("The name of a variant def, which will be retrieved via the catalog.")]
		private string? _cataloguedVariantName;

		private bool _triedToRetrieveFromCatalog;

		public CharacterVariantDef? GetCharacterVariantDef()
		{
			if (!_triedToRetrieveFromCatalog && (Object)(object)_characterVariantDef == (Object)null)
			{
				_triedToRetrieveFromCatalog = true;
				_characterVariantDef = CharacterVariantCatalog.GetCharacterVariantDef(CharacterVariantCatalog.FindCharacterVariantIndex(_cataloguedVariantName));
			}
			return _characterVariantDef;
		}

		public bool IsValid()
		{
			if (!((Object)(object)_characterVariantDef != (Object)null))
			{
				return !string.IsNullOrWhiteSpace(_cataloguedVariantName);
			}
			return true;
		}

		public CataloguedVariantReference(CharacterVariantDef directReference)
		{
			_characterVariantDef = directReference;
			_cataloguedVariantName = "";
			_triedToRetrieveFromCatalog = false;
		}

		public CataloguedVariantReference(string catalogReference)
		{
			_cataloguedVariantName = catalogReference;
			_characterVariantDef = null;
			_triedToRetrieveFromCatalog = false;
		}
	}
	public struct CharacterVariantIndex : IEquatable<CharacterVariantIndex>
	{
		private readonly int i;

		public static readonly CharacterVariantIndex none = new CharacterVariantIndex(-1);

		public bool isValid => i >= 0;

		public CharacterVariantIndex(int i)
		{
			this.i = i;
		}

		public static explicit operator int(CharacterVariantIndex masterIndex)
		{
			return masterIndex.i;
		}

		public static explicit operator CharacterVariantIndex(int value)
		{
			return new CharacterVariantIndex(value);
		}

		public bool Equals(CharacterVariantIndex other)
		{
			return i == other.i;
		}

		public override bool Equals(object obj)
		{
			if (obj is CharacterVariantIndex other)
			{
				return Equals(other);
			}
			return false;
		}

		public override int GetHashCode()
		{
			return i;
		}

		public static bool operator ==(CharacterVariantIndex a, CharacterVariantIndex b)
		{
			return a.i == b.i;
		}

		public static bool operator !=(CharacterVariantIndex a, CharacterVariantIndex b)
		{
			return a.i != b.i;
		}

		public static bool operator <(CharacterVariantIndex a, CharacterVariantIndex b)
		{
			return a.i < b.i;
		}

		public static bool operator >(CharacterVariantIndex a, CharacterVariantIndex b)
		{
			return a.i > b.i;
		}

		public static bool operator <=(CharacterVariantIndex a, CharacterVariantIndex b)
		{
			return a.i <= b.i;
		}

		public static bool operator >=(CharacterVariantIndex a, CharacterVariantIndex b)
		{
			return a.i >= b.i;
		}

		public static CharacterVariantIndex operator ++(CharacterVariantIndex index)
		{
			return new CharacterVariantIndex(index.i + 1);
		}

		public static CharacterVariantIndex operator --(CharacterVariantIndex index)
		{
			return new CharacterVariantIndex(index.i - 1);
		}

		public override string ToString()
		{
			CharacterVariantDef characterVariantDef = CharacterVariantCatalog.GetCharacterVariantDef(this);
			string arg = (Object.op_Implicit((Object)(object)characterVariantDef) ? characterVariantDef.cachedName : "NULL");
			return $"{i}({arg})";
		}
	}
	[Serializable]
	public struct NetworkCharacterVariantIndex : IEquatable<NetworkCharacterVariantIndex>
	{
		public uint i;

		public static implicit operator NetworkCharacterVariantIndex(CharacterVariantIndex masterIndex)
		{
			return new NetworkCharacterVariantIndex
			{
				i = (uint)((int)masterIndex + 1)
			};
		}

		public static implicit operator CharacterVariantIndex(NetworkCharacterVariantIndex networkMasterIndex)
		{
			return new CharacterVariantIndex((int)(networkMasterIndex.i - 1));
		}

		public bool Equals(NetworkCharacterVariantIndex other)
		{
			return i == other.i;
		}

		public override bool Equals(object obj)
		{
			if (obj is CharacterVariantIndex characterVariantIndex)
			{
				return Equals(characterVariantIndex);
			}
			return false;
		}

		public override int GetHashCode()
		{
			return (int)i;
		}
	}
	public class CharacterVariantMask : ICollection<CharacterVariantIndex>, IEnumerable<CharacterVariantIndex>, IEnumerable
	{
		public struct Enumerator : IEnumerator<CharacterVariantIndex>, IEnumerator, IDisposable
		{
			public bool[] target;

			public CharacterVariantIndex Current { get; set; }

			object IEnumerator.Current => Current;

			public Enumerator(bool[] array)
			{
				Current = CharacterVariantIndex.none;
				target = array;
			}

			public void Dispose()
			{
				throw new NotImplementedException();
			}

			public bool MoveNext()
			{
				CharacterVariantIndex characterVariantIndex = (CharacterVariantIndex)CharacterVariantCatalog.characterVariantCount;
				while (Current < characterVariantIndex)
				{
					if (target[(int)Current])
					{
						return true;
					}
					Current++;
				}
				return false;
			}

			public void Reset()
			{
				Current = CharacterVariantIndex.none;
			}
		}

		private bool[] _array;

		public int Count => _array.Length;

		bool ICollection<CharacterVariantIndex>.IsReadOnly => false;

		public CharacterVariantMask()
		{
			_array = new bool[CharacterVariantCatalog.characterVariantCount];
		}

		public static CharacterVariantMask Rent()
		{
			return CollectionPool<CharacterVariantIndex, CharacterVariantMask>.RentCollection();
		}

		public static DisposableRental<CharacterVariantIndex, CharacterVariantMask> Rent(out CharacterVariantMask mask)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return CollectionPool<CharacterVariantIndex, CharacterVariantMask>.RentCollection(ref mask);
		}

		public static void Return(CharacterVariantMask mask)
		{
			if (mask._array.Length == CharacterVariantCatalog.characterVariantCount)
			{
				CollectionPool<CharacterVariantIndex, CharacterVariantMask>.ReturnCollection(mask);
			}
		}

		public bool Contains(CharacterVariantIndex characterVariantIndex)
		{
			return ArrayUtils.GetSafe<bool>(_array, (int)characterVariantIndex);
		}

		public void Add(CharacterVariantIndex characterVariantIndex)
		{
			if (ArrayUtils.IsInBounds<bool>(_array, (int)characterVariantIndex))
			{
				_array[(int)characterVariantIndex] = true;
			}
		}

		public bool Remove(CharacterVariantIndex characterVariantIndex)
		{
			if (ArrayUtils.IsInBounds<bool>(_array, (int)characterVariantIndex))
			{
				ref bool reference = ref _array[(int)characterVariantIndex];
				bool result = reference;
				reference = false;
				return result;
			}
			return false;
		}

		public void Clear()
		{
			bool[] array = _array;
			bool flag = false;
			ArrayUtils.SetAll<bool>(array, ref flag);
		}

		public void CopyTo(CharacterVariantIndex[] array, int arrayIndex)
		{
			for (int i = 0; i < _array.Length; i++)
			{
				if (_array[i])
				{
					array[arrayIndex++] = (CharacterVariantIndex)i;
				}
			}
		}

		public void CloneTo(CharacterVariantMask other)
		{
			for (int i = 0; i < Count; i++)
			{
				other._array[i] = _array[i];
			}
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		public static void Swap(CharacterVariantMask maskA, CharacterVariantMask maskB)
		{
			ArrayUtils.SwapElements<bool>(maskA._array, maskB._array);
		}

		public Enumerator GetEnumerator()
		{
			return new Enumerator(_array);
		}

		IEnumerator<CharacterVariantIndex> IEnumerable<CharacterVariantIndex>.GetEnumerator()
		{
			return GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return GetEnumerator();
		}
	}
	public static class CharacterVariantCatalog
	{
		private static CharacterVariantDef[]? _characterVariantDefs;

		private static Dictionary<string, CharacterVariantIndex> _characterVariantNameToIndex = new Dictionary<string, CharacterVariantIndex>(StringComparer.OrdinalIgnoreCase);

		private static Dictionary<CharacterVariantDef, List<CharacterVariantDef>> _dependeeVariantToDependantVariants = new Dictionary<CharacterVariantDef, List<CharacterVariantDef>>();

		private static CharacterVariantProvider?[] _characterVariantProviders = Array.Empty<CharacterVariantProvider>();

		public static ResourceAvailability catalogAvailability;

		public static ReadOnlyArray<CharacterVariantDef> registeredCharacterVariantDefs => ReadOnlyArray<CharacterVariantDef>.op_Implicit(_characterVariantDefs);

		public static int characterVariantCount
		{
			get
			{
				CharacterVariantDef[]? characterVariantDefs = _characterVariantDefs;
				if (characterVariantDefs == null)
				{
					return -1;
				}
				return characterVariantDefs.Length;
			}
		}

		public static List<CharacterVariantDef>? RetrieveDependantSpawnVariants(CharacterVariantIndex characterVariantIndex)
		{
			return RetrieveDependantSpawnVariants(GetCharacterVariantDef(characterVariantIndex));
		}

		public static List<CharacterVariantDef>? RetrieveDependantSpawnVariants(CharacterVariantDef? dependee)
		{
			if ((Object)(object)dependee == (Object)null || !_dependeeVariantToDependantVariants.TryGetValue(dependee, out List<CharacterVariantDef> value))
			{
				LogWarning($"{dependee} has no Dependant Spawn Variants");
				return null;
			}
			List<CharacterVariantDef> list = CollectionPool<CharacterVariantDef, List<CharacterVariantDef>>.RentCollection();
			list.AddRange(value);
			return list;
		}

		public static CharacterVariantDef? GetCharacterVariantDef(CharacterVariantIndex index)
		{
			ThrowIfUnavailable();
			CharacterVariantDef result = default(CharacterVariantDef);
			if (ArrayUtils.TryGetSafe<CharacterVariantDef>(_characterVariantDefs, (int)index, ref result))
			{
				return result;
			}
			LogWarning($"VariantIndex {index} is out of bounds, returning null.");
			return null;
		}

		public static CharacterVariantIndex FindCharacterVariantIndex(string? characterVariantDefName)
		{
			ThrowIfUnavailable();
			if (string.IsNullOrWhiteSpace(characterVariantDefName))
			{
				LogWarning("Cannot find a CharacterVariantIndex with an empty name, returning CharacterVariantIndex.none");
				return CharacterVariantIndex.none;
			}
			if (_characterVariantNameToIndex.TryGetValue(characterVariantDefName, out var value))
			{
				return value;
			}
			LogWarning("There's no CharacterVariantDef with the name " + characterVariantDefName + ", returning CharacterVariantIndex.none");
			return CharacterVariantIndex.none;
		}

		public static CharacterVariantProvider? FindCharacterVariantProvider(GameObject? bodyPrefab)
		{
			return FindCharacterVariantProvider(((Object)(object)bodyPrefab != (Object)null) ? bodyPrefab.GetComponent<CharacterBody>() : null);
		}

		public static CharacterVariantProvider? FindCharacterVariantProvider(CharacterBody? bodyComponent)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			return GetCharacterVariantProvider((BodyIndex)((!((Object)(object)bodyComponent != (Object)null)) ? (-1) : ((int)bodyComponent.bodyIndex)));
		}

		public static CharacterVariantProvider? GetCharacterVariantProvider(BodyIndex bodyIndex)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected I4, but got Unknown
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			ThrowIfUnavailable();
			CharacterVariantProvider result = default(CharacterVariantProvider);
			if (ArrayUtils.TryGetSafe<CharacterVariantProvider>(_characterVariantProviders, (int)bodyIndex, ref result))
			{
				return result;
			}
			LogWarning("Body " + BodyCatalog.GetBodyName(bodyIndex) + " has no provider");
			return null;
		}

		[SystemInitializer(new Type[]
		{
			typeof(BodyCatalog),
			typeof(VariantPackManager)
		})]
		private static IEnumerator Initialize()
		{
			_characterVariantNameToIndex.Clear();
			CoroutineWithResult<CharacterVariantDef[]> coroutineWithResult = CoroutineWithResult<CharacterVariantDef[]>.Rent((IEnumerator)RegisterVariantDefs(VariantPackManager.characterVariantDefs));
			try
			{
				while (((CoroutineWithResult)coroutineWithResult).MoveNext())
				{
					yield return null;
				}
				_characterVariantDefs = coroutineWithResult.result;
			}
			finally
			{
				((IDisposable)coroutineWithResult)?.Dispose();
			}
			for (int i = 0; i < _characterVariantDefs.Length; i++)
			{
				CharacterVariantDef characterVariantDef = _characterVariantDefs[i];
				if (characterVariantDef.isHidden && characterVariantDef.spawnCondition is VariantDependantCondition variantDependantCondition)
				{
					CharacterVariantDef characterVariantDef2 = variantDependantCondition.dependantVariantDef.GetCharacterVariantDef();
					if ((Object)(object)characterVariantDef2 != (Object)null)
					{
						_dependeeVariantToDependantVariants.TryAdd(characterVariantDef2, new List<CharacterVariantDef>());
						_dependeeVariantToDependantVariants[characterVariantDef2].Add(characterVariantDef);
					}
					else
					{
						VAPILog.Warning($"{characterVariantDef} has a VariantDependantCondition spawn condition, but the dependantVariantDef doesnt exist!", 514, "Initialize");
					}
				}
				try
				{
					if (characterVariantDef.additionalVariantComponents != null)
					{
						SerializableSystemType[] variantComponents = characterVariantDef.additionalVariantComponents.variantComponents;
						if (variantComponents == null || variantComponents.Length != 0)
						{
							LogMessage("Initializing variant components for " + characterVariantDef.cachedName);
							characterVariantDef.additionalVariantComponents?.Initialize();
						}
					}
				}
				catch (Exception ex)
				{
					VAPILog.Error($"Failed to initialize variant components for {characterVariantDef}: {ex}", 530, "Initialize");
					InitializationExceptionWatcher.AddException(ex, characterVariantDef.ownerPlugin);
				}
			}
			for (int j = 0; j < _characterVariantDefs.Length; j++)
			{
				ConfigureVariant(_characterVariantDefs[j]);
			}
			Stage.onStageStartGlobal += FilterCharacterVariantProviders;
			VAPILog.Info("CharacterVariantCatalog Initialized.", 544, "Initialize");
			((ResourceAvailability)(ref catalogAvailability)).MakeAvailable();
		}

		private static IEnumerator<CharacterVariantDef[]?> RegisterVariantDefs(ReadOnlyArray<CharacterVariantDef> readOnlyVariantDefs)
		{
			//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)
			CharacterVariantDef[] sortedVariants = new CharacterVariantDef[readOnlyVariantDefs.Length];
			readOnlyVariantDefs.CopyTo((Array)sortedVariants, 0);
			Array.Sort(sortedVariants, (CharacterVariantDef a, CharacterVariantDef b) => string.CompareOrdinal(a.cachedName, b.cachedName));
			Dictionary<BodyIndex, List<CharacterVariantDef>> bodyToVariants = new Dictionary<BodyIndex, List<CharacterVariantDef>>();
			List<CharacterVariantDef> providerlessVariants = CollectionPool<CharacterVariantDef, List<CharacterVariantDef>>.RentCollection();
			for (int i = 0; i < sortedVariants.Length; i++)
			{
				yield return null;
				CharacterVariantIndex index = (CharacterVariantIndex)i;
				CharacterVariantDef variantDef = sortedVariants[i];
				if (!variantDef.targetBody.IsKeyValid())
				{
					providerlessVariants.Add(variantDef);
					AddToCatalog();
					continue;
				}
				if (!variantDef.targetBody.TryLoadCharacterComponent(out CharacterBody characterComponent))
				{
					providerlessVariants.Add(variantDef);
					AddToCatalog();
					continue;
				}
				if ((int)characterComponent.bodyIndex == -1)
				{
					providerlessVariants.Add(variantDef);
					AddToCatalog();
					continue;
				}
				if (!bodyToVariants.ContainsKey(characterComponent.bodyIndex))
				{
					bodyToVariants.Add(characterComponent.bodyIndex, CollectionPool<CharacterVariantDef, List<CharacterVariantDef>>.RentCollection());
				}
				bodyToVariants[characterComponent.bodyIndex].Add(variantDef);
				variantDef.hasProvider = true;
				AddToCatalog();
				void AddToCatalog()
				{
					variantDef.characterVariantIndex = index;
					_characterVariantNameToIndex.Add(variantDef.cachedName, variantDef.characterVariantIndex);
					LogMessage("CharacterVariantDef " + variantDef.cachedName + " added to the CharacterVariantCatalog");
				}
			}
			VAPILog.Info("Finished associating CharacterVariantDefs with bodies", 614, "RegisterVariantDefs");
			CharacterVariantProvider?[] characterVariantProviders = new CharacterVariantProvider[BodyCatalog.bodyCount];
			BodyIndex key;
			List<CharacterVariantDef> value;
			foreach (KeyValuePair<BodyIndex, List<CharacterVariantDef>> item in bodyToVariants)
			{
				item.Deconstruct(out key, out value);
				BodyIndex bodyIndex = key;
				List<CharacterVariantDef> variantDefs = value;
				yield return null;
				characterVariantProviders[bodyIndex] = new CharacterVariantProvider(variantDefs.ToArray(), bodyIndex);
				CharacterBody bodyPrefabBodyComponent = BodyCatalog.GetBodyPrefabBodyComponent(bodyIndex);
				UnityObjectExtensions.EnsureComponent<CharacterBodyVariantController>(((Component)bodyPrefabBodyComponent).gameObject);
				if (ConfiguredVariable<bool>.op_Implicit((ConfiguredVariable<bool>)(object)VAPIConfig._enableRewards))
				{
					UnityObjectExtensions.EnsureComponent<VariantDeathRewards>(((Component)bodyPrefabBodyComponent).gameObject);
				}
				LogMessage("Added components to " + ((Object)((Component)bodyPrefabBodyComponent).gameObject).name);
			}
			GameObject[] masterPrefabs = MasterCatalog.masterPrefabs;
			CharacterMaster val2 = default(CharacterMaster);
			CharacterBody val3 = default(CharacterBody);
			PlayerCharacterMasterController val4 = default(PlayerCharacterMasterController);
			foreach (GameObject val in masterPrefabs)
			{
				if ((val.TryGetComponent<CharacterMaster>(ref val2) && Object.op_Implicit((Object)(object)val2.bodyPrefab) && val2.bodyPrefab.TryGetComponent<CharacterBody>(ref val3) && bodyToVariants.ContainsKey(val3.bodyIndex)) || val.TryGetComponent<PlayerCharacterMasterController>(ref val4))
				{
					val.AddComponent<CharacterMasterVariantStorage>();
					LogMessage("Added storage component to " + ((Object)val.gameObject).name);
				}
			}
			VAPILog.Info("Created providers and added the necessary behaviours to bodies and masters", 650, "RegisterVariantDefs");
			_characterVariantProviders = characterVariantProviders;
			if (providerlessVariants.Count > 0)
			{
				StringBuilder stringBuilder = default(StringBuilder);
				StringBuilderDisposable val5 = StringBuilderPool.RentStringBuilder(ref stringBuilder);
				try
				{
					stringBuilder.AppendLine("The following variants did not resolve a valid CharacterBody, and as a result, have no CharacterVariantProviders. They're still added to the catalog but they won't be spawned by the built in systems. If they're meant to be for a vanilla charater, consider validating the AddressReferencedBody you're using. If it's for a modded character, consider adding the VariantDef only if the mod is present, and checking that the catalog key for AddressReferencedBody is typed correctly:");
					foreach (CharacterVariantDef item2 in providerlessVariants)
					{
						stringBuilder.AppendLine(((object)item2).ToString());
					}
					VAPILog.Message(stringBuilder.ToString(), 661, "RegisterVariantDefs");
				}
				finally
				{
					((StringBuilderDisposable)(ref val5)).Dispose();
				}
			}
			foreach (KeyValuePair<BodyIndex, List<CharacterVariantDef>> item3 in bodyToVariants)
			{
				item3.Deconstruct(out key, out value);
				CollectionPool<CharacterVariantDef, List<CharacterVariantDef>>.ReturnCollection(value);
			}
			CollectionPool<CharacterVariantDef, List<CharacterVariantDef>>.ReturnCollection(providerlessVariants);
			yield return sortedVariants;
		}

		public static void ForceVariantAvailabilityRecalculation()
		{
			FilterCharacterVariantProviders(null);
		}

		private static void FilterCharacterVariantProviders(Stage? obj)
		{
			for (int i = 0; i < _characterVariantProviders.Length; i++)
			{
				_characterVariantProviders[i]?.FilterVariants();
			}
			VAPILog.Info("CharacterVariantProviders have been filtered", 688, "FilterCharacterVariantProviders");
		}

		private static void ConfigureVariant(CharacterVariantDef variantDef)
		{
			//IL_002d: 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)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Expected O, but got Unknown
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			if (variantDef.isHidden)
			{
				return;
			}
			try
			{
				variantDef.spawnRate = ConfiguredVariable<float>.op_Implicit((ConfiguredVariable<float>)(object)new ConfiguredFloat(variantDef.spawnRate)
				{
					section = ((Object)variantDef.targetBody.LoadCharacterComponent()).name + " Variants",
					key = variantDef.cachedName + " Spawn Rate",
					description = "Chance for the " + variantDef.cachedName + " variant to spawn. (Percentage, 0-100)",
					configFile = variantDef.associatedConfigFile,
					modGUID = variantDef.ownerPlugin.Info.Metadata.GUID,
					modName = variantDef.ownerPlugin.Info.Metadata.Name,
					sliderType = (SliderTypeEnum)1,
					sliderConfig = new SliderConfig
					{
						min = 0f,
						max = 100f
					}
				}.WithConfigChange((OnConfigChangedDelegate<float>)delegate(float f)
				{
					variantDef.spawnRate = f;
					UpdateDependentDefSpawnRates(variantDef);
				}).DoConfigure());
				variantDef.isUnique = ConfiguredVariable<bool>.op_Implicit((ConfiguredVariable<bool>)(object)new ConfiguredBool(variantDef.isUnique)
				{
					section = ((Object)variantDef.targetBody.LoadCharacterComponent()).name + " Variants",
					key = variantDef.cachedName + " Uniqueness",
					description = "Wether or not " + variantDef.cachedName + " is Unique. Unique variants cannot merge with other ones.",
					configFile = variantDef.associatedConfigFile,
					modGUID = variantDef.ownerPlugin.Info.Metadata.GUID,
					modName = variantDef.ownerPlugin.Info.Metadata.Name
				}.WithConfigChange((OnConfigChangedDelegate<bool>)delegate(bool b)
				{
					variantDef.isUnique = b;
					UpdateDependentDefUniqueness(variantDef);
				}).DoConfigure());
			}
			catch (Exception ex)
			{
				VAPILog.Error($"Error Configuring Variant {variantDef}: {ex}", 736, "ConfigureVariant");
				InitializationExceptionWatcher.AddException(ex, variantDef.ownerPlugin);
			}
		}

		private static void UpdateDependentDefSpawnRates(CharacterVariantDef dependee)
		{
			if (!_dependeeVariantToDependantVariants.TryGetValue(dependee, out List<CharacterVariantDef> value))
			{
				return;
			}
			foreach (CharacterVariantDef item in value)
			{
				item.spawnRate = dependee.spawnRate;
			}
		}

		private static void UpdateDependentDefUniqueness(CharacterVariantDef dependee)
		{
			if (!_dependeeVariantToDependantVariants.TryGetValue(dependee, out List<CharacterVariantDef> value))
			{
				return;
			}
			foreach (CharacterVariantDef item in value)
			{
				item.isUnique = dependee.isUnique;
			}
		}

		private static void ThrowIfUnavailable()
		{
			if (!((ResourceAvailability)(ref catalogAvailability)).available)
			{
				throw new InvalidOperationException("Cannot access CharacterVariantCatalog when it's not available, consider subscribing to the catalogAvailability.");
			}
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void CCVapiListBodies(ConCommandArgs args)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Invalid comparison between Unknown and I4
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			ThrowIfUnavailable();
			StringBuilder stringBuilder = StringBuilderPool.RentStringBuilder();
			stringBuilder.AppendLine("Bodies with Variants:");
			stringBuilder.AppendLine("---------------------");
			CharacterVariantProvider[] characterVariantProviders = _characterVariantProviders;
			foreach (CharacterVariantProvider characterVariantProvider in characterVariantProviders)
			{
				if (characterVariantProvider != null && (int)characterVariantProvider.associatedBodyIndex != -1)
				{
					GameObject bodyPrefab = BodyCatalog.GetBodyPrefab(characterVariantProvider.associatedBodyIndex);
					stringBuilder.AppendLine($"{((Object)bodyPrefab).name} (Variant Count: {characterVariantProvider.totalVariantCount}).");
				}
			}
			Debug.Log((object)stringBuilder.ToString());
			StringBuilderPool.ReturnStringBuilder(stringBuilder);
		}

		[ConCommand(commandName = "vapi_list_body_variants", helpText = "Lists all the VariantDefs associated to a body.")]
		private unsafe static void CCVapiListBodyVariants(ConCommandArgs args)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Invalid comparison between Unknown and I4
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			ThrowIfUnavailable();
			if (((ConCommandArgs)(ref args)).Count == 0)
			{
				Debug.Log((object)"No arguments given.");
				return;
			}
			string text = ((ConCommandArgs)(ref args))[0];
			BodyIndex bodyIndex = VAPIUtils.GetBodyIndex(text);
			if ((int)bodyIndex == -1)
			{
				Debug.Log((object)("No body could be found with the name " + text + ". To get a list of bodies that have variants use \"vapi_list_bodies\"."));
				return;
			}
			CharacterVariantProvider characterVariantProvider = GetCharacterVariantProvider(bodyIndex);
			if (characterVariantProvider == null)
			{
				Debug.Log((object)"The provided body does not have a CharacterVariantProvider. To get a list of bodies that have variants use \"vapi_list_bodies\".");
				return;
			}
			StringBuilder stringBuilder = StringBuilderPool.RentStringBuilder();
			stringBuilder.AppendLine(((Object)BodyCatalog.GetBodyPrefab(bodyIndex)).name + "'s Variants");
			stringBuilder.AppendLine("-------------------------------------------------------");
			for (int i = 0; i < characterVariantProvider.totalVariantCount; i++)
			{
				CharacterVariantDef characterVariantDef = Unsafe.Read<CharacterVariantDef>((void*)characterVariantProvider.allVariants[i]);
				stringBuilder.AppendLine($"[{i}] = {characterVariantDef.cachedName}");
			}
			Debug.Log((object)stringBuilder.ToString());
			StringBuilderPool.ReturnStringBuilder(stringBuilder);
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void CCVapiSpawnAI(ConCommandArgs args)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Expected O, but got Unknown
			if (!Object.op_Implicit((Object)(object)VariantSpawnManager.instance))
			{
				Debug.LogWarning((object)"VarianceAPI's Variant Spawning commands are not available when the VarianceAPI expansion is disabled.");
				return;
			}
			if (((ConCommandArgs)(ref args)).Count == 0)
			{
				Debug.Log((object)"No Arguments Given.");
				return;
			}
			if (!Object.op_Implicit((Object)(object)((ConCommandArgs)(ref args)).senderBody))
			{
				Debug.Log((object)"Sender must have a body");
				return;
			}
			MasterIndex masterIndex = VAPIUtils.GetMasterIndex(((ConCommandArgs)(ref args))[0]);
			if (masterIndex == MasterIndex.none)
			{
				Debug.Log((object)"Could not find master.");
				return;
			}
			CharacterMaster component = MasterCatalog.GetMasterPrefab(masterIndex).GetComponent<CharacterMaster>();
			CharacterVariantProvider characterVariantProvider = FindCharacterVariantProvider(component.bodyPrefab);
			if (characterVariantProvider == null)
			{
				Debug.Log((object)("CharacterMaster with name " + ((ConCommandArgs)(ref args))[0] + " does not have a CharacterVariantProvider"));
				return;
			}
			string[] array = ((ConCommandArgs)(ref args))[1].Replace(" ", "").Split(',', StringSplitOptions.RemoveEmptyEntries);
			List<CharacterVariantDef> list = default(List<CharacterVariantDef>);
			DisposableRental<CharacterVariantDef, List<CharacterVariantDef>> val = CollectionPool<CharacterVariantDef, List<CharacterVariantDef>>.RentCollection(ref list);
			try
			{
				ReadOnlyArray<CharacterVariantDef> allVariants = characterVariantProvider.allVariants;
				string[] array2 = array;
				foreach (string value in array2)
				{
					Enumerator<CharacterVariantDef> enumerator = allVariants.GetEnumerator();
					try
					{
						while (enumerator.MoveNext())
						{
							CharacterVariantDef current = enumerator.Current;
							if (current.cachedName.Contains(value, StringComparison.OrdinalIgnoreCase))
							{
								list.Add(current);
								break;
							}
						}
					}
					finally
					{
						((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
					}
				}
				list.Sort((CharacterVariantDef a, CharacterVariantDef b) => ((int)a.characterVariantIndex).CompareTo((int)b.characterVariantIndex));
				CharacterBody senderBody = ((ConCommandArgs)(ref args)).senderBody;
				Vector3 position = args.sender.master.GetBody().transform.position;
				InputBankTest val2 = default(InputBankTest);
				RaycastHit val3 = default(RaycastHit);
				if (((Component)senderBody).TryGetComponent<InputBankTest>(ref val2) && Physics.Raycast(val2.GetAimRay(), ref val3, 1024f, LayerMask.op_Implicit(((LayerIndex)(ref LayerIndex.world)).mask)))
				{
					position = ((RaycastHit)(ref val3)).point;
				}
				int num = args.TryGetOptionalInt("count:") ?? 1;
				EquipmentIndex equipmentIndex = (EquipmentIndex)(((int?)args.TryGetOptionalEquipmentIndex("equipment:")) ?? (-1));
				bool noAI = ((ConCommandArgs)(ref args)).TryGetOptionalBool("noai:", StringComparison.OrdinalIgnoreCase) == true;
				TeamIndex value2 = (TeamIndex)(((int?)((ConCommandArgs)(ref args)).TryGetOptionalEnum<TeamIndex>("team:", StringComparison.OrdinalIgnoreCase)) ?? 2);
				MasterSummon val4 = new MasterSummon
				{
					masterPrefab = ((Component)component).gameObject,
					ignoreTeamMemberLimit = true,
					useAmbientLevel = false,
					position = position,
					rotation = Quaternion.identity,
					summonerBodyObject = null,
					teamIndexOverride = value2
				};
				VariantMasterSummon variantMasterSummon = new VariantMasterSummon(val4);
				variantMasterSummon.preassignedVariantDefs = list.ToArray();
				variantMasterSummon.onSummonPerformed += delegate(VariantMasterSummon.VariantMasterSummonReport report)
				{
					//IL_0001: 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_0013: Invalid comparison between Unknown and I4
					//IL_001c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0028: Unknown result type (might be due to invalid IL or missing references)
					CharacterMaster summonMasterInstance = report.masterSummonReport.summonMasterInstance;
					if ((int)equipmentIndex != -1)
					{
						summonMasterInstance.inventory.SetEquipmentIndex(equipmentIndex, false);
						EliteDef eliteDefFromEquipmentIndex = EliteCatalog.GetEliteDefFromEquipmentIndex(equipmentIndex);
						if (Object.op_Implicit((Object)(object)eliteDefFromEquipmentIndex))
						{
							summonMasterInstance.inventory.GiveItemPermanent(Items.BoostHp, Mathf.RoundToInt((eliteDefFromEquipmentIndex.healthBoostCoefficient - 1f) * 10f));
							summonMasterInstance.inventory.GiveItemPermanent(Items.BoostDamage, Mathf.RoundToInt(eliteDefFromEquipmentIndex.damageBoostCoefficient - 1f) * 10);
						}
					}
					if (noAI)
					{
						BaseAI[] aiComponents = summonMasterInstance.aiComponents;
						for (int j = 0; j < aiComponents.Length; j++)
						{
							Object.Destroy((Object)(object)aiComponents[j]);
						}
						summonMasterInstance.aiComponents = Array.Empty<BaseAI>();
					}
				};
				for (int num2 = 0; num2 < num; num2++)
				{
					val4.Perform();
				}
			}
			finally
			{
				val.Dispose();
			}
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void CCVapiSpawnBody(ConCommandArgs args)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Invalid comparison between Unknown and I4
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: 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_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Expected O, but got Unknown
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Expected O, but got Unknown
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)VariantSpawnManager.instance))
			{
				Debug.LogWarning((object)"VarianceAPI's Variant Spawning commands are not available when the VarianceAPI expansion is disabled.");
				return;
			}
			if (((ConCommandArgs)(ref args)).Count == 0)
			{
				Debug.Log((object)"No Arguments Given");
				return;
			}
			if (!Object.op_Implicit((Object)(object)((ConCommandArgs)(ref args)).senderBody))
			{
				Debug.Log((object)"Sender must have a body");
				return;
			}
			BodyIndex bodyIndex = VAPIUtils.GetBodyIndex(((ConCommandArgs)(ref args))[0]);
			if ((int)bodyIndex == -1)
			{
				Debug.Log((object)"No body could be found with that name");
				return;
			}
			CharacterBody bodyPrefabBodyComponent = BodyCatalog.GetBodyPrefabBodyComponent(bodyIndex);
			if (!((Enum)bodyPrefabBodyComponent.bodyFlags).HasFlag((Enum)(object)(BodyFlags)4))
			{
				Debug.Log((object)$"Cannot spawn {bodyPrefabBodyComponent} as a variant via vapi_spawn_body as it's not flagged as a masterless body. Utilize vapi_spawn_ai instead.");
				return;
			}
			CharacterVariantProvider characterVariantProvider = GetCharacterVariantProvider(bodyIndex);
			if (characterVariantProvider == null)
			{
				Debug.Log((object)("CharacterBody with name " + ((ConCommandArgs)(ref args))[0] + " does not have a CharacterVariantProvider"));
				return;
			}
			string[] array = (((ConCommandArgs)(ref args)).TryGetArgString(1) ?? "").Replace(" ", "").Split(',', StringSplitOptions.RemoveEmptyEntries);
			List<CharacterVariantDef> list = default(List<CharacterVariantDef>);
			DisposableRental<CharacterVariantDef, List<CharacterVariantDef>> val = CollectionPool<CharacterVariantDef, List<CharacterVariantDef>>.RentCollection(ref list);
			try
			{
				ReadOnlyArray<CharacterVariantDef> allVariants = characterVariantProvider.allVariants;
				string[] array2 = array;
				foreach (string value in array2)
				{
					Enumerator<CharacterVariantDef> enumerator = allVariants.GetEnumerator();
					try
					{
						while (enumerator.MoveNext())
						{
							CharacterVariantDef current = enumerator.Current;
							if (current.cachedName.Contains(value, StringComparison.OrdinalIgnoreCase))
							{
								list.Add(current);
								break;
							}
						}
					}
					finally
					{
						((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
					}
				}
				list.Sort((CharacterVariantDef a, CharacterVariantDef b) => ((int)a.characterVariantIndex).CompareTo((int)b.characterVariantIndex));
				BodySpawnCard obj = ScriptableObject.CreateInstance<BodySpawnCard>();
				((SpawnCard)obj).sendOverNetwork = true;
				((SpawnCard)obj).prefab = ((Component)bodyPrefabBodyComponent).gameObject;
				((SpawnCard)obj).nodeGraphType = (GraphType)0;
				((SpawnCard)obj).directorCreditCost = 0;
				DirectorSpawnRequest val2 = new DirectorSpawnRequest((SpawnCard)(object)obj, new DirectorPlacementRule
				{
					position = ((ConCommandArgs)(ref args)).senderBody.corePosition,
					maxDistance = 5f,
					minDistance = 1f,
					placementMode = (PlacementMode)3,
					spawnOnTarget = ((ConCommandArgs)(ref args)).senderBody.transform
				}, VariantSpawnManager.instance.variantSpawnRng);
				new VariantDirectorSpawnRequest(val2).preassignedVariantDefs = list.ToArray();
				((SpawnCard)obj).DoSpawn(((ConCommandArgs)(ref args)).senderBody.corePosition, Quaternion.identity, val2);
				Object.Destroy((Object)(object)obj);
			}
			finally
			{
				val.Dispose();
			}
		}

		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void CCVapiSpawnAs(ConCommandArgs args)
		{
			//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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Invalid comparison between Unknown and I4
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)VariantSpawnManager.instance))
			{
				Debug.LogWarning((object)"VarianceAPI's Variant Spawning commands are not available when the VarianceAPI expansion is disabled.");
				return;
			}
			if (((ConCommandArgs)(ref args)).Count == 0)
			{
				Debug.Log((object)"No arguments Given");
				return;
			}
			BodyIndex bodyIndex = VAPIUtils.GetBodyIndex(((ConCommandArgs)(ref args))[0]);
			if ((int)bodyIndex == -1)
			{
				Debug.Log((object)"No body could be found with that name");
				return;
			}
			GameObject bodyPrefab = BodyCatalog.GetBodyPrefab(bodyIndex);
			CharacterVariantProvider characterVariantProvider = GetCharacterVariantProvider(bodyIndex);
			if (characterVariantProvider == null)
			{
				Debug.Log((object)("CharacterBody with name " + ((ConCommandArgs)(ref args))[0] + " does not have a CharacterVariantProvider"));
				return;
			}
			if (!Object.op_Implicit((Object)(object)args.sender))
			{
				Debug.Log((object)"Sender does not exist.");
				return;
			}
			CharacterMaster senderMaster = ((ConCommandArgs)(ref args)).senderMaster;
			if (!Object.op_Implicit((Object)(object)senderMaster))
			{
				Debug.Log((object)"Sender Master does not exist.");
				return;
			}
			string[] array = (((ConCommandArgs)(ref args)).TryGetArgString(1) ?? "").Replace(" ", "").Split(',', StringSplitOptions.RemoveEmptyEntries);
			List<CharacterVariantDef> list = default(List<CharacterVariantDef>);
			DisposableRental<CharacterVariantDef, List<CharacterVariantDef>> val = CollectionPool<CharacterVariantDef, List<CharacterVariantDef>>.RentCollection(ref list);
			try
			{
				ReadOnlyArray<CharacterVariantDef> allVariants = characterVariantProvider.allVariants;
				string[] array2 = array;
				foreach (string value in array2)
				{
					Enumerator<CharacterVariantDef> enumerator = allVariants.GetEnumerator();
					try
					{
						while (enumerator.MoveNext())
						{
							CharacterVariantDef current = enumerator.Current;
							if (current.cachedName.Contains(value, StringComparison.OrdinalIgnoreCase))
							{
								list.Add(current);
								break;
							}
						}
					}
					finally
					{
						((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
					}
				}
				list.Sort((CharacterVariantDef a, CharacterVariantDef b) => ((int)a.characterVariantIndex).CompareTo((int)b.characterVariantIndex));
				senderMaster.bodyPrefab = bodyPrefab;
				BoolConVar val2 = (BoolConVar)Reflection.GetFieldCached(typeof(Stage), "stage1PodConVar").GetValue(null);
				_ = val2.value;
				val2.SetBool(false);
				CharacterMasterVariantStorage characterMasterVariantStorage = default(CharacterMasterVariantStorage);
				if (((Component)senderMaster).TryGetComponent<CharacterMasterVariantStorage>(ref characterMasterVariantStorage))
				{
					characterMasterVariantStorage.RemoveVariantStorageForCharacter(in bodyIndex);
				}
				CharacterBody val3 = senderMaster.Respawn(senderMaster.GetBody().footPosition, senderMaster.GetBody().transform.rotation, false);
				CharacterBodyVariantController characterBodyVariantController = default(CharacterBodyVariantController);
				if (Object.op_Implicit((Object)(object)val3) && ((Component)val3).TryGetComponent<CharacterBodyVariantController>(ref characterBodyVariantController))
				{
					characterBodyVariantController.doNotRollForVariants = true;
					characterBodyVariantController.SetCharacterVariantDefsServer(list.ToArray());
				}
			}
			finally
			{
				val.Dispose();
			}
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		private static void LogMessage(object data)
		{
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		private static void LogWarning(object data)
		{
		}
	}
	public static class Extensions
	{
		public static void Write(this NetworkWriter writer, NetworkCharacterVariantIndex index)
		{
			writer.WritePackedUInt32(index.i);
		}

		public static NetworkCharacterVariantIndex ReadNetworkCharacterVariantIndex(this NetworkReader reader)
		{
			return new NetworkCharacterVariantIndex
			{
				i = reader.ReadPackedUInt32()
			};
		}

		public static void Write(this NetworkWriter writer, CharacterVariantIndex index)
		{
			writer.Write((NetworkCharacterVariantIndex)index);
		}

		public static CharacterVariantIndex ReadCharacterVariantIndex(this NetworkReader reader)
		{
			return reader.ReadNetworkCharacterVariantIndex();
		}

		public static void Write(this NetworkWriter writer, CharacterVariantTierIndex index)
		{
			NetworkExtensions.WritePackedIndex32(writer, (int)index);
		}

		public static CharacterVariantTierIndex ReadCharacterVariantTierIndex(this NetworkReader reader)
		{
			return (CharacterVariantTierIndex)NetworkExtensions.ReadPackedIndex32(reader);
		}

		public static GenericSkill? GetOrFindSkill(this SkillLocator? locator, SkillSlot slot, string? fallbackSkillName)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)locator == (Object)null)
			{
				return null;
			}
			if ((int)slot == -1)
			{
				if (string.IsNullOrWhiteSpace(fallbackSkillName))
				{
					return null;
				}
				return locator.FindSkill(fallbackSkillName);
			}
			return locator.GetSkill(slot);
		}

		internal static int? TryGetOptionalInt(this ConCommandArgs args, string startingIdentifier, StringComparison stringComparison = StringComparison.OrdinalIgnoreCase)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < args.userArgs.Count; i++)
			{
				if (((ConCommandArgs)(ref args)).TryGetArgString(i).StartsWith(startingIdentifier, stringComparison) && int.TryParse(args.userArgs[i].Substring(startingIdentifier.Length), out var result))
				{
					return result;
				}
			}
			return null;
		}

		internal static EquipmentIndex? TryGetOptionalEquipmentIndex(this ConCommandArgs args, string startingIdentifier)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			string text = ((ConCommandArgs)(ref args)).TryGetOptionalString(startingIdentifier, StringComparison.OrdinalIgnoreCase);
			if (text == null)
			{
				return null;
			}
			return EquipmentCatalog.FindEquipmentIndex(text);
		}
	}
	public sealed class CharacterVariantProvider
	{
		public enum RollType
		{
			Default,
			Unique,
			NonUnique
		}

		public struct RollVariantDefsArgs
		{
			public Xoroshiro128Plus rng;

			public float? spawnChanceMultiplier;

			public RollType? rollType;

			public CharacterVariantDef[]? additiveVariantDefs;

			public override string ToString()
			{
				//IL_0002: 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)
				StringBuilder stringBuilder = default(StringBuilder);
				StringBuilderDisposable val = StringBuilderPool.RentStringBuilder(ref stringBuilder);
				try
				{
					stringBuilder.AppendLine($"SpawnChance Multiplier: {spawnChanceMultiplier ?? 1f}");
					stringBuilder.AppendLine($"RollType: {rollType.GetValueOrDefault()}");
					stringBuilder.AppendLine("Additive Variants: " + ((additiveVariantDefs == null) ? "None" : ""));
					if (additiveVariantDefs != null)
					{
						CharacterVariantDef[] array = additiveVariantDefs;
						foreach (CharacterVariantDef characterVariantDef in array)
						{
							stringBuilder.AppendLine(characterVariantDef.cachedName);
						}
					}
					return stringBuilder.ToString();
				}
				finally
				{
					((StringBuilderDisposable)(ref val)).Dispose();
				}
			}
		}

		private readonly CharacterVariantDef[] _allVariants;

		public readonly BodyIndex associatedBodyIndex;

		private readonly List<CharacterVariantDef> _filteredUniqueVariants;

		private readonly List<CharacterVariantDef> _filteredNonUniqueVariants;

		private readonly WeightedSelection<int> uniqueVariantIndexSelector = new WeightedSelection<int>(8);

		public int totalVariantCount => allVariants.Length;

		public ReadOnlyArray<CharacterVariantDef> allVariants => ReadOnlyArray<CharacterVariantDef>.op_Implicit(_allVariants);

		public ReadOnlyList<CharacterVariantDef> filteredUniqueVariants => ReadOnlyList<CharacterVariantDef>.op_Implicit(_filteredUniqueVariants);

		public ReadOnlyList<CharacterVariantDef> filteredNonUniqueVariants => ReadOnlyList<CharacterVariantDef>.op_Implicit(_filteredNonUniqueVariants);

		public void FilterVariants()
		{
			_filteredNonUniqueVariants.Clear();
			_filteredUniqueVariants.Clear();
			for (int i = 0; i < totalVariantCount; i++)
			{
				CharacterVariantDef characterVariantDef = _allVariants[i];
				if (characterVariantDef.IsAvailable())
				{
					if (characterVariantDef.isUnique)
					{
						_filteredUniqueVariants.Add(characterVariantDef);
					}
					else
					{
						_filteredNonUniqueVariants.Add(characterVariantDef);
					}
				}
			}
		}

		public CharacterVariantDef[] RollVariantDefs(RollVariantDefsArgs args)
		{
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			Xoroshiro128Plus rng = args.rng;
			float spawnChanceMultiplier = args.spawnChanceMultiplier ?? 1f;
			RollType valueOrDefault = args.rollType.GetValueOrDefault();
			CharacterVariantDef[] additiveVariantDefs = args.additiveVariantDefs;
			CharacterVariantDef[] resultFromProcedure;
			switch (valueOrDefault)
			{
			case RollType.Default:
				DefaultRollProcedure(rng, spawnChanceMultiplier, out resultFromProcedure);
				break;
			case RollType.Unique:
				UniqueRollProcedure(rng, spawnChanceMultiplier, out resultFromProcedure);
				break;
			case RollType.NonUnique:
				NonUniqueRollProcedure(rng, spawnChanceMultiplier, out resultFromProcedure);
				break;
			default:
				VAPILog.Warning($"RollType {valueOrDefault} is not supported, returning empty array.", 161, "RollVariantDefs");
				return Array.Empty<CharacterVariantDef>();
			}
			if (additiveVariantDefs == null)
			{
				return resultFromProcedure;
			}
			List<CharacterVariantDef> list = default(List<CharacterVariantDef>);
			DisposableRental<CharacterVariantDef, List<CharacterVariantDef>> val = CollectionPool<CharacterVariantDef, List<CharacterVariantDef>>.RentCollection(ref list);
			try
			{
				list.AddRange(additiveVariantDefs);
				CharacterVariantDef[] array = resultFromProcedure;
				foreach (CharacterVariantDef item in array)
				{
					if (!list.Contains(item))
					{
						list.Add(item);
					}
				}
				return list.ToArray();
			}
			finally
			{
				val.Dispose();
			}
		}

		private void DefaultRollProcedure(Xoroshiro128Plus rng, float spawnChanceMultiplier, out CharacterVariantDef[] resultFromProcedure)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			CharacterVariantDef[] results;
			if (filteredUniqueVariants.Count > 0 && RollUniques(rng, spawnChanceMultiplier, out CharacterVariantDef uniqueResult))
			{
				resultFromProcedure = new CharacterVariantDef[1] { uniqueResult };
			}
			else if (filteredNonUniqueVariants.Count > 0 && RollNonUniques(rng, spawnChanceMultiplier, out results))
			{
				resultFromProcedure = results;
			}
			else
			{
				resultFromProcedure = Array.Empty<CharacterVariantDef>();
			}
		}

		private void UniqueRollProcedure(Xoroshiro128Plus rng, float spawnChanceMultiplier, out CharacterVariantDef[] resultFromProcedure)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			if (filteredUniqueVariants.Count > 0 && RollUniques(rng, spawnChanceMultiplier, out CharacterVariantDef uniqueResult))
			{
				resultFromProcedure = new CharacterVariantDef[1] { uniqueResult };
			}
			else
			{
				resultFromProcedure = Array.Empty<CharacterVariantDef>();
			}
		}

		private void NonUniqueRollProcedure(Xoroshiro128Plus rng, float spawnChanceMultiplier, out CharacterVariantDef[] resultFromProcedure)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			if (filteredNonUniqueVariants.Count > 0 && RollNonUniques(rng, spawnChanceMultiplier, out CharacterVariantDef[] results))
			{
				resultFromProcedure = results;
			}
			else
			{
				resultFromProcedure = Array.Empty<CharacterVariantDef>();
			}
		}

		private bool RollUniques(Xoroshiro128Plus spawnRng, float spawnChanceMultiplier, out CharacterVariantDef? uniqueResult)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			uniqueVariantIndexSelector.Clear();
			float num = 0f;
			for (int i = 0; i < filteredUniqueVariants.Count; i++)
			{
				float num2 = filteredUniqueVariants[i].spawnRate * spawnChanceMultiplier;
				uniqueVariantIndexSelector.AddChoice(i, Mathf.Min(100f, num2));
				num += Mathf.Max(0f, 100f - num2);
			}
			uniqueVariantIndexSelector.AddChoice(-1, num);
			int num3 = uniqueVariantIndexSelector.Evaluate(spawnRng.nextNormalizedFloat);
			bool flag = num3 != -1;
			uniqueResult = (flag ? filteredUniqueVariants[num3] : null);
			return flag;
		}

		private bool RollNonUniques(Xoroshiro128Plus spawnRng, float spawnChanceMultiplier, out CharacterVariantDef[]? results)
		{
			//IL_0002: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			List<CharacterVariantDef> list = default(List<CharacterVariantDef>);
			DisposableRental<CharacterVariantDef, List<CharacterVariantDef>> val = CollectionPool<CharacterVariantDef, List<CharacterVariantDef>>.RentCollection(ref list);
			try
			{
				for (int i = 0; i < filteredNonUniqueVariants.Count; i++)
				{
					CharacterVariantDef characterVariantDef = filteredNonUniqueVariants[i];
					float num = Mathf.Min(100f, characterVariantDef.spawnRate * spawnChanceMultiplier);
					if (!(num <= 0f) && spawnRng.RangeFloat(0f, 100f) <= num)
					{
						list.Add(characterVariantDef);
					}
				}
				bool result = list.Count != 0;
				results = list.ToArray();
				return result;
			}
			finally
			{
				val.Dispose();
			}
		}

		internal CharacterVariantProvider(CharacterVariantDef[] variantDefsForCharacter, BodyIndex associatedBodyIndex)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			_allVariants = variantDefsForCharacter;
			this.associatedBodyIndex = associatedBodyIndex;
			_filteredNonUniqueVariants = new List<CharacterVariantDef>();
			_filteredUniqueVariants = new List<CharacterVariantDef>();
		}
	}
	public enum CharacterVariantTierIndex
	{
		None = -1
	}
	public static class CharacterVariantTierCatalog
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Comparison<CharacterVariantTierDef> <>9__10_0;

			public static IsDisabledDelegate <>9__11_7;

			public static IsDisabledDelegate <>9__11_8;

			public static IsDisabledDelegate <>9__11_9;

			public static IsDisabledDelegate <>9__11_10;

			public static IsDisabledDelegate <>9__11_11;

			public static IsDisabledDelegate <>9__11_12;

			internal int <RegisterTierDefs>b__10_0(CharacterVariantTierDef a, CharacterVariantTierDef b)
			{
				return string.CompareOrdinal(a.cachedName, b.cachedName);
			}

			internal bool <ConfigureTier>b__11_7()
			{
				return !ConfiguredVariable<bool>.op_Implicit((ConfiguredVariable<bool>)(object)VAPIConfig._enableRewards);
			}

			internal bool <ConfigureTier>b__11_8()
			{
				return !ConfiguredVariable<bool>.op_Implicit((ConfiguredVariable<bool>)(object)VAPIConfig._enableRewards);
			}

			internal bool <ConfigureTier>b__11_9()
			{
				return !ConfiguredVariable<bool>.op_Implicit((ConfiguredVariable<bool>)(object)VAPIConfig._enableRewards);
			}

			internal bool <ConfigureTier>b__11_10()
			{
				return !ConfiguredVariable<bool>.op_Implicit((ConfiguredVariable<bool>)(object)VAPIConfig._enableRewards);
			}

			internal bool <ConfigureTier>b__11_11()
			{
				return !ConfiguredVariable<bool>.op_Implicit((ConfiguredVariable<bool>)(object)VAPIConfig._enableRewards);
			}

			internal bool <ConfigureTier>b__11_12()
			{
				return !ConfiguredVariable<bool>.op_Implicit((ConfiguredVariable<bool>)(object)VAPIConfig._enableRewards);
			}
		}

		private static CharacterVariantTierDef[]? _characterVariantTierDefs;

		private static Dictionary<string, CharacterVariantTierIndex> _characterVariantTierNametoIndex = new Dictionary<string, CharacterVariantTierIndex>(StringComparer.OrdinalIgnoreCase);

		public static ResourceAvailability catalogAvailability;

		public static ReadOnlyArray<CharacterVariantTierDef> registeredCharacterVariantTierDefs => ReadOnlyArray<CharacterVariantTierDef>.op_Implicit(_characterVariantTierDefs);

		public static int characterVariantTierCount
		{
			get
			{
				CharacterVariantTierDef[]? characterVariantTierDefs = _characterVariantTierDefs;
				if (characterVariantTierDefs == null)
				{
					return -1;
				}
				return characterVariantTierDefs.Length;
			}
		}

		public static CharacterVariantTierDef? GetCharacterVariantTierDef(CharacterVariantTierIndex index)
		{
			ThrowIfUnavailable();
			CharacterVariantTierDef result = default(CharacterVariantTierDef);
			if (ArrayUtils.TryGetSafe<CharacterVariantTierDef>(_characterVariantTierDefs, (int)index, ref result))
			{
				return result;
			}
			LogWarning($"TierIndex {index} is out of bounds, returning null.");
			return ArrayUtils.GetSafe<CharacterVariantTierDef>(_characterVariantTierDefs, (int)index);
		}

		public static CharacterVariantTierIndex FindCharacterVariantTierIndex(string? characterVariantTierName)
		{
			ThrowIfUnavailable();
			if (string.IsNullOrWhiteSpace(characterVariantTierName))
			{
				LogWarning("Cannot find a CharacterVariantTierIndex with an empty name, returning CharacterVariantTierIndex.None");
				return CharacterVariantTierIndex.None;
			}
			if (_characterVariantTierNametoIndex.TryGetValue(characterVariantTierName, out var value))
			{
				return value;
			}
			LogWarning("There's no CharacterVariantTierDef with the name " + characterVariantTierName + ", returning CharacterVariantTierIndex.None");
			return _characterVariantTierNametoIndex.GetValueOrDefault(characterVariantTierName, CharacterVariantTierIndex.None);
		}

		[SystemInitializer(new Type[] { typeof(VariantPackManager) })]
		private static IEnumerator Initialize()
		{
			_characterVariantTierNametoIndex.Clear();
			CoroutineWithResult<CharacterVariantTierDef[]> coroutineWithResult = CoroutineWithResult<CharacterVariantTierDef[]>.Rent((IEnumerator)RegisterTierDefs(VariantPackManager.characterVariantTierDefs));
			try
			{
				while (((CoroutineWithResult)coroutineWithResult).MoveNext())
				{
					yield return null;
				}
				_characterVariantTierDefs = coroutineWithResult.result;
			}
			finally
			{
				((IDisposable)coroutineWithResult)?.Dispose();
			}
			VAPILog.Info("CharacterVariantTierCatalog Initialized.", 111, "Initialize");
			((ResourceAvailability)(ref catalogAvailability)).MakeAvailable();
		}

		private static IEnumerator<CharacterVariantTierDef[]?> RegisterTierDefs(ReadOnlyArray<CharacterVariantTierDef> tiers)
		{
			//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)
			CharacterVariantTierDef[] sortedTiers = new CharacterVariantTierDef[tiers.Length];
			tiers.CopyTo((Array)sortedTiers, 0);
			Array.Sort(sortedTiers, (CharacterVariantTierDef a, CharacterVariantTierDef b) => string.CompareOrdinal(a.cachedName, b.cachedName));
			for (CharacterVariantTierIndex index = (CharacterVariantTierIndex)0; (int)index < sortedTiers.Length; index++)
			{
				yield return null;
				CharacterVariantTierDef characterVariantTierDef = sortedTiers[(int)index];
				if (characterVariantTierDef.associatedConfigFile != null)
				{
					ConfigureTier(characterVariantTierDef);
				}
				characterVariantTierDef.characterVariantTierIndex = index;
				_characterVariantTierNametoIndex.Add(characterVariantTierDef.cachedName, index);
				LogMessage("CharacterVariantTierDef " + characterVariantTierDef.cachedName + " added to the CharacterVariantTierCatalog");
			}
			yield return sortedTiers;
		}

		private static void ConfigureTier(CharacterVariantTierDef tierDef)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_00fd: Expected O, but got Unknown
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: 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_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Expected O, but got Unknown
			//IL_020d: Expected O, but got Unknown
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Expected O, but got Unknown
			//IL_031d: Expected O, but got Unknown
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: Unknown result type (might be due to invalid IL or missing references)
			//IL_036e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_0384: Unknown result type (might be due to invalid IL or missing references)
			//IL_0395: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0403: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Expected O, but got Unknown
			//IL_042d: Expected O, but got Unknown
			//IL_045e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0463: Unknown result type (might be due to invalid IL or missing references)
			//IL_047e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0489: Unknown result type (might be due to invalid IL or missing references)
			//IL_0494: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0508: Unknown result type (might be due to invalid IL or missing references)
			//IL_0513: Unknown result type (might be due to invalid IL or missing references)
			//IL_0418: Unknown result type (might be due to invalid IL or missing references)
			//IL_041d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0423: Expected O, but got Unknown
			//IL_053d: Expected O, but got Unknown
			//IL_056e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0573: Unknown result type (might be due to invalid IL or missing references)
			//IL_058e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0599: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0602: Unknown result type (might be due to invalid IL or missing references)
			//IL_060d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0618: Unknown result type (might be due to invalid IL or missing references)
			//IL_0623: Unknown result type (might be due to invalid IL or missing references)
			//IL_0528: Unknown result type (might be due to invalid IL or missing references)
			//IL_052d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0533: Expected O, but got Unknown
			//IL_064d: Expected O, but got Unknown
			//IL_067e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0683: Unknown result type (might be due to invalid IL or missing references)
			//IL_069e: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0705: Unknown result type (might be due to invalid IL or missing references)
			//IL_070c: Unknown result type (might be due to invalid IL or missing references)
			//IL_070d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0712: Unknown result type (might be due to invalid IL or missing references)
			//IL_071d: Unknown result type (might be due to invalid IL or missing references)
			//IL_072d: Expected O, but got Unknown
			//IL_0638: Unknown result type (might be due to invalid IL or missing references)
			//IL_063d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0643: Expected O, but got Unknown
			try
			{
				CharacterVariantTierDef characterVariantTierDef = tierDef;
				ConfiguredFloat val = new ConfiguredFloat(tierDef.goldRewardCoefficient)
				{
					section = tierDef.cachedName + " Tier",
					key = "Gold Multiplier",
					description = "The Gold Multiplier for this Tier.",
					configFile = tierDef.associatedConfigFile,
					modName = tierDef.ownerPlugin.Info.Metadata.Name,
					modGUID = tierDef.ownerPlugin.Info.Metadata.GUID,
					sliderType = (SliderTypeEnum)1
				};
				SliderConfig val2 = new SliderConfig
				{
					FormatString = "{0:0.0}",
					min = 0f,
					max = 100f
				};
				object obj = <>c.<>9__11_7;
				if (obj == null)
				{
					IsDisabledDelegate val3 = () => !ConfiguredVariable<bool>.op_Implicit((ConfiguredVariable<bool>)(object)VAPIConfig._enableRewards);
					<>c.<>9__11_7 = val3;
					obj = (object)val3;
				}
				((BaseOptionConfig)val2).checkIfDisabled = (IsDisabledDelegate)obj;
				val.sliderConfig = val2;
				characterVariantTierDef.goldRewardCoefficient = ConfiguredVariable<float>.op_Implicit((ConfiguredVariable<float>)(object)val.WithConfigChange((OnConfigChangedDelegate<float>)delegate(float f)
				{
					tierDef.goldRewardCoefficient = f;
				}).DoConfigure());
				CharacterVariantTierDef characterVariantTierDef2 = tierDef;
				ConfiguredFloat val4 = new ConfiguredFloat(tierDef.experienceRewardCoefficient)
				{
					section = tierDef.cachedName + " Tier",
					key = "Experience Multiplier",
					description = "The Experience Multiplier for this Tier",
					configFile = tierDef.associatedConfigFile,
					modName = tierDef.ownerPlugin.Info.Metadata.Name,
					modGUID = tierDef.ownerPlugin.Info.Metadata.GUID,
					sliderType = (SliderTypeEnum)1
				};
				SliderConfig val5 = new SliderConfig
				{
					FormatString = "{0:0.0}",
					min = 0f,
					max = 100f
				};
				object obj2 = <>c.<>9__11_8;
				if (obj2 == null)
				{
					IsDisabledDelegate val6 = () => !ConfiguredVariable<bool>.op_Implicit((ConfiguredVariable<bool>)(object)VAPIConfig._enableRewards);
					<>c.<>9__11_8 = val6;
					obj2 = (object)val6;
				}
				((BaseOptionConfig)val5).checkIfDisabled = (IsDisabledDelegate)obj2;
				val4.sliderConfig = val5;
				characterVariantTierDef2.experienceRewardCoefficient = ConfiguredVariable<float>.op_Implicit((ConfiguredVariable<float>)(object)val4.WithConfigChange((OnConfigChangedDelegate<float>)delegate(float f)
				{
					tierDef.experienceRewardCoefficient = f;
				}).DoConfigure());
				CharacterVariantTierDef characterVariantTierDef3 = tierDef;
				ConfiguredFloat val7 = new ConfiguredFloat(tierDef.commonItemRewardChance)
				{
					section = tierDef.cachedName + " Tier",
					key = "Common Item Drop Chance",
					description = "The Chance for variants of this Tier to drop a Common Item",
					configFile = tierDef.associatedConfigFile,
					modName = tierDef.ownerPlugin.Info.Metadata.Name,
					modGUID = tierDef.ownerPlugin.Info.Metadata.GUID,
					sliderType = (SliderTypeEnum)1
				};
				SliderConfig val8 = new SliderConfig
				{
					FormatString = "{0:0.0}",
					min = 0f,
					max = 100f
				};
				object obj3 = <>c.<>9__11_9;
				if (obj3 == null)
				{
					IsDisabledDelegate val9 = () => !ConfiguredVariable<bool>.op_Implicit((ConfiguredVariable<bool>)(object)VAPIConfig._enableRewards);
					<>c.<>9__11_9 = val9;
					obj3 = (object)val9;
				}
				((BaseOptionConfig)val8).checkIfDisabled = (IsDisabledDelegate)obj3;
				val7.sliderConfig = val8;
				characterVariantTierDef3.commonItemRewardChance = ConfiguredVariable<float>.op_Implicit((ConfiguredVariable<float>)(object)val7.WithConfigChange((OnConfigChangedDelegate<float>)delegate(float f)
				{
					tierDef.commonItemRewardChance = f;
				}).DoConfigure());
				CharacterVariantTierDef characterVariantTierDef4 = tierDef;
				ConfiguredFloat val10 = new ConfiguredFloat(tierDef.uncommonItemRewardChance)
				{
					section = tierDef.cachedName + " Tier",
					key = "Uncommon Item Drop Chance",
					description = "The Chance for variants of this Tier to drop an Uncommon Item",
					configFile = tierDef.associatedConfigFile,
					modName = tierDef.ownerPlugin.Info.Metadata.Name,
					modGUID = tierDef.ownerPlugin.Info.Metadata.GUID,
					sliderType = (SliderTypeEnum)1
				};
				SliderConfig val11 = new SliderConfig
				{
					FormatString = "{0:0.0}",
					min = 0f,
					max = 100f
				};
				object obj4 = <>c.<>9__11_10;
				if (obj4 == null)
				{
					IsDisabledDelegate val12 = () => !ConfiguredVariable<bool>.op_Implicit((ConfiguredVariable<bool>)(object)VAPIConfig._enableRewards);
					<>c.<>9__11_10 = val12;
					obj4 = (object)val12;
				}
				((BaseOptionConfig)val11).checkIfDisabled = (IsDisabledDelegate)obj4;
				val10.sliderConfig = val11;
				characterVariantTierDef4.uncommonItemRewardChance = ConfiguredVariable<float>.op_Implicit((ConfiguredVariable<float>)(object)val10.WithConfigChange((OnConfigChangedDelegate<float>)delegate(float f)
				{
					tierDef.uncommonItemRewardChance = f;
				}).DoConfigure());
				CharacterVariantTierDef characterVariantTierDef5 = tierDef;
				ConfiguredFloat val13 = new ConfiguredFloat(tierDef.legendaryItemRewardChance)
				{
					section = tierDef.cachedName + " Tier",
					key = "Red Item Drop Chance",
					description = "The Chance for variants of this Tier to drop a Red Item",
					configFile = tierDef.associatedConfigFile,
					modName = tierDef.ownerPlugin.Info.Metadata.Name,
					modGUID = tierDef.ownerPlugin.Info.Metadata.GUID,
					sliderType = (SliderTypeEnum)1
				};
				SliderConfig val14 = new SliderConfig
				{
					FormatString = "{0:0.0}",
					min = 0f,
					max = 100f
				};
				object obj5 = <>c.<>9__11_11;
				if (obj5 == null)
				{
					IsDisabledDelegate val15 = () => !ConfiguredVariable<bool>.op_Implicit((ConfiguredVariable<bool>)(object)VAPIConfig._enableRewards);
					<>c.<>9__11_11 = val15;
					obj5 = (object)val15;
				}
				((BaseOptionConfig)val14).checkIfDisabled = (IsDisabledDelegate)obj5;
				val13.sliderConfig = val14;
				characterVariantTierDef5.legendaryItemRewardChance = ConfiguredVariable<float>.op_Implicit((ConfiguredVariable<float>)(object)val13.WithConfigChange((OnConfigChangedDelegate<float>)delegate(float f)
				{
					tierDef.legendaryItemRewardChance = f;
				}).DoConfigure());
				CharacterVariantTierDef characterVariantTierDef6 = tierDef;
				ConfiguredFloat val16 = new ConfiguredFloat(tierDef.bossItemRewardChance)
				{
					section = tierDef.cachedName + " Tier",
					key = "Boss Item Drop Chance",
					description = "The Chance for Champion Variants of this Tier to drop it's Boss Item",
					configFile = tierDef.associatedConfigFile,
					modName = tierDef.ownerPlugin.Info.Metadata.Name,
					modGUID = tierDef.ownerPlugin.Info.Metadata.GUID,
					sliderType = (SliderTypeEnum)1
				};
				SliderConfig val17 = new SliderConfig
				{
					FormatString = "{0:0.0}",
					min = 0f,
					max = 100f
				};
				object obj6 = <>c.<>9__11_12;
				if (obj6 == null)
				{
					IsDisabledDelegate val18 = () => !ConfiguredVariable<bool>.op_Implicit((ConfiguredVariable<bool>)(object)VAPIConfig._enableRewards);
					<>c.<>9__11_12 = val18;
					obj6 = (object)val18;
				}
				((BaseOptionConfig)val17).checkIfDisabled = (IsDisabledDelegate)obj6;
				val16.sliderConfig = val17;
				characterVariantTierDef6.bossItemRewardChance = ConfiguredVariable<float>.op_Implicit((ConfiguredVariable<float>)(object)val16.WithConfigChange((OnConfigChangedDelegate<float>)delegate(float f)
				{
					tierDef.bossItemRewardChance = f;
				}).DoConfigure());
				tierDef.bonusArmor = ConfiguredVariable<float>.op_Implicit((ConfiguredVariable<float>)(object)new ConfiguredFloat(tierDef.bonusArmor)
				{
					section = tierDef.cachedName + " Tier",
					key = "Tier Armor Bonus",
					description = "Armor bonus applied to variants with this Tier, This value stacks additively when a Character has multiple CharacterVariantDefs applied.",
					configFile = tierDef.associatedConfigFile,
					modName = tierDef.ownerPlugin.Info.Metadata.Name,
					modGUID = tierDef.ownerPlugin.Info.Metadata.GUID,
					sliderType = (SliderTypeEnum)1,
					sliderConfig = new SliderConfig
					{
						min = 0f,
						max = 1000f
					}
				}.WithConfigChange((OnConfigChangedDelegate<float>)delegate(float f)
				{
					tierDef.bonusArmor = f;
				}).DoConfigure());
			}
			catch (Exception ex)
			{
				VAPILog.Error($"Error configuring tier {tierDef}: {ex}", 293, "ConfigureTier");
				InitializationExceptionWatcher.AddException(ex, tierDef.ownerPlugin);
			}
		}

		private static void ThrowIfUnavailable()
		{
			if (!((ResourceAvailability)(ref catalogAvailability)).available)
			{
				throw new InvalidOperationException("Cannot access CharacterVariantTierCatalog when it's not available, consider subscribing to the catalogAvailability.");
			}
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		private static void LogMessage(object data)
		{
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		private static void LogWarning(object data)
		{
		}
	}
	public struct PreAssignedSpawnData
	{
		public CharacterVariantDef[]? additiveVariantDefs;

		public float? spawnRateMultiplier;
	}
	[AddComponentMenu("")]
	public sealed class CharacterBodyVariantController : NetworkBehaviour, IBodyStatArgModifier
	{
		private static readonly ConVarFlags _flags;

		private static BoolConVar _logBodyController;

		private CharacterVariantDef[] _fallbackCharacterVariantDefs = Array.Empty<CharacterVariantDef>();

		private SyncListCharacterVariantIndex _characterVariantIndices = new SyncListCharacterVariantIndex();

		[SyncVar]
		private bool _doNotRollForVariants;

		[SyncVar]
		private bool _variantsApplied;

		private PreAssignedSpawnData? _preAssignedSpawnDataServer;

		private CharacterVariantMask _appliedVariantMask;

		private MSUContentBehaviour? _msuContentBehaviour;

		private CharacterMasterVariantStorage? _characterMasterVariantStorage;

		private static readonly List<string> _possibleArrivalTokensShared;

		private static readonly List<NetworkSoundEventDef> _possibleSpawnSoundsShared;

		private DisposableCollectionHelper _disposableCollectionHelper = new DisposableCollectionHelper(disposeInReverseOrder: true);

		private IEnumerator? _applyVisualModifiersAfterSkinCoroutine;

		private IEnumerator? _mdlSkinControllerApplySkinCoroutine;

		private static int kList_characterVariantIndices;

		public CharacterBody characterBody { get; private set; }

		public CharacterDeathBehavior? characterDeathBehavior { get; private set; }

		public CharacterModel? characterModel { get; private set; }

		public bool doNotRollForVariants
		{
			get
			{
				return _doNotRollForVariants;
			}
			[Server]
			set
			{
				if (!NetworkServer.active)
				{
					Debug.LogWarning((object)"[Server] function 'System.Void VAPI.CharacterBodyVariantController::set_doNotRollForVariants(System.Boolean)' called on client");
				}
				else if (_doNotRollForVariants != value)
				{
					Log($"Setting doNotRollForVariants to {value}");
					Network_doNotRollForVariants = value;
				}
			}
		}

		public bool supressArrivalMessageServer { get; set; }

		public bool variantsApplied
		{
			get
			{
				return _variantsApplied;
			}
			[Server]
			set
			{
				if (!NetworkServer.active)
				{
					Debug.LogWarning((object)"[Server] function 'System.Void VAPI.CharacterBodyVariantController::set_variantsApplied(System.Boolean)' called on client");
				}
				else if (_variantsApplied != value)
				{
					Network_variantsApplied = value;
				}
			}
		}

		public PreAssignedSpawnData? preAssignedSpawnDataServer
		{
			[Server]
			set
			{
				if (!NetworkServer.active)
				{
					Debug.LogWarning((object)"[Server] function 'System.Void VAPI.CharacterBodyVariantController::set_preAssignedSpawnDataServer(System.Nullable`1<VAPI.PreAssignedSpawnData>)' called on client");
					return;
				}
				Log("Setting Preassigned spawn data");
				_preAssignedSpawnDataServer = value;
			}
		}

		public string cachedVariantName { get; private set; } = "";

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

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

		public event Action? onVariantsUnapplied;

		public event Action<CharacterVariantDef[]>? onVariantsApplied;

		internal PreAssignedSpawnData ConsumePreAssignedSpawnData()
		{
			if (!HasPreAssignedSpawnData())
			{
				return default(PreAssignedSpawnData);
			}
			Log("Consuming preassigned spawn data");
			PreAssignedSpawnData value = _preAssignedSpawnDataServer.Value;
			_preAssignedSpawnDataServer = null;
			return value;
		}

		internal bool HasPreAssignedSpawnData()
		{
			return _preAssignedSpawnDataServer.HasValue;
		}

		private void Awake()
		{
			characterBody = ((Component)this).GetComponent<CharacterBody>();
			_msuContentBehaviour = ((Component)this).GetComponent<MSUContentBehaviour>();
			if (Object.op_Implicit((Object)(object)characterBody.modelLocator) && Object.op_Implicit((Object)(object)characterBody.modelLocator.modelTransform))
			{
				characterModel = ((Component)characterBody.modelLocator.modelTransform).GetComponent<CharacterModel>();
			}
			CharacterDeathBehavior val = default(CharacterDeathBehavior);
			if (((Component)characterBody).TryGetComponent<CharacterDeathBehavior>(ref val))
			{
				characterDeathBehavior = val;
			}
			((SyncList<NetworkCharacterVariantIndex>)(object)_characterVariantIndices).Callback = SyncListCallback;
			_appliedVariantMask = CharacterVariantMask.Rent();
			Log("Awake");
			((SyncList<NetworkCharacterVariantIndex>)(object)_characterVariantIndices).InitializeBehaviour((NetworkBehaviour)(object)this, kList_characterVariantIndices);
		}

		public bool IsVariantApplied(CharacterVariantDef? characterVariantDef)
		{
			return IsVariantApplied(Object.op_Implicit((Object)(object)characterVariantDef) ? characterVariantDef.characterVariantIndex : CharacterVariantIndex.none);
		}

		public bool IsVariantApplied(CharacterVariantIndex variantIndex)
		{
			bool num = _appliedVariantMask.Contains(variantIndex);
			if (!num)
			{
				Log($"{variantIndex} is not applied");
			}
			return num;
		}

		public override void OnStartClient()
		{
			((NetworkBehaviour)this).OnStartClient();
			Log("On Start Client");
			if (((SyncListStruct<NetworkCharacterVariantIndex>)_characterVariantIndices).Count != _fallbackCharacterVariantDefs.Length)
			{
				OnSyncListDirty();
			}
		}

		public ReadOnlyArray<CharacterVariantDef> GetCharacterVariantDefs()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			CharacterMasterVariantStorage characterMasterVariantStorage = GetCharacterMasterVariantStorage();
			if ((Object)(object)characterMasterVariantStorage != (Object)null && characterMasterVariantStorage.TryGetVariantsStoredForCharacter(in characterBody.bodyIndex, out CharacterVariantDef[] variantDefs))
			{
				Log("Retrieving CharacterVariantDefs from MasterStorage");
				return ReadOnlyArray<CharacterVariantDef>.op_Implicit(variantDefs);
			}
			Log("Retrieving CharacterVariantDefs from internal array");
			return ReadOnlyArray<CharacterVariantDef>.op_Implicit(_fallbackCharacterVariantDefs);
		}

		public CharacterMasterVariantStorage? GetCharacterMasterVariantStorage()
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_characterMasterVariantStorage != (Object)null && Object.op_Implicit((Object)(object)_characterMasterVariantStorage.characterMaster) && (Object)(object)_characterMasterVariantStorage.characterMaster.GetBody() == (Object)(object)characterBody)
			{
				return _characterMasterVariantStorage;
			}
			if (!Object.op_Implicit((Object)(object)characterBody) || ((Enum)characterBody.bodyFlags).HasFlag((Enum)(object)(BodyFlags)4))
			{
				return null;
			}
			CharacterMasterVariantStorage characterMasterVariantStorage = default(CharacterMasterVariantStorage);
			if (Object.op_Implicit((Object)(object)characterBody.master) && ((Component)characterBody.master).TryGetComponent<CharacterMasterVariantStorage>(ref characterMasterVariantStorage))
			{
				_characterMasterVariantStorage = characterMasterVariantStorage;
			}
			return _characterMasterVariantStorage;
		}

		[Server]
		public void SetCharacterVariantDefsServer(CharacterVariantDef[] variantDefs)
		{
			if (!NetworkServer.active)
			{
				Debug.LogWarning((object)"[Server] function 'System.Void VAPI.CharacterBodyVariantController::SetCharacterVariantDefsServer(VAPI.CharacterVariantDef[])' called on client");
			}
			else if (Object.op_Implicit((Object)(object)characterBody) && variantDefs != null)
			{
				if (variantsApplied)
				{
					VAPILog.Warning($"Tried to set {this}'s variant defs, but there are already variants applied! Either set the array to an empty array first or do not try to override variants!.", 311, "SetCharacterVariantDefsServer");
				}
				else
				{
					SetCharacterVariantDefsServerInternal(variantDefs);
				}
			}
		}

		[Server]
		private void SetCharacterVariantDefsServerInternal(CharacterVariantDef[] variantDefs)
		{
			if (!NetworkServer.active)
			{
				Debug.LogWarning((object)"[Server] function 'System.Void VAPI.CharacterBodyVariantController::SetCharacterVariantDefsServerInternal(VAPI.CharacterVariantDef[])' called on client");
				return;
			}
			if (variantDefs.Length != 0)
			{
				Log($"This is becoming a variant. with {variantDefs.Length} variants applied");
			}
			((SyncList<NetworkCharacterVariantIndex>)(object)_characterVariantIndices).Clear();
			for (int i = 0; i < variantDefs.Length; i++)
			{
				((SyncList<NetworkCharacterVariantIndex>)(object)_characterVariantIndices).Add((NetworkCharacterVariantIndex)variantDefs[i].characterVariantIndex);
			}
			if (((SyncListStruct<NetworkCharacterVariantIndex>)_characterVariantIndices).Count > 0)
			{
				((SyncList<NetworkCharacterVariantIndex>)(object)_characterVariantIndices).Dirty(0);
				variantsApplied = true;
			}
			else
			{
				variantsApplied = false;
			}
		}

		private void SyncListCallback(Operation<NetworkCharacterVariantIndex> op, int itemIndex)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			if ((int)op == 1 || (int)op == 6)
			{
				OnSyncListDirty();
			}
		}

		private void OnSyncListDirty()
		{
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			UnapplyBodyModifications();
			CharacterMasterVariantStorage characterMasterVariantStorage = GetCharacterMasterVariantStorage();
			if ((Object)(object)characterMasterVariantStorage != (Object)null)
			{
				Log("Unapplying variants on master");
				characterMasterVariantStorage.UnapplyVariants();
			}
			this.onVariantsUnapplied?.Invoke();
			Log("Clearing applied variant mask and retrieving new variants from synclist");
			_appliedVariantMask.Clear();
			_fallbackCharacterVariantDefs = new CharacterVariantDef[((SyncListStruct<NetworkCharacterVariantIndex>)_characterVariantIndices).Count];
			for (int i = 0; i < ((SyncListStruct<NetworkCharacterVariantIndex>)_characterVariantIndices).Count; i++)
			{
				_fallbackCharacterVariantDefs[i] = CharacterVariantCatalog.GetCharacterVariantDef(((SyncList<NetworkCharacterVariantIndex>)(object)_characterVariantIndices)[i]);
				_appliedVariantMask.Add(((SyncList<NetworkCharacterVariantIndex>)(object)_characterVariantIndices)[i]);
			}
			ApplyBodyModifications(ReadOnlyArray<CharacterVariantDef>.op_Implicit(_fallbackCharacterVariantDefs));
			if ((Object)(object)characterMasterVariantStorage != (Object)null)
			{
				Log("Applying variants on master");
				characterMasterVariantStorage.ApplyVariants(characterBody.bodyIndex, _fallbackCharacterVariantDefs);
			}
			this.onVariantsApplied?.Invoke(_fallbackCharacterVariantDefs);
			if (NetworkServer.active && !supressArrivalMessageServer && ConfiguredVariable<bool>.op_Implicit((ConfiguredVariable<bool>)(object)VAPIConfig._sendArrivalMessages))
			{
				AnnounceArrivalServer();
			}
			((MonoBehaviour)this).StartCoroutine(MarkStatsDirty());
		}

		private IEnumerator MarkStatsDirty()
		{
			if ((Object)(object)_msuContentBehaviour != (Object)null)
			{
				_msuContentBehaviour.StartGetInterfaces();
			}
			yield return null;
			characterBody.MarkAllStatsDirty();
		}

		private void AnnounceArrivalServer()
		{
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Expected O, but got Unknown
			if (!NetworkServer.active)
			{
				return;
			}
			Log("Announcing Arrival");
			_possibleArrivalTokensShared.Clear();
			_possibleSpawnSoundsShared.Clear();
			bool flag = false;
			bool flag2 = false;
			for (int i = 0; i < _fallbackCharacterVariantDefs.Length; i++)
			{
				CharacterVariantDef characterVariantDef = _fallbackCharacterVariantDefs[i];
				if (!Object.op_Implicit((Object)(object)characterVariantDef) || (Object)(object)characterVariantDef.variantTier == (Object)null)
				{
					continue;
				}
				if (characterVariantDef.variantTier.announceArrivalInChat)
				{
					flag = true;
					if (!string.IsNullOrWhiteSpace(characterVariantDef.arrivalToken))
					{
						_possibleArrivalTokensShared.Add(characterVariantDef.arrivalToken);
					}
				}
				if (Object.op_Implicit((Object)(object)characterVariantDef.variantTier.spawnedSoundEvent))
				{
					flag2 = true;
					_possibleSpawnSoundsShared.Add(characterVariantDef.variantTier.spawnedSoundEvent);
				}
			}
			if (flag)
			{
				bool flag3 = _possibleArrivalTokensShared.Count > 0;
				string baseToken = (flag3 ? ArrayUtils.GetRandom<string>((IList<string>)_possibleArrivalTokensShared) : "VAPI_GENERIC_ARRIVAL");
				SimpleChatMessage val = new SimpleChatMessage();
				val.baseToken = baseToken;
				val.paramTokens = ((!flag3) ? null : new string[1] { Language.GetString(characterBody.baseNameToken) });
				Chat.SendBroadcastChat((ChatMessageBase)(object)val);
			}
			if (flag2 && _possibleSpawnSoundsShared.Count > 0)
			{
				EffectManager.SimpleSoundEffect(ArrayUtils.GetRandom<NetworkSoundEventDef>((IList<NetworkSoundEventDef>)_possibleSpawnSoundsShared).index, characterBody.corePosition, true);
			}
		}

		private unsafe void ApplyBodyModifications(ReadOnlyArray<CharacterVariantDef> characterVariants)
		{
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)