Decompiled source of BlightedElites v1.2.1

plugins/Moffein-BlightedElites/BlightedElites.dll

Decompiled 2 months 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.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BlightedElites.Components;
using IL.RoR2;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.RoR2;
using R2API;
using R2API.Utils;
using RoR2;
using RoR2.ContentManagement;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;

[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("BlightedElites")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+870881fe24d81b9054ae1cf2cbf5df371094b540")]
[assembly: AssemblyProduct("BlightedElites")]
[assembly: AssemblyTitle("BlightedElites")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace BlightedElites
{
	public class BlightedElitesContentPack : IContentPackProvider
	{
		public static ContentPack content = new ContentPack();

		public string identifier => "MoffeinBlightedElites.content";

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

		public IEnumerator GenerateContentPackAsync(GetContentPackAsyncArgs args)
		{
			ContentPack.Copy(content, args.output);
			yield break;
		}

		public IEnumerator LoadStaticContentAsync(LoadStaticContentAsyncArgs args)
		{
			content.eliteDefs.Add((EliteDef[])(object)new EliteDef[1] { BlightedElitesPlugin.AffixBlightedElite });
			content.buffDefs.Add((BuffDef[])(object)new BuffDef[1] { BlightedElitesPlugin.AffixBlightedBuff });
			content.networkSoundEventDefs.Add((NetworkSoundEventDef[])(object)new NetworkSoundEventDef[1] { AffixBlightedComponent.rerollSound });
			content.equipmentDefs.Add((EquipmentDef[])(object)new EquipmentDef[1] { BlightedElitesPlugin.AffixBlightedEquipment });
			yield break;
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.Moffein.BlightedElites", "Blighted Elites", "1.2.1")]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class BlightedElitesPlugin : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static hook_GetSubtitle <>9__17_0;

			public static Func<Instruction, bool> <>9__17_2;

			public static Func<bool, BuffIndex, CharacterBody, bool> <>9__17_3;

			public static Manipulator <>9__17_1;

			public static hook_Init <>9__22_0;

			public static Func<Instruction, bool> <>9__22_3;

			public static Func<int, CharacterModel, int> <>9__22_4;

			public static Manipulator <>9__22_1;

			public static Func<Instruction, bool> <>9__22_5;

			public static Func<float, CharacterModel, float> <>9__22_6;

			public static Manipulator <>9__22_2;

			internal string <SetupBuff>b__17_0(orig_GetSubtitle orig, CharacterBody self)
			{
				//IL_0014: 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)
				if (Object.op_Implicit((Object)(object)self.equipmentSlot) && self.equipmentSlot.equipmentIndex == AffixBlightedEquipment.equipmentIndex)
				{
					return Language.GetString("ELITE_MODIFIER_BLIGHTED_MOFFEIN_SUBTITLENAMETOKEN");
				}
				return orig.Invoke(self);
			}

			internal void <SetupBuff>b__17_1(ILContext il)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: Unknown result type (might be due to invalid IL or missing references)
				ILCursor val = new ILCursor(il);
				val = val.GotoNext((MoveType)2, new Func<Instruction, bool>[1]
				{
					(Instruction x) => ILPatternMatchingExt.MatchCallvirt<CharacterBody>(x, "HasBuff")
				});
				val.Emit(OpCodes.Ldloc, 6);
				val.Emit(OpCodes.Ldloc_0);
				val.EmitDelegate<Func<bool, BuffIndex, CharacterBody, bool>>((Func<bool, BuffIndex, CharacterBody, bool>)delegate(bool hasBuff, BuffIndex buffIndex, CharacterBody cb)
				{
					//IL_0004: Unknown result type (might be due to invalid IL or missing references)
					//IL_000a: Unknown result type (might be due to invalid IL or missing references)
					if (hasBuff && buffIndex != AffixBlightedBuff.buffIndex && cb.HasBuff(AffixBlightedBuff))
					{
						hasBuff = false;
					}
					return hasBuff;
				});
			}

			internal bool <SetupBuff>b__17_2(Instruction x)
			{
				return ILPatternMatchingExt.MatchCallvirt<CharacterBody>(x, "HasBuff");
			}

			internal bool <SetupBuff>b__17_3(bool hasBuff, BuffIndex buffIndex, CharacterBody cb)
			{
				//IL_0004: Unknown result type (might be due to invalid IL or missing references)
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				if (hasBuff && buffIndex != AffixBlightedBuff.buffIndex && cb.HasBuff(AffixBlightedBuff))
				{
					hasBuff = false;
				}
				return hasBuff;
			}

			internal void <SetupElite>b__22_0(orig_Init orig)
			{
				orig.Invoke();
				EliteTierDef[] combatDirectorEliteTiers = EliteAPI.GetCombatDirectorEliteTiers();
				foreach (EliteTierDef val in combatDirectorEliteTiers)
				{
					if (val.eliteTypes.Contains(malachiteDef) || val.eliteTypes.Contains(celestineDef))
					{
						EliteTierDef val2 = val;
						List<EliteDef> list = val2.eliteTypes.ToList();
						list.Add(AffixBlightedElite);
						val2.eliteTypes = list.ToArray();
						Debug.Log((object)"BlightedElites: Successfully added to tier.");
					}
				}
			}

			internal void <SetupElite>b__22_1(ILContext il)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_0047: Unknown result type (might be due to invalid IL or missing references)
				ILCursor val = new ILCursor(il);
				val.GotoNext(new Func<Instruction, bool>[1]
				{
					(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(Items), "InvadingDoppelganger")
				});
				val.Index += 2;
				val.Emit(OpCodes.Ldarg_0);
				val.EmitDelegate<Func<int, CharacterModel, int>>((Func<int, CharacterModel, int>)delegate(int vengeanceCount, CharacterModel self)
				{
					//IL_0002: Unknown result type (might be due to invalid IL or missing references)
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					if (self.myEliteIndex == AffixBlightedElite.eliteIndex)
					{
						vengeanceCount++;
					}
					return vengeanceCount;
				});
			}

			internal bool <SetupElite>b__22_3(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdsfld(x, typeof(Items), "InvadingDoppelganger");
			}

			internal int <SetupElite>b__22_4(int vengeanceCount, CharacterModel self)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				if (self.myEliteIndex == AffixBlightedElite.eliteIndex)
				{
					vengeanceCount++;
				}
				return vengeanceCount;
			}

			internal void <SetupElite>b__22_2(ILContext il)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Expected O, but got Unknown
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				ILCursor val = new ILCursor(il);
				val.GotoNext((MoveType)2, new Func<Instruction, bool>[1]
				{
					(Instruction x) => ILPatternMatchingExt.MatchLdfld(x, typeof(HealthComponent), "shield")
				});
				val.Emit(OpCodes.Ldarg_0);
				val.EmitDelegate<Func<float, CharacterModel, float>>((Func<float, CharacterModel, float>)((float shieldAmount, CharacterModel self) => (self.myEliteIndex == AffixBlightedElite.eliteIndex) ? 0f : shieldAmount));
			}

			internal bool <SetupElite>b__22_5(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdfld(x, typeof(HealthComponent), "shield");
			}

			internal float <SetupElite>b__22_6(float shieldAmount, CharacterModel self)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				if (self.myEliteIndex == AffixBlightedElite.eliteIndex)
				{
					return 0f;
				}
				return shieldAmount;
			}
		}

		public static Color AffixBlightedColor = new Color(0.1f, 0.1f, 0.1f);

		public static Color AffixBlightedLightColor = new Color(31f / 85f, 6f / 85f, 0.05490196f);

		public static EquipmentDef AffixBlightedEquipment;

		public static BuffDef AffixBlightedBuff;

		public static EliteDef AffixBlightedElite;

		public static float healthMult = 12f;

		public static float damageMult = 4f;

		public static float affixDropChance = 0.00025f;

		public static bool allowT2Affixes = false;

		public static AssetBundle assetBundle;

		public static PluginInfo pluginInfo;

		private bool allowTwisted;

		private bool allowGold;

		private static EliteDef malachiteDef = Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/Base/ElitePoison/edPoison.asset").WaitForCompletion();

		private static EliteDef celestineDef = Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/Base/EliteHaunted/edHaunted.asset").WaitForCompletion();

		private void ReadConfig()
		{
			healthMult = ((BaseUnityPlugin)this).Config.Bind<float>("Stats", "Health Multiplier", 12f, "Elite HP Multiplier. Malachite is 18.").Value;
			damageMult = ((BaseUnityPlugin)this).Config.Bind<float>("Stats", "Damage Multiplier", 4f, "Elite damage Multiplier. Malachite is 6.").Value;
			affixDropChance = ((BaseUnityPlugin)this).Config.Bind<float>("Stats", "Affix Drop Chance", 0.025f, "Chance to drop affix on death. Max is 100 (guaranteed drop).").Value;
			allowT2Affixes = ((BaseUnityPlugin)this).Config.Bind<bool>("Stats", "Allow T2 Affixes", false, "Blighted Elites can use T2 affixes like Celestine and Malachite.").Value;
			allowGold = ((BaseUnityPlugin)this).Config.Bind<bool>("Elites", "Allow Gilded", false, "Add Gilded elites to the T1 affix list.").Value;
			allowTwisted = ((BaseUnityPlugin)this).Config.Bind<bool>("Elites", "Allow Twisted", false, "Add Twisted elites to the T2 affix list.").Value;
		}

		public void Awake()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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)
			ContentManager.collectContentPackProviders += new CollectContentPackProvidersDelegate(ContentManager_collectContentPackProviders);
			pluginInfo = ((BaseUnityPlugin)this).Info;
			new LanguageTokens();
			SetupAssetBundle();
			ReadConfig();
			if (allowTwisted)
			{
				AffixBlightedComponent.tier2Affixes.Add(Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/DLC2/Elites/EliteBead/edBead.asset").WaitForCompletion());
			}
			if (allowGold)
			{
				AffixBlightedComponent.tier1Affixes.Add(Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/DLC2/Elites/EliteAurelionite/edAurelionite.asset").WaitForCompletion());
			}
			SetupBuff();
			SetupEquipment();
			SetupElite();
		}

		private void ContentManager_collectContentPackProviders(AddContentPackProviderDelegate addContentPackProvider)
		{
			addContentPackProvider.Invoke((IContentPackProvider)(object)new BlightedElitesContentPack());
		}

		private void SetupAssetBundle()
		{
			using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("BlightedElites.blightedelitebundle"))
			{
				assetBundle = AssetBundle.LoadFromStream(stream);
			}
			using Stream stream2 = Assembly.GetExecutingAssembly().GetManifestResourceStream("BlightedElites.BlightedElitesSoundbank.bnk");
			byte[] array = new byte[stream2.Length];
			stream2.Read(array, 0, array.Length);
			SoundBanks.Add(array);
		}

		private void SetupBuff()
		{
			//IL_0042: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Expected O, but got Unknown
			//IL_00de: 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_00e9: Expected O, but got Unknown
			AffixBlightedBuff = ScriptableObject.CreateInstance<BuffDef>();
			((Object)AffixBlightedBuff).name = ((Object)this).name;
			AffixBlightedBuff.canStack = false;
			AffixBlightedBuff.isCooldown = false;
			AffixBlightedBuff.isDebuff = false;
			AffixBlightedBuff.buffColor = AffixBlightedColor;
			AffixBlightedBuff.iconSprite = assetBundle.LoadAsset<Sprite>("texIconBuffAffixBlight.png");
			((Object)AffixBlightedBuff).name = ((Object)AffixBlightedBuff).name;
			object obj = <>c.<>9__17_0;
			if (obj == null)
			{
				hook_GetSubtitle val = (orig_GetSubtitle orig, CharacterBody self) => (Object.op_Implicit((Object)(object)self.equipmentSlot) && self.equipmentSlot.equipmentIndex == AffixBlightedEquipment.equipmentIndex) ? Language.GetString("ELITE_MODIFIER_BLIGHTED_MOFFEIN_SUBTITLENAMETOKEN") : orig.Invoke(self);
				<>c.<>9__17_0 = val;
				obj = (object)val;
			}
			CharacterBody.GetSubtitle += (hook_GetSubtitle)obj;
			CharacterBody.OnClientBuffsChanged += new hook_OnClientBuffsChanged(UpdateBlightedBuff);
			AffixBlightedComponent.rerollSound = ScriptableObject.CreateInstance<NetworkSoundEventDef>();
			AffixBlightedComponent.rerollSound.eventName = "Play_MoffeinBlighted_Spawn";
			object obj2 = <>c.<>9__17_1;
			if (obj2 == null)
			{
				Manipulator val2 = delegate(ILContext il)
				{
					//IL_0002: Unknown result type (might be due to invalid IL or missing references)
					//IL_0008: Expected O, but got Unknown
					//IL_0039: Unknown result type (might be due to invalid IL or missing references)
					//IL_0046: Unknown result type (might be due to invalid IL or missing references)
					ILCursor val3 = new ILCursor(il);
					val3 = val3.GotoNext((MoveType)2, new Func<Instruction, bool>[1]
					{
						(Instruction x) => ILPatternMatchingExt.MatchCallvirt<CharacterBody>(x, "HasBuff")
					});
					val3.Emit(OpCodes.Ldloc, 6);
					val3.Emit(OpCodes.Ldloc_0);
					val3.EmitDelegate<Func<bool, BuffIndex, CharacterBody, bool>>((Func<bool, BuffIndex, CharacterBody, bool>)delegate(bool hasBuff, BuffIndex buffIndex, CharacterBody cb)
					{
						//IL_0004: Unknown result type (might be due to invalid IL or missing references)
						//IL_000a: Unknown result type (might be due to invalid IL or missing references)
						if (hasBuff && buffIndex != AffixBlightedBuff.buffIndex && cb.HasBuff(AffixBlightedBuff))
						{
							hasBuff = false;
						}
						return hasBuff;
					});
				};
				<>c.<>9__17_1 = val2;
				obj2 = (object)val2;
			}
			Util.GetBestBodyName += (Manipulator)obj2;
		}

		private void SetupEquipment()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: 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_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Expected O, but got Unknown
			AffixBlightedEquipment = ScriptableObject.CreateInstance<EquipmentDef>();
			AffixBlightedEquipment.appearsInMultiPlayer = true;
			AffixBlightedEquipment.appearsInSinglePlayer = true;
			AffixBlightedEquipment.canBeRandomlyTriggered = false;
			AffixBlightedEquipment.canDrop = false;
			AffixBlightedEquipment.colorIndex = (ColorIndex)5;
			AffixBlightedEquipment.cooldown = 45f;
			AffixBlightedEquipment.isLunar = false;
			AffixBlightedEquipment.isBoss = false;
			AffixBlightedEquipment.passiveBuffDef = AffixBlightedBuff;
			AffixBlightedEquipment.pickupIconSprite = assetBundle.LoadAsset<Sprite>("texIconPickupAffixBlight.png");
			AffixBlightedEquipment.dropOnDeathChance = affixDropChance * 0.01f;
			AffixBlightedEquipment.enigmaCompatible = false;
			AffixBlightedEquipment.pickupModelPrefab = PrefabAPI.InstantiateClone(Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/EliteFire/PickupEliteFire.prefab").WaitForCompletion(), "PickupAffixBlightedMoffein", false);
			Material val = Object.Instantiate<Material>(((Renderer)AffixBlightedEquipment.pickupModelPrefab.GetComponentInChildren<MeshRenderer>()).material);
			val.color = Color.black;
			Renderer[] componentsInChildren = AffixBlightedEquipment.pickupModelPrefab.GetComponentsInChildren<Renderer>();
			foreach (Renderer val2 in componentsInChildren)
			{
				val2.material = val;
			}
			AffixBlightedEquipment.pickupToken = "EQUIPMENT_AFFIXBLIGHTED_MOFFEIN_PICKUP";
			AffixBlightedEquipment.descriptionToken = "EQUIPMENT_AFFIXBLIGHTED_MOFFEIN_DESC";
			AffixBlightedEquipment.nameToken = "EQUIPMENT_AFFIXBLIGHTED_MOFFEIN_NAME";
			AffixBlightedEquipment.loreToken = "";
			((Object)AffixBlightedEquipment).name = "AffixBlightedMoffein";
			((Object)AffixBlightedEquipment).name = "AffixBlightedMoffein";
			EquipmentSlot.PerformEquipmentAction += new hook_PerformEquipmentAction(EquipmentSlot_PerformEquipmentAction);
		}

		private bool EquipmentSlot_PerformEquipmentAction(orig_PerformEquipmentAction orig, EquipmentSlot self, EquipmentDef equipmentDef)
		{
			bool flag = orig.Invoke(self, equipmentDef);
			if (!flag && (Object)(object)equipmentDef == (Object)(object)AffixBlightedEquipment)
			{
				CharacterBody characterBody = self.characterBody;
				if (Object.op_Implicit((Object)(object)characterBody) && characterBody.isPlayerControlled && Object.op_Implicit((Object)(object)Run.instance))
				{
					Xoroshiro128Plus spawnRng = Run.instance.spawnRng;
					AffixBlightedComponent component = ((Component)characterBody).GetComponent<AffixBlightedComponent>();
					if (Object.op_Implicit((Object)(object)component))
					{
						component.Reroll(spawnRng);
					}
					else
					{
						component = ((Component)characterBody).gameObject.AddComponent<AffixBlightedComponent>();
						component.characterBody = characterBody;
						component.Activate(spawnRng);
					}
				}
				flag = true;
			}
			return flag;
		}

		private void SetupElite()
		{
			//IL_0010: 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)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: 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_00a9: Expected O, but got Unknown
			//IL_00c3: 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_00ce: Expected O, but got Unknown
			//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
			AffixBlightedElite = ScriptableObject.CreateInstance<EliteDef>();
			AffixBlightedElite.color = Color32.op_Implicit(AffixBlightedColor);
			AffixBlightedElite.eliteEquipmentDef = AffixBlightedEquipment;
			AffixBlightedElite.modifierToken = "ELITE_MODIFIER_BLIGHTED_MOFFEIN";
			((Object)AffixBlightedElite).name = "EliteBlightedMoffein";
			((Object)AffixBlightedElite).name = "EliteBlightedMoffein";
			AffixBlightedElite.healthBoostCoefficient = healthMult;
			AffixBlightedElite.damageBoostCoefficient = damageMult;
			AffixBlightedBuff.eliteDef = AffixBlightedElite;
			object obj = <>c.<>9__22_0;
			if (obj == null)
			{
				hook_Init val = delegate(orig_Init orig)
				{
					orig.Invoke();
					EliteTierDef[] combatDirectorEliteTiers = EliteAPI.GetCombatDirectorEliteTiers();
					foreach (EliteTierDef val6 in combatDirectorEliteTiers)
					{
						if (val6.eliteTypes.Contains(malachiteDef) || val6.eliteTypes.Contains(celestineDef))
						{
							EliteTierDef val7 = val6;
							List<EliteDef> list = val7.eliteTypes.ToList();
							list.Add(AffixBlightedElite);
							val7.eliteTypes = list.ToArray();
							Debug.Log((object)"BlightedElites: Successfully added to tier.");
						}
					}
				};
				<>c.<>9__22_0 = val;
				obj = (object)val;
			}
			CombatDirector.Init += (hook_Init)obj;
			object obj2 = <>c.<>9__22_1;
			if (obj2 == null)
			{
				Manipulator val2 = delegate(ILContext il)
				{
					//IL_0002: Unknown result type (might be due to invalid IL or missing references)
					//IL_0008: Expected O, but got Unknown
					//IL_0047: Unknown result type (might be due to invalid IL or missing references)
					ILCursor val5 = new ILCursor(il);
					val5.GotoNext(new Func<Instruction, bool>[1]
					{
						(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(Items), "InvadingDoppelganger")
					});
					val5.Index += 2;
					val5.Emit(OpCodes.Ldarg_0);
					val5.EmitDelegate<Func<int, CharacterModel, int>>((Func<int, CharacterModel, int>)delegate(int vengeanceCount, CharacterModel self)
					{
						//IL_0002: Unknown result type (might be due to invalid IL or missing references)
						//IL_000c: Unknown result type (might be due to invalid IL or missing references)
						if (self.myEliteIndex == AffixBlightedElite.eliteIndex)
						{
							vengeanceCount++;
						}
						return vengeanceCount;
					});
				};
				<>c.<>9__22_1 = val2;
				obj2 = (object)val2;
			}
			CharacterModel.UpdateOverlays += (Manipulator)obj2;
			object obj3 = <>c.<>9__22_2;
			if (obj3 == null)
			{
				Manipulator val3 = delegate(ILContext il)
				{
					//IL_0002: Unknown result type (might be due to invalid IL or missing references)
					//IL_0008: Expected O, but got Unknown
					//IL_0039: Unknown result type (might be due to invalid IL or missing references)
					ILCursor val4 = new ILCursor(il);
					val4.GotoNext((MoveType)2, new Func<Instruction, bool>[1]
					{
						(Instruction x) => ILPatternMatchingExt.MatchLdfld(x, typeof(HealthComponent), "shield")
					});
					val4.Emit(OpCodes.Ldarg_0);
					val4.EmitDelegate<Func<float, CharacterModel, float>>((Func<float, CharacterModel, float>)((float shieldAmount, CharacterModel self) => (self.myEliteIndex == AffixBlightedElite.eliteIndex) ? 0f : shieldAmount));
				};
				<>c.<>9__22_2 = val3;
				obj3 = (object)val3;
			}
			CharacterModel.UpdateOverlays += (Manipulator)obj3;
		}

		private static void UpdateBlightedBuff(orig_OnClientBuffsChanged orig, CharacterBody self)
		{
			orig.Invoke(self);
			if (NetworkServer.active && self.HasBuff(AffixBlightedBuff))
			{
				AffixBlightedComponent affixBlightedComponent = ((Component)self).GetComponent<AffixBlightedComponent>();
				if (!Object.op_Implicit((Object)(object)affixBlightedComponent))
				{
					affixBlightedComponent = ((Component)self).gameObject.AddComponent<AffixBlightedComponent>();
					affixBlightedComponent.characterBody = self;
				}
				if (Object.op_Implicit((Object)(object)Run.instance))
				{
					affixBlightedComponent.Activate(Run.instance.spawnRng);
				}
			}
		}
	}
	internal class LanguageTokens
	{
		internal static string languageRoot => Path.Combine(assemblyDir, "language");

		internal static string assemblyDir => Path.GetDirectoryName(BlightedElitesPlugin.pluginInfo.Location);

		public LanguageTokens()
		{
			RegisterLanguageTokens();
		}

		public static void RegisterLanguageTokens()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			Language.SetFolders += new hook_SetFolders(fixme);
		}

		private static void fixme(orig_SetFolders orig, Language self, IEnumerable<string> newFolders)
		{
			if (Directory.Exists(languageRoot))
			{
				IEnumerable<string> second = Directory.EnumerateDirectories(Path.Combine(languageRoot), self.name);
				orig.Invoke(self, newFolders.Union(second));
			}
			else
			{
				orig.Invoke(self, newFolders);
			}
		}
	}
}
namespace BlightedElites.Components
{
	public class AffixBlightedComponent : MonoBehaviour
	{
		public static NetworkSoundEventDef rerollSound;

