Decompiled source of SUPER CAT Data Editor v1.1.2

SUPER CAT Stats.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Landfall.TABS;
using Landfall.TABS.UnitEditor;
using TFBGames;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace SuperMrCat.TabsHiddenStats;

internal static class LocalizedText
{
	public static string Translate(string key)
	{
		if (string.IsNullOrWhiteSpace(key))
		{
			return null;
		}
		string singlePhrase;
		try
		{
			singlePhrase = Localizer.GetSinglePhrase(key, (string[])null);
		}
		catch (Exception)
		{
			return key;
		}
		if (string.IsNullOrWhiteSpace(singlePhrase))
		{
			return key;
		}
		if (!Localization.IsChinese() && Localization.HasCjk(singlePhrase))
		{
			return null;
		}
		return singlePhrase;
	}
}
[BepInPlugin("com.supermrcat.tabs.hiddenunitstats", "Hidden Stats Editor", "1.9.0")]
public class HiddenStatsPlugin : BaseUnityPlugin
{
	public const string Guid = "com.supermrcat.tabs.hiddenunitstats";

	public const string PluginName = "Hidden Stats Editor";

	public const string PluginVersion = "1.9.0";

	internal static HiddenStatsPlugin Instance;

	internal static ManualLogSource Log;

	internal static ConfigEntry<bool> CfgEnabled;

	internal static ConfigEntry<bool> CfgLivePreview;

	internal static ConfigEntry<bool> CfgFixScroll;

	internal static ConfigEntry<bool> CfgClampListScroll;

	internal static ConfigEntry<bool> CfgWidenAttackSpeed;

	internal static ConfigEntry<bool> CfgVerbose;

	internal static ConfigEntry<float> CfgScrollSensitivity;

	internal static ConfigEntry<bool> CfgTauntZeroNaN;

	internal static ConfigEntry<bool> CfgSizeNoLimit;

	internal static ConfigEntry<bool> CfgResetButtons;

	internal static ConfigEntry<bool> CfgUnlimitCost;

	internal static ConfigEntry<bool> CfgUnlimitedCostRange;

	internal static ConfigEntry<int> CfgMaxCustomCost;

	internal static ConfigEntry<bool> CfgNegativeCostUI;

	internal static ConfigEntry<bool> CfgWeaponTooltip;

	internal static ConfigEntry<float> CfgWeaponTooltipSeconds;

	internal static ConfigEntry<LanguageMode> CfgLanguage;

	internal static ConfigEntry<bool> CfgUnlimitDesc;

	private static Harmony harmony;

	private static GameObject m_tooltipHost;

	private static readonly string[] CfgDescZh = new string[17]
	{
		"是否在兵种编辑器「属性」页追加隐藏属性行。", "修改数值后是否自动重建预览兵种(关闭则需重新载入兵种才能看到效果)。", "属性页行数变多后是否自动加上下滚动条。", "放宽近战武器攻速钳制(原版近战攻速只能 1x-2x,放宽后才能真正把双手武器改慢/改快)。", "输出详细调试日志(排查问题用)。", "属性页滚轮灵敏度(像素/格)。", "「嘲讽值」填 0 时,把兵种蓝图里的 targetingPriorityMultiplier 写成 NaN(配置文件中会保存为 NaN)。", "解除原生「尺寸」「重量」两行的数值限制(原版有上下限,开启后可以输入任意数字,包括负数和小数)。", "在每一行数值框左边加一个「重置」按钮,点一下恢复成最开始的那份预设值。", "解除兵种「自定义价格」的数值限制:正数、负数都能填,保存时按真实数字写进蓝图。",
		"彻底不设上限,只受兵种文件本身 Int32 边界的限制(约 ±21 亿)。关掉它才会启用下面的 MaxCustomCost。", "仅在 UnlimitedCostRange=false 时生效的正价格上限。", "负价格在界面上显示成 -100,而不是 uint 补码 4294967196。", "在武器栏里右键一件武器时,弹出只读属性卡片(名称 / 武器种类 / 攻击速度 / 伤害 / 弹药)。", "武器属性卡片在右键之后停留多少秒自动关闭(0 = 不自动关闭)。", "界面语言:Auto=跟随游戏语言;Chinese=强制中文;English=强制英文。", "解除兵种编辑器「简介」描述输入框的字数上限,可以填写任意长度的完整简介。"
	};

	private static readonly string[] CfgDescEn = new string[17]
	{
		"Adds hidden stat rows to the unit editor's Stats page.", "Rebuild the preview unit automatically after editing a value (otherwise reload the unit to see changes).", "Add a scroll area to the Stats page when it has too many rows.", "Loosen the vanilla melee attack-speed clamp (vanilla melee attack speed is limited to 1x-2x).", "Write detailed diagnostic logs (for troubleshooting).", "Scroll wheel sensitivity on the Stats page (pixels per notch).", "When Taunt Value is set to 0, write NaN into targetingPriorityMultiplier in the unit blueprint (NaN is saved in the config file).", "Remove the vanilla limits on Size and Weight (allows any number, including negatives and decimals).", "Add a Reset button to the left of each value field; click it to restore the initial preset value.", "Remove the limits on the unit's Custom Cost: positive and negative values are saved as-is.",
		"Remove any upper bound; limited only by the blueprint's Int32 range (about +/-2.1 billion). Disable to use MaxCustomCost.", "Positive cost cap that only applies when UnlimitedCostRange=false.", "Show a negative cost as -100 instead of the uint two's-complement 4294967196.", "Right-click a weapon in the weapon list to show a read-only stats card (name / type / attack speed / damage / ammo).", "How many seconds the weapon stats card stays open after right-click (0 = never auto-close).", "UI language: Auto = follow the game language; Chinese = force Chinese; English = force English.", "Removes the character limit on the unit editor's Description field so you can write a full-length description."
	};

	private static FieldInfo s_descField;

	internal static string DiagPath;

	private void Awake()
	{
		//IL_0262: Unknown result type (might be due to invalid IL or missing references)
		//IL_026c: Expected O, but got Unknown
		//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e2: Expected O, but got Unknown
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		CfgEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "是否在兵种编辑器「属性」页追加隐藏属性行。");
		CfgLivePreview = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "LivePreview", true, "修改数值后是否自动重建预览兵种(关闭则需重新载入兵种才能看到效果)。");
		CfgFixScroll = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "FixOverflowScroll", true, "属性页行数变多后是否自动加上下滚动条。");
		CfgWidenAttackSpeed = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "WidenMeleeAttackSpeedRange", true, "放宽近战武器攻速钳制(原版近战攻速只能 1x-2x,放宽后才能真正把双手武器改慢/改快)。");
		CfgVerbose = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "VerboseLog", false, "输出详细调试日志(排查问题用)。");
		CfgScrollSensitivity = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ScrollSensitivity", 35f, "属性页滚轮灵敏度(像素/格)。");
		CfgTauntZeroNaN = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "TauntZeroBecomesNaN", true, "「嘲讽值」填 0 时,把兵种蓝图里的 targetingPriorityMultiplier 写成 NaN(配置文件中会保存为 NaN)。");
		CfgSizeNoLimit = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "UnlimitSizeWeight", true, "解除原生「尺寸」「重量」两行的数值限制(原版有上下限,开启后可以输入任意数字,包括负数和小数)。");
		CfgResetButtons = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ResetButtons", true, "在每一行数值框左边加一个「重置」按钮,点一下恢复成最开始的那份预设值。");
		CfgUnlimitCost = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "UnlimitCustomCost", true, "解除兵种「自定义价格」的数值限制:正数、负数都能填,保存时按真实数字写进蓝图。");
		CfgUnlimitedCostRange = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "UnlimitedCostRange", true, "彻底不设上限,只受兵种文件本身 Int32 边界的限制(约 ±21 亿)。关掉它才会启用下面的 MaxCustomCost。");
		CfgMaxCustomCost = ((BaseUnityPlugin)this).Config.Bind<int>("General", "MaxCustomCost", int.MaxValue, "仅在 UnlimitedCostRange=false 时生效的正价格上限。");
		CfgNegativeCostUI = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "NegativeCostUI", true, "负价格在界面上显示成 -100,而不是 uint 补码 4294967196。");
		CfgWeaponTooltip = ((BaseUnityPlugin)this).Config.Bind<bool>("WeaponTooltip", "Enabled", true, "在武器栏里右键一件武器时,弹出只读属性卡片(名称 / 武器种类 / 攻击速度 / 伤害 / 弹药)。");
		CfgWeaponTooltipSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("WeaponTooltip", "AutoHideSeconds", 8f, "武器属性卡片在右键之后停留多少秒自动关闭(0 = 不自动关闭)。");
		CfgLanguage = ((BaseUnityPlugin)this).Config.Bind<LanguageMode>("General", "Language", LanguageMode.Auto, "界面语言:Auto=跟随游戏语言;Chinese=强制中文;English=强制英文。");
		CfgUnlimitDesc = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "UnlimitedDescription", true, "解除兵种编辑器「简介」描述输入框的字数上限,可以填写任意长度的完整简介。");
		CfgClampListScroll = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ClampListScroll", false, "把服装/技能等候选列表的滚动钳制在视口边界内(实验性:可能影响超长列表拖拽,默认关闭)。");
		harmony = new Harmony("com.supermrcat.tabs.hiddenunitstats");
		Localization.SetMode(CfgLanguage.Value);
		try
		{
			harmony.PatchAll(typeof(HiddenStatsPlugin).Assembly);
			ScrollKeep.Attach(harmony);
			if (CfgVerbose.Value)
			{
				Log.LogInfo((object)"[HiddenStats] Harmony 补丁已全部应用。");
			}
		}
		catch (Exception ex)
		{
			Log.LogError((object)("[HiddenStats] 打补丁失败:" + ex));
		}
		try
		{
			m_tooltipHost = new GameObject("TabsHiddenStats_WeaponTooltip");
			Object.DontDestroyOnLoad((Object)(object)m_tooltipHost);
			m_tooltipHost.AddComponent<WeaponStatsTooltip>();
		}
		catch (Exception ex2)
		{
			Log.LogError((object)("[HiddenStats] 武器属性浮层挂载失败:" + ex2));
		}
		try
		{
			ApplyConfigDescriptions();
		}
		catch (Exception)
		{
		}
	}

	internal static void ApplyConfigDescriptions()
	{
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Expected O, but got Unknown
		string[] array = (Localization.IsChinese() ? CfgDescZh : CfgDescEn);
		ConfigEntryBase[] array2 = (ConfigEntryBase[])(object)new ConfigEntryBase[18]
		{
			(ConfigEntryBase)CfgEnabled,
			(ConfigEntryBase)CfgLivePreview,
			(ConfigEntryBase)CfgFixScroll,
			(ConfigEntryBase)CfgWidenAttackSpeed,
			(ConfigEntryBase)CfgVerbose,
			(ConfigEntryBase)CfgScrollSensitivity,
			(ConfigEntryBase)CfgTauntZeroNaN,
			(ConfigEntryBase)CfgSizeNoLimit,
			(ConfigEntryBase)CfgResetButtons,
			(ConfigEntryBase)CfgUnlimitCost,
			(ConfigEntryBase)CfgUnlimitedCostRange,
			(ConfigEntryBase)CfgMaxCustomCost,
			(ConfigEntryBase)CfgNegativeCostUI,
			(ConfigEntryBase)CfgWeaponTooltip,
			(ConfigEntryBase)CfgWeaponTooltipSeconds,
			(ConfigEntryBase)CfgLanguage,
			(ConfigEntryBase)CfgUnlimitDesc,
			(ConfigEntryBase)CfgClampListScroll
		};
		if (s_descField == null)
		{
			try
			{
				Type typeFromHandle = typeof(ConfigEntryBase);
				FieldInfo[] fields = typeFromHandle.GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
				for (int i = 0; i < fields.Length; i++)
				{
					if (fields[i].FieldType == typeof(ConfigDescription))
					{
						s_descField = fields[i];
						break;
					}
				}
			}
			catch (Exception)
			{
				s_descField = null;
			}
		}
		if (s_descField == null)
		{
			return;
		}
		for (int j = 0; j < array2.Length && j < array.Length; j++)
		{
			if (array2[j] != null)
			{
				try
				{
					s_descField.SetValue(array2[j], (object?)new ConfigDescription(array[j], (AcceptableValueBase)null, new object[0]));
				}
				catch (Exception)
				{
				}
			}
		}
	}

	private void Update()
	{
		LocalizationSync.Tick();
		try
		{
			if (Input.GetKeyDown((KeyCode)290))
			{
				WeaponInventoryExporter.Export();
			}
		}
		catch (Exception ex)
		{
			Diag("[清单] 导出失败:" + ex);
		}
		try
		{
			Patch_SetCustomCost.TickDescriptionLimit();
			Patch_SetCustomCost.TickMouseScroll();
		}
		catch (Exception)
		{
		}
		try
		{
			ScrollKeep.Tick();
		}
		catch (Exception)
		{
		}
	}

	internal static void Verbose(string msg)
	{
		if (CfgVerbose != null && CfgVerbose.Value)
		{
			Log.LogInfo((object)msg);
		}
	}

	internal static void Diag(string msg)
	{
		try
		{
			if (DiagPath == null)
			{
				DiagPath = Path.Combine(Paths.BepInExRootPath, "HiddenStats_diag.log");
			}
			File.AppendAllText(DiagPath, DateTime.Now.ToString("HH:mm:ss") + "  " + msg + "\r\n");
		}
		catch (Exception)
		{
		}
		if (Log != null)
		{
			Log.LogInfo((object)msg);
		}
	}
}
internal enum LanguageMode
{
	Auto,
	Chinese,
	English
}
internal static class Localization
{
	private const int LANG_EN_US = 0;

