Decompiled source of EliteCreaturesPack v0.1.0

plugins\EliteCreaturesPack.dll

Decompiled 16 hours ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using BundlePrefabs;
using Charter;
using ConfigReload;
using EliteCreaturesPack.Core;
using EliteCreaturesPack.Kraken;
using EliteCreaturesPack.Kraken.Motion;
using EliteCreaturesPack.Mimic;
using EliteCreaturesPack.RimeGiant;
using EliteCreaturesPack.Slinger;
using HarmonyLib;
using LocalEffects;
using Microsoft.CodeAnalysis;
using PatchGuard;
using SyncedConfig;
using UnityEngine;
using UnityEngine.UI;
using YamlConfig;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Core.Tokens;
using YamlDotNet.Helpers;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.BufferedDeserialization;
using YamlDotNet.Serialization.BufferedDeserialization.TypeDiscriminators;
using YamlDotNet.Serialization.Callbacks;
using YamlDotNet.Serialization.Converters;
using YamlDotNet.Serialization.EventEmitters;
using YamlDotNet.Serialization.NamingConventions;
using YamlDotNet.Serialization.NodeDeserializers;
using YamlDotNet.Serialization.NodeTypeResolvers;
using YamlDotNet.Serialization.ObjectFactories;
using YamlDotNet.Serialization.ObjectGraphTraversalStrategies;
using YamlDotNet.Serialization.ObjectGraphVisitors;
using YamlDotNet.Serialization.Schemas;
using YamlDotNet.Serialization.TypeInspectors;
using YamlDotNet.Serialization.TypeResolvers;
using YamlDotNet.Serialization.Utilities;
using YamlDotNet.Serialization.ValueDeserializers;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_guiutils")]
[assembly: IgnoresAccessChecksTo("assembly_utils")]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("Gerald Glasgow")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright (c) Gerald Glasgow. Licensed under the GNU General Public License v3.0.")]
[assembly: AssemblyDescription("Elite Creatures Pack: new creatures for Valheim - the crypt mimic, the Greydwarf Slinger and the Rime Giant")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+7567d4bc79c6129457b3c46624a77c0df392ab80")]
[assembly: AssemblyProduct("Elite Creatures Pack")]
[assembly: AssemblyTitle("EliteCreaturesPack")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 EliteCreaturesPack
{
	public static class Settings
	{
		public const string General = "1 - General";

		public static ConfigEntry<bool> LockConfiguration { get; private set; }

		public static event Action? Changed;

		public static void Initialize(SyncedConfiguration config)
		{
			LockConfiguration = config.BindLocking("1 - General", "Lock Configuration", defaultValue: true, "Server only. When on, every player uses the server's values for this file and cannot override them locally.");
			MimicSettings.Initialize(config);
			SlingerSettings.Initialize(config);
			RimeGiantSettings.Initialize(config);
			KrakenSettings.Initialize(config);
			config.Config.SettingChanged += delegate
			{
				SafeCall.Run("settings changed", delegate
				{
					Settings.Changed?.Invoke();
				});
			};
		}

		public static AcceptableValueRange<float> Range(float min, float max)
		{
			return new AcceptableValueRange<float>(min, max);
		}
	}
	[BepInPlugin("com.EliteCreaturesPack", "Elite Creatures Pack", "0.1.0")]
	public class EliteCreaturesPack : BaseUnityPlugin
	{
		public const string PluginGuid = "com.EliteCreaturesPack";

		public const string PluginName = "Elite Creatures Pack";

		public const string PluginVersion = "0.1.0";

		public static SyncedConfiguration Synced { get; private set; }

		private void Awake()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			Log.Bind(((BaseUnityPlugin)this).Logger);
			Synced = new SyncedConfiguration((BaseUnityPlugin)(object)this, ((BaseUnityPlugin)this).Logger, "Elite Creatures Pack", "0.1.0");
			Settings.Initialize(Synced);
			Harmony val = new Harmony("com.EliteCreaturesPack");
			val.PatchAll(Assembly.GetExecutingAssembly());
			MimicPrefabs.Install(val);
			SlingerPrefabs.Install(val);
			RimeGiantPrefabs.Install(val);
			KrakenPrefabs.Install(val);
			Synced.Finish(val);
			Guard.Install(val, ((BaseUnityPlugin)this).Logger, Assembly.GetExecutingAssembly());
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Elite Creatures Pack 0.1.0 ready.");
		}
	}
}
namespace EliteCreaturesPack.Slinger
{
	public static class SlingerAim
	{
		public static void Lob(Attack attack)
		{
			//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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			if (!(attack.m_attackOriginJoint != "ecr_sling_muzzle") && !((Object)(object)attack.m_baseAI == (Object)null))
			{
				Character targetCreature = attack.m_baseAI.GetTargetCreature();
				if (!((Object)(object)targetCreature == (Object)null))
				{
					Vector3 val = default(Vector3);
					Vector3 val2 = default(Vector3);
					attack.GetProjectileSpawnPoint(ref val, ref val2);
					Vector3 val3 = targetCreature.GetCenterPoint() - val;
					Vector2 val4 = new Vector2(val3.x, val3.z);
					float magnitude = ((Vector2)(ref val4)).magnitude;
					float num = Mathf.Atan2(val3.y, magnitude);
					float num2 = Elevation(attack.m_projectileVel, 5f, magnitude, val3.y);
					attack.m_launchAngle = (0f - (num2 - num)) * 57.29578f;
				}
			}
		}

		public static float Elevation(float speed, float gravity, float across, float up)
		{
			float num = speed * speed;
			float num2 = num * num - gravity * (gravity * across * across + 2f * up * num);
			if (!(num2 < 0f) && !(across < 0.01f))
			{
				return Mathf.Atan((num - Mathf.Sqrt(num2)) / (gravity * across));
			}
			return (float)Math.PI / 4f;
		}
	}
	public static class SlingerCreature
	{
		private const string Kit = "ecr_slinger_kit";

		private const string Clip = "ecr_sling_shot";

		private const string ThrowClip = "Throw";

		public const string ThrownRock = "Greydwarf_throw";

		public static GameObject Build(GameObject greydwarf, GameObject shot, GameObject stone, AssetBundle bundle, GameObject? stoneItem)
		{
			GameObject obj = PrefabBench.Copy(greydwarf, "ECP_GreydwarfSlinger");
			Arm(obj.GetComponent<Humanoid>(), shot);
			StandAndShoot(obj.GetComponent<MonsterAI>());
			MoreStones(obj.GetComponent<CharacterDrop>(), stoneItem);
			Transform val = obj.transform.Find("Visual");
			SlingerKit.Wear(val, EmbeddedBundle.Prefab(bundle, "ecr_slinger_kit"), Skin(val), stone);
			PlayShot(((Component)val).GetComponent<Animator>(), bundle.LoadAsset<AnimationClip>("ecr_sling_shot"));
			obj.AddComponent<SlingRig>();
			return obj;
		}

		private static void Arm(Humanoid humanoid, GameObject shot)
		{
			((Character)humanoid).m_name = "$enemy_ecp_greydwarfslinger";
			humanoid.m_defaultItems = (GameObject[])(object)new GameObject[1] { shot };
		}

		private static void StandAndShoot(MonsterAI ai)
		{
			ai.m_circleTargetInterval = 0f;
		}

		private static void MoreStones(CharacterDrop? drops, GameObject? stoneItem)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			if (!((Object)(object)drops == (Object)null) && !((Object)(object)stoneItem == (Object)null))
			{
				drops.m_drops.Add(new Drop
				{
					m_prefab = stoneItem,
					m_amountMin = 2,
					m_amountMax = 4,
					m_chance = 1f,
					m_levelMultiplier = true
				});
			}
		}

		private static Material Skin(Transform visual)
		{
			Renderer[] componentsInChildren = (Renderer[])(object)((Component)visual).GetComponentsInChildren<SkinnedMeshRenderer>(true);
			Renderer[] source = componentsInChildren;
			return (((IEnumerable<Renderer>)source).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => (Object)(object)r.sharedMaterial != (Object)null && ((Object)r.sharedMaterial).name.StartsWith("greydwarf", StringComparison.OrdinalIgnoreCase))) ?? source.OrderByDescending(delegate(Renderer r)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				Bounds bounds = r.bounds;
				Vector3 size = ((Bounds)(ref bounds)).size;
				return ((Vector3)(ref size)).sqrMagnitude;
			}).First()).sharedMaterial;
		}

		private static void PlayShot(Animator animator, AnimationClip? clip)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Expected O, but got Unknown
			RuntimeAnimatorController runtimeAnimatorController = animator.runtimeAnimatorController;
			AnimationClip val = ((IEnumerable<AnimationClip>)runtimeAnimatorController.animationClips).FirstOrDefault((Func<AnimationClip, bool>)((AnimationClip c) => ((Object)c).name == "Throw"));
			if ((Object)(object)clip == (Object)null || (Object)(object)val == (Object)null)
			{
				Log.Warn("Greydwarf slinger: no " + (((Object)(object)clip == (Object)null) ? "ecr_sling_shot in the bundle" : "Throw clip in the Greydwarf's animator") + "; it throws like a greydwarf.");
				return;
			}
			AnimatorOverrideController val2 = new AnimatorOverrideController(runtimeAnimatorController)
			{
				name = "ecp_slinger_animator"
			};
			val2[val] = clip;
			animator.runtimeAnimatorController = (RuntimeAnimatorController)(object)val2;
		}
	}
	public static class SlingerKit
	{
		private const string StoneSlot = "ecr_sling_stone";

		public static void Wear(Transform visual, GameObject kitPrefab, Material skin, GameObject stone)
		{
			GameObject val = Object.Instantiate<GameObject>(kitPrefab, visual.parent, false);
			Dress(val, skin);
			Transform[] array = ((IEnumerable)val.transform).Cast<Transform>().ToArray();
			for (int i = 0; i < array.Length; i++)
			{
				Hang(array[i], visual);
			}
			Object.DestroyImmediate((Object)(object)val);
			Pebble(GameMaterials.Find(visual, "ecr_sling_stone"), SlingerStone.Visual(stone));
		}

		private static void Dress(GameObject kit, Material skin)
		{
			Dictionary<Material, Material> dictionary = new Dictionary<Material, Material>();
			Renderer[] componentsInChildren = kit.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer obj in componentsInChildren)
			{
				Material sharedMaterial = obj.sharedMaterial;
				if (!dictionary.TryGetValue(sharedMaterial, out var value))
				{
					value = (dictionary[sharedMaterial] = GameMaterials.Dress(skin, sharedMaterial));
				}
				obj.sharedMaterial = value;
			}
		}

		private static void Hang(Transform mount, Transform visual)
		{
			//IL_0045: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			Transform val = GameMaterials.Find(visual, ((Object)mount).name);
			if ((Object)(object)val == (Object)null)
			{
				Log.Warn("Greydwarf slinger: the Greydwarf has no " + ((Object)mount).name + " bone; what hangs there is left off.");
				Object.DestroyImmediate((Object)(object)((Component)mount).gameObject);
				return;
			}
			mount.SetParent(val, false);
			mount.localPosition = Vector3.zero;
			mount.localRotation = Quaternion.identity;
			mount.localScale = Vector3.one;
		}

		private static void Pebble(Transform? slot, Transform? look)
		{
			//IL_003c: 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_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			MeshFilter val = ((look != null) ? ((Component)look).GetComponentInChildren<MeshFilter>(true) : null);
			MeshRenderer val2 = ((val != null) ? ((Component)val).GetComponent<MeshRenderer>() : null);
			if (!((Object)(object)slot == (Object)null) && !((Object)(object)val == (Object)null) && !((Object)(object)val2 == (Object)null))
			{
				GameObject val3 = new GameObject("ecr_sling_pebble")
				{
					layer = ((Component)slot).gameObject.layer
				};
				val3.transform.SetParent(slot, false);
				val3.transform.localScale = ((Component)val).transform.lossyScale / slot.lossyScale.x;
				val3.AddComponent<MeshFilter>().sharedMesh = val.sharedMesh;
				((Renderer)val3.AddComponent<MeshRenderer>()).sharedMaterial = ((Renderer)val2).sharedMaterial;
			}
		}
	}
	[HarmonyPatch(typeof(SpawnSystem), "Spawn")]
	public static class SlingerWildSpawnPatch
	{
		private static bool Prefix(SpawnSystem __instance, SpawnData critter, Vector3 spawnPoint, bool eventSpawner)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			SpawnData slinger = null;
			SafeCall.Run("SpawnSystem.Spawn slinger", delegate
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				slinger = SlingerSpawns.Wild(critter, spawnPoint);
			});
			if (slinger == null)
			{
				return true;
			}
			__instance.Spawn(slinger, spawnPoint, eventSpawner);
			return false;
		}
	}
	[HarmonyPatch(typeof(Attack), "FireProjectileBurst")]
	public static class SlingerAimPatch
	{
		private static void Prefix(Attack __instance)
		{
			if (__instance.m_attackOriginJoint == "ecr_sling_muzzle")
			{
				SafeCall.Run("Attack.FireProjectileBurst slinger aim", delegate
				{
					SlingerAim.Lob(__instance);
				});
			}
		}
	}
	[HarmonyPatch(typeof(SpawnArea), "SelectWeightedPrefab")]
	public static class SlingerNestSpawnPatch
	{
		private static void Postfix(SpawnArea __instance, ref SpawnData __result)
		{
			SpawnData picked = __result;
			SafeCall.Run("SpawnArea.SelectWeightedPrefab slinger", delegate
			{
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				picked = SlingerSpawns.Nest(picked, ((Component)__instance).transform.position);
			});
			__result = picked;
		}
	}
	public static class SlingerPrefabs
	{
		public const string Creature = "ECP_GreydwarfSlinger";

		public const string Shot = "ECP_GreydwarfSlinger_shot";

		public const string Stone = "ECP_GreydwarfSlinger_stone";

		public const string Greydwarf = "Greydwarf";

		private const string Bundle = "ecr_slinger";

		private static GameObject? shot;

		private static GameObject? stone;

		public static GameObject? Prefab { get; private set; }

		public static void Install(Harmony harmony)
		{
			NetPrefabs.OnSceneAwake(harmony, delegate(ZNetScene scene)
			{
				Guard.Run("SlingerPrefabs.Build", delegate
				{
					Build(scene, harmony);
				});
			});
			Settings.Changed += delegate
			{
				SafeCall.Run("slinger settings", SlingerShot.ApplyToAll);
			};
		}

		private static void Build(ZNetScene scene, Harmony harmony)
		{
			if (!((Object)(object)scene.GetPrefab("ECP_GreydwarfSlinger") != (Object)null) && (!((Object)(object)Prefab == (Object)null) || Create(scene, harmony)))
			{
				NetPrefabs.Register(scene, stone);
				NetPrefabs.Register(scene, shot);
				NetPrefabs.Register(scene, Prefab);
				SlingerWords.Add(Localization.instance);
				Log.Info("Greydwarf slinger ready: ECP_GreydwarfSlinger, ECP_GreydwarfSlinger_shot, ECP_GreydwarfSlinger_stone.");
			}
		}

		private static bool Create(ZNetScene scene, Harmony harmony)
		{
			GameObject prefab = scene.GetPrefab("Greydwarf");
			GameObject val = ((prefab == null) ? null : ((IEnumerable<GameObject>)prefab.GetComponent<Humanoid>()?.m_defaultItems).FirstOrDefault((Func<GameObject, bool>)((GameObject item) => (Object)(object)item != (Object)null && ((Object)item).name == "Greydwarf_throw")));
			GameObject prefab2 = scene.GetPrefab("Greydwarf_throw_projectile");
			if ((Object)(object)prefab == (Object)null || (Object)(object)val == (Object)null || (Object)(object)prefab2 == (Object)null)
			{
				Log.Error("Greydwarf slinger not built: the game has no " + (((Object)(object)prefab == (Object)null) ? "Greydwarf" : (((Object)(object)val == (Object)null) ? "Greydwarf_throw" : "Greydwarf_throw_projectile")) + ".");
				return false;
			}
			AssetBundle bundle = EmbeddedBundle.Load(typeof(SlingerPrefabs).Assembly, "ecr_slinger");
			stone = SlingerStone.Build(prefab2);
			shot = SlingerShot.Build(val, stone, scene.GetPrefab("sfx_bow_fire"));
			ItemPrefabs.Register(harmony, shot);
			Prefab = SlingerCreature.Build(prefab, shot, stone, bundle, scene.GetPrefab("Stone"));
			return true;
		}
	}
	public static class SlingerSettings
	{
		public const string Section = "3 - Greydwarf Slinger";

		private static ConfigEntry<bool> enabled;

		private static ConfigEntry<float> share;

		private static ConfigEntry<bool> nests;

		private static ConfigEntry<Biome> biomes;

		private static ConfigEntry<float> shotInterval;

		private static ConfigEntry<float> stoneDamage;

		private static ConfigEntry<float> stoneSpeed;

		private static ConfigEntry<float> range;

		public static bool On => enabled.Value;

		public static float Share => share.Value / 100f;

		public static bool Nests => nests.Value;

		public static float ShotInterval => shotInterval.Value;

		public static float StoneDamage => stoneDamage.Value;

		public static float StoneSpeed => stoneSpeed.Value;

		public static float Range => range.Value;

		public static bool InBiome(Biome biome)
		{
			//IL_0005: 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)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			return (biomes.Value & biome) > 0;
		}

		public static void Initialize(SyncedConfiguration config)
		{
			enabled = config.Bind("3 - Greydwarf Slinger", "Enabled", true, "Greydwarf slingers: a greydwarf with a slingshot that stands and shoots stones like a skeleton archer, at any range, and never melees. Off: no new slingers; ones already in the world stay.", true, null);
			share = config.Bind("3 - Greydwarf Slinger", "Share", 10f, "Percent of the greydwarfs spawning in the biomes below that come as slingers instead.", true, (AcceptableValueBase?)(object)Settings.Range(0f, 100f));
			nests = config.Bind("3 - Greydwarf Slinger", "Nests", true, "Greydwarf nests spawn them too, not only the wild.", true, null);
			biomes = config.Bind<Biome>("3 - Greydwarf Slinger", "Biomes", (Biome)8, "Where greydwarfs can come as slingers. Several biomes are separated by commas, like BlackForest, Meadows.", synced: true, null, Array.Empty<object>());
			BindFight(config);
		}

		private static void BindFight(SyncedConfiguration config)
		{
			shotInterval = config.Bind("3 - Greydwarf Slinger", "Shot Interval", 3.5f, "Seconds between its shots at the least.", true, (AcceptableValueBase?)(object)Settings.Range(0.5f, 60f));
			stoneDamage = config.Bind("3 - Greydwarf Slinger", "Stone Damage", 12f, "Blunt damage of a stone, before stars (a greydwarf's thrown rock: 10).", true, (AcceptableValueBase?)(object)Settings.Range(0f, 500f));
			stoneSpeed = config.Bind("3 - Greydwarf Slinger", "Stone Speed", 16f, "Metres a second the stone flies (a greydwarf's thrown rock: 12); it arcs onto its target.", true, (AcceptableValueBase?)(object)Settings.Range(5f, 60f));
			range = config.Bind("3 - Greydwarf Slinger", "Range", 22f, "Metres it shoots from.", true, (AcceptableValueBase?)(object)Settings.Range(6f, 60f));
		}
	}
	public static class SlingerShot
	{
		public const string Muzzle = "ecr_sling_muzzle";

		private const float Spread = 2.5f;

		public static SharedData Shared { get; private set; }

		public static GameObject Build(GameObject thrownRock, GameObject stone, GameObject? twang)
		{
			GameObject obj = PrefabBench.Copy(thrownRock, "ECP_GreydwarfSlinger_shot");
			Shared = obj.GetComponent<ItemDrop>().m_itemData.m_shared;
			Shared.m_name = "$item_ecp_slinger_shot";
			Shared.m_aiAttackRangeMin = 0f;
			Shared.m_aiAttackMaxAngle = 10f;
			Shared.m_aiPrioritized = true;
			Launch(Shared.m_attack, stone, twang);
			Apply(Shared);
			return obj;
		}

		private static void Launch(Attack attack, GameObject stone, GameObject? twang)
		{
			//IL_000d: 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_00ab: Expected O, but got Unknown
			attack.m_attackAnimation = "throw";
			attack.m_attackType = (AttackType)2;
			attack.m_attackProjectile = stone;
			attack.m_attackOriginJoint = "ecr_sling_muzzle";
			attack.m_attackHeight = 0f;
			attack.m_attackRange = 0.15f;
			attack.m_attackOffset = 0f;
			attack.m_projectileAccuracy = 2.5f;
			attack.m_projectileAccuracyMin = 2.5f;
			attack.m_launchAngle = 0f;
			attack.m_attackStamina = 0f;
			attack.m_speedFactor = 0f;
			attack.m_speedFactorRotation = 0.5f;
			if ((Object)(object)twang != (Object)null)
			{
				attack.m_triggerEffect.m_effectPrefabs = (EffectData[])(object)new EffectData[1]
				{
					new EffectData
					{
						m_prefab = twang
					}
				};
			}
		}

		public static void Apply(SharedData shared)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			shared.m_aiAttackInterval = SlingerSettings.ShotInterval;
			shared.m_aiAttackRange = SlingerSettings.Range;
			shared.m_damages = new DamageTypes
			{
				m_blunt = SlingerSettings.StoneDamage
			};
			shared.m_attack.m_projectileVel = SlingerSettings.StoneSpeed;
			shared.m_attack.m_projectileVelMin = SlingerSettings.StoneSpeed;
		}

		public static void ApplyToAll()
		{
			if (Shared == null)
			{
				return;
			}
			Apply(Shared);
			foreach (Character allCharacter in Character.GetAllCharacters())
			{
				Humanoid val = (Humanoid)(object)((allCharacter is Humanoid) ? allCharacter : null);
				if (val == null || !((Object)(object)((Component)val).GetComponent<SlingRig>() != (Object)null))
				{
					continue;
				}
				foreach (ItemData allItem in val.GetInventory().GetAllItems())
				{
					if (allItem.m_shared.m_name == Shared.m_name)
					{
						Apply(allItem.m_shared);
					}
				}
			}
		}
	}
	public static class SlingerSpawns
	{
		public static SpawnData? Wild(SpawnData critter, Vector3 point)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			if (!Swap(critter.m_prefab, point, nest: false))
			{
				return null;
			}
			SpawnData obj = critter.Clone();
			obj.m_prefab = SlingerPrefabs.Prefab;
			return obj;
		}

		public static SpawnData Nest(SpawnData picked, Vector3 nest)
		{
			//IL_0009: 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)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			if (picked == null || !Swap(picked.m_prefab, nest, nest: true))
			{
				return picked;
			}
			return new SpawnData
			{
				m_prefab = SlingerPrefabs.Prefab,
				m_weight = picked.m_weight,
				m_minLevel = picked.m_minLevel,
				m_maxLevel = picked.m_maxLevel
			};
		}

		private static bool Swap(GameObject? prefab, Vector3 point, bool nest)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			if (!SlingerSettings.On || (nest && !SlingerSettings.Nests) || (Object)(object)SlingerPrefabs.Prefab == (Object)null || (Object)(object)prefab == (Object)null || ((Object)prefab).name != "Greydwarf" || SlingerSettings.Share <= 0f)
			{
				return false;
			}
			if (SlingerSettings.InBiome(WorldGenerator.instance.GetBiome(point)))
			{
				return Random.value < SlingerSettings.Share;
			}
			return false;
		}
	}
	public static class SlingerStone
	{
		public const float Size = 0.5f;

		public const float Gravity = 5f;

		public static GameObject Build(GameObject rock)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = PrefabBench.Copy(rock, "ECP_GreydwarfSlinger_stone");
			Projectile component = obj.GetComponent<Projectile>();
			component.m_gravity = 5f;
			component.m_ttl = 4f;
			component.m_rayRadius = 0.3f;
			if ((Object)(object)component.m_visual != (Object)null)
			{
				Transform transform = component.m_visual.transform;
				transform.localScale *= 0.5f;
			}
			return obj;
		}

		public static Transform? Visual(GameObject stone)
		{
			Projectile component = stone.GetComponent<Projectile>();
			if (component == null)
			{
				return null;
			}
			GameObject visual = component.m_visual;
			if (visual == null)
			{
				return null;
			}
			return visual.transform;
		}
	}
	[HarmonyPatch(typeof(Localization), "SetupLanguage")]
	public static class SlingerWords
	{
		public static void Add(Localization localization)
		{
			localization.AddWord("enemy_ecp_greydwarfslinger", "Greydwarf Slinger");
			localization.AddWord("item_ecp_slinger_shot", "Slingshot stone");
		}

		private static void Postfix(Localization __instance)
		{
			SafeCall.Run("Localization.SetupLanguage slinger words", delegate
			{
				Add(__instance);
			});
		}
	}
	public sealed class SlingRig : MonoBehaviour
	{
		private const float ClipLength = 2f;

		private const float Grab = 0.52f;

		private const float Release = 1.12f;

		private const float PouchHalfWidth = 0.03f;

		private static readonly int ShotState = Animator.StringToHash("throw");

		private Animator? animator;

		private Transform slingshot;

		private Transform pinch;

		private Transform pouch;

		private Transform pebble;

		private Transform anchorA;

		private Transform anchorB;

		private Transform rest;

		private Transform bandA;

		private Transform bandB;

		private Vector3 released;

		private void Awake()
		{
			animator = ((Component)this).GetComponentInChildren<Animator>();
			Transform val = Part("ecr_sling_slingshot");
			Transform val2 = Part("ecr_sling_pinch");
			Transform val3 = Part("ecr_sling_pouch");
			Transform val4 = Part("ecr_sling_stone");
			Transform val5 = Part("ecr_sling_anchor_a");
			Transform val6 = Part("ecr_sling_anchor_b");
			Transform val7 = Part("ecr_sling_rest");
			Transform val8 = Part("ecr_sling_band_a");
			Transform val9 = Part("ecr_sling_band_b");
			if ((Object)(object)animator == (Object)null || (Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null || (Object)(object)val4 == (Object)null || (Object)(object)val5 == (Object)null || (Object)(object)val6 == (Object)null || (Object)(object)val7 == (Object)null || (Object)(object)val8 == (Object)null || (Object)(object)val9 == (Object)null)
			{
				((Behaviour)this).enabled = false;
				return;
			}
			Transform val10 = val;
			Transform val11 = val2;
			Transform val12 = val3;
			Transform val13 = val4;
			Transform val14 = val5;
			Transform val15 = val6;
			Transform val16 = val7;
			Transform val17 = val8;
			Transform val18 = val9;
			slingshot = val10;
			pinch = val11;
			pouch = val12;
			pebble = val13;
			anchorA = val14;
			anchorB = val15;
			rest = val16;
			bandA = val17;
			bandB = val18;
			Transform? Part(string name)
			{
				return GameMaterials.Find(((Component)this).transform, name);
			}
		}

		private void LateUpdate()
		{
			//IL_002a: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: 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_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_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: 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_0147: 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_0156: 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)
			float num = ShotTime();
			bool flag = num >= 0.52f && num < 1.12f;
			if (flag)
			{
				pouch.position = pinch.position;
				released = slingshot.InverseTransformPoint(pinch.position);
			}
			else
			{
				pouch.localPosition = Recoil((num < 0f) ? (-1f) : (num - 1.12f));
			}
			Vector3 val = (anchorA.localPosition + anchorB.localPosition) * 0.5f;
			pouch.localRotation = Quaternion.LookRotation(val - pouch.localPosition, Vector3.up);
			((Component)pebble).gameObject.SetActive(flag);
			Stretch(bandA, anchorA.localPosition, pouch.localPosition + pouch.localRotation * Vector3.right * 0.03f);
			Stretch(bandB, anchorB.localPosition, pouch.localPosition - pouch.localRotation * Vector3.right * 0.03f);
		}

		private float ShotTime()
		{
			//IL_0023: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			AnimatorStateInfo val = (animator.IsInTransition(0) ? animator.GetNextAnimatorStateInfo(0) : animator.GetCurrentAnimatorStateInfo(0));
			if (((AnimatorStateInfo)(ref val)).shortNameHash != ShotState)
			{
				return -1f;
			}
			return Mathf.Clamp01(((AnimatorStateInfo)(ref val)).normalizedTime) * 2f;
		}

		private Vector3 Recoil(float since)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			if (since < 0f || since > 0.35f)
			{
				return rest.localPosition;
			}
			float num = Mathf.Exp(-10f * since) * Mathf.Cos(22f * since);
			return rest.localPosition + (released - rest.localPosition) * num;
		}

		private static void Stretch(Transform band, Vector3 from, Vector3 to)
		{
			//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_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = to - from;
			band.localPosition = from;
			band.localRotation = Quaternion.LookRotation((((Vector3)(ref val)).sqrMagnitude > 1E-06f) ? val : Vector3.back, Vector3.up);
			band.localScale = new Vector3(1f, 1f, ((Vector3)(ref val)).magnitude);
		}
	}
}
namespace EliteCreaturesPack.RimeGiant
{
	public class RimeArmour : MonoBehaviour
	{
		private static readonly int PlatesKey = StringExtensionMethods.GetStableHashCode("ecp_rime_plates");

