Decompiled source of MVP Crown v1.0.2

MVP_Crown/Crown_Mod.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using RoR2;
using RoR2.ContentManagement;
using RoR2.Stats;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Rendering;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Crown_Mod
{
	public class SpinCrown : MonoBehaviour
	{
		private Vector3 localPosBeforeOffset;

		private Transform parentTransform;

		private void Awake()
		{
			((Behaviour)this).enabled = true;
		}

		private void Start()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			parentTransform = ((Component)this).transform.parent;
			localPosBeforeOffset = ((Component)this).transform.localPosition;
			((Component)this).transform.parent = null;
			((Component)this).transform.rotation = Quaternion.identity;
			((Component)this).transform.localScale = CrownItemDisplayRule.GetCrownDisplayRule().localScale;
		}

		private void Update()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)parentTransform))
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
			((Component)this).transform.Rotate(Vector3.up * Time.deltaTime * 60f, (Space)1);
			((Component)this).transform.position = parentTransform.position + localPosBeforeOffset + Mathf.Sin(Time.time * MathF.PI * 0.5f) * Vector3.up * 0.05f;
		}
	}
	public class CharacterSpecific
	{
		private static ItemDisplayRule CreateItemDisplayRuleDeepCopy(ItemDisplayRule toCopy)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_0059: 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_0071: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			ItemDisplayRule result = default(ItemDisplayRule);
			result.childName = toCopy.childName;
			result.localPos = toCopy.localPos;
			result.localAngles = toCopy.localAngles;
			result.localScale = toCopy.localScale;
			result.limbMask = toCopy.limbMask;
			result.ruleType = toCopy.ruleType;
			result.followerPrefab = toCopy.followerPrefab;
			result.followerPrefabAddress = toCopy.followerPrefabAddress;
			return result;
		}

		public static ItemDisplayRule GetCrownDisplayRuleForCharacter(CharacterModel model)
		{
			//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_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: 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_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: 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_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: 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_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			ItemDisplayRule val = CrownItemDisplayRule.GetCrownDisplayRule();
			switch (((Object)model).name)
			{
			case "mdlChef":
				val = CreateItemDisplayRuleDeepCopy(val);
				val.localPos = Vector3.up * 1.1f;
				break;
			case "mdlFalseSon":
				val = CreateItemDisplayRuleDeepCopy(val);
				val.localPos = Vector3.up * 0.9f;
				break;
			case "mdlCroco":
				val = CreateItemDisplayRuleDeepCopy(val);
				val.localPos = Vector3.up * 0.9f;
				break;
			case "mdlEngi":
				val = CreateItemDisplayRuleDeepCopy(val);
				val.localPos = new Vector3(0f, 1.5f, 0.25f);
				val.childName = "Base";
				break;
			case "mdlToolbot":
				val = CreateItemDisplayRuleDeepCopy(val);
				val.localPos = Vector3.up * 0.9f;
				val.childName = "Head";
				break;
			case "mdlCaptain":
				val = CreateItemDisplayRuleDeepCopy(val);
				val.localPos = new Vector3(0f, 1.5f, 0f);
				val.childName = "Base";
				break;
			case "mdlTreebot":
				val = CreateItemDisplayRuleDeepCopy(val);
				val.localPos = new Vector3(0f, 2.5f, 0f);
				val.childName = "Base";
				break;
			}
			return val;
		}
	}
	public class ContentPackLoader
	{
		private class CustomContentPackProvider : IContentPackProvider
		{
			[CompilerGenerated]
			private sealed class <FinalizeAsync>d__4 : IEnumerator<object>, IEnumerator, IDisposable
			{
				private int <>1__state;

				private object <>2__current;

				public FinalizeAsyncArgs args;

				public CustomContentPackProvider <>4__this;

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

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

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

				[DebuggerHidden]
				void IDisposable.Dispose()
				{
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					if (<>1__state != 0)
					{
						return false;
					}
					<>1__state = -1;
					args.ReportProgress(1f);
					return false;
				}

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

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

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

				private object <>2__current;

				public GetContentPackAsyncArgs args;

				public CustomContentPackProvider <>4__this;

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

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

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

				[DebuggerHidden]
				void IDisposable.Dispose()
				{
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					if (<>1__state != 0)
					{
						return false;
					}
					<>1__state = -1;
					ContentPack.Copy(<>4__this.contentPack, args.output);
					args.ReportProgress(1f);
					return false;
				}

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

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

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

				private object <>2__current;

				public LoadStaticContentAsyncArgs args;

				public CustomContentPackProvider <>4__this;

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

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

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

				[DebuggerHidden]
				void IDisposable.Dispose()
				{
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					if (<>1__state != 0)
					{
						return false;
					}
					<>1__state = -1;
					args.ReportProgress(1f);
					return false;
				}

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

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

			protected ContentPack contentPack;

			public string identifier => contentPack.identifier;

			public CustomContentPackProvider(ContentPack contentPack)
			{
				this.contentPack = contentPack;
			}

			[IteratorStateMachine(typeof(<FinalizeAsync>d__4))]
			public IEnumerator FinalizeAsync(FinalizeAsyncArgs args)
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <FinalizeAsync>d__4(0)
				{
					<>4__this = this,
					args = args
				};
			}

			[IteratorStateMachine(typeof(<LoadStaticContentAsync>d__5))]
			public IEnumerator LoadStaticContentAsync(LoadStaticContentAsyncArgs args)
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <LoadStaticContentAsync>d__5(0)
				{
					<>4__this = this,
					args = args
				};
			}

			[IteratorStateMachine(typeof(<GenerateContentPackAsync>d__6))]
			public IEnumerator GenerateContentPackAsync(GetContentPackAsyncArgs args)
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <GenerateContentPackAsync>d__6(0)
				{
					<>4__this = this,
					args = args
				};
			}
		}

		public ContentPack additionalContent;

		private void OnAddContentPack(AddContentPackProviderDelegate _addContentDelegate)
		{
			CustomContentPackProvider customContentPackProvider = new CustomContentPackProvider(additionalContent);
			try
			{
				_addContentDelegate.Invoke((IContentPackProvider)(object)customContentPackProvider);
				Plugin.Logger.LogInfo((object)"Sucessfully supplied the content provider");
			}
			catch
			{
				Plugin.Logger.LogWarning((object)"Could not load the content pack.");
			}
		}

		public void SetupLoadPack()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			ContentManager.collectContentPackProviders += new CollectContentPackProvidersDelegate(OnAddContentPack);
		}

		public ContentPackLoader(ContentPack _additionalContent)
		{
			additionalContent = _additionalContent;
		}
	}
	public class CrownItemDisplayRule
	{
		[HarmonyPatch(typeof(ItemDisplayRuleSet), "Init")]
		private class AddItemDisplayRules
		{
			private static void PatchCharacterModel(CharacterModel model)
			{
				//IL_002d: 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_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_004d: Unknown result type (might be due to invalid IL or missing references)
				if (!Object.op_Implicit((Object)(object)model.itemDisplayRuleSet))
				{
					model.itemDisplayRuleSet = ScriptableObject.CreateInstance<ItemDisplayRuleSet>();
				}
				model.itemDisplayRuleSet.SetDisplayRuleGroup((Object)(object)CrownItemDef.GetCrownDef(), new DisplayRuleGroup
				{
					rules = (ItemDisplayRule[])(object)new ItemDisplayRule[1] { CharacterSpecific.GetCrownDisplayRuleForCharacter(model) }
				});
			}

			[HarmonyPrefix]
			private static void AddCustomDispRules()
			{
				foreach (GameObject allBodyPrefab in BodyCatalog.allBodyPrefabs)
				{
					CharacterModel componentInChildren = allBodyPrefab.GetComponentInChildren<CharacterModel>();
					if (Object.op_Implicit((Object)(object)componentInChildren))
					{
						PatchCharacterModel(componentInChildren);
					}
				}
			}
		}

		private static ItemDisplayRule crownDisplayRule;

		private static bool setCrownDisplayRule;

		public static MeshRenderer crownMeshRenderer
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)CrownItemDef.crownGameobj))
				{
					return null;
				}
				return CrownItemDef.crownGameobj.GetComponentInChildren<MeshRenderer>();
			}
		}

		private static void SetParentedPrefabSettings()
		{
			//IL_0007: 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)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_004e: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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)
			crownDisplayRule.ruleType = (ItemDisplayRuleType)0;
			crownDisplayRule.limbMask = (LimbFlags)0;
			crownDisplayRule.followerPrefab = CrownItemDef.crownGameobj;
			crownDisplayRule.followerPrefabAddress = new AssetReferenceGameObject("");
			crownDisplayRule.childName = "Head";
			crownDisplayRule.localScale = Vector3.one * 0.3f;
			crownDisplayRule.localPos = Vector3.up * 0.55f;
			crownDisplayRule.followerPrefab.AddComponent<SpinCrown>();
		}

		private static void SetRenderingInfo()
		{
			//IL_0013: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			ItemDisplay val = crownDisplayRule.followerPrefab.AddComponent<ItemDisplay>();
			val.visibilityLevel = (VisibilityLevel)3;
			MeshRenderer val2 = crownMeshRenderer;
			val.rendererInfos = (RendererInfo[])(object)new RendererInfo[1]
			{
				new RendererInfo
				{
					renderer = (Renderer)(object)val2,
					defaultMaterial = ((Renderer)val2).material,
					defaultShadowCastingMode = (ShadowCastingMode)1,
					ignoreOverlays = false,
					hideOnDeath = true
				}
			};
		}

		public static ItemDisplayRule GetCrownDisplayRule()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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)
			if (setCrownDisplayRule)
			{
				return crownDisplayRule;
			}
			crownDisplayRule = default(ItemDisplayRule);
			SetParentedPrefabSettings();
			SetRenderingInfo();
			setCrownDisplayRule = true;
			UnitTest.TestShaderConfig();
			return crownDisplayRule;
		}
	}
	public class CrownItemDef
	{
		public const string CROWN_ITEM_NAME = "MVP Crown";

		public const ItemTier CROWN_ITEM_TIER = 5;

		private static ItemDef crownItemDef;

		public static GameObject crownGameobj
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)crownItemDef))
				{
					return null;
				}
				return crownItemDef.pickupModelPrefab;
			}
		}

		private static string ResourcesFolder => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

		private static void SetCrownDescriptions()
		{
			((Object)crownItemDef).name = "MVP Crown";
			crownItemDef.nameToken = "MVP Crown";
			crownItemDef.descriptionToken = "Congrats Your The Best Player In The Lobby!";
			crownItemDef.loreToken = "Wow, i didn't even know that this would ever be visible :)";
			crownItemDef.pickupToken = "Congrats Your The Best Player In The Lobby!";
		}

		private static void SetItemDefDisplayProperties()
		{
			crownItemDef.pickupIconSprite = Helpers.LoadSpriteFromName("CrownItemInventoryImage.png");
			AssetBundle val = AssetBundle.LoadFromFile(ResourcesFolder + "\\crownbundle");
			crownItemDef.pickupModelPrefab = val.LoadAsset<GameObject>("Crown");
			crownItemDef.hidden = false;
		}

		private static void SetRequiredMisc()
		{
			crownItemDef.unlockableDef = null;
			crownItemDef.tier = (ItemTier)5;
			crownItemDef.canRemove = false;
			ItemDef obj = crownItemDef;
			ItemTag[] array = new ItemTag[3];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			obj.tags = (ItemTag[])(object)array;
		}

		public static ItemDef GetCrownDef()
		{
			if (Object.op_Implicit((Object)(object)crownItemDef))
			{
				return crownItemDef;
			}
			crownItemDef = ScriptableObject.CreateInstance<ItemDef>();
			SetCrownDescriptions();
			SetItemDefDisplayProperties();
			SetRequiredMisc();
			return crownItemDef;
		}
	}
	public class CrownDistribution
	{
		private static PlayerStatsComponent lastCrownWinner;

		private static PlayerStatsComponent bestPlayerFound;

		public static PlayerStatsComponent bestPlayerFoundSafer
		{
			get
			{
				if (Object.op_Implicit((Object)(object)bestPlayerFound))
				{
					return bestPlayerFound;
				}
				if (PlayerStatsComponent.instancesList.Count > 0)
				{
					return PlayerStatsComponent.instancesList[0];
				}
				Plugin.Logger.LogWarning((object)"Attempting To Access Best Player Stats When No Player Exist.");
				return null;
			}
		}

		private static ulong GetTotalDamage(StatSheet playerStatSheet)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			ulong num = 0uL;
			StatField[] fields = playerStatSheet.fields;
			for (int i = 0; i < fields.Length; i++)
			{
				StatField val = fields[i];
				if (((StatField)(ref val)).name == "totalDamageDealt")
				{
					num += ((StatField)(ref val)).ulongValue;
				}
				else if (((StatField)(ref val)).name == "totalMinionDamageDealt")
				{
					num += ((StatField)(ref val)).ulongValue;
				}
			}
			return num;
		}

		private static PlayerStatsComponent GetPlayerWithBestStats()
		{
			PlayerStatsComponent val = bestPlayerFoundSafer;
			foreach (PlayerStatsComponent instances in PlayerStatsComponent.instancesList)
			{
				if (GetTotalDamage(val.currentStats) < GetTotalDamage(instances.currentStats))
				{
					val = instances;
				}
			}
			return val;
		}

		public static void EvaluateBestPlayer()
		{
			if (PlayerStatsComponent.instancesList.Count > 0)
			{
				bestPlayerFound = GetPlayerWithBestStats();
			}
		}

		public static void AwardBestPlayer()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)lastCrownWinner))
			{
				lastCrownWinner.characterMaster.inventory.RemoveItem(ItemCatalog.FindItemIndex("MVP Crown"), 1);
			}
			bestPlayerFound.characterMaster.inventory.GiveItemString("MVP Crown");
			lastCrownWinner = bestPlayerFound;
		}
	}
	[HarmonyPatch(typeof(StatManager), "OnServerStageBegin")]
	public class GiveCrownToBestPlayerOnNewStage
	{
		private static int stagesEntered;

		[HarmonyPostfix]
		private static void GiveCrownToBestPlayer()
		{
			stagesEntered++;
			if (stagesEntered >= 2)
			{
				CrownDistribution.EvaluateBestPlayer();
				CrownDistribution.AwardBestPlayer();
			}
		}
	}
	public class Helpers
	{
		public static Sprite LoadSpriteFromName(string name)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_004c: 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)
			string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + name;
			byte[] array = File.ReadAllBytes(path);
			Texture2D val = new Texture2D(0, 0);
			ImageConversion.LoadImage(val, array);
			return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
		}
	}
	[BepInPlugin("Crown_Mod", "MVP Crown For RoR2", "1.0.2")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private void CreateCrownModContentPack()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			ContentPack val = new ContentPack();
			val.itemDefs.Add((ItemDef[])(object)new ItemDef[1] { CrownItemDef.GetCrownDef() });
			val.identifier = "Crown_Mod_Pack";
			ContentPackLoader contentPackLoader = new ContentPackLoader(val);
			contentPackLoader.SetupLoadPack();
		}

		private void Awake()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			CreateCrownModContentPack();
			Harmony val = new Harmony("Crown_Mod");
			val.PatchAll(Assembly.GetExecutingAssembly());
		}
	}
	internal class UnitTest
	{
		[HarmonyPatch(typeof(ItemCatalog), "Init")]
		private class TestGetItemIndex
		{
			private static void OnTestFail()
			{
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				Plugin.Logger.LogInfo((object)("Item Name --> " + ((Object)CrownItemDef.GetCrownDef()).name));
				Plugin.Logger.LogInfo((object)"Printing Entire Catalog");
				foreach (string key in ItemCatalog.itemNameToIndex.Keys)
				{
					Plugin.Logger.LogInfo((object)$"\t{key} --> {ItemCatalog.itemNameToIndex[key]}");
				}
			}

			[HarmonyPostfix]
			private static void PrintCrownIndex()
			{
				//IL_0055: Unknown result type (might be due to invalid IL or missing references)
				if (testingItemIndex)
				{
					bool flag = ItemCatalog.itemNameToIndex.ContainsKey("MVP Crown");
					Plugin.Logger.LogInfo((object)$"Test: Is Item In Catalog : {flag}");
					if (flag)
					{
						Plugin.Logger.LogInfo((object)string.Format("Item Index --> {0}", ItemCatalog.itemNameToIndex["MVP Crown"]));
					}
					else
					{
						OnTestFail();
					}
				}
			}
		}

		[HarmonyPatch(typeof(StatManager), "OnServerStageBegin")]
		private class TestCrownItemEquipable
		{
			[HarmonyPostfix]
			private static void GiveCrownItemToPlayer()
			{
				if (testingCanGiveCrownItem)
				{
					Inventory inventory = PlayerStatsComponent.instancesList[0].characterMaster.inventory;
					inventory.GiveItemString("MVP Crown");
					Plugin.Logger.LogInfo((object)"Testing : Give Player Crown Item : Status Unknown");
				}
			}
		}

		internal static bool testingItemIndex;

		internal static bool testingCanGiveCrownItem;

		internal static bool testingItemShader;

		internal static bool testingCrownDisplayConflicts;

		public static void ReadItemDispRules()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Invalid comparison between Unknown and I4
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			foreach (GameObject allBodyPrefab in BodyCatalog.allBodyPrefabs)
			{
				CharacterModel componentInChildren = allBodyPrefab.GetComponentInChildren<CharacterModel>();
				if (!Object.op_Implicit((Object)(object)componentInChildren))
				{
					continue;
				}
				DisplayRuleGroup[] runtimeItemRuleGroups = componentInChildren.itemDisplayRuleSet.runtimeItemRuleGroups;
				for (int i = 0; i < runtimeItemRuleGroups.Length; i++)
				{
					DisplayRuleGroup val = runtimeItemRuleGroups[i];
					if (!((DisplayRuleGroup)(ref val)).isEmpty && (int)val.rules[0].ruleType <= 0)
					{
						Plugin.Logger.LogInfo((object)val.rules[0].childName);
					}
				}
			}
		}

		public static void TestShaderConfig()
		{
			if (!testingItemShader)
			{
				return;
			}
			MeshRenderer crownMeshRenderer = CrownItemDisplayRule.crownMeshRenderer;
			if (!Object.op_Implicit((Object)(object)crownMeshRenderer))
			{
				Plugin.Logger.LogWarning((object)"Could Not Find The Renderer Of The Crown Model");
				return;
			}
			Material material = ((Renderer)crownMeshRenderer).GetMaterial();
			if (!Object.op_Implicit((Object)(object)material))
			{
				Plugin.Logger.LogWarning((object)"Could Not Find the Material Of The Crown");
				return;
			}
			if (!Object.op_Implicit((Object)(object)material.shader))
			{
				Plugin.Logger.LogWarning((object)"Could Not Find the Shader Of The Crown");
				return;
			}
			Plugin.Logger.LogInfo((object)("Crown Mat Shader Name == " + ((Object)material.shader).name));
			if (!Object.op_Implicit((Object)(object)material.GetTexture("_MainTex")))
			{
				Plugin.Logger.LogInfo((object)"Crown Mat Texture Could Not Be Found");
			}
			else if (Object.op_Implicit((Object)(object)material.GetTexture("_MainTex")))
			{
				Plugin.Logger.LogInfo((object)("Main Texture Name == " + ((Object)material.GetTexture("_MainTex")).name));
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Crown_Mod";

		public const string PLUGIN_NAME = "MVP Crown For RoR2";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}