Decompiled source of DarkMode v1.0.1

BepInEx\plugins\BigWalk.DarkMode\BigWalk.DarkMode.dll

Decompiled a day 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.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("BigWalk.DarkMode")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("Big Walk Dark Mode")]
[assembly: AssemblyTitle("BigWalk.DarkMode")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
namespace BigWalk.DarkMode;

public class GraphicsDarkModeRow : MonoBehaviour
{
	public const string MarkerName = "BigWalk.DarkMode.SettingsRow";

	private static SettingsRow _row;

	private static bool _loggedMissingTemplate;

	private float _nextTry;

	private void Update()
	{
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Expected O, but got Unknown
		if (Time.unscaledTime < _nextTry)
		{
			return;
		}
		_nextTry = Time.unscaledTime + 0.5f;
		try
		{
			if ((Object)(object)_row != (Object)null)
			{
				try
				{
					if (!((Object)(object)((Component)_row).gameObject == (Object)null))
					{
						EnsureTitle(_row);
						return;
					}
					_row = null;
				}
				catch
				{
					_row = null;
				}
			}
			TryInject();
		}
		catch (Exception ex)
		{
			ManualLogSource log = Plugin.Log;
			bool flag = default(bool);
			BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(23, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("DarkMode settings row: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
			}
			log.LogDebug(val);
		}
	}

	private static void TryInject()
	{
		SettingsMenu val = FindSettingsMenu();
		if ((Object)(object)val == (Object)null || (Object)(object)val.catagoryGeneral == (Object)null)
		{
			return;
		}
		SettingsCatagory catagoryGeneral = val.catagoryGeneral;
		Il2CppReferenceArray<SettingsRow> rows = catagoryGeneral.rows;
		if (rows == null || ((Il2CppArrayBase<SettingsRow>)(object)rows).Length == 0)
		{
			return;
		}
		CleanupDuplicates(catagoryGeneral);
		rows = catagoryGeneral.rows;
		for (int i = 0; i < ((Il2CppArrayBase<SettingsRow>)(object)rows).Length; i++)
		{
			SettingsRow val2 = ((Il2CppArrayBase<SettingsRow>)(object)rows)[i];
			if ((Object)(object)val2 != (Object)null && (Object)(object)((Component)val2).gameObject != (Object)null && ((Object)((Component)val2).gameObject).name == "BigWalk.DarkMode.SettingsRow")
			{
				_row = val2;
				RefreshVisuals(val2);
				return;
			}
		}
		if (!TryFindBinaryTemplate(rows, out var template, out var templateIndex))
		{
			if (!_loggedMissingTemplate)
			{
				_loggedMissingTemplate = true;
				Plugin.Log.LogWarning((object)"DarkMode row: no binary On/Off General row to clone.");
			}
			return;
		}
		GameObject val3 = Object.Instantiate<GameObject>(((Component)template).gameObject, ((Component)template).transform.parent);
		((Object)val3).name = "BigWalk.DarkMode.SettingsRow";
		val3.transform.SetSiblingIndex(((Component)template).transform.GetSiblingIndex() + 1);
		SettingsRow component = val3.GetComponent<SettingsRow>();
		if ((Object)(object)component == (Object)null)
		{
			Object.Destroy((Object)(object)val3);
			return;
		}
		try
		{
			component.settingsType = (SettingsType)0;
		}
		catch
		{
		}
		try
		{
			component.hanger = null;
		}
		catch
		{
		}
		try
		{
			component.saveSelf = false;
		}
		catch
		{
		}
		try
		{
			if ((Object)(object)component.label2 != (Object)null)
			{
				((Component)component.label2).gameObject.SetActive(false);
			}
		}
		catch
		{
		}
		EnsureTitle(component);
		int num = Mathf.Clamp(templateIndex + 1, 0, ((Il2CppArrayBase<SettingsRow>)(object)rows).Length);
		Il2CppReferenceArray<SettingsRow> val4 = new Il2CppReferenceArray<SettingsRow>((long)(((Il2CppArrayBase<SettingsRow>)(object)rows).Length + 1));
		for (int j = 0; j < num; j++)
		{
			((Il2CppArrayBase<SettingsRow>)(object)val4)[j] = ((Il2CppArrayBase<SettingsRow>)(object)rows)[j];
		}
		((Il2CppArrayBase<SettingsRow>)(object)val4)[num] = component;
		for (int k = num; k < ((Il2CppArrayBase<SettingsRow>)(object)rows).Length; k++)
		{
			((Il2CppArrayBase<SettingsRow>)(object)val4)[k + 1] = ((Il2CppArrayBase<SettingsRow>)(object)rows)[k];
		}
		catagoryGeneral.rows = val4;
		RelinkNavigation(val4);
		_row = component;
		RefreshVisuals(component);
		Plugin.Log.LogInfo((object)"Added DARK MODE toggle to Settings → General.");
	}

	private static SettingsMenu FindSettingsMenu()
	{
		try
		{
			WorldMenuManager instance = WorldMenuManager.instance;
			if ((Object)(object)instance != (Object)null && (Object)(object)instance.settingsMenu != (Object)null)
			{
				return instance.settingsMenu;
			}
		}
		catch
		{
		}
		return Object.FindFirstObjectByType<SettingsMenu>();
	}

	private static void CleanupDuplicates(SettingsCatagory cat)
	{
		Il2CppReferenceArray<SettingsRow> rows = cat.rows;
		if (rows == null)
		{
			return;
		}
		SettingsRow val = null;
		int num = 0;
		for (int i = 0; i < ((Il2CppArrayBase<SettingsRow>)(object)rows).Length; i++)
		{
			SettingsRow val2 = ((Il2CppArrayBase<SettingsRow>)(object)rows)[i];
			if ((Object)(object)val2 == (Object)null || (Object)(object)((Component)val2).gameObject == (Object)null || (((Object)((Component)val2).gameObject).name != "BigWalk.DarkMode.SettingsRow" && ((Object)((Component)val2).gameObject).name != "BigWalk.DarkMode.GraphicsRow"))
			{
				continue;
			}
			if ((Object)(object)val == (Object)null)
			{
				val = val2;
				((Object)((Component)val2).gameObject).name = "BigWalk.DarkMode.SettingsRow";
				num++;
			}
			else
			{
				try
				{
					Object.Destroy((Object)(object)((Component)val2).gameObject);
				}
				catch
				{
				}
			}
		}
		if (num <= 1 && (Object)(object)val == (Object)null)
		{
			return;
		}
		List<SettingsRow> list = new List<SettingsRow>();
		for (int j = 0; j < ((Il2CppArrayBase<SettingsRow>)(object)rows).Length; j++)
		{
			SettingsRow val3 = ((Il2CppArrayBase<SettingsRow>)(object)rows)[j];
			if ((Object)(object)val3 == (Object)null || (Object)(object)((Component)val3).gameObject == (Object)null)
			{
				continue;
			}
			if (((Object)((Component)val3).gameObject).name == "BigWalk.DarkMode.SettingsRow" || ((Object)((Component)val3).gameObject).name == "BigWalk.DarkMode.GraphicsRow")
			{
				if ((Object)(object)val3 == (Object)(object)val)
				{
					list.Add(val3);
				}
			}
			else
			{
				list.Add(val3);
			}
		}
		if (list.Count != ((Il2CppArrayBase<SettingsRow>)(object)rows).Length || num > 1)
		{
			Il2CppReferenceArray<SettingsRow> val4 = new Il2CppReferenceArray<SettingsRow>((long)list.Count);
			for (int k = 0; k < list.Count; k++)
			{
				((Il2CppArrayBase<SettingsRow>)(object)val4)[k] = list[k];
			}
			cat.rows = val4;
			RelinkNavigation(val4);
		}
	}

	private static bool TryFindBinaryTemplate(Il2CppReferenceArray<SettingsRow> rows, out SettingsRow template, out int templateIndex)
	{
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Invalid comparison between Unknown and I4
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Invalid comparison between Unknown and I4
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Invalid comparison between Unknown and I4
		template = null;
		templateIndex = -1;
		SettingsType[] array = new SettingsType[3];
		RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
		SettingsType[] array2 = (SettingsType[])(object)array;
		for (int i = 0; i < array2.Length; i++)
		{
			for (int j = 0; j < ((Il2CppArrayBase<SettingsRow>)(object)rows).Length; j++)
			{
				SettingsRow val = ((Il2CppArrayBase<SettingsRow>)(object)rows)[j];
				if (!((Object)(object)val == (Object)null) && !((Object)(object)((Component)val).gameObject == (Object)null) && (int)val.settingsType == (int)array2[i] && IsBinaryOnOffRow(val))
				{
					template = val;
					templateIndex = j;
					return true;
				}
			}
		}
		for (int k = 0; k < ((Il2CppArrayBase<SettingsRow>)(object)rows).Length; k++)
		{
			SettingsRow val2 = ((Il2CppArrayBase<SettingsRow>)(object)rows)[k];
			if (!((Object)(object)val2 == (Object)null) && !((Object)(object)((Component)val2).gameObject == (Object)null) && (int)val2.settingsType != 13 && (int)val2.settingsType != 11 && IsBinaryOnOffRow(val2))
			{
				template = val2;
				templateIndex = k;
				return true;
			}
		}
		return false;
	}

	private static bool IsBinaryOnOffRow(SettingsRow r)
	{
		if ((Object)(object)r.label0 == (Object)null || (Object)(object)r.label1 == (Object)null)
		{
			return false;
		}
		if ((Object)(object)r.slider != (Object)null)
		{
			return false;
		}
		try
		{
			if ((Object)(object)r.label2 != (Object)null && (Object)(object)((Component)r.label2).gameObject != (Object)null && ((Component)r.label2).gameObject.activeSelf && (r.label2.text ?? "").Length > 0)
			{
				return false;
			}
		}
		catch
		{
		}
		if (!LabelsLookLikeOnOff(r.label0))
		{
			return LabelsLookLikeOnOff(r.label1);
		}
		return true;
	}

	private static bool LabelsLookLikeOnOff(TMP_Text label)
	{
		try
		{
			string text = (label.text ?? "").Trim();
			return text.Equals("On", StringComparison.OrdinalIgnoreCase) || text.Equals("Off", StringComparison.OrdinalIgnoreCase);
		}
		catch
		{
			return false;
		}
	}

	private static void EnsureTitle(SettingsRow row)
	{
		//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ae: Expected O, but got Unknown
		if ((Object)(object)row == (Object)null)
		{
			return;
		}
		try
		{
			SilenceTitleRemappers(row);
			if ((Object)(object)row.title != (Object)null)
			{
				try
				{
					row.title.displayType = (DisplayType)1;
					row.title.rawValue = "DARK MODE";
					row.title.Change("DARK MODE", (DisplayType)1);
					row.title.ChangeValue("DARK MODE");
				}
				catch
				{
				}
				try
				{
					if ((Object)(object)row.title.textElement != (Object)null)
					{
						row.title.textElement.text = "DARK MODE";
						row.title.textElement.ForceMeshUpdate(true, false);
					}
				}
				catch
				{
				}
				try
				{
					((Behaviour)row.title).enabled = false;
				}
				catch
				{
				}
			}
			try
			{
				if ((Object)(object)row.arrayLabel != (Object)null)
				{
					((Behaviour)row.arrayLabel).enabled = false;
					if ((Object)(object)row.arrayLabel.textElement != (Object)null)
					{
						row.arrayLabel.textElement.text = "DARK MODE";
						row.arrayLabel.textElement.ForceMeshUpdate(true, false);
					}
				}
			}
			catch
			{
			}
			Il2CppArrayBase<TMP_Text> componentsInChildren = ((Component)row).GetComponentsInChildren<TMP_Text>(true);
			if (componentsInChildren == null)
			{
				return;
			}
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				TMP_Text val = componentsInChildren[i];
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val == (Object)(object)row.label0) && !((Object)(object)val == (Object)(object)row.label1) && !((Object)(object)val == (Object)(object)row.label2) && !IsReservedOptionText(val.text ?? ""))
				{
					val.text = "DARK MODE";
					try
					{
						val.ForceMeshUpdate(true, false);
					}
					catch
					{
					}
				}
			}
		}
		catch (Exception ex)
		{
			ManualLogSource log = Plugin.Log;
			bool flag = default(bool);
			BepInExDebugLogInterpolatedStringHandler val2 = new BepInExDebugLogInterpolatedStringHandler(20, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("EnsureTitle failed: ");
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
			}
			log.LogDebug(val2);
		}
	}

	private static void SilenceTitleRemappers(SettingsRow row)
	{
		try
		{
			Il2CppArrayBase<FontMappedText> componentsInChildren = ((Component)row).GetComponentsInChildren<FontMappedText>(true);
			if (componentsInChildren != null)
			{
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					FontMappedText val = componentsInChildren[i];
					if (!((Object)(object)val == (Object)null) && !IsUnderOptionLabel(row, ((Component)val).transform))
					{
						((Behaviour)val).enabled = false;
					}
				}
			}
		}
		catch
		{
		}
		try
		{
			Il2CppArrayBase<LocalizedText> componentsInChildren2 = ((Component)row).GetComponentsInChildren<LocalizedText>(true);
			if (componentsInChildren2 == null)
			{
				return;
			}
			for (int j = 0; j < componentsInChildren2.Length; j++)
			{
				LocalizedText val2 = componentsInChildren2[j];
				if (!((Object)(object)val2 == (Object)null))
				{
					if ((Object)(object)val2 == (Object)(object)row.title || (Object)(object)val2 == (Object)(object)row.arrayLabel)
					{
						((Behaviour)val2).enabled = false;
					}
					else if (!IsUnderOptionLabel(row, ((Component)val2).transform))
					{
						((Behaviour)val2).enabled = false;
					}
				}
			}
		}
		catch
		{
		}
	}

	private static bool IsUnderOptionLabel(SettingsRow row, Transform t)
	{
		if ((Object)(object)t == (Object)null)
		{
			return false;
		}
		try
		{
			if ((Object)(object)row.label0 != (Object)null && ((Object)(object)t == (Object)(object)row.label0.transform || t.IsChildOf(row.label0.transform)))
			{
				return true;
			}
			if ((Object)(object)row.label1 != (Object)null && ((Object)(object)t == (Object)(object)row.label1.transform || t.IsChildOf(row.label1.transform)))
			{
				return true;
			}
			if ((Object)(object)row.label2 != (Object)null && ((Object)(object)t == (Object)(object)row.label2.transform || t.IsChildOf(row.label2.transform)))
			{
				return true;
			}
		}
		catch
		{
		}
		return false;
	}

	private static bool IsReservedOptionText(string text)
	{
		string text2 = (text ?? "").Trim();
		if (text2.Length == 0)
		{
			return true;
		}
		switch (text2)
		{
		case "/":
		case "·":
		case "•":
		case "|":
		case "-":
			return true;
		default:
			if (text2.Equals("On", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (text2.Equals("Off", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (text2.Equals("DARK MODE", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			return false;
		}
	}

	internal static bool IsOurs(SettingsRow row)
	{
		if ((Object)(object)row == (Object)null)
		{
			return false;
		}
		try
		{
			if ((Object)(object)((Component)row).gameObject == (Object)null)
			{
				return false;
			}
			string name = ((Object)((Component)row).gameObject).name;
			return name == "BigWalk.DarkMode.SettingsRow" || name == "BigWalk.DarkMode.GraphicsRow";
		}
		catch
		{
			return false;
		}
	}

	internal static bool IsOurTitle(LocalizedText loc)
	{
		if ((Object)(object)loc == (Object)null || (Object)(object)_row == (Object)null)
		{
			return false;
		}
		try
		{
			if ((Object)(object)_row.title != (Object)null && ((Object)loc).GetInstanceID() == ((Object)_row.title).GetInstanceID())
			{
				return true;
			}
			if ((Object)(object)_row.arrayLabel != (Object)null && ((Object)loc).GetInstanceID() == ((Object)_row.arrayLabel).GetInstanceID())
			{
				return true;
			}
			return false;
		}
		catch
		{
			return false;
		}
	}

	internal static void SetEnabled(bool on)
	{
		if (Plugin.EnableDarkUi != null)
		{
			Plugin.EnableDarkUi.Value = on;
		}
		UiDarkener.NotifyThemeChanged();
		if ((Object)(object)_row != (Object)null)
		{
			RefreshVisuals(_row);
		}
	}

	internal static void RefreshVisuals(SettingsRow row)
	{
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Expected O, but got Unknown
		if ((Object)(object)row == (Object)null)
		{
			return;
		}
		EnsureTitle(row);
		ApplyReadableColors(row);
		bool enabled = Plugin.Enabled;
		try
		{
			if ((Object)(object)row.label0 != (Object)null)
			{
				row.SetUnderlineSingle(row.label0, enabled);
			}
			if ((Object)(object)row.label1 != (Object)null)
			{
				row.SetUnderlineSingle(row.label1, !enabled);
			}
			if ((Object)(object)row.label2 != (Object)null)
			{
				row.SetUnderlineSingle(row.label2, false);
			}
		}
		catch (Exception ex)
		{
			ManualLogSource log = Plugin.Log;
			bool flag = default(bool);
			BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(33, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("RefreshVisuals underline failed: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
			}
			log.LogDebug(val);
		}
	}

	private static void ApplyReadableColors(SettingsRow row)
	{
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Expected O, but got Unknown
		//IL_0022: 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_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: 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_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		Color val = (Color)(Plugin.Enabled ? Theme.Ink : new Color(0.08f, 0.08f, 0.08f, 1f));
		try
		{
			Il2CppArrayBase<TMP_Text> componentsInChildren = ((Component)row).GetComponentsInChildren<TMP_Text>(true);
			if (componentsInChildren == null)
			{
				return;
			}
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				TMP_Text val2 = componentsInChildren[i];
				if (!((Object)(object)val2 == (Object)null))
				{
					((Graphic)val2).color = val;
					try
					{
						val2.faceColor = new Color32((byte)Mathf.Clamp(Mathf.RoundToInt(val.r * 255f), 0, 255), (byte)Mathf.Clamp(Mathf.RoundToInt(val.g * 255f), 0, 255), (byte)Mathf.Clamp(Mathf.RoundToInt(val.b * 255f), 0, 255), byte.MaxValue);
					}
					catch
					{
					}
				}
			}
		}
		catch (Exception ex)
		{
			ManualLogSource log = Plugin.Log;
			bool flag = default(bool);
			BepInExDebugLogInterpolatedStringHandler val3 = new BepInExDebugLogInterpolatedStringHandler(28, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("ApplyReadableColors failed: ");
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex.Message);
			}
			log.LogDebug(val3);
		}
	}

	private static void RelinkNavigation(Il2CppReferenceArray<SettingsRow> rows)
	{
		if (rows == null || ((Il2CppArrayBase<SettingsRow>)(object)rows).Length == 0)
		{
			return;
		}
		for (int i = 0; i < ((Il2CppArrayBase<SettingsRow>)(object)rows).Length; i++)
		{
			SettingsRow val = ((Il2CppArrayBase<SettingsRow>)(object)rows)[i];
			if (!((Object)(object)val == (Object)null))
			{
				SettingsRow val2 = ((i > 0) ? ((Il2CppArrayBase<SettingsRow>)(object)rows)[i - 1] : null);
				SettingsRow val3 = ((i + 1 < ((Il2CppArrayBase<SettingsRow>)(object)rows).Length) ? ((Il2CppArrayBase<SettingsRow>)(object)rows)[i + 1] : null);
				try
				{
					val.SetNavigation(val2, val3);
				}
				catch
				{
				}
			}
		}
	}
}
[HarmonyPatch(typeof(SettingsRow))]
internal static class SettingsRowDarkModePatches
{
	[HarmonyPrefix]
	[HarmonyPatch("ActionSelect0")]
	private static bool ActionSelect0(SettingsRow __instance)
	{
		if (!GraphicsDarkModeRow.IsOurs(__instance))
		{
			return true;
		}
		GraphicsDarkModeRow.SetEnabled(on: true);
		return false;
	}

	[HarmonyPrefix]
	[HarmonyPatch("ActionSelect1")]
	private static bool ActionSelect1(SettingsRow __instance)
	{
		if (!GraphicsDarkModeRow.IsOurs(__instance))
		{
			return true;
		}
		GraphicsDarkModeRow.SetEnabled(on: false);
		return false;
	}

	[HarmonyPrefix]
	[HarmonyPatch("ActionSelect2")]
	private static bool ActionSelect2(SettingsRow __instance)
	{
		if (!GraphicsDarkModeRow.IsOurs(__instance))
		{
			return true;
		}
		return false;
	}

	[HarmonyPrefix]
	[HarmonyPatch("ActionCycle")]
	private static bool ActionCycle(SettingsRow __instance, int delta)
	{
		if (!GraphicsDarkModeRow.IsOurs(__instance))
		{
			return true;
		}
		GraphicsDarkModeRow.SetEnabled(!Plugin.Enabled);
		return false;
	}

	[HarmonyPrefix]
	[HarmonyPatch("Refresh")]
	private static bool Refresh(SettingsRow __instance)
	{
		if (!GraphicsDarkModeRow.IsOurs(__instance))
		{
			return true;
		}
		GraphicsDarkModeRow.RefreshVisuals(__instance);
		return false;
	}

	[HarmonyPrefix]
	[HarmonyPatch("ActionNavigate")]
	private static bool ActionNavigate(SettingsRow __instance, int value)
	{
		if (!GraphicsDarkModeRow.IsOurs(__instance))
		{
			return true;
		}
		switch (value)
		{
		case 0:
			GraphicsDarkModeRow.SetEnabled(on: true);
			break;
		case 1:
			GraphicsDarkModeRow.SetEnabled(on: false);
			break;
		}
		return false;
	}
}
[HarmonyPatch(typeof(LocalizedText), "Refresh", new Type[] { })]
internal static class LocalizedTextRefreshPatch
{
	private static bool Prefix(LocalizedText __instance)
	{
		if (!GraphicsDarkModeRow.IsOurTitle(__instance))
		{
			return true;
		}
		try
		{
			__instance.displayType = (DisplayType)1;
			__instance.rawValue = "DARK MODE";
			if ((Object)(object)__instance.textElement != (Object)null)
			{
				__instance.textElement.text = "DARK MODE";
			}
		}
		catch
		{
		}
		return false;
	}
}
[BepInPlugin("BigWalk.DarkMode", "Big Walk Dark Mode", "1.0.1")]
[BepInProcess("Big Walk.exe")]
public class Plugin : BasePlugin
{
	public const string Guid = "BigWalk.DarkMode";

	internal static ManualLogSource Log;

	internal static ConfigEntry<bool> EnableDarkUi;

	internal static Harmony Harmony;

	public static bool Active { get; private set; }

	public static bool Enabled
	{
		get
		{
			if (EnableDarkUi != null)
			{
				return EnableDarkUi.Value;
			}
			return true;
		}
	}

	public override void Load()
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Expected O, but got Unknown
		Log = ((BasePlugin)this).Log;
		Active = true;
		EnableDarkUi = ((BasePlugin)this).Config.Bind<bool>("General", "EnableDarkUi", true, "Recolor Big Walk's menus and HUD chrome to a dark paper theme. Also toggled from Settings → General → Dark Mode.");
		Harmony = new Harmony("BigWalk.DarkMode");
		Harmony.PatchAll(typeof(Plugin).Assembly);
		((BasePlugin)this).AddComponent<UiDarkener>();
		((BasePlugin)this).AddComponent<GraphicsDarkModeRow>();
		Log.LogInfo((object)"Big Walk Dark Mode v1.0.1 loaded — Settings → General → Dark Mode, or config EnableDarkUi.");
	}
}
public static class Theme
{
	public static readonly Color Paper = new Color(0.14f, 0.14f, 0.15f, 0.97f);

	public static readonly Color PaperEdge = new Color(0.22f, 0.21f, 0.2f, 1f);

	public static readonly Color Ink = new Color(0.93f, 0.91f, 0.87f, 1f);

	public static readonly Color InkMuted = new Color(0.7f, 0.68f, 0.64f, 1f);

	public static readonly Color InkFaint = new Color(0.5f, 0.48f, 0.44f, 1f);

	public static readonly Color Accent = new Color(0.88f, 0.86f, 0.82f, 1f);

	public static readonly Color Panel = new Color(0.18f, 0.17f, 0.16f, 0.96f);

	public static readonly Color Shadow = new Color(0f, 0f, 0f, 0.45f);

	public static bool Active
	{
		get
		{
			if (Plugin.Active)
			{
				return Plugin.Enabled;
			}
			return false;
		}
	}
}
public class UiDarkener : MonoBehaviour
{
	private const float ScanInterval = 0.25f;

	private static UiDarkener _instance;

	private readonly Dictionary<int, Color> _originalColors = new Dictionary<int, Color>();

	private readonly Dictionary<int, Color32> _originalFaceColors = new Dictionary<int, Color32>();

	private readonly List<Graphic> _touchedGraphics = new List<Graphic>();

	private readonly List<Camera> _touchedCameras = new List<Camera>();

	private float _nextScan;

	private string _lastScene;

	private bool _wasEnabled = true;

	private void Awake()
	{
		_instance = this;
		_wasEnabled = Plugin.Enabled;
	}

	public static void NotifyThemeChanged()
	{
		if (!((Object)(object)_instance == (Object)null))
		{
			_instance._nextScan = 0f;
			if (!Plugin.Enabled)
			{
				_instance.RestoreAll();
			}
		}
	}

	private void Update()
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		bool enabled = Plugin.Enabled;
		if (_wasEnabled && !enabled)
		{
			RestoreAll();
		}
		_wasEnabled = enabled;
		if (!enabled)
		{
			return;
		}
		try
		{
			Scene activeScene = SceneManager.GetActiveScene();
			string text = ((Scene)(ref activeScene)).name ?? "";
			if (!string.Equals(text, _lastScene, StringComparison.Ordinal))
			{
				if (_touchedGraphics.Count > 0 || _touchedCameras.Count > 0 || _originalColors.Count > 0)
				{
					RestoreAll();
				}
				_lastScene = text;
				_nextScan = 0f;
			}
		}
		catch
		{
		}
		if (!(Time.unscaledTime < _nextScan))
		{
			_nextScan = Time.unscaledTime + 0.25f;
			ScanAndApply();
		}
	}

	private void RestoreAll()
	{
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Expected O, but got Unknown
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			for (int i = 0; i < _touchedGraphics.Count; i++)
			{
				Graphic val = _touchedGraphics[i];
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				int instanceID = ((Object)val).GetInstanceID();
				if (_originalColors.TryGetValue(instanceID, out var value))
				{
					val.color = value;
				}
				TMP_Text val2 = (TMP_Text)(object)((val is TMP_Text) ? val : null);
				if (val2 != null && _originalFaceColors.TryGetValue(instanceID, out var value2))
				{
					try
					{
						val2.faceColor = value2;
					}
					catch
					{
					}
				}
			}
			for (int j = 0; j < _touchedCameras.Count; j++)
			{
				Camera val3 = _touchedCameras[j];
				if (!((Object)(object)val3 == (Object)null) && _originalColors.TryGetValue(((Object)val3).GetInstanceID(), out var value3))
				{
					val3.backgroundColor = value3;
				}
			}
		}
		catch (Exception ex)
		{
			ManualLogSource log = Plugin.Log;
			bool flag = default(bool);
			BepInExDebugLogInterpolatedStringHandler val4 = new BepInExDebugLogInterpolatedStringHandler(27, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("UiDarkener restore failed: ");
				((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(ex.Message);
			}
			log.LogDebug(val4);
		}
		_touchedGraphics.Clear();
		_touchedCameras.Clear();
		_originalColors.Clear();
		_originalFaceColors.Clear();
		_nextScan = 0f;
	}

	private void RememberGraphic(Graphic g, Color original)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		int instanceID = ((Object)g).GetInstanceID();
		if (!_originalColors.ContainsKey(instanceID))
		{
			_originalColors[instanceID] = original;
			_touchedGraphics.Add(g);
		}
	}

	private void RememberCamera(Camera cam, Color original)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		int instanceID = ((Object)cam).GetInstanceID();
		if (!_originalColors.ContainsKey(instanceID))
		{
			_originalColors[instanceID] = original;
			_touchedCameras.Add(cam);
		}
	}

	private void ScanAndApply()
	{
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Expected O, but got Unknown
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Invalid comparison between Unknown and I4
		try
		{
			DarkenSolidCameras();
			Il2CppArrayBase<Canvas> val = Object.FindObjectsByType<Canvas>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			if (val == null)
			{
				return;
			}
			for (int i = 0; i < val.Length; i++)
			{
				Canvas val2 = val[i];
				if (!((Object)(object)val2 == (Object)null) && (int)val2.renderMode != 2 && !ShouldSkipRoot(((Component)val2).transform))
				{
					ApplyUnder(((Component)val2).transform);
				}
			}
		}
		catch (Exception ex)
		{
			ManualLogSource log = Plugin.Log;
			bool flag = default(bool);
			BepInExDebugLogInterpolatedStringHandler val3 = new BepInExDebugLogInterpolatedStringHandler(24, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("UiDarkener scan failed: ");
				((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex.Message);
			}
			log.LogDebug(val3);
		}
	}

	private void DarkenSolidCameras()
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Invalid comparison between Unknown and I4
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: 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_0054: 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_0077: 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_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			Il2CppArrayBase<Camera> val = Object.FindObjectsByType<Camera>((FindObjectsInactive)0, (FindObjectsSortMode)0);
			if (val == null)
			{
				return;
			}
			for (int i = 0; i < val.Length; i++)
			{
				Camera val2 = val[i];
				if ((Object)(object)val2 == (Object)null || (int)val2.clearFlags != 2)
				{
					continue;
				}
				Color value = val2.backgroundColor;
				if (!(Luma(value) < 0.55f) && !(Saturation(value) > 0.25f))
				{
					RememberCamera(val2, value);
					if (!_originalColors.TryGetValue(((Object)val2).GetInstanceID(), out value))
					{
						value = val2.backgroundColor;
					}
					Color val3 = DarkenPaper(value);
					if (!ColorsClose(val2.backgroundColor, val3))
					{
						val2.backgroundColor = val3;
					}
				}
			}
		}
		catch
		{
		}
	}

	private static bool ShouldSkipRoot(Transform root)
	{
		if ((Object)(object)root == (Object)null)
		{
			return true;
		}
		string text = ((Object)root).name ?? "";
		if (text.StartsWith("BigWalk.", StringComparison.OrdinalIgnoreCase))
		{
			return true;
		}
		if (text.IndexOf("Nameplate", StringComparison.OrdinalIgnoreCase) >= 0)
		{
			return true;
		}
		if (text.IndexOf("Fade", StringComparison.OrdinalIgnoreCase) >= 0)
		{
			return true;
		}
		if (text.IndexOf("Crosshair", StringComparison.OrdinalIgnoreCase) >= 0)
		{
			return true;
		}
		if (text == "BigWalk.DarkMode.SettingsRow" || text == "BigWalk.DarkMode.GraphicsRow")
		{
			return true;
		}
		return false;
	}

	private void ApplyUnder(Transform root)
	{
		Il2CppArrayBase<TMP_Text> componentsInChildren = ((Component)root).GetComponentsInChildren<TMP_Text>(true);
		if (componentsInChildren != null)
		{
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				TMP_Text val = componentsInChildren[i];
				if (!((Object)(object)val == (Object)null) && !IsUnderDarkModeRow(val.transform))
				{
					ApplyTextGraphic((Graphic)(object)val);
				}
			}
		}
		Il2CppArrayBase<Text> componentsInChildren2 = ((Component)root).GetComponentsInChildren<Text>(true);
		if (componentsInChildren2 != null)
		{
			for (int j = 0; j < componentsInChildren2.Length; j++)
			{
				Text val2 = componentsInChildren2[j];
				if (!((Object)(object)val2 == (Object)null) && !IsUnderDarkModeRow(((Component)val2).transform))
				{
					ApplyTextGraphic((Graphic)(object)val2);
				}
			}
		}
		Il2CppArrayBase<Image> componentsInChildren3 = ((Component)root).GetComponentsInChildren<Image>(true);
		if (componentsInChildren3 != null)
		{
			for (int k = 0; k < componentsInChildren3.Length; k++)
			{
				Image val3 = componentsInChildren3[k];
				if (!((Object)(object)val3 == (Object)null) && !IsUnderDarkModeRow(((Component)val3).transform))
				{
					ApplyPanelImage(val3);
				}
			}
		}
		Il2CppArrayBase<RawImage> componentsInChildren4 = ((Component)root).GetComponentsInChildren<RawImage>(true);
		if (componentsInChildren4 == null)
		{
			return;
		}
		for (int l = 0; l < componentsInChildren4.Length; l++)
		{
			RawImage val4 = componentsInChildren4[l];
			if (!((Object)(object)val4 == (Object)null) && !IsUnderDarkModeRow(((Component)val4).transform))
			{
				ApplyPanelRawImage(val4);
			}
		}
	}

	private static bool IsUnderDarkModeRow(Transform t)
	{
		if ((Object)(object)t == (Object)null)
		{
			return false;
		}
		try
		{
			Transform val = t;
			while ((Object)(object)val != (Object)null)
			{
				string text = ((Object)val).name ?? "";
				if (text == "BigWalk.DarkMode.SettingsRow" || text == "BigWalk.DarkMode.GraphicsRow")
				{
					return true;
				}
				val = val.parent;
			}
		}
		catch
		{
		}
		return false;
	}

	private void ApplyTextGraphic(Graphic g)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: 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_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: 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_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_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: 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_00fd: 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_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: 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_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		if (g.color.a < 0.2f)
		{
			return;
		}
		int instanceID = ((Object)g).GetInstanceID();
		Color color = g.color;
		if (!_originalColors.TryGetValue(instanceID, out var value))
		{
			value = color;
		}
		Color val = TransformText(value);
		if (ColorsClose(value, val))
		{
			return;
		}
		RememberGraphic(g, value);
		if (!ColorsClose(g.color, val))
		{
			g.color = val;
		}
		TMP_Text val2 = (TMP_Text)(object)((g is TMP_Text) ? g : null);
		if (val2 == null)
		{
			return;
		}
		try
		{
			if (!_originalFaceColors.ContainsKey(instanceID))
			{
				_originalFaceColors[instanceID] = val2.faceColor;
			}
			Color32 val3 = _originalFaceColors[instanceID];
			Color c = default(Color);
			((Color)(ref c))..ctor((float)(int)val3.r / 255f, (float)(int)val3.g / 255f, (float)(int)val3.b / 255f, (float)(int)val3.a / 255f);
			if (Luma(c) < 0.55f && Saturation(c) < 0.35f)
			{
				Color val4 = TransformText(c);
				val2.faceColor = new Color32((byte)Mathf.Clamp(Mathf.RoundToInt(val4.r * 255f), 0, 255), (byte)Mathf.Clamp(Mathf.RoundToInt(val4.g * 255f), 0, 255), (byte)Mathf.Clamp(Mathf.RoundToInt(val4.b * 255f), 0, 255), val3.a);
			}
		}
		catch
		{
		}
	}

	private void ApplyPanelImage(Image img)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: 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_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		Color color = ((Graphic)img).color;
		if (!(color.a < 0.9f) && IsLightPanel(img))
		{
			int instanceID = ((Object)img).GetInstanceID();
			if (!_originalColors.TryGetValue(instanceID, out var value))
			{
				value = color;
			}
			RememberGraphic((Graphic)(object)img, value);
			Color val = DarkenPaper(value);
			if (!ColorsClose(((Graphic)img).color, val))
			{
				((Graphic)img).color = val;
			}
		}
	}

	private void ApplyPanelRawImage(RawImage img)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: 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_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//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_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: 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)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		Color color = ((Graphic)img).color;
		if (color.a < 0.9f)
		{
			return;
		}
		float num = Luma(color);
		float num2 = Saturation(color);
		if (num < 0.55f || num2 > 0.25f)
		{
			return;
		}
		try
		{
			RectTransform rectTransform = ((Graphic)img).rectTransform;
			if ((Object)(object)rectTransform == (Object)null)
			{
				return;
			}
			Rect rect = rectTransform.rect;
			if (Mathf.Abs(((Rect)(ref rect)).width) < 120f || Mathf.Abs(((Rect)(ref rect)).height) < 80f)
			{
				return;
			}
		}
		catch
		{
			return;
		}
		int instanceID = ((Object)img).GetInstanceID();
		if (!_originalColors.TryGetValue(instanceID, out var value))
		{
			value = color;
		}
		RememberGraphic((Graphic)(object)img, value);
		Color val = DarkenPaper(value);
		if (!ColorsClose(((Graphic)img).color, val))
		{
			((Graphic)img).color = val;
		}
	}

	private static bool IsLightPanel(Image img)
	{
		//IL_0056: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		string name = null;
		string name2 = null;
		try
		{
			name = (((Object)(object)img.sprite != (Object)null) ? ((Object)img.sprite).name : null);
			name2 = (((Object)(object)((Component)img).gameObject != (Object)null) ? ((Object)((Component)img).gameObject).name : null);
		}
		catch
		{
		}
		bool flag = NameLooksLikePaper(name) || NameLooksLikePaper(name2);
		float num = Luma(((Graphic)img).color);
		float num2 = Saturation(((Graphic)img).color);
		if (!flag && (num < 0.55f || num2 > 0.25f))
		{
			return false;
		}
		if (flag)
		{
			return true;
		}
		try
		{
			RectTransform rectTransform = ((Graphic)img).rectTransform;
			if ((Object)(object)rectTransform == (Object)null)
			{
				return false;
			}
			Rect rect = rectTransform.rect;
			float num3 = Mathf.Abs(((Rect)(ref rect)).width);
			float num4 = Mathf.Abs(((Rect)(ref rect)).height);
			if (num3 < 140f || num4 < 70f)
			{
				return false;
			}
			return true;
		}
		catch
		{
			return false;
		}
	}

	private static Color TransformText(Color c)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: 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_001e: 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_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		float num = Luma(c);
		if (Saturation(c) > 0.28f)
		{
			return c;
		}
		if (num < 0.6f)
		{
			Color ink = Theme.Ink;
			return new Color(ink.r, ink.g, ink.b, c.a);
		}
		return c;
	}

	private static Color DarkenPaper(Color c)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: 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: Unknown result type (might be due to invalid IL or missing references)
		Color val = Color.Lerp(c, Theme.Paper, 0.92f);
		return new Color(val.r, val.g, val.b, c.a);
	}

	private static bool NameLooksLikePaper(string name)
	{
		if (string.IsNullOrEmpty(name))
		{
			return false;
		}
		if (name.IndexOf("paper", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("parchment", StringComparison.OrdinalIgnoreCase) < 0)
		{
			return name.IndexOf("paper_modal", StringComparison.OrdinalIgnoreCase) >= 0;
		}
		return true;
	}

	private static float Luma(Color c)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		return 0.2126f * c.r + 0.7152f * c.g + 0.0722f * c.b;
	}

	private static float Saturation(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)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Max(c.r, Mathf.Max(c.g, c.b));
		float num2 = Mathf.Min(c.r, Mathf.Min(c.g, c.b));
		if (num <= 0.001f)
		{
			return 0f;
		}
		return (num - num2) / num;
	}

	private static bool ColorsClose(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.01f && Mathf.Abs(a.g - b.g) < 0.01f && Mathf.Abs(a.b - b.b) < 0.01f)
		{
			return Mathf.Abs(a.a - b.a) < 0.01f;
		}
		return false;
	}
}
public static class MyPluginInfo
{
	public const string PLUGIN_GUID = "BigWalk.DarkMode";

	public const string PLUGIN_NAME = "Big Walk Dark Mode";

	public const string PLUGIN_VERSION = "1.0.1";
}