		private const float HeatCheck = 1f;

		private const float HeatPerCheck = 10f;

		private const float HeatReach = 1.5f;

		private ZNetView _nview;

		private Character _character;

		private MonsterAI _ai;

		private float _fire;

		private float _lastHit = float.NegativeInfinity;

		private float _lastGrowth;

		private float _heatTimer;

		public static int MaxPlates => Mathf.Clamp(RimeGiantSettings.Plates, 0, 8);

		public int Plates
		{
			get
			{
				ZDO obj = (((Object)(object)_nview != (Object)null && _nview.IsValid()) ? _nview.GetZDO() : null);
				return Mathf.Clamp((obj != null) ? obj.GetInt(PlatesKey, MaxPlates) : MaxPlates, 0, MaxPlates);
			}
		}

		public float Through
		{
			get
			{
				int maxPlates = MaxPlates;
				float num = 1f - RimeGiantSettings.ArmouredDamage;
				if (maxPlates > 0)
				{
					return 1f - num * (float)Plates / (float)maxPlates;
				}
				return 1f;
			}
		}

		private bool Wounded => _character.GetHealthPercentage() <= RimeGiantSettings.ShatterAt;

		private bool Fighting
		{
			get
			{
				if (!((Object)(object)_ai != (Object)null) || (!((BaseAI)_ai).IsAlerted() && !((Object)(object)((BaseAI)_ai).GetTargetCreature() != (Object)null)))
				{
					return Time.time - _lastHit < RimeGiantSettings.RegrowDelay;
				}
				return true;
			}
		}

