Decompiled source of CogaCosmos v0.8.1

plugins/CogaCosmos.dll

Decompiled 4 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using CogaCosmos.Procedural;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Splatform;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace CogaCosmos
{
	public sealed class BeaconTraveler : MonoBehaviour
	{
		private const float ChargeTime = 0.55f;

		private const float StreakTime = 0.45f;

		private const float FlashTime = 0.45f;

		private static readonly FieldInfo MaxAirAltitude = AccessTools.Field(typeof(Character), "m_maxAirAltitude");

		private Player _player;

		private BeaconLink _from;

		private BeaconLink _to;

		private Color _color;

		private float _t;

		private int _stage;

		private Vector3 _streakStart;

		private Vector3 _streakEnd;

		private Vector3 _arrive;

		private Quaternion _arriveRot;

		private Transform _streak;

		private Transform _aura;

		private Light _playerLight;

		private float _flash;

		public static bool Busy { get; private set; }

		public static void Begin(Player player, BeaconLink from, BeaconLink to)
		{
			//IL_0025: 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)
			if (!Busy && Object.op_Implicit((Object)(object)player) && Object.op_Implicit((Object)(object)from) && Object.op_Implicit((Object)(object)to))
			{
				BeaconTraveler beaconTraveler = new GameObject("CogaBeaconTravel").AddComponent<BeaconTraveler>();
				beaconTraveler._player = player;
				beaconTraveler._from = from;
				beaconTraveler._to = to;
				beaconTraveler._color = from.Glow;
				Busy = true;
				beaconTraveler.StartCharge();
			}
		}

		private void StartCharge()
		{
			//IL_001e: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			//IL_007f: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
			_from.Flare(departing: true);
			Transform transform = ((Component)_player).transform;
			_aura = new GameObject("Aura").transform;
			_aura.SetParent(transform, false);
			_aura.localPosition = Vector3.zero;
			Spiral(_aura, _color).Play(true);
			GameObject val = new GameObject("Glow");
			val.transform.SetParent(transform, false);
			val.transform.localPosition = Vector3.up * 1f;
			_playerLight = val.AddComponent<Light>();
			_playerLight.type = (LightType)2;
			_playerLight.color = _color;
			_playerLight.range = 4f;
			_playerLight.intensity = 0f;
			_playerLight.shadows = (LightShadows)0;
		}

		private void Update()
		{
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)_player) || !Object.op_Implicit((Object)(object)_from) || !Object.op_Implicit((Object)(object)_to))
			{
				Finish();
				return;
			}
			_t += Time.deltaTime;
			switch (_stage)
			{
			case 0:
				if (Object.op_Implicit((Object)(object)_playerLight))
				{
					_playerLight.intensity = Mathf.Lerp(0f, 3f, _t / 0.55f);
				}
				if (_t >= 0.55f)
				{
					LaunchStreak();
					_stage = 1;
					_t = 0f;
				}
				break;
			case 1:
			{
				float num = Mathf.Clamp01(_t / 0.45f);
				if (Object.op_Implicit((Object)(object)_streak))
				{
					_streak.position = Arc(num);
				}
				if (num >= 1f)
				{
					Arrive();
					_stage = 2;
					_t = 0f;
				}
				break;
			}
			default:
				_flash = 1f - Mathf.Clamp01(_t / 0.45f);
				if (_t >= Mathf.Max(0.45f, 1.2f))
				{
					Finish();
				}
				break;
			}
		}

		private void LaunchStreak()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0035: 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_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_004b: 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_0052: 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_0066: 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_0076: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: 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)
			Vector3 val = ((Component)_from).transform.position + Vector3.up * 1f;
			Vector3 streakEnd = ((Component)_to).transform.position + Vector3.up * 1f;
			_streakStart = val;
			_streakEnd = streakEnd;
			Transform transform = ((Component)_to).transform;
			_arrive = transform.position + transform.forward * 1.6f;
			RaycastHit val2 = default(RaycastHit);
			if (Physics.Raycast(_arrive + Vector3.up * 2f, Vector3.down, ref val2, 5f, LayerMask.GetMask(new string[5] { "Default", "static_solid", "terrain", "piece", "vehicle" }), (QueryTriggerInteraction)1))
			{
				_arrive = ((RaycastHit)(ref val2)).point + Vector3.up * 0.05f;
			}
			Vector3 val3 = Vector3.ProjectOnPlane(transform.forward, Vector3.up);
			_arriveRot = Quaternion.LookRotation(((Vector3)(ref val3)).normalized, Vector3.up);
			_streak = new GameObject("Streak").transform;
			_streak.position = val;
			Comet(_streak, _color).Play(true);
			BeaconFx.Burst(val, _color);
			BeaconFx.Sound("sfx_frozenking_charge_whoosh", val);
		}

		private Vector3 Arc(float k)
		{
			//IL_0001: 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_0028: 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_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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0046: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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_007f: 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_0093: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			//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_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Clamp(Vector3.Distance(_streakStart, _streakEnd) * 0.35f, 4f, 30f);
			Vector3 streakStart = _streakStart;
			Vector3 streakEnd = _streakEnd;
			Vector3 val = streakStart + Vector3.up * num;
			Vector3 val2 = streakEnd + Vector3.up * num;
			float num2 = Mathf.SmoothStep(0f, 1f, k);
			float num3 = 1f - num2;
			return num3 * num3 * num3 * streakStart + 3f * num3 * num3 * num2 * val + 3f * num3 * num2 * num2 * val2 + num2 * num2 * num2 * streakEnd;
		}

		private void Arrive()
		{
			//IL_0007: 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_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_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_004e: 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_0072: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			Move(_player, _arrive, _arriveRot);
			_flash = 1f;
			_to.Flare(departing: false);
			BeaconFx.Burst(_arrive + Vector3.up * 1f, _to.Glow);
			BeaconFx.RingWave(((Component)_to).transform.position + Vector3.up * 0.06f, _to.Glow);
			if (Object.op_Implicit((Object)(object)_aura))
			{
				Object.Destroy((Object)(object)((Component)_aura).gameObject);
			}
			if (Object.op_Implicit((Object)(object)_playerLight))
			{
				Object.Destroy((Object)(object)((Component)_playerLight).gameObject);
			}
			if (Object.op_Implicit((Object)(object)_streak))
			{
				Object.Destroy((Object)(object)((Component)_streak).gameObject, 0.6f);
			}
		}

		public static void Move(Player player, Vector3 pos, Quaternion rot)
		{
			//IL_0006: 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_001d: 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_0054: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			((Component)player).transform.SetPositionAndRotation(pos, rot);
			Rigidbody component = ((Component)player).GetComponent<Rigidbody>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.position = pos;
				component.rotation = rot;
				if (!component.isKinematic)
				{
					component.linearVelocity = Vector3.zero;
					component.angularVelocity = Vector3.zero;
				}
			}
			MaxAirAltitude?.SetValue(player, pos.y);
			((Character)player).SetLookDir(rot * Vector3.forward, 0f);
		}

		private void OnGUI()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Invalid comparison between Unknown and I4
			//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_002b: 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_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)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			if (!(_flash <= 0f) && (int)Event.current.type == 7)
			{
				Color color = Color.Lerp(_color, Color.white, 0.55f);
				color.a = (CosmosComfort.CalmLights ? 0.25f : 0.6f) * _flash * _flash;
				Color color2 = GUI.color;
				GUI.color = color;
				GUI.DrawTexture(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), (Texture)(object)Texture2D.whiteTexture);
				GUI.color = color2;
			}
		}

		private void Finish()
		{
			Busy = false;
			if (Object.op_Implicit((Object)(object)_aura))
			{
				Object.Destroy((Object)(object)((Component)_aura).gameObject);
			}
			if (Object.op_Implicit((Object)(object)_playerLight))
			{
				Object.Destroy((Object)(object)((Component)_playerLight).gameObject);
			}
			if (Object.op_Implicit((Object)(object)_streak))
			{
				Object.Destroy((Object)(object)((Component)_streak).gameObject);
			}
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}

		private void OnDestroy()
		{
			Busy = false;
		}

		private static ParticleSystem Spiral(Transform parent, Color color)
		{
			//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_0025: 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: 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_0049: 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_0058: 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_0070: 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_0083: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: 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_0151: Unknown result type (might be due to invalid IL or missing references)
			ParticleSystem obj = NewSystem(parent, "Spiral", CosmosAssets.Sparkle4Mat, 80);
			MainModule main = obj.main;
			((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.6f, 0.9f);
			((MainModule)(ref main)).startSize = new MinMaxCurve(0.06f, 0.14f);
			((MainModule)(ref main)).startColor = new MinMaxGradient(color, Color.Lerp(color, Color.white, 0.6f));
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)0;
			EmissionModule emission = obj.emission;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(90f);
			ShapeModule shape = obj.shape;
			((ShapeModule)(ref shape)).enabled = true;
			((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)10;
			((ShapeModule)(ref shape)).radius = 0.7f;
			((ShapeModule)(ref shape)).radiusThickness = 0f;
			((ShapeModule)(ref shape)).rotation = new Vector3(90f, 0f, 0f);
			VelocityOverLifetimeModule velocityOverLifetime = obj.velocityOverLifetime;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).enabled = true;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).space = (ParticleSystemSimulationSpace)0;
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).x = MinMaxCurve.op_Implicit(0f);
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).y = MinMaxCurve.op_Implicit(2.4f);
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).z = MinMaxCurve.op_Implicit(0f);
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).orbitalX = MinMaxCurve.op_Implicit(0f);
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).orbitalY = MinMaxCurve.op_Implicit(5f);
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).orbitalZ = MinMaxCurve.op_Implicit(0f);
			((VelocityOverLifetimeModule)(ref velocityOverLifetime)).radial = MinMaxCurve.op_Implicit(-0.6f);
			Fade(obj);
			return obj;
		}

		private static ParticleSystem Comet(Transform parent, Color color)
		{
			//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_0026: 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_0048: 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_0053: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			ParticleSystem val = NewSystem(parent, "Comet", CosmosAssets.GlowMat, 120);
			MainModule main = val.main;
			((MainModule)(ref main)).startLifetime = new MinMaxCurve(0.35f, 0.6f);
			((MainModule)(ref main)).startSize = new MinMaxCurve(0.25f, 0.5f);
			((MainModule)(ref main)).startColor = new MinMaxGradient(Color.Lerp(color, Color.white, 0.6f), color);
			((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
			EmissionModule emission = val.emission;
			((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(0f);
			((EmissionModule)(ref emission)).rateOverDistance = MinMaxCurve.op_Implicit(6f);
			Fade(val);
			SizeOverLifetimeModule sizeOverLifetime = val.sizeOverLifetime;
			((SizeOverLifetimeModule)(ref sizeOverLifetime)).enabled = true;
			((SizeOverLifetimeModule)(ref sizeOverLifetime)).size = new MinMaxCurve(1f, AnimationCurve.Linear(0f, 1f, 1f, 0.1f));
			ParticleSystem val2 = NewSystem(parent, "Head", CosmosAssets.Sparkle8Mat, 4);
			MainModule main2 = val2.main;
			((MainModule)(ref main2)).startLifetime = MinMaxCurve.op_Implicit(10f);
			((MainModule)(ref main2)).startSize = MinMaxCurve.op_Implicit(1.1f);
			((MainModule)(ref main2)).startColor = MinMaxGradient.op_Implicit(Color.Lerp(color, Color.white, 0.5f));
			((MainModule)(ref main2)).simulationSpace = (ParticleSystemSimulationSpace)0;
			EmissionModule emission2 = val2.emission;
			((EmissionModule)(ref emission2)).rateOverTime = MinMaxCurve.op_Implicit(0f);
			((EmissionModule)(ref emission2)).SetBursts((Burst[])(object)new Burst[1]
			{
				new Burst(0f, (short)1)
			});
			val2.Play(true);
			return val;
		}

		private static ParticleSystem NewSystem(Transform parent, string name, Material mat, int max)
		{
			//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_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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			ParticleSystem obj = val.AddComponent<ParticleSystem>();
			obj.Stop(true, (ParticleSystemStopBehavior)0);
			MainModule main = obj.main;
			((MainModule)(ref main)).loop = true;
			((MainModule)(ref main)).duration = 1f;
			((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(0f);
			((MainModule)(ref main)).maxParticles = max;
			((MainModule)(ref main)).playOnAwake = false;
			ShapeModule shape = obj.shape;
			((ShapeModule)(ref shape)).enabled = false;
			ParticleSystemRenderer component = ((Component)obj).GetComponent<ParticleSystemRenderer>();
			((Renderer)component).sharedMaterial = mat;
			((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)component).receiveShadows = false;
			component.maxParticleSize = 2f;
			return obj;
		}

		private static void Fade(ParticleSystem ps)
		{
			//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_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_001e: 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_002d: 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_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_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_0070: 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_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_0098: Unknown result type (might be due to invalid IL or missing references)
			ColorOverLifetimeModule colorOverLifetime = ps.colorOverLifetime;
			((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
			Gradient val = new Gradient();
			val.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
			{
				new GradientColorKey(Color.white, 0f),
				new GradientColorKey(Color.white, 1f)
			}, (GradientAlphaKey[])(object)new GradientAlphaKey[3]
			{
				new GradientAlphaKey(0f, 0f),
				new GradientAlphaKey(1f, 0.15f),
				new GradientAlphaKey(0f, 1f)
			});
			((ColorOverLifetimeModule)(ref colorOverLifetime)).color = new MinMaxGradient(val);
		}
	}
	internal static class CosmosTime
	{
		private static double _smooth;

		private static int _frame = -1;

		private static bool _started;

		public static double? Override { get; set; }

		public static double Now
		{
			get
			{
				if (Override.HasValue)
				{
					return Override.Value;
				}
				double num = (Object.op_Implicit((Object)(object)ZNet.instance) ? ZNet.instance.GetTimeSeconds() : Time.timeAsDouble);
				if (_frame != Time.frameCount)
				{
					_frame = Time.frameCount;
					float num2 = Mathf.Min(Time.deltaTime, 0.25f);
					if (!_started || Math.Abs(num - _smooth) > 3.0)
					{
						_smooth = num;
						_started = true;
					}
					else
					{
						_smooth += num2;
						_smooth += (num - _smooth) * Math.Min(1.0, (double)num2 * 0.5);
					}
				}
				return _smooth;
			}
		}

		public static float Angle(double period, double phaseDeg = 0.0)
		{
			if (period <= 0.01)
			{
				return (float)phaseDeg;
			}
			return (float)(Now % period / period * 360.0 + phaseDeg);
		}

		public static float Wave(double now, double period)
		{
			return (float)(now % period / period * (Math.PI * 2.0));
		}
	}
	public interface IBoothPrepare
	{
		void Prepare();
	}
	public sealed class PlanetSpin : MonoBehaviour, IBoothPrepare
	{
		public Transform Body;

		public float Period = 60f;

		private void Update()
		{
			long start = CosmosPerf.Begin();
			Apply();
			CosmosPerf.End(start);
		}

		public void Prepare()
		{
			Apply();
		}

		public void Apply()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)Body))
			{
				Body.localRotation = Quaternion.Euler(0f, 0f - CosmosTime.Angle(Period), 0f);
			}
		}
	}
	public sealed class OrreryMotion : MonoBehaviour, IBoothPrepare
	{
		public Transform[] Pivots;

		public float[] OrbitPeriods;

		public float[] Phases;

		public Transform[] Bodies;

		public float[] SpinPeriods;

		private void Update()
		{
			long start = CosmosPerf.Begin();
			Apply();
			CosmosPerf.End(start);
		}

		public void Prepare()
		{
			Apply();
		}

		public void Apply()
		{
			//IL_0049: 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)
			if (Pivots == null)
			{
				return;
			}
			for (int i = 0; i < Pivots.Length; i++)
			{
				if (Object.op_Implicit((Object)(object)Pivots[i]))
				{
					Pivots[i].localRotation = Quaternion.Euler(0f, 0f - CosmosTime.Angle(OrbitPeriods[i], Phases[i]), 0f);
				}
				if (Bodies != null && i < Bodies.Length && Object.op_Implicit((Object)(object)Bodies[i]))
				{
					Bodies[i].localRotation = Quaternion.Euler(0f, 0f - CosmosTime.Angle(SpinPeriods[i]), 0f);
				}
			}
		}
	}
	public sealed class Spinner : MonoBehaviour, IBoothPrepare
	{
		public Transform[] Targets = (Transform[])(object)new Transform[0];

		public Vector3[] Axes = (Vector3[])(object)new Vector3[0];

		public float[] Periods = new float[0];

		public float[] Phases = new float[0];

		public Quaternion[] Bases = (Quaternion[])(object)new Quaternion[0];

		public void Add(Transform t, Vector3 axis, float period, float phase = 0f)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			int num = Targets.Length;
			Array.Resize(ref Targets, num + 1);
			Array.Resize(ref Axes, num + 1);
			Array.Resize(ref Periods, num + 1);
			Array.Resize(ref Phases, num + 1);
			Array.Resize(ref Bases, num + 1);
			Targets[num] = t;
			Axes[num] = ((Vector3)(ref axis)).normalized;
			Periods[num] = period;
			Phases[num] = phase;
			Bases[num] = t.localRotation;
		}

		private void Update()
		{
			long start = CosmosPerf.Begin();
			Apply();
			CosmosPerf.End(start);
		}

		public void Prepare()
		{
			Apply();
		}

		public void Apply()
		{
			//IL_0022: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < Targets.Length; i++)
			{
				if (Object.op_Implicit((Object)(object)Targets[i]))
				{
					Targets[i].localRotation = Bases[i] * Quaternion.AngleAxis(0f - CosmosTime.Angle(Periods[i], Phases[i]), Axes[i]);
				}
			}
		}
	}
	public sealed class LightPulse : MonoBehaviour
	{
		public Light Target;

		public float Base = 1f;

		public float Amplitude = 0.4f;

		public float Period = 3f;

		[NonSerialized]
		public float Boost;

		private void Update()
		{
			if (Object.op_Implicit((Object)(object)Target))
			{
				Target.intensity = Base + Boost + Amplitude * Mathf.Sin((float)(CosmosTime.Now % (double)Period / (double)Period) * (float)Math.PI * 2f);
			}
		}
	}
	public sealed class FixedParticles : MonoBehaviour, IBoothPrepare
	{
		public ParticleSystem System;

		public Vector3[] Positions = (Vector3[])(object)new Vector3[0];

		public Color[] Colors = (Color[])(object)new Color[0];

		public float[] Sizes = new float[0];

		public float[] Rotations = new float[0];

		private bool _filled;

		private void Start()
		{
			Prepare();
		}

		public void Recolor(Color[] colors)
		{
			if (colors != null && colors.Length == Positions.Length)
			{
				Colors = colors;
				_filled = false;
				Prepare();
			}
		}

		public void Prepare()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_0051: 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_0072: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
			if (_filled || !Object.op_Implicit((Object)(object)System))
			{
				return;
			}
			_filled = true;
			System.Clear();
			EmitParams val = default(EmitParams);
			((EmitParams)(ref val)).applyShapeToPosition = false;
			((EmitParams)(ref val)).velocity = Vector3.zero;
			((EmitParams)(ref val)).startLifetime = 1000000f;
			EmitParams val2 = val;
			for (int i = 0; i < Positions.Length; i++)
			{
				((EmitParams)(ref val2)).position = Positions[i];
				((EmitParams)(ref val2)).startColor = Color32.op_Implicit(Colors[i]);
				((EmitParams)(ref val2)).startSize = Sizes[i];
				if (i < Rotations.Length)
				{
					((EmitParams)(ref val2)).rotation = Rotations[i];
				}
				System.Emit(val2, 1);
			}
		}
	}
	public sealed class AuroraWave : MonoBehaviour, IBoothPrepare
	{
		public MeshFilter Filter;

		public MeshRenderer Renderer;

		private Mesh _mesh;

		private Vector3[] _base;

		private Vector3[] _work;

		private float _height = 1f;

		private MaterialPropertyBlock _mpb;

		private void Start()
		{
			Init();
		}

		private void Update()
		{
			long start = CosmosPerf.Begin();
			Apply();
			CosmosPerf.End(start);
		}

		public void Prepare()
		{
			Init();
			Apply();
		}

		private void Init()
		{
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Expected O, but got Unknown
			if (!Object.op_Implicit((Object)(object)_mesh) && Object.op_Implicit((Object)(object)Filter) && Object.op_Implicit((Object)(object)Filter.sharedMesh))
			{
				_mesh = Object.Instantiate<Mesh>(Filter.sharedMesh);
				_mesh.MarkDynamic();
				Filter.sharedMesh = _mesh;
				_base = _mesh.vertices;
				_work = (Vector3[])(object)new Vector3[_base.Length];
				Vector3[] array = _base;
				foreach (Vector3 val in array)
				{
					_height = Mathf.Max(_height, val.y);
				}
				_mpb = new MaterialPropertyBlock();
			}
		}

		private void Apply()
		{
			//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_003d: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: 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_0112: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)_mesh))
			{
				float num = (float)(CosmosTime.Now % 10000.0);
				for (int i = 0; i < _base.Length; i++)
				{
					Vector3 val = _base[i];
					float num2 = 0.25f + 0.75f * (val.y / _height);
					float num3 = (Mathf.Sin(val.x * 0.9f + num * 0.5f) * 0.35f + Mathf.Sin(val.x * 2.1f - num * 0.8f + val.y) * 0.15f) * num2;
					_work[i] = new Vector3(val.x, val.y, val.z + num3);
				}
				_mesh.vertices = _work;
				_mesh.RecalculateBounds();
				_mpb.SetVector("_MainTex_ST", new Vector4(1f, 1f, num * 0.015f % 1f, 0f));
				((Renderer)Renderer).SetPropertyBlock(_mpb);
			}
		}

		private void OnDestroy()
		{
			if (Object.op_Implicit((Object)(object)_mesh))
			{
				Object.Destroy((Object)(object)_mesh);
			}
		}
	}
	public sealed class WorldMapDisplay : MonoBehaviour, IBoothPrepare, IHoverLines
	{
		public MeshRenderer Renderer;

		public Transform Marker;

		public float Radius = 1f;

		private Texture2D _shown;

		private float _next;

		private MaterialPropertyBlock _mpb;

		public static bool Live = true;

		private void Start()
		{
			Prepare();
		}

		public void Prepare()
		{
			Show(WorldMapTexture.Get());
		}

		private void Show(Texture2D tex)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_0095: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)tex) && Object.op_Implicit((Object)(object)Renderer) && !((Object)(object)tex == (Object)(object)_shown))
			{
				_shown = tex;
				if (_mpb == null)
				{
					_mpb = new MaterialPropertyBlock();
				}
				((Renderer)Renderer).GetPropertyBlock(_mpb);
				_mpb.SetTexture("_MainTex", (Texture)(object)tex);
				_mpb.SetTexture("_EmissionMap", (Texture)(object)tex);
				((Renderer)Renderer).SetPropertyBlock(_mpb);
				if (Object.op_Implicit((Object)(object)Marker))
				{
					Vector3 position = ((Component)this).transform.position;
					float num = Radius / 10500f;
					Marker.localPosition = new Vector3(position.x * num, Marker.localPosition.y, position.z * num);
				}
			}
		}

		private void Update()
		{
			//IL_003a: 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_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)
			if (Time.time < _next)
			{
				return;
			}
			_next = Time.time + 2f;
			Player localPlayer = Player.m_localPlayer;
			object obj;
			if (Live && Object.op_Implicit((Object)(object)localPlayer))
			{
				Vector3 val = ((Component)localPlayer).transform.position - ((Component)this).transform.position;
				if (((Vector3)(ref val)).sqrMagnitude < 400f)
				{
					obj = WorldMapTexture.Personal();
					goto IL_006b;
				}
			}
			obj = null;
			goto IL_006b;
			IL_006b:
			Texture2D val2 = (Texture2D)obj;
			Show(Object.op_Implicit((Object)(object)val2) ? val2 : WorldMapTexture.Get());
		}

		public string HoverLines()
		{
			//IL_003e: 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_005b: 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_0066: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
			if (!Live || !Object.op_Implicit((Object)(object)Renderer) || !Object.op_Implicit((Object)(object)GameCamera.instance))
			{
				return "The whole world, from its seed";
			}
			Transform transform = ((Component)GameCamera.instance).transform;
			Plane val = default(Plane);
			((Plane)(ref val))..ctor(((Component)Renderer).transform.up, ((Component)Renderer).transform.position);
			float num = default(float);
			if (!((Plane)(ref val)).Raycast(new Ray(transform.position, transform.forward), ref num))
			{
				return "Your map: dim land is unexplored";
			}
			Vector3 val2 = ((Component)Renderer).transform.parent.InverseTransformPoint(transform.position + transform.forward * num);
			float num2 = 10500f / Radius;
			string text = WorldMapTexture.PinNear(new Vector3(val2.x * num2, 0f, val2.z * num2), 350f);
			if (text == null)
			{
				return "Your map: dim land is unexplored";
			}
			return "Your map: <color=#FFD45A>" + text + "</color>";
		}
	}
	internal static class WorldMapTexture
	{
		public const float Extent = 10500f;

		private const int Size = 128;

		private static Texture2D _tex;

		private static Texture2D _personal;

		private static Color32[] _base;

		private static int _seed = int.MinValue;

		private static float _personalAt = -999f;

		private static readonly FieldInfo ExploredField = AccessTools.Field(typeof(Minimap), "m_explored");

		private static readonly FieldInfo ExploredOthersField = AccessTools.Field(typeof(Minimap), "m_exploredOthers");

		private static readonly FieldInfo PinsField = AccessTools.Field(typeof(Minimap), "m_pins");

		public static Texture2D Get()
		{
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: 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_0127: Expected O, but got Unknown
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			WorldGenerator instance = WorldGenerator.instance;
			if (instance == null)
			{
				return null;
			}
			int seed = instance.GetSeed();
			if (Object.op_Implicit((Object)(object)_tex) && seed == _seed)
			{
				return _tex;
			}
			float water = (Object.op_Implicit((Object)(object)ZoneSystem.instance) ? ZoneSystem.instance.m_waterLevel : 30f);
			Color32[] array = (Color32[])(object)new Color32[16384];
			for (int i = 0; i < 128; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					float wx = (((float)j + 0.5f) / 128f * 2f - 1f) * 10500f;
					float wz = (((float)i + 0.5f) / 128f * 2f - 1f) * 10500f;
					array[i * 128 + j] = Sample(instance, wx, wz, water);
				}
			}
			if (Object.op_Implicit((Object)(object)_tex))
			{
				Object.Destroy((Object)(object)_tex);
			}
			_tex = new Texture2D(128, 128, (TextureFormat)4, true)
			{
				name = "coga_worldmap",
				wrapMode = (TextureWrapMode)1,
				filterMode = (FilterMode)0
			};
			_tex.SetPixels32(array);
			_tex.Apply(true, true);
			_base = array;
			_seed = seed;
			_personalAt = -999f;
			return _tex;
		}

		public static Texture2D Personal()
		{
			//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c8: 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_03da: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e6: Expected O, but got Unknown
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: 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_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: Unknown result type (might be due to invalid IL or missing references)
			Minimap instance = Minimap.instance;
			if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)Get()) || _base == null)
			{
				return null;
			}
			if (Object.op_Implicit((Object)(object)_personal) && Time.time - _personalAt < 10f)
			{
				return _personal;
			}
			_personalAt = Time.time;
			BitArray bitArray = ExploredField?.GetValue(instance) as BitArray;
			BitArray bitArray2 = ExploredOthersField?.GetValue(instance) as BitArray;
			int textureSize = instance.m_textureSize;
			float pixelSize = instance.m_pixelSize;
			Color32[] array = (Color32[])_base.Clone();
			if (bitArray != null && textureSize > 0 && pixelSize > 0f)
			{
				float num = 164.0625f;
				for (int i = 0; i < 128; i++)
				{
					for (int j = 0; j < 128; j++)
					{
						float num2 = (((float)j + 0.5f) / 128f * 2f - 1f) * 10500f;
						float num3 = (((float)i + 0.5f) / 128f * 2f - 1f) * 10500f;
						bool flag = false;
						for (int k = -1; k <= 1; k++)
						{
							if (flag)
							{
								break;
							}
							for (int l = -1; l <= 1; l++)
							{
								if (flag)
								{
									break;
								}
								int num4 = Mathf.FloorToInt((num2 + (float)l * num / 3f) / pixelSize + (float)textureSize / 2f);
								int num5 = Mathf.FloorToInt((num3 + (float)k * num / 3f) / pixelSize + (float)textureSize / 2f);
								if (num4 >= 0 && num5 >= 0 && num4 < textureSize && num5 < textureSize)
								{
									int num6 = num5 * textureSize + num4;
									flag = (num6 < bitArray.Length && bitArray[num6]) || (bitArray2 != null && num6 < bitArray2.Length && bitArray2[num6]);
								}
							}
						}
						if (!flag)
						{
							Color32 val = array[i * 128 + j];
							int num7 = (val.r + val.g + val.b) / 3;
							array[i * 128 + j] = new Color32((byte)((val.r + num7) / 6), (byte)((val.g + num7) / 6), (byte)((val.b + num7) / 5), byte.MaxValue);
						}
					}
				}
			}
			if (PinsField?.GetValue(instance) is List<PinData> list)
			{
				foreach (PinData item in list)
				{
					if (item == null || !Shown(item.m_type))
					{
						continue;
					}
					int num8 = Mathf.FloorToInt((item.m_pos.x / 10500f * 0.5f + 0.5f) * 128f);
					int num9 = Mathf.FloorToInt((item.m_pos.z / 10500f * 0.5f + 0.5f) * 128f);
					Color32 val2 = PinColor(item.m_type);
					for (int m = 0; m < 2; m++)
					{
						for (int n = 0; n < 2; n++)
						{
							int num10 = num8 + n - 1;
							int num11 = num9 + m - 1;
							if (num10 >= 0 && num11 >= 0 && num10 < 128 && num11 < 128)
							{
								array[num11 * 128 + num10] = val2;
							}
						}
					}
				}
			}
			if (!Object.op_Implicit((Object)(object)_personal))
			{
				_personal = new Texture2D(128, 128, (TextureFormat)4, false)
				{
					name = "coga_worldmap_personal",
					wrapMode = (TextureWrapMode)1,
					filterMode = (FilterMode)0
				};
			}
			_personal.SetPixels32(array);
			_personal.Apply(false, false);
			return _personal;
		}

		private static bool Shown(PinType t)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Invalid comparison between Unknown and I4
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Invalid comparison between Unknown and I4
			if ((int)t != 10 && (int)t != 12 && (int)t != 7 && (int)t != 8 && (int)t != 13)
			{
				return (int)t != 11;
			}
			return false;
		}

		private static Color32 PinColor(PinType t)
		{
			//IL_0000: 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_0020: Expected I4, but got Unknown
			//IL_0064: 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_004a: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			return (Color32)((t - 4) switch
			{
				1 => new Color32(byte.MaxValue, (byte)190, (byte)90, byte.MaxValue), 
				2 => new Color32((byte)190, (byte)120, byte.MaxValue, byte.MaxValue), 
				0 => new Color32((byte)150, (byte)150, (byte)150, byte.MaxValue), 
				5 => new Color32((byte)230, (byte)70, (byte)60, byte.MaxValue), 
				_ => new Color32(byte.MaxValue, (byte)240, (byte)200, byte.MaxValue), 
			});
		}

		public static string PinNear(Vector3 world, float range)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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)
			Minimap instance = Minimap.instance;
			if (!Object.op_Implicit((Object)(object)instance) || !(PinsField?.GetValue(instance) is List<PinData> list))
			{
				return null;
			}
			string text = null;
			float num = range * range;
			foreach (PinData item in list)
			{
				if (item != null && Shown(item.m_type) && !string.IsNullOrEmpty(item.m_name))
				{
					Vector2 val = new Vector2(item.m_pos.x - world.x, item.m_pos.z - world.z);
					float sqrMagnitude = ((Vector2)(ref val)).sqrMagnitude;
					if (sqrMagnitude < num)
					{
						num = sqrMagnitude;
						text = item.m_name;
					}
				}
			}
			if (text == null || Localization.instance == null)
			{
				return text;
			}
			return Localization.instance.Localize(text);
		}

		private static Color32 Sample(WorldGenerator wg, float wx, float wz, float water)
		{
			//IL_0017: 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_0070: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Invalid comparison between Unknown and I4
			//IL_0044: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Invalid comparison between Unknown and I4
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected I4, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Invalid comparison between Unknown and I4
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Invalid comparison between Unknown and I4
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: 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_00c2: Invalid comparison between Unknown and I4
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Invalid comparison between Unknown and I4
			if (wx * wx + wz * wz > 110250000f)
			{
				return new Color32((byte)6, (byte)8, (byte)14, byte.MaxValue);
			}
			float height = wg.GetHeight(wx, wz);
			if (height < water)
			{
				float num = Mathf.InverseLerp(water - 40f, water, height);
				return Color32.Lerp(new Color32((byte)10, (byte)38, (byte)82, byte.MaxValue), new Color32((byte)40, (byte)104, (byte)168, byte.MaxValue), num);
			}
			Biome biome = wg.GetBiome(new Vector3(wx, 0f, wz));
			Color32 val = default(Color32);
			if ((int)biome <= 16)
			{
				switch (biome - 1)
				{
				case 0:
					goto IL_00cc;
				case 1:
					goto IL_00fd;
				case 3:
					goto IL_0114;
				case 2:
					goto IL_0190;
				}
				if ((int)biome != 8)
				{
					if ((int)biome != 16)
					{
						goto IL_0190;
					}
					((Color32)(ref val))..ctor((byte)201, (byte)179, (byte)94, byte.MaxValue);
				}
				else
				{
					((Color32)(ref val))..ctor((byte)46, (byte)81, (byte)48, byte.MaxValue);
				}
			}
			else if ((int)biome != 32)
			{
				if ((int)biome != 64)
				{
					if ((int)biome != 512)
					{
						goto IL_0190;
					}
					((Color32)(ref val))..ctor((byte)78, (byte)74, (byte)95, byte.MaxValue);
				}
				else
				{
					((Color32)(ref val))..ctor((byte)207, (byte)230, (byte)242, byte.MaxValue);
				}
			}
			else
			{
				((Color32)(ref val))..ctor((byte)122, (byte)46, (byte)30, byte.MaxValue);
			}
			goto IL_01a5;
			IL_01a5:
			float num2 = 0.75f + 0.25f * Mathf.Clamp01((height - water) / 120f);
			return new Color32((byte)((float)(int)val.r * num2), (byte)((float)(int)val.g * num2), (byte)((float)(int)val.b * num2), byte.MaxValue);
			IL_00cc:
			((Color32)(ref val))..ctor((byte)127, (byte)163, (byte)75, byte.MaxValue);
			goto IL_01a5;
			IL_00fd:
			((Color32)(ref val))..ctor((byte)91, (byte)74, (byte)58, byte.MaxValue);
			goto IL_01a5;
			IL_0190:
			((Color32)(ref val))..ctor((byte)40, (byte)104, (byte)168, byte.MaxValue);
			goto IL_01a5;
			IL_0114:
			((Color32)(ref val))..ctor((byte)221, (byte)227, (byte)232, byte.MaxValue);
			goto IL_01a5;
		}
	}
	internal static class CelestialBuilding
	{
		public const string Category = "Cosmos Celestial";

		private static readonly (string Base, string Id, string Name)[] Shapes = new(string, string, string)[16]
		{
			("blackmarble_floor", "floor", "Floor 2x2"),
			("blackmarble_floor_triangle", "floor_tri", "Floor Triangle"),
			("blackmarble_tile_floor_1x1", "tile_1x1", "Floor Tile 1x1"),
			("blackmarble_floor_large", "floor_8x8", "Floor 8x8"),
			("blackmarble_tile_wall_2x2", "wall_2x2", "Wall 2x2"),
			("blackmarble_tile_wall_2x4", "wall_2x4", "Wall 2x4"),
			("blackmarble_1x1", "block_1x1", "Block 1x1"),
			("blackmarble_2x1x1", "block_2x1", "Block 2x1"),
			("blackmarble_2x2x2", "block_2x2", "Block 2x2"),
			("blackmarble_column_1", "column", "Column"),
			("blackmarble_column_2", "column_wide", "Column Wide"),
			("blackmarble_arch", "arch", "Arch"),
			("blackmarble_stair", "stair", "Stair"),
			("blackmarble_slope_1x2", "slope", "Slope 1x2"),
			("blackmarble_base_1", "plinth", "Plinth"),
			("blackmarble_out_1", "cornice", "Cornice")
		};

		public static readonly (string Id, string Name, string Blurb)[] Styles = new(string, string, string)[4]
		{
			("veins", "Star-veined", "glowing cyan-violet star veins"),
			("stars", "Starfield", "a twinkling starfield in the stone"),
			("pulse", "Pulsing", "star veins that slowly breathe"),
			("aurora", "Aurora", "star veins drifting through aurora colors")
		};

		private static Material[] _mats;

		private static readonly List<string> Names = new List<string>();

		internal static readonly Dictionary<string, RequirementConfig[]> Costs = new Dictionary<string, RequirementConfig[]>();

		public static readonly List<CosmosPieceDef> BoothDefs = new List<CosmosPieceDef>();

		public static void Register(ManualLogSource log, Action<GameObject> registerLate, Action<Piece> track)
		{
			//IL_0085: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Expected O, but got Unknown
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Expected O, but got Unknown
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			BuildMaterials();
			Names.Clear();
			BoothDefs.Clear();
			int num = 0;
			int num2 = 0;
			(string, string, string)[] shapes = Shapes;
			for (int i = 0; i < shapes.Length; i++)
			{
				(string, string, string) tuple = shapes[i];
				if (!Object.op_Implicit((Object)(object)PrefabManager.Instance.GetPrefab(tuple.Item1)))
				{
					num2++;
					continue;
				}
				for (int j = 0; j < Styles.Length; j++)
				{
					string text = "coga_celestial_" + tuple.Item2 + "_" + Styles[j].Id;
					PieceConfig val = new PieceConfig
					{
						Name = Styles[j].Name + " " + tuple.Item3,
						Description = "Black marble with " + Styles[j].Blurb + ". Builds, snaps and supports like vanilla black marble.",
						PieceTable = "Hammer",
						Category = "Cosmos Celestial",
						CraftingStation = "",
						Requirements = CosmosCosts.Celestial(tuple.Item2)
					};
					GameObject prefab = PrefabManager.Instance.GetPrefab(text);
					CustomPiece val2 = (Object.op_Implicit((Object)(object)prefab) ? new CustomPiece(prefab, false, val) : new CustomPiece(text, tuple.Item1, val));
					GameObject piecePrefab = val2.PiecePrefab;
					if (!Object.op_Implicit((Object)(object)piecePrefab))
					{
						continue;
					}
					SwapMarble(piecePrefab, _mats[j]);
					Piece component = piecePrefab.GetComponent<Piece>();
					if (Object.op_Implicit((Object)(object)component))
					{
						component.m_craftingStation = null;
					}
					PieceManager.Instance.AddPiece(val2);
					CosmosPieces.SetResources(piecePrefab.GetComponent<Piece>(), val.Requirements);
					registerLate(piecePrefab);
					track(piecePrefab.GetComponent<Piece>());
					Names.Add(text);
					Costs[text] = val.Requirements;
					num++;
					if (tuple.Item2 == "floor" || (j == 0 && (tuple.Item2 == "wall_2x4" || tuple.Item2 == "column" || tuple.Item2 == "arch")))
					{
						GameObject src = piecePrefab;
						BoothDefs.Add(new CosmosPieceDef
						{
							Prefab = text,
							Name = val.Name,
							Build = delegate(GameObject root)
							{
								BoothCopy(src, root);
							},
							Focus = new Vector3(0f, (tuple.Item2 == "floor") ? 0.2f : 1.5f, 0f),
							FocusRadius = ((tuple.Item2 == "floor") ? 1.6f : 2.4f),
							ViewDir = ((tuple.Item2 == "floor") ? new Vector3(0f, 0.9f, -1f) : new Vector3(0.3f, 0.15f, -1f))
						});
					}
				}
			}
			log.LogInfo((object)string.Format("Celestial building: {0} pieces ({1} vanilla black-marble shapes × {2} styles) on the {3} tab{4}.", num, Shapes.Length - num2, Styles.Length, "Cosmos Celestial", (num2 > 0) ? $", {num2} vanilla shapes not found" : ""));
		}

		public static void Shutdown()
		{
			foreach (string name in Names)
			{
				try
				{
					PieceManager instance = PieceManager.Instance;
					if (instance != null)
					{
						instance.RemovePiece(name);
					}
				}
				catch (Exception)
				{
				}
			}
			Names.Clear();
		}

		private static void SwapMarble(GameObject prefab, Material mat)
		{
			Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				Material[] sharedMaterials = val.sharedMaterials;
				bool flag = false;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					if (Object.op_Implicit((Object)(object)sharedMaterials[j]) && (((Object)sharedMaterials[j]).name.StartsWith("blackmarble", StringComparison.OrdinalIgnoreCase) || ((Object)sharedMaterials[j]).name.StartsWith("coga_celestial_", StringComparison.Ordinal)))
					{
						sharedMaterials[j] = mat;
						flag = true;
					}
				}
				if (flag)
				{
					val.sharedMaterials = sharedMaterials;
				}
			}
		}

		private static void BoothCopy(GameObject prefab, GameObject root)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			bool forceDisableInit = ZNetView.m_forceDisableInit;
			ZNetView.m_forceDisableInit = true;
			try
			{
				Object.Instantiate<GameObject>(prefab, root.transform, false).transform.localPosition = Vector3.zero;
			}
			finally
			{
				ZNetView.m_forceDisableInit = forceDisableInit;
			}
		}

		private static void BuildMaterials()
		{
			//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)
			//IL_0048: Expected O, but got Unknown
			Material veinMat = CosmosAssets.VeinMat;
			_mats = (Material[])(object)new Material[Styles.Length];
			for (int i = 0; i < Styles.Length; i++)
			{
				_mats[i] = new Material(veinMat)
				{
					name = "coga_celestial_" + Styles[i].Id
				};
			}
			Texture2D val = CosmosAssets.ToTexture(CelestialConcepts.StarSpeckTexture(CosmosAssets.Headless ? 8 : 256), "coga_celestial_specks", wrapU: true, wrapV: true);
			((Texture)val).filterMode = (FilterMode)1;
			((Texture)val).wrapMode = (TextureWrapMode)2;
			if (_mats[1].HasProperty("_EmissionMap"))
			{
				_mats[1].SetTexture("_EmissionMap", (Texture)(object)val);
			}
		}

		public static void Animate()
		{
			//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_002f: 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_0064: 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_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			if (_mats != null)
			{
				float num = (float)(CosmosTime.Now % 100000.0);
				Set(0, Color.white * 1.4f);
				Set(1, Color.white * (1.25f + 0.25f * Mathf.Sin(num * 2.3f) * Mathf.Sin(num * 0.7f)));
				Set(2, Color.white * (0.35f + 1.35f * (0.5f + 0.5f * Mathf.Sin(num * (float)Math.PI * 2f / 4f))));
				float num2 = Mathf.Repeat(0.5f + 0.18f * Mathf.Sin(num * (float)Math.PI * 2f / 20f) + 0.1f * Mathf.Sin(num * (float)Math.PI * 2f / 7f), 1f);
				Set(3, Color.HSVToRGB(num2, 0.55f, 1f) * 1.6f);
			}
		}

		private static void Set(int i, Color c)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)_mats[i]) && _mats[i].HasProperty("_EmissionColor"))
			{
				_mats[i].SetColor("_EmissionColor", c);
			}
		}
	}
	internal static class CosmosAim
	{
		private static readonly List<Collider> Colliders = new List<Collider>();

		private static readonly List<Piece> Nearby = new List<Piece>();

		public static Piece Find(out float distance, float maxRange = 50f)
		{
			//IL_0023: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			distance = float.MaxValue;
			if (!Object.op_Implicit((Object)(object)GameCamera.instance))
			{
				return null;
			}
			Transform transform = ((Component)GameCamera.instance).transform;
			Ray val = default(Ray);
			((Ray)(ref val))..ctor(transform.position, transform.forward);
			Piece result = null;
			float num = float.MaxValue;
			Nearby.Clear();
			Piece.GetAllPiecesInRadius(((Ray)(ref val)).origin, maxRange, Nearby);
			float num2 = default(float);
			foreach (Piece item in Nearby)
			{
				if (!Object.op_Implicit((Object)(object)item) || !((Object)item).name.StartsWith("coga_cosmos_", StringComparison.Ordinal))
				{
					continue;
				}
				((Component)item).GetComponentsInChildren<Collider>(Colliders);
				foreach (Collider collider in Colliders)
				{
					if (Object.op_Implicit((Object)(object)collider) && collider.enabled && !collider.isTrigger)
					{
						Bounds bounds = collider.bounds;
						if (((Bounds)(ref bounds)).Contains(((Ray)(ref val)).origin))
						{
							num2 = 0f;
						}
						else if (!((Bounds)(ref bounds)).IntersectRay(val, ref num2) || num2 < 0f)
						{
							continue;
						}
						float num3 = num2;
						Vector3 val2 = Vector3.Cross(((Ray)(ref val)).direction, ((Bounds)(ref bounds)).center - ((Ray)(ref val)).origin);
						float num4 = num3 + 0.01f * ((Vector3)(ref val2)).magnitude;
						if (num4 < num)
						{
							num = num4;
							result = item;
							distance = num2;
						}
					}
				}
			}
			return result;
		}
	}
	internal sealed class PlanetLook
	{
		public PlanetSpec Spec;

		public Material Body;

		public Material Ring;

		public Mesh RingMesh;

		public Sprite Icon;
	}
	internal static class CosmosAssets
	{
		public const int TexW = 128;

		public const int TexH = 64;

		public static Mesh Sphere;

		public static Material StarMat;

		public static Material NebulaMat;

		public static Material OrbitMat;

		public static Sprite StarIcon;

		public static readonly Dictionary<string, PlanetLook> Looks = new Dictionary<string, PlanetLook>();

		public static Material BlackMat;

		public static Material DiskMat;

		public static Material PhotonMat;

		public static Material ForceFieldMat;

		public static Material RockMat;

		public static Material BrassMat;

		public static Material AuroraMat;

		public static Material LineMat;

		public static Material MapMat;

		public static Material[] CrystalMats;

		public static Mesh[] Rocks;

		public static Mesh[] Crystals;

		public static Mesh RibbonMesh;

		public static Mesh DiscMesh;

		public static Sprite BlackHoleIcon;

		public static Sprite CometIcon;

		public static Sprite GalaxyIcon;

		public static Sprite AuroraIcon;

		public static Sprite ArmillaryIcon;

		public static Sprite MapIcon;

		public static Sprite ConstellationIcon;

		public static Sprite[] CrystalIcons;

		public static readonly (string Id, string Name, Col Tint)[] CrystalKinds = new(string, string, Col)[3]
		{
			("amethyst", "Amethyst Cluster", Col.Hex("A66BFF")),
			("frost", "Frost Crystal Cluster", Col.Hex("5CE1FF")),
			("sunstone", "Sunstone Cluster", Col.Hex("FF9A3C"))
		};

		private static Material _opaqueTpl;

		private static Material _alphaTpl;

		private static Material _additiveTpl;

		public static Material StarMapMat;

		public static Material VeinMat;

		public static Material DarkMarbleMat;

		public static Material RuneMat;

		public static Material RiftMat;

		public static Material RiftOverlayMat;

		public static Material HaloMat;

		public static Sprite[] CelestialIcons;

		public static Material PlanetariumMat;

		private static readonly Color Neutral = new Color(0.5f, 0.5f, 0.5f, 0.5f);

		public static Material Sparkle0Mat;

		public static Material Sparkle4Mat;

		public static Material Sparkle8Mat;

		public static Material WispMat;

		public static Material GlowMat;

		public static Material BeamMat;

		public static Material ArcMat;

		public static Material TrailMat;

		public static Material RingLightMat;

		public static Material ShockMat;

		public static Material SoftRingMat;

		public static Mesh QuadMesh;

		public static Mesh GemMesh;

		public static Mesh TaperQuadMesh;

		public static Mesh CrystalBaseMesh;

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

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

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

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

		private static Material _starHide;

		public static readonly (string Name, Color Deep, Color Mid, Color Cloud, Color Haze)[] HidePalettes = new(string, Color, Color, Color, Color)[5]
		{
			("Night", new Color(0.04f, 0.07f, 0.26f), new Color(0.24f, 0.1f, 0.5f), new Color(0.12f, 0.72f, 0.85f), new Color(0.3f, 0.45f, 1f)),
			("Rose", new Color(0.18f, 0.04f, 0.16f), new Color(0.55f, 0.12f, 0.38f), new Color(1f, 0.62f, 0.42f), new Color(1f, 0.45f, 0.7f)),
			("Aurora", new Color(0.02f, 0.12f, 0.14f), new Color(0.05f, 0.38f, 0.32f), new Color(0.55f, 1f, 0.45f), new Color(0.3f, 0.9f, 0.85f)),
			("Ember", new Color(0.16f, 0.03f, 0.03f), new Color(0.55f, 0.12f, 0.05f), new Color(1f, 0.6f, 0.15f), new Color(1f, 0.35f, 0.2f)),
			("Frost", new Color(0.05f, 0.09f, 0.2f), new Color(0.3f, 0.45f, 0.7f), new Color(0.85f, 0.95f, 1f), new Color(0.6f, 0.8f, 1f))
		};

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

		private static float _nextHideGlow;

		private const float HideGlowDay = 0.85f;

		private const float HideGlowNight = 1.8f;

		private static readonly Dictionary<int, (Material Rift, Material Overlay, Material Halo)> Rifts = new Dictionary<int, (Material, Material, Material)>();

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

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

		public const float PanoramaElMin = -30f;

		private static readonly Dictionary<int, Task<byte[]>> PanoramaJobs = new Dictionary<int, Task<byte[]>>();

		private static Material _panoramaWait;

		private const int PanoramaW = 3072;

		private const int PanoramaH = 768;

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

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

		public const float LayerFadeRows = 0.13f;

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

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

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

		private static Material _glass;

		private static Material _inlay;

		private static Material _clockFace;

		private static Material _snowCover;

		private static Material _ice;

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

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

		private static readonly Dictionary<(int, Color), Material> LeafBlades = new Dictionary<(int, Color), Material>();

		public static int LeafStyle = 1;

		private static Mesh _leafBlade;

		private const int LeafW = 16;

		private const int LeafH = 32;

		private static readonly Dictionary<string, Sprite> SkyIcons = new Dictionary<string, Sprite>();

		public static bool Ready { get; private set; }

		public static bool Headless => (int)SystemInfo.graphicsDeviceType == 4;

		public static bool CelestialMarbleIsVanilla { get; private set; }

		private static string PanoramaCacheDir => Path.Combine(Paths.CachePath, "coga_cosmos");

		private static string PanoramaBuildKey => PaintCache.PainterTag;

		public static Material PanoramaPlaceholder
		{
			get
			{
				//IL_0011: 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)
				if (!Object.op_Implicit((Object)(object)_panoramaWait))
				{
					_panoramaWait = PlainMaterial("coga_cosmos_panorama_wait", Color.black, 0f, 0f, new Color(0.55f, 0.7f, 0.85f));
				}
				return _panoramaWait;
			}
		}

		public static Mesh LeafBladeMesh
		{
			get
			{
				//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d9: Expected O, but got Unknown
				//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d5: 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)
				if (Object.op_Implicit((Object)(object)_leafBlade))
				{
					return _leafBlade;
				}
				List<Vector3> list = new List<Vector3>();
				List<Vector3> list2 = new List<Vector3>();
				List<Vector2> list3 = new List<Vector2>();
				List<int> list4 = new List<int>();
				for (int i = 0; i < 2; i++)
				{
					int count = list.Count;
					for (int j = 0; j <= 8; j++)
					{
						float num = (float)j / 8f;
						float num2 = Mathf.Pow(Mathf.Max(0f, Mathf.Sin((float)Math.PI * Mathf.Pow(num, 0.8f))), 0.75f);
						float num3 = -1f + 2f * num;
						float num4 = 0.45f * num * num;
						for (int k = 0; k < 3; k++)
						{
							float num5 = (float)(k - 1) * num2;
							float num6 = num4 + ((k == 1) ? 0f : (0.22f * num2));
							list.Add(new Vector3(num5, num3, num6));
							list2.Add((i == 0) ? Vector3.back : Vector3.forward);
							list3.Add(new Vector2((float)k * 0.5f, num));
						}
					}
					for (int l = 0; l < 8; l++)
					{
						for (int m = 0; m < 2; m++)
						{
							int num7 = count + l * 3 + m;
							int num8 = num7 + 1;
							int num9 = num7 + 3;
							int num10 = num9 + 1;
							if (i == 0)
							{
								list4.AddRange(new int[6] { num7, num9, num8, num8, num9, num10 });
							}
							else
							{
								list4.AddRange(new int[6] { num7, num8, num9, num8, num10, num9 });
							}
						}
					}
				}
				_leafBlade = new Mesh
				{
					name = "coga_leaf_blade"
				};
				_leafBlade.SetVertices(list);
				_leafBlade.SetUVs(0, list3);
				_leafBlade.SetTriangles(list4, 0);
				_leafBlade.RecalculateNormals();
				_leafBlade.RecalculateBounds();
				return _leafBlade;
			}
		}

		public static PlanetLook Look(PlanetSpec s)
		{
			return Looks[s.Id];
		}

		public static void Build(ManualLogSource log)
		{
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			if (Ready)
			{
				return;
			}
			FindTemplates(log);
			Sphere = MeshBuilder.UvSphere(64, 32);
			((Object)Sphere).name = "coga_cosmos_sphere";
			int w = (Headless ? 16 : 128);
			int h = (Headless ? 8 : 64);
			foreach (PlanetSpec item in PlanetSpec.Lamps.Concat(new PlanetSpec[1] { PlanetSpec.Sun }))
			{
				string text = "coga_" + item.Id;
				Texture2D val = PaintCache.Find(text + "_albedo");
				Texture2D val2 = PaintCache.Find(text + "_emission");
				Texture2D val3 = (item.HasRing ? PaintCache.Find(text + "_ring") : null);
				Sprite val4 = PaintCache.FindSprite(text + "_icon");
				if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val2) || (item.HasRing && !Object.op_Implicit((Object)(object)val3)) || !Object.op_Implicit((Object)(object)val4))
				{
					PlanetPainter.Paint(item, w, h, out var albedo, out var emission);
					val = PaintCache.Store<Texture2D>(text + "_albedo", ToTexture(albedo, text + "_albedo", wrapU: true));
					val2 = PaintCache.Store<Texture2D>(text + "_emission", ToTexture(emission, text + "_emission", wrapU: true));
					Image image = (item.HasRing ? PlanetPainter.Ring(item, 48) : null);
					val3 = ((image != null) ? PaintCache.Store<Texture2D>(text + "_ring", ToTexture(image, text + "_ring", wrapU: false)) : null);
					val4 = PaintCache.Store<Sprite>(text + "_icon", ToSprite(PlanetPainter.Preview(item, albedo, emission, image, Headless ? 16 : 128, 0.12f, 0.6f, 30f), text + "_icon"));
				}
				PlanetLook planetLook = new PlanetLook
				{
					Spec = item,
					Body = BodyMaterial(item, val, val2)
				};
				if (item.HasRing)
				{
					planetLook.RingMesh = MeshBuilder.Ring(item.RingInner, item.RingOuter, 128);
					planetLook.Ring = RingMaterial(item, val3);
				}
				planetLook.Icon = val4;
				Looks[item.Id] = planetLook;
			}
			Image image2 = PlanetPainter.StarSprite(12);
			StarMat = AdditiveMaterial("coga_cosmos_stars", (Texture)(object)ToTexture(image2, "coga_star", wrapU: false), new Color(0.5f, 0.5f, 0.5f, 0.5f));
			NebulaMat = AdditiveMaterial("coga_cosmos_nebula", (Texture)(object)ToTexture(PlanetPainter.SoftBlob(24, 5), "coga_nebula", wrapU: false), new Color(0.5f, 0.5f, 0.5f, 0.5f));
			OrbitMat = AdditiveMaterial("coga_cosmos_orbit", (Texture)(object)Texture2D.whiteTexture, new Color(0.22f, 0.27f, 0.38f, 0.5f));
			StarIcon = ToSprite(StarIconImage(image2), "coga_star_icon");
			BuildExtras();
			Ready = true;
			log.LogInfo((object)string.Format("Cosmos assets built: {0} planet looks; templates opaque={1} alpha={2} additive={3}; celestial marble={4}", Looks.Count, Name(_opaqueTpl), Name(_alphaTpl), Name(_additiveTpl), CelestialMarbleIsVanilla ? "vanilla blackmarble + Charredspawner_mat glow" : "FALLBACK (vanilla marble not found)"));
		}

		private static void BuildExtras()
		{
			//IL_000b: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			BlackMat = PlainMaterial("coga_cosmos_black", Color.black, 0.92f, 0f, Color.black);
			DiskMat = AlphaGlow("coga_cosmos_disk", ToTexture(Shapes.AccretionDisk(64, 64, 31), "coga_disk", wrapU: false, wrapV: true), 2.2f);
			PhotonMat = AdditiveMaterial("coga_cosmos_photon", (Texture)(object)Texture2D.whiteTexture, new Color(1f, 0.8f, 0.55f, 0.6f));
			RockMat = new Material(Look(PlanetSpec.Moon).Body)
			{
				name = "coga_cosmos_rock"
			};
			RockMat.SetColor("_EmissionColor", Color.white * 0.05f);
			RockMat.color = new Color(0.82f, 0.77f, 0.72f);
			BrassMat = PlainMaterial("coga_cosmos_brass", new Color(0.79f, 0.62f, 0.33f), 0.65f, 0.85f, Color.black);
			Image aurora = Shapes.Aurora(64, 16, 17);
			AuroraMat = AdditiveMaterial("coga_cosmos_aurora", (Texture)(object)ToTexture(aurora, "coga_aurora", wrapU: true, wrapV: false, mips: true, smooth: true), new Color(0.5f, 0.5f, 0.5f, 0.5f));
			LineMat = AdditiveMaterial("coga_cosmos_lines", (Texture)(object)Texture2D.whiteTexture, new Color(0.3f, 0.42f, 0.75f, 0.5f));
			MapMat = PlainMaterial("coga_cosmos_map", Color.white, 0.3f, 0f, Color.white * 0.75f);
			SetTex(MapMat, "_MainTex", (Texture)(object)Texture2D.blackTexture);
			SetTex(MapMat, "_EmissionMap", (Texture)(object)Texture2D.blackTexture);
			CrystalMats = (Material[])(object)new Material[CrystalKinds.Length];
			CrystalIcons = (Sprite[])(object)new Sprite[CrystalKinds.Length];
			for (int i = 0; i < CrystalKinds.Length; i++)
			{
				Col tint = CrystalKinds[i].Tint;
				Texture2D t = ToTexture(Shapes.Gradient(12, tint * 0.35f, tint, Col.Lerp(tint, new Col(1f, 1f, 1f), 0.75f)), "coga_crystal_" + CrystalKinds[i].Id, wrapU: false);
				Material val = PlainMaterial("coga_cosmos_crystal_" + CrystalKinds[i].Id, Color.white, 0.85f, 0f, Color.white * 1.1f);
				SetTex(val, "_MainTex", (Texture)(object)t);
				SetTex(val, "_EmissionMap", (Texture)(object)t);
				CrystalMats[i] = val;
				CrystalIcons[i] = PaintCache.Sprite("coga_crystal_icon_" + CrystalKinds[i].Id, () => ToSprite(Shapes.CrystalIcon(128, tint), "coga_crystal_icon_" + CrystalKinds[i].Id));
			}
			Rocks = (Mesh[])(object)new Mesh[6];
			for (int num = 0; num < Rocks.Length; num++)
			{
				Rocks[num] = MeshBuilder.Rock(11 + num);
				((Object)Rocks[num]).name = "coga_rock_" + num;
			}
			Crystals = (Mesh[])(object)new Mesh[CrystalKinds.Length];
			for (int num2 = 0; num2 < Crystals.Length; num2++)
			{
				Crystals[num2] = MeshBuilder.CrystalCluster(21 + num2);
				((Object)Crystals[num2]).name = "coga_crystals_" + num2;
			}
			RibbonMesh = MeshBuilder.Ribbon(6f, 2.4f, 64, 8);
			DiscMesh = MeshBuilder.Disc(96);
			BlackHoleIcon = PaintCache.Sprite("coga_icon_blackhole", () => ToSprite(Shapes.BlackHoleIcon(128), "coga_icon_blackhole"));
			CometIcon = PaintCache.Sprite("coga_icon_comet", () => ToSprite(Shapes.CometIcon(128), "coga_icon_comet"));
			GalaxyIcon = PaintCache.Sprite("coga_icon_galaxy", () => ToSprite(Shapes.GalaxyIcon(128), "coga_icon_galaxy"));
			AuroraIcon = PaintCache.Sprite("coga_icon_aurora", () => ToSprite(Shapes.AuroraIcon(128, aurora), "coga_icon_aurora"));
			ArmillaryIcon = PaintCache.Sprite("coga_icon_armillary", () => ToSprite(Shapes.ArmillaryIcon(128), "coga_icon_armillary"));
			MapIcon = PaintCache.Sprite("coga_icon_map", () => ToSprite(Shapes.MapIcon(128), "coga_icon_map"));
			ConstellationIcon = PaintCache.Sprite("coga_icon_constellation", () => ToSprite(Shapes.ConstellationIcon(128), "coga_icon_constellation"));
			BuildCelestial();
			BuildSky();
		}

		private static Material CelestialMarble(int s)
		{
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: 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_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Expected O, but got Unknown
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = PaintCache.Find("coga_vein");
			Texture2D val2 = PaintCache.Find("coga_vein_em");
			if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val2))
			{
				CelestialConcepts.VeinTextures(256 / s, 256 / s, 2.8f, 17.5f, 9, out var albedo, out var emission, 0.81f, 0.89f);
				val = PaintCache.Store<Texture2D>("coga_vein", ToTexture(albedo, "coga_vein", wrapU: true, wrapV: true));
				val2 = PaintCache.Store<Texture2D>("coga_vein_em", ToTexture(emission, "coga_vein_em", wrapU: true, wrapV: true));
			}
			Texture2D[] array = (Texture2D[])(object)new Texture2D[2] { val, val2 };
			foreach (Texture2D obj in array)
			{
				((Texture)obj).filterMode = (FilterMode)1;
				((Texture)obj).wrapMode = (TextureWrapMode)2;
			}
			Material[] source = Resources.FindObjectsOfTypeAll<Material>();
			Material val3 = ((IEnumerable<Material>)source).FirstOrDefault((Func<Material, bool>)((Material m) => Object.op_Implicit((Object)(object)m) && ((Object)m).name == "Charredspawner_mat" && Object.op_Implicit((Object)(object)m.shader) && ((Object)m.shader).name == "Custom/Piece"));
			Material val4 = ((IEnumerable<Material>)source).FirstOrDefault((Func<Material, bool>)((Material m) => Object.op_Implicit((Object)(object)m) && ((Object)m).name == "blackmarble_movable" && Object.op_Implicit((Object)(object)m.shader) && ((Object)m.shader).name == "Custom/Piece"));
			if (Object.op_Implicit((Object)(object)val3) && Object.op_Implicit((Object)(object)val4) && val4.HasProperty("_MainTex") && val3.HasProperty("_EmissionMap"))
			{
				Material val5 = new Material(val3)
				{
					name = "coga_cosmos_celestial_marble"
				};
				val5.SetTexture("_MainTex", val4.GetTexture("_MainTex"));
				val5.SetTextureScale("_MainTex", Vector2.one);
				val5.SetTextureOffset("_MainTex", Vector2.zero);
				if (val5.HasProperty("_BumpMap") && val4.HasProperty("_BumpMap"))
				{
					val5.SetTexture("_BumpMap", val4.GetTexture("_BumpMap"));
					val5.SetTextureScale("_BumpMap", Vector2.one);
				}
				val5.color = val4.color;
				val5.SetTexture("_EmissionMap", (Texture)(object)val2);
				val5.SetTextureScale("_EmissionMap", Vector2.one);
				val5.SetColor("_EmissionColor", Color.white * 1.4f);
				val5.EnableKeyword("_EMISSION");
				CelestialMarbleIsVanilla = true;
				return val5;
			}
			Material obj2 = PlainMaterial("coga_cosmos_vein", Color.white, 0.25f, 0f, Color.white * 1.1f);
			SetTex(obj2, "_MainTex", (Texture)(object)val);
			SetTex(obj2, "_EmissionMap", (Texture)(object)val2);
			return obj2;
		}

		private static Material PlanetariumMarble(int s)
		{
			//IL_0080: 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_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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			Texture2D val = PaintCache.Texture("coga_starmap_hi", () => ToTexture(CelestialConcepts.StarMapTexture(512 / s), "coga_starmap_hi", wrapU: false));
			((Texture)val).filterMode = (FilterMode)1;
			if (CelestialMarbleIsVanilla && Object.op_Implicit((Object)(object)VeinMat))
			{
				Material val2 = new Material(VeinMat)
				{
					name = "coga_cosmos_planetarium"
				};
				val2.SetTexture("_EmissionMap", (Texture)(object)val);
				val2.SetColor("_EmissionColor", Color.white * 1.1f);
				return val2;
			}
			Material obj = PlainMaterial("coga_cosmos_planetarium", Color.white, 0.2f, 0f, Color.white * 0.8f);
			SetTex(obj, "_MainTex", (Texture)(object)val);
			SetTex(obj, "_EmissionMap", (Texture)(object)val);
			return obj;
		}

		private static void BuildCelestial()
		{
			//IL_003b: 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_0054: 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)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Expected O, but got Unknown
			//IL_011f: 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_0168: 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_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			int s = ((!Headless) ? 1 : 8);
			Texture2D t = PaintCache.Texture("coga_starmap", () => ToTexture(CelestialConcepts.StarMapTexture(Headless ? 8 : 128), "coga_starmap", wrapU: false));
			StarMapMat = PlainMaterial("coga_cosmos_starmap", Color.white, 0.1f, 0f, Color.white * 0.7f);
			SetTex(StarMapMat, "_MainTex", (Texture)(object)t);
			SetTex(StarMapMat, "_EmissionMap", (Texture)(object)t);
			VeinMat = CelestialMarble(s);
			PlanetariumMat = PlanetariumMarble(s);
			RuneMat = AdditiveMaterial("coga_cosmos_runes", (Texture)(object)PaintCache.Texture("coga_runes", () => ToTexture(CelestialConcepts.RuneRingTexture(Headless ? 8 : 256), "coga_runes", wrapU: false, wrapV: false, mips: false)), new Color(1f, 1f, 1f, 1f));
			DarkMarbleMat = new Material(VeinMat)
			{
				name = "coga_cosmos_dark_marble"
			};
			if (DarkMarbleMat.HasProperty("_EmissionColor"))
			{
				DarkMarbleMat.SetColor("_EmissionColor", Color.black);
			}
			Texture2D val = PaintCache.Texture("coga_rift", () => ToTexture(CelestialConcepts.RiftTexture(Headless ? 8 : 64), "coga_rift", wrapU: false));
			RiftMat = PlainMaterial("coga_cosmos_rift", Color.white, 0.1f, 0f, Color.white * 1.2f);
			SetTex(RiftMat, "_MainTex", (Texture)(object)val);
			SetTex(RiftMat, "_EmissionMap", (Texture)(object)val);
			RiftOverlayMat = AdditiveMaterial("coga_cosmos_rift_overlay", (Texture)(object)val, new Color(0.32f, 0.3f, 0.4f, 0.5f));
			Texture2D val2 = PaintCache.Texture("coga_halo", () => ToTexture(PlanetPainter.SoftBlob(Headless ? 8 : 128, 11), "coga_halo", wrapU: false));
			((Texture)val2).filterMode = (FilterMode)1;
			HaloMat = AdditiveMaterial("coga_cosmos_halo", (Texture)(object)val2, new Color(0.42f, 0.28f, 0.55f, 0.35f));
			CelestialIcons = (Sprite[])(object)new Sprite[7];
			if (Headless)
			{
				return;
			}
			bool flag = true;
			for (int num = 0; num < CelestialIcons.Length; num++)
			{
				CelestialIcons[num] = PaintCache.FindSprite("coga_celestial_icon_" + num);
				flag &= Object.op_Implicit((Object)(object)CelestialIcons[num]);
			}
			if (!flag)
			{
				(string, Image)[] array = CelestialConcepts.All(128);
				for (int num2 = 0; num2 < array.Length && num2 < CelestialIcons.Length; num2++)
				{
					CelestialIcons[num2] = PaintCache.Store<Sprite>("coga_celestial_icon_" + num2, ToSprite(array[num2].Item2, "coga_icon_" + array[num2].Item1));
				}
			}
		}

		private static void FindTemplates(ManualLogSource log)
		{
			Material[] source = (from m in Resources.FindObjectsOfTypeAll<Material>()
				where Object.op_Implicit((Object)(object)m) && !((Object)m).name.StartsWith("coga_", StringComparison.Ordinal)
				select m).ToArray();
			_opaqueTpl = (from m in source
				where Object.op_Implicit((Object)(object)m) && Object.op_Implicit((Object)(object)m.shader) && ((Object)m.shader).name == "Standard" && m.IsKeywordEnabled("_EMISSION") && !HasBadKeyword(m, opaque: true)
				orderby m.shaderKeywords.Length, ((Object)m).name
				select m).FirstOrDefault();
			_alphaTpl = (from m in source
				where Object.op_Implicit((Object)(object)m) && Object.op_Implicit((Object)(object)m.shader) && ((Object)m.shader).name == "Standard" && m.IsKeywordEnabled("_EMISSION") && m.IsKeywordEnabled("_ALPHABLEND_ON") && !HasBadKeyword(m, opaque: false)
				orderby m.shaderKeywords.Length, ((Object)m).name
				select m).FirstOrDefault();
			_additiveTpl = ((IEnumerable<Material>)source).FirstOrDefault((Func<Material, bool>)((Material m) => Object.op_Implicit((Object)(object)m) && Object.op_Implicit((Object)(object)m.shader) && ((Object)m.shader).name == "Legacy Shaders/Particles/Additive")) ?? ((IEnumerable<Material>)source).FirstOrDefault((Func<Material, bool>)((Material m) => Object.op_Implicit((Object)(object)m) && Object.op_Implicit((Object)(object)m.shader) && ((Object)m.shader).name == "Legacy Shaders/Particles/Alpha Blended"));
			ForceFieldMat = ((IEnumerable<Material>)source).FirstOrDefault((Func<Material, bool>)((Material m) => ((Object)m).name == "ForceField" && Object.op_Implicit((Object)(object)m.shader) && ((Object)m.shader).name == "Custom/Distortion"));
			if (!Object.op_Implicit((Object)(object)_opaqueTpl) || !Object.op_Implicit((Object)(object)_alphaTpl) || !Object.op_Implicit((Object)(object)_additiveTpl))
			{
				log.LogWarning((object)"Cosmos: a vanilla template material was not found; falling back to Shader.Find (may render pink if the variant was stripped).");
			}
		}

		private static bool HasBadKeyword(Material m, bool opaque)
		{
			string[] shaderKeywords = m.shaderKeywords;
			foreach (string text in shaderKeywords)
			{
				if (!(text == "_EMISSION") && !(text == "_NORMALMAP") && (opaque || !(text == "_ALPHABLEND_ON")))
				{
					return true;
				}
			}
			return false;
		}

		private static string Name(Material m)
		{
			if (!Object.op_Implicit((Object)(object)m))
			{
				return "<none>";
			}
			return ((Object)m).name;
		}

		private static Material BodyMaterial(PlanetSpec s, Texture2D albedo, Texture2D emission)
		{
			//IL_0022: 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)
			//IL_0027: 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_0043: Expected O, but got Unknown
			//IL_0043: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			//IL_0066: 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_0077: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected O, but got Unknown
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Expected O, but got Unknown
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Expected O, but got Unknown
			//IL_00d3: Expected O, but got Unknown
			Material val = (Object.op_Implicit((Object)(object)_opaqueTpl) ? new Material(_opaqueTpl) : new Material(Shader.Find("Standard")));
			((Object)val).name = "coga_cosmos_" + s.Id;
			ClearMaps(val);
			val.color = Color.white;
			SetTex(val, "_MainTex", (Texture)(object)albedo);
			SetTex(val, "_EmissionMap", (Texture)(object)emission);
			val.SetColor("_EmissionColor", Color.white * s.Glow);
			val.EnableKeyword("_EMISSION");
			val.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)0;
			SetFloat(val, "_Metallic", 0f);
			SetFloat(val, "_Glossiness", (s.Style == PlanetStyle.Terra) ? 0.2f : 0.08f);
			SetFloat(val, "_GlossMapScale", 0