		public static List<EliteDef> tier1Affixes = new List<EliteDef>
		{
			Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/Base/EliteFire/edFire.asset").WaitForCompletion(),
			Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/Base/EliteIce/edIce.asset").WaitForCompletion(),
			Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/Base/EliteLightning/edLightning.asset").WaitForCompletion(),
			Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/DLC1/EliteEarth/edEarth.asset").WaitForCompletion()
		};

		public static List<EliteDef> tier2Affixes = new List<EliteDef>
		{
			Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/Base/EliteHaunted/edHaunted.asset").WaitForCompletion(),
			Addressables.LoadAssetAsync<EliteDef>((object)"RoR2/Base/ElitePoison/edPoison.asset").WaitForCompletion()
		};

		public BuffDef buff1;

		public BuffDef buff2;

		public CharacterBody characterBody;

		public bool active = false;

		public static float soundCooldown = 3f;

		private float soundCooldownStopwatch = 0f;

		public void Reroll(Xoroshiro128Plus rng)
		{
			if (NetworkServer.active)
			{
				Deactivate();
				Activate(rng);
			}
		}

		public void Activate(Xoroshiro128Plus rng)
		{
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active)
			{
				return;
			}
			if (!Object.op_Implicit((Object)(object)characterBody))
			{
				characterBody = ((Component)this).GetComponent<CharacterBody>();
			}
			if (soundCooldownStopwatch > 0f)
			{
				soundCooldownStopwatch -= Time.fixedDeltaTime;
			}
			if (active)
			{
				return;
			}
			buff1 = null;
			buff2 = null;
			EliteDef elite1 = GetRandomElite(tier1Affixes);
			if (BlightedElitesPlugin.allowT2Affixes && Random.Range(0, 6) == 0)
			{
				EliteDef randomElite = GetRandomElite(tier2Affixes);
				if ((Object)(object)randomElite != (Object)null)
				{
					elite1 = randomElite;
				}
			}
			if (Object.op_Implicit((Object)(object)elite1))
			{
				buff1 = GetEliteBuff(elite1);
			}
			EliteDef randomElite2 = GetRandomElite(tier1Affixes.Where((EliteDef ed) => (Object)(object)ed != (Object)(object)elite1).ToList());
			if (Object.op_Implicit((Object)(object)randomElite2))
			{
				buff2 = GetEliteBuff(randomElite2);
			}
			if (Object.op_Implicit((Object)(object)buff1) || Object.op_Implicit((Object)(object)buff2))
			{
				active = true;
				if (Object.op_Implicit((Object)(object)buff1))
				{
					characterBody.AddBuff(buff1);
				}
				if (Object.op_Implicit((Object)(object)buff2))
				{
					characterBody.AddBuff(buff2);
				}
				if (Object.op_Implicit((Object)(object)rerollSound) && soundCooldownStopwatch <= 0f)
				{
					soundCooldownStopwatch = soundCooldown;
					EffectManager.SimpleSoundEffect(rerollSound.index, ((Component)this).transform.position, true);
				}
			}
		}

