Decompiled source of SmelterGrateFire v0.3.0

BepInEx/plugins/SmelterGrateFire/SmelterGrateFire.dll

Decompiled an hour ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("SmelterGrateFire")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.3.0.0")]
[assembly: AssemblyInformationalVersion("0.3.0")]
[assembly: AssemblyProduct("SmelterGrateFire")]
[assembly: AssemblyTitle("SmelterGrateFire")]
[assembly: AssemblyVersion("0.3.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SmelterGrateFire
{
	internal sealed class UISkin : IDisposable
	{
		private delegate bool ImageLoader(Texture2D texture, byte[] bytes, bool unreadable);

		private sealed class Glyph
		{
			internal readonly int Code;

			internal readonly int X;

			internal readonly int Y;

			internal readonly int W;

			internal readonly int H;

			internal readonly int Left;

			internal readonly int Top;

			internal readonly float Advance;

			internal Glyph(int code, int x, int y, int w, int h, int left, int top, float advance)
			{
				Code = code;
				X = x;
				Y = y;
				W = w;
				H = h;
				Left = left;
				Top = top;
				Advance = advance;
			}
		}

		private static readonly ImageLoader LoadPng = (ImageLoader)Delegate.CreateDelegate(typeof(ImageLoader), Type.GetType("UnityEngine.ImageConversion, UnityEngine.ImageConversionModule", throwOnError: true).GetMethod("LoadImage", new Type[3]
		{
			typeof(Texture2D),
			typeof(byte[]),
			typeof(bool)
		}));

		private readonly List<Texture2D> textures = new List<Texture2D>();

		internal readonly Texture2D Panel;

		internal readonly Texture2D Title;

		internal readonly Texture2D Ring;

		internal readonly Texture2D Buttons;

		internal readonly Texture2D Slider;

		internal readonly Texture2D PreviewFrame;

		private readonly Texture2D atlas;

		private static readonly Glyph[] Glyphs = new Glyph[81]
		{
			new Glyph(32, 4, 4, 19, 0, 0, 0, 19f),
			new Glyph(33, 100, 4, 16, 47, 0, -46, 16f),
			new Glyph(34, 196, 4, 25, 46, 0, -46, 25f),
			new Glyph(39, 292, 4, 14, 46, 0, -46, 14f),
			new Glyph(40, 388, 4, 23, 60, 0, -50, 23f),
			new Glyph(41, 484, 4, 22, 60, 0, -50, 22f),
			new Glyph(43, 580, 4, 36, 30, 0, -30, 36f),
			new Glyph(44, 676, 4, 15, 17, 0, -7, 15f),
			new Glyph(45, 772, 4, 27, 21, 0, -21, 27f),
			new Glyph(46, 868, 4, 14, 8, 0, -7, 14f),
			new Glyph(47, 964, 4, 29, 55, 0, -49, 29f),
			new Glyph(48, 1060, 4, 35, 46, 0, -45, 35f),
			new Glyph(49, 1156, 4, 28, 46, 0, -45, 28f),
			new Glyph(50, 1252, 4, 34, 45, 0, -45, 34f),
			new Glyph(51, 1348, 4, 35, 46, 0, -45, 35f),
			new Glyph(52, 1444, 4, 36, 47, 0, -46, 36f),
			new Glyph(53, 4, 100, 33, 45, 0, -44, 33f),
			new Glyph(54, 100, 100, 35, 46, 0, -45, 35f),
			new Glyph(55, 196, 100, 34, 44, 0, -44, 34f),
			new Glyph(56, 292, 100, 35, 46, 0, -45, 35f),
			new Glyph(57, 388, 100, 35, 46, 0, -45, 35f),
			new Glyph(58, 484, 100, 14, 30, 0, -29, 14f),
			new Glyph(59, 580, 100, 15, 39, 0, -29, 15f),
			new Glyph(61, 676, 100, 36, 23, 0, -23, 36f),
			new Glyph(63, 772, 100, 31, 46, 0, -45, 31f),
			new Glyph(65, 868, 100, 46, 48, 0, -47, 46f),
			new Glyph(66, 964, 100, 44, 45, 0, -45, 44f),
			new Glyph(67, 1060, 100, 43, 48, 0, -47, 43f),
			new Glyph(68, 1156, 100, 47, 45, 0, -45, 47f),
			new Glyph(69, 1252, 100, 42, 49, 0, -47, 42f),
			new Glyph(70, 1348, 100, 40, 48, 0, -47, 40f),
			new Glyph(71, 1444, 100, 47, 48, 0, -47, 47f),
			new Glyph(72, 4, 196, 48, 47, 0, -46, 48f),
			new Glyph(73, 100, 196, 19, 46, 0, -46, 19f),
			new Glyph(74, 196, 196, 31, 53, 0, -46, 31f),
			new Glyph(75, 292, 196, 47, 47, 0, -47, 47f),
			new Glyph(76, 388, 196, 40, 48, 0, -46, 40f),
			new Glyph(77, 484, 196, 59, 47, 0, -46, 59f),
			new Glyph(78, 580, 196, 50, 48, 0, -46, 50f),
			new Glyph(79, 676, 196, 49, 47, 0, -46, 49f),
			new Glyph(80, 772, 196, 42, 46, 0, -45, 42f),
			new Glyph(81, 868, 196, 52, 57, 0, -46, 52f),
			new Glyph(82, 964, 196, 48, 46, 0, -45, 47f),
			new Glyph(83, 1060, 196, 43, 49, 0, -48, 43f),
			new Glyph(84, 1156, 196, 47, 48, 0, -47, 47f),
			new Glyph(85, 1252, 196, 48, 47, 0, -46, 48f),
			new Glyph(86, 1348, 196, 46, 47, 0, -46, 46f),
			new Glyph(87, 1444, 196, 65, 47, 0, -46, 65f),
			new Glyph(88, 4, 292, 47, 46, 0, -46, 47f),
			new Glyph(89, 100, 292, 47, 46, 0, -45, 47f),
			new Glyph(90, 196, 292, 44, 49, 0, -47, 44f),
			new Glyph(91, 292, 292, 22, 57, 0, -49, 22f),
			new Glyph(92, 388, 292, 29, 55, 0, -49, 29f),
			new Glyph(93, 484, 292, 22, 57, 0, -49, 22f),
			new Glyph(95, 580, 292, 37, 9, 0, 0, 37f),
			new Glyph(97, 676, 292, 35, 32, 0, -31, 35f),
			new Glyph(98, 772, 292, 34, 47, 0, -46, 34f),
			new Glyph(99, 868, 292, 31, 32, 0, -31, 31f),
			new Glyph(100, 964, 292, 35, 47, 0, -46, 35f),
			new Glyph(101, 1060, 292, 31, 32, 0, -31, 31f),
			new Glyph(102, 1156, 292, 24, 48, 0, -47, 24f),
			new Glyph(103, 1252, 292, 35, 45, 0, -32, 35f),
			new Glyph(104, 1348, 292, 32, 47, 0, -46, 32f),
			new Glyph(105, 1444, 292, 16, 43, 0, -43, 16f),
			new Glyph(106, 4, 388, 17, 56, 0, -43, 17f),
			new Glyph(107, 100, 388, 33, 46, 0, -46, 33f),
			new Glyph(108, 196, 388, 16, 47, 0, -47, 16f),
			new Glyph(109, 292, 388, 50, 32, 0, -31, 50f),
			new Glyph(110, 388, 388, 32, 32, 0, -31, 32f),
			new Glyph(111, 484, 388, 32, 32, 0, -31, 32f),
			new Glyph(112, 580, 388, 34, 44, 0, -31, 34f),
			new Glyph(113, 676, 388, 35, 44, 0, -31, 35f),
			new Glyph(114, 772, 388, 25, 32, 0, -31, 25f),
			new Glyph(115, 868, 388, 27, 32, 0, -31, 27f),
			new Glyph(116, 964, 388, 21, 42, 0, -41, 21f),
			new Glyph(117, 1060, 388, 32, 32, 0, -31, 32f),
			new Glyph(118, 1156, 388, 32, 31, 0, -30, 32f),
			new Glyph(119, 1252, 388, 47, 31, 0, -30, 47f),
			new Glyph(120, 1348, 388, 31, 30, 0, -30, 31f),
			new Glyph(121, 1444, 388, 32, 43, 0, -30, 32f),
			new Glyph(122, 4, 484, 30, 30, 0, -30, 30f)
		};

		private static readonly Dictionary<int, float> Kern = new Dictionary<int, float>();

		internal UISkin()
		{
			Panel = Load("SmelterGrateFire-Panel-Concept.png");
			Title = Load("SmelterGrateFire-Title-Art-Original.png");
			Ring = Load("SmelterGrateFire-Wheel-Frame.png");
			Buttons = Load("SmelterGrateFire-Button-States.png");
			Slider = Load("SmelterGrateFire-Slider-Concept.png");
			atlas = Load("font-atlas.png");
			PreviewFrame = Load("SmelterGrateFire-Color-Preview-Frame.png");
		}

		private Texture2D Load(string name)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SmelterGrateFire.UI." + name);
			if (stream == null)
			{
				throw new InvalidOperationException("Missing embedded UI artwork: " + name);
			}
			byte[] array = new byte[checked((int)stream.Length)];
			int num;
			for (int i = 0; i < array.Length; i += num)
			{
				num = stream.Read(array, i, array.Length - i);
				if (num == 0)
				{
					throw new InvalidOperationException("Incomplete embedded artwork");
				}
			}
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false)
			{
				hideFlags = (HideFlags)61,
				filterMode = (FilterMode)1,
				wrapMode = (TextureWrapMode)1
			};
			textures.Add(val);
			if (!LoadPng(val, array, unreadable: true))
			{
				throw new InvalidOperationException("Invalid embedded artwork: " + name);
			}
			return val;
		}

		internal static void Region(Texture2D texture, Rect target, Rect source)
		{
			//IL_0000: 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)
			GUI.DrawTextureWithTexCoords(target, (Texture)(object)texture, new Rect(((Rect)(ref source)).x / (float)((Texture)texture).width, 1f - (((Rect)(ref source)).y + ((Rect)(ref source)).height) / (float)((Texture)texture).height, ((Rect)(ref source)).width / (float)((Texture)texture).width, ((Rect)(ref source)).height / (float)((Texture)texture).height), true);
		}

		internal static void Slice(Texture2D texture, Rect target, Rect source, float cap)
		{
			//IL_0029: 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_0075: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			float num = cap * ((Rect)(ref target)).height / ((Rect)(ref source)).height;
			Region(texture, new Rect(((Rect)(ref target)).x, ((Rect)(ref target)).y, num, ((Rect)(ref target)).height), new Rect(((Rect)(ref source)).x, ((Rect)(ref source)).y, cap, ((Rect)(ref source)).height));
			Region(texture, new Rect(((Rect)(ref target)).x + num, ((Rect)(ref target)).y, ((Rect)(ref target)).width - 2f * num, ((Rect)(ref target)).height), new Rect(((Rect)(ref source)).x + cap, ((Rect)(ref source)).y, ((Rect)(ref source)).width - 2f * cap, ((Rect)(ref source)).height));
			Region(texture, new Rect(((Rect)(ref target)).xMax - num, ((Rect)(ref target)).y, num, ((Rect)(ref target)).height), new Rect(((Rect)(ref source)).xMax - cap, ((Rect)(ref source)).y, cap, ((Rect)(ref source)).height));
		}

		internal bool Button(Rect rect, string text)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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: Invalid comparison between Unknown and I4
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: 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)
			int controlID = GUIUtility.GetControlID(text.GetHashCode(), (FocusType)2, rect);
			Event current = Event.current;
			bool flag = ((Rect)(ref rect)).Contains(current.mousePosition);
			bool flag2 = GUIUtility.hotControl == controlID;
			bool result = false;
			if ((int)current.type == 0 && current.button == 0 && flag)
			{
				GUIUtility.hotControl = controlID;
				flag2 = true;
				current.Use();
			}
			else if ((int)current.type == 1 && flag2)
			{
				GUIUtility.hotControl = 0;
				result = flag;
				flag2 = false;
				current.Use();
			}
			float num = (flag2 ? 2 : (flag ? 1 : 0)) switch
			{
				1 => 282, 
				0 => 33, 
				_ => 526, 
			};
			Slice(Buttons, rect, new Rect(33f, num, 1920f, 236f), 210f);
			Text(text, rect, 24f, (Color)(flag ? Color.white : new Color(0.96f, 0.81f, 0.49f)));
			return result;
		}

		internal void Text(string text, Rect rect, float size, Color color, bool centered = true)
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			float num = size / 64f;
			float num2 = 0f;
			int num3 = 0;
			string text2 = text;
			foreach (char c in text2)
			{
				Glyph glyph = Find(c);
				if (glyph != null)
				{
					Kern.TryGetValue(num3 * 128 + c, out var value);
					num2 += (glyph.Advance + value) * num;
					num3 = c;
				}
			}
			float num4 = ((Rect)(ref rect)).x + (centered ? ((((Rect)(ref rect)).width - num2) / 2f) : 0f);
			float num5 = ((Rect)(ref rect)).center.y + size * 0.34f;
			num3 = 0;
			Color color2 = GUI.color;
			GUI.color = color;
			text2 = text;
			foreach (char c2 in text2)
			{
				Glyph glyph2 = Find(c2);
				if (glyph2 != null)
				{
					Kern.TryGetValue(num3 * 128 + c2, out var value2);
					num4 += value2 * num;
					if (glyph2.W > 0 && glyph2.H > 0)
					{
						Region(atlas, new Rect(num4 + (float)glyph2.Left * num, num5 + (float)glyph2.Top * num, (float)glyph2.W * num, (float)glyph2.H * num), new Rect((float)glyph2.X, (float)glyph2.Y, (float)glyph2.W, (float)glyph2.H));
					}
					num4 += glyph2.Advance * num;
					num3 = c2;
				}
			}
			GUI.color = color2;
		}

		private static Glyph? Find(char c)
		{
			Glyph[] glyphs = Glyphs;
			foreach (Glyph glyph in glyphs)
			{
				if (glyph.Code == c)
				{
					return glyph;
				}
			}
			return null;
		}

		public void Dispose()
		{
			foreach (Texture2D texture in textures)
			{
				if ((Object)(object)texture != (Object)null)
				{
					Object.Destroy((Object)(object)texture);
				}
			}
			textures.Clear();
		}
	}
	[BepInPlugin("local.smeltergratefire", "Smelter Grate Fire", "0.3.0")]
	public sealed class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Smelter), "Awake")]
		private static class Setup
		{
			[HarmonyPostfix]
			private static void Postfix(Smelter __instance)
			{
				if ((Object)(object)instance == (Object)null)
				{
					return;
				}
				try
				{
					AddVisual(__instance);
				}
				catch (Exception ex)
				{
					instance.Warn("Visual setup skipped: " + ex.Message);
				}
			}
		}

		[HarmonyPatch(typeof(ZNetView), "Awake")]
		private static class LoadingEffect
		{
			[HarmonyPostfix]
			private static void Postfix(ZNetView __instance)
			{
				if ((Object)(object)instance == (Object)null || (((Object)__instance).name != "vfx_smelter_addfuel(Clone)" && ((Object)__instance).name != "vfx_smelter_addore(Clone)") || !__instance.IsValid())
				{
					return;
				}
				try
				{
					(((Component)__instance).GetComponent<ColorVisual>() ?? ((Component)__instance).gameObject.AddComponent<ColorVisual>()).InitializeTransient();
				}
				catch (Exception ex)
				{
					instance.Warn("Loading-effect tint skipped: " + ex.Message);
				}
			}
		}

		public const string Id = "local.smeltergratefire";

		public const string Marker = "SmelterGrateFire_RearFlames";

		private Harmony? harmony;

		private static Plugin? instance;

		private bool warned;

		internal static Color? SelectedColor => ColorChooser.Instance?.Selection;

		private void Awake()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			if ((int)SystemInfo.graphicsDeviceType != 4)
			{
				instance = this;
				((Component)this).gameObject.AddComponent<ColorChooser>().Initialize(((BaseUnityPlugin)this).Config.Bind<string>("Visuals", "FlameColor", "", "Client-local regular smelter flame color (#RRGGBB). Empty restores vanilla. Use /smeltercolor in chat."));
				harmony = new Harmony("local.smeltergratefire");
				harmony.PatchAll(typeof(Plugin).Assembly);
			}
		}

		private void OnDestroy()
		{
			Harmony? obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			if ((Object)(object)instance == (Object)(object)this)
			{
				instance = null;
			}
		}

		private void Warn(string message)
		{
			if (!warned)
			{
				warned = true;
				((BaseUnityPlugin)this).Logger.LogWarning((object)message);
			}
		}

		private static void AttachColor(Smelter smelter, GameObject enabled)
		{
			(((Component)smelter).GetComponent<ColorVisual>() ?? ((Component)smelter).gameObject.AddComponent<ColorVisual>()).Initialize(enabled);
		}

		private static bool Safe(Transform source)
		{
			//IL_005f: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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)
			if (source.childCount != 0)
			{
				return false;
			}
			Component[] components = ((Component)source).GetComponents<Component>();
			if (components.Length != 3 || components.Any((Component c) => (Object)(object)c == (Object)null || (!(c is Transform) && !(c is ParticleSystem) && !(c is ParticleSystemRenderer))))
			{
				return false;
			}
			ParticleSystem component = ((Component)source).GetComponent<ParticleSystem>();
			if ((Object)(object)component != (Object)null && (Object)(object)((Component)source).GetComponent<ParticleSystemRenderer>() != (Object)null)
			{
				CollisionModule collision = component.collision;
				if (!((CollisionModule)(ref collision)).enabled)
				{
					TriggerModule trigger = component.trigger;
					if (!((TriggerModule)(ref trigger)).enabled)
					{
						LightsModule lights = component.lights;
						if (!((LightsModule)(ref lights)).enabled)
						{
							SubEmittersModule subEmitters = component.subEmitters;
							if (!((SubEmittersModule)(ref subEmitters)).enabled)
							{
								MainModule main = component.main;
								return (Object)(object)((MainModule)(ref main)).customSimulationSpace == (Object)null;
							}
						}
					}
				}
			}
			return false;
		}

		public static void AddVisual(Smelter smelter)
		{
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Expected O, but got Unknown
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)smelter == (Object)null || (((Object)smelter).name != "smelter" && ((Object)smelter).name != "smelter(Clone)") || smelter.m_name != "$piece_smelter")
			{
				return;
			}
			ZNetView component = ((Component)smelter).GetComponent<ZNetView>();
			if ((Object)(object)component == (Object)null || !component.IsValid())
			{
				return;
			}
			GameObject enabledObject = smelter.m_enabledObject;
			if ((Object)(object)enabledObject == (Object)null || ((Object)enabledObject).name != "_enabled" || (Object)(object)enabledObject.transform.parent != (Object)(object)((Component)smelter).transform)
			{
				return;
			}
			if ((Object)(object)enabledObject.transform.Find("SmelterGrateFire_RearFlames") != (Object)null)
			{
				AttachColor(smelter, enabledObject);
				return;
			}
			Transform val = enabledObject.transform.Find("flames (1)");
			Transform val2 = enabledObject.transform.Find("flare (3)");
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || !Safe(val))
			{
				instance?.Warn("Expected safe smelter flame source or rear anchor is absent; leaving the smelter unchanged.");
				return;
			}
			GameObject val3 = new GameObject("SmelterGrateFire_RearFlames");
			val3.SetActive(false);
			try
			{
				val3.transform.SetParent(enabledObject.transform, false);
				val3.transform.localPosition = val2.localPosition + new Vector3(0.2f, -0.12f, 0f);
				GameObject obj = Object.Instantiate<GameObject>(((Component)val).gameObject, val3.transform, false);
				((Object)obj).name = "flames";
				obj.transform.localPosition = Vector3.zero;
				obj.transform.localRotation = val.localRotation;
				obj.transform.localScale = val.localScale;
				val3.SetActive(true);
				AttachColor(smelter, enabledObject);
			}
			catch
			{
				Object.Destroy((Object)(object)val3);
				throw;
			}
		}
	}
	public sealed class ColorChooser : MonoBehaviour
	{
		[HarmonyPatch(typeof(Chat), "InputText")]
		private static class ChatCommand
		{
			[HarmonyPrefix]
			private static bool Prefix(Chat __instance)
			{
				if ((Object)(object)Instance == (Object)null || !string.Equals(((TMP_InputField)((Terminal)__instance).m_input).text.Trim(), "/smeltercolor", StringComparison.OrdinalIgnoreCase))
				{
					return true;
				}
				Instance.Open();
				return false;
			}
		}

		[HarmonyPatch(typeof(Chat), "HasFocus")]
		private static class Focus
		{
			[HarmonyPostfix]
			private static void Postfix(ref bool __result)
			{
				if (BlocksInput)
				{
					__result = true;
				}
			}
		}

		[HarmonyPatch(typeof(Chat), "Update")]
		private static class ChatKeys
		{
			[HarmonyPrefix]
			private static bool Prefix()
			{
				return !BlocksInput;
			}
		}

		[HarmonyPatch(typeof(Player), "TakeInput")]
		private static class PlayerInput
		{
			[HarmonyPostfix]
			private static void Postfix(ref bool __result)
			{
				if (BlocksInput)
				{
					__result = false;
				}
			}
		}

		[HarmonyPatch(typeof(Menu), "Update")]
		private static class MenuKeys
		{
			[HarmonyPrefix]
			private static bool Prefix()
			{
				return !BlocksInput;
			}
		}

		[HarmonyPatch(typeof(GameCamera), "UpdateMouseCapture")]
		private static class MouseCapture
		{
			[HarmonyPrefix]
			private static bool Prefix()
			{
				if (!BlocksInput)
				{
					return true;
				}
				ZCursor.LockState = (CursorLockMode)0;
				ZCursor.Show();
				return false;
			}
		}

		internal static ColorChooser? Instance;

		private ConfigEntry<string> saved;

		private bool opened;

		private int closeFrame = -10;

		private int scene;

		private float hue;

		private float saturation = 1f;

		private float value = 1f;

		private Texture2D? wheel;

		private Texture2D? marker;

		private UISkin? skin;

		private GUIStyle? labelStyle;

		private GUIStyle? buttonStyle;

		private readonly Color gold = new Color(0.89f, 0.74f, 0.43f);

		public bool IsOpen => opened;

		internal static bool BlocksInput
		{
			get
			{
				if ((Object)(object)Instance != (Object)null)
				{
					if (!Instance.opened)
					{
						return Time.frameCount <= Instance.closeFrame + 1;
					}
					return true;
				}
				return false;
			}
		}

		internal Color? Selection
		{
			get
			{
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				if (string.IsNullOrEmpty(saved.Value))
				{
					return null;
				}
				Color val = default(Color);
				if (!ColorUtility.TryParseHtmlString(saved.Value, ref val))
				{
					return null;
				}
				return val;
			}
		}

		internal void Initialize(ConfigEntry<string> config)
		{
			Instance = this;
			saved = config;
			SceneManager.activeSceneChanged += SceneChanged;
		}

		private void SceneChanged(Scene a, Scene b)
		{
			Close();
		}

		private void Update()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			if (!opened)
			{
				return;
			}
			if (!((Object)(object)Player.m_localPlayer == (Object)null))
			{
				Scene activeScene = SceneManager.GetActiveScene();
				if (((Scene)(ref activeScene)).handle == scene)
				{
					if (ZInput.GetKeyDown((KeyCode)27, true))
					{
						Close();
					}
					return;
				}
			}
			Close();
		}

		public void Open()
		{
			//IL_003e: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			if (!opened && !((Object)(object)Player.m_localPlayer == (Object)null))
			{
				Color.RGBToHSV((Color)(((??)Selection) ?? new Color(1f, 0.45f, 0.08f)), ref hue, ref saturation, ref value);
				Scene activeScene = SceneManager.GetActiveScene();
				scene = ((Scene)(ref activeScene)).handle;
				opened = true;
			}
		}

		public void Close()
		{
			if (opened)
			{
				opened = false;
				closeFrame = Time.frameCount;
				GUIUtility.hotControl = 0;
			}
		}

		public void Choose(float h, float s, float v)
		{
			hue = Mathf.Repeat(h, 1f);
			saturation = Mathf.Clamp01(s);
			value = Mathf.Clamp01(v);
		}

		public void Apply()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			Commit("#" + ColorUtility.ToHtmlStringRGB(Color.HSVToRGB(hue, saturation, value)));
			Close();
		}

		public void ResetVanilla()
		{
			Commit("");
			Close();
		}

		private void Commit(string text)
		{
			saved.Value = text;
			((ConfigEntryBase)saved).ConfigFile.Save();
			ColorVisual[] array = ColorVisual.Live.ToArray();
			foreach (ColorVisual colorVisual in array)
			{
				if ((Object)(object)colorVisual != (Object)null)
				{
					colorVisual.Apply(Selection);
				}
			}
		}

		private static Texture2D Solid(Color c)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false)
			{
				hideFlags = (HideFlags)61
			};
			val.SetPixel(0, 0, c);
			val.Apply();
			return val;
		}

		private void Styles()
		{
			//IL_0015: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			//IL_008c: 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_00a2: 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_00b6: Expected O, but got Unknown
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: 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_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Expected O, but got Unknown
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			if (skin != null)
			{
				return;
			}
			skin = new UISkin();
			marker = Solid(Color.white);
			Font val = ((IEnumerable<Font>)Resources.FindObjectsOfTypeAll<Font>()).FirstOrDefault((Func<Font, bool>)((Font f) => ((Object)f).name.IndexOf("Averia", StringComparison.OrdinalIgnoreCase) >= 0));
			labelStyle = new GUIStyle(GUI.skin.label)
			{
				fontSize = 17,
				wordWrap = true
			};
			labelStyle.normal.textColor = new Color(0.92f, 0.89f, 0.81f);
			buttonStyle = new GUIStyle(labelStyle)
			{
				fontSize = 24,
				alignment = (TextAnchor)4
			};
			buttonStyle.normal.textColor = gold;
			buttonStyle.hover.textColor = Color.white;
			if ((Object)(object)val != (Object)null)
			{
				labelStyle.font = val;
				buttonStyle.font = val;
			}
			wheel = new Texture2D(256, 256, (TextureFormat)4, false)
			{
				hideFlags = (HideFlags)61,
				filterMode = (FilterMode)1
			};
			for (int num = 0; num < 256; num++)
			{
				for (int num2 = 0; num2 < 256; num2++)
				{
					float num3 = ((float)num2 - 127.5f) / 126f;
					float num4 = ((float)num - 127.5f) / 126f;
					float num5 = Mathf.Sqrt(num3 * num3 + num4 * num4);
					Color val2 = Color.HSVToRGB(Mathf.Repeat(Mathf.Atan2(num4, num3) / ((float)Math.PI * 2f), 1f), Mathf.Clamp01(num5), 1f);
					val2.a = Mathf.Clamp01((1f - num5) * 126f);
					wheel.SetPixel(num2, num, val2);
				}
			}
			wheel.Apply();
		}

		private void OnGUI()
		{
			//IL_06d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d6: 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_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_008d: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Invalid comparison between Unknown and I4
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Invalid comparison between Unknown and I4
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_0381: Unknown result type (might be due to invalid IL or missing references)
			//IL_0390: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0435: Unknown result type (might be due to invalid IL or missing references)
			//IL_0440: Unknown result type (might be due to invalid IL or missing references)
			//IL_046c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0477: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: 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_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_04dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e3: Invalid comparison between Unknown and I4
			//IL_0532: Unknown result type (might be due to invalid IL or missing references)
			//IL_0538: Invalid comparison between Unknown and I4
			//IL_0489: Unknown result type (might be due to invalid IL or missing references)
			//IL_056f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0588: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0608: Unknown result type (might be due to invalid IL or missing references)
			//IL_0626: Unknown result type (might be due to invalid IL or missing references)
			//IL_0655: Unknown result type (might be due to invalid IL or missing references)
			//IL_0513: Unknown result type (might be due to invalid IL or missing references)
			//IL_04be: Unknown result type (might be due to invalid IL or missing references)
			//IL_0686: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b7: Unknown result type (might be due to invalid IL or missing references)
			if (!opened)
			{
				return;
			}
			Styles();
			Matrix4x4 matrix = GUI.matrix;
			Color color = GUI.color;
			int depth = GUI.depth;
			float num = Mathf.Min(1f, Mathf.Min((float)(Screen.width - 40) / 800f, (float)(Screen.height - 40) / 640f));
			GUI.matrix = Matrix4x4.TRS(new Vector3(((float)Screen.width - 800f * num) / 2f, ((float)Screen.height - 640f * num) / 2f, 0f), Quaternion.identity, new Vector3(num, num, 1f));
			GUI.depth = -100;
			try
			{
				GUI.color = Color.white;
				GUI.DrawTexture(new Rect(0f, 0f, 800f, 640f), (Texture)(object)skin.Panel);
				UISkin.Region(skin.Title, new Rect(196f, 35f, 408f, 70f), new Rect(19f, 162f, 2137f, 368f));
				if (GUI.Button(new Rect(718f, 108f, 32f, 32f), "x", buttonStyle))
				{
					Close();
				}
				GUI.Label(new Rect(95f, 120f, 610f, 30f), "All regular smelters  |  Visible only to you", labelStyle);
				Rect val = default(Rect);
				((Rect)(ref val))..ctor(110f, 208f, 240f, 240f);
				GUI.DrawTexture(val, (Texture)(object)wheel);
				GUI.DrawTexture(new Rect(55f, 165f, 350f, 330f), (Texture)(object)skin.Ring);
				Event current = Event.current;
				Vector2 mousePosition = current.mousePosition;
				int controlID = GUIUtility.GetControlID(21325, (FocusType)2, val);
				if ((int)current.type == 0 && current.button == 0 && ((Rect)(ref val)).Contains(mousePosition))
				{
					GUIUtility.hotControl = controlID;
					Pick(mousePosition, val);
					current.Use();
				}
				if ((int)current.type == 3 && GUIUtility.hotControl == controlID)
				{
					Pick(mousePosition, val);
					current.Use();
				}
				if ((int)current.type == 1 && GUIUtility.hotControl == controlID)
				{
					GUIUtility.hotControl = 0;
					current.Use();
				}
				float num2 = hue * 2f * (float)Math.PI;
				float num3 = ((Rect)(ref val)).center.x + Mathf.Cos(num2) * saturation * 118f;
				float num4 = ((Rect)(ref val)).center.y - Mathf.Sin(num2) * saturation * 118f;
				GUI.color = Color.black;
				GUI.DrawTexture(new Rect(num3 - 5f, num4 - 5f, 10f, 10f), (Texture)(object)marker);
				GUI.color = Color.white;
				GUI.DrawTexture(new Rect(num3 - 3f, num4 - 3f, 6f, 6f), (Texture)(object)marker);
				Color val2 = Color.HSVToRGB(hue, saturation, value);
				skin.Text("Selected color", new Rect(445f, 190f, 275f, 32f), 28f, gold, centered: false);
				GUI.color = val2;
				GUI.DrawTexture(new Rect(474.5f, 251f, 216f, 33f), (Texture)(object)Texture2D.whiteTexture);
				GUI.color = Color.white;
				UISkin.Slice(skin.PreviewFrame, new Rect(445f, 237f, 275f, 60f), new Rect(35f, 201f, 1913f, 361f), 320f);
				GUI.Label(new Rect(445f, 304f, 275f, 28f), "#" + ColorUtility.ToHtmlStringRGB(val2), labelStyle);
				skin.Text("Brightness", new Rect(445f, 347f, 275f, 32f), 28f, gold, centered: false);
				Rect val3 = default(Rect);
				((Rect)(ref val3))..ctor(445f, 388f, 275f, 44f);
				int controlID2 = GUIUtility.GetControlID(21326, (FocusType)2, val3);
				if ((int)current.type == 0 && current.button == 0 && ((Rect)(ref val3)).Contains(mousePosition))
				{
					GUIUtility.hotControl = controlID2;
					value = Mathf.Lerp(0.05f, 1f, Mathf.InverseLerp(((Rect)(ref val3)).x + 18f, ((Rect)(ref val3)).xMax - 18f, mousePosition.x));
					current.Use();
				}
				if ((int)current.type == 3 && GUIUtility.hotControl == controlID2)
				{
					value = Mathf.Lerp(0.05f, 1f, Mathf.InverseLerp(((Rect)(ref val3)).x + 18f, ((Rect)(ref val3)).xMax - 18f, mousePosition.x));
					current.Use();
				}
				if ((int)current.type == 1 && GUIUtility.hotControl == controlID2)
				{
					GUIUtility.hotControl = 0;
					current.Use();
				}
				UISkin.Slice(skin.Slider, new Rect(445f, 399f, 275f, 23f), new Rect(33f, 111f, 2107f, 178f), 220f);
				float num5 = Mathf.Lerp(((Rect)(ref val3)).x + 18f, ((Rect)(ref val3)).xMax - 18f, Mathf.InverseLerp(0.05f, 1f, value));
				UISkin.Region(skin.Slider, new Rect(num5 - 10f, 388f, 20f, 44f), new Rect(1005f, 315f, 165f, 350f));
				GUI.Label(new Rect(445f, 449f, 280f, 53f), "Choose a color, then Apply.\nCancel keeps your current color.", labelStyle);
				if (skin.Button(new Rect(48f, 530f, 230f, 44f), "Vanilla"))
				{
					ResetVanilla();
				}
				if (skin.Button(new Rect(285f, 530f, 230f, 44f), "Cancel"))
				{
					Close();
				}
				if (skin.Button(new Rect(522f, 530f, 230f, 44f), "Apply"))
				{
					Apply();
				}
			}
			finally
			{
				GUI.matrix = matrix;
				GUI.color = color;
				GUI.depth = depth;
			}
		}

		private void Pick(Vector2 p, Rect r)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = p - ((Rect)(ref r)).center;
			hue = Mathf.Repeat(Mathf.Atan2(0f - val.y, val.x) / ((float)Math.PI * 2f), 1f);
			saturation = Mathf.Clamp01(((Vector2)(ref val)).magnitude / (((Rect)(ref r)).width * 0.492f));
		}

		private void OnDestroy()
		{
			Close();
			SceneManager.activeSceneChanged -= SceneChanged;
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
			skin?.Dispose();
			skin = null;
			Texture2D[] array = (Texture2D[])(object)new Texture2D[2] { wheel, marker };
			foreach (Texture2D val in array)
			{
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
			}
		}
	}
	public sealed class ColorVisual : MonoBehaviour
	{
		private sealed class Target
		{
			public ParticleSystem System;

			public bool Flame;

			public GradientColorKey[] Colors;

			public GradientAlphaKey[] Alphas;

			public GradientMode Mode;

			public Color Start;
		}

		private sealed class Ember
		{
			public Renderer Renderer;

			public MaterialPropertyBlock Original;

			public Color Color;

			public Color Emission;
		}

		private readonly List<Ember> embers = new List<Ember>();

		private readonly List<Target> targets = new List<Target>();

		internal static readonly HashSet<ColorVisual> Live = new HashSet<ColorVisual>();

		private bool initialized;

		internal void Initialize(GameObject enabled)
		{
			//IL_034c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: Expected O, but got Unknown
			//IL_039b: Unknown result type (might be due to invalid IL or missing references)
			//IL_038d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Invalid comparison between Unknown and I4
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: 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_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			if (initialized)
			{
				return;
			}
			initialized = true;
			ParticleSystem[] componentsInChildren = enabled.GetComponentsInChildren<ParticleSystem>(true);
			foreach (ParticleSystem val in componentsInChildren)
			{
				ParticleSystemRenderer component = ((Component)val).GetComponent<ParticleSystemRenderer>();
				Material val2 = (((Object)(object)component == (Object)null) ? null : ((Renderer)component).sharedMaterial);
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				bool num = (((Object)val).name == "flames" || ((Object)val).name == "flames (1)" || ((Object)val).name == "flames (2)") && ((Object)val2).name == "flame" && ((Object)val2.shader).name == "Legacy Shaders/Particles/Additive";
				bool flag = ((Object)val).name == "smoke (1)" && (Object)(object)((Component)val).transform.parent == (Object)(object)enabled.transform && ((Object)val2).name == "fog" && ((Object)val2.shader).name == "Lux Lit Particles/ Bumped";
				bool flag2 = (((Object)val).name == "flare" || ((Object)val).name == "flare (1)" || ((Object)val).name == "flare (2)" || ((Object)val).name == "flare (3)") && ((Object)val2).name == "light_glow" && ((Object)val2.shader).name == "Legacy Shaders/Particles/Alpha Blended";
				ColorOverLifetimeModule colorOverLifetime;
				MinMaxGradient val3;
				if (num || flag)
				{
					colorOverLifetime = val.colorOverLifetime;
					if (((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled)
					{
						colorOverLifetime = val.colorOverLifetime;
						val3 = ((ColorOverLifetimeModule)(ref colorOverLifetime)).color;
						if ((int)((MinMaxGradient)(ref val3)).mode == 1)
						{
							colorOverLifetime = val.colorOverLifetime;
							val3 = ((ColorOverLifetimeModule)(ref colorOverLifetime)).color;
							Gradient gradient = ((MinMaxGradient)(ref val3)).gradient;
							targets.Add(new Target
							{
								System = val,
								Flame = true,
								Colors = gradient.colorKeys,
								Alphas = gradient.alphaKeys,
								Mode = gradient.mode
							});
							continue;
						}
					}
				}
				if (!flag2)
				{
					continue;
				}
				colorOverLifetime = val.colorOverLifetime;
				if (!((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled)
				{
					MainModule main = val.main;
					val3 = ((MainModule)(ref main)).startColor;
					if ((int)((MinMaxGradient)(ref val3)).mode == 0)
					{
						List<Target> list = targets;
						Target obj = new Target
						{
							System = val,
							Flame = false
						};
						main = val.main;
						val3 = ((MainModule)(ref main)).startColor;
						obj.Start = ((MinMaxGradient)(ref val3)).color;
						list.Add(obj);
					}
				}
			}
			MeshRenderer[] componentsInChildren2 = enabled.GetComponentsInChildren<MeshRenderer>(true);
			foreach (MeshRenderer val4 in componentsInChildren2)
			{
				Material sharedMaterial = ((Renderer)val4).sharedMaterial;
				if (!((Object)(object)((Component)val4).transform.parent != (Object)(object)enabled.transform) && (!(((Object)val4).name != "Cube") || !(((Object)val4).name != "Cube (1)")) && !((Object)(object)sharedMaterial == (Object)null) && !(((Object)sharedMaterial).name != "fire_log") && !(((Object)sharedMaterial.shader).name != "Standard") && sharedMaterial.HasProperty("_Color") && sharedMaterial.HasProperty("_EmissionColor"))
				{
					MaterialPropertyBlock val5 = new MaterialPropertyBlock();
					((Renderer)val4).GetPropertyBlock(val5);
					embers.Add(new Ember
					{
						Renderer = (Renderer)(object)val4,
						Original = val5,
						Color = (val5.HasColor("_Color") ? val5.GetColor("_Color") : sharedMaterial.GetColor("_Color")),
						Emission = (val5.HasColor("_EmissionColor") ? val5.GetColor("_EmissionColor") : sharedMaterial.GetColor("_EmissionColor"))
					});
				}
			}
			Live.Add(this);
			Apply(Plugin.SelectedColor);
		}

		internal void InitializeTransient()
		{
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0117: 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_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Invalid comparison between Unknown and I4
			//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_0132: 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_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			if (initialized)
			{
				return;
			}
			initialized = true;
			ParticleSystem[] componentsInChildren = ((Component)this).GetComponentsInChildren<ParticleSystem>(true);
			foreach (ParticleSystem val in componentsInChildren)
			{
				ParticleSystemRenderer component = ((Component)val).GetComponent<ParticleSystemRenderer>();
				Material val2 = ((component != null) ? ((Renderer)component).sharedMaterial : null);
				if ((Object)(object)val2 == (Object)null || ((!(((Object)val).name == "smoke") || !(((Object)val2).name == "smoke") || !(((Object)val2.shader).name == "Lux Lit Particles/ Bumped")) && (!(((Object)val).name == "fire") || !(((Object)val2).name == "flameball_flipbook_gradient") || !(((Object)val2.shader).name == "Custom/Gradient Mapped Particle (Unlit)")) && (!(((Object)val).name == "cinders") || !(((Object)val2).name == "flame_small") || !(((Object)val2.shader).name == "Legacy Shaders/Particles/Additive"))))
				{
					continue;
				}
				ColorOverLifetimeModule colorOverLifetime = val.colorOverLifetime;
				if (((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled)
				{
					colorOverLifetime = val.colorOverLifetime;
					MinMaxGradient color = ((ColorOverLifetimeModule)(ref colorOverLifetime)).color;
					if ((int)((MinMaxGradient)(ref color)).mode == 1)
					{
						colorOverLifetime = val.colorOverLifetime;
						color = ((ColorOverLifetimeModule)(ref colorOverLifetime)).color;
						Gradient gradient = ((MinMaxGradient)(ref color)).gradient;
						targets.Add(new Target
						{
							System = val,
							Flame = true,
							Colors = gradient.colorKeys,
							Alphas = gradient.alphaKeys,
							Mode = gradient.mode
						});
					}
				}
			}
			Live.Add(this);
			Apply(Plugin.SelectedColor);
		}

		private static Color Tint(Color original, Color selected)
		{
			//IL_0000: 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_000c: 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_0025: 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_0035: 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)
			float num = Mathf.Max(original.r, Mathf.Max(original.g, original.b));
			return new Color(selected.r * num, selected.g * num, selected.b * num, original.a);
		}

		internal void Apply(Color? color)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_006f: 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_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_0098: 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_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Expected O, but got Unknown
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			foreach (Ember ember in embers)
			{
				if (!((Object)(object)ember.Renderer == (Object)null))
				{
					if (!color.HasValue)
					{
						ember.Renderer.SetPropertyBlock(ember.Original.isEmpty ? null : ember.Original);
						continue;
					}
					MaterialPropertyBlock val = new MaterialPropertyBlock();
					ember.Renderer.GetPropertyBlock(val);
					val.SetColor("_Color", Tint(ember.Color, color.Value));
					val.SetColor("_EmissionColor", Tint(ember.Emission, color.Value));
					ember.Renderer.SetPropertyBlock(val);
				}
			}
			foreach (Target target in targets)
			{
				if ((Object)(object)target.System == (Object)null)
				{
					continue;
				}
				if (target.Flame)
				{
					ColorOverLifetimeModule colorOverLifetime = target.System.colorOverLifetime;
					GradientColorKey[] array = (GradientColorKey[])target.Colors.Clone();
					if (color.HasValue)
					{
						for (int i = 0; i < array.Length; i++)
						{
							array[i].color = Tint(array[i].color, color.Value);
						}
					}
					Gradient val2 = new Gradient
					{
						mode = target.Mode
					};
					val2.SetKeys(array, target.Alphas);
					((ColorOverLifetimeModule)(ref colorOverLifetime)).color = new MinMaxGradient(val2);
					continue;
				}
				Color val3 = (color.HasValue ? Tint(target.Start, color.Value) : target.Start);
				MainModule main = target.System.main;
				((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(val3);
				int particleCount = target.System.particleCount;
				if (particleCount > 0)
				{
					Particle[] array2 = (Particle[])(object)new Particle[particleCount];
					particleCount = target.System.GetParticles(array2);
					for (int j = 0; j < particleCount; j++)
					{
						((Particle)(ref array2[j])).startColor = Color32.op_Implicit(val3);
					}
					target.System.SetParticles(array2, particleCount);
				}
			}
		}

		private void OnDestroy()
		{
			Live.Remove(this);
		}
	}
}