Decompiled source of Run Verifier v2.0.5
Jdenticon.dll
Decompiled 3 weeks ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.ComponentModel.Design.Serialization; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.IO.Compression; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using Jdenticon.Drawing; using Jdenticon.Drawing.Png; using Jdenticon.Drawing.Rasterization; using Jdenticon.IO; using Jdenticon.Rendering; using Jdenticon.Shapes; using Microsoft.CodeAnalysis; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("Jdenticon .NET Standard 2.1")] [assembly: AssemblyDescription("Jdenticon is an open source library for generating highly recognizable identicons.")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Jdenticon")] [assembly: AssemblyCopyright("Copyright © Daniel Mester Pirttijärvi 2016-2021")] [assembly: AssemblyTrademark("")] [assembly: AssemblyFileVersion("3.1.2.0")] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")] [assembly: AssemblyVersion("3.1.2.0")] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [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; } } } namespace Jdenticon { internal static class NumericList { public static char GetSeparator(IFormatProvider formatProvider) { if (formatProvider == null) { throw new ArgumentNullException("formatProvider"); } string text = ((formatProvider.GetFormat(typeof(NumberFormatInfo)) is NumberFormatInfo numberFormatInfo) ? numberFormatInfo.NumberDecimalSeparator : null); if (string.IsNullOrEmpty(text) || text[0] != ',') { return ','; } return ';'; } public static string Join<T>(IEnumerable<T> items, IFormatProvider formatProvider) { if (items == null) { throw new ArgumentNullException("items"); } if (formatProvider == null) { throw new ArgumentNullException("formatProvider"); } string value = GetSeparator(formatProvider) + " "; StringBuilder stringBuilder = new StringBuilder(); foreach (T item in items) { if (stringBuilder.Length > 0) { stringBuilder.Append(value); } stringBuilder.Append(Convert.ToString(item, formatProvider)); } return stringBuilder.ToString(); } public static string[] Parse(string? str, IFormatProvider formatProvider) { if (formatProvider == null) { throw new ArgumentNullException("formatProvider"); } if (str != null) { str = str.Trim(); if (str.Length > 0) { char separator = GetSeparator(formatProvider); return Regex.Split(str.Trim(), "\\s*" + separator + "\\s*|\\s+"); } } return new string[0]; } } public class RangeConverter : TypeConverter { private readonly Type rangeType; public RangeConverter() { } protected RangeConverter(Type type) { rangeType = type; } public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { if (!(sourceType == typeof(string))) { return base.CanConvertFrom(context, sourceType); } return true; } public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string str) { Type type = rangeType ?? context?.PropertyDescriptor?.PropertyType; if (type != null && type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Range<>)) { Type conversionType = type.GetGenericArguments()[0]; CultureInfo cultureInfo = culture ?? CultureInfo.InvariantCulture; string[] array = NumericList.Parse(str, cultureInfo); if (array.Length != 0 && array.Length < 3) { object obj2; object obj; if (array.Length == 1) { obj2 = (obj = Convert.ChangeType(array[0], conversionType, cultureInfo)); } else { obj2 = Convert.ChangeType(array[0], conversionType, cultureInfo); obj = Convert.ChangeType(array[1], conversionType, cultureInfo); } return Activator.CreateInstance(type, obj2, obj); } } } return base.ConvertFrom(context, culture, value); } public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (!(destinationType == typeof(InstanceDescriptor)) && !(destinationType == typeof(string))) { return base.CanConvertTo(context, destinationType); } return true; } public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (value != null) { Type type = value.GetType(); if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Range<>)) { object value2 = type.GetProperty("From").GetValue(value, null); object value3 = type.GetProperty("To").GetValue(value, null); if (destinationType == typeof(InstanceDescriptor)) { Type type2 = type.GetGenericArguments()[0]; ConstructorInfo constructor = type.GetConstructor(new Type[2] { type2, type2 }); if (constructor != null) { return new InstanceDescriptor(constructor, new object[2] { value2, value3 }, isComplete: true); } } else if (destinationType == typeof(string)) { CultureInfo cultureInfo = culture ?? CultureInfo.InvariantCulture; string text = Convert.ToString(value2, cultureInfo); if (!object.Equals(value2, value3)) { text = text + NumericList.GetSeparator(cultureInfo) + " " + Convert.ToString(value3, cultureInfo); } return text; } } } return base.ConvertTo(context, culture, value, destinationType); } } public static class HashGenerator { public static byte[] ComputeHash(object? value, string hashAlgorithmName) { string s = ((!(value is IFormattable formattable)) ? ((value == null) ? "" : value.ToString()) : formattable.ToString(null, CultureInfo.InvariantCulture)); byte[] bytes = Encoding.UTF8.GetBytes(s); return ComputeHash(bytes, hashAlgorithmName); } private static byte[] ComputeHash(byte[] value, string hashAlgorithmName) { using HashAlgorithm hashAlgorithm = CreateHashAlgorithm(hashAlgorithmName); return hashAlgorithm.ComputeHash(value); } private static HashAlgorithm CreateHashAlgorithm(string name) { object obj = CryptoConfig.CreateFromName(name); if (obj is HashAlgorithm result) { return result; } if (obj is IDisposable disposable) { disposable.Dispose(); } throw new ArgumentException("Unknown hash algorithm '" + name + "'.", "name"); } } public enum ExportImageFormat { Png, Svg } public class IdenticonRequest { private byte[]? hash; private IdenticonStyle? style; private int size; private static readonly int[] DefaultSizes = new int[7] { 16, 32, 48, 64, 128, 256, 512 }; public byte[] Hash { get { if (hash == null) { hash = new byte[10] { 218, 57, 163, 238, 94, 107, 175, 216, 7, 9 }; } return hash; } set { if (value == null) { throw new ArgumentNullException("value"); } if (value.Length < 6) { throw new ArgumentException("The hash must contain at least 10 bytes.", "value"); } hash = value; } } public ExportImageFormat Format { get; set; } public IdenticonStyle Style { get { if (style == null) { style = Identicon.DefaultStyle.Clone(); } return style; } set { style = value; } } public int Size { get { return size; } set { size = Math.Max(value, 1); } } private static byte ComputeChecksum(byte[] buffer, int offset, int count) { byte b = 0; for (int i = 0; i < count; i++) { b = (byte)(((b << 1) | (b >> 7)) ^ buffer[offset + i]); } return b; } public static bool TryParse(string? requestString, [NotNullWhen(true)] out IdenticonRequest request) { if (requestString != null && requestString.Length != 0 && requestString.Length <= 50) { char[] array = requestString.ToCharArray(); int num = ((array[0] == '?') ? 1 : 0); for (int i = num; i < array.Length; i++) { switch (array[i]) { case '-': array[i] = '='; break; case '_': array[i] = '/'; break; case '~': array[i] = '+'; break; } } byte[] array2; try { array2 = Convert.FromBase64CharArray(array, num, array.Length - num); } catch { goto IL_0309; } byte b = ComputeChecksum(array2, 1, array2.Length - 1); if (b == array2[0]) { request = new IdenticonRequest(); try { using MemoryStream memoryStream = new MemoryStream(array2, 1, array2.Length - 1); using BinaryReader binaryReader = new BinaryReader(memoryStream); byte b2 = binaryReader.ReadByte(); request.size = ((b2 == byte.MaxValue) ? binaryReader.ReadUInt16() : ((b2 < DefaultSizes.Length) ? DefaultSizes[b2] : ((b2 - DefaultSizes.Length) * 5))); byte b3 = binaryReader.ReadByte(); request.Format = (ExportImageFormat)((b3 >> 1) & 7); if ((b3 & 1) == 1) { float padding = (float)Math.Round((float)(int)binaryReader.ReadByte() / 637f, 3); byte alpha = binaryReader.ReadByte(); byte red = binaryReader.ReadByte(); byte green = binaryReader.ReadByte(); byte blue = binaryReader.ReadByte(); float from = (float)Math.Round((float)(int)binaryReader.ReadByte() / 255f, 3); float to = (float)Math.Round((float)(int)binaryReader.ReadByte() / 255f, 3); float from2 = (float)Math.Round((float)(int)binaryReader.ReadByte() / 255f, 3); float to2 = (float)Math.Round((float)(int)binaryReader.ReadByte() / 255f, 3); float colorSaturation = (float)Math.Round((float)(int)binaryReader.ReadByte() / 255f, 3); request.Hash = binaryReader.ReadBytes(10); float grayscaleSaturation = ((memoryStream.Position < memoryStream.Length) ? ((float)Math.Round((float)(int)binaryReader.ReadByte() / 255f, 3)) : IdenticonStyle.DefaultGrayscaleSaturation); request.style = new IdenticonStyle { Padding = padding, BackColor = Color.FromArgb(alpha, red, green, blue), ColorLightness = Range.Create(from2, to2), GrayscaleLightness = Range.Create(from, to), ColorSaturation = colorSaturation, GrayscaleSaturation = grayscaleSaturation }; int num2 = ((memoryStream.Position < memoryStream.Length) ? binaryReader.ReadByte() : 0); for (int j = 0; j < num2; j++) { float hue = (float)Math.Round((float)(int)binaryReader.ReadByte() / 255f, 3); request.style.Hues.Add(hue); } } else { request.Hash = binaryReader.ReadBytes(10); } } catch (EndOfStreamException) { goto IL_0309; } if (request.size <= 1000) { return true; } } } goto IL_0309; IL_0309: request = null; return false; } public override string ToString() { using MemoryStream memoryStream = new MemoryStream(50); using BinaryWriter binaryWriter = new BinaryWriter(memoryStream); binaryWriter.Write((byte)0); int num = ((IList<int>)DefaultSizes).IndexOf(size); if (num >= 0) { binaryWriter.Write((byte)num); } else if (size % 5 == 0 && size <= (254 - DefaultSizes.Length) * 5) { binaryWriter.Write((byte)(DefaultSizes.Length + size / 5)); } else { binaryWriter.Write(byte.MaxValue); binaryWriter.Write((ushort)size); } IdenticonStyle identiconStyle = ((style != null && !style.Equals(Identicon.DefaultStyle)) ? style : null); int format = (int)Format; binaryWriter.Write((byte)((uint)(format << 1) | ((identiconStyle != null) ? 1u : 0u))); if (identiconStyle != null) { binaryWriter.Write((byte)(identiconStyle.Padding * 637f)); binaryWriter.Write((byte)identiconStyle.BackColor.A); binaryWriter.Write((byte)identiconStyle.BackColor.R); binaryWriter.Write((byte)identiconStyle.BackColor.G); binaryWriter.Write((byte)identiconStyle.BackColor.B); binaryWriter.Write((byte)(identiconStyle.GrayscaleLightness.From * 255f)); binaryWriter.Write((byte)(identiconStyle.GrayscaleLightness.To * 255f)); binaryWriter.Write((byte)(identiconStyle.ColorLightness.From * 255f)); binaryWriter.Write((byte)(identiconStyle.ColorLightness.To * 255f)); binaryWriter.Write((byte)(identiconStyle.ColorSaturation * 255f)); } byte[] array = Hash; if (array.Length != 10) { binaryWriter.Write(array, 0, 6); binaryWriter.Write(array, array.Length - 4, 4); } else { binaryWriter.Write(array); } if (identiconStyle != null) { binaryWriter.Write((byte)(identiconStyle.GrayscaleSaturation * 255f)); int count = identiconStyle.Hues.Count; binaryWriter.Write((byte)count); for (int i = 0; i < count; i++) { binaryWriter.Write((byte)(identiconStyle.Hues[i] * 255f)); } } binaryWriter.Flush(); byte[] buffer = memoryStream.GetBuffer(); int num2 = (int)memoryStream.Length; byte b = ComputeChecksum(buffer, 1, num2 - 1); buffer[0] = b; char[] array2 = new char[num2 * 2]; int num3 = Convert.ToBase64CharArray(buffer, 0, num2, array2, 0); for (int j = 0; j < num3; j++) { switch (array2[j]) { case '=': array2[j] = '-'; break; case '/': array2[j] = '_'; break; case '+': array2[j] = '~'; break; } } return new string(array2, 0, num3); } } internal static class HexString { private const string HexCharacters = "0123456789abcdef"; public static string ToString(byte[] array) { if (array == null) { throw new ArgumentNullException("array"); } char[] array2 = new char[array.Length * 2]; for (int i = 0; i < array.Length; i++) { array2[i * 2] = "0123456789abcdef"[array[i] >> 4]; array2[i * 2 + 1] = "0123456789abcdef"[array[i] & 0xF]; } return new string(array2); } public static byte[] ToArray(string hexString) { if (hexString == null) { throw new ArgumentNullException("hexString"); } if (hexString.Length % 2 == 1) { throw new FormatException("The hexadecimal string had an unexpected length."); } byte[] array = new byte[hexString.Length / 2]; for (int i = 0; i < hexString.Length; i += 2) { char value = char.ToLowerInvariant(hexString[i]); char value2 = char.ToLowerInvariant(hexString[i + 1]); int num = "0123456789abcdef".IndexOf(value); int num2 = "0123456789abcdef".IndexOf(value2); if (num < 0 || num2 < 0) { throw new FormatException("Invalid characters were found in the hexadecimal string."); } array[i / 2] = (byte)((num << 4) | num2); } return array; } } public class Identicon { private byte[] hash; private int size; private IconGenerator? iconGenerator; private IdenticonStyle? style; private static IdenticonStyle defaultStyle = new IdenticonStyle(); public int Size { get { return size; } set { if (value < 1) { throw new ArgumentOutOfRangeException("Size", value, "The size should be 1 pixel or larger."); } size = value; } } public IconGenerator IconGenerator { get { if (iconGenerator == null) { iconGenerator = new IconGenerator(); } return iconGenerator; } set { iconGenerator = value; } } public IdenticonStyle Style { get { if (style == null) { style = DefaultStyle.Clone(); } return style; } set { style = value; } } public static IdenticonStyle DefaultStyle { get { return defaultStyle; } set { defaultStyle = value ?? new IdenticonStyle(); } } public byte[] Hash { get { byte[] array = new byte[hash.Length]; Buffer.BlockCopy(hash, 0, array, 0, hash.Length); return array; } } public Identicon(byte[] hash, int size) { if (hash == null) { throw new ArgumentNullException("hash"); } if (hash.Length < 6) { throw new ArgumentException("hash", "The hash array was too short. At least 6 bytes are required."); } if (size < 1) { throw new ArgumentOutOfRangeException("size", size, "The size should be 1 pixel or larger."); } this.size = size; if (hash.Length <= 10) { this.hash = new byte[hash.Length]; Buffer.BlockCopy(hash, 0, this.hash, 0, hash.Length); } else { this.hash = new byte[10]; Buffer.BlockCopy(hash, 0, this.hash, 0, 6); Buffer.BlockCopy(hash, hash.Length - 4, this.hash, this.hash.Length - 4, 4); } } public static Identicon FromHash(byte[] hash, int size) { return new Identicon(hash, size); } public static Identicon FromHash(string hash, int size) { if (hash == null) { throw new ArgumentNullException("hash"); } return new Identicon(HexString.ToArray(hash), size); } public static Identicon FromValue(object? value, int size, string hashAlgorithmName = "SHA1") { return new Identicon(HashGenerator.ComputeHash(value, hashAlgorithmName), size); } public void Draw(Renderer renderer) { Draw(renderer, new Rectangle(0, 0, Size, Size)); } public void Draw(Renderer renderer, Rectangle rect) { IconGenerator.Generate(renderer, rect, Style, hash); renderer.Flush(); } [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("The Draw method now includes padding. You don't need to pass a rectangle to Draw.")] public Rectangle GetIconBounds() { return new Rectangle(0, 0, size, size); } public override string ToString() { return "Identicon: " + HexString.ToString(hash); } } [CompilerGenerated] internal static class NamespaceDoc { } public static class PngExtensions { private static byte[] GeneratePng(this Identicon icon) { PngRenderer pngRenderer = new PngRenderer(icon.Size, icon.Size); icon.Draw(pngRenderer); using MemoryStream memoryStream = new MemoryStream(); pngRenderer.SavePng(memoryStream); return memoryStream.ToArray(); } public static void SaveAsPng(this Identicon icon, Stream stream) { if (stream == null) { throw new ArgumentNullException("stream"); } byte[] array = icon.GeneratePng(); stream.Write(array, 0, array.Length); } public static Stream SaveAsPng(this Identicon icon) { byte[] buffer = icon.GeneratePng(); return new MemoryStream(buffer, writable: false); } public static void SaveAsPng(this Identicon icon, string path) { if (path == null) { throw new ArgumentNullException("path"); } using FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write); byte[] array = icon.GeneratePng(); fileStream.Write(array, 0, array.Length); } public static Task SaveAsPngAsync(this Identicon icon, Stream stream) { if (stream == null) { throw new ArgumentNullException("stream"); } byte[] array = icon.GeneratePng(); return stream.WriteAsync(array, 0, array.Length); } public static async Task SaveAsPngAsync(this Identicon icon, string path) { if (path == null) { throw new ArgumentNullException("path"); } using FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write); byte[] array = icon.GeneratePng(); await stream.WriteAsync(array, 0, array.Length); } } public class IdenticonStyle : IEquatable<IdenticonStyle?> { private HueCollection hues; private Color backColor; private float padding; private float colorSaturation; private float grayscaleSaturation; private Range<float> colorLightness; private Range<float> grayscaleLightness; public static float DefaultPadding => 0.08f; public static Range<float> DefaultColorLightness => Range.Create(0.4f, 0.8f); public static Range<float> DefaultGrayscaleLightness => Range.Create(0.3f, 0.9f); [Obsolete("Use DefaultColorSaturation instead.")] [EditorBrowsable(EditorBrowsableState.Never)] public static float DefaultSaturation => DefaultColorSaturation; public static float DefaultColorSaturation => 0.5f; public static float DefaultGrayscaleSaturation => 0f; public static Color DefaultBackColor => Color.White; public HueCollection Hues { get { return hues; } set { hues = value ?? new HueCollection(); } } public Color BackColor { get { return backColor; } set { backColor = value; } } public float Padding { get { return padding; } set { if (value < 0f || value > 0.4f) { throw new ArgumentOutOfRangeException("Padding", value, "Only padding values in the range [0.0, 0.4] are valid."); } padding = value; } } [Obsolete("Use ColorSaturation instead.")] [EditorBrowsable(EditorBrowsableState.Never)] [Browsable(false)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public float Saturation { get { return ColorSaturation; } set { ColorSaturation = value; } } public float ColorSaturation { get { return colorSaturation; } set { if (value < 0f || value > 1f) { throw new ArgumentOutOfRangeException("ColorSaturation", value, "Only saturation values in the range [0.0, 1.0] are allowed."); } colorSaturation = value; } } public float GrayscaleSaturation { get { return grayscaleSaturation; } set { if (value < 0f || value > 1f) { throw new ArgumentOutOfRangeException("GrayscaleSaturation", value, "Only saturation values in the range [0.0, 1.0] are allowed."); } grayscaleSaturation = value; } } public Range<float> ColorLightness { get { return colorLightness; } set { if (value.From < 0f || value.From > 1f) { throw new ArgumentOutOfRangeException("ColorLightness.From", value.From, "Only lightness values in the range [0.0, 1.0] are allowed."); } if (value.To < 0f || value.To > 1f) { throw new ArgumentOutOfRangeException("ColorLightness.To", value.To, "Only lightness values in the range [0.0, 1.0] are allowed."); } colorLightness = value; } } public Range<float> GrayscaleLightness { get { return grayscaleLightness; } set { if (value.From < 0f || value.From > 1f) { throw new ArgumentOutOfRangeException("GrayscaleLightness.From", value.From, "Only lightness values in the range [0.0, 1.0] are allowed."); } if (value.To < 0f || value.To > 1f) { throw new ArgumentOutOfRangeException("GrayscaleLightness.To", value.To, "Only lightness values in the range [0.0, 1.0] are allowed."); } grayscaleLightness = value; } } public IdenticonStyle() { hues = new HueCollection(); backColor = DefaultBackColor; padding = DefaultPadding; colorSaturation = DefaultColorSaturation; grayscaleSaturation = DefaultGrayscaleSaturation; colorLightness = DefaultColorLightness; grayscaleLightness = DefaultGrayscaleLightness; } private IdenticonStyle(IdenticonStyle otherStyleToClone) { hues = new HueCollection(otherStyleToClone.hues); backColor = otherStyleToClone.backColor; padding = otherStyleToClone.padding; colorSaturation = otherStyleToClone.colorSaturation; grayscaleSaturation = otherStyleToClone.grayscaleSaturation; colorLightness = otherStyleToClone.colorLightness; grayscaleLightness = otherStyleToClone.grayscaleLightness; } private bool ShouldSerializeHues() { if (hues != null) { return hues.Count > 0; } return false; } private void ResetHues() { Hues = new HueCollection(); } private bool ShouldSerializeBackColor() { return BackColor != DefaultBackColor; } private void ResetBackColor() { BackColor = DefaultBackColor; } private bool ShouldSerializePadding() { return Padding != DefaultPadding; } private void ResetPadding() { Padding = DefaultPadding; } private bool ShouldSerializeColorSaturation() { return ColorSaturation != DefaultColorSaturation; } private void ResetColorSaturation() { ColorSaturation = DefaultColorSaturation; } private bool ShouldSerializeGrayscaleSaturation() { return GrayscaleSaturation != DefaultGrayscaleSaturation; } private void ResetGrayscaleSaturation() { GrayscaleSaturation = DefaultGrayscaleSaturation; } private bool ShouldSerializeColorLightness() { return ColorLightness != DefaultColorLightness; } private void ResetColorLightness() { ColorLightness = DefaultColorLightness; } private bool ShouldSerializeGrayscaleLightness() { return GrayscaleLightness != DefaultGrayscaleLightness; } private void ResetGrayscaleLightness() { GrayscaleLightness = DefaultGrayscaleLightness; } public override int GetHashCode() { return padding.GetHashCode() ^ colorSaturation.GetHashCode() ^ grayscaleSaturation.GetHashCode() ^ backColor.GetHashCode() ^ colorLightness.GetHashCode() ^ grayscaleLightness.GetHashCode(); } public override bool Equals(object obj) { return Equals(obj as IdenticonStyle); } public bool Equals(IdenticonStyle? other) { if (other != null && other.padding == padding && other.backColor == backColor && other.colorLightness == colorLightness && ((other.grayscaleLightness == grayscaleLightness) & (other.colorSaturation == colorSaturation)) && other.grayscaleSaturation == grayscaleSaturation) { return other.hues.Equals(hues); } return false; } public IdenticonStyle Clone() { return new IdenticonStyle(this); } } public static class SvgExtensions { private static string GenerateSvg(this Identicon icon, bool fragment) { SvgRenderer svgRenderer = new SvgRenderer(icon.Size, icon.Size); icon.Draw(svgRenderer); return svgRenderer.ToSvg(fragment); } private static byte[] GenerateBinarySvg(this Identicon icon, bool fragment) { string text = icon.GenerateSvg(fragment); int byteCount = Encoding.UTF8.GetByteCount(text); byte[] preamble = Encoding.UTF8.GetPreamble(); byte[] array = new byte[byteCount + preamble.Length]; for (int i = 0; i < preamble.Length; i++) { array[i] = preamble[i]; } Encoding.UTF8.GetBytes(text, 0, text.Length, array, preamble.Length); return array; } public static string ToSvg(this Identicon icon) { return icon.ToSvg(fragment: false); } public static string ToSvg(this Identicon icon, bool fragment) { return icon.GenerateSvg(fragment); } public static void SaveAsSvg(this Identicon icon, TextWriter writer) { icon.SaveAsSvg(writer, fragment: false); } public static void SaveAsSvg(this Identicon icon, Stream stream) { icon.SaveAsSvg(stream, fragment: false); } public static void SaveAsSvg(this Identicon icon, string path) { icon.SaveAsSvg(path, fragment: false); } public static void SaveAsSvg(this Identicon icon, TextWriter writer, bool fragment) { if (writer == null) { throw new ArgumentNullException("writer"); } string value = icon.GenerateSvg(fragment); writer.Write(value); } public static void SaveAsSvg(this Identicon icon, Stream stream, bool fragment) { if (stream == null) { throw new ArgumentNullException("stream"); } byte[] array = icon.GenerateBinarySvg(fragment); stream.Write(array, 0, array.Length); } public static Stream SaveAsSvg(this Identicon icon, bool fragment) { byte[] buffer = icon.GenerateBinarySvg(fragment); return new MemoryStream(buffer, writable: false); } public static Stream SaveAsSvg(this Identicon icon) { return icon.SaveAsSvg(fragment: false); } public static void SaveAsSvg(this Identicon icon, string path, bool fragment) { if (path == null) { throw new ArgumentNullException("path"); } using FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write); icon.SaveAsSvg(stream, fragment); } public static Task SaveAsSvgAsync(this Identicon icon, TextWriter writer) { return icon.SaveAsSvgAsync(writer, fragment: false); } public static Task SaveAsSvgAsync(this Identicon icon, Stream stream) { return icon.SaveAsSvgAsync(stream, fragment: false); } public static Task SaveAsSvgAsync(this Identicon icon, string path) { return icon.SaveAsSvgAsync(path, fragment: false); } public static Task SaveAsSvgAsync(this Identicon icon, TextWriter writer, bool fragment) { if (writer == null) { throw new ArgumentNullException("writer"); } string value = icon.GenerateSvg(fragment); return writer.WriteAsync(value); } public static Task SaveAsSvgAsync(this Identicon icon, Stream stream, bool fragment) { if (stream == null) { throw new ArgumentNullException("stream"); } byte[] array = icon.GenerateBinarySvg(fragment); return stream.WriteAsync(array, 0, array.Length); } public static async Task SaveAsSvgAsync(this Identicon icon, string path, bool fragment) { if (path == null) { throw new ArgumentNullException("path"); } using FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write); await icon.SaveAsSvgAsync(stream, fragment); } } public static class Range { public static Range<TValue> Create<TValue>(TValue from, TValue to) where TValue : struct { return new Range<TValue>(from, to); } } [TypeConverter(typeof(RangeConverter))] public struct Range<TValue> : IEquatable<Range<TValue>> where TValue : struct { private TValue from; private TValue to; public TValue From => from; public TValue To => to; public Range(TValue from, TValue to) { this.from = from; this.to = to; } public override int GetHashCode() { return from.GetHashCode() ^ to.GetHashCode(); } public override bool Equals(object obj) { if (obj is Range<TValue>) { return Equals((Range<TValue>)obj); } return false; } public bool Equals(Range<TValue> other) { EqualityComparer<TValue> @default = EqualityComparer<TValue>.Default; if (@default.Equals(other.from, from)) { return @default.Equals(other.to, to); } return false; } public static bool operator ==(Range<TValue> a, Range<TValue> b) { return a.Equals(b); } public static bool operator !=(Range<TValue> a, Range<TValue> b) { return !a.Equals(b); } public override string ToString() { return string.Format(CultureInfo.InvariantCulture, "{0} - {1}", from, to); } } } namespace Jdenticon.Shapes { [CompilerGenerated] internal static class NamespaceDoc { } public class Shape { public ShapeDefinition Definition { get; set; } = delegate { }; public Color Color { get; set; } public ShapePositionCollection Positions { get; set; } = new ShapePositionCollection(); public int StartRotationIndex { get; set; } } public class ShapeCategory { public int ColorIndex { get; set; } public IList<ShapeDefinition> Shapes { get; set; } = new ShapeDefinition[0]; public int ShapeIndex { get; set; } public int? RotationIndex { get; set; } public ShapePositionCollection Positions { get; set; } = new ShapePositionCollection(); } public delegate void ShapeDefinition(Renderer renderer, int cell, int index); public static class ShapeDefinitions { public static IList<ShapeDefinition> CenterShapes { get; } public static IList<ShapeDefinition> OuterShapes { get; } static ShapeDefinitions() { OuterShapes = new ShapeDefinition[4] { delegate(Renderer renderer, int cell, int index) { renderer.AddTriangle(0f, 0f, cell, cell, TriangleDirection.SouthWest); }, delegate(Renderer renderer, int cell, int index) { renderer.AddTriangle(0f, (float)cell / 2f, cell, (float)cell / 2f, TriangleDirection.SouthWest); }, delegate(Renderer renderer, int cell, int index) { renderer.AddRhombus(0f, 0f, cell, cell); }, delegate(Renderer renderer, int cell, int index) { float num19 = (float)cell * 0.16667f; renderer.AddCircle(num19, num19, (float)cell - 2f * num19); } }; CenterShapes = new ShapeDefinition[14] { delegate(Renderer renderer, int cell, int index) { float num18 = (float)cell * 0.42f; renderer.AddPolygon(new PointF[5] { new PointF(0f, 0f), new PointF(cell, 0f), new PointF(cell, (float)cell - num18 * 2f), new PointF((float)cell - num18, cell), new PointF(0f, cell) }); }, delegate(Renderer renderer, int cell, int index) { int num16 = (int)((double)cell * 0.5); int num17 = (int)((double)cell * 0.8); renderer.AddTriangle(cell - num16, 0f, num16, num17, TriangleDirection.NorthEast); }, delegate(Renderer renderer, int cell, int index) { int num15 = cell / 3; renderer.AddRectangle(num15, num15, cell - num15, cell - num15); }, delegate(Renderer renderer, int cell, int index) { float num12 = (float)cell * 0.1f; float num13 = ((num12 > 1f) ? ((float)(int)num12) : (((double)num12 > 0.5) ? 1f : num12)); int num14 = ((cell < 6) ? 1 : ((cell < 8) ? 2 : (cell / 4))); renderer.AddRectangle(num14, num14, (float)cell - num13 - (float)num14, (float)cell - num13 - (float)num14); }, delegate(Renderer renderer, int cell, int index) { int num10 = (int)((double)cell * 0.15); int num11 = (int)((double)cell * 0.5); renderer.AddCircle(cell - num11 - num10, cell - num11 - num10, num11); }, delegate(Renderer renderer, int cell, int index) { float num8 = (float)cell * 0.1f; float num9 = num8 * 4f; if (num9 > 3f) { num9 = (int)num9; } renderer.AddRectangle(0f, 0f, cell, cell); renderer.AddPolygon(new PointF[3] { new PointF(num9, num9), new PointF((float)cell - num8, num9), new PointF(num9 + ((float)cell - num9 - num8) / 2f, (float)cell - num8) }, invert: true); }, delegate(Renderer renderer, int cell, int index) { renderer.AddPolygon(new PointF[6] { new PointF(0f, 0f), new PointF(cell, 0f), new PointF(cell, (float)cell * 0.7f), new PointF((float)cell * 0.4f, (float)cell * 0.4f), new PointF((float)cell * 0.7f, cell), new PointF(0f, cell) }); }, delegate(Renderer renderer, int cell, int index) { renderer.AddTriangle((float)cell / 2f, (float)cell / 2f, (float)cell / 2f, (float)cell / 2f, TriangleDirection.SouthEast); }, delegate(Renderer renderer, int cell, int index) { renderer.AddPolygon(new PointF[5] { new PointF(0f, 0f), new PointF(cell, 0f), new PointF(cell, cell / 2), new PointF(cell / 2, cell), new PointF(0f, cell) }); }, delegate(Renderer renderer, int cell, int index) { float num5 = (float)cell * 0.14f; float num6 = ((cell < 8) ? num5 : ((float)(int)num5)); int num7 = ((cell < 4) ? 1 : ((cell < 6) ? 2 : ((int)((float)cell * 0.35f)))); renderer.AddRectangle(0f, 0f, cell, cell); renderer.AddRectangle(num7, num7, (float)(cell - num7) - num6, (float)(cell - num7) - num6, invert: true); }, delegate(Renderer renderer, int cell, int index) { float num3 = (float)cell * 0.12f; float num4 = num3 * 3f; renderer.AddRectangle(0f, 0f, cell, cell); renderer.AddCircle(num4, num4, (float)cell - num3 - num4, invert: true); }, delegate(Renderer renderer, int cell, int index) { renderer.AddTriangle((float)cell / 2f, (float)cell / 2f, (float)cell / 2f, (float)cell / 2f, TriangleDirection.SouthEast); }, delegate(Renderer renderer, int cell, int index) { float num2 = (float)cell * 0.25f; renderer.AddRectangle(0f, 0f, cell, cell); renderer.AddRhombus(num2, num2, (float)cell - num2, (float)cell - num2, invert: true); }, delegate(Renderer renderer, int cell, int index) { float num = (float)cell * 0.4f; float size = (float)cell * 1.2f; if (index != 0) { renderer.AddCircle(num, num, size); } } }; } } public struct ShapePosition : IEquatable<ShapePosition> { private int x; private int y; public int X => x; public int Y => y; public ShapePosition(int x, int y) { this.x = x; this.y = y; } public override string ToString() { return "{ " + x + ", " + y + " }"; } public override int GetHashCode() { return x ^ y; } public override bool Equals(object? obj) { if (obj is ShapePosition) { return Equals((ShapePosition)obj); } return false; } public bool Equals(ShapePosition other) { if (other.x == x) { return other.y == y; } return false; } public static bool operator ==(ShapePosition a, ShapePosition b) { return a.Equals(b); } public static bool operator !=(ShapePosition a, ShapePosition b) { return !a.Equals(b); } } public class ShapePositionCollection : Collection<ShapePosition> { public void Add(int x, int y) { Add(new ShapePosition(x, y)); } } } namespace Jdenticon.IO { internal class ZlibStream : Stream { private Adler32 adler32 = new Adler32(); private Stream outputStream; private Stream deflateStream; public override bool CanRead => false; public override bool CanSeek => false; public override bool CanWrite => true; public override long Length => deflateStream.Length; public override long Position { get { return deflateStream.Position; } set { throw new NotSupportedException(); } } public ZlibStream(Stream stream) { byte b = 128; int num = (30720 + b % 31) % 31; if (num != 0) { b += (byte)(31 - num); } stream.WriteByte(120); stream.WriteByte(b); outputStream = stream; deflateStream = new DeflateStream(stream, CompressionLevel.Optimal, leaveOpen: true); } public override void Flush() { deflateStream.Flush(); } public override int Read(byte[] buffer, int offset, int count) { throw new NotSupportedException(); } public override long Seek(long offset, SeekOrigin origin) { throw new NotSupportedException(); } public override void SetLength(long value) { throw new NotSupportedException(); } public override void Write(byte[] buffer, int offset, int count) { deflateStream.Write(buffer, offset, count); adler32.Update(buffer, offset, count); } protected override void Dispose(bool disposing) { if (disposing && deflateStream != null) { deflateStream.Flush(); deflateStream.Dispose(); deflateStream = null; outputStream.WriteBigEndian(adler32.Value); } base.Dispose(disposing); } } internal class Adler32 { private uint s1 = 1u; private uint s2; public uint Value => (s2 << 16) + s1; public void Update(byte[] buffer, int offset, int count) { uint num = s1; uint num2 = s2; for (int i = 0; i < count; i++) { num += buffer[offset + i]; if (num2 + num < num2) { num %= 65521; num2 %= 65521; } num2 += num; } s1 = num % 65521; s2 = num2 % 65521; } } internal class Crc32 { private static readonly uint[] crcTable = MakeCrcTable(); private uint crc; public uint Value => crc ^ 0xFFFFFFFFu; public Crc32(uint seed = uint.MaxValue) { crc = seed; } private static uint[] MakeCrcTable() { uint[] array = new uint[256]; for (int i = 0; i < 256; i++) { uint num = (uint)i; for (int j = 0; j < 8; j++) { num = (((num & 1) != 1) ? (num >> 1) : (0xEDB88320u ^ (num >> 1))); } array[i] = num; } return array; } public void Update(byte[] data, int offset, int count) { for (int i = 0; i < count; i++) { crc = crcTable[(crc ^ data[offset + i]) & 0xFF] ^ (crc >> 8); } } } internal static class StreamExtensions { public static void WriteBigEndian(this Stream stream, int value) { stream.WriteBigEndian((uint)value); } public static void WriteBigEndian(this Stream stream, uint uvalue) { byte[] buffer = new byte[4] { (byte)(uvalue >> 24), (byte)((uvalue >> 16) & 0xFFu), (byte)((uvalue >> 8) & 0xFFu), (byte)(uvalue & 0xFFu) }; stream.Write(buffer, 0, 4); } } internal class LeaveOpenStream : Stream { private readonly Stream baseStream; public override bool CanRead => baseStream.CanRead; public override bool CanSeek => baseStream.CanSeek; public override bool CanWrite => baseStream.CanWrite; public override long Length => baseStream.Length; public override long Position { get { return baseStream.Position; } set { baseStream.Position = value; } } public LeaveOpenStream(Stream baseStream) { this.baseStream = baseStream; } public override void Flush() { baseStream.Flush(); } public override int Read(byte[] buffer, int offset, int count) { return baseStream.Read(buffer, offset, count); } public override long Seek(long offset, SeekOrigin origin) { return baseStream.Seek(offset, origin); } public override void SetLength(long value) { baseStream.SetLength(value); } public override void Write(byte[] buffer, int offset, int count) { baseStream.Write(buffer, offset, count); } } } namespace Jdenticon.Rendering { public class HueStringConverter : TypeConverter { public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (!(destinationType == typeof(string)) && !(destinationType == typeof(InstanceDescriptor))) { return base.CanConvertTo(context, destinationType); } return true; } public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (value is HueString hueString) { if (destinationType == typeof(string)) { return hueString.ToString(culture); } if (destinationType == typeof(InstanceDescriptor)) { MethodInfo method = typeof(HueString).GetMethod("Parse", new Type[1] { typeof(string) }); return new InstanceDescriptor(method, new object[1] { hueString.ToString() }); } } return base.ConvertTo(context, culture, value, destinationType); } public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { if (!(sourceType == typeof(string))) { return base.CanConvertFrom(context, sourceType); } return true; } public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string value2) { return HueString.Parse(value2, culture ?? CultureInfo.InvariantCulture); } return base.ConvertFrom(context, culture, value); } } [TypeConverter(typeof(ColorConverter))] public struct Color : IFormattable, IEquatable<Color> { private class NamedCssColors { private static readonly Dictionary<string, uint> namedColors = new Dictionary<string, uint>(StringComparer.OrdinalIgnoreCase) { { "transparent", 0u }, { "antiquewhite", 4209760255u }, { "aqua", 16777215u }, { "aquamarine", 2147472639u }, { "azure", 4043309055u }, { "beige", 4126530815u }, { "bisque", 4293182719u }, { "black", 255u }, { "blanchedalmond", 4293643775u }, { "blue", 65535u }, { "blueviolet", 2318131967u }, { "brown", 2771004159u }, { "burlywood", 3736635391u }, { "cadetblue", 1604231423u }, { "chartreuse", 2147418367u }, { "chocolate", 3530104575u }, { "coral", 4286533887u }, { "cornflowerblue", 1687547391u }, { "cornsilk", 4294499583u }, { "crimson", 3692313855u }, { "cyan", 16777215u }, { "darkblue", 35839u }, { "darkcyan", 9145343u }, { "darkgoldenrod", 3095792639u }, { "darkgray", 2846468607u }, { "darkgreen", 6553855u }, { "darkgrey", 2846468607u }, { "darkkhaki", 3182914559u }, { "darkmagenta", 2332068863u }, { "darkolivegreen", 1433087999u }, { "darkorange", 4287365375u }, { "darkorchid", 2570243327u }, { "darkred", 2332033279u }, { "darksalmon", 3918953215u }, { "darkseagreen", 2411499519u }, { "darkslateblue", 1211993087u }, { "darkslategray", 793726975u }, { "darkslategrey", 793726975u }, { "darkturquoise", 13554175u }, { "darkviolet", 2483082239u }, { "deeppink", 4279538687u }, { "deepskyblue", 12582911u }, { "dimgray", 1768516095u }, { "dimgrey", 1768516095u }, { "dodgerblue", 512819199u }, { "firebrick", 2988581631u }, { "floralwhite", 4294635775u }, { "forestgreen", 579543807u }, { "fuchsia", 4278255615u }, { "gainsboro", 3705462015u }, { "ghostwhite", 4177068031u }, { "gold", 4292280575u }, { "goldenrod", 3668254975u }, { "gray", 2155905279u }, { "green", 8388863u }, { "greenyellow", 2919182335u }, { "grey", 2155905279u }, { "honeydew", 4043305215u }, { "hotpink", 4285117695u }, { "indianred", 3445382399u }, { "indigo", 1258324735u }, { "ivory", 4294963455u }, { "khaki", 4041641215u }, { "lavender", 3873897215u }, { "lavenderblush", 4293981695u }, { "lawngreen", 2096890111u }, { "lemonchiffon", 4294626815u }, { "lightblue", 2916673279u }, { "lightcoral", 4034953471u }, { "lightcyan", 3774873599u }, { "lightgoldenrodyellow", 4210742015u }, { "lightgray", 3553874943u }, { "lightgreen", 2431553791u }, { "lightgrey", 3553874943u }, { "lightpink", 4290167295u }, { "lightsalmon", 4288707327u }, { "lightseagreen", 548580095u }, { "lightskyblue", 2278488831u }, { "lightslategray", 2005441023u }, { "lightslategrey", 2005441023u }, { "lightsteelblue", 2965692159u }, { "lightyellow", 4294959359u }, { "lime", 16711935u }, { "limegreen", 852308735u }, { "linen", 4210091775u }, { "magenta", 4278255615u }, { "maroon", 2147483903u }, { "mediumaquamarine", 1724754687u }, { "mediumblue", 52735u }, { "mediumorchid", 3126187007u }, { "mediumpurple", 2473647103u }, { "mediumseagreen", 1018393087u }, { "mediumslateblue", 2070474495u }, { "mediumspringgreen", 16423679u }, { "mediumturquoise", 1221709055u }, { "mediumvioletred", 3340076543u }, { "midnightblue", 421097727u }, { "mintcream", 4127193855u }, { "mistyrose", 4293190143u }, { "moccasin", 4293178879u }, { "navajowhite", 4292783615u }, { "navy", 33023u }, { "oldlace", 4260751103u }, { "olive", 2155872511u }, { "olivedrab", 1804477439u }, { "orange", 4289003775u }, { "orangered", 4282712319u }, { "orchid", 3664828159u }, { "palegoldenrod", 4008225535u }, { "palegreen", 2566625535u }, { "paleturquoise", 2951671551u }, { "palevioletred", 3681588223u }, { "papayawhip", 4293907967u }, { "peachpuff", 4292524543u }, { "peru", 3448061951u }, { "pink", 4290825215u }, { "plum", 3718307327u }, { "powderblue", 2967529215u }, { "purple", 2147516671u }, { "rebeccapurple", 1714657791u }, { "red", 4278190335u }, { "rosybrown", 3163525119u }, { "royalblue", 1097458175u }, { "saddlebrown", 2336560127u }, { "salmon", 4202722047u }, { "sandybrown", 4104413439u }, { "seagreen", 780883967u }, { "seashell", 4294307583u }, { "sienna", 2689740287u }, { "silver", 3233857791u }, { "skyblue", 2278484991u }, { "slateblue", 1784335871u }, { "slategray", 1887473919u }, { "slategrey", 1887473919u }, { "snow", 4294638335u }, { "springgreen", 16744447u }, { "steelblue", 1182971135u }, { "tan", 3535047935u }, { "teal", 8421631u }, { "thistle", 3636451583u }, { "tomato", 4284696575u }, { "turquoise", 1088475391u }, { "violet", 4001558271u }, { "wheat", 4125012991u }, { "white", uint.MaxValue }, { "whitesmoke", 4126537215u }, { "yellow", 4294902015u }, { "yellowgreen", 2597139199u } }; public static bool TryParse(string input, out Color result) { if (namedColors.TryGetValue(input, out var value)) { result = new Color(value); return true; } result = default(Color); return false; } } private uint value; public static Color Transparent => new Color(0u); public static Color Snow => new Color(4294638335u); public static Color GhostWhite => new Color(4177068031u); public static Color WhiteSmoke => new Color(4126537215u); public static Color Gainsboro => new Color(3705462015u); public static Color FloralWhite => new Color(4294635775u); public static Color OldLace => new Color(4260751103u); public static Color Linen => new Color(4210091775u); public static Color AntiqueWhite => new Color(4209760255u); public static Color PapayaWhip => new Color(4293907967u); public static Color BlanchedAlmond => new Color(4293643775u); public static Color Bisque => new Color(4293182719u); public static Color PeachPuff => new Color(4292524543u); public static Color NavajoWhite => new Color(4292783615u); public static Color Moccasin => new Color(4293178879u); public static Color Cornsilk => new Color(4294499583u); public static Color Ivory => new Color(4294963455u); public static Color LemonChiffon => new Color(4294626815u); public static Color Seashell => new Color(4294307583u); public static Color Honeydew => new Color(4043305215u); public static Color MintCream => new Color(4127193855u); public static Color Azure => new Color(4043309055u); public static Color AliceBlue => new Color(4042850303u); public static Color Lavender => new Color(3873897215u); public static Color LavenderBlush => new Color(4293981695u); public static Color MistyRose => new Color(4293190143u); public static Color White => new Color(uint.MaxValue); public static Color Black => new Color(255u); public static Color DarkSlateGray => new Color(793726975u); public static Color DarkSlateGrey => new Color(793726975u); public static Color DimGray => new Color(1768516095u); public static Color DimGrey => new Color(1768516095u); public static Color SlateGray => new Color(1887473919u); public static Color SlateGrey => new Color(1887473919u); public static Color LightSlateGray => new Color(2005441023u); public static Color LightSlateGrey => new Color(2005441023u); public static Color Gray => new Color(3200171775u); public static Color Grey => new Color(3200171775u); public static Color WebGray => new Color(2155905279u); public static Color WebGrey => new Color(2155905279u); public static Color LightGrey => new Color(3553874943u); public static Color LightGray => new Color(3553874943u); public static Color MidnightBlue => new Color(421097727u); public static Color Navy => new Color(33023u); public static Color NavyBlue => new Color(33023u); public static Color CornflowerBlue => new Color(1687547391u); public static Color DarkSlateBlue => new Color(1211993087u); public static Color SlateBlue => new Color(1784335871u); public static Color MediumSlateBlue => new Color(2070474495u); public static Color LightSlateBlue => new Color(2221998079u); public static Color MediumBlue => new Color(52735u); public static Color RoyalBlue => new Color(1097458175u); public static Color Blue => new Color(65535u); public static Color DodgerBlue => new Color(512819199u); public static Color DeepSkyBlue => new Color(12582911u); public static Color SkyBlue => new Color(2278484991u); public static Color LightSkyBlue => new Color(2278488831u); public static Color SteelBlue => new Color(1182971135u); public static Color LightSteelBlue => new Color(2965692159u); public static Color LightBlue => new Color(2916673279u); public static Color PowderBlue => new Color(2967529215u); public static Color PaleTurquoise => new Color(2951671551u); public static Color DarkTurquoise => new Color(13554175u); public static Color MediumTurquoise => new Color(1221709055u); public static Color Turquoise => new Color(1088475391u); public static Color Cyan => new Color(16777215u); public static Color Aqua => new Color(16777215u); public static Color LightCyan => new Color(3774873599u); public static Color CadetBlue => new Color(1604231423u); public static Color MediumAquamarine => new Color(1724754687u); public static Color Aquamarine => new Color(2147472639u); public static Color DarkGreen => new Color(6553855u); public static Color DarkOliveGreen => new Color(1433087999u); public static Color DarkSeaGreen => new Color(2411499519u); public static Color SeaGreen => new Color(780883967u); public static Color MediumSeaGreen => new Color(1018393087u); public static Color LightSeaGreen => new Color(548580095u); public static Color PaleGreen => new Color(2566625535u); public static Color SpringGreen => new Color(16744447u); public static Color LawnGreen => new Color(2096890111u); public static Color Green => new Color(16711935u); public static Color Lime => new Color(16711935u); public static Color WebGreen => new Color(8388863u); public static Color Chartreuse => new Color(2147418367u); public static Color MediumSpringGreen => new Color(16423679u); public static Color GreenYellow => new Color(2919182335u); public static Color LimeGreen => new Color(852308735u); public static Color YellowGreen => new Color(2597139199u); public static Color ForestGreen => new Color(579543807u); public static Color OliveDrab => new Color(1804477439u); public static Color DarkKhaki => new Color(3182914559u); public static Color Khaki => new Color(4041641215u); public static Color PaleGoldenrod => new Color(4008225535u); public static Color LightGoldenrodYellow => new Color(4210742015u); public static Color LightYellow => new Color(4294959359u); public static Color Yellow => new Color(4294902015u); public static Color Gold => new Color(4292280575u); public static Color LightGoldenrod => new Color(4007494399u); public static Color Goldenrod => new Color(3668254975u); public static Color DarkGoldenrod => new Color(3095792639u); public static Color RosyBrown => new Color(3163525119u); public static Color IndianRed => new Color(3445382399u); public static Color SaddleBrown => new Color(2336560127u); public static Color Sienna => new Color(2689740287u); public static Color Peru => new Color(3448061951u); public static Color Burlywood => new Color(3736635391u); public static Color Beige => new Color(4126530815u); public static Color Wheat => new Color(4125012991u); public static Color SandyBrown => new Color(4104413439u); public static Color Tan => new Color(3535047935u); public static Color Chocolate => new Color(3530104575u); public static Color Firebrick => new Color(2988581631u); public static Color Brown => new Color(2771004159u); public static Color DarkSalmon => new Color(3918953215u); public static Color Salmon => new Color(4202722047u); public static Color LightSalmon => new Color(4288707327u); public static Color Orange => new Color(4289003775u); public static Color DarkOrange => new Color(4287365375u); public static Color Coral => new Color(4286533887u); public static Color LightCoral => new Color(4034953471u); public static Color Tomato => new Color(4284696575u); public static Color OrangeRed => new Color(4282712319u); public static Color Red => new Color(4278190335u); public static Color HotPink => new Color(4285117695u); public static Color DeepPink => new Color(4279538687u); public static Color Pink => new Color(4290825215u); public static Color LightPink => new Color(4290167295u); public static Color PaleVioletRed => new Color(3681588223u); public static Color Maroon => new Color(2955960575u); public static Color WebMaroon => new Color(2147483903u); public static Color MediumVioletRed => new Color(3340076543u); public static Color VioletRed => new Color(3491795199u); public static Color Magenta => new Color(4278255615u); public static Color Fuchsia => new Color(4278255615u); public static Color Violet => new Color(4001558271u); public static Color Plum => new Color(3718307327u); public static Color Orchid => new Color(3664828159u); public static Color MediumOrchid => new Color(3126187007u); public static Color DarkOrchid => new Color(2570243327u); public static Color DarkViolet => new Color(2483082239u); public static Color BlueViolet => new Color(2318131967u); public static Color Purple => new Color(2686513407u); public static Color WebPurple => new Color(2147516671u); public static Color MediumPurple => new Color(2473647103u); public static Color Thistle => new Color(3636451583u); public static Color DarkGrey => new Color(2846468607u); public static Color DarkGray => new Color(2846468607u); public static Color DarkBlue => new Color(35839u); public static Color DarkCyan => new Color(9145343u); public static Color DarkMagenta => new Color(2332068863u); public static Color DarkRed => new Color(2332033279u); public static Color LightGreen => new Color(2431553791u); public static Color Crimson => new Color(3692313855u); public static Color Indigo => new Color(1258324735u); public static Color Olive => new Color(2155872511u); public static Color RebeccaPurple => new Color(1714657791u); public static Color Silver => new Color(3233857791u); public static Color Teal => new Color(8421631u); public int R => (int)(value >> 24); public int G => (int)((value >> 16) & 0xFF); public int B => (int)((value >> 8) & 0xFF); public int A => (int)(value & 0xFF); [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("This method does not return an ARGB value, but rather an RGBA value. Use ToRgba instead.")] public uint ToArgb() { return value; } [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("This method does not operate on ARGB color values as suggested by its name. Use FromRgba instead.")] public static Color FromArgb(uint rgba) { return new Color(rgba); } public static Color Mix(Color color1, Color color2, float weight) { int num = (int)(32768f * weight); if (num < 0) { num = 0; } else if (num > 32768) { num = 32768; } int num2 = color1.A * (32768 - num) + color2.A * num; if (num2 == 0) { return Transparent; } return new Color(num2 >> 15, (color1.R * color1.A * (32768 - num) + color2.R * color2.A * num) / num2, (color1.G * color1.A * (32768 - num) + color2.G * color2.A * num) / num2, (color1.B * color1.A * (32768 - num) + color2.B * color2.A * num) / num2); } public Color Over(Color background) { int a = A; if (a < 1) { return background; } if (a > 254 || background.A < 1) { return this; } int num = a * 255; int num2 = background.A * (255 - a); int num3 = num + num2; byte b = (byte)((num * B + num2 * background.B) / num3); byte g = (byte)((num * G + num2 * background.G) / num3); byte r = (byte)((num * R + num2 * background.R) / num3); byte a2 = (byte)(num3 / 255); return new Color(a2, r, g, b); } public static Color FromArgb(int alpha, int red, int green, int blue) { return FromRgba(red, green, blue, alpha); } public static Color FromRgb(int red, int green, int blue) { return FromRgba(red, green, blue, 255); } public static Color FromRgba(int red, int green, int blue, int alpha) { if (red < 0 || red > 255) { throw new ArgumentOutOfRangeException("red", string.Format("Value {0} is not a valid value of {1}. Allowed values are in the range [0, 255].", red, "red")); } if (green < 0 || green > 255) { throw new ArgumentOutOfRangeException("green", string.Format("Value {0} is not a valid value of {1}. Allowed values are in the range [0, 255].", green, "green")); } if (blue < 0 || blue > 255) { throw new ArgumentOutOfRangeException("blue", string.Format("Value {0} is not a valid value of {1}. Allowed values are in the range [0, 255].", blue, "blue")); } if (alpha < 0 || alpha > 255) { throw new ArgumentOutOfRangeException("alpha", string.Format("Value {0} is not a valid value of {1}. Allowed values are in the range [0, 255].", alpha, "alpha")); } return new Color(alpha, red, green, blue); } public static Color FromRgba(uint rgba) { return new Color(rgba); } public static Color FromHsl(float hue, float saturation, float lightness) { return FromHsl(hue, saturation, lightness, 1f); } public static Color FromHsl(float hue, float saturation, float lightness, float alpha) { if (float.IsNaN(hue)) { throw new ArgumentOutOfRangeException("hue", "NaN is not a valid hue. Allowed values are in the range [0, 1]."); } if (hue < 0f || hue > 1f) { throw new ArgumentOutOfRangeException("hue", string.Format("Value {0} is not a valid {1}. Allowed values are in the range [0, 1].", hue, "hue")); } if (float.IsNaN(saturation)) { throw new ArgumentOutOfRangeException("saturation", "NaN is not a valid saturation. Allowed values are in the range [0, 1]."); } if (saturation < 0f || saturation > 1f) { throw new ArgumentOutOfRangeException("saturation", string.Format("Value {0} is not a valid {1}. Allowed values are in the range [0, 1].", saturation, "saturation")); } if (float.IsNaN(lightness)) { throw new ArgumentOutOfRangeException("lightness", "NaN is not a valid lightness. Allowed values are in the range [0, 1]."); } if (lightness < 0f || lightness > 1f) { throw new ArgumentOutOfRangeException("lightness", string.Format("Value {0} is not a valid {1}. Allowed values are in the range [0, 1].", lightness, "lightness")); } if (float.IsNaN(alpha)) { throw new ArgumentOutOfRangeException("alpha", "NaN is not a valid value of alpha. Allowed values are in the range [0, 1]."); } if (alpha < 0f || alpha > 1f) { throw new ArgumentOutOfRangeException("alpha", string.Format("Value {0} is not a valid value of {1}. Allowed values are in the range [0, 1].", alpha, "alpha")); } if (saturation == 0f) { int num = (int)(lightness * 255f); return new Color((int)(255f * alpha), num, num, num); } float num2 = ((lightness <= 0.5f) ? (lightness * (saturation + 1f)) : (lightness + saturation - lightness * saturation)); float m = lightness * 2f - num2; return new Color((int)(255f * alpha), HueToRgb(m, num2, hue * 6f + 2f), HueToRgb(m, num2, hue * 6f), HueToRgb(m, num2, hue * 6f - 2f)); } public static Color FromHwb(float hue, float whiteness, float blackness) { return FromHwb(hue, whiteness, blackness, 1f); } public static Color FromHwb(float hue, float whiteness, float blackness, float alpha) { if (float.IsNaN(hue)) { throw new ArgumentOutOfRangeException("hue", "NaN is not a valid hue. Allowed values are in the range [0, 1]."); } if (hue < 0f || hue > 1f) { throw new ArgumentOutOfRangeException("hue", string.Format("Value {0} is not a valid {1}. Allowed values are in the range [0, 1].", hue, "hue")); } if (float.IsNaN(whiteness)) { throw new ArgumentOutOfRangeException("whiteness", "NaN is not a valid value of whiteness. Allowed values are in the range [0, 1]."); } if (whiteness < 0f || whiteness > 1f) { throw new ArgumentOutOfRangeException("whiteness", string.Format("Value {0} is not a valid value of {1}. Allowed values are in the range [0, 1].", whiteness, "whiteness")); } if (float.IsNaN(blackness)) { throw new ArgumentOutOfRangeException("blackness", "NaN is not a valid value of blackness. Allowed values are in the range [0, 1]."); } if (blackness < 0f || blackness > 1f) { throw new ArgumentOutOfRangeException("blackness", string.Format("Value {0} is not a valid value of {1}. Allowed values are in the range [0, 1].", blackness, "blackness")); } if (float.IsNaN(alpha)) { throw new ArgumentOutOfRangeException("alpha", "NaN is not a valid value of alpha. Allowed values are in the range [0, 1]."); } if (alpha < 0f || alpha > 1f) { throw new ArgumentOutOfRangeException("alpha", string.Format("Value {0} is not a valid value of {1}. Allowed values are in the range [0, 1].", alpha, "alpha")); } Color color = FromHsl(hue, 1f, 0.5f); if (whiteness + blackness > 1f) { whiteness /= whiteness + blackness; blackness = 1f - whiteness; } float num = 1f - whiteness - blackness; int num2 = (int)((float)color.R * num + whiteness * 255f); int num3 = (int)((float)color.G * num + whiteness * 255f); int num4 = (int)((float)color.B * num + whiteness * 255f); return new Color((int)(255f * alpha), (num2 >= 0) ? ((num2 > 255) ? 255 : num2) : 0, (num3 >= 0) ? ((num3 > 255) ? 255 : num3) : 0, (num4 >= 0) ? ((num4 > 255) ? 255 : num4) : 0); } private static int HueToRgb(float m1, float m2, float h) { h = ((h < 0f) ? (h + 6f) : ((h > 6f) ? (h - 6f) : h)); return (int)(255f * ((h < 1f) ? (m1 + (m2 - m1) * h) : ((h < 3f) ? m2 : ((h < 4f) ? (m1 + (m2 - m1) * (4f - h)) : m1)))); } public static bool TryParse(string? input, out Color result) { return TryParse(input, out result, throwOnError: false); } public static Color Parse(string input) { TryParse(input, out var result, throwOnError: true); return result; } private static bool TryParse(string? input, out Color result, bool throwOnError) { if (input == null) { if (throwOnError) { throw new ArgumentNullException("input"); } result = default(Color); return false; } if (NamedCssColors.TryParse(input, out result)) { return true; } Match match = Regex.Match(input, "^#?[0-9a-fA-F]+$"); if (match.Success) { if (TryParseHexColor(input, out result)) { return true; } if (throwOnError) { throw new FormatException("'" + input + "' is not a valid hexadecimal color."); } return false; } Match match2 = Regex.Match(input, "^(rgba?)\\(([^,]+),([^,]+),([^,]+)(?:,([^,]+))?\\)$"); if (match2.Success) { if (TryParseRgbComponent(match2.Groups[2].Value, out var result2) && TryParseRgbComponent(match2.Groups[3].Value, out var result3) && TryParseRgbComponent(match2.Groups[4].Value, out var result4) && TryParseIntegerAlpha(match2.Groups[5].Value, out var result5)) { result = new Color(result5, result2, result3, result4); return true; } if (throwOnError) { throw new FormatException("'" + input + "' is not a valid " + match2.Groups[1].Value + "() color."); } return false; } Match match3 = Regex.Match(input, "^(hsla?)\\(([^,]+),([^,]+),([^,]+)(?:,([^,]+))?\\)$"); if (match3.Success) { if (TryParseHue(match3.Groups[2].Value, out var result6) && TryParsePercent(match3.Groups[3].Value, out var result7) && TryParsePercent(match3.Groups[4].Value, out var result8) && TryParseAlpha(match3.Groups[5].Value, out var result9)) { result = FromHsl(result6, result7, result8, result9); return true; } if (throwOnError) { throw new FormatException("'" + input + "' is not a valid $" + match3.Groups[1].Value + "() color."); } return false; } Match match4 = Regex.Match(input, "^hwb\\(([^,]+),([^,]+),([^,]+)(?:,([^,]+))?\\)$"); if (match4.Success) { if (TryParseHue(match4.Groups[1].Value, out var result10) && TryParsePercent(match4.Groups[2].Value, out var result11) && TryParsePercent(match4.Groups[3].Value, out var result12) && TryParseAlpha(match4.Groups[4].Value, out var result13)) { result = FromHwb(result10, result11, result12, result13); return true; } if (throwOnError) { throw new FormatException("'" + input + "' is not a valid hwb() color."); } return false; } if (throwOnError) { throw new FormatException(Regex.IsMatch(input, "^[a-zA-Z]+$") ? ("'" + input + "' is not a known named color.") : ("'" + input + "' is not a valid color.")); } return false; } private static bool TryParsePercent(string input, out float result) { bool percentFound = false; input = Regex.Replace(input, "%\\s*$", delegate { percentFound = true; return ""; }); if (!percentFound || !float.TryParse(input, NumberStyles.Float, CultureInfo.InvariantCulture, out result)) { result = 0f; return false; } result *= 0.01f; if (result < 0f) { result = 0f; } else if (result > 1f) { result = 1f; } return true; } private static bool TryParseIntegerAlpha(string input, out int result) { if (TryParseAlpha(input, out var result2)) { result = (int)(255f * result2); return true; } result = 0; return false; } private static bool TryParseAlpha(string input, out float result) { if (string.IsNullOrEmpty(input)) { result = 1f; return true; } bool flag = false; Match match = Regex.Match(input, "%\\s*$"); if (match.Success) { input = input.Substring(0, match.Index); flag = true; } if (!float.TryParse(input, NumberStyles.Float, CultureInfo.InvariantCulture, out result)) { result = 0f; return false; } if (flag) { result *= 0.01f; } if (result < 0f) { result = 0f; } else if (result > 1f) { result = 1f; } return true; } private static bool TryParseRgbComponent(string input, out int result) { bool flag = false; Match match = Regex.Match(input, "%\\s*$"); if (match.Success) { input = input.Substring(0, match.Index); flag = true; } if (!float.TryParse(input, NumberStyles.Float, CultureInfo.InvariantCulture, out var result2)) { result = 0; return false; } if (flag) { result2 *= 2.55f; } result = (int)result2; if (result < 0) { result = 0; } else if (result > 255) { result = 255; } return true; } private static bool TryParseHue(string input, out float result) { string unit = "deg"; input = Regex.Replace(input, "(deg|grad|rad|turn)\\s*$", delegate(Match m) { unit = m.Groups[1].Value.ToLowerInvariant(); return ""; }, RegexOptions.IgnoreCase); if (!float.TryParse(input, NumberStyles.Float, CultureInfo.InvariantCulture, out result)) { result = 0f; return false; } switch (unit) { case "grad": result /= 400f; break; case "rad": result /= MathF.PI * 2f; break; default: result /= 360f; break; case "turn": break; } result %= 1f; if (result < 0f) { result += 1f; } return true; } private static bool TryParseHexColor(string input, out Color result) { if (input.Length < 10) { if (input[0] == '#') { input = input.Substring(1); } if (uint.TryParse(input, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var result2)) { switch (input.Length) { case 3: result = new Color(((result2 & 0xF00) << 20) | ((result2 & 0xF00) << 16) | ((result2 & 0xF0) << 16) | ((result2 & 0xF0) << 12) | ((result2 & 0xF) << 12) | ((result2 & 0xF) << 8) | 0xFFu); return true; case 4: result = new Color(((result2 & 0xF000) << 16) | ((result2 & 0xF000) << 12) | ((result2 & 0xF00) << 12) | ((result2 & 0xF00) << 8) | ((result2 & 0xF0) << 8) | ((result2 & 0xF0) << 4) | ((result2 & 0xF) << 4) | (result2 & 0xFu)); return true; case 6: result = new Color((result2 << 8) | 0xFFu); return true; case 8: result = new Color(result2); return true; } } } result = default(Color); return false; } private Color(int a, int r, int g, int b) { value = (uint)((r << 24) | (g << 16) | (b << 8) | a); } private Color(uint rgba) { value = rgba; } public uint ToRgba() { return value; } public override string ToString() { return "#" + value.ToString("x8"); } public string ToString(string format) { return ToString(format, CultureInfo.InvariantCulture); } public string ToString(string format, IFormatProvider formatProvider) { if (format == null) { throw new ArgumentNullException("format"); } StringBuilder stringBuilder = new StringBuilder(format.Length * 3); char[] anyOf = new char[8] { 'R', 'G', 'B', 'A', 'r', 'g', 'b', 'a' }; int num = 0; while (num < format.Length) { int num2 = format.IndexOfAny(anyOf, num); if (num2 < 0) { break; } stringBuilder.Append(format, num, num2 - num); num = num2 + 1; int num3; bool flag; switch (format[num2]) { case 'R': num3 = R; flag = true; break; case 'G': num3 = G; flag = true; break; case 'B': num3 = B; flag = true; break; case 'A': num3 = A; flag = true; break; case 'r': num3 = R; flag = false; break; case 'g': num3 = G; flag = false; break; case 'b': num3 = B; flag = false; break; case 'a': num3 = A; flag = false; break; default: throw new Exception("Unknown placeholder."); } if (num2 + 1 < format.Length && format[num2] == format[num2 + 1]) { num++; stringBuilder.Append(num3.ToString(flag ? "X2" : "x2", formatProvider)); } else if (flag) { stringBuilder.Append(num3.ToString(formatProvider)); } else { stringBuilder.Append(format[num2]); } } if (num < format.Length) { stringBuilder.Append(format, num, format.Length - num); } return stringBuilder.ToString(); } public override int GetHashCode() { return (int)value; } public override bool Equals(object? obj) { if (obj is Color) { return Equals((Color)obj); } return false; } public bool Equals(Color other) { return other.value == value; } public static bool operator ==(Color a, Color b) { return a.value == b.value; } public static bool operator !=(Color a, Color b) { return a.value != b.value; } } public class ColorConverter : TypeConverter { public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (!(destinationType == typeof(InstanceDescriptor)) && !(destinationType == typeof(string))) { return base.CanConvertTo(context, destinationType); } return true; } public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (value is Color color) { if (destinationType == typeof(InstanceDescriptor)) { MethodInfo method = typeof(Color).GetMethod("FromArgb", new Type[4] { typeof(int), typeof(int), typeof(int), typeof(int) }); return new InstanceDescriptor(method, new object[4] { color.A, color.R, color.G, color.B }); } if (destinationType == typeof(string)) { if (color.A < 255) { return color.ToString("#RRGGBBAA"); } return color.ToString("#RRGGBB"); } } return base.ConvertTo(context, culture, value, destinationType); } public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { if (!(sourceType == typeof(string))) { return base.CanConvertFrom(context, sourceType); } return true; } public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string input) { return Color.Parse(input); } return base.ConvertFrom(context, culture, value); } } public class HueCollection : ICollection<float>, IEnumerable<float>, IEnumerable, IEquatable<HueCollection?>, IFormattable { private readonly List<HueValue> hues; public int Count => hues.Count; public bool IsReadOnly => false; public float this[int index] => hues[index].Turns; internal IEnumerable<HueValue> Values => hues; internal HueCollection(IEnumerable<HueValue> values) { hues = new List<HueValue>(values); } public HueCollection() { hues = new List<HueValue>(); } public HueCollection(IEnumerable<float> hues) { this.hues = new List<HueValue>(); foreach (float item in hues ?? throw new ArgumentNullException("hues")) { this.hues.Add(new HueValue(item)); } } public HueCollection(params float[] hues) { this.hues = new List<HueValue>(); float[] array = hues ?? throw new ArgumentNullException("hues"); foreach (float turns in array) { this.hues.Add(new HueValue(turns)); } } public void Add(float hue) { if (float.IsNaN(hue)) { throw new ArgumentException("NaN is not a valid hue.", "hue"); } if (float.IsPositiveInfinity(hue)) { throw new ArgumentException("Positive infinity is not a valid hue.", "hue"); } if (float.IsNegativeInfinity(hue)) { throw new ArgumentException("Negative infinity is not a valid hue.", "hue"); } hues.Add(new HueValue(hue)); } public void Add(float hue, HueUnit hueUnit) { if (float.IsNaN(hue)) { throw new ArgumentException("NaN is not a valid hue.", "hue"); } if (float.IsPositiveInfinity(hue)) { throw new ArgumentException("Positive infinity is not a valid hue.", "hue"); } if (float.IsNegativeInfinity(hue)) { throw new ArgumentException("Negative infinity is not a valid hue.", "hue"); } hues.Add(new HueValue(hue, hueUnit)); } public void Clear() { hues.Clear(); } public bool Contains(float hue) { return hues.Contains(new HueValue(hue)); } public bool Contains(float hue, HueUnit hueUnit) { return hues.Contains(new HueValue(hue, hueUnit)); } public void CopyTo(float[] array, int arrayIndex) { if (array == null) { throw new ArgumentNullException("array"); } if (arrayIndex < 0) { throw new ArgumentOutOfRangeException("arrayIndex"); } if (array.Length < arrayIndex + hues.Count) { throw new ArgumentException("Insufficient space in the specified array.", "array"); } for (int i = 0; i < hues.Count; i++) { array[arrayIndex + i] = hues[i].Turns; } } private IEnumerable<float> EnumerateTurns() { foreach (HueValue hue in hues) { yield return hue.Turns; } } public IEnumerator<float> GetEnumerator() { return EnumerateTurns().GetEnumerator(); } public bool Remove(float hue) { return hues.Remove(new HueValue(hue)); } public bool Remove(float hue, HueUnit hueUnit) { return hues.Remove(new HueValue(hue, hueUnit)); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } public override int GetHashCode() { return hues.GetHashCode(); } public override bool Equals(object? obj) { return Equals(obj as HueCollection); } public bool Equals(HueCollection? other) { if (other == null || other.hues.Count != hues.Count) { return false; } for (int i = 0; i < hues.Count; i++) { if (hues[i].Turns != other.hues[i].Turns) { return false; } } return true; } public override string ToString() { return ToString(CultureInfo.InvariantCulture); } public string ToString(IFormatProvider formatProvider) { return NumericList.Join(hues, formatProvider ?? CultureInfo.CurrentCulture); } string IFormattable.ToString(string format, IFormatProvider formatProvider) { return ToString(formatProvider); } } [TypeConverter(typeof(HueStringConverter))] public class HueString : IFormattable, IEquatable<HueString?> { private readonly List<HueValue> hues = new List<HueValue>(); private int? hashCode; public static HueString Empty { get; } = new HueString(); private HueString() { } public HueString(HueCollection collection) { hues = new List<HueValue>(collection.Values ?? throw new ArgumentNullException("collection")); } public HueString(string? value) : this(value, CultureInfo.InvariantCulture) { } public HueString(string? value, IFormatProvider formatProvider) { string[] array = NumericList.Parse(value, formatProvider); foreach (string value2 in array) { hues.Add(HueValue.Parse(value2, formatProvider)); } } public static HueString Parse(string? value) { return new HueString(value); } public static HueString Parse(string? value, IFormatProvider formatProvider) { return new HueString(value, formatProvider); } public override int GetHashCode() { if (!hashCode.HasValue) { int num = 0; int num2 = 0; foreach (HueValue hue in hues) { num += (int)(1000f * hue.Turns) * num2; num2 = num2 + num2 + 37; } hashCode = num; } return hashCode.Value; } public override bool Equals(object? obj) { return Equals(obj as HueString); } public bool Equals(HueString? other) { if ((object)other == null) { return false; } if ((object)this != other) { if (other.hues.Count != hues.Count) { return false; } for (int i = 0; i < hues.Count; i++) { if (hues[i].Turns != other.hues[i].Turns) { return false; } } } return true; } public static bool operator ==(HueString? a, HueString? b) { return object.Equals(a, b); } public static bool operator !=(HueString? a, HueString? b) { return !object.Equals(a, b); } public HueCollection ToCollection() { return new HueCollection(hues); } public override string ToString() { return ToString(CultureInfo.InvariantCulture); } public string ToString(IFormatProvider formatProvider) { return NumericList.Join(hues, formatProvider ?? CultureInfo.CurrentCulture); } string IFormattable.ToString(string format, IFormatProvider formatProvider) { return ToString(formatProvider); } } public enum HueUnit { Degrees, Turns, Radians, Gradians } internal class HueUnitInfo { public HueUnit Key { get; } public string Suffix { get; } public float Period { get; } public static HueUnitInfo[] Values { get; } = new HueUnitInfo[4] { new HueUnitInfo(HueUnit.Turns, "turn", 1f), new HueUnitInfo(HueUnit.Gradians, "grad", 400f), new HueUnitInfo(HueUnit.Degrees, "deg", 360f), new HueUnitInfo(HueUnit.Radians, "rad", MathF.PI * 2f) }; public HueUnitInfo(HueUnit key, string suffix, float period) { Key = key; Suffix = suffix; Period = period; } public static HueUnitInfo Get(HueUnit hueUnit) { HueUnitInfo[] values = Values; foreach (HueUnitInfo hueUnitInfo in values) { if (hueUnitInfo.Key == hueUnit) { return hueUnitInfo; } } throw new ArgumentException($"Unknown hue unit {hueUnit}.", "hueUnit"); } } internal class HueValue : IEquatable<HueValue?>, IFormattable { public float Value { get; } public float Turns { get; } public string Suffix { get; } private HueValue(string value, IFormatProvider formatProvider) { if (value == null) { throw new ArgumentNullException("value"); } string text = ""; float num = 1f; HueUnitInfo[] values = HueUnitInfo.Values; foreach (HueUnitInfo hueUnitInfo in values) { if (value.EndsWith(hueUnitInfo.Suffix, StringComparison.OrdinalIgnoreCase)) { text = hueUnitInfo.Suffix; num = hueUnitInfo.Period; value = value.Substring(0, value.Length - hueUnitInfo.Suffix.Length); break; } } float value2 = float.Parse(value, NumberStyles.Number, formatProvider); Suffix = text; Value = Normalize(value2, num); Turns = Value / num; } public HueValue(float hue, HueUnit hueUnit) { HueUnitInfo hueUnitInfo = HueUnitInfo.Get(hueUnit); float num = Normalize(hue, hueUnitInfo.Period); Suffix = hueUnitInfo.Suffix; Turns = num / hueUnitInfo.Period; Value = num; } public HueValue(float turns) { Value = (Turns = Normalize(turns, 1f)); Suffix = ""; } public static HueValue Parse(string value, IFormatProvider formatProvider) { return new HueValue(value, formatProvider); } private static float Normalize(float value, float period) { value %= period; if (value < 0f) { value += period; } return value; } public override int GetHashCode() { return (int)(1000f * Turns); } public override bool Equals(object obj) { return Equals(obj as HueValue); } public bool Equals(HueValue? other) { if (other != null) { return other.Turns == Turns; } return false; } public override string ToString() { return ToString(CultureInfo.InvariantCulture); } public string ToString(IFormatProvider formatProvider) { return Value.ToString("0.##", formatProvider) + Suffix; } string IFormattable.ToString(string format, IFormatProvider formatProvider) { return ToString(formatProvider); } } [CompilerGenerated] internal static class NamespaceDoc { } public class ActionDisposable : IDisposable { private Action? action; public static ActionDisposable Empty => new ActionDisposable(null); public ActionDisposable(Action? action) { this.action = action; } public void Dispose() { Interlocked.Exchange(ref action, null)?.Invoke(); } } public class ColorTheme { public Color DarkGray { get; set; } public Color MidColor { get; set; } public Color LightGray { get; set; } public Color LightColor { get; set; } public Color DarkColor { get; set; } public Color this[int index] => index switch { 0 => DarkGray, 1 => MidColor, 2 => LightGray, 3 => LightColor, 4 => DarkColor, _ => throw new ArgumentOutOfRangeException("index"), }; public int Count => 5; public ColorTheme(float hue, IdenticonStyle style) { if (style == null) { throw new ArgumentNullException("style"); } if (style.Hues.Count > 0) { int index = (int)(0.999f * hue * (float)style.Hues.Count); hue = style.Hues[index]; } DarkGray = ColorUtils.FromHslCompensated(hue, style.GrayscaleSaturation, style.GrayscaleLightness.From); MidColor = ColorUtils.FromHslCompensated(hue, style.ColorSaturation, (style.ColorLightness.From + style.ColorLightness.To) / 2f); LightGray = ColorUtils.FromHslCompensated(hue, style.GrayscaleSaturation, style.GrayscaleLightness.To); LightColor = ColorUtils.FromHslCompensated(hue, style.ColorSaturation, style.ColorLightness.To); DarkColor = ColorUtils.FromHslCompensated(hue, style.ColorSaturation, style.ColorLightness.From); } } internal static class ColorUtils { private static readonly float[] LightnessCompensations = new float[7] { 0.55f, 0.5f, 0.5f, 0.46f, 0.6f, 0.55f, 0.55f }; public static string ToHexString(Color color) { return $"#{color.R:x2}{color.G:x2}{color.B:x2}"; } public static Color FromHslCompensated(float hue, float saturation, float lightness) { if (hue < 0f) { throw new ArgumentOutOfRangeException("hue"); } if (hue > 1f) { throw new ArgumentOutOfRangeException("hue"); } float num = LightnessCompensations[(int)(hue * 6f + 0.5f)]; lightness = ((lightness < 0.5f) ? (lightness * num * 2f) : (num + (lightness - 0.5f) * (1f - num) * 2f)); return Color.FromHsl(hue, saturation, lightness); } } public class IconGenerator { private static readonly ShapeCategory[] DefaultCategories = new ShapeCategory[3] { new ShapeCategory { ColorIndex = 8, Shapes = ShapeDefinitions.OuterShapes, ShapeIndex = 2, RotationIndex = 3, Positions = new ShapePositionCollection { { 1, 0 }, { 2, 0 }, { 2, 3 }, { 1, 3 }, { 0, 1 }, { 3, 1 }, { 3, 2 }, { 0, 2 } } }, new ShapeCategory { ColorIndex = 9, Shapes = ShapeDefinitions.OuterShapes, ShapeIndex = 4, RotationIndex = 5, Positions = new ShapePositionCollection { { 0, 0 }, { 3, 0 }, { 3, 3 }, { 0, 3 } } }, new ShapeCategory { ColorIndex = 10, Shapes = ShapeDefinitions.CenterShapes, ShapeIndex = 1, RotationIndex = null, Positions = new ShapePositionCollection { { 1, 1 }, { 2, 1 }, { 2, 2 }, { 1, 2 } } } }; public virtual int CellCount => 4; protected static float GetHue(byte[] hash) { byte[] array = new byte[4]; Array.Copy(hash, hash.Length - 4, array, 0, 4); if (BitConverter.IsLittleEndian) { Array.Reverse(array); } uint num = BitConverter.ToUInt32(array, 0) & 0xFFFFFFFu; return (float)num / 268435460f; } private static bool IsDuplicate(ICollection<int> source, int newValue, params int[] duplicateValues) { if (((ICollection<int>)duplicateValues).Contains(newValue)) { for (int i = 0; i < duplicateValues.Length; i++) { if (source.Contains(duplicateValues[i])) { return true; } } } return false; } protected static byte GetOctet(byte[] source, int index) { int num = index / 2; byte b = source[num]; if (num * 2 == index) { return (byte)(b >> 4); } return (byte)(b & 0xFu); } protected virtual IEnumerable<ShapeCategory> GetCategories() { return DefaultCategories; } protected virtual IEnumerable<Shape> GetShapes(ColorTheme colorTheme, byte[] hash) { List<int> usedColorThemeIndexes = new List<int>(); foreach (ShapeCategory category in GetCategories()) { int num = GetOctet(hash, category.ColorIndex) % colorTheme.Count; if (IsDuplicate(usedColorThemeIndexes, num, 0, 4) || IsDuplicate(usedColorThemeIndexes, num, 2, 3)) { num = 1; } usedColorThemeIndexes.Add(num); int startRotationIndex = (category.RotationIndex.HasValue ? GetOctet(hash, category.RotationIndex.Value) : 0); ShapeDefinition definition = category.Shapes[GetOctet(hash, category.ShapeIndex) % category.Shapes.Count]; yield return new Shape { Definition = definition, Color = colorTheme[num], Positions = category.Positions, StartRotationIndex = startRotationIndex }; } } protected Rectangle GetInnerRectangle(Rectangle rect, float padding) { int num = Math.Min(rect.Width, rect.Height); int num2 = (int)((1f - 2f * padding) * (float)num); num2 -= num2 % CellCount; return new Rectangle(rect.X + (rect.Width - num2) / 2, rect.Y + (rect.Height - num2) / 2, num2, num2); } protected virtual void RenderBackground(Renderer renderer, Rectangle rect, IdenticonStyle style, ColorTheme colorTheme, byte[] hash) { renderer.SetBackground(style.BackColor, rect); } protected virtual void RenderForeground(Renderer renderer, Rectangle rect, IdenticonStyle style, ColorTheme colorTheme, byte[] hash) { Rectangle innerRectangle = GetInnerRectangle(rect, style.Padding); int num = innerRectangle.Width / CellCount; foreach (Shape shape in GetShapes(colorTheme, hash)) { int startRotationIndex = shape.StartRotationIndex; using (renderer.BeginShape(shape.Color)) { for (int i = 0; i < shape.Positions.Count; i++) { ShapePosition shapePosition = shape.Positions[i]; renderer.Transform = new Transform(innerRectangle.X + shapePosition.X * num, innerRectangle.Y + shapePosition.Y * num, num, startRotationIndex++ % 4); shape.Definition(renderer, num, i); } } } } public void Generate(Renderer renderer, Rectangle rect, IdenticonStyle style, byte[] hash) { if (renderer == null) { throw new ArgumentNullException("renderer"); } if (style == null) { throw new ArgumentNullException("style"); } if (hash == null) { throw new ArgumentNullException("hash"); } float hue = GetHue(hash); ColorTheme colorTheme = new ColorTheme(hue, style); RenderBackground(renderer, rect, style, colorTheme, hash); RenderForeground(renderer, rect, style, colorTheme, hash); } } public class PngRenderer : Renderer { private Bitmap bitmap; private Jdenticon.Drawing.Path? path; public PngRenderer(int width, int height) { bitmap = new Bitmap(width, height); } protected override void AddCircleNoTransform(PointF location, float diameter, bool counterClockwise) { if (path == null) { throw new InvalidOperationException("No active shape. Call BeginShape before calling this method."); } path.AddCircle(new PointF(location.X + diameter / 2f, location.Y + diameter / 2f), diameter / 2f, !counterClockwise); } protected override void AddPolygonNoTransform(PointF[] points) { if (points == null) { throw new ArgumentNullException("points"); } if (path == null) { throw new InvalidOperationException("No active shape. Call BeginShape before calling this method."); } path.AddPolygon(points); } public override void SetBackground(Color color, Rectangle iconBounds) { bitmap.BackgroundColor = color; } public override IDisposable BeginShape(Color color) { path = new Jdenticon.Drawing.Path(); return new ActionDisposable(delegate { bitmap.FillPath(color, path); }); } public void SavePng(Stream stream) { bitmap.SaveAsPng(stream); } } public struct PointF { private readonly float x; private readonly float y; public float X => x; public float Y => y; public PointF(float x, float y) { this.x = x; this.y = y; } public override string ToString() { return x + ", " + y; } } public struct Rectangle { private readonly int x; private readonly int y; private readonly int width; private readonly int height; public int X => x; public int Y => y; public int Width => width; public int Height => height; public Rectangle(int x, int y, int width, int height) { this.x = x; this.y = y; this.width = width; this.height = height; } } public abstract class Renderer { private Transform transform = Jdenticon.Rendering.Transform.Empty; internal Transform Transform { get { return transform; } set { transform = value ?? Jdenticon.Rendering.Transform.Empty; } } protected abstract void AddPolygonNoTransform(PointF[] points); protected abstract void AddCircleNoTransform(PointF location, float diameter, bool counterClockwise); public abstract void SetBackground(Color color, Rectangle iconBounds); public abstract IDisposable BeginShape(Color color); private void AddPolygonCore(PointF[] points, bool invert) { if (invert) { Array.Reverse(points); } for (int i = 0; i < points.Length; i++) { points[i] = transform.TransformPoint(points[i].X, points[i].Y); } AddPolygonNoTransform(points); } public void AddRectangle(float x, float y, float width, float height, bool invert = false) { AddPolygonCore(new PointF[4] { new PointF(x, y), new PointF(x + width, y), new PointF(x + width, y + height), new PointF(x, y + height) }, invert); } public void AddCircle(float x, float y, float size, bool invert = false) { PointF location = transform.TransformPoint(x, y, size, size); AddCircleNoTransform(location, size, invert); } public void AddPolygon(PointF[] points, bool invert = false) { if (points == null) { throw new ArgumentNullException("points"); } AddPolygonCore((PointF[])points.Clone(), invert); } public void AddTriangle(float x, float y, float width, float height, TriangleDirection direction, bool invert = false) { List<PointF> list = new List<PointF>(4) { new PointF(x + width, y), new PointF(x + width, y + height), new PointF(x, y + height), new PointF(x, y) }; list.RemoveAt((int)direction); AddPolygonCore(list.ToArray(), invert); } public void AddRhombus(float x, float y, float width, float height, bool invert = false) { AddPolygonCore(new PointF[4] { new PointF(x + width / 2f, y), new PointF(x + width, y + height / 2f), new PointF(x + width / 2f, y + height), new PointF(x, y + height / 2f) }, invert); } public virtual void Flush() { } } internal class SvgPath { private readonly List<string> dataString = new List<string>(); private static string FormatCoordinate(float coordinate) { return coordinate.ToString("0.#", CultureInfo.InvariantCulture); } public void AddCircle(PointF location, float diameter, bool counterClockwise) { char c = (counterClockwise ? '0' : '1'); float num = diameter / 2f; string text = FormatCoordinate(num); dataString.Add("M" + FormatCoordinate(location.X) + " " + FormatCoordinate(location.Y + num) + "a" + text + "," + text + " 0 1," + c + " " + FormatCoordinate(diameter) + ",0a" + text + "," + text + " 0 1," + c + " " + FormatCoordinate(0f - diameter) + ",0"); } public void AddPolygon(PointF[] points) { dataString.Add("M" + FormatCoordinate(points[0].X) + " " + FormatCoordinate(points[0].Y)); for (int i = 1; i < points.Length; i++) { dataString.Add("L" + FormatCoordinate(points[i].X) + " " + FormatCoordinate(points[i].Y)); } dataString.Add("Z"); } public override string ToString() { return string.Concat(dataString); } } public class SvgRenderer : Renderer { private readonly Dictionary<Color, SvgPath> pathsByColor = new Dictionary<Color, SvgPath>(); private SvgPath? path; private int width; private int height; private Color backColor; public SvgRenderer(int width, int height) { this.width = width; this.height = height; } protected override void AddCircleNoTransform(PointF location, float diameter, bool counterClockwise) { if (path == null) { throw new InvalidOperationException("No active shape. Call BeginShape before calling this method."); } path.AddCircle(location, diameter, counterClockwise); } protected override void AddPolygonNoTransform(PointF[] points) { if (points == null) { throw new ArgumentNullException("points"); } if (path == null) { throw new InvalidOperationException("No active shape. Call BeginShape before calling this method."); } path.AddPolygon(points); } public override void SetBackground(Color color, Rectangle iconBounds) { backColor = color; } public override IDisposable BeginShape(Color color) { if (!pathsByColor.TryGetValue(color, out path)) { pathsByColor[color] = (path = new SvgPath()); } return ActionDisposable.Empty; } public void Save(TextWriter writer, bool fragment) { writer.Write(ToSvg(fragment)); } public string ToSvg(bool fragment) { List<string> list = new List<string>(); CultureInfo invariantCulture = CultureInfo.InvariantCulture; string text = width.ToString(invariantCulture); string text2 = height.ToString(invariantCulture); if (!fragment) { list.Add("<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"" + text + "\" height=\"" + text2 + "\" viewBox=\"0 0 " + text + " " + text2 + "\" preserveAspectRatio=\"xMidYMid meet\">"); } if (backColor.A > 0) { float num = (float)backColor.A / 255f; list.Add("<rect fill=\"" + ColorUtils.ToHexString(backColor) + "\" fill-opacity=\"" + num.ToString("0.##", invariantCulture) + "\" x=\"0\" y=\"0\" width=\"" + text + "\" height=\"" + text2 + "\"/>"); } foreach (KeyValuePair<Color, SvgPath> item in pathsByColor) { list.Add("<path fill=\"" + ColorUtils.ToHexString(item.Key) + "\" d=\"" + item.Value?.ToString() + "\"/>"); } if (!fragment) { list.Add("</svg>"); } return string.Concat(list); } } internal class Transform { private int x; private int y; private int size; private int rotation; private static readonly Transform empty = new Transform(0, 0, 0, 0); public static Transform Empty => empty; public Transform(int x, int y, int size, int rotation) { this.x = x; this.y = y; this.size = size; this.rotation = rotation; } public PointF TransformPoint(float x, float y, float width = 0f, float height = 0f) { int num = this.x + size; int num2 = this.y + size; if (rotation != 1) { if (rotation != 2) { if (rotation != 3) { return new PointF((float)this.x + x, (float)this.y + y); } return new PointF((float)this.x + y, (flo
RunVerifier.dll
Decompiled 3 weeks agousing System; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using HarmonyLib; using Jdenticon; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.UI; [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("RunVerifier")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("RunVerifier")] [assembly: AssemblyTitle("RunVerifier")] [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 SpearPractice { [BepInPlugin("RunVerifier", "RunVerifier", "1.0.0")] public class Plugin : BaseUnityPlugin { private void Awake() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) new Harmony("com.lin.SpearPractice").PatchAll(); } } internal static class IdenticonUIHelper { private static int starter; public static string foundCanvas; private static RawImage rawImage; public static void EnsureCreated(Texture2D identiconTexture) { //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Expected O, but got Unknown //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) Canvas val = Object.FindObjectOfType<Canvas>(); if ((Object)(object)val == (Object)null) { Debug.LogError((object)"[IdenticonUI] No Canvas found."); return; } if (starter == 0) { foundCanvas = ((Object)val).name; starter++; } GameObject val2 = new GameObject("Identicon_Display"); val2.transform.SetParent(((Component)val).transform, false); RectTransform val3 = val2.AddComponent<RectTransform>(); val3.anchorMin = new Vector2(1f, 0f); val3.anchorMax = new Vector2(1f, 0f); val3.pivot = new Vector2(1f, 0f); val3.anchoredPosition = new Vector2(-50f, 120f); val3.sizeDelta = new Vector2(100f, 100f); rawImage = val2.AddComponent<RawImage>(); rawImage.texture = (Texture)(object)identiconTexture; Debug.Log((object)("[IdenticonUI] Identicon displayed on canvas " + ((Object)val).name)); } } [HarmonyPatch(typeof(M_Gamemode), "Initialize")] public class testing { private static int starter; private static void Postfix() { //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Expected O, but got Unknown long folderSize = GetFolderSize(Paths.PluginPath); string fileName = Path.Combine(Paths.ManagedPath, "Assembly-CSharp.dll"); long length = new FileInfo(fileName).Length; string text = (folderSize + length).ToString(); Canvas val = Object.FindObjectOfType<Canvas>(); Debug.Log((object)folderSize); byte[] array; using (MemoryStream memoryStream = new MemoryStream()) { PngExtensions.SaveAsPng(Identicon.FromValue((object)text, 100, "SHA1"), (Stream)memoryStream); array = memoryStream.ToArray(); } Texture2D val2 = new Texture2D(2, 2, (TextureFormat)4, false); ImageConversion.LoadImage(val2, array); if (((Object)val).name == IdenticonUIHelper.foundCanvas || starter == 0) { IdenticonUIHelper.EnsureCreated(val2); starter++; } } private static long GetFolderSize(string folderPath) { long num = 0L; int num2 = 0; if (!Directory.Exists(folderPath)) { return 0L; } foreach (string item in Directory.EnumerateFiles(folderPath, "*", SearchOption.AllDirectories)) { try { num += new FileInfo(item).Length; num2++; } catch { } } long num3 = num % 3 + 1; return (num * num3) ^ num2; } } public class PauseTimer : MonoBehaviour { public enum TimerMode { GlobalSinceLaunch, RunSinceStart } private Text text; public TimerMode mode; private void Awake() { text = ((Component)this).GetComponent<Text>(); } private void Update() { TimerMode timerMode = mode; if (1 == 0) { } float num = timerMode switch { TimerMode.GlobalSinceLaunch => PausePatch.gameLaunchTimer, TimerMode.RunSinceStart => PausePatch.timerBegan, _ => 0f, }; if (1 == 0) { } float num2 = num; float num3 = Time.unscaledTime - num2; int num4 = (int)(num3 / 3600f); int num5 = (int)(num3 % 3600f / 60f); int num6 = (int)(num3 % 60f); TimerMode timerMode2 = mode; if (1 == 0) { } string text = timerMode2 switch { TimerMode.GlobalSinceLaunch => "Time passed since game launch ", TimerMode.RunSinceStart => "Time passed since run start ", _ => "error", }; if (1 == 0) { } string text2 = text; this.text.text = $"{text2}{num4}:{num5:00}:{num6:00}"; } } internal static class TimerMaker { public static GameObject CreateTimerTextLine(Transform parent, string name, Vector2 anchoredPos) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name); val.transform.SetParent(parent, false); RectTransform val2 = val.AddComponent<RectTransform>(); val2.anchorMin = new Vector2(1f, 1f); val2.anchorMax = new Vector2(1f, 1f); val2.pivot = new Vector2(1f, 1f); val2.anchoredPosition = anchoredPos; val2.sizeDelta = new Vector2(400f, 80f); Text val3 = val.AddComponent<Text>(); val3.font = Resources.GetBuiltinResource<Font>("Arial.ttf"); val3.fontSize = 20; val3.alignment = (TextAnchor)2; ((Graphic)val3).color = Color.white; return val; } } [HarmonyPatch(typeof(CL_GameManager), "Pause")] internal static class PausePatch { public static float timerBegan; public static float gameLaunchTimer; private static GameObject runGO; private static GameObject globalGO; private static void Postfix(object __instance) { //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) object? obj = __instance.GetType().GetField("pauseMenu", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(__instance); GameObject val = (GameObject)((obj is GameObject) ? obj : null); if ((Object)(object)val == (Object)null) { Debug.Log((object)"[TimerMod] pauseMenu field not found or null"); return; } if ((Object)(object)runGO == (Object)null || (Object)(object)globalGO == (Object)null) { runGO = TimerMaker.CreateTimerTextLine(val.transform, "Run_Timer", new Vector2(-30f, -60f)); globalGO = TimerMaker.CreateTimerTextLine(val.transform, "Global_Timer", new Vector2(-30f, -30f)); PauseTimer pauseTimer = globalGO.AddComponent<PauseTimer>(); pauseTimer.mode = PauseTimer.TimerMode.GlobalSinceLaunch; PauseTimer pauseTimer2 = runGO.AddComponent<PauseTimer>(); pauseTimer2.mode = PauseTimer.TimerMode.RunSinceStart; runGO.SetActive(true); globalGO.SetActive(true); } Debug.Log((object)$"[TimerMod] pauseMenu name={((Object)val).name} activeSelf={val.activeSelf} activeInHierarchy={val.activeInHierarchy}"); } } [HarmonyPatch(typeof(M_Gamemode), "Initialize")] internal static class TimerStarter { private static int starter; private static void Postfix() { if (starter == 0) { starter++; PausePatch.gameLaunchTimer = Time.unscaledTime; } PausePatch.timerBegan = Time.unscaledTime; } } public static class MyPluginInfo { public const string PLUGIN_GUID = "RunVerifier"; public const string PLUGIN_NAME = "RunVerifier"; public const string PLUGIN_VERSION = "1.0.0"; } }