using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Numerics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using System.Text.Json; using Microsoft.CodeAnalysis; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] [assembly: AssemblyCompany("ForgeCore.Once")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.1.0.0")] [assembly: AssemblyInformationalVersion("0.1.0+66ec6b43e1a1603bac84a4b9a226674300b2fc7d")] [assembly: AssemblyProduct("ForgeCore.Once")] [assembly: AssemblyTitle("ForgeCore.Once")] [assembly: AssemblyVersion("0.1.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [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.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ForgeCore { public static class Fnv { public const uint Offset32 = 2166136261u; public const uint Prime32 = 16777619u; public const ulong Offset64 = 14695981039346656037uL; public const ulong Prime64 = 1099511628211uL; public static uint Mix32(uint hash, byte value) { return (hash ^ value) * 16777619; } public static ulong Mix64(ulong hash, byte value) { return (hash ^ value) * 1099511628211L; } public static uint Hash32(ReadOnlySpan bytes) { uint num = 2166136261u; ReadOnlySpan readOnlySpan = bytes; for (int i = 0; i < readOnlySpan.Length; i++) { byte value = readOnlySpan[i]; num = Mix32(num, value); } return num; } public static ulong Hash64(ReadOnlySpan bytes) { ulong num = 14695981039346656037uL; ReadOnlySpan readOnlySpan = bytes; for (int i = 0; i < readOnlySpan.Length; i++) { byte value = readOnlySpan[i]; num = Mix64(num, value); } return num; } public static uint Hash32(string text) { return Hash32(Encoding.UTF8.GetBytes(text)); } public static ulong Hash64(string text) { return Hash64(Encoding.UTF8.GetBytes(text)); } } public sealed class OnceReporter { private readonly Action? _sink; private readonly Dictionary _counts = new Dictionary(StringComparer.Ordinal); private readonly object _gate = new object(); public OnceReporter(Action sink) { _sink = sink ?? throw new ArgumentNullException("sink"); } public OnceReporter() { } public bool Report(string key, string message) { long count = Tick(key); if (!Reports(count)) { return false; } Write(count, message); return true; } public bool Report(string key, TState state, Func message) { long count = Tick(key); if (!Reports(count)) { return false; } Write(count, message(state)); return true; } public bool ShouldReport(string key) { return Reports(Tick(key)); } private long Tick(string key) { lock (_gate) { _counts.TryGetValue(key, out var value); return _counts[key] = value + 1; } } private void Write(long count, string message) { if (_sink == null) { throw new InvalidOperationException("This OnceReporter has no output target; use ShouldReport."); } _sink((count == 1) ? message : (message + " (" + count.ToString(CultureInfo.InvariantCulture) + " times)")); } public long Count(string key) { lock (_gate) { long value; return _counts.TryGetValue(key, out value) ? value : 0; } } public void Reset() { lock (_gate) { _counts.Clear(); } } private static bool Reports(long count) { if (count <= 0) { return false; } while (count % 10 == 0L) { count /= 10; } return count == 1; } } public static class PosixPath { public static string ToPosix(string value) { return value.Replace('\\', '/'); } } public class StrictJsonException : Exception { public string Field { get; } public StrictJsonException(string field, string message) : base(message) { Field = field; } } public static class StrictJson { public static void OnlyKnown(JsonElement value, string prefix, string[] known, string[]? alsoAllowed = null, string? owner = null) { if (value.ValueKind != JsonValueKind.Object) { throw new StrictJsonException(prefix.TrimEnd('.'), "must be an object."); } HashSet hashSet = new HashSet(StringComparer.Ordinal); foreach (JsonProperty item in value.EnumerateObject()) { if (Array.IndexOf(known, item.Name) < 0 && (alsoAllowed == null || Array.IndexOf(alsoAllowed, item.Name) < 0)) { throw new StrictJsonException(prefix + item.Name, "unknown field" + ((owner == null) ? "" : (" for " + owner)) + " (known: " + string.Join(", ", known) + ")."); } if (!hashSet.Add(item.Name)) { throw new StrictJsonException(prefix + item.Name, "duplicate field."); } } } public static void UniqueMembers(JsonElement value, string prefix = "") { if (value.ValueKind == JsonValueKind.Object) { HashSet hashSet = new HashSet(StringComparer.Ordinal); { foreach (JsonProperty item in value.EnumerateObject()) { if (!hashSet.Add(item.Name)) { throw new StrictJsonException(prefix + item.Name, "duplicate field."); } UniqueMembers(item.Value, prefix + item.Name + "."); } return; } } if (value.ValueKind != JsonValueKind.Array) { return; } foreach (JsonElement item2 in value.EnumerateArray()) { UniqueMembers(item2, prefix); } } public static JsonElement Object(JsonElement value, string prefix, string field) { if (!value.TryGetProperty(field, out var value2) || value2.ValueKind != JsonValueKind.Object) { throw new StrictJsonException(prefix + field, "is required and must be an object."); } return value2; } public static bool Finite(JsonElement value, out double number) { number = 0.0; if (value.ValueKind == JsonValueKind.Number && value.TryGetDouble(out number)) { return double.IsFinite(number); } return false; } public static double Number(JsonElement value, string prefix, string field, double? fallback, double min, double max) { if (!value.TryGetProperty(field, out var value2)) { return fallback ?? throw new StrictJsonException(prefix + field, "is required."); } if (!Finite(value2, out var number)) { throw new StrictJsonException(prefix + field, "must be a finite number."); } return InRange(number, prefix + field, min, max); } public static double Integer(JsonElement value, string prefix, string field, double? fallback, double min, double max) { if (!value.TryGetProperty(field, out var value2)) { return fallback ?? throw new StrictJsonException(prefix + field, "is required."); } if (!Finite(value2, out var number)) { throw new StrictJsonException(prefix + field, "must be a finite number."); } if (Math.Floor(number) != number) { throw new StrictJsonException(prefix + field, "must be a whole number."); } return InRange(number, prefix + field, min, max); } public static bool Bool(JsonElement value, string prefix, string field, bool? fallback) { if (!value.TryGetProperty(field, out var value2)) { return fallback ?? throw new StrictJsonException(prefix + field, "is required."); } JsonValueKind valueKind = value2.ValueKind; if (valueKind - 5 <= JsonValueKind.Object) { return value2.GetBoolean(); } throw new StrictJsonException(prefix + field, "must be true or false."); } public static T Enum(JsonElement value, string prefix, string field) where T : struct, Enum { string text = string.Join(", ", System.Enum.GetNames(typeof(T))); if (!value.TryGetProperty(field, out var value2) || value2.ValueKind != JsonValueKind.String) { throw new StrictJsonException(prefix + field, "is required: one of " + text + "."); } string text2 = value2.GetString(); if (!System.Enum.TryParse(text2, ignoreCase: false, out var result) || !System.Enum.IsDefined(typeof(T), result) || text2 != result.ToString()) { throw new StrictJsonException(prefix + field, "'" + text2 + "' is not one of " + text + "."); } return result; } public static (uint? Id, string? Name) Reference(JsonElement value, string prefix, string field) { if (!value.TryGetProperty(field, out var value2)) { throw new StrictJsonException(prefix + field, "is required (a persistentID number or a block name)."); } if (value2.ValueKind == JsonValueKind.Number && value2.TryGetUInt32(out var value3)) { return (Id: value3, Name: null); } if (value2.ValueKind == JsonValueKind.String && !string.IsNullOrEmpty(value2.GetString())) { return (Id: null, Name: value2.GetString()); } throw new StrictJsonException(prefix + field, "must be a persistentID number or a block name."); } private static double InRange(double number, string field, double min, double max) { if (!(number >= min) || !(number <= max)) { throw new StrictJsonException(field, number.ToString(CultureInfo.InvariantCulture) + " is outside " + min.ToString(CultureInfo.InvariantCulture) + ".." + max.ToString(CultureInfo.InvariantCulture) + "."); } return number; } public static string Canonical(JsonElement value) { StringBuilder stringBuilder = new StringBuilder(); Write(stringBuilder, value); return stringBuilder.ToString(); } private static void Write(StringBuilder text, JsonElement value) { switch (value.ValueKind) { case JsonValueKind.Object: { List list = new List(); foreach (JsonProperty item in value.EnumerateObject()) { list.Add(item); } list.Sort((JsonProperty a, JsonProperty b) => string.CompareOrdinal(a.Name, b.Name)); text.Append('{'); for (int num2 = 0; num2 < list.Count; num2++) { if (num2 > 0) { text.Append(','); } text.Append(JsonSerializer.Serialize(list[num2].Name)).Append(':'); Write(text, list[num2].Value); } text.Append('}'); break; } case JsonValueKind.Array: { text.Append('['); int num = 0; foreach (JsonElement item2 in value.EnumerateArray()) { if (num++ > 0) { text.Append(','); } Write(text, item2); } text.Append(']'); break; } case JsonValueKind.Number: text.Append(CanonicalNumber(value.GetRawText())); break; case JsonValueKind.String: text.Append(JsonSerializer.Serialize(value.GetString())); break; default: text.Append(value.GetRawText()); break; } } private static string CanonicalNumber(string raw) { int num = raw.IndexOfAny(new char[2] { 'e', 'E' }); string text = ((num < 0) ? raw : raw.Substring(0, num)); BigInteger bigInteger = ((num < 0) ? BigInteger.Zero : BigInteger.Parse(raw.Substring(num + 1), NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture)); int num2 = text.IndexOf('.'); if (num2 >= 0) { bigInteger -= (BigInteger)(text.Length - num2 - 1); } bool flag = text[0] == '-'; string text2 = text.Replace(".", "").TrimStart('-', '0'); if (text2.Length == 0) { return "0"; } string text3 = text2.TrimEnd('0'); bigInteger += (BigInteger)(text2.Length - text3.Length); return (flag ? "-" : "") + text3 + (bigInteger.IsZero ? "" : ("e" + bigInteger.ToString(CultureInfo.InvariantCulture))); } } }