		private void Awake()
		{
			_nview = ((Component)this).GetComponent<ZNetView>();
			_character = ((Component)this).GetComponent<Character>();
			_ai = ((Component)this).GetComponent<MonsterAI>();
		}

		private void Update()
		{
			if (!((Object)(object)_nview == (Object)null) && _nview.IsValid() && _nview.IsOwner() && !_character.IsDead())
			{
				FeelHeat(Time.deltaTime);
				if (Plates > 0 && Wounded)
				{
					Shatter();
				}
				Regrow();
			}
		}

		public void Soften(HitData hit)
		{
			_lastHit = Time.time;
			float through = Through;
			hit.m_damage.m_blunt *= through;
			hit.m_damage.m_slash *= through;
			hit.m_damage.m_pierce *= through;
			hit.m_damage.m_chop *= through;
			hit.m_damage.m_pickaxe *= through;
		}

		public void Melt(float fire)
		{
			if (fire <= 0f || !_nview.IsOwner())
			{
				return;
			}
			_lastHit = Time.time;
			_fire += fire;
			float firePerPlate = RimeGiantSettings.FirePerPlate;
			while (_fire >= firePerPlate && Plates > 0)
			{
				_fire -= firePerPlate;
				Set(Plates - 1);
				if (Plates == 0)
				{
					Shatter();
				}
			}
		}

