Decompiled source of ColorHolds v1.0.1

ColorholdsMod/GreenHolds.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("GreenHolds")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GreenHolds")]
[assembly: AssemblyTitle("GreenHolds")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
[DefaultExecutionOrder(32000)]
[BepInPlugin("you.greenholds", "Color Holds", "1.0.0")]
public class GreenHolds : BaseUnityPlugin
{
	private class PropInfo
	{
		public int[] colorIds;

		public string[] colorNames;

		public bool[] colorShimmer;

		public bool[] colorShader;

		public int[] texIds;

		public bool[] texGlow;

		public bool[] texSkip;
	}

	private class ColorState
	{
		public Color orig;

		public Color applied = new Color(-9f, -9f, -9f, -9f);

		public Color tinted;

		public int gen = -1;

		public bool logged;
	}

	private class MatPlan
	{
		public Material owner;

		public bool needClone;

		public Material clone;

		public MatPlan clonePlan;

		public PropInfo pi;

		public ColorState[] cs;

		public Texture[] orig;

		public int texEpoch = -1;

		public bool paintMain;
	}

	private class Tracked
	{
		public Renderer r;

		public bool paint;

		public ColorState[] blockStates = new ColorState[4];
	}

	private class TexEntry
	{
		public Texture src;

		public Texture2D result;

		public bool busy;

		public bool started;

		public bool rerun;

		public bool failed;

		public bool glow;
	}

	private class TexJob
	{
		public TexEntry e;

		public Color32[] px;

		public int w;

		public int h;

		public float hue;

		public float sMul;

		public float vMul;

		public float mix;

		public volatile bool done;

		public volatile bool error;
	}

	private class PendDestroy
	{
		public Texture2D tex;

		public float time;
	}

	private bool menuOpen;

	private bool closeRequested;

	private CursorLockMode prevLock;

	private bool prevVisible;

	private bool texDirty;

	private float lastChange;

	private const int WheelD = 88;

	private static readonly Color colWinFill = new Color(0.035f, 0.035f, 0.045f, 1f);

	private static readonly Color colWinBorder = new Color(0.82f, 0.82f, 0.84f, 1f);

	private static readonly Color colRed = new Color(0.86f, 0.06f, 0.06f, 1f);

	private static readonly Color colGray = new Color(0.55f, 0.55f, 0.58f, 1f);

	private static readonly Color colBtnBorder = new Color(0.45f, 0.45f, 0.48f, 1f);

	private static readonly Color colBtnHover = new Color(0.1f, 0.02f, 0.02f, 1f);

	private static readonly Color colBtnDown = new Color(0.38f, 0.03f, 0.03f, 1f);

	private static readonly Color colTrack = new Color(0.1f, 0.1f, 0.11f, 1f);

	private const string charset = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,:-+#/()%!?=_";

	private static readonly string[] glyphs = new string[51]
	{
		"00000|00000|00000|00000|00000|00000|00000", "01110|10001|10001|11111|10001|10001|10001", "11110|10001|10001|11110|10001|10001|11110", "01110|10001|10000|10000|10000|10001|01110", "11110|10001|10001|10001|10001|10001|11110", "11111|10000|10000|11110|10000|10000|11111", "11111|10000|10000|11110|10000|10000|10000", "01110|10001|10000|10111|10001|10001|01111", "10001|10001|10001|11111|10001|10001|10001", "01110|00100|00100|00100|00100|00100|01110",
		"00111|00010|00010|00010|00010|10010|01100", "10001|10010|10100|11000|10100|10010|10001", "10000|10000|10000|10000|10000|10000|11111", "10001|11011|10101|10101|10001|10001|10001", "10001|11001|10101|10011|10001|10001|10001", "01110|10001|10001|10001|10001|10001|01110", "11110|10001|10001|11110|10000|10000|10000", "01110|10001|10001|10001|10101|10010|01101", "11110|10001|10001|11110|10100|10010|10001", "01111|10000|10000|01110|00001|00001|11110",
		"11111|00100|00100|00100|00100|00100|00100", "10001|10001|10001|10001|10001|10001|01110", "10001|10001|10001|10001|10001|01010|00100", "10001|10001|10001|10101|10101|11011|10001", "10001|10001|01010|00100|01010|10001|10001", "10001|10001|01010|00100|00100|00100|00100", "11111|00001|00010|00100|01000|10000|11111", "01110|10001|10011|10101|11001|10001|01110", "00100|01100|00100|00100|00100|00100|01110", "01110|10001|00001|00010|00100|01000|11111",
		"11110|00001|00001|01110|00001|00001|11110", "00010|00110|01010|10010|11111|00010|00010", "11111|10000|11110|00001|00001|10001|01110", "00110|01000|10000|11110|10001|10001|01110", "11111|00001|00010|00100|01000|01000|01000", "01110|10001|10001|01110|10001|10001|01110", "01110|10001|10001|01111|00001|00010|01100", "00000|00000|00000|00000|00000|01100|01100", "00000|00000|00000|00000|01100|00100|01000", "00000|01100|01100|00000|01100|01100|00000",
		"00000|00000|00000|11111|00000|00000|00000", "00000|00100|00100|11111|00100|00100|00000", "01010|01010|11111|01010|11111|01010|01010", "00001|00010|00010|00100|01000|01000|10000", "00010|00100|01000|01000|01000|00100|00010", "01000|00100|00010|00010|00010|00100|01000", "11001|11010|00010|00100|01000|01011|10011", "00100|00100|00100|00100|00100|00000|00100", "01110|10001|00001|00010|00100|00000|00100", "00000|00000|11111|00000|11111|00000|00000",
		"00000|00000|00000|00000|00000|00000|11111"
	};

	private Texture2D fontTex;

	private Texture2D thumbTex;

	private Texture2D wheelTex;

	private int atlasW;

	private int atlasH;

	private int ps = 2;

	private float ox;

	private float oy;

	private Vector2 winPos = new Vector2(40f, 40f);

	private float menuH = 250f;

	private int idCounter;

	private int activeId;

	private bool dragWin;

	private Vector2 dragOff;

	private static readonly Tracked Ignored = new Tracked();

	private readonly Dictionary<long, MatPlan> plans = new Dictionary<long, MatPlan>();

	private readonly Dictionary<int, PropInfo> shaderInfo = new Dictionary<int, PropInfo>();

	private readonly Dictionary<int, TexEntry> texEntries = new Dictionary<int, TexEntry>();

	private readonly Dictionary<int, Texture> greenToSrc = new Dictionary<int, Texture>();

	private readonly Queue<TexEntry> startQueue = new Queue<TexEntry>();

	private readonly List<TexJob> running = new List<TexJob>();

	private readonly List<PendDestroy> pendingDestroy = new List<PendDestroy>();

	private readonly List<Tracked> tracked = new List<Tracked>();

	private readonly List<Material> matBuf = new List<Material>();

	private readonly List<long> deadKeys = new List<long>();

	private Dictionary<int, Tracked> cacheA = new Dictionary<int, Tracked>();

	private Dictionary<int, Tracked> cacheB = new Dictionary<int, Tracked>();

	private MaterialPropertyBlock mpb;

	private const int Depth = 3;

	private static readonly string[] holdKeys = new string[4] { "handhold", "piton", "rebar", "ladder" };

	private static readonly string[] paintKeys = new string[3] { "piton", "rebar", "ladder" };

	private static readonly string[] blockNames = new string[4] { "_EmissionColor", "_Color", "_BaseColor", "_ShimmerColor" };

	private static readonly string[] skipTex = new string[7] { "bump", "normal", "metal", "occlusion", "parallax", "mask", "detail" };

	private int[] blockIds;

	private int texEpoch;

	private int colorGen;

	private int refreshCycle;

	private double msAvg;

	private double refreshMs;

	private ConfigEntry<float> cfgHue;

	private ConfigEntry<float> cfgSat;

	private ConfigEntry<float> cfgBright;

	private ConfigEntry<float> cfgShader;

	private ConfigEntry<KeyCode> cfgKey;

	private ConfigEntry<int> cfgHidden;

	private ConfigEntry<int> cfgTexJobs;

	private ConfigEntry<int> cfgPixel;

	private ConfigEntry<bool> cfgStats;

	private Color target = new Color(0f, 1f, 0f, 1f);

	private float tH = 1f / 3f;

	private float tS = 1f;

	private float tV = 1f;

	private float shaderMix = 1f;

	private static Texture2D MakeX(int size)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Expected O, but got Unknown
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(size, size, (TextureFormat)4, false);
		((Texture)val).filterMode = (FilterMode)0;
		((Texture)val).wrapMode = (TextureWrapMode)1;
		bool[] array = new bool[size * size];
		int num = 2;
		for (int i = num; i < size - num; i++)
		{
			for (int j = 0; j < 2; j++)
			{
				int num2 = Mathf.Clamp(i + j, 0, size - 1);
				array[i * size + num2] = true;
				array[i * size + (size - 1 - num2)] = true;
			}
		}
		Color32[] array2 = (Color32[])(object)new Color32[size * size];
		for (int k = 0; k < size; k++)
		{
			for (int l = 0; l < size; l++)
			{
				if (array[k * size + l])
				{
					array2[k * size + l] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
					continue;
				}
				bool flag = false;
				for (int m = -1; m <= 1; m++)
				{
					if (flag)
					{
						break;
					}
					for (int n = -1; n <= 1; n++)
					{
						if (flag)
						{
							break;
						}
						int num3 = l + n;
						int num4 = k + m;
						if (num3 >= 0 && num4 >= 0 && num3 < size && num4 < size && array[num4 * size + num3])
						{
							flag = true;
						}
					}
				}
				array2[k * size + l] = (flag ? new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue) : new Color32((byte)0, (byte)0, (byte)0, (byte)0));
			}
		}
		val.SetPixels32(array2);
		val.Apply(false, true);
		return val;
	}

	private static Texture2D MakeWheel(int d)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Expected O, but got Unknown
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(d, d, (TextureFormat)4, false);
		((Texture)val).filterMode = (FilterMode)0;
		((Texture)val).wrapMode = (TextureWrapMode)1;
		Color32[] array = (Color32[])(object)new Color32[d * d];
		float num = (float)d / 2f;
		float num2 = (float)d / 2f - 0.5f;
		float num3 = num2 - 1.2f;
		for (int i = 0; i < d; i++)
		{
			for (int j = 0; j < d; j++)
			{
				float num4 = (float)j + 0.5f - num;
				float num5 = (float)i + 0.5f - num;
				float num6 = Mathf.Sqrt(num4 * num4 + num5 * num5);
				if (num6 > num2)
				{
					array[i * d + j] = new Color32((byte)0, (byte)0, (byte)0, (byte)0);
					continue;
				}
				if (num6 > num3)
				{
					array[i * d + j] = new Color32((byte)209, (byte)209, (byte)214, byte.MaxValue);
					continue;
				}
				float num7 = Mathf.Atan2(num5, num4) / ((float)Math.PI * 2f);
				if (num7 < 0f)
				{
					num7 += 1f;
				}
				array[i * d + j] = Color32.op_Implicit(Color.HSVToRGB(num7, Mathf.Clamp01(num6 / num3), 1f));
			}
		}
		val.SetPixels32(array);
		val.Apply(false, true);
		return val;
	}

	private void BuildAtlas()
	{
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Expected O, but got Unknown
		//IL_00be: 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)
		int length = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,:-+#/()%!?=_".Length;
		int num = (length + 16 - 1) / 16;
		atlasW = 96;
		atlasH = num * 8;
		Color32[] array = (Color32[])(object)new Color32[atlasW * atlasH];
		Color32 val = default(Color32);
		((Color32)(ref val))..ctor(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
		for (int i = 0; i < length && i < glyphs.Length; i++)
		{
			string[] array2 = glyphs[i].Split(new char[1] { '|' });
			int num2 = i % 16;
			int num3 = i / 16;
			for (int j = 0; j < 7 && j < array2.Length; j++)
			{
				for (int k = 0; k < 5 && k < array2[j].Length; k++)
				{
					if (array2[j][k] == '1')
					{
						array[(atlasH - 1 - (num3 * 8 + j)) * atlasW + (num2 * 6 + k)] = val;
					}
				}
			}
		}
		fontTex = new Texture2D(atlasW, atlasH, (TextureFormat)4, false);
		((Texture)fontTex).filterMode = (FilterMode)0;
		((Texture)fontTex).wrapMode = (TextureWrapMode)1;
		fontTex.SetPixels32(array);
		fontTex.Apply(false, true);
		thumbTex = MakeX(11);
		wheelTex = MakeWheel(88);
	}

	private int PixelScale()
	{
		int num = cfgPixel.Value;
		if (num <= 0)
		{
			num = Mathf.Clamp(Mathf.RoundToInt((float)Screen.height / 540f), 1, 6);
		}
		return num;
	}

	private Rect U(float x, float y, float w, float h)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		return new Rect(ox + x * (float)ps, oy + y * (float)ps, w * (float)ps, h * (float)ps);
	}

	private static void Fill(Rect r, Color c)
	{
		//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)
		GUI.color = c;
		GUI.DrawTexture(r, (Texture)(object)Texture2D.whiteTexture);
	}

	private void PixelBox(Rect r, Color fill, Color border, int cut)
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_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_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: 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_00bd: 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_00d8: 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_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_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		float num = ps;
		float x = ((Rect)(ref r)).x;
		float y = ((Rect)(ref r)).y;
		float width = ((Rect)(ref r)).width;
		float height = ((Rect)(ref r)).height;
		Fill(new Rect(x + (float)cut * num, y, width - (float)(2 * cut) * num, num), border);
		Fill(new Rect(x + (float)cut * num, y + height - num, width - (float)(2 * cut) * num, num), border);
		Fill(new Rect(x, y + (float)cut * num, num, height - (float)(2 * cut) * num), border);
		Fill(new Rect(x + width - num, y + (float)cut * num, num, height - (float)(2 * cut) * num), border);
		if (cut >= 2)
		{
			Fill(new Rect(x + num, y + num, num, num), border);
			Fill(new Rect(x + width - 2f * num, y + num, num, num), border);
			Fill(new Rect(x + num, y + height - 2f * num, num, num), border);
			Fill(new Rect(x + width - 2f * num, y + height - 2f * num, num, num), border);
			Fill(new Rect(x + 2f * num, y + num, width - 4f * num, height - 2f * num), fill);
			Fill(new Rect(x + num, y + 2f * num, width - 2f * num, height - 4f * num), fill);
		}
		else
		{
			Fill(new Rect(x + num, y + num, width - 2f * num, height - 2f * num), fill);
		}
	}

	private void TextAt(string s, float px, float py, int ts, Color c, int align)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Invalid comparison between Unknown and I4
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		if ((int)Event.current.type != 7)
		{
			return;
		}
		float num = 6f * (float)ts * (float)ps;
		float num2 = (float)s.Length * num - (float)(ts * ps);
		switch (align)
		{
		case 1:
			px -= num2;
			break;
		case 2:
			px -= num2 / 2f;
			break;
		}
		px = Mathf.Round(px);
		py = Mathf.Round(py);
		GUI.color = c;
		Rect val = default(Rect);
		for (int i = 0; i < s.Length; i++)
		{
			int num3 = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,:-+#/()%!?=_".IndexOf(char.ToUpperInvariant(s[i]));
			if (num3 > 0 && num3 < glyphs.Length)
			{
				int num4 = num3 % 16;
				int num5 = num3 / 16;
				((Rect)(ref val))..ctor((float)num4 * 6f / (float)atlasW, 1f - (float)(num5 + 1) * 8f / (float)atlasH, 6f / (float)atlasW, 8f / (float)atlasH);
				GUI.DrawTextureWithTexCoords(new Rect(px + (float)i * num, py, num, 8f * (float)ts * (float)ps), (Texture)(object)fontTex, val);
			}
		}
	}

	private void TextU(string s, float xu, float yu, int ts, Color c, int align)
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		TextAt(s, ox + xu * (float)ps, oy + yu * (float)ps, ts, c, align);
	}

	private bool Click(Rect r, out bool hover, out bool down)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Invalid comparison between Unknown and I4
		int num = ++idCounter;
		Event current = Event.current;
		hover = ((Rect)(ref r)).Contains(current.mousePosition);
		bool result = false;
		if (((int)current.type == 0 && current.button == 0) & hover)
		{
			activeId = num;
			current.Use();
		}
		else if ((int)current.type == 1 && current.button == 0 && activeId == num)
		{
			result = hover;
			activeId = 0;
			current.Use();
		}
		down = activeId == num;
		return result;
	}

	private bool PButton(Rect r, string text, Color textColor)
	{
		//IL_0001: 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_0016: Invalid comparison between Unknown and I4
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: 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_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		bool hover;
		bool down;
		bool result = Click(r, out hover, out down);
		if ((int)Event.current.type == 7)
		{
			PixelBox(r, down ? colBtnDown : (hover ? colBtnHover : Color.black), (hover || down) ? colRed : colBtnBorder, 1);
			TextAt(text, ((Rect)(ref r)).x + ((Rect)(ref r)).width / 2f, ((Rect)(ref r)).y + (((Rect)(ref r)).height - 7f * (float)ps) / 2f, 1, textColor, 2);
		}
		return result;
	}

	private float PSlider(Rect area, float v)
	{
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: 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_00cf: Invalid comparison between Unknown and I4
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Invalid comparison between Unknown and I4
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Invalid comparison between Unknown and I4
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: 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_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		int num = ++idCounter;
		Event current = Event.current;
		float num2 = 11f * (float)ps;
		float num3 = ((Rect)(ref area)).x + num2 / 2f;
		float num4 = ((Rect)(ref area)).xMax - num2 / 2f;
		if ((int)current.type == 0 && current.button == 0 && ((Rect)(ref area)).Contains(current.mousePosition))
		{
			activeId = num;
		}
		if (activeId == num && ((int)current.type == 0 || (int)current.type == 3))
		{
			v = Mathf.Clamp01((current.mousePosition.x - num3) / (num4 - num3));
			current.Use();
		}
		if (activeId == num && (int)current.type == 1)
		{
			activeId = 0;
			current.Use();
		}
		if ((int)current.type == 7)
		{
			float num5 = ps;
			Rect r = default(Rect);
			((Rect)(ref r))..ctor(((Rect)(ref area)).x + 2f * num5, ((Rect)(ref area)).y + (((Rect)(ref area)).height - 5f * num5) / 2f, ((Rect)(ref area)).width - 4f * num5, 5f * num5);
			PixelBox(r, colTrack, colBtnBorder, 1);
			float num6 = num3 + Mathf.Clamp01(v) * (num4 - num3);
			float num7 = Mathf.Max(0f, num6 - (((Rect)(ref r)).x + num5));
			Fill(new Rect(((Rect)(ref r)).x + num5, ((Rect)(ref r)).y + num5, num7, 3f * num5), colRed);
			GUI.color = Color.white;
			GUI.DrawTexture(new Rect(Mathf.Round(num6 - num2 / 2f), ((Rect)(ref area)).y + (((Rect)(ref area)).height - num2) / 2f, num2, num2), (Texture)(object)thumbTex);
		}
		return v;
	}

	private bool PWheel(Rect area, ref float h, ref float s)
	{
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: 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_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Invalid comparison between Unknown and I4
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Invalid comparison between Unknown and I4
		//IL_00cb: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Invalid comparison between Unknown and I4
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ee: 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)
		//IL_0222: Unknown result type (might be due to invalid IL or missing references)
		//IL_0250: Unknown result type (might be due to invalid IL or missing references)
		//IL_025e: Unknown result type (might be due to invalid IL or missing references)
		int num = ++idCounter;
		Event current = Event.current;
		float num2 = ((Rect)(ref area)).x + ((Rect)(ref area)).width / 2f;
		float num3 = ((Rect)(ref area)).y + ((Rect)(ref area)).height / 2f;
		float num4 = ((Rect)(ref area)).width / 2f;
		float num5 = num4 - 2f * (float)ps;
		bool result = false;
		if ((int)current.type == 0 && current.button == 0)
		{
			float num6 = current.mousePosition.x - num2;
			float num7 = current.mousePosition.y - num3;
			if (num6 * num6 + num7 * num7 <= num4 * num4)
			{
				activeId = num;
			}
		}
		if (activeId == num && ((int)current.type == 0 || (int)current.type == 3))
		{
			float num8 = current.mousePosition.x - num2;
			float num9 = num3 - current.mousePosition.y;
			float num10 = Mathf.Sqrt(num8 * num8 + num9 * num9);
			if (num10 > 0.5f)
			{
				float num11 = Mathf.Atan2(num9, num8) / ((float)Math.PI * 2f);
				if (num11 < 0f)
				{
					num11 += 1f;
				}
				h = num11;
			}
			s = Mathf.Clamp01(num10 / num5);
			result = true;
			current.Use();
		}
		if (activeId == num && (int)current.type == 1)
		{
			activeId = 0;
			current.Use();
		}
		if ((int)current.type == 7)
		{
			GUI.color = Color.white;
			GUI.DrawTexture(area, (Texture)(object)wheelTex);
			float num12 = h * 2f * (float)Math.PI;
			float num13 = Mathf.Round(num2 + Mathf.Cos(num12) * s * num5);
			float num14 = Mathf.Round(num3 - Mathf.Sin(num12) * s * num5);
			float num15 = ps;
			Fill(new Rect(num13 - 4f * num15, num14 - 4f * num15, 8f * num15, 8f * num15), Color.black);
			Fill(new Rect(num13 - 3f * num15, num14 - 3f * num15, 6f * num15, 6f * num15), Color.white);
			Fill(new Rect(num13 - 2f * num15, num14 - 2f * num15, 4f * num15, 4f * num15), Color.HSVToRGB(h, s, 1f));
		}
		return result;
	}

	private void ToggleMenu()
	{
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		menuOpen = !menuOpen;
		activeId = 0;
		dragWin = false;
		if (menuOpen)
		{
			prevLock = Cursor.lockState;
			prevVisible = Cursor.visible;
		}
		else
		{
			Cursor.lockState = prevLock;
			Cursor.visible = prevVisible;
			SaveConfig();
		}
	}

	private void OnGUI()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Invalid comparison between Unknown and I4
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		Event current = Event.current;
		if ((int)current.type == 4 && current.keyCode == cfgKey.Value)
		{
			ToggleMenu();
			current.Use();
		}
		if (menuOpen)
		{
			if ((Object)(object)fontTex == (Object)null)
			{
				BuildAtlas();
			}
			DrawMenu();
			GUI.color = Color.white;
			if (closeRequested)
			{
				closeRequested = false;
				ToggleMenu();
			}
		}
	}

	private void DrawMenu()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Invalid comparison between Unknown and I4
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Invalid comparison between Unknown and I4
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01aa: Invalid comparison between Unknown and I4
		//IL_017e: 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_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: 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_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: 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_0251: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: Unknown result type (might be due to invalid IL or missing references)
		//IL_020d: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_030b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0328: 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_027f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0284: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0400: Unknown result type (might be due to invalid IL or missing references)
		//IL_0393: Unknown result type (might be due to invalid IL or missing references)
		//IL_0398: Unknown result type (might be due to invalid IL or missing references)
		//IL_053b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0558: Unknown result type (might be due to invalid IL or missing references)
		//IL_0562: Unknown result type (might be due to invalid IL or missing references)
		//IL_047e: Unknown result type (might be due to invalid IL or missing references)
		//IL_050d: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_05aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0610: Unknown result type (might be due to invalid IL or missing references)
		//IL_061a: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0654: Unknown result type (might be due to invalid IL or missing references)
		//IL_065e: Unknown result type (might be due to invalid IL or missing references)
		//IL_067a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0684: Unknown result type (might be due to invalid IL or missing references)
		Event current = Event.current;
		bool num = (int)current.type == 7;
		ps = PixelScale();
		idCounter = 0;
		winPos.x = Mathf.Clamp(winPos.x, 0f, Mathf.Max(0f, (float)Screen.width - 236f * (float)ps));
		winPos.y = Mathf.Clamp(winPos.y, 0f, Mathf.Max(0f, (float)Screen.height - menuH * (float)ps));
		ox = Mathf.Round(winPos.x);
		oy = Mathf.Round(winPos.y);
		Rect r = default(Rect);
		((Rect)(ref r))..ctor(ox, oy, 236f * (float)ps, menuH * (float)ps);
		Rect val = default(Rect);
		((Rect)(ref val))..ctor(ox, oy, 236f * (float)ps, 30f * (float)ps);
		if ((int)current.type == 0 && current.button == 0 && ((Rect)(ref val)).Contains(current.mousePosition))
		{
			dragWin = true;
			dragOff = current.mousePosition - winPos;
			current.Use();
		}
		else if (dragWin && (int)current.type == 3)
		{
			winPos = current.mousePosition - dragOff;
			current.Use();
		}
		else if (dragWin && (int)current.type == 1)
		{
			dragWin = false;
			current.Use();
		}
		if (num)
		{
			PixelBox(r, colWinFill, colWinBorder, 2);
		}
		float num2 = 12f;
		TextU("COLOR HOLDS", 12f, num2, 2, Color.white, 0);
		num2 += 19f;
		if (num)
		{
			Fill(U(12f, num2, 212f, 1f), Color.white);
		}
		num2 += 10f;
		float h = tH;
		float s = tS;
		float num3 = tV;
		float v = shaderMix;
		PWheel(U(12f, num2, 88f, 88f), ref h, ref s);
		float num4 = 110f;
		float num5 = 224f - num4;
		if (num)
		{
			Fill(U(num4, num2, num5, 16f), Color.white);
			Fill(U(num4 + 1f, num2 + 1f, num5 - 2f, 14f), Color.HSVToRGB(h, s, num3));
		}
		TextU("BRIGHTNESS", num4, num2 + 24f, 1, Color.white, 0);
		num3 = PSlider(U(num4, num2 + 33f, num5, 13f), num3);
		TextU("SHADER", num4, num2 + 54f, 1, Color.white, 0);
		v = PSlider(U(num4, num2 + 63f, num5, 13f), v);
		num2 += 97f;
		if (Click(U(12f, num2, 212f, 12f), out var hover, out var _))
		{
			cfgStats.Value = !cfgStats.Value;
		}
		if (num)
		{
			PixelBox(U(12f, num2 + 1f, 9f, 9f), Color.black, hover ? colRed : Color.white, 1);
			if (cfgStats.Value)
			{
				PixelBox(U(14f, num2 + 3f, 5f, 5f), Color.white, Color.white, 1);
			}
		}
		TextU("SHOW PERFORMANCE INFO", 26f, num2 + 3f, 1, Color.white, 0);
		num2 += 15f;
		if (cfgStats.Value)
		{
			TextU("MOD " + msAvg.ToString("F2", CultureInfo.InvariantCulture) + " MS/FRAME  SCAN " + refreshMs.ToString("F1", CultureInfo.InvariantCulture) + " MS", 12f, num2, 1, colGray, 0);
			num2 += 10f;
			TextU("HOLDS " + tracked.Count + "  TEX " + texEntries.Count + "  QUEUE " + (startQueue.Count + running.Count), 12f, num2, 1, colGray, 0);
			num2 += 10f;
		}
		num2 += 3f;
		TextU("MENU SIZE", 12f, num2 + 4f, 1, Color.white, 0);
		if (PButton(U(160f, num2, 16f, 14f), "-", Color.white))
		{
			cfgPixel.Value = Mathf.Max(1, ps - 1);
		}
		TextU("X" + ps, 192f, num2 + 4f, 1, Color.white, 2);
		if (PButton(U(208f, num2, 16f, 14f), "+", Color.white))
		{
			cfgPixel.Value = Mathf.Min(6, ps + 1);
		}
		num2 += 23f;
		if (PButton(U(12f, num2, 64f, 18f), "RESET", Color.white))
		{
			h = 1f / 3f;
			s = 1f;
			num3 = 1f;
			v = 1f;
		}
		if (PButton(U(114f, num2, 110f, 18f), "SAVE AND CLOSE", Color.white))
		{
			closeRequested = true;
		}
		num2 += 30f;
		if ((int)current.type == 0 && ((Rect)(ref r)).Contains(current.mousePosition))
		{
			current.Use();
		}
		menuH = num2;
		if (Mathf.Abs(h - tH) > 0.0005f || Mathf.Abs(s - tS) > 0.0005f || Mathf.Abs(num3 - tV) > 0.0005f || Mathf.Abs(v - shaderMix) > 0.0005f)
		{
			SetTarget(h, s, num3, v);
			texDirty = true;
			lastChange = Time.realtimeSinceStartup;
		}
	}

	private void Awake()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Expected O, but got Unknown
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Expected O, but got Unknown
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Expected O, but got Unknown
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Expected O, but got Unknown
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_018d: Expected O, but got Unknown
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: Expected O, but got Unknown
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		//IL_0213: Expected O, but got Unknown
		mpb = new MaterialPropertyBlock();
		blockIds = new int[blockNames.Length];
		for (int i = 0; i < blockNames.Length; i++)
		{
			blockIds[i] = Shader.PropertyToID(blockNames[i]);
		}
		cfgHue = ((BaseUnityPlugin)this).Config.Bind<float>("Color", "Hue", 1f / 3f, new ConfigDescription("Hue 0..1", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
		cfgSat = ((BaseUnityPlugin)this).Config.Bind<float>("Color", "Saturation", 1f, new ConfigDescription("Saturation 0..1", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
		cfgBright = ((BaseUnityPlugin)this).Config.Bind<float>("Color", "Brightness", 1f, new ConfigDescription("Color brightness 0..1", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
		cfgShader = ((BaseUnityPlugin)this).Config.Bind<float>("Color", "ShaderStrength", 1f, new ConfigDescription("0 = original shader look (red), 1 = fully recolored", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
		cfgKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Menu", "ToggleKey", (KeyCode)287, "Key that opens the color menu");
		cfgPixel = ((BaseUnityPlugin)this).Config.Bind<int>("Menu", "PixelScale", 0, new ConfigDescription("Menu pixel size: 0 = automatic by screen height, 1..6 = fixed", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 6), Array.Empty<object>()));
		cfgStats = ((BaseUnityPlugin)this).Config.Bind<bool>("Menu", "ShowPerformanceInfo", true, "Show performance numbers in the menu");
		cfgHidden = ((BaseUnityPlugin)this).Config.Bind<int>("Performance", "HiddenEveryNFrames", 3, new ConfigDescription("Holds that are not on screen are recolored every N frames (1 = every frame, slowest)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 30), Array.Empty<object>()));
		cfgTexJobs = ((BaseUnityPlugin)this).Config.Bind<int>("Performance", "TextureJobsPerFrame", 2, new ConfigDescription("How many textures may start/finish repainting per frame", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 8), Array.Empty<object>()));
		SetTarget(cfgHue.Value, cfgSat.Value, cfgBright.Value, cfgShader.Value);
		((MonoBehaviour)this).InvokeRepeating("Refresh", 1f, 0.5f);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Color Holds 1.0.0 loaded");
	}

	private void SetTarget(float h, float s, float v, float mix)
	{
		//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)
		tH = Mathf.Clamp01(h);
		tS = Mathf.Clamp01(s);
		tV = Mathf.Clamp01(v);
		shaderMix = Mathf.Clamp01(mix);
		target = Color.HSVToRGB(tH, tS, tV);
		colorGen++;
	}

	private void SaveConfig()
	{
		cfgHue.Value = tH;
		cfgSat.Value = tS;
		cfgBright.Value = tV;
		cfgShader.Value = shaderMix;
	}

	private static bool HasAny(string n, string[] keys)
	{
		for (int i = 0; i < keys.Length; i++)
		{
			if (n.IndexOf(keys[i], StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
		}
		return false;
	}

	private static int Mod(int a, int b)
	{
		int num = a % b;
		if (num >= 0)
		{
			return num;
		}
		return num + b;
	}

	private static bool Same(Color a, Color b)
	{
		//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_0019: 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_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: 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)
		if (Mathf.Abs(a.r - b.r) < 0.002f && Mathf.Abs(a.g - b.g) < 0.002f && Mathf.Abs(a.b - b.b) < 0.002f)
		{
			return Mathf.Abs(a.a - b.a) < 0.002f;
		}
		return false;
	}

	private static bool IsGlowTex(string l)
	{
		if (!l.Contains("emi") && !l.Contains("noise") && !l.Contains("shimmer"))
		{
			return l.Contains("glow");
		}
		return true;
	}

	private static bool IsSkippedTex(string l)
	{
		string[] array = skipTex;
		foreach (string value in array)
		{
			if (l.Contains(value))
			{
				return true;
			}
		}
		return false;
	}

	private Color Tint(Color c)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		float num = default(float);
		float num2 = default(float);
		float num3 = default(float);
		Color.RGBToHSV(c, ref num, ref num2, ref num3);
		if (num2 < 0.25f || num3 < 0.05f)
		{
			return c;
		}
		Color result = Color.HSVToRGB(tH, Mathf.Clamp01(num2 * tS), num3 * tV, true);
		result.a = c.a;
		return result;
	}

	private Color Resolve(ColorState st, Color cur, bool shimmer, bool shader)
	{
		//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_000f: 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_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: 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_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		if (!Same(cur, st.applied))
		{
			st.orig = cur;
			st.gen = -1;
		}
		if (st.gen != colorGen)
		{
			Color val = (Color)(shimmer ? new Color(target.r, target.g, target.b, st.orig.a) : Tint(st.orig));
			if (shader)
			{
				val = Color.Lerp(st.orig, val, shaderMix);
			}
			st.tinted = val;
			st.gen = colorGen;
		}
		st.applied = st.tinted;
		return st.tinted;
	}

	private PropInfo Info(Shader sh)
	{
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Invalid comparison between Unknown and I4
		int instanceID = ((Object)sh).GetInstanceID();
		if (shaderInfo.TryGetValue(instanceID, out var value))
		{
			return value;
		}
		List<int> list = new List<int>();
		List<string> list2 = new List<string>();
		List<bool> list3 = new List<bool>();
		List<bool> list4 = new List<bool>();
		List<int> list5 = new List<int>();
		List<bool> list6 = new List<bool>();
		List<bool> list7 = new List<bool>();
		int propertyCount = sh.GetPropertyCount();
		for (int i = 0; i < propertyCount; i++)
		{
			ShaderPropertyType propertyType = sh.GetPropertyType(i);
			string propertyName = sh.GetPropertyName(i);
			string text = propertyName.ToLowerInvariant();
			if ((int)propertyType == 0)
			{
				list.Add(Shader.PropertyToID(propertyName));
				list2.Add(propertyName);
				list3.Add(text.Contains("shimmer"));
				list4.Add(text.Contains("shimmer") || text.Contains("emi"));
			}
			else if ((int)propertyType == 4)
			{
				list5.Add(Shader.PropertyToID(propertyName));
				list6.Add(IsGlowTex(text));
				list7.Add(IsSkippedTex(text));
			}
		}
		value = new PropInfo
		{
			colorIds = list.ToArray(),
			colorNames = list2.ToArray(),
			colorShimmer = list3.ToArray(),
			colorShader = list4.ToArray(),
			texIds = list5.ToArray(),
			texGlow = list6.ToArray(),
			texSkip = list7.ToArray()
		};
		shaderInfo[instanceID] = value;
		return value;
	}

	private static Tracked Classify(Renderer r, Tracked old)
	{
		bool flag = false;
		bool paint = false;
		bool flag2 = false;
		Transform val = ((Component)r).transform;
		int num = 0;
		while (num < 9 && (Object)(object)val != (Object)null)
		{
			if (num == 3 && !flag)
			{
				return Ignored;
			}
			string name = ((Object)val).name;
			if (name.IndexOf("inventory", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				flag2 = true;
			}
			if (num < 3)
			{
				if (HasAny(name, holdKeys))
				{
					flag = true;
				}
				if (HasAny(name, paintKeys))
				{
					paint = true;
				}
			}
			num++;
			val = val.parent;
		}
		if (!flag || flag2)
		{
			return Ignored;
		}
		if (old != null && old != Ignored)
		{
			old.paint = paint;
			return old;
		}
		return new Tracked
		{
			r = r,
			paint = paint
		};
	}

	private void Refresh()
	{
		long timestamp = Stopwatch.GetTimestamp();
		refreshCycle++;
		Renderer[] array = Object.FindObjectsByType<Renderer>((FindObjectsSortMode)0);
		cacheB.Clear();
		this.tracked.Clear();
		foreach (Renderer val in array)
		{
			int instanceID = ((Object)val).GetInstanceID();
			Tracked value;
			bool flag = cacheA.TryGetValue(instanceID, out value);
			Tracked tracked = value;
			if (flag)
			{
				int num = ((value == Ignored) ? 16 : 4);
				if (Mod(instanceID, num) == refreshCycle % num)
				{
					flag = false;
				}
			}
			if (!flag)
			{
				tracked = Classify(val, value);
			}
			cacheB[instanceID] = tracked;
			if (tracked != Ignored)
			{
				this.tracked.Add(tracked);
			}
		}
		Dictionary<int, Tracked> dictionary = cacheA;
		cacheA = cacheB;
		cacheB = dictionary;
		if (refreshCycle % 120 == 0)
		{
			CleanPlans();
		}
		refreshMs = refreshMs * 0.8 + (double)(Stopwatch.GetTimestamp() - timestamp) * 1000.0 / (double)Stopwatch.Frequency * 0.2;
	}

	private void CleanPlans()
	{
		deadKeys.Clear();
		foreach (KeyValuePair<long, MatPlan> plan in plans)
		{
			if ((Object)(object)plan.Value.owner == (Object)null)
			{
				deadKeys.Add(plan.Key);
			}
		}
		for (int i = 0; i < deadKeys.Count; i++)
		{
			plans.Remove(deadKeys[i]);
		}
	}

	private MatPlan GetPlan(Material m, bool paint)
	{
		long key = ((long)((Object)m).GetInstanceID() << 1) | (paint ? 1 : 0);
		if (plans.TryGetValue(key, out var value))
		{
			return value;
		}
		value = new MatPlan
		{
			owner = m
		};
		string name = ((Object)m).name;
		bool flag = name.IndexOf("(Instance)", StringComparison.Ordinal) >= 0;
		bool flag2 = name.IndexOf("GreenClone", StringComparison.Ordinal) >= 0;
		value.needClone = !flag && !flag2 && (m.HasProperty("_Emission") || (paint && m.HasProperty("_MainTex") && (Object)(object)m.GetTexture("_MainTex") != (Object)null));
		if (!value.needClone)
		{
			value.pi = Info(m.shader);
			value.cs = new ColorState[value.pi.colorIds.Length];
			for (int i = 0; i < value.cs.Length; i++)
			{
				value.cs[i] = new ColorState();
			}
			value.orig = (Texture[])(object)new Texture[value.pi.texIds.Length];
			value.paintMain = paint || name.IndexOf("grate", StringComparison.OrdinalIgnoreCase) >= 0;
		}
		plans[key] = value;
		return value;
	}

	private void ApplyPlan(Material m, MatPlan p)
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: 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_0064: 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_0067: 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)
		PropInfo pi = p.pi;
		if (p.texEpoch != texEpoch)
		{
			p.texEpoch = texEpoch;
			DoTextures(m, p);
		}
		int[] colorIds = pi.colorIds;
		for (int i = 0; i < colorIds.Length; i++)
		{
			Color color = m.GetColor(colorIds[i]);
			ColorState colorState = p.cs[i];
			Color val = Resolve(colorState, color, pi.colorShimmer[i], pi.colorShader[i]);
			if (!Same(color, val))
			{
				m.SetColor(colorIds[i], val);
				if (!colorState.logged)
				{
					colorState.logged = true;
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Recolored " + ((Object)m).name + " (" + pi.colorNames[i] + ")"));
				}
			}
		}
	}

	private void ApplyBlock(Tracked t)
	{
		//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_0088: 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_009d: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		Renderer r = t.r;
		if (!r.HasPropertyBlock())
		{
			return;
		}
		r.GetPropertyBlock(mpb);
		if (mpb.isEmpty)
		{
			return;
		}
		bool flag = false;
		for (int i = 0; i < blockIds.Length; i++)
		{
			int num = blockIds[i];
			if (mpb.HasColor(num) || mpb.HasVector(num))
			{
				Color color = mpb.GetColor(num);
				ColorState colorState = t.blockStates[i];
				if (colorState == null)
				{
					colorState = new ColorState();
					t.blockStates[i] = colorState;
				}
				Color val = Resolve(colorState, color, i == 3, i == 0 || i == 3);
				if (!Same(color, val))
				{
					mpb.SetColor(num, val);
					flag = true;
				}
			}
		}
		if (flag)
		{
			r.SetPropertyBlock(mpb);
		}
	}

	private void LateUpdate()
	{
		//IL_0214: Unknown result type (might be due to invalid IL or missing references)
		//IL_021e: Expected O, but got Unknown
		long timestamp = Stopwatch.GetTimestamp();
		if (menuOpen)
		{
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
		}
		if (texDirty && Time.realtimeSinceStartup - lastChange > 0.4f)
		{
			texDirty = false;
			SaveConfig();
			RebuildTextures();
		}
		int value = cfgTexJobs.Value;
		for (int i = 0; i < value; i++)
		{
			if (startQueue.Count <= 0)
			{
				break;
			}
			StartJob(startQueue.Dequeue());
		}
		int num = 0;
		int num2 = 0;
		while (num2 < running.Count && num < value)
		{
			if (running[num2].done)
			{
				FinishJob(running[num2]);
				running.RemoveAt(num2);
				num++;
			}
			else
			{
				num2++;
			}
		}
		for (int num3 = pendingDestroy.Count - 1; num3 >= 0; num3--)
		{
			if (!(Time.realtimeSinceStartup < pendingDestroy[num3].time))
			{
				Texture2D tex = pendingDestroy[num3].tex;
				if ((Object)(object)tex != (Object)null)
				{
					greenToSrc.Remove(((Object)tex).GetInstanceID());
					Object.Destroy((Object)(object)tex);
				}
				pendingDestroy.RemoveAt(num3);
			}
		}
		int frameCount = Time.frameCount;
		int value2 = cfgHidden.Value;
		for (int j = 0; j < this.tracked.Count; j++)
		{
			Tracked tracked = this.tracked[j];
			Renderer r = tracked.r;
			if ((Object)(object)r == (Object)null || (value2 > 1 && (frameCount + j) % value2 != 0 && !r.isVisible))
			{
				continue;
			}
			r.GetSharedMaterials(matBuf);
			bool flag = false;
			for (int k = 0; k < matBuf.Count; k++)
			{
				Material val = matBuf[k];
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				MatPlan matPlan = GetPlan(val, tracked.paint);
				if (matPlan.needClone)
				{
					if ((Object)(object)matPlan.clone == (Object)null)
					{
						matPlan.clone = new Material(val);
						((Object)matPlan.clone).name = ((Object)val).name + " (GreenClone)";
						matPlan.clonePlan = GetPlan(matPlan.clone, tracked.paint);
					}
					val = matPlan.clone;
					matPlan = matPlan.clonePlan;
					matBuf[k] = val;
					flag = true;
				}
				ApplyPlan(val, matPlan);
			}
			if (flag)
			{
				r.SetSharedMaterials(matBuf);
			}
			ApplyBlock(tracked);
		}
		msAvg = msAvg * 0.95 + (double)(Stopwatch.GetTimestamp() - timestamp) * 1000.0 / (double)Stopwatch.Frequency * 0.05;
	}

	private void DoTextures(Material m, MatPlan p)
	{
		PropInfo pi = p.pi;
		for (int i = 0; i < pi.texIds.Length; i++)
		{
			if (pi.texSkip[i] || (!pi.texGlow[i] && !p.paintMain))
			{
				continue;
			}
			int num = pi.texIds[i];
			Texture val = p.orig[i];
			if ((Object)(object)val == (Object)null)
			{
				Texture val2 = m.GetTexture(num);
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				if (greenToSrc.TryGetValue(((Object)val2).GetInstanceID(), out var value) && (Object)(object)value != (Object)null)
				{
					val2 = value;
				}
				p.orig[i] = val2;
				val = val2;
			}
			Texture val3 = GreenTex(val, pi.texGlow[i]);
			if ((Object)(object)val3 != (Object)null)
			{
				m.SetTexture(num, val3);
			}
		}
	}

	private Texture GreenTex(Texture src, bool glow)
	{
		int instanceID = ((Object)src).GetInstanceID();
		if (!texEntries.TryGetValue(instanceID, out var value))
		{
			value = new TexEntry
			{
				src = src,
				glow = glow
			};
			texEntries[instanceID] = value;
			QueueStart(value);
		}
		return (Texture)(object)value.result;
	}

	private void QueueStart(TexEntry e)
	{
		if (e.busy)
		{
			if (e.started)
			{
				e.rerun = true;
			}
		}
		else
		{
			e.busy = true;
			startQueue.Enqueue(e);
		}
	}

	private void RebuildTextures()
	{
		foreach (KeyValuePair<int, TexEntry> texEntry in texEntries)
		{
			if (!texEntry.Value.failed)
			{
				QueueStart(texEntry.Value);
			}
		}
	}

	private void StartJob(TexEntry e)
	{
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Expected O, but got Unknown
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		e.started = true;
		Texture src = e.src;
		if ((Object)(object)src == (Object)null)
		{
			e.busy = false;
			e.started = false;
			e.failed = true;
			return;
		}
		RenderTexture active = RenderTexture.active;
		RenderTexture val = null;
		Texture2D val2 = null;
		try
		{
			int width = src.width;
			int height = src.height;
			val = RenderTexture.GetTemporary(width, height, 0, (RenderTextureFormat)0);
			Graphics.Blit(src, val);
			RenderTexture.active = val;
			val2 = new Texture2D(width, height, (TextureFormat)4, false);
			val2.ReadPixels(new Rect(0f, 0f, (float)width, (float)height), 0, 0);
			Color32[] pixels = val2.GetPixels32();
			TexJob texJob = new TexJob
			{
				e = e,
				px = pixels,
				w = width,
				h = height,
				hue = tH,
				sMul = tS,
				vMul = tV,
				mix = (e.glow ? shaderMix : 1f)
			};
			running.Add(texJob);
			ThreadPool.QueueUserWorkItem(Worker, texJob);
		}
		catch (Exception ex)
		{
			e.busy = false;
			e.started = false;
			e.failed = true;
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Texture repaint failed for " + ((Object)src).name + ": " + ex.Message));
		}
		finally
		{
			RenderTexture.active = active;
			if ((Object)(object)val != (Object)null)
			{
				RenderTexture.ReleaseTemporary(val);
			}
			if ((Object)(object)val2 != (Object)null)
			{
				Object.Destroy((Object)(object)val2);
			}
		}
	}

	private static void Worker(object state)
	{
		TexJob texJob = (TexJob)state;
		try
		{
			Repaint(texJob.px, texJob.hue, texJob.sMul, texJob.vMul, texJob.mix);
		}
		catch
		{
			texJob.error = true;
		}
		texJob.done = true;
	}

	private static void Repaint(Color32[] px, float hue, float sMul, float vMul, float mix)
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: 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_0077: 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_0055: 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_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: 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_00c4: 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_0284: Unknown result type (might be due to invalid IL or missing references)
		//IL_0286: 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_01e1: 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_0206: 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_022b: Unknown result type (might be due to invalid IL or missing references)
		float num = hue * 6f;
		if (num >= 6f)
		{
			num -= 6f;
		}
		if (num < 0f)
		{
			num = 0f;
		}
		int num2 = (int)num;
		float num3 = num - (float)num2;
		for (int i = 0; i < px.Length; i++)
		{
			Color32 val = px[i];
			int num4 = ((val.r <= val.g) ? ((val.g > val.b) ? val.g : val.b) : ((val.r > val.b) ? val.r : val.b));
			if (num4 < 13)
			{
				continue;
			}
			int num5 = ((val.r >= val.g) ? ((val.g < val.b) ? val.g : val.b) : ((val.r < val.b) ? val.r : val.b));
			int num6 = num4 - num5;
			if (num6 * 4 > num4)
			{
				float num7 = (float)num4 / 255f;
				float num8 = (float)num6 / (float)num4 * sMul;
				if (num8 > 1f)
				{
					num8 = 1f;
				}
				float num9 = num7 * vMul;
				float num10 = num9 * (1f - num8);
				float num11 = num9 * (1f - num8 * num3);
				float num12 = num9 * (1f - num8 * (1f - num3));
				float num13;
				float num14;
				float num15;
				switch (num2)
				{
				case 0:
					num13 = num9;
					num14 = num12;
					num15 = num10;
					break;
				case 1:
					num13 = num11;
					num14 = num9;
					num15 = num10;
					break;
				case 2:
					num13 = num10;
					num14 = num9;
					num15 = num12;
					break;
				case 3:
					num13 = num10;
					num14 = num11;
					num15 = num9;
					break;
				case 4:
					num13 = num12;
					num14 = num10;
					num15 = num9;
					break;
				default:
					num13 = num9;
					num14 = num10;
					num15 = num11;
					break;
				}
				if (mix < 1f)
				{
					num13 = (float)(int)val.r / 255f + (num13 - (float)(int)val.r / 255f) * mix;
					num14 = (float)(int)val.g / 255f + (num14 - (float)(int)val.g / 255f) * mix;
					num15 = (float)(int)val.b / 255f + (num15 - (float)(int)val.b / 255f) * mix;
				}
				val.r = (byte)(num13 * 255f + 0.5f);
				val.g = (byte)(num14 * 255f + 0.5f);
				val.b = (byte)(num15 * 255f + 0.5f);
				px[i] = val;
			}
		}
	}

	private void FinishJob(TexJob job)
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Expected O, but got Unknown
		//IL_0068: 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)
		TexEntry e = job.e;
		e.busy = false;
		e.started = false;
		try
		{
			if (job.error || (Object)(object)e.src == (Object)null)
			{
				e.failed = true;
			}
			else
			{
				Texture2D val = new Texture2D(job.w, job.h, (TextureFormat)4, true);
				val.SetPixels32(job.px);
				val.Apply(true, true);
				((Texture)val).filterMode = e.src.filterMode;
				((Texture)val).wrapMode = e.src.wrapMode;
				((Object)val).name = ((Object)e.src).name + "_green";
				greenToSrc[((Object)val).GetInstanceID()] = e.src;
				if ((Object)(object)e.result != (Object)null)
				{
					pendingDestroy.Add(new PendDestroy
					{
						tex = e.result,
						time = Time.realtimeSinceStartup + 5f
					});
				}
				e.result = val;
				texEpoch++;
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Repainted texture " + ((Object)e.src).name));
			}
		}
		catch (Exception ex)
		{
			e.failed = true;
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Texture repaint failed: " + ex.Message));
		}
		job.px = null;
		if (e.rerun)
		{
			e.rerun = false;
			if (!e.failed)
			{
				QueueStart(e);
			}
		}
	}
}