Decompiled source of SUPER CAT Stats Editor v1.0.1

SUPER CAT Stats.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
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;

[BepInPlugin("com.supermrcat.tabs.hiddenunitstats", "TABS 隐藏属性编辑器", "1.5.1")]
public class HiddenStatsPlugin : BaseUnityPlugin
{
	public const string Guid = "com.supermrcat.tabs.hiddenunitstats";

	public const string PluginName = "TABS 隐藏属性编辑器";

	public const string PluginVersion = "1.5.1";

	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> 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;

	private static Harmony harmony;

	internal static string DiagPath;

	private void Awake()
	{
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: 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。");
		harmony = new Harmony("com.supermrcat.tabs.hiddenunitstats");
		try
		{
			harmony.PatchAll(typeof(HiddenStatsPlugin).Assembly);
			if (CfgVerbose.Value)
			{
				Log.LogInfo((object)"[HiddenStats] Harmony 补丁已全部应用。");
			}
		}
		catch (Exception ex)
		{
			Log.LogError((object)("[HiddenStats] 打补丁失败:" + ex));
		}
	}

	private void Update()
	{
		LocalizationSync.Tick();
	}

	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 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 bool _probed;

	private static int _lastLocale = -9999;

	private static float _nextProbe;

	private static int _revision;

	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 (!_probed)
		{
			_probed = true;
			try
			{
				_localeField = AccessTools.Field(typeof(Localizer), "m_locale");
				_settingsField = AccessTools.Field(typeof(Localizer), "m_settings");
			}
			catch (Exception)
			{
				_localeField = null;
				_settingsField = null;
			}
		}
		if (_localeField == null)
		{
			return 7;
		}
		try
		{
			if (_settingsField != null && _settingsField.GetValue(null) == null)
			{
				return 7;
			}
			object value = _localeField.GetValue(null);
			return (value == null) ? 7 : Convert.ToInt32(value);
		}
		catch (Exception)
		{
			return 7;
		}
	}

	internal static bool UseChinese()
	{
		return Locale() == 7;
	}

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

	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=中文),插件文案按此选择");
			return false;
		}
		_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 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
{
	internal static readonly FieldInfo FManager = AccessTools.Field(typeof(UnitEditorSaveScreen), "UCManager");

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

	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 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)
	{
		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(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")]
internal static class Patch_GetBlueprintCost
{
	private static void Postfix(UnitEditorManager __instance, UnitBlueprint __result)
	{
		if (HiddenStatsPlugin.CfgUnlimitCost == null || !HiddenStatsPlugin.CfgUnlimitCost.Value)
		{
			return;
		}
		try
		{
			if (!((Object)(object)__instance == (Object)null) && !((Object)(object)__result == (Object)null) && !__instance.AutoCost && CustomCostLimit.TryGet(__instance, out var value))
			{
				__result.useCustomCost = true;
				__result.customCost = value;
			}
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Log.LogError((object)("[HiddenStats] GetBlueprint Postfix 异常:" + ex));
		}
	}
}
[HarmonyPatch(typeof(UnitBlueprint), "GetUnitCost")]
internal static class Patch_GetUnitCost
{
	private static FieldInfo FForceCost;

	private static int _lastDiag = -1;

	private static void Postfix(UnitBlueprint __instance, ref uint __result)
	{
		if (HiddenStatsPlugin.CfgUnlimitCost == null || !HiddenStatsPlugin.CfgUnlimitCost.Value)
		{
			return;
		}
		try
		{
			if ((Object)(object)__instance == (Object)null || !__instance.useCustomCost)
			{
				return;
			}
			int customCost = __instance.customCost;
			if (customCost == 0 || (customCost > 0 && customCost <= 65535))
			{
				return;
			}
			if (FForceCost == null)
			{
				FForceCost = AccessTools.Field(typeof(UnitBlueprint), "forceCost");
			}
			if (FForceCost != null)
			{
				object value = FForceCost.GetValue(__instance);
				if (value is uint && (uint)value != 0)
				{
					return;
				}
			}
			__result = (uint)customCost;
			if ((customCost > 65535 || customCost < 0) && customCost != _lastDiag)
			{
				_lastDiag = customCost;
				HiddenStatsPlugin.Diag("[价格] GetUnitCost 已按真实自定义价格返回:" + customCost);
			}
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Log.LogError((object)("[HiddenStats] GetUnitCost Postfix 异常:" + ex));
		}
	}
}
internal static class NegativeCostUI
{
	internal static bool Skip(UnitBlueprint bp)
	{
		if (HiddenStatsPlugin.CfgNegativeCostUI == null || !HiddenStatsPlugin.CfgNegativeCostUI.Value)
		{
			return true;
		}
		if ((Object)(object)bp == (Object)null || !bp.useCustomCost)
		{
			return true;
		}
		return bp.customCost >= 0;
	}
}
[HarmonyPatch(typeof(UnitInfoBar), "SetUnitInfo")]
internal static class Patch_UnitInfoBarCost
{
	private static readonly FieldInfo FUnitCost = AccessTools.Field(typeof(UnitInfoBar), "unitCost");

	private static void Postfix(UnitInfoBar __instance, UnitBlueprint __0)
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (!NegativeCostUI.Skip(__0) && !(FUnitCost == null))
			{
				object value = FUnitCost.GetValue(__instance);
				if (value is TMP_Text)
				{
					((TMP_Text)value).text = __0.customCost.ToString();
				}
			}
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Log.LogError((object)("[HiddenStats] UnitInfoBar 价格显示异常:" + ex));
		}
	}
}
[HarmonyPatch(typeof(UnitButton), "SetupUnit", new Type[] { typeof(UnitButtonData) })]
internal static class Patch_UnitButtonCost
{
	private static readonly FieldInfo FCost = AccessTools.Field(typeof(UnitButton), "m_cost");

