Decompiled source of JuteRugColorChanger v1.0.1

JuteRugColorChanger.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("JuteRugColorChanger")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("JuteRugColorChanger")]
[assembly: AssemblyTitle("JuteRugColorChanger")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace JuteRugColorChanger;

[BepInPlugin("com.modder.juterugcolorchanger", "Jute Rug Color Changer", "1.0.0")]
public class JuteRugColorChangerPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Player), "TakeInput")]
	private static class Player_TakeInput_Patch
	{
		private static bool Prefix(ref bool __result)
		{
			if (showColorPicker)
			{
				__result = false;
				return false;
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(Menu), "IsVisible")]
	private static class Menu_IsVisible_Patch
	{
		private static void Postfix(ref bool __result)
		{
			if (showColorPicker)
			{
				__result = true;
			}
		}
	}

	[HarmonyPatch(typeof(ZNetView), "Awake")]
	private static class ZNetView_Awake_Patch
	{
		private static void Postfix(ZNetView __instance)
		{
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)__instance == (Object)null || !__instance.IsValid())
				{
					return;
				}
				Piece component = ((Component)__instance).GetComponent<Piece>();
				if ((Object)(object)component == (Object)null)
				{
					return;
				}
				string prefabName = Utils.GetPrefabName(((Component)__instance).gameObject);
				if (IsTargetRug(prefabName))
				{
					string @string = __instance.GetZDO().GetString("RugColor", "");
					Color val = default(Color);
					if (!string.IsNullOrEmpty(@string) && ColorUtility.TryParseHtmlString("#" + @string, ref val))
					{
						ZDOID uid = __instance.GetZDO().m_uid;
						Renderer[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Renderer>();
						ApplyColorToRenderers(componentsInChildren, val, uid);
						savedColors[uid] = val;
					}
				}
			}
			catch (Exception)
			{
			}
		}
	}

	[HarmonyPatch(typeof(HoverText), "GetHoverText")]
	private static class HoverText_GetHoverText_Patch
	{
		private static void Postfix(HoverText __instance, ref string __result)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance == (Object)null))
			{
				string prefabName = Utils.GetPrefabName(((Component)__instance).gameObject);
				if (IsTargetRug(prefabName))
				{
					__result += $"\n<color=#FFC864>[<color=yellow>{openMenuKey.Value}</color>] Change Color</color>";
				}
			}
		}
	}

	public const string PluginGUID = "com.modder.juterugcolorchanger";

	public const string PluginName = "Jute Rug Color Changer";

	public const string PluginVersion = "1.0.0";

	private static ConfigEntry<float> interactionRange;

	private static ConfigEntry<KeyCode> openMenuKey;

	private static bool showColorPicker = false;

	private static Piece targetPiece = null;

	private static Color selectedColor = Color.red;

	private static string hexInput = "FF0000";

	private static float hue = 0f;

	private static float saturation = 1f;

	private static float brightness = 1f;

	private static Texture2D colorWheelTexture;

	private static Texture2D brightnessSliderTexture;

	private static Texture2D previewTexture;

	private static Texture2D checkerTexture;

	private static Texture2D windowBackground;

	private static Texture2D buttonNormal;

	private static Texture2D buttonHover;

	private static Texture2D inputBackground;

	private static Texture2D sliderThumb;

	private static Rect windowRect = new Rect(0f, 0f, 360f, 440f);

	private static bool windowPositioned = false;

	private static bool isDragging = false;

	private static Vector2 dragOffset;

	private static Dictionary<ZDOID, Color> savedColors = new Dictionary<ZDOID, Color>();

	private static readonly HashSet<string> rugPrefabNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "jute_carpet", "jute_carpet_blue" };

	private Harmony harmony;

	private static ManualLogSource Log;

	private static Dictionary<ZDOID, Dictionary<string, Texture>> originalTextures = new Dictionary<ZDOID, Dictionary<string, Texture>>();

	private static Dictionary<int, Texture2D> grayscaleCache = new Dictionary<int, Texture2D>();

	private void Awake()
	{
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		interactionRange = ((BaseUnityPlugin)this).Config.Bind<float>("General", "InteractionRange", 10f, "Maximum distance to interact with rugs.");
		openMenuKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "OpenMenuKey", (KeyCode)45, "Key to open color picker when near a rug.");
		harmony = new Harmony("com.modder.juterugcolorchanger");
		harmony.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Jute Rug Color Changer v1.0.0 loaded!");
	}

	private void OnDestroy()
	{
		Harmony obj = harmony;
		if (obj != null)
		{
			obj.UnpatchSelf();
		}
		DestroyTextures();
	}

	private void Start()
	{
		GenerateTextures();
	}

	private void Update()
	{
		//IL_0027: 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)
		if (showColorPicker)
		{
			if (Input.GetKeyDown((KeyCode)27))
			{
				CloseColorPicker();
			}
		}
		else if (Input.GetKeyDown(openMenuKey.Value))
		{
			Log.LogInfo((object)$"[Input] Key pressed: {openMenuKey.Value}");
			TryOpenColorPicker();
		}
	}

	private void TryOpenColorPicker()
	{
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//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_007f: 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_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: 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_02fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0315: Unknown result type (might be due to invalid IL or missing references)
		//IL_0281: 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_028d: Unknown result type (might be due to invalid IL or missing references)
		//IL_029d: Unknown result type (might be due to invalid IL or missing references)
		//IL_029f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cc: 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_02ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null)
		{
			Log.LogWarning((object)"[TryOpen] No local player found");
			return;
		}
		if ((Object)(object)GameCamera.instance == (Object)null)
		{
			Log.LogWarning((object)"[TryOpen] GameCamera.instance is null");
			return;
		}
		float value = interactionRange.Value;
		Vector3 position = ((Component)GameCamera.instance).transform.position;
		Vector3 forward = ((Component)GameCamera.instance).transform.forward;
		Piece val = null;
		RaycastHit[] array = Physics.SphereCastAll(position, 0.5f, forward, value);
		if (array.Length != 0)
		{
			Array.Sort(array, (RaycastHit a, RaycastHit b) => ((RaycastHit)(ref a)).distance.CompareTo(((RaycastHit)(ref b)).distance));
			RaycastHit[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				RaycastHit val2 = array2[i];
				Piece componentInParent = ((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<Piece>();
				if ((Object)(object)componentInParent != (Object)null)
				{
					string prefabName = Utils.GetPrefabName(((Component)componentInParent).gameObject);
					if (IsTargetRug(prefabName))
					{
						val = componentInParent;
						Log.LogInfo((object)$"[TryOpen] SphereCast found rug: '{prefabName}' at distance {((RaycastHit)(ref val2)).distance:F1}");
						break;
					}
				}
			}
		}
		if ((Object)(object)val == (Object)null)
		{
			Vector3 position2 = ((Component)localPlayer).transform.position;
			float num = float.MaxValue;
			Collider[] array3 = Physics.OverlapSphere(position2, value);
			Collider[] array4 = array3;
			foreach (Collider val3 in array4)
			{
				Piece componentInParent2 = ((Component)val3).GetComponentInParent<Piece>();
				if ((Object)(object)componentInParent2 == (Object)null)
				{
					continue;
				}
				string prefabName2 = Utils.GetPrefabName(((Component)componentInParent2).gameObject);
				if (IsTargetRug(prefabName2))
				{
					float num2 = Vector3.Distance(position2, ((Component)componentInParent2).transform.position);
					if (num2 < num)
					{
						num = num2;
						val = componentInParent2;
						Log.LogInfo((object)$"[TryOpen] Proximity scan found rug: '{prefabName2}' at distance {num2:F1}");
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				Log.LogInfo((object)"[TryOpen] No rug found nearby");
				return;
			}
		}
		targetPiece = val;
		ZNetView component = ((Component)val).GetComponent<ZNetView>();
		if ((Object)(object)component != (Object)null && component.IsValid())
		{
			ZDOID uid = component.GetZDO().m_uid;
			if (savedColors.TryGetValue(uid, out var value2))
			{
				selectedColor = value2;
			}
			else
			{
				string @string = component.GetZDO().GetString("RugColor", "");
				if (!string.IsNullOrEmpty(@string))
				{
					ColorUtility.TryParseHtmlString("#" + @string, ref selectedColor);
				}
				else
				{
					selectedColor = GetCurrentRugColor(val);
				}
			}
		}
		Color.RGBToHSV(selectedColor, ref hue, ref saturation, ref brightness);
		hexInput = ColorUtility.ToHtmlStringRGB(selectedColor);
		showColorPicker = true;
		((Rect)(ref windowRect)).x = ((float)Screen.width - ((Rect)(ref windowRect)).width) / 2f;
		((Rect)(ref windowRect)).y = ((float)Screen.height - ((Rect)(ref windowRect)).height) / 2f;
		Log.LogInfo((object)("[TryOpen] SUCCESS - Color picker opened, color=#" + hexInput));
		Cursor.lockState = (CursorLockMode)0;
		Cursor.visible = true;
	}

	private static bool IsTargetRug(string prefabName)
	{
		if (string.IsNullOrEmpty(prefabName))
		{
			return false;
		}
		foreach (string rugPrefabName in rugPrefabNames)
		{
			if (prefabName.IndexOf(rugPrefabName, StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
		}
		return false;
	}

	private static Color GetCurrentRugColor(Piece piece)
	{
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		Renderer[] componentsInChildren = ((Component)piece).GetComponentsInChildren<Renderer>();
		Renderer[] array = componentsInChildren;
		foreach (Renderer val in array)
		{
			if ((Object)(object)val.material != (Object)null && val.material.HasProperty("_Color"))
			{
				return val.material.color;
			}
		}
		return Color.white;
	}

	private void CloseColorPicker()
	{
		showColorPicker = false;
		targetPiece = null;
		Cursor.lockState = (CursorLockMode)1;
		Cursor.visible = false;
	}

	private static Texture2D GetGrayscaleTexture(Texture sourceTex)
	{
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Expected O, but got Unknown
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		int instanceID = ((Object)sourceTex).GetInstanceID();
		if (grayscaleCache.TryGetValue(instanceID, out var value) && (Object)(object)value != (Object)null)
		{
			return value;
		}
		RenderTexture temporary = RenderTexture.GetTemporary(sourceTex.width, sourceTex.height, 0, (RenderTextureFormat)0);
		Graphics.Blit(sourceTex, temporary);
		RenderTexture active = RenderTexture.active;
		RenderTexture.active = temporary;
		Texture2D val = new Texture2D(sourceTex.width, sourceTex.height, (TextureFormat)4, false);
		val.ReadPixels(new Rect(0f, 0f, (float)sourceTex.width, (float)sourceTex.height), 0, 0);
		val.Apply();
		RenderTexture.active = active;
		RenderTexture.ReleaseTemporary(temporary);
		Color[] pixels = val.GetPixels();
		for (int i = 0; i < pixels.Length; i++)
		{
			float num = pixels[i].r * 0.299f + pixels[i].g * 0.587f + pixels[i].b * 0.114f;
			num = Mathf.Clamp01(num * 1.3f + 0.1f);
			pixels[i] = new Color(num, num, num, pixels[i].a);
		}
		val.SetPixels(pixels);
		val.Apply();
		grayscaleCache[instanceID] = val;
		Log.LogInfo((object)$"[Grayscale] Created grayscale texture {sourceTex.width}x{sourceTex.height} from '{((Object)sourceTex).name}'");
		return val;
	}

	private static void ApplyColorToRenderers(Renderer[] renderers, Color color, ZDOID zdoid)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: 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_022e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
		foreach (Renderer val in renderers)
		{
			if ((Object)(object)val.material == (Object)null)
			{
				continue;
			}
			if (!((ZDOID)(ref zdoid)).IsNone() && !originalTextures.ContainsKey(zdoid))
			{
				Dictionary<string, Texture> dictionary = new Dictionary<string, Texture>();
				if (val.material.HasProperty("_MainTex") && (Object)(object)val.material.GetTexture("_MainTex") != (Object)null)
				{
					dictionary["_MainTex"] = val.material.GetTexture("_MainTex");
				}
				if (val.material.HasProperty("_BumpMap") && (Object)(object)val.material.GetTexture("_BumpMap") != (Object)null)
				{
					dictionary["_BumpMap"] = val.material.GetTexture("_BumpMap");
				}
				originalTextures[zdoid] = dictionary;
			}
			if (val.material.HasProperty("_MainTex"))
			{
				Texture texture = val.material.GetTexture("_MainTex");
				if ((Object)(object)texture != (Object)null)
				{
					int instanceID = ((Object)texture).GetInstanceID();
					if (!grayscaleCache.ContainsKey(instanceID))
					{
						Texture2D grayscaleTexture = GetGrayscaleTexture(texture);
						val.material.SetTexture("_MainTex", (Texture)(object)grayscaleTexture);
					}
					else
					{
						val.material.SetTexture("_MainTex", (Texture)(object)grayscaleCache[instanceID]);
					}
				}
			}
			if (val.material.HasProperty("_Color"))
			{
				val.material.SetColor("_Color", color);
			}
			if (val.material.HasProperty("_BaseColor"))
			{
				val.material.SetColor("_BaseColor", color);
			}
			if (val.material.HasProperty("_MainColor"))
			{
				val.material.SetColor("_MainColor", color);
			}
			if (val.material.HasProperty("_TintColor"))
			{
				val.material.SetColor("_TintColor", color);
			}
			if (val.material.HasProperty("_Metallic"))
			{
				val.material.SetFloat("_Metallic", 0f);
			}
			if (val.material.HasProperty("_Glossiness"))
			{
				val.material.SetFloat("_Glossiness", 0.3f);
			}
			if (val.material.HasProperty("_Smoothness"))
			{
				val.material.SetFloat("_Smoothness", 0.3f);
			}
			if (val.material.HasProperty("_EmissionColor"))
			{
				val.material.EnableKeyword("_EMISSION");
				val.material.SetColor("_EmissionColor", color * 0.1f);
			}
		}
	}

	private void ApplyColor()
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: 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_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)targetPiece == (Object)null)
		{
			return;
		}
		Log.LogInfo((object)("[ApplyColor] Applying color #" + ColorUtility.ToHtmlStringRGB(selectedColor)));
		ZDOID val = default(ZDOID);
		ZNetView component = ((Component)targetPiece).GetComponent<ZNetView>();
		if ((Object)(object)component != (Object)null && component.IsValid())
		{
			val = component.GetZDO().m_uid;
		}
		Renderer[] componentsInChildren = ((Component)targetPiece).GetComponentsInChildren<Renderer>();
		Renderer[] array = componentsInChildren;
		foreach (Renderer val2 in array)
		{
			if ((Object)(object)val2.material != (Object)null)
			{
				Log.LogInfo((object)("[ApplyColor] Renderer: " + ((Object)((Component)val2).gameObject).name + ", Shader: " + ((Object)val2.material.shader).name));
			}
		}
		ApplyColorToRenderers(componentsInChildren, selectedColor, val);
		if ((Object)(object)component != (Object)null && component.IsValid())
		{
			savedColors[val] = selectedColor;
			component.GetZDO().Set("RugColor", ColorUtility.ToHtmlStringRGB(selectedColor));
		}
	}

	private static void GenerateTextures()
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Expected O, but got Unknown
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Expected O, but got Unknown
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Expected O, but got Unknown
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: 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_0222: Unknown result type (might be due to invalid IL or missing references)
		//IL_0245: 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_0277: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		int num = 200;
		colorWheelTexture = new Texture2D(num, num, (TextureFormat)4, false);
		float num2 = (float)num / 2f;
		float num3 = num2 - 2f;
		for (int i = 0; i < num; i++)
		{
			for (int j = 0; j < num; j++)
			{
				float num4 = (float)j - num2;
				float num5 = (float)i - num2;
				float num6 = Mathf.Sqrt(num4 * num4 + num5 * num5);
				if (num6 <= num3)
				{
					float num7 = Mathf.Atan2(num5, num4);
					float num8 = (num7 / ((float)Math.PI * 2f) + 1f) % 1f;
					float num9 = num6 / num3;
					Color val = Color.HSVToRGB(num8, num9, 1f);
					val.a = 1f;
					if (num6 > num3 - 1.5f)
					{
						val.a = Mathf.Clamp01(num3 - num6 + 1.5f);
					}
					colorWheelTexture.SetPixel(j, i, val);
				}
				else
				{
					colorWheelTexture.SetPixel(j, i, new Color(0f, 0f, 0f, 0f));
				}
			}
		}
		colorWheelTexture.Apply();
		brightnessSliderTexture = new Texture2D(1, 256, (TextureFormat)4, false);
		for (int k = 0; k < 256; k++)
		{
			float num10 = (float)k / 255f;
			brightnessSliderTexture.SetPixel(0, k, new Color(num10, num10, num10, 1f));
		}
		brightnessSliderTexture.Apply();
		previewTexture = new Texture2D(1, 1);
		previewTexture.SetPixel(0, 0, Color.white);
		previewTexture.Apply();
		checkerTexture = CreateSolidTexture(new Color(0.3f, 0.3f, 0.3f, 1f));
		windowBackground = CreateSolidTexture(new Color(0.12f, 0.12f, 0.14f, 0.96f));
		buttonNormal = CreateSolidTexture(new Color(0.22f, 0.22f, 0.26f, 1f));
		buttonHover = CreateSolidTexture(new Color(0.35f, 0.55f, 0.85f, 1f));
		inputBackground = CreateSolidTexture(new Color(0.08f, 0.08f, 0.1f, 1f));
		sliderThumb = CreateSolidTexture(Color.white);
	}

	private static Texture2D CreateSolidTexture(Color color)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Expected O, but got Unknown
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(1, 1);
		val.SetPixel(0, 0, color);
		val.Apply();
		return val;
	}

	private static void DestroyTextures()
	{
		if ((Object)(object)colorWheelTexture != (Object)null)
		{
			Object.Destroy((Object)(object)colorWheelTexture);
		}
		if ((Object)(object)brightnessSliderTexture != (Object)null)
		{
			Object.Destroy((Object)(object)brightnessSliderTexture);
		}
		if ((Object)(object)previewTexture != (Object)null)
		{
			Object.Destroy((Object)(object)previewTexture);
		}
		if ((Object)(object)checkerTexture != (Object)null)
		{
			Object.Destroy((Object)(object)checkerTexture);
		}
		if ((Object)(object)windowBackground != (Object)null)
		{
			Object.Destroy((Object)(object)windowBackground);
		}
		if ((Object)(object)buttonNormal != (Object)null)
		{
			Object.Destroy((Object)(object)buttonNormal);
		}
		if ((Object)(object)buttonHover != (Object)null)
		{
			Object.Destroy((Object)(object)buttonHover);
		}
		if ((Object)(object)inputBackground != (Object)null)
		{
			Object.Destroy((Object)(object)inputBackground);
		}
		if ((Object)(object)sliderThumb != (Object)null)
		{
			Object.Destroy((Object)(object)sliderThumb);
		}
	}

	private void OnGUI()
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Invalid comparison between Unknown and I4
		//IL_004f: 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_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Expected O, but got Unknown
		//IL_00a6: 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)
		if (showColorPicker)
		{
			if ((int)Event.current.type == 0 || (int)Event.current.type == 1)
			{
			}
			GUI.depth = 0;
			GUI.color = new Color(0f, 0f, 0f, 0.4f);
			GUI.DrawTexture(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), (Texture)(object)previewTexture);
			GUI.color = Color.white;
			windowRect = GUI.Window(948372, windowRect, new WindowFunction(DrawColorPickerWindow), "");
		}
	}

	private void DrawColorPickerWindow(int windowID)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: 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_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Expected O, but got Unknown
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: 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_01dc: 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_0216: 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_0232: Unknown result type (might be due to invalid IL or missing references)
		//IL_0238: Invalid comparison between Unknown and I4
		//IL_024c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0251: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: 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_0328: Unknown result type (might be due to invalid IL or missing references)
		//IL_032d: 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_0374: 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_03ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_03da: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e0: Invalid comparison between Unknown and I4
		//IL_0451: Unknown result type (might be due to invalid IL or missing references)
		//IL_0456: Unknown result type (might be due to invalid IL or missing references)
		//IL_045f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0474: Unknown result type (might be due to invalid IL or missing references)
		//IL_0481: Expected O, but got Unknown
		//IL_0495: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_04fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0519: Unknown result type (might be due to invalid IL or missing references)
		//IL_051e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0527: Unknown result type (might be due to invalid IL or missing references)
		//IL_052f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0537: Unknown result type (might be due to invalid IL or missing references)
		//IL_053d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0548: Unknown result type (might be due to invalid IL or missing references)
		//IL_0559: Unknown result type (might be due to invalid IL or missing references)
		//IL_055f: Unknown result type (might be due to invalid IL or missing references)
		//IL_056a: Unknown result type (might be due to invalid IL or missing references)
		//IL_057b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0580: Unknown result type (might be due to invalid IL or missing references)
		//IL_058a: Expected O, but got Unknown
		//IL_058d: Expected O, but got Unknown
		//IL_05b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_06df: Unknown result type (might be due to invalid IL or missing references)
		//IL_0702: Unknown result type (might be due to invalid IL or missing references)
		//IL_0734: Unknown result type (might be due to invalid IL or missing references)
		//IL_0739: Unknown result type (might be due to invalid IL or missing references)
		//IL_074f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0754: Unknown result type (might be due to invalid IL or missing references)
		//IL_076a: Unknown result type (might be due to invalid IL or missing references)
		//IL_076f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0785: Unknown result type (might be due to invalid IL or missing references)
		//IL_078a: Unknown result type (might be due to invalid IL or missing references)
		//IL_07a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_07a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_07bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_07c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_07d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_07db: Unknown result type (might be due to invalid IL or missing references)
		//IL_07f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_07f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_080c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0811: Unknown result type (might be due to invalid IL or missing references)
		//IL_0828: Unknown result type (might be due to invalid IL or missing references)
		//IL_082d: Unknown result type (might be due to invalid IL or missing references)
		//IL_040d: Unknown result type (might be due to invalid IL or missing references)
		//IL_086a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0875: Unknown result type (might be due to invalid IL or missing references)
		//IL_0882: Unknown result type (might be due to invalid IL or missing references)
		//IL_088d: Unknown result type (might be due to invalid IL or missing references)
		//IL_089e: Unknown result type (might be due to invalid IL or missing references)
		//IL_08ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_0940: Unknown result type (might be due to invalid IL or missing references)
		//IL_0945: Unknown result type (might be due to invalid IL or missing references)
		//IL_094e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0956: Unknown result type (might be due to invalid IL or missing references)
		//IL_095c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0967: Unknown result type (might be due to invalid IL or missing references)
		//IL_0978: Unknown result type (might be due to invalid IL or missing references)
		//IL_097e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0989: Unknown result type (might be due to invalid IL or missing references)
		//IL_099a: Unknown result type (might be due to invalid IL or missing references)
		//IL_09a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_09ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_09bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_09c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_09cd: Expected O, but got Unknown
		//IL_09ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_09d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_09dd: Expected O, but got Unknown
		//IL_09e0: Expected O, but got Unknown
		//IL_0a09: Unknown result type (might be due to invalid IL or missing references)
		//IL_08bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a32: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a37: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a4c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a57: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a68: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a6e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a79: Unknown result type (might be due to invalid IL or missing references)
		//IL_0a93: Unknown result type (might be due to invalid IL or missing references)
		//IL_0aa5: Expected O, but got Unknown
		//IL_0ab7: 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_0656: Unknown result type (might be due to invalid IL or missing references)
		//IL_065b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0af0: Unknown result type (might be due to invalid IL or missing references)
		//IL_08d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_08d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_08de: Unknown result type (might be due to invalid IL or missing references)
		//IL_08f8: Unknown result type (might be due to invalid IL or missing references)
		GUI.DrawTexture(new Rect(0f, 0f, ((Rect)(ref windowRect)).width, ((Rect)(ref windowRect)).height), (Texture)(object)windowBackground);
		float num = 16f;
		float num2 = num;
		GUIStyle val = new GUIStyle(GUI.skin.label)
		{
			fontSize = 16,
			fontStyle = (FontStyle)1,
			alignment = (TextAnchor)4
		};
		val.normal.textColor = new Color(0.9f, 0.85f, 0.7f);
		GUIStyle val2 = val;
		GUI.Label(new Rect(num, num2, ((Rect)(ref windowRect)).width - num * 2f, 28f), "⚔ Rug Color Changer ⚔", val2);
		num2 += 34f;
		GUI.color = new Color(0.9f, 0.75f, 0.4f, 0.5f);
		GUI.DrawTexture(new Rect(num, num2, ((Rect)(ref windowRect)).width - num * 2f, 1f), (Texture)(object)previewTexture);
		GUI.color = Color.white;
		num2 += 8f;
		float num3 = 200f;
		float num4 = (((Rect)(ref windowRect)).width - num3 - 30f) / 2f;
		Rect val3 = default(Rect);
		((Rect)(ref val3))..ctor(num4, num2, num3, num3);
		GUI.DrawTexture(val3, (Texture)(object)colorWheelTexture);
		float num5 = num3 / 2f;
		float num6 = num5 - 2f;
		float num7 = hue * 2f * (float)Math.PI;
		float num8 = saturation * num6;
		float num9 = ((Rect)(ref val3)).x + num5 + Mathf.Cos(num7) * num8;
		float num10 = ((Rect)(ref val3)).y + num5 - Mathf.Sin(num7) * num8;
		GUI.color = ((brightness > 0.5f) ? Color.black : Color.white);
		GUI.DrawTexture(new Rect(num9 - 6f, num10 - 1f, 12f, 2f), (Texture)(object)previewTexture);
		GUI.DrawTexture(new Rect(num9 - 1f, num10 - 6f, 2f, 12f), (Texture)(object)previewTexture);
		GUI.color = Color.white;
		if ((int)Event.current.type == 0 || (int)Event.current.type == 3)
		{
			Vector2 mousePosition = Event.current.mousePosition;
			float num11 = mousePosition.x - (((Rect)(ref val3)).x + num5);
			float num12 = -1f * (mousePosition.y - (((Rect)(ref val3)).y + num5));
			float num13 = Mathf.Sqrt(num11 * num11 + num12 * num12);
			if (num13 <= num6)
			{
				hue = (Mathf.Atan2(num12, num11) / ((float)Math.PI * 2f) + 1f) % 1f;
				saturation = Mathf.Clamp01(num13 / num6);
				UpdateColorFromHSV();
				Event.current.Use();
			}
		}
		float num14 = 20f;
		float num15 = num3;
		Rect val4 = default(Rect);
		((Rect)(ref val4))..ctor(((Rect)(ref val3)).xMax + 10f, num2, num14, num15);
		for (int i = 0; i < (int)num15; i++)
		{
			float num16 = 1f - (float)i / num15;
			Color color = Color.HSVToRGB(hue, saturation, num16);
			GUI.color = color;
			GUI.DrawTexture(new Rect(((Rect)(ref val4)).x, ((Rect)(ref val4)).y + (float)i, num14, 1f), (Texture)(object)previewTexture);
		}
		GUI.color = Color.white;
		float num17 = ((Rect)(ref val4)).y + (1f - brightness) * num15;
		GUI.DrawTexture(new Rect(((Rect)(ref val4)).x - 2f, num17 - 1f, num14 + 4f, 3f), (Texture)(object)previewTexture);
		if ((int)Event.current.type == 0 || (int)Event.current.type == 3)
		{
			Vector2 mousePosition2 = Event.current.mousePosition;
			if (((Rect)(ref val4)).Contains(mousePosition2))
			{
				brightness = 1f - Mathf.Clamp01((mousePosition2.y - ((Rect)(ref val4)).y) / num15);
				UpdateColorFromHSV();
				Event.current.Use();
			}
		}
		num2 += num3 + 12f;
		GUIStyle val5 = new GUIStyle(GUI.skin.label)
		{
			fontSize = 12
		};
		val5.normal.textColor = new Color(0.75f, 0.75f, 0.78f);
		GUIStyle val6 = val5;
		float num18 = 44f;
		Rect val7 = default(Rect);
		((Rect)(ref val7))..ctor(num, num2, num18, num18);
		GUI.DrawTexture(val7, (Texture)(object)checkerTexture);
		GUI.color = selectedColor;
		GUI.DrawTexture(val7, (Texture)(object)previewTexture);
		GUI.color = Color.white;
		DrawBorder(val7, new Color(0.4f, 0.4f, 0.45f));
		float num19 = ((Rect)(ref val7)).xMax + 12f;
		GUI.Label(new Rect(num19, num2, 30f, 20f), "HEX", val6);
		GUIStyle val8 = new GUIStyle(GUI.skin.textField)
		{
			fontSize = 14,
			fontStyle = (FontStyle)1,
			alignment = (TextAnchor)3
		};
		val8.normal.textColor = Color.white;
		val8.normal.background = inputBackground;
		val8.focused.textColor = Color.white;
		val8.focused.background = inputBackground;
		val8.padding = new RectOffset(8, 8, 4, 4);
		GUIStyle val9 = val8;
		float num20 = ((Rect)(ref windowRect)).width - num19 - num - 30f;
		string text = GUI.TextField(new Rect(num19 + 28f, num2, num20, 24f), "#" + hexInput, val9);
		if (text != "#" + hexInput)
		{
			string text2 = text.Replace("#", "").Trim();
			if (text2.Length <= 6)
			{
				hexInput = text2.ToUpper();
				Color val10 = default(Color);
				if (text2.Length == 6 && ColorUtility.TryParseHtmlString("#" + text2, ref val10))
				{
					selectedColor = val10;
					Color.RGBToHSV(selectedColor, ref hue, ref saturation, ref brightness);
				}
			}
		}
		num2 += 28f;
		string text3 = $"R:{(int)(selectedColor.r * 255f)}  G:{(int)(selectedColor.g * 255f)}  B:{(int)(selectedColor.b * 255f)}";
		GUI.Label(new Rect(num19, num2, num20 + 30f, 20f), text3, val6);
		num2 += 26f;
		GUI.Label(new Rect(num, num2, 100f, 20f), "Presets", val6);
		num2 += 20f;
		Color[] array = (Color[])(object)new Color[10]
		{
			new Color(0.8f, 0.15f, 0.15f),
			new Color(0.9f, 0.45f, 0.1f),
			new Color(0.9f, 0.85f, 0.2f),
			new Color(0.2f, 0.7f, 0.2f),
			new Color(0.15f, 0.5f, 0.85f),
			new Color(0.55f, 0.2f, 0.8f),
			new Color(0.85f, 0.4f, 0.6f),
			new Color(0.95f, 0.95f, 0.9f),
			new Color(0.2f, 0.2f, 0.2f),
			new Color(0.6f, 0.35f, 0.15f)
		};
		float num21 = 26f;
		float num22 = 6f;
		float num23 = num;
		Rect val11 = default(Rect);
		for (int j = 0; j < array.Length; j++)
		{
			((Rect)(ref val11))..ctor(num23 + (float)j * (num21 + num22), num2, num21, num21);
			GUI.color = array[j];
			GUI.DrawTexture(val11, (Texture)(object)previewTexture);
			GUI.color = Color.white;
			DrawBorder(val11, new Color(0.5f, 0.5f, 0.55f));
			if ((int)Event.current.type == 0 && ((Rect)(ref val11)).Contains(Event.current.mousePosition))
			{
				selectedColor = array[j];
				Color.RGBToHSV(selectedColor, ref hue, ref saturation, ref brightness);
				hexInput = ColorUtility.ToHtmlStringRGB(selectedColor);
				Event.current.Use();
			}
		}
		num2 += num21 + 14f;
		GUIStyle val12 = new GUIStyle(GUI.skin.button)
		{
			fontSize = 13,
			fontStyle = (FontStyle)1
		};
		val12.normal.textColor = Color.white;
		val12.normal.background = buttonNormal;
		val12.hover.textColor = Color.white;
		val12.hover.background = buttonHover;
		val12.active.textColor = Color.white;
		val12.active.background = buttonHover;
		val12.padding = new RectOffset(12, 12, 8, 8);
		val12.border = new RectOffset(2, 2, 2, 2);
		GUIStyle val13 = val12;
		float num24 = (((Rect)(ref windowRect)).width - num * 2f - 8f) / 2f;
		if (GUI.Button(new Rect(num, num2, num24, 34f), "✓ Apply", val13))
		{
			ApplyColor();
			CloseColorPicker();
		}
		GUIStyle val14 = new GUIStyle(val13);
		val14.normal.textColor = new Color(0.8f, 0.6f, 0.6f);
		val14.normal.background = buttonNormal;
		val14.hover.textColor = Color.white;
		val14.hover.background = CreateSolidTexture(new Color(0.7f, 0.25f, 0.25f, 1f));
		GUIStyle val15 = val14;
		if (GUI.Button(new Rect(num + num24 + 8f, num2, num24, 34f), "✕ Cancel", val15))
		{
			CloseColorPicker();
		}
		GUI.DragWindow(new Rect(0f, 0f, ((Rect)(ref windowRect)).width, 40f));
	}

	private static void DrawBorder(Rect rect, Color color)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		GUI.color = color;
		GUI.DrawTexture(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, ((Rect)(ref rect)).width, 1f), (Texture)(object)previewTexture);
		GUI.DrawTexture(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).yMax - 1f, ((Rect)(ref rect)).width, 1f), (Texture)(object)previewTexture);
		GUI.DrawTexture(new Rect(((Rect)(ref rect)).x, ((Rect)(ref rect)).y, 1f, ((Rect)(ref rect)).height), (Texture)(object)previewTexture);
		GUI.DrawTexture(new Rect(((Rect)(ref rect)).xMax - 1f, ((Rect)(ref rect)).y, 1f, ((Rect)(ref rect)).height), (Texture)(object)previewTexture);
		GUI.color = Color.white;
	}

	private static void UpdateColorFromHSV()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		selectedColor = Color.HSVToRGB(hue, saturation, brightness);
		hexInput = ColorUtility.ToHtmlStringRGB(selectedColor);
	}
}