Decompiled source of SlotInspectorCounter v1.9.4

plugins/SlotInspectorCounter/SlotInspectorCounter.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.NET.Common;
using BepInExResoniteShim;
using Elements.Core;
using FrooxEngine;
using FrooxEngine.ProtoFlux.Runtimes.Execution.Nodes;
using FrooxEngine.UIX;
using HarmonyLib;
using Renderite.Shared;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: TargetFramework(".NETCoreApp,Version=v9.0", FrameworkDisplayName = ".NET 9.0")]
[assembly: AssemblyCompany("NepuShiro")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.9.4.0")]
[assembly: AssemblyInformationalVersion("1.9.4+0869c7012250c1e4ce7ab1f8079885734f664785")]
[assembly: AssemblyProduct("SlotInspectorCounter")]
[assembly: AssemblyTitle("SlotInspectorCounter")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/NepuShiro/SlotInspectorCounter")]
[assembly: AssemblyVersion("1.9.4.0")]
[module: RefSafetyRules(11)]
namespace SlotInspectorCounter;

[ResonitePlugin("NepuShiro.SlotInspectorCounter", "SlotInspectorCounter", "1.9.4", "NepuShiro", "https://github.com/NepuShiro/SlotInspectorCounter")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BasePlugin
{
	[HarmonyPatch(typeof(SlotInspector), "OnChanges")]
	private class SlotInspector_Patch
	{
		public static void Postfix(SlotInspector __instance, SyncRef<Slot> ____rootSlot, SyncRef<TextExpandIndicator> ____expanderIndicator)
		{
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Expected O, but got Unknown
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Expected O, but got Unknown
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!Enabled.Value)
				{
					return;
				}
				SlotInspector obj = __instance;
				object obj2;
				if (obj == null)
				{
					obj2 = null;
				}
				else
				{
					Slot slot = ((Component)obj).Slot;
					obj2 = ((slot != null) ? slot.GetComponentInParents<SceneInspector>((Predicate<SceneInspector>)null, true, false) : null);
				}
				SceneInspector inspector = (SceneInspector)obj2;
				SceneInspector obj3 = inspector;
				Slot val = ((obj3 != null) ? ((Component)obj3).Slot : null);
				if (val == null)
				{
					return;
				}
				RefID referenceID = ((Worker)val).ReferenceID;
				ulong num = default(ulong);
				byte b = default(byte);
				((RefID)(ref referenceID)).ExtractIDs(ref num, ref b);
				User userByAllocationID = ((Worker)val).World.GetUserByAllocationID(b);
				if (userByAllocationID == null || num < userByAllocationID.AllocationIDStart || (!userByAllocationID.IsLocalUser && userByAllocationID != ((Worker)val).World.LocalUser))
				{
					return;
				}
				if (RunInUpdates.Value)
				{
					((Component)__instance).Slot.RunInUpdates(RunInUpdatesAmount.Value, (Action)delegate
					{
						ExpanderReplacer(__instance, inspector, ____rootSlot, ____expanderIndicator);
					});
				}
				else
				{
					ExpanderReplacer(__instance, inspector, ____rootSlot, ____expanderIndicator);
				}
			}
			catch (global::System.Exception ex)
			{
				ManualLogSource log = Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(32, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Error in SlotInspector Postfix: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<global::System.Exception>(ex);
				}
				log.LogError(val2);
			}
		}
	}

	internal static ManualLogSource Log;

	private static ConfigEntry<bool> Enabled;

	private static ConfigEntry<bool> RunInUpdates;

	private static ConfigEntry<int> RunInUpdatesAmount;

	private static ConfigEntry<bool> DynVars;

	private static ConfigEntry<bool> ReplaceVanillaButton;

	private static ConfigEntry<colorX> ClosedColor;

	private static ConfigEntry<colorX> OpenedColor;

	private static ConfigEntry<colorX> EmptyColor;

	private static ConfigEntry<bool> LerpColor;

	private static ConfigEntry<bool> LerpColorRootSlot;

	private static ConfigEntry<bool> LerpColorInspectRootSlot;

	private static ConfigEntry<int> LerpColorMax;

	private static ConfigEntry<colorX> LerpMinColor;

	private static ConfigEntry<colorX> LerpMidColor;

	private static ConfigEntry<colorX> LerpMaxColor;

	public override void Load()
	{
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0238: Unknown result type (might be due to invalid IL or missing references)
		//IL_0271: Unknown result type (might be due to invalid IL or missing references)
		//IL_029a: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a0: Expected O, but got Unknown
		Log = ((BasePlugin)this).Log;
		Enabled = ((BasePlugin)this).Config.Bind<bool>("General", "Enabled", true, "Should the mod be enabled");
		RunInUpdates = ((BasePlugin)this).Config.Bind<bool>("General", "RunInUpdates", false, "RunInUpdates? Enable this if you're having issues with things applying.");
		RunInUpdatesAmount = ((BasePlugin)this).Config.Bind<int>("General", "RunInUpdates Amount", 1, "Amount of updates to wait.");
		DynVars = ((BasePlugin)this).Config.Bind<bool>("General", "Dynvars", true, "Create DynVars for the Inspector Root Slot Count?");
		ReplaceVanillaButton = ((BasePlugin)this).Config.Bind<bool>("General", "Replace Vanilla Button", true, "Should the mod replace the vanilla dropdown or create a new button");
		ClosedColor = ((BasePlugin)this).Config.Bind<colorX>("Base Colors", "Closed Color", new colorX(1f, 1f, 1f, 1f, (ColorProfile)1), "Collapsed Color");
		OpenedColor = ((BasePlugin)this).Config.Bind<colorX>("Base Colors", "Opened Color", new colorX(0.6f, 0.6f, 0.6f, 1f, (ColorProfile)1), "Expanded Color");
		EmptyColor = ((BasePlugin)this).Config.Bind<colorX>("Base Colors", "Empty Color", new colorX(1f, 1f, 1f, 1f, (ColorProfile)1), "Empty Color");
		LerpColor = ((BasePlugin)this).Config.Bind<bool>("Lerp Settings", "Color Lerp", false, "Should the SlotCount color be lerped instead?");
		LerpColorRootSlot = ((BasePlugin)this).Config.Bind<bool>("Lerp Settings", "Use Root Slot", false, "Use the RootSlot's Slot count as the max?");
		LerpColorInspectRootSlot = ((BasePlugin)this).Config.Bind<bool>("Lerp Settings", "Use Inspected Slot", false, "Use the Inspected Slot's Slot count as the max?");
		LerpColorMax = ((BasePlugin)this).Config.Bind<int>("Lerp Settings", "Max Slot Count", 10000, "The amount of slots for the Color to be the Max Lerp Color");
		LerpMinColor = ((BasePlugin)this).Config.Bind<colorX>("Lerp Colors", "Min Lerp Color", new colorX(0f, 1f, 0f, 1f, (ColorProfile)1), "Min Lerp Color");
		LerpMidColor = ((BasePlugin)this).Config.Bind<colorX>("Lerp Colors", "Mid Lerp Color", new colorX(1f, 1f, 0f, 1f, (ColorProfile)1), "Mid Lerp Color");
		LerpMaxColor = ((BasePlugin)this).Config.Bind<colorX>("Lerp Colors", "Max Lerp Color", new colorX(1f, 0f, 0f, 1f, (ColorProfile)1), "Max Lerp Color");
		((BasePlugin)this).HarmonyInstance.PatchAll();
		ManualLogSource log = Log;
		bool flag = default(bool);
		BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(18, 1, ref flag);
		if (flag)
		{
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
			((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("NepuShiro.SlotInspectorCounter");
			((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
		}
		log.LogInfo(val);
	}

	private static void ExpanderReplacer(SlotInspector instance, SceneInspector inspector, SyncRef<Slot> _rootSlot, SyncRef<TextExpandIndicator> _expanderIndicator)
	{
		//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_00a5: 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_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: Unknown result type (might be due to invalid IL or missing references)
		//IL_0239: Unknown result type (might be due to invalid IL or missing references)
		//IL_029d: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0351: Unknown result type (might be due to invalid IL or missing references)
		//IL_035b: Expected O, but got Unknown
		//IL_0356: Unknown result type (might be due to invalid IL or missing references)
		Slot target = _rootSlot.Target;
		if (target == null)
		{
			return;
		}
		int totalChildCount = CountSlots(target);
		global::System.Runtime.CompilerServices.DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new global::System.Runtime.CompilerServices.DefaultInterpolatedStringHandler(16, 2);
		defaultInterpolatedStringHandler.AppendLiteral("<color=");
		colorX val = ClosedColor.Value;
		defaultInterpolatedStringHandler.AppendFormatted(((colorX)(ref val)).ToHexString(false, "#"));
		defaultInterpolatedStringHandler.AppendLiteral(">");
		defaultInterpolatedStringHandler.AppendFormatted<int>(totalChildCount);
		defaultInterpolatedStringHandler.AppendLiteral("</color>");
		string value = defaultInterpolatedStringHandler.ToStringAndClear();
		defaultInterpolatedStringHandler = new global::System.Runtime.CompilerServices.DefaultInterpolatedStringHandler(16, 2);
		defaultInterpolatedStringHandler.AppendLiteral("<color=");
		val = OpenedColor.Value;
		defaultInterpolatedStringHandler.AppendFormatted(((colorX)(ref val)).ToHexString(false, "#"));
		defaultInterpolatedStringHandler.AppendLiteral(">");
		defaultInterpolatedStringHandler.AppendFormatted<int>(totalChildCount);
		defaultInterpolatedStringHandler.AppendLiteral("</color>");
		string openedColor = defaultInterpolatedStringHandler.ToStringAndClear();
		defaultInterpolatedStringHandler = new global::System.Runtime.CompilerServices.DefaultInterpolatedStringHandler(16, 2);
		defaultInterpolatedStringHandler.AppendLiteral("<color=");
		val = EmptyColor.Value;
		defaultInterpolatedStringHandler.AppendFormatted(((colorX)(ref val)).ToHexString(false, "#"));
		defaultInterpolatedStringHandler.AppendLiteral(">");
		defaultInterpolatedStringHandler.AppendFormatted<int>(totalChildCount);
		defaultInterpolatedStringHandler.AppendLiteral("</color>");
		string value2 = defaultInterpolatedStringHandler.ToStringAndClear();
		Slot target2 = ((SyncRef<Slot>)(object)inspector.Root).Target;
		if (LerpColor.Value)
		{
			colorX colorBasedOnSlotCount = GetColorBasedOnSlotCount(totalChildCount, LerpColorInspectRootSlot.Value ? CountSlots(target2) : (LerpColorRootSlot.Value ? CountSlots(((Worker)instance).World.RootSlot) : LerpColorMax.Value));
			value = $"<color={((colorX)(ref colorBasedOnSlotCount)).ToHexString(false, "#")}>{totalChildCount}</color>";
			defaultInterpolatedStringHandler = new global::System.Runtime.CompilerServices.DefaultInterpolatedStringHandler(16, 2);
			defaultInterpolatedStringHandler.AppendLiteral("<color=");
			val = ((colorX)(ref colorBasedOnSlotCount)).MulValue(0.7f);
			defaultInterpolatedStringHandler.AppendFormatted(((colorX)(ref val)).ToHexString(false, "#"));
			defaultInterpolatedStringHandler.AppendLiteral(">");
			defaultInterpolatedStringHandler.AppendFormatted<int>(totalChildCount);
			defaultInterpolatedStringHandler.AppendLiteral("</color>");
			openedColor = defaultInterpolatedStringHandler.ToStringAndClear();
			defaultInterpolatedStringHandler = new global::System.Runtime.CompilerServices.DefaultInterpolatedStringHandler(16, 2);
			defaultInterpolatedStringHandler.AppendLiteral("<color=");
			val = ((colorX)(ref colorBasedOnSlotCount)).MulValue(0.85f);
			defaultInterpolatedStringHandler.AppendFormatted(((colorX)(ref val)).ToHexString(false, "#"));
			defaultInterpolatedStringHandler.AppendLiteral(">");
			defaultInterpolatedStringHandler.AppendFormatted<int>(totalChildCount);
			defaultInterpolatedStringHandler.AppendLiteral("</color>");
			value2 = defaultInterpolatedStringHandler.ToStringAndClear();
		}
		if (DynVars.Value)
		{
			DynamicVariableSpace componentOrAttach = ((ContainerWorker<Component>)(object)((Component)inspector).Slot).GetComponentOrAttach<DynamicVariableSpace>((Predicate<DynamicVariableSpace>)null);
			string dynVarSpaceName = ((SyncField<string>)(object)componentOrAttach.SpaceName).Value;
			if (string.IsNullOrEmpty(dynVarSpaceName))
			{
				((SyncField<string>)(object)componentOrAttach.SpaceName).Value = "Inspector";
				((ComponentBase<Component>)(object)componentOrAttach).Persistent = false;
			}
			if (target2 != null && target == target2)
			{
				((Component)instance).Slot.RunInUpdates(2, (Action)delegate
				{
					//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
					//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
					Slot obj = ((Component)inspector).Slot.FindChildOrAdd("Slot Count Vars", false);
					DynamicValueVariable<string> componentOrAttach2 = ((ContainerWorker<Component>)(object)obj).GetComponentOrAttach<DynamicValueVariable<string>>((Predicate<DynamicValueVariable<string>>)null);
					string text = dynVarSpaceName + "/SlotCountString";
					if (string.IsNullOrEmpty(((SyncField<string>)(object)((DynamicVariableBase<string>)(object)componentOrAttach2).VariableName).Value))
					{
						((ComponentBase<Component>)(object)componentOrAttach2).Persistent = false;
						((SyncField<string>)(object)((DynamicVariableBase<string>)(object)componentOrAttach2).VariableName).Value = text;
						((SyncField<string>)(object)componentOrAttach2.Value).Value = openedColor;
					}
					DynamicValueVariable<int> componentOrAttach3 = ((ContainerWorker<Component>)(object)obj).GetComponentOrAttach<DynamicValueVariable<int>>((Predicate<DynamicValueVariable<int>>)null);
					string text2 = dynVarSpaceName + "/SlotCountInt";
					if (string.IsNullOrEmpty(((SyncField<string>)(object)((DynamicVariableBase<int>)(object)componentOrAttach3).VariableName).Value))
					{
						((ComponentBase<Component>)(object)componentOrAttach3).Persistent = false;
						((SyncField<string>)(object)((DynamicVariableBase<int>)(object)componentOrAttach3).VariableName).Value = text2;
						((SyncField<int>)(object)componentOrAttach3.Value).Value = totalChildCount;
					}
					DynamicVariableHelper.WriteDynamicVariable<string>(((Component)inspector).Slot, text, openedColor);
					DynamicVariableHelper.WriteDynamicVariable<int>(((Component)inspector).Slot, text2, totalChildCount);
				});
			}
		}
		TextExpandIndicator val2 = _expanderIndicator.Target;
		if (val2 == null)
		{
			return;
		}
		if (!ReplaceVanillaButton.Value)
		{
			Slot val3 = ((Component)val2).Slot.Parent.FindChild("RSIC - Button");
			if (val3 == null)
			{
				val3 = ((Component)val2).Slot.Duplicate((Slot)null, true, (DuplicationSettings)null, false);
				val3.Name = "RSIC - Button";
			}
			val3.OrderOffset = -1L;
			TextExpandIndicator val4 = val2;
			val2 = ((ContainerWorker<Component>)(object)val3).GetComponent<TextExpandIndicator>((Predicate<TextExpandIndicator>)null, false);
			if (val2 == null)
			{
				val3.Destroy();
				val2 = val4;
			}
		}
		((SyncField<string>)(object)val2.Closed).Value = value;
		((SyncField<string>)(object)val2.Opened).Value = openedColor;
		ValueObjectInput<string> component = ((ContainerWorker<Component>)(object)((Component)val2).Slot).GetComponent<ValueObjectInput<string>>((Predicate<ValueObjectInput<string>>)null, false);
		if (component != null || ((SyncElement)val2.Empty).IsLinked)
		{
			((SyncField<string>)(object)component.Value).Value = value2;
		}
		else
		{
			((SyncField<string>)(object)val2.Empty).Value = value2;
		}
	}

	private static int CountSlots(Slot slot)
	{
		if (slot == null)
		{
			return 0;
		}
		int slotCount = 0;
		try
		{
			slot.ForeachChild((Action<Slot>)delegate
			{
				slotCount++;
			}, false);
		}
		catch (object obj) when (((Func<bool>)delegate
		{
			// Could not convert BlockContainer to single expression
			object obj2 = ((obj is InvalidOperationException) ? obj : null);
			return obj2 != null && ((global::System.Exception)obj2).Message.Contains("Collection was modified");
		}).Invoke())
		{
		}
		return slotCount;
	}

	private static colorX Lerp(colorX a, colorX b, float t, ColorProfile colorProfile)
	{
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		return new colorX(((colorX)(ref a)).r + (((colorX)(ref b)).r - ((colorX)(ref a)).r) * t, ((colorX)(ref a)).g + (((colorX)(ref b)).g - ((colorX)(ref a)).g) * t, ((colorX)(ref a)).b + (((colorX)(ref b)).b - ((colorX)(ref a)).b) * t, ((colorX)(ref a)).a + (((colorX)(ref b)).a - ((colorX)(ref a)).a) * t, colorProfile);
	}

	private static colorX GetColorBasedOnSlotCount(int slotCount, int maxSlotCount)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: 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_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: 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_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: 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_006e: 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_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		colorX value = LerpMinColor.Value;
		colorX value2 = LerpMidColor.Value;
		colorX value3 = LerpMaxColor.Value;
		ColorProfile mostCommonProfile = GetMostCommonProfile(((colorX)(ref value)).Profile, ((colorX)(ref value2)).Profile, ((colorX)(ref value3)).Profile);
		float num = (float)slotCount / (float)maxSlotCount;
		if (!(num <= 0.5f))
		{
			return Lerp(value2, value3, (num - 0.5f) * 2f, mostCommonProfile);
		}
		return Lerp(value, value2, num * 2f, mostCommonProfile);
	}

	private static ColorProfile GetMostCommonProfile(ColorProfile a, ColorProfile b, ColorProfile c)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Expected I4, but got Unknown
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Expected I4, but got Unknown
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected I4, but got Unknown
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		return Enumerable.First<IGrouping<ColorProfile, ColorProfile>>((global::System.Collections.Generic.IEnumerable<IGrouping<ColorProfile, ColorProfile>>)Enumerable.OrderByDescending<IGrouping<ColorProfile, ColorProfile>, int>(Enumerable.GroupBy<ColorProfile, ColorProfile>((global::System.Collections.Generic.IEnumerable<ColorProfile>)(object)new ColorProfile[3]
		{
			(ColorProfile)(int)a,
			(ColorProfile)(int)b,
			(ColorProfile)(int)c
		}, (Func<ColorProfile, ColorProfile>)((ColorProfile p) => p)), (Func<IGrouping<ColorProfile, ColorProfile>, int>)((IGrouping<ColorProfile, ColorProfile> g) => Enumerable.Count<ColorProfile>((global::System.Collections.Generic.IEnumerable<ColorProfile>)g)))).Key;
	}
}
public static class PluginMetadata
{
	public const string GUID = "NepuShiro.SlotInspectorCounter";

	public const string NAME = "SlotInspectorCounter";

	public const string VERSION = "1.9.4";

	public const string AUTHORS = "NepuShiro";

	public const string REPOSITORY_URL = "https://github.com/NepuShiro/SlotInspectorCounter";
}