	private static readonly FieldInfo FCustom = AccessTools.Field(typeof(UnitButton), "m_customUnitCost");

	private static void Postfix(UnitButton __instance, UnitButtonData __0)
	{
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (__0 == null)
			{
				return;
			}
			UnitBlueprint unit = __0.unit;
			if (NegativeCostUI.Skip(unit))
			{
				return;
			}
			string text = unit.customCost.ToString();
			if (FCost != null)
			{
				object value = FCost.GetValue(__instance);
				if (value is TMP_Text)
				{
					((TMP_Text)value).text = text;
				}
			}
			if (FCustom != null)
			{
				object value2 = FCustom.GetValue(__instance);
				if (value2 is TMP_Text)
				{
					((TMP_Text)value2).text = text;
				}
			}
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Log.LogError((object)("[HiddenStats] UnitButton 价格显示异常:" + ex));
		}
	}
}
[HarmonyPatch(typeof(BattleRadialButton), "UpdateData")]
internal static class Patch_RadialCost
{
	private static readonly FieldInfo FCostLabel = AccessTools.Field(typeof(BattleRadialButton), "costLabel");

	private static void Postfix(BattleRadialButton __instance, IDatabaseEntity __0)
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			UnitBlueprint val = (UnitBlueprint)(object)((__0 is UnitBlueprint) ? __0 : null);
			if (!NegativeCostUI.Skip(val) && !(FCostLabel == null))
			{
				object value = FCostLabel.GetValue(__instance);
				if (value is TMP_Text)
				{
					((TMP_Text)value).text = val.customCost.ToString();
				}
			}
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Log.LogError((object)("[HiddenStats] BattleRadialButton 价格显示异常:" + ex));
		}
	}
}
internal static class LocalizationSync
{
	private static readonly List<UnitEditorStatCell> Cells = new List<UnitEditorStatCell>();

	private static readonly List<int> CellIndexes = new List<int>();

	internal static void Register(UnitEditorStatCell cell, int index)
	{
		if ((Object)(object)cell == (Object)null || index < 0)
		{
			return;
		}
		for (int i = 0; i < Cells.Count; i++)
		{
			if ((Object)(object)Cells[i] == (Object)(object)cell)
			{
				CellIndexes[i] = index;
				return;
			}
		}
		Cells.Add(cell);
		CellIndexes.Add(index);
	}

	private static void Cleanup()
	{
		for (int num = Cells.Count - 1; num >= 0; num--)
		{
			if ((Object)(object)Cells[num] == (Object)null)
			{
				Cells.RemoveAt(num);
				CellIndexes.RemoveAt(num);
			}
		}
	}

	internal static void Tick()
	{
		if (Localization.Poll())
		{
			ForceAll("轮询到语言切换");
		}
	}

