Decompiled source of Whats that mod v1.0.2

WhatsMod.dll

Decompiled 8 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using DM;
using HarmonyLib;
using Landfall.TABS;
using Landfall.TABS.UnitEditor;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[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 ModSourceLabel
{
	internal static class AssetBundleLoadAllAssetsHook
	{
		private static bool s_installed;

		private static readonly HashSet<string> s_loggedCallers = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

		internal static void Install()
		{
			//IL_004b: 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_0075: Expected O, but got Unknown
			if (s_installed)
			{
				return;
			}
			MethodInfo methodInfo = AccessTools.Method(typeof(AssetBundle), "LoadAllAssets", new Type[1] { typeof(Type) }, (Type[])null);
			if (methodInfo == null)
			{
				Plugin.LogWarn("[ModLabel] AssetBundle.LoadAllAssets(Type) not found; asset-level capture disabled");
				return;
			}
			try
			{
				new Harmony("saucein.uniteditor.modlabel.assetbundle").Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(AssetBundleLoadAllAssetsHook).GetMethod("Postfix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				s_installed = true;
				Plugin.LogInfo("[ModLabel] hooked AssetBundle.LoadAllAssets(Type)");
			}
			catch (Exception ex)
			{
				Plugin.LogWarn("[ModLabel] AssetBundle hook failed: " + ex.Message);
			}
		}

		private static void Postfix(Object[] __result)
		{
			try
			{
				if (__result == null || __result.Length == 0)
				{
					return;
				}
				string text = ModSourceResolver.FindCallerAssembly("UnityEngine.AssetBundleModule");
				if (string.IsNullOrEmpty(text))
				{
					return;
				}
				int num = 0;
				foreach (Object obj in __result)
				{
					GameObject val = (GameObject)(object)((obj is GameObject) ? obj : null);
					if ((Object)(object)val == (Object)null)
					{
						continue;
					}
					CharacterItem[] componentsInChildren = val.GetComponentsInChildren<CharacterItem>(true);
					foreach (CharacterItem val2 in componentsInChildren)
					{
						if (!((Object)(object)val2 == (Object)null))
						{
							ModSourceResolver.RecordExplicitSource(val2, text);
							num++;
						}
					}
					ProjectileEntity[] componentsInChildren2 = val.GetComponentsInChildren<ProjectileEntity>(true);
					foreach (ProjectileEntity val3 in componentsInChildren2)
					{
						if (!((Object)(object)val3 == (Object)null))
						{
							ModSourceResolver.RecordExplicitProjectileSource(val3, text, null);
							num++;
						}
					}
				}
				if (num > 0 && s_loggedCallers.Add(text))
				{
					Plugin.LogInfo("[ModLabel] AssetBundle content source captured: " + text + " -> " + ModSourceResolver.DisplayNameForAssembly(text) + " (" + num + " items this call, " + ModSourceResolver.ExplicitSourceCount + " total)");
				}
				if (Plugin.CfgVerbose != null && Plugin.CfgVerbose.Value && num > 0)
				{
					Plugin.LogInfo("[ModLabel] AssetBundle.LoadAllAssets from " + text + ": " + num + " CharacterItems");
				}
			}
			catch (Exception ex)
			{
				Plugin.LogWarn("[ModLabel] AssetBundle capture failed: " + ex.Message);
			}
		}
	}
	internal static class DbDiffUtility
	{
		internal static readonly string[] Fields = new string[3] { "m_weapons", "m_characterProps", "m_combatMoves" };

		internal static Dictionary<string, HashSet<object>> Snapshot()
		{
			Dictionary<string, HashSet<object>> dictionary = new Dictionary<string, HashSet<object>>(StringComparer.Ordinal);
			object database = GetDatabase();
			if (database == null)
			{
				return dictionary;
			}
			for (int i = 0; i < Fields.Length; i++)
			{
				IDictionary dictionary2 = GetDictionary(database, Fields[i]);
				if (dictionary2 == null)
				{
					continue;
				}
				HashSet<object> hashSet = new HashSet<object>();
				foreach (object key in dictionary2.Keys)
				{
					hashSet.Add(key);
				}
				dictionary[Fields[i]] = hashSet;
			}
			return dictionary;
		}

		internal static int Capture(Dictionary<string, HashSet<object>> snapshot, string assemblyName, string displayName)
		{
			if (snapshot == null)
			{
				return 0;
			}
			object database = GetDatabase();
			if (database == null)
			{
				return 0;
			}
			int num = 0;
			for (int i = 0; i < Fields.Length; i++)
			{
				string text = Fields[i];
				if (!snapshot.TryGetValue(text, out var value))
				{
					continue;
				}
				IDictionary dictionary = GetDictionary(database, text);
				if (dictionary == null)
				{
					continue;
				}
				foreach (DictionaryEntry item in dictionary)
				{
					if (value.Contains(item.Key))
					{
						continue;
					}
					object? value2 = item.Value;
					GameObject val = (GameObject)((value2 is GameObject) ? value2 : null);
					if (!((Object)(object)val == (Object)null))
					{
						CharacterItem val2 = val.GetComponent<CharacterItem>();
						if ((Object)(object)val2 == (Object)null)
						{
							val2 = val.GetComponentInChildren<CharacterItem>(true);
						}
						if (!((Object)(object)val2 == (Object)null))
						{
							ModSourceResolver.RecordExplicitSource(val2, assemblyName, displayName);
							num++;
						}
					}
				}
			}
			return num;
		}

		private static object GetDatabase()
		{
			try
			{
				return ContentDatabase.Instance().LandfallContentDatabase;
			}
			catch
			{
				return null;
			}
		}

		private static IDictionary GetDictionary(object database, string fieldName)
		{
			try
			{
				FieldInfo fieldInfo = AccessTools.Field(database.GetType(), fieldName);
				return (fieldInfo != null) ? (fieldInfo.GetValue(database) as IDictionary) : null;
			}
			catch
			{
				return null;
			}
		}
	}
	[HarmonyPatch(typeof(UnitEditorEquipedClothing), "Setup")]
	internal static class EquippedPagePatch
	{
		private static FieldInfo s_itemNameField;

		private static bool s_fieldWarningLogged;

		[HarmonyPostfix]
		private static void Postfix(UnitEditorEquipedClothing __instance, EquipedWrapper equiped)
		{
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)__instance == (Object)null)
				{
					return;
				}
				ModSourceLabelHost modSourceLabelHost = ((Component)__instance).GetComponent<ModSourceLabelHost>();
				if ((Object)(object)modSourceLabelHost == (Object)null)
				{
					modSourceLabelHost = ((Component)__instance).gameObject.AddComponent<ModSourceLabelHost>();
				}
				if (equiped == null || (Object)(object)equiped.prop == (Object)null)
				{
					modSourceLabelHost.Hide();
					return;
				}
				if (Plugin.CfgEnabled != null && !Plugin.CfgEnabled.Value)
				{
					modSourceLabelHost.Hide();
					return;
				}
				if (s_itemNameField == null)
				{
					s_itemNameField = AccessTools.Field(typeof(UnitEditorEquipedClothing), "ItemName");
				}
				LocalizeText val = (LocalizeText)((s_itemNameField != null) ? /*isinst with value type is only supported in some contexts*/: null);
				if ((Object)(object)val == (Object)null && !s_fieldWarningLogged)
				{
					s_fieldWarningLogged = true;
					Plugin.LogWarn("[ModLabel] ItemName field not found; label cannot be placed");
				}
				CharacterItem prop = equiped.prop;
				ModSourceResolver.Resolve(prop, out var source, out var detail);
				EquipedWeaponWrapper val2 = (EquipedWeaponWrapper)(object)((equiped is EquipedWeaponWrapper) ? equiped : null);
				if (val2 != null && !string.IsNullOrEmpty(source))
				{
					ProjectileEntity projectile = val2.projectile;
					try
					{
						UnitEditorManager val3 = Object.FindObjectOfType<UnitEditorManager>();
						if ((Object)(object)val3 != (Object)null)
						{
							projectile = val3.GetProjectile(val2);
						}
					}
					catch
					{
					}
					string detail2;
					string text = ModSourceResolver.ResolveProjectileSource(projectile, out detail2);
					if (!string.IsNullOrEmpty(text))
					{
						if (string.IsNullOrEmpty(source))
						{
							source = text;
						}
						else if (!string.Equals(source, text, StringComparison.OrdinalIgnoreCase))
						{
							source = source + " · " + text;
						}
						detail = detail + "; projectile:" + detail2;
					}
				}
				modSourceLabelHost.Bind(val, source);
				if (Plugin.CfgVerbose != null && Plugin.CfgVerbose.Value)
				{
					string text2 = "?";
					try
					{
						text2 = ((object)equiped.GetWrapperType()/*cast due to .constrained prefix*/).ToString();
					}
					catch
					{
					}
					string text3 = "?";
					try
					{
						text3 = prop.DisplayName;
					}
					catch
					{
					}
					Plugin.LogInfo("[ModLabel] " + text2 + " '" + text3 + "' -> " + (source ?? "<vanilla>") + " (" + detail + ")");
				}
			}
			catch (Exception ex)
			{
				Plugin.LogError("[ModLabel] Setup postfix failed: " + ex);
			}
		}
	}
	internal sealed class ModSourceLabelHost : MonoBehaviour
	{
		private LocalizeText m_itemName;

		private TextMeshProUGUI m_label;

		private string m_modName;

		private string m_labelText;

		private string m_lastSourceText;

		private Bounds m_lastBounds;

		private int m_layoutFrames;

		private static readonly Color kLabelColor = new Color(0.62f, 0.8f, 1f, 0.96f);

		internal unsafe void Bind(LocalizeText itemName, string modName)
		{
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//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)
			m_itemName = itemName;
			m_modName = modName;
			if (Plugin.CfgEnabled != null && !Plugin.CfgEnabled.Value)
			{
				Hide();
				return;
			}
			if ((Object)(object)m_itemName == (Object)null || string.IsNullOrEmpty(modName))
			{
				Hide();
				return;
			}
			EnsureLabel();
			if (!((Object)(object)m_label == (Object)null))
			{
				m_labelText = Plugin.FormatLabel(modName);
				if (string.IsNullOrEmpty(m_labelText))
				{
					m_labelText = modName;
				}
				((TMP_Text)m_label).text = m_labelText;
				((Component)m_label).gameObject.SetActive(true);
				m_layoutFrames = 0;
				ApplyStyle();
				RefreshPosition(force: true);
				if (Plugin.CfgVerbose != null && Plugin.CfgVerbose.Value)
				{
					TextMeshProUGUI val = SourceText();
					string[] obj = new string[12]
					{
						"[ModLabel] label='",
						m_labelText,
						"' itemFont='",
						((Object)(object)val != (Object)null && (Object)(object)((TMP_Text)val).font != (Object)null) ? ((Object)((TMP_Text)val).font).name : "null",
						"' labelFont='",
						((Object)(object)((TMP_Text)m_label).font != (Object)null) ? ((Object)((TMP_Text)m_label).font).name : "null",
						"' bounds=",
						null,
						null,
						null,
						null,
						null
					};
					Bounds lastBounds = m_lastBounds;
					obj[7] = ((object)(*(Bounds*)(&lastBounds))/*cast due to .constrained prefix*/).ToString();
					obj[8] = " pos=";
					obj[9] = ((object)((Transform)((TMP_Text)m_label).rectTransform).localPosition/*cast due to .constrained prefix*/).ToString();
					obj[10] = " active=";
					obj[11] = ((Component)m_label).gameObject.activeInHierarchy.ToString();
					Plugin.LogInfo(string.Concat(obj));
				}
			}
		}

		internal void Hide()
		{
			m_modName = null;
			m_labelText = null;
			if ((Object)(object)m_label != (Object)null)
			{
				((Component)m_label).gameObject.SetActive(false);
			}
		}

		private void LateUpdate()
		{
			if (!((Object)(object)m_label == (Object)null) && ((Component)m_label).gameObject.activeSelf)
			{
				if ((Object)(object)m_itemName == (Object)null)
				{
					Hide();
				}
				else if (!((Object)(object)SourceText() == (Object)null))
				{
					ApplyStyle();
					RefreshPosition(force: false);
				}
			}
		}

		private TextMeshProUGUI SourceText()
		{
			if ((Object)(object)m_itemName == (Object)null)
			{
				return null;
			}
			TextMeshProUGUI val = m_itemName.Text;
			if ((Object)(object)val == (Object)null)
			{
				val = ((Component)m_itemName).GetComponent<TextMeshProUGUI>();
			}
			return val;
		}

		private void EnsureLabel()
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Expected O, but got Unknown
			//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_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI val = SourceText();
			if (!((Object)(object)val == (Object)null) && (!((Object)(object)m_label != (Object)null) || !((Object)(object)((TMP_Text)m_label).transform.parent == (Object)(object)((TMP_Text)val).transform)))
			{
				if ((Object)(object)m_label != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)m_label).gameObject);
					m_label = null;
				}
				GameObject val2 = new GameObject("ModSourceLabel", new Type[1] { typeof(RectTransform) });
				val2.transform.SetParent(((TMP_Text)val).transform, false);
				RectTransform val3 = (RectTransform)val2.transform;
				val3.anchorMin = new Vector2(0f, 0f);
				val3.anchorMax = new Vector2(0f, 0f);
				val3.pivot = new Vector2(0f, 1f);
				val3.sizeDelta = new Vector2(520f, 28f);
				((Transform)val3).localScale = Vector3.one;
				((Transform)val3).localRotation = Quaternion.identity;
				m_label = val2.AddComponent<TextMeshProUGUI>();
				((Graphic)m_label).raycastTarget = false;
				((TMP_Text)m_label).alignment = (TextAlignmentOptions)257;
				((TMP_Text)m_label).enableWordWrapping = false;
				((TMP_Text)m_label).overflowMode = (TextOverflowModes)0;
				((TMP_Text)m_label).enableAutoSizing = false;
				((TMP_Text)m_label).richText = true;
				((Graphic)m_label).color = kLabelColor;
				TMP_FontAsset val4 = ChooseFont(val);
				((TMP_Text)m_label).font = val4;
				if ((Object)(object)val4 != (Object)null)
				{
					((TMP_Text)m_label).fontSharedMaterial = ((TMP_Asset)val4).material;
				}
				val2.transform.SetAsLastSibling();
			}
		}

		private static TMP_FontAsset ChooseFont(TextMeshProUGUI source)
		{
			TMP_FontAsset font = ((TMP_Text)source).font;
			if ((Object)(object)font != (Object)null && font.HasCharacter('A', false, false) && font.HasCharacter('0', false, false))
			{
				return font;
			}
			TMP_FontAsset defaultFontAsset = TMP_Settings.defaultFontAsset;
			if ((Object)(object)defaultFontAsset != (Object)null)
			{
				return defaultFontAsset;
			}
			return font;
		}

		private void ApplyStyle()
		{
			TextMeshProUGUI val = SourceText();
			if ((Object)(object)val == (Object)null || (Object)(object)m_label == (Object)null)
			{
				return;
			}
			TMP_FontAsset val2 = ChooseFont(val);
			if ((Object)(object)((TMP_Text)m_label).font != (Object)(object)val2)
			{
				((TMP_Text)m_label).font = val2;
				if ((Object)(object)val2 != (Object)null)
				{
					((TMP_Text)m_label).fontSharedMaterial = ((TMP_Asset)val2).material;
				}
				m_layoutFrames = 0;
			}
			else if ((Object)(object)val2 == (Object)(object)((TMP_Text)val).font && (Object)(object)((TMP_Text)val).fontSharedMaterial != (Object)null && (Object)(object)((TMP_Text)m_label).fontSharedMaterial != (Object)(object)((TMP_Text)val).fontSharedMaterial)
			{
				((TMP_Text)m_label).fontSharedMaterial = ((TMP_Text)val).fontSharedMaterial;
			}
			float num = ((((TMP_Text)val).fontSize > 1f) ? ((TMP_Text)val).fontSize : 24f);
			float num2 = ((Plugin.CfgFontScale != null) ? Plugin.CfgFontScale.Value : 0.62f);
			float num3 = Mathf.Clamp(num * num2, 10f, 40f);
			if (Mathf.Abs(((TMP_Text)m_label).fontSize - num3) > 0.05f)
			{
				((TMP_Text)m_label).fontSize = num3;
				m_layoutFrames = 0;
			}
			if (((TMP_Text)m_label).text != m_labelText && !string.IsNullOrEmpty(m_labelText))
			{
				((TMP_Text)m_label).text = m_labelText;
				m_layoutFrames = 0;
			}
		}

		private void RefreshPosition(bool force)
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: 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_00d8: 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)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: 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_0114: 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)
			TextMeshProUGUI val = SourceText();
			if ((Object)(object)val == (Object)null || (Object)(object)m_label == (Object)null || !((Component)val).gameObject.activeInHierarchy)
			{
				return;
			}
			bool flag = m_lastSourceText != ((TMP_Text)val).text;
			if (flag)
			{
				m_lastSourceText = ((TMP_Text)val).text;
				m_layoutFrames = 0;
			}
			if (force || flag || m_layoutFrames < 10)
			{
				((TMP_Text)val).ForceMeshUpdate(false, false);
				m_lastBounds = ((TMP_Text)val).textBounds;
				if (m_layoutFrames < 10)
				{
					m_layoutFrames++;
				}
			}
			Bounds lastBounds = m_lastBounds;
			float num = ((Plugin.CfgOffsetY != null) ? Mathf.Clamp(Plugin.CfgOffsetY.Value, 0f, 40f) : 6f);
			Rect rect;
			float num2;
			if (!(((Bounds)(ref lastBounds)).size.x > 0.01f))
			{
				rect = ((TMP_Text)val).rectTransform.rect;
				num2 = ((Rect)(ref rect)).xMin;
			}
			else
			{
				num2 = ((Bounds)(ref lastBounds)).min.x;
			}
			float num3 = num2;
			float num4;
			if (!(((Bounds)(ref lastBounds)).size.y > 0.01f))
			{
				rect = ((TMP_Text)val).rectTransform.rect;
				num4 = ((Rect)(ref rect)).yMin - num;
			}
			else
			{
				num4 = ((Bounds)(ref lastBounds)).min.y - num;
			}
			float num5 = num4;
			((Transform)((TMP_Text)m_label).rectTransform).localPosition = new Vector3(num3, num5, 0f);
		}
	}
	internal static class ModSourceResolver
	{
		private sealed class CachedSource
		{
			internal string Name;

			internal string Detail;
		}

		private sealed class ExplicitSource
		{
			internal string Assembly;

			internal string DisplayName;
		}

		private static readonly Dictionary<int, CachedSource> s_cache = new Dictionary<int, CachedSource>();

		private static readonly Dictionary<int, ExplicitSource> s_explicitSources = new Dictionary<int, ExplicitSource>();

		private static readonly Dictionary<string, ExplicitSource> s_explicitByGuid = new Dictionary<string, ExplicitSource>(StringComparer.Ordinal);

		private static readonly Dictionary<int, ExplicitSource> s_blueprintSources = new Dictionary<int, ExplicitSource>();

		private static readonly Dictionary<int, ExplicitSource> s_projectileSources = new Dictionary<int, ExplicitSource>();

		private static readonly Dictionary<string, ExplicitSource> s_projectileByGuid = new Dictionary<string, ExplicitSource>(StringComparer.Ordinal);

		private static readonly Dictionary<string, string> s_manifestNames = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

		private static Dictionary<string, string> s_pluginByAssembly;

		private static int s_pluginMapCount = -1;

		private static HashSet<string> s_vanillaAssemblies;

		private static bool s_vanillaBuildTried;

		private static readonly HashSet<string> s_frameworkAssemblies = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
		{
			"SLMACore", "SLMAcore", "TGCore", "UCM", "CN", "CN_UntranslatedLogger", "UFoxLib", "Terren-UFoxLib", "UnityExplorer", "UniverseLib",
			"UniverseLib.Mono", "Tomlet", "mcs", "BepInEx", "BepInEx.Preloader", "0Harmony", "HarmonyLib", "ModSourceLabel", "EquipQuickButtons", "UCMSearch",
			"FactionRowScroll", "FactionUnitSort", "EditorPossess", "LanguageSwitch", "EquipQuick"
		};

		private static readonly Dictionary<string, string> s_displayAliases = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
		{
			{ "ChouChou_s_Unit", "ChouChou" },
			{ "ChouChou's Units", "ChouChou" },
			{ "ChouChou's Units-part2", "ChouChou" },
			{ "ChouChou's Units-part3", "ChouChou" },
			{ "rwdseerfd", "ChouChou" },
			{ "fhp.cc.chouchou", "ChouChou" },
			{ "Chinese myth", "Chinese_myth" },
			{ "Chinese_myth", "Chinese_myth" },
			{ "ChineseMythology", "Chinese_myth" },
			{ "fhp.cc.monkeyking", "Chinese_myth" },
			{ "Terren-HalloweenMod", "SpookifiedMod" },
			{ "Terren-UFoxLib", "UFoxLib" }
		};

		private static readonly HashSet<string> s_frameworkGuids = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "org.bepinex.plugins.UCM", "com.chinese.patch.allinone", "com.ti.tooltip", "saucein.ucm.modelsearch", "saucein.uniteditor.equipquick", "saucein.uniteditor.modlabel", "com.supermrcat.tabs.hiddenunitstats" };

		internal static int ExplicitSourceCount => s_explicitSources.Count;

		internal static void Resolve(CharacterItem item, out string source, out string detail)
		{
			source = null;
			detail = "none";
			if ((Object)(object)item == (Object)null)
			{
				return;
			}
			Transform transform = ((Component)item).transform;
			if ((Object)(object)transform == (Object)null)
			{
				return;
			}
			if (s_explicitSources.TryGetValue(((Object)item).GetInstanceID(), out var value))
			{
				EnsurePluginMap();
				source = ((!string.IsNullOrEmpty(value.DisplayName)) ? value.DisplayName : DisplayNameFor(value.Assembly));
				detail = "registration:" + value.Assembly;
				return;
			}
			string guid = GetGuid(item);
			if (!string.IsNullOrEmpty(guid) && s_explicitByGuid.TryGetValue(guid, out value))
			{
				EnsurePluginMap();
				source = ((!string.IsNullOrEmpty(value.DisplayName)) ? value.DisplayName : DisplayNameFor(value.Assembly));
				detail = "registration-guid:" + value.Assembly;
				return;
			}
			int instanceID = ((Object)transform).GetInstanceID();
			if (s_cache.TryGetValue(instanceID, out var value2))
			{
				source = value2.Name;
				detail = value2.Detail;
				return;
			}
			EnsurePluginMap();
			Transform sourceRoot;
			string assemblyName;
			string evidence;
			bool num = TryFindPrefixedRoot(transform, out sourceRoot, out assemblyName, out evidence);
			if (!num)
			{
				sourceRoot = transform;
			}
			if (num)
			{
				if (s_pluginByAssembly.TryGetValue(assemblyName, out var value3))
				{
					source = value3;
					detail = evidence;
					Store(instanceID, source, detail);
					return;
				}
				if (IsLikelyModAssembly(assemblyName))
				{
					source = assemblyName;
					detail = evidence;
					Store(instanceID, source, detail);
					return;
				}
			}
			if (HasComponentFromAssembly(sourceRoot, "IDK"))
			{
				source = DisplayNameFor("IDK");
				detail = "tool-component:IDK";
				Store(instanceID, source, detail);
				return;
			}
			ScanComponents(sourceRoot, out var pluginHits, out var customHits);
			Transform parent = sourceRoot.parent;
			int num2 = 0;
			while ((Object)(object)parent != (Object)null && num2++ < 4)
			{
				ScanOwnComponents(parent, pluginHits, customHits);
				parent = parent.parent;
			}
			string text = PickBest(pluginHits, ((Object)sourceRoot).name);
			if (text != null && s_pluginByAssembly.TryGetValue(text, out var value4))
			{
				source = value4;
				detail = "components:" + text + " x" + pluginHits[text];
				Store(instanceID, source, detail);
				return;
			}
			string text2 = PickBest(customHits, ((Object)sourceRoot).name);
			if (text2 != null)
			{
				source = text2;
				detail = "components:" + text2 + " x" + customHits[text2];
				Store(instanceID, source, detail);
				return;
			}
			if (IsAbilityCreatorExample(sourceRoot, item))
			{
				source = DisplayNameFor("IDK");
				detail = "abilitycreator-example";
				Store(instanceID, source, detail);
				return;
			}
			string text3 = FindAssemblyInItemName(item, sourceRoot);
			if (!string.IsNullOrEmpty(text3))
			{
				source = DisplayNameFor(text3);
				detail = "object-name:" + text3;
				Store(instanceID, source, detail);
			}
			else
			{
				Store(instanceID, null, "no-mod-component");
			}
		}

		private static bool HasComponentFromAssembly(Transform root, string assemblyName)
		{
			if ((Object)(object)root == (Object)null)
			{
				return false;
			}
			try
			{
				MonoBehaviour[] componentsInChildren = ((Component)root).GetComponentsInChildren<MonoBehaviour>(true);
				foreach (MonoBehaviour val in componentsInChildren)
				{
					if ((Object)(object)val == (Object)null)
					{
						continue;
					}
					try
					{
						if (((object)val).GetType().Assembly.GetName().Name.Equals(assemblyName, StringComparison.OrdinalIgnoreCase))
						{
							return true;
						}
					}
					catch
					{
					}
				}
			}
			catch
			{
			}
			return false;
		}

		private static string FindAssemblyInItemName(CharacterItem item, Transform sourceRoot)
		{
			if ((Object)(object)item == (Object)null || s_pluginByAssembly == null)
			{
				return null;
			}
			string text = (((Object)(object)sourceRoot != (Object)null) ? ((Object)sourceRoot).name : ((Object)((Component)item).gameObject).name);
			string text2 = null;
			string text3 = null;
			try
			{
				if (item.Entity != null)
				{
					text2 = item.Entity.Name;
				}
				text3 = item.DisplayName;
			}
			catch
			{
			}
			string text4 = null;
			foreach (string key in s_pluginByAssembly.Keys)
			{
				if (key.Length >= 4 && !s_frameworkAssemblies.Contains(key) && !IsIgnoredAssembly(key) && (Contains(text, key) || Contains(text2, key) || Contains(text3, key)) && (text4 == null || key.Length > text4.Length))
				{
					text4 = key;
				}
			}
			return text4;
		}

		private static bool Contains(string text, string value)
		{
			if (!string.IsNullOrEmpty(text))
			{
				return text.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0;
			}
			return false;
		}

		private static bool IsAbilityCreatorExample(Transform sourceRoot, CharacterItem item)
		{
			string text = (((Object)(object)sourceRoot != (Object)null) ? ((Object)sourceRoot).name : (((Object)(object)item != (Object)null) ? ((Object)((Component)item).gameObject).name : null));
			string text2 = null;
			string text3 = null;
			try
			{
				if ((Object)(object)item != (Object)null && item.Entity != null)
				{
					text2 = item.Entity.Name;
				}
				if ((Object)(object)item != (Object)null)
				{
					text3 = item.DisplayName;
				}
			}
			catch
			{
			}
			if (!Contains(text, "<size=8>Example") && !Contains(text2, "<size=8>Example") && !Contains(text3, "<size=8>Example") && !Contains(text, "Example:<size="))
			{
				return false;
			}
			if (s_pluginByAssembly != null)
			{
				return s_pluginByAssembly.ContainsKey("IDK");
			}
			return false;
		}

		private static void Store(int key, string name, string detail)
		{
			if (s_pluginMapCount > 0)
			{
				s_cache[key] = new CachedSource
				{
					Name = name,
					Detail = detail
				};
			}
		}

		internal static void RecordExplicitSource(CharacterItem item, string assemblyName, string displayName = null)
		{
			if ((Object)(object)item == (Object)null || string.IsNullOrEmpty(assemblyName))
			{
				return;
			}
			int instanceID = ((Object)item).GetInstanceID();
			if (!s_explicitSources.ContainsKey(instanceID))
			{
				ExplicitSource value = new ExplicitSource
				{
					Assembly = assemblyName,
					DisplayName = displayName
				};
				s_explicitSources[instanceID] = value;
				string guid = GetGuid(item);
				if (!string.IsNullOrEmpty(guid) && !s_explicitByGuid.ContainsKey(guid))
				{
					s_explicitByGuid[guid] = value;
				}
				Transform transform = ((Component)item).transform;
				if ((Object)(object)transform != (Object)null)
				{
					s_cache.Remove(((Object)transform).GetInstanceID());
				}
			}
		}

		internal static void RecordExplicitProjectileSource(ProjectileEntity projectile, string assemblyName, string displayName)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)projectile == (Object)null || string.IsNullOrEmpty(assemblyName))
			{
				return;
			}
			ExplicitSource value = new ExplicitSource
			{
				Assembly = assemblyName,
				DisplayName = displayName
			};
			s_projectileSources[((Object)projectile).GetInstanceID()] = value;
			try
			{
				if (projectile.Entity != null)
				{
					string text = ((object)projectile.Entity.GUID/*cast due to .constrained prefix*/).ToString();
					if (!string.IsNullOrEmpty(text) && !s_projectileByGuid.ContainsKey(text))
					{
						s_projectileByGuid[text] = value;
					}
				}
			}
			catch
			{
			}
		}

		internal static string ResolveProjectileSource(ProjectileEntity projectile, out string detail)
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			detail = "none";
			if ((Object)(object)projectile == (Object)null)
			{
				return null;
			}
			EnsurePluginMap();
			if (s_projectileSources.TryGetValue(((Object)projectile).GetInstanceID(), out var value))
			{
				detail = "projectile-registration:" + value.Assembly;
				if (string.IsNullOrEmpty(value.DisplayName))
				{
					return DisplayNameFor(value.Assembly);
				}
				return value.DisplayName;
			}
			try
			{
				if (projectile.Entity != null)
				{
					string text = ((object)projectile.Entity.GUID/*cast due to .constrained prefix*/).ToString();
					if (!string.IsNullOrEmpty(text) && s_projectileByGuid.TryGetValue(text, out value))
					{
						detail = "projectile-registration-guid:" + value.Assembly;
						return (!string.IsNullOrEmpty(value.DisplayName)) ? value.DisplayName : DisplayNameFor(value.Assembly);
					}
				}
			}
			catch
			{
			}
			GameObject gameObject = ((Component)projectile).gameObject;
			if ((Object)(object)gameObject == (Object)null)
			{
				return null;
			}
			ScanComponents(gameObject.transform, out var pluginHits, out var _);
			string text2 = PickBest(pluginHits, ((Object)gameObject).name);
			if (!string.IsNullOrEmpty(text2))
			{
				detail = "projectile-components:" + text2 + " x" + pluginHits[text2];
				return DisplayNameFor(text2);
			}
			string text3 = null;
			try
			{
				text3 = projectile.DisplayName;
			}
			catch
			{
			}
			string text4 = FindAssemblyInNames(new string[2]
			{
				((Object)gameObject).name,
				text3
			});
			if (!string.IsNullOrEmpty(text4))
			{
				detail = "projectile-name:" + text4;
				return DisplayNameFor(text4);
			}
			return null;
		}

		internal static void RecordBlueprintSource(UnitBlueprint blueprint, string assemblyName)
		{
			if (!((Object)(object)blueprint == (Object)null) && !string.IsNullOrEmpty(assemblyName))
			{
				int instanceID = ((Object)blueprint).GetInstanceID();
				if (!s_blueprintSources.ContainsKey(instanceID))
				{
					s_blueprintSources[instanceID] = new ExplicitSource
					{
						Assembly = assemblyName,
						DisplayName = null
					};
				}
			}
		}

		internal static string ResolveBlueprintSource(UnitBlueprint blueprint, out string detail)
		{
			detail = "none";
			if ((Object)(object)blueprint == (Object)null)
			{
				return null;
			}
			EnsurePluginMap();
			if (s_blueprintSources.TryGetValue(((Object)blueprint).GetInstanceID(), out var value))
			{
				detail = "base-registration:" + value.Assembly;
				return DisplayNameFor(value.Assembly);
			}
			GameObject unitBase = blueprint.UnitBase;
			if ((Object)(object)unitBase == (Object)null)
			{
				return null;
			}
			ScanComponents(unitBase.transform, out var pluginHits, out var _);
			string text = PickBest(pluginHits, ((Object)unitBase).name);
			if (!string.IsNullOrEmpty(text))
			{
				detail = "base-components:" + text + " x" + pluginHits[text];
				return DisplayNameFor(text);
			}
			string text2 = FindAssemblyInNames(new string[2]
			{
				((Object)unitBase).name,
				(blueprint.Entity != null) ? blueprint.Entity.Name : null
			});
			if (!string.IsNullOrEmpty(text2))
			{
				detail = "base-name:" + text2;
				return DisplayNameFor(text2);
			}
			return null;
		}

		private static string FindAssemblyInNames(string[] names)
		{
			if (names == null || s_pluginByAssembly == null)
			{
				return null;
			}
			string text = null;
			foreach (string key in s_pluginByAssembly.Keys)
			{
				if (key.Length < 4 || s_frameworkAssemblies.Contains(key) || IsIgnoredAssembly(key))
				{
					continue;
				}
				for (int i = 0; i < names.Length; i++)
				{
					if (Contains(names[i], key))
					{
						if (text == null || key.Length > text.Length)
						{
							text = key;
						}
						break;
					}
				}
			}
			return text;
		}

		private static string GetGuid(CharacterItem item)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				return ((Object)(object)item != (Object)null && item.Entity != null) ? ((object)item.Entity.GUID/*cast due to .constrained prefix*/).ToString() : null;
			}
			catch
			{
				return null;
			}
		}

		internal static string DisplayNameForAssembly(string assemblyName)
		{
			EnsurePluginMap();
			return DisplayNameFor(assemblyName);
		}

		private static string DisplayNameFor(string assemblyName)
		{
			if (s_pluginByAssembly != null && s_pluginByAssembly.TryGetValue(assemblyName, out var value))
			{
				return value;
			}
			return assemblyName;
		}

		private static string CleanDllStem(string pluginLocation)
		{
			if (string.IsNullOrEmpty(pluginLocation))
			{
				return null;
			}
			try
			{
				string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(pluginLocation);
				if (string.IsNullOrEmpty(fileNameWithoutExtension))
				{
					return null;
				}
				fileNameWithoutExtension = Regex.Replace(fileNameWithoutExtension, "\\s*\\(\\d+\\)\\s*$", "");
				fileNameWithoutExtension = Regex.Replace(fileNameWithoutExtension, "[ _-]*v?\\d+(?:\\.\\d+)+\\s*$", "");
				return fileNameWithoutExtension.Trim();
			}
			catch
			{
				return null;
			}
		}

		private static string ApplyDisplayAlias(string displayName)
		{
			if (string.IsNullOrEmpty(displayName))
			{
				return displayName;
			}
			if (s_displayAliases.TryGetValue(displayName.Trim(), out var value))
			{
				return value;
			}
			return displayName;
		}

		private static string GetManifestName(string pluginLocation)
		{
			if (string.IsNullOrEmpty(pluginLocation))
			{
				return null;
			}
			string directoryName;
			try
			{
				directoryName = Path.GetDirectoryName(pluginLocation);
			}
			catch
			{
				return null;
			}
			int num = 0;
			while (directoryName != null && num < 3)
			{
				if (s_manifestNames.TryGetValue(directoryName, out var value) && !string.IsNullOrEmpty(value))
				{
					return value;
				}
				string path = Path.Combine(directoryName, "manifest.json");
				if (File.Exists(path))
				{
					try
					{
						Match match = Regex.Match(File.ReadAllText(path), "\"name\"\\s*:\\s*\"((?:\\\\.|[^\"\\\\])*)\"");
						if (match.Success)
						{
							string text = Regex.Unescape(match.Groups[1].Value).Trim();
							if (!string.IsNullOrEmpty(text) && !text.Equals("Rename Me", StringComparison.OrdinalIgnoreCase))
							{
								s_manifestNames[directoryName] = text;
								return text;
							}
						}
					}
					catch
					{
					}
				}
				try
				{
					directoryName = Path.GetDirectoryName(directoryName);
				}
				catch
				{
					break;
				}
				num++;
			}
			return null;
		}

		internal static string FindCallerAssembly(string frameworkAssembly)
		{
			StackTrace stackTrace = new StackTrace(fNeedFileInfo: false);
			for (int i = 0; i < stackTrace.FrameCount; i++)
			{
				StackFrame frame = stackTrace.GetFrame(i);
				if (frame == null)
				{
					continue;
				}
				MethodBase method = frame.GetMethod();
				if (method == null)
				{
					continue;
				}
				Type declaringType = method.DeclaringType;
				if (!(declaringType == null))
				{
					string name;
					try
					{
						name = declaringType.Assembly.GetName().Name;
					}
					catch
					{
						continue;
					}
					if (!string.IsNullOrEmpty(name) && (string.IsNullOrEmpty(frameworkAssembly) || !name.Equals(frameworkAssembly, StringComparison.OrdinalIgnoreCase)) && !name.Equals("ModSourceLabel", StringComparison.OrdinalIgnoreCase) && !name.Equals("System", StringComparison.OrdinalIgnoreCase) && !name.StartsWith("System.", StringComparison.OrdinalIgnoreCase) && !name.StartsWith("Microsoft.", StringComparison.OrdinalIgnoreCase) && !name.StartsWith("Mono.", StringComparison.OrdinalIgnoreCase) && !name.StartsWith("BepInEx", StringComparison.OrdinalIgnoreCase) && !name.StartsWith("0Harmony", StringComparison.OrdinalIgnoreCase) && !name.StartsWith("HarmonyLib", StringComparison.OrdinalIgnoreCase) && IsLikelyModAssembly(name))
					{
						return name;
					}
				}
			}
			return null;
		}

		private static void EnsurePluginMap()
		{
			int num = 0;
			try
			{
				num = Chainloader.PluginInfos.Count;
			}
			catch
			{
				num = 0;
			}
			if (s_pluginByAssembly != null && num == s_pluginMapCount)
			{
				return;
			}
			Dictionary<string, string> dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
			try
			{
				foreach (KeyValuePair<string, PluginInfo> pluginInfo in Chainloader.PluginInfos)
				{
					PluginInfo value = pluginInfo.Value;
					if (value == null || value.Metadata == null || IsFrameworkPlugin(value))
					{
						continue;
					}
					string pluginAssemblyName = GetPluginAssemblyName(value);
					if (!string.IsNullOrEmpty(pluginAssemblyName))
					{
						string pluginDisplayName = GetPluginDisplayName(value, pluginAssemblyName);
						if (!dictionary.ContainsKey(pluginAssemblyName))
						{
							dictionary[pluginAssemblyName] = pluginDisplayName;
						}
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.LogWarn("[ModLabel] plugin map failed: " + ex.Message);
			}
			s_pluginByAssembly = dictionary;
			s_pluginMapCount = num;
			s_cache.Clear();
		}

		private static string GetPluginAssemblyName(PluginInfo info)
		{
			if (info == null)
			{
				return null;
			}
			try
			{
				if ((Object)(object)info.Instance != (Object)null)
				{
					return ((object)info.Instance).GetType().Assembly.GetName().Name;
				}
			}
			catch
			{
			}
			if (!string.IsNullOrEmpty(info.Location))
			{
				return Path.GetFileNameWithoutExtension(info.Location);
			}
			return null;
		}

		private static string GetPluginDisplayName(PluginInfo info, string assemblyName = null)
		{
			if (info == null || info.Metadata == null)
			{
				return null;
			}
			if (string.IsNullOrEmpty(assemblyName))
			{
				assemblyName = GetPluginAssemblyName(info);
			}
			string manifestName = GetManifestName(info.Location);
			string text = ((!string.IsNullOrEmpty(manifestName)) ? manifestName : CleanDllStem(info.Location));
			if (string.IsNullOrEmpty(text))
			{
				text = info.Metadata.Name;
			}
			if (string.IsNullOrEmpty(text))
			{
				text = assemblyName;
			}
			if (string.IsNullOrEmpty(text))
			{
				return null;
			}
			text = ApplyDisplayAlias(text);
			text = text.Trim().Replace("\r", " ").Replace("\n", " ");
			if (text.Length <= 0)
			{
				return assemblyName;
			}
			return text;
		}

		internal static List<string> GetPrerequisites(IEnumerable<string> sourceNames)
		{
			List<string> list = new List<string>();
			if (sourceNames == null)
			{
				return list;
			}
			HashSet<string> hashSet = new HashSet<string>(sourceNames, StringComparer.OrdinalIgnoreCase);
			HashSet<string> seen = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
			try
			{
				foreach (KeyValuePair<string, PluginInfo> pluginInfo in Chainloader.PluginInfos)
				{
					PluginInfo value = pluginInfo.Value;
					if (value != null && value.Metadata != null)
					{
						string pluginDisplayName = GetPluginDisplayName(value);
						if (!string.IsNullOrEmpty(pluginDisplayName) && hashSet.Contains(pluginDisplayName))
						{
							AddDependencies(value, hashSet, list, seen, 0);
							AddManifestDependencies(value, hashSet, list, seen);
							AddReferencedAssemblyDependencies(value, hashSet, list, seen);
						}
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.LogWarn("[ModLabel] prerequisite scan failed: " + ex.Message);
			}
			list.Sort(StringComparer.OrdinalIgnoreCase);
			return list;
		}

		private static void AddReferencedAssemblyDependencies(PluginInfo info, HashSet<string> sources, List<string> result, HashSet<string> seen)
		{
			Assembly assembly = null;
			try
			{
				if ((Object)(object)info.Instance != (Object)null)
				{
					assembly = ((object)info.Instance).GetType().Assembly;
				}
			}
			catch
			{
				return;
			}
			if (assembly == null)
			{
				return;
			}
			AssemblyName[] referencedAssemblies;
			try
			{
				referencedAssemblies = assembly.GetReferencedAssemblies();
			}
			catch
			{
				return;
			}
			for (int i = 0; i < referencedAssemblies.Length; i++)
			{
				string text = ((referencedAssemblies[i] != null) ? referencedAssemblies[i].Name : null);
				if (string.IsNullOrEmpty(text) || IsIgnoredAssembly(text))
				{
					continue;
				}
				PluginInfo val = FindPluginByAssembly(text);
				if (val != null && val.Metadata != null)
				{
					string pluginDisplayName = GetPluginDisplayName(val);
					if (!string.IsNullOrEmpty(pluginDisplayName) && pluginDisplayName.Length >= 4 && pluginDisplayName.IndexOf("BepInEx", StringComparison.OrdinalIgnoreCase) < 0 && pluginDisplayName.IndexOf("Harmony", StringComparison.OrdinalIgnoreCase) < 0 && !sources.Contains(pluginDisplayName) && !seen.Contains(pluginDisplayName) && seen.Add(pluginDisplayName))
					{
						result.Add(pluginDisplayName);
					}
				}
			}
		}

		private static PluginInfo FindPluginByAssembly(string assemblyName)
		{
			try
			{
				foreach (KeyValuePair<string, PluginInfo> pluginInfo in Chainloader.PluginInfos)
				{
					PluginInfo value = pluginInfo.Value;
					if (value != null)
					{
						string pluginAssemblyName = GetPluginAssemblyName(value);
						if (!string.IsNullOrEmpty(pluginAssemblyName) && pluginAssemblyName.Equals(assemblyName, StringComparison.OrdinalIgnoreCase))
						{
							return value;
						}
					}
				}
			}
			catch
			{
			}
			return null;
		}

		private static void AddManifestDependencies(PluginInfo info, HashSet<string> sources, List<string> result, HashSet<string> seen)
		{
			List<string> manifestDependencyNames = GetManifestDependencyNames(info.Location);
			if (manifestDependencyNames.Count == 0)
			{
				return;
			}
			try
			{
				foreach (KeyValuePair<string, PluginInfo> pluginInfo in Chainloader.PluginInfos)
				{
					PluginInfo value = pluginInfo.Value;
					if (value == null || value.Metadata == null)
					{
						continue;
					}
					string pluginDisplayName = GetPluginDisplayName(value);
					if (string.IsNullOrEmpty(pluginDisplayName) || pluginDisplayName.Length < 4 || pluginDisplayName.IndexOf("BepInEx", StringComparison.OrdinalIgnoreCase) >= 0 || sources.Contains(pluginDisplayName) || seen.Contains(pluginDisplayName))
					{
						continue;
					}
					string value2 = NormalizeForDependency(pluginDisplayName);
					bool flag = false;
					for (int i = 0; i < manifestDependencyNames.Count; i++)
					{
						if (NormalizeForDependency(manifestDependencyNames[i]).IndexOf(value2, StringComparison.Ordinal) >= 0)
						{
							flag = true;
							break;
						}
					}
					if (flag)
					{
						seen.Add(pluginDisplayName);
						result.Add(pluginDisplayName);
					}
				}
			}
			catch
			{
			}
		}

		private static string NormalizeForDependency(string value)
		{
			if (string.IsNullOrEmpty(value))
			{
				return string.Empty;
			}
			StringBuilder stringBuilder = new StringBuilder(value.Length);
			foreach (char c in value)
			{
				if (char.IsLetterOrDigit(c))
				{
					stringBuilder.Append(char.ToLowerInvariant(c));
				}
			}
			return stringBuilder.ToString();
		}

		private static List<string> GetManifestDependencyNames(string pluginLocation)
		{
			List<string> list = new List<string>();
			if (string.IsNullOrEmpty(pluginLocation))
			{
				return list;
			}
			string directoryName;
			try
			{
				directoryName = Path.GetDirectoryName(pluginLocation);
			}
			catch
			{
				return list;
			}
			int num = 0;
			while (directoryName != null && num < 3)
			{
				string path = Path.Combine(directoryName, "manifest.json");
				if (File.Exists(path))
				{
					try
					{
						Match match = Regex.Match(File.ReadAllText(path), "\"dependencies\"\\s*:\\s*\\[(.*?)\\]", RegexOptions.Singleline);
						if (match.Success)
						{
							MatchCollection matchCollection = Regex.Matches(match.Groups[1].Value, "\"([^\"]+)\"");
							for (int i = 0; i < matchCollection.Count; i++)
							{
								list.Add(matchCollection[i].Groups[1].Value);
							}
						}
					}
					catch
					{
					}
					return list;
				}
				try
				{
					directoryName = Path.GetDirectoryName(directoryName);
				}
				catch
				{
					break;
				}
				num++;
			}
			return list;
		}

		private static void AddDependencies(PluginInfo info, HashSet<string> sources, List<string> result, HashSet<string> seen, int depth)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			if (info == null || info.Dependencies == null || depth > 3)
			{
				return;
			}
			foreach (BepInDependency dependency in info.Dependencies)
			{
				string text = ((dependency != null) ? dependency.DependencyGUID : null);
				if (string.IsNullOrEmpty(text) || (dependency.Flags & 2) != 0 || text.IndexOf("BepInEx", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("Harmony", StringComparison.OrdinalIgnoreCase) >= 0 || !Chainloader.PluginInfos.TryGetValue(text, out var value))
				{
					continue;
				}
				string pluginDisplayName = GetPluginDisplayName(value);
				if (!string.IsNullOrEmpty(pluginDisplayName) && pluginDisplayName.IndexOf("BepInEx", StringComparison.OrdinalIgnoreCase) < 0 && pluginDisplayName.IndexOf("Harmony", StringComparison.OrdinalIgnoreCase) < 0 && !sources.Contains(pluginDisplayName))
				{
					if (seen.Add(pluginDisplayName))
					{
						result.Add(pluginDisplayName);
					}
					AddDependencies(value, sources, result, seen, depth + 1);
				}
			}
		}

		private static bool IsFrameworkPlugin(PluginInfo info)
		{
			if (info == null || info.Metadata == null)
			{
				return true;
			}
			string item = info.Metadata.GUID ?? string.Empty;
			if (s_frameworkGuids.Contains(item))
			{
				return true;
			}
			string text = info.Metadata.Name ?? string.Empty;
			if (text.IndexOf("汉化", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
			if (text.IndexOf("Tooltip", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
			if (text.IndexOf("Untranslated", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
			if (text.IndexOf("Logger", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
			if (text.IndexOf("Mod Source", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
			string text2 = null;
			try
			{
				if ((Object)(object)info.Instance != (Object)null)
				{
					text2 = ((object)info.Instance).GetType().Assembly.GetName().Name;
				}
			}
			catch
			{
			}
			if (string.IsNullOrEmpty(text2) && !string.IsNullOrEmpty(info.Location))
			{
				text2 = Path.GetFileNameWithoutExtension(info.Location);
			}
			if (!string.IsNullOrEmpty(text2))
			{
				return s_frameworkAssemblies.Contains(text2);
			}
			return false;
		}

		private static bool TryFindPrefixedRoot(Transform itemTransform, out Transform sourceRoot, out string assemblyName, out string evidence)
		{
			sourceRoot = null;
			assemblyName = null;
			evidence = null;
			if ((Object)(object)itemTransform == (Object)null)
			{
				return false;
			}
			Transform val = itemTransform;
			int num = 0;
			while ((Object)(object)val != (Object)null && num++ < 12)
			{
				string text = PrefixOf(((Object)val).name);
				if (!string.IsNullOrEmpty(text) && (s_pluginByAssembly.ContainsKey(text) || IsLikelyModAssembly(text)))
				{
					sourceRoot = val;
					assemblyName = text;
					evidence = "name-prefix:" + ((Object)val).name;
					return true;
				}
				val = val.parent;
			}
			Stack<Transform> stack = new Stack<Transform>();
			stack.Push(itemTransform);
			int num2 = 0;
			while (stack.Count > 0 && num2 < 120)
			{
				Transform val2 = stack.Pop();
				if (!((Object)(object)val2 == (Object)null))
				{
					num2++;
					string text2 = PrefixOf(((Object)val2).name);
					if (!string.IsNullOrEmpty(text2) && (s_pluginByAssembly.ContainsKey(text2) || IsLikelyModAssembly(text2)))
					{
						sourceRoot = val2;
						assemblyName = text2;
						evidence = "name-prefix:" + ((Object)val2).name;
						return true;
					}
					for (int i = 0; i < val2.childCount; i++)
					{
						stack.Push(val2.GetChild(i));
					}
				}
			}
			return false;
		}

		private static string PrefixOf(string objectName)
		{
			if (string.IsNullOrEmpty(objectName))
			{
				return null;
			}
			int num = objectName.IndexOf(':');
			if (num <= 0 || num >= objectName.Length - 1)
			{
				return null;
			}
			string text = objectName.Substring(0, num).Trim();
			if (text.Length == 0 || text.Length > 80)
			{
				return null;
			}
			return text;
		}

		private static void ScanComponents(Transform root, out Dictionary<string, int> pluginHits, out Dictionary<string, int> customHits)
		{
			pluginHits = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
			customHits = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
			MonoBehaviour[] componentsInChildren;
			try
			{
				componentsInChildren = ((Component)root).GetComponentsInChildren<MonoBehaviour>(true);
			}
			catch (Exception ex)
			{
				Plugin.LogWarn("[ModLabel] component scan failed: " + ex.Message);
				return;
			}
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				ProcessBehaviour(componentsInChildren[i], pluginHits, customHits);
			}
		}

		private static void ScanOwnComponents(Transform target, Dictionary<string, int> pluginHits, Dictionary<string, int> customHits)
		{
			if (!((Object)(object)target == (Object)null))
			{
				MonoBehaviour[] components;
				try
				{
					components = ((Component)target).GetComponents<MonoBehaviour>();
				}
				catch
				{
					return;
				}
				for (int i = 0; i < components.Length; i++)
				{
					ProcessBehaviour(components[i], pluginHits, customHits);
				}
			}
		}

		private static void ProcessBehaviour(MonoBehaviour behaviour, Dictionary<string, int> pluginHits, Dictionary<string, int> customHits)
		{
			if ((Object)(object)behaviour == (Object)null)
			{
				return;
			}
			string name;
			try
			{
				Type type = ((object)behaviour).GetType();
				if (type == null)
				{
					return;
				}
				Assembly assembly = type.Assembly;
				if (assembly == null)
				{
					return;
				}
				name = assembly.GetName().Name;
			}
			catch
			{
				return;
			}
			if (!string.IsNullOrEmpty(name) && !IsIgnoredAssembly(name) && !IsGameAssembly(name) && !s_frameworkAssemblies.Contains(name))
			{
				if (s_pluginByAssembly.ContainsKey(name))
				{
					Increment(pluginHits, name);
				}
				else
				{
					Increment(customHits, name);
				}
			}
		}

		private static void Increment(Dictionary<string, int> counts, string key)
		{
			counts.TryGetValue(key, out var value);
			counts[key] = value + 1;
		}

		private static string PickBest(Dictionary<string, int> counts, string rootName)
		{
			string text = null;
			int num = -1;
			foreach (KeyValuePair<string, int> count in counts)
			{
				int value = count.Value;
				if (value > num)
				{
					text = count.Key;
					num = value;
				}
				else if (value == num && text != null)
				{
					bool num2 = !string.IsNullOrEmpty(rootName) && rootName.IndexOf(count.Key, StringComparison.OrdinalIgnoreCase) >= 0;
					bool flag = !string.IsNullOrEmpty(rootName) && rootName.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0;
					if (num2 && !flag)
					{
						text = count.Key;
					}
				}
			}
			return text;
		}

		internal static bool IsLikelyModAssembly(string assemblyName)
		{
			if (string.IsNullOrEmpty(assemblyName))
			{
				return false;
			}
			if (IsIgnoredAssembly(assemblyName))
			{
				return false;
			}
			if (IsGameAssembly(assemblyName))
			{
				return false;
			}
			if (s_frameworkAssemblies.Contains(assemblyName))
			{
				return false;
			}
			return true;
		}

		private static bool IsIgnoredAssembly(string assemblyName)
		{
			if (string.IsNullOrEmpty(assemblyName))
			{
				return true;
			}
			if (assemblyName.Equals("mscorlib", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (assemblyName.Equals("netstandard", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (assemblyName.Equals("System", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (assemblyName.StartsWith("System.", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (assemblyName.StartsWith("Microsoft.", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (assemblyName.StartsWith("Mono.", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (assemblyName.StartsWith("Unity", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (assemblyName.StartsWith("TMPro", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (assemblyName.StartsWith("Unity.TextMeshPro", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (assemblyName.StartsWith("Sirenix", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (assemblyName.StartsWith("DOTween", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (assemblyName.StartsWith("DG.Tweening", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (assemblyName.StartsWith("BepInEx", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (assemblyName.StartsWith("0Harmony", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (assemblyName.StartsWith("HarmonyLib", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (assemblyName.StartsWith("UniverseLib", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (assemblyName.StartsWith("InControl", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (assemblyName.StartsWith("Rewired", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (assemblyName.StartsWith("Newtonsoft", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (assemblyName.StartsWith("Cinemachine", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (assemblyName.StartsWith("PostProcessing", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (assemblyName.Equals("Assembly-CSharp", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (assemblyName.Equals("Assembly-CSharp-firstpass", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			return false;
		}

		private static bool IsGameAssembly(string assemblyName)
		{
			if (string.IsNullOrEmpty(assemblyName))
			{
				return true;
			}
			BuildVanillaAssemblySet();
			if (s_vanillaAssemblies != null)
			{
				return s_vanillaAssemblies.Contains(assemblyName);
			}
			return false;
		}

		private static void BuildVanillaAssemblySet()
		{
			if (s_vanillaBuildTried)
			{
				return;
			}
			s_vanillaBuildTried = true;
			s_vanillaAssemblies = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
			string value = null;
			try
			{
				Assembly assembly = typeof(CharacterItem).Assembly;
				if (assembly != null)
				{
					s_vanillaAssemblies.Add(assembly.GetName().Name);
					string location = assembly.Location;
					if (!string.IsNullOrEmpty(location))
					{
						value = Path.GetDirectoryName(location);
					}
				}
			}
			catch
			{
			}
			if (string.IsNullOrEmpty(value))
			{
				return;
			}
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly2 in assemblies)
			{
				if (assembly2 == null)
				{
					continue;
				}
				try
				{
					string location2 = assembly2.Location;
					if (!string.IsNullOrEmpty(location2) && location2.StartsWith(value, StringComparison.OrdinalIgnoreCase))
					{
						s_vanillaAssemblies.Add(assembly2.GetName().Name);
					}
				}
				catch
				{
				}
			}
		}
	}
	[BepInPlugin("saucein.uniteditor.modlabel", "Mod Source Label", "1.6.9")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInProcess("TotallyAccurateBattleSimulator.exe")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "saucein.uniteditor.modlabel";

		public const string PluginName = "Mod Source Label";

		public const string PluginVersion = "1.6.9";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> CfgEnabled;

		internal static ConfigEntry<string> CfgFormat;

		internal static ConfigEntry<float> CfgFontScale;

		internal static ConfigEntry<float> CfgOffsetY;

		internal static ConfigEntry<bool> CfgVerbose;

		private void Awake()
		{
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			CfgEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Show the source mod name on the equipped clothing / weapon / ability page.");
			CfgFormat = ((BaseUnityPlugin)this).Config.Bind<string>("General", "LabelFormat", "{0}", "Label text. {0} is replaced with the mod name. Rich text tags are supported.");
			CfgFontScale = ((BaseUnityPlugin)this).Config.Bind<float>("General", "FontScale", 0.62f, "Label font size as a fraction of the item name's font size (0.3 - 1.5).");
			CfgOffsetY = ((BaseUnityPlugin)this).Config.Bind<float>("General", "OffsetY", 6f, "Distance in pixels between the bottom of the item name and the label (0 - 40).");
			CfgVerbose = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "VerboseLogging", false, "Log every resolved item and its source to the BepInEx log.");
			TgCoreAddItemsHook.Install();
			UFoxLibAddUnitCreatorPassHook.Install();
			SlmaBundleModHook.Install();
			AssetBundleLoadAllAssetsHook.Install();
			UcmLucmHook.Install();
			TeamColorPaletteHook.Install();
			UnitBaseRegistrationHook.Install();
			HeMoRegistrationHook.Install();
			PropEditorRegistrationHook.Install();
			AbilityCreatorHook.Install();
			MoveEditorHook.Install();
			if (CfgVerbose.Value)
			{
				((MonoBehaviour)this).StartCoroutine(DumpInterestingItems());
			}
			try
			{
				Harmony val = new Harmony("saucein.uniteditor.modlabel");
				val.PatchAll(typeof(EquippedPagePatch));
				val.PatchAll(typeof(SaveScreenOpenPatch));
				val.PatchAll(typeof(SaveScreenEnterPatch));
				Log.LogInfo((object)"[ModLabel] loaded v1.6.9 (equipped page + save screen patches)");
			}
			catch (Exception ex)
			{
				Log.LogError((object)("[ModLabel] Harmony patch failed: " + ex));
			}
		}

		private IEnumerator DumpInterestingItems()
		{
			yield return (object)new WaitForSecondsRealtime(45f);
			try
			{
				CharacterItem[] array = Resources.FindObjectsOfTypeAll<CharacterItem>();
				int num = 0;
				foreach (CharacterItem val in array)
				{
					if ((Object)(object)val == (Object)null || val.Entity == null)
					{
						continue;
					}
					string text = val.DisplayName ?? string.Empty;
					string text2 = val.Entity.Name ?? string.Empty;
					string text3 = ((Object)((Component)val).gameObject).name ?? string.Empty;
					string text4 = text3 + "|" + text + "|" + text2;
					if (text4.IndexOf("感染", StringComparison.Ordinal) < 0 && text4.IndexOf("鲜血", StringComparison.Ordinal) < 0 && text4.IndexOf("初王", StringComparison.Ordinal) < 0 && text4.IndexOf("猩红", StringComparison.Ordinal) < 0 && text4.IndexOf("EXAMPLE", StringComparison.OrdinalIgnoreCase) < 0 && text4.IndexOf("VAMPIRE", StringComparison.OrdinalIgnoreCase) < 0 && text4.IndexOf("CHAKRAM", StringComparison.OrdinalIgnoreCase) < 0)
					{
						continue;
					}
					ModSourceResolver.Resolve(val, out var source, out var detail);
					StringBuilder stringBuilder = new StringBuilder();
					MonoBehaviour[] componentsInChildren = ((Component)val).GetComponentsInChildren<MonoBehaviour>(true);
					for (int j = 0; j < componentsInChildren.Length; j++)
					{
						if ((Object)(object)componentsInChildren[j] == (Object)null)
						{
							continue;
						}
						string name = ((object)componentsInChildren[j]).GetType().Assembly.GetName().Name;
						if (stringBuilder.ToString().IndexOf(name, StringComparison.Ordinal) < 0)
						{
							if (stringBuilder.Length > 0)
							{
								stringBuilder.Append(',');
							}
							stringBuilder.Append(name);
						}
					}
					Log.LogInfo((object)("[ModLabel] DIAG name='" + text3 + "' display='" + text + "' entity='" + text2 + "' src='" + (source ?? "<vanilla>") + "' detail=" + detail + " asm=" + stringBuilder));
					num++;
					if (num >= 80)
					{
						break;
					}
				}
				Log.LogInfo((object)("[ModLabel] DIAG finished, matches=" + num));
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("[ModLabel] DIAG failed: " + ex.Message));
			}
		}

		internal static string FormatLabel(string modName)
		{
			if (string.IsNullOrEmpty(modName))
			{
				return string.Empty;
			}
			string format = ((CfgFormat != null && !string.IsNullOrEmpty(CfgFormat.Value)) ? CfgFormat.Value : "模组:{0}");
			try
			{
				return string.Format(format, modName);
			}
			catch
			{
				return "模组:" + modName;
			}
		}

		internal static void LogInfo(string message)
		{
			if (Log != null)
			{
				Log.LogInfo((object)message);
			}
		}

		internal static void LogWarn(string message)
		{
			if (Log != null)
			{
				Log.LogWarning((object)message);
			}
		}

		internal static void LogError(string message)
		{
			if (Log != null)
			{
				Log.LogError((object)message);
			}
		}
	}
	internal static class PropEditorRegistrationHook
	{
		private static bool s_installed;

		private static int s_captured;

		internal static void Install()
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Expected O, but got Unknown
			if (s_installed)
			{
				return;
			}
			Type type = AccessTools.TypeByName("PropEditor.物品添加类.游戏内容工具");
			if (type == null)
			{
				Plugin.LogInfo("[ModLabel] PropEditor not present; PropEditor capture disabled");
				return;
			}
			MethodInfo method = typeof(PropEditorRegistrationHook).GetMethod("Postfix", BindingFlags.Static | BindingFlags.NonPublic);
			string[] array = new string[5] { "注册武器", "注册道具", "注册能力", "注册单位Base", "注册投射物" };
			int num = 0;
			try
			{
				Harmony val = new Harmony("saucein.uniteditor.modlabel.propeditor");
				for (int i = 0; i < array.Length; i++)
				{
					MethodInfo methodInfo = AccessTools.Method(type, array[i], (Type[])null, (Type[])null);
					if (!(methodInfo == null))
					{
						val.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(method), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						num++;
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.LogWarn("[ModLabel] PropEditor hook failed: " + ex.Message);
				return;
			}
			if (num > 0)
			{
				s_installed = true;
				Plugin.LogInfo("[ModLabel] hooked PropEditor content registration (" + num + " methods)");
			}
		}

		private static void Postfix(GameObject __result)
		{
			try
			{
				if ((Object)(object)__result == (Object)null)
				{
					return;
				}
				CharacterItem val = __result.GetComponent<CharacterItem>();
				if ((Object)(object)val == (Object)null)
				{
					val = __result.GetComponentInChildren<CharacterItem>(true);
				}
				if ((Object)(object)val != (Object)null)
				{
					ModSourceResolver.RecordExplicitSource(val, "PropEditor", "PropEditor");
				}
				else
				{
					ProjectileEntity val2 = __result.GetComponent<ProjectileEntity>();
					if ((Object)(object)val2 == (Object)null)
					{
						val2 = __result.GetComponentInChildren<ProjectileEntity>(true);
					}
					if ((Object)(object)val2 != (Object)null)
					{
						ModSourceResolver.RecordExplicitProjectileSource(val2, "PropEditor", "PropEditor");
					}
				}
				s_captured++;
				if (s_captured == 1)
				{
					Plugin.LogInfo("[ModLabel] PropEditor content captured");
				}
			}
			catch (Exception ex)
			{
				Plugin.LogWarn("[ModLabel] PropEditor capture failed: " + ex.Message);
			}
		}
	}
	internal static class HeMoRegistrationHook
	{
		private static bool s_installed;

		private static int s_captured;

		internal static void Install()
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Expected O, but got Unknown
			if (s_installed)
			{
				return;
			}
			Type type = AccessTools.TypeByName("HeMoDingDingMod.游戏内容工具");
			if (type == null)
			{
				Plugin.LogInfo("[ModLabel] HeMoDingDingMod not present; HeMo capture disabled");
				return;
			}
			MethodInfo method = typeof(HeMoRegistrationHook).GetMethod("Postfix", BindingFlags.Static | BindingFlags.NonPublic);
			string[] array = new string[5] { "注册武器", "注册道具", "注册能力", "注册单位Base", "注册投射物" };
			int num = 0;
			try
			{
				Harmony val = new Harmony("saucein.uniteditor.modlabel.hemo");
				for (int i = 0; i < array.Length; i++)
				{
					MethodInfo methodInfo = AccessTools.Method(type, array[i], (Type[])null, (Type[])null);
					if (!(methodInfo == null))
					{
						val.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(method), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						num++;
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.LogWarn("[ModLabel] HeMo hook failed: " + ex.Message);
				return;
			}
			if (num > 0)
			{
				s_installed = true;
				Plugin.LogInfo("[ModLabel] hooked HeMoDingDingMod content registration (" + num + " methods)");
			}
		}

		private static void Postfix(GameObject __result)
		{
			try
			{
				if ((Object)(object)__result == (Object)null)
				{
					return;
				}
				CharacterItem val = __result.GetComponent<CharacterItem>();
				if ((Object)(object)val == (Object)null)
				{
					val = __result.GetComponentInChildren<CharacterItem>(true);
				}
				if (!((Object)(object)val == (Object)null))
				{
					ModSourceResolver.RecordExplicitSource(val, "HeMoDingDingMod");
					s_captured++;
					if (s_captured == 1)
					{
						Plugin.LogInfo("[ModLabel] HeMoDingDingMod content captured");
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.LogWarn("[ModLabel] HeMo capture failed: " + ex.Message);
			}
		}
	}
	internal static class AbilityCreatorHook
	{
		private static bool s_installed;

		private static Dictionary<string, HashSet<object>> s_snapshot;

		internal static void Install()
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			//IL_006d: 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_0095: Expected O, but got Unknown
			//IL_0095: Expected O, but got Unknown
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Expected O, but got Unknown
			if (s_installed)
			{
				return;
			}
			Type type = AccessTools.TypeByName("IDK.Main");
			if (type == null)
			{
				Plugin.LogInfo("[ModLabel] AbilityCreator not present; AbilityCreator capture disabled");
				return;
			}
			MethodInfo methodInfo = AccessTools.Method(type, "AddAbility", (Type[])null, (Type[])null);
			if (methodInfo == null)
			{
				Plugin.LogWarn("[ModLabel] AbilityCreator.AddAbility not found; capture disabled");
				return;
			}
			try
			{
				Harmony val = new Harmony("saucein.uniteditor.modlabel.abilitycreator");
				val.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(AbilityCreatorHook).GetMethod("Before", BindingFlags.Static | BindingFlags.NonPublic)), new HarmonyMethod(typeof(AbilityCreatorHook).GetMethod("After", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				MethodInfo methodInfo2 = AccessTools.Method(type, "CreateAbility", (Type[])null, (Type[])null);
				if (methodInfo2 != null)
				{
					val.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(AbilityCreatorHook).GetMethod("CreatePostfix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
				s_installed = true;
				Plugin.LogInfo("[ModLabel] hooked AbilityCreator.AddAbility/CreateAbility");
			}
			catch (Exception ex)
			{
				Plugin.LogWarn("[ModLabel] AbilityCreator hook failed: " + ex.Message);
			}
		}

		private static void CreatePostfix(GameObject __result)
		{
			try
			{
				if (!((Object)(object)__result == (Object)null))
				{
					CharacterItem val = __result.GetComponent<CharacterItem>();
					if ((Object)(object)val == (Object)null)
					{
						val = __result.GetComponentInChildren<CharacterItem>(true);
					}
					if (!((Object)(object)val == (Object)null))
					{
						ModSourceResolver.RecordExplicitSource(val, "AbilityCreator", "AbilityCreator");
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.LogWarn("[ModLabel] AbilityCreator create capture failed: " + ex.Message);
			}
		}

		private static void Before()
		{
			try
			{
				s_snapshot = DbDiffUtility.Snapshot();
			}
			catch
			{
				s_snapshot = null;
			}
		}

		private static void After()
		{
			try
			{
				int num = DbDiffUtility.Capture(s_snapshot, "AbilityCreator", "AbilityCreator");
				if (num > 0)
				{
					Plugin.LogInfo("[ModLabel] AbilityCreator content captured: " + num + " items (" + ModSourceResolver.ExplicitSourceCount + " total)");
				}
			}
			catch (Exception ex)
			{
				Plugin.LogWarn("[ModLabel] AbilityCreator capture failed: " + ex.Message);
			}
			finally
			{
				s_snapshot = null;
			}
		}
	}
	internal static class MoveEditorHook
	{
		private static bool s_installed;

		private static Dictionary<string, HashSet<object>> s_snapshot;

		internal static void Install()
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			//IL_006d: 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_0095: Expected O, but got Unknown
			//IL_0095: Expected O, but got Unknown
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Expected O, but got Unknown
			if (s_installed)
			{
				return;
			}
			Type type = AccessTools.TypeByName("Move_Editor.MoveEditor");
			if (type == null)
			{
				Plugin.LogInfo("[ModLabel] MoveEditor not present; MoveEditor capture disabled");
				return;
			}
			MethodInfo methodInfo = AccessTools.Method(type, "ReadMove", (Type[])null, (Type[])null);
			if (methodInfo == null)
			{
				Plugin.LogWarn("[ModLabel] MoveEditor.ReadMove not found; capture disabled");
				return;
			}
			try
			{
				Harmony val = new Harmony("saucein.uniteditor.modlabel.moveeditor");
				val.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(MoveEditorHook).GetMethod("Before", BindingFlags.Static | BindingFlags.NonPublic)), new HarmonyMethod(typeof(MoveEditorHook).GetMethod("After", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				MethodInfo methodInfo2 = AccessTools.Method(type, "ReadMoveCanlog", (Type[])null, (Type[])null);
				if (methodInfo2 != null)
				{
					val.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(MoveEditorHook).GetMethod("CanlogPostfix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				}
				s_installed = true;
				Plugin.LogInfo("[ModLabel] hooked MoveEditor.ReadMove/ReadMoveCanlog");
			}
			catch (Exception ex)
			{
				Plugin.LogWarn("[ModLabel] MoveEditor hook failed: " + ex.Message);
			}
		}

		private static void CanlogPostfix(GameObject __result)
		{
			try
			{
				if (!((Object)(object)__result == (Object)null))
				{
					CharacterItem val = __result.GetComponent<CharacterItem>();
					if ((Object)(object)val == (Object)null)
					{
						val = __result.GetComponentInChildren<CharacterItem>(true);
					}
					if (!((Object)(object)val == (Object)null))
					{
						ModSourceResolver.RecordExplicitSource(val, "MoveEditor", "MoveEditor");
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.LogWarn("[ModLabel] MoveEditor clone capture failed: " + ex.Message);
			}
		}

		private static void Before()
		{
			try
			{
				s_snapshot = DbDiffUtility.Snapshot();
			}
			catch
			{
				s_snapshot = null;
			}
		}

		private static void After()
		{
			try
			{
				int num = DbDiffUtility.Capture(s_snapshot, "MoveEditor", "MoveEditor");
				if (num > 0)
				{
					Plugin.LogInfo("[ModLabel] MoveEditor content captured: " + num + " items (" + ModSourceResolver.ExplicitSourceCount + " total)");
				}
			}
			catch (Exception ex)
			{
				Plugin.LogWarn("[ModLabel] MoveEditor capture failed: " + ex.Message);
			}
			finally
			{
				s_snapshot = null;
			}
		}
	}
	[HarmonyPatch(typeof(UnitEditorSaveScreen), "Open")]
	internal static class SaveScreenOpenPatch
	{
		[HarmonyPostfix]
		private static void Postfix(UnitEditorSaveScreen __instance)
		{
			try
			{
				if (!((Object)(object)__instance == (Object)null))
				{
					SaveScreenModSummary saveScreenModSummary = ((Component)__instance).GetComponent<SaveScreenModSummary>();
					if ((Object)(object)saveScreenModSummary == (Object)null)
					{
						saveScreenModSummary = ((Component)__instance).gameObject.AddComponent<SaveScreenModSummary>();
					}
					saveScreenModSummary.Refresh();
				}
			}
			catch (Exception ex)
			{
				Plugin.LogError("[ModLabel] save screen open summary failed: " + ex);
			}
		}
	}
	[HarmonyPatch(typeof(UnitEditorSaveScreen), "OnEnterSaveScreen")]
	internal static class SaveScreenEnterPatch
	{
		[HarmonyPostfix]
		private static void Postfix(UnitEditorSaveScreen __instance)
		{
			try
			{
				if (!((Object)(object)__instance == (Object)null))
				{
					SaveScreenModSummary component = ((Component)__instance).GetComponent<SaveScreenModSummary>();
					if ((Object)(object)component != (Object)null)
					{
						component.Refresh();
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.LogError("[ModLabel] save screen refresh failed: " + ex);
			}
		}
	}
	internal sealed class SaveScreenModSummary : MonoBehaviour
	{
		private struct BackgroundSkin
		{
			internal bool Valid;

			internal Sprite Sprite;

			internal Type Type;

			internal Material Material;

			internal Color Color;

			internal float PixelsPerUnitMultiplier;
		}

		private const float HeaderHeight = 30f;

		private const float Gap = 8f;

		private UnitEditorSaveScreen m_page;

		private RectTransform m_root;

		private RectTransform m_bodyRect;

		private TextMeshProUGUI m_headerLabel;

		private TextMeshProUGUI m_bodyLabel;

		private GameObject m_body;

		private Button m_headerButton;

		private TMP_FontAsset m_font;

		private bool m_open;

		private bool m_initialized;

		private string m_lastNames;

		private bool m_loggedEmpty;

		private bool m_loggedShown;

		private Dictionary<int, string> m_paletteSources = new Dictionary<int, string>();

		internal void Refresh()
		{
			try
			{
				if ((Object)(object)m_page == (Object)null)
				{
					m_page = ((Component)this).GetComponent<UnitEditorSaveScreen>();
				}
				EnsureBuilt();
				List<string> list = CollectEquippedMods();
				if (list.Count == 0)
				{
					if ((Object)(object)m_root != (Object)null)
					{
						((Component)m_root).gameObject.SetActive(false);
					}
					if (!m_loggedEmpty)
					{
						m_loggedEmpty = true;
						Plugin.LogInfo("[ModLabel] save summary: no modded equipped items");
					}
				}
				else
				{
					if ((Object)(object)m_root == (Object)null)
					{
						return;
					}
					((Component)m_root).gameObject.SetActive(true);
					if (!m_loggedShown)
					{
						m_loggedShown = true;
						Plugin.LogInfo("[ModLabel] save summary shown: " + list.Count + " mods");
					}
					if (!m_initialized)
					{
						m_initialized = true;
						m_open = list.Count <= 6;
					}
					List<string> prerequisites = ModSourceResolver.GetPrerequisites(list);
					string text = string.Join(" · ", list.ToArray());
					if (prerequisites.Count > 0)
					{
						text = text + "\n" + (IsChineseLanguage() ? "前置:" : "Requires: ") + string.Join(" · ", prerequisites.ToArray());
					}
					if (text != m_lastNames)
					{
						m_lastNames = text;
						if ((Object)(object)m_bodyLabel != (Object)null)
						{
							((TMP_Text)m_bodyLabel).text = text;
						}
					}
					if ((Object)(object)m_headerLabel != (Object)null)
					{
						string text2 = (IsChineseLanguage() ? "已装备模组" : "Equipped Mods");
						((TMP_Text)m_headerLabel).text = text2 + " (" + list.Count + ") " + (m_open ? "▼" : "▶");
					}
					UpdateExpandedState();
				}
			}
			catch (Exception ex)
			{
				Plugin.LogError("[ModLabel] save screen summary refresh failed: " + ex);
			}
		}

		private static bool IsChineseLanguage()
		{
			try
			{
				FieldInfo fieldInfo = AccessTools.Field(typeof(Localizer), "m_locale");
				object obj = ((fieldInfo != null) ? fieldInfo.GetValue(null) : null);
				return obj != null && obj.ToString() == "LANG_CH";
			}
			catch
			{
				return false;
			}
		}

		private List<string> CollectEquippedMods()
		{
			List<string> list = new List<string>();
			HashSet<string> seen = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
			UnitEditorManager manager = GetManager();
			if ((Object)(object)manager == (Object)null)
			{
				return list;
			}
			m_paletteSources = BuildPaletteSourceMap(manager.UnitEditorColorPalette);
			AddWrapperList(manager, "equipedClothes", list, seen);
			AddWrapperList(manager, "equipedAbilities", list, seen);
			AddWrapper((EquipedWrapper)(object)manager.RightHandedWeapon, list, seen);
			AddWrapper((EquipedWrapper)(object)manager.LeftHandedWeapon, list, seen);
			AddCurrentBase(manager, list, seen);
			list.Sort(StringComparer.OrdinalIgnoreCase);
			return list;
		}

		private UnitEditorManager GetManager()
		{
			if ((Object)(object)m_page == (Object)null)
			{
				return null;
			}
			try
			{
				FieldInfo fieldInfo = AccessTools.Field(typeof(UnitEditorSaveScreen), "UCManager");
				return (UnitEditorManager)((fieldInfo != null) ? /*isinst with value type is only supported in some contexts*/: null);
			}
			catch
			{
				return null;
			}
		}

		private void AddCurrentBase(UnitEditorManager manager, List<string> result, HashSet<string> seen)
		{
			try
			{
				if (manager.UnitBases == null || manager.UnitBases.Length == 0)
				{
					return;
				}
				FieldInfo fieldInfo = AccessTools.Field(typeof(UnitEditorManager), "currentUnitBase");
				int num = ((fieldInfo != null) ? ((int)fieldInfo.GetValue(manager)) : 0);
				if (num < 0 || num >= manager.UnitBases.Length)
				{
					return;
				}
				UnitBaseWrapper val = manager.UnitBases[num];
				if (val != null && !((Object)(object)val.UnitBaseBlueprint == (Object)null))
				{
					string detail;
					string text = ModSourceResolver.ResolveBlueprintSource(val.UnitBaseBlueprint, out detail);
					if (!string.IsNullOrEmpty(text) && seen.Add(text))
					{
						result.Add(text);
					}
				}
			}
			catch
			{
			}
		}

		private void AddWrapperList(UnitEditorManager manager, string fieldName, List<string> result, HashSet<string> seen)
		{
			try
			{
				FieldInfo fieldInfo = AccessTools.Field(typeof(UnitEditorManager), fieldName);
				IEnumerable enumerable = ((fieldInfo != null) ? (fieldInfo.GetValue(manager) as IEnumerable) : null);
				if (enumerable == null)
				{
					return;
				}
				foreach (object item in enumerable)
				{
					AddWrapper((EquipedWrapper)((item is EquipedWrapper) ? item : null), result, seen);
				}
			}
			catch
			{
			}
		}

		private void AddWrapper(EquipedWrapper wrapper, List<string> result, HashSet<string> seen)
		{
			if (wrapper == null)
			{
				return;
			}
			try
			{
				CharacterItem prop = wrapper.prop;
				if ((Object)(object)prop == (Object)null)
				{
					return;
				}
				ModSourceResolver.Resolve(prop, out var source, out var detail);
				if (!string.IsNullOrEmpty(source) && seen.Add(source))
				{
					result.Add(source);
				}
				EquipedWeaponWrapper val = (EquipedWeaponWrapper)(object)((wrapper is EquipedWeaponWrapper) ? wrapper : null);
				if (val != null && !string.IsNullOrEmpty(source))
				{
					ProjectileEntity val2 = null;
					UnitEditorManager manager = GetManager();
					if ((Object)(object)manager != (Object)null)
					{
						try
						{
							val2 = manager.GetProjectile(val);
						}
						catch
						{
						}
					}
					if ((Object)(object)val2 == (Object)null)
					{
						val2 = val.projectile;
					}
					string text = ModSourceResolver.ResolveProjectileSource(val2, out detail);
					if (!string.IsNullOrEmpty(text) && seen.Add(text))
					{
						result.Add(text);
					}
				}
				AddPaletteSources(wrapper.propData, result, seen);
			}
			catch
			{
			}
		}

		private void AddPaletteSources(PropItemData propData, List<string> result, HashSet<string> seen)
		{
			if (propData == null || propData.m_colors == null || m_paletteSources == null)
			{
				return;
			}
			for (int i = 0; i < propData.m_colors.Length; i++)
			{
				string value;
				if (propData.m_isTeamColor != null && i < propData.m_isTeamColor.Length && propData.m_isTeamColor[i])
				{
					if (TeamColorPaletteHook.TryGetSource(propData.m_colors[i], out var source) && !string.IsNullOrEmpty(source) && seen.Add(source))
					{
						result.Add(source);
					}
				}
				else if (m_paletteSources.TryGetValue(propData.m_colors[i], out value) && !string.IsNullOrEmpty(value) && seen.Add(value))
				{
					result.Add(value);
				}
			}
		}

		private static Dictionary<int, string> BuildPaletteSourceMap(UnitEditorColorPalette palette)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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_0061: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<int, string> dictionary = new Dictionary<int, string>();
			if ((Object)(object)palette == (Object)null)
			{
				return dictionary;
			}
			try
			{
				ParentCatagories[] colorPaletteParentCatagories = palette.ColorPaletteParentCatagories;
				if (colorPaletteParentCatagories == null)
				{
					return dictionary;
				}
				int num = 0;
				foreach (ParentCatagories val in colorPaletteParentCatagories)
				{
					if (val.colorPaletteCatagories == null)
					{
						continue;
					}
					for (int j = 0; j < val.colorPaletteCatagories.Length; j++)
					{
						ColorPaletteCatagory val2 = val.colorPaletteCatagories[j];
						if ((int)val2.Cataogry != 0)
						{
							continue;
						}
						int num2 = ((val2.Colors != null) ? val2.Colors.Length : 0);
						for (int k = 0; k < num2; k++)
						{
							string value = PaletteSourceFor(val.name, val2.name);
							if (!string.IsNullOrEmpty(value))
							{
								dictionary[num] = value;
							}
							num++;
						}
					}
				}
			}
			catch
			{
			}
			return dictionary;
		}

		private static string PaletteSourceFor(string parentName, string categoryName)
		{
			string text = (parentName ?? string.Empty) + "|" + (categoryName ?? string.Empty);
			if (text.IndexOf("MorePallete", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("MorePalette", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return "MorePalette";
			}
			if (text.IndexOf("BasicColor-more", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("SpecialColors", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return "ColorFulUC";
			}
			return null;
		}

		private void EnsureBuilt()
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			//IL_00d7: 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_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: 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_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Expected O, but got Unknown
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: 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_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_036c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0364: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_0375: Unknown result type (might be due to invalid IL or missing references)
			//IL_0395: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0420: Unknown result type (might be due to invalid IL or missing references)
			//IL_045b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0462: Expected O, but got Unknown
			//IL_046a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0474: Expected O, but got Unknown
			//IL_0496: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0553: Unknown result type (might be due to invalid IL or missing references)
			//IL_058d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0598: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c1: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)m_root != (Object)null)
			{
				return;
			}
			Button val = null;
			try
			{
				FieldInfo fieldInfo = AccessTools.Field(typeof(UnitEditorSaveScreen), "saveButton");
				val = (Button)((fieldInfo != null) ? /*isinst with value type is only supported in some contexts*/: null);
			}
			catch
			{
			}
			RectTransform val2 = (RectTransform)(((Object)(object)val != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
			Transform val3 = (((Object)(object)val2 != (Object)null && (Object)(object)((Transform)val2).parent != (Object)null) ? ((Transform)val2).parent : ((Component)this).transform);
			GameObject val4 = new GameObject("EquippedModSummary", new Type[1] { typeof(RectTransform) });
			m_root = (RectTransform)val4.transform;
			((Transform)m_root).SetParent(val3, false);
			((Transform)m_root).SetAsLastSibling();
			((Transform)m_root).localScale = Vector3.one;
			((Transform)m_root).localRotation = Quaternion.identity;
			if ((Object)(object)val2 != (Object)null)
			{
				m_root.anchorMin = val2.anchorMin;
				m_root.anchorMax = val2.anchorMax;
				m_root.pivot = new Vector2(0.5f, 1f);
				Rect rect = val2.rect;
				float num;
				if (!(((Rect)(ref rect)).width > 20f))
				{
					num = 420f;
				}
				else
				{
					rect = val2.rect;
					num = ((Rect)(ref rect)).width;
				}
				float num2 = num;
				m_root.sizeDelta = new Vector2(num2, 30f);
				RectTransform root = m_root;
				float x = val2.anchoredPosition.x;
				float y = val2.anchoredPosition.y;
				rect = val2.rect;
				root.anchoredPosition = new Vector2(x, y - ((Rect)(ref rect)).height - 8f);
			}
			else
			{
				m_root.anchorMin = new Vector2(0.5f, 0f);
				m_root.anchorMax = new Vector2(0.5f, 0f);
				m_root.pivot = new Vector2(0.5f, 0f);
				m_root.sizeDelta = new Vector2(420f, 30f);
				m_root.anchoredPosition = new Vector2(0f, 60f);
			}
			val4.AddComponent<LayoutElement>().ignoreLayout = true;
			m_font = FindFont(val);
			BackgroundSkin skin = CaptureBackgroundSkin(val);
			GameObject val5 = new GameObject("Header", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(Button)
			});
			RectTransform val6 = (RectTransform)val5.transform;
			((Transform)val6).SetParent((Transform)(object)m_root, false);
			val6.anchorMin = new Vector2(0f, 1f);
			val6.anchorMax = new Vector2(1f, 1f);
			val6.pivot = new Vector2(0.5f, 1f);
			val6.sizeDelta = new Vector2(0f, 30f);
			val6.anchoredPosition = Vector2.zero;
			Image component = val5.GetComponent<Image>();
			ApplyBackground(component, skin, header: true);
			m_headerButton = val5.GetComponent<Button>();
			((Selectable)m_headerButton).targetGraphic = (Graphic)(object)component;
			((UnityEvent)m_headerButton.onClick).AddListener(new UnityAction(Toggle));
			ColorBlock colors = (((Object)(object)val != (Object)null) ? ((Selectable)val).colors : ColorBlock.defaultColorBlock);
			((ColorBlock)(ref colors)).normalColor = Color.white;
			((ColorBlock)(ref colors)).highlightedColor = new Color(1f, 1f, 1f, 0.92f);
			((ColorBlock)(ref colors)).pressedColor = new Color(0.82f, 0.82f, 0.82f, 1f);
			((ColorBlock)(ref colors)).selectedColor = Color.white;
			((Selectable)m_headerButton).colors = colors;
			((Selectable)m_headerButton).transition = (Transition)1;
			m_headerLabel = CreateText(val5.transform, "HeaderLabel", (TextAlignmentOptions)514, 16f);
			((Graphic)m_headerLabel).color = new Color(0.94f, 0.95f, 0.98f, 1f);
			((Graphic)m_headerLabel).raycastTarget = false;
			GameObject val7 = new GameObject("Body", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			m_bodyRect = (RectTransform)val7.transform;
			((Transform)m_bodyRect).SetParent((Transform)(object)m_root, false);
			m_bodyRect.anchorMin = new Vector2(0f, 0f);
			m_bodyRect.anchorMax = new Vector2(1f, 1f);
			m_bodyRect.pivot = new Vector2(0.5f, 1f);
			m_bodyRect.offsetMin = new Vector2(0f, 0f);
			m_bodyRect.offsetMax = new Vector2(0f, -30f);
			ApplyBackground(val7.GetComponent<Image>(), skin, header: false);
			m_bodyLabel = CreateText(val7.transform, "BodyLabel", (TextAlignmentOptions)257, 13f);
			((Graphic)m_bodyLabel).color = new Color(0.8f, 0.84f, 0.92f, 1f);
			((TMP_Text)m_bodyLabel).enableWordWrapping = true;
			((TMP_Text)m_bodyLabel).overflowMode = (TextOverflowModes)0;
			((Graphic)m_bodyLabel).raycastTarget = false;
			RectTransform rectTransform = ((TMP_Text)m_bodyLabel).rectTransform;
			rectTransform.anchorMin = Vector2.zero;
			rectTransform.anchorMax = Vector2.one;
			rectTransform.offsetMin = new Vector2(10f, 6f);
			rectTransform.offsetMax = new Vector2(-10f, -4f);
			m_body = val7;
		}

		private void UpdateExpandedState()
		{
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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)
			if ((Object)(object)m_body == (Object)null || (Object)(object)m_bodyLabel == (Object)null || (Object)(object)m_bodyRect == (Object)null)
			{
				return;
			}
			m_body.SetActive(m_open);
			if (!m_open)
			{
				if ((Object)(object)m_root != (Object)null)
				{
					m_root.sizeDelta = new Vector2(m_root.sizeDelta.x, 30f);
				}
				return;
			}
			((TMP_Text)m_bodyLabel).ForceMeshUpdate(false, false);
			float num = Mathf.Clamp(((TMP_Text)m_bodyLabel).preferredHeight + 14f, 30f, 150f);
			if ((Object)(object)m_root != (Object)null)
			{
				m_root.sizeDelta = new Vector2(m_root.sizeDelta.x, 30f + num + 3f);
			}
			m_bodyRect.offsetMax = new Vector2(0f, -33f);
		}

		private void Toggle()
		{
			m_open = !m_open;
			Refresh();
		}

		private TextMeshProUGUI CreateText(Transform parent, string name, TextAlignmentOptions alignment, float size)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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)
			//IL_0037: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent(parent, false);
			val2.anchorMin = new Vector2(0f, 0f);
			val2.anchorMax = new Vector2(1f, 1f);
			val2.offsetMin = new Vector2(8f, 2f);
			val2.offsetMax = new Vector2(-8f, -2f);
			TextMeshProUGUI val3 = val.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val3).font = m_font;
			if ((Object)(object)m_font != (Object)null)
			{
				((TMP_Text)val3).fontSharedMaterial = ((TMP_Asset)m_font).material;
			}
			((TMP_Text)val3).fontSize = size;
			((TMP_Text)val3).alignment = alignment;
			((TMP_Text)val3).enableWordWrapping = true;
			((TMP_Text)val3).overflowMode = (TextOverflowModes)3;
			return val3;
		}

		private BackgroundSkin CaptureBackgroundSkin(Button saveButton)
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			BackgroundSkin result = default(BackgroundSkin);
			Image val = FindDescriptionBackground();
			if ((Object)(object)val == (Object)null && (Object)(object)saveButton != (Object)null)
			{
				Graphic targetGraphic = ((Selectable)saveButton).targetGraphic;
				val = (Image)(object)((targetGraphic is Image) ? targetGraphic : null);
				if ((Object)(object)val == (Object)null)
				{
					val = ((Component)saveButton).GetComponent<Image>();
				}
				if ((Object)(object)val == (Object)null)
				{
					val = ((Component)saveButton).GetComponentInChildren<Image>(true);
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				return result;
			}
			re