		public void Deactivate()
		{
			if (NetworkServer.active)
			{
				if (Object.op_Implicit((Object)(object)buff1) && characterBody.HasBuff(buff1))
				{
					characterBody.RemoveBuff(buff1);
				}
				if (Object.op_Implicit((Object)(object)buff2) && characterBody.HasBuff(buff2))
				{
					characterBody.RemoveBuff(buff2);
				}
				buff1 = null;
				buff2 = null;
				active = false;
			}
		}

		public void FixedUpdate()
		{
			if (!Object.op_Implicit((Object)(object)characterBody))
			{
				return;
			}
			if (active)
			{
				if (!characterBody.HasBuff(BlightedElitesPlugin.AffixBlightedBuff))
				{
					Deactivate();
				}
			}
			else if (characterBody.HasBuff(BlightedElitesPlugin.AffixBlightedBuff) && Object.op_Implicit((Object)(object)Run.instance))
			{
				Activate(Run.instance.spawnRng);
			}
		}

		public static BuffDef GetEliteBuff(EliteDef eliteDef)
		{
			if (Object.op_Implicit((Object)(object)eliteDef.eliteEquipmentDef) && Object.op_Implicit((Object)(object)eliteDef.eliteEquipmentDef.passiveBuffDef))
			{
				return eliteDef.eliteEquipmentDef.passiveBuffDef;
			}
			return null;
		}

		public static EliteDef GetRandomElite(List<EliteDef> eliteDefs)
		{
			List<EliteDef> list = eliteDefs.Where((EliteDef ed) => ed.IsAvailable()).ToList();
			if (list.Count <= 0)
			{
				Debug.LogError((object)"BlightedElites: GetRandomElite returned null.");
				return null;
			}
			return list[Random.Range(0, list.Count)];
		}
	}
}