Decompiled source of BlightedElites v1.1.8

plugins/Moffein-BlightedElites/BlightedElites.dll

Decompiled 4 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.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("BlightedElites")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[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.*/)]
	[BepInPlugin("com.Moffein.BlightedElites", "Blighted Elites", "1.1.4")]
	[R2APISubmoduleDependency(new string[] { "PrefabAPI", "EliteAPI", "SoundAPI" })]
	[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__15_0;

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

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

			public static Manipulator <>9__15_1;

			public static hook_Init <>9__18_0;

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

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

			public static Manipulator <>9__18_1;

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

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

			public static Manipulator <>9__18_2;

			internal string <SetupBuff>b__15_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__15_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__15_2(Instruction x)
			{
				return ILPatternMatchingExt.MatchCallvirt<CharacterBody>(x, "HasBuff");
			}

			internal bool <SetupBuff>b__15_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__18_0(orig_Init orig)
			{
				orig.Invoke();
				if (EliteAPI.VanillaEliteTiers.Length > 3)
				{
					EliteTierDef val = EliteAPI.VanillaEliteTiers[3];
					List<EliteDef> list = val.eliteTypes.ToList();
					list.Add(AffixBlightedElite);
					val.eliteTypes = list.ToArray();
				}
			}

			internal void <SetupElite>b__18_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__18_3(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdsfld(x, typeof(Items), "InvadingDoppelganger");
			}

			internal int <SetupElite>b__18_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__18_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__18_5(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdfld(x, typeof(HealthComponent), "shield");
			}

			internal float <SetupElite>b__18_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 = 3.5f;

		public static float affixDropChance = 0.00025f;

		public static bool allowT2Affixes = false;

		public static AssetBundle assetBundle;

		public static PluginInfo pluginInfo;

		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", 3.5f, "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;
		}

		public void Awake()
		{
			//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(ContentManager_collectContentPackProviders);
			pluginInfo = ((BaseUnityPlugin)this).Info;
			new LanguageTokens();
			SetupAssetBundle();
			ReadConfig();
			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__15_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__15_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__15_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__15_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_00e5: 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_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: 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;
			Debug.Log((object)("Drop Chance: " + Addressables.LoadAssetAsync<EquipmentDef>((object)"RoR2/Base/EliteFire/EliteFireEquipment.asset").WaitForCompletion().dropOnDeathChance));
			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__18_0;
			if (obj == null)
			{
				hook_Init val = delegate(orig_Init orig)
				{
					orig.Invoke();
					if (EliteAPI.VanillaEliteTiers.Length > 3)
					{
						EliteTierDef val6 = EliteAPI.VanillaEliteTiers[3];
						List<EliteDef> list = val6.eliteTypes.ToList();
						list.Add(AffixBlightedElite);
						val6.eliteTypes = list.ToArray();
					}
				};
				<>c.<>9__18_0 = val;
				obj = (object)val;
			}
			CombatDirector.Init += (hook_Init)obj;
			object obj2 = <>c.<>9__18_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__18_1 = val2;
				obj2 = (object)val2;
			}
			CharacterModel.UpdateOverlays += (Manipulator)obj2;
			object obj3 = <>c.<>9__18_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__18_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 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_0377: Unknown result type (might be due to invalid IL or missing references)
			//IL_0382: 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;
			if (!BlightedElitesPlugin.allowT2Affixes || EliteAPI.VanillaEliteTiers.Length <= 3)
			{
				EliteTierDef vanillaFirstTierDef = EliteAPI.VanillaFirstTierDef;
				if (vanillaFirstTierDef != null && vanillaFirstTierDef.HasAnyAvailableEliteDefs())
				{
					EliteDef randomAvailableEliteDef = vanillaFirstTierDef.GetRandomAvailableEliteDef(rng);
					if (Object.op_Implicit((Object)(object)randomAvailableEliteDef) && Object.op_Implicit((Object)(object)randomAvailableEliteDef.eliteEquipmentDef) && Object.op_Implicit((Object)(object)randomAvailableEliteDef.eliteEquipmentDef.passiveBuffDef))
					{
						buff1 = randomAvailableEliteDef.eliteEquipmentDef.passiveBuffDef;
					}
					if (vanillaFirstTierDef.availableDefs.Count > 1)
					{
						List<EliteDef> list = new List<EliteDef>(vanillaFirstTierDef.availableDefs);
						list.Remove(randomAvailableEliteDef);
						int index = rng.RangeInt(0, list.Count);
						EliteDef val = list[index];
						if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.eliteEquipmentDef) && Object.op_Implicit((Object)(object)val.eliteEquipmentDef.passiveBuffDef))
						{
							buff2 = val.eliteEquipmentDef.passiveBuffDef;
						}
					}
				}
			}
			else
			{
				EliteTierDef vanillaFirstTierDef2 = EliteAPI.VanillaFirstTierDef;
				EliteTierDef val2 = EliteAPI.VanillaEliteTiers[3];
				List<EliteDef> list2 = new List<EliteDef>(vanillaFirstTierDef2.availableDefs);
				list2.AddRange(new List<EliteDef>(val2.availableDefs));
				list2.Remove(BlightedElitesPlugin.AffixBlightedElite);
				EliteDef val3 = null;
				EliteDef val4 = null;
				if (list2.Count > 0)
				{
					int index2 = rng.RangeInt(0, list2.Count);
					val3 = list2[index2];
					if (Object.op_Implicit((Object)(object)val3) && Object.op_Implicit((Object)(object)val3.eliteEquipmentDef) && Object.op_Implicit((Object)(object)val3.eliteEquipmentDef.passiveBuffDef))
					{
						buff1 = val3.eliteEquipmentDef.passiveBuffDef;
					}
					list2.Remove(val3);
					if (list2.Count > 0)
					{
						index2 = rng.RangeInt(0, list2.Count);
						val4 = list2[index2];
						if (Object.op_Implicit((Object)(object)val4) && Object.op_Implicit((Object)(object)val4.eliteEquipmentDef) && Object.op_Implicit((Object)(object)val4.eliteEquipmentDef.passiveBuffDef))
						{
							buff2 = val4.eliteEquipmentDef.passiveBuffDef;
						}
					}
				}
			}
			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);
			}
		}
	}
}