Decompiled source of Ragnarok v0.0.1

plugins\Ragnarok.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using Explosives;
using FireSpreads;
using HarmonyLib;
using Jotunn;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Ragnarok.Commands;
using Ragnarok.Mono;
using Ragnarok.States;
using SoftReferenceableAssets;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Ragnarok")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Ragnarok")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.0")]
namespace FireSpreads
{
	public class IgniteDestroy : MonoBehaviour
	{
		public float m_fireresists = 1f;

		public bool m_eternalfire = true;

		public float m_time;

		public WearNTear m_wear;

		public void Awake()
		{
			m_wear = ((Component)this).GetComponent<WearNTear>();
			if ((Object)(object)m_wear != (Object)null && (Object)(object)m_wear.m_nview != (Object)null)
			{
				m_wear.m_nview.ClaimOwnership();
			}
		}

		public void Update()
		{
			m_time -= Time.deltaTime;
			if (!(m_time > 0f) && !((Object)(object)m_wear == (Object)null) && !((Object)(object)m_wear.m_nview == (Object)null) && m_wear.m_nview.IsOwner())
			{
				if (m_eternalfire)
				{
					FireController.Instance.SetFire<WearNTear>(m_wear, m_wear.m_nview, 1f, m_eternalfire);
				}
				else
				{
					FireController.Instance.SetFireResist(m_wear.m_nview, m_fireresists, true);
				}
				m_wear.Destroy((HitData)null, false);
			}
		}
	}
}
namespace Ragnarok
{
	public struct HeightmapKey : IEquatable<HeightmapKey>
	{
		public Heightmap m_heightmap;

		public float m_x;

		public float m_y;

		public HeightmapKey(Heightmap heightmap, float x, float y)
		{
			m_heightmap = heightmap;
			m_x = x;
			m_y = y;
		}

		public override bool Equals(object obj)
		{
			if (obj is HeightmapKey other)
			{
				return Equals(other);
			}
			return false;
		}

		public bool Equals(HeightmapKey other)
		{
			if (EqualityComparer<Heightmap>.Default.Equals(m_heightmap, other.m_heightmap) && m_x == other.m_x)
			{
				return m_y == other.m_y;
			}
			return false;
		}

		public override int GetHashCode()
		{
			return ((17 * 31 + (((Object)(object)m_heightmap != (Object)null) ? ((object)m_heightmap).GetHashCode() : 0)) * 31 + m_x.GetHashCode()) * 31 + m_y.GetHashCode();
		}

		public override string ToString()
		{
			return $"HeightmapKey {{ Heightmap = {m_heightmap}, X = {m_x}, Y = {m_y} }}";
		}
	}
	public class RagnarokCrack : MonoBehaviour
	{
		public int m_seed;

		public ZNetView m_view;

		public bool m_paintupdated;

		public int m_crackWidth = 7;

		public int m_crackDepth = -4;

		public List<Vector2Int> m_crackPath = new List<Vector2Int>();

		public static Random m_seededRandom;

		private void Awake()
		{
			//IL_0013: 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)
			m_view = ((Component)this).GetComponent<ZNetView>();
			m_seed = (int)(((Component)this).transform.position.x + ((Component)this).transform.position.y);
			m_crackPath = CreateCrackPath(m_seed);
		}

