using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Linq; using System.Reflection; using System.Resources; using System.Runtime.CompilerServices; using System.Runtime.Serialization; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Threading; using Microsoft.CodeAnalysis; using Newtonsoft.Json; using Newtonsoft.Json.Linq; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] [assembly: AssemblyCompany("Warp World, Inc.")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyCopyright("© 2026 Warp World, Inc.")] [assembly: AssemblyFileVersion("5.0.9718.29595")] [assembly: AssemblyInformationalVersion("5.0.9718.29595+1cda1f7b799cf2173b64339b8d26c024098ee0ce")] [assembly: AssemblyProduct("ConnectorLib.JSON")] [assembly: AssemblyTitle("ConnectorLib.JSON")] [assembly: NeutralResourcesLanguage("en-US")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("5.0.9718.29595")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] internal sealed class ParamCollectionAttribute : Attribute { } [CompilerGenerated] [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] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] internal sealed class ScopedRefAttribute : Attribute { } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ConnectorLib.JSON { public class CamelCaseStringEnumConverter : JsonConverter { public override void WriteJson(JsonWriter writer, Enum? value, JsonSerializer serializer) { if (value == null) { serializer.Serialize(writer, (object)null); } else { serializer.Serialize(writer, (object)value.ToCamelCase()); } } public override Enum ReadJson(JsonReader reader, Type objectType, Enum? existingValue, bool hasExistingValue, JsonSerializer serializer) { return ReadJToken(JToken.ReadFrom(reader), objectType); } public static Enum ReadJToken(JToken reader, Type objectType) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Invalid comparison between Unknown and I4 //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Invalid comparison between Unknown and I4 JTokenType type = reader.Type; JTokenType val = type; if ((int)val != 6) { if ((int)val == 8) { string text = Extensions.Value((IEnumerable)reader); if (text == null) { throw new SerializationException("The value was null."); } try { object obj = Enum.Parse(objectType, text, ignoreCase: true); return (Enum)obj; } catch (Exception) { throw new SerializationException("The value was not recognized."); } } throw new SerializationException("The value was not a string or number."); } int? num = Extensions.Value((IEnumerable)reader); if (!num.HasValue) { throw new SerializationException("The value was null."); } return (Enum)Enum.ToObject(objectType, num.Value); } } public class DataRequest : SimpleJSONRequest { public string key; public DataRequest(string key) { this.key = key; type = RequestType.DataRequest; } } public class DataResponse : SimpleJSONResponse { public string key; public JToken? value; public EffectStatus status; public long timeRemaining; public string? message; [JsonConstructor] public DataResponse(string key, EffectStatus status, object? value = null, long timeRemaining = 0L, string? message = null) { this.key = key; this.value = value.IfNotNull((Func)JToken.FromObject); this.status = status; this.timeRemaining = timeRemaining; this.message = message; type = ResponseType.DataResponse; } public static DataResponse SuccessIfDefined(string key, object? value, string failMessage = "") { if (value == null) { return Retry(key, 0L, failMessage); } if (value is string input && input.IsNullOrWhiteSpace()) { return Retry(key, 0L, failMessage); } return Success(key, value); } public static DataResponse Success(string key, object? value) { return new DataResponse(key, EffectStatus.Success, value, 0L); } public static DataResponse Success(string key, object? value, string? message) { return new DataResponse(key, EffectStatus.Success, value, 0L, message); } public static DataResponse Failure(string key) { return new DataResponse(key, EffectStatus.Failure, null, 0L); } public static DataResponse Failure(string key, string? message) { return new DataResponse(key, EffectStatus.Failure, null, 0L, message); } public static DataResponse Failure(string key, object? value, string? message = null) { return new DataResponse(key, EffectStatus.Failure, value, 0L, message); } public static DataResponse Retry(string key, long delay = 0L, string? message = null) { return new DataResponse(key, EffectStatus.Retry, null, delay, message); } } public class EffectRequest : SimpleJSONRequest { public class Target { public string? service; public string? id; public string? name; public string? avatar; } public string? code; public string? message; public JToken? parameters; public uint? quantity; public JArray? targets; public long? duration; public string? viewer; public JArray? viewers; public long? cost; public Dictionary? arguments; public Guid? requestID; [JsonConverter(typeof(IEffectSourceDetails.Converter))] public IEffectSourceDetails? sourceDetails; public EffectRequest() { type = RequestType.EffectStart; } } public class EffectResponse : SimpleJSONResponse { private class MetadataConverter : JsonConverter?> { public override void WriteJson(JsonWriter writer, Dictionary? value, JsonSerializer serializer) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown if (value == null) { serializer.Serialize(writer, (object)null); return; } JObject val = new JObject(); foreach (KeyValuePair item in value) { JObject val2 = JObject.FromObject((object)item.Value); val2.Remove("key"); val[item.Key] = (JToken)(object)val2; } serializer.Serialize(writer, (object)val); } public override Dictionary? ReadJson(JsonReader reader, Type objectType, Dictionary? existingValue, bool hasExistingValue, JsonSerializer serializer) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Expected O, but got Unknown //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Expected O, but got Unknown JObject val = (JObject)serializer.Deserialize(reader); if (val == null) { return null; } Dictionary dictionary = new Dictionary(); foreach (JProperty item in val.Properties()) { JObject val2 = (JObject)item.Value; val2["key"] = JToken.op_Implicit(item.Name); dictionary.Add(item.Name, ((JToken)val2).ToObject()); } return dictionary; } } public EffectStatus status; public string? message; public StandardErrors messageID; public long timeRemaining; [JsonConverter(typeof(MetadataConverter))] public Dictionary? metadata; public EffectResponse() { } public EffectResponse(uint id, EffectStatus status) : this(id, status, 0L) { } public EffectResponse(uint id, EffectStatus status, StandardErrors messageID, string? message = null) : this(id, status, 0L, messageID, message) { } public EffectResponse(uint id, EffectStatus status, string? message) : this(id, status, 0L, message) { } public EffectResponse(uint id, EffectStatus status, TimeSpan timeRemaining) : this(id, status, checked((long)timeRemaining.TotalMilliseconds)) { } public EffectResponse(uint id, EffectStatus status, TimeSpan timeRemaining, StandardErrors messageID) : this(id, status, checked((long)timeRemaining.TotalMilliseconds), messageID) { } public EffectResponse(uint id, EffectStatus status, TimeSpan timeRemaining, string? message) : this(id, status, checked((long)timeRemaining.TotalMilliseconds), message) { } public EffectResponse(uint id, EffectStatus status, long timeRemaining, string? message = null) { base.id = id; this.status = status; this.timeRemaining = timeRemaining; this.message = message; type = ResponseType.EffectRequest; } [JsonConstructor] public EffectResponse(uint id, EffectStatus status, long timeRemaining, StandardErrors messageID, string? message = null) { base.id = id; this.status = status; this.timeRemaining = timeRemaining; this.messageID = messageID; this.message = message; type = ResponseType.EffectRequest; } public static EffectResponse Success(uint id, string? message = null) { return new EffectResponse(id, EffectStatus.Success, message); } public static EffectResponse Success(uint id, long delay, string? message = null) { return new EffectResponse(id, EffectStatus.Success, delay, message); } public static EffectResponse Success(uint id, TimeSpan delay, string? message = null) { return new EffectResponse(id, EffectStatus.Success, delay, message); } public static EffectResponse Failure(uint id, string? message = null) { return new EffectResponse(id, EffectStatus.Failure, message); } public static EffectResponse Failure(uint id, StandardErrors error, string? message = null) { return new EffectResponse(id, EffectStatus.Failure, error, message); } public static EffectResponse Unavailable(uint id, string? message = null) { return new EffectResponse(id, EffectStatus.Unavailable, message); } public static EffectResponse Unavailable(uint id, StandardErrors error) { return new EffectResponse(id, EffectStatus.Unavailable, error); } public static EffectResponse Retry(uint id, string? message = null) { return new EffectResponse(id, EffectStatus.Retry, 0L, message); } public static EffectResponse Retry(uint id, long delay, string? message = null) { return new EffectResponse(id, EffectStatus.Retry, delay, message); } public static EffectResponse Retry(uint id, TimeSpan delay, string? message = null) { return new EffectResponse(id, EffectStatus.Retry, delay, message); } public static EffectResponse Retry(uint id, StandardErrors error) { return new EffectResponse(id, EffectStatus.Retry, 0L, error); } public static EffectResponse Retry(uint id, long delay, StandardErrors error) { return new EffectResponse(id, EffectStatus.Retry, delay, error); } public static EffectResponse Retry(uint id, TimeSpan delay, StandardErrors error) { return new EffectResponse(id, EffectStatus.Retry, delay, error); } public static EffectResponse Paused(uint id, string? message = null) { return new EffectResponse(id, EffectStatus.Paused, 0L, message); } public static EffectResponse Paused(uint id, long timeRemaining, string? message = null) { return new EffectResponse(id, EffectStatus.Paused, timeRemaining, message); } public static EffectResponse Paused(uint id, TimeSpan timeRemaining, string? message = null) { return new EffectResponse(id, EffectStatus.Paused, timeRemaining, message); } public static EffectResponse Paused(uint id, StandardErrors error) { return new EffectResponse(id, EffectStatus.Paused, 0L, error); } public static EffectResponse Paused(uint id, long timeRemaining, StandardErrors error) { return new EffectResponse(id, EffectStatus.Paused, timeRemaining, error); } public static EffectResponse Paused(uint id, TimeSpan timeRemaining, StandardErrors error) { return new EffectResponse(id, EffectStatus.Paused, timeRemaining, error); } public static EffectResponse Resumed(uint id, string? message = null) { return new EffectResponse(id, EffectStatus.Resumed, 0L, message); } public static EffectResponse Resumed(uint id, long timeRemaining, string? message = null) { return new EffectResponse(id, EffectStatus.Resumed, timeRemaining, message); } public static EffectResponse Resumed(uint id, TimeSpan timeRemaining, string? message = null) { return new EffectResponse(id, EffectStatus.Resumed, timeRemaining, message); } public static EffectResponse Resumed(uint id, StandardErrors error) { return new EffectResponse(id, EffectStatus.Resumed, 0L, error); } public static EffectResponse Resumed(uint id, long timeRemaining, StandardErrors error) { return new EffectResponse(id, EffectStatus.Resumed, timeRemaining, error); } public static EffectResponse Resumed(uint id, TimeSpan timeRemaining, StandardErrors error) { return new EffectResponse(id, EffectStatus.Resumed, timeRemaining, error); } public static EffectResponse Finished(uint id, string? message = null) { return new EffectResponse(id, EffectStatus.Finished, 0L, message); } public static EffectResponse Finished(uint id, StandardErrors error) { return new EffectResponse(id, EffectStatus.Finished, 0L, error); } } public interface IEffectSourceDetails { public class Converter : JsonConverter { public static readonly Converter Instance = new Converter(); public override IEffectSourceDetails? ReadJson(JsonReader reader, Type objectType, IEffectSourceDetails? existingValue, bool hasExistingValue, JsonSerializer serializer) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Invalid comparison between Unknown and I4 if ((int)reader.TokenType == 11) { return null; } JObject val = JObject.Load(reader); JToken obj = val["type"]; string text = ((obj != null) ? Extensions.Value((IEnumerable)obj) : null); if (1 == 0) { } IEffectSourceDetails result = text switch { "twitch-channel-reward" => ((JToken)val).ToObject(), "stream-labs-donation" => ((JToken)val).ToObject(), "event-hype-train" => ((JToken)val).ToObject(), "tiktok-gift" => ((JToken)val).ToObject(), "tiktok-like" => ((JToken)val).ToObject(), "tiktok-follow" => ((JToken)val).ToObject(), "tiktok-share" => ((JToken)val).ToObject(), "pulsoid-trigger" => ((JToken)val).ToObject(), "crowd-control-test" => ((JToken)val).ToObject(), "crowd-control-chaos-mode" => ((JToken)val).ToObject(), "crowd-control-retry" => ((JToken)val).ToObject(), _ => null, }; if (1 == 0) { } return result; } public override void WriteJson(JsonWriter writer, IEffectSourceDetails? value, JsonSerializer serializer) { serializer.Serialize(writer, (object)((value == null) ? null : JObject.FromObject((object)value))); } } [JsonProperty("type")] string Type { get; } } public class TwitchChannelRewardSourceDetails : IEffectSourceDetails { [JsonProperty("type")] public string Type => "twitch-channel-reward"; [JsonProperty("rewardID")] public string RewardID { get; set; } [JsonProperty("redemptionID")] public string RedemptionID { get; set; } [JsonProperty("twitchID")] public string TwitchID { get; set; } [JsonProperty("name")] public string Name { get; set; } [JsonProperty("cost")] public int Cost { get; set; } } public class StreamLabsDonationSourceDetails : IEffectSourceDetails { [JsonProperty("type")] public string Type => "stream-labs-donation"; [JsonProperty("donationID")] public string DonationID { get; set; } [JsonProperty("cost")] public string Cost { get; set; } [JsonProperty("currency")] public string Currency { get; set; } [JsonProperty("name")] public string? Name { get; set; } [JsonProperty("message")] public string? Message { get; set; } } public class HypeTrainSourceDetails : IEffectSourceDetails { public class Contribution { [JsonProperty("user_id")] public string UserID { get; set; } [JsonProperty("user_login")] public string UserLogin { get; set; } [JsonProperty("user_name")] public string UserName { get; set; } [JsonProperty("type")] public string Type { get; set; } [JsonProperty("total")] public int Total { get; set; } } [JsonProperty("type")] public string Type => "event-hype-train"; [JsonProperty("total")] public int Total { get; set; } [JsonProperty("progress")] public int Progress { get; set; } [JsonProperty("goal")] public int Goal { get; set; } [JsonProperty("top_contributions")] public List TopContributions { get; set; } [JsonProperty("last_contribution")] public Contribution LastContribution { get; set; } [JsonProperty("level")] public int Level { get; set; } } public abstract class TikTokSourceDetails : IEffectSourceDetails { [JsonProperty("type")] public abstract string Type { get; } [JsonProperty("cost")] public int Cost { get; set; } [JsonProperty("name")] public string Name { get; set; } [JsonProperty("userID")] public string UserID { get; set; } } public class TikTokGiftSourceDetails : TikTokSourceDetails { [JsonProperty("type")] public override string Type => "tiktok-gift"; [JsonProperty("giftID")] public int GiftID { get; set; } [JsonProperty("giftName")] public string GiftName { get; set; } [JsonProperty("transactionID")] public string? TransactionID { get; set; } } public class TikTokLikeSourceDetails : TikTokSourceDetails { [JsonProperty("type")] public override string Type => "tiktok-like"; } public class TikTokFollowSourceDetails : TikTokSourceDetails { [JsonProperty("type")] public override string Type => "tiktok-follow"; } public class TikTokShareSourceDetails : TikTokSourceDetails { [JsonProperty("type")] public override string Type => "tiktok-share"; } public class PulsoidTriggerSourceDetails : IEffectSourceDetails { [JsonProperty("type")] public string Type => "pulsoid-trigger"; [JsonProperty("heartRate")] public int HeartRate { get; set; } [JsonProperty("uuid")] public Guid Uuid { get; set; } [JsonProperty("triggerType")] public string TriggerType { get; set; } [JsonProperty("targetHeartRate")] public int TargetHeartRate { get; set; } [JsonProperty("holdTime")] public int HoldTime { get; set; } [JsonProperty("cooldown")] public int Cooldown { get; set; } } public class CrowdControlTestSourceDetails : IEffectSourceDetails { [JsonProperty("type")] public string Type => "crowd-control-test"; } public class CrowdControlChaosModeSourceDetails : IEffectSourceDetails { [JsonProperty("type")] public string Type => "crowd-control-chaos-mode"; } public class CrowdControlRetrySourceDetails : IEffectSourceDetails { [JsonProperty("type")] public string Type => "crowd-control-retry"; } [JsonConverter(typeof(CamelCaseStringEnumConverter))] public enum EffectStatus { Success = 0, Failure = 1, Unavailable = 2, Retry = 3, Queue = 4, Running = 5, Paused = 6, Resumed = 7, Finished = 8, Wait = 9, RemoteScheduled = 10, Visible = 128, NotVisible = 129, Selectable = 130, NotSelectable = 131, Reserved0 = 160, NotReady = 255 } public class EffectUpdate : SimpleJSONResponse { [JsonConverter(typeof(CamelCaseStringEnumConverter))] public enum IdentifierType { Effect, Group, Category } [Obsolete("This field is deprecated. Please use the ids field instead.")] [JsonProperty(/*Could not decode attribute arguments.*/)] public string? code; [JsonProperty(/*Could not decode attribute arguments.*/)] public string[]? ids; public IdentifierType idType; public EffectStatus status; public string? message; public EffectUpdate() { } public EffectUpdate(string id, EffectStatus status, string? message = null) { ids = new string[1] { id }; idType = IdentifierType.Effect; this.status = status; this.message = message; type = ResponseType.EffectStatus; } public EffectUpdate(string id, IdentifierType idType, EffectStatus status, string? message = null) { ids = new string[1] { id }; this.idType = idType; this.status = status; this.message = message; type = ResponseType.EffectStatus; } public EffectUpdate(string[] ids, EffectStatus status, string? message = null) { this.ids = ids; idType = IdentifierType.Effect; this.status = status; this.message = message; type = ResponseType.EffectStatus; } public EffectUpdate(string[] ids, IdentifierType idType, EffectStatus status, string? message = null) { this.ids = ids; this.idType = idType; this.status = status; this.message = message; type = ResponseType.EffectStatus; } public EffectUpdate(IEnumerable ids, EffectStatus status, string? message = null) { this.ids = ids.ToArray(); idType = IdentifierType.Effect; this.status = status; this.message = message; type = ResponseType.EffectStatus; } public EffectUpdate(IEnumerable ids, IdentifierType idType, EffectStatus status, string? message = null) { this.ids = ids.ToArray(); this.idType = idType; this.status = status; this.message = message; type = ResponseType.EffectStatus; } } public class EmptyRequest : SimpleJSONRequest { } public class EmptyResponse : SimpleJSONResponse { } internal static class EnumEx { internal static string ToCamelCase(this Enum value) { return value.ToString("G").ToCamelCase(); } } [JsonConverter(typeof(CamelCaseStringEnumConverter))] public enum GameState { Unknown = 0, Error = -1, Unmodded = -2, BadGameSettings = -3, WrongVersion = -4, NotFocused = -5, Loading = -6, InLevel = 1, [Obsolete("Use InLevel instead. This state is redundant and does not provide any additional information about the game state.")] Ready = 1, TitleScreen = -17, Credits = -18, Menu = -13, Paused = -7, WrongMode = -8, SafeArea = -9, StartingArea = -19, Dialogue = -20, Cutscene = -11, BadPlayerState = -12, InputLocked = -21, Map = -14, UntimedArea = -10, InCombat = -15, NotInCombat = -16, PipelineBusy = -128, NotReady = int.MinValue } public class GameUpdate : SimpleJSONResponse { public GameState state; public string? message; public GameUpdate(GameState state, string? message = null) { this.state = state; this.message = message; type = ResponseType.GameUpdate; } } public class GenericEventRequest : SimpleJSONRequest { [JsonProperty(PropertyName = "internal")] public bool @internal; public string eventType; public Dictionary? data; public GenericEventRequest(string eventType) { type = RequestType.GenericEvent; this.eventType = eventType; } [JsonConstructor] public GenericEventRequest(string eventType, IEnumerable>? data) : this(eventType) { this.data = ((data != null) ? data.ToDictionary() : null); } [JsonConstructor] public GenericEventRequest(string eventType, IEnumerable>? data, bool @internal) : this(eventType, data) { this.@internal = @internal; } } public class GenericEventResponse : SimpleJSONResponse { [JsonProperty(PropertyName = "internal")] public bool @internal; public string eventType; public Dictionary? data; public GenericEventResponse(string eventType) { type = ResponseType.GenericEvent; this.eventType = eventType; } public GenericEventResponse(string eventType, IEnumerable>? data, bool @internal = false) : this(eventType) { this.data = ((data != null) ? data.ToDictionary() : null); this.@internal = @internal; } [JsonConstructor] public GenericEventResponse(string eventType, Dictionary? data, [JsonProperty(PropertyName = "internal")] bool @internal) : this(eventType, data) { this.@internal = @internal; } } internal class HexColorConverter : JsonConverter { private static readonly Dictionary CHAR_LOOKUP = new Dictionary { { '0', 0 }, { '1', 1 }, { '2', 2 }, { '3', 3 }, { '4', 4 }, { '5', 5 }, { '6', 6 }, { '7', 7 }, { '8', 8 }, { '9', 9 }, { 'A', 10 }, { 'B', 11 }, { 'C', 12 }, { 'D', 13 }, { 'E', 14 }, { 'F', 15 } }; public override void WriteJson(JsonWriter writer, ParameterColorValue value, JsonSerializer serializer) { serializer.Serialize(writer, (object)$"#{((value.A != byte.MaxValue) ? value.A.ToString("X2") : string.Empty)}{value.R:X2}{value.G:X2}{value.B:X2}"); } public override ParameterColorValue ReadJson(JsonReader reader, Type objectType, ParameterColorValue existingValue, bool hasExistingValue, JsonSerializer serializer) { string value = serializer.Deserialize(reader); if (TryParse(value, out var color)) { return color; } throw new SerializationException("Unrecognized color code."); } public static bool TryParse(string? value, out ParameterColorValue color) { if (value == null) { color = default(ParameterColorValue); return false; } value = value.TrimStart('#'); switch (value.Length) { case 6: { string[] array2 = value.Chop(2); byte result2; byte red3 = (byte)(byte.TryParse(array2[0], NumberStyles.AllowHexSpecifier, NumberFormatInfo.InvariantInfo, out result2) ? result2 : 0); byte green3 = (byte)(byte.TryParse(array2[1], NumberStyles.AllowHexSpecifier, NumberFormatInfo.InvariantInfo, out result2) ? result2 : 0); byte blue3 = (byte)(byte.TryParse(array2[2], NumberStyles.AllowHexSpecifier, NumberFormatInfo.InvariantInfo, out result2) ? result2 : 0); color = ParameterColorValue.FromArgb(red3, green3, blue3); return true; } case 8: { string[] array = value.Chop(2); byte result; byte alpha2 = (byte)(byte.TryParse(array[0], NumberStyles.AllowHexSpecifier, NumberFormatInfo.InvariantInfo, out result) ? result : 0); byte red2 = (byte)(byte.TryParse(array[1], NumberStyles.AllowHexSpecifier, NumberFormatInfo.InvariantInfo, out result) ? result : 0); byte green2 = (byte)(byte.TryParse(array[2], NumberStyles.AllowHexSpecifier, NumberFormatInfo.InvariantInfo, out result) ? result : 0); byte blue2 = (byte)(byte.TryParse(array[3], NumberStyles.AllowHexSpecifier, NumberFormatInfo.InvariantInfo, out result) ? result : 0); color = ParameterColorValue.FromArgb(alpha2, red2, green2, blue2); return true; } case 3: { byte value3; byte red4 = (byte)(CHAR_LOOKUP.TryGetValue(value[0], out value3) ? checked((byte)(value3 * 16)) : 0); byte green4 = (byte)(CHAR_LOOKUP.TryGetValue(value[1], out value3) ? checked((byte)(value3 * 16)) : 0); byte blue4 = (byte)(CHAR_LOOKUP.TryGetValue(value[2], out value3) ? checked((byte)(value3 * 16)) : 0); color = ParameterColorValue.FromArgb(red4, green4, blue4); return true; } case 4: { byte value2; byte alpha = (byte)(CHAR_LOOKUP.TryGetValue(value[0], out value2) ? checked((byte)(value2 * 16)) : 0); byte red = (byte)(CHAR_LOOKUP.TryGetValue(value[1], out value2) ? checked((byte)(value2 * 16)) : 0); byte green = (byte)(CHAR_LOOKUP.TryGetValue(value[2], out value2) ? checked((byte)(value2 * 16)) : 0); byte blue = (byte)(CHAR_LOOKUP.TryGetValue(value[3], out value2) ? checked((byte)(value2 * 16)) : 0); color = ParameterColorValue.FromArgb(alpha, red, green, blue); return true; } default: color = default(ParameterColorValue); return false; } } } internal static class IEnumerableEx { internal static Dictionary ToDictionary(this IEnumerable> values) where TKey : notnull { Dictionary dictionary = new Dictionary(); foreach (KeyValuePair value in values) { dictionary.Add(value.Key, value.Value); } return dictionary; } } public interface IParameterValue { string ID { get; } string Name { get; } ParameterBase.ParameterType Type { get; } object? Value { get; } } public class LoginRequest : SimpleJSONRequest { public string? login; public string? password; } public class MessageRequest : SimpleJSONRequest { public string? message; } public class MessageResponse : SimpleJSONResponse { public string? message; } internal static class ObjectEx { internal static T2? IfNotNull(this T1? value, Func selector) where T2 : class { return (value != null) ? selector(value) : null; } } public abstract class ParameterBase { [JsonConverter(typeof(ParameterTypeConverter))] public enum ParameterType { Options, HexColor } private class ParameterTypeConverter : JsonConverter { public override void WriteJson(JsonWriter writer, ParameterType value, JsonSerializer serializer) { if (1 == 0) { } string text = value switch { ParameterType.Options => "options", ParameterType.HexColor => "hex-color", _ => throw new SerializationException("Unknown parameter type."), }; if (1 == 0) { } string text2 = text; writer.WriteValue(text2); } public override ParameterType ReadJson(JsonReader reader, Type objectType, ParameterType existingValue, bool hasExistingValue, JsonSerializer serializer) { switch (reader.Value?.ToString().ToLowerInvariant()) { case "options": return ParameterType.Options; case "hexcolor": case "hex-color": return ParameterType.HexColor; default: throw new SerializationException("Unknown parameter type."); } } } [JsonIgnore] public readonly string ID; [JsonProperty(PropertyName = "title")] public readonly string Name; [JsonProperty(PropertyName = "type")] public readonly ParameterType Type; protected ParameterBase(string name, string id, ParameterType type) { ID = id; Name = name; Type = type; } } public class ParameterColor : ParameterBase, IParameterValue { [JsonProperty(PropertyName = "value")] [JsonConverter(typeof(HexColorConverter))] public ParameterColorValue Value; [JsonIgnore] string IParameterValue.ID => ID; [JsonIgnore] string IParameterValue.Name => Name; [JsonIgnore] ParameterType IParameterValue.Type => Type; [JsonIgnore] object? IParameterValue.Value => Value; [JsonConstructor] public ParameterColor(string name, string id, ParameterColorValue value) : base(name, id, ParameterType.HexColor) { Value = value; } [JsonConstructor] public ParameterColor(string name, string id, string value) : base(name, id, ParameterType.HexColor) { if (!HexColorConverter.TryParse(value, out Value)) { throw new ArgumentException("Unknown color code.", "value"); } } } [DebuggerDisplay("{NameAndARGBValue}")] [TypeForwardedFrom("System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] public readonly struct ParameterColorValue : IEquatable { public static readonly ParameterColorValue Empty = default(ParameterColorValue); private const short StateARGBValueValid = 2; private const short StateValueMask = 2; private const short StateNameValid = 8; private const long NotDefinedValue = 0L; internal const int ARGBAlphaShift = 24; internal const int ARGBRedShift = 16; internal const int ARGBGreenShift = 8; internal const int ARGBBlueShift = 0; internal const uint ARGBAlphaMask = 4278190080u; internal const uint ARGBRedMask = 16711680u; internal const uint ARGBGreenMask = 65280u; internal const uint ARGBBlueMask = 255u; private readonly long value; private readonly short state; public byte R => (byte)(Value >> 16); public byte G => (byte)(Value >> 8); public byte B => (byte)Value; public byte A => (byte)(Value >> 24); public bool IsEmpty => state == 0; private long Value { get { if ((state & 2) != 0) { return value; } return 0L; } } private ParameterColorValue(long value, short state) { this.value = value; this.state = state; } private static ParameterColorValue FromArgb(uint argb) { return new ParameterColorValue(argb, 2); } public static ParameterColorValue FromArgb(int argb) { return FromArgb((uint)argb); } public static ParameterColorValue FromArgb(byte alpha, byte red, byte green, byte blue) { return FromArgb((uint)((alpha << 24) | (red << 16) | (green << 8) | blue)); } public static ParameterColorValue FromArgb(int alpha, ParameterColorValue baseColor) { return FromArgb(checked(((uint)alpha << 24) | ((uint)baseColor.Value & 0xFFFFFF))); } public static ParameterColorValue FromArgb(byte red, byte green, byte blue) { return FromArgb(byte.MaxValue, red, green, blue); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void GetRgbValues(out byte r, out byte g, out byte b) { checked { uint num = (uint)Value; r = (byte)((num & 0xFF0000) >> 16); g = (byte)((num & 0xFF00) >> 8); b = (byte)(num & 0xFF); } } public float GetBrightness() { GetRgbValues(out var r, out var g, out var b); int num = Math.Min(Math.Min(r, g), b); int num2 = Math.Max(Math.Max(r, g), b); return (float)checked(num2 + num) / 510f; } public float GetHue() { GetRgbValues(out var r, out var g, out var b); if (r == g && g == b) { return 0f; } int num = Math.Min(Math.Min(r, g), b); int num2 = Math.Max(Math.Max(r, g), b); checked { float num3 = num2 - num; float num4 = ((r == num2) ? ((float)(g - b) / num3) : ((g != num2) ? ((float)(r - g) / num3 + 4f) : ((float)(b - r) / num3 + 2f))); num4 *= 60f; if (num4 < 0f) { num4 += 360f; } return num4; } } public float GetSaturation() { GetRgbValues(out var r, out var g, out var b); if (r == g && g == b) { return 0f; } int num = Math.Min(Math.Min(r, g), b); int num2 = Math.Max(Math.Max(r, g), b); checked { int num3 = num2 + num; if (num3 > 255) { num3 = 510 - num2 - num; } return (float)(num2 - num) / (float)num3; } } public int ToArgb() { return (int)Value; } public override string ToString() { if ((state & 2) != 0) { return "ParameterColorValue [A=" + A + ", R=" + R + ", G=" + G + ", B=" + B + "]"; } return "ParameterColorValue [Empty]"; } public static bool operator ==(ParameterColorValue left, ParameterColorValue right) { return left.value == right.value && left.state == right.state; } public static bool operator !=(ParameterColorValue left, ParameterColorValue right) { return !(left == right); } public override bool Equals(object? obj) { return obj is ParameterColorValue other && Equals(other); } public bool Equals(ParameterColorValue other) { return this == other; } public override int GetHashCode() { return (value.GetHashCode() * 397) ^ state.GetHashCode(); } } public class ParameterValue : ParameterBase, IParameterValue { [JsonProperty(PropertyName = "value")] public TValue? Value; [JsonIgnore] string IParameterValue.ID => ID; [JsonIgnore] string IParameterValue.Name => Name; [JsonIgnore] ParameterType IParameterValue.Type => Type; [JsonIgnore] object? IParameterValue.Value => Value; [JsonConstructor] public ParameterValue(string name, string id, TValue? value) : base(name, id, ParameterType.Options) { Value = value; } public override string ToString() { return Name; } } public class PlayerInfo : SimpleJSONRequest { public JObject? player; public PlayerInfo() { type = RequestType.PlayerInfo; } } [JsonConverter(typeof(Converter))] public class RequestParameters : IReadOnlyList, IEnumerable, IEnumerable, IReadOnlyCollection, IReadOnlyDictionary, IEnumerable>, IReadOnlyCollection> { private class Converter : JsonConverter { public override void WriteJson(JsonWriter writer, RequestParameters? value, JsonSerializer serializer) { serializer.Serialize(writer, (object)value?._parameters); } public override RequestParameters? ReadJson(JsonReader reader, Type objectType, RequestParameters? existingValue, bool hasExistingValue, JsonSerializer serializer) { JObject val = JObject.Load(reader); List list = new List(); foreach (KeyValuePair item in val) { string key = item.Key; string name = Extensions.Value((IEnumerable)item.Value[(object)"name"]); switch (Extensions.Value((IEnumerable)item.Value[(object)"type"])) { case ParameterBase.ParameterType.Options: { string value2 = Extensions.Value((IEnumerable)item.Value[(object)"value"]); list.Add(new ParameterValue(name, key, value2)); break; } case ParameterBase.ParameterType.HexColor: { string value = Extensions.Value((IEnumerable)item.Value[(object)"value"]); if (HexColorConverter.TryParse(value, out var color)) { list.Add(new ParameterColor(name, key, color)); } break; } default: throw new SerializationException(); } } return new RequestParameters(list); } } private readonly Dictionary _parameters; private readonly List _parameter_list; int IReadOnlyCollection.Count => _parameters.Count; int IReadOnlyCollection>.Count => _parameters.Count; public string this[int index] => _parameter_list[index]; public IParameterValue this[string key] => _parameters[key]; public IEnumerable Keys => _parameters.Keys; public IEnumerable Values => _parameters.Values; public int Count => _parameters.Count; private RequestParameters() { _parameters = new Dictionary(); _parameter_list = new List(); } public RequestParameters(IEnumerable parameters) { parameters = parameters.ToArray(); _parameters = parameters.ToDictionary((IParameterValue d) => d.ID); _parameter_list = parameters.Select((IParameterValue v) => v.Value.ToString()).ToList(); } public RequestParameters(IEnumerable> parameters) { _parameters = parameters.ToDictionary(); _parameter_list = _parameters.Values.Select((IParameterValue p) => p.Value.ToString()).ToList(); } IEnumerator> IEnumerable>.GetEnumerator() { return _parameters.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return _parameters.Values.Select((IParameterValue v) => v.Value?.ToString()).GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable)this).GetEnumerator(); } public bool ContainsKey(string key) { return _parameters.ContainsKey(key); } public bool TryGetValue(string key, out IParameterValue value) { return _parameters.TryGetValue(key, out value); } public IEnumerable Where(Func predicate) { return Enumerable.Where(this, predicate); } public IEnumerable Select(Func selector) { return Enumerable.Select(this, selector); } public IEnumerable SelectMany(Func> selector) { return Enumerable.SelectMany(this, selector); } public IEnumerable SelectMany(Func> selector) { return Enumerable.SelectMany(this, selector); } public string First() { return this.First(); } public string First(Func predicate) { return Enumerable.First(this, predicate); } public string? FirstOrDefault() { return this.FirstOrDefault(); } public string FirstOrDefault(string defaultValue) { return this.FirstOrDefault() ?? defaultValue; } public string? FirstOrDefault(Func predicate) { return Enumerable.FirstOrDefault(this, predicate); } public string FirstOrDefault(Func predicate, string defaultValue) { return Enumerable.FirstOrDefault(this, predicate) ?? defaultValue; } public bool Any() { return this.Any(); } public bool Any(Func predicate) { return Enumerable.Any(this, predicate); } } public enum RequestType : byte { EffectTest = 0, EffectStart = 1, EffectStop = 2, [Obsolete("Use EffectTest instead.")] Test = 0, [Obsolete("Use EffectStart instead.")] Start = 1, [Obsolete("Use EffectStop instead.")] Stop = 2, GenericEvent = 16, DataRequest = 32, RpcResponse = 208, PlayerInfo = 224, Login = 240, Version = 252, GameUpdate = 253, KeepAlive = byte.MaxValue } [JsonConverter(typeof(CamelCaseStringEnumConverter))] public enum ResponseType : byte { EffectRequest = 0, EffectStatus = 1, GenericEvent = 16, LoadEvent = 24, SaveEvent = 25, DataResponse = 32, RpcRequest = 208, Login = 240, LoginSuccess = 241, Version = 252, GameUpdate = 253, Disconnect = 254, KeepAlive = byte.MaxValue } public class RpcRequest : SimpleJSONResponse { public string? method; public object?[]? args; public RpcTarget? target; public RpcRequest() { type = ResponseType.RpcRequest; } } public class RpcResponse : SimpleJSONRequest { public object? value; [JsonProperty(/*Could not decode attribute arguments.*/)] public bool exception; public RpcResponse() { type = RequestType.RpcResponse; } } [Flags] [JsonConverter(typeof(CamelCaseStringEnumConverter))] public enum RpcTarget { Game = 1, Pack = 2, Native = 4, Client = 8, Server = 0x10 } public abstract class SimpleJSONMessage { public static readonly JsonSerializerSettings JSON_SERIALIZER_SETTINGS = new JsonSerializerSettings { NullValueHandling = (NullValueHandling)1, MissingMemberHandling = (MissingMemberHandling)0, Formatting = (Formatting)0 }; public static readonly JsonSerializer JSON_SERIALIZER = new JsonSerializer { NullValueHandling = JSON_SERIALIZER_SETTINGS.NullValueHandling, MissingMemberHandling = JSON_SERIALIZER_SETTINGS.MissingMemberHandling, Formatting = JSON_SERIALIZER_SETTINGS.Formatting }; private static int _next_id = 0; public static uint NextID { get { uint result; while ((result = (uint)Interlocked.Increment(ref _next_id)) == 0) { } return result; } } public abstract uint ID { get; } public abstract bool IsKeepAlive { get; } public string Serialize() { return JsonConvert.SerializeObject((object)this, JSON_SERIALIZER_SETTINGS); } } public class SimpleJSONRequest : SimpleJSONMessage { public uint id = SimpleJSONMessage.NextID; public RequestType type; [JsonIgnore] public override uint ID => id; [JsonIgnore] public override bool IsKeepAlive => type == RequestType.KeepAlive; public static bool TryParse(string json, out SimpleJSONRequest? request) { return TryParse(JObject.Parse(json), out request); } public static bool TryParse(JObject j, out SimpleJSONRequest? request) { try { JToken value = j.GetValue("type"); switch ((value != null) ? ((RequestType)(object)CamelCaseStringEnumConverter.ReadJToken(value, typeof(RequestType))) : RequestType.EffectTest) { case RequestType.EffectTest: case RequestType.EffectStart: request = ((JToken)j).ToObject(SimpleJSONMessage.JSON_SERIALIZER); return true; case RequestType.EffectStop: request = ((JToken)j).ToObject(SimpleJSONMessage.JSON_SERIALIZER); return true; case RequestType.DataRequest: request = ((JToken)j).ToObject(SimpleJSONMessage.JSON_SERIALIZER); return true; case RequestType.RpcResponse: request = ((JToken)j).ToObject(SimpleJSONMessage.JSON_SERIALIZER); return true; case RequestType.PlayerInfo: request = ((JToken)j).ToObject(SimpleJSONMessage.JSON_SERIALIZER); return true; case RequestType.Login: request = ((JToken)j).ToObject(SimpleJSONMessage.JSON_SERIALIZER); return true; case RequestType.Version: request = ((JToken)j).ToObject(SimpleJSONMessage.JSON_SERIALIZER); return true; case RequestType.GameUpdate: request = ((JToken)j).ToObject(SimpleJSONMessage.JSON_SERIALIZER); return true; case RequestType.KeepAlive: request = ((JToken)j).ToObject(SimpleJSONMessage.JSON_SERIALIZER); return true; } } catch { } request = null; return false; } } public class SimpleJSONResponse : SimpleJSONMessage { public uint id; public ResponseType type; [JsonIgnore] public override uint ID => id; [JsonIgnore] public override bool IsKeepAlive => type == ResponseType.KeepAlive; [JsonIgnore] public static SimpleJSONResponse KeepAlive { get; } = new EmptyResponse { type = ResponseType.KeepAlive }; public static bool TryParse(string json, out SimpleJSONResponse? response) { return TryParse(JObject.Parse(json), out response); } public static bool TryParse(JObject j, out SimpleJSONResponse? response) { try { JToken value = j.GetValue("type"); ResponseType responseType = ((value != null) ? ((ResponseType)(object)CamelCaseStringEnumConverter.ReadJToken(value, typeof(ResponseType))) : ResponseType.EffectRequest); ResponseType responseType2 = responseType; ResponseType responseType3 = responseType2; switch (responseType3) { case ResponseType.EffectStatus: if (responseType3 != ResponseType.EffectStatus) { break; } response = ((JToken)j).ToObject(SimpleJSONMessage.JSON_SERIALIZER); return true; case ResponseType.EffectRequest: response = ((JToken)j).ToObject(SimpleJSONMessage.JSON_SERIALIZER); return true; case ResponseType.RpcRequest: response = ((JToken)j).ToObject(SimpleJSONMessage.JSON_SERIALIZER); return true; case ResponseType.GenericEvent: response = ((JToken)j).ToObject(SimpleJSONMessage.JSON_SERIALIZER); return true; case ResponseType.DataResponse: response = ((JToken)j).ToObject(SimpleJSONMessage.JSON_SERIALIZER); return true; case ResponseType.Login: response = ((JToken)j).ToObject(SimpleJSONMessage.JSON_SERIALIZER); return true; case ResponseType.LoginSuccess: response = ((JToken)j).ToObject(SimpleJSONMessage.JSON_SERIALIZER); return true; case ResponseType.Version: response = ((JToken)j).ToObject(SimpleJSONMessage.JSON_SERIALIZER); return true; case ResponseType.GameUpdate: response = ((JToken)j).ToObject(SimpleJSONMessage.JSON_SERIALIZER); return true; case ResponseType.Disconnect: response = ((JToken)j).ToObject(SimpleJSONMessage.JSON_SERIALIZER); return true; case ResponseType.KeepAlive: response = ((JToken)j).ToObject(SimpleJSONMessage.JSON_SERIALIZER); return true; } } catch { } response = null; return false; } } [JsonConverter(typeof(CamelCaseStringEnumConverter))] public enum StandardErrors { Unknown = 0, ExceptionThrown = 1, BadRequest = 4096, EffectUnknown = 4097, [Obsolete("Use EffectUnknown instead.")] UnknownEffect = 4097, EffectDisabled = 4098, AlreadyFailed = 4099, CannotParseNumber = 4112, UnknownSelection = 4113, ConnectorError = 8192, ConnectorReadFailure = 8193, ConnectorWriteFailure = 8194, ConnectorNotConnected = 8195, ConnectorNotSupported = 8196, NoResponse = 8448, SettingsError = 12288, CooldownPerEffect = 12545, CooldownGlobal = 12546, RetryMaxTime = 12291, RetryMaxAttempts = 12292, NoSession = 20480, SessionEnding = 20481, BadGameState = 16384, GameObjectNotFound = 16640, PlayerNotFound = 16641, CharacterNotFound = 16642, EnemyNotFound = 16643, ObjectNotFound = 16644, PrerequisiteNotFound = 16645, ObjectStateError = 16896, AlreadyInState = 16897, AlreadyAcquired = 16898, AlreadyFinished = 16899, NoEmptyContainers = 16912, PartyFull = 16913, InvalidArea = 16928, InvalidTarget = 16929, NoValidTargets = 16930, SpawnNotAllowedHere = 16932, RangeError = 17152, AlreadyMinimum = 17153, AlreadyMaximum = 17154, EffectNotImplemented = 24576, PackResourceMissing = 24577, EmulatorNotSupported = 28672, EmulatorInvalidSetting = 28673, ConflictingEffectRunning = 32768, UnqueueablePending = 32769 } internal static class StringEx { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsNullOrWhiteSpace(this string? input) { return string.IsNullOrWhiteSpace(input); } internal static string ToCamelCase(this string input) { bool flag = false; string text = ""; checked { for (int i = 0; i < input.Length; i++) { if (char.IsUpper(input[i])) { if (flag) { text += input.Substring(i); break; } text += char.ToLower(input[i]); } else { flag = true; text = ((i <= 1 || !char.IsUpper(input[i - 1]) || !char.IsUpper(input[i - 2])) ? (text + input[i]) : (text.Substring(0, text.Length - 1) + char.ToUpper(input[i - 1]) + input[i])); } } return text; } } internal unsafe static string[] Chop(this string value, int chopLength) { int length = value.Length; char* ptr = stackalloc char[chopLength]; string[] array = new string[length]; for (int i = 0; i < length; i = checked(i + chopLength)) { int j; for (j = 0; j < chopLength; j = checked(j + 1)) { int num = checked(i + j); if (num >= length) { break; } *(char*)((byte*)ptr + checked(unchecked((nint)j) * (nint)2)) = value[num]; } array[i / chopLength] = new string(ptr, 0, j); } return array; } } public static class TypeEx { public static bool IsAssignableTo(this Type? type, Type? targetType) { return (object)type != null && (object)targetType != null && targetType.IsAssignableFrom(type); } } [Serializable] [JsonConverter(typeof(Converter))] public class VersionNumber : IEquatable, IComparable { private class Converter : JsonConverter { public override void WriteJson(JsonWriter writer, VersionNumber? value, JsonSerializer serializer) { if (value == null) { writer.WriteNull(); } else { writer.WriteValue((string)value); } } public override VersionNumber? ReadJson(JsonReader reader, Type objectType, VersionNumber? existingValue, bool hasExistingValue, JsonSerializer serializer) { object value = reader.Value; if (value == null) { return null; } if (!(value is string value2)) { return null; } return new VersionNumber(value2); } } public static readonly VersionNumber Zero = new VersionNumber(new Span(new uint[1])); public static readonly VersionNumber One = new VersionNumber(new Span(new uint[1] { 1u })); private readonly uint[] _version; public VersionNumber(string value) { _version = (from v in value.Split('.') select uint.TryParse(Sanitize(v), out var result) ? result : 0u).ToArray(); } public VersionNumber(IEnumerable values) { _version = values.ToArray(); } public VersionNumber(VersionNumber version) { _version = version._version.ToArray(); } public VersionNumber([ParamCollection] scoped Span values) { _version = values.ToArray(); } public static implicit operator VersionNumber(string value) { return new VersionNumber(value); } public static implicit operator VersionNumber(uint value) { return new VersionNumber(new Span(new uint[1] { value })); } public static implicit operator VersionNumber(uint[] values) { return new VersionNumber((Span)values); } public static implicit operator VersionNumber(Span values) { return new VersionNumber(values); } public static implicit operator VersionNumber(List values) { return new VersionNumber((IEnumerable)values); } public static implicit operator string(VersionNumber value) { return value.ToString(); } public static implicit operator uint[](VersionNumber value) { return value._version.ToArray(); } public static bool operator ==(VersionNumber? a, VersionNumber? b) { return Equals(a, b); } public static bool operator !=(VersionNumber? a, VersionNumber? b) { return !Equals(a, b); } public static bool operator <(VersionNumber? a, VersionNumber? b) { return CompareTo(a, b) < 0; } public static bool operator >(VersionNumber? a, VersionNumber? b) { return CompareTo(a, b) > 0; } public static bool operator <=(VersionNumber? a, VersionNumber? b) { return CompareTo(a, b) <= 0; } public static bool operator >=(VersionNumber? a, VersionNumber? b) { return CompareTo(a, b) >= 0; } public override string ToString() { return string.Join('.', _version.Select((uint v) => v.ToString("D"))); } public static bool Equals(VersionNumber? a, VersionNumber? b) { return a?.Equals(b) ?? ((object)b == null); } public override bool Equals(object? obj) { if (obj == null) { return false; } if (this == obj) { return true; } if (obj.GetType().IsAssignableTo(typeof(VersionNumber))) { return false; } return Equals((VersionNumber)obj); } public override int GetHashCode() { return _version.GetHashCode(); } public bool Equals(VersionNumber? other) { if ((object)other == null) { return false; } if ((object)this == other) { return true; } int num = _version.Length; if (num != other._version.Length) { return false; } for (int i = 0; i < num; i = checked(i + 1)) { if (_version[i] != other._version[i]) { return false; } } return true; } public static int CompareTo(VersionNumber? a, VersionNumber? b) { return a?.CompareTo(b) ?? (((object)b != null) ? (-1) : 0); } public int CompareTo(VersionNumber? other) { if ((object)other == null) { return 1; } int num = _version.Length; int num2 = other._version.Length; int num3 = Math.Min(num, num2); checked { int i; for (i = 0; i < num3; i++) { uint num4 = _version[i]; uint num5 = other._version[i]; if (num4 != num5) { if (num4 > num5) { return 1; } return -1; } } if (num == num2) { return 0; } if (num > num2) { for (; i < num; i++) { if (_version[i] != 0) { return 1; } } return 0; } for (; i < num2; i++) { if (other._version[i] != 0) { return -1; } } return 0; } } public static VersionNumber GetAssemblyVersion(IEnumerable assemblies) { VersionNumber versionNumber = Zero; foreach (Assembly assembly in assemblies) { VersionNumber versionNumber2; try { versionNumber2 = GetAssemblyVersion(assembly); } catch { versionNumber2 = Zero; } if (versionNumber2 > versionNumber) { versionNumber = versionNumber2; } } return versionNumber; } public static VersionNumber GetAssemblyVersion(Assembly assembly) { string text = null; object[] customAttributes = assembly.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), inherit: false); if (customAttributes != null && customAttributes.Length > 0) { text = ((AssemblyInformationalVersionAttribute)customAttributes[0]).InformationalVersion; } if (text == null || text.Length == 0) { text = GetFileVersionInfo(assembly).ProductVersion?.Trim(); } if (text == null || text.Length == 0) { text = Zero; } return text; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static string Sanitize(string value) { for (int i = 0; i < value.Length; i = checked(i + 1)) { if (!char.IsDigit(value[i])) { return value.Substring(0, i); } } return value; } private static FileVersionInfo GetFileVersionInfo(Assembly assembly) { return FileVersionInfo.GetVersionInfo(assembly.Location); } } public class VersionResponse : SimpleJSONResponse { public VersionNumber version; [JsonConstructor] public VersionResponse(VersionNumber version) { this.version = version; type = ResponseType.Version; } public VersionResponse(uint id, VersionNumber version) { base.id = id; this.version = version; type = ResponseType.Version; } } }