	private const int LANG_CH = 7;

	private static FieldInfo _localeField;

	private static FieldInfo _settingsField;

	private static int _lastLocale = -9999;

	private static float _nextProbe;

	private static int _revision;

	private static LanguageMode _mode = LanguageMode.Auto;

	private static int _lastGoodLocale = -9999;

	internal static readonly string[] NamesZh = new string[5] { "动画速度", "步伐速度", "手臂抬起幅度", "嘲讽值", "转向速度" };

	internal static readonly string[] NamesEn = new string[5] { "Animation Speed", "Stride Speed", "Arm Raise Height", "Taunt Value", "Turn Speed" };

	internal static readonly string[] DescriptionsZh = new string[5] { "单位整体动画的播放速度。1.00 = 原速。", "步行时腿脚摆动的频率。1.00 = 原速。", "手臂可以抬起的最大幅度。", "被 AI 优先锁定攻击的程度。越大越容易被围攻。", "单位转身的角速度。越大转身越快。" };

	internal static readonly string[] DescriptionsEn = new string[5] { "Animation playback speed of the whole unit. 1.00 = normal.", "How fast the legs swing while walking. 1.00 = normal.", "Maximum height the arms can be raised.", "How strongly the AI targets this unit first. Higher = more likely to be swarmed.", "Rotation speed of the unit. Higher = turns faster." };

	private static MethodInfo _fontMethod;

	private static bool _fontProbed;

	internal static int Revision => _revision;

	internal static int Locale()
	{
		if (_localeField == null)
		{
			try
			{
				_localeField = AccessTools.Field(typeof(Localizer), "m_locale");
				_settingsField = AccessTools.Field(typeof(Localizer), "m_settings");
			}
			catch (Exception)
			{
				_localeField = null;
				_settingsField = null;
			}
		}
		if (_localeField == null)
		{
			if (_lastGoodLocale != -9999)
			{
				return _lastGoodLocale;
			}
			return 7;
		}
		try
		{
			object value = _localeField.GetValue(null);
			if (value == null)
			{
				return (_lastGoodLocale == -9999) ? 7 : _lastGoodLocale;
			}
			return _lastGoodLocale = Convert.ToInt32(value);
		}
		catch (Exception)
		{
			return (_lastGoodLocale == -9999) ? 7 : _lastGoodLocale;
		}
	}

	internal static void SetMode(LanguageMode mode)
	{
		_mode = mode;
	}

	internal static bool IsChinese()
	{
		if (_mode == LanguageMode.Chinese)
		{
			return true;
		}
		if (_mode == LanguageMode.English)
		{
			return false;
		}
		return Locale() == 7;
	}

	internal static bool UseChinese()
	{
		return IsChinese();
	}

	internal static string ModeName()
	{
		if (_mode == LanguageMode.Chinese)
		{
			return "Chinese";
		}
		if (_mode == LanguageMode.English)
		{
			return "English";
		}
		return "Auto";
	}

	internal static int LastGoodLocale()
	{
		return _lastGoodLocale;
	}

	internal static bool UseEnglish()
	{
		return !IsChinese();
	}

	internal static bool Poll()
	{
		float realtimeSinceStartup = Time.realtimeSinceStartup;
		if (realtimeSinceStartup < _nextProbe)
		{
			return false;
		}
		_nextProbe = realtimeSinceStartup + 0.4f;
		int num = Locale();
		if (num == _lastLocale)
		{
			return false;
		}
		bool flag = _lastLocale == -9999;
		_lastLocale = num;
		if (flag)
		{
			HiddenStatsPlugin.Diag("[语言] 初始语言 locale=" + num + "(0=英文 7=中文),插件文案按此选择");
			_revision++;
			return true;
		}
		_revision++;
		HiddenStatsPlugin.Diag("[语言] 检测到语言切换 → locale=" + num + "(0=英文 7=中文),插件文案改用" + ((num == 7) ? "中文" : "英文"));
		return true;
	}

	internal static string Name(int index)
	{
		if (index < 0 || index >= NamesZh.Length)
		{
			return string.Empty;
		}
		if (!UseChinese())
		{
			return NamesEn[index];
		}
		return NamesZh[index];
	}

	internal static string Desc(int index)
	{
		if (index < 0 || index >= DescriptionsZh.Length)
		{
			return string.Empty;
		}
		if (!UseChinese())
		{
			return DescriptionsEn[index];
		}
		return DescriptionsZh[index];
	}

	internal static string ResetLabel()
	{
		if (!UseChinese())
		{
			return "R\nE\nS\nE\nT";
		}
		return "重\n置";
	}

	internal static float ResetLabelSize()
	{
		if (!UseChinese())
		{
			return 15f;
		}
		return 26f;
	}

	internal static string T(string key)
	{
		bool flag = IsChinese();
		switch (key)
		{
		case "focus":
			if (!flag)
			{
				return "Weak Point";
			}
			return "重点部位";
		case "dotzone":
			if (!flag)
			{
				return "DoT Zone";
			}
			return "持续伤害区";
		case "splash":
			if (!flag)
			{
				return "Splash";
			}
			return "溅射";
		case "spell":
			if (!flag)
			{
				return "Spell";
			}
			return "法术";
		case "bite":
			if (!flag)
			{
				return "Bite";
			}
			return "撕咬";
		case "dot":
			if (!flag)
			{
				return "DoT";
			}
			return "持续伤害";
		case "impact":
			if (!flag)
			{
				return "Impact";
			}
			return "撞击";
		case "projectile":
			if (!flag)
			{
				return "Projectile";
			}
			return "投射物";
		case "spawned":
			if (!flag)
			{
				return "Spawned";
			}
			return "召唤单位";
		case "assass":
			if (!flag)
			{
				return "Assassinate";
			}
			return "刺杀";
		case "stun":
			if (!flag)
			{
				return "Stun";
			}
			return "眩晕";
		default:
			return key;
		}
	}

	internal static bool HasCjk(string s)
	{
		if (string.IsNullOrEmpty(s))
		{
			return false;
		}
		foreach (char c in s)
		{
			if ((c >= '一' && c <= '鿿') || (c >= '㐀' && c <= '䶿') || (c >= '豈' && c <= '\ufaff') || (c >= '\u3000' && c <= '〿') || (c >= '\uff00' && c <= '\uffef'))
			{
				return true;
			}
		}
		return false;
	}

	internal static string En(string s, string fallback)
	{
		if (IsChinese())
		{
			return s;
		}
		if (string.IsNullOrEmpty(s))
		{
			return fallback;
		}
		if (!HasCjk(s))
		{
			return s;
		}
		if (!string.IsNullOrEmpty(fallback) && !HasCjk(fallback))
		{
			return fallback;
		}
		return "—";
	}

	internal static string DeCjk(string s)
	{
		if (string.IsNullOrEmpty(s))
		{
			return s;
		}
		if (!HasCjk(s))
		{
			return s;
		}
		s = s.Replace("持续伤害区", "DoT Zone");
		s = s.Replace("投射物命中", "Projectile Hit");
		s = s.Replace("重点部位", "Weak Point");
		s = s.Replace("持续伤害", "DoT");
		s = s.Replace("召唤单位", "Spawned");
		s = s.Replace("生成单位", "Spawned");
		s = s.Replace("投射物", "Projectile");
		s = s.Replace("撞击", "Impact");
		s = s.Replace("溅射", "Splash");
		s = s.Replace("法术", "Spell");
		s = s.Replace("撕咬", "Bite");
		s = s.Replace("刺杀", "Assassinate");
		s = s.Replace("眩晕", "Stun");
		s = s.Replace("弹药", "Ammo");
		s = s.Replace("未命名", "Unnamed");
		s = s.Replace("包含 ", "Includes ");
		s = s.Replace(" 件武器", " weapons");
		s = s.Replace("件武器", "weapons");
		s = s.Replace(":", ": ");
		s = s.Replace("/秒", "/s");
		if (HasCjk(s))
		{
			return "—";
		}
		return s;
	}

	internal static TMP_FontAsset CurrentFont()
	{
		if (!_fontProbed)
		{
			_fontProbed = true;
			try
			{
				_fontMethod = AccessTools.Method(typeof(Localizer), "GetCurrentFont", (Type[])null, (Type[])null);
			}
			catch (Exception)
			{
				_fontMethod = null;
			}
		}
		if (_fontMethod == null)
		{
			return null;
		}
		try
		{
			object? obj = _fontMethod.Invoke(null, new object[1] { 0 });
			return (TMP_FontAsset)((obj is TMP_FontAsset) ? obj : null);
		}
		catch (Exception)
		{
			return null;
		}
	}
}
internal static class ExtraStats
{
	internal const int Count = 5;

	internal static readonly int[] Ids = new int[5] { 101, 102, 103, 104, 105 };

	private static int _syncedRevision = -9999;

	internal static readonly float[] Defaults = new float[5] { 1f, 1f, 1f, 1f, 10f };

	internal static readonly float[] Mins = new float[5] { -9999999f, -9999999f, -9999999f, -9999999f, -9999999f };

	internal static readonly float[] Maxs = new float[5] { 9999999f, 9999999f, 9999999f, 9999999f, 9999999f };

	internal static readonly bool[] UseMultiplierMode = new bool[5] { true, true, true, true, false };

	internal static StatsWrapper[] Wrappers;

	internal static readonly float[] LastValues = new float[5] { 1f, 1f, 1f, 1f, 10f };

	internal static UnitEditorManager LastManager;

	internal static readonly int[] UnlockedNativeStats = new int[2] { 1, 2 };

	private static bool _nativeRangeLogged;

	internal static bool TauntTouchedByUser;

	internal static UnitBlueprint LastSyncedBp;

	internal static readonly FieldInfo LoadedUnitField = AccessTools.Field(typeof(UnitEditorManager), "loadedUnit");

	internal static readonly FieldInfo CellStatField = AccessTools.Field(typeof(UnitEditorStatCell), "stat");

	internal static readonly MethodInfo RespawnUnitMethod = AccessTools.Method(typeof(UnitEditorManager), "RespawnUnit", (Type[])null, (Type[])null);

	private static bool previewPending;

	private static int scrollBuiltForInstanceId = 0;

	internal static string Name(int index)
	{
		return Localization.Name(index);
	}

	internal static string Desc(int index)
	{
		return Localization.Desc(index);
	}

	internal static void SyncText()
	{
		if (Wrappers == null || _syncedRevision == Localization.Revision)
		{
			return;
		}
		_syncedRevision = Localization.Revision;
		for (int i = 0; i < Wrappers.Length && i < 5; i++)
		{
			if (Wrappers[i] != null)
			{
				Wrappers[i].name = Name(i);
				Wrappers[i].description = Desc(i);
			}
		}
	}

	internal static void EnsureWrappers()
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		//IL_0030: 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)
		if (Wrappers == null)
		{
			StatsWrapper[] array = (StatsWrapper[])(object)new StatsWrapper[5];
			for (int i = 0; i < 5; i++)
			{
				StatsWrapper val = new StatsWrapper();
				val.name = Name(i);
				val.unitStat = (UnitStat)Ids[i];
				val.description = Desc(i);
				val.defaultValue = Defaults[i];
				val.minValue = Mins[i];
				val.maxValue = Maxs[i];
				val.statsMode = (StatMode)(UseMultiplierMode[i] ? 1 : 0);
				val.Initialize();
				array[i] = val;
				LastValues[i] = Defaults[i];
			}
			Wrappers = array;
		}
	}

	internal static int IndexOf(StatsWrapper stat)
	{
		if (stat == null || Wrappers == null)
		{
			return -1;
		}
		for (int i = 0; i < Wrappers.Length; i++)
		{
			if (object.ReferenceEquals(Wrappers[i], stat))
			{
				return i;
			}
		}
		return -1;
	}

	internal static void ResetCell(UnitEditorStatCell cell)
	{
		if ((Object)(object)cell == (Object)null)
		{
			return;
		}
		StatsWrapper cellStat = GetCellStat(cell);
		if (cellStat == null)
		{
			return;
		}
		int num = IndexOf(cellStat);
		float defaultValue = cellStat.defaultValue;
		if (float.IsNaN(defaultValue) || float.IsInfinity(defaultValue))
		{
			return;
		}
		cellStat.CurrentValue = defaultValue;
		if (num >= 0)
		{
			LastValues[num] = defaultValue;
			if (num == 3)
			{
				TauntTouchedByUser = false;
			}
		}
		if ((Object)(object)cell != (Object)null)
		{
			cell.UpdateValue(true);
		}
		RequestLivePreview();
		HiddenStatsPlugin.Verbose("[HiddenStats] 已重置为预设值:" + ((num >= 0) ? Name(num) : cellStat.name) + " = " + defaultValue);
	}

	internal static void AttachResetButton(UnitEditorStatCell cell)
	{
		//IL_018c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: Expected O, but got Unknown
		if ((Object)(object)cell == (Object)null || HiddenStatsPlugin.CfgResetButtons == null || !HiddenStatsPlugin.CfgResetButtons.Value || (Object)(object)((Component)cell).GetComponent<HiddenStatsResetButton>() != (Object)null)
		{
			return;
		}
		RectTransform val = (RectTransform)(((Object)(object)cell.m_InputField != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		Transform val2 = ((Component)cell).transform.Find("Plus");
		if ((Object)(object)val2 == (Object)null)
		{
			val2 = ((Component)cell).transform.Find("Minus");
		}
		if ((Object)(object)val2 == (Object)null)
		{
			HiddenStatsPlugin.Verbose("[HiddenStats] 没找到原生 +/- 按钮,跳过重置按钮。");
			return;
		}
		GameObject val3 = Object.Instantiate<GameObject>(((Component)val2).gameObject);
		if ((Object)(object)val3 == (Object)null)
		{
			return;
		}
		((Object)val3).name = "HiddenStatsReset";
		val3.transform.SetParent(((Component)cell).transform, false);
		val3.SetActive(true);
		val3.transform.SetAsLastSibling();
		Button val4 = val3.GetComponent<Button>();
		if ((Object)(object)val4 == (Object)null)
		{
			Image val5 = val3.GetComponent<Image>();
			if ((Object)(object)val5 == (Object)null)
			{
				val5 = val3.GetComponentInChildren<Image>(true);
			}
			if ((Object)(object)val5 == (Object)null)
			{
				Object.Destroy((Object)(object)val3);
				HiddenStatsPlugin.Verbose("[HiddenStats] 原生按钮既无 Button 也无 Image,跳过重置按钮。");
				return;
			}
			((Graphic)val5).raycastTarget = true;
			val4 = val3.AddComponent<Button>();
			((Selectable)val4).targetGraphic = (Graphic)(object)val5;
		}
		((UnityEventBase)val4.onClick).RemoveAllListeners();
		((UnityEvent)val4.onClick).AddListener((UnityAction)delegate
		{
			ResetCell(cell);
		});
		for (int num = val3.transform.childCount - 1; num >= 0; num--)
		{
			Object.Destroy((Object)(object)((Component)val3.transform.GetChild(num)).gameObject);
		}
		BuildResetLabel(val3, cell);
		HiddenStatsResetButton hiddenStatsResetButton = val3.AddComponent<HiddenStatsResetButton>();
		hiddenStatsResetButton.Setup(cell);
		HiddenStatsPlugin.Diag("[HiddenStats] 重置按钮已挂上:" + ((Object)cell).name);
	}

	private static void BuildResetLabel(GameObject buttonGo, UnitEditorStatCell cell)
	{
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Expected O, but got Unknown
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			TextMeshProUGUI val = null;
			if ((Object)(object)cell.m_NameText != (Object)null)
			{
				val = ((Component)cell.m_NameText).GetComponent<TextMeshProUGUI>();
				if ((Object)(object)val == (Object)null)
				{
					val = ((Component)cell.m_NameText).GetComponentInChildren<TextMeshProUGUI>(true);
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				Transform val2 = ((Component)cell).transform.Find("Text");
				if ((Object)(object)val2 != (Object)null)
				{
					val = ((Component)val2).GetComponent<TextMeshProUGUI>();
				}
			}
			GameObject val3 = new GameObject("ResetLabel", new Type[1] { typeof(RectTransform) });
			val3.transform.SetParent(buttonGo.transform, false);
			TextMeshProUGUI val4 = val3.AddComponent<TextMeshProUGUI>();
			if ((Object)(object)val != (Object)null)
			{
				((TMP_Text)val4).font = ((TMP_Text)val).font;
				if ((Object)(object)((TMP_Text)val).fontSharedMaterial != (Object)null)
				{
					((TMP_Text)val4).fontSharedMaterial = ((TMP_Text)val).fontSharedMaterial;
				}
				((Graphic)val4).color = ((Graphic)val).color;
			}
			((TMP_Text)val4).enableAutoSizing = false;
			((TMP_Text)val4).fontSize = Localization.ResetLabelSize();
			((TMP_Text)val4).enableWordWrapping = false;
			((TMP_Text)val4).overflowMode = (TextOverflowModes)0;
			((TMP_Text)val4).alignment = (TextAlignmentOptions)514;
			((Graphic)val4).raycastTarget = false;
			((TMP_Text)val4).text = Localization.ResetLabel();
			RectTransform component = val3.GetComponent<RectTransform>();
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.pivot = new Vector2(0.5f, 0.5f);
			component.offsetMin = Vector2.zero;
			component.offsetMax = Vector2.zero;
			((Transform)component).localScale = Vector3.one;
			((Transform)component).localRotation = Quaternion.identity;
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Log.LogError((object)("[HiddenStats] 生成「重置」文字失败:" + ex));
		}
	}

	internal static bool ContainsOurs(StatsWrapper[] stats)
	{
		if (stats == null)
		{
			return false;
		}
		for (int i = 0; i < stats.Length; i++)
		{
			if (IndexOf(stats[i]) >= 0)
			{
				return true;
			}
		}
		return false;
	}

	internal static void WidenNativeRanges(StatsWrapper[] stats)
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Expected I4, but got Unknown
		if (stats == null || HiddenStatsPlugin.CfgSizeNoLimit == null || !HiddenStatsPlugin.CfgSizeNoLimit.Value)
		{
			return;
		}
		int num = 0;
		foreach (StatsWrapper val in stats)
		{
			if (val == null)
			{
				continue;
			}
			int num2 = (int)val.unitStat;
			bool flag = false;
			for (int j = 0; j < UnlockedNativeStats.Length; j++)
			{
				if (UnlockedNativeStats[j] == num2)
				{
					flag = true;
					break;
				}
			}
			if (flag && (val.minValue != -9999999f || val.maxValue != 9999999f))
			{
				val.minValue = -9999999f;
				val.maxValue = 9999999f;
				num++;
			}
		}
		if (num > 0 && !_nativeRangeLogged)
		{
			_nativeRangeLogged = true;
			HiddenStatsPlugin.Log.LogInfo((object)"[HiddenStats] 已解除「尺寸」「重量」的数值上下限,可输入任意数字。");
			HiddenStatsPlugin.Diag("[HiddenStats] 已解除 尺寸/重量 上下限(" + num + " 行)。");
		}
	}

	internal static float ClampToRange(int index, float value)
	{
		if (float.IsNaN(value) || float.IsInfinity(value))
		{
			if (index == 3 && float.IsNaN(value) && HiddenStatsPlugin.CfgTauntZeroNaN != null && HiddenStatsPlugin.CfgTauntZeroNaN.Value)
			{
				return value;
			}
			HiddenStatsPlugin.Diag("[HiddenStats] " + Name(index) + " 收到非法数值(" + value + "),已回退到 " + LastValues[index]);
			return LastValues[index];
		}
		return value;
	}

	internal static float TauntForBlueprint(float value)
	{
		if (value == 0f && TauntTouchedByUser && HiddenStatsPlugin.CfgTauntZeroNaN != null && HiddenStatsPlugin.CfgTauntZeroNaN.Value)
		{
			HiddenStatsPlugin.Diag("[HiddenStats] 嘲讽值被设为 0,写回蓝图时改为 NaN");
			return float.NaN;
		}
		return value;
	}

	internal static StatsWrapper GetCellStat(UnitEditorStatCell cell)
	{
		if ((Object)(object)cell == (Object)null || CellStatField == null)
		{
			return null;
		}
		object? value = CellStatField.GetValue(cell);
		return (StatsWrapper)((value is StatsWrapper) ? value : null);
	}

	internal static void SyncFromLoaded(UnitEditorUIManager uiManager)
	{
		try
		{
			if (!HiddenStatsPlugin.CfgEnabled.Value)
			{
				return;
			}
			EnsureWrappers();
			if ((Object)(object)uiManager == (Object)null)
			{
				return;
			}
			UnitEditorManager unitEditorManager = uiManager.unitEditorManager;
			if ((Object)(object)unitEditorManager == (Object)null)
			{
				return;
			}
			LastManager = unitEditorManager;
			UnitBlueprint val = null;
			if (LoadedUnitField != null)
			{
				object? value = LoadedUnitField.GetValue(unitEditorManager);
				val = (UnitBlueprint)((value is UnitBlueprint) ? value : null);
			}
			if (!((Object)(object)val == (Object)null))
			{
				float num = val.TurnSpeed;
				if (num <= 0f)
				{
					num = Defaults[4];
				}
				float[] array = new float[5] { val.animationMultiplier, val.stepMultiplier, val.ArmLimitMultiplier, val.targetingPriorityMultiplier, num };
				if ((Object)(object)LastSyncedBp != (Object)null && (Object)(object)LastSyncedBp != (Object)(object)val)
				{
					TauntTouchedByUser = false;
				}
				LastSyncedBp = val;
				for (int i = 0; i < 5; i++)
				{
					float num2 = ClampToRange(i, array[i]);
					Wrappers[i].CurrentValue = num2;
					LastValues[i] = num2;
				}
				HiddenStatsPlugin.Verbose("[HiddenStats] 已从蓝图回读隐藏属性:anim=" + array[0] + " step=" + array[1] + " arm=" + array[2] + " taunt=" + array[3] + " turn=" + array[4]);
			}
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Log.LogError((object)("[HiddenStats] SyncFromLoaded 异常:" + ex));
		}
	}

	internal static void ApplyToBlueprint(UnitBlueprint bp)
	{
		if (HiddenStatsPlugin.CfgEnabled.Value && !((Object)(object)bp == (Object)null))
		{
			EnsureWrappers();
			bp.animationMultiplier = ClampToRange(0, Wrappers[0].CurrentValue);
			bp.stepMultiplier = ClampToRange(1, Wrappers[1].CurrentValue);
			bp.ArmLimitMultiplier = ClampToRange(2, Wrappers[2].CurrentValue);
			bp.targetingPriorityMultiplier = TauntForBlueprint(ClampToRange(3, Wrappers[3].CurrentValue));
			float num = (bp.turnSpeed = ClampToRange(4, Wrappers[4].CurrentValue));
			TurningData turningData = bp.turningData;
			if ((Object)(object)turningData != (Object)null && Mathf.Abs(turningData.TurnSpeed - num) > 0.05f)
			{
				bp.turningData = null;
				HiddenStatsPlugin.Verbose("[HiddenStats] 已解除 turningData 资产覆盖,转向速度改用 " + num);
			}
			HiddenStatsPlugin.Verbose("[HiddenStats] 已写入蓝图:anim=" + bp.animationMultiplier + " step=" + bp.stepMultiplier + " arm=" + bp.ArmLimitMultiplier + " taunt=" + bp.targetingPriorityMultiplier + " turn=" + bp.turnSpeed);
		}
	}

	internal static void RequestLivePreview()
	{
		if (HiddenStatsPlugin.CfgLivePreview.Value && !UnitEditorManager.isTestingUnit && !previewPending && !((Object)(object)HiddenStatsPlugin.Instance == (Object)null))
		{
			((MonoBehaviour)HiddenStatsPlugin.Instance).StartCoroutine(PreviewRoutine());
		}
	}

	private static IEnumerator PreviewRoutine()
	{
		previewPending = true;
		yield return (object)new WaitForSeconds(0.2f);
		previewPending = false;
		try
		{
			if ((Object)(object)LastManager != (Object)null && RespawnUnitMethod != null)
			{
				RespawnUnitMethod.Invoke(LastManager, null);
			}
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Log.LogWarning((object)("[HiddenStats] 重建预览失败:" + ex.Message));
		}
	}

	internal static void SetupScroll(UnitEditorStatsPageUI page)
	{
		if ((Object)(object)page == (Object)null)
		{
			return;
		}
		StatsScroll.ReportHierarchy(page);
		if (!HiddenStatsPlugin.CfgFixScroll.Value || scrollBuiltForInstanceId == ((Object)page).GetInstanceID())
		{
			return;
		}
		scrollBuiltForInstanceId = ((Object)page).GetInstanceID();
		try
		{
			StatsScroll.Install(page);
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Log.LogError((object)("[HiddenStats] 构建滚动条失败:" + ex));
		}
	}
}
internal static class StatsScroll
{
	internal static void ReportHierarchy(UnitEditorStatsPageUI page)
	{
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fe: 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_0221: Unknown result type (might be due to invalid IL or missing references)
		//IL_0226: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0301: Unknown result type (might be due to invalid IL or missing references)
		//IL_033a: Unknown result type (might be due to invalid IL or missing references)
		//IL_033f: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			Transform contentParent = page.contentParent;
			if ((Object)(object)contentParent == (Object)null)
			{
				HiddenStatsPlugin.Log.LogWarning((object)"[HiddenStats][Hierarchy] contentParent 为空。");
				return;
			}
			string text = "";
			Transform val = contentParent;
			int num = 0;
			while ((Object)(object)val != (Object)null && num < 6)
			{
				text = text + ((num == 0) ? "" : " <- ") + ((Object)val).name;
				RectTransform val2 = (RectTransform)(object)((val is RectTransform) ? val : null);
				if ((Object)(object)val2 != (Object)null)
				{
					string[] array = new string[6] { text, "(w=", null, null, null, null };
					Rect rect = val2.rect;
					array[2] = ((Rect)(ref rect)).width.ToString("F0");
					array[3] = ",h=";
					Rect rect2 = val2.rect;
					array[4] = ((Rect)(ref rect2)).height.ToString("F0");
					array[5] = ")";
					text = string.Concat(array);
				}
				LayoutGroup component = ((Component)val).GetComponent<LayoutGroup>();
				if ((Object)(object)component != (Object)null)
				{
					text = text + "{Layout:" + ((object)component).GetType().Name + "}";
				}
				if ((Object)(object)((Component)val).GetComponent<ScrollRect>() != (Object)null)
				{
					text += "{ScrollRect}";
				}
				if ((Object)(object)((Component)val).GetComponent<ContentSizeFitter>() != (Object)null)
				{
					text += "{Fitter}";
				}
				val = val.parent;
				num++;
			}
			HiddenStatsPlugin.Diag("[HiddenStats][Hierarchy] 链:" + text);
			RectTransform val3 = (RectTransform)(object)((contentParent is RectTransform) ? contentParent : null);
			object[] array2 = new object[6]
			{
				"[HiddenStats][Hierarchy] 子节点数=",
				contentParent.childCount,
				" 容器锚点=",
				((Object)(object)val3 != (Object)null) ? (((object)val3.anchorMin/*cast due to .constrained prefix*/).ToString() + "/" + ((object)val3.anchorMax/*cast due to .constrained prefix*/).ToString()) : "?",
				" 尺寸=",
				null
			};
			object obj;
			if (!((Object)(object)val3 != (Object)null))
			{
				obj = "?";
			}
			else
			{
				Rect rect3 = val3.rect;
				string text2 = ((Rect)(ref rect3)).width.ToString("F0");
				Rect rect4 = val3.rect;
				obj = text2 + "x" + ((Rect)(ref rect4)).height.ToString("F0");
			}
			array2[5] = obj;
			string text3 = string.Concat(array2);
			string text4 = "";
			for (int i = 0; i < contentParent.childCount && i < 14; i++)
			{
				Transform child = contentParent.GetChild(i);
				RectTransform val4 = (RectTransform)(object)((child is RectTransform) ? child : null);
				object[] array3 = new object[11]
				{
					text4,
					"\n    #",
					i,
					" ",
					((Object)child).name,
					" y=",
					null,
					null,
					null,
					null,
					null
				};
				object obj2;
				if (!((Object)(object)val4 != (Object)null))
				{
					obj2 = "?";
				}
				else
				{
					float y = val4.anchoredPosition.y;
					obj2 = y.ToString("F1");
				}
				array3[6] = obj2;
				array3[7] = " h=";
				object obj3;
				if (!((Object)(object)val4 != (Object)null))
				{
					obj3 = "?";
				}
				else
				{
					Rect rect5 = val4.rect;
					obj3 = ((Rect)(ref rect5)).height.ToString("F1");
				}
				array3[8] = obj3;
				array3[9] = " w=";
				object obj4;
				if (!((Object)(object)val4 != (Object)null))
				{
					obj4 = "?";
				}
				else
				{
					Rect rect6 = val4.rect;
					obj4 = ((Rect)(ref rect6)).width.ToString("F1");
				}
				array3[10] = obj4;
				text4 = string.Concat(array3);
			}
			HiddenStatsPlugin.Diag(text3 + text4);
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Log.LogWarning((object)("[HiddenStats][Hierarchy] 记录层级失败:" + ex.Message));
		}
	}

	internal static void Install(UnitEditorStatsPageUI page)
	{
		Transform contentParent = page.contentParent;
		if ((Object)(object)contentParent == (Object)null)
		{
			HiddenStatsPlugin.Log.LogWarning((object)"[HiddenStats] contentParent 为空,跳过滚动条。");
			return;
		}
		RectTransform val = (RectTransform)(object)((contentParent is RectTransform) ? contentParent : null);
		if ((Object)(object)val == (Object)null)
		{
			HiddenStatsPlugin.Log.LogWarning((object)"[HiddenStats] contentParent 不是 RectTransform,跳过滚动条。");
			return;
		}
		if ((Object)(object)((Component)contentParent).GetComponent<LayoutGroup>() == (Object)null)
		{
			HiddenStatsPlugin.Verbose("[HiddenStats] 行容器无布局组,按原生手动排布处理。");
		}
		if (HiddenStatsPlugin.CfgVerbose.Value)
		{
			DumpHierarchy(contentParent, 4);
		}
		ScrollRect componentInParent = ((Component)contentParent).GetComponentInParent<ScrollRect>();
		if ((Object)(object)componentInParent != (Object)null && ((Behaviour)componentInParent).enabled)
		{
			((Behaviour)componentInParent).enabled = false;
			HiddenStatsPlugin.Diag("[HiddenStats] 已停用原生 ScrollRect(" + ((Object)componentInParent).name + "),改用自研滚动器。");
		}
		Transform parent = contentParent.parent;
		RectTransform val2 = (RectTransform)(object)((parent is RectTransform) ? parent : null);
		if ((Object)(object)val2 == (Object)null)
		{
			HiddenStatsPlugin.Log.LogWarning((object)"[HiddenStats] contentParent 的父级不是 RectTransform,跳过滚动条。");
			return;
		}
		HiddenStatsScroller component = ((Component)val2).GetComponent<HiddenStatsScroller>();
		if ((Object)(object)component != (Object)null)
		{
			if (component.BindContent(val))
			{
				HiddenStatsPlugin.Diag("[HiddenStats] 行容器已重建,滚动器重新绑定(保留位置 " + HiddenStatsScroller.SavedOffset.ToString("F0") + ")");
			}
			return;
		}
		RectMask2D component2 = ((Component)val2).GetComponent<RectMask2D>();
		if ((Object)(object)component2 == (Object)null)
		{
			((Component)val2).gameObject.AddComponent<RectMask2D>();
		}
		component = ((Component)val2).gameObject.AddComponent<HiddenStatsScroller>();
		component.Init(val, val2, HiddenStatsPlugin.CfgScrollSensitivity.Value);
		HiddenStatsPlugin.Diag("[HiddenStats] 属性页滚动器已挂载:" + ((Object)val2).name + "(行容器:" + ((Object)contentParent).name + ",原生布局保持不变,位移在渲染前叠加;无滚动条,滚轮+拖拽)");
	}

	private static void EnsureContentFitter(RectTransform rt)
	{
		if (!((Object)(object)rt == (Object)null))
		{
			ContentSizeFitter val = ((Component)rt).GetComponent<ContentSizeFitter>();
			if ((Object)(object)val == (Object)null)
			{
				val = ((Component)rt).gameObject.AddComponent<ContentSizeFitter>();
			}
			val.horizontalFit = (FitMode)0;
			val.verticalFit = (FitMode)2;
		}
	}

	private static void CreateBar(RectTransform parent, UnitEditorStatsPageUI page, HiddenStatsScroller scroller)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		//IL_002c: 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_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Expected O, but got Unknown
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Expected O, but got Unknown
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0206: Unknown result type (might be due to invalid IL or missing references)
		Sprite sprite = FindSprite(page);
		GameObject val = new GameObject("HiddenStatsBar");
		RectTransform val2 = val.AddComponent<RectTransform>();
		((Transform)val2).SetParent((Transform)(object)parent, false);
		val2.anchorMin = new Vector2(1f, 0f);
		val2.anchorMax = new Vector2(1f, 1f);
		val2.pivot = new Vector2(1f, 0.5f);
		val2.sizeDelta = new Vector2(12f, -24f);
		val2.anchoredPosition = new Vector2(-4f, 0f);
		((Transform)val2).localScale = Vector3.one;
		Image val3 = val.AddComponent<Image>();
		val3.sprite = sprite;
		val3.type = (Type)1;
		((Graphic)val3).color = new Color(1f, 1f, 1f, 0.1f);
		((Graphic)val3).raycastTarget = true;
		GameObject val4 = new GameObject("Track");
		RectTransform val5 = val4.AddComponent<RectTransform>();
		((Transform)val5).SetParent(val.transform, false);
		val5.anchorMin = Vector2.zero;
		val5.anchorMax = Vector2.one;
		val5.offsetMin = new Vector2(1f, 2f);
		val5.offsetMax = new Vector2(-1f, -2f);
		((Transform)val5).localScale = Vector3.one;
		GameObject val6 = new GameObject("Handle");
		RectTransform val7 = val6.AddComponent<RectTransform>();
		((Transform)val7).SetParent(val4.transform, false);
		val7.anchorMin = new Vector2(0f, 1f);
		val7.anchorMax = new Vector2(1f, 1f);
		val7.pivot = new Vector2(0.5f, 1f);
		val7.sizeDelta = new Vector2(0f, 80f);
		val7.anchoredPosition = Vector2.zero;
		((Transform)val7).localScale = Vector3.one;
		Image val8 = val6.AddComponent<Image>();
		val8.sprite = sprite;
		val8.type = (Type)1;
		((Graphic)val8).color = new Color(1f, 1f, 1f, 0.72f);
		((Graphic)val8).raycastTarget = true;
		scroller.AttachBar(val2, val5, val7);
	}

	private static Sprite FindSprite(UnitEditorStatsPageUI page)
	{
		try
		{
			if ((Object)(object)page != (Object)null && (Object)(object)page.statsCell != (Object)null)
			{
				Image componentInChildren = page.statsCell.GetComponentInChildren<Image>(true);
				if ((Object)(object)componentInChildren != (Object)null && (Object)(object)componentInChildren.sprite != (Object)null)
				{
					return componentInChildren.sprite;
				}
			}
		}
		catch (Exception)
		{
		}
		return null;
	}

	internal static void EnsureVisible(Transform item)
	{
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)item == (Object)null)
		{
			return;
		}
		HiddenStatsScroller componentInParent = ((Component)item).GetComponentInParent<HiddenStatsScroller>();
		if ((Object)(object)componentInParent != (Object)null)
		{
			componentInParent.ScrollToTransform(item);
			return;
		}
		ScrollRect componentInParent2 = ((Component)item).GetComponentInParent<ScrollRect>();
		if ((Object)(object)componentInParent2 == (Object)null || (Object)(object)componentInParent2.content == (Object)null || (Object)(object)componentInParent2.viewport == (Object)null)
		{
			return;
		}
		RectTransform content = componentInParent2.content;
		RectTransform viewport = componentInParent2.viewport;
		Rect rect = content.rect;
		float height = ((Rect)(ref rect)).height;
		Rect rect2 = viewport.rect;
		float height2 = ((Rect)(ref rect2)).height;
		if (height <= height2 + 1f)
		{
			return;
		}
		float num = 0f - ((Transform)content).InverseTransformPoint(item.position).y;
		float num2 = height2;
		float num3 = height - num2;
		float num4 = (1f - componentInParent2.verticalNormalizedPosition) * num3;
		float num5 = num4;
		if (num < num4)
		{
			num5 = num;
		}
		else
		{
			if (!(num > num4 + num2 - 4f))
			{
				return;
			}
			num5 = num - num2 + 4f;
		}
		num5 = Mathf.Clamp(num5, 0f, num3);
		componentInParent2.verticalNormalizedPosition = Mathf.Clamp01(1f - num5 / num3);
	}

	private static void DumpHierarchy(Transform t, int depth)
	{
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)t == (Object)null) && depth >= 0)
		{
			string text = "";
			for (int i = 0; i < 4 - depth; i++)
			{
				text += "  ";
			}
			RectTransform val = (RectTransform)(object)((t is RectTransform) ? t : null);
			object obj;
			if (!((Object)(object)val == (Object)null))
			{
				object[] array = new object[8] { " size=", null, null, null, null, null, null, null };
				Rect rect = val.rect;
				array[1] = ((Rect)(ref rect)).width;
				array[2] = "x";
				Rect rect2 = val.rect;
				array[3] = ((Rect)(ref rect2)).height;
				array[4] = " anchors=";
				array[5] = val.anchorMin;
				array[6] = "/";
				array[7] = val.anchorMax;
				obj = string.Concat(array);
			}
			else
			{
				obj = "";
			}
			string text2 = (string)obj;
			HiddenStatsPlugin.Log.LogInfo((object)("[HiddenStats][Hierarchy] " + text + ((Object)t).name + text2 + " components=" + ComponentNames(((Component)t).gameObject)));
			for (int j = 0; j < t.childCount; j++)
			{
				DumpHierarchy(t.GetChild(j), depth - 1);
			}
		}
	}

	private static string ComponentNames(GameObject go)
	{
		Component[] components = go.GetComponents<Component>();
		string text = "";
		for (int i = 0; i < components.Length; i++)
		{
			if (!((Object)(object)components[i] == (Object)null))
			{
				text = text + ((object)components[i]).GetType().Name + ",";
			}
		}
		return text;
	}
}
[HarmonyPatch(typeof(UnitEditorStatsPageUI), "SpawnStats")]
internal static class Patch_SpawnStats
{
	private static void Prefix(ref StatsWrapper[] __0)
	{
		try
		{
			if (!HiddenStatsPlugin.CfgEnabled.Value)
			{
				return;
			}
			ExtraStats.EnsureWrappers();
			if (__0 == null)
			{
				HiddenStatsPlugin.Log.LogWarning((object)"[HiddenStats] SpawnStats 传入的数组为空,跳过注入。");
				return;
			}
			ExtraStats.WidenNativeRanges(__0);
			if (!ExtraStats.ContainsOurs(__0))
			{
				List<StatsWrapper> list = new List<StatsWrapper>(__0);
				for (int i = 0; i < 5; i++)
				{
					list.Add(ExtraStats.Wrappers[i]);
				}
				__0 = list.ToArray();
				HiddenStatsPlugin.Log.LogInfo((object)("[HiddenStats] 属性页行数:" + __0.Length + "(原生 " + (__0.Length - 5) + " + 隐藏 " + 5 + ")"));
			}
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Log.LogError((object)("[HiddenStats] SpawnStats Prefix 异常:" + ex));
		}
	}

