Decompiled source of UltraRGBLighting v2.0.3

OpenRGBnetstandard21.dll

Decompiled 3 weeks ago
#define DEBUG
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using OpenRGB.NET.Utils;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Diogo Trindade")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyCopyright("Copyright © 2020 Diogo Trindade")]
[assembly: AssemblyDescription("Client for the OpenRGB SDK")]
[assembly: AssemblyFileVersion("3.1.1.0")]
[assembly: AssemblyInformationalVersion("3.1.1")]
[assembly: AssemblyProduct("OpenRGBnetstandard21")]
[assembly: AssemblyTitle("OpenRGBnetstandard21")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/diogotr7/OpenRGB.NET")]
[assembly: InternalsVisibleTo("OpenRGBnetstandard21.Tests")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("3.1.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class IsUnmanagedAttribute : Attribute
	{
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
public class UnsafeReplacement
{
	public static int SizeOf<T>()
	{
		return Unsafe.SizeOf<T>();
	}
}
namespace System.Runtime.CompilerServices
{
	[EditorBrowsable(EditorBrowsableState.Never)]
	internal static class IsExternalInit
	{
	}
}
namespace OpenRGB.NET
{
	public enum ColorMode : uint
	{
		None,
		PerLed,
		ModeSpecific,
		Random
	}
	public enum CommandId : uint
	{
		RequestControllerCount = 0u,
		RequestControllerData = 1u,
		RequestProtocolVersion = 40u,
		SetClientName = 50u,
		DeviceListUpdated = 100u,
		RequestProfiles = 150u,
		SaveProfile = 151u,
		LoadProfile = 152u,
		DeleteProfile = 153u,
		RequestPlugins = 200u,
		PluginSpecific = 201u,
		ResizeZone = 1000u,
		UpdateLeds = 1050u,
		UpdateZoneLeds = 1051u,
		UpdateSingleLed = 1052u,
		SetCustomMode = 1100u,
		UpdateMode = 1101u,
		SaveMode = 1102u
	}
	public enum DeviceType : uint
	{
		Motherboard,
		Dram,
		Gpu,
		Cooler,
		Ledstrip,
		Keyboard,
		Mouse,
		Mousemat,
		Headset,
		HeadsetStand,
		Gamepad,
		Light,
		Speaker,
		Virtual,
		Unknown
	}
	public enum Direction : uint
	{
		None = uint.MaxValue,
		Left = 0u,
		Right = 1u,
		Up = 2u,
		Down = 3u,
		Horizontal = 4u,
		Vertical = 5u
	}
	[Flags]
	public enum ModeFlags : uint
	{
		None = 0u,
		HasSpeed = 1u,
		HasDirectionLR = 2u,
		HasDirectionUD = 4u,
		HasDirectionHV = 8u,
		HasBrightness = 0x10u,
		HasPerLedColor = 0x20u,
		HasModeSpecificColor = 0x40u,
		HasRandomColor = 0x80u
	}
	public enum ZoneType : uint
	{
		Single,
		Linear,
		Matrix
	}
	public interface IOpenRgbClient
	{
		bool Connected { get; }

		ProtocolVersion MaxSupportedProtocolVersion { get; }

		ProtocolVersion ClientProtocolVersion { get; }

		ProtocolVersion CommonProtocolVersion { get; }

		event EventHandler<EventArgs>? DeviceListUpdated;

		void Connect();

		int GetControllerCount();

		Device GetControllerData(int deviceId);

		Device[] GetAllControllerData();

		string[] GetProfiles();

		void LoadProfile(string profile);

		void DeleteProfile(string profile);

		void SaveProfile(string profile);

		Plugin[] GetPlugins();

		void ResizeZone(int deviceId, int zoneId, int size);

		void UpdateLeds(int deviceId, ReadOnlySpan<Color> colors);

		void UpdateZoneLeds(int deviceId, int zoneId, ReadOnlySpan<Color> colors);

		void UpdateSingleLed(int deviceId, int ledId, Color color);

		void SetCustomMode(int deviceId);

		void UpdateMode(int deviceId, int modeId, uint? speed = null, Direction? direction = null, Color[]? colors = null);

		void SaveMode(int deviceId, int modeId);

		void PluginSpecific(int pluginId, int pluginPacketType, ReadOnlySpan<byte> data);
	}
	internal interface ISpanReader<out T>
	{
	}
	internal interface ISpanWritable
	{
		int Length { get; }

		void WriteTo(ref SpanWriter writer);
	}
	[StructLayout(LayoutKind.Sequential, Pack = 1)]
	public readonly record struct Color(byte R = 0, byte G = 0, byte B = 0)
	{
		private readonly byte UnusedAlpha = 0;

		[CompilerGenerated]
		private bool PrintMembers(StringBuilder builder)
		{
			builder.Append("R = ");
			builder.Append(R.ToString());
			builder.Append(", G = ");
			builder.Append(G.ToString());
			builder.Append(", B = ");
			builder.Append(B.ToString());
			return true;
		}
	}
	public class Device
	{
		public int Index { get; }

		public DeviceType Type { get; }

		public string Name { get; }

		public string? Vendor { get; }

		public string Description { get; }

		public string Version { get; }

		public string Serial { get; }

		public string Location { get; }

		public int ActiveModeIndex { get; }

		public Mode[] Modes { get; }

		public Zone[] Zones { get; }

		public Led[] Leds { get; }

		public Color[] Colors { get; }

		public Mode ActiveMode => Modes[ActiveModeIndex];

		internal Device(int index, DeviceType type, string name, string? vendor, string description, string version, string serial, string location, int activeModeIndex, Mode[] modes, Zone[] zones, Led[] leds, Color[] colors)
		{
			Index = index;
			Type = type;
			Name = name;
			Vendor = vendor;
			Description = description;
			Version = version;
			Serial = serial;
			Location = location;
			ActiveModeIndex = activeModeIndex;
			Modes = modes;
			Zones = zones;
			Leds = leds;
			Colors = colors;
		}

		public override string ToString()
		{
			return $"{Type}: {Name}";
		}
	}
	public class Led
	{
		public int Index { get; }

		public string Name { get; }

		public uint Value { get; }

		internal Led(int index, string name, uint value)
		{
			Index = index;
			Name = name;
			Value = value;
		}

		public override string ToString()
		{
			return $"Name: {Name}, Value: {Value}";
		}
	}
	public class MatrixMap
	{
		public uint Height { get; }

		public uint Width { get; }

		public uint[,] Matrix { get; }

		internal MatrixMap(uint height, uint width, uint[,] matrix)
		{
			Height = height;
			Width = width;
			Matrix = matrix;
		}
	}
	public class Mode
	{
		public ProtocolVersion ProtocolVersion { get; }

		public int Index { get; }

		public string Name { get; }

		public int Value { get; }

		public ModeFlags Flags { get; }

		public uint SpeedMin { get; }

		public uint SpeedMax { get; }

		public uint BrightnessMin { get; }

		public uint BrightnessMax { get; }

		public uint ColorMin { get; }

		public uint ColorMax { get; }

		public uint Speed { get; private set; }

		public uint Brightness { get; private set; }

		public Direction Direction { get; private set; }

		public ColorMode ColorMode { get; }

		public Color[] Colors { get; private set; }

		public bool SupportsSpeed => Flags.HasFlag(ModeFlags.HasSpeed);

		public bool SupportsBrightness => Flags.HasFlag(ModeFlags.HasBrightness);

		public bool SupportsDirection => Flags.HasFlag(ModeFlags.HasDirectionHV) || Flags.HasFlag(ModeFlags.HasDirectionUD) || Flags.HasFlag(ModeFlags.HasDirectionLR);

		internal Mode(ProtocolVersion protocolVersion, int index, string name, int value, ModeFlags flags, uint speedMin, uint speedMax, uint brightnessMin, uint brightnessMax, uint colorMin, uint colorMax, uint speed, uint brightness, Direction direction, ColorMode colorMode, Color[] colors)
		{
			ProtocolVersion = protocolVersion;
			Index = index;
			Name = name;
			Value = value;
			Flags = flags;
			SpeedMin = (SupportsSpeed ? speedMin : 0u);
			SpeedMax = (SupportsSpeed ? speedMax : 0u);
			BrightnessMin = (SupportsBrightness ? brightnessMin : 0u);
			BrightnessMax = (SupportsBrightness ? brightnessMax : 0u);
			ColorMin = (Flags.HasFlag(ModeFlags.HasModeSpecificColor) ? colorMin : 0u);
			ColorMax = (Flags.HasFlag(ModeFlags.HasModeSpecificColor) ? colorMax : 0u);
			Speed = speed;
			Brightness = brightness;
			Direction = (SupportsDirection ? direction : Direction.None);
			ColorMode = colorMode;
			Colors = colors;
		}

		public void SetSpeed(uint newSpeed)
		{
			if (!SupportsSpeed)
			{
				throw new InvalidOperationException("This mode does not support speed.");
			}
			Speed = newSpeed;
		}

		public void SetBrightness(uint newBrightness)
		{
			if (!SupportsBrightness)
			{
				throw new InvalidOperationException("This mode does not support brightness.");
			}
			Brightness = newBrightness;
		}

		public void SetDirection(Direction newDirection)
		{
			if (!SupportsDirection)
			{
				throw new InvalidOperationException("This mode does not support direction.");
			}
			Direction = newDirection;
		}

		public void SetColors(Color[] newColors)
		{
			Colors = newColors;
		}
	}
	public class Plugin
	{
		public string Name { get; }

		public string Description { get; }

		public string Version { get; }

		public uint Index { get; }

		public int SdkVersion { get; }

		internal Plugin(string name, string description, string version, uint index, int sdkVersion)
		{
			Name = name;
			Description = description;
			Version = version;
			Index = index;
			SdkVersion = sdkVersion;
		}
	}
	public readonly struct ProtocolVersion
	{
		public static readonly ProtocolVersion Invalid = new ProtocolVersion(0u, supportsVendorString: false, supportsProfileControls: false, supportsBrightnessAndSaveMode: false, supportsSegmentsAndPlugins: false);

		public static readonly ProtocolVersion V0 = new ProtocolVersion(0u, supportsVendorString: false, supportsProfileControls: false, supportsBrightnessAndSaveMode: false, supportsSegmentsAndPlugins: false);

		public static readonly ProtocolVersion V1 = new ProtocolVersion(1u, supportsVendorString: true, supportsProfileControls: false, supportsBrightnessAndSaveMode: false, supportsSegmentsAndPlugins: false);

		public static readonly ProtocolVersion V2 = new ProtocolVersion(2u, supportsVendorString: true, supportsProfileControls: true, supportsBrightnessAndSaveMode: false, supportsSegmentsAndPlugins: false);

		public static readonly ProtocolVersion V3 = new ProtocolVersion(3u, supportsVendorString: true, supportsProfileControls: true, supportsBrightnessAndSaveMode: true, supportsSegmentsAndPlugins: false);

		public static readonly ProtocolVersion V4 = new ProtocolVersion(4u, supportsVendorString: true, supportsProfileControls: true, supportsBrightnessAndSaveMode: true, supportsSegmentsAndPlugins: true);

		public uint Number { get; }

		public bool SupportsVendorString { get; }

		public bool SupportsProfileControls { get; }

		public bool SupportsBrightnessAndSaveMode { get; }

		public bool SupportsSegmentsAndPlugins { get; }

		private ProtocolVersion(uint number, bool supportsVendorString, bool supportsProfileControls, bool supportsBrightnessAndSaveMode, bool supportsSegmentsAndPlugins)
		{
			Number = number;
			SupportsVendorString = supportsVendorString;
			SupportsProfileControls = supportsProfileControls;
			SupportsBrightnessAndSaveMode = supportsBrightnessAndSaveMode;
			SupportsSegmentsAndPlugins = supportsSegmentsAndPlugins;
		}

		public static ProtocolVersion FromNumber(uint number)
		{
			if (1 == 0)
			{
			}
			ProtocolVersion result = number switch
			{
				0u => V0, 
				1u => V1, 
				2u => V2, 
				3u => V3, 
				4u => V4, 
				_ => throw new ArgumentOutOfRangeException("number", number, "Unknown protocol version"), 
			};
			if (1 == 0)
			{
			}
			return result;
		}
	}
	public class Segment
	{
		public int Index { get; }

		public string Name { get; }

		public ZoneType Type { get; }

		public uint Start { get; }

		public uint LedCount { get; }

		internal Segment(int index, string name, ZoneType type, uint start, uint ledCount)
		{
			Index = index;
			Name = name;
			Type = type;
			Start = start;
			LedCount = ledCount;
		}
	}
	public class Zone
	{
		public int Index { get; }

		public int DeviceIndex { get; }

		public string Name { get; }

		public ZoneType Type { get; }

		public uint LedCount { get; }

		public uint LedsMin { get; }

		public uint LedsMax { get; }

		public MatrixMap? MatrixMap { get; }

		public Segment[] Segments { get; }

		internal Zone(int index, int deviceIndex, string name, ZoneType type, uint ledCount, uint ledsMin, uint ledsMax, MatrixMap? matrixMap, Segment[] segments)
		{
			Index = index;
			DeviceIndex = deviceIndex;
			Name = name;
			Type = type;
			LedCount = ledCount;
			LedsMin = ledsMin;
			LedsMax = ledsMax;
			MatrixMap = matrixMap;
			Segments = segments;
		}
	}
	public sealed class OpenRgbClient : IDisposable, IOpenRgbClient
	{
		private const int MaxProtocolNumber = 4;

		private readonly string _name;

		private readonly string _ip;

		private readonly int _port;

		private readonly int _timeoutMs;

		private readonly uint _protocolVersionNumber;

		private readonly OpenRgbConnection _connection;

		public bool Connected => _connection.Connected;

		public ProtocolVersion MaxSupportedProtocolVersion => ProtocolVersion.FromNumber(4u);

		public ProtocolVersion ClientProtocolVersion => ProtocolVersion.FromNumber(_protocolVersionNumber);

		public ProtocolVersion CommonProtocolVersion => _connection.CurrentProtocolVersion;

		public event EventHandler<EventArgs>? DeviceListUpdated;

		public OpenRgbClient(string ip = "127.0.0.1", int port = 6742, string name = "OpenRGB.NET", bool autoConnect = true, int timeoutMs = 1000, uint protocolVersionNumber = 4u)
		{
			_ip = ip;
			_port = port;
			_name = name;
			_timeoutMs = timeoutMs;
			_protocolVersionNumber = protocolVersionNumber;
			_connection = new OpenRgbConnection(this.DeviceListUpdated);
			if (protocolVersionNumber > 4)
			{
				throw new ArgumentException("Client protocol version provided higher than supported.", "protocolVersionNumber");
			}
			if (autoConnect)
			{
				Connect();
			}
		}

		public void Connect()
		{
			if (!Connected)
			{
				_connection.Connect(_name, _ip, _port, _timeoutMs, _protocolVersionNumber);
			}
		}

		public int GetControllerCount()
		{
			return _connection.RequestControllerCount<EmptyArg, PrimitiveReader<int>, int>(CommandId.RequestControllerCount, 0u, default(EmptyArg));
		}

		public Device GetControllerData(int deviceId)
		{
			if (deviceId < 0)
			{
				throw new ArgumentException("Unexpected device Id", "deviceId");
			}
			return _connection.RequestControllerData<ProtocolVersionArg, DeviceReader, Device>(CommandId.RequestControllerData, (uint)deviceId, new ProtocolVersionArg(_connection.CurrentProtocolVersion));
		}

		public Device[] GetAllControllerData()
		{
			int controllerCount = GetControllerCount();
			Device[] array = new Device[controllerCount];
			for (int i = 0; i < controllerCount; i++)
			{
				array[i] = GetControllerData(i);
			}
			return array;
		}

		public string[] GetProfiles()
		{
			if (!CommonProtocolVersion.SupportsProfileControls)
			{
				throw new NotSupportedException($"Not supported on protocol version {CommonProtocolVersion.Number}");
			}
			return _connection.RequestProfiles<EmptyArg, ProfilesReader, string[]>(CommandId.RequestProfiles, 0u, default(EmptyArg));
		}

		public Plugin[] GetPlugins()
		{
			if (!CommonProtocolVersion.SupportsSegmentsAndPlugins)
			{
				throw new NotSupportedException($"Not supported on protocol version {CommonProtocolVersion.Number}");
			}
			return _connection.RequestPlugins<EmptyArg, PluginsReader, Plugin[]>(CommandId.RequestPlugins, 0u, default(EmptyArg));
		}

		public void ResizeZone(int deviceId, int zoneId, int size)
		{
			_connection.Send(CommandId.ResizeZone, (uint)deviceId, new Args<uint, uint>((uint)zoneId, (uint)size));
		}

		public void UpdateLeds(int deviceId, ReadOnlySpan<Color> colors)
		{
			if (colors.Length == 0)
			{
				throw new ArgumentException("The colors span is empty.", "colors");
			}
			if (deviceId < 0)
			{
				throw new ArgumentException("Invalid deviceId", "deviceId");
			}
			ReadOnlySpan<byte> additionalData = MemoryMarshal.Cast<Color, byte>(colors);
			_connection.Send(CommandId.UpdateLeds, (uint)deviceId, new UpdateLedsArg((ushort)colors.Length), additionalData);
		}

		public void UpdateZoneLeds(int deviceId, int zoneId, ReadOnlySpan<Color> colors)
		{
			if (colors.Length == 0)
			{
				throw new ArgumentException("The colors span is empty.", "colors");
			}
			if (deviceId < 0)
			{
				throw new ArgumentException("Invalid device id.", "deviceId");
			}
			if (zoneId < 0)
			{
				throw new ArgumentException("Invalid zone id", "zoneId");
			}
			ReadOnlySpan<byte> additionalData = MemoryMarshal.Cast<Color, byte>(colors);
			_connection.Send(CommandId.UpdateZoneLeds, (uint)deviceId, new UpdateZoneLedsArg((uint)zoneId, (ushort)colors.Length), additionalData);
		}

		public void UpdateSingleLed(int deviceId, int ledId, Color color)
		{
			if (deviceId < 0)
			{
				throw new ArgumentException("Invalid device id.", "deviceId");
			}
			if (ledId < 0)
			{
				throw new ArgumentException("Invalid led id", "ledId");
			}
			_connection.Send(CommandId.UpdateSingleLed, (uint)deviceId, new Args<uint, Color>((uint)ledId, color));
		}

		public void SetCustomMode(int deviceId)
		{
			_connection.Send(CommandId.SetCustomMode, (uint)deviceId, default(EmptyArg));
		}

		public void LoadProfile(string profile)
		{
			_connection.Send(CommandId.LoadProfile, 0u, new StringArg(profile));
		}

		public void SaveProfile(string profile)
		{
			_connection.Send(CommandId.SaveProfile, 0u, new StringArg(profile));
		}

		public void DeleteProfile(string profile)
		{
			_connection.Send(CommandId.DeleteProfile, 0u, new StringArg(profile));
		}

		public void UpdateMode(int deviceId, int modeId, uint? speed = null, Direction? direction = null, Color[]? colors = null)
		{
			Device controllerData = GetControllerData(deviceId);
			if (modeId > controllerData.Modes.Length)
			{
				throw new ArgumentException("modeId");
			}
			Mode mode = controllerData.Modes[modeId];
			if (speed.HasValue)
			{
				if (!mode.SupportsSpeed)
				{
					throw new InvalidOperationException("Cannot set speed on a mode that doesn't use this parameter");
				}
				mode.SetSpeed(speed.Value);
			}
			if (direction.HasValue)
			{
				if (!mode.SupportsDirection)
				{
					throw new InvalidOperationException("Cannot set direction on a mode that doesn't use this parameter");
				}
				mode.SetDirection(direction.Value);
			}
			if (colors != null)
			{
				if (colors.Length != mode.Colors.Length)
				{
					throw new InvalidOperationException("Incorrect number of colors supplied");
				}
				mode.SetColors(colors);
			}
			_connection.Send(CommandId.UpdateMode, (uint)deviceId, new ModeOperationArg((uint)modeId, new ModeArg(mode)));
		}

		public void SaveMode(int deviceId, int modeId)
		{
			Device controllerData = GetControllerData(deviceId);
			if (modeId > controllerData.Modes.Length)
			{
				throw new ArgumentException("modeId");
			}
			Mode mode = controllerData.Modes[modeId];
			_connection.Send(CommandId.SaveMode, (uint)deviceId, new ModeOperationArg((uint)modeId, new ModeArg(mode)));
		}

		public void PluginSpecific(int pluginId, int pluginPacketType, ReadOnlySpan<byte> data)
		{
			if (!CommonProtocolVersion.SupportsSegmentsAndPlugins)
			{
				throw new NotSupportedException($"Not supported on protocol version {CommonProtocolVersion.Number}");
			}
			_connection.Send(CommandId.PluginSpecific, (uint)pluginId, new Args<uint>((uint)pluginPacketType), data);
		}

		public void Dispose()
		{
			_connection.Dispose();
		}
	}
	internal sealed class OpenRgbConnection : IDisposable
	{
		private readonly CancellationTokenSource _cancellationTokenSource;

		private readonly Socket _socket;

		private readonly Dictionary<CommandId, BlockingCollection<byte[]>> _pendingRequests;

		private Task? _readLoopTask;

		public bool Connected => _socket.Connected;

		public ProtocolVersion CurrentProtocolVersion { get; private set; }

		public EventHandler<EventArgs>? DeviceListUpdated { get; set; }

		public OpenRgbConnection(EventHandler<EventArgs>? OnDeviceListUpdated)
		{
			_cancellationTokenSource = new CancellationTokenSource();
			_socket = new Socket(SocketType.Stream, ProtocolType.Tcp);
			_socket.NoDelay = true;
			_pendingRequests = Enum.GetValues(typeof(CommandId)).Cast<CommandId>().ToDictionary((CommandId c) => c, (CommandId _) => new BlockingCollection<byte[]>());
			DeviceListUpdated = OnDeviceListUpdated;
		}

		public void Connect(string name, string ip, int port, int timeoutMs, uint protocolVersionNumber = 4u)
		{
			if (!Connected)
			{
				_socket.Connect(ip, port, timeoutMs, _cancellationTokenSource.Token);
				_readLoopTask = Task.Run((Func<Task?>)ReadLoop, _cancellationTokenSource.Token);
				Send(CommandId.SetClientName, 0u, new StringArg(name));
				uint number = NegotiateProtocolVersion(protocolVersionNumber);
				CurrentProtocolVersion = ProtocolVersion.FromNumber(number);
			}
		}

		private async Task ReadLoop()
		{
			byte[] headerBuffer = new byte[16];
			while (!_cancellationTokenSource.IsCancellationRequested && _socket.Connected)
			{
				try
				{
					await _socket.ReceiveAllAsync(headerBuffer, _cancellationTokenSource.Token);
					PacketHeader header = PacketHeader.FromSpan(headerBuffer);
					if (header.Command == CommandId.DeviceListUpdated)
					{
						Task.Run(delegate
						{
							try
							{
								DeviceListUpdated?.Invoke(this, EventArgs.Empty);
							}
							catch
							{
							}
						});
					}
					else
					{
						byte[] dataBuffer = new byte[header.DataLength];
						await _socket.ReceiveAllAsync(dataBuffer, _cancellationTokenSource.Token);
						DebugDumpBuffer(dataBuffer, sending: false, header.Command);
						_pendingRequests[header.Command].Add(dataBuffer, _cancellationTokenSource.Token);
					}
				}
				catch (TaskCanceledException)
				{
				}
			}
		}

		public void Send<TRequest>(CommandId command, uint deviceId, TRequest requestData, ReadOnlySpan<byte> additionalData = default(ReadOnlySpan<byte>)) where TRequest : ISpanWritable
		{
			int num = requestData.Length + additionalData.Length;
			int num2 = 16 + num;
			PacketHeader packetHeader = new PacketHeader(deviceId, command, (uint)num);
			byte[] array = ArrayPool<byte>.Shared.Rent(num2);
			Span<byte> span = array.AsSpan(0, num2);
			SpanWriter writer = new SpanWriter(span);
			packetHeader.WriteTo(ref writer);
			requestData.WriteTo(ref writer);
			writer.Write(additionalData);
			try
			{
				DebugDumpBuffer(span, sending: true, command);
				_socket.SendAll(span);
			}
			finally
			{
				ArrayPool<byte>.Shared.Return(array);
			}
		}

		public int RequestControllerCount<EmptyArg, TReader, TResult>(CommandId command, uint deviceId, EmptyArg requestData, ReadOnlySpan<byte> additionalData = default(ReadOnlySpan<byte>)) where EmptyArg : ISpanWritable where TReader : struct, ISpanReader<TResult>
		{
			Send(command, deviceId, requestData, additionalData);
			SpanReader reader = new SpanReader(_pendingRequests[command].Take(_cancellationTokenSource.Token));
			return PrimitiveReader<int>.ReadFrom(ref reader, CurrentProtocolVersion, (int)deviceId);
		}

		public Device RequestControllerData<ProtocolVersionArg, TReader, TResult>(CommandId command, uint deviceId, ProtocolVersionArg requestData, ReadOnlySpan<byte> additionalData = default(ReadOnlySpan<byte>)) where ProtocolVersionArg : ISpanWritable where TReader : struct, ISpanReader<TResult>
		{
			Send(command, deviceId, requestData, additionalData);
			SpanReader reader = new SpanReader(_pendingRequests[command].Take(_cancellationTokenSource.Token));
			return DeviceReader.ReadFrom(ref reader, CurrentProtocolVersion, (int)deviceId);
		}

		public string[] RequestProfiles<EmptyArg, TReader, TResult>(CommandId command, uint deviceId, EmptyArg requestData, ReadOnlySpan<byte> additionalData = default(ReadOnlySpan<byte>)) where EmptyArg : ISpanWritable where TReader : struct, ISpanReader<TResult>
		{
			Send(command, deviceId, requestData, additionalData);
			SpanReader reader = new SpanReader(_pendingRequests[command].Take(_cancellationTokenSource.Token));
			return ProfilesReader.ReadFrom(ref reader, CurrentProtocolVersion, (int)deviceId);
		}

		public Plugin[] RequestPlugins<EmptyArg, TReader, TResult>(CommandId command, uint deviceId, EmptyArg requestData, ReadOnlySpan<byte> additionalData = default(ReadOnlySpan<byte>)) where EmptyArg : ISpanWritable where TReader : struct, ISpanReader<TResult>
		{
			Send(command, deviceId, requestData, additionalData);
			SpanReader reader = new SpanReader(_pendingRequests[command].Take(_cancellationTokenSource.Token));
			return PluginsReader.ReadFrom(ref reader, CurrentProtocolVersion, (int)deviceId);
		}

		public uint RequestVersion<Args, TReader, TResult>(CommandId command, uint deviceId, Args requestData, ReadOnlySpan<byte> additionalData = default(ReadOnlySpan<byte>)) where Args : ISpanWritable where TReader : struct, ISpanReader<TResult>
		{
			Send(command, deviceId, requestData, additionalData);
			SpanReader reader = new SpanReader(_pendingRequests[command].Take(_cancellationTokenSource.Token));
			return PrimitiveReader<uint>.ReadFrom(ref reader, CurrentProtocolVersion, (int)deviceId);
		}

		private uint NegotiateProtocolVersion(uint maxSupportedProtocolVersion)
		{
			_socket.ReceiveTimeout = 1000;
			uint val;
			try
			{
				val = RequestVersion<Args<uint>, PrimitiveReader<uint>, uint>(CommandId.RequestProtocolVersion, 0u, new Args<uint>(maxSupportedProtocolVersion));
			}
			catch (TimeoutException)
			{
				val = 0u;
			}
			_socket.ReceiveTimeout = 0;
			return Math.Min(val, maxSupportedProtocolVersion);
		}

		public void Dispose()
		{
			_cancellationTokenSource.Cancel();
			try
			{
				_readLoopTask?.Wait();
			}
			catch
			{
			}
			_cancellationTokenSource.Dispose();
			_socket.Dispose();
			_readLoopTask?.Dispose();
		}

		[Conditional("DEBUG")]
		private static void DebugDumpBuffer(ReadOnlySpan<byte> buffer, bool sending, CommandId command)
		{
			string text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "OpenRGB.NET");
			if (!Directory.Exists(text))
			{
				Directory.CreateDirectory(text);
			}
			string text2 = Directory.EnumerateFiles(text).Max((string f) => f);
			int num = ((text2 == null) ? (-1) : int.Parse(Path.GetFileNameWithoutExtension(text2).Split('-')[0]));
			File.WriteAllBytes(Path.Combine(text, string.Format("{0:D2}-{1}-{2}.bin", num + 1, sending ? "Send" : "Receive", command)), buffer.ToArray());
		}
	}
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	internal readonly struct ColorsReader : ISpanReader<Color[]>
	{
		public static Color[] ReadFrom(ref SpanReader reader, ProtocolVersion? protocolVersion = null, int? index = null, int? outerCount = null)
		{
			ushort num = reader.Read<ushort>();
			Color[] array = new Color[num];
			for (int i = 0; i < num; i++)
			{
				byte r = reader.Read<byte>();
				byte g = reader.Read<byte>();
				byte b = reader.Read<byte>();
				reader.Read<byte>();
				array[i] = new Color(r, g, b);
			}
			return array;
		}
	}
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	internal readonly struct DeviceReader : ISpanReader<Device>
	{
		public static Device ReadFrom(ref SpanReader reader, ProtocolVersion? protocolVersion = null, int? index = null, int? outerCount = null)
		{
			if (protocolVersion.HasValue)
			{
				ProtocolVersion valueOrDefault = protocolVersion.GetValueOrDefault();
				if (true)
				{
					if (index.HasValue)
					{
						int valueOrDefault2 = index.GetValueOrDefault();
						if (true)
						{
							uint num = reader.Read<uint>();
							int type = reader.Read<int>();
							string name = reader.ReadLengthAndString();
							string vendor = (valueOrDefault.SupportsVendorString ? reader.ReadLengthAndString() : null);
							string description = reader.ReadLengthAndString();
							string version = reader.ReadLengthAndString();
							string serial = reader.ReadLengthAndString();
							string location = reader.ReadLengthAndString();
							ushort value = reader.Read<ushort>();
							int activeModeIndex = reader.Read<int>();
							ProtocolVersion? protocolVersion2 = valueOrDefault;
							int? outerCount2 = value;
							Mode[] modes = ModesReader.ReadFrom(ref reader, protocolVersion2, null, outerCount2);
							Zone[] zones = ZonesReader.ReadFrom(ref reader, valueOrDefault, valueOrDefault2);
							Led[] leds = LedsReader.ReadFrom(ref reader);
							Color[] colors = ColorsReader.ReadFrom(ref reader);
							return new Device(valueOrDefault2, (DeviceType)type, name, vendor, description, version, serial, location, activeModeIndex, modes, zones, leds, colors);
						}
					}
					throw new ArgumentNullException("index");
				}
			}
			throw new ArgumentNullException("protocolVersion");
		}
	}
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	internal readonly struct LedsReader : ISpanReader<Led[]>
	{
		public static Led[] ReadFrom(ref SpanReader reader, ProtocolVersion? protocolVersion = null, int? index = null, int? outerCount = null)
		{
			ushort num = reader.Read<ushort>();
			Led[] array = new Led[num];
			for (int i = 0; i < num; i++)
			{
				string name = reader.ReadLengthAndString();
				uint value = reader.Read<uint>();
				array[i] = new Led(i, name, value);
			}
			return array;
		}
	}
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	internal readonly struct MatrixMapReader : ISpanReader<MatrixMap>
	{
		public static MatrixMap ReadFrom(ref SpanReader reader, ProtocolVersion? protocolVersion = null, int? index = null, int? outerCount = null)
		{
			uint num = reader.Read<uint>();
			uint num2 = reader.Read<uint>();
			uint[,] array = new uint[num, num2];
			for (int i = 0; i < num; i++)
			{
				for (int j = 0; j < num2; j++)
				{
					array[i, j] = reader.Read<uint>();
				}
			}
			return new MatrixMap(num, num2, array);
		}
	}
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	internal readonly struct ModesReader : ISpanReader<Mode[]>
	{
		public static Mode[] ReadFrom(ref SpanReader reader, ProtocolVersion? protocolVersion = null, int? index = null, int? outerCount = null)
		{
			if (protocolVersion.HasValue)
			{
				ProtocolVersion valueOrDefault = protocolVersion.GetValueOrDefault();
				if (true)
				{
					if (outerCount.HasValue)
					{
						int valueOrDefault2 = outerCount.GetValueOrDefault();
						if (true)
						{
							Mode[] array = new Mode[valueOrDefault2];
							for (int i = 0; i < array.Length; i++)
							{
								string name = reader.ReadLengthAndString();
								int value = reader.Read<int>();
								ModeFlags flags = (ModeFlags)reader.Read<uint>();
								uint speedMin = reader.Read<uint>();
								uint speedMax = reader.Read<uint>();
								uint brightnessMin = (valueOrDefault.SupportsBrightnessAndSaveMode ? reader.Read<uint>() : 0u);
								uint brightnessMax = (valueOrDefault.SupportsBrightnessAndSaveMode ? reader.Read<uint>() : 0u);
								uint colorMin = reader.Read<uint>();
								uint colorMax = reader.Read<uint>();
								uint speed = reader.Read<uint>();
								uint brightness = (valueOrDefault.SupportsBrightnessAndSaveMode ? reader.Read<uint>() : 0u);
								uint direction = reader.Read<uint>();
								ColorMode colorMode = (ColorMode)reader.Read<uint>();
								Color[] colors = ColorsReader.ReadFrom(ref reader);
								array[i] = new Mode(valueOrDefault, i, name, value, flags, speedMin, speedMax, brightnessMin, brightnessMax, colorMin, colorMax, speed, brightness, (Direction)direction, colorMode, colors);
							}
							return array;
						}
					}
					throw new ArgumentNullException("outerCount");
				}
			}
			throw new ArgumentNullException("protocolVersion");
		}
	}
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	internal readonly struct PluginsReader : ISpanReader<Plugin[]>
	{
		public static Plugin[] ReadFrom(ref SpanReader reader, ProtocolVersion? p = null, int? i = null, int? outerCount = null)
		{
			uint num = reader.Read<uint>();
			ushort num2 = reader.Read<ushort>();
			Plugin[] array = new Plugin[num2];
			for (int j = 0; j < num2; j++)
			{
				string name = reader.ReadLengthAndString();
				string description = reader.ReadLengthAndString();
				string version = reader.ReadLengthAndString();
				uint index = reader.Read<uint>();
				int sdkVersion = reader.Read<int>();
				array[j] = new Plugin(name, description, version, index, sdkVersion);
			}
			return array;
		}
	}
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	internal readonly struct PrimitiveReader<T> : ISpanReader<T> where T : unmanaged
	{
		public static T ReadFrom(ref SpanReader reader, ProtocolVersion? protocolVersion = null, int? index = null, int? outerCount = null)
		{
			return reader.Read<T>();
		}
	}
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	internal readonly struct ProfilesReader : ISpanReader<string[]>
	{
		public static string[] ReadFrom(ref SpanReader reader, ProtocolVersion? p = null, int? i = null, int? outerCount = null)
		{
			uint num = reader.Read<uint>();
			ushort num2 = reader.Read<ushort>();
			string[] array = new string[num2];
			for (int j = 0; j < num2; j++)
			{
				array[j] = reader.ReadLengthAndString();
			}
			return array;
		}
	}
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	internal readonly struct ProtocolVersionReader : ISpanReader<ProtocolVersion>
	{
		public static ProtocolVersion ReadFrom(ref SpanReader reader, ProtocolVersion? p = null, int? i = null, int? outerCount = null)
		{
			return ProtocolVersion.FromNumber(reader.Read<uint>());
		}
	}
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	internal readonly struct SegmentsReader : ISpanReader<Segment[]>
	{
		public static Segment[] ReadFrom(ref SpanReader reader, ProtocolVersion? protocolVersion = null, int? index = null, int? outerCount = null)
		{
			ushort num = reader.Read<ushort>();
			Segment[] array = new Segment[num];
			for (int i = 0; i < num; i++)
			{
				string name = reader.ReadLengthAndString();
				ZoneType type = (ZoneType)reader.Read<uint>();
				uint start = reader.Read<uint>();
				uint ledCount = reader.Read<uint>();
				array[i] = new Segment(i, name, type, start, ledCount);
			}
			return array;
		}
	}
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	internal readonly struct ZonesReader : ISpanReader<Zone[]>
	{
		public static Zone[] ReadFrom(ref SpanReader reader, ProtocolVersion? protocolVersion = null, int? index = null, int? outerCount = null)
		{
			if (protocolVersion.HasValue)
			{
				ProtocolVersion valueOrDefault = protocolVersion.GetValueOrDefault();
				if (true)
				{
					if (index.HasValue)
					{
						int valueOrDefault2 = index.GetValueOrDefault();
						if (true)
						{
							ushort num = reader.Read<ushort>();
							Zone[] array = new Zone[num];
							for (int i = 0; i < num; i++)
							{
								string name = reader.ReadLengthAndString();
								ZoneType type = (ZoneType)reader.Read<uint>();
								uint ledsMin = reader.Read<uint>();
								uint ledsMax = reader.Read<uint>();
								uint ledCount = reader.Read<uint>();
								ushort num2 = reader.Read<ushort>();
								MatrixMap matrixMap = ((num2 > 0) ? MatrixMapReader.ReadFrom(ref reader) : null);
								Segment[] segments = (valueOrDefault.SupportsSegmentsAndPlugins ? SegmentsReader.ReadFrom(ref reader, protocolVersion) : Array.Empty<Segment>());
								array[i] = new Zone(i, valueOrDefault2, name, type, ledCount, ledsMin, ledsMax, matrixMap, segments);
							}
							return array;
						}
					}
					throw new ArgumentNullException("index");
				}
			}
			throw new ArgumentNullException("protocolVersion");
		}
	}
	internal readonly record struct Args<T1>(T1 Arg1) : ISpanWritable where T1 : unmanaged
	{
		public int Length => UnsafeReplacement.SizeOf<T1>();

		public void WriteTo(ref SpanWriter writer)
		{
			writer.Write(Arg1);
		}
	}
	internal readonly record struct Args<T1, T2>(T1 Arg1, T2 Arg2) : ISpanWritable where T1 : unmanaged where T2 : unmanaged
	{
		public int Length => UnsafeReplacement.SizeOf<T1>() + UnsafeReplacement.SizeOf<T2>();

		public void WriteTo(ref SpanWriter writer)
		{
			writer.Write(Arg1);
			writer.Write(Arg2);
		}
	}
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	internal readonly struct EmptyArg : ISpanWritable
	{
		public int Length => 0;

		public void WriteTo(ref SpanWriter writer)
		{
		}
	}
	internal readonly record struct ModeArg(Mode Mode) : ISpanWritable
	{
		public int Length
		{
			get
			{
				int num = 0;
				num += 4;
				num += 36;
				num += Mode.Name.Length + 1;
				num += 4 * Mode.Colors.Length;
				if (Mode.ProtocolVersion.SupportsBrightnessAndSaveMode)
				{
					num += 12;
				}
				return num;
			}
		}

		public void WriteTo(ref SpanWriter writer)
		{
			writer.WriteLengthAndString(Mode.Name);
			writer.Write(Mode.Value);
			writer.Write((uint)Mode.Flags);
			writer.Write(Mode.SpeedMin);
			writer.Write(Mode.SpeedMax);
			if (Mode.ProtocolVersion.SupportsBrightnessAndSaveMode)
			{
				writer.Write(Mode.BrightnessMin);
				writer.Write(Mode.BrightnessMax);
			}
			writer.Write(Mode.ColorMin);
			writer.Write(Mode.ColorMax);
			writer.Write(Mode.Speed);
			if (Mode.ProtocolVersion.SupportsBrightnessAndSaveMode)
			{
				writer.Write(Mode.Brightness);
			}
			writer.Write((uint)Mode.Direction);
			writer.Write((uint)Mode.ColorMode);
			writer.Write((ushort)Mode.Colors.Length);
			Span<byte> span = MemoryMarshal.Cast<Color, byte>(Mode.Colors);
			writer.Write((ReadOnlySpan<byte>)span);
		}
	}
	internal readonly record struct ModeOperationArg(uint ModeId, ModeArg Mode) : ISpanWritable
	{
		public int Length => 8 + Mode.Length;

		public void WriteTo(ref SpanWriter writer)
		{
			writer.Write(Length);
			writer.Write(ModeId);
			Mode.WriteTo(ref writer);
		}
	}
	internal readonly struct PacketHeader : ISpanWritable
	{
		internal const int LENGTH = 16;

		internal static ReadOnlySpan<byte> MagicBytes => "ORGB"u8;

		internal uint DeviceId { get; }

		internal CommandId Command { get; }

		internal uint DataLength { get; }

		public int Length => 16;

		public PacketHeader(uint deviceId, CommandId command, uint length)
		{
			DeviceId = deviceId;
			Command = command;
			DataLength = length;
		}

		public static PacketHeader FromSpan(ReadOnlySpan<byte> span)
		{
			SpanReader spanReader = new SpanReader(span);
			ReadOnlySpan<byte> span2 = spanReader.ReadBytes(4);
			if (!span2.SequenceEqual(MagicBytes))
			{
				throw new ArgumentException("Magic bytes \"ORGB\" were not found");
			}
			uint deviceId = spanReader.Read<uint>();
			CommandId command = (CommandId)spanReader.Read<uint>();
			uint length = spanReader.Read<uint>();
			return new PacketHeader(deviceId, command, length);
		}

		public void WriteTo(ref SpanWriter writer)
		{
			writer.Write(MagicBytes);
			writer.Write(DeviceId);
			writer.Write((uint)Command);
			writer.Write(DataLength);
		}
	}
	internal readonly record struct ProtocolVersionArg(ProtocolVersion Version) : ISpanWritable
	{
		public int Length => 4;

		public void WriteTo(ref SpanWriter writer)
		{
			writer.Write(Version.Number);
		}
	}
	internal readonly record struct StringArg(string Value) : ISpanWritable
	{
		public int Length => Value.Length + 1;

		public void WriteTo(ref SpanWriter writer)
		{
			writer.Write(Value);
		}
	}
	internal readonly record struct UpdateLedsArg(ushort ColorCount) : ISpanWritable
	{
		public int Length => 6;

		public void WriteTo(ref SpanWriter writer)
		{
			writer.Write((uint)(Length + UnsafeReplacement.SizeOf<Color>() * ColorCount));
			writer.Write(ColorCount);
		}
	}
	internal readonly record struct UpdateZoneLedsArg(uint ZoneId, ushort ColorCount) : ISpanWritable
	{
		public int Length => 10;

		public void WriteTo(ref SpanWriter writer)
		{
			writer.Write((uint)(Length + UnsafeReplacement.SizeOf<Color>() * ColorCount));
			writer.Write(ZoneId);
			writer.Write(ColorCount);
		}
	}
}
namespace OpenRGB.NET.Utils
{
	public static class ColorUtils
	{
		public static Color FromHsv(double hue, double saturation, double value)
		{
			if ((saturation < 0.0 || saturation > 1.0) ? true : false)
			{
				throw new ArgumentOutOfRangeException("saturation");
			}
			if ((value < 0.0 || value > 1.0) ? true : false)
			{
				throw new ArgumentOutOfRangeException("value");
			}
			while (hue < 0.0)
			{
				hue += 360.0;
			}
			while (hue >= 360.0)
			{
				hue -= 360.0;
			}
			int num = Convert.ToInt32(Math.Floor(hue / 60.0)) % 6;
			double num2 = hue / 60.0 - Math.Floor(hue / 60.0);
			value *= 255.0;
			byte b = Convert.ToByte(value);
			byte b2 = Convert.ToByte(value * (1.0 - saturation));
			byte b3 = Convert.ToByte(value * (1.0 - num2 * saturation));
			byte b4 = Convert.ToByte(value * (1.0 - (1.0 - num2) * saturation));
			return num switch
			{
				0 => new Color(b, b4, b2), 
				1 => new Color(b3, b, b2), 
				2 => new Color(b2, b, b4), 
				3 => new Color(b2, b3, b), 
				4 => new Color(b4, b2, b), 
				_ => new Color(b, b2, b3), 
			};
		}

		public static (double h, double s, double v) ToHsv(this Color clr)
		{
			byte b = Math.Max(clr.R, Math.Max(clr.G, clr.B));
			byte b2 = Math.Min(clr.R, Math.Min(clr.G, clr.B));
			int num = b - b2;
			double num2 = 0.0;
			if (num != 0)
			{
				if (clr.R == b)
				{
					num2 = (double)(clr.G - clr.B) / (double)num;
				}
				else if (clr.G == b)
				{
					num2 = 2.0 + (double)(clr.B - clr.R) / (double)num;
				}
				else if (clr.B == b)
				{
					num2 = 4.0 + (double)(clr.R - clr.G) / (double)num;
				}
			}
			num2 *= 60.0;
			if (num2 < 0.0)
			{
				num2 += 360.0;
			}
			double item = ((b == 0) ? 0.0 : (1.0 - 1.0 * (double)(int)b2 / (double)(int)b));
			double item2 = (double)(int)b / 255.0;
			return (num2, item, item2);
		}

		public static IEnumerable<Color> GetHueRainbow(int amount, double hueStart = 0.0, double huePercent = 1.0, double saturation = 1.0, double value = 1.0)
		{
			return from i in Enumerable.Range(0, amount)
				select FromHsv(hueStart + 360.0 * huePercent / (double)amount * (double)i, saturation, value);
		}

		public static IEnumerable<Color> GetSinRainbow(int amount, int floor = 127, int width = 128, double range = 1.0, double offset = Math.PI / 2.0)
		{
			return from i in Enumerable.Range(0, amount)
				select new Color((byte)((double)floor + (double)width * Math.Sin(offset + Math.PI * 2.0 * range / (double)amount * (double)i + 0.0)), (byte)((double)floor + (double)width * Math.Sin(offset + Math.PI * 2.0 * range / (double)amount * (double)i + Math.PI * 2.0 / 3.0)), (byte)((double)floor + (double)width * Math.Sin(offset + Math.PI * 2.0 * range / (double)amount * (double)i + 4.1887902047863905)));
		}
	}
	[AttributeUsage(AttributeTargets.Struct)]
	internal class NonCopyableAttribute : Attribute
	{
	}
	internal static class SocketExtensions
	{
		public static void Connect(this Socket socket, string host, int port, int timeoutMs, CancellationToken cancellationToken)
		{
			Task task = SocketTaskExtensions.ConnectAsync(socket, host, port);
			Task.WaitAny(new Task[1] { task }, timeoutMs, cancellationToken);
			if (socket.Connected)
			{
				return;
			}
			socket.Close();
			throw new TimeoutException("Could not connect to OpenRGB");
		}

		public static async Task ReceiveAllAsync(this Socket socket, Memory<byte> buffer, CancellationToken cancellationToken)
		{
			int received;
			for (int recv = 0; recv < buffer.Length; recv += received)
			{
				int num = recv;
				received = await SocketTaskExtensions.ReceiveAsync(socket, buffer.Slice(num, buffer.Length - num), SocketFlags.None, cancellationToken);
				if (received == 0)
				{
					break;
				}
			}
		}

		public static async Task SendAllAsync(this Socket socket, ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken)
		{
			int num;
			for (int sent = 0; sent < buffer.Length; sent += await SocketTaskExtensions.SendAsync(socket, buffer.Slice(num, buffer.Length - num), SocketFlags.None, cancellationToken))
			{
				num = sent;
			}
		}

		public static void SendAll(this Socket socket, ReadOnlySpan<byte> buffer)
		{
			int num2;
			for (int i = 0; i < buffer.Length; i += num2)
			{
				int num = i;
				num2 = socket.Send(buffer.Slice(num, buffer.Length - num));
			}
		}
	}
	[NonCopyable]
	internal ref struct SpanReader
	{
		private ReadOnlySpan<byte> Span { get; }

		private int Position { get; set; }

		public SpanReader(ReadOnlySpan<byte> span)
		{
			Span = span;
			Position = 0;
		}

		internal T Read<T>() where T : unmanaged
		{
			ReadOnlySpan<byte> span = Span;
			int position = Position;
			T result = MemoryMarshal.Read<T>(span.Slice(position, span.Length - position));
			Position += UnsafeReplacement.SizeOf<T>();
			return result;
		}

		public ReadOnlySpan<byte> ReadBytes(int length)
		{
			ReadOnlySpan<byte> span = Span;
			int position = Position;
			ReadOnlySpan<byte> result = span.Slice(position, Position + length - position);
			Position += length;
			return result;
		}

		public string ReadLengthAndString()
		{
			int num = Read<ushort>();
			if (num == 0)
			{
				return string.Empty;
			}
			Encoding aSCII = Encoding.ASCII;
			ReadOnlySpan<byte> readOnlySpan = ReadBytes(num);
			return aSCII.GetString(readOnlySpan.Slice(0, readOnlySpan.Length - 1));
		}
	}
	[NonCopyable]
	internal ref struct SpanWriter
	{
		public Span<byte> Span { get; }

		public int Position { get; private set; }

		public SpanWriter(Span<byte> span)
		{
			Span = span;
			Position = 0;
		}

		public void Write<T>(T value) where T : unmanaged
		{
			Span<byte> span = Span;
			int position = Position;
			MemoryMarshal.Write(span.Slice(position, span.Length - position), ref value);
			Position += UnsafeReplacement.SizeOf<T>();
		}

		public void Write(ReadOnlySpan<byte> span)
		{
			Span<byte> span2 = Span;
			int position = Position;
			span.CopyTo(span2.Slice(position, span2.Length - position));
			Position += span.Length;
		}

		public void WriteLengthAndString(string value)
		{
			Write((ushort)(value.Length + 1));
			Write(value);
		}

		public void Write(string value)
		{
			int byteCount = Encoding.ASCII.GetByteCount(value.AsSpan());
			Encoding.ASCII.GetBytes(value, Span.Slice(Position, byteCount));
			Position += byteCount;
			Write((byte)0);
		}
	}
}

UltraRGBLighting.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using OpenRGB.NET;
using PluginConfig.API;
using PluginConfig.API.Decorators;
using PluginConfig.API.Fields;
using PluginConfig.API.Functionals;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("UltraRGBLighting")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("UltraRGBLighting")]
[assembly: AssemblyTitle("UltraRGBLighting")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace UltraRGBLighting
{
	public enum PermutatorCause
	{
		None,
		RecentKills,
		RecentDamage,
		RecentStyle,
		OnStyleGain,
		OnRankGain,
		OnRankLose,
		OnKill,
		OnDamage,
		OnTakeDamage,
		OnPlayerDeath,
		Always
	}
	public enum FadeEnum
	{
		Linear,
		NoFade,
		SquareRoot,
		Quadratic,
		PassIfAboveHalf,
		PassIfBelowHalf
	}
	public class Permutator
	{
		public PermutatorCause cause = PermutatorCause.None;

		public bool scaleWithCauseMagnitude = false;

		public FadeEnum fadeType = FadeEnum.Linear;

		public Color propertyColor = Color.white;

		public colorPropertyEnum property = colorPropertyEnum.None;

		public float propertyFloat1 = 0f;

		public float propertyFloat2 = 0f;

		public float propertyFloat3 = 0f;

		public float length = 0f;
	}
	public class Permutators
	{
		[HarmonyPatch(typeof(StyleHUD), "AddPoints")]
		public class StyleHUDAddPointsPatch
		{
			[HarmonyPrefix]
			private static void Prefix(int points, string pointID, GameObject sourceWeapon = null, EnemyIdentifier eid = null, int count = -1, string prefix = "", string postfix = "")
			{
				lastTimeStyleGain = Time.realtimeSinceStartup;
				styleGainedThisTick.Add(points);
				recentStyle += points;
			}
		}

		[HarmonyPatch(typeof(StyleHUD), "AscendRank")]
		public class StyleHUDAscendRankPatch
		{
			[HarmonyPrefix]
			private static void Prefix()
			{
				lastTimeRankGain = Time.realtimeSinceStartup;
			}
		}

		[HarmonyPatch(typeof(StyleHUD), "DescendRank")]
		public class StyleHUDDescendRankPatch
		{
			[HarmonyPrefix]
			private static void Prefix()
			{
				lastTimeRankLose = Time.realtimeSinceStartup;
			}
		}

		[HarmonyPatch(typeof(EnemyIdentifier))]
		public class EnemyIdentifierPatch
		{
			[HarmonyPatch("DeliverDamage")]
			private static void Prefix(EnemyIdentifier __instance, out float __state)
			{
				__state = __instance.health;
			}

			[HarmonyPatch("DeliverDamage")]
			private static void Postfix(EnemyIdentifier __instance, float __state, float multiplier, GameObject sourceWeapon)
			{
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				if (__state <= 0f)
				{
					return;
				}
				__instance.ForceGetHealth();
				float num;
				if (__instance.health <= 0f)
				{
					num = 0f;
					lastTimeKill = Time.realtimeSinceStartup;
					EnemyType[] array = new EnemyType[25];
					RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
					EnemyType[] source = (EnemyType[])(object)array;
					if (source.Contains(__instance.enemyType))
					{
						lastKillBig = true;
						recentKills += 3f;
					}
					else
					{
						lastKillBig = false;
						recentKills += 1f;
					}
				}
				else
				{
					num = __instance.health;
				}
				float num2 = __state - num;
				if (num2 != 0f && __instance.hitter != "enemy")
				{
					lastTimeDamage = Time.realtimeSinceStartup;
				}
				if (__instance.hitter != "enemy")
				{
					damageDealtThisTick.Add(num2);
					recentDamage += num2;
				}
			}
		}

		public static float lastTimeStyleGain = -1f;

		public static float lastTimeRankGain = -1f;

		public static float lastTimeRankLose = -1f;

		public static float lastTimeKill = -1f;

		public static float lastTimeDamage = -1f;

		public static float lastTimeOnTakeDamage = -1f;

		public static float lastTimePlayerDeath = -1f;

		public static List<float> damageDealtThisTick = new List<float>();

		public static float lastDamage = -1f;

		public static float lastOnTakeDamage = -1f;

		public static bool lastKillBig = false;

		public static List<float> styleGainedThisTick = new List<float>();

		public static float lastStyleGain = -1f;

		public static float recentKills = 0f;

		public static float recentDamage = 0f;

		public static float recentStyle = 0f;

		private static int hp = 0;

		private static bool dead = false;

		public static Permutator[] permutatorArr = new Permutator[15];

		public static void actionLogic()
		{
			if (hp > MonoSingleton<NewMovement>.instance.hp)
			{
				lastOnTakeDamage = hp - MonoSingleton<NewMovement>.instance.hp;
				lastTimeOnTakeDamage = Time.realtimeSinceStartup;
			}
			hp = MonoSingleton<NewMovement>.instance.hp;
			if (dead != MonoSingleton<NewMovement>.instance.dead && MonoSingleton<NewMovement>.instance.dead)
			{
				lastTimePlayerDeath = Time.realtimeSinceStartup;
			}
			dead = MonoSingleton<NewMovement>.instance.dead;
			if (styleGainedThisTick.Count != 0)
			{
				float num = 0f;
				for (int i = 0; i < styleGainedThisTick.Count; i++)
				{
					num += styleGainedThisTick[i];
				}
				styleGainedThisTick = new List<float>();
			}
			if (damageDealtThisTick.Count != 0)
			{
				float num2 = 0f;
				for (int j = 0; j < damageDealtThisTick.Count; j++)
				{
					num2 += damageDealtThisTick[j];
				}
				lastDamage = num2;
				damageDealtThisTick = new List<float>();
			}
			recentDamage = recentDamage * (1f - 1f * (Time.deltaTime * (float)Plugin.framesSinceLastRefreshed)) - 0.1f * (Time.deltaTime * (float)Plugin.framesSinceLastRefreshed);
			recentStyle = recentStyle * (1f - 1f * (Time.deltaTime * (float)Plugin.framesSinceLastRefreshed)) - 5f * (Time.deltaTime * (float)Plugin.framesSinceLastRefreshed);
			recentKills = recentKills * (1f - 1f * (Time.deltaTime * (float)Plugin.framesSinceLastRefreshed)) - 0.04f * (Time.deltaTime * (float)Plugin.framesSinceLastRefreshed);
			if (recentDamage < 0f)
			{
				recentDamage = 0f;
			}
			if (recentStyle < 0f)
			{
				recentStyle = 0f;
			}
			if (recentKills < 0f)
			{
				recentKills = 0f;
			}
		}

		public static Color ApplyPermutators(Color colorIn, int LEDindex)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0405: Unknown result type (might be due to invalid IL or missing references)
			//IL_0406: Unknown result type (might be due to invalid IL or missing references)
			//IL_040a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0367: Unknown result type (might be due to invalid IL or missing references)
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_038c: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0398: Unknown result type (might be due to invalid IL or missing references)
			//IL_03af: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
			Color val = colorIn;
			for (int i = 0; i < permutatorArr.Length; i++)
			{
				Permutator permutator = permutatorArr[i];
				PermutatorCause cause = permutator.cause;
				FadeEnum fadeType = permutator.fadeType;
				bool scaleWithCauseMagnitude = permutator.scaleWithCauseMagnitude;
				float length = permutator.length;
				float value = 0f;
				float num = 1f;
				if (cause == PermutatorCause.None)
				{
					continue;
				}
				switch (cause)
				{
				case PermutatorCause.OnStyleGain:
					if (lastTimeStyleGain < 0f)
					{
						continue;
					}
					value = Time.realtimeSinceStartup - lastTimeStyleGain;
					if (scaleWithCauseMagnitude)
					{
						num = Convert.ToSingle(Math.Sqrt(lastStyleGain / 5f));
					}
					break;
				case PermutatorCause.OnRankGain:
					if (lastTimeRankGain < 0f)
					{
						continue;
					}
					value = Time.realtimeSinceStartup - lastTimeRankGain;
					break;
				case PermutatorCause.OnRankLose:
					if (lastTimeRankLose < 0f)
					{
						continue;
					}
					value = Time.realtimeSinceStartup - lastTimeRankLose;
					break;
				case PermutatorCause.OnKill:
					if (lastTimeKill < 0f)
					{
						continue;
					}
					value = Time.realtimeSinceStartup - lastTimeKill;
					if (scaleWithCauseMagnitude && lastKillBig)
					{
						num = 2f;
					}
					break;
				case PermutatorCause.OnDamage:
					if (lastTimeDamage < 0f)
					{
						continue;
					}
					value = Time.realtimeSinceStartup - lastTimeDamage;
					if (scaleWithCauseMagnitude)
					{
						num = Convert.ToSingle(Math.Sqrt(lastDamage));
					}
					break;
				case PermutatorCause.OnTakeDamage:
					if (lastTimeOnTakeDamage < 0f)
					{
						continue;
					}
					value = Time.realtimeSinceStartup - lastTimeOnTakeDamage;
					if (scaleWithCauseMagnitude)
					{
						num = lastOnTakeDamage / 25f;
					}
					break;
				case PermutatorCause.OnPlayerDeath:
					if (lastTimePlayerDeath < 0f)
					{
						continue;
					}
					value = Time.realtimeSinceStartup - lastTimePlayerDeath;
					break;
				case PermutatorCause.Always:
					value = 0f;
					break;
				case PermutatorCause.RecentKills:
				{
					float num4 = recentKills / (4f / length);
					if (num4 > 1f)
					{
						num4 = 1f;
					}
					value = length * num * (1f - num4);
					break;
				}
				case PermutatorCause.RecentDamage:
				{
					float num3 = recentStyle / (30f / length);
					if (num3 > 1f)
					{
						num3 = 1f;
					}
					value = length * num * (1f - num3);
					break;
				}
				case PermutatorCause.RecentStyle:
				{
					float num2 = recentStyle / (1000f / length);
					if (num2 > 1f)
					{
						num2 = 1f;
					}
					value = length * num * (1f - num2);
					break;
				}
				}
				value = Math.Abs(value);
				if (!(value >= length * num))
				{
					float f = 1f - value / (length * num);
					f = FadeLogic(f, fadeType);
					val = Plugin.ApplyColorPropertyStep2(val, permutator.property, permutator.propertyColor, permutator.propertyFloat1, permutator.propertyFloat2, permutator.propertyFloat3, LEDindex);
					val.r = val.r * f + colorIn.r * (1f - f);
					val.g = val.g * f + colorIn.g * (1f - f);
					val.b = val.b * f + colorIn.b * (1f - f);
				}
			}
			return val;
		}

		public static float FadeLogic(float f, FadeEnum fe)
		{
			switch (fe)
			{
			case FadeEnum.NoFade:
				if (f > 0f && f <= 1f)
				{
					f = 1f;
				}
				break;
			case FadeEnum.Quadratic:
				f *= f;
				break;
			case FadeEnum.SquareRoot:
				f = Convert.ToSingle(Math.Sqrt(f));
				break;
			case FadeEnum.PassIfAboveHalf:
				f = ((!((double)f > 0.5)) ? 0f : 1f);
				break;
			case FadeEnum.PassIfBelowHalf:
				f = ((!((double)f < 0.5)) ? 0f : 1f);
				break;
			}
			return f;
		}

		public static Color Colorfy(Color colorIn, Color taintColor, float amt)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_0053: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			float num = taintColor.r * amt + colorIn.r * (1f - amt);
			float num2 = taintColor.g * amt + colorIn.g * (1f - amt);
			float num3 = taintColor.b * amt + colorIn.b * (1f - amt);
			Color result = default(Color);
			((Color)(ref result))..ctor(num, num2, num3);
			return result;
		}

		public static Color Brighten(Color colorIn, float amt)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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_0052: 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)
			float r = colorIn.r;
			float g = colorIn.g;
			float b = colorIn.b;
			float num = Math.Max(Math.Max(r, g), b);
			float num2 = num * amt + 1f * (1f - amt);
			r /= num2;
			g /= num2;
			b /= num2;
			Color result = default(Color);
			((Color)(ref result))..ctor(r, g, b);
			return result;
		}
	}
	[BepInPlugin("UltraRGBLighting", "UltraRGBLighting", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private string DefaultParentFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? "";

		public static ManualLogSource logger = null;

		public static Random random = new Random();

		public static bool modEnabled = false;

		public static bool connected = false;

		public static int currentRankInt = 0;

		public static float currentRankFloat = 0f;

		public static styleRankColoringScheme[,] styleRankColorSettings = new styleRankColoringScheme[4, 9];

		public static Dictionary<int, deviceColoringScheme> deviceColorSettings = new Dictionary<int, deviceColoringScheme>();

		public static Dictionary<int, List<Color>> colorsBoard = new Dictionary<int, List<Color>>();

		public static List<Device> connectedDevices = new List<Device>();

		public static OpenRgbClient client;

		public static float[] lastFlickerTime = new float[4];

		public static List<float>[] flickerIntensity = new List<float>[4];

		public static float flickerIntensityFixedFrequency = 10f;

		public static float lastFlickerTimeFixed = 0f;

		public static List<float> flickerIntensityFixed = new List<float>();

		public static int maxLEDCount = 0;

		public static bool[] connectedSchemes = new bool[4];

		public static float nextTimeAttemptAutoconnect = 0f;

		public static float refreshRate = 60f;

		public static float lastTimeRefreshed = 0f;

		public static int framesSinceLastRefreshed = 0;

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			Harmony val = new Harmony("UltraRGBLighting");
			val.PatchAll();
			for (int i = 0; i < Permutators.permutatorArr.Length; i++)
			{
				Permutators.permutatorArr[i] = new Permutator();
			}
			for (int j = 0; j < 4; j++)
			{
				for (int k = 0; k < 9; k++)
				{
					styleRankColorSettings[j, k] = new styleRankColoringScheme();
				}
			}
			ModConfig.createConfig();
			logger = new ManualLogSource("UltraRGBLighting");
			Logger.Sources.Add((ILogSource)(object)logger);
			logger.LogInfo((object)"UltraRGBLighting started!");
		}

		public static Color AlternateColors(styleRankColoringScheme data)
		{
			//IL_0002: 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_00ca: 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_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_0025: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_00ab: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
			Color mainColor = data.mainColor;
			if (data.alternateColorFreq > 0f)
			{
				Color mainColor2 = data.mainColor;
				Color secondaryColor = data.secondaryColor;
				float num = Time.realtimeSinceStartup * data.alternateColorFreq * 2f * Convert.ToSingle(Math.PI);
				float num2 = Convert.ToSingle(Math.Sin(num)) / 2f + 0.5f;
				mainColor.r = mainColor2.r * (1f - num2) + secondaryColor.r * num2;
				mainColor.g = mainColor2.g * (1f - num2) + secondaryColor.g * num2;
				mainColor.b = mainColor2.b * (1f - num2) + secondaryColor.b * num2;
			}
			return mainColor;
		}

		public static Color PulsateColors(Color color, styleRankColoringScheme data)
		{
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: 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)
			if (data.pulsateFrequency > 0f)
			{
				float num = Time.realtimeSinceStartup * data.pulsateFrequency * 2f * Convert.ToSingle(Math.PI);
				float num2 = data.pulsateAmplitude * Convert.ToSingle(Math.Sin(num)) / 2f + 0.5f;
				color.r *= 1f - num2;
				color.g *= 1f - num2;
				color.b *= 1f - num2;
			}
			return color;
		}

		public static Color FlickerColors(Color color, styleRankColoringScheme data, int settingsIndex, int LEDindex)
		{
			//IL_0095: 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_002d: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			if (data.flickerFrequency > 0f)
			{
				float num = flickerIntensity[settingsIndex][LEDindex] * data.flickerAmplitude;
				color.r = color.r * (1f - num) + data.flickerColor.r * num;
				color.g = color.g * (1f - num) + data.flickerColor.g * num;
				color.b = color.b * (1f - num) + data.flickerColor.b * num;
			}
			return color;
		}

		public static Color HSVToColor(float h, float S, float V)
		{
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			float num;
			for (num = h; num < 0f; num += 360f)
			{
			}
			while (num >= 360f)
			{
				num -= 360f;
			}
			float num4;
			float num3;
			float num2;
			if (V <= 0f)
			{
				num4 = (num3 = (num2 = 0f));
			}
			else if (S <= 0f)
			{
				num4 = (num3 = (num2 = V));
			}
			else
			{
				float num5 = num / 60f;
				int num6 = (int)Math.Floor(num5);
				float num7 = num5 - (float)num6;
				float num8 = V * (1f - S);
				float num9 = V * (1f - S * num7);
				float num10 = V * (1f - S * (1f - num7));
				switch (num6)
				{
				case 0:
					num4 = V;
					num3 = num10;
					num2 = num8;
					break;
				case 1:
					num4 = num9;
					num3 = V;
					num2 = num8;
					break;
				case 2:
					num4 = num8;
					num3 = V;
					num2 = num10;
					break;
				case 3:
					num4 = num8;
					num3 = num9;
					num2 = V;
					break;
				case 4:
					num4 = num10;
					num3 = num8;
					num2 = V;
					break;
				case 5:
					num4 = V;
					num3 = num8;
					num2 = num9;
					break;
				case 6:
					num4 = V;
					num3 = num10;
					num2 = num8;
					break;
				case -1:
					num4 = V;
					num3 = num8;
					num2 = num9;
					break;
				default:
					num4 = (num3 = (num2 = V));
					break;
				}
			}
			Color result = default(Color);
			((Color)(ref result))..ctor(num4, num3, num2);
			return result;
		}

		public static Color InverseColor(Color colorIn)
		{
			//IL_0003: 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_0023: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			Color result = default(Color);
			result.r = 1f - colorIn.r;
			result.g = 1f - colorIn.g;
			result.b = 1f - colorIn.b;
			return result;
		}

		public static Color ApplyColorPropertyStep2(Color colorIn, colorPropertyEnum property, Color propertyColor, float f1, float f2, float f3, int LEDindex)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: 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_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_0381: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_041d: Unknown result type (might be due to invalid IL or missing references)
			//IL_042b: Unknown result type (might be due to invalid IL or missing references)
			//IL_043b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0449: Unknown result type (might be due to invalid IL or missing references)
			//IL_0459: Unknown result type (might be due to invalid IL or missing references)
			//IL_0467: Unknown result type (might be due to invalid IL or missing references)
			//IL_04da: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0506: Unknown result type (might be due to invalid IL or missing references)
			//IL_0516: Unknown result type (might be due to invalid IL or missing references)
			//IL_0524: Unknown result type (might be due to invalid IL or missing references)
			//IL_0565: Unknown result type (might be due to invalid IL or missing references)
			//IL_0573: Unknown result type (might be due to invalid IL or missing references)
			//IL_0583: Unknown result type (might be due to invalid IL or missing references)
			//IL_0591: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05af: Unknown result type (might be due to invalid IL or missing references)
			Color result = colorIn;
			switch (property)
			{
			case colorPropertyEnum.None:
				return colorIn;
			case colorPropertyEnum.RainbowWhole:
			{
				if (f1 > 1f)
				{
					f1 = 1f;
				}
				if (f1 < 0f)
				{
					f1 = 0f;
				}
				Color val = HSVToColor(Convert.ToSingle((double)Time.realtimeSinceStartup * 360.0 * (double)f2), 1f, 1f);
				result.r = val.r * f1 + colorIn.r * (1f - f1);
				result.g = val.g * f1 + colorIn.g * (1f - f1);
				result.b = val.b * f1 + colorIn.b * (1f - f1);
				break;
			}
			case colorPropertyEnum.RainbowFlickerFixed:
				if (flickerIntensityFixed.Count != 0)
				{
					Color val2 = HSVToColor(flickerIntensityFixed[LEDindex] * 360f, 1f, 1f);
					result.r = val2.r * f1 + colorIn.r * (1f - f1);
					result.g = val2.g * f1 + colorIn.g * (1f - f1);
					result.b = val2.b * f1 + colorIn.b * (1f - f1);
				}
				break;
			case colorPropertyEnum.FlickerFixed:
				if (flickerIntensityFixed.Count != 0)
				{
					float num3 = flickerIntensityFixed[LEDindex] * f1;
					result.r = colorIn.r * (1f - num3) + propertyColor.r * num3;
					result.g = colorIn.g * (1f - num3) + propertyColor.g * num3;
					result.b = colorIn.b * (1f - num3) + propertyColor.b * num3;
				}
				break;
			case colorPropertyEnum.InverseColors:
				result = InverseColor(colorIn);
				break;
			case colorPropertyEnum.Brighten:
				result = Permutators.Brighten(colorIn, f1);
				break;
			case colorPropertyEnum.CheckerboardInverseColor:
			{
				int num5 = 1;
				if (f2 > 0f)
				{
					num5 = (int)Math.Round(Time.realtimeSinceStartup * f2) % 2;
				}
				if (LEDindex % 2 == num5)
				{
					result = InverseColor(colorIn);
				}
				break;
			}
			case colorPropertyEnum.CheckerboardColor:
			{
				int num4 = 1;
				if (f1 > 1f)
				{
					f1 = 1f;
				}
				if (f2 > 0f)
				{
					num4 = (int)Math.Round(Time.realtimeSinceStartup * f2) % 2;
				}
				if (LEDindex % 2 == num4)
				{
					if (f3 > 0f)
					{
						f1 *= 0.5f + 0.5f * Convert.ToSingle(Math.Sin((double)(Time.realtimeSinceStartup * 2f) * Math.PI * (double)f3));
					}
					result.r = colorIn.r * (1f - f1) + propertyColor.r * f1;
					result.g = colorIn.g * (1f - f1) + propertyColor.g * f1;
					result.b = colorIn.b * (1f - f1) + propertyColor.b * f1;
				}
				break;
			}
			case colorPropertyEnum.Colorfy:
				if (f1 > 1f)
				{
					f1 = 1f;
				}
				result = Permutators.Colorfy(colorIn, propertyColor, f1);
				break;
			case colorPropertyEnum.SnakeColor:
			{
				int num2 = (int)Math.Round(f3);
				for (int j = 0; j < num2; j++)
				{
					if ((int)Math.Round(Time.realtimeSinceStartup * f2) % maxLEDCount == LEDindex - j)
					{
						result.r = colorIn.r * (1f - f1) + propertyColor.r * f1;
						result.g = colorIn.g * (1f - f1) + propertyColor.g * f1;
						result.b = colorIn.b * (1f - f1) + propertyColor.b * f1;
					}
				}
				break;
			}
			case colorPropertyEnum.DoubleSnakeColor:
			{
				int num = (int)Math.Round(f3);
				for (int i = 0; i < num; i++)
				{
					if ((int)Math.Round(Time.realtimeSinceStartup * f2) % maxLEDCount == LEDindex - i)
					{
						result.r = colorIn.r * (1f - f1) + propertyColor.r * f1;
						result.g = colorIn.g * (1f - f1) + propertyColor.g * f1;
						result.b = colorIn.b * (1f - f1) + propertyColor.b * f1;
					}
					if (((int)(0.0 - Math.Round(Time.realtimeSinceStartup * f2)) % maxLEDCount + maxLEDCount) % maxLEDCount == LEDindex - i)
					{
						result.r = colorIn.r * (1f - f1) + propertyColor.r * f1;
						result.g = colorIn.g * (1f - f1) + propertyColor.g * f1;
						result.b = colorIn.b * (1f - f1) + propertyColor.b * f1;
					}
				}
				break;
			}
			}
			return result;
		}

		public static Color ApplyColorPropertyStep1(Color colorIn, styleRankColoringScheme data, int settingsIndex, int LEDindex, int propertyNum)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			colorPropertyEnum property = colorPropertyEnum.None;
			float f = 0f;
			float f2 = 0f;
			float f3 = 0f;
			Color propertyColor = Color.black;
			switch (propertyNum)
			{
			case 1:
				property = data.property1;
				f = data.property1Float1;
				f2 = data.property1Float2;
				f3 = data.property1Float3;
				propertyColor = data.property1Color;
				break;
			case 2:
				property = data.property2;
				f = data.property2Float1;
				f2 = data.property2Float2;
				f3 = data.property2Float3;
				propertyColor = data.property2Color;
				break;
			case 3:
				property = data.property3;
				f = data.property3Float1;
				f2 = data.property3Float2;
				f3 = data.property3Float3;
				propertyColor = data.property3Color;
				break;
			}
			return ApplyColorPropertyStep2(colorIn, property, propertyColor, f, f2, f3, LEDindex);
		}

		public static Color getColorByRank(int i, int settingsIndex, int LEDindex)
		{
			//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_0017: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			Color white = Color.white;
			styleRankColoringScheme data = styleRankColorSettings[settingsIndex, i + 1];
			white = AlternateColors(data);
			white = FlickerColors(white, data, settingsIndex, LEDindex);
			white = PulsateColors(white, data);
			white = ApplyColorPropertyStep1(white, data, settingsIndex, LEDindex, 1);
			white = ApplyColorPropertyStep1(white, data, settingsIndex, LEDindex, 2);
			return ApplyColorPropertyStep1(white, data, settingsIndex, LEDindex, 3);
		}

		public static Color getCurrentColor(int settingsIndex, int LEDindex)
		{
			//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_00c1: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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_0062: 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_0084: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			Color colorIn = Color.white;
			if (ModConfig.gradientizeRankColors)
			{
				int i = (int)Math.Floor(currentRankFloat);
				int i2 = (int)Math.Ceiling(currentRankFloat);
				float num = currentRankFloat - (float)currentRankInt;
				Color colorByRank = getColorByRank(i, settingsIndex, LEDindex);
				Color colorByRank2 = getColorByRank(i2, settingsIndex, LEDindex);
				colorIn.r = colorByRank.r * (1f - num) + colorByRank2.r * num;
				colorIn.g = colorByRank.g * (1f - num) + colorByRank2.g * num;
				colorIn.b = colorByRank.b * (1f - num) + colorByRank2.b * num;
			}
			else
			{
				colorIn = getColorByRank(currentRankInt, settingsIndex, LEDindex);
			}
			return Permutators.ApplyPermutators(colorIn, LEDindex);
		}

		public static int getSettingsByDeviceIndex(int deviceIndex)
		{
			if (deviceColorSettings.ContainsKey(deviceIndex))
			{
				if (deviceColorSettings[deviceIndex].scheme == styleRankColoringSchemeEnum.Scheme1 && deviceColorSettings[deviceIndex].enabled)
				{
					return 0;
				}
				if (deviceColorSettings[deviceIndex].scheme == styleRankColoringSchemeEnum.Scheme2 && deviceColorSettings[deviceIndex].enabled)
				{
					return 1;
				}
				if (deviceColorSettings[deviceIndex].scheme == styleRankColoringSchemeEnum.Scheme3 && deviceColorSettings[deviceIndex].enabled)
				{
					return 2;
				}
				if (deviceColorSettings[deviceIndex].scheme == styleRankColoringSchemeEnum.Scheme4 && deviceColorSettings[deviceIndex].enabled)
				{
					return 3;
				}
				if (ModConfig.allDevicesConnected)
				{
					return (int)(ModConfig.defaultColoring - 1);
				}
				if (deviceColorSettings[deviceIndex].scheme == styleRankColoringSchemeEnum.None || !deviceColorSettings[deviceIndex].enabled)
				{
					return -1;
				}
			}
			return 0;
		}

		public static void flickerIntensityLogic()
		{
			float realtimeSinceStartup = Time.realtimeSinceStartup;
			for (int i = 0; i < 4; i++)
			{
				if (!connectedSchemes[i])
				{
					continue;
				}
				float flickerFrequency = styleRankColorSettings[i, currentRankInt + 1].flickerFrequency;
				float num = 1f / flickerFrequency;
				if (realtimeSinceStartup > lastFlickerTime[i] + num)
				{
					for (int j = 0; j < maxLEDCount; j++)
					{
						flickerIntensity[i][j] = Convert.ToSingle(random.NextDouble());
						lastFlickerTime[i] = Time.realtimeSinceStartup;
					}
				}
			}
			float num2 = flickerIntensityFixedFrequency;
			float num3 = 1f / num2;
			if (realtimeSinceStartup > lastFlickerTimeFixed + num3)
			{
				for (int k = 0; k < maxLEDCount; k++)
				{
					flickerIntensityFixed[k] = Convert.ToSingle(random.NextDouble());
					lastFlickerTimeFixed = Time.realtimeSinceStartup;
				}
			}
		}

		private void Update()
		{
			//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_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			if (!modEnabled || (Object)(object)MonoSingleton<StyleHUD>.Instance == (Object)null)
			{
				return;
			}
			framesSinceLastRefreshed++;
			if (!(lastTimeRefreshed + 1f / refreshRate < Time.realtimeSinceStartup))
			{
				return;
			}
			lastTimeRefreshed = Time.realtimeSinceStartup;
			connectedSchemes[0] = false;
			connectedSchemes[1] = false;
			connectedSchemes[2] = false;
			connectedSchemes[3] = false;
			for (int i = 0; i < connectedDevices.Count; i++)
			{
				connectedSchemes[getSettingsByDeviceIndex(i)] = true;
			}
			Permutators.actionLogic();
			currentRankInt = MonoSingleton<StyleHUD>.Instance.rankIndex;
			currentRankFloat = (float)currentRankInt + MonoSingleton<StyleHUD>.Instance.currentMeter / (float)MonoSingleton<StyleHUD>.Instance.currentRank.maxMeter;
			if (currentRankFloat < 0f)
			{
				currentRankFloat = -1f;
				currentRankInt = -1;
			}
			if (connected)
			{
				flickerIntensityLogic();
				foreach (Device connectedDevice in connectedDevices)
				{
					int index = connectedDevice.Index;
					int num = 0;
					while (true)
					{
						if (num < colorsBoard[index].Count)
						{
							int settingsByDeviceIndex = getSettingsByDeviceIndex(index);
							if (settingsByDeviceIndex == -1)
							{
								goto end_IL_0248;
							}
							Color currentColor = getCurrentColor(settingsByDeviceIndex, num);
							byte b = (byte)(int)(currentColor.r * 255f);
							byte b2 = (byte)(int)(currentColor.g * 255f);
							byte b3 = (byte)(int)(currentColor.b * 255f);
							colorsBoard[index][num] = new Color(b, b2, b3);
							num++;
							continue;
						}
						Color[] array = (Color[])(object)new Color[colorsBoard[index].Count];
						for (int j = 0; j < array.Length; j++)
						{
							array[j] = colorsBoard[index][j];
						}
						client.UpdateLeds(index, (ReadOnlySpan<Color>)array);
						break;
					}
					continue;
					end_IL_0248:
					break;
				}
			}
			else if (ModConfig.autoConnect && Time.realtimeSinceStartup > nextTimeAttemptAutoconnect)
			{
				ModConfig.connectToOpenRGB();
				nextTimeAttemptAutoconnect = Time.realtimeSinceStartup + 15f;
			}
			framesSinceLastRefreshed = 0;
		}
	}
	public class styleRankColoringScheme
	{
		public Color mainColor;

		public Color secondaryColor;

		public float alternateColorFreq = 0f;

		public float pulsateAmplitude = 0f;

		public float pulsateFrequency = 0f;

		public float flickerAmplitude = 0f;

		public Color flickerColor = Color.black;

		public float flickerFrequency = 0f;

		public colorPropertyEnum property1 = colorPropertyEnum.None;

		public Color property1Color = Color.black;

		public float property1Float1 = 0f;

		public float property1Float2 = 0f;

		public float property1Float3 = 0f;

		public colorPropertyEnum property2 = colorPropertyEnum.None;

		public Color property2Color = Color.black;

		public float property2Float1 = 0f;

		public float property2Float2 = 0f;

		public float property2Float3 = 0f;

		public colorPropertyEnum property3 = colorPropertyEnum.None;

		public Color property3Color = Color.black;

		public float property3Float1 = 0f;

		public float property3Float2 = 0f;

		public float property3Float3 = 0f;
	}
	public enum styleRankColoringSchemeEnum
	{
		None,
		Scheme1,
		Scheme2,
		Scheme3,
		Scheme4
	}
	public enum colorPropertyEnum
	{
		None,
		RainbowWhole,
		RainbowFlickerFixed,
		FlickerFixed,
		InverseColors,
		Brighten,
		CheckerboardInverseColor,
		CheckerboardColor,
		Colorfy,
		SnakeColor,
		DoubleSnakeColor
	}
	public class deviceColoringScheme
	{
		public bool enabled = false;

		public styleRankColoringSchemeEnum scheme = styleRankColoringSchemeEnum.None;
	}
	public class ModConfig
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static BoolValueChangeEventDelegate <>9__6_1;

			public static BoolValueChangeEventDelegate <>9__6_2;

			public static FloatValueChangeEventDelegate <>9__6_3;

			public static FloatValueChangeEventDelegate <>9__6_4;

			public static EnumValueChangeEventDelegate<styleRankColoringSchemeEnum> <>9__17_0;

			public static BoolValueChangeEventDelegate <>9__17_1;

			internal void <createConfig>b__6_1(BoolValueChangeEvent e)
			{
				autoConnect = e.value;
			}

			internal void <createConfig>b__6_2(BoolValueChangeEvent e)
			{
				gradientizeRankColors = e.value;
			}

			internal void <createConfig>b__6_3(FloatValueChangeEvent e)
			{
				Plugin.flickerIntensityFixedFrequency = e.value;
			}

			internal void <createConfig>b__6_4(FloatValueChangeEvent e)
			{
				Plugin.refreshRate = e.value;
			}

			internal void <fillConnectedDevicesPanel>b__17_0(EnumValueChangeEvent<styleRankColoringSchemeEnum> e)
			{
				defaultColoring = e.value;
			}

			internal void <fillConnectedDevicesPanel>b__17_1(BoolValueChangeEvent e)
			{
				allDevicesConnected = e.value;
			}
		}

		private static string DefaultParentFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? "";

		public static bool gradientizeRankColors = false;

		public static ConfigPanel connectedDevicesPanel;

		public static ButtonField connectButton;

		public static bool autoConnect = false;

		public static string[] styleNames = new string[9] { "No Rank", "Destructive", "Chaotic", "Brutal", "Anarchic", "Supreme", "SSadistic", "SSShitstorm", "ULTRAKILL" };

		public static Color[] styleColors = (Color[])(object)new Color[9]
		{
			Color.grey,
			Color.blue,
			Color.green,
			Color.yellow,
			Color.magenta,
			Color.red,
			Color.red,
			Color.red,
			Color.white
		};

		public static Dictionary<int, ConfigPanel> deviceConfigPanels = new Dictionary<int, ConfigPanel>();

		public static Dictionary<int, ConfigHeader> deviceConfigHeaders = new Dictionary<int, ConfigHeader>();

		public static ConfigDivision enableRestDevicesDivision;

		public static bool allDevicesConnected = false;

		public static styleRankColoringSchemeEnum defaultColoring = styleRankColoringSchemeEnum.None;

		public static void connectToOpenRGB()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			OpenRgbClient val = null;
			if (!Plugin.connected || Plugin.client == null)
			{
				val = (Plugin.client = new OpenRgbClient("127.0.0.1", 6742, "OpenRGB.NET", true, 1000, 4u));
				try
				{
					val.Connect();
				}
				catch (Exception)
				{
					Plugin.logger.LogInfo((object)"could not connect to OpenRGB");
				}
				Plugin.logger.LogInfo((object)"Connected to OpenRGB");
			}
			else
			{
				val = Plugin.client;
			}
			Plugin[] plugins = val.GetPlugins();
			Device[] allControllerData = val.GetAllControllerData();
			string[] profiles = val.GetProfiles();
			Plugin.logger.LogInfo((object)"Found devices:");
			Device[] array = allControllerData;
			foreach (Device val2 in array)
			{
				Plugin.connectedDevices.Add(val2);
				Plugin.logger.LogInfo((object)val2.Name);
				List<Color> list = new List<Color>(val2.Leds.Length);
				for (int j = 0; j < val2.Leds.Length; j++)
				{
					list.Add(new Color(byte.MaxValue, byte.MaxValue, byte.MaxValue));
				}
				Plugin.colorsBoard[val2.Index] = list;
				if (Plugin.maxLEDCount < val2.Leds.Length)
				{
					Plugin.maxLEDCount = val2.Leds.Length;
				}
			}
			Plugin.flickerIntensity[0] = new List<float>();
			Plugin.flickerIntensity[1] = new List<float>();
			Plugin.flickerIntensity[2] = new List<float>();
			Plugin.flickerIntensity[3] = new List<float>();
			Plugin.flickerIntensityFixed = new List<float>();
			for (int k = 0; k < Plugin.maxLEDCount; k++)
			{
				Plugin.flickerIntensity[0].Add(0f);
				Plugin.flickerIntensity[1].Add(0f);
				Plugin.flickerIntensity[2].Add(0f);
				Plugin.flickerIntensity[3].Add(0f);
				Plugin.flickerIntensityFixed.Add(0f);
			}
			Plugin.connected = true;
			refillConnectedDevicePanels();
		}

		public static void createConfig()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Expected O, but got Unknown
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Expected O, but got Unknown
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Expected O, but got Unknown
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Expected O, but got Unknown
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Expected O, but got Unknown
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Expected O, but got Unknown
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Expected O, but got Unknown
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Expected O, but got Unknown
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Expected O, but got Unknown
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Expected O, but got Unknown
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Expected O, but got Unknown
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Expected O, but got Unknown
			PluginConfigurator val = PluginConfigurator.Create("UltraRGBLighting", "UltraRGBLighting");
			val.SetIconWithURL(Path.Combine(DefaultParentFolder, "icon.png") ?? "");
			connectButton = new ButtonField(val.rootPanel, "Connect", "button.connectButton");
			connectButton.onClick += new OnClick(connectToOpenRGB);
			BoolField val2 = new BoolField(val.rootPanel, "Mod Enabled", "modEnabled", true);
			ConfigDivision division = new ConfigDivision(val.rootPanel, "division");
			val2.onValueChange += (BoolValueChangeEventDelegate)delegate(BoolValueChangeEvent e)
			{
				Plugin.modEnabled = e.value;
				((ConfigField)division).interactable = e.value;
			};
			Plugin.modEnabled = val2.value;
			((ConfigField)division).interactable = val2.value;
			BoolField val3 = new BoolField((ConfigPanel)(object)division, "Attempt Autoconnect Periodically", "autoconnectfield", false);
			object obj = <>c.<>9__6_1;
			if (obj == null)
			{
				BoolValueChangeEventDelegate val4 = delegate(BoolValueChangeEvent e)
				{
					autoConnect = e.value;
				};
				<>c.<>9__6_1 = val4;
				obj = (object)val4;
			}
			val3.onValueChange += (BoolValueChangeEventDelegate)obj;
			autoConnect = val3.value;
			BoolField val5 = new BoolField((ConfigPanel)(object)division, "Gradientize Colors between Ranks", "stylerankcolorsgradientize", false);
			object obj2 = <>c.<>9__6_2;
			if (obj2 == null)
			{
				BoolValueChangeEventDelegate val6 = delegate(BoolValueChangeEvent e)
				{
					gradientizeRankColors = e.value;
				};
				<>c.<>9__6_2 = val6;
				obj2 = (object)val6;
			}
			val5.onValueChange += (BoolValueChangeEventDelegate)obj2;
			gradientizeRankColors = val5.value;
			FloatField val7 = new FloatField((ConfigPanel)(object)division, "Fixed Flicker Frequency", "fixedflickerfrequency", 0f, 0f, 1000f);
			object obj3 = <>c.<>9__6_3;
			if (obj3 == null)
			{
				FloatValueChangeEventDelegate val8 = delegate(FloatValueChangeEvent e)
				{
					Plugin.flickerIntensityFixedFrequency = e.value;
				};
				<>c.<>9__6_3 = val8;
				obj3 = (object)val8;
			}
			val7.onValueChange += (FloatValueChangeEventDelegate)obj3;
			Plugin.flickerIntensityFixedFrequency = val7.value;
			connectedDevicesPanel = new ConfigPanel((ConfigPanel)(object)division, "Connected Devices Settings", "connectedDevicesPanel");
			fillConnectedDevicesPanel(connectedDevicesPanel);
			ConfigPanel rootPanel = new ConfigPanel((ConfigPanel)(object)division, "Style Rank Settings", "styleranksettingsPanel");
			for (int i = 0; i < 4; i++)
			{
				createEntireStyleColoringPanel(rootPanel, i);
			}
			ConfigPanel val9 = new ConfigPanel((ConfigPanel)(object)division, "Permutator Settings", "permutatorsettingsPanel");
			new ConfigHeader(val9, "Permutators are handled sequentially in order", 15);
			for (int j = 0; j < 15; j++)
			{
				createPermutatorPanel(val9, j);
			}
			new ConfigHeader((ConfigPanel)(object)division, "Increase refresh rate for more responsiveness on RGB device, decrease to reduce load on game.", 18);
			FloatField val10 = new FloatField((ConfigPanel)(object)division, "Refresh rate (Hz)", "refreshRate", 50f, 0.1f, 1000f);
			object obj4 = <>c.<>9__6_4;
			if (obj4 == null)
			{
				FloatValueChangeEventDelegate val11 = delegate(FloatValueChangeEvent e)
				{
					Plugin.refreshRate = e.value;
				};
				<>c.<>9__6_4 = val11;
				obj4 = (object)val11;
			}
			val10.onValueChange += (FloatValueChangeEventDelegate)obj4;
			Plugin.refreshRate = val10.value;
		}

		public static void changePermutatorPanel(PermutatorCause pc, colorPropertyEnum property, BoolField boolField, FloatField lengthField, FloatField ff1, FloatField ff2, FloatField ff3, ColorField colorField)
		{
			changePropertyFieldNames(property, ff1, ff2, ff3, colorField);
			switch (pc)
			{
			case PermutatorCause.None:
				((ConfigField)boolField).interactable = false;
				((ConfigField)boolField).displayName = "N/A";
				((ConfigField)lengthField).displayName = "Effect Duration";
				break;
			case PermutatorCause.RecentDamage:
				((ConfigField)boolField).interactable = false;
				((ConfigField)boolField).displayName = "N/A";
				((ConfigField)lengthField).displayName = "Damage Sensitivity";
				break;
			case PermutatorCause.RecentKills:
				((ConfigField)boolField).interactable = false;
				((ConfigField)boolField).displayName = "N/A";
				((ConfigField)lengthField).displayName = "Kill Sensitivity";
				break;
			case PermutatorCause.RecentStyle:
				((ConfigField)boolField).interactable = false;
				((ConfigField)boolField).displayName = "N/A";
				((ConfigField)lengthField).displayName = "Style Sensitivity";
				break;
			case PermutatorCause.OnDamage:
				((ConfigField)boolField).interactable = true;
				((ConfigField)boolField).displayName = "Scale Time With Damage";
				((ConfigField)lengthField).displayName = "Effect Duration";
				break;
			case PermutatorCause.OnKill:
				((ConfigField)boolField).interactable = true;
				((ConfigField)boolField).displayName = "Scale Time With Kill Size";
				((ConfigField)lengthField).displayName = "Effect Duration";
				break;
			case PermutatorCause.OnPlayerDeath:
				((ConfigField)boolField).interactable = false;
				((ConfigField)boolField).displayName = "N/A";
				((ConfigField)lengthField).displayName = "Effect Duration";
				break;
			case PermutatorCause.OnRankGain:
				((ConfigField)boolField).interactable = false;
				((ConfigField)boolField).displayName = "N/A";
				((ConfigField)lengthField).displayName = "Effect Duration";
				break;
			case PermutatorCause.OnRankLose:
				((ConfigField)boolField).interactable = false;
				((ConfigField)boolField).displayName = "N/A";
				((ConfigField)lengthField).displayName = "Effect Duration";
				break;
			case PermutatorCause.OnStyleGain:
				((ConfigField)boolField).interactable = true;
				((ConfigField)boolField).displayName = "Scale With Style Gained";
				((ConfigField)lengthField).displayName = "Effect Duration";
				break;
			case PermutatorCause.OnTakeDamage:
				((ConfigField)boolField).interactable = true;
				((ConfigField)boolField).displayName = "Scale With Damage Taken";
				((ConfigField)lengthField).displayName = "Effect Duration";
				break;
			case PermutatorCause.Always:
				((ConfigField)boolField).interactable = false;
				((ConfigField)boolField).displayName = "N/A";
				((ConfigField)lengthField).displayName = "Effect Duration";
				break;
			}
		}

		public static void createPermutatorPanel(ConfigPanel rootPanel, int i)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Expected O, but got Unknown
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Expected O, but got Unknown
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Expected O, but got Unknown
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Expected O, but got Unknown
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Expected O, but got Unknown
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Expected O, but got Unknown
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Expected O, but got Unknown
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Expected O, but got Unknown
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Expected O, but got Unknown
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Expected O, but got Unknown
			ConfigPanel val = new ConfigPanel(rootPanel, "Permutator " + (i + 1), "permutatorPanel" + i);
			EnumField<PermutatorCause> causeField = new EnumField<PermutatorCause>(val, "Permutator Cause", "permutatorCause" + i, PermutatorCause.None);
			BoolField scaleWithCauseField = new BoolField(val, "Scale With Cause Magnitude", "permutatorscalecause" + i, false);
			scaleWithCauseField.onValueChange += (BoolValueChangeEventDelegate)delegate(BoolValueChangeEvent e)
			{
				Permutators.permutatorArr[i].scaleWithCauseMagnitude = e.value;
			};
			Permutators.permutatorArr[i].scaleWithCauseMagnitude = scaleWithCauseField.value;
			EnumField<colorPropertyEnum> effectField = new EnumField<colorPropertyEnum>(val, "Permutator Effect", "permutatorEffect" + i, colorPropertyEnum.None);
			EnumField<FadeEnum> val2 = new EnumField<FadeEnum>(val, "Permutator Fade Type", "permutatorfade" + i, FadeEnum.Linear);
			val2.onValueChange += delegate(EnumValueChangeEvent<FadeEnum> e)
			{
				Permutators.permutatorArr[i].fadeType = e.value;
			};
			Permutators.permutatorArr[i].fadeType = val2.value;
			FloatField lengthField = new FloatField(val, "Effect Duration", "permutatorEffectduration" + i, 0f, 0f, 100f);
			lengthField.onValueChange += (FloatValueChangeEventDelegate)delegate(FloatValueChangeEvent e)
			{
				Permutators.permutatorArr[i].length = e.value;
			};
			Permutators.permutatorArr[i].length = lengthField.value;
			ColorField colorField = new ColorField(val, "Effect Color (if applicable)", "permutatorEffectColor" + i, Color.white);
			colorField.onValueChange += (ColorValueChangeEventDelegate)delegate(ColorValueChangeEvent e)
			{
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				Permutators.permutatorArr[i].propertyColor = e.value;
			};
			Permutators.permutatorArr[i].propertyColor = colorField.value;
			FloatField propertyValue1Field = new FloatField(val, "Value 1", "permutatorfloat1" + i, 0f, 0f, 1000f);
			propertyValue1Field.onValueChange += (FloatValueChangeEventDelegate)delegate(FloatValueChangeEvent e)
			{
				Permutators.permutatorArr[i].propertyFloat1 = e.value;
			};
			Permutators.permutatorArr[i].propertyFloat1 = propertyValue1Field.value;
			FloatField propertyValue2Field = new FloatField(val, "Value 2", "permutatorfloat2" + i, 0f, 0f, 1000f);
			propertyValue2Field.onValueChange += (FloatValueChangeEventDelegate)delegate(FloatValueChangeEvent e)
			{
				Permutators.permutatorArr[i].propertyFloat2 = e.value;
			};
			Permutators.permutatorArr[i].propertyFloat2 = propertyValue2Field.value;
			FloatField propertyValue3Field = new FloatField(val, "Value 3", "permutatorfloat3" + i, 0f, 0f, 1000f);
			propertyValue3Field.onValueChange += (FloatValueChangeEventDelegate)delegate(FloatValueChangeEvent e)
			{
				Permutators.permutatorArr[i].propertyFloat3 = e.value;
			};
			Permutators.permutatorArr[i].propertyFloat3 = propertyValue3Field.value;
			causeField.onValueChange += delegate(EnumValueChangeEvent<PermutatorCause> e)
			{
				Permutators.permutatorArr[i].cause = e.value;
				changePermutatorPanel(e.value, effectField.value, scaleWithCauseField, lengthField, propertyValue1Field, propertyValue2Field, propertyValue3Field, colorField);
			};
			Permutators.permutatorArr[i].cause = causeField.value;
			effectField.onValueChange += delegate(EnumValueChangeEvent<colorPropertyEnum> e)
			{
				Permutators.permutatorArr[i].property = e.value;
				changePermutatorPanel(causeField.value, e.value, scaleWithCauseField, lengthField, propertyValue1Field, propertyValue2Field, propertyValue3Field, colorField);
			};
			Permutators.permutatorArr[i].property = effectField.value;
			changePermutatorPanel(causeField.value, effectField.value, scaleWithCauseField, lengthField, propertyValue1Field, propertyValue2Field, propertyValue3Field, colorField);
		}

		public static void createEntireStyleColoringPanel(ConfigPanel rootPanel, int i)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			ConfigPanel rootPanel2 = new ConfigPanel(rootPanel, "Style Rank Colors Config " + (i + 1), "configPanelX" + i);
			for (int j = 0; j < 9; j++)
			{
				createStyleRankColoringSchemePanel(rootPanel2, i, j);
			}
		}

		public static void changePropertyFieldNames(colorPropertyEnum property, FloatField ff1, FloatField ff2, FloatField ff3, ColorField colorField)
		{
			((ConfigField)ff3).displayName = "N/A";
			((ConfigField)ff3).interactable = false;
			switch (property)
			{
			case colorPropertyEnum.None:
				((ConfigField)ff1).displayName = "N/A";
				((ConfigField)ff2).displayName = "N/A";
				((ConfigField)ff1).interactable = false;
				((ConfigField)ff2).interactable = false;
				((ConfigField)colorField).interactable = false;
				break;
			case colorPropertyEnum.RainbowWhole:
				((ConfigField)ff1).displayName = "Intensity";
				((ConfigField)ff2).displayName = "Frequency";
				((ConfigField)ff1).interactable = true;
				((ConfigField)ff2).interactable = true;
				((ConfigField)colorField).interactable = false;
				break;
			case colorPropertyEnum.RainbowFlickerFixed:
				((ConfigField)ff1).displayName = "Intensity Of Flicker";
				((ConfigField)ff2).displayName = "Frequency Of Fixed Flicker";
				((ConfigField)ff1).interactable = true;
				((ConfigField)ff2).interactable = false;
				((ConfigField)colorField).interactable = false;
				break;
			case colorPropertyEnum.FlickerFixed:
				((ConfigField)ff1).displayName = "Intensity Of Flicker";
				((ConfigField)ff2).displayName = "Frequency Of Fixed Flicker";
				((ConfigField)ff1).interactable = true;
				((ConfigField)ff2).interactable = false;
				((ConfigField)colorField).interactable = true;
				break;
			case colorPropertyEnum.InverseColors:
				((ConfigField)ff1).displayName = "N/A";
				((ConfigField)ff2).displayName = "N/A";
				((ConfigField)ff1).interactable = false;
				((ConfigField)ff2).interactable = false;
				((ConfigField)colorField).interactable = false;
				break;
			case colorPropertyEnum.Brighten:
				((ConfigField)ff1).displayName = "Intensity";
				((ConfigField)ff2).displayName = "N/A";
				((ConfigField)ff1).interactable = true;
				((ConfigField)ff2).interactable = false;
				((ConfigField)colorField).interactable = false;
				break;
			case colorPropertyEnum.CheckerboardInverseColor:
				((ConfigField)ff1).displayName = "N/A";
				((ConfigField)ff2).displayName = "Frequency of Swapping";
				((ConfigField)ff1).interactable = false;
				((ConfigField)ff2).interactable = true;
				((ConfigField)colorField).interactable = false;
				break;
			case colorPropertyEnum.CheckerboardColor:
				((ConfigField)ff1).displayName = "Color Intensity";
				((ConfigField)ff2).displayName = "Frequency of Swapping";
				((ConfigField)ff3).displayName = "Frequency of Pulsating";
				((ConfigField)ff1).interactable = true;
				((ConfigField)ff2).interactable = true;
				((ConfigField)ff3).interactable = true;
				((ConfigField)colorField).interactable = true;
				break;
			case colorPropertyEnum.Colorfy:
				((ConfigField)ff1).displayName = "Color Intensity";
				((ConfigField)ff2).displayName = "N/A";
				((ConfigField)ff1).interactable = true;
				((ConfigField)ff2).interactable = false;
				((ConfigField)colorField).interactable = true;
				break;
			case colorPropertyEnum.SnakeColor:
				((ConfigField)ff1).displayName = "Color Intensity";
				((ConfigField)ff2).displayName = "Speed";
				((ConfigField)ff3).displayName = "Length (rounded)";
				((ConfigField)ff1).interactable = true;
				((ConfigField)ff2).interactable = true;
				((ConfigField)ff3).interactable = true;
				((ConfigField)colorField).interactable = true;
				break;
			case colorPropertyEnum.DoubleSnakeColor:
				((ConfigField)ff1).displayName = "Color Intensity";
				((ConfigField)ff2).displayName = "Speed";
				((ConfigField)ff3).displayName = "Length (rounded)";
				((ConfigField)ff1).interactable = true;
				((ConfigField)ff2).interactable = true;
				((ConfigField)ff3).interactable = true;
				((ConfigField)colorField).interactable = true;
				break;
			}
		}

		public static void createStyleRankColoringSchemePanel(ConfigPanel rootPanel, int index, int j)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Expected O, but got Unknown
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Expected O, but got Unknown
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Expected O, but got Unknown
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: 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_017b: Expected O, but got Unknown
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Expected O, but got Unknown
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Expected O, but got Unknown
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Expected O, but got Unknown
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Expected O, but got Unknown
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Expected O, but got Unknown
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Expected O, but got Unknown
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Expected O, but got Unknown
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Expected O, but got Unknown
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_0360: Expected O, but got Unknown
			//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c4: Expected O, but got Unknown
			//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d7: Expected O, but got Unknown
			//IL_0402: Unknown result type (might be due to invalid IL or missing references)
			//IL_0410: Unknown result type (might be due to invalid IL or missing references)
			//IL_0475: Unknown result type (might be due to invalid IL or missing references)
			//IL_047a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0484: Expected O, but got Unknown
			//IL_0491: Unknown result type (might be due to invalid IL or missing references)
			//IL_049b: Expected O, but got Unknown
			//IL_04b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bd: 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_0507: Expected O, but got Unknown
			//IL_0514: Unknown result type (might be due to invalid IL or missing references)
			//IL_051e: Expected O, but got Unknown
			//IL_0580: Unknown result type (might be due to invalid IL or missing references)
			//IL_058a: Expected O, but got Unknown
			//IL_0597: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a1: Expected O, but got Unknown
			//IL_0603: Unknown result type (might be due to invalid IL or missing references)
			//IL_060d: Expected O, but got Unknown
			//IL_061a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0624: Expected O, but got Unknown
			//IL_06ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0713: Unknown result type (might be due to invalid IL or missing references)
			//IL_0718: Unknown result type (might be due to invalid IL or missing references)
			//IL_0722: Expected O, but got Unknown
			//IL_072f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0739: Expected O, but got Unknown
			//IL_0756: Unknown result type (might be due to invalid IL or missing references)
			//IL_075b: Unknown result type (might be due to invalid IL or missing references)
			//IL_079b: Unknown result type (might be due to invalid IL or missing references)
			//IL_07a5: Expected O, but got Unknown
			//IL_07b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_07bc: Expected O, but got Unknown
			//IL_081e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0828: Expected O, but got Unknown
			//IL_0835: Unknown result type (might be due to invalid IL or missing references)
			//IL_083f: Expected O, but got Unknown
			//IL_08a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ab: Expected O, but got Unknown
			//IL_08b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_08c2: Expected O, but got Unknown
			//IL_094c: Unknown result type (might be due to invalid IL or missing references)
			//IL_09b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_09b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_09c0: Expected O, but got Unknown
			//IL_09cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_09d7: Expected O, but got Unknown
			//IL_09f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_09f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a39: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a43: Expected O, but got Unknown
			//IL_0a50: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a5a: Expected O, but got Unknown
			//IL_0abc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ac6: Expected O, but got Unknown
			//IL_0ad3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0add: Expected O, but got Unknown
			//IL_0b3f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b49: Expected O, but got Unknown
			//IL_0b56: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b60: Expected O, but got Unknown
			ConfigPanel val = new ConfigPanel(rootPanel, styleNames[j], "stylerankpanel" + j + " " + index);
			ColorField val2 = new ColorField(val, "Main Color", "stylerankMainColor" + j + " " + index, styleColors[j]);
			val2.onValueChange += (ColorValueChangeEventDelegate)delegate(ColorValueChangeEvent e)
			{
				//IL_0018: 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)
				Plugin.styleRankColorSettings[index, j].mainColor = e.value;
			};
			Plugin.styleRankColorSettings[index, j].mainColor = val2.value;
			new ConfigHeader(val, "Alternate Color only used if Color Alternate Frequency > 0", 12);
			ColorField val3 = new ColorField(val, "Alternate Color", "stylerankAltColor" + j + " " + index, Color.cyan);
			val3.onValueChange += (ColorValueChangeEventDelegate)delegate(ColorValueChangeEvent e)
			{
				//IL_0018: 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)
				Plugin.styleRankColorSettings[index, j].secondaryColor = e.value;
			};
			Plugin.styleRankColorSettings[index, j].secondaryColor = val3.value;
			FloatField val4 = new FloatField(val, "Color Alternate Frequency", "colorAlternateFrequency" + j + " " + index, 0f, 0f, 1000f);
			val4.onValueChange += (FloatValueChangeEventDelegate)delegate(FloatValueChangeEvent e)
			{
				Plugin.styleRankColorSettings[index, j].alternateColorFreq = e.value;
			};
			Plugin.styleRankColorSettings[index, j].alternateColorFreq = val4.value;
			FloatField val5 = new FloatField(val, "Flicker Frequency", "flickerFrequency" + j + " " + index, 0f, 0f, 1000f);
			val5.onValueChange += (FloatValueChangeEventDelegate)delegate(FloatValueChangeEvent e)
			{
				Plugin.styleRankColorSettings[index, j].flickerFrequency = e.value;
			};
			Plugin.styleRankColorSettings[index, j].flickerFrequency = val5.value;
			ColorField val6 = new ColorField(val, "Flicker Color", "flickerColor" + j + " " + index, Color.black);
			val6.onValueChange += (ColorValueChangeEventDelegate)delegate(ColorValueChangeEvent e)
			{
				//IL_0018: 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)
				Plugin.styleRankColorSettings[index, j].flickerColor = e.value;
			};
			Plugin.styleRankColorSettings[index, j].flickerColor = val6.value;
			FloatField val7 = new FloatField(val, "Flicker Intensity", "flickerIntensity" + j + " " + index, 0f, 0f, 1f);
			val7.onValueChange += (FloatValueChangeEventDelegate)delegate(FloatValueChangeEvent e)
			{
				Plugin.styleRankColorSettings[index, j].flickerAmplitude = e.value;
			};
			Plugin.styleRankColorSettings[index, j].flickerAmplitude = val7.value;
			FloatField val8 = new FloatField(val, "Pulsate Frequency", "pulsateFrequency" + j + " " + index, 0f, 0f, 1000f);
			val8.onValueChange += (FloatValueChangeEventDelegate)delegate(FloatValueChangeEvent e)
			{
				Plugin.styleRankColorSettings[index, j].pulsateFrequency = e.value;
			};
			Plugin.styleRankColorSettings[index, j].pulsateFrequency = val8.value;
			FloatField val9 = new FloatField(val, "Pulsate Intensity", "pulsateIntensity" + j + " " + index, 0f, 0f, 1f);
			val9.onValueChange += (FloatValueChangeEventDelegate)delegate(FloatValueChangeEvent e)
			{
				Plugin.styleRankColorSettings[index, j].pulsateAmplitude = e.value;
			};
			Plugin.styleRankColorSettings[index, j].pulsateAmplitude = val9.value;
			new ConfigHeader(val, "Additional Properties", 24);
			new ConfigHeader(val, "Property 1", 15);
			EnumField<colorPropertyEnum> val10 = new EnumField<colorPropertyEnum>(val, "Property 1", "property1" + j + " " + index, colorPropertyEnum.None);
			ColorField filter1ColorField = new ColorField(val, "Property 1 Color", "property1color" + j + " " + index, Color.black);
			filter1ColorField.onValueChange += (ColorValueChangeEventDelegate)delegate(ColorValueChangeEvent e)
			{
				//IL_0018: 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)
				Plugin.styleRankColorSettings[index, j].property1Color = e.value;
			};
			Plugin.styleRankColorSettings[index, j].property1Color = filter1ColorField.value;
			FloatField additionalFilter1Float1Field = new FloatField(val, "Property 1 Value 1", "property1float1" + j + " " + index, 0f, 0f, 1000f);
			additionalFilter1Float1Field.onValueChange += (FloatValueChangeEventDelegate)delegate(FloatValueChangeEvent e)
			{
				Plugin.styleRankColorSettings[index, j].property1Float1 = e.value;
			};
			Plugin.styleRankColorSettings[index, j].property1Float1 = additionalFilter1Float1Field.value;
			FloatField additionalFilter1Float2Field = new FloatField(val, "Property 1 Value 2", "property1float2" + j + " " + index, 0f, 0f, 1000f);
			additionalFilter1Float2Field.onValueChange += (FloatValueChangeEventDelegate)delegate(FloatValueChangeEvent e)
			{
				Plugin.styleRankColorSettings[index, j].property1Float2 = e.value;
			};
			Plugin.styleRankColorSettings[index, j].property1Float2 = additionalFilter1Float2Field.value;
			FloatField additionalFilter1Float3Field = new FloatField(val, "Property 1 Value 3", "property1float3" + j + " " + index, 0f, 0f, 1000f);
			additionalFilter1Float3Field.onValueChange += (FloatValueChangeEventDelegate)delegate(FloatValueChangeEvent e)
			{
				Plugin.styleRankColorSettings[index, j].property1Float3 = e.value;
			};
			Plugin.styleRankColorSettings[index, j].property1Float3 = additionalFilter1Float3Field.value;
			val10.onValueChange += delegate(EnumValueChangeEvent<colorPropertyEnum> e)
			{
				Plugin.styleRankColorSettings[index, j].property1 = e.value;
				changePropertyFieldNames(e.value, additionalFilter1Float1Field, additionalFilter1Float2Field, additionalFilter1Float3Field, filter1ColorField);
			};
			Plugin.styleRankColorSettings[index, j].property1 = val10.value;
			changePropertyFieldNames(val10.value, additionalFilter1Float1Field, additionalFilter1Float2Field, additionalFilter1Float3Field, filter1ColorField);
			new ConfigHeader(val, "Property 2", 15);
			EnumField<colorPropertyEnum> val11 = new EnumField<colorPropertyEnum>(val, "Property 2", "property2" + j + " " + index, colorPropertyEnum.None);
			ColorField filter2ColorField = new ColorField(val, "Property 2 Color", "property2color" + j + " " + index, Color.black);
			filter2ColorField.onValueChange += (ColorValueChangeEventDelegate)delegate(ColorValueChangeEvent e)
			{
				//IL_0018: 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)
				Plugin.styleRankColorSettings[index, j].property2Color = e.value;
			};
			Plugin.styleRankColorSettings[index, j].property2Color = filter2ColorField.value;
			FloatField additionalFilter2Float1Field = new FloatField(val, "Property 2 Value 1", "property2float1" + j + " " + index, 0f, 0f, 1000f);
			additionalFilter2Float1Field.onValueChange += (FloatValueChangeEventDelegate)delegate(FloatValueChangeEvent e)
			{
				Plugin.styleRankColorSettings[index, j].property2Float1 = e.value;
			};
			Plugin.styleRankColorSettings[index, j].property2Float1 = additionalFilter2Float1Field.value;
			FloatField additionalFilter2Float2Field = new FloatField(val, "Property 2 Value 2", "property2float2" + j + " " + index, 0f, 0f, 1000f);
			additionalFilter2Float2Field.onValueChange += (FloatValueChangeEventDelegate)delegate(FloatValueChangeEvent e)
			{
				Plugin.styleRankColorSettings[index, j].property2Float2 = e.value;
			};
			Plugin.styleRankColorSettings[index, j].property2Float2 = additionalFilter2Float2Field.value;
			FloatField additionalFilter2Float3Field = new FloatField(val, "Property 2 Value 3", "property2float3" + j + " " + index, 0f, 0f, 1000f);
			additionalFilter2Float3Field.onValueChange += (FloatValueChangeEventDelegate)delegate(FloatValueChangeEvent e)
			{
				Plugin.styleRankColorSettings[index, j].property2Float3 = e.value;
			};
			Plugin.styleRankColorSettings[index, j].property2Float3 = additionalFilter2Float3Field.value;
			val11.onValueChange += delegate(EnumValueChangeEvent<colorPropertyEnum> e)
			{
				Plugin.styleRankColorSettings[index, j].property2 = e.value;
				changePropertyFieldNames(e.value, additionalFilter2Float1Field, additionalFilter2Float2Field, additionalFilter2Float3Field, filter2ColorField);
			};
			Plugin.styleRankColorSettings[index, j].property2 = val11.value;
			changePropertyFieldNames(val11.value, additionalFilter2Float1Field, additionalFilter2Float2Field, additionalFilter2Float3Field, filter2ColorField);
			new ConfigHeader(val, "Property 3", 15);
			EnumField<colorPropertyEnum> val12 = new EnumField<colorPropertyEnum>(val, "Property 3", "property3" + j + " " + index, colorPropertyEnum.None);
			ColorField filter3ColorField = new ColorField(val, "Property 3 Color", "property3color" + j + " " + index, Color.black);
			filter3ColorField.onValueChange += (ColorValueChangeEventDelegate)delegate(ColorValueChangeEvent e)
			{
				//IL_0018: 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)
				Plugin.styleRankColorSettings[index, j].property3Color = e.value;
			};
			Plugin.styleRankColorSettings[index, j].property3Color = filter3ColorField.value;
			FloatField additionalFilter3Float1Field = new FloatField(val, "Property 3 Value 1", "property3float1" + j + " " + index, 0f, 0f, 1000f);
			additionalFilter3Float1Field.onValueChange += (FloatValueChangeEventDelegate)delegate(FloatValueChangeEvent e)
			{
				Plugin.styleRankColorSettings[index, j].property3Float1 = e.value;
			};
			Plugin.styleRankColorSettings[index, j].property3Float1 = additionalFilter3Float1Field.value;
			FloatField additionalFilter3Float2Field = new FloatField(val, "Property 3 Value 2", "property3float2" + j + " " + index, 0f, 0f, 1000f);
			additionalFilter3Float2Field.onValueChange += (FloatValueChangeEventDelegate)delegate(FloatValueChangeEvent e)
			{
				Plugin.styleRankColorSettings[index, j].property3Float2 = e.value;
			};
			Plugin.styleRankColorSettings[index, j].property3Float2 = additionalFilter3Float2Field.value;
			FloatField additionalFilter3Float3Field = new FloatField(val, "Property 3 Value 3", "property3float3" + j + " " + index, 0f, 0f, 1000f);
			additionalFilter3Float3Field.onValueChange += (FloatValueChangeEventDelegate)delegate(FloatValueChangeEvent e)
			{
				Plugin.styleRankColorSettings[index, j].property3Float3 = e.value;
			};
			Plugin.styleRankColorSettings[index, j].property3Float3 = additionalFilter3Float3Field.value;
			val12.onValueChange += delegate(EnumValueChangeEvent<colorPropertyEnum> e)
			{
				Plugin.styleRankColorSettings[index, j].property3 = e.value;
				changePropertyFieldNames(e.value, additionalFilter3Float1Field, additionalFilter3Float2Field, additionalFilter3Float3Field, filter3ColorField);
			};
			Plugin.styleRankColorSettings[index, j].property3 = val12.value;
			changePropertyFieldNames(val12.value, additionalFilter3Float1Field, additionalFilter3Float2Field, additionalFilter3Float3Field, filter3ColorField);
		}

		public static void fillConnectedDevicesPanel(ConfigPanel rootPanel)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Expected O, but got Unknown
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Expected O, but got Unknown
			EnumField<styleRankColoringSchemeEnum> val = new EnumField<styleRankColoringSchemeEnum>(rootPanel, "Default Color Scheme", "defaultColorSchemeField", styleRankColoringSchemeEnum.Scheme1);
			val.onValueChange += delegate(EnumValueChangeEvent<styleRankColoringSchemeEnum> e)
			{
				defaultColoring = e.value;
			};
			defaultColoring = val.value;
			BoolField val2 = new BoolField(rootPanel, "Connect All Devices", "connectAllDevicesField", true);
			enableRestDevicesDivision = new ConfigDivision(rootPanel, "enableRestDevicesDivision");
			object obj = <>c.<>9__17_1;
			if (obj == null)
			{
				BoolValueChangeEventDelegate val3 = delegate(BoolValueChangeEvent e)
				{
					allDevicesConnected = e.value;
				};
				<>c.<>9__17_1 = val3;
				obj = (object)val3;
			}
			val2.onValueChange += (BoolValueChangeEventDelegate)obj;
			allDevicesConnected = val2.value;
			foreach (Device connectedDevice in Plugin.connectedDevices)
			{
				int index = connectedDevice.Index;
				ConfigHeader value = new ConfigHeader((ConfigPanel)(object)enableRestDevicesDivision, connectedDevice.Name, 18);
				ConfigPanel val4 = new ConfigPanel((ConfigPanel)(object)enableRestDevicesDivision, "Device " + index, "devicepanel" + index);
				createConnectedDevicePanel(val4, index);
				deviceConfigPanels[index] = val4;
				deviceConfigHeaders[index] = value;
			}
		}

		public static void checkForDeviceColorSettingsOfIExists(int i)
		{
			if (!Plugin.deviceColorSettings.ContainsKey(i))
			{
				Plugin.deviceColorSettings[i] = new deviceColoringScheme();
			}
		}

		public static void createConnectedDevicePanel(ConfigPanel rootPanel, int index)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			checkForDeviceColorSettingsOfIExists(index);
			BoolField val = new BoolField(rootPanel, "Enabled for this device", "deviceEnabledField", false);
			val.onValueChange += (BoolValueChangeEventDelegate)delegate(BoolValueChangeEvent e)
			{
				checkForDeviceColorSettingsOfIExists(index);
				Plugin.deviceColorSettings[index].enabled = e.value;
			};
			Plugin.deviceColorSettings[index].enabled = val.value;
			EnumField<styleRankColoringSchemeEnum> val2 = new EnumField<styleRankColoringSchemeEnum>(rootPanel, "Device Color Scheme", "deviceColorSchemeField", styleRankColoringSchemeEnum.None);
			val2.onValueChange += delegate(EnumValueChangeEvent<styleRankColoringSchemeEnum> e)
			{
				checkForDeviceColorSettingsOfIExists(index);
				Plugin.deviceColorSettings[index].scheme = e.value;
			};
			Plugin.deviceColorSettings[index].scheme = val2.value;
		}

		public static void refillConnectedDevicePanels()
		{
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Expected O, but got Unknown
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Expected O, but got Unknown
			foreach (int key in deviceConfigHeaders.Keys)
			{
				ConfigHeader val = deviceConfigHeaders[key];
				val.text = "Device not connected";
				for (int i = 0; i < Plugin.connectedDevices.Count; i++)
				{
					if (key == Plugin.connectedDevices[i].Index)
					{
						val.text = Plugin.connectedDevices[i].Name;
					}
				}
			}
			foreach (ConfigPanel value2 in deviceConfigPanels.Values)
			{
				((ConfigField)value2).interactable = false;
			}
			foreach (Device connectedDevice in Plugin.connectedDevices)
			{
				if (deviceConfigPanels.ContainsKey(connectedDevice.Index))
				{
					((ConfigField)deviceConfigPanels[connectedDevice.Index]).interactable = true;
					continue;
				}
				ConfigHeader value = new ConfigHeader((ConfigPanel)(object)enableRestDevicesDivision, connectedDevice.Name, 18);
				ConfigPanel val2 = new ConfigPanel((ConfigPanel)(object)enableRestDevicesDivision, "Device " + connectedDevice.Index, "devicepanel" + connectedDevice.Index);
				createConnectedDevicePanel(val2, connectedDevice.Index);
				deviceConfigPanels[connectedDevice.Index] = val2;
				deviceConfigHeaders[connectedDevice.Index] = value;
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "UltraRGBLighting";

		public const string PLUGIN_NAME = "UltraRGBLighting";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}