Decompiled source of FortnitificationScanner v0.0.2

FortnitificationScanner.dll

Decompiled 15 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Dawn;
using Dawn.Utils;
using HarmonyLib;
using InjectionLibrary.Attributes;
using ItemRarities.Injections;
using ItemRarities.Patches;
using Microsoft.CodeAnalysis;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: RequiresInjections]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("FortnitificationScanner")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.0.2.0")]
[assembly: AssemblyInformationalVersion("0.0.2")]
[assembly: AssemblyProduct("FortnitificationScanner")]
[assembly: AssemblyTitle("FortnitificationScanner")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ItemRarities
{
	internal static class ConfigManager
	{
		internal static ConfigEntry<bool> DebugLogsEnabled { get; private set; }

		internal static ConfigEntry<string> CommonItems { get; private set; }

		internal static ConfigEntry<string> UncommonItems { get; private set; }

		internal static ConfigEntry<string> RareItems { get; private set; }

		internal static ConfigEntry<string> ExceptionalItems { get; private set; }

		internal static ConfigEntry<string> LegendaryItems { get; private set; }

		internal static ConfigEntry<float> CommonPercentage { get; private set; }

		internal static ConfigEntry<float> UncommonPercentage { get; private set; }

		internal static ConfigEntry<float> RarePercentage { get; private set; }

		internal static ConfigEntry<float> ExceptionalPercentage { get; private set; }

		internal static ConfigEntry<float> LegendaryPercentage { get; private set; }

		internal static ConfigEntry<string> CommonName { get; private set; }

		internal static ConfigEntry<string> UncommonName { get; private set; }

		internal static ConfigEntry<string> RareName { get; private set; }

		internal static ConfigEntry<string> ExceptionalName { get; private set; }

		internal static ConfigEntry<string> LegendaryName { get; private set; }

		internal static ConfigEntry<bool> OverrideExistingScanColours { get; private set; }

		internal static string[] ItemOverrides => new string[5] { CommonItems.Value, UncommonItems.Value, RareItems.Value, ExceptionalItems.Value, LegendaryItems.Value };

		internal static float[] RarityPercentages => new float[5] { CommonPercentage.Value, UncommonPercentage.Value, RarePercentage.Value, ExceptionalPercentage.Value, LegendaryPercentage.Value };

		internal static void Bind(ConfigFile config)
		{
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Expected O, but got Unknown
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Expected O, but got Unknown
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Expected O, but got Unknown
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Expected O, but got Unknown
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Expected O, but got Unknown
			DebugLogsEnabled = config.Bind<bool>("Internal", "Enable Debug Logging", false, "If true, enables debug logging");
			CommonItems = config.Bind<string>("Item overrides", "Common items", string.Empty, "Namespaced keys for the Common rarity, e.g. 'lethal_company:big_bolt,lethal_company:apparatus'");
			UncommonItems = config.Bind<string>("Item overrides", "Uncommon items", string.Empty, "Namespaced keys for the Uncommon rarity, e.g. 'lethal_company:big_bolt,lethal_company:apparatus'");
			RareItems = config.Bind<string>("Item overrides", "Rare items", string.Empty, "Namespaced keys for the Rare rarity, e.g. 'lethal_company:big_bolt,lethal_company:apparatus'");
			ExceptionalItems = config.Bind<string>("Item overrides", "Exceptional items", "lethal_company:apparatus", "Namespaced keys for the Exceptional rarity, e.g. 'lethal_company:big_bolt,lethal_company:apparatus'");
			LegendaryItems = config.Bind<string>("Item overrides", "Legendary items", string.Empty, "Namespaced keys for the Legendary rarity, e.g. 'lethal_company:big_bolt,lethal_company:apparatus'");
			CommonPercentage = config.Bind<float>("Rarity groups", "Common percentage", 39f, new ConfigDescription("Percentage of scrap to be Common. If all rarity percentages do not total 100, they will scale automatically", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			UncommonPercentage = config.Bind<float>("Rarity groups", "Uncommon percentage", 28f, new ConfigDescription("Percentage of scrap to be Uncommon. If all rarity percentages do not total 100, they will scale automatically", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			RarePercentage = config.Bind<float>("Rarity groups", "Rare percentage", 16f, new ConfigDescription("Percentage of scrap to be Rare. If all rarity percentages do not total 100, they will scale automatically", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			ExceptionalPercentage = config.Bind<float>("Rarity groups", "Exceptional percentage", 11f, new ConfigDescription("Percentage of scrap to be Exceptional. If all rarity percentages do not total 100, they will scale automatically", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			LegendaryPercentage = config.Bind<float>("Rarity groups", "Legendary percentage", 6f, new ConfigDescription("Percentage of scrap to be Legendary. If all rarity percentages do not total 100, they will scale automatically", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
			CommonName = config.Bind<string>("Rarity groups", "Common name", "Common", "Rarity name shown on the scanner for Common scrap");
			UncommonName = config.Bind<string>("Rarity groups", "Uncommon name", "Uncommon", "Rarity name shown on the scanner for Uncommon scrap");
			RareName = config.Bind<string>("Rarity groups", "Rare name", "Rare", "Rarity name shown on the scanner for Rare scrap");
			ExceptionalName = config.Bind<string>("Rarity groups", "Exceptional name", "Exceptional", "Rarity name shown on the scanner for Exceptional scrap");
			LegendaryName = config.Bind<string>("Rarity groups", "Legendary name", "Legendary", "Rarity name shown on the scanner for Legendary scrap");
			OverrideExistingScanColours = config.Bind<bool>("General", "Override existing scan colours", false, "If there are already items with scan node colours set by DawnLib, should they be overriden?");
		}
	}
	internal static class Log
	{
		internal static void Debug(string message)
		{
			if (ConfigManager.DebugLogsEnabled.Value)
			{
				Write((LogLevel)32, message);
			}
		}

		internal static void Info(string message)
		{
			Write((LogLevel)16, message);
		}

		internal static void Warn(string message)
		{
			Write((LogLevel)4, message);
		}

		internal static void Error(string message)
		{
			Write((LogLevel)2, message);
		}

		internal static void Fatal(string message)
		{
			Write((LogLevel)1, message);
		}

		private static void Write(LogLevel logLevel, string message)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			Plugin.mls.Log(logLevel, (object)message);
		}
	}
	[BepInPlugin("MrHat.FortnitificationScanner", "FortnitificationScanner", "0.0.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string modGUID = "MrHat.FortnitificationScanner";

		public const string modName = "FortnitificationScanner";

		public const string modVersion = "0.0.2";

		private readonly Harmony _harmony = new Harmony("MrHat.FortnitificationScanner");

		internal static ManualLogSource mls;

		private void Awake()
		{
			mls = ((BaseUnityPlugin)this).Logger;
			ConfigManager.Bind(((BaseUnityPlugin)this).Config);
			RarityGroups.Enable();
			_harmony.PatchAll(typeof(StartOfRoundPatches));
			_harmony.PatchAll(typeof(ScanNodePropertiesPatches));
			Log.Info("FortnitificationScanner loaded");
		}
	}
	internal static class RarityGroups
	{
		private static readonly Dictionary<Item, RarityGroup> AssignedItems = new Dictionary<Item, RarityGroup>();

		private static readonly List<RarityGroup> Groups = new List<RarityGroup>();

		internal static void Enable()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			Groups.AddRange(new <>z__ReadOnlyArray<RarityGroup>(new RarityGroup[5]
			{
				new RarityGroup(ConfigManager.CommonName.Value, Color32.op_Implicit(new Color32((byte)74, (byte)74, (byte)74, byte.MaxValue)), Color32.op_Implicit(new Color32((byte)226, (byte)226, (byte)226, byte.MaxValue))),
				new RarityGroup(ConfigManager.UncommonName.Value, Color32.op_Implicit(new Color32((byte)28, (byte)90, (byte)49, byte.MaxValue)), Color32.op_Implicit(new Color32((byte)118, (byte)242, (byte)154, byte.MaxValue))),
				new RarityGroup(ConfigManager.RareName.Value, Color32.op_Implicit(new Color32((byte)36, (byte)74, (byte)122, byte.MaxValue)), Color32.op_Implicit(new Color32((byte)127, (byte)199, byte.MaxValue, byte.MaxValue))),
				new RarityGroup(ConfigManager.ExceptionalName.Value, Color32.op_Implicit(new Color32((byte)85, (byte)48, (byte)112, byte.MaxValue)), Color32.op_Implicit(new Color32((byte)215, (byte)156, byte.MaxValue, byte.MaxValue))),
				new RarityGroup(ConfigManager.LegendaryName.Value, Color32.op_Implicit(new Color32((byte)111, (byte)91, (byte)16, byte.MaxValue)), Color32.op_Implicit(new Color32(byte.MaxValue, (byte)230, (byte)109, byte.MaxValue)))
			}));
			if (((Registry<DawnItemInfo>)(object)LethalContent.Items).IsFrozen)
			{
				SortItems();
			}
			else
			{
				((Registry<DawnItemInfo>)(object)LethalContent.Items).OnFreeze += SortItems;
			}
		}

		internal static bool Find(Item item, out RarityGroup rarity)
		{
			return AssignedItems.TryGetValue(item, out rarity);
		}

		private static void SortItems()
		{
			List<DawnItemInfo> source = ((Registry<DawnItemInfo>)(object)LethalContent.Items).Values.Where((DawnItemInfo itemInfo) => itemInfo.Item.isScrap).ToList();
			Dictionary<Item, RarityGroup> overriddenItems = new Dictionary<Item, RarityGroup>();
			List<string>[] array = new List<string>[5]
			{
				new List<string>(),
				new List<string>(),
				new List<string>(),
				new List<string>(),
				new List<string>()
			};
			string[] itemOverrides = ConfigManager.ItemOverrides;
			NamespacedKey val = default(NamespacedKey);
			DawnItemInfo val3 = default(DawnItemInfo);
			for (int num = 0; num < Groups.Count; num++)
			{
				string[] array2 = itemOverrides[num].Split(new char[4] { ',', ';', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
				string[] array3 = array2;
				foreach (string text in array3)
				{
					string text2 = text.Trim();
					if (!NamespacedKey.TryParse(text2, ref val))
					{
						Log.Error("Item override key is invalid: " + text2);
						continue;
					}
					NamespacedKey<DawnItemInfo> val2 = NamespacedKey<DawnItemInfo>.From(val.Namespace, val.Key);
					if (!((Registry<DawnItemInfo>)(object)LethalContent.Items).TryGetValue(val2, ref val3))
					{
						Log.Error("Item override was not loaded: " + text2);
					}
					else if (!val3.Item.isScrap)
					{
						Log.Warn("Item override is not scrap: " + text2);
					}
					else if (!overriddenItems.TryAdd(val3.Item, Groups[num]))
					{
						Log.Error("Item override appears in more than one rarity: " + text2);
					}
					else
					{
						array[num].Add(text2);
					}
				}
			}
			List<DawnItemInfo> list = (from itemInfo in source
				where !overriddenItems.ContainsKey(itemInfo.Item)
				orderby MeanValue(itemInfo.Item)
				select itemInfo).ToList();
			float[] rarityPercentages = ConfigManager.RarityPercentages;
			float num3 = rarityPercentages.Sum();
			AssignedItems.Clear();
			if (list.Count > 0 && num3 <= 0f)
			{
				Log.Error("Rarity percentages must total more than zero");
				return;
			}
			if (list.Count > 0)
			{
				int num4 = 0;
				float num5 = rarityPercentages[0] / num3;
				for (int num6 = 0; num6 < list.Count; num6++)
				{
					float num7 = ((float)num6 + 0.5f) / (float)list.Count;
					while (num4 < Groups.Count - 1 && num7 >= num5)
					{
						num4++;
						num5 += rarityPercentages[num4] / num3;
					}
					AssignedItems[list[num6].Item] = Groups[num4];
				}
			}
			foreach (KeyValuePair<Item, RarityGroup> item in overriddenItems)
			{
				AssignedItems[item.Key] = item.Value;
			}
			Log.Info($"{Groups[0].Name} scrap amount: {AssignedItems.Count<KeyValuePair<Item, RarityGroup>>((KeyValuePair<Item, RarityGroup> item) => item.Value == Groups[0])}");
			Log.Info($"{Groups[1].Name} scrap amount: {AssignedItems.Count<KeyValuePair<Item, RarityGroup>>((KeyValuePair<Item, RarityGroup> item) => item.Value == Groups[1])}");
			Log.Info($"{Groups[2].Name} scrap amount: {AssignedItems.Count<KeyValuePair<Item, RarityGroup>>((KeyValuePair<Item, RarityGroup> item) => item.Value == Groups[2])}");
			Log.Info($"{Groups[3].Name} scrap amount: {AssignedItems.Count<KeyValuePair<Item, RarityGroup>>((KeyValuePair<Item, RarityGroup> item) => item.Value == Groups[3])}");
			Log.Info($"{Groups[4].Name} scrap amount: {AssignedItems.Count<KeyValuePair<Item, RarityGroup>>((KeyValuePair<Item, RarityGroup> item) => item.Value == Groups[4])}");
			for (int num8 = 0; num8 < Groups.Count; num8++)
			{
				if (array[num8].Count > 0)
				{
					Log.Info(Groups[num8].Name + " item overrides: " + string.Join(", ", array[num8]));
				}
			}
			Log.Info($"{list.Count} scrap items sorted by value rank with {overriddenItems.Count} overrides");
		}

		private static float MeanValue(Item item)
		{
			return (float)(item.minValue + item.maxValue) / 2f;
		}
	}
	internal class RarityGroup(string name, Color scanColor, Color textColor)
	{
		internal string Name { get; } = name;

		internal Color ScanColor { get; } = scanColor;

		internal Color TextColor { get; } = textColor;
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "FortnitificationScanner";

		public const string PLUGIN_NAME = "FortnitificationScanner";

		public const string PLUGIN_VERSION = "0.0.2";
	}
}
namespace ItemRarities.Patches
{
	[HarmonyPatch(typeof(ScanNodeProperties))]
	internal static class ScanNodePropertiesPatches
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPostfix(ScanNodeProperties __instance)
		{
			GrabbableObject componentInParent = ((Component)__instance).GetComponentInParent<GrabbableObject>();
			if (componentInParent != null && componentInParent.itemProperties?.isScrap == true && !((Object)(object)((Component)componentInParent).GetComponentInChildren<ScanNodeProperties>(true) != (Object)(object)__instance))
			{
				IScanNodeProperties scanNodeProperties = (IScanNodeProperties)__instance;
				scanNodeProperties.ItemRaritiesSet = true;
				scanNodeProperties.ItemRaritiesItem = componentInParent;
				Log.Debug(componentInParent.itemProperties.itemName + " scan node found");
				scanNodeProperties.ItemRaritiesCoroutine = ((MonoBehaviour)__instance).StartCoroutine(RarityScanLoop(__instance, scanNodeProperties));
			}
		}

		[HarmonyPatch("OnDestroy")]
		[HarmonyPostfix]
		private static void OnDestroyPostfix(ScanNodeProperties __instance)
		{
			IScanNodeProperties scanNodeProperties = (IScanNodeProperties)__instance;
			if (scanNodeProperties.ItemRaritiesCoroutine != null)
			{
				((MonoBehaviour)__instance).StopCoroutine(scanNodeProperties.ItemRaritiesCoroutine);
				scanNodeProperties.ItemRaritiesCoroutine = null;
			}
		}

		private static IEnumerator RarityScanLoop(ScanNodeProperties scanNode, IScanNodeProperties scanNodeData)
		{
			WaitForSeconds updateDelay = new WaitForSeconds(0.1f);
			while (true)
			{
				GrabbableObject rarityItem = scanNodeData.ItemRaritiesItem;
				if ((Object)(object)rarityItem == (Object)null)
				{
					break;
				}
				string rarityText = scanNodeData.ItemRaritiesText;
				if (rarityText == null || scanNodeData.ItemRaritiesScrapValue != rarityItem.scrapValue)
				{
					if (!RarityGroups.Find(rarityItem.itemProperties, out RarityGroup rarity))
					{
						yield return updateDelay;
						continue;
					}
					scanNodeData.ItemRaritiesScrapValue = rarityItem.scrapValue;
					Log.Debug($"{rarityItem.itemProperties.itemName} rarity scan value set to {rarityItem.scrapValue}");
					rarityText = (scanNodeData.ItemRaritiesText = $"{rarity.Name} - ${rarityItem.scrapValue}");
					Log.Debug(rarityItem.itemProperties.itemName + " rarity scan text set to " + rarityText);
					if (!scanNodeData.ItemRaritiesColoursSet)
					{
						ForceScanColorOnItem scanColour = ((Component)rarityItem).GetComponent<ForceScanColorOnItem>();
						if ((Object)(object)scanColour == (Object)null || ConfigManager.OverrideExistingScanColours.Value)
						{
							if (scanColour == null)
							{
								scanColour = ((Component)rarityItem).gameObject.AddComponent<ForceScanColorOnItem>();
							}
							scanColour.grabbableObject = rarityItem;
							scanColour.borderColor = rarity.ScanColor;
							scanColour.textColor = rarity.TextColor;
							scanColour.FindGrabbableObjectsScanObject();
						}
						scanNodeData.ItemRaritiesColoursSet = true;
						Log.Debug(rarityItem.itemProperties.itemName + " rarity scan colours done");
					}
					rarity = null;
				}
				if (scanNode.subText != rarityText)
				{
					scanNode.subText = rarityText;
				}
				yield return updateDelay;
			}
		}
	}
	internal static class StartOfRoundPatches
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static HandleNamedMessageDelegate <0>__ReadScrapValues;
		}

		private const string ScrapValueMessage = "MrHat.FortnitificationScanner.ScrapValues";

		[HarmonyPatch(typeof(StartOfRound), "Start")]
		[HarmonyPostfix]
		private static void RegisterScrapValueMessage()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			NetworkManager singleton = NetworkManager.Singleton;
			CustomMessagingManager val = ((singleton != null) ? singleton.CustomMessagingManager : null);
			if (val != null)
			{
				val.UnregisterNamedMessageHandler("MrHat.FortnitificationScanner.ScrapValues");
				object obj = <>O.<0>__ReadScrapValues;
				if (obj == null)
				{
					HandleNamedMessageDelegate val2 = ReadScrapValues;
					<>O.<0>__ReadScrapValues = val2;
					obj = (object)val2;
				}
				val.RegisterNamedMessageHandler("MrHat.FortnitificationScanner.ScrapValues", (HandleNamedMessageDelegate)obj);
				Log.Debug("Scrap value message registered");
			}
		}

		[HarmonyPatch(typeof(GameNetworkManager), "SetInstanceValuesBackToDefault")]
		[HarmonyPostfix]
		private static void UnregisterScrapValueMessage()
		{
			NetworkManager singleton = NetworkManager.Singleton;
			CustomMessagingManager val = ((singleton != null) ? singleton.CustomMessagingManager : null);
			if (val != null)
			{
				val.UnregisterNamedMessageHandler("MrHat.FortnitificationScanner.ScrapValues");
				Log.Debug("Scrap value message unregistered");
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "SyncAlreadyHeldObjectsServerRpc")]
		[HarmonyPostfix]
		private unsafe static void SendScrapValues(StartOfRound __instance, int joiningClientId)
		{
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			if (!((NetworkBehaviour)__instance).IsServer)
			{
				return;
			}
			NetworkManager singleton = NetworkManager.Singleton;
			CustomMessagingManager val = ((singleton != null) ? singleton.CustomMessagingManager : null);
			ulong num = (ulong)joiningClientId;
			if (singleton == null || !singleton.IsListening || val == null || !singleton.ConnectedClients.ContainsKey(num))
			{
				return;
			}
			GrabbableObject[] array = Object.FindObjectsByType<GrabbableObject>((FindObjectsInactive)0, (FindObjectsSortMode)0);
			List<GrabbableObject> list = new List<GrabbableObject>();
			GrabbableObject[] array2 = array;
			foreach (GrabbableObject val2 in array2)
			{
				Item itemProperties = val2.itemProperties;
				if (itemProperties != null && itemProperties.isScrap)
				{
					NetworkObject networkObject = ((NetworkBehaviour)val2).NetworkObject;
					if (networkObject != null && networkObject.IsSpawned)
					{
						list.Add(val2);
					}
				}
			}
			int num2 = 4 + list.Count * 12;
			FastBufferWriter val3 = default(FastBufferWriter);
			((FastBufferWriter)(ref val3))..ctor(num2, (Allocator)2, -1);
			try
			{
				int count = list.Count;
				((FastBufferWriter)(ref val3)).WriteValueSafe<int>(ref count, default(ForPrimitives));
				foreach (GrabbableObject item in list)
				{
					ulong networkObjectId = ((NetworkBehaviour)item).NetworkObject.NetworkObjectId;
					((FastBufferWriter)(ref val3)).WriteValueSafe<ulong>(ref networkObjectId, default(ForPrimitives));
					((FastBufferWriter)(ref val3)).WriteValueSafe<int>(ref item.scrapValue, default(ForPrimitives));
				}
				val.SendNamedMessage("MrHat.FortnitificationScanner.ScrapValues", num, val3, (NetworkDelivery)4);
				Log.Debug($"{list.Count} scrap values sent to client {num}");
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val3))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private static void ReadScrapValues(ulong senderClientId, FastBufferReader reader)
		{
			//IL_0027: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || senderClientId != 0)
			{
				return;
			}
			int num = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			int num2 = 0;
			ulong key = default(ulong);
			int scrapValue = default(int);
			for (int i = 0; i < num; i++)
			{
				((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref key, default(ForPrimitives));
				((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref scrapValue, default(ForPrimitives));
				if (!singleton.SpawnManager.SpawnedObjects.TryGetValue(key, out var value))
				{
					continue;
				}
				GrabbableObject component = ((Component)value).GetComponent<GrabbableObject>();
				if ((Object)(object)component != (Object)null)
				{
					Item itemProperties = component.itemProperties;
					if (itemProperties != null && itemProperties.isScrap)
					{
						component.SetScrapValue(scrapValue);
						num2++;
					}
				}
			}
			Log.Debug($"{num2} of {num} scrap values synced");
		}
	}
}
namespace ItemRarities.Injections
{
	[InjectInterface(typeof(ScanNodeProperties))]
	public interface IScanNodeProperties
	{
		bool ItemRaritiesSet { get; set; }

		GrabbableObject? ItemRaritiesItem { get; set; }

		int ItemRaritiesScrapValue { get; set; }

		string? ItemRaritiesText { get; set; }

		bool ItemRaritiesColoursSet { get; set; }

		Coroutine? ItemRaritiesCoroutine { get; set; }

		void Start();

		void OnDestroy();
	}
}
[CompilerGenerated]
internal sealed class <>z__ReadOnlyArray<T> : IEnumerable, ICollection, IList, IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection<T>, IList<T>
{
	int ICollection.Count => _items.Length;

	bool ICollection.IsSynchronized => false;

	object ICollection.SyncRoot => this;

	object IList.this[int index]
	{
		get
		{
			return _items[index];
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	bool IList.IsFixedSize => true;

	bool IList.IsReadOnly => true;

	int IReadOnlyCollection<T>.Count => _items.Length;

	T IReadOnlyList<T>.this[int index] => _items[index];

	int ICollection<T>.Count => _items.Length;

	bool ICollection<T>.IsReadOnly => true;

	T IList<T>.this[int index]
	{
		get
		{
			return _items[index];
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	public <>z__ReadOnlyArray(T[] items)
	{
		_items = items;
	}

	IEnumerator IEnumerable.GetEnumerator()
	{
		return ((IEnumerable)_items).GetEnumerator();
	}

	void ICollection.CopyTo(Array array, int index)
	{
		((ICollection)_items).CopyTo(array, index);
	}

	int IList.Add(object value)
	{
		throw new NotSupportedException();
	}

	void IList.Clear()
	{
		throw new NotSupportedException();
	}

	bool IList.Contains(object value)
	{
		return ((IList)_items).Contains(value);
	}

	int IList.IndexOf(object value)
	{
		return ((IList)_items).IndexOf(value);
	}

	void IList.Insert(int index, object value)
	{
		throw new NotSupportedException();
	}

	void IList.Remove(object value)
	{
		throw new NotSupportedException();
	}

	void IList.RemoveAt(int index)
	{
		throw new NotSupportedException();
	}

	IEnumerator<T> IEnumerable<T>.GetEnumerator()
	{
		return ((IEnumerable<T>)_items).GetEnumerator();
	}

	void ICollection<T>.Add(T item)
	{
		throw new NotSupportedException();
	}

	void ICollection<T>.Clear()
	{
		throw new NotSupportedException();
	}

	bool ICollection<T>.Contains(T item)
	{
		return ((ICollection<T>)_items).Contains(item);
	}

	void ICollection<T>.CopyTo(T[] array, int arrayIndex)
	{
		((ICollection<T>)_items).CopyTo(array, arrayIndex);
	}

	bool ICollection<T>.Remove(T item)
	{
		throw new NotSupportedException();
	}

	int IList<T>.IndexOf(T item)
	{
		return ((IList<T>)_items).IndexOf(item);
	}

	void IList<T>.Insert(int index, T item)
	{
		throw new NotSupportedException();
	}

	void IList<T>.RemoveAt(int index)
	{
		throw new NotSupportedException();
	}
}