	private static void Postfix(UnitEditorStatsPageUI __instance)
	{
		try
		{
			HiddenStatsPlugin.Diag("[HiddenStats] SpawnStats 完成:页面 " + ((Object)__instance).GetInstanceID() + ",行容器 " + (((Object)(object)__instance.contentParent != (Object)null) ? ((Object)__instance.contentParent).GetInstanceID().ToString() : "空"));
			ExtraStats.SetupScroll(__instance);
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Log.LogError((object)("[HiddenStats] SpawnStats Postfix 异常:" + ex));
		}
	}
}
[HarmonyPatch(typeof(UnitEditorStatsPageUI), "SpawnStatsCell")]
internal static class Patch_SpawnStatsCell
{
	private static void Postfix(ref UnitEditorStatCell __result)
	{
		try
		{
			UnitEditorStatCell val = __result;
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			ExtraStats.AttachResetButton(val);
			StatsWrapper cellStat = ExtraStats.GetCellStat(val);
			int num = ExtraStats.IndexOf(cellStat);
			if (num >= 0)
			{
				if ((Object)(object)val.m_NameText != (Object)null)
				{
					val.m_NameText.Localized = false;
					val.m_NameText.LocaleID = ExtraStats.Name(num);
				}
				if ((Object)(object)val.m_DescriptionText != (Object)null)
				{
					val.m_DescriptionText.Localized = false;
					val.m_DescriptionText.LocaleID = ExtraStats.Desc(num);
				}
				LocalizationSync.Register(val, num);
				LocalizationSync.ApplyCellText(val, num);
				HiddenStatsPlugin.Verbose("[HiddenStats] 已设置隐藏行文案:" + ExtraStats.Name(num));
			}
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Log.LogError((object)("[HiddenStats] SpawnStatsCell Postfix 异常:" + ex));
		}
	}
}
[HarmonyPatch(typeof(UnitEditorStatsPageUI), "OnItemSelected")]
internal static class Patch_OnItemSelected
{
	private static void Postfix(UnitEditorSelectableItem __0)
	{
		try
		{
			if (!((Object)(object)__0 == (Object)null))
			{
				HiddenStatsPlugin.Verbose("[HiddenStats] 选中行:" + ((Object)__0).name + "(不自动滚动)");
			}
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Log.LogError((object)("[HiddenStats] OnItemSelected Postfix 异常:" + ex));
		}
	}
}
[HarmonyPatch(typeof(UnitEditorUIManager), "UpdateStatUI")]
internal static class Patch_UpdateStatUI
{
	private static void Prefix(UnitEditorUIManager __instance)
	{
		ExtraStats.SyncFromLoaded(__instance);
	}