		private void Shatter()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			Set(0);
			_fire = 0f;
			_character.Stagger(-((Component)this).transform.forward);
		}

		private void FeelHeat(float dt)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			_heatTimer += dt;
			if (!(_heatTimer < 1f))
			{
				_heatTimer = 0f;
				if ((Object)(object)EffectArea.IsPointInsideArea(((Component)this).transform.position, (Type)1, 1.5f * ((Component)this).transform.localScale.x) != (Object)null)
				{
					Melt(10f);
				}
			}
		}

		private void Regrow()
		{
			if (Plates < MaxPlates && !Fighting && !Wounded && !(Time.time - _lastGrowth < RimeGiantSettings.RegrowInterval))
			{
				_lastGrowth = Time.time;
				_fire = 0f;
				Set(Plates + 1);
			}
		}

		private void Set(int plates)
		{
			_nview.GetZDO().Set(PlatesKey, Mathf.Clamp(plates, 0, MaxPlates), false);
		}
	}
	public class RimeArmourLook : MonoBehaviour
	{
		private const int KitPlates = 8;

		private RimeArmour _armour;

		private GameObject?[] _plates = (GameObject?[])(object)new GameObject[0];

		private int _shown = -1;

		private void Awake()
		{
			_armour = ((Component)this).GetComponent<RimeArmour>();
			_plates = RimeKit.Plates(((Component)this).transform, 8);
		}

		private void Update()
		{
			int plates = _armour.Plates;
			if (plates != _shown)
			{
				bool watched = _shown >= 0;
				_shown = plates;
				for (int i = 0; i < _plates.Length; i++)
				{
					Show(_plates[i], i < plates, watched);
				}
			}
		}

		private void Show(GameObject? plate, bool on, bool watched)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)plate == (Object)null) && plate.activeSelf != on)
			{
				if (watched && !on)
				{
					RimeShards.BreakOff(plate, ((Component)this).transform);
				}
				plate.SetActive(on);
				if (watched && on)
				{
					RimeEffects.Grow(plate.transform.position);
				}
			}
		}
	}
	public static class RimeAttacks
	{
		public const string Punch = "troll_punch";

		public const string GroundSlam = "troll_groundslam";

		public const string RockThrow = "troll_throw";

		public const string SweepName = "$item_ecp_rimegiant_sweep";

		public const string SlamName = "$item_ecp_rimegiant_slam";

		public const string ThrowName = "$item_ecp_rimegiant_throw";

		private const float SweepPush = 220f;

		private static GameObject[] prefabs = (GameObject[])(object)new GameObject[0];

		public static GameObject? TrollItem(Humanoid troll, string name)
		{
			return troll.m_randomSets.SelectMany((ItemSet set) => set.m_items).FirstOrDefault((Func<GameObject, bool>)((GameObject item) => (Object)(object)item != (Object)null && ((Object)item).name == name));
		}

		public static GameObject[] Build(GameObject punch, GameObject slam, GameObject rockThrow, GameObject boulder)
		{
			GameObject val = Copy(punch, "ECP_RimeGiant_sweep", "$item_ecp_rimegiant_sweep");
			GameObject val2 = Copy(slam, "ECP_RimeGiant_slam", "$item_ecp_rimegiant_slam");
			Shared(val2).m_aiAttackRange = 12f;
			Shared(val2).m_aiAttackInterval = 12f;
			GameObject val3 = Copy(rockThrow, "ECP_RimeGiant_throw", "$item_ecp_rimegiant_throw");
			Shared(val3).m_attack.m_attackProjectile = boulder;
			Shared(val3).m_aiAttackRange = 22f;
			prefabs = (GameObject[])(object)new GameObject[3] { val, val2, val3 };
			GameObject[] array = prefabs;
			for (int i = 0; i < array.Length; i++)
			{
				Apply(Shared(array[i]));
			}
			return prefabs;
		}

		private static GameObject Copy(GameObject troll, string name, string token)
		{
			GameObject obj = PrefabBench.Copy(troll, name);
			SharedData obj2 = Shared(obj);
			obj2.m_name = token;
			Grow(obj2, 1.4f);
			return obj;
		}

		private static void Grow(SharedData shared, float size)
		{
			Attack attack = shared.m_attack;
			attack.m_attackRange *= size;
			attack.m_attackHeight *= size;
			attack.m_attackRayWidth *= size;
			shared.m_aiAttackRange *= size;
			shared.m_aiAttackRangeMin *= size;
		}

		public static void Apply(SharedData shared)
		{
			//IL_0015: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			if (shared.m_name == "$item_ecp_rimegiant_sweep")
			{
				shared.m_damages = new DamageTypes
				{
					m_blunt = RimeGiantSettings.SweepDamage
				};
				shared.m_attackForce = 220f;
			}
			else if (shared.m_name == "$item_ecp_rimegiant_slam")
			{
				shared.m_damages = new DamageTypes
				{
					m_blunt = RimeGiantSettings.SlamDamage
				};
			}
			else if (shared.m_name == "$item_ecp_rimegiant_throw")
			{
				shared.m_damages = new DamageTypes
				{
					m_blunt = RimeGiantSettings.BoulderDamage,
					m_frost = RimeGiantSettings.BoulderDamage
				};
			}
		}

		public static void ApplyToAll()
		{
			GameObject[] array = prefabs;
			for (int i = 0; i < array.Length; i++)
			{
				Apply(Shared(array[i]));
			}
			foreach (Character allCharacter in Character.GetAllCharacters())
			{
				Humanoid val = (Humanoid)(object)((allCharacter is Humanoid) ? allCharacter : null);
				if (val != null && (Object)(object)((Component)val).GetComponent<RimeArmour>() != (Object)null)
				{
					val.GetInventory().GetAllItems().ForEach(delegate(ItemData item)
					{
						Apply(item.m_shared);
					});
				}
			}
		}

		private static SharedData Shared(GameObject item)
		{
			return item.GetComponent<ItemDrop>().m_itemData.m_shared;
		}
	}
	public class RimeAvalanche : MonoBehaviour
	{
		public const string WaveRpc = "ecp_rime_wave";

		private const float StepTime = 0.09f;

		private const float Reach = 2.6f;

		private const float Push = 140f;

		private const float StartAhead = 3f;

		private Character _character;

		private MonsterAI _ai;

		private ZNetView _nview;

		private void Awake()
		{
			_character = ((Component)this).GetComponent<Character>();
			_ai = ((Component)this).GetComponent<MonsterAI>();
			_nview = ((Component)this).GetComponent<ZNetView>();
			if (!((Object)(object)_nview != (Object)null) || !_nview.IsValid())
			{
				return;
			}
			_nview.Register<ZPackage>("ecp_rime_wave", (Action<long, ZPackage>)delegate(long sender, ZPackage package)
			{
				Guard.Run("RimeAvalanche.Draw", delegate
				{
					Draw(package);
				});
			});
		}

		public void Roll()
		{
			//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_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_0053: 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_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)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_nview == (Object)null) && _nview.IsValid() && _nview.IsOwner() && !(RimeGiantSettings.AvalancheLength <= 0f))
			{
				Vector3 val = Heading();
				List<Vector3> list = RimeWavePath.Trace(((Component)this).transform.position + val * (3f * ((Component)this).transform.localScale.x), val, RimeGiantSettings.AvalancheLength);
				if (list.Count != 0)
				{
					_nview.InvokeRPC(ZNetView.Everybody, "ecp_rime_wave", new object[1] { Pack(list) });
					((MonoBehaviour)this).StartCoroutine(Crush(list, val));
				}
			}
		}

		private Vector3 Heading()
		{
			//IL_0039: 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_0049: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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)
			Character val = (((Object)(object)_ai != (Object)null) ? ((BaseAI)_ai).GetTargetCreature() : null);
			Vector3 val2 = (((Object)(object)val != (Object)null) ? (((Component)val).transform.position - ((Component)this).transform.position) : ((Component)this).transform.forward);
			val2.y = 0f;
			if (!(((Vector3)(ref val2)).sqrMagnitude > 0.01f))
			{
				return ((Component)this).transform.forward;
			}
			return ((Vector3)(ref val2)).normalized;
		}

		private IEnumerator Crush(List<Vector3> path, Vector3 direction)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			HashSet<Character> struck = new HashSet<Character>();
			foreach (Vector3 item in path)
			{
				if ((Object)(object)_character == (Object)null || _character.IsDead())
				{
					yield break;
				}
				foreach (Character item2 in Caught(item, struck))
				{
					item2.Damage(Hit(item2, direction));
				}
				yield return (object)new WaitForSeconds(0.09f);
			}
		}

		private List<Character> Caught(Vector3 point, HashSet<Character> struck)
		{
			//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)
			//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_0030: 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_003c: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			List<Character> list = new List<Character>();
			foreach (Character allCharacter in Character.GetAllCharacters())
			{
				Vector3 val = ((Component)allCharacter).transform.position - point;
				Vector2 val2 = new Vector2(val.x, val.z);
				if (((Vector2)(ref val2)).magnitude <= 2.6f && Mathf.Abs(val.y) <= 3.8999999f && (Object)(object)allCharacter != (Object)(object)_character && !allCharacter.IsDead() && BaseAI.IsEnemy(_character, allCharacter) && struck.Add(allCharacter))
				{
					list.Add(allCharacter);
				}
			}
			return list;
		}

		private HitData Hit(Character victim, Vector3 direction)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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
			float avalancheDamage = RimeGiantSettings.AvalancheDamage;
			HitData val = new HitData
			{
				m_point = victim.GetCenterPoint(),
				m_dir = direction,
				m_pushForce = 140f,
				m_dodgeable = true,
				m_blockable = true,
				m_hitType = (HitType)1,
				m_damage = 
				{
					m_blunt = avalancheDamage
				},
				m_damage = 
				{
					m_frost = avalancheDamage * 0.5f
				}
			};
			val.SetAttacker(_character);
			return val;
		}

		private static ZPackage Pack(List<Vector3> path)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			ZPackage val = new ZPackage();
			val.Write(path.Count);
			path.ForEach((Action<Vector3>)val.Write);
			return val;
		}

		private void Draw(ZPackage package)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			int num = package.ReadInt();
			for (int i = 0; i < num; i++)
			{
				list.Add(package.ReadVector3());
			}
			((MonoBehaviour)this).StartCoroutine(Steps(list));
		}

		private static IEnumerator Steps(List<Vector3> path)
		{
			for (int i = 0; i < path.Count; i++)
			{
				RimeEffects.Wave(path[i], i);
				yield return (object)new WaitForSeconds(0.09f);
			}
		}
	}
	public static class RimeBoulder
	{
		public const float Burst = 3.5f;

		public static GameObject Build(GameObject rock, GameObject? look, Material skin, ZNetScene scene)
		{
			GameObject obj = PrefabBench.Copy(rock, "ECP_RimeGiant_boulder");
			Projectile component = obj.GetComponent<Projectile>();
			component.m_aoe = 3.5f;
			component.m_hitEffects.m_effectPrefabs = WithIce(component.m_hitEffects.m_effectPrefabs, scene);
			if ((Object)(object)look != (Object)null && (Object)(object)component.m_visual != (Object)null)
			{
				Reskin(component.m_visual.transform, look, skin);
			}
			return obj;
		}

		private static void Reskin(Transform visual, GameObject look, Material skin)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			MeshFilter componentInChildren = ((Component)visual).GetComponentInChildren<MeshFilter>(true);
			Vector3 val;
			if (!((Object)(object)componentInChildren != (Object)null) || !((Object)(object)componentInChildren.sharedMesh != (Object)null))
			{
				val = Vector3.zero;
			}
			else
			{
				Transform transform = ((Component)componentInChildren).transform;
				Bounds bounds = componentInChildren.sharedMesh.bounds;
				val = visual.InverseTransformPoint(transform.TransformPoint(((Bounds)(ref bounds)).center));
			}
			Vector3 localPosition = val;
			Renderer[] componentsInChildren = ((Component)visual).GetComponentsInChildren<Renderer>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].enabled = false;
			}
			GameObject obj = Object.Instantiate<GameObject>(look, visual, false);
			((Object)obj).name = "ecr_rime_boulder";
			obj.transform.localPosition = localPosition;
			obj.transform.localScale = Vector3.one * (1f / Mathf.Max(visual.lossyScale.x, 0.0001f));
			componentsInChildren = obj.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val2 in componentsInChildren)
			{
				val2.sharedMaterial = GameMaterials.Dress(skin, val2.sharedMaterial);
			}
		}

		private static EffectData[] WithIce(EffectData[] rock, ZNetScene scene)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			List<EffectData> list = new List<EffectData>(rock);
			string[] array = new string[2] { "vfx_ice_destroyed", "sfx_ice_destroyed" };
			foreach (string text in array)
			{
				GameObject prefab = scene.GetPrefab(text);
				if ((Object)(object)prefab != (Object)null)
				{
					list.Add(new EffectData
					{
						m_prefab = prefab
					});
				}
			}
			return list.ToArray();
		}
	}
	public static class RimeCorpse
	{
		public static GameObject? Build(Humanoid troll)
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = null;
			EffectData[] effectPrefabs = ((Character)troll).m_deathEffects.m_effectPrefabs;
			foreach (EffectData val2 in effectPrefabs)
			{
				if ((Object)(object)val2.m_prefab != (Object)null && (Object)(object)val2.m_prefab.GetComponent<Ragdoll>() != (Object)null)
				{
					val = val2.m_prefab;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			GameObject obj = PrefabBench.Copy(val, "ECP_RimeGiant_ragdoll");
			obj.transform.localScale = val.transform.localScale * 1.4f;
			RimeLook.StarLooks(obj);
			return obj;
		}
	}
	internal static class RimeEffects
	{
		private static readonly string[] Shatter = new string[2] { "vfx_ice_destroyed", "vfx_ice_hit" };

		private static readonly string[] ShatterSound = new string[2] { "sfx_ice_destroyed", "sfx_ice_hit" };

		private static readonly string[] Frost = new string[2] { "vfx_Frost", "vfx_ice_hit" };

		private static readonly string[] FrostSound = new string[2] { "sfx_Frost_Start", "sfx_ice_hit" };

		private static readonly string[] Snow = new string[2] { "vfx_BombBlob_explode_frost", "vfx_troll_groundslam" };

		private static readonly string[] SnowSound = new string[2] { "sfx_ice_destroyed", "sfx_troll_rock_destroyed" };

		private static readonly Dictionary<string, GameObject?> found = new Dictionary<string, GameObject>();

		public static void Break(Vector3 at)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			LocalEffect.Flash(Find(Shatter), at, 2f);
			LocalEffect.Sound(Find(ShatterSound), at);
		}

		public static void Grow(Vector3 at)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			LocalEffect.Flash(Find(Frost), at, 1.5f);
			LocalEffect.Sound(Find(FrostSound), at);
		}

		public static void Wave(Vector3 at, int step)
		{
			//IL_000a: 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)
			LocalEffect.FlashWhole(Find(Snow), at, 3f, 1f);
			if (step % 3 == 0)
			{
				LocalEffect.Sound(Find(SnowSound), at);
			}
		}

		public static GameObject? Find(string[] names)
		{
			string key = names[0];
			if (found.TryGetValue(key, out GameObject value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			value = null;
			foreach (string text in names)
			{
				object obj = value;
				if (obj == null)
				{
					ZNetScene instance = ZNetScene.instance;
					obj = ((instance != null) ? instance.GetPrefab(text) : null);
				}
				value = (GameObject)obj;
			}
			if ((Object)(object)value == (Object)null && !found.ContainsKey(key))
			{
				Log.Warn("Rime giant: the game has none of " + string.Join(", ", names) + "; that effect is left out.");
			}
			found[key] = value;
			return value;
		}
	}
	public static class RimeGiantCreature
	{
		public const float Size = 1.4f;

		public static GameObject Build(GameObject troll, GameObject[] attacks, GameObject corpse, GameObject kit, ZNetScene scene)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = PrefabBench.Copy(troll, "ECP_RimeGiant");
			val.transform.localScale = Vector3.one * 1.4f;
			Humanoid component = val.GetComponent<Humanoid>();
			Arm(component, attacks);
			Harden(component, scene);
			Asleep(val.GetComponent<MonsterAI>(), scene);
			Die(component, corpse, scene);
			Loot(val.GetComponent<CharacterDrop>(), scene);
			Dress(val, kit);
			val.AddComponent<RimeArmour>();
			val.AddComponent<RimeArmourLook>();
			val.AddComponent<RimeSlumber>();
			val.AddComponent<RimeAvalanche>();
			return val;
		}

		private static void Arm(Humanoid humanoid, GameObject[] attacks)
		{
			((Character)humanoid).m_name = "$enemy_ecp_rimegiant";
			humanoid.m_defaultItems = attacks;
			humanoid.m_randomWeapon = (GameObject[])(object)new GameObject[0];
			humanoid.m_randomSets = (ItemSet[])(object)new ItemSet[0];
			humanoid.m_randomItems = (RandomItem[])(object)new RandomItem[0];
		}

		private static void Harden(Humanoid humanoid, ZNetScene scene)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			((Character)humanoid).m_faction = (Faction)5;
			((Character)humanoid).m_health = RimeGiantSettings.Health;
			((Character)humanoid).m_damageModifiers.m_frost = (DamageModifier)3;
			((Character)humanoid).m_damageModifiers.m_fire = (DamageModifier)2;
			((Character)humanoid).m_hitEffects.m_effectPrefabs = Swap(((Character)humanoid).m_hitEffects.m_effectPrefabs, "vfx_foresttroll_hit", scene.GetPrefab("vfx_frosttroll_hit"));
		}

		private static void Asleep(MonsterAI ai, ZNetScene scene)
		{
			((Component)ai).GetComponent<Character>().m_disableWhileSleeping = true;
			ai.m_sleeping = true;
			ai.m_wakeupRange = 0f;
			ai.m_noiseWakeup = false;
			ai.m_fallAsleepDistance = 0f;
			ai.m_wakeUpDelayMin = 0f;
			ai.m_wakeUpDelayMax = 0f;
			ai.m_enableHuntPlayer = false;
			ai.m_wakeupEffects.m_effectPrefabs = Effects(scene, "vfx_ice_destroyed", "sfx_ice_destroyed", "sfx_troll_alerted");
		}

		private static void Die(Humanoid humanoid, GameObject corpse, ZNetScene scene)
		{
			//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_0047: Expected O, but got Unknown
			List<EffectData> list = ((Character)humanoid).m_deathEffects.m_effectPrefabs.Where((EffectData effect) => (Object)(object)effect.m_prefab != (Object)null && (Object)(object)effect.m_prefab.GetComponent<Ragdoll>() == (Object)null).ToList();
			list.Add(new EffectData
			{
				m_prefab = corpse
			});
			list.AddRange(Effects(scene, "vfx_ice_destroyed", "sfx_ice_destroyed"));
			((Character)humanoid).m_deathEffects.m_effectPrefabs = list.ToArray();
		}

		private static void Loot(CharacterDrop drops, ZNetScene scene)
		{
			drops.m_drops = new List<Drop>();
			Add(drops, scene.GetPrefab("Crystal"), 4, 8);
			Add(drops, scene.GetPrefab("FreezeGland"), 3, 6);
			Add(drops, scene.GetPrefab("SilverOre"), 3, 6);
		}

		private static void Add(CharacterDrop drops, GameObject? item, int min, int max)
		{
			//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)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			if ((Object)(object)item != (Object)null)
			{
				drops.m_drops.Add(new Drop
				{
					m_prefab = item,
					m_amountMin = min,
					m_amountMax = max,
					m_chance = 1f,
					m_levelMultiplier = true
				});
			}
		}

		private static void Dress(GameObject giant, GameObject kit)
		{
			Transform val = giant.transform.Find("Visual");
			RimeKit.Wear(val, kit, RimeKit.Skin(val));
			RimeLook.Tint(val);
			RimeLook.StarLooks(giant);
		}

		private static EffectData[] Swap(EffectData[] effects, string name, GameObject? with)
		{
			foreach (EffectData val in effects)
			{
				if ((Object)(object)with != (Object)null && (Object)(object)val.m_prefab != (Object)null && ((Object)val.m_prefab).name == name)
				{
					val.m_prefab = with;
				}
			}
			return effects;
		}

		public static EffectData[] Effects(ZNetScene scene, params string[] names)
		{
			return (from prefab in ((IEnumerable<string>)names).Select((Func<string, GameObject>)scene.GetPrefab)
				where (Object)(object)prefab != (Object)null
				select prefab).Select((Func<GameObject, EffectData>)((GameObject prefab) => new EffectData
			{
				m_prefab = prefab
			})).ToArray();
		}
	}
	[HarmonyPatch(typeof(SpawnSystem), "Awake")]
	public static class RimeGiantSpawnPatch
	{
		private static void Postfix(SpawnSystem __instance)
		{
			SafeCall.Run("SpawnSystem.Awake rime giant", delegate
			{
				RimeGiantSpawns.Join(__instance);
			});
		}
	}
	[HarmonyPatch(typeof(SpawnSystem), "Spawn")]
	public static class RimeGiantSpawnGatePatch
	{
		private static bool Prefix(SpawnData critter, Vector3 spawnPoint)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)critter?.m_prefab == (Object)null || (Object)(object)critter.m_prefab != (Object)(object)RimeGiantPrefabs.Prefab || SpawnSystem.m_nospawn)
			{
				return true;
			}
			bool allowed = false;
			SafeCall.Run("SpawnSystem.Spawn rime giant", delegate
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				allowed = RimeGiantSpawns.Allow(spawnPoint);
			});
			return allowed;
		}
	}
	[HarmonyPatch(typeof(Character), "RPC_Damage")]
	public static class RimeArmourHitPatch
	{
		private static void Prefix(Character __instance, HitData hit)
		{
			RimeArmour armour = default(RimeArmour);
			if (hit != null && ((Component)__instance).TryGetComponent<RimeArmour>(ref armour) && __instance.m_nview.IsOwner())
			{
				SafeCall.Run("Character.RPC_Damage rime armour", delegate
				{
					armour.Soften(hit);
				});
			}
		}
	}
	[HarmonyPatch(typeof(Character), "ApplyDamage")]
	public static class RimeArmourFirePatch
	{
		private static void Prefix(Character __instance, HitData hit)
		{
			RimeArmour armour = default(RimeArmour);
			if (hit != null && hit.m_damage.m_fire > 0f && ((Component)__instance).TryGetComponent<RimeArmour>(ref armour))
			{
				SafeCall.Run("Character.ApplyDamage rime armour", delegate
				{
					armour.Melt(hit.m_damage.m_fire);
				});
			}
		}
	}
	[HarmonyPatch(typeof(Attack), "OnAttackTrigger")]
	public static class RimeAvalanchePatch
	{
		private static void Postfix(Attack __instance)
		{
			RimeAvalanche rimeAvalanche = default(RimeAvalanche);
			if (!(__instance.m_weapon?.m_shared.m_name != "$item_ecp_rimegiant_slam") && !((Object)(object)__instance.m_character == (Object)null) && !((Character)__instance.m_character).IsStaggering() && ((Component)__instance.m_character).TryGetComponent<RimeAvalanche>(ref rimeAvalanche))
			{
				SafeCall.Run("Attack.OnAttackTrigger rime avalanche", rimeAvalanche.Roll);
			}
		}
	}
	[HarmonyPatch(typeof(EnemyHud), "TestShow")]
	public static class RimeGiantHudPatch
	{
		private static void Postfix(Character c, ref bool __result)
		{
			RimeSlumber rimeSlumber = default(RimeSlumber);
			if (__result && (Object)(object)c != (Object)null && ((Component)c).TryGetComponent<RimeSlumber>(ref rimeSlumber) && rimeSlumber.Asleep)
			{
				__result = false;
			}
		}
	}
	[HarmonyPatch(typeof(Character))]
	public static class RimeGiantHoverPatch
	{
		[HarmonyPatch("GetHoverText")]
		[HarmonyPostfix]
		[HarmonyPriority(0)]
		private static void HoverText(Character __instance, ref string __result)
		{
			Blank(__instance, ref __result);
		}

		[HarmonyPatch("GetHoverName")]
		[HarmonyPostfix]
		[HarmonyPriority(0)]
		private static void HoverName(Character __instance, ref string __result)
		{
			Blank(__instance, ref __result);
		}

		private static void Blank(Character character, ref string text)
		{
			RimeSlumber rimeSlumber = default(RimeSlumber);
			if (((Component)character).TryGetComponent<RimeSlumber>(ref rimeSlumber) && rimeSlumber.Asleep)
			{
				text = "";
			}
		}
	}
	[HarmonyPatch(typeof(LevelEffects), "GetColorChanges")]
	public static class RimeGiantColorPatch
	{
		[HarmonyPriority(0)]
		private static void Postfix(LevelEffects __instance, ref float hue, ref float saturation, ref float value)
		{
			RimeArmour rimeArmour = default(RimeArmour);
			if (hue == 0f && saturation == 0f && value == 0f && (Object)(object)__instance.m_character != (Object)null && ((Component)__instance.m_character).TryGetComponent<RimeArmour>(ref rimeArmour))
			{
				hue = 0f;
				saturation = -0.55f;
				value = 0.25f;
			}
		}
	}
	public static class RimeGiantPrefabs
	{
		public const string Creature = "ECP_RimeGiant";

		public const string Boulder = "ECP_RimeGiant_boulder";

		public const string Corpse = "ECP_RimeGiant_ragdoll";

		private const string Troll = "Troll";

		private const string Bundle = "ecr_rimegiant";

		private const string Kit = "ecr_rimegiant_kit";

		private const string BoulderLook = "ecr_rime_boulder";

		private static GameObject? boulder;

		private static GameObject? corpse;

		public static GameObject? Prefab { get; private set; }

		public static void Install(Harmony harmony)
		{
			NetPrefabs.OnSceneAwake(harmony, delegate(ZNetScene scene)
			{
				Guard.Run("RimeGiantPrefabs.Build", delegate
				{
					Build(scene, harmony);
				});
			});
			Settings.Changed += delegate
			{
				SafeCall.Run("rime giant settings", Reapply);
			};
		}

		private static void Build(ZNetScene scene, Harmony harmony)
		{
			if (!((Object)(object)scene.GetPrefab("ECP_RimeGiant") != (Object)null) && (!((Object)(object)Prefab == (Object)null) || Create(scene, harmony)))
			{
				NetPrefabs.Register(scene, boulder);
				NetPrefabs.Register(scene, corpse);
				NetPrefabs.Register(scene, Prefab);
				RimeGiantSpawns.Refresh();
				RimeGiantWords.Add(Localization.instance);
				Log.Info("Rime giant ready: ECP_RimeGiant, ECP_RimeGiant_boulder, ECP_RimeGiant_ragdoll.");
			}
		}

		private static bool Create(ZNetScene scene, Harmony harmony)
		{
			GameObject prefab = scene.GetPrefab("Troll");
			Humanoid val = ((prefab != null) ? prefab.GetComponent<Humanoid>() : null);
			GameObject[] array = (GameObject[])(object)(((Object)(object)val == (Object)null) ? new GameObject[0] : new GameObject[3]
			{
				RimeAttacks.TrollItem(val, "troll_punch"),
				RimeAttacks.TrollItem(val, "troll_groundslam"),
				RimeAttacks.TrollItem(val, "troll_throw")
			});
			object obj;
			if (array.Length != 3)
			{
				obj = null;
			}
			else
			{
				GameObject obj2 = array[2];
				obj = ((obj2 != null) ? obj2.GetComponent<ItemDrop>().m_itemData.m_shared.m_attack.m_attackProjectile : null);
			}
			GameObject val2 = (GameObject)obj;
			corpse = (((Object)(object)val == (Object)null) ? null : RimeCorpse.Build(val));
			if ((Object)(object)val == (Object)null || array.Any((GameObject part) => (Object)(object)part == (Object)null) || (Object)(object)val2 == (Object)null || (Object)(object)corpse == (Object)null)
			{
				Log.Error("Rime giant not built: the game's Troll is missing " + (((Object)(object)val == (Object)null) ? "entirely" : "an attack, its thrown rock or its ragdoll") + ".");
				return false;
			}
			AssetBundle val3 = EmbeddedBundle.Load(typeof(RimeGiantPrefabs).Assembly, "ecr_rimegiant");
			Material skin = RimeKit.Skin(((Component)val).transform);
			boulder = RimeBoulder.Build(val2, val3.LoadAsset<GameObject>("ecr_rime_boulder"), skin, scene);
			GameObject[] array2 = RimeAttacks.Build(array[0], array[1], array[2], boulder);
			GameObject[] array3 = array2;
			foreach (GameObject item in array3)
			{
				ItemPrefabs.Register(harmony, item);
			}
			Prefab = RimeGiantCreature.Build(((Component)val).gameObject, array2, corpse, EmbeddedBundle.Prefab(val3, "ecr_rimegiant_kit"), scene);
			return true;
		}

		private static void Reapply()
		{
			RimeAttacks.ApplyToAll();
			RimeGiantSpawns.Refresh();
			if ((Object)(object)Prefab != (Object)null)
			{
				Prefab.GetComponent<Character>().m_health = RimeGiantSettings.Health;
			}
		}
	}
	public static class RimeGiantSettings
	{
		public const string Section = "4 - Rime Giant";

		private static ConfigEntry<bool> enabled;

		private static ConfigEntry<float> mountains;

		private static ConfigEntry<float> chance;

		private static ConfigEntry<float> interval;

		private static ConfigEntry<Biome> biomes;

		private static ConfigEntry<float> health;

		private static ConfigEntry<int> plates;

		private static ConfigEntry<float> armouredDamage;

		private static ConfigEntry<float> shatterAt;

		private static ConfigEntry<float> firePerPlate;

		private static ConfigEntry<float> regrowDelay;

		private static ConfigEntry<float> regrowInterval;

		private static ConfigEntry<float> sweepDamage;

		private static ConfigEntry<float> slamDamage;

		private static ConfigEntry<float> boulderDamage;

		private static ConfigEntry<float> avalancheDamage;

		private static ConfigEntry<float> avalancheLength;

		public static bool On => enabled.Value;

		public static float Mountains => mountains.Value / 100f;

		public static float Chance => chance.Value;

		public static float Interval => interval.Value;

		public static Biome Biomes => biomes.Value;

		public static float Health => health.Value;

		public static int Plates => plates.Value;

		public static float ArmouredDamage => armouredDamage.Value / 100f;

		public static float ShatterAt => shatterAt.Value / 100f;

		public static float FirePerPlate => firePerPlate.Value;

		public static float RegrowDelay => regrowDelay.Value;

		public static float RegrowInterval => regrowInterval.Value;

		public static float SweepDamage => sweepDamage.Value;

		public static float SlamDamage => slamDamage.Value;

		public static float AvalancheDamage => avalancheDamage.Value;

		public static float AvalancheLength => avalancheLength.Value;

		public static float BoulderDamage => boulderDamage.Value;

		public static bool InBiome(Biome biome)
		{
			//IL_0005: 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)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			return (biomes.Value & biome) > 0;
		}

		public static void Initialize(SyncedConfiguration config)
		{
			BindSpawn(config);
			BindArmour(config);
			BindAttacks(config);
		}

		private static void BindSpawn(SyncedConfiguration config)
		{
			enabled = config.Bind("4 - Rime Giant", "Enabled", true, "Rime giants: a very rare giant of the Mountains, a troll crusted in plates of ice that sleeps by day like a snowy outcrop. At most one per mountain, ever. Off: no new giants; ones already in the world stay.", true, null);
			mountains = config.Bind("4 - Rime Giant", "Mountains", 60f, "Percent of mountains that hold a giant, fixed by the world seed. Snowy hilltops under about 150 m across don't count. Once a mountain's giant has come it never gets another, even after it dies.", true, (AcceptableValueBase?)(object)Settings.Range(0f, 100f));
			chance = config.Bind("4 - Rime Giant", "Chance", 25f, "Percent per zone roll, while someone roams a mountain whose giant has not come yet.", true, (AcceptableValueBase?)(object)Settings.Range(0f, 100f));
			interval = config.Bind("4 - Rime Giant", "Interval", 3600f, "Seconds between a zone's rolls.", true, (AcceptableValueBase?)(object)Settings.Range(60f, 86400f));
			biomes = config.Bind<Biome>("4 - Rime Giant", "Biomes", (Biome)4, "The biomes whose regions count as mountains. Several are separated by commas.", synced: true, null, Array.Empty<object>());
			health = config.Bind("4 - Rime Giant", "Health", 1500f, "Its health before stars (a forest troll: 600).", true, (AcceptableValueBase?)(object)Settings.Range(1f, 100000f));
		}

		private static void BindArmour(SyncedConfiguration config)
		{
			plates = config.Bind("4 - Rime Giant", "Plates", 8, "Plates of ice it wears, 0 to 8.", true, (AcceptableValueBase?)(object)new AcceptableValueRange<int>(0, 8));
			armouredDamage = config.Bind("4 - Rime Giant", "Armoured Damage", 15f, "Percent of a physical hit that gets through with every plate on; each plate lost lets an equal part more through.", true, (AcceptableValueBase?)(object)Settings.Range(0f, 100f));
			shatterAt = config.Bind("4 - Rime Giant", "Shatter At", 40f, "Percent of its health at which the plates left all break off.", true, (AcceptableValueBase?)(object)Settings.Range(0f, 100f));
			firePerPlate = config.Bind("4 - Rime Giant", "Fire Per Plate", 30f, "Fire damage that breaks one plate (a fire arrow against its weakness: about 33).", true, (AcceptableValueBase?)(object)Settings.Range(1f, 1000f));
			regrowDelay = config.Bind("4 - Rime Giant", "Regrow Delay", 12f, "Seconds unhurt, out of the fight, before the plates grow back.", true, (AcceptableValueBase?)(object)Settings.Range(0f, 600f));
			regrowInterval = config.Bind("4 - Rime Giant", "Regrow Interval", 5f, "Seconds per plate as they grow back.", true, (AcceptableValueBase?)(object)Settings.Range(0.5f, 600f));
		}

		private static void BindAttacks(SyncedConfiguration config)
		{
			sweepDamage = config.Bind("4 - Rime Giant", "Sweep Damage", 75f, "Blunt damage of its fist, with heavy knockback (a troll's punch: 60).", true, (AcceptableValueBase?)(object)Settings.Range(0f, 1000f));
			slamDamage = config.Bind("4 - Rime Giant", "Slam Damage", 60f, "Blunt damage where its fists land in the slam.", true, (AcceptableValueBase?)(object)Settings.Range(0f, 1000f));
			avalancheDamage = config.Bind("4 - Rime Giant", "Avalanche Damage", 45f, "Blunt damage, plus half as much frost, where the slam's wave rolls over you.", true, (AcceptableValueBase?)(object)Settings.Range(0f, 1000f));
			avalancheLength = config.Bind("4 - Rime Giant", "Avalanche Length", 24f, "Metres the wave rolls on flat ground; far further downhill, a few metres uphill. 0 turns the avalanche off.", true, (AcceptableValueBase?)(object)Settings.Range(0f, 60f));
			boulderDamage = config.Bind("4 - Rime Giant", "Boulder Damage", 40f, "Blunt damage of its ice boulder, plus as much frost in the burst around it.", true, (AcceptableValueBase?)(object)Settings.Range(0f, 1000f));
		}
	}
	public static class RimeGiantSpawns
	{
		private const float Apart = 1000f;

		private static SpawnSystemList? list;

		private static readonly SpawnData Entry = new SpawnData
		{
			m_name = "ECP_RimeGiant",
			m_biomeArea = (BiomeArea)2,
			m_maxSpawned = 1,
			m_spawnDistance = 1000f,
			m_groupSizeMin = 1,
			m_groupSizeMax = 1,
			m_huntPlayer = false,
			m_groundOffset = 0.05f,
			m_minLevel = 1,
			m_maxLevel = 1
		};

		public static void Join(SpawnSystem system)
		{
			if (!((Object)(object)Entry.m_prefab == (Object)null))
			{
				list = (SpawnSystemList?)(((Object)(object)list != (Object)null) ? ((object)list) : ((object)Make()));
				if (!system.m_spawnLists.Contains(list))
				{
					system.m_spawnLists.Add(list);
				}
			}
		}

		public static bool Allow(Vector3 point)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			int num = RimeMountains.Waiting(point);
			if (num < 0)
			{
				return false;
			}
			RimeMountains.Claim(num);
			return true;
		}

		public static void Refresh()
		{
			//IL_0041: 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)
			Entry.m_prefab = RimeGiantPrefabs.Prefab;
			Entry.m_enabled = RimeGiantSettings.On;
			Entry.m_spawnChance = RimeGiantSettings.Chance;
			Entry.m_spawnInterval = RimeGiantSettings.Interval;
			Entry.m_biome = RimeGiantSettings.Biomes;
		}

		private static SpawnSystemList Make()
		{
			//IL_0005: 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)
			GameObject val = new GameObject("ECP_RimeGiant_spawns");
			val.transform.SetParent(PrefabBench.Root, false);
			SpawnSystemList obj = val.AddComponent<SpawnSystemList>();
			obj.m_spawners.Add(Entry);
			return obj;
		}
	}
	[HarmonyPatch(typeof(Localization), "SetupLanguage")]
	public static class RimeGiantWords
	{
		public static void Add(Localization localization)
		{
			localization.AddWord("enemy_ecp_rimegiant", "Rime Giant");
			localization.AddWord("item_ecp_rimegiant_sweep", "Rime fist");
			localization.AddWord("item_ecp_rimegiant_slam", "Avalanche");
			localization.AddWord("item_ecp_rimegiant_throw", "Ice boulder");
		}

		private static void Postfix(Localization __instance)
		{
			SafeCall.Run("Localization.SetupLanguage rime giant words", delegate
			{
				Add(__instance);
			});
		}
	}
	public static class RimeKit
	{
		public const string Plate = "ecr_rime_plate_";

		public const string Crust = "ecr_rime_crust";

		public static void Wear(Transform visual, GameObject kitPrefab, Material skin)
		{
			GameObject val = Object.Instantiate<GameObject>(kitPrefab, visual.parent, false);
			Dress(val, skin);
			Transform[] array = ((IEnumerable)val.transform).Cast<Transform>().ToArray();
			for (int i = 0; i < array.Length; i++)
			{
				Hang(array[i], visual);
			}
			Object.DestroyImmediate((Object)(object)val);
		}

		public static Material Skin(Transform troll)
		{
			return ((Renderer)(from r in ((Component)troll).GetComponentsInChildren<SkinnedMeshRenderer>(true)
				orderby ((Object)(object)r.sharedMesh != (Object)null) ? r.sharedMesh.vertexCount : 0 descending
				select r).First()).sharedMaterial;
		}

		public static GameObject?[] Plates(Transform giant, int count)
		{
			GameObject[] array = (GameObject[])(object)new GameObject[count];
			for (int i = 0; i < count; i++)
			{
				int num = i;
				Transform? obj = GameMaterials.Find(giant, "ecr_rime_plate_" + i);
				array[num] = ((obj != null) ? ((Component)obj).gameObject : null);
			}
			return array;
		}

		public static List<GameObject> CrustPieces(Transform giant)
		{
			return (from t in ((Component)giant).GetComponentsInChildren<Transform>(true)
				where ((Object)t).name.StartsWith("ecr_rime_crust")
				select ((Component)t).gameObject).ToList();
		}

		private static void Dress(GameObject kit, Material skin)
		{
			Dictionary<Material, Material> dictionary = new Dictionary<Material, Material>();
			Renderer[] componentsInChildren = kit.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer obj in componentsInChildren)
			{
				Material sharedMaterial = obj.sharedMaterial;
				if (!dictionary.TryGetValue(sharedMaterial, out var value))
				{
					value = (dictionary[sharedMaterial] = GameMaterials.Dress(skin, sharedMaterial));
				}
				obj.sharedMaterial = value;
			}
		}

		private static void Hang(Transform mount, Transform visual)
		{
			//IL_0045: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			Transform val = GameMaterials.Find(visual, ((Object)mount).name);
			if ((Object)(object)val == (Object)null)
			{
				Log.Warn("Rime giant: the troll has no " + ((Object)mount).name + " bone; what hangs there is left off.");
				Object.DestroyImmediate((Object)(object)((Component)mount).gameObject);
				return;
			}
			mount.SetParent(val, false);
			mount.localPosition = Vector3.zero;
			mount.localRotation = Quaternion.identity;
			mount.localScale = Vector3.one;
		}
	}
	public static class RimeLook
	{
		public const float Hue = 0f;

		public const float Saturation = -0.55f;

		public const float Value = 0.25f;

		public static void Tint(Transform visual)
		{
			SkinnedMeshRenderer[] componentsInChildren = ((Component)visual).GetComponentsInChildren<SkinnedMeshRenderer>(true);
			foreach (SkinnedMeshRenderer val in componentsInChildren)
			{
				Material[] sharedMaterials = ((Renderer)val).sharedMaterials;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					if ((Object)(object)sharedMaterials[j] != (Object)null && sharedMaterials[j].HasProperty("_Saturation"))
					{
						sharedMaterials[j] = Frosted(sharedMaterials[j]);
					}
				}
				((Renderer)val).sharedMaterials = sharedMaterials;
			}
		}

		public static void StarLooks(GameObject copy)
		{
			LevelEffects[] componentsInChildren = copy.GetComponentsInChildren<LevelEffects>(true);
			foreach (LevelEffects val in componentsInChildren)
			{
				val.m_levelSetups = new List<LevelSetup>
				{
					Look(val, 0, -0.06f, -0.35f, 0.2f),
					Look(val, 1, 0.04f, -0.75f, 0.4f)
				};
			}
		}

		private static LevelSetup Look(LevelEffects effects, int index, float hue, float saturation, float value)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_0062: Expected O, but got Unknown
			LevelSetup val = ((index < effects.m_levelSetups.Count) ? effects.m_levelSetups[index] : null);
			return new LevelSetup
			{
				m_scale = (val?.m_scale ?? 1f),
				m_hue = hue,
				m_saturation = saturation,
				m_value = value,
				m_enableObject = val?.m_enableObject
			};
		}

		private static Material Frosted(Material troll)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			Material val = new Material(troll)
			{
				name = ((Object)troll).name + "_rime"
			};
			val.SetFloat("_Hue", 0f);
			val.SetFloat("_Saturation", -0.55f);
			val.SetFloat("_Value", 0.25f);
			return val;
		}
	}
	internal static class RimeMountains
	{
		public const int MinEdge = 40;

		private const string KeyPrefix = "ecp_rimegiant_";

		public static int Waiting(Vector3 point)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			AltBiomeWorldData val = WorldGenerator.instance?.m_world?.m_biomeData;
			if (val == null || !val.IsReady || (Object)(object)ZoneSystem.instance == (Object)null)
			{
				return -1;
			}
			BiomeSector biomeSector = WorldGenerator.instance.GetBiomeSector(point, false);
			int num = val.Sectors.IndexOf(biomeSector);
			if (num < 0 || biomeSector.EdgeCount < 40 || !RimeGiantSettings.InBiome(biomeSector.Biome) || !Holds(num) || ZoneSystem.instance.GetGlobalKey("ecp_rimegiant_" + num))
			{
				return -1;
			}
			return num;
		}

		public static void Claim(int region)
		{
			ZoneSystem.instance.SetGlobalKey("ecp_rimegiant_" + region);
			Log.Info($"Rime giant: mountain {region} wakes its giant.");
		}

		private static bool Holds(int region)
		{
			int num = (WorldGenerator.instance.GetSeed() * -1640531535) ^ (region * -2048144789);
			int num2 = (num ^ (num >>> 16)) * 2146121005;
			int num3 = (num2 ^ (num2 >>> 15)) * -2073254261;
			return (float)(uint)((num3 ^ (num3 >>> 16)) & 0xFFFFFF) / 16777216f < RimeGiantSettings.Mountains;
		}
	}
	internal static class RimeShards
	{
		private const float Life = 8f;

		private const float Mass = 30f;

		private const float Outward = 3f;

		private const float Upward = 2.5f;

		public static void BreakOff(GameObject plate, Transform giant)
		{
			//IL_0008: 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)
			//IL_001a: 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_0064: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = plate.transform;
			RimeEffects.Break(transform.position);
			GameObject obj = Object.Instantiate<GameObject>(plate, transform.position, transform.rotation);
			((Object)obj).name = "ecp_rime_shard";
			obj.transform.localScale = transform.lossyScale;
			obj.SetActive(true);
			SetLayer(obj, LayerMask.NameToLayer("item"));
			Fit(obj);
			Throw(obj.AddComponent<Rigidbody>(), transform.position - (giant.position + Vector3.up * 3f));
			Object.Destroy((Object)(object)obj, 8f);
		}

		private static void Fit(GameObject shard)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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_005a: 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_0056: 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_0060: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			Bounds? val = null;
			MeshFilter[] componentsInChildren = shard.GetComponentsInChildren<MeshFilter>(true);
			foreach (MeshFilter val2 in componentsInChildren)
			{
				if (!((Object)(object)val2.sharedMesh == (Object)null))
				{
					Bounds val3 = Local(shard.transform, ((Component)val2).transform, val2.sharedMesh.bounds);
					Bounds value;
					if (val.HasValue)
					{
						Bounds valueOrDefault = val.GetValueOrDefault();
						value = Grown(valueOrDefault, val3);
					}
					else
					{
						value = val3;
					}
					val = value;
				}
			}
			BoxCollider obj = shard.AddComponent<BoxCollider>();
			Vector3 center;
			Bounds valueOrDefault2;
			if (!val.HasValue)
			{
				center = Vector3.zero;
			}
			else
			{
				valueOrDefault2 = val.GetValueOrDefault();
				center = ((Bounds)(ref valueOrDefault2)).center;
			}
			obj.center = center;
			Vector3 val4;
			if (!val.HasValue)
			{
				val4 = Vector3.one * 0.5f;
			}
			else
			{
				valueOrDefault2 = val.GetValueOrDefault();
				val4 = ((Bounds)(ref valueOrDefault2)).size;
			}
			obj.size = Vector3.Max(val4, Vector3.one * 0.1f);
		}

		private static Bounds Local(Transform root, Transform part, Bounds mesh)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = root.InverseTransformPoint(part.TransformPoint(((Bounds)(ref mesh)).center));
			Vector3 val2 = root.InverseTransformVector(part.TransformVector(((Bounds)(ref mesh)).size));
			return new Bounds(val, new Vector3(Mathf.Abs(val2.x), Mathf.Abs(val2.y), Mathf.Abs(val2.z)));
		}

		private static Bounds Grown(Bounds a, Bounds b)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			((Bounds)(ref a)).Encapsulate(b);
			return a;
		}

		private static void Throw(Rigidbody body, Vector3 away)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//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)
			//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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			away.y = 0f;
			body.mass = 30f;
			body.linearVelocity = ((Vector3)(ref away)).normalized * 3f + Vector3.up * 2.5f;
			body.angularVelocity = Random.insideUnitSphere * 4f;
		}

		private static void SetLayer(GameObject shard, int layer)
		{
			if (layer >= 0)
			{
				Transform[] componentsInChildren = shard.GetComponentsInChildren<Transform>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					((Component)componentsInChildren[i]).gameObject.layer = layer;
				}
			}
		}
	}
	public class RimeSlumber : MonoBehaviour
	{
		public const string Blizzard = "SnowStorm";

		private const float Check = 1f;

		private const float Settle = 20f;

		private MonsterAI _ai;

		private Character _character;

		private ZNetView _nview;

		private List<GameObject> _crust = new List<GameObject>();

		private bool? _crustShown;

		private float _checkTimer;

		private float _quiet;

		public bool Asleep
		{
			get
			{
				if ((Object)(object)_ai != (Object)null)
				{
					return ((BaseAI)_ai).IsSleeping();
				}
				return false;
			}
		}

		private void Awake()
		{
			_ai = ((Component)this).GetComponent<MonsterAI>();
			_character = ((Component)this).GetComponent<Character>();
			_nview = ((Component)this).GetComponent<ZNetView>();
			_crust = RimeKit.CrustPieces(((Component)this).transform);
		}

		private void Update()
		{
			bool asleep = Asleep;
			_character.m_hideHud = asleep;
			ShowCrust(asleep);
			_checkTimer += Time.deltaTime;
			if (_checkTimer >= 1f && (Object)(object)_nview != (Object)null && _nview.IsValid() && _nview.IsOwner() && !_character.IsDead())
			{
				_checkTimer = 0f;
				Decide(asleep);
			}
		}

		private void Decide(bool asleep)
		{
			bool flag = EnvMan.IsNight() || ((Object)(object)EnvMan.instance != (Object)null && EnvMan.instance.IsEnvironment("SnowStorm"));
			if (asleep)
			{
				if (flag)
				{
					_ai.Wakeup();
				}
				else
				{
					Ground();
				}
				return;
			}
			bool flag2 = flag || ((BaseAI)_ai).IsAlerted() || (Object)(object)((BaseAI)_ai).GetTargetCreature() != (Object)null || _character.InAttack();
			_quiet = (flag2 ? 0f : (_quiet + 1f));
			if (_quiet >= 20f)
			{
				_quiet = 0f;
				_ai.Sleep();
			}
		}

		private void Ground()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)this).transform.position;
			float groundHeight = default(float);
			if (!ZoneSystem.instance.GetSolidHeight(position, ref groundHeight, 2))
			{
				groundHeight = ZoneSystem.instance.GetGroundHeight(position);
			}
			if (position.y - groundHeight > 0.05f)
			{
				position.y = groundHeight;
				((Component)this).transform.position = position;
				_character.m_body.position = position;
			}
		}

		private void ShowCrust(bool asleep)
		{
			if (_crustShown == asleep)
			{
				return;
			}
			_crustShown = asleep;
			foreach (GameObject item in _crust)
			{
				if ((Object)(object)item != (Object)null)
				{
					item.SetActive(asleep);
				}
			}
		}
	}
	public static class RimeWavePath
	{
		public const float Step = 2f;

		private const float ClimbCost = 3f;

		private const float DropGain = 0.5f;

		private const int MaxSteps = 25;

		public static List<Vector3> Trace(Vector3 start, Vector3 direction, float length)
		{
			//IL_0019: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (m