Decompiled source of GlacialPerforator v0.1.5

plugins/GlacialPerforator/GlacialPerforator.dll

Decompiled 15 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using HG.Reflection;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using R2API;
using R2API.Utils;
using RoR2;
using RoR2.Orbs;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: OptIn]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 GlacialPerforator
{
	internal static class Balance
	{
		internal const float Chance = 10f;

		internal const float DamagePerStack = 6f;

		internal const float Radius = 6f;

		internal const float SlowDuration = 3f;

		internal const float Delay = 0.35f;

		internal const float ProcCoefficient = 0.7f;

		internal const float WormDelay = 0.9f;

		internal const float WormRadius = 13f;

		internal static bool PositiveFinite(float x)
		{
			if (x > 0f && !float.IsInfinity(x))
			{
				return !float.IsNaN(x);
			}
			return false;
		}

		internal static float RollChance(float coefficient)
		{
			if (!PositiveFinite(coefficient))
			{
				return 0f;
			}
			return Math.Min(100f, 10f * coefficient);
		}

		internal static float Damage(float hit, int count)
		{
			if (!PositiveFinite(hit) || count <= 0)
			{
				return 0f;
			}
			double num = (double)hit * 6.0 * (double)count;
			if (!(num <= 3.4028234663852886E+38))
			{
				return 0f;
			}
			return (float)num;
		}
	}
	internal static class Combat
	{
		internal static void OnDamage(DamageReport report)
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_00ac: Invalid comparison between Unknown and I4
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: 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_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: 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_013b: 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)
			if (!NetworkServer.active || report?.damageInfo == null || !Object.op_Implicit((Object)(object)Plugin.Item) || !Object.op_Implicit((Object)(object)OrbManager.instance))
			{
				return;
			}
			DamageInfo damageInfo = report.damageInfo;
			CharacterBody attackerBody = report.attackerBody;
			if (Object.op_Implicit((Object)(object)attackerBody) && Object.op_Implicit((Object)(object)attackerBody.inventory) && Object.op_Implicit((Object)(object)report.victim) && Object.op_Implicit((Object)(object)report.victimBody) && !((Object)(object)attackerBody == (Object)(object)report.victimBody) && report.attackerTeamIndex != report.victimTeamIndex && (int)report.victimTeamIndex != 0 && !damageInfo.rejected && !damageInfo.delayedDamageSecondHalf && (int)damageInfo.dotIndex == -1 && Balance.PositiveFinite(report.damageDealt) && Balance.PositiveFinite(damageInfo.procCoefficient) && !ProcTypeAPI.HasModdedProc(damageInfo.procChainMask, Plugin.Proc))
			{
				int itemCountEffective = attackerBody.inventory.GetItemCountEffective(Plugin.Item);
				float num = Balance.Damage(damageInfo.damage, itemCountEffective);
				if (!(num <= 0f) && Util.CheckRoll(Balance.RollChance(damageInfo.procCoefficient), attackerBody.master))
				{
					ProcChainMask procChainMask = damageInfo.procChainMask;
					ProcTypeAPI.AddModdedProc(ref procChainMask, Plugin.Proc);
					Queue(((Component)attackerBody).gameObject, report.attackerTeamIndex, damageInfo.position, num, damageInfo.crit, procChainMask, 6f, 0.35f, 0.7f, worm: false);
					Plugin.Trace("Perforator proc: " + ((Object)attackerBody).name + ", stacks=" + itemCountEffective + ", damage=" + num);
				}
			}
		}

		internal static void Queue(GameObject attacker, TeamIndex team, Vector3 position, float damage, bool crit, ProcChainMask mask, float radius, float delay, float coefficient, bool worm)
		{
			//IL_0027: 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_0035: 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_004b: 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 (NetworkServer.active && Object.op_Implicit((Object)(object)OrbManager.instance) && Balance.PositiveFinite(damage))
			{
				OrbManager.instance.AddOrb((Orb)(object)new FrostBurstOrb
				{
					origin = position,
					attacker = attacker,
					team = team,
					damage = damage,
					crit = crit,
					mask = mask,
					radius = radius,
					delay = delay,
					coefficient = coefficient,
					worm = worm
				});
			}
		}
	}
	internal sealed class FrostBurstOrb : Orb
	{
		internal GameObject attacker;

		internal TeamIndex team;

		internal float damage;

		internal float radius;

		internal float delay;

		internal float coefficient;

		internal bool crit;

		internal bool worm;

		internal ProcChainMask mask;

		private bool fired;

		public override void Begin()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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_004a: Expected O, but got Unknown
			((Orb)this).duration = delay;
			if (NetworkServer.active)
			{
				EffectManager.SpawnEffect(worm ? Effects.WormWarning : Effects.ItemWarning, new EffectData
				{
					origin = base.origin,
					scale = radius
				}, true);
			}
		}

		public override void OnArrival()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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_004d: Expected O, but got Unknown
			//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_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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_00b1: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: 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_00e3: 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_00ef: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: 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_0124: Unknown result type (might be due to invalid IL or missing references)
			if (fired || !NetworkServer.active)
			{
				return;
			}
			fired = true;
			if (!Object.op_Implicit((Object)(object)attacker))
			{
				return;
			}
			EffectManager.SpawnEffect(Effects.Burst, new EffectData
			{
				origin = base.origin,
				scale = radius
			}, true);
			Result val = new BlastAttack
			{
				attacker = attacker,
				inflictor = attacker,
				teamIndex = team,
				position = base.origin,
				baseDamage = damage,
				crit = crit,
				radius = radius,
				baseForce = 0f,
				procCoefficient = coefficient,
				procChainMask = mask,
				damageColorIndex = (DamageColorIndex)3,
				damageType = DamageTypeCombo.op_Implicit((DamageType)0),
				falloffModel = (FalloffModel)0,
				attackerFiltering = (AttackerFiltering)2
			}.Fire();
			HashSet<HealthComponent> hashSet = new HashSet<HealthComponent>();
			if (val.hitPoints == null)
			{
				return;
			}
			HitPoint[] hitPoints = val.hitPoints;
			foreach (HitPoint val2 in hitPoints)
			{
				HealthComponent val3 = (Object.op_Implicit((Object)(object)val2.hurtBox) ? val2.hurtBox.healthComponent : null);
				if (Object.op_Implicit((Object)(object)val3) && val3.alive && Object.op_Implicit((Object)(object)val3.body) && hashSet.Add(val3))
				{
					val3.body.AddTimedBuff(Buffs.Slow80, 3f);
				}
			}
		}
	}
	internal static class Crafting
	{
		internal static CraftableDef Definition;

		internal static void Register()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			Definition = ScriptableObject.CreateInstance<CraftableDef>();
			((Object)Definition).name = "CraftableGlacialPerforator";
			Definition.pickup = (Object)(object)Plugin.Item;
			CraftableDef definition = Definition;
			Recipe[] array = new Recipe[1];
			Recipe val = new Recipe();
			val.amountToDrop = 1;
			val.ingredients = (RecipeIngredient[])(object)new RecipeIngredient[2]
			{
				Ingredient("RoR2/Base/ElementalRings/IceRing.asset"),
				Ingredient("RoR2/Base/Missile/Missile.asset")
			};
			array[0] = val;
			definition.recipes = (Recipe[])(object)array;
			if (!ContentAddition.AddCraftableDef(Definition))
			{
				throw new InvalidOperationException("Glacial Perforator recipe registration failed.");
			}
		}

		private static RecipeIngredient Ingredient(string address)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: 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_000c: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			return new RecipeIngredient
			{
				type = (IngredientTypeIndex)0,
				pickup = (Object)(object)Visuals.Load<ItemDef>((object)address),
				requiredTags = Array.Empty<ItemTag>(),
				forbiddenTags = Array.Empty<ItemTag>()
			};
		}
	}
	internal static class Effects
	{
		internal static GameObject ItemWarning;

		internal static GameObject WormWarning;

		internal static GameObject Burst;

		internal static void Register()
		{
			ItemWarning = Warning("GlacialPerforatorWarning", 0.35f);
			WormWarning = Warning("GlacialWormWarning", 0.9f);
			Burst = PrefabAPI.InstantiateClone(Visuals.Load<GameObject>((object)"RoR2/Base/EliteIce/AffixWhiteExplosion.prefab"), "GlacialIceShardBurst", false);
			Setup(Burst, 2f);
		}

		private static GameObject Warning(string name, float time)
		{
			GameObject val = PrefabAPI.InstantiateClone(Visuals.Load<GameObject>((object)"RoR2/Base/EliteIce/AffixWhiteDelayEffect.prefab"), name, false);
			AkEvent[] componentsInChildren = val.GetComponentsInChildren<AkEvent>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
			}
			RTPCController[] componentsInChildren2 = val.GetComponentsInChildren<RTPCController>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren2[i]);
			}
			ObjectScaleCurve[] componentsInChildren3 = val.GetComponentsInChildren<ObjectScaleCurve>(true);
			for (int i = 0; i < componentsInChildren3.Length; i++)
			{
				componentsInChildren3[i].timeMax = time;
			}
			EffectComponent component = val.GetComponent<EffectComponent>();
			component.positionAtReferencedTransform = false;
			component.parentToReferencedTransform = false;
			component.soundName = "";
			Setup(val, time);
			return val;
		}

		private static void Setup(GameObject obj, float time)
		{
			(obj.GetComponent<EffectComponent>() ?? obj.AddComponent<EffectComponent>()).applyScale = true;
			(obj.GetComponent<DestroyOnTimer>() ?? obj.AddComponent<DestroyOnTimer>()).duration = time;
			(obj.GetComponent<VFXAttributes>() ?? obj.AddComponent<VFXAttributes>()).DoNotPool = true;
			if (!ContentAddition.AddEffect(obj))
			{
				throw new InvalidOperationException("Effect registration failed: " + ((Object)obj).name);
			}
		}
	}
	public sealed class GlacialDropTable : PickupDropTable
	{
		private PickupIndex Pickup
		{
			get
			{
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Invalid comparison between Unknown and I4
				//IL_0024: 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)
				if (!Object.op_Implicit((Object)(object)Plugin.Item) || (int)Plugin.Item.itemIndex == -1)
				{
					return PickupIndex.none;
				}
				return PickupCatalog.FindPickupIndex(Plugin.Item.itemIndex);
			}
		}

		public override int GetPickupCount()
		{
			//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)
			return (!(Pickup == PickupIndex.none)) ? 1 : 0;
		}

		protected override UniquePickup GeneratePickupPreReplacement(Xoroshiro128Plus rng)
		{
			//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)
			return new UniquePickup(Pickup);
		}

		protected override void GenerateDistinctPickupsPreReplacement(List<UniquePickup> output, int count, Xoroshiro128Plus rng)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if (count > 0 && ((PickupDropTable)this).GetPickupCount() > 0)
			{
				output.Add(new UniquePickup(Pickup));
			}
		}
	}
	[BepInPlugin("wreckzog.glacialperforator", "Glacial Perforator", "0.1.5")]
	[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.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "wreckzog.glacialperforator";

		public const string Version = "0.1.5";

		internal static Plugin Instance;

		internal static ItemDef Item;

		internal static ItemDef SourceItem;

		internal static ModdedProcType Proc;

		internal static ConfigEntry<bool> LogProcs;

		private Harmony harmony;

		private void Awake()
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Expected O, but got Unknown
			Instance = this;
			LogProcs = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "LogActivations", false, "Log item procs and worm frost attacks.");
			bool value = ((BaseUnityPlugin)this).Config.Bind<bool>("Worm", "EnableNaturalSpawns", true, "Add Glacial Worms to normal pools that already contain Overloading Worms. Restart required.").Value;
			int value2 = ((BaseUnityPlugin)this).Config.Bind<int>("Worm", "RallypointDeltaWeightMultiplier", 3, new ConfigDescription("Glacial Worm selection weight multiplier on Rallypoint Delta. 1 restores the normal weight. Existing stage and director-credit requirements still apply. Restart required.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 10), Array.Empty<object>())).Value;
			Proc = ProcTypeAPI.ReserveProcType();
			Effects.Register();
			SourceItem = Visuals.Load<ItemDef>((object)"RoR2/Base/LightningStrikeOnHit/LightningStrikeOnHit.asset");
			Item = ScriptableObject.CreateInstance<ItemDef>();
			((Object)Item).name = "GlacialPerforator";
			Item.nameToken = "GLACIAL_PERFORATOR_NAME";
			Item.pickupToken = "GLACIAL_PERFORATOR_PICKUP";
			Item.descriptionToken = "GLACIAL_PERFORATOR_DESCRIPTION";
			Item.loreToken = "GLACIAL_PERFORATOR_LORE";
			FieldInfo? field = typeof(ItemDef).GetField("_itemTierDef", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field == null)
			{
				throw new MissingFieldException("ItemDef._itemTierDef");
			}
			field.SetValue(Item, Visuals.Load<ItemTierDef>((object)"RoR2/Base/Common/BossTierDef.asset"));
			Item.canRemove = true;
			Item.tags = (ItemTag[])(object)new ItemTag[2]
			{
				(ItemTag)1,
				(ItemTag)3
			};
			Item.pickupIconSprite = Visuals.FrostIcon(Visuals.Load<Sprite>(((AssetReference)SourceItem.pickupIconSpriteReference).RuntimeKey));
			Item.pickupModelPrefab = Visuals.FrostPrefab(Visuals.Load<GameObject>(((AssetReference)SourceItem.pickupModelReference).RuntimeKey), "PickupGlacialPerforator");
			if (!ContentAddition.AddItemDef(Item))
			{
				throw new InvalidOperationException("Item registration failed.");
			}
			LanguageAPI.Add(Item.nameToken, "Glacial Perforator");
			LanguageAPI.Add(Item.pickupToken, "Chance on hit to erupt ice shards, damaging and slowing nearby enemies.");
			LanguageAPI.Add(Item.descriptionToken, "<style=cIsDamage>10%</style> chance on hit to erupt ice shards after <style=cIsUtility>0.35 seconds</style>, dealing <style=cIsDamage>600%</style> <style=cStack>(+600% per stack)</style> TOTAL damage within <style=cIsDamage>6m</style> and <style=cIsUtility>slowing</style> enemies by <style=cIsUtility>80%</style> for <style=cIsUtility>3 seconds</style>.");
			LanguageAPI.Add(Item.loreToken, "The tooth never thawed.\n\nWe wrapped it in cloth, then sealed it in steel. By morning the hinges had frozen solid. Beneath our camp, something enormous shifted in its sleep.");
			Crafting.Register();
			Worm.Register(value, value2);
			harmony = new Harmony("wreckzog.glacialperforator");
			harmony.PatchAll(typeof(Plugin).Assembly);
			GlobalEventManager.onServerDamageDealt += Combat.OnDamage;
			RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(Verify));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Glacial Perforator loaded; native Perforator geometry, white/cyan recolor, dedicated Glacial Worm.");
		}

		private void Verify()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Invalid comparison between Unknown and I4
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Invalid comparison between Unknown and I4
			//IL_002c: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_0054: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((int)Item.itemIndex == -1 || (int)Item.tier != 4 || (int)BodyCatalog.FindBodyIndex("GlacialWormBody") == -1 || MasterCatalog.FindMasterIndex("GlacialWormMaster") == MasterIndex.none)
				{
					throw new InvalidOperationException("Item or worm catalog registration failed.");
				}
				if (((PickupDropTable)Worm.DropTable).GeneratePickup(new Xoroshiro128Plus(1uL)).pickupIndex != PickupCatalog.FindPickupIndex(Item.itemIndex))
				{
					throw new InvalidOperationException("Worm boss drop table does not resolve Glacial Perforator.");
				}
				int num = Visuals.AddDisplays();
				((BaseUnityPlugin)this).Logger.LogInfo((object)("CATALOG CHECK PASSED: yellow item, worm body/master, boss drop, and " + num + " worn display rule sets."));
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("GLACIAL VALIDATION FAILED: " + ex));
			}
		}

		internal static void Trace(string text)
		{
			if (LogProcs.Value)
			{
				((BaseUnityPlugin)Instance).Logger.LogInfo((object)text);
			}
		}

		internal static void Warn(string text)
		{
			((BaseUnityPlugin)Instance).Logger.LogWarning((object)text);
		}

		private void OnDestroy()
		{
			GlobalEventManager.onServerDamageDealt -= Combat.OnDamage;
			RoR2Application.onLoad = (Action)Delegate.Remove(RoR2Application.onLoad, new Action(Verify));
			Worm.Unregister();
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}
	}
	internal static class TestCommands
	{
		[ConCommand(/*Could not decode attribute arguments.*/)]
		private static void Spawn(ConCommandArgs args)
		{
			//IL_0073: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//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_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: 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_015d: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active || !Object.op_Implicit((Object)(object)Run.instance))
			{
				Debug.Log((object)"glacial_spawn: start a single-player run or host a multiplayer run first.");
				return;
			}
			CharacterBody senderBody = ((ConCommandArgs)(ref args)).senderBody;
			if (!Object.op_Implicit((Object)(object)senderBody) || !Object.op_Implicit((Object)(object)senderBody.healthComponent) || !senderBody.healthComponent.alive)
			{
				Debug.Log((object)"glacial_spawn: you must be alive in the run.");
				return;
			}
			Vector3 val = Vector3.ProjectOnPlane(Object.op_Implicit((Object)(object)senderBody.inputBank) ? senderBody.inputBank.aimDirection : ((Component)senderBody).transform.forward, Vector3.up);
			Vector3 val2 = ((Vector3)(ref val)).normalized;
			if (((Vector3)(ref val2)).sqrMagnitude < 0.01f)
			{
				val2 = Vector3.forward;
			}
			Vector3 val3 = senderBody.footPosition + val2 * 35f;
			Vector3 val4 = val3 + Vector3.up * 100f;
			Vector3 down = Vector3.down;
			LayerIndex world = LayerIndex.world;
			RaycastHit val5 = default(RaycastHit);
			if (Physics.Raycast(val4, down, ref val5, 300f, LayerMask.op_Implicit(((LayerIndex)(ref world)).mask), (QueryTriggerInteraction)1))
			{
				val3 = ((RaycastHit)(ref val5)).point + Vector3.up * 2f;
				Debug.Log((object)(Object.op_Implicit((Object)(object)new MasterSummon
				{
					masterPrefab = Worm.Master,
					position = val3,
					rotation = Quaternion.identity,
					teamIndexOverride = (TeamIndex)2,
					useAmbientLevel = true,
					ignoreTeamMemberLimit = true,
					summonerBodyObject = null
				}.Perform()) ? "Glacial Worm spawned ahead. This test spawn is not a teleporter encounter; use Tricorn to test its boss item." : "glacial_spawn: summon failed; check the BepInEx log."));
			}
			else
			{
				Debug.Log((object)"glacial_spawn: no terrain ahead. Face an open area of the stage and try again.");
			}
		}
	}
	internal static class Visuals
	{
		private static readonly Dictionary<Texture, Texture2D> textures = new Dictionary<Texture, Texture2D>();

		private static readonly Dictionary<Texture, Texture2D> iconTextures = new Dictionary<Texture, Texture2D>();

		private static readonly Dictionary<Texture, Texture2D> wormTextures = new Dictionary<Texture, Texture2D>();

		private static readonly Dictionary<Material, Material> materials = new Dictionary<Material, Material>();

		private static readonly Dictionary<Material, Material> wormMaterials = new Dictionary<Material, Material>();

		private static readonly Dictionary<GameObject, GameObject> displays = new Dictionary<GameObject, GameObject>();

		internal static readonly Color Ice = new Color(0.78f, 0.92f, 1f, 1f);

		internal static T Load<T>(object key) where T : Object
		{
			//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)
			T val = Addressables.LoadAssetAsync<T>(key).WaitForCompletion();
			if (!Object.op_Implicit((Object)(object)val))
			{
				throw new InvalidOperationException("Missing native asset: " + key);
			}
			return val;
		}

		internal static Texture2D FrostTexture(Texture source, bool preserveBossOutline = false, bool wormAlbedo = false)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Invalid comparison between Unknown and I4
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_00af: Expected O, but got Unknown
			//IL_00c9: 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_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: 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_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: 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_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: 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_01cc: 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_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: 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)
			if (!Object.op_Implicit((Object)(object)source))
			{
				return null;
			}
			Dictionary<Texture, Texture2D> dictionary = (preserveBossOutline ? iconTextures : (wormAlbedo ? wormTextures : textures));
			if (dictionary.TryGetValue(source, out var value))
			{
				return value;
			}
			if ((int)SystemInfo.graphicsDeviceType == 4)
			{
				return (Texture2D)(object)((source is Texture2D) ? source : null);
			}
			RenderTexture active = RenderTexture.active;
			RenderTexture temporary = RenderTexture.GetTemporary(source.width, source.height, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)2);
			Texture2D val = null;
			try
			{
				Graphics.Blit(source, temporary);
				RenderTexture.active = temporary;
				val = new Texture2D(source.width, source.height, (TextureFormat)4, true, false)
				{
					name = "Glacial_" + ((Object)source).name,
					filterMode = source.filterMode,
					wrapMode = source.wrapMode
				};
				val.ReadPixels(new Rect(0f, 0f, (float)source.width, (float)source.height), 0, 0);
				Color32[] pixels = val.GetPixels32();
				for (int i = 0; i < pixels.Length; i++)
				{
					Color32 val2 = pixels[i];
					if (!preserveBossOutline || Mathf.Min((int)val2.r, (int)val2.g) - val2.b <= 12 || !((float)(int)val2.r > (float)(int)val2.g * 0.65f) || !((float)(int)val2.g > (float)(int)val2.r * 0.65f))
					{
						float num = Mathf.Pow((float)Mathf.Max((int)val2.r, Mathf.Max((int)val2.g, (int)val2.b)) / 255f, 0.72f);
						if (wormAlbedo)
						{
							Color val3 = Color.Lerp(new Color(0.38f, 0.55f, 0.64f), new Color(0.94f, 0.98f, 1f), num);
							val3.a = (float)(int)val2.a / 255f;
							pixels[i] = Color32.op_Implicit(val3);
						}
						else
						{
							pixels[i] = Color32.op_Implicit(new Color(num * (0.82f + 0.18f * num), num * (0.94f + 0.06f * num), num, (float)(int)val2.a / 255f));
						}
					}
				}
				val.SetPixels32(pixels);
				val.Apply(true, false);
				dictionary.Add(source, val);
				return val;
			}
			catch
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					Object.Destroy((Object)(object)val);
				}
				throw;
			}
			finally
			{
				RenderTexture.active = active;
				RenderTexture.ReleaseTemporary(temporary);
			}
		}

		internal static Sprite FrostIcon(Sprite source)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)source))
			{
				throw new InvalidOperationException("Native Perforator icon missing.");
			}
			Texture2D obj = FrostTexture((Texture)(object)source.texture, preserveBossOutline: true);
			Rect rect = source.rect;
			float x = source.pivot.x;
			Rect rect2 = source.rect;
			float num = x / ((Rect)(ref rect2)).width;
			float y = source.pivot.y;
			rect2 = source.rect;
			Sprite obj2 = Sprite.Create(obj, rect, new Vector2(num, y / ((Rect)(ref rect2)).height), source.pixelsPerUnit);
			((Object)obj2).name = "Glacial_" + ((Object)source).name;
			return obj2;
		}

		internal static Material FrostMaterial(Material source)
		{
			//IL_0031: 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_004d: Expected O, but got Unknown
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: 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_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)source))
			{
				return null;
			}
			if (((Object)source).name.StartsWith("Glacial_", StringComparison.Ordinal))
			{
				return source;
			}
			if (materials.TryGetValue(source, out var value))
			{
				return value;
			}
			Material val = new Material(source)
			{
				name = "Glacial_" + ((Object)source).name
			};
			string[] array = new string[4] { "_MainTex", "_EmTex", "_EmissionMap", "_RemapTex" };
			foreach (string text in array)
			{
				if (val.HasProperty(text) && Object.op_Implicit((Object)(object)val.GetTexture(text)))
				{
					val.SetTexture(text, (Texture)(object)FrostTexture(val.GetTexture(text)));
				}
			}
			array = new string[4] { "_Color", "_TintColor", "_EmColor", "_EmissionColor" };
			foreach (string text2 in array)
			{
				if (val.HasProperty(text2))
				{
					Color color = val.GetColor(text2);
					float num = Mathf.Max(color.r, Mathf.Max(color.g, color.b));
					val.SetColor(text2, new Color(Ice.r * num, Ice.g * num, num, color.a));
				}
			}
			materials.Add(source, val);
			return val;
		}

		private static Material FrostWormMaterial(Material source)
		{
			//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_0052: Expected O, but got Unknown
			//IL_0117: 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_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)source))
			{
				return null;
			}
			if (((Object)source).name.StartsWith("GlacialWorm_", StringComparison.Ordinal))
			{
				return source;
			}
			if (wormMaterials.TryGetValue(source, out var value))
			{
				return value;
			}
			Material val = new Material(FrostMaterial(source))
			{
				name = "GlacialWorm_" + ((Object)source).name
			};
			if (source.HasProperty("_MainTex") && Object.op_Implicit((Object)(object)source.GetTexture("_MainTex")))
			{
				val.SetTexture("_MainTex", (Texture)(object)FrostTexture(source.GetTexture("_MainTex"), preserveBossOutline: false, wormAlbedo: true));
			}
			if (source.HasProperty("_FlowHeightRamp") && Object.op_Implicit((Object)(object)source.GetTexture("_FlowHeightRamp")))
			{
				val.SetTexture("_FlowHeightRamp", (Texture)(object)FrostTexture(source.GetTexture("_FlowHeightRamp")));
			}
			if (val.HasProperty("_FlowEmissionStrength"))
			{
				val.SetFloat("_FlowEmissionStrength", 2.2f);
			}
			if (val.HasProperty("_FlowDiffuseStrength"))
			{
				val.SetFloat("_FlowDiffuseStrength", 0.5f);
			}
			if (val.HasProperty("_Color"))
			{
				val.SetColor("_Color", Color.white);
			}
			if (val.HasProperty("_SpecularTint"))
			{
				val.SetColor("_SpecularTint", Ice);
			}
			if (val.HasProperty("_RimTint"))
			{
				val.SetColor("_RimTint", Ice);
			}
			if (val.HasProperty("_EmColor"))
			{
				val.SetColor("_EmColor", new Color(0.72f, 0.93f, 1f));
			}
			if (val.HasProperty("_EmPower"))
			{
				val.SetFloat("_EmPower", Mathf.Min(val.GetFloat("_EmPower"), 1.4f));
			}
			if (val.HasProperty("_Smoothness"))
			{
				val.SetFloat("_Smoothness", 0.65f);
			}
			if (val.HasProperty("_SpecularStrength"))
			{
				val.SetFloat("_SpecularStrength", 0.25f);
			}
			wormMaterials.Add(source, val);
			return val;
		}

		internal static GameObject FrostPrefab(GameObject source, string name)
		{
			if (!Object.op_Implicit((Object)(object)source))
			{
				throw new InvalidOperationException("Native model missing: " + name);
			}
			GameObject obj = PrefabAPI.InstantiateClone(source, name, false);
			FrostModel(obj);
			return obj;
		}

		internal static void FrostModel(GameObject root, bool wormBody = false)
		{
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Expected O, but got Unknown
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			Renderer[] componentsInChildren = root.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				Material[] sharedMaterials = val.sharedMaterials;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					sharedMaterials[j] = ((wormBody && !(val is ParticleSystemRenderer)) ? FrostWormMaterial(sharedMaterials[j]) : FrostMaterial(sharedMaterials[j]));
				}
				val.sharedMaterials = sharedMaterials;
			}
			CharacterModel[] componentsInChildren2 = root.GetComponentsInChildren<CharacterModel>(true);
			foreach (CharacterModel val2 in componentsInChildren2)
			{
				if (val2.baseRendererInfos == null)
				{
					continue;
				}
				RendererInfo[] array = (RendererInfo[])val2.baseRendererInfos.Clone();
				for (int k = 0; k < array.Length; k++)
				{
					Material val3 = array[k].defaultMaterial;
					if (!Object.op_Implicit((Object)(object)val3) && array[k].defaultMaterialAddress != null && ((AssetReference)array[k].defaultMaterialAddress).RuntimeKeyIsValid())
					{
						val3 = Visuals.Load<Material>(((AssetReference)array[k].defaultMaterialAddress).RuntimeKey);
					}
					array[k].defaultMaterial = ((wormBody && !(array[k].renderer is ParticleSystemRenderer)) ? FrostWormMaterial(val3) : FrostMaterial(val3));
					array[k].defaultMaterialAddress = null;
				}
				val2.baseRendererInfos = array;
				val2.forceUpdate = true;
			}
			ItemDisplay[] componentsInChildren3 = root.GetComponentsInChildren<ItemDisplay>(true);
			foreach (ItemDisplay val4 in componentsInChildren3)
			{
				if (val4.rendererInfos == null)
				{
					continue;
				}
				RendererInfo[] array2 = (RendererInfo[])val4.rendererInfos.Clone();
				for (int l = 0; l < array2.Length; l++)
				{
					Material val5 = array2[l].defaultMaterial;
					if (!Object.op_Implicit((Object)(object)val5) && array2[l].defaultMaterialAddress != null && ((AssetReference)array2[l].defaultMaterialAddress).RuntimeKeyIsValid())
					{
						val5 = Visuals.Load<Material>(((AssetReference)array2[l].defaultMaterialAddress).RuntimeKey);
					}
					array2[l].defaultMaterial = FrostMaterial(val5);
					array2[l].defaultMaterialAddress = null;
				}
				val4.rendererInfos = array2;
				val4.canBeEliteRecolored = false;
			}
			Light[] componentsInChildren4 = root.GetComponentsInChildren<Light>(true);
			for (int i = 0; i < componentsInChildren4.Length; i++)
			{
				componentsInChildren4[i].color = Ice;
			}
			ParticleSystem[] componentsInChildren5 = root.GetComponentsInChildren<ParticleSystem>(true);
			foreach (ParticleSystem obj in componentsInChildren5)
			{
				MainModule main = obj.main;
				((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(Ice);
				ColorOverLifetimeModule colorOverLifetime = obj.colorOverLifetime;
				if (((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled)
				{
					Gradient val6 = new Gradient();
					MinMaxGradient color = ((ColorOverLifetimeModule)(ref colorOverLifetime)).color;
					GradientAlphaKey[] array3 = (GradientAlphaKey[])((((MinMaxGradient)(ref color)).gradient != null) ? ((Array)((MinMaxGradient)(ref color)).gradient.alphaKeys) : ((Array)new GradientAlphaKey[2]
					{
						new GradientAlphaKey(1f, 0f),
						new GradientAlphaKey(0f, 1f)
					}));
					val6.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
					{
						new GradientColorKey(Ice, 0f),
						new GradientColorKey(Color.white, 1f)
					}, array3);
					((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(val6);
				}
			}
		}

		internal static int AddDisplays()
		{
			//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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: 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)
			int num = 0;
			HashSet<ItemDisplayRuleSet> hashSet = new HashSet<ItemDisplayRuleSet>();
			foreach (GameObject allBodyPrefab in BodyCatalog.allBodyPrefabs)
			{
				CharacterModel[] componentsInChildren = allBodyPrefab.GetComponentsInChildren<CharacterModel>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					ItemDisplayRuleSet itemDisplayRuleSet = componentsInChildren[i].itemDisplayRuleSet;
					if (!Object.op_Implicit((Object)(object)itemDisplayRuleSet) || !hashSet.Add(itemDisplayRuleSet))
					{
						continue;
					}
					DisplayRuleGroup itemDisplayRuleGroup = itemDisplayRuleSet.GetItemDisplayRuleGroup(Plugin.SourceItem.itemIndex);
					if (itemDisplayRuleGroup.rules == null || itemDisplayRuleGroup.rules.Length == 0)
					{
						continue;
					}
					ItemDisplayRule[] array = (ItemDisplayRule[])itemDisplayRuleGroup.rules.Clone();
					for (int j = 0; j < array.Length; j++)
					{
						GameObject val = array[j].followerPrefab;
						if (!Object.op_Implicit((Object)(object)val) && array[j].followerPrefabAddress != null && ((AssetReference)array[j].followerPrefabAddress).RuntimeKeyIsValid())
						{
							val = Visuals.Load<GameObject>(((AssetReference)array[j].followerPrefabAddress).RuntimeKey);
						}
						if (Object.op_Implicit((Object)(object)val))
						{
							if (!displays.TryGetValue(val, out var value))
							{
								value = FrostPrefab(val, "DisplayGlacial_" + ((Object)val).name);
								displays.Add(val, value);
							}
							array[j].followerPrefab = value;
							array[j].followerPrefabAddress = null;
						}
					}
					itemDisplayRuleSet.SetDisplayRuleGroup((Object)(object)Plugin.Item, new DisplayRuleGroup
					{
						rules = array
					});
					itemDisplayRuleSet.GenerateRuntimeValues();
					num++;
				}
			}
			return num;
		}
	}
	internal static class Worm
	{
		[HarmonyPatch(typeof(WormBodyPositions2), "FireImpactBlastAttack")]
		private static class FrostSurfaceAttack
		{
			private unsafe static bool Prefix(WormBodyPositions2 __instance, Vector3 __0)
			{
				//IL_004e: 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_0069: Unknown result type (might be due to invalid IL or missing references)
				//IL_006f: Unknown result type (might be due to invalid IL or missing references)
				//IL_008a: Unknown result type (might be due to invalid IL or missing references)
				//IL_008b: Unknown result type (might be due to invalid IL or missing references)
				if (!Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<GlacialWormMarker>()))
				{
					return true;
				}
				if (NetworkServer.active)
				{
					CharacterBody component = ((Component)__instance).GetComponent<CharacterBody>();
					if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.healthComponent) && component.healthComponent.alive)
					{
						Combat.Queue(((Component)component).gameObject, component.teamComponent.teamIndex, __0, component.damage * __instance.blastAttackDamageCoefficient, component.RollCrit(), default(ProcChainMask), 13f, 0.9f, 1f, worm: true);
						Vector3 val = __0;
						Plugin.Trace("Glacial Worm surface burst at " + ((object)(*(Vector3*)(&val))/*cast due to .constrained prefix*/).ToString());
					}
				}
				return false;
			}
		}

		internal static GameObject Body;

		internal static GameObject Master;

		internal static CharacterSpawnCard SpawnCard;

		internal static GlacialDropTable DropTable;

		internal static UnlockableDef LogUnlockable;

		private static bool naturalSpawns;

		private static int rallypointWeightMultiplier = 3;

		internal static void Register(bool spawn, int rallyWeight)
		{
			//IL_004a: 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_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: 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_01a9: 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)
			rallypointWeightMultiplier = Mathf.Clamp(rallyWeight, 1, 10);
			Body = PrefabAPI.InstantiateClone(Visuals.Load<GameObject>((object)"RoR2/Base/ElectricWorm/ElectricWormBody.prefab"), "GlacialWormBody", true);
			CharacterBody component = Body.GetComponent<CharacterBody>();
			component.baseNameToken = "GLACIAL_WORM_NAME";
			component.subtitleNameToken = "GLACIAL_WORM_SUBTITLE";
			component.bodyColor = Visuals.Ice;
			component.portraitIcon = (Texture)(object)Visuals.FrostTexture(component.portraitIcon, preserveBossOutline: false, wormAlbedo: true);
			Body.AddComponent<GlacialWormMarker>();
			ModelLocator component2 = Body.GetComponent<ModelLocator>();
			component2.shouldOverrideLogbookModel = false;
			((Component)component2.modelTransform).gameObject.AddComponent<GlacialWormVisual>();
			LanguageAPI.Add(component.baseNameToken, "Glacial Worm");
			LanguageAPI.Add(component.subtitleNameToken, "The Buried Winter");
			LanguageAPI.Add("GLACIAL_WORM_LORE", "Field Report: The Buried Winter\n\nThe first warning was frost on the underside of the rover. The sun had been overhead for hours.\n\nThen the valley floor cracked. A chain of white plates rose through the dust, each larger than our shelter. Pale light ran between them. Where the creature vanished, ice flowered outward from the broken stone.\n\nWe learned to keep moving when the ground began to glow. We learned nothing about how to make it stop.\n\nOne tooth remains in cold storage. The refrigeration unit has been disconnected for six days.");
			WormBodyPositions2 component3 = Body.GetComponent<WormBodyPositions2>();
			component3.shouldFireMeatballsOnEnter = false;
			component3.shouldFireMeatballsOnExit = false;
			component3.shouldFireMeatballsOnImpact = false;
			component3.meatballProjectile = null;
			component3.blastAttackEffect = Effects.Burst;
			component3.blastAttackRadius = 13f;
			GameObject val = Visuals.FrostPrefab(component3.burrowEffectPrefab, "GlacialWormBurrow");
			if (!ContentAddition.AddEffect(val))
			{
				throw new InvalidOperationException("Burrow effect registration failed.");
			}
			component3.burrowEffectPrefab = val;
			ContactDamage[] componentsInChildren = Body.GetComponentsInChildren<ContactDamage>(true);
			foreach (ContactDamage obj in componentsInChildren)
			{
				obj.damageType = DamageTypeCombo.op_Implicit((DamageType)8);
				obj.impactEffect = Effects.Burst;
			}
			DropTable = ScriptableObject.CreateInstance<GlacialDropTable>();
			((Object)DropTable).name = "dtBossGlacialWorm";
			((PickupDropTable)DropTable).canDropBeReplaced = false;
			DeathRewards component4 = Body.GetComponent<DeathRewards>();
			component4.bossDropTable = (PickupDropTable)(object)DropTable;
			component4.bossPickup = new SerializablePickupIndex
			{
				pickupName = "ItemIndex.GlacialPerforator"
			};
			LogUnlockable = ScriptableObject.CreateInstance<UnlockableDef>();
			LogUnlockable.cachedName = "Logs.GlacialWormBody";
			LogUnlockable.nameToken = component.baseNameToken;
			LogUnlockable.getHowToUnlockString = () => "Collect a Monster Log dropped by a Glacial Worm.";
			LogUnlockable.getUnlockedString = () => "Glacial Worm Monster Log collected.";
			if (!ContentAddition.AddUnlockableDef(LogUnlockable))
			{
				throw new InvalidOperationException("Glacial Worm log registration failed.");
			}
			component4.logUnlockableDef = LogUnlockable;
			component4.useLogbookDropChanceOverride = false;
			Master = PrefabAPI.InstantiateClone(Visuals.Load<GameObject>((object)"RoR2/Base/ElectricWorm/ElectricWormMaster.prefab"), "GlacialWormMaster", true);
			Master.GetComponent<CharacterMaster>().bodyPrefab = Body;
			Master.GetComponent<CharacterMaster>().originalBodyPrefab = Body;
			SpawnCard = Object.Instantiate<CharacterSpawnCard>(Visuals.Load<CharacterSpawnCard>((object)"RoR2/Base/ElectricWorm/cscElectricWorm.asset"));
			((Object)SpawnCard).name = "cscGlacialWorm";
			((SpawnCard)SpawnCard).prefab = Master;
			SpawnCard.noElites = true;
			if (!ContentAddition.AddBody(Body) || !ContentAddition.AddMaster(Master))
			{
				throw new InvalidOperationException("Glacial Worm registration failed.");
			}
			naturalSpawns = spawn;
			if (naturalSpawns)
			{
				DirectorAPI.MonsterActions += AddToPools;
			}
		}

		internal static void Unregister()
		{
			if (naturalSpawns)
			{
				DirectorAPI.MonsterActions -= AddToPools;
			}
		}

		private static bool IsElectric(DirectorCard card)
		{
			if (card == null)
			{
				return false;
			}
			SpawnCard val = card.spawnCard;
			if (!Object.op_Implicit((Object)(object)val) && card.spawnCardReference != null && ((AssetReference)card.spawnCardReference).RuntimeKeyIsValid())
			{
				val = Visuals.Load<SpawnCard>(((AssetReference)card.spawnCardReference).RuntimeKey);
			}
			if (Object.op_Implicit((Object)(object)val))
			{
				return ((Object)val).name == "cscElectricWorm";
			}
			return false;
		}

		private static DirectorCard CopyCard(DirectorCard source, int weightMultiplier)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: 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_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_0069: Expected O, but got Unknown
			return new DirectorCard
			{
				spawnCard = (SpawnCard)(object)SpawnCard,
				selectionWeight = (int)Math.Min(2147483647L, (long)source.selectionWeight * (long)weightMultiplier),
				spawnDistance = source.spawnDistance,
				preventOverhead = source.preventOverhead,
				minimumStageCompletions = source.minimumStageCompletions,
				requiredUnlockableDef = source.requiredUnlockableDef,
				forbiddenUnlockableDef = source.forbiddenUnlockableDef
			};
		}

		private static void AddToPools(DccsPool pool, List<DirectorCardHolder> fallback, StageInfo stage)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Invalid comparison between Unknown and I8
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Expected O, but got Unknown
			int weightMultiplier = (((long)stage.stage != 32) ? 1 : rallypointWeightMultiplier);
			if (Object.op_Implicit((Object)(object)pool) && pool.poolCategories != null)
			{
				HashSet<DirectorCardCategorySelection> seen = new HashSet<DirectorCardCategorySelection>();
				Category[] poolCategories = pool.poolCategories;
				foreach (Category val in poolCategories)
				{
					if (val != null && val.name.IndexOf("Family", StringComparison.OrdinalIgnoreCase) < 0)
					{
						AddEntries(val.alwaysIncluded, seen, weightMultiplier);
						PoolEntry[] includedIfConditionsMet = (PoolEntry[])(object)val.includedIfConditionsMet;
						AddEntries(includedIfConditionsMet, seen, weightMultiplier);
						AddEntries(val.includedIfNoConditionsMet, seen, weightMultiplier);
					}
				}
			}
			if (fallback == null || fallback.Exists((DirectorCardHolder x) => (Object)(object)x.Card?.spawnCard == (Object)(object)SpawnCard))
			{
				return;
			}
			DirectorCardHolder[] array = fallback.ToArray();
			foreach (DirectorCardHolder val2 in array)
			{
				if (IsElectric(val2.Card))
				{
					fallback.Add(new DirectorCardHolder
					{
						Card = CopyCard(val2.Card, weightMultiplier),
						MonsterCategory = val2.MonsterCategory,
						CustomMonsterCategory = val2.CustomMonsterCategory,
						MonsterCategorySelectionWeight = val2.MonsterCategorySelectionWeight
					});
					break;
				}
			}
		}

		private static void AddEntries(PoolEntry[] entries, HashSet<DirectorCardCategorySelection> seen, int weightMultiplier)
		{
			//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_0054: 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_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
			if (entries == null)
			{
				return;
			}
			for (int i = 0; i < entries.Length; i++)
			{
				DirectorCardCategorySelection val = entries[i]?.dccs;
				if (!Object.op_Implicit((Object)(object)val) || !seen.Add(val) || val.categories == null)
				{
					continue;
				}
				for (int j = 0; j < val.categories.Length; j++)
				{
					Category val2 = val.categories[j];
					if (val2.cards != null && !Array.Exists(val2.cards, (DirectorCard x) => (Object)(object)x?.spawnCard == (Object)(object)SpawnCard))
					{
						DirectorCard val3 = Array.Find(val2.cards, IsElectric);
						if (val3 != null)
						{
							List<DirectorCard> list = new List<DirectorCard>(val2.cards) { CopyCard(val3, weightMultiplier) };
							val2.cards = list.ToArray();
							val.categories[j] = val2;
						}
					}
				}
			}
		}
	}
	public sealed class GlacialWormMarker : MonoBehaviour
	{
	}
	public sealed class GlacialWormVisual : MonoBehaviour
	{
		private ModelSkinController skin;

		private void Awake()
		{
			skin = ((Component)this).GetComponentInChildren<ModelSkinController>(true);
			if (Object.op_Implicit((Object)(object)skin))
			{
				skin.onSkinApplied += Apply;
			}
		}

		private IEnumerator Start()
		{
			yield return null;
			Apply(0);
		}

		private void Apply(int index)
		{
			try
			{
				Visuals.FrostModel(((Component)this).gameObject, wormBody: true);
			}
			catch (Exception ex)
			{
				Plugin.Warn("Worm visual recolor failed: " + ex);
			}
		}

		private void OnDestroy()
		{
			if (Object.op_Implicit((Object)(object)skin))
			{
				skin.onSkinApplied -= Apply;
			}
		}
	}
}