	private static void Postfix()
	{
		LocalizationSync.RefreshRows();
	}
}
[HarmonyPatch(typeof(UnitEditorManager), "SetStats")]
internal static class Patch_SetStats
{
	private static void Postfix(UnitBlueprint __0)
	{
		try
		{
			ExtraStats.ApplyToBlueprint(__0);
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Log.LogError((object)("[HiddenStats] SetStats Postfix 异常:" + ex));
		}
	}
}
[HarmonyPatch(typeof(UnitEditorManager), "SetStatValue")]
internal static class Patch_SetStatValue
{
	private static void Postfix(UnitEditorManager __instance, UnitStat __0, float __1)
	{
		try
		{
			ExtraStats.LastManager = __instance;
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Log.LogError((object)("[HiddenStats] SetStatValue Postfix 异常:" + ex));
		}
	}
}
[HarmonyPatch(typeof(UnitEditorStatCell), "UpdateValue")]
internal static class Patch_UpdateValue
{
	private static void Postfix(UnitEditorStatCell __instance, bool __0)
	{
		try
		{
			StatsWrapper cellStat = ExtraStats.GetCellStat(__instance);
			int num = ExtraStats.IndexOf(cellStat);
			if (num < 0)
			{
				return;
			}
			float currentValue = cellStat.CurrentValue;
			if (num == 3 && float.IsNaN(currentValue) && HiddenStatsPlugin.CfgTauntZeroNaN != null && HiddenStatsPlugin.CfgTauntZeroNaN.Value)
			{
				ExtraStats.LastValues[num] = currentValue;
				if (!__0)
				{
					ExtraStats.RequestLivePreview();
				}
				return;
			}
			float num2 = ExtraStats.ClampToRange(num, currentValue);
			if (float.IsNaN(currentValue) || float.IsInfinity(currentValue))
			{
				cellStat.CurrentValue = num2;
				__instance.UpdateValue(true);
				ExtraStats.LastValues[num] = num2;
			}
			else if (!(Mathf.Abs(num2 - ExtraStats.LastValues[num]) < 0.0001f))
			{
				ExtraStats.LastValues[num] = num2;
				if (num == 3 && !__0)
				{
					ExtraStats.TauntTouchedByUser = num2 == 0f;
				}
				if (!__0)
				{
					ExtraStats.RequestLivePreview();
				}
			}
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Log.LogError((object)("[HiddenStats] UpdateValue Postfix 异常:" + ex));
		}
	}
}
[HarmonyPatch(typeof(Weapon), "UpdateCounters")]
internal static class Patch_UpdateCounters
{
	private static void Postfix(Weapon __instance, float __0)
	{
		try
		{
			if (HiddenStatsPlugin.CfgWidenAttackSpeed.Value && !((Object)(object)__instance == (Object)null) && !__instance.isRange)
			{
				__instance.attackSpeedM = Mathf.Clamp((__0 + 4f) * 0.2f, 0.02f, 20f);
			}
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Log.LogError((object)("[HiddenStats] UpdateCounters Postfix 异常:" + ex));
		}
	}
}
internal static class CustomCostLimit
{
	private static readonly Dictionary<int, int> Values = new Dictionary<int, int>();

	internal static bool TryGet(UnitEditorManager manager, out int value)
	{
		value = 0;
		if ((Object)(object)manager == (Object)null)
		{
			return false;
		}
		try
		{
			return Values.TryGetValue(((Object)manager).GetInstanceID(), out value);
		}
		catch (Exception)
		{
			return false;
		}
	}

	internal static int Get(UnitEditorManager manager)
	{
		if (!TryGet(manager, out var value))
		{
			return 0;
		}
		return value;
	}

	internal static void Set(UnitEditorManager manager, int value)
	{
		if ((Object)(object)manager == (Object)null)
		{
			return;
		}
		try
		{
			Values[((Object)manager).GetInstanceID()] = value;
		}
		catch (Exception)
		{
		}
	}

	internal static void Clear(UnitEditorManager manager)
	{
		if ((Object)(object)manager == (Object)null)
		{
			return;
		}
		try
		{
			Values.Remove(((Object)manager).GetInstanceID());
		}
		catch (Exception)
		{
		}
	}
}
[HarmonyPatch(typeof(UnitEditorSaveScreen), "SetCustomCost")]
internal static class Patch_SetCustomCost
{
	private sealed class BoxNode
	{
		public RectTransform rt;

		public Vector2 baseSD;

		public Vector2 basePos;

		public LayoutElement le;

		public float lePrefBase;

		public float leMinBase;
	}

	private const float DescExtraHeight = 48f;

	internal static readonly FieldInfo FManager = AccessTools.Field(typeof(UnitEditorSaveScreen), "UCManager");

	internal static readonly FieldInfo FInput = AccessTools.Field(typeof(UnitEditorSaveScreen), "CostInputField");

	internal static readonly FieldInfo FDescInput = AccessTools.Field(typeof(UnitEditorSaveScreen), "UnitDescriptionField");

	private static bool s_descDiagDone;

	private static bool s_descFixDone;

	internal static UnitEditorSaveScreen s_descScreen;

	private static float s_nextDescTick;

	private static bool s_boxMeasured;

	private static List<BoxNode> s_boxNodes;

	private static float s_boxDelta;

	private static RectTransform s_saveRect;

	private static Vector2 s_saveBasePos;

	private static bool s_saveHasBase;

	private static int s_lastReportLen;

	private static TMP_InputField s_descField;

	private static bool s_hierarchyDumped;

	private static bool s_panelDiagLogged;

	private static bool s_stretchMeasured;

	private static RectTransform s_stBox;

	private static RectTransform s_stInput;

	private static RectTransform s_stPanel;

	private static LayoutElement s_stPanelLe;

	private static RectTransform s_stSave;

	private static Vector2 s_stBoxBaseSD;

	private static Vector2 s_stBoxBasePos;

	private static Vector2 s_stInputBaseSD;

	private static Vector2 s_stInputBasePos;

	private static Vector2 s_stPanelBaseSD;

	private static float s_stPanelLeMinBase;

	private static float s_stPanelLePrefBase;

	private static Vector2 s_stSaveBasePos;

	internal static readonly FieldInfo FCheckmark = AccessTools.Field(typeof(UnitEditorSaveScreen), "CostCheckmark");

	private static readonly MethodInfo MCheckLegal = AccessTools.Method(typeof(UnitEditorSaveScreen), "CheckSaveLegality", (Type[])null, (Type[])null);

	private static readonly MethodInfo MSetAutoCost = AccessTools.Method(typeof(UnitEditorSaveScreen), "SetAutoCost", new Type[1] { typeof(bool) }, (Type[])null);