	internal static void ForceAll(string reason)
	{
		try
		{
			int num = RefreshRows();
			HiddenStatsResetButton[] array = Resources.FindObjectsOfTypeAll<HiddenStatsResetButton>();
			int num2 = 0;
			for (int i = 0; i < array.Length; i++)
			{
				if (!((Object)(object)array[i] == (Object)null))
				{
					array[i].ApplyLanguage();
					num2++;
				}
			}
			HiddenStatsPlugin.Diag("[语言] 已按 locale=" + Localization.Locale() + " 刷新文案(" + reason + "):隐藏行 " + num + " 个,重置按钮 " + num2 + " 个");
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Log.LogError((object)("[HiddenStats] 语言刷新异常:" + ex));
		}
	}

	internal static void ForceAll()
	{
		ForceAll("手动");
	}

	internal static int RefreshRows()
	{
		ExtraStats.SyncText();
		Cleanup();
		int num = 0;
		for (int i = 0; i < Cells.Count; i++)
		{
			if (ApplyCellText(Cells[i], CellIndexes[i]))
			{
				num++;
			}
		}
		return num;
	}

	internal static bool ApplyCellText(UnitEditorStatCell cell, int index)
	{
		if ((Object)(object)cell == (Object)null || index < 0)
		{
			return false;
		}
		bool result = false;
		TMP_FontAsset val = Localization.CurrentFont();
		string localeID = Localization.Name(index);
		string localeID2 = Localization.Desc(index);
		if ((Object)(object)cell.m_NameText != (Object)null)
		{
			cell.m_NameText.Localized = false;
			cell.m_NameText.LocaleID = localeID;
			if ((Object)(object)val != (Object)null && (Object)(object)cell.m_NameText.Text != (Object)null && (Object)(object)((TMP_Text)cell.m_NameText.Text).font != (Object)(object)val)
			{
				((TMP_Text)cell.m_NameText.Text).font = val;
			}
			result = true;
		}
		if ((Object)(object)cell.m_DescriptionText != (Object)null)
		{
			cell.m_DescriptionText.Localized = false;
			cell.m_DescriptionText.LocaleID = localeID2;
			if ((Object)(object)val != (Object)null && (Object)(object)cell.m_DescriptionText.Text != (Object)null && (Object)(object)((TMP_Text)cell.m_DescriptionText.Text).font != (Object)(object)val)
			{
				((TMP_Text)cell.m_DescriptionText.Text).font = val;
			}
		}
		return result;
	}
}
internal sealed class HiddenStatsResetButton : MonoBehaviour
{
	private RectTransform _rect;

	private RectTransform _input;

	private RectTransform _plus;

	private RectTransform _minus;

	private UnitEditorStatCell _cell;

	private TextMeshProUGUI _label;

	internal void Setup(UnitEditorStatCell cell)
	{
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		_cell = cell;
		ref RectTransform rect = ref _rect;
		Transform transform = ((Component)this).transform;
		rect = (RectTransform)(object)((transform is RectTransform) ? transform : null);
		Transform val = ((Component)this).transform.Find("ResetLabel");
		if ((Object)(object)val != (Object)null)
		{
			_label = ((Component)val).GetComponent<TextMeshProUGUI>();
		}
		_input = (RectTransform)(((Object)(object)cell != (Object)null && (Object)(object)cell.m_InputField != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
		if ((Object)(object)cell != (Object)null)
		{
			Transform val2 = ((Component)cell).transform.Find("Plus");
			Transform val3 = ((Component)cell).transform.Find("Minus");
			_plus = (RectTransform)(object)((val2 is RectTransform) ? val2 : null);
			_minus = (RectTransform)(object)((val3 is RectTransform) ? val3 : null);
		}
		if ((Object)(object)_rect != (Object)null)
		{
			_rect.anchorMin = new Vector2(0.5f, 0.5f);
			_rect.anchorMax = new Vector2(0.5f, 0.5f);
			_rect.pivot = new Vector2(0.5f, 0.5f);
			_rect.sizeDelta = new Vector2(40f, 96f);
		}
	}

	internal void ApplyLanguage()
	{
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_label == (Object)null)
		{
			return;
		}
		try
		{
			((TMP_Text)_label).fontSize = Localization.ResetLabelSize();
			((TMP_Text)_label).text = Localization.ResetLabel();
			if ((Object)(object)_cell != (Object)null && (Object)(object)_cell.m_NameText != (Object)null && (Object)(object)_cell.m_NameText.Text != (Object)null)
			{
				TextMeshProUGUI text = _cell.m_NameText.Text;
				if ((Object)(object)((TMP_Text)text).font != (Object)null)
				{
					((TMP_Text)_label).font = ((TMP_Text)text).font;
				}
				if ((Object)(object)((TMP_Text)text).fontSharedMaterial != (Object)null)
				{
					((TMP_Text)_label).fontSharedMaterial = ((TMP_Text)text).fontSharedMaterial;
				}
				((Graphic)_label).color = ((Graphic)text).color;
			}
		}
		catch (Exception ex)
		{
			HiddenStatsPlugin.Log.LogError((object)("[HiddenStats] 重置按钮文案切换异常:" + ex));
		}
	}

	private void LateUpdate()
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_rect == (Object)null || (Object)(object)_input == (Object)null)
		{
			return;
		}
		Rect rect = _input.rect;
		if (((Rect)(ref rect)).width < 1f)
		{
			return;
		}
		Transform parent = ((Transform)_rect).parent;
		RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null);
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		RectTransform input = _input;
		Rect rect2 = _input.rect;
		float num = LocalY(val, input, ((Rect)(ref rect2)).yMax);
		RectTransform input2 = _input;
		Rect rect3 = _input.rect;
		float num2 = LocalY(val, input2, ((Rect)(ref rect3)).yMin);
		float num3 = num2;
		if ((Object)(object)_plus != (Object)null)
		{
			RectTransform plus = _plus;
			Rect rect4 = _plus.rect;
			float num4 = LocalY(val, plus, ((Rect)(ref rect4)).yMin);
			if (num4 < num3)
			{
				num3 = num4;
			}
		}
		if ((Object)(object)_minus != (Object)null)
		{
			RectTransform minus = _minus;
			Rect rect5 = _minus.rect;
			float num5 = LocalY(val, minus, ((Rect)(ref rect5)).yMin);
			if (num5 < num3)
			{
				num3 = num5;
			}
		}
		num2 = num3;
		float num6 = num - num2;
		if (num6 < 40f)
		{
			num6 = 40f;
		}
		if (num6 > 200f)
		{
			num6 = 200f;
		}
		_rect.anchorMin = new Vector2(0.5f, 0.5f);
		_rect.anchorMax = new Vector2(0.5f, 0.5f);
		_rect.pivot = new Vector2(0.5f, 0.5f);
		_rect.sizeDelta = new Vector2(40f, num6);
		RectTransform input3 = _input;
		Rect rect6 = _input.rect;
		float num7 = LocalX(val, input3, ((Rect)(ref rect6)).xMin);
		float num8 = 40f;
		_rect.anchoredPosition = new Vector2(num7 - 6f - num8 * 0.5f, (num + num2) * 0.5f);
	}

	private static float LocalY(RectTransform parent, RectTransform target, float localY)
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)parent == (Object)null || (Object)(object)target == (Object)null)
		{
			return 0f;
		}
		return ((Transform)parent).InverseTransformPoint(((Transform)target).TransformPoint(new Vector3(0f, localY, 0f))).y;
	}

	private static float LocalX(RectTransform parent, RectTransform target, float localX)
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)parent == (Object)null || (Object)(object)target == (Object)null)
		{
			return 0f;
		}
		return ((Transform)parent).InverseTransformPoint(((Transform)target).TransformPoint(new Vector3(localX, 0f, 0f))).x;
	}
}
internal sealed class HiddenStatsBarDrag : MonoBehaviour, IPointerDownHandler, IDragHandler, IEventSystemHandler
{
	private HiddenStatsScroller scroller;

	private RectTransform track;

	private bool isHandle;

	private float lastY;

	internal void Init(HiddenStatsScroller sc, RectTransform trackRt, bool handleMode)
	{
		scroller = sc;
		track = trackRt;
		isHandle = handleMode;
	}