		public void Update()
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)m_view == (Object)null || !m_view.IsValid())
			{
				return;
			}
			if (!m_view.GetZDO().GetBool("ragnarok_cracked", false) && m_view.IsOwner())
			{
				ApplyCrack();
			}
			if (m_paintupdated)
			{
				return;
			}
			List<Heightmap> list = new List<Heightmap>();
			Heightmap.FindHeightmap(((Component)this).transform.position, 1f, list);
			foreach (Heightmap item in list)
			{
				TerrainComp andCreateTerrainCompiler = item.GetAndCreateTerrainCompiler();
				UpdateHeightmapPaint(item, ref andCreateTerrainCompiler.m_levelDelta, andCreateTerrainCompiler.m_paintMask);
				item.Poke(false);
			}
			m_paintupdated = true;
		}

		public void UpdateHeightmapPaint(Heightmap hmap, ref float[] heights, Color[] paint)
		{
			//IL_0016: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			int num = 64;
			foreach (Vector2Int item in m_crackPath)
			{
				Vector2Int current = item;
				for (int i = -m_crackWidth / 2; i <= m_crackWidth / 2; i++)
				{
					int num2 = ((Vector2Int)(ref current)).x + i;
					if (num2 <= 0 || num2 >= num - 1)
					{
						continue;
					}
					int num3 = ((Vector2Int)(ref current)).y * (num + 1) + num2;
					if (num3 < 0 || num3 >= heights.Length)
					{
						continue;
					}
					Color32 biomeColor = Heightmap.GetBiomeColor(hmap.m_cornerBiomes[0]);
					float x = DUtils.SmoothStep(0f, 1f, (float)((double)num2 / (double)num));
					float y = DUtils.SmoothStep(0f, 1f, (float)((double)((Vector2Int)(ref current)).y / (double)num));
					HeightmapKey key = new HeightmapKey(hmap, x, y);
					Ragnarok.s_biomeColors[key] = Color32.op_Implicit(Color32.Lerp(biomeColor, new Color32(byte.MaxValue, (byte)0, (byte)0, byte.MaxValue), 1f));
					for (int j = -1; j <= 1; j++)
					{
						for (int k = -1; k <= 1; k++)
						{
							if (j != 0 || k != 0)
							{
								Ragnarok.UpdateBiomeColorAndPaint(hmap, Color32.op_Implicit(biomeColor), j, k, num, paint);
							}
						}
					}
				}
			}
			m_paintupdated = true;
		}

		public void ApplyCrack()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			m_view.GetZDO().Set("ragnarok_cracked", true);
			List<Heightmap> list = new List<Heightmap>();
			Heightmap.FindHeightmap(((Component)this).transform.position, 1f, list);
			foreach (Heightmap item in list)
			{
				TerrainComp andCreateTerrainCompiler = item.GetAndCreateTerrainCompiler();
				CreateCrack(m_seed, andCreateTerrainCompiler.m_hmap, ref andCreateTerrainCompiler.m_levelDelta, ref andCreateTerrainCompiler.m_modifiedHeight, ref andCreateTerrainCompiler.m_paintMask, ref andCreateTerrainCompiler.m_modifiedPaint, 7, -4f);
				if (!((Object)(object)m_view == (Object)null) && m_view.IsOwner())
				{
					andCreateTerrainCompiler.Save();
					andCreateTerrainCompiler.m_hmap.Poke(false);
					andCreateTerrainCompiler.m_nview.GetZDO().IncreaseDataRevision();
				}
			}
			ClutterSystem instance = ClutterSystem.instance;
			if (instance != null)
			{
				instance.ResetGrass(((Component)Player.m_localPlayer).transform.position, 1000f);
			}
		}

		public static List<Vector2Int> CreateCrackPath(int seed)
		{
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			int num = 64;
			m_seededRandom = new Random(seed);
			int num2 = m_seededRandom.Next(0, 4);
			int num3 = 0;
			int num4 = 0;
			switch (num2)
			{
			case 0:
				num3 = m_seededRandom.Next(1, num - 1);
				num4 = 1;
				break;
			case 1:
				num3 = m_seededRandom.Next(1, num - 1);
				num4 = num - 1;
				break;
			case 2:
				num3 = 1;
				num4 = m_seededRandom.Next(1, num - 1);
				break;
			case 3:
				num3 = num - 1;
				num4 = m_seededRandom.Next(1, num - 1);
				break;
			}
			float num5 = (float)num / 2f;
			float num6 = Mathf.Atan2((float)num / 2f - (float)num4, num5 - (float)num3);
			List<Vector2Int> list = new List<Vector2Int>();
			Vector2Int item = default(Vector2Int);
			((Vector2Int)(ref item))..ctor(num3, num4);
			list.Add(item);
			while (((Vector2Int)(ref item)).x >= 1 && ((Vector2Int)(ref item)).x <= num - 1 && ((Vector2Int)(ref item)).y >= 1 && ((Vector2Int)(ref item)).y <= num - 1)
			{
				if (m_seededRandom.NextDouble() < 0.10000000149011612)
				{
					num6 += (float)(m_seededRandom.NextDouble() * 3.1415927410125732 - 1.5707963705062866);
				}
				int num7 = ((Vector2Int)(ref item)).x + Mathf.RoundToInt(Mathf.Cos(num6));
				int num8 = ((Vector2Int)(ref item)).y + Mathf.RoundToInt(Mathf.Sin(num6));
				num7 = Mathf.Clamp(num7, 1, num - 1);
				num8 = Mathf.Clamp(num8, 1, num - 1);
				((Vector2Int)(ref item))..ctor(num7, num8);
				list.Add(item);
				if (num7 == 1 || num7 == num - 1 || num8 == 1 || num8 == num - 1)
				{
					break;
				}
			}
			return list;
		}

		public void CreateCrack(int seed, Heightmap hmap, ref float[] heights, ref bool[] modifiedHeights, ref Color[] paint, ref bool[] modifiedPaint, int crackWidth = 5, float crackDepth = -20f, float crackNoise = 0.5f)
		{
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			m_paintupdated = true;
			int num = 64;
			Random random = new Random(seed);
			int num2 = random.Next(0, 4);
			int num3 = 0;
			int num4 = 0;
			switch (num2)
			{
			case 0:
				num3 = random.Next(1, num - 1);
				num4 = 1;
				break;
			case 1:
				num3 = random.Next(1, num - 1);
				num4 = num - 1;
				break;
			case 2:
				num3 = 1;
				num4 = random.Next(1, num - 1);
				break;
			case 3:
				num3 = num - 1;
				num4 = random.Next(1, num - 1);
				break;
			}
			float num5 = (float)num / 2f;
			float num6 = Mathf.Atan2((float)num / 2f - (float)num4, num5 - (float)num3);
			List<Vector2Int> list = new List<Vector2Int>();
			Vector2Int item = default(Vector2Int);
			((Vector2Int)(ref item))..ctor(num3, num4);
			list.Add(item);
			while (((Vector2Int)(ref item)).x >= 1 && ((Vector2Int)(ref item)).x <= num - 1 && ((Vector2Int)(ref item)).y >= 1 && ((Vector2Int)(ref item)).y <= num - 1)
			{
				if (random.NextDouble() < 0.10000000149011612)
				{
					num6 += (float)(random.NextDouble() * 3.1415927410125732 - 1.5707963705062866);
				}
				int num7 = ((Vector2Int)(ref item)).x + Mathf.RoundToInt(Mathf.Cos(num6));
				int num8 = ((Vector2Int)(ref item)).y + Mathf.RoundToInt(Mathf.Sin(num6));
				num7 = Mathf.Clamp(num7, 1, num - 1);
				num8 = Mathf.Clamp(num8, 1, num - 1);
				((Vector2Int)(ref item))..ctor(num7, num8);
				list.Add(item);
				if (num7 == 1 || num7 == num - 1 || num8 == 1 || num8 == num - 1)
				{
					break;
				}
			}
			foreach (Vector2Int item2 in list)
			{
				Vector2Int current = item2;
				for (int i = -crackWidth / 2; i <= crackWidth / 2; i++)
				{
					int num9 = ((Vector2Int)(ref current)).x + i;
					if (num9 <= 0 || num9 >= num - 1)
					{
						continue;
					}
					int num10 = ((Vector2Int)(ref current)).y * (num + 1) + num9;
					if (num10 < 0 || num10 >= heights.Length)
					{
						continue;
					}
					float num11 = (float)(random.NextDouble() * 2.0 - 1.0) * crackNoise;
					heights[num10] += crackDepth + num11;
					modifiedHeights[num10] = true;
					paint[num10].a = 1f;
					modifiedPaint[num10] = true;
					Color32 biomeColor = Heightmap.GetBiomeColor(hmap.m_cornerBiomes[0]);
					float x = DUtils.SmoothStep(0f, 1f, (float)((double)num9 / (double)num));
					float y = DUtils.SmoothStep(0f, 1f, (float)((double)((Vector2Int)(ref current)).y / (double)num));
					HeightmapKey key = new HeightmapKey(hmap, x, y);
					Ragnarok.s_biomeColors[key] = Color32.op_Implicit(Color32.Lerp(biomeColor, new Color32(byte.MaxValue, (byte)0, (byte)0, byte.MaxValue), 1f));
					for (int j = -1; j <= 1; j++)
					{
						for (int k = -1; k <= 1; k++)
						{
							if (j != 0 || k != 0)
							{
								Ragnarok.UpdateBiomeColorAndPaint(hmap, Color32.op_Implicit(biomeColor), j, k, num, paint);
							}
						}
					}
				}
			}
		}
	}
	public class RigifyMe : MonoBehaviour
	{
		private ZNetView m_nview;

		private bool m_rigified;

		public void Awake()
		{
			m_nview = ((Component)this).GetComponent<ZNetView>();
			if ((Object)(object)m_nview == (Object)null)
			{
				m_nview = ((Component)this).GetComponentInChildren<ZNetView>();
			}
			if ((Object)(object)m_nview != (Object)null)
			{
				try
				{
					m_nview.Register("Rigify", (Action<long>)Rigify);
				}
				catch
				{
				}
			}
		}

		public void Rigify(long sender)
		{
			DoIt();
		}

		public void RigifyNetwork()
		{
			if (!m_rigified && (Object)(object)m_nview != (Object)null)
			{
				m_nview.InvokeRPC(ZNetView.Everybody, "Rigify", Array.Empty<object>());
			}
		}

		public void DoIt()
		{
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			if (m_rigified)
			{
				return;
			}
			m_rigified = true;
			MeshCollider[] componentsInChildren = ((Component)this).gameObject.GetComponentsInChildren<MeshCollider>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].convex = true;
			}
			Collider[] componentsInChildren2 = ((Component)this).gameObject.GetComponentsInChildren<Collider>();
			foreach (Collider val in componentsInChildren2)
			{
				if (((Component)val).gameObject.layer == 16 || ((Component)val).gameObject.layer == 12 || ((Component)val).gameObject.layer == 23 || ((Component)val).gameObject.layer == 20)
				{
					((Component)val).gameObject.layer = 0;
				}
			}
			GameObject gameObject = ((Component)this).gameObject;
			TerrainComp component = ((Component)this).gameObject.GetComponent<TerrainComp>();
			if (Object.op_Implicit((Object)(object)component?.m_hmap))
			{
				gameObject = ((Component)component.m_hmap).gameObject;
			}
			Ragnarok.AddRigidbody(gameObject);
			Ragnarok.ActivateRigidBody(gameObject);
			ImpactEffect obj = gameObject.AddComponent<ImpactEffect>();
			obj.m_minVelocity = 1f;
			obj.m_maxVelocity = 5f;
			obj.m_damagePlayers = true;
			obj.m_damageToSelf = false;
			obj.m_damageFish = true;
			obj.m_damages.m_blunt = 100f;
			obj.m_damages.m_chop = 100f;
			obj.m_damages.m_pickaxe = 100f;
			obj.m_interval = 0.25f;
			obj.m_toolTier = 0;
			obj.m_hitType = (HitType)20;
			obj.m_triggerMask = default(LayerMask);
			obj.m_triggerMask = LayerMask.op_Implicit(-1);
			WearNTear component2 = gameObject.GetComponent<WearNTear>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.m_noSupportWear = false;
			}
			if (!((Object)(object)component != (Object)null))
			{
				return;
			}
			gameObject.AddComponent<TerrainAnimation>();
			gameObject.AddComponent<TriggerEventCaller>();
			MeshCollider component3 = gameObject.GetComponent<MeshCollider>();
			if ((Object)(object)component3 == (Object)null)
			{
				Debug.LogError((object)("No MeshCollider found on " + ((Object)this).name));
				return;
			}
			MeshCollider obj2 = gameObject.AddComponent<MeshCollider>();
			obj2.sharedMesh = component3.sharedMesh;
			obj2.convex = true;
			((Collider)obj2).isTrigger = true;
			ZSyncTransform obj3 = ((Component)this).gameObject.AddComponent<ZSyncTransform>();
			if ((Object)(object)obj3 == (Object)null)
			{
				((Component)this).gameObject.AddComponent<ZSyncTransform>();
			}
			obj3.m_syncRotation = true;
		}
	}
	public class RagnarokController : MonoBehaviour
	{
		public int m_state;

		public static Vector3 s_initialGravity = new Vector3(0f, -20f, 0f);

		public Vector3 m_gravity = s_initialGravity;

		public ZNetView m_view;

		public float m_updateTimer;

		public bool m_owner;

		public float m_elapsedTime;

		public static Quaternion s_rotationToTargetTop = Quaternion.identity;

		public FallStateMachine m_fallStateMachine;

		public HashSet<GameObject> m_roofs = new HashSet<GameObject>();

		public Dictionary<GameObject, Container> m_containers = new Dictionary<GameObject, Container>();

		public static RagnarokController s_instance;

		public bool m_noGrass;

		public bool m_isDead;

		public void Awake()
		{
			s_instance = this;
		}

		public void Update()
		{
			if (m_state > 0)
			{
				m_elapsedTime += Time.deltaTime;
				m_updateTimer -= Time.deltaTime;
				if (m_owner && m_updateTimer < 0f)
				{
					m_updateTimer = 5f;
					ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "UpdateRagnarok", new object[2] { m_state, m_elapsedTime });
				}
			}
		}

		public bool IsGod()
		{
			if (m_fallStateMachine != null && m_fallStateMachine.m_currentState != null)
			{
				return m_fallStateMachine.m_currentState.IsGod();
			}
			return false;
		}

		public bool CheckUnderword()
		{
			if (m_fallStateMachine != null && m_fallStateMachine.m_currentState != null)
			{
				return m_fallStateMachine.m_currentState.CheckUnderword();
			}
			return false;
		}

		public void PrepareQueuedEnvironment(EnvSetup env)
		{
			if (m_fallStateMachine != null && m_fallStateMachine.m_currentState != null)
			{
				m_fallStateMachine.m_currentState.PrepareQueuedEnvironment(env);
			}
		}

		public void FixedUpdate()
		{
			if (m_state != 0)
			{
				m_fallStateMachine.Update();
			}
		}

		public void DestroyInstance(GameObject go)
		{
			m_roofs.Remove(go);
			m_containers.Remove(go);
		}

		public List<Container> GetExplosiveContainers()
		{
			List<Container> list = new List<Container>();
			foreach (KeyValuePair<GameObject, Container> container in m_containers)
			{
				if (!container.Value.m_nview.IsOwner())
				{
					continue;
				}
				foreach (ItemData item in container.Value.m_inventory.m_inventory)
				{
					if (Explosives.s_explosives.Contains(((Object)item.m_dropPrefab).name))
					{
						list.Add(container.Value);
						break;
					}
				}
			}
			return list;
		}
	}
	[BepInPlugin("org.bepinex.plugins.bid.Ragnarok", "Ragnarok", "0.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class Ragnarok : BaseUnityPlugin
	{
		public const string PluginGUID = "org.bepinex.plugins.bid.Ragnarok";

		public const string PluginName = "Ragnarok";

		public const string PluginVersion = "0.0.1";

		private readonly Harmony harmony = new Harmony("org.bepinex.plugins.bid.Ragnarok");

		public static bool s_init = false;

		public static readonly int s_StateHash = StringExtensionMethods.GetStableHashCode("RagnarokState");

		public static ConfigEntry<float> FallSpeedConfig;

		public static ConfigEntry<float> NoCutStateDurationConfig;

		public static ConfigEntry<float> CutStateDurationConfig;

		public static ConfigEntry<Vector3> CutStateGravityConfig;

		public static ConfigEntry<float> InitialFallStateDurationConfig;

		public static ConfigEntry<Vector3> InitialFallStateGravityConfig;

		public static ConfigEntry<float> HitStateDurationConfig;

		public static ConfigEntry<Vector3> HitStateGavityConfig;

		public static ConfigEntry<float> RotationStateDurationConfig;

		public static ConfigEntry<float> CrackStateDurationConfig;

		public static ConfigEntry<float> PurificationStateDurationConfig;

		public static ConfigEntry<float> DesintegratorRadiusConfig;

		public static ConfigEntry<float> RandomSpawnTimerConfig;

		public static ConfigEntry<float> CrackTimerConfig;

		public static ConfigEntry<float> EndStateDurationConfig;

		public static GameObject s_sfxTreeHit = null;

		public static GameObject s_vfxTreeHit = null;

		public static GameObject s_sfxTreeFall = null;

		public static SimulateFlyingAway s_flyaway = null;

		public static readonly Dictionary<HeightmapKey, Color> s_biomeColors = new Dictionary<HeightmapKey, Color>();

		public static BiomeEnvSetup s_miomeSetupMeadows = null;

		public static EnvSetup s_envClear = null;

		public static EnvSetup s_envAsh = null;

		public static EnvSetup s_envStorm = null;

		public static AudioClip s_ambientFallCalm = null;

		public static AudioClip s_ambientFallIntsense = null;

		public static Dictionary<GameObject, Vector3> s_randomSpawns = new Dictionary<GameObject, Vector3>();

		public static GameObject s_psysDebris;

		private void Awake()
		{
			Logger.LogInfo((object)"Ragnarok has landed");
			CreateConfigValues();
			CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new RagnarokCommand());
			PrefabManager.OnVanillaPrefabsAvailable += AddClonedItems;
			harmony.PatchAll();
		}

		private void CreateConfigValues()
		{
			//IL_002f: 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_003c: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected O, but got Unknown
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Expected O, but got Unknown
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Expected O, but got Unknown
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Expected O, but got Unknown
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Expected O, but got Unknown
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Expected O, but got Unknown
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Expected O, but got Unknown
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Expected O, but got Unknown
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Expected O, but got Unknown
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Expected O, but got Unknown
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Expected O, but got Unknown
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Expected O, but got Unknown
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Expected O, but got Unknown
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Expected O, but got Unknown
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Expected O, but got Unknown
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Expected O, but got Unknown
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Expected O, but got Unknown
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Expected O, but got Unknown
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Expected O, but got Unknown
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Expected O, but got Unknown
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0328: Expected O, but got Unknown
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Expected O, but got Unknown
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0367: Expected O, but got Unknown
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0394: Unknown result type (might be due to invalid IL or missing references)
			//IL_039c: Expected O, but got Unknown
			//IL_039c: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a6: Expected O, but got Unknown
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03db: Expected O, but got Unknown
			//IL_03db: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e5: Expected O, but got Unknown
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
			FallSpeedConfig = ((BaseUnityPlugin)this).Config.Bind<float>("1 - General", "FallSpeed", -9.81f, new ConfigDescription("rate to rigify in purification state", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			DesintegratorRadiusConfig = ((BaseUnityPlugin)this).Config.Bind<float>("1 - General", "DesintegratorBallRadius", 0.5f, new ConfigDescription("radius of the desintegration ball - internal instrument to drive destruction", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			RandomSpawnTimerConfig = ((BaseUnityPlugin)this).Config.Bind<float>("1 - General", "RandomSpawnTimer", 15f, new ConfigDescription("random spawns (meteor/lightning) all x seconds", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			NoCutStateDurationConfig = ((BaseUnityPlugin)this).Config.Bind<float>("2 - NoCutState", "NoCutStateDuration", 20f, new ConfigDescription("NoCutState length in seconds", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			CutStateDurationConfig = ((BaseUnityPlugin)this).Config.Bind<float>("3 - CutState", "CutStateDuration", 0.35f, new ConfigDescription("NoCutState length in seconds", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			CutStateGravityConfig = ((BaseUnityPlugin)this).Config.Bind<Vector3>("3 - CutState", "CutStateGravity", new Vector3(0f, 100f, 0f), new ConfigDescription("CutStore gravity", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			InitialFallStateDurationConfig = ((BaseUnityPlugin)this).Config.Bind<float>("4 - InitialFallState", "InitialFallStateDuration", 120f, new ConfigDescription("InitialFallState length in seconds", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			InitialFallStateGravityConfig = ((BaseUnityPlugin)this).Config.Bind<Vector3>("4 - InitialFallState", "InitialFallStateGravity", new Vector3(0.7f, -5f, 0f), new ConfigDescription("InitialFallState gravity", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			HitStateDurationConfig = ((BaseUnityPlugin)this).Config.Bind<float>("5 - HitState", "HitStateDuration", 0.5f, new ConfigDescription("HitState length in seconds", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			HitStateGavityConfig = ((BaseUnityPlugin)this).Config.Bind<Vector3>("5 - HitState", "HitStateGravity", new Vector3(50f, 50f, 0f), new ConfigDescription("HitState gravity", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			RotationStateDurationConfig = ((BaseUnityPlugin)this).Config.Bind<float>("6 - RotationState", "RotationStateDuration", 300f, new ConfigDescription("RotationState length in seconds", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			CrackStateDurationConfig = ((BaseUnityPlugin)this).Config.Bind<float>("7 - CrackState", "CrackStateDuration", 150f, new ConfigDescription("CrackState length in seconds", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			CrackTimerConfig = ((BaseUnityPlugin)this).Config.Bind<float>("7 - CrackState", "CrackTimer", 12f, new ConfigDescription("create cracks all x seconds", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			PurificationStateDurationConfig = ((BaseUnityPlugin)this).Config.Bind<float>("8 - PurificationState", "PurificationStateDuration", 150f, new ConfigDescription("PurificationState length in seconds", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			EndStateDurationConfig = ((BaseUnityPlugin)this).Config.Bind<float>("9 - EndState", "EndStateDuration", 100f, new ConfigDescription("EndState length in seconds", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			SynchronizationManager.OnConfigurationSynchronized += delegate
			{
			};
		}

		public static void Init()
		{
			//IL_004a: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			if (!s_init)
			{
				s_init = true;
				AddRigidbody2Prefabs();
				PrepareEnvironments();
				AddRigidbody2Dungeons();
				CrackState.s_ashed = 0f;
				s_randomSpawns.Add(PrefabManager.Instance.GetPrefab("ragnarok_meteor"), new Vector3(0f, 20f, 0f));
				s_randomSpawns.Add(PrefabManager.Instance.GetPrefab("ragnarok_meteor2"), new Vector3(0f, 20f, 0f));
				s_randomSpawns.Add(PrefabManager.Instance.GetPrefab("ragnarok_lightning"), new Vector3(0f, 0f, 0f));
			}
		}

		public static void PreparePrefab(GameObject prefab)
		{
			prefab.AddComponent<RigifyMe>();
		}

		public static Bounds CalculateCombinedBounds(Transform transform)
		{
			//IL_000a: 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_0075: 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_0035: 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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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)
			Renderer[] componentsInChildren = (Renderer[])(object)((Component)transform).GetComponentsInChildren<MeshRenderer>();
			Renderer[] array = componentsInChildren;
			Bounds result = default(Bounds);
			((Bounds)(ref result))..ctor(Vector3.zero, Vector3.zero);
			componentsInChildren = array;
			foreach (Renderer val in componentsInChildren)
			{
				if (((Component)val).gameObject.activeSelf)
				{
					Bounds bounds = val.bounds;
					if (((Bounds)(ref result)).center == Vector3.zero && ((Bounds)(ref result)).size == Vector3.zero)
					{
						result = bounds;
					}
					else
					{
						((Bounds)(ref result)).Encapsulate(bounds);
					}
				}
			}
			return result;
		}

		public static void AddRigidbody(GameObject prefab)
		{
			//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_0041: 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_005a: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)prefab.GetComponent<Rigidbody>() != (Object)null) && !((Object)(object)prefab.GetComponent<Location>() != (Object)null) && !((Object)(object)prefab.GetComponent<LocationProxy>() != (Object)null))
			{
				float num = 50f;
				Bounds val = CalculateCombinedBounds(prefab.transform);
				float num2 = ((Bounds)(ref val)).size.x * ((Bounds)(ref val)).size.y * ((Bounds)(ref val)).size.z * num;
				if (num2 >= 0f)
				{
					num2 = 10f;
				}
				Rigidbody val2 = prefab.AddComponent<Rigidbody>();
				val2.isKinematic = true;
				if ((Object)(object)prefab.GetComponent<DungeonGenerator>() != (Object)null)
				{
					num2 = 100000f;
					val2.drag = 25f;
				}
				val2.mass = num2;
			}
		}

		public static void AddRigidbody2Prefabs()
		{
			foreach (string prefabName in ZNetScene.instance.GetPrefabNames())
			{
				if (!prefabName.StartsWith("vfx") && !prefabName.StartsWith("sfx") && !prefabName.Equals("Valkyrie"))
				{
					GameObject prefab = PrefabManager.Instance.GetPrefab(prefabName);
					if (!((Object)(object)prefab.GetComponent<Rigidbody>() != (Object)null))
					{
						PreparePrefab(prefab);
					}
				}
			}
			GameObject prefab2 = PrefabManager.Instance.GetPrefab("YggdrasilBranch");
			PreparePrefab(prefab2);
			s_flyaway = prefab2.AddComponent<SimulateFlyingAway>();
			s_flyaway.m_minScale = 0.005f;
			s_flyaway.m_maxScale = 1f;
			s_flyaway.m_scalingSpeed = 0f;
			s_flyaway.m_rotationSpeed = 0f;
			s_sfxTreeHit = PrefabManager.Instance.GetPrefab("sfx_tree_hit");
			s_sfxTreeFall = PrefabManager.Instance.CreateClonedPrefab("sfx_worldfall_tree_fall", "sfx_tree_fall");
			ZSFX component = s_sfxTreeFall.GetComponent<ZSFX>();
			AudioClip val = component.m_audioClips[3];
			component.m_audioClips = (AudioClip[])(object)new AudioClip[1] { val };
			s_vfxTreeHit = PrefabManager.Instance.GetPrefab("vfx_yggashoot_cut");
		}

		public static void AddRigidbody2Location(ZoneLocation location)
		{
			//IL_0001: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			_ = location.m_prefab;
			if (location.m_prefab.IsValid)
			{
				location.m_prefab.Load();
				location.m_prefab.HoldReference();
				ZNetView[] componentsInChildren = location.m_prefab.Asset.GetComponentsInChildren<ZNetView>();
				foreach (ZNetView obj in componentsInChildren)
				{
					Vector3 localPosition = ((Component)obj).transform.localPosition;
					PreparePrefab(((Component)obj).gameObject);
					((Component)obj).transform.localPosition = localPosition;
				}
			}
		}

		public static void AddRigidbody2Dungeons()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			foreach (RoomData room in DungeonDB.instance.m_rooms)
			{
				room.m_prefab.Load();
				room.m_prefab.HoldReference();
				MeshRenderer[] componentsInChildren = room.m_prefab.Asset.GetComponentsInChildren<MeshRenderer>();
				foreach (MeshRenderer val in componentsInChildren)
				{
					if (!IsDungeonPiece(((Component)val).transform))
					{
						PreparePrefab(((Component)val).gameObject);
					}
				}
			}
		}

		public static bool IsDungeonPiece(Transform transform)
		{
			if (((Object)transform).name.StartsWith("props") || ((Object)transform).name.StartsWith("Props"))
			{
				return false;
			}
			if ((Object)(object)transform.parent != (Object)null)
			{
				return IsDungeonPiece(transform.parent);
			}
			return true;
		}

		public static Transform GetTopmostTransform(Transform obj)
		{
			Transform val = obj;
			while ((Object)(object)val.parent != (Object)null)
			{
				val = val.parent;
			}
			return val;
		}

		public static void ActivateRigidBody(GameObject prefab)
		{
			StaticPhysics[] componentsInChildren = prefab.GetComponentsInChildren<StaticPhysics>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.Destroy((Object)(object)componentsInChildren[i]);
			}
			Rigidbody component = prefab.GetComponent<Rigidbody>();
			if ((Object)(object)component != (Object)null)
			{
				if ((Object)(object)prefab.GetComponent<Heightmap>() != (Object)null)
				{
					component.isKinematic = true;
				}
				else
				{
					component.isKinematic = false;
				}
			}
			ZNetView component2 = prefab.GetComponent<ZNetView>();
			ZSyncTransform val = null;
			if ((Object)(object)component2 != (Object)null)
			{
				val = prefab.GetComponent<ZSyncTransform>();
				if ((Object)(object)val == (Object)null)
				{
					val = prefab.AddComponent<ZSyncTransform>();
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				val.m_syncPosition = true;
				val.m_syncRotation = true;
				val.m_syncBodyVelocity = true;
			}
		}

		public static void UpdateRagnarok(long sender, int state, float time)
		{
			//IL_0039: 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)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			RagnarokController s_instance = RagnarokController.s_instance;
			if (s_instance.m_state == 0 && state == 1)
			{
				s_instance.m_fallStateMachine = new FallStateMachine();
				NoCutState noCutState = new NoCutState(NoCutStateDurationConfig.Value);
				noCutState.AddNextState(new CutState(CutStateGravityConfig.Value, CutStateDurationConfig.Value)).AddNextState(new InitialFallState(InitialFallStateGravityConfig.Value, InitialFallStateDurationConfig.Value)).AddNextState(new HitState(HitStateGavityConfig.Value, HitStateDurationConfig.Value))
					.AddNextState(new RotationState(RotationStateDurationConfig.Value))
					.AddNextState(new CrackState(CrackStateDurationConfig.Value))
					.AddNextState(new PurificationState(PurificationStateDurationConfig.Value))
					.AddNextState(new EndState(EndStateDurationConfig.Value));
				s_instance.m_fallStateMachine.ChangeState(noCutState);
			}
			s_instance.m_state = state;
			float num = time - s_instance.m_elapsedTime;
			if (num > 0f)
			{
				s_instance.m_elapsedTime += Mathf.Min(num, Time.deltaTime * 5f);
				MonoBehaviour.print((object)$"Compensating elapsed time by {Mathf.Min(num, Time.deltaTime * 5f)} (behind by {num})");
			}
		}

		public static void PrepareEnvironments()
		{
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			s_miomeSetupMeadows = EnvMan.instance.GetBiomeEnvSetup((Biome)1);
			foreach (EnvEntry environment in s_miomeSetupMeadows.m_environments)
			{
				if (environment.m_env.m_name.Equals("Clear"))
				{
					s_envClear = GetEnvSetupClone(environment.m_env, "worldfall_cut");
					s_envClear.m_musicDay = "boss_fader";
					s_envClear.m_musicEvening = "boss_fader";
					s_envClear.m_musicMorning = "boss_fader";
					s_envClear.m_musicNight = "boss_fader";
					s_envClear.m_name = "worldfall_cut";
				}
			}
			foreach (EnvEntry environment2 in EnvMan.instance.GetBiomeEnvSetup((Biome)32).m_environments)
			{
				if (environment2.m_env.m_name.Equals("Ashlands_ashrain"))
				{
					s_ambientFallCalm = environment2.m_env.m_ambientLoop;
					s_psysDebris = environment2.m_env.m_psystems[0];
					s_psysDebris.transform.localRotation = Quaternion.Euler(180f, 0f, 0f);
					s_psysDebris.transform.localPosition = new Vector3(0f, 9f, 0f);
					ParticleSystem[] componentsInChildren = s_psysDebris.GetComponentsInChildren<ParticleSystem>();
					for (int i = 0; i < componentsInChildren.Length; i++)
					{
						MainModule main = componentsInChildren[i].main;
						((MainModule)(ref main)).startSpeedMultiplier = 2f;
					}
					s_envAsh = GetEnvSetupClone(environment2.m_env, "worldfall_fall");
					s_envAsh.m_name = "worldfall_fall";
					s_envAsh.m_musicDay = "boss_fader";
					s_envAsh.m_musicEvening = "boss_fader";
					s_envAsh.m_musicMorning = "boss_fader";
					s_envAsh.m_musicNight = "boss_fader";
				}
				else if (environment2.m_env.m_name.Equals("Ashlands_storm"))
				{
					s_ambientFallIntsense = environment2.m_env.m_ambientLoop;
					s_envStorm = GetEnvSetupClone(environment2.m_env, "worldfall_storm");
					s_envStorm.m_name = "worldfall_storm";
					s_envStorm.m_musicDay = "boss_fader";
					s_envStorm.m_musicEvening = "boss_fader";
					s_envStorm.m_musicMorning = "boss_fader";
					s_envStorm.m_musicNight = "boss_fader";
					s_envStorm.m_lightIntensityDay = 0.5f;
					s_envStorm.m_lightIntensityNight = 0.5f;
					GameObject[] psystems = s_envStorm.m_psystems;
					for (int i = 0; i < psystems.Length; i++)
					{
						psystems[i].transform.localRotation = Quaternion.Euler(180f, 0f, 0f);
					}
				}
			}
			EnvMan.instance.AppendEnvironment(s_envClear);
			EnvMan.instance.AppendEnvironment(s_envAsh);
			EnvMan.instance.AppendEnvironment(s_envStorm);
		}

		public static EnvSetup GetEnvSetupClone(EnvSetup envSetup, string name)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_0013: 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_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_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_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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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_005b: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			return new EnvSetup
			{
				m_name = name,
				m_ambColorDay = envSetup.m_ambColorDay,
				m_ambColorNight = envSetup.m_ambColorNight,
				m_envObject = envSetup.m_envObject,
				m_fogColorDay = envSetup.m_fogColorDay,
				m_fogColorEvening = envSetup.m_fogColorEvening,
				m_fogColorMorning = envSetup.m_fogColorMorning,
				m_fogColorNight = envSetup.m_fogColorNight,
				m_fogColorSunDay = envSetup.m_fogColorSunDay,
				m_fogColorSunEvening = envSetup.m_fogColorSunEvening,
				m_fogColorSunMorning = envSetup.m_fogColorSunMorning,
				m_fogColorSunNight = envSetup.m_fogColorSunNight,
				m_fogDensityDay = envSetup.m_fogDensityDay,
				m_psystems = envSetup.m_psystems
			};
		}

		private void AddClonedItems()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Expected O, but got Unknown
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Expected O, but got Unknown
			GameObject val = new GameObject();
			SphereCollider obj = val.AddComponent<SphereCollider>();
			((Collider)obj).isTrigger = false;
			obj.radius = DesintegratorRadiusConfig.Value;
			((Object)val).name = "desintegratorBall";
			SphereCollider obj2 = val.AddComponent<SphereCollider>();
			((Collider)obj2).isTrigger = true;
			obj2.radius = DesintegratorRadiusConfig.Value;
			val.AddComponent<Rigidbody>().isKinematic = false;
			val.AddComponent<TriggerEventCaller>();
			val.AddComponent<TimedRespawn>().m_prefab = val;
			PrefabManager.Instance.AddPrefab(val);
			GameObject val2 = PrefabManager.Instance.CreateClonedPrefab("desintegratorBallBumpy", val);
			TimedRespawn component = val2.GetComponent<TimedRespawn>();
			component.m_prefab = val2;
			component.m_hightoffset = 5f;
			SphereCollider[] components = val2.GetComponents<SphereCollider>();
			foreach (SphereCollider val3 in components)
			{
				if (!((Collider)val3).isTrigger)
				{
					PhysicMaterial val4 = new PhysicMaterial();
					val4.bounciness = 0.9f;
					val4.frictionCombine = (PhysicMaterialCombine)2;
					val4.bounceCombine = (PhysicMaterialCombine)3;
					((Collider)val3).material = val4;
				}
			}
			PrefabManager.Instance.AddPrefab(val2);
			GameObject val5 = new GameObject();
			((Object)val5).name = "RagnarokCrack";
			PrefabManager.Instance.AddPrefab(val5);
			val5.AddComponent<ZNetView>().m_persistent = true;
			val5.AddComponent<RagnarokCrack>();
			GameObject val6 = PrefabManager.Instance.CreateClonedPrefab("ragnarok_dig", "digg_UnstableLavaRock");
			val6.GetComponent<TerrainOp>().m_settings.m_paintType = (PaintType)1;
			PrefabManager.Instance.AddPrefab(val6);
			GameObject val7 = PrefabManager.Instance.CreateClonedPrefab("ragnarok_meteor", "projectile_ashlandmeteor");
			val7.GetComponent<Projectile>().m_spawnOnHit = val6;
			PrefabManager.Instance.AddPrefab(val7);
			val7 = PrefabManager.Instance.CreateClonedPrefab("ragnarok_meteor2", "projectile_ashlandmeteor2");
			val7.GetComponent<Projectile>().m_spawnOnHit = val6;
			PrefabManager.Instance.AddPrefab(val7);
			val7 = PrefabManager.Instance.CreateClonedPrefab("ragnarok_lightning", "fire_lightning");
			((Component)GetChildrenByName(val7.transform, "AOE_ROD").First()).gameObject.GetComponent<Aoe>().m_spawnOnHitTerrain = val6;
			PrefabManager.Instance.AddPrefab(val7);
			PrefabManager.OnVanillaPrefabsAvailable -= AddClonedItems;
		}

		private void OnDestroy()
		{
			harmony.UnpatchSelf();
		}

		private List<Transform> GetChildrenByName(Transform parent, string name)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			List<Transform> list = new List<Transform>();
			foreach (Transform item in parent)
			{
				Transform val = item;
				if (((Object)val).name == name)
				{
					list.Add(val);
				}
				list.AddRange(GetChildrenByName(val, name));
			}
			return list;
		}

		public static void UpdateBiomeColorAndPaint(Heightmap hmap, Color color, int x, int y, int width, Color[] paint)
		{
			//IL_0049: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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)
			float x2 = DUtils.SmoothStep(0f, 1f, (float)x / (float)width);
			float y2 = DUtils.SmoothStep(0f, 1f, (float)y / (float)width);
			HeightmapKey key = new HeightmapKey(hmap, x2, y2);
			if (!s_biomeColors.ContainsKey(key))
			{
				s_biomeColors[key] = Color32.op_Implicit(Color32.Lerp(Color32.op_Implicit(color), new Color32(byte.MaxValue, (byte)0, (byte)0, byte.MaxValue), 0.75f));
				int num = y * (width + 1) + x;
				if (num >= 0 && num < paint.Length)
				{
					paint[num].a = 0.75f;
				}
			}
		}
	}
	public class TerrainAnimation : MonoBehaviour
	{
		public float rotationSpeed = 2f;

		private Vector3 rotationAxis;

		private void Awake()
		{
			//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_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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			Random random = new Random((int)(((Component)this).transform.position.x * 1000f + ((Component)this).transform.position.z * 1000f));
			float num = (float)(random.NextDouble() * 2.0 - 1.0);
			float num2 = (float)(random.NextDouble() * 2.0 - 1.0);
			float num3 = (float)(random.NextDouble() * 2.0 - 1.0);
			Vector3 val = new Vector3(num, num2, num3);
			rotationAxis = ((Vector3)(ref val)).normalized;
		}

		private void Update()
		{
			//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)
			float num = rotationSpeed * Time.deltaTime;
			((Component)this).transform.Rotate(rotationAxis * num, (Space)0);
		}
	}
	public class TimedRespawn : MonoBehaviour
	{
		public float m_time = 15f;

		public float m_hightoffset;

		public GameObject m_prefab;

		public void Awake()
		{
			m_time = 15f;
		}

		public void Update()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			m_time -= Time.deltaTime;
			if (m_time < 0f)
			{
				Vector3 position = ((Component)Player.m_localPlayer).transform.position;
				float num = 5f;
				float num2 = Random.Range(0f, 360f) * ((float)Math.PI / 180f);
				float num3 = Random.Range(2.5f, num);
				position.x += Mathf.Cos(num2) * num3;
				position.z += Mathf.Sin(num2) * num3;
				position.y += Random.Range(0f + m_hightoffset, 5f + m_hightoffset);
				Object.Instantiate<GameObject>(m_prefab, position, Quaternion.identity);
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}
	}
	public class TriggerEventCaller : MonoBehaviour
	{
		public float m_triggerRadius;

		public float m_last_rigidify;

		private SphereCollider m_triggerCollider;

		public float m_awakeTime;

		public bool m_active;

		private void Awake()
		{
			m_awakeTime = Time.realtimeSinceStartup;
			m_triggerCollider = ((Component)this).gameObject.AddComponent<SphereCollider>();
			((Collider)m_triggerCollider).isTrigger = true;
			m_triggerCollider.radius = m_triggerRadius;
		}

		private void Update()
		{
			if (!m_active && Time.realtimeSinceStartup - m_awakeTime > 1f)
			{
				m_triggerCollider.radius = 1f;
				m_active = true;
			}
		}

		private void OnTriggerEnter(Collider other)
		{
			Transform topmostTransform = Ragnarok.GetTopmostTransform(((Component)other).transform);
			RigifyMe component = ((Component)topmostTransform).GetComponent<RigifyMe>();
			if ((Object)(object)component != (Object)null && (Object)(object)((Component)topmostTransform).GetComponent<TerrainComp>() == (Object)null)
			{
				component.RigifyNetwork();
			}
		}
	}
}
namespace Ragnarok.States
{
	public abstract class AbstractFallState
	{
		protected FallStateMachine m_stateMachine;

		public AbstractFallState m_nextState;

		protected List<GameObject> m_sounds = new List<GameObject>();

		private float m_nextSound;

		protected float m_soundIntervalMin = 0.4f;

		protected float m_soundIntervalMax = 5f;

		private float m_randomSpawnTimer = Ragnarok.RandomSpawnTimerConfig.Value;

		public float m_duration;

		public float m_starttime;

		public AbstractFallState(float duration)
		{
			m_nextSound = Time.realtimeSinceStartup + Random.Range(m_soundIntervalMin, m_soundIntervalMax);
			m_duration = duration;
		}

		public float GetRemainingTime()
		{
			float num = m_starttime + m_duration - m_stateMachine.m_elapsedTime;
			if (num < 0f)
			{
				return 60f;
			}
			return num;
		}

		public AbstractFallState AddNextState(AbstractFallState nextState)
		{
			m_nextState = nextState;
			return nextState;
		}

		public void SetStateMachine(FallStateMachine stateMachine)
		{
			m_stateMachine = stateMachine;
		}

		public virtual void Enter()
		{
			m_starttime = m_stateMachine.m_elapsedTime;
			MonoBehaviour.print((object)$"enter {this} with starttime {m_starttime}");
		}

		public virtual void Update()
		{
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)Player.m_localPlayer == (Object)null))
			{
				m_randomSpawnTimer -= Time.deltaTime;
				if (m_randomSpawnTimer < 0f)
				{
					m_randomSpawnTimer = Ragnarok.RandomSpawnTimerConfig.Value;
					SpawnRandom();
				}
				if (Time.realtimeSinceStartup >= m_nextSound && m_sounds.Count > 0)
				{
					Object.Instantiate<GameObject>(m_sounds[Random.Range(0, m_sounds.Count - 1)], GetRandomPointAround(((Component)Player.m_localPlayer).transform.position, 7f), Quaternion.identity);
					m_nextSound = Time.realtimeSinceStartup + Random.Range(m_soundIntervalMin, m_soundIntervalMax);
				}
			}
		}

		public virtual void SpawnRandom()
		{
			//IL_003f: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			int num = Random.Range(0, Ragnarok.s_randomSpawns.Keys.Count);
			foreach (GameObject key in Ragnarok.s_randomSpawns.Keys)
			{
				if (num == 0)
				{
					Object.Instantiate<GameObject>(key, GetRandomPointAround(((Component)Player.m_localPlayer).transform.position, 20f) + Ragnarok.s_randomSpawns[key], Quaternion.identity);
					break;
				}
				num--;
			}
		}

		public abstract void Exit();

		public virtual bool IsGod()
		{
			return true;
		}

		public virtual bool CheckUnderword()
		{
			return true;
		}

		public void AddHitSounds()
		{
			foreach (Character s_character in Character.s_characters)
			{
				EffectData[] effectPrefabs = s_character.m_hitEffects.m_effectPrefabs;
				foreach (EffectData val in effectPrefabs)
				{
					if (((Object)val.m_prefab).name.ToUpper().StartsWith("SFX"))
					{
						m_sounds.Add(val.m_prefab);
					}
				}
			}
		}

		public void AddDeathSounds()
		{
			foreach (Character s_character in Character.s_characters)
			{
				EffectData[] effectPrefabs = s_character.m_deathEffects.m_effectPrefabs;
				foreach (EffectData val in effectPrefabs)
				{
					if (((Object)val.m_prefab).name.ToUpper().StartsWith("SFX"))
					{
						m_sounds.Add(val.m_prefab);
					}
				}
			}
		}

		private Vector3 GetRandomPointAround(Vector3 center, float radius)
		{
			//IL_0022: 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_0030: 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)
			float num = Random.Range(0f, (float)Math.PI * 2f);
			float num2 = Mathf.Cos(num) * radius;
			float num3 = Mathf.Sin(num) * radius;
			return new Vector3(center.x + num2, center.y, center.z + num3);
		}

		public void RemoveDrops()
		{
			ItemDrop[] array = Object.FindObjectsOfType<ItemDrop>();
			for (int i = 0; i < array.Length; i++)
			{
				ZNetView component = ((Component)array[i]).GetComponent<ZNetView>();
				if (Object.op_Implicit((Object)(object)component) && component.IsValid() && component.IsOwner())
				{
					component.Destroy();
				}
			}
		}

		public virtual void PrepareQueuedEnvironment(EnvSetup env)
		{
			int num = env.m_psystems.Length;
			GameObject[] array = (GameObject[])(object)new GameObject[num + 1];
			for (int i = 0; i < num; i++)
			{
				array[i] = env.m_psystems[i];
			}
			array[num] = Ragnarok.s_psysDebris;
			env.m_psystems = array;
		}
	}
	public class NoCutState : FallState
	{
		public NoCutState(float duration)
			: base(duration)
		{
		}

		public override void Enter()
		{
			base.Enter();
		}

		public override void SpawnRandom()
		{
		}

		public override bool IsGod()
		{
			return false;
		}
	}
	public class PurificationState : CrackState
	{
		private float m_collidertimer;

		private float m_waittime;

		private List<WearNTear> m_wnts;

		public PurificationState(float duration)
			: base(duration)
		{
		}

		public override void Enter()
		{
			base.Enter();
			Reset();
		}

		public void Reset()
		{
			m_wnts = WearNTear.s_allInstances.ToList();
			m_wnts.Sort((WearNTear a, WearNTear b) => ((Component)b).transform.position.y.CompareTo(((Component)a).transform.position.y));
			m_waittime = GetRemainingTime() / (float)m_wnts.Count;
		}

		public override void Update()
		{
			base.Update();
			m_collidertimer -= Time.deltaTime;
			if (!(m_collidertimer <= 0f))
			{
				return;
			}
			m_collidertimer = m_waittime;
			if (m_wnts.Count < 0)
			{
				Reset();
			}
			if (m_wnts.Count > 0)
			{
				WearNTear val = m_wnts.First();
				m_wnts.Remove(val);
				if ((Object)(object)val != (Object)null && val.m_nview.IsValid() && val.m_nview.IsOwner())
				{
					((Component)val).GetComponent<RigifyMe>()?.RigifyNetwork();
				}
			}
		}
	}
	public class CrackState : RotationState
	{
		public float m_cracktimer;

		public static float s_ashed;

		public CrackState(float duration)
			: base(duration)
		{
		}

		public override void Enter()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			base.Enter();
			EnvMan.instance.m_debugEnv = "worldfall_storm";
			GameCamera.instance.AddShake(((Component)Player.m_localPlayer).transform.position, 100f, 2f, false);
		}

		public override void Update()
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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)
			base.Update();
			m_cracktimer -= Time.deltaTime;
			if (m_cracktimer <= 0f)
			{
				m_cracktimer = Ragnarok.CrackTimerConfig.Value;
				s_ashed += 0.05f;
				if (s_ashed > 0.9f)
				{
					s_ashed = 0.9f;
				}
				if ((Object)(object)Player.m_localPlayer != (Object)null)
				{
					Object.Instantiate<GameObject>(PrefabManager.Instance.GetPrefab("RagnarokCrack"), ((Component)Player.m_localPlayer).transform.position, Quaternion.identity);
					GameCamera.instance.AddShake(((Component)Player.m_localPlayer).transform.position, 100f, 2f, false);
				}
			}
		}
	}
	public class CutState : FallState
	{
		public CutState(Vector3 gravity, float duration)
			: base(gravity, duration)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			m_soundIntervalMin = 0.1f;
			m_soundIntervalMax = 0.1f;
		}

		public override void Enter()
		{
			//IL_0052: 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)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			base.Enter();
			foreach (GameObject roof in RagnarokController.s_instance.m_roofs)
			{
				roof.GetComponent<RigifyMe>()?.DoIt();
			}
			Vector3 position = ((Component)Player.m_localPlayer).transform.position;
			position.y += 5f;
			Object.Instantiate<GameObject>(Ragnarok.s_sfxTreeHit, position, Quaternion.identity);
			position.x += 30f;
			Object.Instantiate<GameObject>(Ragnarok.s_vfxTreeHit, position, Quaternion.identity);
			position.x -= 60f;
			Object.Instantiate<GameObject>(Ragnarok.s_vfxTreeHit, position, Quaternion.identity);
			position.z += 30f;
			Object.Instantiate<GameObject>(Ragnarok.s_vfxTreeHit, position, Quaternion.identity);
			position.z -= 60f;
			Object.Instantiate<GameObject>(Ragnarok.s_vfxTreeHit, position, Quaternion.identity);
			EnvMan.instance.QueueEnvironment(EnvMan.instance.m_currentEnv);
			AddHitSounds();
		}

		public override void Update()
		{
			base.Update();
		}
	}
	public class EndState : FallState
	{
		private float m_waterHeight;

		public EndState(float duration)
			: base(duration)
		{
			m_soundIntervalMin = 0.1f;
			m_soundIntervalMax = 2f;
		}

		public override void Enter()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			base.Enter();
			EnvMan.instance.m_debugTimeOfDay = true;
			EnvMan.instance.m_debugTime = 0.5f;
			m_waterHeight = GetWaterHeight(((Component)Player.m_localPlayer).transform.position);
			RagnarokController.s_instance.m_noGrass = true;
			ClutterSystem.instance.ClearAll();
			m_sounds.Clear();
			m_sounds.Add(PrefabManager.Instance.GetPrefab("sfx_eikthyr_death"));
			m_sounds.Add(PrefabManager.Instance.GetPrefab("sfx_gdking_death"));
			m_sounds.Add(PrefabManager.Instance.GetPrefab("sfx_Bonemass_death"));
			m_sounds.Add(PrefabManager.Instance.GetPrefab("sfx_dragon_death"));
			m_sounds.Add(PrefabManager.Instance.GetPrefab("sfx_fader_taunt"));
			m_sounds.Add(PrefabManager.Instance.GetPrefab("sfx_seeker_brute_taunt"));
			m_sounds.Add(PrefabManager.Instance.GetPrefab("sfx_goblinking_taunt"));
			RagnarokController.s_instance.m_noGrass = true;
			ClutterSystem.instance.ClearAll();
		}

		public override bool IsGod()
		{
			return true;
		}

		public override bool CheckUnderword()
		{
			return false;
		}

		public override void Update()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			base.Update();
			EnvSetup currentEnv = EnvMan.instance.m_currentEnv;
			currentEnv.m_lightIntensityDay -= 0.001f;
			List<Heightmap> list = new List<Heightmap>();
			Heightmap.FindHeightmap(((Component)Player.m_localPlayer).transform.position, 1f, list);
			foreach (Heightmap item in list)
			{
				((Component)item.GetAndCreateTerrainCompiler()).GetComponent<RigifyMe>()?.RigifyNetwork();
			}
			foreach (MonoBehaviour item2 in new List<MonoBehaviour>((IEnumerable<MonoBehaviour>)WaterVolume.Instances))
			{
				if ((Object)(object)item2 != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)item2).gameObject);
				}
			}
			WaterVolume.Instances.Clear();
			if (((Component)Player.m_localPlayer).transform.position.y <= m_waterHeight - 200f || GetRemainingTime() <= 0f || ((Component)Player.m_localPlayer).transform.position.y > 3000f)
			{
				RagnarokController.s_instance.m_isDead = true;
				((Character)Player.m_localPlayer).SetHealth(0f);
			}
		}

		public float GetWaterHeight(Vector3 position)
		{
			//IL_0014: 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)
			int mask = LayerMask.GetMask(new string[1] { "WaterVolume" });
			Collider[] array = Physics.OverlapSphere(position, 100f, mask);
			float result = 0f;
			Collider[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				WaterVolume component = ((Component)array2[i]).GetComponent<WaterVolume>();
				if ((Object)(object)component != (Object)null)
				{
					result = component.GetWaterSurface(position, 1f);
					break;
				}
			}
			return result;
		}
	}
	public class FallState : AbstractFallState
	{
		protected Vector3 m_gravity = new Vector3(0f, -20f, 0f);

		public FallState(float duration)
			: base(duration)
		{
		}//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)


		public FallState(Vector3 gravity, float duration)
			: base(duration)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			m_duration = duration;
			m_gravity = gravity;
		}

		public override void Enter()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			base.Enter();
			Physics.gravity = m_gravity;
			if ((Object)(object)Player.m_localPlayer != (Object)null)
			{
				Transform obj = ((Component)Player.m_localPlayer).transform.Find("rigid");
				if (obj != null)
				{
					((Component)obj).gameObject.SetActive(true);
				}
			}
			if ((Object)(object)Ragnarok.s_flyaway != (Object)null)
			{
				Ragnarok.s_flyaway.m_scalingSpeed = 0.33f;
				Ragnarok.s_flyaway.m_rotationSpeed = 100f;
			}
		}

		public override void Update()
		{
			base.Update();
		}

		public override void Exit()
		{
		}
	}
	public class FallStateMachine
	{
		public AbstractFallState m_currentState;

		public float m_elapsedTime;

		public void ChangeState(AbstractFallState newState)
		{
			if (m_currentState != null)
			{
				m_currentState.Exit();
			}
			m_currentState = newState;
			if (m_currentState != null)
			{
				m_currentState.SetStateMachine(this);
				m_currentState.Enter();
			}
		}

		public void Update()
		{
			if (m_currentState != null)
			{
				m_elapsedTime += Time.deltaTime;
				if (m_currentState.m_nextState != null && m_elapsedTime > m_currentState.m_starttime + m_currentState.m_duration)
				{
					ChangeState(m_currentState.m_nextState);
				}
				m_currentState.Update();
			}
		}
	}
	public class HitState : FallState
	{
		public HitState(Vector3 gravity, float duration)
			: base(gravity, duration)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			m_soundIntervalMin = 0.1f;
			m_soundIntervalMax = 0.2f;
		}

		public override void Enter()
		{
			base.Enter();
			AddDeathSounds();
		}

		public override void Update()
		{
			base.Update();
		}

		public override void Exit()
		{
			base.Exit();
		}
	}
	public class InitialFallState : FallState
	{
		public InitialFallState(Vector3 gravity, float duration)
			: base(gravity, duration)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			m_soundIntervalMin = 0.1f;
			m_soundIntervalMax = 2f;
		}

		public override void Enter()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			base.Enter();
			Vector3 position = ((Component)Player.m_localPlayer).transform.position;
			position.y += 5f;
			AddHitSounds();
			foreach (Container explosiveContainer in RagnarokController.s_instance.GetExplosiveContainers())
			{
				((Component)explosiveContainer).gameObject.AddComponent<IgniteDestroy>().m_time = Random.Range(0f, m_duration);
			}
			Object.Instantiate<GameObject>(PrefabManager.Instance.GetPrefab("desintegratorBall"), position, Quaternion.identity);
			Object.Instantiate<GameObject>(PrefabManager.Instance.GetPrefab("desintegratorBallBumpy"), position, Quaternion.identity);
		}

		public override void Update()
		{
			base.Update();
		}
	}
	public class RotationState : AbstractFallState
	{
		public float m_tiltIntensity = 10f;

		public float m_tiltIntensityY = 1f;

		public float m_tiltFrequency = 0.5f;

		public float m_tiltFrequencyY = 0.1f;

		public float m_shakeIntensity = 0.2f;

		public float m_shakeFrequency = 1f;

		private float m_clear;

		public RotationState(float duration)
			: base(duration)
		{
			m_duration = duration;
			m_soundIntervalMin = 0.1f;
			m_soundIntervalMax = 2f;
		}

		public override void Enter()
		{
			base.Enter();
			AddDeathSounds();
			RemoveDrops();
		}

		public override void Update()
		{
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			base.Update();
			m_clear += Time.deltaTime;
			if (m_clear > 10f)
			{
				m_clear = 0f;
				RemoveDrops();
			}
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(0f, Ragnarok.FallSpeedConfig.Value, 0f);
			float num = Mathf.Sin(m_stateMachine.m_elapsedTime * m_tiltFrequency) * m_tiltIntensity;
			float num2 = Mathf.Cos(m_stateMachine.m_elapsedTime * m_tiltFrequency) * m_tiltIntensity;
			float num3 = Mathf.Sin(m_stateMachine.m_elapsedTime * m_tiltFrequencyY) * m_tiltIntensityY;
			float num4 = (Mathf.PerlinNoise(Time.time * m_shakeFrequency, 0f) * 2f - 1f) * m_shakeIntensity;
			float num5 = (Mathf.PerlinNoise(0f, Time.time * m_shakeFrequency) * 2f - 1f) * m_shakeIntensity;
			Vector3 gravity = default(Vector3);
			((Vector3)(ref gravity))..ctor(num, val.y + num3 + num5, num2 + num4);
			Physics.gravity = gravity;
			if ((Object)(object)Player.m_localPlayer != (Object)null)
			{
				Vector3 val2 = -((Vector3)(ref gravity)).normalized;
				RagnarokController.s_rotationToTargetTop = Quaternion.Lerp(Quaternion.identity, Quaternion.FromToRotation(((Component)Player.m_localPlayer).transform.up, val2), 0.5f);
				((Component)Player.m_localPlayer).transform.GetChild(0).rotation = RagnarokController.s_rotationToTargetTop * ((Component)Player.m_localPlayer).transform.rotation;
				EnvMan.instance.m_debugTime = ((Vector3)(ref gravity)).normalized.x * 0.3f + 0.5f;
			}
		}

		public override void Exit()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			RagnarokController.s_rotationToTargetTop = Quaternion.identity;
			RemoveDrops();
		}
	}
}
namespace Ragnarok.Patches
{
	[HarmonyPatch(typeof(Character), "UnderWorldCheck")]
	internal class Character_UnderWorldCheck_patch
	{
		private static bool Prefix(ref Character __instance)
		{
			if (RagnarokController.s_instance.m_fallStateMachine == null || RagnarokController.s_instance.m_fallStateMachine.m_currentState == null)
			{
				return true;
			}
			return RagnarokController.s_instance.m_fallStateMachine.m_currentState.CheckUnderword();
		}
	}
	[HarmonyPatch(typeof(ClutterSystem), "UpdateGrass")]
	internal class ClutterSystem_UpdateGrass_patch
	{
		private static bool Prefix()
		{
			if ((Object)(object)RagnarokController.s_instance != (Object)null && RagnarokController.s_instance.m_noGrass)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Container), "Awake")]
	internal class Container_Awake_patch
	{
		private static void Postfix(ref Container __instance)
		{
			RagnarokController.s_instance.m_containers[((Component)__instance).gameObject] = __instance;
		}
	}
	[HarmonyPatch(typeof(DungeonDB), "Start")]
	internal class DungeonDB_Start_patch
	{
		private static void Postfix()
		{
			Ragnarok.Init();
		}
	}
	[HarmonyPatch(typeof(EnvMan), "QueueEnvironment", new Type[] { typeof(EnvSetup) })]
	internal class EnvMan_QueueEnvironment_patch
	{
		private static void Prefix(ref EnvSetup env)
		{
			RagnarokController.s_instance?.PrepareQueuedEnvironment(env);
		}
	}
	[HarmonyPatch(typeof(Heightmap), "GetBiomeColor", new Type[]
	{
		typeof(float),
		typeof(float)
	})]
	internal class Heightmap_GetBiomeColor_patch
	{
		private static bool Prefix(float ix, float iy, ref Color __result, ref Heightmap __instance)
		{
			//IL_001f: 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)
			HeightmapKey key = new HeightmapKey(__instance, ix, iy);
			if (Ragnarok.s_biomeColors.ContainsKey(key))
			{
				__result = Ragnarok.s_biomeColors[key];
				return false;
			}
			return true;
		}

		private static void Postfix(float ix, float iy, ref Color __result, ref Heightmap __instance)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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_0022: 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)
			__result = Color.Lerp(__result, Color32.op_Implicit(new Color32(byte.MaxValue, (byte)0, (byte)0, byte.MaxValue)), CrackState.s_ashed);
		}
	}
	[HarmonyPatch(typeof(ImpactEffect), "OnCollisionEnter")]
	internal class ImpactEffect_OnCollisionEntern_patch
	{
		private static bool Prefix(ref ImpactEffect __instance)
		{
			if ((Object)(object)__instance.m_nview == (Object)null)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(ZoneSystem), "SpawnLocation")]
	internal static class ZoneSystem_SpawnLocation_Patch
	{
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> OnCreateLocationTranspiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(true, (CodeMatch[])(object)new CodeMatch[1]
			{
				new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(SoftReference<GameObject>), "Load", (Type[])null, (Type[])null), (string)null)
			}).ThrowIfInvalid("Could not patch ZoneSystem.SpawnLocation: SoftReference.Load not found! ").Advance(2)
				.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[2]
				{
					new CodeInstruction(OpCodes.Ldarg_1, (object)null),
					Transpilers.EmitDelegate<Action<ZoneLocation>>((Action<ZoneLocation>)OnInstantiateDelegate)
				})
				.InstructionEnumeration();
		}

		private static void OnInstantiateDelegate(ZoneLocation location)
		{
			Ragnarok.AddRigidbody2Location(location);
		}
	}
	[HarmonyPatch(typeof(ZSyncTransform), "Awake")]
	internal class ZSyncTransorm_Awake_patch
	{
		private static void Postfix(ref ZSyncTransform __instance)
		{
			TerrainComp component = ((Component)__instance).GetComponent<TerrainComp>();
			if ((Object)(object)component != (Object)null)
			{
				__instance.m_body = ((Component)component.m_hmap).GetComponent<Rigidbody>();
			}
		}
	}
	[HarmonyPatch(typeof(Player), "InGodMode")]
	internal class Player_InGodMode_patch
	{
		private static bool Prefix(ref Player __instance, ref bool __result)
		{
			if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer)
			{
				return true;
			}
			if ((RagnarokController.s_instance?.IsGod()).Value)
			{
				__result = true;
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(WearNTear), "Awake")]
	internal class WearNTear_Awake_patch
	{
		public static void Postfix(ref WearNTear __instance)
		{
			Collider[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Collider>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				_ = componentsInChildren[i];
				if (((Object)((Component)Ragnarok.GetTopmostTransform(((Component)__instance).transform)).gameObject).name.ToLower().Contains("roof"))
				{
					RagnarokController.s_instance.m_roofs.Add(((Component)__instance).gameObject);
				}
			}
		}
	}
	[HarmonyPatch(typeof(ZNetView), "OnDestroy")]
	public static class ZNetView_OnDestroy_Patch
	{
		private static void Prefix(ZNetView __instance)
		{
			RagnarokController.s_instance?.DestroyInstance(((Component)__instance).gameObject);
		}
	}
	[HarmonyPatch(typeof(GameCamera), "UpdateCamera")]
	internal class GameCamera_UpdateCamera_patch
	{
		private static void Postfix(ref GameCamera __instance)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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)
			((Component)__instance).transform.rotation = RagnarokController.s_rotationToTargetTop * ((Component)__instance).transform.rotation;
		}
	}
	[HarmonyPatch(typeof(Game), "Start")]
	public static class Game_Start_Patch
	{
		private static void Prefix()
		{
			ZRoutedRpc.instance.Register<int, float>("UpdateRagnarok", (Action<long, int, float>)Ragnarok.UpdateRagnarok);
		}
	}
	[HarmonyPatch(typeof(Game), "RequestRespawn")]
	internal class Game_RequestRespawn_patch
	{
		private static bool Prefix()
		{
			if (Object.op_Implicit((Object)(object)RagnarokController.s_instance) && RagnarokController.s_instance.m_isDead)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(ZNetScene), "Awake")]
	public static class ZNetScene_Awake_AddWearNTearFireController
	{
		private static void Postfix(ZNetScene __instance)
		{
			((Behaviour)((Component)((Component)__instance).transform.parent).gameObject.AddComponent<RagnarokController>()).enabled = true;
		}
	}
}
namespace Ragnarok.Mono
{
	public class SimulateFlyingAway : MonoBehaviour
	{
		public float m_scalingSpeed = 0.01f;