	private static readonly MethodInfo MSelectTab = AccessTools.Method(typeof(UnitEditorSaveScreen), "SelectCostTab", (Type[])null, (Type[])null);

	private static FieldInfo FCustomCostField;

	private static int _lastBigValue = -1;

	internal static void WidenInput(UnitEditorSaveScreen screen)
	{
		try
		{
			object inputObject = GetInputObject(screen);
			if (inputObject == null)
			{
				return;
			}
			FieldInfo fieldInfo = AccessTools.Field(inputObject.GetType(), "m_InputField");
			if (fieldInfo == null)
			{
				HiddenStatsPlugin.Verbose("[价格] 找不到输入框内部字段,字符上限无法解除。");
				return;
			}
			object? value = fieldInfo.GetValue(inputObject);
			TMP_InputField val = (TMP_InputField)((value is TMP_InputField) ? value : null);
			if (!((Object)(object)val == (Object)null) && val.characterLimit != 0)
			{
				int characterLimit = val.characterLimit;
				val.characterLimit = 0;
				HiddenStatsPlugin.Verbose("[价格] 已解除价格输入框的字符上限(原上限 " + characterLimit + ")。");
			}
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Verbose("[价格] 解除字符上限失败:" + ex.Message);
		}
	}

	internal static object GetInputObject(UnitEditorSaveScreen screen)
	{
		if (FInput == null || (Object)(object)screen == (Object)null)
		{
			return null;
		}
		return FInput.GetValue(screen);
	}

	internal static void WidenDescription(UnitEditorSaveScreen screen)
	{
		//IL_028a: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if ((Object)(object)screen == (Object)null || FDescInput == null)
			{
				HiddenStatsPlugin.Diag("[简介] 诊断:screen=" + ((Object)(object)screen == (Object)null) + " fieldInfo=" + (FDescInput == null));
				return;
			}
			object value = FDescInput.GetValue(screen);
			if (value == null)
			{
				HiddenStatsPlugin.Diag("[简介] 诊断:UnitDescriptionField 为空");
				return;
			}
			FieldInfo fieldInfo = AccessTools.Field(value.GetType(), "m_InputField");
			TMP_InputField val = (TMP_InputField)((fieldInfo == null) ? null : /*isinst with value type is only supported in some contexts*/);
			if ((Object)(object)val == (Object)null)
			{
				Component val2 = (Component)((value is Component) ? value : null);
				if ((Object)(object)val2 != (Object)null)
				{
					val = val2.GetComponentInChildren<TMP_InputField>(true);
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				HiddenStatsPlugin.Diag("[简介] 诊断:取不到 TMP_InputField,type=" + value.GetType().FullName + " hasField=" + (fieldInfo != null));
				return;
			}
			if (!s_descDiagDone)
			{
				s_descDiagDone = true;
				int num = -1;
				FieldInfo fieldInfo2 = AccessTools.Field(typeof(TMP_InputField), "m_CharacterLimit");
				if (fieldInfo2 != null)
				{
					try
					{
						num = (int)fieldInfo2.GetValue(val);
					}
					catch (Exception)
					{
					}
				}
				int num2 = -1;
				FieldInfo fieldInfo3 = AccessTools.Field(value.GetType(), "m_MaxTextLength");
				if (fieldInfo3 != null)
				{
					try
					{
						num2 = (int)fieldInfo3.GetValue(value);
					}
					catch (Exception)
					{
					}
				}
				int num3 = -1;
				if ((Object)(object)val.textComponent != (Object)null)
				{
					num3 = val.textComponent.maxVisibleCharacters;
				}
				int num4 = ((!string.IsNullOrEmpty(val.text)) ? val.text.Length : 0);
				HiddenStatsPlugin.Diag(string.Concat("[简介] 诊断:type=", value.GetType().FullName, " go=", ((Object)val).name, " characterLimit=", val.characterLimit, " lineLimit=", val.lineLimit, " m_CharacterLimit=", num, " m_MaxTextLength=", num2, " maxVisible=", num3, " lineType=", val.lineType, " textLen=", num4));
			}
			bool flag = false;
			if (val.characterLimit != 0)
			{
				val.characterLimit = 0;
				flag = true;
			}
			if (val.lineLimit != 0)
			{
				val.lineLimit = 0;
				flag = true;
			}
			FieldInfo fieldInfo4 = AccessTools.Field(typeof(TMP_InputField), "m_CharacterLimit");
			if (fieldInfo4 != null)
			{
				try
				{
					if ((int)fieldInfo4.GetValue(val) != 0)
					{
						fieldInfo4.SetValue(val, 0);
						flag = true;
					}
				}
				catch (Exception)
				{
				}
			}
			FieldInfo fieldInfo5 = AccessTools.Field(typeof(TMP_InputField), "m_LineLimit");
			if (fieldInfo5 != null)
			{
				try
				{
					if ((int)fieldInfo5.GetValue(val) != 0)
					{
						fieldInfo5.SetValue(val, 0);
						flag = true;
					}
				}
				catch (Exception)
				{
				}
			}
			FieldInfo fieldInfo6 = AccessTools.Field(value.GetType(), "m_MaxTextLength");
			if (fieldInfo6 != null)
			{
				try
				{
					if ((int)fieldInfo6.GetValue(value) < 1000000)
					{
						fieldInfo6.SetValue(value, 1000000);
						flag = true;
					}
				}
				catch (Exception)
				{
				}
			}
			if ((Object)(object)val.textComponent != (Object)null && val.textComponent.maxVisibleCharacters < 999999)
			{
				val.textComponent.maxVisibleCharacters = 999999;
				flag = true;
			}
			if (flag && !s_descFixDone)
			{
				s_descFixDone = true;
				HiddenStatsPlugin.Diag("[简介] 已强制解除兵种简介字数上限(characterLimit / m_MaxTextLength / maxVisible)。");
			}
			s_descField = val;
			EnsureScrollbar(val);
			StretchDescription(screen, value, val);
			int num5 = ((val.text != null) ? val.text.Length : 0);
			if (num5 >= s_lastReportLen + 40 || num5 < s_lastReportLen - 100)
			{
				s_lastReportLen = num5;
				HiddenStatsPlugin.Diag("[简介] 当前简介文本长度 " + num5);
			}
		}
		catch (Exception ex6)
		{
			HiddenStatsPlugin.Verbose("[简介] 解除字数上限失败:" + ex6.Message);
		}
	}

	internal static void TickDescriptionLimit()
	{
		if (HiddenStatsPlugin.CfgUnlimitDesc == null || !HiddenStatsPlugin.CfgUnlimitDesc.Value)
		{
			return;
		}
		float realtimeSinceStartup = Time.realtimeSinceStartup;
		if (!(realtimeSinceStartup < s_nextDescTick))
		{
			s_nextDescTick = realtimeSinceStartup + 0.5f;
			if (!((Object)(object)s_descScreen == (Object)null))
			{
				WidenDescription(s_descScreen);
			}
		}
	}