	public void OnPointerDown(PointerEventData eventData)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		if (isHandle)
		{
			lastY = eventData.position.y;
		}
		else
		{
			Jump(eventData);
		}
	}

	public void OnDrag(PointerEventData eventData)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)scroller == (Object)null))
		{
			if (isHandle)
			{
				float d = eventData.position.y - lastY;
				lastY = eventData.position.y;
				scroller.AddOffset(d);
			}
			else
			{
				Jump(eventData);
			}
		}
	}

	private void Jump(PointerEventData eventData)
	{
		//IL_0048: 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_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)scroller == (Object)null || (Object)(object)track == (Object)null)
		{
			return;
		}
		float maxOffset = scroller.MaxOffset;
		if (maxOffset < 1f)
		{
			return;
		}
		Canvas componentInParent = ((Component)track).GetComponentInParent<Canvas>();
		Camera val = (((Object)(object)componentInParent != (Object)null && (int)componentInParent.renderMode != 0) ? componentInParent.worldCamera : null);
		Vector2 val2 = default(Vector2);
		if (RectTransformUtility.ScreenPointToLocalPointInRectangle(track, eventData.position, val, ref val2))
		{
			Rect rect = track.rect;
			float height = ((Rect)(ref rect)).height;
			if (!(height < 1f))
			{
				float num = Mathf.Clamp01((height * 0.5f - val2.y) / height);
				scroller.SetOffsetFromBar(num * maxOffset);
			}
		}
	}
}
internal sealed class HiddenStatsScroller : MonoBehaviour, IScrollHandler, IBeginDragHandler, IDragHandler, IEventSystemHandler
{
	internal static float SavedOffset;

	private int lastUiScrollFrame = -10;

	private RectTransform content;

	private RectTransform panel;

	private RectTransform barRoot;

	private RectTransform barTrack;

	private RectTransform barHandle;

	private float sensitivity = 35f;

	private float offset;

	private float maxOffset;

	private float stableMax;

	private float contentHeight;

	private bool wheelLogged;

	private float prevApplied;

	private int frames;

	private float dragLastY;

	private bool dragging;

	private Canvas hookCanvas;

	private float applied;

	internal float MaxOffset => maxOffset;

	internal float Offset => offset;

	internal void Init(RectTransform contentRt, RectTransform panelRt, float sens)
	{
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Expected O, but got Unknown
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Expected O, but got Unknown
		content = contentRt;
		panel = panelRt;
		sensitivity = Mathf.Max(1f, sens);
		offset = SavedOffset;
		frames = 0;
		HiddenStatsPlugin.Diag("[HiddenStats] 滚动器初始化,恢复上次位置:" + offset.ToString("F0"));
		Canvas componentInParent = ((Component)panel).GetComponentInParent<Canvas>();
		if ((Object)(object)componentInParent != (Object)null && (Object)(object)hookCanvas != (Object)(object)componentInParent)
		{
			if ((Object)(object)hookCanvas != (Object)null)
			{
				Canvas.willRenderCanvases -= new WillRenderCanvases(ApplyOffset);
			}
			hookCanvas = componentInParent;
			Canvas.willRenderCanvases += new WillRenderCanvases(ApplyOffset);
		}
	}

