Decompiled source of Extractor v1.0.0

BepInEx/plugins/DiceModders.Extractor.dll

Decompiled 9 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using DiceModders.ModCore.Tools;
using DiceModders.UiKit;
using DiceModders.UiKit.Native;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("DiceModders")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Developer tool for Dice Kingdoms: UI and building dumps, frame-time probe.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DiceModders.Extractor")]
[assembly: AssemblyTitle("DiceModders.Extractor")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace DiceModders.Extractor
{
	internal static class BuildingDumpFile
	{
		private static string OutputPath => Path.Combine(Paths.BepInExRootPath, "DiceKingdoms_buildings.txt");

		public static void Run()
		{
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Expected O, but got Unknown
			try
			{
				object obj = FindBuildingTypes();
				if (obj == null)
				{
					Plugin.L.LogWarning((object)"[buildings] BuildingTypes not found - join a match (bottom-bar building panels visible) and try again.");
					return;
				}
				IntPtr intPtr = Mem.PtrOf(Reflect.Call(obj, "get_Types", Array.Empty<object>()));
				if (intPtr == IntPtr.Zero)
				{
					Plugin.L.LogWarning((object)"[buildings] get_Types() returned null.");
					return;
				}
				int num = Mem.ArrayLength(intPtr);
				StringBuilder stringBuilder = new StringBuilder();
				for (int i = 0; i < num; i++)
				{
					IntPtr intPtr2 = Mem.ArrayElem(intPtr, i);
					stringBuilder.Append((intPtr2 == IntPtr.Zero) ? $"{i}: (null)" : Describe(i, intPtr2)).Append("\r\n");
				}
				File.WriteAllText(OutputPath, stringBuilder.ToString());
				ManualLogSource l = Plugin.L;
				bool flag = default(bool);
				BepInExMessageLogInterpolatedStringHandler val = new BepInExMessageLogInterpolatedStringHandler(39, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[buildings] ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" building types written to ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(OutputPath);
				}
				l.LogMessage(val);
			}
			catch (Exception ex)
			{
				Plugin.L.LogError((object)("[buildings] dump failed: " + ex));
			}
		}

		private static object FindBuildingTypes()
		{
			Type type = GameTypes.Find("BuildingTypes");
			if (type != null)
			{
				Il2CppReferenceArray<Object> val = Resources.FindObjectsOfTypeAll(Il2CppType.From(type));
				if (val != null && ((Il2CppArrayBase<Object>)(object)val).Length > 0)
				{
					return Reflect.Wrap(type, Mem.PtrOf((object)((Il2CppArrayBase<Object>)(object)val)[0]));
				}
			}
			Type type2 = GameTypes.Find("RulesBuilding");
			if (type2 != null && type != null)
			{
				Il2CppReferenceArray<Object> val2 = Resources.FindObjectsOfTypeAll(Il2CppType.From(type2));
				if (val2 != null && ((Il2CppArrayBase<Object>)(object)val2).Length > 0)
				{
					IntPtr intPtr = Mem.ReadPtr(Mem.PtrOf((object)((Il2CppArrayBase<Object>)(object)val2)[0]), 24);
					if (intPtr != IntPtr.Zero)
					{
						return Reflect.Wrap(type, intPtr);
					}
				}
			}
			return null;
		}

		private static string Describe(int index, IntPtr bt)
		{
			string value = Reflect.Call(Reflect.Wrap(GameTypes.Find("BuildingType"), bt), "get_DisplayName", Array.Empty<object>())?.ToString() ?? "?";
			IntPtr intPtr = Mem.ReadPtr(bt, 24);
			StringBuilder stringBuilder = new StringBuilder("[");
			int num = Mem.ArrayLength(intPtr);
			for (int i = 0; i < num; i++)
			{
				stringBuilder.Append('[').Append(Mem.ReadInt(intPtr, 32 + i * 8)).Append(',')
					.Append(Mem.ReadInt(intPtr, 32 + i * 8 + 4))
					.Append(']');
				if (i + 1 < num)
				{
					stringBuilder.Append(',');
				}
			}
			stringBuilder.Append(']');
			return $"{index}: {value} | tier={Mem.ReadInt(bt, 120)} hp={Mem.ReadInt(bt, 128)} | {stringBuilder}";
		}
	}
	internal static class FrameProbe
	{
		private sealed class Data
		{
			public string Name;

			public long Ticks;

			public long Calls;
		}

		private static readonly (string Type, string Method)[] Targets = new(string, string)[8]
		{
			("UnitVisual", "Update"),
			("UnitVisual", "SpawnParticles"),
			("ProjectileVisual", "Update"),
			("CombatInterface", "Update"),
			("CombatGrid", "PrepareSimulationStep"),
			("CombatGrid", "SimulationStep"),
			("PlayerSummary", "Update"),
			("GameState", "Update")
		};

		private static readonly Dictionary<MethodBase, Data> Stats = new Dictionary<MethodBase, Data>();

		private static Patcher _patcher;

		private static bool _patched;

		private static bool _on;

		private static ConfigEntry<int> _intervalMs;

		private static readonly Stopwatch Clock = new Stopwatch();

		internal static void Bind(ConfigFile config, Patcher patcher)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			_patcher = patcher;
			_intervalMs = config.Bind<int>("Probe", "ReportIntervalMs", 2000, new ConfigDescription("How often the probe prints its report.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(500, 30000), Array.Empty<object>()));
		}

		internal static void Set(bool on)
		{
			if (on && !_patched)
			{
				_patched = true;
				(string, string)[] targets = Targets;
				for (int i = 0; i < targets.Length; i++)
				{
					var (text, text2) = targets[i];
					_patcher.Patch(text, text2, typeof(FrameProbe), "Prefix", "Postfix");
				}
				_patcher.Summary();
			}
			_on = on;
			foreach (Data value in Stats.Values)
			{
				value.Ticks = 0L;
				value.Calls = 0L;
			}
			Clock.Restart();
			Plugin.L.LogMessage((object)("frame-time probe " + (on ? "on" : "off")));
		}

		internal static void Prefix(out long __state)
		{
			__state = (_on ? Stopwatch.GetTimestamp() : 0);
		}

		internal static void Postfix(MethodBase __originalMethod, long __state)
		{
			if (__state != 0L)
			{
				if (!Stats.TryGetValue(__originalMethod, out var value))
				{
					Dictionary<MethodBase, Data> stats = Stats;
					Data obj = new Data
					{
						Name = __originalMethod.DeclaringType?.Name + "." + __originalMethod.Name
					};
					value = obj;
					stats[__originalMethod] = obj;
				}
				value.Ticks += Stopwatch.GetTimestamp() - __state;
				value.Calls++;
				if (value.Name == "GameState.Update" && Clock.ElapsedMilliseconds >= _intervalMs.Value)
				{
					Report(value);
				}
			}
		}

		private static void Report(Data frames)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			double totalSeconds = Clock.Elapsed.TotalSeconds;
			double num = frames.Calls;
			double num2 = 1000.0 / (double)Stopwatch.Frequency;
			ManualLogSource l = Plugin.L;
			bool flag = default(bool);
			BepInExMessageLogInterpolatedStringHandler val = new BepInExMessageLogInterpolatedStringHandler(25, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[probe] ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(num / totalSeconds, "F1");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" fps  (");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(1000.0 * totalSeconds / num, "F1");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ms/frame)");
			}
			l.LogMessage(val);
			foreach (Data value in Stats.Values)
			{
				if (value != frames && value.Calls > 0)
				{
					double num3 = (double)value.Ticks * num2;
					string text = $"        {value.Name,-28} {(double)value.Calls / num,7:F1} calls/frame  {num3 / num,6:F2} ms/frame  ({1000.0 * num3 / (double)value.Calls:F1} us/call)";
					Plugin.L.LogMessage((object)text);
				}
				value.Ticks = 0L;
				value.Calls = 0L;
			}
			Clock.Restart();
		}
	}
	[BepInPlugin("org.dicemodders.dicekingdoms.extractor", "DiceKingdoms Extractor", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInProcess("Dice-Kingdoms.exe")]
	public sealed class Plugin : BasePlugin
	{
		public const string Guid = "org.dicemodders.dicekingdoms.extractor";

		public const string Name = "DiceKingdoms Extractor";

		public const string Version = "1.0.0";

		internal static ManualLogSource L;

		public override void Load()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			L = ((BasePlugin)this).Log;
			EnableLogging();
			FrameProbe.Bind(((BasePlugin)this).Config, new Patcher("org.dicemodders.dicekingdoms.extractor", ((BasePlugin)this).Log));
			UiScope obj = UiKit.CreateScope("org.dicemodders.dicekingdoms.extractor");
			if (obj != null)
			{
				obj.Native.Settings.AddTab("org.dicemodders.dicekingdoms.extractor", "Extractor", (Action<SettingsTabHandle>)delegate(SettingsTabHandle tab)
				{
					tab.AddInfo("Open the screen you want to capture first (for example Settings > Video, or the lobby). Each file is overwritten by the next dump.");
					tab.AddButton("UI hierarchy", "Write", (Action)UiProbe.Dump);
					tab.AddInfo("All canvases: object names, components, sizes, texts -> BepInEx\\DiceKingdoms_ui.txt");
					tab.AddButton("UI assets", "Write", (Action)UiAssetDump.Run);
					tab.AddInfo("Component types, sprites, fonts, button settings and every loaded sprite -> BepInEx\\DiceKingdoms_ui_assets.txt");
					tab.AddButton("Buildings", "Write", (Action)BuildingDumpFile.Run);
					tab.AddInfo("Building types and footprints -> BepInEx\\DiceKingdoms_buildings.txt (join a match first)");
					tab.AddToggle("Frame-time probe", false, (Action<bool>)FrameProbe.Set);
					tab.AddInfo("While on, the log shows the frame rate and the cost of the game's heaviest per-frame methods every few seconds (in a match).");
				});
			}
		}

		private static void EnableLogging()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			try
			{
				ConfigFile val = new ConfigFile(Path.Combine(Paths.ConfigPath, "BepInEx.cfg"), false);
				ConfigEntry<bool> val2 = val.Bind<bool>("Logging.Console", "Enabled", true, "Enables showing a console for log output.");
				ConfigEntry<bool> val3 = val.Bind<bool>("Logging.Disk", "Enabled", true, "Enables writing log messages to disk.");
				if (!val2.Value || !val3.Value)
				{
					val2.Value = true;
					val3.Value = true;
					val.Save();
					L.LogMessage((object)"BepInEx console window and log file switched on for the next start.");
				}
			}
			catch (Exception ex)
			{
				L.LogWarning((object)("could not update BepInEx.cfg: " + ex.Message));
			}
		}
	}
	internal static class UiAssetDump
	{
		private static MethodInfo _getClass;

		private static MethodInfo _className;

		private static MethodInfo _classNs;

		private static bool _nativeInit;

		private static readonly Dictionary<string, Type> TypeCache = new Dictionary<string, Type>();

		private const int MaxChildren = 40;

		private static readonly HashSet<string> Deny = new HashSet<string>
		{
			"gameObject", "transform", "parent", "root", "hideFlags", "tag", "name", "canvas", "rootCanvas", "mesh",
			"meshes", "sharedMesh", "materials", "sharedMaterials", "rectTransform", "canvasRenderer", "onClick", "isActiveAndEnabled", "runInEditMode", "useGUILayout",
			"enabled", "Pointer", "WasCollected", "ObjectClass", "isStatic"
		};

		private static readonly Dictionary<string, string[]> Curated = new Dictionary<string, string[]>
		{
			["Image"] = new string[9] { "sprite", "overrideSprite", "type", "color", "material", "preserveAspect", "fillCenter", "pixelsPerUnitMultiplier", "raycastTarget" },
			["RawImage"] = new string[5] { "texture", "color", "uvRect", "material", "raycastTarget" },
			["Button"] = new string[5] { "interactable", "transition", "colors", "spriteState", "targetGraphic" },
			["Toggle"] = new string[5] { "interactable", "transition", "isOn", "targetGraphic", "graphic" },
			["Slider"] = new string[5] { "interactable", "minValue", "maxValue", "value", "targetGraphic" },
			["TextMeshProUGUI"] = new string[11]
			{
				"text", "font", "fontSize", "color", "alignment", "fontStyle", "fontSharedMaterial", "enableAutoSizing", "characterSpacing", "lineSpacing",
				"raycastTarget"
			},
			["CanvasScaler"] = new string[5] { "uiScaleMode", "referenceResolution", "screenMatchMode", "matchWidthOrHeight", "scaleFactor" },
			["Animator"] = new string[1] { "runtimeAnimatorController" },
			["HorizontalLayoutGroup"] = new string[3] { "padding", "spacing", "childAlignment" },
			["VerticalLayoutGroup"] = new string[3] { "padding", "spacing", "childAlignment" },
			["GridLayoutGroup"] = new string[3] { "padding", "cellSize", "spacing" },
			["LayoutElement"] = new string[4] { "minWidth", "minHeight", "preferredWidth", "preferredHeight" }
		};

		private static readonly HashSet<string> SkipComponents = new HashSet<string> { "Transform", "RectTransform", "CanvasRenderer" };

		public static string OutputPath => Path.Combine(Paths.BepInExRootPath, "DiceKingdoms_ui_assets.txt");

		private static void InitNative()
		{
			if (_nativeInit)
			{
				return;
			}
			_nativeInit = true;
			try
			{
				Type typeFromHandle = typeof(IL2CPP);
				_getClass = typeFromHandle.GetMethod("il2cpp_object_get_class", new Type[1] { typeof(IntPtr) });
				_className = typeFromHandle.GetMethod("il2cpp_class_get_name", new Type[1] { typeof(IntPtr) });
				_classNs = typeFromHandle.GetMethod("il2cpp_class_get_namespace", new Type[1] { typeof(IntPtr) });
			}
			catch (Exception ex)
			{
				Plugin.L.LogWarning((object)("[uidump] native class lookup unavailable: " + ex.Message));
			}
		}

		public static string ClassNameOf(Il2CppObjectBase o)
		{
			string ns;
			return ClassNameOf(o, out ns);
		}

		public static string ClassNameOf(Il2CppObjectBase o, out string ns)
		{
			ns = "";
			InitNative();
			try
			{
				if (_getClass != null && _className != null && o != null)
				{
					IntPtr intPtr = (IntPtr)_getClass.Invoke(null, new object[1] { o.Pointer });
					if (intPtr != IntPtr.Zero)
					{
						string text = Marshal.PtrToStringAnsi((IntPtr)_className.Invoke(null, new object[1] { intPtr }));
						if (_classNs != null)
						{
							ns = Marshal.PtrToStringAnsi((IntPtr)_classNs.Invoke(null, new object[1] { intPtr })) ?? "";
						}
						if (!string.IsNullOrEmpty(text))
						{
							return text;
						}
					}
				}
			}
			catch (Exception)
			{
			}
			return ((object)o)?.GetType().Name ?? "null";
		}

		private static Type FindWrapperType(string ns, string name)
		{
			string text = (string.IsNullOrEmpty(ns) ? name : (ns + "." + name));
			if (TypeCache.TryGetValue(text, out var value))
			{
				return value;
			}
			Type type = null;
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				try
				{
					type = assembly.GetType(text, throwOnError: false);
				}
				catch (Exception)
				{
				}
				if (type != null)
				{
					break;
				}
			}
			TypeCache[text] = type;
			return type;
		}

		private static object Upcast(Il2CppObjectBase o, out string className, out string ns)
		{
			className = ClassNameOf(o, out ns);
			try
			{
				Type type = FindWrapperType(ns, className);
				if (type != null && type.IsInstanceOfType(o))
				{
					return o;
				}
				if (type != null)
				{
					return Activator.CreateInstance(type, o.Pointer);
				}
			}
			catch (Exception)
			{
			}
			return o;
		}

		private static string Fmt(object v)
		{
			if (v == null)
			{
				return "null";
			}
			if (v is string text)
			{
				return "\"" + ((text.Length > 70) ? (text.Substring(0, 70) + "...") : text).Replace("\n", "\\n").Replace("\r", "") + "\"";
			}
			Type type = v.GetType();
			if (type.IsPrimitive || type.IsEnum || v is decimal)
			{
				return v.ToString();
			}
			Object val = (Object)((v is Object) ? v : null);
			if (val != null)
			{
				string text2;
				try
				{
					text2 = val.name;
				}
				catch (Exception)
				{
					text2 = "?";
				}
				return ClassNameOf((Il2CppObjectBase)(object)val) + ":" + text2;
			}
			if (type.IsValueType)
			{
				return v.ToString();
			}
			return type.Name;
		}

		private static bool IsGameType(Type t)
		{
			try
			{
				return t != null && t.Assembly.GetName().Name.StartsWith("Assembly-CSharp", StringComparison.Ordinal);
			}
			catch (Exception)
			{
				return false;
			}
		}

		private static void DumpProps(object o, string indent, int depth, StringBuilder sb, HashSet<string> seen)
		{
			if (o == null)
			{
				return;
			}
			Type type = o.GetType();
			List<PropertyInfo> list = new List<PropertyInfo>();
			if (Curated.TryGetValue(type.Name, out var value))
			{
				string[] array = value;
				foreach (string name in array)
				{
					PropertyInfo property = type.GetProperty(name);
					if (property != null)
					{
						list.Add(property);
					}
				}
			}
			else if (IsGameType(type))
			{
				Type type2 = type;
				while (type2 != null && IsGameType(type2))
				{
					list.AddRange(type2.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public));
					type2 = type2.BaseType;
				}
			}
			foreach (PropertyInfo item2 in list)
			{
				if (!item2.CanRead || item2.GetIndexParameters().Length != 0 || Deny.Contains(item2.Name))
				{
					continue;
				}
				object value2;
				try
				{
					value2 = item2.GetValue(o);
				}
				catch (Exception)
				{
					continue;
				}
				sb.Append(indent).Append(item2.Name).Append(" = ")
					.AppendLine(Fmt(value2));
				if (depth <= 0)
				{
					continue;
				}
				Object val = (Object)((value2 is Object) ? value2 : null);
				if (val != null && IsGameType(value2.GetType()))
				{
					string item = ((Il2CppObjectBase)val).Pointer.ToString();
					if (seen.Add(item))
					{
						DumpProps(value2, indent + "  ", depth - 1, sb, seen);
					}
				}
			}
		}

		private static void DumpButtonEvents(object button, string indent, StringBuilder sb)
		{
			try
			{
				object obj = default(object);
				if (Reflect.TryGetMember(button, "onClick", ref obj) && obj != null)
				{
					Type type = obj.GetType();
					int num = (int)type.GetMethod("GetPersistentEventCount").Invoke(obj, null);
					sb.Append(indent).Append("onClick persistent listeners = ").AppendLine(num.ToString());
					for (int i = 0; i < num; i++)
					{
						object v = type.GetMethod("GetPersistentTarget").Invoke(obj, new object[1] { i });
						object obj2 = type.GetMethod("GetPersistentMethodName").Invoke(obj, new object[1] { i });
						sb.Append(indent).Append("  [").Append(i)
							.Append("] ")
							.Append(Fmt(v))
							.Append(" . ")
							.AppendLine(Convert.ToString(obj2));
					}
				}
			}
			catch (Exception)
			{
			}
		}

		private static void Walk(Transform t, int depth, StringBuilder sb)
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: 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_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			string text = new string(' ', depth * 2);
			if (depth > 16)
			{
				sb.AppendLine(text + "...");
				return;
			}
			GameObject gameObject = ((Component)t).gameObject;
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(text).Append("- ").Append(((Object)gameObject).name)
				.Append(gameObject.activeSelf ? "" : " [inactive]");
			RectTransform val = ((Il2CppObjectBase)t).TryCast<RectTransform>();
			if ((Object)(object)val != (Object)null)
			{
				Vector2 anchoredPosition = val.anchoredPosition;
				Vector2 sizeDelta = val.sizeDelta;
				StringBuilder stringBuilder2 = stringBuilder;
				StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(40, 10, stringBuilder2);
				handler.AppendLiteral("  pos=");
				handler.AppendFormatted(anchoredPosition.x, "0.#");
				handler.AppendLiteral(",");
				handler.AppendFormatted(anchoredPosition.y, "0.#");
				handler.AppendLiteral(" size=");
				handler.AppendFormatted(sizeDelta.x, "0.#");
				handler.AppendLiteral("x");
				handler.AppendFormatted(sizeDelta.y, "0.#");
				handler.AppendLiteral(" anchors=(");
				handler.AppendFormatted(val.anchorMin.x, "0.##");
				handler.AppendLiteral(",");
				handler.AppendFormatted(val.anchorMin.y, "0.##");
				handler.AppendLiteral(")-(");
				handler.AppendFormatted(val.anchorMax.x, "0.##");
				handler.AppendLiteral(",");
				handler.AppendFormatted(val.anchorMax.y, "0.##");
				handler.AppendLiteral(") pivot=(");
				handler.AppendFormatted(val.pivot.x, "0.##");
				handler.AppendLiteral(",");
				handler.AppendFormatted(val.pivot.y, "0.##");
				handler.AppendLiteral(")");
				stringBuilder2.Append(ref handler);
			}
			sb.AppendLine(stringBuilder.ToString());
			try
			{
				foreach (Component component in gameObject.GetComponents<Component>())
				{
					if ((Object)(object)component == (Object)null)
					{
						continue;
					}
					string className;
					string ns;
					object obj = Upcast((Il2CppObjectBase)(object)component, out className, out ns);
					if (!SkipComponents.Contains(className))
					{
						sb.Append(text).Append("    * ").Append(string.IsNullOrEmpty(ns) ? className : (ns + "." + className))
							.AppendLine();
						DumpProps(obj, text + "        ", 1, sb, new HashSet<string>());
						if (className == "Button")
						{
							DumpButtonEvents(obj, text + "        ", sb);
						}
					}
				}
			}
			catch (Exception ex)
			{
				sb.AppendLine(text + "    (components failed: " + ex.Message + ")");
			}
			int childCount = t.childCount;
			for (int i = 0; i < childCount && i < 40; i++)
			{
				Walk(t.GetChild(i), depth + 1, sb);
			}
			if (childCount > 40)
			{
				sb.AppendLine(text + "  ... " + (childCount - 40) + " more children not listed");
			}
		}

		private static void DumpSprites(StringBuilder sb)
		{
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			sb.AppendLine().AppendLine("##### ALL LOADED SPRITES: name | texture | rect w x h | border (l,b,r,t) | ppu");
			try
			{
				Il2CppReferenceArray<Object> obj = Resources.FindObjectsOfTypeAll(Il2CppType.From(typeof(Sprite)));
				int num = 0;
				foreach (Object item in (Il2CppArrayBase<Object>)(object)obj)
				{
					Sprite val = ((item != null) ? ((Il2CppObjectBase)item).TryCast<Sprite>() : null);
					if (!((Object)(object)val == (Object)null))
					{
						num++;
						string value = "?";
						string value2 = "?";
						string value3 = "?";
						string value4 = "?";
						try
						{
							value = (((Object)(object)val.texture != (Object)null) ? ((Object)val.texture).name : "null");
						}
						catch (Exception)
						{
						}
						try
						{
							Rect rect = val.rect;
							value2 = $"{((Rect)(ref rect)).width:0}x{((Rect)(ref rect)).height:0}";
						}
						catch (Exception)
						{
						}
						try
						{
							value3 = ((object)val.border/*cast due to .constrained prefix*/).ToString();
						}
						catch (Exception)
						{
						}
						try
						{
							value4 = val.pixelsPerUnit.ToString("0.#");
						}
						catch (Exception)
						{
						}
						StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(12, 5, sb);
						handler.AppendFormatted(((Object)val).name);
						handler.AppendLiteral(" | ");
						handler.AppendFormatted(value);
						handler.AppendLiteral(" | ");
						handler.AppendFormatted(value2);
						handler.AppendLiteral(" | ");
						handler.AppendFormatted(value3);
						handler.AppendLiteral(" | ");
						handler.AppendFormatted(value4);
						sb.AppendLine(ref handler);
					}
				}
				sb.AppendLine("# " + num + " sprites");
			}
			catch (Exception ex5)
			{
				sb.AppendLine("(sprite inventory failed: " + ex5.Message + ")");
			}
			sb.AppendLine().AppendLine("##### TMP FONT ASSETS");
			try
			{
				foreach (Object item2 in (Il2CppArrayBase<Object>)(object)Resources.FindObjectsOfTypeAll(Il2CppType.From(typeof(TMP_FontAsset))))
				{
					TMP_FontAsset val2 = ((item2 != null) ? ((Il2CppObjectBase)item2).TryCast<TMP_FontAsset>() : null);
					if ((Object)(object)val2 != (Object)null)
					{
						sb.AppendLine(((Object)val2).name);
					}
				}
			}
			catch (Exception ex6)
			{
				sb.AppendLine("(font inventory failed: " + ex6.Message + ")");
			}
		}

		public static void Run()
		{
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Expected O, but got Unknown
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				StringBuilder stringBuilder = new StringBuilder();
				StringBuilder stringBuilder2 = stringBuilder;
				StringBuilder stringBuilder3 = stringBuilder2;
				StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(41, 3, stringBuilder2);
				handler.AppendLiteral("# Dice Kingdoms UI asset dump, screen ");
				handler.AppendFormatted(Screen.width);
				handler.AppendLiteral("x");
				handler.AppendFormatted(Screen.height);
				handler.AppendLiteral(", ");
				handler.AppendFormatted(DateTime.Now, "yyyy-MM-dd HH:mm:ss");
				stringBuilder3.AppendLine(ref handler);
				stringBuilder.AppendLine("# '* Class' lines list a component with its readable fields; sprites: name, 9-slice border, ppu.");
				int num = 0;
				foreach (Canvas item in Object.FindObjectsOfType<Canvas>())
				{
					if (!((Object)(object)item == (Object)null) && item.isRootCanvas && !((Object)item).name.Contains("Graphy") && !((Object)item).name.Contains("DiceModders"))
					{
						num++;
						stringBuilder2 = stringBuilder.AppendLine();
						StringBuilder stringBuilder4 = stringBuilder2;
						handler = new StringBuilder.AppendInterpolatedStringHandler(47, 5, stringBuilder2);
						handler.AppendLiteral("=== CANVAS '");
						handler.AppendFormatted(((Object)item).name);
						handler.AppendLiteral("' mode=");
						handler.AppendFormatted<RenderMode>(item.renderMode);
						handler.AppendLiteral(" sorting=");
						handler.AppendFormatted(item.sortingOrder);
						handler.AppendLiteral(" scale=");
						handler.AppendFormatted(item.scaleFactor, "0.###");
						handler.AppendLiteral(" active=");
						handler.AppendFormatted(((Component)item).gameObject.activeInHierarchy);
						handler.AppendLiteral(" ===");
						stringBuilder4.AppendLine(ref handler);
						Walk(((Component)item).transform, 0, stringBuilder);
					}
				}
				DumpSprites(stringBuilder);
				File.WriteAllText(OutputPath, stringBuilder.ToString());
				ManualLogSource l = Plugin.L;
				bool flag = default(bool);
				BepInExMessageLogInterpolatedStringHandler val = new BepInExMessageLogInterpolatedStringHandler(62, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[uidump] ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" canvas(es) + sprite/font inventory written to ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(OutputPath);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(stringBuilder.Length / 1024);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" KB)");
				}
				l.LogMessage(val);
			}
			catch (Exception ex)
			{
				Plugin.L.LogError((object)("[uidump] failed: " + ex));
			}
		}
	}
	internal static class UiProbe
	{
		public static string OutputPath => Path.Combine(Paths.BepInExRootPath, "DiceKingdoms_ui.txt");

		public static void Dump()
		{
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Expected O, but got Unknown
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				StringBuilder stringBuilder = new StringBuilder();
				int num = 0;
				StringBuilder stringBuilder2 = stringBuilder;
				StringBuilder stringBuilder3 = stringBuilder2;
				StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(35, 3, stringBuilder2);
				handler.AppendLiteral("# Dice Kingdoms UI dump, screen ");
				handler.AppendFormatted(Screen.width);
				handler.AppendLiteral("x");
				handler.AppendFormatted(Screen.height);
				handler.AppendLiteral(", ");
				handler.AppendFormatted(DateTime.Now, "yyyy-MM-dd HH:mm:ss");
				stringBuilder3.AppendLine(ref handler);
				stringBuilder.AppendLine("# format: name [active] (components) rect | text");
				foreach (Canvas item in Object.FindObjectsOfType<Canvas>())
				{
					if (!((Object)(object)item == (Object)null) && item.isRootCanvas)
					{
						num++;
						stringBuilder.AppendLine();
						stringBuilder2 = stringBuilder;
						StringBuilder stringBuilder4 = stringBuilder2;
						handler = new StringBuilder.AppendInterpolatedStringHandler(47, 5, stringBuilder2);
						handler.AppendLiteral("=== CANVAS '");
						handler.AppendFormatted(((Object)item).name);
						handler.AppendLiteral("' mode=");
						handler.AppendFormatted<RenderMode>(item.renderMode);
						handler.AppendLiteral(" sorting=");
						handler.AppendFormatted(item.sortingOrder);
						handler.AppendLiteral(" scale=");
						handler.AppendFormatted(item.scaleFactor, "0.###");
						handler.AppendLiteral(" active=");
						handler.AppendFormatted(((Component)item).gameObject.activeInHierarchy);
						handler.AppendLiteral(" ===");
						stringBuilder4.AppendLine(ref handler);
						Walk(((Component)item).transform, 0, stringBuilder);
					}
				}
				File.WriteAllText(OutputPath, stringBuilder.ToString());
				ManualLogSource l = Plugin.L;
				bool flag = default(bool);
				BepInExMessageLogInterpolatedStringHandler val = new BepInExMessageLogInterpolatedStringHandler(44, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ui] UI hierarchy of ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" canvas(es) written to ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(OutputPath);
				}
				l.LogMessage(val);
			}
			catch (Exception ex)
			{
				Plugin.L.LogError((object)("[ui] dump failed: " + ex));
			}
		}

		private static void Walk(Transform t, int depth, StringBuilder sb)
		{
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			if (depth > 14)
			{
				sb.AppendLine(new string(' ', depth * 2) + "...");
				return;
			}
			GameObject gameObject = ((Component)t).gameObject;
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(new string(' ', depth * 2)).Append(((Object)gameObject).name).Append(gameObject.activeSelf ? "" : " [inactive]");
			string text = null;
			StringBuilder stringBuilder2 = new StringBuilder();
			try
			{
				object obj = default(object);
				foreach (Component component in gameObject.GetComponents<Component>())
				{
					if ((Object)(object)component == (Object)null)
					{
						continue;
					}
					string text2 = UiAssetDump.ClassNameOf((Il2CppObjectBase)(object)component);
					if (!(text2 == "Transform") && !(text2 == "CanvasRenderer"))
					{
						if (stringBuilder2.Length > 0)
						{
							stringBuilder2.Append(',');
						}
						stringBuilder2.Append(text2);
						if (text == null && Reflect.TryGetMember((object)component, "text", ref obj) && obj is string { Length: >0 } text3)
						{
							text = text3;
						}
					}
				}
			}
			catch (Exception)
			{
			}
			if (stringBuilder2.Length > 0)
			{
				stringBuilder.Append(" (").Append(stringBuilder2).Append(')');
			}
			RectTransform val = ((Il2CppObjectBase)t).TryCast<RectTransform>();
			if ((Object)(object)val != (Object)null)
			{
				Vector2 anchoredPosition = val.anchoredPosition;
				Vector2 sizeDelta = val.sizeDelta;
				StringBuilder stringBuilder3 = stringBuilder;
				StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(29, 8, stringBuilder3);
				handler.AppendLiteral(" pos=");
				handler.AppendFormatted(anchoredPosition.x, "0");
				handler.AppendLiteral(",");
				handler.AppendFormatted(anchoredPosition.y, "0");
				handler.AppendLiteral(" size=");
				handler.AppendFormatted(sizeDelta.x, "0");
				handler.AppendLiteral("x");
				handler.AppendFormatted(sizeDelta.y, "0");
				handler.AppendLiteral(" anchors=(");
				handler.AppendFormatted(val.anchorMin.x, "0.##");
				handler.AppendLiteral(",");
				handler.AppendFormatted(val.anchorMin.y, "0.##");
				handler.AppendLiteral(")-(");
				handler.AppendFormatted(val.anchorMax.x, "0.##");
				handler.AppendLiteral(",");
				handler.AppendFormatted(val.anchorMax.y, "0.##");
				handler.AppendLiteral(")");
				stringBuilder3.Append(ref handler);
			}
			if (text != null)
			{
				stringBuilder.Append(" | ").Append(text.Replace("\n", "\\n").Replace("\r", ""));
			}
			sb.AppendLine(stringBuilder.ToString());
			for (int i = 0; i < t.childCount; i++)
			{
				Walk(t.GetChild(i), depth + 1, sb);
			}
		}
	}
}