using System; using System.Buffers; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.IO.Compression; using System.Linq; using System.Numerics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Runtime.Versioning; using System.Security; using System.Security.Cryptography; using System.Security.Permissions; using System.Threading; using System.Threading.Tasks; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using HS; using HarmonyLib; using JetBrains.Annotations; using Microsoft.CodeAnalysis; using ServerSync; using TMPro; using UnityEngine; [assembly: AssemblyTitle("HS_QuickStash")] [assembly: AssemblyProduct("HS_QuickStash")] [assembly: AssemblyInformationalVersion("0.0.2+40ccafd27b9883c7f0cb0a2af45be199324b63c2")] [assembly: AssemblyFileVersion("0.0.2.0")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCompany("HS")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: IgnoresAccessChecksTo("assembly_valheim")] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: CompilationRelaxations(8)] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.2.0")] [module: <41047c61-b61c-4423-b187-aebe4d53be29>RefSafetyRules(11)] [module: UnverifiableCode] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [<4695b251-1d2b-47ab-9410-87ed9fefc31e>Embedded] internal sealed class <4695b251-1d2b-47ab-9410-87ed9fefc31e>EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [<4695b251-1d2b-47ab-9410-87ed9fefc31e>Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class <0da50030-0caa-48a2-bdb4-5299f2a8c630>NullableAttribute : Attribute { public readonly byte[] NullableFlags; public <0da50030-0caa-48a2-bdb4-5299f2a8c630>NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public <0da50030-0caa-48a2-bdb4-5299f2a8c630>NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [<4695b251-1d2b-47ab-9410-87ed9fefc31e>Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class <78c6efc5-b5eb-49e3-8897-4b8b64484657>NullableContextAttribute : Attribute { public readonly byte Flag; public <78c6efc5-b5eb-49e3-8897-4b8b64484657>NullableContextAttribute(byte P_0) { Flag = P_0; } } [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] [<4695b251-1d2b-47ab-9410-87ed9fefc31e>Embedded] [CompilerGenerated] internal sealed class <41047c61-b61c-4423-b187-aebe4d53be29>RefSafetyRulesAttribute : Attribute { public readonly int Version; public <41047c61-b61c-4423-b187-aebe4d53be29>RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } [<78c6efc5-b5eb-49e3-8897-4b8b64484657>NullableContext(1)] [<0da50030-0caa-48a2-bdb4-5299f2a8c630>Nullable(0)] internal sealed class ConfigurationManagerAttributes { [<78c6efc5-b5eb-49e3-8897-4b8b64484657>NullableContext(0)] public delegate void CustomHotkeyDrawerFunc(ConfigEntryBase setting, ref bool isCurrentlyAcceptingInput); public bool? ShowRangeAsPercent; public Action CustomDrawer; public CustomHotkeyDrawerFunc CustomHotkeyDrawer; public bool? Browsable; public string Category; public object DefaultValue; public bool? HideDefaultButton; public bool? HideSettingName; public string Description; public string DispName; public int? Order; public bool? ReadOnly; public bool? IsAdvanced; public Func ObjToStr; public Func StrToObj; } namespace HS { [<78c6efc5-b5eb-49e3-8897-4b8b64484657>NullableContext(1)] [<0da50030-0caa-48a2-bdb4-5299f2a8c630>Nullable(0)] internal static class VersionChecker { private const string ValheimVersions = "0.218.15,0.218.16"; public static bool Check(ManualLogSource logger, PluginInfo info, bool allowWrongVersion = false, [<0da50030-0caa-48a2-bdb4-5299f2a8c630>Nullable(2)] ConfigFile config = null) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) GameVersion currentVersion = Version.CurrentVersion; string text = ((object)(GameVersion)(ref currentVersion)).ToString(); if ("0.218.15,0.218.16".Split(new char[1] { ',' }).Contains(text)) { return true; } string text2 = $"The current version of {info.Metadata.Name} (v{info.Metadata.Version}) is designed for Valheim " + (("0.218.15,0.218.16".Split(new char[1] { ',' }).Count() >= 2) ? ("versions " + string.Join(" | ", "0.218.15,0.218.16".Split(new char[1] { ',' }))) : "version 0.218.15,0.218.16") + ", however, your current Valheim version was " + text + ".\n"; if (!allowWrongVersion) { string text3 = "ERROR: " + text2 + "To resolve this issue, please obtain the appropriate plugin version, or alternatively, await an update if one is not currently available.\nPlease download the correct plugin version or wait for the plugin to be updated if a new version is not available."; logger.LogError((object)text3); Chainloader.DependencyErrors.Add(text3); if (config != null) { SetConfigAlert(config, text3); } return false; } logger.LogWarning((object)("WARNING: " + text2 + "Although the plugin author has permitted this version to work with an outdated Valheim version, it's important to note that unforeseen complications may occur\nPlease download the correct plugin version or wait for the plugin to be updated if a new version is not available and any issues arise.")); return true; } private static void SetConfigAlert([<0da50030-0caa-48a2-bdb4-5299f2a8c630>Nullable(2)] ConfigFile config, string errorMessage) { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown if (config != null) { config.Bind("", "NotCompatable", "", new ConfigDescription(errorMessage, (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { CustomDrawer = ErrorLabelDrawer, ReadOnly = true, HideDefaultButton = true, HideSettingName = true, Category = null } })); } } private static void ErrorLabelDrawer(ConfigEntryBase entry) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Expected O, but got Unknown GUIStyle val = new GUIStyle(GUI.skin.label) { wordWrap = true, stretchWidth = true }; GUIStyle val2 = new GUIStyle(GUI.skin.label) { stretchWidth = true, alignment = (TextAnchor)4 }; val2.normal.textColor = Color.red; val2.fontStyle = (FontStyle)1; GUIStyle val3 = val2; GUILayout.BeginVertical(Array.Empty()); GUILayout.Label(entry.Description.Description, val, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }); GUILayout.Label("Plugin has been disabled!", val3, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }); GUILayout.EndVertical(); } } } namespace HS_QuickStash { [BepInPlugin("HS_QuickStash", "HS_QuickStash", "0.0.2")] [<0da50030-0caa-48a2-bdb4-5299f2a8c630>Nullable(0)] [<78c6efc5-b5eb-49e3-8897-4b8b64484657>NullableContext(1)] public class Plugin : BaseUnityPlugin { [<78c6efc5-b5eb-49e3-8897-4b8b64484657>NullableContext(0)] private enum Toggle { On = 1, Off = 0 } [<78c6efc5-b5eb-49e3-8897-4b8b64484657>NullableContext(0)] private enum FilterMode { Blacklist, Whitelist } private static readonly ConfigSync ConfigSync = new ConfigSync("HS_QuickStash") { DisplayName = "HS_QuickStash", CurrentVersion = "0.0.2", MinimumRequiredVersion = "0.0.2" }; public static readonly ManualLogSource Logger = Logger.CreateLogSource("HS_QuickStash"); private static ConfigEntry _serverConfigLocked = null; public static ConfigEntry ModEnabled = null; private static ConfigEntry _overrideVersionCheck = null; public static ConfigEntry ContainerRange = null; public static ConfigEntry ExcludedSlots = null; public static ConfigEntry PrioritizeChestInUse = null; public static ConfigEntry HighlightChests = null; public static ConfigEntry HighlightColor = null; public static ConfigEntry HighlightTime = null; public static ConfigEntry QuickStashHotkey = null; public static ConfigEntry DebugLogging = null; public static List ContainersFastAccess = new List(); private ConfigEntry Config<[<0da50030-0caa-48a2-bdb4-5299f2a8c630>Nullable(2)] T>(string group, string name, T value, ConfigDescription description, bool synchronizedSetting = true) { ConfigEntry val = ((BaseUnityPlugin)this).Config.Bind(group, name, value, description); ConfigSync.AddConfigEntry(val).SynchronizedConfig = synchronizedSetting; return val; } private ConfigEntry Config<[<0da50030-0caa-48a2-bdb4-5299f2a8c630>Nullable(2)] T>(string group, string name, T value, string description, bool synchronizedSetting = true) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown return Config(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty()), synchronizedSetting); } private void Awake() { //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Expected O, but got Unknown //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Expected O, but got Unknown //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Expected O, but got Unknown //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Expected O, but got Unknown //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Expected O, but got Unknown //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Expected O, but got Unknown //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Expected O, but got Unknown //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_01a0: Expected O, but got Unknown //IL_01bc: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: Expected O, but got Unknown //IL_0200: Unknown result type (might be due to invalid IL or missing references) _serverConfigLocked = Config("1 - General", "Lock Configuration", Toggle.On, "If on, the configuration is locked and can only be changed by server admins."); ConfigSync.AddLockingConfigEntry(_serverConfigLocked); ModEnabled = Config("1 - General", "Mod Enabled", value: true, ""); _overrideVersionCheck = Config("1 - General", "Override Version Check", value: true, new ConfigDescription("Set to True to override the Valheim version check and allow the mod to start even if an incorrect Valheim version is detected.", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Browsable = false } })); ContainerRange = Config("2 - Settings", "Max Container Distance", 100, new ConfigDescription("The maximum range to stash items", (AcceptableValueBase)null, Array.Empty())); ExcludedSlots = Config("2 - Settings", "Excluded Inventory Slots", 8, new ConfigDescription("Exclude slots from the top left corner of the inventory's first row when storing items", (AcceptableValueBase)null, Array.Empty())); QuickStashHotkey = Config("2 - Settings", "Quick Stash Keybind", new KeyboardShortcut((KeyCode)103, Array.Empty()), new ConfigDescription("Key to Press to Quickly Stash your Inventory to Nearby Chests", (AcceptableValueBase)null, Array.Empty()), synchronizedSetting: false); HighlightChests = Config("2 - Settings", "Highlight Target Chests", value: true, new ConfigDescription("Highlights chests that items are sorted to", (AcceptableValueBase)null, Array.Empty())); PrioritizeChestInUse = Config("2 - Settings", "Prioritize Chest in Use", value: true, new ConfigDescription("If a matching item is not found when stashing, try to add item to chest that is open", (AcceptableValueBase)null, Array.Empty())); HighlightColor = Config("2 - Settings", "Highlight Chest Color", Color.green, new ConfigDescription("Color to Highlight chests", (AcceptableValueBase)null, Array.Empty())); HighlightTime = Config("2 - Settings", "Highlight Chest Time", 3, new ConfigDescription("Time in seconds to Highlight chests", (AcceptableValueBase)null, Array.Empty())); DebugLogging = Config("2 - Settings", "Enable Debug Logging", value: true, new ConfigDescription("Log Items that are stashed and extra debug info to Log", (AcceptableValueBase)null, Array.Empty())); if (_overrideVersionCheck.Value || VersionChecker.Check(Logger, ((BaseUnityPlugin)this).Info, _overrideVersionCheck.Value, ((BaseUnityPlugin)this).Config)) { new Harmony("HS_QuickStash").PatchAll(Assembly.GetExecutingAssembly()); } } } [<0da50030-0caa-48a2-bdb4-5299f2a8c630>Nullable(0)] [<78c6efc5-b5eb-49e3-8897-4b8b64484657>NullableContext(1)] public class ContainerData { [<0da50030-0caa-48a2-bdb4-5299f2a8c630>Nullable(new byte[] { 2, 0, 1, 1, 1 })] private List> _chestHighlightMaterials; [<0da50030-0caa-48a2-bdb4-5299f2a8c630>Nullable(2)] [field: <0da50030-0caa-48a2-bdb4-5299f2a8c630>Nullable(2)] public Container Container { [<78c6efc5-b5eb-49e3-8897-4b8b64484657>NullableContext(2)] get; } public Dictionary ItemData { get; } public ContainerData(Container container) { Container = container; ItemData = (from item in container.GetInventory().GetAllItems() group item by item.m_shared.m_name).ToDictionary([<78c6efc5-b5eb-49e3-8897-4b8b64484657>NullableContext(0)] (IGrouping group) => group.Key, [<78c6efc5-b5eb-49e3-8897-4b8b64484657>NullableContext(0)] (IGrouping group) => group.Sum([<78c6efc5-b5eb-49e3-8897-4b8b64484657>NullableContext(0)] (ItemData item) => item.m_stack)); } public async void DisableHighlight() { await Task.Delay(Plugin.HighlightTime.Value * 1000); SetChestHighlight(enabled: false); } public void SetChestHighlight(bool enabled) { if ((Object)(object)Container == (Object)null || (enabled && _chestHighlightMaterials != null) || (!enabled && _chestHighlightMaterials == null)) { return; } Renderer[] componentsInChildren = ((Component)Container.m_piece).GetComponentsInChildren(); if (enabled) { _chestHighlightMaterials = componentsInChildren.Select([<78c6efc5-b5eb-49e3-8897-4b8b64484657>NullableContext(0)] (Renderer renderer) => new KeyValuePair(renderer, renderer.sharedMaterials)).ToList(); componentsInChildren.ToList().ForEach([<78c6efc5-b5eb-49e3-8897-4b8b64484657>NullableContext(0)] (Renderer renderer) => { renderer.materials.ToList().ForEach([<78c6efc5-b5eb-49e3-8897-4b8b64484657>NullableContext(0)] (Material material) => { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) if (material.HasProperty("_EmissionColor")) { material.SetColor("_EmissionColor", Plugin.HighlightColor.Value * Plugin.HighlightColor.Value.a); } material.color = Plugin.HighlightColor.Value; }); }); DisableHighlight(); } else if (_chestHighlightMaterials != null) { _chestHighlightMaterials.Where([<78c6efc5-b5eb-49e3-8897-4b8b64484657>NullableContext(0)] (KeyValuePair kvp) => (Object)(object)kvp.Key != (Object)null).ToList().ForEach([<78c6efc5-b5eb-49e3-8897-4b8b64484657>NullableContext(0)] (KeyValuePair kvp) => { kvp.Key.materials = kvp.Value; }); _chestHighlightMaterials = null; } } } [<0da50030-0caa-48a2-bdb4-5299f2a8c630>Nullable(0)] [HarmonyPatch] [<78c6efc5-b5eb-49e3-8897-4b8b64484657>NullableContext(1)] internal class Patch { [HarmonyPostfix] [HarmonyPatch(typeof(Container), "Awake")] private static void Patch_Container_Awake(Container __instance, [<0da50030-0caa-48a2-bdb4-5299f2a8c630>Nullable(2)] ZNetView ___m_nview) { if (!((Object)(object)___m_nview == (Object)null) && ___m_nview.GetZDO() != null && !((Object)(object)((Component)___m_nview).GetComponent() == (Object)null) && ((object)__instance).ToString().StartsWith("piece_chest") && !Plugin.ContainersFastAccess.Contains(__instance)) { Plugin.ContainersFastAccess.Add(__instance); } } [HarmonyPostfix] [HarmonyPatch(typeof(Container), "OnDestroyed")] private static void Patch_Container_OnDestroyed(Container __instance) { Plugin.ContainersFastAccess.Remove(__instance); } [HarmonyPostfix] [HarmonyPatch(typeof(Container), "GetHoverText")] public static string Patch_Container_GetHoverText(string __result) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) KeyboardShortcut value = Plugin.QuickStashHotkey.Value; return __result + "\n[" + ((object)(KeyboardShortcut)(ref value)).ToString() + "] Quick Stash"; } [HarmonyPatch(typeof(Player), "Update")] [HarmonyPrefix] private static void Patch_Player_Update(Player __instance) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_0214: Unknown result type (might be due to invalid IL or missing references) //IL_0227: Unknown result type (might be due to invalid IL or missing references) //IL_0631: Unknown result type (might be due to invalid IL or missing references) //IL_0641: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.ModEnabled.Value) { return; } KeyboardShortcut value = Plugin.QuickStashHotkey.Value; if (!Input.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey) || TextInput.IsVisible() || (Object)(object)Settings.instance != (Object)null || Menu.IsVisible() || Console.IsVisible() || Minimap.IsOpen() || Game.IsPaused() || PlayerCustomizaton.IsBarberGuiVisible() || ((Object)(object)Chat.instance != (Object)null && Chat.instance.IsChatDialogWindowVisible()) || StoreGui.IsVisible() || Hud.InRadial() || (InventoryGui.IsVisible() && (InventoryGui.instance.IsSkillsPanelOpen || InventoryGui.instance.IsTrophisPanelOpen || InventoryGui.instance.IsTextPanelOpen))) { return; } Inventory playerInventory = ((Humanoid)__instance).GetInventory(); int value2 = Plugin.ExcludedSlots.Value; List containersFastAccess = Plugin.ContainersFastAccess; Dictionary dictionary = Enumerable.Range(0, playerInventory.m_height).SelectMany([<78c6efc5-b5eb-49e3-8897-4b8b64484657>NullableContext(0)] (int y) => Enumerable.Range(0, playerInventory.m_width).Select((Func)([<78c6efc5-b5eb-49e3-8897-4b8b64484657>NullableContext(0)] (int x) => (new Vector2i(x, y), playerInventory.GetItemAt(x, y))))).ToDictionary([<78c6efc5-b5eb-49e3-8897-4b8b64484657>NullableContext(0)] ((Vector2i, ItemData) pair) => pair.Item1, [<78c6efc5-b5eb-49e3-8897-4b8b64484657>NullableContext(0)] ((Vector2i, ItemData) pair) => pair.Item2); List list = new List(); List list2 = new List(); foreach (Container item in containersFastAccess) { if (item.GetInventory().NrOfItems() <= 0) { list2.Add(new ContainerData(item)); } else if (!(Vector3.Distance(((Component)item).transform.position, ((Component)__instance).transform.position) > (float)Plugin.ContainerRange.Value)) { list.Add(new ContainerData(item)); } } foreach (KeyValuePair playerItem in dictionary) { if (playerItem.Value == null || (playerItem.Key.y == 0 && playerItem.Key.x <= value2) || playerItem.Value.m_equipped) { continue; } List list3 = new List(); ContainerData containerData = null; ContainerData containerData2 = null; foreach (ContainerData item2 in list) { if ((Object)(object)item2.Container == (Object)null) { continue; } Inventory inventory = item2.Container.GetInventory(); if (inventory.CanAddItem(playerItem.Value, -1)) { if (containerData == null || ((Object)(object)containerData.Container != (Object)null && inventory.GetEmptySlots() > containerData.Container.GetInventory().GetEmptySlots())) { containerData = item2; } if (item2.ItemData.ContainsKey(playerItem.Value.m_shared.m_name)) { list3.Add(item2); } if (item2.Container.IsInUse()) { containerData2 = item2; } } } List list4 = list3.OrderByDescending([<78c6efc5-b5eb-49e3-8897-4b8b64484657>NullableContext(0)] (ContainerData match) => match.ItemData[playerItem.Value.m_shared.m_name]).ToList(); ContainerData containerData3 = null; foreach (ContainerData item3 in list4) { if (!((Object)(object)item3.Container == (Object)null) && item3.Container.GetInventory().AddItem(playerItem.Value)) { containerData3 = item3; break; } } if (containerData3 == null && containerData2 != null && (Object)(object)containerData2.Container != (Object)null && Plugin.PrioritizeChestInUse.Value) { containerData3 = (containerData2.Container.GetInventory().AddItem(playerItem.Value) ? containerData2 : null); } object obj; if (containerData3 == null && list2.Any()) { ContainerData containerData4 = (from emptyContainer in list2 where (Object)(object)emptyContainer?.Container != (Object)null orderby (!((Object)(object)emptyContainer.Container != (Object)null)) ? float.MaxValue : Vector3.Distance(((Component)emptyContainer.Container).transform.position, ((Component)__instance).transform.position) select emptyContainer).FirstOrDefault(); if (containerData4 != null) { Container container = containerData4.Container; if (((container != null) ? new bool?(container.GetInventory().AddItem(playerItem.Value)) : null) == true) { obj = containerData4; goto IL_04b1; } } obj = null; goto IL_04b1; } goto IL_04b3; IL_04b1: containerData3 = (ContainerData)obj; goto IL_04b3; IL_04b3: if (containerData3 == null && containerData != null) { Container container2 = containerData.Container; containerData3 = ((container2 != null && container2.GetInventory().AddItem(playerItem.Value)) ? containerData : null); } if (containerData3 == null) { Player obj2 = __instance; if (obj2 != null) { ((Character)obj2).Message((MessageType)2, "No available storage to stash items", 0, (Sprite)null); } if (Plugin.DebugLogging.Value) { Plugin.Logger.LogInfo((object)("Quick Stash halted on Item: " + Localization.instance.Localize(playerItem.Value.m_shared.m_name))); } } else if (!((Object)(object)containerData3.Container == (Object)null)) { playerInventory.RemoveItem(playerItem.Value); if (Plugin.DebugLogging.Value) { Plugin.Logger.LogInfo((object)$"Added (Item: {Localization.instance.Localize(playerItem.Value.m_shared.m_name)}) Count: {playerItem.Value.m_stack} to Container: Name: {containerData3.Container.m_name} Distance: {Vector3.Distance(((Component)containerData3.Container).transform.position, ((Component)__instance).transform.position)}"); } if (Plugin.HighlightChests.Value) { containerData3.SetChestHighlight(enabled: true); } } } } } [<0da50030-0caa-48a2-bdb4-5299f2a8c630>Nullable(0)] [<78c6efc5-b5eb-49e3-8897-4b8b64484657>NullableContext(1)] public static class MyPluginInfo { public const string PLUGIN_GUID = "HS_QuickStash"; public const string PLUGIN_NAME = "HS_QuickStash"; public const string PLUGIN_VERSION = "0.0.2"; } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } } namespace Microsoft.CodeAnalysis { [CompilerGenerated] [<2aac24e0-ce31-4667-b872-2470a9eccbdd>Embedded] internal sealed class <2aac24e0-ce31-4667-b872-2470a9eccbdd>EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [<2aac24e0-ce31-4667-b872-2470a9eccbdd>Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class <1a013cea-436f-47e7-9ef0-942ec835cd53>NullableAttribute : Attribute { public readonly byte[] NullableFlags; public <1a013cea-436f-47e7-9ef0-942ec835cd53>NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public <1a013cea-436f-47e7-9ef0-942ec835cd53>NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [<2aac24e0-ce31-4667-b872-2470a9eccbdd>Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class <08001146-5bb1-445e-9ab9-c673c77332fb>NullableContextAttribute : Attribute { public readonly byte Flag; public <08001146-5bb1-445e-9ab9-c673c77332fb>NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [<2aac24e0-ce31-4667-b872-2470a9eccbdd>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 ServerSync { [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(0)] [<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(1)] [PublicAPI] internal abstract class OwnConfigEntryBase { [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(2)] public object LocalBaseValue; public bool SynchronizedConfig = true; public abstract ConfigEntryBase BaseConfig { get; } } [PublicAPI] [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(0)] [<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(1)] internal class SyncedConfigEntry<[<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(2)] T> : OwnConfigEntryBase { public readonly ConfigEntry SourceConfig; public override ConfigEntryBase BaseConfig => (ConfigEntryBase)(object)SourceConfig; public T Value { get { return SourceConfig.Value; } set { SourceConfig.Value = value; } } public SyncedConfigEntry(ConfigEntry sourceConfig) { SourceConfig = sourceConfig; } public void AssignLocalValue(T value) { if (LocalBaseValue == null) { Value = value; } else { LocalBaseValue = value; } } } [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(0)] [<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(2)] internal abstract class CustomSyncedValueBase { public object LocalBaseValue; [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(1)] public readonly string Identifier; [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(1)] public readonly Type Type; private object boxedValue; protected bool localIsOwner; public readonly int Priority; public object BoxedValue { get { return boxedValue; } set { boxedValue = value; this.ValueChanged?.Invoke(); } } public event Action ValueChanged; [<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(1)] protected CustomSyncedValueBase(ConfigSync configSync, string identifier, Type type, int priority) { Priority = priority; Identifier = identifier; Type = type; configSync.AddCustomValue(this); localIsOwner = configSync.IsSourceOfTruth; configSync.SourceOfTruthChanged += delegate(bool truth) { localIsOwner = truth; }; } } [<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(1)] [PublicAPI] [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(0)] internal sealed class CustomSyncedValue<[<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(2)] T> : CustomSyncedValueBase { public T Value { get { return (T)base.BoxedValue; } set { base.BoxedValue = value; } } public CustomSyncedValue(ConfigSync configSync, string identifier, T value = default(T), int priority = 0) : base(configSync, identifier, typeof(T), priority) { Value = value; } public void AssignLocalValue(T value) { if (localIsOwner) { Value = value; } else { LocalBaseValue = value; } } } internal class ConfigurationManagerAttributes { [UsedImplicitly] public bool? ReadOnly = false; } [PublicAPI] [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(0)] [<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(1)] internal class ConfigSync { [HarmonyPatch(typeof(ZRpc), "HandlePackage")] [<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] private static class SnatchCurrentlyHandlingRPC { [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(2)] public static ZRpc currentRpc; [<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(1)] [HarmonyPrefix] private static void Prefix(ZRpc __instance) { currentRpc = __instance; } } [<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] [HarmonyPatch(typeof(ZNet), "Awake")] internal static class RegisterRPCPatch { [<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(1)] [HarmonyPostfix] private static void Postfix(ZNet __instance) { isServer = __instance.IsServer(); foreach (ConfigSync configSync2 in configSyncs) { ZRoutedRpc.instance.Register(configSync2.Name + " ConfigSync", (Action)configSync2.RPC_FromOtherClientConfigSync); if (isServer) { configSync2.InitialSyncDone = true; Debug.Log((object)("Registered '" + configSync2.Name + " ConfigSync' RPC - waiting for incoming connections")); } } if (isServer) { ((MonoBehaviour)__instance).StartCoroutine(WatchAdminListChanges()); } [<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(1)] static void SendAdmin(List peers, bool isAdmin) { ZPackage package = ConfigsToPackage(null, null, new PackageEntry[1] { new PackageEntry { section = "Internal", key = "lockexempt", type = typeof(bool), value = isAdmin } }); ConfigSync configSync = configSyncs.First(); if (configSync != null) { ((MonoBehaviour)ZNet.instance).StartCoroutine(configSync.sendZPackage(peers, package)); } } [<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(1)] static IEnumerator WatchAdminListChanges() { MethodInfo listContainsId = AccessTools.DeclaredMethod(typeof(ZNet), "ListContainsId", (Type[])null, (Type[])null); SyncedList adminList = (SyncedList)AccessTools.DeclaredField(typeof(ZNet), "m_adminList").GetValue(ZNet.instance); List CurrentList = new List(adminList.GetList()); while (true) { yield return (object)new WaitForSeconds(30f); if (!adminList.GetList().SequenceEqual(CurrentList)) { CurrentList = new List(adminList.GetList()); List adminPeer = ZNet.instance.GetPeers().Where(delegate(ZNetPeer p) { string hostName = p.m_rpc.GetSocket().GetHostName(); return ((object)listContainsId == null) ? adminList.Contains(hostName) : ((bool)listContainsId.Invoke(ZNet.instance, new object[2] { adminList, hostName })); }).ToList(); List nonAdminPeer = ZNet.instance.GetPeers().Except(adminPeer).ToList(); SendAdmin(nonAdminPeer, isAdmin: false); SendAdmin(adminPeer, isAdmin: true); } } } } } [<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] [HarmonyPatch(typeof(ZNet), "OnNewConnection")] private static class RegisterClientRPCPatch { [<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(1)] [HarmonyPostfix] private static void Postfix(ZNet __instance, ZNetPeer peer) { if (__instance.IsServer()) { return; } foreach (ConfigSync configSync in configSyncs) { peer.m_rpc.Register(configSync.Name + " ConfigSync", (Action)configSync.RPC_FromServerConfigSync); } } } [<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] private class ParsedConfigs { [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(new byte[] { 1, 1, 2 })] public readonly Dictionary configValues = new Dictionary(); [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(new byte[] { 1, 1, 2 })] public readonly Dictionary customValues = new Dictionary(); } [<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] [HarmonyPatch(typeof(ZNet), "Shutdown")] private class ResetConfigsOnShutdown { [HarmonyPostfix] private static void Postfix() { ProcessingServerUpdate = true; foreach (ConfigSync configSync in configSyncs) { configSync.resetConfigsFromServer(); configSync.IsSourceOfTruth = true; configSync.InitialSyncDone = false; } ProcessingServerUpdate = false; } } [HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")] [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(0)] private class SendConfigsAfterLogin { [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(0)] private class BufferingSocket : ISocket { public volatile bool finished = false; public volatile int versionMatchQueued = -1; public readonly List Package = new List(); public readonly ISocket Original; public BufferingSocket(ISocket original) { Original = original; } public bool IsConnected() { return Original.IsConnected(); } public ZPackage Recv() { return Original.Recv(); } public int GetSendQueueSize() { return Original.GetSendQueueSize(); } public int GetCurrentSendRate() { return Original.GetCurrentSendRate(); } public bool IsHost() { return Original.IsHost(); } public void Dispose() { Original.Dispose(); } public bool GotNewData() { return Original.GotNewData(); } public void Close() { Original.Close(); } public string GetEndPointString() { return Original.GetEndPointString(); } public void GetAndResetStats(out int totalSent, out int totalRecv) { Original.GetAndResetStats(ref totalSent, ref totalRecv); } public void GetConnectionQuality(out float localQuality, out float remoteQuality, out int ping, out float outByteSec, out float inByteSec) { Original.GetConnectionQuality(ref localQuality, ref remoteQuality, ref ping, ref outByteSec, ref inByteSec); } public ISocket Accept() { return Original.Accept(); } public int GetHostPort() { return Original.GetHostPort(); } public bool Flush() { return Original.Flush(); } public string GetHostName() { return Original.GetHostName(); } public void VersionMatch() { if (finished) { Original.VersionMatch(); } else { versionMatchQueued = Package.Count; } } public void Send(ZPackage pkg) { //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Expected O, but got Unknown int pos = pkg.GetPos(); pkg.SetPos(0); int num = pkg.ReadInt(); if ((num == StringExtensionMethods.GetStableHashCode("PeerInfo") || num == StringExtensionMethods.GetStableHashCode("RoutedRPC") || num == StringExtensionMethods.GetStableHashCode("ZDOData")) && !finished) { ZPackage val = new ZPackage(pkg.GetArray()); val.SetPos(pos); Package.Add(val); } else { pkg.SetPos(pos); Original.Send(pkg); } } } [HarmonyPrefix] [HarmonyPriority(800)] private static void Prefix([<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(new byte[] { 2, 1, 1 })] ref Dictionary __state, ZNet __instance, ZRpc rpc) { //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Invalid comparison between Unknown and I4 if (__instance.IsServer()) { BufferingSocket value = new BufferingSocket(rpc.GetSocket()); AccessTools.DeclaredField(typeof(ZRpc), "m_socket").SetValue(rpc, value); object? obj = AccessTools.DeclaredMethod(typeof(ZNet), "GetPeer", new Type[1] { typeof(ZRpc) }, (Type[])null).Invoke(__instance, new object[1] { rpc }); ZNetPeer val = (ZNetPeer)((obj is ZNetPeer) ? obj : null); if (val != null && (int)ZNet.m_onlineBackend > 0) { AccessTools.DeclaredField(typeof(ZNetPeer), "m_socket").SetValue(val, value); } if (__state == null) { __state = new Dictionary(); } __state[Assembly.GetExecutingAssembly()] = value; } } [HarmonyPostfix] private static void Postfix(Dictionary __state, ZNet __instance, ZRpc rpc) { ZNetPeer peer; if (__instance.IsServer()) { object obj = AccessTools.DeclaredMethod(typeof(ZNet), "GetPeer", new Type[1] { typeof(ZRpc) }, (Type[])null).Invoke(__instance, new object[1] { rpc }); peer = (ZNetPeer)((obj is ZNetPeer) ? obj : null); if (peer == null) { SendBufferedData(); } else { ((MonoBehaviour)__instance).StartCoroutine(sendAsync()); } } void SendBufferedData() { if (rpc.GetSocket() is BufferingSocket bufferingSocket) { AccessTools.DeclaredField(typeof(ZRpc), "m_socket").SetValue(rpc, bufferingSocket.Original); object? obj2 = AccessTools.DeclaredMethod(typeof(ZNet), "GetPeer", new Type[1] { typeof(ZRpc) }, (Type[])null).Invoke(__instance, new object[1] { rpc }); ZNetPeer val = (ZNetPeer)((obj2 is ZNetPeer) ? obj2 : null); if (val != null) { AccessTools.DeclaredField(typeof(ZNetPeer), "m_socket").SetValue(val, bufferingSocket.Original); } } BufferingSocket bufferingSocket2 = __state[Assembly.GetExecutingAssembly()]; bufferingSocket2.finished = true; for (int i = 0; i < bufferingSocket2.Package.Count; i++) { if (i == bufferingSocket2.versionMatchQueued) { bufferingSocket2.Original.VersionMatch(); } bufferingSocket2.Original.Send(bufferingSocket2.Package[i]); } if (bufferingSocket2.Package.Count == bufferingSocket2.versionMatchQueued) { bufferingSocket2.Original.VersionMatch(); } } IEnumerator sendAsync() { foreach (ConfigSync configSync in configSyncs) { List entries = new List(); if (configSync.CurrentVersion != null) { entries.Add(new PackageEntry { section = "Internal", key = "serverversion", type = typeof(string), value = configSync.CurrentVersion }); } MethodInfo listContainsId = AccessTools.DeclaredMethod(typeof(ZNet), "ListContainsId", (Type[])null, (Type[])null); SyncedList adminList = (SyncedList)AccessTools.DeclaredField(typeof(ZNet), "m_adminList").GetValue(ZNet.instance); entries.Add(new PackageEntry { section = "Internal", key = "lockexempt", type = typeof(bool), value = (((object)listContainsId == null) ? ((object)adminList.Contains(rpc.GetSocket().GetHostName())) : listContainsId.Invoke(ZNet.instance, new object[2] { adminList, rpc.GetSocket().GetHostName() })) }); ZPackage package = ConfigsToPackage(configSync.allConfigs.Select([<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] (OwnConfigEntryBase c) => c.BaseConfig), configSync.allCustomValues, entries, partial: false); yield return ((MonoBehaviour)__instance).StartCoroutine(configSync.sendZPackage(new List { peer }, package)); } SendBufferedData(); } } } [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(0)] private class PackageEntry { public string section = null; public string key = null; public Type type = null; [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(2)] public object value; } [HarmonyPatch(typeof(ConfigEntryBase), "GetSerializedValue")] [<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] private static class PreventSavingServerInfo { [HarmonyPrefix] [<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(1)] private static bool Prefix(ConfigEntryBase __instance, ref string __result) { OwnConfigEntryBase ownConfigEntryBase = configData(__instance); if (ownConfigEntryBase == null || isWritableConfig(ownConfigEntryBase)) { return true; } __result = TomlTypeConverter.ConvertToString(ownConfigEntryBase.LocalBaseValue, __instance.SettingType); return false; } } [HarmonyPatch(typeof(ConfigEntryBase), "SetSerializedValue")] [<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] private static class PreventConfigRereadChangingValues { [HarmonyPrefix] [<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(1)] private static bool Prefix(ConfigEntryBase __instance, string value) { OwnConfigEntryBase ownConfigEntryBase = configData(__instance); if (ownConfigEntryBase == null || ownConfigEntryBase.LocalBaseValue == null) { return true; } try { ownConfigEntryBase.LocalBaseValue = TomlTypeConverter.ConvertToValue(value, __instance.SettingType); } catch (Exception ex) { Debug.LogWarning((object)$"Config value of setting \"{__instance.Definition}\" could not be parsed and will be ignored. Reason: {ex.Message}; Value: {value}"); } return false; } } [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(0)] private class InvalidDeserializationTypeException : Exception { public string expected = null; public string received = null; public string field = ""; } public static bool ProcessingServerUpdate; public readonly string Name; [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(2)] public string DisplayName; [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(2)] public string CurrentVersion; [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(2)] public string MinimumRequiredVersion; public bool ModRequired = false; private bool? forceConfigLocking; private bool isSourceOfTruth = true; private static readonly HashSet configSyncs; private readonly HashSet allConfigs = new HashSet(); private HashSet allCustomValues = new HashSet(); private static bool isServer; private static bool lockExempt; [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(2)] private OwnConfigEntryBase lockedConfig = null; private const byte PARTIAL_CONFIGS = 1; private const byte FRAGMENTED_CONFIG = 2; private const byte COMPRESSED_CONFIG = 4; private readonly Dictionary> configValueCache = new Dictionary>(); [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(new byte[] { 1, 0, 1 })] private readonly List> cacheExpirations = new List>(); private static long packageCounter; public bool IsLocked { get { bool? flag = forceConfigLocking; bool num; if (!flag.HasValue) { if (lockedConfig == null) { goto IL_0052; } num = ((IConvertible)lockedConfig.BaseConfig.BoxedValue).ToInt32(CultureInfo.InvariantCulture) != 0; } else { num = flag.GetValueOrDefault(); } if (!num) { goto IL_0052; } int result = ((!lockExempt) ? 1 : 0); goto IL_0053; IL_0053: return (byte)result != 0; IL_0052: result = 0; goto IL_0053; } set { forceConfigLocking = value; } } public bool IsAdmin => lockExempt || isSourceOfTruth; public bool IsSourceOfTruth { get { return isSourceOfTruth; } private set { if (value != isSourceOfTruth) { isSourceOfTruth = value; this.SourceOfTruthChanged?.Invoke(value); } } } public bool InitialSyncDone { get; private set; } = false; [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(2)] [method: <08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(2)] [field: <1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(2)] public event Action SourceOfTruthChanged; [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(2)] [method: <08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(2)] [field: <1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(2)] private event Action lockedConfigChanged; static ConfigSync() { ProcessingServerUpdate = false; configSyncs = new HashSet(); lockExempt = false; packageCounter = 0L; RuntimeHelpers.RunClassConstructor(typeof(VersionCheck).TypeHandle); } public ConfigSync(string name) { Name = name; configSyncs.Add(this); new VersionCheck(this); } public SyncedConfigEntry AddConfigEntry<[<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(2)] T>(ConfigEntry configEntry) { OwnConfigEntryBase ownConfigEntryBase = configData((ConfigEntryBase)(object)configEntry); SyncedConfigEntry syncedEntry = ownConfigEntryBase as SyncedConfigEntry; if (syncedEntry == null) { syncedEntry = new SyncedConfigEntry(configEntry); AccessTools.DeclaredField(typeof(ConfigDescription), "k__BackingField").SetValue(((ConfigEntryBase)configEntry).Description, new object[1] { new ConfigurationManagerAttributes() }.Concat(((ConfigEntryBase)configEntry).Description.Tags ?? Array.Empty()).Concat(new SyncedConfigEntry[1] { syncedEntry }).ToArray()); configEntry.SettingChanged += [<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] (object _, EventArgs _) => { if (!ProcessingServerUpdate && syncedEntry.SynchronizedConfig) { Broadcast(ZRoutedRpc.Everybody, (ConfigEntryBase)configEntry); } }; allConfigs.Add(syncedEntry); } return syncedEntry; } public SyncedConfigEntry AddLockingConfigEntry<[<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(0)] T>(ConfigEntry lockingConfig) where T : IConvertible { if (lockedConfig != null) { throw new Exception("Cannot initialize locking ConfigEntry twice"); } lockedConfig = AddConfigEntry(lockingConfig); lockingConfig.SettingChanged += [<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] (object _, EventArgs _) => { this.lockedConfigChanged?.Invoke(); }; return (SyncedConfigEntry)lockedConfig; } internal void AddCustomValue(CustomSyncedValueBase customValue) { if (allCustomValues.Select([<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] (CustomSyncedValueBase v) => v.Identifier).Concat(new string[1] { "serverversion" }).Contains(customValue.Identifier)) { throw new Exception("Cannot have multiple settings with the same name or with a reserved name (serverversion)"); } allCustomValues.Add(customValue); allCustomValues = new HashSet(allCustomValues.OrderByDescending([<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] (CustomSyncedValueBase v) => v.Priority)); customValue.ValueChanged += delegate { if (!ProcessingServerUpdate) { Broadcast(ZRoutedRpc.Everybody, customValue); } }; } private void RPC_FromServerConfigSync(ZRpc rpc, ZPackage package) { lockedConfigChanged += serverLockedSettingChanged; IsSourceOfTruth = false; if (HandleConfigSyncRPC(0L, package, clientUpdate: false)) { InitialSyncDone = true; } } private void RPC_FromOtherClientConfigSync(long sender, ZPackage package) { HandleConfigSyncRPC(sender, package, clientUpdate: true); } private bool HandleConfigSyncRPC(long sender, ZPackage package, bool clientUpdate) { //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Expected O, but got Unknown //IL_0250: Unknown result type (might be due to invalid IL or missing references) //IL_0257: Expected O, but got Unknown //IL_01ea: Unknown result type (might be due to invalid IL or missing references) //IL_01f1: Expected O, but got Unknown try { if (isServer && IsLocked) { ZRpc currentRpc = SnatchCurrentlyHandlingRPC.currentRpc; object obj; if (currentRpc == null) { obj = null; } else { ISocket socket = currentRpc.GetSocket(); obj = ((socket != null) ? socket.GetHostName() : null); } string text = (string)obj; if (text != null) { MethodInfo methodInfo = AccessTools.DeclaredMethod(typeof(ZNet), "ListContainsId", (Type[])null, (Type[])null); SyncedList val = (SyncedList)AccessTools.DeclaredField(typeof(ZNet), "m_adminList").GetValue(ZNet.instance); if (!(((object)methodInfo == null) ? val.Contains(text) : ((bool)methodInfo.Invoke(ZNet.instance, new object[2] { val, text })))) { return false; } } } cacheExpirations.RemoveAll(([<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(new byte[] { 0, 1 })] KeyValuePair kv) => { if (kv.Key < DateTimeOffset.Now.Ticks) { configValueCache.Remove(kv.Value); return true; } return false; }); byte b = package.ReadByte(); if ((b & 2u) != 0) { long num = package.ReadLong(); string text2 = sender.ToString() + num; if (!configValueCache.TryGetValue(text2, out var value)) { value = new SortedDictionary(); configValueCache[text2] = value; cacheExpirations.Add(new KeyValuePair(DateTimeOffset.Now.AddSeconds(60.0).Ticks, text2)); } int key = package.ReadInt(); int num2 = package.ReadInt(); value.Add(key, package.ReadByteArray()); if (value.Count < num2) { return false; } configValueCache.Remove(text2); package = new ZPackage(value.Values.SelectMany([<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] (byte[] a) => a).ToArray()); b = package.ReadByte(); } ProcessingServerUpdate = true; if ((b & 4u) != 0) { byte[] buffer = package.ReadByteArray(); MemoryStream stream = new MemoryStream(buffer); MemoryStream memoryStream = new MemoryStream(); using (DeflateStream deflateStream = new DeflateStream(stream, CompressionMode.Decompress)) { deflateStream.CopyTo(memoryStream); } package = new ZPackage(memoryStream.ToArray()); b = package.ReadByte(); } if ((b & 1) == 0) { resetConfigsFromServer(); } ParsedConfigs parsedConfigs = ReadConfigsFromPackage(package); ConfigFile val2 = null; bool saveOnConfigSet = false; foreach (KeyValuePair configValue in parsedConfigs.configValues) { if (!isServer && configValue.Key.LocalBaseValue == null) { configValue.Key.LocalBaseValue = configValue.Key.BaseConfig.BoxedValue; } if (val2 == null) { val2 = configValue.Key.BaseConfig.ConfigFile; saveOnConfigSet = val2.SaveOnConfigSet; val2.SaveOnConfigSet = false; } configValue.Key.BaseConfig.BoxedValue = configValue.Value; } if (val2 != null) { val2.SaveOnConfigSet = saveOnConfigSet; } foreach (KeyValuePair customValue in parsedConfigs.customValues) { if (!isServer) { CustomSyncedValueBase key2 = customValue.Key; if (key2.LocalBaseValue == null) { key2.LocalBaseValue = customValue.Key.BoxedValue; } } customValue.Key.BoxedValue = customValue.Value; } Debug.Log((object)string.Format("Received {0} configs and {1} custom values from {2} for mod {3}", parsedConfigs.configValues.Count, parsedConfigs.customValues.Count, (isServer || clientUpdate) ? $"client {sender}" : "the server", DisplayName ?? Name)); if (!isServer) { serverLockedSettingChanged(); } return true; } finally { ProcessingServerUpdate = false; } } private ParsedConfigs ReadConfigsFromPackage(ZPackage package) { ParsedConfigs parsedConfigs = new ParsedConfigs(); Dictionary dictionary = allConfigs.Where([<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] (OwnConfigEntryBase c) => c.SynchronizedConfig).ToDictionary([<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] (OwnConfigEntryBase c) => c.BaseConfig.Definition.Section + "_" + c.BaseConfig.Definition.Key, [<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] (OwnConfigEntryBase c) => c); Dictionary dictionary2 = allCustomValues.ToDictionary([<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] (CustomSyncedValueBase c) => c.Identifier, [<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] (CustomSyncedValueBase c) => c); int num = package.ReadInt(); for (int i = 0; i < num; i++) { string text = package.ReadString(); string text2 = package.ReadString(); string text3 = package.ReadString(); Type type = Type.GetType(text3); if (text3 == "" || type != null) { object obj; try { obj = ((text3 == "") ? null : ReadValueWithTypeFromZPackage(package, type)); } catch (InvalidDeserializationTypeException ex) { Debug.LogWarning((object)("Got unexpected struct internal type " + ex.received + " for field " + ex.field + " struct " + text3 + " for " + text2 + " in section " + text + " for mod " + (DisplayName ?? Name) + ", expecting " + ex.expected)); continue; } OwnConfigEntryBase value2; if (text == "Internal") { CustomSyncedValueBase value; if (text2 == "serverversion") { if (obj?.ToString() != CurrentVersion) { Debug.LogWarning((object)("Received server version is not equal: server version = " + (obj?.ToString() ?? "null") + "; local version = " + (CurrentVersion ?? "unknown"))); } } else if (text2 == "lockexempt") { if (obj is bool flag) { lockExempt = flag; } } else if (dictionary2.TryGetValue(text2, out value)) { if ((text3 == "" && (!value.Type.IsValueType || Nullable.GetUnderlyingType(value.Type) != null)) || GetZPackageTypeString(value.Type) == text3) { parsedConfigs.customValues[value] = obj; continue; } Debug.LogWarning((object)("Got unexpected type " + text3 + " for internal value " + text2 + " for mod " + (DisplayName ?? Name) + ", expecting " + value.Type.AssemblyQualifiedName)); } } else if (dictionary.TryGetValue(text + "_" + text2, out value2)) { Type type2 = configType(value2.BaseConfig); if ((text3 == "" && (!type2.IsValueType || Nullable.GetUnderlyingType(type2) != null)) || GetZPackageTypeString(type2) == text3) { parsedConfigs.configValues[value2] = obj; continue; } Debug.LogWarning((object)("Got unexpected type " + text3 + " for " + text2 + " in section " + text + " for mod " + (DisplayName ?? Name) + ", expecting " + type2.AssemblyQualifiedName)); } else { Debug.LogWarning((object)("Received unknown config entry " + text2 + " in section " + text + " for mod " + (DisplayName ?? Name) + ". This may happen if client and server versions of the mod do not match.")); } continue; } Debug.LogWarning((object)("Got invalid type " + text3 + ", abort reading of received configs")); return new ParsedConfigs(); } return parsedConfigs; } private static bool isWritableConfig(OwnConfigEntryBase config) { ConfigSync configSync = configSyncs.FirstOrDefault([<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] (ConfigSync cs) => cs.allConfigs.Contains(config)); if (configSync == null) { return true; } return configSync.IsSourceOfTruth || !config.SynchronizedConfig || config.LocalBaseValue == null || (!configSync.IsLocked && (config != configSync.lockedConfig || lockExempt)); } private void serverLockedSettingChanged() { foreach (OwnConfigEntryBase allConfig in allConfigs) { configAttribute(allConfig.BaseConfig).ReadOnly = !isWritableConfig(allConfig); } } private void resetConfigsFromServer() { ConfigFile val = null; bool saveOnConfigSet = false; foreach (OwnConfigEntryBase item in allConfigs.Where([<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] (OwnConfigEntryBase config) => config.LocalBaseValue != null)) { if (val == null) { val = item.BaseConfig.ConfigFile; saveOnConfigSet = val.SaveOnConfigSet; val.SaveOnConfigSet = false; } item.BaseConfig.BoxedValue = item.LocalBaseValue; item.LocalBaseValue = null; } if (val != null) { val.SaveOnConfigSet = saveOnConfigSet; } foreach (CustomSyncedValueBase item2 in allCustomValues.Where([<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] (CustomSyncedValueBase config) => config.LocalBaseValue != null)) { item2.BoxedValue = item2.LocalBaseValue; item2.LocalBaseValue = null; } lockedConfigChanged -= serverLockedSettingChanged; serverLockedSettingChanged(); } private IEnumerator distributeConfigToPeers(ZNetPeer peer, ZPackage package) { ZRoutedRpc rpc = ZRoutedRpc.instance; if (rpc == null) { yield break; } byte[] data = package.GetArray(); if (data != null && data.LongLength > 250000) { int fragments = (int)(1 + (data.LongLength - 1) / 250000); long packageIdentifier = ++packageCounter; int fragment = 0; while (fragment < fragments) { foreach (bool item in waitForQueue()) { yield return item; } if (peer.m_socket.IsConnected()) { ZPackage fragmentedPackage = new ZPackage(); fragmentedPackage.Write((byte)2); fragmentedPackage.Write(packageIdentifier); fragmentedPackage.Write(fragment); fragmentedPackage.Write(fragments); fragmentedPackage.Write(data.Skip(250000 * fragment).Take(250000).ToArray()); SendPackage(fragmentedPackage); if (fragment != fragments - 1) { yield return true; } int num = fragment + 1; fragment = num; continue; } break; } yield break; } foreach (bool item2 in waitForQueue()) { yield return item2; } SendPackage(package); void SendPackage(ZPackage pkg) { string text = Name + " ConfigSync"; if (isServer) { peer.m_rpc.Invoke(text, new object[1] { pkg }); } else { rpc.InvokeRoutedRPC(peer.m_server ? 0 : peer.m_uid, text, new object[1] { pkg }); } } IEnumerable waitForQueue() { float timeout = Time.time + 30f; while (peer.m_socket.GetSendQueueSize() > 20000) { if (Time.time > timeout) { Debug.Log((object)$"Disconnecting {peer.m_uid} after 30 seconds config sending timeout"); peer.m_rpc.Invoke("Error", new object[1] { (object)(ConnectionStatus)5 }); ZNet.instance.Disconnect(peer); break; } yield return false; } } } private IEnumerator sendZPackage(long target, ZPackage package) { if (!Object.op_Implicit((Object)(object)ZNet.instance)) { return Enumerable.Empty().GetEnumerator(); } List list = (List)AccessTools.DeclaredField(typeof(ZRoutedRpc), "m_peers").GetValue(ZRoutedRpc.instance); if (target != ZRoutedRpc.Everybody) { list = list.Where([<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] (ZNetPeer p) => p.m_uid == target).ToList(); } return sendZPackage(list, package); } private IEnumerator sendZPackage(List peers, ZPackage package) { if (!Object.op_Implicit((Object)(object)ZNet.instance)) { yield break; } byte[] rawData = package.GetArray(); if (rawData != null && rawData.LongLength > 10000) { ZPackage compressedPackage = new ZPackage(); compressedPackage.Write((byte)4); MemoryStream output = new MemoryStream(); using (DeflateStream deflateStream = new DeflateStream(output, CompressionLevel.Optimal)) { deflateStream.Write(rawData, 0, rawData.Length); } compressedPackage.Write(output.ToArray()); package = compressedPackage; } List> writers = (from peer in peers where peer.IsReady() select peer into p select distributeConfigToPeers(p, package)).ToList(); writers.RemoveAll((IEnumerator writer) => !writer.MoveNext()); while (writers.Count > 0) { yield return null; writers.RemoveAll((IEnumerator writer) => !writer.MoveNext()); } } private void Broadcast(long target, params ConfigEntryBase[] configs) { if (!IsLocked || isServer) { ZPackage package = ConfigsToPackage(configs); ZNet instance = ZNet.instance; if (instance != null) { ((MonoBehaviour)instance).StartCoroutine(sendZPackage(target, package)); } } } private void Broadcast(long target, params CustomSyncedValueBase[] customValues) { if (!IsLocked || isServer) { ZPackage package = ConfigsToPackage(null, customValues); ZNet instance = ZNet.instance; if (instance != null) { ((MonoBehaviour)instance).StartCoroutine(sendZPackage(target, package)); } } } [return: <1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(2)] private static OwnConfigEntryBase configData(ConfigEntryBase config) { return config.Description.Tags?.OfType().SingleOrDefault(); } [return: <1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(new byte[] { 2, 1 })] public static SyncedConfigEntry ConfigData<[<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(2)] T>(ConfigEntry config) { return ((ConfigEntryBase)config).Description.Tags?.OfType>().SingleOrDefault(); } private static T configAttribute<[<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(2)] T>(ConfigEntryBase config) { return config.Description.Tags.OfType().First(); } private static Type configType(ConfigEntryBase config) { return configType(config.SettingType); } private static Type configType(Type type) { return type.IsEnum ? Enum.GetUnderlyingType(type) : type; } private static ZPackage ConfigsToPackage([<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(new byte[] { 2, 1 })] IEnumerable configs = null, [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(new byte[] { 2, 1 })] IEnumerable customValues = null, [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(new byte[] { 2, 1 })] IEnumerable packageEntries = null, bool partial = true) { //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Expected O, but got Unknown List list = configs?.Where([<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] (ConfigEntryBase config) => configData(config).SynchronizedConfig).ToList() ?? new List(); List list2 = customValues?.ToList() ?? new List(); ZPackage val = new ZPackage(); val.Write((byte)(partial ? 1 : 0)); val.Write(list.Count + list2.Count + (packageEntries?.Count() ?? 0)); foreach (PackageEntry item in packageEntries ?? Array.Empty()) { AddEntryToPackage(val, item); } foreach (CustomSyncedValueBase item2 in list2) { AddEntryToPackage(val, new PackageEntry { section = "Internal", key = item2.Identifier, type = item2.Type, value = item2.BoxedValue }); } foreach (ConfigEntryBase item3 in list) { AddEntryToPackage(val, new PackageEntry { section = item3.Definition.Section, key = item3.Definition.Key, type = configType(item3), value = item3.BoxedValue }); } return val; } private static void AddEntryToPackage(ZPackage package, PackageEntry entry) { package.Write(entry.section); package.Write(entry.key); package.Write((entry.value == null) ? "" : GetZPackageTypeString(entry.type)); AddValueToZPackage(package, entry.value); } private static string GetZPackageTypeString(Type type) { return type.AssemblyQualifiedName; } private static void AddValueToZPackage(ZPackage package, [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(2)] object value) { Type type = value?.GetType(); if (value is Enum) { value = ((IConvertible)value).ToType(Enum.GetUnderlyingType(value.GetType()), CultureInfo.InvariantCulture); } else { if (value is ICollection collection) { package.Write(collection.Count); { foreach (object item in collection) { AddValueToZPackage(package, item); } return; } } if ((object)type != null && type.IsValueType && !type.IsPrimitive) { FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); package.Write(fields.Length); FieldInfo[] array = fields; foreach (FieldInfo fieldInfo in array) { package.Write(GetZPackageTypeString(fieldInfo.FieldType)); AddValueToZPackage(package, fieldInfo.GetValue(value)); } return; } } ZRpc.Serialize(new object[1] { value }, ref package); } private static object ReadValueWithTypeFromZPackage(ZPackage package, Type type) { if ((object)type != null && type.IsValueType && !type.IsPrimitive && !type.IsEnum) { FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); int num = package.ReadInt(); if (num != fields.Length) { throw new InvalidDeserializationTypeException { received = $"(field count: {num})", expected = $"(field count: {fields.Length})" }; } object uninitializedObject = FormatterServices.GetUninitializedObject(type); FieldInfo[] array = fields; foreach (FieldInfo fieldInfo in array) { string text = package.ReadString(); if (text != GetZPackageTypeString(fieldInfo.FieldType)) { throw new InvalidDeserializationTypeException { received = text, expected = GetZPackageTypeString(fieldInfo.FieldType), field = fieldInfo.Name }; } fieldInfo.SetValue(uninitializedObject, ReadValueWithTypeFromZPackage(package, fieldInfo.FieldType)); } return uninitializedObject; } if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary<, >)) { int num2 = package.ReadInt(); IDictionary dictionary = (IDictionary)Activator.CreateInstance(type); Type type2 = typeof(KeyValuePair<, >).MakeGenericType(type.GenericTypeArguments); FieldInfo field = type2.GetField("key", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field2 = type2.GetField("value", BindingFlags.Instance | BindingFlags.NonPublic); for (int j = 0; j < num2; j++) { object obj = ReadValueWithTypeFromZPackage(package, type2); dictionary.Add(field.GetValue(obj), field2.GetValue(obj)); } return dictionary; } if (type != typeof(List) && type.IsGenericType) { Type type3 = typeof(ICollection<>).MakeGenericType(type.GenericTypeArguments[0]); if ((object)type3 != null && type3.IsAssignableFrom(type)) { int num3 = package.ReadInt(); object obj2 = Activator.CreateInstance(type); MethodInfo method = type3.GetMethod("Add"); for (int k = 0; k < num3; k++) { method.Invoke(obj2, new object[1] { ReadValueWithTypeFromZPackage(package, type.GenericTypeArguments[0]) }); } return obj2; } } ParameterInfo parameterInfo = (ParameterInfo)FormatterServices.GetUninitializedObject(typeof(ParameterInfo)); AccessTools.DeclaredField(typeof(ParameterInfo), "ClassImpl").SetValue(parameterInfo, type); List source = new List(); ZRpc.Deserialize(new ParameterInfo[2] { null, parameterInfo }, package, ref source); return source.First(); } } [HarmonyPatch] [PublicAPI] [<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(1)] [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(0)] internal class VersionCheck { private static readonly HashSet versionChecks; private static readonly Dictionary notProcessedNames; public string Name; [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(2)] private string displayName; [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(2)] private string currentVersion; [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(2)] private string minimumRequiredVersion; public bool ModRequired = true; [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(2)] private string ReceivedCurrentVersion; [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(2)] private string ReceivedMinimumRequiredVersion; private readonly List ValidatedClients = new List(); [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(2)] private ConfigSync ConfigSync; public string DisplayName { get { return displayName ?? Name; } set { displayName = value; } } public string CurrentVersion { get { return currentVersion ?? "0.0.0"; } set { currentVersion = value; } } public string MinimumRequiredVersion { get { return minimumRequiredVersion ?? (ModRequired ? CurrentVersion : "0.0.0"); } set { minimumRequiredVersion = value; } } private static void PatchServerSync() { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Expected O, but got Unknown Patches patchInfo = PatchProcessor.GetPatchInfo((MethodBase)AccessTools.DeclaredMethod(typeof(ZNet), "Awake", (Type[])null, (Type[])null)); if (patchInfo != null && patchInfo.Postfixes.Count([<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] (Patch p) => p.PatchMethod.DeclaringType == typeof(ConfigSync.RegisterRPCPatch)) > 0) { return; } Harmony val = new Harmony("org.bepinex.helpers.ServerSync"); foreach (Type item in from t in typeof(ConfigSync).GetNestedTypes(BindingFlags.NonPublic).Concat(new Type[1] { typeof(VersionCheck) }) where t.IsClass select t) { val.PatchAll(item); } } static VersionCheck() { versionChecks = new HashSet(); notProcessedNames = new Dictionary(); typeof(ThreadingHelper).GetMethod("StartSyncInvoke").Invoke(ThreadingHelper.Instance, new object[1] { new Action(PatchServerSync) }); } public VersionCheck(string name) { Name = name; ModRequired = true; versionChecks.Add(this); } public VersionCheck(ConfigSync configSync) { ConfigSync = configSync; Name = ConfigSync.Name; versionChecks.Add(this); } public void Initialize() { ReceivedCurrentVersion = null; ReceivedMinimumRequiredVersion = null; if (ConfigSync != null) { Name = ConfigSync.Name; DisplayName = ConfigSync.DisplayName; CurrentVersion = ConfigSync.CurrentVersion; MinimumRequiredVersion = ConfigSync.MinimumRequiredVersion; ModRequired = ConfigSync.ModRequired; } } private bool IsVersionOk() { if (ReceivedMinimumRequiredVersion == null || ReceivedCurrentVersion == null) { return !ModRequired; } bool flag = new Version(CurrentVersion) >= new Version(ReceivedMinimumRequiredVersion); bool flag2 = new Version(ReceivedCurrentVersion) >= new Version(MinimumRequiredVersion); return flag && flag2; } private string ErrorClient() { if (ReceivedMinimumRequiredVersion == null) { return DisplayName + " is not installed on the server."; } return (new Version(CurrentVersion) >= new Version(ReceivedMinimumRequiredVersion)) ? (DisplayName + " may not be higher than version " + ReceivedCurrentVersion + ". You have version " + CurrentVersion + ".") : (DisplayName + " needs to be at least version " + ReceivedMinimumRequiredVersion + ". You have version " + CurrentVersion + "."); } private string ErrorServer(ZRpc rpc) { return "Disconnect: The client (" + rpc.GetSocket().GetHostName() + ") doesn't have the correct " + DisplayName + " version " + MinimumRequiredVersion; } private string Error([<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(2)] ZRpc rpc = null) { return (rpc == null) ? ErrorClient() : ErrorServer(rpc); } private static VersionCheck[] GetFailedClient() { return versionChecks.Where([<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] (VersionCheck check) => !check.IsVersionOk()).ToArray(); } private static VersionCheck[] GetFailedServer(ZRpc rpc) { return versionChecks.Where([<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] (VersionCheck check) => check.ModRequired && !check.ValidatedClients.Contains(rpc)).ToArray(); } private static void Logout() { Game.instance.Logout(true, true); AccessTools.DeclaredField(typeof(ZNet), "m_connectionStatus").SetValue(null, (object)(ConnectionStatus)3); } private static void DisconnectClient(ZRpc rpc) { rpc.Invoke("Error", new object[1] { 3 }); } private static void CheckVersion(ZRpc rpc, ZPackage pkg) { CheckVersion(rpc, pkg, null); } private static void CheckVersion(ZRpc rpc, ZPackage pkg, [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(new byte[] { 2, 1, 1 })] Action original) { string text = pkg.ReadString(); string text2 = pkg.ReadString(); string text3 = pkg.ReadString(); bool flag = false; foreach (VersionCheck versionCheck in versionChecks) { if (!(text != versionCheck.Name)) { Debug.Log((object)("Received " + versionCheck.DisplayName + " version " + text3 + " and minimum version " + text2 + " from the " + (ZNet.instance.IsServer() ? "client" : "server") + ".")); versionCheck.ReceivedMinimumRequiredVersion = text2; versionCheck.ReceivedCurrentVersion = text3; if (ZNet.instance.IsServer() && versionCheck.IsVersionOk()) { versionCheck.ValidatedClients.Add(rpc); } flag = true; } } if (flag) { return; } pkg.SetPos(0); if (original != null) { original(rpc, pkg); if (pkg.GetPos() == 0) { notProcessedNames.Add(text, text3); } } } [HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")] [HarmonyPrefix] private static bool RPC_PeerInfo(ZRpc rpc, ZNet __instance) { VersionCheck[] array = (__instance.IsServer() ? GetFailedServer(rpc) : GetFailedClient()); if (array.Length == 0) { return true; } VersionCheck[] array2 = array; foreach (VersionCheck versionCheck in array2) { Debug.LogWarning((object)versionCheck.Error(rpc)); } if (__instance.IsServer()) { DisconnectClient(rpc); } else { Logout(); } return false; } [HarmonyPatch(typeof(ZNet), "OnNewConnection")] [HarmonyPrefix] private static void RegisterAndCheckVersion(ZNetPeer peer, ZNet __instance) { //IL_018e: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Expected O, but got Unknown notProcessedNames.Clear(); IDictionary dictionary = (IDictionary)typeof(ZRpc).GetField("m_functions", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(peer.m_rpc); if (dictionary.Contains(StringExtensionMethods.GetStableHashCode("ServerSync VersionCheck"))) { object obj = dictionary[StringExtensionMethods.GetStableHashCode("ServerSync VersionCheck")]; Action action = (Action)obj.GetType().GetField("m_action", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(obj); peer.m_rpc.Register("ServerSync VersionCheck", (Action)([<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] (ZRpc rpc, [<1a013cea-436f-47e7-9ef0-942ec835cd53>Nullable(1)] ZPackage pkg) => { CheckVersion(rpc, pkg, action); })); } else { peer.m_rpc.Register("ServerSync VersionCheck", (Action)CheckVersion); } foreach (VersionCheck versionCheck in versionChecks) { versionCheck.Initialize(); if (versionCheck.ModRequired || __instance.IsServer()) { Debug.Log((object)("Sending " + versionCheck.DisplayName + " version " + versionCheck.CurrentVersion + " and minimum version " + versionCheck.MinimumRequiredVersion + " to the " + (__instance.IsServer() ? "client" : "server") + ".")); ZPackage val = new ZPackage(); val.Write(versionCheck.Name); val.Write(versionCheck.MinimumRequiredVersion); val.Write(versionCheck.CurrentVersion); peer.m_rpc.Invoke("ServerSync VersionCheck", new object[1] { val }); } } } [HarmonyPatch(typeof(ZNet), "Disconnect")] [HarmonyPrefix] private static void RemoveDisconnected(ZNetPeer peer, ZNet __instance) { if (!__instance.IsServer()) { return; } foreach (VersionCheck versionCheck in versionChecks) { versionCheck.ValidatedClients.Remove(peer.m_rpc); } } [HarmonyPostfix] [HarmonyPatch(typeof(FejdStartup), "ShowConnectError")] private static void ShowConnectionError(FejdStartup __instance) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Invalid comparison between Unknown and I4 //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Unknown result type (might be due to invalid IL or missing references) //IL_01de: Unknown result type (might be due to invalid IL or missing references) //IL_01ea: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_021e: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Unknown result type (might be due to invalid IL or missing references) if (!__instance.m_connectionFailedPanel.activeSelf || (int)ZNet.GetConnectionStatus() != 3) { return; } bool flag = false; VersionCheck[] failedClient = GetFailedClient(); if (failedClient.Length != 0) { string text = string.Join("\n", failedClient.Select([<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] (VersionCheck check) => check.Error())); TMP_Text connectionFailedError = __instance.m_connectionFailedError; connectionFailedError.text = connectionFailedError.text + "\n" + text; flag = true; } foreach (KeyValuePair item in notProcessedNames.OrderBy([<08001146-5bb1-445e-9ab9-c673c77332fb>NullableContext(0)] (KeyValuePair kv) => kv.Key)) { if (!__instance.m_connectionFailedError.text.Contains(item.Key)) { TMP_Text connectionFailedError2 = __instance.m_connectionFailedError; connectionFailedError2.text = connectionFailedError2.text + "\nServer expects you to have " + item.Key + " (Version: " + item.Value + ") installed."; flag = true; } } if (flag) { RectTransform component = ((Component)__instance.m_connectionFailedPanel.transform.Find("Image")).GetComponent(); Vector2 sizeDelta = component.sizeDelta; sizeDelta.x = 675f; component.sizeDelta = sizeDelta; __instance.m_connectionFailedError.ForceMeshUpdate(false, false); float num = __instance.m_connectionFailedError.renderedHeight + 105f; RectTransform component2 = ((Component)((Component)component).transform.Find("ButtonOk")).GetComponent(); component2.anchoredPosition = new Vector2(component2.anchoredPosition.x, component2.anchoredPosition.y - (num - component.sizeDelta.y) / 2f); sizeDelta = component.sizeDelta; sizeDelta.y = num; component.sizeDelta = sizeDelta; } } } } namespace Microsoft.CodeAnalysis { [CompilerGenerated] [<8b2b47d8-68a8-4e6b-8869-37c2122a801b>Embedded] internal sealed class <8b2b47d8-68a8-4e6b-8869-37c2122a801b>EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [<8b2b47d8-68a8-4e6b-8869-37c2122a801b>Embedded] internal sealed class IsReadOnlyAttribute : Attribute { } [CompilerGenerated] [<8b2b47d8-68a8-4e6b-8869-37c2122a801b>Embedded] internal sealed class IsByRefLikeAttribute : Attribute { } [CompilerGenerated] [<8b2b47d8-68a8-4e6b-8869-37c2122a801b>Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>NullableAttribute : Attribute { public readonly byte[] NullableFlags; public <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] [<8b2b47d8-68a8-4e6b-8869-37c2122a801b>Embedded] [CompilerGenerated] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] [<8b2b47d8-68a8-4e6b-8869-37c2122a801b>Embedded] [CompilerGenerated] internal sealed class <9248bc27-e977-4246-b6f6-bd8f7836272f>NativeIntegerAttribute : Attribute { public readonly bool[] TransformFlags; public <9248bc27-e977-4246-b6f6-bd8f7836272f>NativeIntegerAttribute() { TransformFlags = new bool[1] { true }; } public <9248bc27-e977-4246-b6f6-bd8f7836272f>NativeIntegerAttribute(bool[] P_0) { TransformFlags = P_0; } } [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] [<8b2b47d8-68a8-4e6b-8869-37c2122a801b>Embedded] [CompilerGenerated] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace MonoMod.Backports { internal static class MethodImplOptionsEx { public const MethodImplOptions Unmanaged = MethodImplOptions.Unmanaged; public const MethodImplOptions NoInlining = MethodImplOptions.NoInlining; public const MethodImplOptions ForwardRef = MethodImplOptions.ForwardRef; public const MethodImplOptions Synchronized = MethodImplOptions.Synchronized; public const MethodImplOptions NoOptimization = MethodImplOptions.NoOptimization; public const MethodImplOptions PreserveSig = MethodImplOptions.PreserveSig; public const MethodImplOptions AggressiveInlining = MethodImplOptions.AggressiveInlining; public const MethodImplOptions AggressiveOptimization = MethodImplOptions.AggressiveOptimization; public const MethodImplOptions InternalCall = MethodImplOptions.InternalCall; } } namespace System { internal static class ArrayEx { private static class TypeHolder<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T> { [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(1)] public static readonly T[] Empty = new T[0]; } public static int MaxLength => 1879048191; [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(1)] public static T[] Empty<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T>() { return TypeHolder.Empty; } } [NullableContext(2)] [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] [IsReadOnly] internal struct SequencePosition : IEquatable { private readonly object _object; private readonly int _integer; public SequencePosition(object @object, int integer) { _object = @object; _integer = integer; } [EditorBrowsable(EditorBrowsableState.Never)] public object GetObject() { return _object; } [EditorBrowsable(EditorBrowsableState.Never)] public int GetInteger() { return _integer; } public bool Equals(SequencePosition other) { if (_integer == other._integer) { return object.Equals(_object, other._object); } return false; } [EditorBrowsable(EditorBrowsableState.Never)] public override bool Equals(object obj) { if (obj is SequencePosition other) { return Equals(other); } return false; } [EditorBrowsable(EditorBrowsableState.Never)] public override int GetHashCode() { return HashCode.Combine(_object, _integer); } } internal static class EnvironmentEx { public static int CurrentManagedThreadId => Environment.CurrentManagedThreadId; } [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] [NullableContext(1)] internal sealed class Gen2GcCallback : CriticalFinalizerObject { [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] private readonly Func _callback0; [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] private readonly Func _callback1; private GCHandle _weakTargetObj; private Gen2GcCallback(Func callback) { _callback0 = callback; } private Gen2GcCallback(Func callback, object targetObj) { _callback1 = callback; _weakTargetObj = GCHandle.Alloc(targetObj, GCHandleType.Weak); } public static void Register(Func callback) { new System.Gen2GcCallback(callback); } public static void Register(Func callback, object targetObj) { new System.Gen2GcCallback(callback, targetObj); } ~Gen2GcCallback() { if (_weakTargetObj.IsAllocated) { object target = _weakTargetObj.Target; if (target == null) { _weakTargetObj.Free(); return; } try { if (!_callback1(target)) { _weakTargetObj.Free(); return; } } catch { } } else { try { if (!_callback0()) { return; } } catch { } } GC.ReRegisterForFinalize(this); } } [NullableContext(1)] [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] internal struct HashCode { private static readonly uint s_seed = GenerateGlobalSeed(); private const uint Prime1 = 2654435761u; private const uint Prime2 = 2246822519u; private const uint Prime3 = 3266489917u; private const uint Prime4 = 668265263u; private const uint Prime5 = 374761393u; private uint _v1; private uint _v2; private uint _v3; private uint _v4; private uint _queue1; private uint _queue2; private uint _queue3; private uint _length; private static uint GenerateGlobalSeed() { Span destination = stackalloc byte[4]; using (RandomNumberGenerator randomNumberGenerator = RandomNumberGenerator.Create()) { byte[] array = new byte[destination.Length]; randomNumberGenerator.GetBytes(array); MemoryExtensions.AsSpan(array).CopyTo(destination); } return Unsafe.ReadUnaligned(ref destination[0]); } public static int Combine<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T1>(T1 value1) { uint queuedValue = (uint)(value1?.GetHashCode() ?? 0); return (int)MixFinal(QueueRound(MixEmptyState() + 4, queuedValue)); } public static int Combine<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T1, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T2>(T1 value1, T2 value2) { uint queuedValue = (uint)(value1?.GetHashCode() ?? 0); uint queuedValue2 = (uint)(value2?.GetHashCode() ?? 0); return (int)MixFinal(QueueRound(QueueRound(MixEmptyState() + 8, queuedValue), queuedValue2)); } public static int Combine<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T1, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T2, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T3>(T1 value1, T2 value2, T3 value3) { uint queuedValue = (uint)(value1?.GetHashCode() ?? 0); uint queuedValue2 = (uint)(value2?.GetHashCode() ?? 0); uint queuedValue3 = (uint)(value3?.GetHashCode() ?? 0); return (int)MixFinal(QueueRound(QueueRound(QueueRound(MixEmptyState() + 12, queuedValue), queuedValue2), queuedValue3)); } public static int Combine<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T1, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T2, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T3, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T4>(T1 value1, T2 value2, T3 value3, T4 value4) { uint input = (uint)(value1?.GetHashCode() ?? 0); uint input2 = (uint)(value2?.GetHashCode() ?? 0); uint input3 = (uint)(value3?.GetHashCode() ?? 0); uint input4 = (uint)(value4?.GetHashCode() ?? 0); Initialize(out var v, out var v2, out var v3, out var v4); v = Round(v, input); v2 = Round(v2, input2); v3 = Round(v3, input3); v4 = Round(v4, input4); return (int)MixFinal(MixState(v, v2, v3, v4) + 16); } public static int Combine<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T1, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T2, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T3, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T4, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T5>(T1 value1, T2 value2, T3 value3, T4 value4, T5 value5) { uint input = (uint)(value1?.GetHashCode() ?? 0); uint input2 = (uint)(value2?.GetHashCode() ?? 0); uint input3 = (uint)(value3?.GetHashCode() ?? 0); uint input4 = (uint)(value4?.GetHashCode() ?? 0); uint queuedValue = (uint)(value5?.GetHashCode() ?? 0); Initialize(out var v, out var v2, out var v3, out var v4); v = Round(v, input); v2 = Round(v2, input2); v3 = Round(v3, input3); v4 = Round(v4, input4); return (int)MixFinal(QueueRound(MixState(v, v2, v3, v4) + 20, queuedValue)); } public static int Combine<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T1, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T2, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T3, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T4, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T5, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T6>(T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6) { uint input = (uint)(value1?.GetHashCode() ?? 0); uint input2 = (uint)(value2?.GetHashCode() ?? 0); uint input3 = (uint)(value3?.GetHashCode() ?? 0); uint input4 = (uint)(value4?.GetHashCode() ?? 0); uint queuedValue = (uint)(value5?.GetHashCode() ?? 0); uint queuedValue2 = (uint)(value6?.GetHashCode() ?? 0); Initialize(out var v, out var v2, out var v3, out var v4); v = Round(v, input); v2 = Round(v2, input2); v3 = Round(v3, input3); v4 = Round(v4, input4); return (int)MixFinal(QueueRound(QueueRound(MixState(v, v2, v3, v4) + 24, queuedValue), queuedValue2)); } public static int Combine<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T1, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T2, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T3, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T4, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T5, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T6, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T7>(T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7) { uint input = (uint)(value1?.GetHashCode() ?? 0); uint input2 = (uint)(value2?.GetHashCode() ?? 0); uint input3 = (uint)(value3?.GetHashCode() ?? 0); uint input4 = (uint)(value4?.GetHashCode() ?? 0); uint queuedValue = (uint)(value5?.GetHashCode() ?? 0); uint queuedValue2 = (uint)(value6?.GetHashCode() ?? 0); uint queuedValue3 = (uint)(value7?.GetHashCode() ?? 0); Initialize(out var v, out var v2, out var v3, out var v4); v = Round(v, input); v2 = Round(v2, input2); v3 = Round(v3, input3); v4 = Round(v4, input4); return (int)MixFinal(QueueRound(QueueRound(QueueRound(MixState(v, v2, v3, v4) + 28, queuedValue), queuedValue2), queuedValue3)); } public static int Combine<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T1, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T2, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T3, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T4, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T5, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T6, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T7, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T8>(T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6, T7 value7, T8 value8) { uint input = (uint)(value1?.GetHashCode() ?? 0); uint input2 = (uint)(value2?.GetHashCode() ?? 0); uint input3 = (uint)(value3?.GetHashCode() ?? 0); uint input4 = (uint)(value4?.GetHashCode() ?? 0); uint input5 = (uint)(value5?.GetHashCode() ?? 0); uint input6 = (uint)(value6?.GetHashCode() ?? 0); uint input7 = (uint)(value7?.GetHashCode() ?? 0); uint input8 = (uint)(value8?.GetHashCode() ?? 0); Initialize(out var v, out var v2, out var v3, out var v4); v = Round(v, input); v2 = Round(v2, input2); v3 = Round(v3, input3); v4 = Round(v4, input4); v = Round(v, input5); v2 = Round(v2, input6); v3 = Round(v3, input7); v4 = Round(v4, input8); return (int)MixFinal(MixState(v, v2, v3, v4) + 32); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void Initialize(out uint v1, out uint v2, out uint v3, out uint v4) { v1 = (uint)((int)s_seed + -1640531535 + -2048144777); v2 = s_seed + 2246822519u; v3 = s_seed; v4 = s_seed - 2654435761u; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint Round(uint hash, uint input) { return BitOperations.RotateLeft(hash + (uint)((int)input * -2048144777), 13) * 2654435761u; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint QueueRound(uint hash, uint queuedValue) { return BitOperations.RotateLeft(hash + (uint)((int)queuedValue * -1028477379), 17) * 668265263; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint MixState(uint v1, uint v2, uint v3, uint v4) { return BitOperations.RotateLeft(v1, 1) + BitOperations.RotateLeft(v2, 7) + BitOperations.RotateLeft(v3, 12) + BitOperations.RotateLeft(v4, 18); } private static uint MixEmptyState() { return s_seed + 374761393; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint MixFinal(uint hash) { hash ^= hash >> 15; hash *= 2246822519u; hash ^= hash >> 13; hash *= 3266489917u; hash ^= hash >> 16; return hash; } public void Add<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T>(T value) { Add(value?.GetHashCode() ?? 0); } public void Add<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T>(T value, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] IEqualityComparer comparer) { Add((value != null) ? (comparer?.GetHashCode(value) ?? value.GetHashCode()) : 0); } [NullableContext(0)] public void AddBytes(ReadOnlySpan value) { ref byte reference = ref MemoryMarshal.GetReference(value); ref byte reference2 = ref Unsafe.Add(ref reference, value.Length); while ((nint)Unsafe.ByteOffset(ref reference, ref reference2) >= 4) { Add(Unsafe.ReadUnaligned(ref reference)); reference = ref Unsafe.Add(ref reference, 4); } while (Unsafe.IsAddressLessThan(ref reference, ref reference2)) { Add((int)reference); reference = ref Unsafe.Add(ref reference, 1); } } private void Add(int value) { uint num = _length++; switch (num % 4) { case 0u: _queue1 = (uint)value; return; case 1u: _queue2 = (uint)value; return; case 2u: _queue3 = (uint)value; return; } if (num == 3) { Initialize(out _v1, out _v2, out _v3, out _v4); } _v1 = Round(_v1, _queue1); _v2 = Round(_v2, _queue2); _v3 = Round(_v3, _queue3); _v4 = Round(_v4, (uint)value); } public int ToHashCode() { uint length = _length; uint num = length % 4; uint num2 = ((length < 4) ? MixEmptyState() : MixState(_v1, _v2, _v3, _v4)); num2 += length * 4; if (num != 0) { num2 = QueueRound(num2, _queue1); if (num > 1) { num2 = QueueRound(num2, _queue2); if (num > 2) { num2 = QueueRound(num2, _queue3); } } } return (int)MixFinal(num2); } [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("HashCode is a mutable struct and should not be compared with other HashCodes. Use ToHashCode to retrieve the computed hash code.", true)] public override int GetHashCode() { throw new NotSupportedException("GetHashCode on HashCode is not supported"); } [NullableContext(2)] [EditorBrowsable(EditorBrowsableState.Never)] [Obsolete("HashCode is a mutable struct and should not be compared with other HashCodes.", true)] public override bool Equals(object obj) { throw new NotSupportedException("Equals on HashCode is not supported"); } } internal static class MathEx { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte Clamp(byte value, byte min, byte max) { if (min > max) { ThrowMinMaxException(min, max); } if (value < min) { return min; } if (value > max) { return max; } return value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static decimal Clamp(decimal value, decimal min, decimal max) { if (min > max) { ThrowMinMaxException(min, max); } if (value < min) { return min; } if (value > max) { return max; } return value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static double Clamp(double value, double min, double max) { if (min > max) { ThrowMinMaxException(min, max); } if (value < min) { return min; } if (value > max) { return max; } return value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static short Clamp(short value, short min, short max) { if (min > max) { ThrowMinMaxException(min, max); } if (value < min) { return min; } if (value > max) { return max; } return value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Clamp(int value, int min, int max) { if (min > max) { ThrowMinMaxException(min, max); } if (value < min) { return min; } if (value > max) { return max; } return value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static long Clamp(long value, long min, long max) { if (min > max) { ThrowMinMaxException(min, max); } if (value < min) { return min; } if (value > max) { return max; } return value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: <9248bc27-e977-4246-b6f6-bd8f7836272f>NativeInteger] public static IntPtr Clamp([<9248bc27-e977-4246-b6f6-bd8f7836272f>NativeInteger] IntPtr value, [<9248bc27-e977-4246-b6f6-bd8f7836272f>NativeInteger] IntPtr min, [<9248bc27-e977-4246-b6f6-bd8f7836272f>NativeInteger] IntPtr max) { if ((nint)min > (nint)max) { ThrowMinMaxException(min, max); } if ((nint)value < (nint)min) { return min; } if ((nint)value > (nint)max) { return max; } return value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static sbyte Clamp(sbyte value, sbyte min, sbyte max) { if (min > max) { ThrowMinMaxException(min, max); } if (value < min) { return min; } if (value > max) { return max; } return value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static float Clamp(float value, float min, float max) { if (min > max) { ThrowMinMaxException(min, max); } if (value < min) { return min; } if (value > max) { return max; } return value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static ushort Clamp(ushort value, ushort min, ushort max) { if (min > max) { ThrowMinMaxException(min, max); } if (value < min) { return min; } if (value > max) { return max; } return value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static uint Clamp(uint value, uint min, uint max) { if (min > max) { ThrowMinMaxException(min, max); } if (value < min) { return min; } if (value > max) { return max; } return value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static ulong Clamp(ulong value, ulong min, ulong max) { if (min > max) { ThrowMinMaxException(min, max); } if (value < min) { return min; } if (value > max) { return max; } return value; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] [return: <9248bc27-e977-4246-b6f6-bd8f7836272f>NativeInteger] public static UIntPtr Clamp([<9248bc27-e977-4246-b6f6-bd8f7836272f>NativeInteger] UIntPtr value, [<9248bc27-e977-4246-b6f6-bd8f7836272f>NativeInteger] UIntPtr min, [<9248bc27-e977-4246-b6f6-bd8f7836272f>NativeInteger] UIntPtr max) { if ((nuint)min > (nuint)max) { ThrowMinMaxException(min, max); } if ((nuint)value < (nuint)min) { return min; } if ((nuint)value > (nuint)max) { return max; } return value; } [NullableContext(1)] [DoesNotReturn] private static void ThrowMinMaxException<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T>(T min, T max) { throw new ArgumentException($"Minimum {min} is less than maximum {max}"); } } [NullableContext(1)] [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] [DebuggerTypeProxy(typeof(System.MemoryDebugView<>))] [DebuggerDisplay("{ToString(),raw}")] [IsReadOnly] internal struct Memory<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T> { [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] private readonly object _object; private readonly int _index; private readonly int _length; private const int RemoveFlagsBitMask = int.MaxValue; [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static Memory Empty { [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] get { return default(Memory); } } public int Length => _length & 0x7FFFFFFF; public bool IsEmpty => (_length & 0x7FFFFFFF) == 0; [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public Span Span { [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] get { Span result; if (_index < 0) { result = ((MemoryManager)_object).GetSpan(); return result.Slice(_index & 0x7FFFFFFF, _length); } if (typeof(T) == typeof(char) && _object is string text) { result = new Span(Unsafe.As>(text), MemoryExtensions.StringAdjustment, text.Length); return result.Slice(_index, _length); } if (_object != null) { return new Span((T[])_object, _index, _length & 0x7FFFFFFF); } result = default(Span); return result; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Memory([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] T[] array) { if (array == null) { this = default(Memory); return; } if (default(T) == null && array.GetType() != typeof(T[])) { System.ThrowHelper.ThrowArrayTypeMismatchException(); } _object = array; _index = 0; _length = array.Length; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal Memory([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] T[] array, int start) { if (array == null) { if (start != 0) { System.ThrowHelper.ThrowArgumentOutOfRangeException(); } this = default(Memory); return; } if (default(T) == null && array.GetType() != typeof(T[])) { System.ThrowHelper.ThrowArrayTypeMismatchException(); } if ((uint)start > (uint)array.Length) { System.ThrowHelper.ThrowArgumentOutOfRangeException(); } _object = array; _index = start; _length = array.Length - start; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Memory([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] T[] array, int start, int length) { if (array == null) { if (start != 0 || length != 0) { System.ThrowHelper.ThrowArgumentOutOfRangeException(); } this = default(Memory); return; } if (default(T) == null && array.GetType() != typeof(T[])) { System.ThrowHelper.ThrowArrayTypeMismatchException(); } if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start)) { System.ThrowHelper.ThrowArgumentOutOfRangeException(); } _object = array; _index = start; _length = length; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal Memory(MemoryManager manager, int length) { if (length < 0) { System.ThrowHelper.ThrowArgumentOutOfRangeException(); } _object = manager; _index = int.MinValue; _length = length; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal Memory(MemoryManager manager, int start, int length) { if (length < 0 || start < 0) { System.ThrowHelper.ThrowArgumentOutOfRangeException(); } _object = manager; _index = start | int.MinValue; _length = length; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(2)] internal Memory(object obj, int start, int length) { _object = obj; _index = start; _length = length; } [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static implicit operator Memory([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] T[] array) { return new Memory(array); } [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static implicit operator Memory([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ArraySegment segment) { return new Memory(segment.Array, segment.Offset, segment.Count); } [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static implicit operator ReadOnlyMemory([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] Memory memory) { return Unsafe.As, ReadOnlyMemory>(ref memory); } public override string ToString() { if (typeof(T) == typeof(char)) { if (!(_object is string text)) { return Span.ToString(); } return text.Substring(_index, _length & 0x7FFFFFFF); } return $"System.Memory<{typeof(T).Name}>[{_length & 0x7FFFFFFF}]"; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public Memory Slice(int start) { int length = _length; int num = length & 0x7FFFFFFF; if ((uint)start > (uint)num) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } return new Memory(_object, _index + start, length - start); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public Memory Slice(int start, int length) { int length2 = _length; int num = length2 & 0x7FFFFFFF; if ((uint)start > (uint)num || (uint)length > (uint)(num - start)) { System.ThrowHelper.ThrowArgumentOutOfRangeException(); } return new Memory(_object, _index + start, length | (length2 & int.MinValue)); } public void CopyTo([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] Memory destination) { Span.CopyTo(destination.Span); } public bool TryCopyTo([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] Memory destination) { return Span.TryCopyTo(destination.Span); } public unsafe MemoryHandle Pin() { if (_index < 0) { return ((MemoryManager)_object).Pin(_index & 0x7FFFFFFF); } if (typeof(T) == typeof(char) && _object is string value) { GCHandle handle = GCHandle.Alloc(value, GCHandleType.Pinned); return new MemoryHandle(Unsafe.Add((void*)handle.AddrOfPinnedObject(), _index), handle); } if (_object is T[] array) { if (_length < 0) { return new MemoryHandle(Unsafe.Add(Unsafe.AsPointer(ref MemoryMarshal.GetReference(array)), _index)); } GCHandle handle2 = GCHandle.Alloc(array, GCHandleType.Pinned); return new MemoryHandle(Unsafe.Add((void*)handle2.AddrOfPinnedObject(), _index), handle2); } return default(MemoryHandle); } public T[] ToArray() { return Span.ToArray(); } [EditorBrowsable(EditorBrowsableState.Never)] [NullableContext(2)] public override bool Equals(object obj) { if (obj is ReadOnlyMemory readOnlyMemory) { return readOnlyMemory.Equals(this); } if (obj is Memory other) { return Equals(other); } return false; } public bool Equals([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] Memory other) { if (_object == other._object && _index == other._index) { return _length == other._length; } return false; } [EditorBrowsable(EditorBrowsableState.Never)] public override int GetHashCode() { if (_object == null) { return 0; } return HashCode.Combine(_object, _index, _length); } } [NullableContext(1)] [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] internal sealed class MemoryDebugView<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T> { [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] private readonly ReadOnlyMemory _memory; [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)] public T[] Items => _memory.ToArray(); public MemoryDebugView([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] Memory memory) { _memory = memory; } public MemoryDebugView([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlyMemory memory) { _memory = memory; } } internal static class MemoryExtensions { [<9248bc27-e977-4246-b6f6-bd8f7836272f>NativeInteger] internal static readonly IntPtr StringAdjustment = MeasureStringAdjustment(); public static ReadOnlySpan Trim(this ReadOnlySpan span) { return span.TrimStart().TrimEnd(); } public static ReadOnlySpan TrimStart(this ReadOnlySpan span) { int i; for (i = 0; i < span.Length && char.IsWhiteSpace(span[i]); i++) { } return span.Slice(i); } public static ReadOnlySpan TrimEnd(this ReadOnlySpan span) { int num = span.Length - 1; while (num >= 0 && char.IsWhiteSpace(span[num])) { num--; } return span.Slice(0, num + 1); } public static ReadOnlySpan Trim(this ReadOnlySpan span, char trimChar) { return span.TrimStart(trimChar).TrimEnd(trimChar); } public static ReadOnlySpan TrimStart(this ReadOnlySpan span, char trimChar) { int i; for (i = 0; i < span.Length && span[i] == trimChar; i++) { } return span.Slice(i); } public static ReadOnlySpan TrimEnd(this ReadOnlySpan span, char trimChar) { int num = span.Length - 1; while (num >= 0 && span[num] == trimChar) { num--; } return span.Slice(0, num + 1); } public static ReadOnlySpan Trim(this ReadOnlySpan span, ReadOnlySpan trimChars) { return span.TrimStart(trimChars).TrimEnd(trimChars); } public static ReadOnlySpan TrimStart(this ReadOnlySpan span, ReadOnlySpan trimChars) { if (trimChars.IsEmpty) { return span.TrimStart(); } int i; for (i = 0; i < span.Length; i++) { int num = 0; while (num < trimChars.Length) { if (span[i] != trimChars[num]) { num++; continue; } goto IL_003c; } break; IL_003c:; } return span.Slice(i); } public static ReadOnlySpan TrimEnd(this ReadOnlySpan span, ReadOnlySpan trimChars) { if (trimChars.IsEmpty) { return span.TrimEnd(); } int num; for (num = span.Length - 1; num >= 0; num--) { int num2 = 0; while (num2 < trimChars.Length) { if (span[num] != trimChars[num2]) { num2++; continue; } goto IL_0044; } break; IL_0044:; } return span.Slice(0, num + 1); } public static bool IsWhiteSpace(this ReadOnlySpan span) { for (int i = 0; i < span.Length; i++) { if (!char.IsWhiteSpace(span[i])) { return false; } } return true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(1)] public static int IndexOf<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] T>([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this Span span, T value) where T : IEquatable { if (typeof(T) == typeof(byte)) { return System.SpanHelpers.IndexOf(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), Unsafe.As(ref value), span.Length); } if (typeof(T) == typeof(char)) { return System.SpanHelpers.IndexOf(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), Unsafe.As(ref value), span.Length); } return System.SpanHelpers.IndexOf(ref MemoryMarshal.GetReference(span), value, span.Length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int IndexOf([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this Span span, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan value) where T : IEquatable { if (typeof(T) == typeof(byte)) { return System.SpanHelpers.IndexOf(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), span.Length, ref Unsafe.As(ref MemoryMarshal.GetReference(value)), value.Length); } return System.SpanHelpers.IndexOf(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(value), value.Length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(1)] public static int LastIndexOf<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] T>([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this Span span, T value) where T : IEquatable { if (typeof(T) == typeof(byte)) { return System.SpanHelpers.LastIndexOf(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), Unsafe.As(ref value), span.Length); } if (typeof(T) == typeof(char)) { return System.SpanHelpers.LastIndexOf(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), Unsafe.As(ref value), span.Length); } return System.SpanHelpers.LastIndexOf(ref MemoryMarshal.GetReference(span), value, span.Length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int LastIndexOf([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this Span span, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan value) where T : IEquatable { if (typeof(T) == typeof(byte)) { return System.SpanHelpers.LastIndexOf(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), span.Length, ref Unsafe.As(ref MemoryMarshal.GetReference(value)), value.Length); } return System.SpanHelpers.LastIndexOf(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(value), value.Length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool SequenceEqual([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this Span span, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan other) where T : IEquatable { int length = span.Length; if (default(T) != null && IsTypeComparableAsBytes(out nuint size)) { if (length == other.Length) { return System.SpanHelpers.SequenceEqual(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), ref Unsafe.As(ref MemoryMarshal.GetReference(other)), (nuint)length * size); } return false; } if (length == other.Length) { return System.SpanHelpers.SequenceEqual(ref MemoryMarshal.GetReference(span), ref MemoryMarshal.GetReference(other), length); } return false; } public static int SequenceCompareTo([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this Span span, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan other) where T : IComparable { if (typeof(T) == typeof(byte)) { return System.SpanHelpers.SequenceCompareTo(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), span.Length, ref Unsafe.As(ref MemoryMarshal.GetReference(other)), other.Length); } if (typeof(T) == typeof(char)) { return System.SpanHelpers.SequenceCompareTo(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), span.Length, ref Unsafe.As(ref MemoryMarshal.GetReference(other)), other.Length); } return System.SpanHelpers.SequenceCompareTo(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(other), other.Length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(1)] public static int IndexOf<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] T>([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this ReadOnlySpan span, T value) where T : IEquatable { if (typeof(T) == typeof(byte)) { return System.SpanHelpers.IndexOf(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), Unsafe.As(ref value), span.Length); } if (typeof(T) == typeof(char)) { return System.SpanHelpers.IndexOf(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), Unsafe.As(ref value), span.Length); } return System.SpanHelpers.IndexOf(ref MemoryMarshal.GetReference(span), value, span.Length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int IndexOf([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this ReadOnlySpan span, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan value) where T : IEquatable { if (typeof(T) == typeof(byte)) { return System.SpanHelpers.IndexOf(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), span.Length, ref Unsafe.As(ref MemoryMarshal.GetReference(value)), value.Length); } return System.SpanHelpers.IndexOf(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(value), value.Length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(1)] public static int LastIndexOf<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] T>([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this ReadOnlySpan span, T value) where T : IEquatable { if (typeof(T) == typeof(byte)) { return System.SpanHelpers.LastIndexOf(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), Unsafe.As(ref value), span.Length); } if (typeof(T) == typeof(char)) { return System.SpanHelpers.LastIndexOf(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), Unsafe.As(ref value), span.Length); } return System.SpanHelpers.LastIndexOf(ref MemoryMarshal.GetReference(span), value, span.Length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int LastIndexOf([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this ReadOnlySpan span, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan value) where T : IEquatable { if (typeof(T) == typeof(byte)) { return System.SpanHelpers.LastIndexOf(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), span.Length, ref Unsafe.As(ref MemoryMarshal.GetReference(value)), value.Length); } return System.SpanHelpers.LastIndexOf(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(value), value.Length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(1)] public static int IndexOfAny<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] T>([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this Span span, T value0, T value1) where T : IEquatable { if (typeof(T) == typeof(byte)) { return System.SpanHelpers.IndexOfAny(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), Unsafe.As(ref value0), Unsafe.As(ref value1), span.Length); } return System.SpanHelpers.IndexOfAny(ref MemoryMarshal.GetReference(span), value0, value1, span.Length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(1)] public static int IndexOfAny<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] T>([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this Span span, T value0, T value1, T value2) where T : IEquatable { if (typeof(T) == typeof(byte)) { return System.SpanHelpers.IndexOfAny(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), Unsafe.As(ref value0), Unsafe.As(ref value1), Unsafe.As(ref value2), span.Length); } return System.SpanHelpers.IndexOfAny(ref MemoryMarshal.GetReference(span), value0, value1, value2, span.Length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int IndexOfAny([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this Span span, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan values) where T : IEquatable { if (typeof(T) == typeof(byte)) { return System.SpanHelpers.IndexOfAny(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), span.Length, ref Unsafe.As(ref MemoryMarshal.GetReference(values)), values.Length); } return System.SpanHelpers.IndexOfAny(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(values), values.Length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(1)] public static int IndexOfAny<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] T>([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this ReadOnlySpan span, T value0, T value1) where T : IEquatable { if (typeof(T) == typeof(byte)) { return System.SpanHelpers.IndexOfAny(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), Unsafe.As(ref value0), Unsafe.As(ref value1), span.Length); } return System.SpanHelpers.IndexOfAny(ref MemoryMarshal.GetReference(span), value0, value1, span.Length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(1)] public static int IndexOfAny<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] T>([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this ReadOnlySpan span, T value0, T value1, T value2) where T : IEquatable { if (typeof(T) == typeof(byte)) { return System.SpanHelpers.IndexOfAny(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), Unsafe.As(ref value0), Unsafe.As(ref value1), Unsafe.As(ref value2), span.Length); } return System.SpanHelpers.IndexOfAny(ref MemoryMarshal.GetReference(span), value0, value1, value2, span.Length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int IndexOfAny([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this ReadOnlySpan span, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan values) where T : IEquatable { if (typeof(T) == typeof(byte)) { return System.SpanHelpers.IndexOfAny(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), span.Length, ref Unsafe.As(ref MemoryMarshal.GetReference(values)), values.Length); } return System.SpanHelpers.IndexOfAny(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(values), values.Length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(1)] public static int LastIndexOfAny<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] T>([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this Span span, T value0, T value1) where T : IEquatable { if (typeof(T) == typeof(byte)) { return System.SpanHelpers.LastIndexOfAny(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), Unsafe.As(ref value0), Unsafe.As(ref value1), span.Length); } return System.SpanHelpers.LastIndexOfAny(ref MemoryMarshal.GetReference(span), value0, value1, span.Length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(1)] public static int LastIndexOfAny<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] T>([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this Span span, T value0, T value1, T value2) where T : IEquatable { if (typeof(T) == typeof(byte)) { return System.SpanHelpers.LastIndexOfAny(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), Unsafe.As(ref value0), Unsafe.As(ref value1), Unsafe.As(ref value2), span.Length); } return System.SpanHelpers.LastIndexOfAny(ref MemoryMarshal.GetReference(span), value0, value1, value2, span.Length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int LastIndexOfAny([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this Span span, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan values) where T : IEquatable { if (typeof(T) == typeof(byte)) { return System.SpanHelpers.LastIndexOfAny(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), span.Length, ref Unsafe.As(ref MemoryMarshal.GetReference(values)), values.Length); } return System.SpanHelpers.LastIndexOfAny(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(values), values.Length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(1)] public static int LastIndexOfAny<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] T>([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this ReadOnlySpan span, T value0, T value1) where T : IEquatable { if (typeof(T) == typeof(byte)) { return System.SpanHelpers.LastIndexOfAny(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), Unsafe.As(ref value0), Unsafe.As(ref value1), span.Length); } return System.SpanHelpers.LastIndexOfAny(ref MemoryMarshal.GetReference(span), value0, value1, span.Length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(1)] public static int LastIndexOfAny<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] T>([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this ReadOnlySpan span, T value0, T value1, T value2) where T : IEquatable { if (typeof(T) == typeof(byte)) { return System.SpanHelpers.LastIndexOfAny(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), Unsafe.As(ref value0), Unsafe.As(ref value1), Unsafe.As(ref value2), span.Length); } return System.SpanHelpers.LastIndexOfAny(ref MemoryMarshal.GetReference(span), value0, value1, value2, span.Length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int LastIndexOfAny([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this ReadOnlySpan span, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan values) where T : IEquatable { if (typeof(T) == typeof(byte)) { return System.SpanHelpers.LastIndexOfAny(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), span.Length, ref Unsafe.As(ref MemoryMarshal.GetReference(values)), values.Length); } return System.SpanHelpers.LastIndexOfAny(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(values), values.Length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool SequenceEqual([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this ReadOnlySpan span, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan other) where T : IEquatable { int length = span.Length; if (default(T) != null && IsTypeComparableAsBytes(out nuint size)) { if (length == other.Length) { return System.SpanHelpers.SequenceEqual(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), ref Unsafe.As(ref MemoryMarshal.GetReference(other)), (nuint)length * size); } return false; } if (length == other.Length) { return System.SpanHelpers.SequenceEqual(ref MemoryMarshal.GetReference(span), ref MemoryMarshal.GetReference(other), length); } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int SequenceCompareTo([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this ReadOnlySpan span, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan other) where T : IComparable { if (typeof(T) == typeof(byte)) { return System.SpanHelpers.SequenceCompareTo(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), span.Length, ref Unsafe.As(ref MemoryMarshal.GetReference(other)), other.Length); } if (typeof(T) == typeof(char)) { return System.SpanHelpers.SequenceCompareTo(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), span.Length, ref Unsafe.As(ref MemoryMarshal.GetReference(other)), other.Length); } return System.SpanHelpers.SequenceCompareTo(ref MemoryMarshal.GetReference(span), span.Length, ref MemoryMarshal.GetReference(other), other.Length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool StartsWith([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this Span span, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan value) where T : IEquatable { int length = value.Length; if (default(T) != null && IsTypeComparableAsBytes(out nuint size)) { if (length <= span.Length) { return System.SpanHelpers.SequenceEqual(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), ref Unsafe.As(ref MemoryMarshal.GetReference(value)), (nuint)length * size); } return false; } if (length <= span.Length) { return System.SpanHelpers.SequenceEqual(ref MemoryMarshal.GetReference(span), ref MemoryMarshal.GetReference(value), length); } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool StartsWith([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this ReadOnlySpan span, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan value) where T : IEquatable { int length = value.Length; if (default(T) != null && IsTypeComparableAsBytes(out nuint size)) { if (length <= span.Length) { return System.SpanHelpers.SequenceEqual(ref Unsafe.As(ref MemoryMarshal.GetReference(span)), ref Unsafe.As(ref MemoryMarshal.GetReference(value)), (nuint)length * size); } return false; } if (length <= span.Length) { return System.SpanHelpers.SequenceEqual(ref MemoryMarshal.GetReference(span), ref MemoryMarshal.GetReference(value), length); } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool EndsWith([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this Span span, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan value) where T : IEquatable { int length = span.Length; int length2 = value.Length; if (default(T) != null && IsTypeComparableAsBytes(out nuint size)) { if (length2 <= length) { return System.SpanHelpers.SequenceEqual(ref Unsafe.As(ref Unsafe.Add(ref MemoryMarshal.GetReference(span), length - length2)), ref Unsafe.As(ref MemoryMarshal.GetReference(value)), (nuint)length2 * size); } return false; } if (length2 <= length) { return System.SpanHelpers.SequenceEqual(ref Unsafe.Add(ref MemoryMarshal.GetReference(span), length - length2), ref MemoryMarshal.GetReference(value), length2); } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool EndsWith([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this ReadOnlySpan span, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan value) where T : IEquatable { int length = span.Length; int length2 = value.Length; if (default(T) != null && IsTypeComparableAsBytes(out nuint size)) { if (length2 <= length) { return System.SpanHelpers.SequenceEqual(ref Unsafe.As(ref Unsafe.Add(ref MemoryMarshal.GetReference(span), length - length2)), ref Unsafe.As(ref MemoryMarshal.GetReference(value)), (nuint)length2 * size); } return false; } if (length2 <= length) { return System.SpanHelpers.SequenceEqual(ref Unsafe.Add(ref MemoryMarshal.GetReference(span), length - length2), ref MemoryMarshal.GetReference(value), length2); } return false; } [NullableContext(2)] public static void Reverse([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this Span span) { if (span.Length > 1) { ref T reference = ref MemoryMarshal.GetReference(span); ref T reference2 = ref Unsafe.Add(ref Unsafe.Add(ref reference, span.Length), -1); do { T val = reference; reference = reference2; reference2 = val; reference = ref Unsafe.Add(ref reference, 1); reference2 = ref Unsafe.Add(ref reference2, -1); } while (Unsafe.IsAddressLessThan(ref reference, ref reference2)); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(2)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static Span AsSpan([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] this T[] array) { return new Span(array); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(2)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static Span AsSpan([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] this T[] array, int start, int length) { return new Span(array, start, length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(2)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static Span AsSpan([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this ArraySegment segment) { return new Span(segment.Array, segment.Offset, segment.Count); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(2)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static Span AsSpan([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this ArraySegment segment, int start) { if ((uint)start > segment.Count) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } return new Span(segment.Array, segment.Offset + start, segment.Count - start); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(2)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static Span AsSpan([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this ArraySegment segment, int start, int length) { if ((uint)start > segment.Count) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } if ((uint)length > segment.Count - start) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.length); } return new Span(segment.Array, segment.Offset + start, length); } [NullableContext(2)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static Memory AsMemory([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] this T[] array) { return new Memory(array); } [NullableContext(2)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static Memory AsMemory([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] this T[] array, int start) { return new Memory(array, start); } [NullableContext(2)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static Memory AsMemory([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] this T[] array, int start, int length) { return new Memory(array, start, length); } [NullableContext(2)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static Memory AsMemory([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this ArraySegment segment) { return new Memory(segment.Array, segment.Offset, segment.Count); } [NullableContext(2)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static Memory AsMemory([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this ArraySegment segment, int start) { if ((uint)start > segment.Count) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } return new Memory(segment.Array, segment.Offset + start, segment.Count - start); } [NullableContext(2)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static Memory AsMemory([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this ArraySegment segment, int start, int length) { if ((uint)start > segment.Count) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } if ((uint)length > segment.Count - start) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.length); } return new Memory(segment.Array, segment.Offset + start, length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(2)] public static void CopyTo([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] this T[] source, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] Span destination) { new ReadOnlySpan(source).CopyTo(destination); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(2)] public static void CopyTo([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] this T[] source, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] Memory destination) { source.CopyTo(destination.Span); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(2)] public static bool Overlaps([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this Span span, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan other) { return ((ReadOnlySpan)span).Overlaps(other); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(2)] public static bool Overlaps([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this Span span, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan other, out int elementOffset) { return ((ReadOnlySpan)span).Overlaps(other, out elementOffset); } [NullableContext(2)] public static bool Overlaps([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this ReadOnlySpan span, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan other) { if (span.IsEmpty || other.IsEmpty) { return false; } IntPtr intPtr = Unsafe.ByteOffset(ref MemoryMarshal.GetReference(span), ref MemoryMarshal.GetReference(other)); if (Unsafe.SizeOf() == 4) { if ((uint)(int)intPtr >= (uint)(span.Length * Unsafe.SizeOf())) { return (uint)(int)intPtr > (uint)(-(other.Length * Unsafe.SizeOf())); } return true; } if ((ulong)(long)intPtr >= (ulong)((long)span.Length * (long)Unsafe.SizeOf())) { return (ulong)(long)intPtr > (ulong)(-((long)other.Length * (long)Unsafe.SizeOf())); } return true; } [NullableContext(2)] public static bool Overlaps([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this ReadOnlySpan span, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan other, out int elementOffset) { if (span.IsEmpty || other.IsEmpty) { elementOffset = 0; return false; } IntPtr intPtr = Unsafe.ByteOffset(ref MemoryMarshal.GetReference(span), ref MemoryMarshal.GetReference(other)); if (Unsafe.SizeOf() == 4) { if ((uint)(int)intPtr < (uint)(span.Length * Unsafe.SizeOf()) || (uint)(int)intPtr > (uint)(-(other.Length * Unsafe.SizeOf()))) { if ((int)intPtr % Unsafe.SizeOf() != 0) { System.ThrowHelper.ThrowArgumentException_OverlapAlignmentMismatch(); } elementOffset = (int)intPtr / Unsafe.SizeOf(); return true; } elementOffset = 0; return false; } if ((ulong)(long)intPtr < (ulong)((long)span.Length * (long)Unsafe.SizeOf()) || (ulong)(long)intPtr > (ulong)(-((long)other.Length * (long)Unsafe.SizeOf()))) { if ((long)intPtr % Unsafe.SizeOf() != 0L) { System.ThrowHelper.ThrowArgumentException_OverlapAlignmentMismatch(); } elementOffset = (int)((long)intPtr / Unsafe.SizeOf()); return true; } elementOffset = 0; return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(1)] public static int BinarySearch<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T>([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this Span span, IComparable comparable) { return span.BinarySearch>(comparable); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(1)] public static int BinarySearch<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] TComparable>([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this Span span, TComparable comparable) where TComparable : IComparable { return BinarySearch((ReadOnlySpan)span, comparable); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(1)] public static int BinarySearch<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] TComparer>([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this Span span, T value, TComparer comparer) where TComparer : IComparer { return ((ReadOnlySpan)span).BinarySearch(value, comparer); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(1)] public static int BinarySearch<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T>([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this ReadOnlySpan span, IComparable comparable) { return MemoryExtensions.BinarySearch>(span, comparable); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(1)] public static int BinarySearch<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] TComparable>([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this ReadOnlySpan span, TComparable comparable) where TComparable : IComparable { return System.SpanHelpers.BinarySearch(span, comparable); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(1)] public static int BinarySearch<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] TComparer>([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this ReadOnlySpan span, T value, TComparer comparer) where TComparer : IComparer { if (comparer == null) { System.ThrowHelper.ThrowArgumentNullException(System.ExceptionArgument.comparer); } System.SpanHelpers.ComparerComparable comparable = new System.SpanHelpers.ComparerComparable(value, comparer); return BinarySearch(span, comparable); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(2)] private static bool IsTypeComparableAsBytes([<9248bc27-e977-4246-b6f6-bd8f7836272f>NativeInteger] out UIntPtr size) { if (typeof(T) == typeof(byte) || typeof(T) == typeof(sbyte)) { size = (nuint)1u; return true; } if (typeof(T) == typeof(char) || typeof(T) == typeof(short) || typeof(T) == typeof(ushort)) { size = (nuint)2u; return true; } if (typeof(T) == typeof(int) || typeof(T) == typeof(uint)) { size = (nuint)4u; return true; } if (typeof(T) == typeof(long) || typeof(T) == typeof(ulong)) { size = (nuint)8u; return true; } size = (nuint)0u; return false; } [NullableContext(2)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static Span AsSpan([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] this T[] array, int start) { return Span.Create(array, start); } public static bool Contains(this ReadOnlySpan span, ReadOnlySpan value, StringComparison comparisonType) { return span.IndexOf(value, comparisonType) >= 0; } public static bool Equals(this ReadOnlySpan span, ReadOnlySpan other, StringComparison comparisonType) { switch (comparisonType) { case StringComparison.Ordinal: return span.SequenceEqual(other); case StringComparison.OrdinalIgnoreCase: if (span.Length != other.Length) { return false; } return EqualsOrdinalIgnoreCase(span, other); default: return span.ToString().Equals(other.ToString(), comparisonType); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static bool EqualsOrdinalIgnoreCase(ReadOnlySpan span, ReadOnlySpan other) { if (other.Length == 0) { return true; } return CompareToOrdinalIgnoreCase(span, other) == 0; } public static int CompareTo(this ReadOnlySpan span, ReadOnlySpan other, StringComparison comparisonType) { return comparisonType switch { StringComparison.Ordinal => span.SequenceCompareTo(other), StringComparison.OrdinalIgnoreCase => CompareToOrdinalIgnoreCase(span, other), _ => string.Compare(span.ToString(), other.ToString(), comparisonType), }; } private unsafe static int CompareToOrdinalIgnoreCase(ReadOnlySpan strA, ReadOnlySpan strB) { int num = Math.Min(strA.Length, strB.Length); int num2 = num; fixed (char* ptr = &MemoryMarshal.GetReference(strA)) { fixed (char* ptr3 = &MemoryMarshal.GetReference(strB)) { char* ptr2 = ptr; char* ptr4 = ptr3; while (num != 0 && *ptr2 <= '\u007f' && *ptr4 <= '\u007f') { int num3 = *ptr2; int num4 = *ptr4; if (num3 == num4) { ptr2++; ptr4++; num--; continue; } if ((uint)(num3 - 97) <= 25u) { num3 -= 32; } if ((uint)(num4 - 97) <= 25u) { num4 -= 32; } if (num3 != num4) { return num3 - num4; } ptr2++; ptr4++; num--; } if (num == 0) { return strA.Length - strB.Length; } num2 -= num; return string.Compare(strA.Slice(num2).ToString(), strB.Slice(num2).ToString(), StringComparison.OrdinalIgnoreCase); } } } public static int IndexOf(this ReadOnlySpan span, ReadOnlySpan value, StringComparison comparisonType) { if (comparisonType == StringComparison.Ordinal) { return span.IndexOf(value); } return span.ToString().IndexOf(value.ToString(), comparisonType); } public static int ToLower(this ReadOnlySpan source, Span destination, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(1)] CultureInfo culture) { System.ThrowHelper.ThrowIfArgumentNull(culture, System.ExceptionArgument.culture); if (destination.Length < source.Length) { return -1; } string str = source.ToString(); AsSpan(culture.TextInfo.ToLower(str)).CopyTo(destination); return source.Length; } public static int ToLowerInvariant(this ReadOnlySpan source, Span destination) { return source.ToLower(destination, CultureInfo.InvariantCulture); } public static int ToUpper(this ReadOnlySpan source, Span destination, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(1)] CultureInfo culture) { System.ThrowHelper.ThrowIfArgumentNull(culture, System.ExceptionArgument.culture); if (destination.Length < source.Length) { return -1; } string str = source.ToString(); AsSpan(culture.TextInfo.ToUpper(str)).CopyTo(destination); return source.Length; } public static int ToUpperInvariant(this ReadOnlySpan source, Span destination) { return source.ToUpper(destination, CultureInfo.InvariantCulture); } public static bool EndsWith(this ReadOnlySpan span, ReadOnlySpan value, StringComparison comparisonType) { switch (comparisonType) { case StringComparison.Ordinal: return span.EndsWith(value); case StringComparison.OrdinalIgnoreCase: if (value.Length <= span.Length) { return EqualsOrdinalIgnoreCase(span.Slice(span.Length - value.Length), value); } return false; default: { string text = span.ToString(); string value2 = value.ToString(); return text.EndsWith(value2, comparisonType); } } } public static bool StartsWith(this ReadOnlySpan span, ReadOnlySpan value, StringComparison comparisonType) { switch (comparisonType) { case StringComparison.Ordinal: return span.StartsWith(value); case StringComparison.OrdinalIgnoreCase: if (value.Length <= span.Length) { return EqualsOrdinalIgnoreCase(span.Slice(0, value.Length), value); } return false; default: { string text = span.ToString(); string value2 = value.ToString(); return text.StartsWith(value2, comparisonType); } } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan AsSpan([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] this string text) { if (text == null) { return default(ReadOnlySpan); } return new ReadOnlySpan(Unsafe.As>(text), StringAdjustment, text.Length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan AsSpan([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] this string text, int start) { if (text == null) { if (start != 0) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } return default(ReadOnlySpan); } if ((uint)start > (uint)text.Length) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } return new ReadOnlySpan(Unsafe.As>(text), (nint)StringAdjustment + start * 2, text.Length - start); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan AsSpan([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] this string text, int start, int length) { if (text == null) { if (start != 0 || length != 0) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } return default(ReadOnlySpan); } if ((uint)start > (uint)text.Length || (uint)length > (uint)(text.Length - start)) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } return new ReadOnlySpan(Unsafe.As>(text), (nint)StringAdjustment + start * 2, length); } public static ReadOnlyMemory AsMemory([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] this string text) { if (text == null) { return default(ReadOnlyMemory); } return new ReadOnlyMemory(text, 0, text.Length); } public static ReadOnlyMemory AsMemory([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] this string text, int start) { if (text == null) { if (start != 0) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } return default(ReadOnlyMemory); } if ((uint)start > (uint)text.Length) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } return new ReadOnlyMemory(text, start, text.Length - start); } public static ReadOnlyMemory AsMemory([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] this string text, int start, int length) { if (text == null) { if (start != 0 || length != 0) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } return default(ReadOnlyMemory); } if ((uint)start > (uint)text.Length || (uint)length > (uint)(text.Length - start)) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } return new ReadOnlyMemory(text, start, length); } [return: <9248bc27-e977-4246-b6f6-bd8f7836272f>NativeInteger] private unsafe static IntPtr MeasureStringAdjustment() { fixed (char* source = "a") { return Unsafe.ByteOffset(ref Unsafe.As>("a").Data, ref Unsafe.AsRef(source)); } } } [StructLayout(LayoutKind.Sequential)] internal sealed class Pinnable<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T> { [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(1)] public T Data; } [IsReadOnly] [DebuggerTypeProxy(typeof(System.MemoryDebugView<>))] [NullableContext(2)] [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] [DebuggerDisplay("{ToString(),raw}")] internal struct ReadOnlyMemory { private readonly object _object; private readonly int _index; private readonly int _length; internal const int RemoveFlagsBitMask = int.MaxValue; [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static ReadOnlyMemory Empty { [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] get { return default(ReadOnlyMemory); } } public int Length => _length & 0x7FFFFFFF; public bool IsEmpty => (_length & 0x7FFFFFFF) == 0; [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public ReadOnlySpan Span { [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] get { if (_index < 0) { return ((MemoryManager)_object).GetSpan().Slice(_index & 0x7FFFFFFF, _length); } ReadOnlySpan result; if (typeof(T) == typeof(char) && _object is string text) { result = new ReadOnlySpan(Unsafe.As>(text), MemoryExtensions.StringAdjustment, text.Length); return result.Slice(_index, _length); } if (_object != null) { return new ReadOnlySpan((T[])_object, _index, _length & 0x7FFFFFFF); } result = default(ReadOnlySpan); return result; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public ReadOnlyMemory([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] T[] array) { if (array == null) { this = default(ReadOnlyMemory); return; } _object = array; _index = 0; _length = array.Length; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public ReadOnlyMemory([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] T[] array, int start, int length) { if (array == null) { if (start != 0 || length != 0) { System.ThrowHelper.ThrowArgumentOutOfRangeException(); } this = default(ReadOnlyMemory); return; } if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start)) { System.ThrowHelper.ThrowArgumentOutOfRangeException(); } _object = array; _index = start; _length = length; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal ReadOnlyMemory(object obj, int start, int length) { _object = obj; _index = start; _length = length; } [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static implicit operator ReadOnlyMemory([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] T[] array) { return new ReadOnlyMemory(array); } [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static implicit operator ReadOnlyMemory([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ArraySegment segment) { return new ReadOnlyMemory(segment.Array, segment.Offset, segment.Count); } [NullableContext(1)] public override string ToString() { if (typeof(T) == typeof(char)) { if (!(_object is string text)) { return Span.ToString(); } return text.Substring(_index, _length & 0x7FFFFFFF); } return $"System.ReadOnlyMemory<{typeof(T).Name}>[{_length & 0x7FFFFFFF}]"; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public ReadOnlyMemory Slice(int start) { int length = _length; int num = length & 0x7FFFFFFF; if ((uint)start > (uint)num) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } return new ReadOnlyMemory(_object, _index + start, length - start); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public ReadOnlyMemory Slice(int start, int length) { int length2 = _length; int num = _length & 0x7FFFFFFF; if ((uint)start > (uint)num || (uint)length > (uint)(num - start)) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } return new ReadOnlyMemory(_object, _index + start, length | (length2 & int.MinValue)); } public void CopyTo([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] Memory destination) { Span.CopyTo(destination.Span); } public bool TryCopyTo([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] Memory destination) { return Span.TryCopyTo(destination.Span); } public unsafe MemoryHandle Pin() { if (_index < 0) { return ((MemoryManager)_object).Pin(_index & 0x7FFFFFFF); } if (typeof(T) == typeof(char) && _object is string value) { GCHandle handle = GCHandle.Alloc(value, GCHandleType.Pinned); return new MemoryHandle(Unsafe.Add((void*)handle.AddrOfPinnedObject(), _index), handle); } if (_object is T[] array) { if (_length < 0) { return new MemoryHandle(Unsafe.Add(Unsafe.AsPointer(ref MemoryMarshal.GetReference(array)), _index)); } GCHandle handle2 = GCHandle.Alloc(array, GCHandleType.Pinned); return new MemoryHandle(Unsafe.Add((void*)handle2.AddrOfPinnedObject(), _index), handle2); } return default(MemoryHandle); } [NullableContext(1)] public T[] ToArray() { return Span.ToArray(); } [EditorBrowsable(EditorBrowsableState.Never)] public override bool Equals(object obj) { if (obj is ReadOnlyMemory other) { return Equals(other); } if (obj is Memory memory) { return Equals(memory); } return false; } public bool Equals([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlyMemory other) { if (_object == other._object && _index == other._index) { return _length == other._length; } return false; } [EditorBrowsable(EditorBrowsableState.Never)] public override int GetHashCode() { if (_object == null) { return 0; } return HashCode.Combine(_object, _index, _length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal object GetObjectStartLength(out int start, out int length) { start = _index; length = _length; return _object; } } [DebuggerTypeProxy(typeof(System.SpanDebugView<>))] [IsReadOnly] [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] [DebuggerDisplay("{ToString(),raw}")] [NullableContext(1)] internal ref struct ReadOnlySpan<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T> { [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] public ref struct Enumerator { [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] private readonly ReadOnlySpan _span; private int _index; [IsReadOnly] public ref T Current { [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: IsReadOnly] get { return ref _span[_index]; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal Enumerator([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan span) { _span = span; _index = -1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() { int num = _index + 1; if (num < _span.Length) { _index = num; return true; } return false; } } [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] private readonly Pinnable _pinnable; private readonly IntPtr _byteOffset; private readonly int _length; public int Length => _length; public bool IsEmpty => _length == 0; [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static ReadOnlySpan Empty { [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] get { return default(ReadOnlySpan); } } [IsReadOnly] public unsafe ref T this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: IsReadOnly] get { if ((uint)index >= (uint)_length) { System.ThrowHelper.ThrowIndexOutOfRangeException(); } if (_pinnable == null) { IntPtr byteOffset = _byteOffset; return ref Unsafe.Add(ref Unsafe.AsRef(byteOffset.ToPointer()), index); } return ref Unsafe.Add(ref Unsafe.AddByteOffset(ref _pinnable.Data, _byteOffset), index); } } [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] internal Pinnable Pinnable { [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] get { return _pinnable; } } internal IntPtr ByteOffset => _byteOffset; public static bool operator !=([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan left, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan right) { return !(left == right); } [NullableContext(2)] [Obsolete("Equals() on ReadOnlySpan will always throw an exception. Use == instead.")] [EditorBrowsable(EditorBrowsableState.Never)] public override bool Equals(object obj) { throw new NotSupportedException("Cannot call Equals on Span"); } [Obsolete("GetHashCode() on ReadOnlySpan will always throw an exception.")] [EditorBrowsable(EditorBrowsableState.Never)] public override int GetHashCode() { throw new NotSupportedException("Cannot call GetHashCodee on Span"); } [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static implicit operator ReadOnlySpan([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] T[] array) { return new ReadOnlySpan(array); } [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static implicit operator ReadOnlySpan([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ArraySegment segment) { return new ReadOnlySpan(segment.Array ?? throw new ArgumentNullException("segment"), segment.Offset, segment.Count); } [NullableContext(0)] public Enumerator GetEnumerator() { return new Enumerator(this); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public ReadOnlySpan([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] T[] array) { if (array == null) { this = default(ReadOnlySpan); return; } _length = array.Length; _pinnable = Unsafe.As>(array); _byteOffset = System.SpanHelpers.PerTypeValues.ArrayAdjustment; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public ReadOnlySpan([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] T[] array, int start, int length) { if (array == null) { if (start != 0 || length != 0) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } this = default(ReadOnlySpan); return; } if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start)) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } _length = length; _pinnable = Unsafe.As>(array); _byteOffset = System.SpanHelpers.PerTypeValues.ArrayAdjustment.Add(start); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] [NullableContext(0)] public unsafe ReadOnlySpan(void* pointer, int length) { if (System.SpanHelpers.IsReferenceOrContainsReferences()) { System.ThrowHelper.ThrowArgumentException_InvalidTypeWithPointersNotSupported(typeof(T)); } if (length < 0) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } _length = length; _pinnable = null; _byteOffset = new IntPtr(pointer); } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal ReadOnlySpan([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] Pinnable pinnable, IntPtr byteOffset, int length) { _length = length; _pinnable = pinnable; _byteOffset = byteOffset; } [EditorBrowsable(EditorBrowsableState.Never)] [return: IsReadOnly] public unsafe ref T GetPinnableReference() { if (_length != 0) { if (_pinnable == null) { IntPtr byteOffset = _byteOffset; return ref Unsafe.AsRef(byteOffset.ToPointer()); } return ref Unsafe.AddByteOffset(ref _pinnable.Data, _byteOffset); } return ref Unsafe.AsRef(null); } public void CopyTo([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] Span destination) { if (!TryCopyTo(destination)) { System.ThrowHelper.ThrowArgumentException_DestinationTooShort(); } } public bool TryCopyTo([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] Span destination) { int length = _length; int length2 = destination.Length; if (length == 0) { return true; } if ((uint)length > (uint)length2) { return false; } ref T src = ref DangerousGetPinnableReference(); System.SpanHelpers.CopyTo(ref destination.DangerousGetPinnableReference(), length2, ref src, length); return true; } public static bool operator ==([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan left, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan right) { if (left._length == right._length) { return Unsafe.AreSame(ref left.DangerousGetPinnableReference(), ref right.DangerousGetPinnableReference()); } return false; } public unsafe override string ToString() { if (typeof(T) == typeof(char)) { if (_byteOffset == MemoryExtensions.StringAdjustment && Unsafe.As(_pinnable) is string text && _length == text.Length) { return text; } fixed (char* value = &Unsafe.As(ref DangerousGetPinnableReference())) { return new string(value, 0, _length); } } return $"System.ReadOnlySpan<{typeof(T).Name}>[{_length}]"; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public ReadOnlySpan Slice(int start) { if ((uint)start > (uint)_length) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } IntPtr byteOffset = _byteOffset.Add(start); int length = _length - start; return new ReadOnlySpan(_pinnable, byteOffset, length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public ReadOnlySpan Slice(int start, int length) { if ((uint)start > (uint)_length || (uint)length > (uint)(_length - start)) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } IntPtr byteOffset = _byteOffset.Add(start); return new ReadOnlySpan(_pinnable, byteOffset, length); } public T[] ToArray() { if (_length == 0) { return System.SpanHelpers.PerTypeValues.EmptyArray; } T[] array = new T[_length]; CopyTo(array); return array; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [EditorBrowsable(EditorBrowsableState.Never)] internal unsafe ref T DangerousGetPinnableReference() { if (_pinnable == null) { IntPtr byteOffset = _byteOffset; return ref Unsafe.AsRef(byteOffset.ToPointer()); } return ref Unsafe.AddByteOffset(ref _pinnable.Data, _byteOffset); } } [NullableContext(1)] [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] [IsReadOnly] [DebuggerTypeProxy(typeof(System.SpanDebugView<>))] [DebuggerDisplay("{ToString(),raw}")] internal ref struct Span<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T> { [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] public ref struct Enumerator { [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] private readonly Span _span; private int _index; public ref T Current { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return ref _span[_index]; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal Enumerator([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] Span span) { _span = span; _index = -1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() { int num = _index + 1; if (num < _span.Length) { _index = num; return true; } return false; } } [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] private readonly Pinnable _pinnable; private readonly IntPtr _byteOffset; private readonly int _length; public int Length => _length; public bool IsEmpty => _length == 0; [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static Span Empty { [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] get { return default(Span); } } public unsafe ref T this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { if ((uint)index >= (uint)_length) { System.ThrowHelper.ThrowIndexOutOfRangeException(); } if (_pinnable == null) { IntPtr byteOffset = _byteOffset; return ref Unsafe.Add(ref Unsafe.AsRef(byteOffset.ToPointer()), index); } return ref Unsafe.Add(ref Unsafe.AddByteOffset(ref _pinnable.Data, _byteOffset), index); } } [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] internal Pinnable Pinnable { [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] get { return _pinnable; } } internal IntPtr ByteOffset => _byteOffset; public static bool operator !=([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] Span left, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] Span right) { return !(left == right); } [EditorBrowsable(EditorBrowsableState.Never)] [NullableContext(2)] [Obsolete("Equals() on Span will always throw an exception. Use == instead.")] public override bool Equals(object obj) { throw new NotSupportedException("Cannot call Equals on Span"); } [Obsolete("GetHashCode() on Span will always throw an exception.")] [EditorBrowsable(EditorBrowsableState.Never)] public override int GetHashCode() { throw new NotSupportedException("Cannot call GetHashCode on Span"); } [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static implicit operator Span([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] T[] array) { return new Span(array); } [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static implicit operator Span([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ArraySegment segment) { return new Span(segment.Array, segment.Offset, segment.Count); } [NullableContext(0)] public Enumerator GetEnumerator() { return new Enumerator(this); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Span([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] T[] array) { if (array == null) { this = default(Span); return; } if (default(T) == null && array.GetType() != typeof(T[])) { System.ThrowHelper.ThrowArrayTypeMismatchException(); } _length = array.Length; _pinnable = Unsafe.As>(array); _byteOffset = System.SpanHelpers.PerTypeValues.ArrayAdjustment; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] internal static Span Create([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] T[] array, int start) { if (array == null) { if (start != 0) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } return default(Span); } if (default(T) == null && array.GetType() != typeof(T[])) { System.ThrowHelper.ThrowArrayTypeMismatchException(); } if ((uint)start > (uint)array.Length) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } IntPtr byteOffset = System.SpanHelpers.PerTypeValues.ArrayAdjustment.Add(start); int length = array.Length - start; return new Span(Unsafe.As>(array), byteOffset, length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Span([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] T[] array, int start, int length) { if (array == null) { if (start != 0 || length != 0) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } this = default(Span); return; } if (default(T) == null && array.GetType() != typeof(T[])) { System.ThrowHelper.ThrowArrayTypeMismatchException(); } if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start)) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } _length = length; _pinnable = Unsafe.As>(array); _byteOffset = System.SpanHelpers.PerTypeValues.ArrayAdjustment.Add(start); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(0)] [CLSCompliant(false)] public unsafe Span(void* pointer, int length) { if (System.SpanHelpers.IsReferenceOrContainsReferences()) { System.ThrowHelper.ThrowArgumentException_InvalidTypeWithPointersNotSupported(typeof(T)); } if (length < 0) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } _length = length; _pinnable = null; _byteOffset = new IntPtr(pointer); } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal Span([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] Pinnable pinnable, IntPtr byteOffset, int length) { _length = length; _pinnable = pinnable; _byteOffset = byteOffset; } [EditorBrowsable(EditorBrowsableState.Never)] public unsafe ref T GetPinnableReference() { if (_length != 0) { if (_pinnable == null) { IntPtr byteOffset = _byteOffset; return ref Unsafe.AsRef(byteOffset.ToPointer()); } return ref Unsafe.AddByteOffset(ref _pinnable.Data, _byteOffset); } return ref Unsafe.AsRef(null); } public unsafe void Clear() { int length = _length; if (length == 0) { return; } UIntPtr byteLength = (UIntPtr)(ulong)((uint)length * Unsafe.SizeOf()); if ((Unsafe.SizeOf() & (sizeof(IntPtr) - 1)) != 0) { if (_pinnable == null) { IntPtr byteOffset = _byteOffset; byte* ptr = (byte*)byteOffset.ToPointer(); System.SpanHelpers.ClearLessThanPointerSized(ptr, byteLength); } else { System.SpanHelpers.ClearLessThanPointerSized(ref Unsafe.As(ref Unsafe.AddByteOffset(ref _pinnable.Data, _byteOffset)), byteLength); } } else if (System.SpanHelpers.IsReferenceOrContainsReferences()) { UIntPtr pointerSizeLength = (UIntPtr)(ulong)(length * Unsafe.SizeOf() / sizeof(IntPtr)); System.SpanHelpers.ClearPointerSizedWithReferences(ref Unsafe.As(ref DangerousGetPinnableReference()), pointerSizeLength); } else { System.SpanHelpers.ClearPointerSizedWithoutReferences(ref Unsafe.As(ref DangerousGetPinnableReference()), byteLength); } } public unsafe void Fill(T value) { int length = _length; if (length == 0) { return; } if (Unsafe.SizeOf() == 1) { byte value2 = Unsafe.As(ref value); if (_pinnable == null) { IntPtr byteOffset = _byteOffset; Unsafe.InitBlockUnaligned(byteOffset.ToPointer(), value2, (uint)length); } else { Unsafe.InitBlockUnaligned(ref Unsafe.As(ref Unsafe.AddByteOffset(ref _pinnable.Data, _byteOffset)), value2, (uint)length); } return; } ref T source = ref DangerousGetPinnableReference(); int i; for (i = 0; i < (length & -8); i += 8) { Unsafe.Add(ref source, i) = value; Unsafe.Add(ref source, i + 1) = value; Unsafe.Add(ref source, i + 2) = value; Unsafe.Add(ref source, i + 3) = value; Unsafe.Add(ref source, i + 4) = value; Unsafe.Add(ref source, i + 5) = value; Unsafe.Add(ref source, i + 6) = value; Unsafe.Add(ref source, i + 7) = value; } if (i < (length & -4)) { Unsafe.Add(ref source, i) = value; Unsafe.Add(ref source, i + 1) = value; Unsafe.Add(ref source, i + 2) = value; Unsafe.Add(ref source, i + 3) = value; i += 4; } for (; i < length; i++) { Unsafe.Add(ref source, i) = value; } } public void CopyTo([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] Span destination) { if (!TryCopyTo(destination)) { System.ThrowHelper.ThrowArgumentException_DestinationTooShort(); } } public bool TryCopyTo([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] Span destination) { int length = _length; int length2 = destination._length; if (length == 0) { return true; } if ((uint)length > (uint)length2) { return false; } ref T src = ref DangerousGetPinnableReference(); System.SpanHelpers.CopyTo(ref destination.DangerousGetPinnableReference(), length2, ref src, length); return true; } public static bool operator ==([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] Span left, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] Span right) { if (left._length == right._length) { return Unsafe.AreSame(ref left.DangerousGetPinnableReference(), ref right.DangerousGetPinnableReference()); } return false; } [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static implicit operator ReadOnlySpan([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] Span span) { return new ReadOnlySpan(span._pinnable, span._byteOffset, span._length); } public unsafe override string ToString() { if (typeof(T) == typeof(char)) { fixed (char* value = &Unsafe.As(ref DangerousGetPinnableReference())) { return new string(value, 0, _length); } } return $"System.Span<{typeof(T).Name}>[{_length}]"; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public Span Slice(int start) { if ((uint)start > (uint)_length) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } IntPtr byteOffset = _byteOffset.Add(start); int length = _length - start; return new Span(_pinnable, byteOffset, length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public Span Slice(int start, int length) { if ((uint)start > (uint)_length || (uint)length > (uint)(_length - start)) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } IntPtr byteOffset = _byteOffset.Add(start); return new Span(_pinnable, byteOffset, length); } public T[] ToArray() { if (_length == 0) { return System.SpanHelpers.PerTypeValues.EmptyArray; } T[] array = new T[_length]; CopyTo(array); return array; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [EditorBrowsable(EditorBrowsableState.Never)] internal unsafe ref T DangerousGetPinnableReference() { if (_pinnable == null) { IntPtr byteOffset = _byteOffset; return ref Unsafe.AsRef(byteOffset.ToPointer()); } return ref Unsafe.AddByteOffset(ref _pinnable.Data, _byteOffset); } } [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] [NullableContext(1)] internal sealed class SpanDebugView<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T> { private readonly T[] _array; [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)] public T[] Items => _array; public SpanDebugView([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] Span span) { _array = span.ToArray(); } public SpanDebugView([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan span) { _array = span.ToArray(); } } [NullableContext(1)] [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] internal static class SpanHelpers { [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] internal struct ComparerComparable<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] TComparer> : IComparable where TComparer : IComparer { private readonly T _value; private readonly TComparer _comparer; public ComparerComparable(T value, TComparer comparer) { _value = value; _comparer = comparer; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(2)] public int CompareTo(T other) { return _comparer.Compare(_value, other); } } [StructLayout(LayoutKind.Sequential, Size = 64)] [NullableContext(0)] private struct Reg64 { } [StructLayout(LayoutKind.Sequential, Size = 32)] [NullableContext(0)] private struct Reg32 { } [StructLayout(LayoutKind.Sequential, Size = 16)] [NullableContext(0)] private struct Reg16 { } [NullableContext(0)] public static class PerTypeValues<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T> { public static readonly bool IsReferenceOrContainsReferences = IsReferenceOrContainsReferencesCore(typeof(T)); [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(1)] public static readonly T[] EmptyArray = ArrayEx.Empty(); public static readonly IntPtr ArrayAdjustment = MeasureArrayAdjustment(); private static IntPtr MeasureArrayAdjustment() { T[] array = new T[1]; return Unsafe.ByteOffset(ref Unsafe.As>(array).Data, ref array[0]); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int BinarySearch<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] TComparable>([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] this ReadOnlySpan span, TComparable comparable) where TComparable : IComparable { if (comparable == null) { System.ThrowHelper.ThrowArgumentNullException(System.ExceptionArgument.comparable); } return BinarySearch(ref MemoryMarshal.GetReference(span), span.Length, comparable); } public static int BinarySearch<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] TComparable>(ref T spanStart, int length, TComparable comparable) where TComparable : IComparable { int num = 0; int num2 = length - 1; while (num <= num2) { int num3 = num2 + num >>> 1; ref TComparable reference = ref comparable; TComparable val = default(TComparable); if (val == null) { val = reference; reference = ref val; } int num4 = reference.CompareTo(Unsafe.Add(ref spanStart, num3)); if (num4 == 0) { return num3; } if (num4 > 0) { num = num3 + 1; } else { num2 = num3 - 1; } } return ~num; } public static int IndexOf(ref byte searchSpace, int searchSpaceLength, ref byte value, int valueLength) { if (valueLength == 0) { return 0; } byte value2 = value; ref byte second = ref Unsafe.Add(ref value, 1); int num = valueLength - 1; int num2 = 0; while (true) { int num3 = searchSpaceLength - num2 - num; if (num3 <= 0) { break; } int num4 = IndexOf(ref Unsafe.Add(ref searchSpace, num2), value2, num3); if (num4 == -1) { break; } num2 += num4; if (SequenceEqual(ref Unsafe.Add(ref searchSpace, num2 + 1), ref second, num)) { return num2; } num2++; } return -1; } public static int IndexOfAny(ref byte searchSpace, int searchSpaceLength, ref byte value, int valueLength) { if (valueLength == 0) { return 0; } int num = -1; for (int i = 0; i < valueLength; i++) { int num2 = IndexOf(ref searchSpace, Unsafe.Add(ref value, i), searchSpaceLength); if ((uint)num2 < (uint)num) { num = num2; searchSpaceLength = num2; if (num == 0) { break; } } } return num; } public static int LastIndexOfAny(ref byte searchSpace, int searchSpaceLength, ref byte value, int valueLength) { if (valueLength == 0) { return 0; } int num = -1; for (int i = 0; i < valueLength; i++) { int num2 = LastIndexOf(ref searchSpace, Unsafe.Add(ref value, i), searchSpaceLength); if (num2 > num) { num = num2; } } return num; } public static int IndexOf(ref byte searchSpace, byte value, int length) { nint num = 0; nint num2 = length; while (true) { if ((nuint)num2 >= (nuint)8u) { num2 -= 8; if (value != Unsafe.AddByteOffset(ref searchSpace, num)) { if (value == Unsafe.AddByteOffset(ref searchSpace, num + 1)) { goto IL_0109; } if (value == Unsafe.AddByteOffset(ref searchSpace, num + 2)) { goto IL_010f; } if (value != Unsafe.AddByteOffset(ref searchSpace, num + 3)) { if (value != Unsafe.AddByteOffset(ref searchSpace, num + 4)) { if (value != Unsafe.AddByteOffset(ref searchSpace, num + 5)) { if (value != Unsafe.AddByteOffset(ref searchSpace, num + 6)) { if (value == Unsafe.AddByteOffset(ref searchSpace, num + 7)) { break; } num += 8; continue; } return (int)(num + 6); } return (int)(num + 5); } return (int)(num + 4); } goto IL_0115; } } else { if ((nuint)num2 >= (nuint)4u) { num2 -= 4; if (value == Unsafe.AddByteOffset(ref searchSpace, num)) { goto IL_0106; } if (value == Unsafe.AddByteOffset(ref searchSpace, num + 1)) { goto IL_0109; } if (value == Unsafe.AddByteOffset(ref searchSpace, num + 2)) { goto IL_010f; } if (value == Unsafe.AddByteOffset(ref searchSpace, num + 3)) { goto IL_0115; } num += 4; } while (true) { if (num2 != 0) { num2--; if (value == Unsafe.AddByteOffset(ref searchSpace, num)) { break; } num++; continue; } return -1; } } goto IL_0106; IL_010f: return (int)(num + 2); IL_0106: return (int)num; IL_0109: return (int)(num + 1); IL_0115: return (int)(num + 3); } return (int)(num + 7); } public static int LastIndexOf(ref byte searchSpace, int searchSpaceLength, ref byte value, int valueLength) { if (valueLength == 0) { return 0; } byte value2 = value; ref byte second = ref Unsafe.Add(ref value, 1); int num = valueLength - 1; int num2 = 0; while (true) { int num3 = searchSpaceLength - num2 - num; if (num3 <= 0) { break; } int num4 = LastIndexOf(ref searchSpace, value2, num3); if (num4 == -1) { break; } if (SequenceEqual(ref Unsafe.Add(ref searchSpace, num4 + 1), ref second, num)) { return num4; } num2 += num3 - num4; } return -1; } public static int LastIndexOf(ref byte searchSpace, byte value, int length) { nint num = length; nint num2 = length; while (true) { if ((nuint)num2 >= (nuint)8u) { num2 -= 8; num -= 8; if (value == Unsafe.AddByteOffset(ref searchSpace, num + 7)) { break; } if (value == Unsafe.AddByteOffset(ref searchSpace, num + 6)) { return (int)(num + 6); } if (value == Unsafe.AddByteOffset(ref searchSpace, num + 5)) { return (int)(num + 5); } if (value == Unsafe.AddByteOffset(ref searchSpace, num + 4)) { return (int)(num + 4); } if (value == Unsafe.AddByteOffset(ref searchSpace, num + 3)) { goto IL_010f; } if (value == Unsafe.AddByteOffset(ref searchSpace, num + 2)) { goto IL_0109; } if (value == Unsafe.AddByteOffset(ref searchSpace, num + 1)) { goto IL_0103; } if (value != Unsafe.AddByteOffset(ref searchSpace, num)) { continue; } } else { if ((nuint)num2 >= (nuint)4u) { num2 -= 4; num -= 4; if (value == Unsafe.AddByteOffset(ref searchSpace, num + 3)) { goto IL_010f; } if (value == Unsafe.AddByteOffset(ref searchSpace, num + 2)) { goto IL_0109; } if (value == Unsafe.AddByteOffset(ref searchSpace, num + 1)) { goto IL_0103; } if (value == Unsafe.AddByteOffset(ref searchSpace, num)) { goto IL_0100; } } do { if (num2 != 0) { num2--; num--; continue; } return -1; } while (value != Unsafe.AddByteOffset(ref searchSpace, num)); } goto IL_0100; IL_0109: return (int)(num + 2); IL_010f: return (int)(num + 3); IL_0103: return (int)(num + 1); IL_0100: return (int)num; } return (int)(num + 7); } public static int IndexOfAny(ref byte searchSpace, byte value0, byte value1, int length) { nint num = 0; nint num2 = length; while (true) { if ((nuint)num2 >= (nuint)8u) { num2 -= 8; uint num3 = Unsafe.AddByteOffset(ref searchSpace, num); if (value0 != num3 && value1 != num3) { num3 = Unsafe.AddByteOffset(ref searchSpace, num + 1); if (value0 == num3 || value1 == num3) { goto IL_019b; } num3 = Unsafe.AddByteOffset(ref searchSpace, num + 2); if (value0 == num3 || value1 == num3) { goto IL_01a1; } num3 = Unsafe.AddByteOffset(ref searchSpace, num + 3); if (value0 != num3 && value1 != num3) { num3 = Unsafe.AddByteOffset(ref searchSpace, num + 4); if (value0 != num3 && value1 != num3) { num3 = Unsafe.AddByteOffset(ref searchSpace, num + 5); if (value0 != num3 && value1 != num3) { num3 = Unsafe.AddByteOffset(ref searchSpace, num + 6); if (value0 != num3 && value1 != num3) { num3 = Unsafe.AddByteOffset(ref searchSpace, num + 7); if (value0 == num3 || value1 == num3) { break; } num += 8; continue; } return (int)(num + 6); } return (int)(num + 5); } return (int)(num + 4); } goto IL_01a7; } } else { if ((nuint)num2 >= (nuint)4u) { num2 -= 4; uint num3 = Unsafe.AddByteOffset(ref searchSpace, num); if (value0 == num3 || value1 == num3) { goto IL_0198; } num3 = Unsafe.AddByteOffset(ref searchSpace, num + 1); if (value0 == num3 || value1 == num3) { goto IL_019b; } num3 = Unsafe.AddByteOffset(ref searchSpace, num + 2); if (value0 == num3 || value1 == num3) { goto IL_01a1; } num3 = Unsafe.AddByteOffset(ref searchSpace, num + 3); if (value0 == num3 || value1 == num3) { goto IL_01a7; } num += 4; } while (true) { if (num2 != 0) { num2--; uint num3 = Unsafe.AddByteOffset(ref searchSpace, num); if (value0 == num3 || value1 == num3) { break; } num++; continue; } return -1; } } goto IL_0198; IL_01a1: return (int)(num + 2); IL_019b: return (int)(num + 1); IL_01a7: return (int)(num + 3); IL_0198: return (int)num; } return (int)(num + 7); } public static int IndexOfAny(ref byte searchSpace, byte value0, byte value1, byte value2, int length) { nint num = 0; nint num2 = length; while (true) { if ((nuint)num2 >= (nuint)8u) { num2 -= 8; uint num3 = Unsafe.AddByteOffset(ref searchSpace, num); if (value0 != num3 && value1 != num3 && value2 != num3) { num3 = Unsafe.AddByteOffset(ref searchSpace, num + 1); if (value0 == num3 || value1 == num3 || value2 == num3) { goto IL_020a; } num3 = Unsafe.AddByteOffset(ref searchSpace, num + 2); if (value0 == num3 || value1 == num3 || value2 == num3) { goto IL_0210; } num3 = Unsafe.AddByteOffset(ref searchSpace, num + 3); if (value0 != num3 && value1 != num3 && value2 != num3) { num3 = Unsafe.AddByteOffset(ref searchSpace, num + 4); if (value0 != num3 && value1 != num3 && value2 != num3) { num3 = Unsafe.AddByteOffset(ref searchSpace, num + 5); if (value0 != num3 && value1 != num3 && value2 != num3) { num3 = Unsafe.AddByteOffset(ref searchSpace, num + 6); if (value0 != num3 && value1 != num3 && value2 != num3) { num3 = Unsafe.AddByteOffset(ref searchSpace, num + 7); if (value0 == num3 || value1 == num3 || value2 == num3) { break; } num += 8; continue; } return (int)(num + 6); } return (int)(num + 5); } return (int)(num + 4); } goto IL_0216; } } else { if ((nuint)num2 >= (nuint)4u) { num2 -= 4; uint num3 = Unsafe.AddByteOffset(ref searchSpace, num); if (value0 == num3 || value1 == num3 || value2 == num3) { goto IL_0207; } num3 = Unsafe.AddByteOffset(ref searchSpace, num + 1); if (value0 == num3 || value1 == num3 || value2 == num3) { goto IL_020a; } num3 = Unsafe.AddByteOffset(ref searchSpace, num + 2); if (value0 == num3 || value1 == num3 || value2 == num3) { goto IL_0210; } num3 = Unsafe.AddByteOffset(ref searchSpace, num + 3); if (value0 == num3 || value1 == num3 || value2 == num3) { goto IL_0216; } num += 4; } while (true) { if (num2 != 0) { num2--; uint num3 = Unsafe.AddByteOffset(ref searchSpace, num); if (value0 == num3 || value1 == num3 || value2 == num3) { break; } num++; continue; } return -1; } } goto IL_0207; IL_0207: return (int)num; IL_0210: return (int)(num + 2); IL_020a: return (int)(num + 1); IL_0216: return (int)(num + 3); } return (int)(num + 7); } public static int LastIndexOfAny(ref byte searchSpace, byte value0, byte value1, int length) { nint num = length; nint num2 = length; while (true) { if ((nuint)num2 >= (nuint)8u) { num2 -= 8; num -= 8; uint num3 = Unsafe.AddByteOffset(ref searchSpace, num + 7); if (value0 == num3 || value1 == num3) { break; } num3 = Unsafe.AddByteOffset(ref searchSpace, num + 6); if (value0 == num3 || value1 == num3) { return (int)(num + 6); } num3 = Unsafe.AddByteOffset(ref searchSpace, num + 5); if (value0 == num3 || value1 == num3) { return (int)(num + 5); } num3 = Unsafe.AddByteOffset(ref searchSpace, num + 4); if (value0 == num3 || value1 == num3) { return (int)(num + 4); } num3 = Unsafe.AddByteOffset(ref searchSpace, num + 3); if (value0 == num3 || value1 == num3) { goto IL_01a7; } num3 = Unsafe.AddByteOffset(ref searchSpace, num + 2); if (value0 == num3 || value1 == num3) { goto IL_01a1; } num3 = Unsafe.AddByteOffset(ref searchSpace, num + 1); if (value0 == num3 || value1 == num3) { goto IL_019b; } num3 = Unsafe.AddByteOffset(ref searchSpace, num); if (value0 != num3 && value1 != num3) { continue; } } else { uint num3; if ((nuint)num2 >= (nuint)4u) { num2 -= 4; num -= 4; num3 = Unsafe.AddByteOffset(ref searchSpace, num + 3); if (value0 == num3 || value1 == num3) { goto IL_01a7; } num3 = Unsafe.AddByteOffset(ref searchSpace, num + 2); if (value0 == num3 || value1 == num3) { goto IL_01a1; } num3 = Unsafe.AddByteOffset(ref searchSpace, num + 1); if (value0 == num3 || value1 == num3) { goto IL_019b; } num3 = Unsafe.AddByteOffset(ref searchSpace, num); if (value0 == num3 || value1 == num3) { goto IL_0198; } } do { if (num2 != 0) { num2--; num--; num3 = Unsafe.AddByteOffset(ref searchSpace, num); continue; } return -1; } while (value0 != num3 && value1 != num3); } goto IL_0198; IL_01a1: return (int)(num + 2); IL_019b: return (int)(num + 1); IL_0198: return (int)num; IL_01a7: return (int)(num + 3); } return (int)(num + 7); } public static int LastIndexOfAny(ref byte searchSpace, byte value0, byte value1, byte value2, int length) { nint num = length; nint num2 = length; while (true) { if ((nuint)num2 >= (nuint)8u) { num2 -= 8; num -= 8; uint num3 = Unsafe.AddByteOffset(ref searchSpace, num + 7); if (value0 == num3 || value1 == num3 || value2 == num3) { break; } num3 = Unsafe.AddByteOffset(ref searchSpace, num + 6); if (value0 == num3 || value1 == num3 || value2 == num3) { return (int)(num + 6); } num3 = Unsafe.AddByteOffset(ref searchSpace, num + 5); if (value0 == num3 || value1 == num3 || value2 == num3) { return (int)(num + 5); } num3 = Unsafe.AddByteOffset(ref searchSpace, num + 4); if (value0 == num3 || value1 == num3 || value2 == num3) { return (int)(num + 4); } num3 = Unsafe.AddByteOffset(ref searchSpace, num + 3); if (value0 == num3 || value1 == num3 || value2 == num3) { goto IL_0217; } num3 = Unsafe.AddByteOffset(ref searchSpace, num + 2); if (value0 == num3 || value1 == num3 || value2 == num3) { goto IL_0211; } num3 = Unsafe.AddByteOffset(ref searchSpace, num + 1); if (value0 == num3 || value1 == num3 || value2 == num3) { goto IL_020b; } num3 = Unsafe.AddByteOffset(ref searchSpace, num); if (value0 != num3 && value1 != num3 && value2 != num3) { continue; } } else { uint num3; if ((nuint)num2 >= (nuint)4u) { num2 -= 4; num -= 4; num3 = Unsafe.AddByteOffset(ref searchSpace, num + 3); if (value0 == num3 || value1 == num3 || value2 == num3) { goto IL_0217; } num3 = Unsafe.AddByteOffset(ref searchSpace, num + 2); if (value0 == num3 || value1 == num3 || value2 == num3) { goto IL_0211; } num3 = Unsafe.AddByteOffset(ref searchSpace, num + 1); if (value0 == num3 || value1 == num3 || value2 == num3) { goto IL_020b; } num3 = Unsafe.AddByteOffset(ref searchSpace, num); if (value0 == num3 || value1 == num3 || value2 == num3) { goto IL_0208; } } do { if (num2 != 0) { num2--; num--; num3 = Unsafe.AddByteOffset(ref searchSpace, num); continue; } return -1; } while (value0 != num3 && value1 != num3 && value2 != num3); } goto IL_0208; IL_020b: return (int)(num + 1); IL_0211: return (int)(num + 2); IL_0217: return (int)(num + 3); IL_0208: return (int)num; } return (int)(num + 7); } public unsafe static bool SequenceEqual(ref byte first, ref byte second, [<9248bc27-e977-4246-b6f6-bd8f7836272f>NativeInteger] UIntPtr length) { if (!Unsafe.AreSame(ref first, ref second)) { nint num = 0; nint num2 = (nint)(nuint)length; if ((nuint)num2 >= (nuint)sizeof(UIntPtr)) { num2 -= sizeof(UIntPtr); while (true) { if ((nuint)num2 > (nuint)num) { if (Unsafe.ReadUnaligned(ref Unsafe.AddByteOffset(ref first, num)) != Unsafe.ReadUnaligned(ref Unsafe.AddByteOffset(ref second, num))) { break; } num += sizeof(UIntPtr); continue; } return Unsafe.ReadUnaligned(ref Unsafe.AddByteOffset(ref first, num2)) == Unsafe.ReadUnaligned(ref Unsafe.AddByteOffset(ref second, num2)); } goto IL_008f; } while ((nuint)num2 > (nuint)num) { if (Unsafe.AddByteOffset(ref first, num) == Unsafe.AddByteOffset(ref second, num)) { num++; continue; } goto IL_008f; } } return true; IL_008f: return false; } public unsafe static int SequenceCompareTo(ref byte first, int firstLength, ref byte second, int secondLength) { if (!Unsafe.AreSame(ref first, ref second)) { nint num = ((firstLength < secondLength) ? firstLength : secondLength); nint num2 = 0; nint num3 = num; if ((nuint)num3 > (nuint)sizeof(UIntPtr)) { for (num3 -= sizeof(UIntPtr); (nuint)num3 > (nuint)num2 && !(Unsafe.ReadUnaligned(ref Unsafe.AddByteOffset(ref first, num2)) != Unsafe.ReadUnaligned(ref Unsafe.AddByteOffset(ref second, num2))); num2 += sizeof(UIntPtr)) { } } for (; (nuint)num > (nuint)num2; num2++) { int num4 = Unsafe.AddByteOffset(ref first, num2).CompareTo(Unsafe.AddByteOffset(ref second, num2)); if (num4 != 0) { return num4; } } } return firstLength - secondLength; } public unsafe static int SequenceCompareTo(ref char first, int firstLength, ref char second, int secondLength) { int result = firstLength - secondLength; if (!Unsafe.AreSame(ref first, ref second)) { nint num = ((firstLength < secondLength) ? firstLength : secondLength); nint num2 = 0; if ((nuint)num >= (nuint)(sizeof(UIntPtr) / 2)) { for (; (nuint)num >= (nuint)(num2 + sizeof(UIntPtr) / 2) && !(Unsafe.ReadUnaligned(ref Unsafe.As(ref Unsafe.Add(ref first, num2))) != Unsafe.ReadUnaligned(ref Unsafe.As(ref Unsafe.Add(ref second, num2)))); num2 += sizeof(UIntPtr) / 2) { } } if (sizeof(UIntPtr) > 4 && (nuint)num >= (nuint)(num2 + 2) && Unsafe.ReadUnaligned(ref Unsafe.As(ref Unsafe.Add(ref first, num2))) == Unsafe.ReadUnaligned(ref Unsafe.As(ref Unsafe.Add(ref second, num2)))) { num2 += 2; } for (; (nuint)num2 < (nuint)num; num2++) { int num3 = Unsafe.Add(ref first, num2).CompareTo(Unsafe.Add(ref second, num2)); if (num3 != 0) { return num3; } } } return result; } public unsafe static int IndexOf(ref char searchSpace, char value, int length) { fixed (char* ptr = &searchSpace) { char* ptr2 = ptr; _ = length; while (true) { if (length >= 4) { length -= 4; if (*ptr2 == value) { break; } if (ptr2[1] != value) { if (ptr2[2] != value) { if (ptr2[3] != value) { ptr2 += 4; continue; } ptr2++; } ptr2++; } ptr2++; break; } while (true) { if (length > 0) { length--; if (*ptr2 == value) { break; } ptr2++; continue; } return -1; } break; } return (int)(ptr2 - ptr); } } public unsafe static int LastIndexOf(ref char searchSpace, char value, int length) { fixed (char* ptr = &searchSpace) { char* ptr2 = ptr + length; char* ptr3 = ptr; while (true) { if (length >= 4) { length -= 4; ptr2 -= 4; if (ptr2[3] == value) { break; } if (ptr2[2] == value) { return (int)(ptr2 - ptr3) + 2; } if (ptr2[1] == value) { return (int)(ptr2 - ptr3) + 1; } if (*ptr2 != value) { continue; } } else { do { if (length > 0) { length--; ptr2--; continue; } return -1; } while (*ptr2 != value); } return (int)(ptr2 - ptr3); } return (int)(ptr2 - ptr3) + 3; } } public unsafe static void CopyTo<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T>(ref T dst, int dstLength, ref T src, int srcLength) { IntPtr intPtr = Unsafe.ByteOffset(ref src, ref Unsafe.Add(ref src, srcLength)); IntPtr intPtr2 = Unsafe.ByteOffset(ref dst, ref Unsafe.Add(ref dst, dstLength)); IntPtr intPtr3 = Unsafe.ByteOffset(ref src, ref dst); bool num; if (sizeof(IntPtr) != 4) { if ((ulong)(long)intPtr3 >= (ulong)(long)intPtr) { num = (ulong)(long)intPtr3 > (ulong)(-(long)intPtr2); goto IL_006f; } } else if ((uint)(int)intPtr3 >= (uint)(int)intPtr) { num = (uint)(int)intPtr3 > (uint)(-(int)intPtr2); goto IL_006f; } goto IL_00da; IL_00da: bool num2 = ((sizeof(IntPtr) == 4) ? ((uint)(int)intPtr3 > (uint)(-(int)intPtr2)) : ((ulong)(long)intPtr3 > (ulong)(-(long)intPtr2))); int num3 = (num2 ? 1 : (-1)); int num4 = ((!num2) ? (srcLength - 1) : 0); int i; for (i = 0; i < (srcLength & -8); i += 8) { Unsafe.Add(ref dst, num4) = Unsafe.Add(ref src, num4); Unsafe.Add(ref dst, num4 + num3) = Unsafe.Add(ref src, num4 + num3); Unsafe.Add(ref dst, num4 + num3 * 2) = Unsafe.Add(ref src, num4 + num3 * 2); Unsafe.Add(ref dst, num4 + num3 * 3) = Unsafe.Add(ref src, num4 + num3 * 3); Unsafe.Add(ref dst, num4 + num3 * 4) = Unsafe.Add(ref src, num4 + num3 * 4); Unsafe.Add(ref dst, num4 + num3 * 5) = Unsafe.Add(ref src, num4 + num3 * 5); Unsafe.Add(ref dst, num4 + num3 * 6) = Unsafe.Add(ref src, num4 + num3 * 6); Unsafe.Add(ref dst, num4 + num3 * 7) = Unsafe.Add(ref src, num4 + num3 * 7); num4 += num3 * 8; } if (i < (srcLength & -4)) { Unsafe.Add(ref dst, num4) = Unsafe.Add(ref src, num4); Unsafe.Add(ref dst, num4 + num3) = Unsafe.Add(ref src, num4 + num3); Unsafe.Add(ref dst, num4 + num3 * 2) = Unsafe.Add(ref src, num4 + num3 * 2); Unsafe.Add(ref dst, num4 + num3 * 3) = Unsafe.Add(ref src, num4 + num3 * 3); num4 += num3 * 4; i += 4; } for (; i < srcLength; i++) { Unsafe.Add(ref dst, num4) = Unsafe.Add(ref src, num4); num4 += num3; } return; IL_006f: if (!num && !IsReferenceOrContainsReferences()) { ref byte source = ref Unsafe.As(ref dst); ref byte source2 = ref Unsafe.As(ref src); ulong num5 = (ulong)(long)intPtr; uint num7; for (ulong num6 = 0uL; num6 < num5; num6 += num7) { num7 = (uint)((num5 - num6 > uint.MaxValue) ? uint.MaxValue : (num5 - num6)); Unsafe.CopyBlock(ref Unsafe.Add(ref source, (IntPtr)(long)num6), ref Unsafe.Add(ref source2, (IntPtr)(long)num6), num7); } return; } goto IL_00da; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(2)] public unsafe static IntPtr Add(this IntPtr start, int index) { if (sizeof(IntPtr) == 4) { uint num = (uint)(index * Unsafe.SizeOf()); return (IntPtr)((byte*)(void*)start + num); } ulong num2 = (ulong)index * (ulong)Unsafe.SizeOf(); return (IntPtr)((byte*)(void*)start + num2); } [NullableContext(2)] public static bool IsReferenceOrContainsReferences() { return PerTypeValues.IsReferenceOrContainsReferences; } private static bool IsReferenceOrContainsReferencesCore(Type type) { if (type.GetTypeInfo().IsPrimitive) { return false; } if (!type.GetTypeInfo().IsValueType) { return true; } Type underlyingType = Nullable.GetUnderlyingType(type); if (underlyingType != null) { type = underlyingType; } if (type.GetTypeInfo().IsEnum) { return false; } foreach (FieldInfo declaredField in type.GetTypeInfo().DeclaredFields) { if (!declaredField.IsStatic && IsReferenceOrContainsReferencesCore(declaredField.FieldType)) { return true; } } return false; } [NullableContext(0)] public unsafe static void ClearLessThanPointerSized(byte* ptr, UIntPtr byteLength) { if (sizeof(UIntPtr) == 4) { Unsafe.InitBlockUnaligned(ptr, 0, (uint)byteLength); return; } ulong num = (ulong)byteLength; uint num2 = (uint)(num & 0xFFFFFFFFu); Unsafe.InitBlockUnaligned(ptr, 0, num2); num -= num2; ptr += num2; while (num != 0) { num2 = (uint)((num >= uint.MaxValue) ? uint.MaxValue : num); Unsafe.InitBlockUnaligned(ptr, 0, num2); ptr += num2; num -= num2; } } public unsafe static void ClearLessThanPointerSized(ref byte b, UIntPtr byteLength) { if (sizeof(UIntPtr) == 4) { Unsafe.InitBlockUnaligned(ref b, 0, (uint)byteLength); return; } ulong num = (ulong)byteLength; uint num2 = (uint)(num & 0xFFFFFFFFu); Unsafe.InitBlockUnaligned(ref b, 0, num2); num -= num2; long num3 = num2; while (num != 0) { num2 = (uint)((num >= uint.MaxValue) ? uint.MaxValue : num); Unsafe.InitBlockUnaligned(ref Unsafe.Add(ref b, (IntPtr)num3), 0, num2); num3 += num2; num -= num2; } } public unsafe static void ClearPointerSizedWithoutReferences(ref byte b, [<9248bc27-e977-4246-b6f6-bd8f7836272f>NativeInteger] UIntPtr byteLength) { nint num; for (num = 0; num.LessThanEqual((nuint)((nint)(nuint)byteLength - sizeof(Reg64))); num += sizeof(Reg64)) { Unsafe.As(ref Unsafe.Add(ref b, num)) = default(Reg64); } if (num.LessThanEqual((nuint)((nint)(nuint)byteLength - sizeof(Reg32)))) { Unsafe.As(ref Unsafe.Add(ref b, num)) = default(Reg32); num += sizeof(Reg32); } if (num.LessThanEqual((nuint)((nint)(nuint)byteLength - sizeof(Reg16)))) { Unsafe.As(ref Unsafe.Add(ref b, num)) = default(Reg16); num += sizeof(Reg16); } if (num.LessThanEqual((nuint)((nint)(nuint)byteLength - 8))) { Unsafe.As(ref Unsafe.Add(ref b, num)) = 0L; num += 8; } if (sizeof(IntPtr) == 4 && num.LessThanEqual((nuint)((nint)(nuint)byteLength - 4))) { Unsafe.As(ref Unsafe.Add(ref b, num)) = 0; } } public static void ClearPointerSizedWithReferences(ref IntPtr ip, [<9248bc27-e977-4246-b6f6-bd8f7836272f>NativeInteger] UIntPtr pointerSizeLength) { nint num = 0; nint num2; while ((num2 = num + 8).LessThanEqual(pointerSizeLength)) { Unsafe.Add(ref ip, num + 0) = default(IntPtr); Unsafe.Add(ref ip, num + 1) = default(IntPtr); Unsafe.Add(ref ip, num + 2) = default(IntPtr); Unsafe.Add(ref ip, num + 3) = default(IntPtr); Unsafe.Add(ref ip, num + 4) = default(IntPtr); Unsafe.Add(ref ip, num + 5) = default(IntPtr); Unsafe.Add(ref ip, num + 6) = default(IntPtr); Unsafe.Add(ref ip, num + 7) = default(IntPtr); num = num2; } if ((num2 = num + 4).LessThanEqual(pointerSizeLength)) { Unsafe.Add(ref ip, num + 0) = default(IntPtr); Unsafe.Add(ref ip, num + 1) = default(IntPtr); Unsafe.Add(ref ip, num + 2) = default(IntPtr); Unsafe.Add(ref ip, num + 3) = default(IntPtr); num = num2; } if ((num2 = num + 2).LessThanEqual(pointerSizeLength)) { Unsafe.Add(ref ip, num + 0) = default(IntPtr); Unsafe.Add(ref ip, num + 1) = default(IntPtr); num = num2; } if ((num + 1).LessThanEqual(pointerSizeLength)) { Unsafe.Add(ref ip, num) = default(IntPtr); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] private unsafe static bool LessThanEqual(this IntPtr index, UIntPtr length) { if (sizeof(UIntPtr) != 4) { return (long)index <= (long)(ulong)length; } return (int)index <= (int)(uint)length; } public static int IndexOf<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] T>(ref T searchSpace, int searchSpaceLength, ref T value, int valueLength) where T : IEquatable { if (valueLength == 0) { return 0; } T value2 = value; ref T second = ref Unsafe.Add(ref value, 1); int num = valueLength - 1; int num2 = 0; while (true) { int num3 = searchSpaceLength - num2 - num; if (num3 <= 0) { break; } int num4 = IndexOf(ref Unsafe.Add(ref searchSpace, num2), value2, num3); if (num4 == -1) { break; } num2 += num4; if (SequenceEqual(ref Unsafe.Add(ref searchSpace, num2 + 1), ref second, num)) { return num2; } num2++; } return -1; } public static int IndexOf<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] T>(ref T searchSpace, T value, int length) where T : IEquatable { nuint num = 0u; while (true) { T val; if (length >= 8) { length -= 8; ref T reference = ref value; val = default(T); if (val == null) { val = reference; reference = ref val; } if (!reference.Equals(Unsafe.Add(ref searchSpace, num))) { ref T reference2 = ref value; val = default(T); if (val == null) { val = reference2; reference2 = ref val; } if (reference2.Equals(Unsafe.Add(ref searchSpace, num + 1))) { goto IL_0315; } ref T reference3 = ref value; val = default(T); if (val == null) { val = reference3; reference3 = ref val; } if (reference3.Equals(Unsafe.Add(ref searchSpace, num + 2))) { goto IL_031b; } ref T reference4 = ref value; val = default(T); if (val == null) { val = reference4; reference4 = ref val; } if (!reference4.Equals(Unsafe.Add(ref searchSpace, num + 3))) { ref T reference5 = ref value; val = default(T); if (val == null) { val = reference5; reference5 = ref val; } if (!reference5.Equals(Unsafe.Add(ref searchSpace, num + 4))) { ref T reference6 = ref value; val = default(T); if (val == null) { val = reference6; reference6 = ref val; } if (!reference6.Equals(Unsafe.Add(ref searchSpace, num + 5))) { ref T reference7 = ref value; val = default(T); if (val == null) { val = reference7; reference7 = ref val; } if (!reference7.Equals(Unsafe.Add(ref searchSpace, num + 6))) { ref T reference8 = ref value; val = default(T); if (val == null) { val = reference8; reference8 = ref val; } if (reference8.Equals(Unsafe.Add(ref searchSpace, num + 7))) { break; } num += 8; continue; } return (int)(num + 6); } return (int)(num + 5); } return (int)(num + 4); } goto IL_0321; } } else { if (length >= 4) { length -= 4; ref T reference9 = ref value; val = default(T); if (val == null) { val = reference9; reference9 = ref val; } if (reference9.Equals(Unsafe.Add(ref searchSpace, num))) { goto IL_0312; } ref T reference10 = ref value; val = default(T); if (val == null) { val = reference10; reference10 = ref val; } if (reference10.Equals(Unsafe.Add(ref searchSpace, num + 1))) { goto IL_0315; } ref T reference11 = ref value; val = default(T); if (val == null) { val = reference11; reference11 = ref val; } if (reference11.Equals(Unsafe.Add(ref searchSpace, num + 2))) { goto IL_031b; } ref T reference12 = ref value; val = default(T); if (val == null) { val = reference12; reference12 = ref val; } if (reference12.Equals(Unsafe.Add(ref searchSpace, num + 3))) { goto IL_0321; } num += 4; } while (true) { if (length > 0) { ref T reference13 = ref value; val = default(T); if (val == null) { val = reference13; reference13 = ref val; } if (reference13.Equals(Unsafe.Add(ref searchSpace, num))) { break; } num++; length--; continue; } return -1; } } goto IL_0312; IL_0312: return (int)num; IL_031b: return (int)(num + 2); IL_0315: return (int)(num + 1); IL_0321: return (int)(num + 3); } return (int)(num + 7); } public static int IndexOfAny<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] T>(ref T searchSpace, T value0, T value1, int length) where T : IEquatable { int num = 0; while (true) { if (length - num >= 8) { T other = Unsafe.Add(ref searchSpace, num); if (!value0.Equals(other) && !value1.Equals(other)) { other = Unsafe.Add(ref searchSpace, num + 1); if (value0.Equals(other) || value1.Equals(other)) { goto IL_02cb; } other = Unsafe.Add(ref searchSpace, num + 2); if (value0.Equals(other) || value1.Equals(other)) { goto IL_02cf; } other = Unsafe.Add(ref searchSpace, num + 3); if (!value0.Equals(other) && !value1.Equals(other)) { other = Unsafe.Add(ref searchSpace, num + 4); if (!value0.Equals(other) && !value1.Equals(other)) { other = Unsafe.Add(ref searchSpace, num + 5); if (!value0.Equals(other) && !value1.Equals(other)) { other = Unsafe.Add(ref searchSpace, num + 6); if (!value0.Equals(other) && !value1.Equals(other)) { other = Unsafe.Add(ref searchSpace, num + 7); if (value0.Equals(other) || value1.Equals(other)) { break; } num += 8; continue; } return num + 6; } return num + 5; } return num + 4; } goto IL_02d3; } } else { if (length - num >= 4) { T other = Unsafe.Add(ref searchSpace, num); if (value0.Equals(other) || value1.Equals(other)) { goto IL_02c9; } other = Unsafe.Add(ref searchSpace, num + 1); if (value0.Equals(other) || value1.Equals(other)) { goto IL_02cb; } other = Unsafe.Add(ref searchSpace, num + 2); if (value0.Equals(other) || value1.Equals(other)) { goto IL_02cf; } other = Unsafe.Add(ref searchSpace, num + 3); if (value0.Equals(other) || value1.Equals(other)) { goto IL_02d3; } num += 4; } while (true) { if (num < length) { T other = Unsafe.Add(ref searchSpace, num); if (value0.Equals(other) || value1.Equals(other)) { break; } num++; continue; } return -1; } } goto IL_02c9; IL_02cf: return num + 2; IL_02cb: return num + 1; IL_02d3: return num + 3; IL_02c9: return num; } return num + 7; } public static int IndexOfAny<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] T>(ref T searchSpace, T value0, T value1, T value2, int length) where T : IEquatable { int num = 0; while (true) { if (length - num >= 8) { T other = Unsafe.Add(ref searchSpace, num); if (!value0.Equals(other) && !value1.Equals(other) && !value2.Equals(other)) { other = Unsafe.Add(ref searchSpace, num + 1); if (value0.Equals(other) || value1.Equals(other) || value2.Equals(other)) { goto IL_03c2; } other = Unsafe.Add(ref searchSpace, num + 2); if (value0.Equals(other) || value1.Equals(other) || value2.Equals(other)) { goto IL_03c6; } other = Unsafe.Add(ref searchSpace, num + 3); if (!value0.Equals(other) && !value1.Equals(other) && !value2.Equals(other)) { other = Unsafe.Add(ref searchSpace, num + 4); if (!value0.Equals(other) && !value1.Equals(other) && !value2.Equals(other)) { other = Unsafe.Add(ref searchSpace, num + 5); if (!value0.Equals(other) && !value1.Equals(other) && !value2.Equals(other)) { other = Unsafe.Add(ref searchSpace, num + 6); if (!value0.Equals(other) && !value1.Equals(other) && !value2.Equals(other)) { other = Unsafe.Add(ref searchSpace, num + 7); if (value0.Equals(other) || value1.Equals(other) || value2.Equals(other)) { break; } num += 8; continue; } return num + 6; } return num + 5; } return num + 4; } goto IL_03ca; } } else { if (length - num >= 4) { T other = Unsafe.Add(ref searchSpace, num); if (value0.Equals(other) || value1.Equals(other) || value2.Equals(other)) { goto IL_03c0; } other = Unsafe.Add(ref searchSpace, num + 1); if (value0.Equals(other) || value1.Equals(other) || value2.Equals(other)) { goto IL_03c2; } other = Unsafe.Add(ref searchSpace, num + 2); if (value0.Equals(other) || value1.Equals(other) || value2.Equals(other)) { goto IL_03c6; } other = Unsafe.Add(ref searchSpace, num + 3); if (value0.Equals(other) || value1.Equals(other) || value2.Equals(other)) { goto IL_03ca; } num += 4; } while (true) { if (num < length) { T other = Unsafe.Add(ref searchSpace, num); if (value0.Equals(other) || value1.Equals(other) || value2.Equals(other)) { break; } num++; continue; } return -1; } } goto IL_03c0; IL_03c0: return num; IL_03c6: return num + 2; IL_03c2: return num + 1; IL_03ca: return num + 3; } return num + 7; } public static int IndexOfAny<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] T>(ref T searchSpace, int searchSpaceLength, ref T value, int valueLength) where T : IEquatable { if (valueLength == 0) { return 0; } int num = -1; for (int i = 0; i < valueLength; i++) { int num2 = IndexOf(ref searchSpace, Unsafe.Add(ref value, i), searchSpaceLength); if ((uint)num2 < (uint)num) { num = num2; searchSpaceLength = num2; if (num == 0) { break; } } } return num; } public static int LastIndexOf<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] T>(ref T searchSpace, int searchSpaceLength, ref T value, int valueLength) where T : IEquatable { if (valueLength == 0) { return 0; } T value2 = value; ref T second = ref Unsafe.Add(ref value, 1); int num = valueLength - 1; int num2 = 0; while (true) { int num3 = searchSpaceLength - num2 - num; if (num3 <= 0) { break; } int num4 = LastIndexOf(ref searchSpace, value2, num3); if (num4 == -1) { break; } if (SequenceEqual(ref Unsafe.Add(ref searchSpace, num4 + 1), ref second, num)) { return num4; } num2 += num3 - num4; } return -1; } public static int LastIndexOf<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] T>(ref T searchSpace, T value, int length) where T : IEquatable { while (true) { T val; if (length >= 8) { length -= 8; ref T reference = ref value; val = default(T); if (val == null) { val = reference; reference = ref val; } if (reference.Equals(Unsafe.Add(ref searchSpace, length + 7))) { break; } ref T reference2 = ref value; val = default(T); if (val == null) { val = reference2; reference2 = ref val; } if (reference2.Equals(Unsafe.Add(ref searchSpace, length + 6))) { return length + 6; } ref T reference3 = ref value; val = default(T); if (val == null) { val = reference3; reference3 = ref val; } if (reference3.Equals(Unsafe.Add(ref searchSpace, length + 5))) { return length + 5; } ref T reference4 = ref value; val = default(T); if (val == null) { val = reference4; reference4 = ref val; } if (reference4.Equals(Unsafe.Add(ref searchSpace, length + 4))) { return length + 4; } ref T reference5 = ref value; val = default(T); if (val == null) { val = reference5; reference5 = ref val; } if (reference5.Equals(Unsafe.Add(ref searchSpace, length + 3))) { goto IL_02fd; } ref T reference6 = ref value; val = default(T); if (val == null) { val = reference6; reference6 = ref val; } if (reference6.Equals(Unsafe.Add(ref searchSpace, length + 2))) { goto IL_02f9; } ref T reference7 = ref value; val = default(T); if (val == null) { val = reference7; reference7 = ref val; } if (reference7.Equals(Unsafe.Add(ref searchSpace, length + 1))) { goto IL_02f5; } ref T reference8 = ref value; val = default(T); if (val == null) { val = reference8; reference8 = ref val; } if (!reference8.Equals(Unsafe.Add(ref searchSpace, length))) { continue; } } else { if (length >= 4) { length -= 4; ref T reference9 = ref value; val = default(T); if (val == null) { val = reference9; reference9 = ref val; } if (reference9.Equals(Unsafe.Add(ref searchSpace, length + 3))) { goto IL_02fd; } ref T reference10 = ref value; val = default(T); if (val == null) { val = reference10; reference10 = ref val; } if (reference10.Equals(Unsafe.Add(ref searchSpace, length + 2))) { goto IL_02f9; } ref T reference11 = ref value; val = default(T); if (val == null) { val = reference11; reference11 = ref val; } if (reference11.Equals(Unsafe.Add(ref searchSpace, length + 1))) { goto IL_02f5; } ref T reference12 = ref value; val = default(T); if (val == null) { val = reference12; reference12 = ref val; } if (reference12.Equals(Unsafe.Add(ref searchSpace, length))) { goto IL_02f3; } } ref T reference13; do { if (length > 0) { length--; reference13 = ref value; val = default(T); if (val == null) { val = reference13; reference13 = ref val; } continue; } return -1; } while (!reference13.Equals(Unsafe.Add(ref searchSpace, length))); } goto IL_02f3; IL_02f5: return length + 1; IL_02f9: return length + 2; IL_02fd: return length + 3; IL_02f3: return length; } return length + 7; } public static int LastIndexOfAny<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] T>(ref T searchSpace, T value0, T value1, int length) where T : IEquatable { while (true) { if (length >= 8) { length -= 8; T other = Unsafe.Add(ref searchSpace, length + 7); if (value0.Equals(other) || value1.Equals(other)) { break; } other = Unsafe.Add(ref searchSpace, length + 6); if (value0.Equals(other) || value1.Equals(other)) { return length + 6; } other = Unsafe.Add(ref searchSpace, length + 5); if (value0.Equals(other) || value1.Equals(other)) { return length + 5; } other = Unsafe.Add(ref searchSpace, length + 4); if (value0.Equals(other) || value1.Equals(other)) { return length + 4; } other = Unsafe.Add(ref searchSpace, length + 3); if (value0.Equals(other) || value1.Equals(other)) { goto IL_02cd; } other = Unsafe.Add(ref searchSpace, length + 2); if (value0.Equals(other) || value1.Equals(other)) { goto IL_02c9; } other = Unsafe.Add(ref searchSpace, length + 1); if (value0.Equals(other) || value1.Equals(other)) { goto IL_02c5; } other = Unsafe.Add(ref searchSpace, length); if (!value0.Equals(other) && !value1.Equals(other)) { continue; } } else { T other; if (length >= 4) { length -= 4; other = Unsafe.Add(ref searchSpace, length + 3); if (value0.Equals(other) || value1.Equals(other)) { goto IL_02cd; } other = Unsafe.Add(ref searchSpace, length + 2); if (value0.Equals(other) || value1.Equals(other)) { goto IL_02c9; } other = Unsafe.Add(ref searchSpace, length + 1); if (value0.Equals(other) || value1.Equals(other)) { goto IL_02c5; } other = Unsafe.Add(ref searchSpace, length); if (value0.Equals(other) || value1.Equals(other)) { goto IL_02c3; } } do { if (length > 0) { length--; other = Unsafe.Add(ref searchSpace, length); continue; } return -1; } while (!value0.Equals(other) && !value1.Equals(other)); } goto IL_02c3; IL_02c9: return length + 2; IL_02c5: return length + 1; IL_02c3: return length; IL_02cd: return length + 3; } return length + 7; } public static int LastIndexOfAny<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] T>(ref T searchSpace, T value0, T value1, T value2, int length) where T : IEquatable { while (true) { if (length >= 8) { length -= 8; T other = Unsafe.Add(ref searchSpace, length + 7); if (value0.Equals(other) || value1.Equals(other) || value2.Equals(other)) { break; } other = Unsafe.Add(ref searchSpace, length + 6); if (value0.Equals(other) || value1.Equals(other) || value2.Equals(other)) { return length + 6; } other = Unsafe.Add(ref searchSpace, length + 5); if (value0.Equals(other) || value1.Equals(other) || value2.Equals(other)) { return length + 5; } other = Unsafe.Add(ref searchSpace, length + 4); if (value0.Equals(other) || value1.Equals(other) || value2.Equals(other)) { return length + 4; } other = Unsafe.Add(ref searchSpace, length + 3); if (value0.Equals(other) || value1.Equals(other) || value2.Equals(other)) { goto IL_03da; } other = Unsafe.Add(ref searchSpace, length + 2); if (value0.Equals(other) || value1.Equals(other) || value2.Equals(other)) { goto IL_03d5; } other = Unsafe.Add(ref searchSpace, length + 1); if (value0.Equals(other) || value1.Equals(other) || value2.Equals(other)) { goto IL_03d0; } other = Unsafe.Add(ref searchSpace, length); if (!value0.Equals(other) && !value1.Equals(other) && !value2.Equals(other)) { continue; } } else { T other; if (length >= 4) { length -= 4; other = Unsafe.Add(ref searchSpace, length + 3); if (value0.Equals(other) || value1.Equals(other) || value2.Equals(other)) { goto IL_03da; } other = Unsafe.Add(ref searchSpace, length + 2); if (value0.Equals(other) || value1.Equals(other) || value2.Equals(other)) { goto IL_03d5; } other = Unsafe.Add(ref searchSpace, length + 1); if (value0.Equals(other) || value1.Equals(other) || value2.Equals(other)) { goto IL_03d0; } other = Unsafe.Add(ref searchSpace, length); if (value0.Equals(other) || value1.Equals(other) || value2.Equals(other)) { goto IL_03cd; } } do { if (length > 0) { length--; other = Unsafe.Add(ref searchSpace, length); continue; } return -1; } while (!value0.Equals(other) && !value1.Equals(other) && !value2.Equals(other)); } goto IL_03cd; IL_03d0: return length + 1; IL_03d5: return length + 2; IL_03da: return length + 3; IL_03cd: return length; } return length + 7; } public static int LastIndexOfAny<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] T>(ref T searchSpace, int searchSpaceLength, ref T value, int valueLength) where T : IEquatable { if (valueLength == 0) { return 0; } int num = -1; for (int i = 0; i < valueLength; i++) { int num2 = LastIndexOf(ref searchSpace, Unsafe.Add(ref value, i), searchSpaceLength); if (num2 > num) { num = num2; } } return num; } public static bool SequenceEqual<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] T>(ref T first, ref T second, int length) where T : IEquatable { if (!Unsafe.AreSame(ref first, ref second)) { nuint num = 0u; while (true) { T val; if (length >= 8) { length -= 8; ref T reference = ref Unsafe.Add(ref first, num); val = default(T); if (val == null) { val = reference; reference = ref val; } if (reference.Equals(Unsafe.Add(ref second, num))) { ref T reference2 = ref Unsafe.Add(ref first, num + 1); val = default(T); if (val == null) { val = reference2; reference2 = ref val; } if (reference2.Equals(Unsafe.Add(ref second, num + 1))) { ref T reference3 = ref Unsafe.Add(ref first, num + 2); val = default(T); if (val == null) { val = reference3; reference3 = ref val; } if (reference3.Equals(Unsafe.Add(ref second, num + 2))) { ref T reference4 = ref Unsafe.Add(ref first, num + 3); val = default(T); if (val == null) { val = reference4; reference4 = ref val; } if (reference4.Equals(Unsafe.Add(ref second, num + 3))) { ref T reference5 = ref Unsafe.Add(ref first, num + 4); val = default(T); if (val == null) { val = reference5; reference5 = ref val; } if (reference5.Equals(Unsafe.Add(ref second, num + 4))) { ref T reference6 = ref Unsafe.Add(ref first, num + 5); val = default(T); if (val == null) { val = reference6; reference6 = ref val; } if (reference6.Equals(Unsafe.Add(ref second, num + 5))) { ref T reference7 = ref Unsafe.Add(ref first, num + 6); val = default(T); if (val == null) { val = reference7; reference7 = ref val; } if (reference7.Equals(Unsafe.Add(ref second, num + 6))) { ref T reference8 = ref Unsafe.Add(ref first, num + 7); val = default(T); if (val == null) { val = reference8; reference8 = ref val; } if (reference8.Equals(Unsafe.Add(ref second, num + 7))) { num += 8; continue; } } } } } } } } } else { if (length < 4) { goto IL_0377; } length -= 4; ref T reference9 = ref Unsafe.Add(ref first, num); val = default(T); if (val == null) { val = reference9; reference9 = ref val; } if (reference9.Equals(Unsafe.Add(ref second, num))) { ref T reference10 = ref Unsafe.Add(ref first, num + 1); val = default(T); if (val == null) { val = reference10; reference10 = ref val; } if (reference10.Equals(Unsafe.Add(ref second, num + 1))) { ref T reference11 = ref Unsafe.Add(ref first, num + 2); val = default(T); if (val == null) { val = reference11; reference11 = ref val; } if (reference11.Equals(Unsafe.Add(ref second, num + 2))) { ref T reference12 = ref Unsafe.Add(ref first, num + 3); val = default(T); if (val == null) { val = reference12; reference12 = ref val; } if (reference12.Equals(Unsafe.Add(ref second, num + 3))) { num += 4; goto IL_0377; } } } } } goto IL_037d; IL_0377: while (length > 0) { ref T reference13 = ref Unsafe.Add(ref first, num); val = default(T); if (val == null) { val = reference13; reference13 = ref val; } if (reference13.Equals(Unsafe.Add(ref second, num))) { num++; length--; continue; } goto IL_037d; } break; IL_037d: return false; } } return true; } public static int SequenceCompareTo<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] T>(ref T first, int firstLength, ref T second, int secondLength) where T : IComparable { int num = firstLength; if (num > secondLength) { num = secondLength; } for (int i = 0; i < num; i++) { ref T reference = ref Unsafe.Add(ref first, i); T val = default(T); if (val == null) { val = reference; reference = ref val; } int num2 = reference.CompareTo(Unsafe.Add(ref second, i)); if (num2 != 0) { return num2; } } return firstLength.CompareTo(secondLength); } } internal static class StringComparerEx { [NullableContext(1)] public static StringComparer FromComparison(StringComparison comparisonType) { return comparisonType switch { StringComparison.CurrentCulture => StringComparer.CurrentCulture, StringComparison.CurrentCultureIgnoreCase => StringComparer.CurrentCultureIgnoreCase, StringComparison.InvariantCulture => StringComparer.InvariantCulture, StringComparison.InvariantCultureIgnoreCase => StringComparer.InvariantCultureIgnoreCase, StringComparison.Ordinal => StringComparer.Ordinal, StringComparison.OrdinalIgnoreCase => StringComparer.OrdinalIgnoreCase, _ => throw new ArgumentException("Invalid StringComparison value", "comparisonType"), }; } } [NullableContext(1)] [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] internal static class StringExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string Replace(this string self, string oldValue, string newValue, StringComparison comparison) { System.ThrowHelper.ThrowIfArgumentNull(self, System.ExceptionArgument.self); System.ThrowHelper.ThrowIfArgumentNull(oldValue, System.ExceptionArgument.oldValue); System.ThrowHelper.ThrowIfArgumentNull(newValue, System.ExceptionArgument.newValue); DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(oldValue.Length, 0); ReadOnlySpan readOnlySpan = MemoryExtensions.AsSpan(self); ReadOnlySpan value = MemoryExtensions.AsSpan(oldValue); while (true) { int num = readOnlySpan.IndexOf(value, comparison); if (num < 0) { break; } defaultInterpolatedStringHandler.AppendFormatted(readOnlySpan.Slice(0, num)); defaultInterpolatedStringHandler.AppendLiteral(newValue); readOnlySpan = readOnlySpan.Slice(num + value.Length); } defaultInterpolatedStringHandler.AppendFormatted(readOnlySpan); return defaultInterpolatedStringHandler.ToStringAndClear(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool Contains(this string self, string value, StringComparison comparison) { System.ThrowHelper.ThrowIfArgumentNull(self, System.ExceptionArgument.self); System.ThrowHelper.ThrowIfArgumentNull(value, System.ExceptionArgument.value); return self.IndexOf(value, comparison) >= 0; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool Contains(this string self, char value, StringComparison comparison) { System.ThrowHelper.ThrowIfArgumentNull(self, System.ExceptionArgument.self); return IndexOf(self, value, comparison) >= 0; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int GetHashCode(this string self, StringComparison comparison) { System.ThrowHelper.ThrowIfArgumentNull(self, System.ExceptionArgument.self); return StringComparerEx.FromComparison(comparison).GetHashCode(self); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int IndexOf(this string self, char value, StringComparison comparison) { System.ThrowHelper.ThrowIfArgumentNull(self, System.ExceptionArgument.self); return self.IndexOf(new string(value, 1), comparison); } } [NullableContext(1)] [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] internal static class ThrowHelper { [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(2)] internal static void ThrowIfArgumentNull([NotNull] object obj, System.ExceptionArgument argument) { if (obj == null) { ThrowArgumentNullException(argument); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(2)] internal static void ThrowIfArgumentNull([NotNull] object obj, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(1)] string argument, string message = null) { if (obj == null) { ThrowArgumentNullException(argument, message); } } [DoesNotReturn] internal static void ThrowArgumentNullException(System.ExceptionArgument argument) { throw CreateArgumentNullException(argument); } [DoesNotReturn] internal static void ThrowArgumentNullException(string argument, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] string message = null) { throw CreateArgumentNullException(argument, message); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateArgumentNullException(System.ExceptionArgument argument) { return CreateArgumentNullException(argument.ToString()); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateArgumentNullException(string argument, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] string message = null) { return new ArgumentNullException(argument, message); } [DoesNotReturn] internal static void ThrowArrayTypeMismatchException() { throw CreateArrayTypeMismatchException(); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateArrayTypeMismatchException() { return new ArrayTypeMismatchException(); } [DoesNotReturn] internal static void ThrowArgumentException_InvalidTypeWithPointersNotSupported(Type type) { throw CreateArgumentException_InvalidTypeWithPointersNotSupported(type); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateArgumentException_InvalidTypeWithPointersNotSupported(Type type) { return new ArgumentException($"Type {type} with managed pointers cannot be used in a Span"); } [DoesNotReturn] internal static void ThrowArgumentException_DestinationTooShort() { throw CreateArgumentException_DestinationTooShort(); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateArgumentException_DestinationTooShort() { return new ArgumentException("Destination too short"); } [DoesNotReturn] internal static void ThrowArgumentException(string message, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] string argument = null) { throw CreateArgumentException(message, argument); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateArgumentException(string message, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] string argument) { return new ArgumentException(message, argument ?? ""); } [DoesNotReturn] internal static void ThrowIndexOutOfRangeException() { throw CreateIndexOutOfRangeException(); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateIndexOutOfRangeException() { return new IndexOutOfRangeException(); } [DoesNotReturn] internal static void ThrowArgumentOutOfRangeException() { throw CreateArgumentOutOfRangeException(); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateArgumentOutOfRangeException() { return new ArgumentOutOfRangeException(); } [DoesNotReturn] internal static void ThrowArgumentOutOfRangeException(System.ExceptionArgument argument) { throw CreateArgumentOutOfRangeException(argument); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateArgumentOutOfRangeException(System.ExceptionArgument argument) { return new ArgumentOutOfRangeException(argument.ToString()); } [DoesNotReturn] internal static void ThrowArgumentOutOfRangeException_PrecisionTooLarge() { throw CreateArgumentOutOfRangeException_PrecisionTooLarge(); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateArgumentOutOfRangeException_PrecisionTooLarge() { return new ArgumentOutOfRangeException("precision", $"Precision too large (max: {99})"); } [DoesNotReturn] internal static void ThrowArgumentOutOfRangeException_SymbolDoesNotFit() { throw CreateArgumentOutOfRangeException_SymbolDoesNotFit(); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateArgumentOutOfRangeException_SymbolDoesNotFit() { return new ArgumentOutOfRangeException("symbol", "Bad format specifier"); } [DoesNotReturn] internal static void ThrowInvalidOperationException() { throw CreateInvalidOperationException(); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateInvalidOperationException() { return new InvalidOperationException(); } [DoesNotReturn] internal static void ThrowInvalidOperationException_OutstandingReferences() { throw CreateInvalidOperationException_OutstandingReferences(); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateInvalidOperationException_OutstandingReferences() { return new InvalidOperationException("Outstanding references"); } [DoesNotReturn] internal static void ThrowInvalidOperationException_UnexpectedSegmentType() { throw CreateInvalidOperationException_UnexpectedSegmentType(); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateInvalidOperationException_UnexpectedSegmentType() { return new InvalidOperationException("Unexpected segment type"); } [DoesNotReturn] internal static void ThrowInvalidOperationException_EndPositionNotReached() { throw CreateInvalidOperationException_EndPositionNotReached(); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateInvalidOperationException_EndPositionNotReached() { return new InvalidOperationException("End position not reached"); } [DoesNotReturn] internal static void ThrowArgumentOutOfRangeException_PositionOutOfRange() { throw CreateArgumentOutOfRangeException_PositionOutOfRange(); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateArgumentOutOfRangeException_PositionOutOfRange() { return new ArgumentOutOfRangeException("position"); } [DoesNotReturn] internal static void ThrowArgumentOutOfRangeException_OffsetOutOfRange() { throw CreateArgumentOutOfRangeException_OffsetOutOfRange(); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateArgumentOutOfRangeException_OffsetOutOfRange() { return new ArgumentOutOfRangeException("offset"); } [DoesNotReturn] internal static void ThrowObjectDisposedException_ArrayMemoryPoolBuffer() { throw CreateObjectDisposedException_ArrayMemoryPoolBuffer(); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateObjectDisposedException_ArrayMemoryPoolBuffer() { return new ObjectDisposedException("ArrayMemoryPoolBuffer"); } [DoesNotReturn] internal static void ThrowFormatException_BadFormatSpecifier() { throw CreateFormatException_BadFormatSpecifier(); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateFormatException_BadFormatSpecifier() { return new FormatException("Bad format specifier"); } [DoesNotReturn] internal static void ThrowArgumentException_OverlapAlignmentMismatch() { throw CreateArgumentException_OverlapAlignmentMismatch(); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateArgumentException_OverlapAlignmentMismatch() { return new ArgumentException("Overlap alignment mismatch"); } [NullableContext(2)] [DoesNotReturn] internal static void ThrowNotSupportedException(string msg = null) { throw CreateThrowNotSupportedException(msg); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateThrowNotSupportedException([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] string msg) { return new NotSupportedException(); } [DoesNotReturn] internal static void ThrowKeyNullException() { ThrowArgumentNullException(System.ExceptionArgument.key); } [DoesNotReturn] internal static void ThrowValueNullException() { throw CreateThrowValueNullException(); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateThrowValueNullException() { return new ArgumentException("Value is null"); } [DoesNotReturn] internal static void ThrowOutOfMemoryException() { throw CreateOutOfMemoryException(); } [MethodImpl(MethodImplOptions.NoInlining)] private static Exception CreateOutOfMemoryException() { return new OutOfMemoryException(); } public static bool TryFormatThrowFormatException(out int bytesWritten) { bytesWritten = 0; ThrowFormatException_BadFormatSpecifier(); return false; } public static bool TryParseThrowFormatException<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T>(out T value, out int bytesConsumed) { value = default(T); bytesConsumed = 0; ThrowFormatException_BadFormatSpecifier(); return false; } [NullableContext(2)] [DoesNotReturn] public static void ThrowArgumentValidationException([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] ReadOnlySequenceSegment startSegment, int startIndex, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] ReadOnlySequenceSegment endSegment) { throw CreateArgumentValidationException(startSegment, startIndex, endSegment); } private static Exception CreateArgumentValidationException<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T>([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] ReadOnlySequenceSegment startSegment, int startIndex, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] ReadOnlySequenceSegment endSegment) { if (startSegment == null) { return CreateArgumentNullException(System.ExceptionArgument.startSegment); } if (endSegment == null) { return CreateArgumentNullException(System.ExceptionArgument.endSegment); } if (startSegment != endSegment && startSegment.RunningIndex > endSegment.RunningIndex) { return CreateArgumentOutOfRangeException(System.ExceptionArgument.endSegment); } if ((uint)startSegment.Memory.Length < (uint)startIndex) { return CreateArgumentOutOfRangeException(System.ExceptionArgument.startIndex); } return CreateArgumentOutOfRangeException(System.ExceptionArgument.endIndex); } [NullableContext(2)] [DoesNotReturn] public static void ThrowArgumentValidationException(Array array, int start) { throw CreateArgumentValidationException(array, start); } private static Exception CreateArgumentValidationException([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] Array array, int start) { if (array == null) { return CreateArgumentNullException(System.ExceptionArgument.array); } if ((uint)start > (uint)array.Length) { return CreateArgumentOutOfRangeException(System.ExceptionArgument.start); } return CreateArgumentOutOfRangeException(System.ExceptionArgument.length); } [DoesNotReturn] internal static void ThrowArgumentException_TupleIncorrectType(object other) { throw new ArgumentException($"Value tuple of incorrect type (found {other.GetType()})", "other"); } [DoesNotReturn] public static void ThrowStartOrEndArgumentValidationException(long start) { throw CreateStartOrEndArgumentValidationException(start); } private static Exception CreateStartOrEndArgumentValidationException(long start) { if (start < 0) { return CreateArgumentOutOfRangeException(System.ExceptionArgument.start); } return CreateArgumentOutOfRangeException(System.ExceptionArgument.length); } } internal enum ExceptionArgument { length, start, bufferSize, minimumBufferSize, elementIndex, comparable, comparer, destination, offset, startSegment, endSegment, startIndex, endIndex, array, culture, manager, key, collection, index, type, self, value, oldValue, newValue } internal static class TypeExtensions { [NullableContext(1)] public static bool IsByRefLike(this Type type) { System.ThrowHelper.ThrowIfArgumentNull(type, System.ExceptionArgument.type); if ((object)type == null) { System.ThrowHelper.ThrowArgumentNullException(System.ExceptionArgument.type); } object[] customAttributes = type.GetCustomAttributes(inherit: false); for (int i = 0; i < customAttributes.Length; i++) { if (customAttributes[i].GetType().FullName == "System.Runtime.CompilerServices.IsByRefLikeAttribute") { return true; } } return false; } } } namespace System.Threading { internal static class MonitorEx { [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(1)] public static void Enter(object obj, ref bool lockTaken) { Monitor.Enter(obj, ref lockTaken); } } } namespace System.Text { internal static class StringBuilderExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(1)] public static StringBuilder Clear(this StringBuilder builder) { System.ThrowHelper.ThrowIfArgumentNull(builder, "builder"); return builder.Clear(); } } } namespace System.Numerics { internal static class BitOperations { private static ReadOnlySpan TrailingZeroCountDeBruijn => new byte[32] { 0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9 }; private static ReadOnlySpan Log2DeBruijn => new byte[32] { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static int LeadingZeroCount(uint value) { if (value == 0) { return 32; } return 0x1F ^ Log2SoftwareFallback(value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static int LeadingZeroCount(ulong value) { uint num = (uint)(value >> 32); if (num == 0) { return 32 + LeadingZeroCount((uint)value); } return LeadingZeroCount(num); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static int Log2(uint value) { value |= 1u; return Log2SoftwareFallback(value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static int Log2(ulong value) { value |= 1; uint num = (uint)(value >> 32); if (num == 0) { return Log2((uint)value); } return 32 + Log2(num); } private static int Log2SoftwareFallback(uint value) { value |= value >> 1; value |= value >> 2; value |= value >> 4; value |= value >> 8; value |= value >> 16; return Unsafe.AddByteOffset(ref MemoryMarshal.GetReference(Log2DeBruijn), (IntPtr)(int)(value * 130329821 >> 27)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static int Log2Ceiling(uint value) { int num = Log2(value); if (PopCount(value) != 1) { num++; } return num; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static int Log2Ceiling(ulong value) { int num = Log2(value); if (PopCount(value) != 1) { num++; } return num; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static int PopCount(uint value) { return SoftwareFallback(value); static int SoftwareFallback(uint value) { value -= (value >> 1) & 0x55555555; value = (value & 0x33333333) + ((value >> 2) & 0x33333333); value = ((value + (value >> 4)) & 0xF0F0F0F) * 16843009 >> 24; return (int)value; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static int PopCount(ulong value) { if (IntPtr.Size == 8) { return PopCount((uint)value) + PopCount((uint)(value >> 32)); } return SoftwareFallback(value); static int SoftwareFallback(ulong value) { value -= (value >> 1) & 0x5555555555555555L; value = (value & 0x3333333333333333L) + ((value >> 2) & 0x3333333333333333L); value = ((value + (value >> 4)) & 0xF0F0F0F0F0F0F0FL) * 72340172838076673L >> 56; return (int)value; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int TrailingZeroCount(int value) { return TrailingZeroCount((uint)value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static int TrailingZeroCount(uint value) { if (value == 0) { return 32; } return Unsafe.AddByteOffset(ref MemoryMarshal.GetReference(TrailingZeroCountDeBruijn), (IntPtr)(int)((value & (0 - value)) * 125613361 >> 27)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int TrailingZeroCount(long value) { return TrailingZeroCount((ulong)value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static int TrailingZeroCount(ulong value) { uint num = (uint)value; if (num == 0) { return 32 + TrailingZeroCount((uint)(value >> 32)); } return TrailingZeroCount(num); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static uint RotateLeft(uint value, int offset) { return (value << offset) | (value >> 32 - offset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static ulong RotateLeft(ulong value, int offset) { return (value << offset) | (value >> 64 - offset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static uint RotateRight(uint value, int offset) { return (value >> offset) | (value << 32 - offset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static ulong RotateRight(ulong value, int offset) { return (value >> offset) | (value << 64 - offset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static uint ResetLowestSetBit(uint value) { return value & (value - 1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static uint ResetBit(uint value, int bitPos) { return value & (uint)(~(1 << bitPos)); } } internal static class BitOperationsEx { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsPow2(int value) { if ((value & (value - 1)) == 0) { return value > 0; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static bool IsPow2(uint value) { if ((value & (value - 1)) == 0) { return value != 0; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsPow2(long value) { if ((value & (value - 1)) == 0L) { return value > 0; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static bool IsPow2(ulong value) { if ((value & (value - 1)) == 0L) { return value != 0; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsPow2([<9248bc27-e977-4246-b6f6-bd8f7836272f>NativeInteger] IntPtr value) { if (((nint)value & ((nint)value - 1)) == 0) { return (nint)value > 0; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static bool IsPow2([<9248bc27-e977-4246-b6f6-bd8f7836272f>NativeInteger] UIntPtr value) { if (((nint)(nuint)value & ((nint)(nuint)value - 1)) == 0) { return value != (UIntPtr)(nuint)0u; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static uint RoundUpToPowerOf2(uint value) { value--; value |= value >> 1; value |= value >> 2; value |= value >> 4; value |= value >> 8; value |= value >> 16; return value + 1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static ulong RoundUpToPowerOf2(ulong value) { value--; value |= value >> 1; value |= value >> 2; value |= value >> 4; value |= value >> 8; value |= value >> 16; value |= value >> 32; return value + 1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] [return: <9248bc27-e977-4246-b6f6-bd8f7836272f>NativeInteger] public static UIntPtr RoundUpToPowerOf2([<9248bc27-e977-4246-b6f6-bd8f7836272f>NativeInteger] UIntPtr value) { if (IntPtr.Size == 8) { return (nuint)RoundUpToPowerOf2((ulong)value); } return (UIntPtr)RoundUpToPowerOf2((uint)(nuint)value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static int LeadingZeroCount(uint value) { return BitOperations.LeadingZeroCount(value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static int LeadingZeroCount(ulong value) { return BitOperations.LeadingZeroCount(value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static int LeadingZeroCount([<9248bc27-e977-4246-b6f6-bd8f7836272f>NativeInteger] UIntPtr value) { if (IntPtr.Size == 8) { return LeadingZeroCount((ulong)value); } return LeadingZeroCount((uint)(nuint)value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static int Log2(uint value) { return BitOperations.Log2(value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static int Log2(ulong value) { return BitOperations.Log2(value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static int Log2([<9248bc27-e977-4246-b6f6-bd8f7836272f>NativeInteger] UIntPtr value) { if (IntPtr.Size == 8) { return Log2((ulong)value); } return Log2((uint)(nuint)value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static int PopCount(uint value) { return BitOperations.PopCount(value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static int PopCount(ulong value) { return BitOperations.PopCount(value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static int PopCount([<9248bc27-e977-4246-b6f6-bd8f7836272f>NativeInteger] UIntPtr value) { if (IntPtr.Size == 8) { return PopCount((ulong)value); } return PopCount((uint)(nuint)value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int TrailingZeroCount(int value) { return BitOperations.TrailingZeroCount(value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static int TrailingZeroCount(uint value) { return BitOperations.TrailingZeroCount(value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int TrailingZeroCount(long value) { return BitOperations.TrailingZeroCount(value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static int TrailingZeroCount(ulong value) { return BitOperations.TrailingZeroCount(value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int TrailingZeroCount([<9248bc27-e977-4246-b6f6-bd8f7836272f>NativeInteger] IntPtr value) { if (IntPtr.Size == 8) { return TrailingZeroCount((long)value); } return TrailingZeroCount((int)(nint)value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static int TrailingZeroCount([<9248bc27-e977-4246-b6f6-bd8f7836272f>NativeInteger] UIntPtr value) { if (IntPtr.Size == 8) { return TrailingZeroCount((ulong)value); } return TrailingZeroCount((uint)(nuint)value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static uint RotateLeft(uint value, int offset) { return BitOperations.RotateLeft(value, offset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static ulong RotateLeft(ulong value, int offset) { return BitOperations.RotateLeft(value, offset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] [return: <9248bc27-e977-4246-b6f6-bd8f7836272f>NativeInteger] public static UIntPtr RotateLeft([<9248bc27-e977-4246-b6f6-bd8f7836272f>NativeInteger] UIntPtr value, int offset) { if (IntPtr.Size == 8) { return (nuint)RotateLeft((ulong)value, offset); } return (UIntPtr)RotateLeft((uint)(nuint)value, offset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static uint RotateRight(uint value, int offset) { return BitOperations.RotateRight(value, offset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] public static ulong RotateRight(ulong value, int offset) { return BitOperations.RotateRight(value, offset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [CLSCompliant(false)] [return: <9248bc27-e977-4246-b6f6-bd8f7836272f>NativeInteger] public static UIntPtr RotateRight([<9248bc27-e977-4246-b6f6-bd8f7836272f>NativeInteger] UIntPtr value, int offset) { if (IntPtr.Size == 8) { return (nuint)RotateRight((ulong)value, offset); } return (UIntPtr)RotateRight((uint)(nuint)value, offset); } } } namespace System.IO { [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] [NullableContext(1)] internal static class StreamExtensions { public static void CopyTo(this Stream src, Stream destination) { System.ThrowHelper.ThrowIfArgumentNull(src, "src"); src.CopyTo(destination); } public static void CopyTo(this Stream src, Stream destination, int bufferSize) { System.ThrowHelper.ThrowIfArgumentNull(src, "src"); src.CopyTo(destination, bufferSize); } } } namespace System.Collections { internal static class HashHelpers { public const uint HashCollisionThreshold = 100u; public const int MaxPrimeArrayLength = 2147483587; public const int HashPrime = 101; [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(1)] private static readonly int[] s_primes = new int[72] { 3, 7, 11, 17, 23, 29, 37, 47, 59, 71, 89, 107, 131, 163, 197, 239, 293, 353, 431, 521, 631, 761, 919, 1103, 1327, 1597, 1931, 2333, 2801, 3371, 4049, 4861, 5839, 7013, 8419, 10103, 12143, 14591, 17519, 21023, 25229, 30293, 36353, 43627, 52361, 62851, 75431, 90523, 108631, 130363, 156437, 187751, 225307, 270371, 324449, 389357, 467237, 560689, 672827, 807403, 968897, 1162687, 1395263, 1674319, 2009191, 2411033, 2893249, 3471899, 4166287, 4999559, 5999471, 7199369 }; public static bool IsPrime(int candidate) { if (((uint)candidate & (true ? 1u : 0u)) != 0) { int num = (int)Math.Sqrt(candidate); for (int i = 3; i <= num; i += 2) { if (candidate % i == 0) { return false; } } return true; } return candidate == 2; } public static int GetPrime(int min) { if (min < 0) { throw new ArgumentException("Prime minimum cannot be less than zero"); } int[] array = s_primes; foreach (int num in array) { if (num >= min) { return num; } } for (int j = min | 1; j < int.MaxValue; j += 2) { if (IsPrime(j) && (j - 1) % 101 != 0) { return j; } } return min; } public static int ExpandPrime(int oldSize) { int num = 2 * oldSize; if ((uint)num > 2147483587u && 2147483587 > oldSize) { return 2147483587; } return GetPrime(num); } public static ulong GetFastModMultiplier(uint divisor) { return ulong.MaxValue / (ulong)divisor + 1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint FastMod(uint value, uint divisor, ulong multiplier) { return (uint)(((multiplier * value >> 32) + 1) * divisor >> 32); } } } namespace System.Collections.Concurrent { [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] [NullableContext(1)] internal static class ConcurrentExtensions { public static void Clear<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T>(this ConcurrentBag bag) { System.ThrowHelper.ThrowIfArgumentNull(bag, "bag"); T result; while (bag.TryTake(out result)) { } } public static void Clear<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T>(this ConcurrentQueue queue) { System.ThrowHelper.ThrowIfArgumentNull(queue, "queue"); T result; while (queue.TryDequeue(out result)) { } } public static TValue AddOrUpdateNullable(2)] TValue, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] TArg>(this ConcurrentDictionary dict, TKey key, Func addValueFactory, Func updateValueFactory, TArg factoryArgument) { System.ThrowHelper.ThrowIfArgumentNull(dict, "dict"); return dict.AddOrUpdate(key, [NullableContext(0)] ([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(1)] TKey k) => addValueFactory(k, factoryArgument), [NullableContext(0)] ([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(1)] TKey k, TValue v) => updateValueFactory(k, v, factoryArgument)); } public static TValue GetOrAddNullable(2)] TValue, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] TArg>(this ConcurrentDictionary dict, TKey key, Func valueFactory, TArg factoryArgument) { System.ThrowHelper.ThrowIfArgumentNull(dict, "dict"); return dict.GetOrAdd(key, [NullableContext(0)] ([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(1)] TKey k) => valueFactory(k, factoryArgument)); } public static bool TryRemoveNullable(2)] TValue>(this ConcurrentDictionary dict, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1, 1 })] KeyValuePair item) { System.ThrowHelper.ThrowIfArgumentNull(dict, "dict"); if (dict.TryRemove(item.Key, out var value)) { if (EqualityComparer.Default.Equals(item.Value, value)) { return true; } dict.AddOrUpdate(item.Key, [NullableContext(0)] ([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(1)] TKey _) => value, [NullableContext(0)] ([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(1)] TKey _, TValue _) => value); return false; } return false; } } } namespace System.Buffers { [NullableContext(1)] [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] internal abstract class ArrayPool<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T> { private static readonly System.Buffers.TlsOverPerCoreLockedStacksArrayPool s_shared = new System.Buffers.TlsOverPerCoreLockedStacksArrayPool(); public static ArrayPool Shared => s_shared; public static ArrayPool Create() { return new System.Buffers.ConfigurableArrayPool(); } public static ArrayPool Create(int maxArrayLength, int maxArraysPerBucket) { return new System.Buffers.ConfigurableArrayPool(maxArrayLength, maxArraysPerBucket); } public abstract T[] Rent(int minimumLength); public abstract void Return(T[] array, bool clearArray = false); } [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] [NullableContext(1)] internal static class BuffersExtensions { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static SequencePosition? PositionOf<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] T>([In][<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })][IsReadOnly] this ref ReadOnlySequence source, T value) where T : IEquatable { if (source.IsSingleSegment) { int num = source.First.Span.IndexOf(value); if (num != -1) { return source.GetPosition(num); } return null; } return PositionOfMultiSegment(ref source, value); } private static SequencePosition? PositionOfMultiSegment<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] T>([In][IsReadOnly][<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ref ReadOnlySequence source, T value) where T : IEquatable { SequencePosition position = source.Start; SequencePosition origin = position; ReadOnlyMemory memory; while (source.TryGet(ref position, out memory)) { int num = memory.Span.IndexOf(value); if (num != -1) { return source.GetPosition(num, origin); } if (position.GetObject() == null) { break; } origin = position; } return null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(2)] public static void CopyTo([In][<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })][IsReadOnly] this ref ReadOnlySequence source, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] Span destination) { if (source.Length > destination.Length) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.destination); } if (source.IsSingleSegment) { source.First.Span.CopyTo(destination); } else { CopyToMultiSegment(ref source, destination); } } [NullableContext(2)] private static void CopyToMultiSegment([In][<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })][IsReadOnly] ref ReadOnlySequence sequence, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] Span destination) { SequencePosition position = sequence.Start; ReadOnlyMemory memory; while (sequence.TryGet(ref position, out memory)) { ReadOnlySpan span = memory.Span; span.CopyTo(destination); if (position.GetObject() != null) { destination = destination.Slice(span.Length); continue; } break; } } public static T[] ToArray<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T>([In][<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })][IsReadOnly] this ref ReadOnlySequence sequence) { T[] array = new T[sequence.Length]; CopyTo(ref sequence, array); return array; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Write<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T>(this IBufferWriter writer, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan value) { System.ThrowHelper.ThrowIfArgumentNull(writer, "writer"); Span span = writer.GetSpan(); if (value.Length <= span.Length) { value.CopyTo(span); writer.Advance(value.Length); } else { WriteMultiSegment(writer, ref value, span); } } private static void WriteMultiSegment<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T>(IBufferWriter writer, [In][IsReadOnly][<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ref ReadOnlySpan source, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] Span destination) { ReadOnlySpan readOnlySpan = source; while (true) { int num = Math.Min(destination.Length, readOnlySpan.Length); readOnlySpan.Slice(0, num).CopyTo(destination); writer.Advance(num); readOnlySpan = readOnlySpan.Slice(num); if (readOnlySpan.Length > 0) { destination = writer.GetSpan(readOnlySpan.Length); continue; } break; } } } [NullableContext(1)] [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] internal sealed class ConfigurableArrayPool<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T> : ArrayPool { [NullableContext(0)] private sealed class Bucket { internal readonly int _bufferLength; [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 1, 2, 1 })] private readonly T[][] _buffers; private readonly int _poolId; private SpinLock _lock; private int _index; internal int Id => GetHashCode(); internal Bucket(int bufferLength, int numberOfBuffers, int poolId) { _lock = new SpinLock(Debugger.IsAttached); _buffers = new T[numberOfBuffers][]; _bufferLength = bufferLength; _poolId = poolId; } [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] internal T[] Rent() { T[][] buffers = _buffers; T[] array = null; bool lockTaken = false; bool flag = false; try { _lock.Enter(ref lockTaken); if (_index < buffers.Length) { array = buffers[_index]; buffers[_index++] = null; flag = array == null; } } finally { if (lockTaken) { _lock.Exit(useMemoryBarrier: false); } } if (flag) { array = new T[_bufferLength]; } return array; } [NullableContext(1)] internal void Return(T[] array) { if (array.Length != _bufferLength) { throw new ArgumentException("Buffer not from this pool", "array"); } bool lockTaken = false; try { _lock.Enter(ref lockTaken); if (_index != 0) { _buffers[--_index] = array; } } finally { if (lockTaken) { _lock.Exit(useMemoryBarrier: false); } } } } private const int DefaultMaxArrayLength = 1048576; private const int DefaultMaxNumberOfArraysPerBucket = 50; [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 1, 1, 0 })] private readonly Bucket[] _buckets; private int Id => GetHashCode(); internal ConfigurableArrayPool() : this(1048576, 50) { } internal ConfigurableArrayPool(int maxArrayLength, int maxArraysPerBucket) { if (maxArrayLength <= 0) { throw new ArgumentOutOfRangeException("maxArrayLength"); } if (maxArraysPerBucket <= 0) { throw new ArgumentOutOfRangeException("maxArraysPerBucket"); } if (maxArrayLength > 1073741824) { maxArrayLength = 1073741824; } else if (maxArrayLength < 16) { maxArrayLength = 16; } int id = Id; Bucket[] array = new Bucket[System.Buffers.Utilities.SelectBucketIndex(maxArrayLength) + 1]; for (int i = 0; i < array.Length; i++) { array[i] = new Bucket(System.Buffers.Utilities.GetMaxSizeForBucket(i), maxArraysPerBucket, id); } _buckets = array; } public override T[] Rent(int minimumLength) { if (minimumLength < 0) { throw new ArgumentOutOfRangeException("minimumLength"); } if (minimumLength == 0) { return ArrayEx.Empty(); } int num = System.Buffers.Utilities.SelectBucketIndex(minimumLength); if (num < _buckets.Length) { int num2 = num; do { T[] array = _buckets[num2].Rent(); if (array != null) { return array; } } while (++num2 < _buckets.Length && num2 != num + 2); return new T[_buckets[num]._bufferLength]; } return new T[minimumLength]; } public override void Return(T[] array, bool clearArray = false) { if (array == null) { throw new ArgumentNullException("array"); } if (array.Length == 0) { return; } int num = System.Buffers.Utilities.SelectBucketIndex(array.Length); if (num < _buckets.Length) { if (clearArray) { Array.Clear(array, 0, array.Length); } _buckets[num].Return(array); } } } [NullableContext(2)] internal interface IBufferWriter { void Advance(int count); [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] Memory GetMemory(int sizeHint = 0); [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] Span GetSpan(int sizeHint = 0); } internal interface IMemoryOwner<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T> : IDisposable { [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] Memory Memory { [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] get; } } internal interface IPinnable { MemoryHandle Pin(int elementIndex); void Unpin(); } internal struct MemoryHandle : IDisposable { private unsafe void* _pointer; private GCHandle _handle; [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] private IPinnable _pinnable; [CLSCompliant(false)] public unsafe void* Pointer => _pointer; [CLSCompliant(false)] public unsafe MemoryHandle(void* pointer, GCHandle handle = default(GCHandle), [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] IPinnable pinnable = null) { _pointer = pointer; _handle = handle; _pinnable = pinnable; } public unsafe void Dispose() { if (_handle.IsAllocated) { _handle.Free(); } if (_pinnable != null) { _pinnable.Unpin(); _pinnable = null; } _pointer = null; } } internal abstract class MemoryManager<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T> : IMemoryOwner, IDisposable, IPinnable { [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public virtual Memory Memory { [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] get { return new Memory(this, GetSpan().Length); } } [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public abstract Span GetSpan(); public abstract MemoryHandle Pin(int elementIndex = 0); public abstract void Unpin(); [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] protected Memory CreateMemory(int length) { return new Memory(this, length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] protected Memory CreateMemory(int start, int length) { return new Memory(this, start, length); } protected internal virtual bool TryGetArray([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] out ArraySegment segment) { segment = default(ArraySegment); return false; } void IDisposable.Dispose() { Dispose(disposing: true); GC.SuppressFinalize(this); } protected abstract void Dispose(bool disposing); } [NullableContext(1)] [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] [IsReadOnly] [DebuggerTypeProxy(typeof(ReadOnlySequenceDebugView<>))] [DebuggerDisplay("{ToString(),raw}")] internal struct ReadOnlySequence<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T> { [NullableContext(0)] public struct Enumerator { [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] private readonly ReadOnlySequence _sequence; private SequencePosition _next; [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] private ReadOnlyMemory _currentMemory; [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public ReadOnlyMemory Current { [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] get { return _currentMemory; } } public Enumerator([In][IsReadOnly][<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ref ReadOnlySequence sequence) { _currentMemory = default(ReadOnlyMemory); _next = sequence.Start; _sequence = sequence; } public bool MoveNext() { if (_next.GetObject() == null) { return false; } return _sequence.TryGet(ref _next, out _currentMemory); } } [NullableContext(0)] private enum SequenceType { MultiSegment, Array, MemoryManager, String, Empty } private readonly SequencePosition _sequenceStart; private readonly SequencePosition _sequenceEnd; [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static readonly ReadOnlySequence Empty = new ReadOnlySequence(System.SpanHelpers.PerTypeValues.EmptyArray); public long Length => GetLength(); public bool IsEmpty => Length == 0; public bool IsSingleSegment { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return _sequenceStart.GetObject() == _sequenceEnd.GetObject(); } } [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public ReadOnlyMemory First { [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] get { return GetFirstBuffer(); } } public SequencePosition Start => _sequenceStart; public SequencePosition End => _sequenceEnd; [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(2)] private ReadOnlySequence(object startSegment, int startIndexAndFlags, object endSegment, int endIndexAndFlags) { _sequenceStart = new SequencePosition(startSegment, startIndexAndFlags); _sequenceEnd = new SequencePosition(endSegment, endIndexAndFlags); } public ReadOnlySequence(ReadOnlySequenceSegment startSegment, int startIndex, ReadOnlySequenceSegment endSegment, int endIndex) { if (startSegment == null || endSegment == null || (startSegment != endSegment && startSegment.RunningIndex > endSegment.RunningIndex) || (uint)startSegment.Memory.Length < (uint)startIndex || (uint)endSegment.Memory.Length < (uint)endIndex || (startSegment == endSegment && endIndex < startIndex)) { System.ThrowHelper.ThrowArgumentValidationException(startSegment, startIndex, endSegment); } _sequenceStart = new SequencePosition(startSegment, ReadOnlySequence.SegmentToSequenceStart(startIndex)); _sequenceEnd = new SequencePosition(endSegment, ReadOnlySequence.SegmentToSequenceEnd(endIndex)); } public ReadOnlySequence(T[] array) { System.ThrowHelper.ThrowIfArgumentNull(array, System.ExceptionArgument.array); _sequenceStart = new SequencePosition(array, ReadOnlySequence.ArrayToSequenceStart(0)); _sequenceEnd = new SequencePosition(array, ReadOnlySequence.ArrayToSequenceEnd(array.Length)); } public ReadOnlySequence(T[] array, int start, int length) { if (array == null || (uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start)) { System.ThrowHelper.ThrowArgumentValidationException(array, start); } _sequenceStart = new SequencePosition(array, ReadOnlySequence.ArrayToSequenceStart(start)); _sequenceEnd = new SequencePosition(array, ReadOnlySequence.ArrayToSequenceEnd(start + length)); } public ReadOnlySequence([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlyMemory memory) { ArraySegment segment; if (MemoryMarshal.TryGetMemoryManager>(memory, out var manager, out var start, out var length)) { _sequenceStart = new SequencePosition(manager, ReadOnlySequence.MemoryManagerToSequenceStart(start)); _sequenceEnd = new SequencePosition(manager, ReadOnlySequence.MemoryManagerToSequenceEnd(length)); } else if (MemoryMarshal.TryGetArray(memory, out segment)) { T[] array = segment.Array; int offset = segment.Offset; _sequenceStart = new SequencePosition(array, ReadOnlySequence.ArrayToSequenceStart(offset)); _sequenceEnd = new SequencePosition(array, ReadOnlySequence.ArrayToSequenceEnd(offset + segment.Count)); } else if (typeof(T) == typeof(char)) { if (!MemoryMarshal.TryGetString(Unsafe.As, ReadOnlyMemory>(ref memory), out var text, out var start2, out length)) { System.ThrowHelper.ThrowInvalidOperationException(); } _sequenceStart = new SequencePosition(text, ReadOnlySequence.StringToSequenceStart(start2)); _sequenceEnd = new SequencePosition(text, ReadOnlySequence.StringToSequenceEnd(start2 + length)); } else { System.ThrowHelper.ThrowInvalidOperationException(); _sequenceStart = default(SequencePosition); _sequenceEnd = default(SequencePosition); } } [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public ReadOnlySequence Slice(long start, long length) { if (start < 0 || length < 0) { System.ThrowHelper.ThrowStartOrEndArgumentValidationException(start); } int index = GetIndex(ref _sequenceStart); int index2 = GetIndex(ref _sequenceEnd); object @object = _sequenceStart.GetObject(); object object2 = _sequenceEnd.GetObject(); SequencePosition start2; SequencePosition end; if (@object != object2) { ReadOnlySequenceSegment readOnlySequenceSegment = (ReadOnlySequenceSegment)@object; int num = readOnlySequenceSegment.Memory.Length - index; if (num > start) { index += (int)start; start2 = new SequencePosition(@object, index); end = GetEndPosition(readOnlySequenceSegment, @object, index, object2, index2, length); } else { if (num < 0) { System.ThrowHelper.ThrowArgumentOutOfRangeException_PositionOutOfRange(); } start2 = SeekMultiSegment(readOnlySequenceSegment.Next, object2, index2, start - num, System.ExceptionArgument.start); int index3 = GetIndex(ref start2); object object3 = start2.GetObject(); if (object3 != object2) { end = GetEndPosition((ReadOnlySequenceSegment)object3, object3, index3, object2, index2, length); } else { if (index2 - index3 < length) { System.ThrowHelper.ThrowStartOrEndArgumentValidationException(0L); } end = new SequencePosition(object3, index3 + (int)length); } } } else { if (index2 - index < start) { System.ThrowHelper.ThrowStartOrEndArgumentValidationException(-1L); } index += (int)start; start2 = new SequencePosition(@object, index); if (index2 - index < length) { System.ThrowHelper.ThrowStartOrEndArgumentValidationException(0L); } end = new SequencePosition(@object, index + (int)length); } return SliceImpl(ref start2, ref end); } [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public ReadOnlySequence Slice(long start, SequencePosition end) { if (start < 0) { System.ThrowHelper.ThrowStartOrEndArgumentValidationException(start); } uint index = (uint)GetIndex(ref end); object @object = end.GetObject(); uint index2 = (uint)GetIndex(ref _sequenceStart); object object2 = _sequenceStart.GetObject(); uint index3 = (uint)GetIndex(ref _sequenceEnd); object object3 = _sequenceEnd.GetObject(); if (object2 == object3) { if (!InRange(index, index2, index3)) { System.ThrowHelper.ThrowArgumentOutOfRangeException_PositionOutOfRange(); } if (index - index2 < start) { System.ThrowHelper.ThrowStartOrEndArgumentValidationException(-1L); } } else { ReadOnlySequenceSegment readOnlySequenceSegment = (ReadOnlySequenceSegment)object2; ulong num = (ulong)(readOnlySequenceSegment.RunningIndex + index2); ulong num2 = (ulong)(((ReadOnlySequenceSegment)@object).RunningIndex + index); if (!InRange(num2, num, (ulong)(((ReadOnlySequenceSegment)object3).RunningIndex + index3))) { System.ThrowHelper.ThrowArgumentOutOfRangeException_PositionOutOfRange(); } if ((ulong)((long)num + start) > num2) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.start); } int num3 = readOnlySequenceSegment.Memory.Length - (int)index2; if (num3 <= start) { if (num3 < 0) { System.ThrowHelper.ThrowArgumentOutOfRangeException_PositionOutOfRange(); } SequencePosition start2 = SeekMultiSegment(readOnlySequenceSegment.Next, @object, (int)index, start - num3, System.ExceptionArgument.start); return SliceImpl(ref start2, ref end); } } SequencePosition start3 = new SequencePosition(object2, (int)index2 + (int)start); return SliceImpl(ref start3, ref end); } [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public ReadOnlySequence Slice(SequencePosition start, long length) { uint index = (uint)GetIndex(ref start); object @object = start.GetObject(); uint index2 = (uint)GetIndex(ref _sequenceStart); object object2 = _sequenceStart.GetObject(); uint index3 = (uint)GetIndex(ref _sequenceEnd); object object3 = _sequenceEnd.GetObject(); if (object2 == object3) { if (!InRange(index, index2, index3)) { System.ThrowHelper.ThrowArgumentOutOfRangeException_PositionOutOfRange(); } if (length < 0) { System.ThrowHelper.ThrowStartOrEndArgumentValidationException(0L); } if (index3 - index < length) { System.ThrowHelper.ThrowStartOrEndArgumentValidationException(0L); } } else { ReadOnlySequenceSegment readOnlySequenceSegment = (ReadOnlySequenceSegment)@object; long num = readOnlySequenceSegment.RunningIndex + index; ulong start2 = (ulong)(((ReadOnlySequenceSegment)object2).RunningIndex + index2); ulong num2 = (ulong)(((ReadOnlySequenceSegment)object3).RunningIndex + index3); if (!InRange((ulong)num, start2, num2)) { System.ThrowHelper.ThrowArgumentOutOfRangeException_PositionOutOfRange(); } if (length < 0) { System.ThrowHelper.ThrowStartOrEndArgumentValidationException(0L); } if ((ulong)(num + length) > num2) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.length); } int num3 = readOnlySequenceSegment.Memory.Length - (int)index; if (num3 < length) { if (num3 < 0) { System.ThrowHelper.ThrowArgumentOutOfRangeException_PositionOutOfRange(); } SequencePosition end = SeekMultiSegment(readOnlySequenceSegment.Next, object3, (int)index3, length - num3, System.ExceptionArgument.length); return SliceImpl(ref start, ref end); } } SequencePosition end2 = new SequencePosition(@object, (int)index + (int)length); return SliceImpl(ref start, ref end2); } [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public ReadOnlySequence Slice(int start, int length) { return Slice((long)start, (long)length); } [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public ReadOnlySequence Slice(int start, SequencePosition end) { return Slice((long)start, end); } [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public ReadOnlySequence Slice(SequencePosition start, int length) { return Slice(start, (long)length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public ReadOnlySequence Slice(SequencePosition start, SequencePosition end) { BoundsCheck((uint)GetIndex(ref start), start.GetObject(), (uint)GetIndex(ref end), end.GetObject()); return SliceImpl(ref start, ref end); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public ReadOnlySequence Slice(SequencePosition start) { BoundsCheck(ref start); return SliceImpl(ref start, ref _sequenceEnd); } [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public ReadOnlySequence Slice(long start) { if (start < 0) { System.ThrowHelper.ThrowStartOrEndArgumentValidationException(start); } if (start == 0L) { return this; } SequencePosition start2 = Seek(ref _sequenceStart, ref _sequenceEnd, start, System.ExceptionArgument.start); return SliceImpl(ref start2, ref _sequenceEnd); } public override string ToString() { if (typeof(T) == typeof(char)) { ReadOnlySequence source = this; ReadOnlySequence sequence = Unsafe.As, ReadOnlySequence>(ref source); if (SequenceMarshal.TryGetString(sequence, out var text, out var start, out var length)) { return text.Substring(start, length); } if (Length < int.MaxValue) { return new string(BuffersExtensions.ToArray(ref sequence)); } } return $"System.Buffers.ReadOnlySequence<{typeof(T).Name}>[{Length}]"; } [NullableContext(0)] public Enumerator GetEnumerator() { return new Enumerator(ref this); } public SequencePosition GetPosition(long offset) { return GetPosition(offset, _sequenceStart); } public SequencePosition GetPosition(long offset, SequencePosition origin) { if (offset < 0) { System.ThrowHelper.ThrowArgumentOutOfRangeException_OffsetOutOfRange(); } return Seek(ref origin, ref _sequenceEnd, offset, System.ExceptionArgument.offset); } public bool TryGet(ref SequencePosition position, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] out ReadOnlyMemory memory, bool advance = true) { SequencePosition next; bool result = TryGetBuffer(ref position, out memory, out next); if (advance) { position = next; } return result; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal bool TryGetBuffer([In][IsReadOnly] ref SequencePosition position, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] out ReadOnlyMemory memory, out SequencePosition next) { object @object = position.GetObject(); next = default(SequencePosition); if (@object == null) { memory = default(ReadOnlyMemory); return false; } SequenceType sequenceType = GetSequenceType(); object object2 = _sequenceEnd.GetObject(); int index = GetIndex(ref position); int index2 = GetIndex(ref _sequenceEnd); if (sequenceType == SequenceType.MultiSegment) { ReadOnlySequenceSegment readOnlySequenceSegment = (ReadOnlySequenceSegment)@object; if (readOnlySequenceSegment != object2) { ReadOnlySequenceSegment next2 = readOnlySequenceSegment.Next; if (next2 == null) { System.ThrowHelper.ThrowInvalidOperationException_EndPositionNotReached(); } next = new SequencePosition(next2, 0); memory = readOnlySequenceSegment.Memory.Slice(index); } else { memory = readOnlySequenceSegment.Memory.Slice(index, index2 - index); } } else { if (@object != object2) { System.ThrowHelper.ThrowInvalidOperationException_EndPositionNotReached(); } if (sequenceType == SequenceType.Array) { memory = new ReadOnlyMemory((T[])@object, index, index2 - index); } else if (typeof(T) == typeof(char) && sequenceType == SequenceType.String) { memory = (ReadOnlyMemory)(object)MemoryExtensions.AsMemory((string)@object, index, index2 - index); } else { memory = ((MemoryManager)@object).Memory.Slice(index, index2 - index); } } return true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] private ReadOnlyMemory GetFirstBuffer() { object @object = _sequenceStart.GetObject(); if (@object == null) { return default(ReadOnlyMemory); } int integer = _sequenceStart.GetInteger(); int integer2 = _sequenceEnd.GetInteger(); bool flag = @object != _sequenceEnd.GetObject(); if (integer >= 0) { if (integer2 >= 0) { ReadOnlyMemory memory = ((ReadOnlySequenceSegment)@object).Memory; if (flag) { return memory.Slice(integer); } return memory.Slice(integer, integer2 - integer); } if (flag) { System.ThrowHelper.ThrowInvalidOperationException_EndPositionNotReached(); } return new ReadOnlyMemory((T[])@object, integer, (integer2 & 0x7FFFFFFF) - integer); } if (flag) { System.ThrowHelper.ThrowInvalidOperationException_EndPositionNotReached(); } if (typeof(T) == typeof(char) && integer2 < 0) { return (ReadOnlyMemory)(object)MemoryExtensions.AsMemory((string)@object, integer & 0x7FFFFFFF, integer2 - integer); } integer &= 0x7FFFFFFF; return ((MemoryManager)@object).Memory.Slice(integer, integer2 - integer); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static SequencePosition Seek([In][IsReadOnly] ref SequencePosition start, [In][IsReadOnly] ref SequencePosition end, long offset, System.ExceptionArgument argument) { int index = GetIndex(ref start); int index2 = GetIndex(ref end); object @object = start.GetObject(); object object2 = end.GetObject(); if (@object != object2) { ReadOnlySequenceSegment readOnlySequenceSegment = (ReadOnlySequenceSegment)@object; int num = readOnlySequenceSegment.Memory.Length - index; if (num <= offset) { if (num < 0) { System.ThrowHelper.ThrowArgumentOutOfRangeException_PositionOutOfRange(); } return SeekMultiSegment(readOnlySequenceSegment.Next, object2, index2, offset - num, argument); } } else if (index2 - index < offset) { System.ThrowHelper.ThrowArgumentOutOfRangeException(argument); } return new SequencePosition(@object, index + (int)offset); } [MethodImpl(MethodImplOptions.NoInlining)] [NullableContext(2)] private static SequencePosition SeekMultiSegment([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] ReadOnlySequenceSegment currentSegment, object endObject, int endIndex, long offset, System.ExceptionArgument argument) { while (true) { if (currentSegment != null && currentSegment != endObject) { int length = currentSegment.Memory.Length; if (length > offset) { break; } offset -= length; currentSegment = currentSegment.Next; continue; } if (currentSegment == null || endIndex < offset) { System.ThrowHelper.ThrowArgumentOutOfRangeException(argument); } break; } return new SequencePosition(currentSegment, (int)offset); } private void BoundsCheck([In][IsReadOnly] ref SequencePosition position) { uint index = (uint)GetIndex(ref position); uint index2 = (uint)GetIndex(ref _sequenceStart); uint index3 = (uint)GetIndex(ref _sequenceEnd); object @object = _sequenceStart.GetObject(); object object2 = _sequenceEnd.GetObject(); if (@object == object2) { if (!InRange(index, index2, index3)) { System.ThrowHelper.ThrowArgumentOutOfRangeException_PositionOutOfRange(); } return; } ulong start = (ulong)(((ReadOnlySequenceSegment)@object).RunningIndex + index2); if (!InRange((ulong)(((ReadOnlySequenceSegment)position.GetObject()).RunningIndex + index), start, (ulong)(((ReadOnlySequenceSegment)object2).RunningIndex + index3))) { System.ThrowHelper.ThrowArgumentOutOfRangeException_PositionOutOfRange(); } } [NullableContext(2)] private void BoundsCheck(uint sliceStartIndex, object sliceStartObject, uint sliceEndIndex, object sliceEndObject) { uint index = (uint)GetIndex(ref _sequenceStart); uint index2 = (uint)GetIndex(ref _sequenceEnd); object @object = _sequenceStart.GetObject(); object object2 = _sequenceEnd.GetObject(); if (@object == object2) { if (sliceStartObject != sliceEndObject || sliceStartObject != @object || sliceStartIndex > sliceEndIndex || sliceStartIndex < index || sliceEndIndex > index2) { System.ThrowHelper.ThrowArgumentOutOfRangeException_PositionOutOfRange(); } return; } long num = ((ReadOnlySequenceSegment)sliceStartObject).RunningIndex + sliceStartIndex; ulong num2 = (ulong)(((ReadOnlySequenceSegment)sliceEndObject).RunningIndex + sliceEndIndex); if ((ulong)num > num2) { System.ThrowHelper.ThrowArgumentOutOfRangeException_PositionOutOfRange(); } if ((ulong)num < (ulong)(((ReadOnlySequenceSegment)@object).RunningIndex + index) || num2 > (ulong)(((ReadOnlySequenceSegment)object2).RunningIndex + index2)) { System.ThrowHelper.ThrowArgumentOutOfRangeException_PositionOutOfRange(); } } private static SequencePosition GetEndPosition(ReadOnlySequenceSegment startSegment, object startObject, int startIndex, object endObject, int endIndex, long length) { int num = startSegment.Memory.Length - startIndex; if (num > length) { return new SequencePosition(startObject, startIndex + (int)length); } if (num < 0) { System.ThrowHelper.ThrowArgumentOutOfRangeException_PositionOutOfRange(); } return SeekMultiSegment(startSegment.Next, endObject, endIndex, length - num, System.ExceptionArgument.length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(0)] private SequenceType GetSequenceType() { return (SequenceType)(-(2 * (_sequenceStart.GetInteger() >> 31) + (_sequenceEnd.GetInteger() >> 31))); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private static int GetIndex([In][IsReadOnly] ref SequencePosition position) { return position.GetInteger() & 0x7FFFFFFF; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] private ReadOnlySequence SliceImpl([In][IsReadOnly] ref SequencePosition start, [In][IsReadOnly] ref SequencePosition end) { return new ReadOnlySequence(start.GetObject(), GetIndex(ref start) | (_sequenceStart.GetInteger() & int.MinValue), end.GetObject(), GetIndex(ref end) | (_sequenceEnd.GetInteger() & int.MinValue)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private long GetLength() { int index = GetIndex(ref _sequenceStart); int index2 = GetIndex(ref _sequenceEnd); object @object = _sequenceStart.GetObject(); object object2 = _sequenceEnd.GetObject(); if (@object != object2) { ReadOnlySequenceSegment readOnlySequenceSegment = (ReadOnlySequenceSegment)@object; return ((ReadOnlySequenceSegment)object2).RunningIndex + index2 - (readOnlySequenceSegment.RunningIndex + index); } return index2 - index; } internal bool TryGetReadOnlySequenceSegment([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] out ReadOnlySequenceSegment startSegment, out int startIndex, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] out ReadOnlySequenceSegment endSegment, out int endIndex) { object @object = _sequenceStart.GetObject(); if (@object == null || GetSequenceType() != 0) { startSegment = null; startIndex = 0; endSegment = null; endIndex = 0; return false; } startSegment = (ReadOnlySequenceSegment)@object; startIndex = GetIndex(ref _sequenceStart); endSegment = (ReadOnlySequenceSegment)_sequenceEnd.GetObject(); endIndex = GetIndex(ref _sequenceEnd); return true; } internal bool TryGetArray([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] out ArraySegment segment) { if (GetSequenceType() != SequenceType.Array) { segment = default(ArraySegment); return false; } int index = GetIndex(ref _sequenceStart); segment = new ArraySegment((T[])_sequenceStart.GetObject(), index, GetIndex(ref _sequenceEnd) - index); return true; } internal bool TryGetString([MaybeNullWhen(false)] out string text, out int start, out int length) { if (typeof(T) != typeof(char) || GetSequenceType() != SequenceType.String) { start = 0; length = 0; text = null; return false; } start = GetIndex(ref _sequenceStart); length = GetIndex(ref _sequenceEnd) - start; text = (string)_sequenceStart.GetObject(); return true; } private static bool InRange(uint value, uint start, uint end) { return value - start <= end - start; } private static bool InRange(ulong value, ulong start, ulong end) { return value - start <= end - start; } } internal static class ReadOnlySequence { public const int FlagBitMask = int.MinValue; public const int IndexBitMask = int.MaxValue; public const int SegmentStartMask = 0; public const int SegmentEndMask = 0; public const int ArrayStartMask = 0; public const int ArrayEndMask = int.MinValue; public const int MemoryManagerStartMask = int.MinValue; public const int MemoryManagerEndMask = 0; public const int StringStartMask = int.MinValue; public const int StringEndMask = int.MinValue; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int SegmentToSequenceStart(int startIndex) { return startIndex | 0; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int SegmentToSequenceEnd(int endIndex) { return endIndex | 0; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int ArrayToSequenceStart(int startIndex) { return startIndex | 0; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int ArrayToSequenceEnd(int endIndex) { return endIndex | int.MinValue; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int MemoryManagerToSequenceStart(int startIndex) { return startIndex | int.MinValue; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int MemoryManagerToSequenceEnd(int endIndex) { return endIndex | 0; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int StringToSequenceStart(int startIndex) { return startIndex | int.MinValue; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int StringToSequenceEnd(int endIndex) { return endIndex | int.MinValue; } } internal sealed class ReadOnlySequenceDebugView<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T> { [DebuggerDisplay("Count: {Segments.Length}", Name = "Segments")] public struct ReadOnlySequenceDebugViewSegments { [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)] [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 1, 0, 1 })] public ReadOnlyMemory[] Segments { [IsReadOnly] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 1, 0, 1 })] get; [param: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 1, 0, 1 })] set; } } [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(1)] private readonly T[] _array; private readonly ReadOnlySequenceDebugViewSegments _segments; public ReadOnlySequenceDebugViewSegments BufferSegments => _segments; [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(1)] [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)] public T[] Items { [NullableContext(1)] get { return _array; } } public ReadOnlySequenceDebugView([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySequence sequence) { _array = BuffersExtensions.ToArray(ref sequence); int num = 0; ReadOnlySequence.Enumerator enumerator = sequence.GetEnumerator(); while (enumerator.MoveNext()) { _ = enumerator.Current; num++; } ReadOnlyMemory[] array = new ReadOnlyMemory[num]; int num2 = 0; enumerator = sequence.GetEnumerator(); while (enumerator.MoveNext()) { ReadOnlyMemory current = enumerator.Current; array[num2] = current; num2++; } _segments = new ReadOnlySequenceDebugViewSegments { Segments = array }; } } internal abstract class ReadOnlySequenceSegment<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T> { [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public ReadOnlyMemory Memory { [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] get; [param: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] protected set; } [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] public ReadOnlySequenceSegment Next { [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] get; [param: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] protected set; } public long RunningIndex { get; protected set; } } [IsReadOnly] internal struct StandardFormat : IEquatable { public const byte NoPrecision = byte.MaxValue; public const byte MaxPrecision = 99; private readonly byte _format; private readonly byte _precision; public char Symbol => (char)_format; public byte Precision => _precision; public bool HasPrecision => _precision != byte.MaxValue; public bool IsDefault { get { if (_format == 0) { return _precision == 0; } return false; } } public StandardFormat(char symbol, byte precision = byte.MaxValue) { if (precision != byte.MaxValue && precision > 99) { System.ThrowHelper.ThrowArgumentOutOfRangeException_PrecisionTooLarge(); } if (symbol != (byte)symbol) { System.ThrowHelper.ThrowArgumentOutOfRangeException_SymbolDoesNotFit(); } _format = (byte)symbol; _precision = precision; } public static implicit operator StandardFormat(char symbol) { return new StandardFormat(symbol); } public static StandardFormat Parse(ReadOnlySpan format) { if (format.Length == 0) { return default(StandardFormat); } char symbol = format[0]; byte precision; if (format.Length == 1) { precision = byte.MaxValue; } else { uint num = 0u; for (int i = 1; i < format.Length; i++) { uint num2 = (uint)(format[i] - 48); if (num2 > 9) { throw new FormatException($"Cannot parse precision (max is {99})"); } num = num * 10 + num2; if (num > 99) { throw new FormatException($"Precision is larger than the maximum {99}"); } } precision = (byte)num; } return new StandardFormat(symbol, precision); } [NullableContext(2)] public static StandardFormat Parse(string format) { if (format != null) { return Parse(MemoryExtensions.AsSpan(format)); } return default(StandardFormat); } [NullableContext(2)] public override bool Equals(object obj) { if (obj is StandardFormat other) { return Equals(other); } return false; } public override int GetHashCode() { byte format = _format; int hashCode = format.GetHashCode(); format = _precision; return hashCode ^ format.GetHashCode(); } public bool Equals(StandardFormat other) { if (_format == other._format) { return _precision == other._precision; } return false; } [NullableContext(1)] public unsafe override string ToString() { char* ptr = stackalloc char[4]; int length = 0; char symbol = Symbol; if (symbol != 0) { ptr[length++] = symbol; byte b = Precision; if (b != byte.MaxValue) { if (b >= 100) { ptr[length++] = (char)(48 + b / 100 % 10); b %= 100; } if (b >= 10) { ptr[length++] = (char)(48 + b / 10 % 10); b %= 10; } ptr[length++] = (char)(48 + b); } } return new string(ptr, 0, length); } public static bool operator ==(StandardFormat left, StandardFormat right) { return left.Equals(right); } public static bool operator !=(StandardFormat left, StandardFormat right) { return !left.Equals(right); } } [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] internal sealed class TlsOverPerCoreLockedStacksArrayPool<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T> : ArrayPool { private sealed class PerCoreLockedStacks { private static readonly int s_lockedStackCount = Math.Min(Environment.ProcessorCount, 64); [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 1, 1, 0 })] private readonly LockedStack[] _perCoreStacks; public PerCoreLockedStacks() { LockedStack[] array = new LockedStack[s_lockedStackCount]; for (int i = 0; i < array.Length; i++) { array[i] = new LockedStack(); } _perCoreStacks = array; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(1)] public bool TryPush(T[] array) { LockedStack[] perCoreStacks = _perCoreStacks; int num = (int)((uint)EnvironmentEx.CurrentManagedThreadId % (uint)s_lockedStackCount); for (int i = 0; i < perCoreStacks.Length; i++) { if (perCoreStacks[num].TryPush(array)) { return true; } if (++num == perCoreStacks.Length) { num = 0; } } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] public T[] TryPop() { LockedStack[] perCoreStacks = _perCoreStacks; int num = (int)((uint)EnvironmentEx.CurrentManagedThreadId % (uint)s_lockedStackCount); for (int i = 0; i < perCoreStacks.Length; i++) { T[] result; if ((result = perCoreStacks[num].TryPop()) != null) { return result; } if (++num == perCoreStacks.Length) { num = 0; } } return null; } public void Trim(int currentMilliseconds, int id, System.Buffers.Utilities.MemoryPressure pressure, int bucketSize) { LockedStack[] perCoreStacks = _perCoreStacks; for (int i = 0; i < perCoreStacks.Length; i++) { perCoreStacks[i].Trim(currentMilliseconds, id, pressure, bucketSize); } } } private sealed class LockedStack { [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 1, 2, 1 })] private readonly T[][] _arrays = new T[8][]; private int _count; private int _millisecondsTimestamp; [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(1)] public bool TryPush(T[] array) { bool result = false; Monitor.Enter(this); T[][] arrays = _arrays; int count = _count; if ((uint)count < (uint)arrays.Length) { if (count == 0) { _millisecondsTimestamp = 0; } arrays[count] = array; _count = count + 1; result = true; } Monitor.Exit(this); return result; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] public T[] TryPop() { T[] result = null; Monitor.Enter(this); T[][] arrays = _arrays; int num = _count - 1; if ((uint)num < (uint)arrays.Length) { result = arrays[num]; arrays[num] = null; _count = num; } Monitor.Exit(this); return result; } public void Trim(int currentMilliseconds, int id, System.Buffers.Utilities.MemoryPressure pressure, int bucketSize) { if (_count == 0) { return; } int num = ((pressure == System.Buffers.Utilities.MemoryPressure.High) ? 10000 : 60000); lock (this) { if (_count == 0) { return; } if (_millisecondsTimestamp == 0) { _millisecondsTimestamp = currentMilliseconds; } else { if (currentMilliseconds - _millisecondsTimestamp <= num) { return; } int num2 = 1; switch (pressure) { case System.Buffers.Utilities.MemoryPressure.High: num2 = 8; if (bucketSize > 16384) { num2++; } if (Unsafe.SizeOf() > 16) { num2++; } if (Unsafe.SizeOf() > 32) { num2++; } break; case System.Buffers.Utilities.MemoryPressure.Medium: num2 = 2; break; } while (_count > 0 && num2-- > 0) { _ = _arrays[--_count]; _arrays[_count] = null; } _millisecondsTimestamp = ((_count > 0) ? (_millisecondsTimestamp + num / 4) : 0); } } } } private struct ThreadLocalArray { [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] public T[] Array; public int MillisecondsTimeStamp; [NullableContext(1)] public ThreadLocalArray(T[] array) { Array = array; MillisecondsTimeStamp = 0; } } private const int NumBuckets = 27; private const int MaxPerCorePerArraySizeStacks = 64; private const int MaxBuffersPerArraySizePerCore = 8; [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 0, 0 })] [ThreadStatic] private static ThreadLocalArray[] t_tlsBuckets; [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 1, 1, 0, 0, 2 })] private readonly ConditionalWeakTable _allTlsBuckets = new ConditionalWeakTable(); [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 1, 2, 0 })] private readonly PerCoreLockedStacks[] _buckets = new PerCoreLockedStacks[27]; private int _trimCallbackCreated; private int Id => GetHashCode(); [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 1, 0 })] private PerCoreLockedStacks CreatePerCoreLockedStacks(int bucketIndex) { PerCoreLockedStacks perCoreLockedStacks = new PerCoreLockedStacks(); return Interlocked.CompareExchange(ref _buckets[bucketIndex], perCoreLockedStacks, null) ?? perCoreLockedStacks; } [NullableContext(1)] public override T[] Rent(int minimumLength) { int num = System.Buffers.Utilities.SelectBucketIndex(minimumLength); ThreadLocalArray[] array = t_tlsBuckets; if (array != null && (uint)num < (uint)array.Length) { T[] array2 = array[num].Array; if (array2 != null) { array[num].Array = null; return array2; } } PerCoreLockedStacks[] buckets = _buckets; if ((uint)num < (uint)buckets.Length) { PerCoreLockedStacks perCoreLockedStacks = buckets[num]; if (perCoreLockedStacks != null) { T[] array2 = perCoreLockedStacks.TryPop(); if (array2 != null) { return array2; } } minimumLength = System.Buffers.Utilities.GetMaxSizeForBucket(num); } else { if (minimumLength == 0) { return ArrayEx.Empty(); } if (minimumLength < 0) { throw new ArgumentOutOfRangeException("minimumLength"); } } return new T[minimumLength]; } [NullableContext(1)] public override void Return(T[] array, bool clearArray = false) { if (array == null) { System.ThrowHelper.ThrowArgumentNullException(System.ExceptionArgument.array); } int num = System.Buffers.Utilities.SelectBucketIndex(array.Length); ThreadLocalArray[] array2 = t_tlsBuckets ?? InitializeTlsBucketsAndTrimming(); if ((uint)num < (uint)array2.Length) { if (clearArray) { Array.Clear(array, 0, array.Length); } if (array.Length != System.Buffers.Utilities.GetMaxSizeForBucket(num)) { throw new ArgumentException("Buffer not from this pool", "array"); } ref ThreadLocalArray reference = ref array2[num]; T[] array3 = reference.Array; reference = new ThreadLocalArray(array); if (array3 != null) { (_buckets[num] ?? CreatePerCoreLockedStacks(num)).TryPush(array3); } } } public bool Trim() { int tickCount = Environment.TickCount; System.Buffers.Utilities.MemoryPressure memoryPressure = System.Buffers.Utilities.GetMemoryPressure(); PerCoreLockedStacks[] buckets = _buckets; for (int i = 0; i < buckets.Length; i++) { buckets[i]?.Trim(tickCount, Id, memoryPressure, System.Buffers.Utilities.GetMaxSizeForBucket(i)); } if (memoryPressure == System.Buffers.Utilities.MemoryPressure.High) { foreach (KeyValuePair allTlsBucket in _allTlsBuckets) { Array.Clear(allTlsBucket.Key, 0, allTlsBucket.Key.Length); } } else { uint num = ((memoryPressure != System.Buffers.Utilities.MemoryPressure.Medium) ? 30000u : 15000u); uint num2 = num; foreach (KeyValuePair allTlsBucket2 in _allTlsBuckets) { ThreadLocalArray[] key = allTlsBucket2.Key; for (int j = 0; j < key.Length; j++) { if (key[j].Array != null) { int millisecondsTimeStamp = key[j].MillisecondsTimeStamp; if (millisecondsTimeStamp == 0) { key[j].MillisecondsTimeStamp = tickCount; } else if (tickCount - millisecondsTimeStamp >= num2) { Interlocked.Exchange(ref key[j].Array, null); } } } } } if (!Environment.HasShutdownStarted) { return !AppDomain.CurrentDomain.IsFinalizingForUnload(); } return false; } [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 1, 0, 0 })] private ThreadLocalArray[] InitializeTlsBucketsAndTrimming() { ThreadLocalArray[] array = (t_tlsBuckets = new ThreadLocalArray[27]); _allTlsBuckets.Add(array, null); if (Interlocked.Exchange(ref _trimCallbackCreated, 1) == 0) { System.Gen2GcCallback.Register([NullableContext(1)] (object s) => ((System.Buffers.TlsOverPerCoreLockedStacksArrayPool)s).Trim(), this); } return array; } } internal static class Utilities { internal enum MemoryPressure { Low, Medium, High } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static int SelectBucketIndex(int bufferSize) { return BitOperations.Log2((uint)(bufferSize - 1) | 0xFu) - 3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static int GetMaxSizeForBucket(int binIndex) { return 16 << binIndex; } internal static MemoryPressure GetMemoryPressure() { return MemoryPressure.Low; } } } namespace System.Runtime { [NullableContext(2)] [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] internal struct DependentHandle : IDisposable { [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] private sealed class DependentHolder : CriticalFinalizerObject { public GCHandle TargetHandle; private IntPtr dependent; public object Dependent { get { return GCHandle.FromIntPtr(dependent).Target; } set { IntPtr value2 = GCHandle.ToIntPtr(GCHandle.Alloc(value, GCHandleType.Normal)); IntPtr intPtr; do { intPtr = dependent; } while (Interlocked.CompareExchange(ref dependent, value2, intPtr) == intPtr); GCHandle.FromIntPtr(intPtr).Free(); } } [NullableContext(1)] public DependentHolder(GCHandle targetHandle, object dependent) { TargetHandle = targetHandle; this.dependent = GCHandle.ToIntPtr(GCHandle.Alloc(dependent, GCHandleType.Normal)); } ~DependentHolder() { if (!AppDomain.CurrentDomain.IsFinalizingForUnload() && (!Environment.HasShutdownStarted && (TargetHandle.IsAllocated && TargetHandle.Target != null))) { GC.ReRegisterForFinalize(this); } else { GCHandle.FromIntPtr(dependent).Free(); } } } private GCHandle dependentHandle; private volatile bool allocated; public bool IsAllocated => allocated; public object Target { get { if (!allocated) { throw new InvalidOperationException(); } return UnsafeGetTarget(); } set { if (!allocated || value != null) { throw new InvalidOperationException(); } UnsafeSetTargetToNull(); } } public object Dependent { get { if (!allocated) { throw new InvalidOperationException(); } return UnsafeGetHolder()?.Dependent; } set { if (!allocated) { throw new InvalidOperationException(); } UnsafeSetDependent(value); } } [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 2, 2 })] public (object Target, object Dependent) TargetAndDependent { [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 2, 2 })] get { if (!allocated) { throw new InvalidOperationException(); } return (UnsafeGetTarget(), Dependent); } } public DependentHandle(object target, object dependent) { GCHandle targetHandle = GCHandle.Alloc(target, GCHandleType.WeakTrackResurrection); dependentHandle = AllocDepHolder(targetHandle, dependent); GC.KeepAlive(target); allocated = true; } private static GCHandle AllocDepHolder(GCHandle targetHandle, object dependent) { return GCHandle.Alloc((dependent != null) ? new DependentHolder(targetHandle, dependent) : null, GCHandleType.WeakTrackResurrection); } private DependentHolder UnsafeGetHolder() { return Unsafe.As(dependentHandle.Target); } internal object UnsafeGetTarget() { return UnsafeGetHolder()?.TargetHandle.Target; } internal object UnsafeGetTargetAndDependent(out object dependent) { dependent = null; DependentHolder dependentHolder = UnsafeGetHolder(); if (dependentHolder == null) { return null; } object target = dependentHolder.TargetHandle.Target; if (target == null) { return null; } dependent = dependentHolder.Dependent; return target; } internal void UnsafeSetTargetToNull() { Free(); } internal void UnsafeSetDependent(object value) { DependentHolder dependentHolder = UnsafeGetHolder(); if (dependentHolder != null) { if (!dependentHolder.TargetHandle.IsAllocated) { Free(); } else { dependentHolder.Dependent = value; } } } private void FreeDependentHandle() { if (allocated) { UnsafeGetHolder()?.TargetHandle.Free(); dependentHandle.Free(); } allocated = false; } private void Free() { FreeDependentHandle(); } public void Dispose() { Free(); allocated = false; } } } namespace System.Runtime.InteropServices { internal static class MemoryMarshal { [NullableContext(2)] public static bool TryGetArray([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlyMemory memory, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] out ArraySegment segment) { int start; int length; object objectStartLength = memory.GetObjectStartLength(out start, out length); if (start < 0) { if (((MemoryManager)objectStartLength).TryGetArray(out var segment2)) { segment = new ArraySegment(segment2.Array, segment2.Offset + (start & 0x7FFFFFFF), length); return true; } } else if (objectStartLength is T[] array) { segment = new ArraySegment(array, start, length & 0x7FFFFFFF); return true; } if ((length & 0x7FFFFFFF) == 0) { segment = new ArraySegment(System.SpanHelpers.PerTypeValues.EmptyArray); return true; } segment = default(ArraySegment); return false; } [NullableContext(2)] public static bool TryGetMemoryManagerNullable(0)] TManager>([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlyMemory memory, out TManager manager) where TManager : MemoryManager { int start; int length; return (manager = memory.GetObjectStartLength(out start, out length) as TManager) != null; } [NullableContext(2)] public static bool TryGetMemoryManagerNullable(0)] TManager>([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlyMemory memory, out TManager manager, out int start, out int length) where TManager : MemoryManager { TManager val = (manager = memory.GetObjectStartLength(out start, out length) as TManager); start &= int.MaxValue; if (val == null) { start = 0; length = 0; return false; } return true; } [NullableContext(1)] public static IEnumerable ToEnumerable<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T>([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlyMemory memory) { for (int i = 0; i < memory.Length; i++) { yield return memory.Span[i]; } } public static bool TryGetString(ReadOnlyMemory memory, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] out string text, out int start, out int length) { if (memory.GetObjectStartLength(out var start2, out var length2) is string text2) { text = text2; start = start2; length = length2; return true; } text = null; start = 0; length = 0; return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T Read(ReadOnlySpan source) where T : struct { if (System.SpanHelpers.IsReferenceOrContainsReferences()) { System.ThrowHelper.ThrowArgumentException_InvalidTypeWithPointersNotSupported(typeof(T)); } if (Unsafe.SizeOf() > source.Length) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.length); } return Unsafe.ReadUnaligned(ref GetReference(source)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryRead(ReadOnlySpan source, out T value) where T : struct { if (System.SpanHelpers.IsReferenceOrContainsReferences()) { System.ThrowHelper.ThrowArgumentException_InvalidTypeWithPointersNotSupported(typeof(T)); } if (Unsafe.SizeOf() > (uint)source.Length) { value = default(T); return false; } value = Unsafe.ReadUnaligned(ref GetReference(source)); return true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Write(Span destination, ref T value) where T : struct { if (System.SpanHelpers.IsReferenceOrContainsReferences()) { System.ThrowHelper.ThrowArgumentException_InvalidTypeWithPointersNotSupported(typeof(T)); } if ((uint)Unsafe.SizeOf() > (uint)destination.Length) { System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.length); } Unsafe.WriteUnaligned(ref GetReference(destination), value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TryWrite(Span destination, ref T value) where T : struct { if (System.SpanHelpers.IsReferenceOrContainsReferences()) { System.ThrowHelper.ThrowArgumentException_InvalidTypeWithPointersNotSupported(typeof(T)); } if (Unsafe.SizeOf() > (uint)destination.Length) { return false; } Unsafe.WriteUnaligned(ref GetReference(destination), value); return true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(1)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static Memory CreateFromPinnedArray<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T>(T[] array, int start, int length) { if (array == null) { if (start != 0 || length != 0) { System.ThrowHelper.ThrowArgumentOutOfRangeException(); } return default(Memory); } if (default(T) == null && array.GetType() != typeof(T[])) { System.ThrowHelper.ThrowArrayTypeMismatchException(); } if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start)) { System.ThrowHelper.ThrowArgumentOutOfRangeException(); } return new Memory((object)array, start, length | int.MinValue); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Span AsBytes(Span span) where T : struct { if (System.SpanHelpers.IsReferenceOrContainsReferences()) { System.ThrowHelper.ThrowArgumentException_InvalidTypeWithPointersNotSupported(typeof(T)); } int length = checked(span.Length * Unsafe.SizeOf()); return new Span(Unsafe.As>(span.Pinnable), span.ByteOffset, length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ReadOnlySpan AsBytes(ReadOnlySpan span) where T : struct { if (System.SpanHelpers.IsReferenceOrContainsReferences()) { System.ThrowHelper.ThrowArgumentException_InvalidTypeWithPointersNotSupported(typeof(T)); } int length = checked(span.Length * Unsafe.SizeOf()); return new ReadOnlySpan(Unsafe.As>(span.Pinnable), span.ByteOffset, length); } [NullableContext(2)] [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] public static Memory AsMemory([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlyMemory memory) { return Unsafe.As, Memory>(ref memory); } [NullableContext(1)] public unsafe static ref T GetReference<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T>([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] Span span) { if (span.Pinnable == null) { return ref Unsafe.AsRef(span.ByteOffset.ToPointer()); } return ref Unsafe.AddByteOffset(ref span.Pinnable.Data, span.ByteOffset); } [NullableContext(1)] public unsafe static ref T GetReference<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T>([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySpan span) { if (span.Pinnable == null) { return ref Unsafe.AsRef(span.ByteOffset.ToPointer()); } return ref Unsafe.AddByteOffset(ref span.Pinnable.Data, span.ByteOffset); } public static Span Cast(Span span) where TFrom : struct where TTo : struct { if (System.SpanHelpers.IsReferenceOrContainsReferences()) { System.ThrowHelper.ThrowArgumentException_InvalidTypeWithPointersNotSupported(typeof(TFrom)); } if (System.SpanHelpers.IsReferenceOrContainsReferences()) { System.ThrowHelper.ThrowArgumentException_InvalidTypeWithPointersNotSupported(typeof(TTo)); } checked { int length = (int)unchecked(checked(unchecked((long)span.Length) * unchecked((long)Unsafe.SizeOf())) / Unsafe.SizeOf()); return new Span(Unsafe.As>(span.Pinnable), span.ByteOffset, length); } } public static ReadOnlySpan Cast(ReadOnlySpan span) where TFrom : struct where TTo : struct { if (System.SpanHelpers.IsReferenceOrContainsReferences()) { System.ThrowHelper.ThrowArgumentException_InvalidTypeWithPointersNotSupported(typeof(TFrom)); } if (System.SpanHelpers.IsReferenceOrContainsReferences()) { System.ThrowHelper.ThrowArgumentException_InvalidTypeWithPointersNotSupported(typeof(TTo)); } checked { int length = (int)unchecked(checked(unchecked((long)span.Length) * unchecked((long)Unsafe.SizeOf())) / Unsafe.SizeOf()); return new ReadOnlySpan(Unsafe.As>(span.Pinnable), span.ByteOffset, length); } } } [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] [NullableContext(2)] internal static class SequenceMarshal { public static bool TryGetReadOnlySequenceSegment([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySequence sequence, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] out ReadOnlySequenceSegment startSegment, out int startIndex, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 1 })] out ReadOnlySequenceSegment endSegment, out int endIndex) { return sequence.TryGetReadOnlySequenceSegment(out startSegment, out startIndex, out endSegment, out endIndex); } public static bool TryGetArray([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySequence sequence, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] out ArraySegment segment) { return sequence.TryGetArray(out segment); } public static bool TryGetReadOnlyMemory([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] ReadOnlySequence sequence, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 0, 1 })] out ReadOnlyMemory memory) { if (!sequence.IsSingleSegment) { memory = default(ReadOnlyMemory); return false; } memory = sequence.First; return true; } [NullableContext(0)] internal static bool TryGetString(ReadOnlySequence sequence, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(1)][MaybeNullWhen(false)] out string text, out int start, out int length) { return sequence.TryGetString(out text, out start, out length); } } [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] [NullableContext(2)] internal static class MarshalEx { private static readonly MethodInfo Marshal_SetLastWin32Error_Meth = typeof(Marshal).GetMethod("SetLastPInvokeError", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) ?? typeof(Marshal).GetMethod("SetLastWin32Error", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); private static readonly Action Marshal_SetLastWin32Error = (((object)Marshal_SetLastWin32Error_Meth == null) ? null : ((Action)Delegate.CreateDelegate(typeof(Action), Marshal_SetLastWin32Error_Meth))); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int GetLastPInvokeError() { return Marshal.GetLastWin32Error(); } public static void SetLastPInvokeError(int error) { (Marshal_SetLastWin32Error ?? throw new PlatformNotSupportedException("Cannot set last P/Invoke error (no method Marshal.SetLastWin32Error or Marshal.SetLastPInvokeError)"))(error); } } } namespace System.Runtime.CompilerServices { [DebuggerNonUserCode] [ExcludeFromCodeCoverage] internal static class IsExternalInit { } [NullableContext(1)] [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] internal sealed class CallerArgumentExpressionAttribute : Attribute { public string ParameterName { get; } public CallerArgumentExpressionAttribute(string parameterName) { ParameterName = parameterName; } } [NullableContext(1)] internal interface ICWTEnumerable<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T> { IEnumerable SelfEnumerable { get; } IEnumerator GetEnumerator(); } [NullableContext(1)] [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] internal sealed class CWTEnumerableNullable(2)] TValue> : IEnumerable>, IEnumerable where TKey : class where TValue : class { private readonly ConditionalWeakTable cwt; public CWTEnumerable(ConditionalWeakTable table) { cwt = table; } [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 1, 0, 1, 1 })] public IEnumerator> GetEnumerator() { return cwt.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } [NullableContext(1)] [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] internal static class ConditionalWeakTableExtensions { [NullableContext(0)] private static class CWTInfoHolder<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(1)] TKey, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] TValue> where TKey : class where TValue : class { public delegate IEnumerable GetKeys(ConditionalWeakTable cwt); [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] private static readonly MethodInfo get_KeysMethod; [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 2, 0, 0 })] public static readonly GetKeys get_Keys; static CWTInfoHolder() { get_KeysMethod = typeof(ConditionalWeakTable).GetProperty("Keys", BindingFlags.Instance | BindingFlags.NonPublic)?.GetGetMethod(nonPublic: true); if ((object)get_KeysMethod != null) { get_Keys = (GetKeys)Delegate.CreateDelegate(typeof(GetKeys), get_KeysMethod); } } } [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 1, 0, 1, 1 })] public static IEnumerable> AsEnumerableNullable(2)] TValue>(this ConditionalWeakTable self) where TKey : class where TValue : class { System.ThrowHelper.ThrowIfArgumentNull(self, "self"); if (self is IEnumerable> result) { return result; } if (self is ICWTEnumerable> iCWTEnumerable) { return iCWTEnumerable.SelfEnumerable; } return new CWTEnumerable(self); } [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 1, 0, 1, 1 })] public static IEnumerator> GetEnumeratorNullable(2)] TValue>(this ConditionalWeakTable self) where TKey : class where TValue : class { System.ThrowHelper.ThrowIfArgumentNull(self, "self"); if (self is IEnumerable> enumerable) { return enumerable.GetEnumerator(); } if (self is ICWTEnumerable> iCWTEnumerable) { return iCWTEnumerable.GetEnumerator(); } CWTInfoHolder.GetKeys get_Keys = CWTInfoHolder.get_Keys; if (get_Keys != null) { return Enumerate(self, get_Keys(self)); } throw new PlatformNotSupportedException("Could not get Keys property of ConditionalWeakTable to enumerate it"); [return: <89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 1, 0, 1, 0 })] static IEnumerator> Enumerate([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(new byte[] { 1, 1, 0 })] ConditionalWeakTable cwt, IEnumerable keys) { foreach (TKey key in keys) { if (cwt.TryGetValue(key, out var value)) { yield return new KeyValuePair(key, value); } } } } public static void ClearNullable(2)] TValue>(this ConditionalWeakTable self) where TKey : class where TValue : class { System.ThrowHelper.ThrowIfArgumentNull(self, "self"); using IEnumerator> enumerator = self.GetEnumerator(); while (enumerator.MoveNext()) { self.Remove(enumerator.Current.Key); } } public static bool TryAddNullable(2)] TValue>(this ConditionalWeakTable self, TKey key, TValue value) where TKey : class where TValue : class { System.ThrowHelper.ThrowIfArgumentNull(self, "self"); bool didAdd = false; self.GetValue(key, [NullableContext(0)] ([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(1)] TKey _) => { didAdd = true; return value; }); return didAdd; } } [InterpolatedStringHandler] [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] [NullableContext(2)] internal ref struct DefaultInterpolatedStringHandler { private const int GuessedLengthPerHole = 11; private const int MinimumArrayPoolLength = 256; private readonly IFormatProvider _provider; private char[] _arrayToReturnToPool; [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] private Span _chars; private int _pos; private readonly bool _hasCustomFormatter; [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] internal ReadOnlySpan Text { [NullableContext(0)] get { return _chars.Slice(0, _pos); } } public DefaultInterpolatedStringHandler(int literalLength, int formattedCount) { _provider = null; _chars = (_arrayToReturnToPool = ArrayPool.Shared.Rent(GetDefaultLength(literalLength, formattedCount))); _pos = 0; _hasCustomFormatter = false; } public DefaultInterpolatedStringHandler(int literalLength, int formattedCount, IFormatProvider provider) { _provider = provider; _chars = (_arrayToReturnToPool = ArrayPool.Shared.Rent(GetDefaultLength(literalLength, formattedCount))); _pos = 0; _hasCustomFormatter = provider != null && HasCustomFormatter(provider); } [NullableContext(0)] public DefaultInterpolatedStringHandler(int literalLength, int formattedCount, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] IFormatProvider provider, Span initialBuffer) { _provider = provider; _chars = initialBuffer; _arrayToReturnToPool = null; _pos = 0; _hasCustomFormatter = provider != null && HasCustomFormatter(provider); } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static int GetDefaultLength(int literalLength, int formattedCount) { return Math.Max(256, literalLength + formattedCount * 11); } [NullableContext(1)] public override string ToString() { return Text.ToString(); } [NullableContext(1)] public string ToStringAndClear() { string result = Text.ToString(); Clear(); return result; } [MethodImpl(MethodImplOptions.AggressiveInlining)] internal void Clear() { char[] arrayToReturnToPool = _arrayToReturnToPool; this = default(DefaultInterpolatedStringHandler); if (arrayToReturnToPool != null) { ArrayPool.Shared.Return(arrayToReturnToPool); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(1)] public void AppendLiteral(string value) { if (value.Length == 1) { Span chars = _chars; int pos = _pos; if ((uint)pos < (uint)chars.Length) { chars[pos] = value[0]; _pos = pos + 1; } else { GrowThenCopyString(value); } } else if (value.Length == 2) { Span chars2 = _chars; int pos2 = _pos; if ((uint)pos2 < chars2.Length - 1) { MemoryExtensions.AsSpan(value).CopyTo(chars2.Slice(pos2)); _pos = pos2 + 2; } else { GrowThenCopyString(value); } } else { AppendStringDirect(value); } } [NullableContext(1)] private void AppendStringDirect(string value) { if (MemoryExtensions.AsSpan(value).TryCopyTo(_chars.Slice(_pos))) { _pos += value.Length; } else { GrowThenCopyString(value); } } [NullableContext(1)] public void AppendFormatted<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T>(T value) { if (_hasCustomFormatter) { AppendCustomFormatter(value, null); return; } if (typeof(T) == typeof(IntPtr)) { AppendFormatted(Unsafe.As(ref value)); return; } if (typeof(T) == typeof(UIntPtr)) { AppendFormatted(Unsafe.As(ref value)); return; } string text = ((!(value is IFormattable)) ? value?.ToString() : ((IFormattable)(object)value).ToString(null, _provider)); if (text != null) { AppendStringDirect(text); } } public void AppendFormatted([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(1)] T value, string format) { if (_hasCustomFormatter) { AppendCustomFormatter(value, format); return; } if (typeof(T) == typeof(IntPtr)) { AppendFormatted(Unsafe.As(ref value), format); return; } if (typeof(T) == typeof(UIntPtr)) { AppendFormatted(Unsafe.As(ref value), format); return; } string text = ((!(value is IFormattable)) ? value?.ToString() : ((IFormattable)(object)value).ToString(format, _provider)); if (text != null) { AppendStringDirect(text); } } [NullableContext(1)] public void AppendFormatted<[<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] T>(T value, int alignment) { int pos = _pos; AppendFormatted(value); if (alignment != 0) { AppendOrInsertAlignmentIfNeeded(pos, alignment); } } public void AppendFormatted([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(1)] T value, int alignment, string format) { int pos = _pos; AppendFormatted(value, format); if (alignment != 0) { AppendOrInsertAlignmentIfNeeded(pos, alignment); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void AppendFormatted(IntPtr value) { if (IntPtr.Size == 4) { AppendFormatted((int)value); } else { AppendFormatted((long)value); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void AppendFormatted(IntPtr value, string format) { if (IntPtr.Size == 4) { AppendFormatted((int)value, format); } else { AppendFormatted((long)value, format); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void AppendFormatted(UIntPtr value) { if (UIntPtr.Size == 4) { AppendFormatted((uint)value); } else { AppendFormatted((ulong)value); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void AppendFormatted(UIntPtr value, string format) { if (UIntPtr.Size == 4) { AppendFormatted((uint)value, format); } else { AppendFormatted((ulong)value, format); } } [NullableContext(0)] public void AppendFormatted(ReadOnlySpan value) { if (value.TryCopyTo(_chars.Slice(_pos))) { _pos += value.Length; } else { GrowThenCopySpan(value); } } [NullableContext(0)] public void AppendFormatted(ReadOnlySpan value, int alignment = 0, [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(2)] string format = null) { bool flag = false; if (alignment < 0) { flag = true; alignment = -alignment; } int num = alignment - value.Length; if (num <= 0) { AppendFormatted(value); return; } EnsureCapacityForAdditionalChars(value.Length + num); if (flag) { value.CopyTo(_chars.Slice(_pos)); _pos += value.Length; _chars.Slice(_pos, num).Fill(' '); _pos += num; } else { _chars.Slice(_pos, num).Fill(' '); _pos += num; value.CopyTo(_chars.Slice(_pos)); _pos += value.Length; } } public void AppendFormatted(string value) { if (!_hasCustomFormatter && value != null && MemoryExtensions.AsSpan(value).TryCopyTo(_chars.Slice(_pos))) { _pos += value.Length; } else { AppendFormattedSlow(value); } } [MethodImpl(MethodImplOptions.NoInlining)] private void AppendFormattedSlow(string value) { if (_hasCustomFormatter) { AppendCustomFormatter(value, null); } else if (value != null) { EnsureCapacityForAdditionalChars(value.Length); MemoryExtensions.AsSpan(value).CopyTo(_chars.Slice(_pos)); _pos += value.Length; } } public void AppendFormatted(string value, int alignment = 0, string format = null) { this.AppendFormatted(value, alignment, format); } public void AppendFormatted(object value, int alignment = 0, string format = null) { this.AppendFormatted(value, alignment, format); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [NullableContext(1)] internal static bool HasCustomFormatter(IFormatProvider provider) { if (provider.GetType() != typeof(CultureInfo)) { return provider.GetFormat(typeof(ICustomFormatter)) != null; } return false; } [MethodImpl(MethodImplOptions.NoInlining)] private void AppendCustomFormatter([<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(1)] T value, string format) { ICustomFormatter customFormatter = (ICustomFormatter)_provider.GetFormat(typeof(ICustomFormatter)); if (customFormatter != null) { string text = customFormatter.Format(format, value, _provider); if (text != null) { AppendStringDirect(text); } } } private void AppendOrInsertAlignmentIfNeeded(int startingPos, int alignment) { int num = _pos - startingPos; bool flag = false; if (alignment < 0) { flag = true; alignment = -alignment; } int num2 = alignment - num; if (num2 > 0) { EnsureCapacityForAdditionalChars(num2); if (flag) { _chars.Slice(_pos, num2).Fill(' '); } else { _chars.Slice(startingPos, num).CopyTo(_chars.Slice(startingPos + num2)); _chars.Slice(startingPos, num2).Fill(' '); } _pos += num2; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void EnsureCapacityForAdditionalChars(int additionalChars) { if (_chars.Length - _pos < additionalChars) { Grow(additionalChars); } } [MethodImpl(MethodImplOptions.NoInlining)] [NullableContext(1)] private void GrowThenCopyString(string value) { Grow(value.Length); MemoryExtensions.AsSpan(value).CopyTo(_chars.Slice(_pos)); _pos += value.Length; } [MethodImpl(MethodImplOptions.NoInlining)] [NullableContext(0)] private void GrowThenCopySpan(ReadOnlySpan value) { Grow(value.Length); value.CopyTo(_chars.Slice(_pos)); _pos += value.Length; } [MethodImpl(MethodImplOptions.NoInlining)] private void Grow(int additionalChars) { GrowCore((uint)(_pos + additionalChars)); } [MethodImpl(MethodImplOptions.NoInlining)] private void Grow() { GrowCore((uint)(_chars.Length + 1)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void GrowCore(uint requiredMinCapacity) { int minimumLength = (int)MathEx.Clamp(Math.Max(requiredMinCapacity, Math.Min((uint)(_chars.Length * 2), uint.MaxValue)), 256u, 2147483647u); char[] array = ArrayPool.Shared.Rent(minimumLength); _chars.Slice(0, _pos).CopyTo(array); char[] arrayToReturnToPool = _arrayToReturnToPool; _chars = (_arrayToReturnToPool = array); if (arrayToReturnToPool != null) { ArrayPool.Shared.Return(arrayToReturnToPool); } } } [AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)] internal sealed class DisableRuntimeMarshallingAttribute : Attribute { } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = false)] internal sealed class InterpolatedStringHandlerAttribute : Attribute { } [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] [NullableContext(1)] [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] internal sealed class InterpolatedStringHandlerArgumentAttribute : Attribute { public string[] Arguments { get; } public InterpolatedStringHandlerArgumentAttribute(string argument) { Arguments = new string[1] { argument }; } public InterpolatedStringHandlerArgumentAttribute(params string[] arguments) { Arguments = arguments; } } [NullableContext(2)] internal interface ITuple { int Length { get; } object this[int index] { get; } } [AttributeUsage(AttributeTargets.Method, Inherited = false)] internal sealed class ModuleInitializerAttribute : Attribute { } } namespace System.Diagnostics.CodeAnalysis { [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, Inherited = false)] [ExcludeFromCodeCoverage] [DebuggerNonUserCode] internal sealed class AllowNullAttribute : Attribute { } [ExcludeFromCodeCoverage] [DebuggerNonUserCode] [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, Inherited = false)] internal sealed class DisallowNullAttribute : Attribute { } [ExcludeFromCodeCoverage] [AttributeUsage(AttributeTargets.Method, Inherited = false)] [DebuggerNonUserCode] internal sealed class DoesNotReturnAttribute : Attribute { } [ExcludeFromCodeCoverage] [DebuggerNonUserCode] [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] internal sealed class DoesNotReturnIfAttribute : Attribute { public bool ParameterValue { get; } public DoesNotReturnIfAttribute(bool parameterValue) { ParameterValue = parameterValue; } } [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue, Inherited = false)] [ExcludeFromCodeCoverage] [DebuggerNonUserCode] internal sealed class MaybeNullAttribute : Attribute { } [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] [DebuggerNonUserCode] [ExcludeFromCodeCoverage] internal sealed class MaybeNullWhenAttribute : Attribute { public bool ReturnValue { get; } public MaybeNullWhenAttribute(bool returnValue) { ReturnValue = returnValue; } } [NullableContext(1)] [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] [ExcludeFromCodeCoverage] [DebuggerNonUserCode] internal sealed class MemberNotNullAttribute : Attribute { public string[] Members { get; } public MemberNotNullAttribute(string member) { Members = new string[1] { member }; } public MemberNotNullAttribute(params string[] members) { Members = members; } } [NullableContext(1)] [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] [ExcludeFromCodeCoverage] [DebuggerNonUserCode] internal sealed class MemberNotNullWhenAttribute : Attribute { public bool ReturnValue { get; } public string[] Members { get; } public MemberNotNullWhenAttribute(bool returnValue, string member) { ReturnValue = returnValue; Members = new string[1] { member }; } public MemberNotNullWhenAttribute(bool returnValue, params string[] members) { ReturnValue = returnValue; Members = members; } } [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue, Inherited = false)] [DebuggerNonUserCode] [ExcludeFromCodeCoverage] internal sealed class NotNullAttribute : Attribute { } [<89867cc0-aec8-456b-8ce6-5bb19c9d4c41>Nullable(0)] [DebuggerNonUserCode] [AttributeUsage(AttributeTargets.Property | AttributeTargets.Parameter | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)] [NullableContext(1)] [ExcludeFromCodeCoverage] internal sealed class NotNullIfNotNullAttribute : Attribute { public string ParameterName { get; } public NotNullIfNotNullAttribute(string parameterName) { ParameterName = parameterName; } } [ExcludeFromCodeCoverage] [DebuggerNonUserCode] [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] internal sealed class NotNullWhenAttribute : Attribute { public bool ReturnValue { get; } public NotNullWhenAttribute(bool returnValue) { ReturnValue = returnValue; } } internal static class ExtraDynamicallyAccessedMemberTypes { public const DynamicallyAccessedMemberTypes Interfaces = (DynamicallyAccessedMemberTypes)8192; } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Interface | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, Inherited = false)] internal sealed class DynamicallyAccessedMembersAttribute : Attribute { public DynamicallyAccessedMemberTypes MemberTypes { get; } public DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes memberTypes) { MemberTypes = memberTypes; } } [Flags] internal enum DynamicallyAccessedMemberTypes { None = 0, PublicParameterlessConstructor = 1, PublicConstructors = 3, NonPublicConstructors = 4, PublicMethods = 8, NonPublicMethods = 0x10, PublicFields = 0x20, NonPublicFields = 0x40, PublicNestedTypes = 0x80, NonPublicNestedTypes = 0x100, PublicProperties = 0x200, NonPublicProperties = 0x400, PublicEvents = 0x800, NonPublicEvents = 0x1000, All = -1 } [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] internal sealed class UnscopedRefAttribute : Attribute { } } namespace System.Runtime.Versioning { [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method, AllowMultiple = false, Inherited = false)] internal sealed class NonVersionableAttribute : Attribute { } } namespace System.Runtime.CompilerServices { internal sealed class IsReadOnlyAttribute : Attribute { } } namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] [Microsoft.CodeAnalysis.Embedded] [CompilerGenerated] internal sealed class NativeIntegerAttribute : Attribute { public readonly bool[] TransformFlags; public NativeIntegerAttribute() { TransformFlags = new bool[1] { true }; } public NativeIntegerAttribute(bool[] A_0) { TransformFlags = A_0; } } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] [Microsoft.CodeAnalysis.Embedded] [CompilerGenerated] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte A_0) { NullableFlags = new byte[1] { A_0 }; } public NullableAttribute(byte[] A_0) { NullableFlags = A_0; } } [CompilerGenerated] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] [Microsoft.CodeAnalysis.Embedded] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte A_0) { Flag = A_0; } } } namespace MonoMod { internal static class ILHelpers { [MethodImpl(MethodImplOptions.AggressiveInlining)] public unsafe static T TailCallDelegatePtr(IntPtr source) { //IL_0001: Ignored invalid 'tail' prefix return ((delegate*)source)(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T TailCallFunc(Func func) { return func(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ref T? UnboxAnyUnsafe(ref object? box) { if (default(T) == null) { return ref Unsafe.As(ref box); } return ref (T)box; } } } namespace System.Runtime.CompilerServices { internal static class Unsafe { [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public unsafe static T Read(void* source) { return Unsafe.Read(source); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public unsafe static T ReadUnaligned(void* source) { return Unsafe.ReadUnaligned(source); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public static T ReadUnaligned(ref byte source) { return Unsafe.ReadUnaligned(ref source); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public unsafe static void Write(void* destination, T value) { Unsafe.Write(destination, value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public unsafe static void WriteUnaligned(void* destination, T value) { Unsafe.WriteUnaligned(destination, value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public static void WriteUnaligned(ref byte destination, T value) { Unsafe.WriteUnaligned(ref destination, value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public unsafe static void Copy(void* destination, ref T source) { Unsafe.Write(destination, source); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public unsafe static void Copy(ref T destination, void* source) { destination = Unsafe.Read(source); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public unsafe static void* AsPointer(ref T value) { return Unsafe.AsPointer(ref value); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public static void SkipInit(out T value) { } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public static int SizeOf() { return Unsafe.SizeOf(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public unsafe static void CopyBlock(void* destination, void* source, uint byteCount) { // IL cpblk instruction Unsafe.CopyBlock(destination, source, byteCount); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public static void CopyBlock(ref byte destination, ref byte source, uint byteCount) { // IL cpblk instruction Unsafe.CopyBlock(ref destination, ref source, byteCount); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public unsafe static void CopyBlockUnaligned(void* destination, void* source, uint byteCount) { // IL cpblk instruction Unsafe.CopyBlockUnaligned(destination, source, byteCount); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public static void CopyBlockUnaligned(ref byte destination, ref byte source, uint byteCount) { // IL cpblk instruction Unsafe.CopyBlockUnaligned(ref destination, ref source, byteCount); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public unsafe static void InitBlock(void* startAddress, byte value, uint byteCount) { // IL initblk instruction Unsafe.InitBlock(startAddress, value, byteCount); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public static void InitBlock(ref byte startAddress, byte value, uint byteCount) { // IL initblk instruction Unsafe.InitBlock(ref startAddress, value, byteCount); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public unsafe static void InitBlockUnaligned(void* startAddress, byte value, uint byteCount) { // IL initblk instruction Unsafe.InitBlockUnaligned(startAddress, value, byteCount); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public static void InitBlockUnaligned(ref byte startAddress, byte value, uint byteCount) { // IL initblk instruction Unsafe.InitBlockUnaligned(ref startAddress, value, byteCount); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public static T As(object o) where T : class { return (T)o; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public unsafe static ref T AsRef(void* source) { return ref *(T*)source; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public static ref T AsRef(in T source) { return ref source; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public static ref TTo As(ref TFrom source) { return ref Unsafe.As(ref source); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public static ref T Unbox(object box) where T : struct { return ref (T)box; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public static ref T Add(ref T source, int elementOffset) { return ref Unsafe.Add(ref source, elementOffset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public unsafe static void* Add(void* source, int elementOffset) { return (byte*)source + (nint)elementOffset * (nint)Unsafe.SizeOf(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public static ref T Add(ref T source, IntPtr elementOffset) { return ref Unsafe.Add(ref source, elementOffset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ref T Add(ref T source, [System.Runtime.Versioning.NonVersionable] nuint elementOffset) { return ref Unsafe.Add(ref source, elementOffset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public static ref T AddByteOffset(ref T source, IntPtr byteOffset) { return ref Unsafe.AddByteOffset(ref source, byteOffset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ref T AddByteOffset(ref T source, [System.Runtime.Versioning.NonVersionable] nuint byteOffset) { return ref Unsafe.AddByteOffset(ref source, byteOffset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public static ref T Subtract(ref T source, int elementOffset) { return ref Unsafe.Subtract(ref source, elementOffset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public unsafe static void* Subtract(void* source, int elementOffset) { return (byte*)source - (nint)elementOffset * (nint)Unsafe.SizeOf(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public static ref T Subtract(ref T source, IntPtr elementOffset) { return ref Unsafe.Subtract(ref source, elementOffset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ref T Subtract(ref T source, [System.Runtime.Versioning.NonVersionable] nuint elementOffset) { return ref Unsafe.Subtract(ref source, elementOffset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public static ref T SubtractByteOffset(ref T source, IntPtr byteOffset) { return ref Unsafe.SubtractByteOffset(ref source, byteOffset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ref T SubtractByteOffset(ref T source, [System.Runtime.Versioning.NonVersionable] nuint byteOffset) { return ref Unsafe.SubtractByteOffset(ref source, byteOffset); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public static IntPtr ByteOffset(ref T origin, ref T target) { return Unsafe.ByteOffset(target: ref target, origin: ref origin); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public static bool AreSame(ref T left, ref T right) { return Unsafe.AreSame(ref left, ref right); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public static bool IsAddressGreaterThan(ref T left, ref T right) { return Unsafe.IsAddressGreaterThan(ref left, ref right); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public static bool IsAddressLessThan(ref T left, ref T right) { return Unsafe.IsAddressLessThan(ref left, ref right); } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public unsafe static bool IsNullRef(ref T source) { return Unsafe.AsPointer(ref source) == null; } [MethodImpl(MethodImplOptions.AggressiveInlining)] [System.Runtime.Versioning.NonVersionable] public unsafe static ref T NullRef() { return ref *(T*)null; } } }