		public float m_maxScale = 1f;

		public float m_minScale = 0.01f;

		public float m_rotationSpeed = 10f;

		private void Update()
		{
			//IL_0014: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)Player.m_localPlayer == (Object)null))
			{
				float num = Mathf.Lerp(((Component)this).transform.localScale.x, m_minScale, 1f - Mathf.Exp((0f - m_scalingSpeed) * Time.deltaTime));
				Vector3 localScale = default(Vector3);
				((Vector3)(ref localScale))..ctor(num, num, num);
				((Component)this).transform.localScale = localScale;
				((Component)this).transform.position = new Vector3(((Component)Player.m_localPlayer).transform.position.x, 2000f, ((Component)Player.m_localPlayer).transform.position.z);
				((Component)this).transform.Rotate(Vector3.up, m_rotationSpeed * Time.deltaTime);
			}
		}
	}
}
namespace Ragnarok.Commands
{
	public class RagnarokCommand : ConsoleCommand
	{
		private string[] commands = new string[3] { "start", "set", "end" };

		public override string Name => "ragnarok";

		public override string Help => "Ragnarok";

		public override void Run(string[] args)
		{
			if (args.Length < 1 || !commands.Any((string x) => x.Equals(args[0])))
			{
				Console.instance.Print("Usage: " + ((ConsoleCommand)this).Name + " [" + string.Join("|", commands) + "]");
			}
			else if (args[0] == "start")
			{
				RagnarokController.s_instance.m_owner = true;
				ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "UpdateRagnarok", new object[2] { 1, 0 });
			}
			else
			{
				Console.instance.Print("unknown command");
			}
		}
	}
}