	internal static void TickMouseScroll()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		//IL_004f: 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_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Expected O, but got Unknown
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)s_descField == (Object)null || (Object)(object)s_descScreen == (Object)null)
		{
			return;
		}
		Vector2 mouseScrollDelta = Input.mouseScrollDelta;
		if (mouseScrollDelta.y == 0f)
		{
			return;
		}
		RectTransform textViewport = s_descField.textViewport;
		if ((Object)(object)textViewport == (Object)null)
		{
			return;
		}
		Vector2 val = Vector2.op_Implicit(Input.mousePosition);
		if (!RectTransformUtility.RectangleContainsScreenPoint(textViewport, val, (Camera)null))
		{
			return;
		}
		try
		{
			PointerEventData val2 = new PointerEventData(EventSystem.current);
			val2.scrollDelta = new Vector2(0f, mouseScrollDelta.y);
			((IScrollHandler)s_descField).OnScroll(val2);
		}
		catch (Exception)
		{
		}
	}

	private static RectTransform AsRect(object o)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		if (o == null)
		{
			return null;
		}
		if (o is Component)
		{
			Transform transform = ((Component)o).transform;
			return (RectTransform)(object)((transform is RectTransform) ? transform : null);
		}
		if (o is GameObject)
		{
			Transform transform2 = ((GameObject)o).transform;
			return (RectTransform)(object)((transform2 is RectTransform) ? transform2 : null);
		}
		return null;
	}

	private static void AddBoxNode(RectTransform rt)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		BoxNode boxNode = new BoxNode();
		boxNode.rt = rt;
		boxNode.baseSD = rt.sizeDelta;
		boxNode.basePos = rt.anchoredPosition;
		boxNode.le = ((Component)rt).GetComponent<LayoutElement>();
		if ((Object)(object)boxNode.le != (Object)null)
		{
			boxNode.lePrefBase = boxNode.le.preferredHeight;
			boxNode.leMinBase = boxNode.le.minHeight;
		}
		s_boxNodes.Add(boxNode);
	}

	private static void StretchNode(BoxNode n, float delta)
	{
		//IL_004c: 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_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: 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_006f: Unknown result type (might be due to invalid IL or missing references)
		RectTransform rt = n.rt;
		Vector2 val = default(Vector2);
		((Vector2)(ref val))..ctor(n.baseSD.x, n.baseSD.y + delta);
		Vector2 val2 = default(Vector2);
		((Vector2)(ref val2))..ctor(n.basePos.x, n.basePos.y - delta * 0.5f);
		if (!Near(rt.sizeDelta, val))
		{
			rt.sizeDelta = val;
		}
		if (!Near(rt.anchoredPosition, val2))
		{
			rt.anchoredPosition = val2;
		}
		if ((Object)(object)n.le != (Object)null)
		{
			if (n.le.preferredHeight != n.lePrefBase + delta)
			{
				n.le.preferredHeight = n.lePrefBase + delta;
			}
			if (n.le.minHeight != n.leMinBase + delta)
			{
				n.le.minHeight = n.leMinBase + delta;
			}
		}
	}

	private static RectTransform FindChildRect(Transform t, string contains)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Expected O, but got Unknown
		foreach (Transform item in t)
		{
			Transform val = item;
			if (((Object)val).name.IndexOf(contains, StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return (RectTransform)(object)((val is RectTransform) ? val : null);
			}
			RectTransform val2 = FindChildRect(val, contains);
			if ((Object)(object)val2 != (Object)null)
			{
				return val2;
			}
		}
		return null;
	}

	private static RectTransform FindChildByComp(Transform t, string comp)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Expected O, but got Unknown
		foreach (Transform item in t)
		{
			Transform val = item;
			if ((Object)(object)((Component)val).GetComponent(comp) != (Object)null)
			{
				return (RectTransform)(object)((val is RectTransform) ? val : null);
			}
			RectTransform val2 = FindChildByComp(val, comp);
			if ((Object)(object)val2 != (Object)null)
			{
				return val2;
			}
		}
		return null;
	}

	private static RectTransform FindPanel(Transform box)
	{
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Expected O, but got Unknown
		RectTransform val = FindChildRect(box, "UnitDesciption");
		if ((Object)(object)val != (Object)null)
		{
			return val;
		}
		if ((Object)(object)box != (Object)null)
		{
			val = FindChildByComp(box, "UnitEditorSelectableInputFieldItem");
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			if ((Object)(object)box.parent != (Object)null)
			{
				foreach (Transform item in box.parent)
				{
					Transform val2 = item;
					if (((Object)val2).name.IndexOf("UnitDesciption", StringComparison.OrdinalIgnoreCase) >= 0)
					{
						return (RectTransform)(object)((val2 is RectTransform) ? val2 : null);
					}
					if ((Object)(object)((Component)val2).GetComponent("UnitEditorSelectableInputFieldItem") != (Object)null)
					{
						return (RectTransform)(object)((val2 is RectTransform) ? val2 : null);
					}
				}
			}
		}
		return null;
	}

	internal static void EnsureScrollbar(TMP_InputField field)
	{
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Expected O, but got Unknown
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Expected O, but got Unknown
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: 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)
		try
		{
			if (!((Object)(object)field == (Object)null) && !((Object)(object)field.verticalScrollbar != (Object)null))
			{
				Transform transform = ((Component)field).transform;
				RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
				if (!((Object)(object)val == (Object)null))
				{
					((Selectable)field).transition = (Transition)0;
					GameObject val2 = new GameObject("DescScrollbar", new Type[3]
					{
						typeof(RectTransform),
						typeof(Image),
						typeof(Scrollbar)
					});
					val2.transform.SetParent((Transform)(object)val, false);
					Transform transform2 = val2.transform;
					RectTransform val3 = (RectTransform)(object)((transform2 is RectTransform) ? transform2 : null);
					val3.anchorMin = new Vector2(1f, 0f);
					val3.anchorMax = new Vector2(1f, 1f);
					val3.pivot = new Vector2(1f, 0.5f);
					val3.offsetMin = new Vector2(-8f, 2f);
					val3.offsetMax = new Vector2(-2f, -2f);
					Image component = val2.GetComponent<Image>();
					((Graphic)component).color = new Color(1f, 1f, 1f, 0.12f);
					Scrollbar component2 = val2.GetComponent<Scrollbar>();
					component2.direction = (Direction)2;
					component2.numberOfSteps = 0;
					component2.value = 0f;
					GameObject val4 = new GameObject("Handle", new Type[2]
					{
						typeof(RectTransform),
						typeof(Image)
					});
					val4.transform.SetParent(val2.transform, false);
					Transform transform3 = val4.transform;
					RectTransform val5 = (RectTransform)(object)((transform3 is RectTransform) ? transform3 : null);
					val5.anchorMin = new Vector2(0f, 0f);
					val5.anchorMax = new Vector2(1f, 1f);
					val5.offsetMin = Vector2.zero;
					val5.offsetMax = Vector2.zero;
					Image component3 = val4.GetComponent<Image>();
					((Graphic)component3).color = new Color(1f, 1f, 1f, 0.55f);
					((Selectable)component2).targetGraphic = (Graphic)(object)component3;
					component2.handleRect = val5;
					field.verticalScrollbar = component2;
					HiddenStatsPlugin.Diag("[简介] 已为描述框挂载垂直滚动条。");
				}
			}
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Verbose("[简介] 挂载滚动条失败:" + ex.Message);
		}
	}

	internal static void StretchDescription(UnitEditorSaveScreen screen, object input, TMP_InputField field)
	{
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//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)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_056b: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0497: Unknown result type (might be due to invalid IL or missing references)
		//IL_0206: Unknown result type (might be due to invalid IL or missing references)
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: 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_0128: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0539: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_033e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0345: Expected O, but got Unknown
		//IL_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0266: Expected O, but got Unknown
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			Transform transform = ((Component)((input is Component) ? input : null)).transform;
			RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			Transform transform2 = ((Component)field).transform;
			RectTransform val2 = (RectTransform)(object)((transform2 is RectTransform) ? transform2 : null);
			if (!s_stretchMeasured)
			{
				s_stBox = val;
				s_stInput = val2;
				if ((Object)(object)val != (Object)null)
				{
					s_stBoxBaseSD = val.sizeDelta;
					s_stBoxBasePos = val.anchoredPosition;
				}
				if ((Object)(object)val2 != (Object)null)
				{
					s_stInputBaseSD = val2.sizeDelta;
					s_stInputBasePos = val2.anchoredPosition;
				}
				FieldInfo fieldInfo = AccessTools.Field(typeof(UnitEditorSaveScreen), "saveButton");
				if (fieldInfo != null)
				{
					s_stSave = AsRect(fieldInfo.GetValue(screen));
					if ((Object)(object)s_stSave != (Object)null)
					{
						s_stSaveBasePos = s_stSave.anchoredPosition;
					}
				}
				s_stretchMeasured = true;
				string text = "按钮=" + ((Object)(object)s_stSave != (Object)null);
				if ((Object)(object)s_stSave != (Object)null)
				{
					string text2 = text;
					string[] array = new string[5]
					{
						text2,
						" pos=",
						F2(s_stSaveBasePos),
						" rectH=",
						null
					};
					Rect rect = s_stSave.rect;
					array[4] = ((Rect)(ref rect)).height.ToString("F1");
					text = string.Concat(array);
				}
				object[] array2 = new object[6] { "[简介] 加高基准:boxH=", null, null, null, null, null };
				float num;
				if (!((Object)(object)val == (Object)null))
				{
					Rect rect2 = val.rect;
					num = ((Rect)(ref rect2)).height;
				}
				else
				{
					num = -1f;
				}
				array2[1] = num;
				array2[2] = " inputH=";
				float num2;
				if (!((Object)(object)val2 == (Object)null))
				{
					Rect rect3 = val2.rect;
					num2 = ((Rect)(ref rect3)).height;
				}
				else
				{
					num2 = -1f;
				}
				array2[3] = num2;
				array2[4] = " ";
				array2[5] = text;
				HiddenStatsPlugin.Diag(string.Concat(array2));
			}
			if ((Object)(object)s_stPanel == (Object)null && (Object)(object)val != (Object)null)
			{
				RectTransform val3 = FindPanel((Transform)(object)val);
				if ((Object)(object)val3 != (Object)null)
				{
					s_stPanel = val3;
					s_stPanelBaseSD = val3.sizeDelta;
					s_stPanelLe = ((Component)val3).GetComponent<LayoutElement>();
					if ((Object)(object)s_stPanelLe != (Object)null)
					{
						s_stPanelLeMinBase = s_stPanelLe.minHeight;
						s_stPanelLePrefBase = s_stPanelLe.preferredHeight;
					}
					string text3 = "";
					foreach (Transform item in (Transform)val)
					{
						Transform val4 = item;
						text3 = text3 + ((Object)val4).name + ";";
					}
					string[] array3 = new string[7] { "[简介] 底板已找到 H=", null, null, null, null, null, null };
					Rect rect4 = val3.rect;
					array3[1] = ((Rect)(ref rect4)).height.ToString("F1");
					array3[2] = " LEmin=";
					array3[3] = s_stPanelLeMinBase.ToString("F1");
					array3[4] = " 子级=[";
					array3[5] = text3;
					array3[6] = "]";
					HiddenStatsPlugin.Diag(string.Concat(array3));
				}
				else if (!s_panelDiagLogged)
				{
					s_panelDiagLogged = true;
					string text4 = "";
					foreach (Transform item2 in (Transform)val)
					{
						Transform val5 = item2;
						string text5 = "";
						Component[] components = ((Component)val5).GetComponents<Component>();
						for (int i = 0; i < components.Length; i++)
						{
							if ((Object)(object)components[i] != (Object)null)
							{
								text5 = text5 + ((object)components[i]).GetType().Name + ",";
							}
						}
						string text6 = text4;
						text4 = text6 + ((Object)val5).name + "{" + text5 + "};";
					}
					HiddenStatsPlugin.Diag("[简介] 底板未找到 box=" + ((Object)val).name + " parent=" + (((Object)(object)((Transform)val).parent == (Object)null) ? "-" : ((Object)((Transform)val).parent).name) + " 子级=[" + text4 + "]");
				}
			}
			if ((Object)(object)s_stPanel != (Object)null)
			{
				if ((Object)(object)val != (Object)null)
				{
					val.sizeDelta = new Vector2(s_stBoxBaseSD.x, s_stBoxBaseSD.y + 48f);
				}
				s_stPanel.sizeDelta = new Vector2(s_stPanelBaseSD.x, s_stPanelBaseSD.y + 48f);
				if ((Object)(object)s_stPanelLe != (Object)null)
				{
					s_stPanelLe.minHeight = s_stPanelLeMinBase + 48f;
					if (s_stPanelLePrefBase >= 0f)
					{
						s_stPanelLe.preferredHeight = s_stPanelLePrefBase + 48f;
					}
				}
				if ((Object)(object)s_stSave != (Object)null)
				{
					s_stSave.anchoredPosition = new Vector2(s_stSaveBasePos.x, s_stSaveBasePos.y - 48f);
				}
			}
			else if ((Object)(object)s_stSave != (Object)null)
			{
				s_stSave.anchoredPosition = new Vector2(s_stSaveBasePos.x, s_stSaveBasePos.y);
			}
			if (!s_hierarchyDumped)
			{
				s_hierarchyDumped = true;
				DumpBoxHierarchy((Component)((input is Component) ? input : null), field);
			}
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Verbose("[简介] 加高描述框失败:" + ex.Message);
		}
	}

	private static bool Near(Vector2 a, Vector2 b)
	{
		if (Mathf.Abs(a.x - b.x) < 0.6f)
		{
			return Mathf.Abs(a.y - b.y) < 0.6f;
		}
		return false;
	}

	internal static bool IsDescriptionField(TMP_InputField f)
	{
		return object.ReferenceEquals(f, s_descField);
	}

	private static string F2(Vector2 v)
	{
		return "(" + v.x.ToString("F1") + "," + v.y.ToString("F1") + ")";
	}

	private static void DumpDown(Transform t, int depth, int maxDepth, List<string> lines)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Expected O, but got Unknown
		if (depth > maxDepth)
		{
			return;
		}
		foreach (Transform item in t)
		{
			Transform t2 = item;
			lines.Add(Line(t2, depth + 1));
			DumpDown(t2, depth + 1, maxDepth, lines);
		}
	}

	private static string Line(Transform t, int depth)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: 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)
		//IL_0095: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0241: 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_02ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_0318: Unknown result type (might be due to invalid IL or missing references)
		//IL_031d: Unknown result type (might be due to invalid IL or missing references)
		RectTransform val = (RectTransform)(object)((t is RectTransform) ? t : null);
		string text = "-";
		if ((Object)(object)val != (Object)null)
		{
			string[] array = new string[12]
			{
				"anchorMin=",
				F2(val.anchorMin),
				" anchorMax=",
				F2(val.anchorMax),
				" sizeDelta=",
				F2(val.sizeDelta),
				" pos=",
				F2(val.anchoredPosition),
				" rectH=",
				null,
				null,
				null
			};
			Rect rect = val.rect;
			array[9] = ((Rect)(ref rect)).height.ToString("F1");
			array[10] = " rectW=";
			Rect rect2 = val.rect;
			array[11] = ((Rect)(ref rect2)).width.ToString("F1");
			text = string.Concat(array);
		}
		string text2 = "";
		Component[] components = ((Component)t).GetComponents<Component>();
		for (int i = 0; i < components.Length; i++)
		{
			if (!((Object)(object)components[i] == (Object)null))
			{
				text2 = text2 + "[" + ((object)components[i]).GetType().Name + "]";
			}
		}
		LayoutElement component = ((Component)t).GetComponent<LayoutElement>();
		if ((Object)(object)component != (Object)null)
		{
			string text3 = text2;
			text2 = text3 + " LE(minH=" + component.minHeight.ToString("F1") + " prefH=" + component.preferredHeight.ToString("F1") + " flexH=" + component.flexibleHeight.ToString("F1") + " minW=" + component.minWidth.ToString("F1") + " prefW=" + component.preferredWidth.ToString("F1") + ")";
		}
		ContentSizeFitter component2 = ((Component)t).GetComponent<ContentSizeFitter>();
		if ((Object)(object)component2 != (Object)null)
		{
			object obj = text2;
			text2 = string.Concat(obj, " CSF(v=", component2.verticalFit, ")");
		}
		Graphic component3 = ((Component)t).GetComponent<Graphic>();
		if ((Object)(object)component3 != (Object)null)
		{
			string text4 = "-";
			Image val2 = (Image)(object)((component3 is Image) ? component3 : null);
			if ((Object)(object)val2 != (Object)null && (Object)(object)val2.sprite != (Object)null)
			{
				text4 = ((Object)val2.sprite).name;
			}
			object obj2 = text2;
			object[] array2 = new object[10] { obj2, " G(col=", null, null, null, null, null, null, null, null };
			Color color = component3.color;
			array2[2] = ((Color)(ref color)).ToString("F2");
			array2[3] = " sprite=";
			array2[4] = text4;
			array2[5] = " ray=";
			array2[6] = component3.raycastTarget;
			array2[7] = " rectH=";
			Rect rect3 = component3.rectTransform.rect;
			array2[8] = ((Rect)(ref rect3)).height.ToString("F1");
			array2[9] = ")";
			text2 = string.Concat(array2);
		}
		return new string(' ', depth * 2) + "• " + ((Object)t).name + "  " + text + "  " + text2;
	}

	internal static void DumpBoxHierarchy(Component anchor, TMP_InputField field)
	{
		try
		{
			List<string> list = new List<string>();
			Transform transform = anchor.transform;
			Transform val = transform;
			int num = 0;
			while ((Object)(object)val != (Object)null && num < 10)
			{
				list.Add(Line(val, num));
				val = val.parent;
				num++;
			}
			DumpDown(transform, 0, 3, list);
			DumpApplicator(transform, list);
			if ((Object)(object)field != (Object)null && (Object)(object)field.textViewport != (Object)null)
			{
				list.Add("[viewport] " + Line(((Component)field.textViewport).transform, 0));
			}
			HiddenStatsPlugin.Diag("[简介] 层级 dump:\n" + string.Join("\n", list.ToArray()));
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Verbose("[简介] 层级 dump 失败:" + ex.Message);
		}
	}

	private static void DumpApplicator(Transform root, List<string> lines)
	{
		//IL_0135: 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_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_018c: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			Component[] componentsInChildren = ((Component)root).GetComponentsInChildren<Component>(true);
			foreach (Component val in componentsInChildren)
			{
				if ((Object)(object)val == (Object)null || ((object)val).GetType().Name != "SelectableColorApplicator")
				{
					continue;
				}
				FieldInfo fieldInfo = AccessTools.Field(((object)val).GetType(), "innerElements");
				if (fieldInfo == null)
				{
					lines.Add("  [applicator] " + ((Object)val.gameObject).name + " 无 innerElements 字段");
					continue;
				}
				object value = fieldInfo.GetValue(val);
				if (value == null)
				{
					lines.Add("  [applicator] " + ((Object)val.gameObject).name + " innerElements=null");
					continue;
				}
				if (!(value is Graphic[] array))
				{
					lines.Add("  [applicator] " + ((Object)val.gameObject).name + " 元素类型=" + value.GetType().Name);
					continue;
				}
				Graphic[] array2 = array;
				foreach (Graphic val2 in array2)
				{
					if (!((Object)(object)val2 == (Object)null))
					{
						string[] array3 = new string[8]
						{
							"  [applicator] -> ",
							((Object)((Component)val2).gameObject).name,
							" col=",
							null,
							null,
							null,
							null,
							null
						};
						Color color = val2.color;
						array3[3] = ((Color)(ref color)).ToString("F2");
						array3[4] = " rectH=";
						Rect rect = val2.rectTransform.rect;
						array3[5] = ((Rect)(ref rect)).height.ToString("F1");
						array3[6] = " pos=";
						array3[7] = F2(val2.rectTransform.anchoredPosition);
						lines.Add(string.Concat(array3));
					}
				}
			}
		}
		catch (Exception ex)
		{
			lines.Add("  [applicator] 失败: " + ex.Message);
		}
	}

	internal static void GrowBox(UnitEditorSaveScreen screen, object input, TMP_InputField field)
	{
		//IL_00ad: 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_0220: Unknown result type (might be due to invalid IL or missing references)
		//IL_0225: Unknown result type (might be due to invalid IL or missing references)
		//IL_0233: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: 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)
		try
		{
			Component val = (Component)((input is Component) ? input : null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Transform transform = val.transform;
			RectTransform val2 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			RectTransform textViewport = field.textViewport;
			if (!s_boxMeasured)
			{
				s_boxNodes = new List<BoxNode>();
				AddBoxNode(val2);
				RectTransform val3 = FindChildRect((Transform)(object)val2, "UnitDesciption");
				if ((Object)(object)val3 != (Object)null)
				{
					AddBoxNode(val3);
				}
				Transform transform2 = ((Component)field).transform;
				RectTransform val4 = (RectTransform)(object)((transform2 is RectTransform) ? transform2 : null);
				if ((Object)(object)val4 != (Object)null && (Object)(object)val4 != (Object)(object)val2 && (Object)(object)val4 != (Object)(object)val3)
				{
					AddBoxNode(val4);
				}
				if ((Object)(object)textViewport != (Object)null)
				{
					AddBoxNode(textViewport);
				}
				Rect rect = val2.rect;
				float height = ((Rect)(ref rect)).height;
				s_boxDelta = ((height >= 40f) ? (height * 0.5f) : 0f);
				FieldInfo fieldInfo = AccessTools.Field(typeof(UnitEditorSaveScreen), "saveButton");
				if (fieldInfo != null)
				{
					s_saveRect = AsRect(fieldInfo.GetValue(screen));
					if ((Object)(object)s_saveRect != (Object)null)
					{
						s_saveBasePos = s_saveRect.anchoredPosition;
						s_saveHasBase = true;
					}
				}
				s_boxMeasured = true;
				HiddenStatsPlugin.Diag("[简介] 框体基准:高=" + height + " 增量=" + s_boxDelta + " 节点数=" + s_boxNodes.Count + " 保存按钮=" + ((Object)(object)s_saveRect != (Object)null));
				DumpBoxHierarchy(val, field);
			}
			if (s_boxDelta <= 0f)
			{
				return;
			}
			for (int i = 0; i < s_boxNodes.Count; i++)
			{
				StretchNode(s_boxNodes[i], s_boxDelta);
			}
			if (s_saveHasBase)
			{
				Vector2 val5 = default(Vector2);
				((Vector2)(ref val5))..ctor(s_saveBasePos.x, s_saveBasePos.y - s_boxDelta);
				if (!Near(s_saveRect.anchoredPosition, val5))
				{
					s_saveRect.anchoredPosition = val5;
				}
			}
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Verbose("[简介] 调整框体失败:" + ex.Message);
		}
	}

	internal static void WriteText(UnitEditorSaveScreen screen, string text)
	{
		try
		{
			object inputObject = GetInputObject(screen);
			if (inputObject != null)
			{
				PropertyInfo propertyInfo = AccessTools.Property(inputObject.GetType(), "text");
				if (!(propertyInfo == null))
				{
					propertyInfo.SetValue(inputObject, text, null);
				}
			}
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Verbose("[价格] 写入输入框失败:" + ex.Message);
		}
	}

	private static bool Prefix(UnitEditorSaveScreen __instance, string customCost)
	{
		if (HiddenStatsPlugin.CfgUnlimitCost == null || !HiddenStatsPlugin.CfgUnlimitCost.Value)
		{
			return true;
		}
		try
		{
			if (string.IsNullOrEmpty(customCost))
			{
				return false;
			}
			if (!long.TryParse(customCost, out var result))
			{
				if (!float.TryParse(customCost, out var result2))
				{
					return false;
				}
				result = ((result2 < -1E+09f) ? (-1000000000) : ((!(result2 > 2.1474836E+09f)) ? ((long)Math.Floor(result2)) : int.MaxValue));
			}
			long num = -1000000000L;
			long num2;
			if (HiddenStatsPlugin.CfgUnlimitedCostRange == null || HiddenStatsPlugin.CfgUnlimitedCostRange.Value)
			{
				num2 = 2147483647L;
			}
			else
			{
				num2 = HiddenStatsPlugin.CfgMaxCustomCost.Value;
				if (num2 <= 0)
				{
					num2 = 2147483647L;
				}
			}
			bool flag = false;
			if (result < num)
			{
				result = num;
				flag = true;
			}
			if (result > num2)
			{
				result = num2;
				flag = true;
			}
			int num3 = (int)result;
			UnitEditorManager val = (UnitEditorManager)((FManager == null) ? null : /*isinst with value type is only supported in some contexts*/);
			if ((Object)(object)val != (Object)null)
			{
				CustomCostLimit.Set(val, num3);
				if (FCustomCostField == null)
				{
					FCustomCostField = AccessTools.Field(typeof(UnitEditorManager), "<CustomCost>k__BackingField");
				}
				if (FCustomCostField != null)
				{
					int num4 = num3;
					if (num4 < 0)
					{
						num4 = 0;
					}
					if (num4 > 65535)
					{
						num4 = 65535;
					}
					FCustomCostField.SetValue(val, (ushort)num4);
				}
			}
			WriteText(__instance, num3.ToString());
			object obj = ((FCheckmark == null) ? null : FCheckmark.GetValue(__instance));
			if (obj != null)
			{
				MethodInfo methodInfo = AccessTools.Method(obj.GetType(), "SetState", new Type[1] { typeof(bool) }, (Type[])null);
				if (methodInfo != null)
				{
					methodInfo.Invoke(obj, new object[1] { true });
				}
			}
			if (MCheckLegal != null)
			{
				MCheckLegal.Invoke(__instance, null);
			}
			if (MSetAutoCost != null)
			{
				bool flag2 = (Object)(object)val != (Object)null && num3 == (int)val.GetAutoCost();
				MSetAutoCost.Invoke(__instance, new object[1] { flag2 });
			}
			if (MSelectTab != null)
			{
				MSelectTab.Invoke(__instance, null);
			}
			if ((num3 > 65535 || num3 < 0) && num3 != _lastBigValue)
			{
				_lastBigValue = num3;
				HiddenStatsPlugin.Diag("[价格] 已接管自定义价格 = " + num3 + (flag ? "(超出范围,已压到边界)" : ""));
			}
			HiddenStatsPlugin.Verbose("[价格] 自定义价格 = " + num3);
			return false;
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Log.LogError((object)("[HiddenStats] 价格解除限制 Prefix 异常,回退原生逻辑:" + ex));
			return true;
		}
	}
}
[HarmonyPatch(typeof(UnitEditorSaveScreen), "OnEnterSaveScreen")]
internal static class Patch_OnEnterSaveScreen
{
	private static bool DiagDone;