	private void OnDestroy()
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Expected O, but got Unknown
		if ((Object)(object)hookCanvas != (Object)null)
		{
			Canvas.willRenderCanvases -= new WillRenderCanvases(ApplyOffset);
			hookCanvas = null;
		}
	}

	internal bool BindContent(RectTransform rt)
	{
		if ((Object)(object)rt == (Object)null || (Object)(object)content == (Object)(object)rt)
		{
			return false;
		}
		content = rt;
		applied = 0f;
		offset = Mathf.Max(0f, SavedOffset);
		return true;
	}

	private void ApplyOffset()
	{
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)content == (Object)null))
		{
			float num = Mathf.Min(offset, Mathf.Max(0f, maxOffset));
			Vector2 anchoredPosition = content.anchoredPosition;
			content.anchoredPosition = new Vector2(anchoredPosition.x, anchoredPosition.y - applied + num);
			applied = num;
		}
	}

	public void OnScroll(PointerEventData eventData)
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		if (eventData == null || (Object)(object)content == (Object)null || (Object)(object)panel == (Object)null)
		{
			return;
		}
		lastUiScrollFrame = Time.frameCount;
		float y = eventData.scrollDelta.y;
		if (!(Mathf.Abs(y) < 0.01f))
		{
			offset = Mathf.Clamp(offset - y * sensitivity, 0f, Mathf.Max(stableMax, maxOffset));
			if (!wheelLogged)
			{
				wheelLogged = true;
				HiddenStatsPlugin.Diag("[HiddenStats] 收到 UI 滚轮事件 delta=" + y + " → offset " + offset.ToString("F0") + "/" + maxOffset.ToString("F0"));
			}
		}
	}

	public void OnBeginDrag(PointerEventData eventData)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		dragging = true;
		dragLastY = eventData.position.y;
	}

	public void OnDrag(PointerEventData eventData)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		if (dragging && !((Object)(object)content == (Object)null))
		{
			float num = eventData.position.y - dragLastY;
			dragLastY = eventData.position.y;
			offset = Mathf.Clamp(offset + num, 0f, Mathf.Max(stableMax, maxOffset));
		}
	}

	internal void SetOffsetFromBar(float want)
	{
		offset = Mathf.Clamp(want, 0f, Mathf.Max(stableMax, maxOffset));
	}

	internal void AttachBar(RectTransform root, RectTransform track, RectTransform handle)
	{
		barRoot = root;
		barTrack = track;
		barHandle = handle;
		((Component)handle).gameObject.AddComponent<HiddenStatsBarDrag>().Init(this, track, handleMode: true);
		if ((Object)(object)root != (Object)null)
		{
			((Component)root).gameObject.AddComponent<HiddenStatsBarDrag>().Init(this, track, handleMode: false);
		}
	}

	internal void AddOffset(float d)
	{
		offset = Mathf.Clamp(offset + d, 0f, Mathf.Max(stableMax, maxOffset));
	}

	private void Update()
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)content == (Object)null || (Object)(object)panel == (Object)null || Time.frameCount - lastUiScrollFrame <= 1)
		{
			return;
		}
		float y = Input.mouseScrollDelta.y;
		if (!(Mathf.Abs(y) < 0.01f) && RectTransformUtility.RectangleContainsScreenPoint(panel, Vector2.op_Implicit(Input.mousePosition), (Camera)null))
		{
			offset = Mathf.Clamp(offset - y * sensitivity, 0f, Mathf.Max(stableMax, maxOffset));
			if (!wheelLogged)
			{
				wheelLogged = true;
				HiddenStatsPlugin.Diag("[HiddenStats] 收到滚轮事件 delta=" + y + " → offset " + offset.ToString("F0") + "/" + maxOffset.ToString("F0"));
			}
		}
	}

	private void LateUpdate()
	{
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_0413: Unknown result type (might be due to invalid IL or missing references)
		//IL_045d: Unknown result type (might be due to invalid IL or missing references)
		//IL_046d: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)content == (Object)null || (Object)(object)panel == (Object)null)
		{
			return;
		}
		float num = 0f;
		float num2 = 0f;
		bool flag = false;
		for (int i = 0; i < ((Transform)content).childCount; i++)
		{
			Transform child = ((Transform)content).GetChild(i);
			RectTransform val = (RectTransform)(object)((child is RectTransform) ? child : null);
			if (!((Object)(object)val == (Object)null))
			{
				float y = val.anchoredPosition.y;
				Rect rect = val.rect;
				float num3 = y + ((Rect)(ref rect)).height * (1f - val.pivot.y);
				float y2 = val.anchoredPosition.y;
				Rect rect2 = val.rect;
				float num4 = y2 - ((Rect)(ref rect2)).height * val.pivot.y;
				if (!flag || num3 > num)
				{
					num = num3;
				}
				if (!flag || num4 < num2)
				{
					num2 = num4;
				}
				flag = true;
			}
		}
		contentHeight = (flag ? (num - num2 + 12f + 110f) : 0f);
		if (contentHeight < 1f)
		{
			return;
		}
		float num5 = ComputeVisibleHeight();
		maxOffset = Mathf.Max(0f, contentHeight - num5);
		if (maxOffset > stableMax)
		{
			stableMax = maxOffset;
		}
		if (maxOffset < 1f && offset > 1f)
		{
			return;
		}
		offset = Mathf.Round(Mathf.Clamp(offset, 0f, Mathf.Max(stableMax, maxOffset)));
		if (offset <= 1f && prevApplied > 5f)
		{
			HiddenStatsPlugin.Diag("[HiddenStats] 滚动位置被清零(上一帧 " + prevApplied.ToString("F0") + ",maxOffset " + maxOffset.ToString("F0") + ")");
		}
		prevApplied = offset;
		ApplyOffset();
		SavedOffset = offset;
		if (frames < 60)
		{
			frames++;
			if (frames == 30)
			{
				HiddenStatsPlugin.Diag("[HiddenStats] 滚动器就绪:面板高 " + num5.ToString("F0") + ",内容高 " + contentHeight.ToString("F0") + ",可滚动 " + maxOffset.ToString("F0") + ",行数 " + ((Transform)content).childCount + ",滚动条 " + (((Object)(object)barRoot != (Object)null) ? "有" : "无") + ",当前位置 " + offset.ToString("F0"));
				DumpRow(content, 2);
				DumpRow(content, ((Transform)content).childCount - 1);
			}
		}
		if (!((Object)(object)barRoot != (Object)null) || !((Object)(object)barTrack != (Object)null) || !((Object)(object)barHandle != (Object)null))
		{
			return;
		}
		bool flag2 = maxOffset > 1f;
		if (((Component)barRoot).gameObject.activeSelf != flag2)
		{
			((Component)barRoot).gameObject.SetActive(flag2);
		}
		if (flag2)
		{
			Rect rect3 = barTrack.rect;
			float height = ((Rect)(ref rect3)).height;
			float num6 = Mathf.Clamp01(num5 / Mathf.Max(1f, contentHeight));
			float num7 = Mathf.Clamp(height * num6, 28f, height);
			Vector2 sizeDelta = barHandle.sizeDelta;
			if (Mathf.Abs(sizeDelta.y - num7) > 0.5f)
			{
				barHandle.sizeDelta = new Vector2(sizeDelta.x, num7);
			}
			float num8 = Mathf.Max(0f, height - num7);
			float num9 = ((maxOffset > 0f) ? (offset / maxOffset) : 0f);
			barHandle.anchoredPosition = new Vector2(barHandle.anchoredPosition.x, (0f - num8) * num9);
		}
	}

	private static void DumpRow(RectTransform content, int index)
	{
		//IL_006a: 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_00b7: 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_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_0214: Unknown result type (might be due to invalid IL or missing references)
		//IL_023a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0260: Unknown result type (might be due to invalid IL or missing references)
		//IL_0265: Unknown result type (might be due to invalid IL or missing references)
		//IL_028c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0291: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)content == (Object)null || index < 0 || index >= ((Transform)content).childCount)
		{
			return;
		}
		Transform child = ((Transform)content).GetChild(index);
		RectTransform val = (RectTransform)(object)((child is RectTransform) ? child : null);
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		object[] array = new object[22]
		{
			"[HiddenStats][Row",
			index,
			"] ",
			((Object)val).name,
			" 位置=(",
			null,
			null,
			null,
			null,
			null,
			null,
			null,
			null,
			null,
			null,
			null,
			null,
			null,
			null,
			null,
			null,
			null
		};
		float x = val.anchoredPosition.x;
		array[5] = x.ToString("F0");
		array[6] = ",";
		float y = val.anchoredPosition.y;
		array[7] = y.ToString("F0");
		array[8] = ") 尺寸=";
		Rect rect = val.rect;
		array[9] = ((Rect)(ref rect)).width.ToString("F0");
		array[10] = "x";
		Rect rect2 = val.rect;
		array[11] = ((Rect)(ref rect2)).height.ToString("F0");
		array[12] = " 锚点=(";
		float x2 = val.anchorMin.x;
		array[13] = x2.ToString("F2");
		array[14] = ",";
		float y2 = val.anchorMin.y;
		array[15] = y2.ToString("F2");
		array[16] = ")-(";
		float x3 = val.anchorMax.x;
		array[17] = x3.ToString("F2");
		array[18] = ",";
		float y3 = val.anchorMax.y;
		array[19] = y3.ToString("F2");
		array[20] = ") 子元素 ";
		array[21] = ((Transform)val).childCount;
		string text = string.Concat(array);
		for (int i = 0; i < ((Transform)val).childCount; i++)
		{
			Transform child2 = ((Transform)val).GetChild(i);
			RectTransform val2 = (RectTransform)(object)((child2 is RectTransform) ? child2 : null);
			if (!((Object)(object)val2 == (Object)null))
			{
				string text2 = text;
				string[] array2 = new string[12]
				{
					text2,
					" | ",
					((Object)val2).name,
					"(",
					null,
					null,
					null,
					null,
					null,
					null,
					null,
					null
				};
				float x4 = val2.anchoredPosition.x;
				array2[4] = x4.ToString("F0");
				array2[5] = ",";
				float y4 = val2.anchoredPosition.y;
				array2[6] = y4.ToString("F0");
				array2[7] = " ";
				Rect rect3 = val2.rect;
				array2[8] = ((Rect)(ref rect3)).width.ToString("F0");
				array2[9] = "x";
				Rect rect4 = val2.rect;
				array2[10] = ((Rect)(ref rect4)).height.ToString("F0");
				array2[11] = ")";
				text = string.Concat(array2);
			}
		}
		HiddenStatsPlugin.Diag(text);
	}

	private float ComputeVisibleHeight()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)panel == (Object)null)
		{
			return 0f;
		}
		Rect a = WorldRect(panel);
		Transform parent = ((Transform)panel).parent;
		int num = 0;
		while ((Object)(object)parent != (Object)null && num < 6)
		{
			RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null);
			if ((Object)(object)val != (Object)null && ((Object)(object)((Component)parent).GetComponent<RectMask2D>() != (Object)null || (Object)(object)((Component)parent).GetComponent<Mask>() != (Object)null))
			{
				Rect b = WorldRect(val);
				if (((Rect)(ref b)).height > 0.5f)
				{
					a = Intersect(a, b);
				}
			}
			parent = parent.parent;
			num++;
		}
		Rect val2 = WorldRect(panel);
		if (((Rect)(ref val2)).height <= 0.01f)
		{
			Rect rect = panel.rect;
			return ((Rect)(ref rect)).height;
		}
		if (((Rect)(ref a)).height <= 0.5f)
		{
			Rect rect2 = panel.rect;
			return ((Rect)(ref rect2)).height;
		}
		float height = ((Rect)(ref a)).height;
		Rect rect3 = panel.rect;
		return height * (((Rect)(ref rect3)).height / ((Rect)(ref val2)).height);
	}

	private static Rect WorldRect(RectTransform rt)
	{
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		Vector3[] array = (Vector3[])(object)new Vector3[4];
		rt.GetWorldCorners(array);
		float x = array[0].x;
		float y = array[0].y;
		float x2 = array[2].x;
		float y2 = array[2].y;
		return new Rect(x, y, Mathf.Max(0f, x2 - x), Mathf.Max(0f, y2 - y));
	}

	private static Rect Intersect(Rect a, Rect b)
	{
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Max(((Rect)(ref a)).xMin, ((Rect)(ref b)).xMin);
		float num2 = Mathf.Max(((Rect)(ref a)).yMin, ((Rect)(ref b)).yMin);
		float num3 = Mathf.Min(((Rect)(ref a)).xMax, ((Rect)(ref b)).xMax);
		float num4 = Mathf.Min(((Rect)(ref a)).yMax, ((Rect)(ref b)).yMax);
		if (num3 <= num || num4 <= num2)
		{
			return a;
		}
		return new Rect(num, num2, num3 - num, num4 - num2);
	}

	internal void ScrollToTransform(Transform item)
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: 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_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_0076: Unknown result type (might be due to invalid IL or missing references)
		RectTransform val = (RectTransform)(object)((item is RectTransform) ? item : null);
		if (!((Object)(object)val == (Object)null) && !((Object)(object)content == (Object)null) && !((Object)(object)panel == (Object)null))
		{
			float y = val.anchoredPosition.y;
			Rect rect = val.rect;
			float num = y + ((Rect)(ref rect)).height * (1f - val.pivot.y);
			float y2 = val.anchoredPosition.y;
			Rect rect2 = val.rect;
			float num2 = y2 - ((Rect)(ref rect2)).height * val.pivot.y;
			float num3 = 0f - num;
			float num4 = 0f - num2;
			float num5 = ComputeVisibleHeight();
			if (num3 - offset < 0f)
			{
				offset = num3;
			}
			else if (num4 - offset > num5)
			{
				offset = num4 - num5;
			}
			offset = Mathf.Clamp(offset, 0f, maxOffset);
		}
	}
}