	private static void Postfix(UnitEditorSaveScreen __instance)
	{
		Patch_SetCustomCost.s_descScreen = __instance;
		if (HiddenStatsPlugin.CfgUnlimitDesc != null && HiddenStatsPlugin.CfgUnlimitDesc.Value)
		{
			Patch_SetCustomCost.WidenDescription(__instance);
		}
		if (HiddenStatsPlugin.CfgUnlimitCost == null || !HiddenStatsPlugin.CfgUnlimitCost.Value)
		{
			return;
		}
		try
		{
			Patch_SetCustomCost.WidenInput(__instance);
			if (!DiagDone)
			{
				DiagDone = true;
				HiddenStatsPlugin.Diag("[价格] 保存页已就绪,价格输入框字符上限已交给本插件接管。");
			}
			object obj = ((Patch_SetCustomCost.FManager == null) ? null : Patch_SetCustomCost.FManager.GetValue(__instance));
			UnitEditorManager val = (UnitEditorManager)((obj is UnitEditorManager) ? obj : null);
			if (!((Object)(object)val == (Object)null) && CustomCostLimit.TryGet(val, out var value) && !val.AutoCost)
			{
				Patch_SetCustomCost.WriteText(__instance, value.ToString());
			}
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Log.LogError((object)("[HiddenStats] 保存页 Postfix 异常:" + ex));
		}
	}
}
[HarmonyPatch(typeof(UnitEditorSaveScreen), "OnEnterDescription")]
internal static class Patch_OnEnterDescription
{
	private static void Postfix(UnitEditorSaveScreen __instance)
	{
		if (HiddenStatsPlugin.CfgUnlimitDesc != null && HiddenStatsPlugin.CfgUnlimitDesc.Value)
		{
			Patch_SetCustomCost.WidenDescription(__instance);
		}
	}
}
[HarmonyPatch(typeof(UnitEditorSaveScreen), "SetDescription")]
internal static class Patch_SetDescription
{
	private static void Postfix(UnitEditorSaveScreen __instance)
	{
		if (HiddenStatsPlugin.CfgUnlimitDesc != null && HiddenStatsPlugin.CfgUnlimitDesc.Value)
		{
			Patch_SetCustomCost.WidenDescription(__instance);
		}
	}
}
[HarmonyPatch(typeof(TMP_InputField), "set_text")]
internal static class Patch_DescTextSet
{
	private static void Postfix(TMP_InputField __instance, string value)
	{
		if (Patch_SetCustomCost.IsDescriptionField(__instance))
		{
			int num = value?.Length ?? 0;
			string text = "";
			try
			{
				text = Environment.StackTrace;
			}
			catch (Exception)
			{
			}
			if (text != null && text.Length > 1200)
			{
				text = text.Substring(0, 1200);
			}
			HiddenStatsPlugin.Diag("[简介] set_text len=" + num + "\n" + text);
		}
	}
}
[HarmonyPatch(typeof(UnitEditorManager), "LoadUnit")]
internal static class Patch_LoadUnitCost
{
	private static void Postfix(UnitEditorManager __instance, UnitBlueprint __0)
	{
		if (HiddenStatsPlugin.CfgUnlimitCost == null || !HiddenStatsPlugin.CfgUnlimitCost.Value)
		{
			return;
		}
		try
		{
			if (!((Object)(object)__instance == (Object)null))
			{
				if ((Object)(object)__0 != (Object)null && __0.useCustomCost)
				{
					CustomCostLimit.Set(__instance, __0.customCost);
					HiddenStatsPlugin.Verbose("[价格] 载入兵种,接管自定义价格 = " + __0.customCost);
				}
				else
				{
					CustomCostLimit.Clear(__instance);
				}
			}
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Log.LogError((object)("[HiddenStats] LoadUnit Postfix 异常:" + ex));
		}
	}
}
[HarmonyPatch(typeof(UnitEditorManager), "GetBlueprint"