Decompiled source of Super Cat Ultimate Placement v1.1.0

SUPER CAT SUPER Placement.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Globalization;
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 InControl;
using Landfall.TABS;
using Landfall.TABS.UnitPlacement;
using Landfall.TABS_Input;
using TFBGames;
using UnityEngine;
using UnityEngine.SceneManagement;

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

[BepInPlugin("doubao.tabs.freeplace", "TABS Free Placement (自由放置)", "1.13.8")]
public class Plugin : BaseUnityPlugin
{
	private sealed class BindItem
	{
		internal ConfigEntry<KeyCode> Entry;

		internal KeyCode Default;

		internal string Zh;

		internal string En;
	}

	private const float FadeInTime = 0.18f;

	private const float FadeOutTime = 0.13f;

	private const float BindOutTime = 0.22f;

	private const float BindInTime = 0.16f;

	private const int HintLines = 8;

	public static Plugin Inst;

	public static ManualLogSource L;

	public static ConfigEntry<bool> TerrainUnlock;

	public static ConfigEntry<bool> AirUnlock;

	public static ConfigEntry<bool> AllowOverlap;

	public static ConfigEntry<bool> FreezeFloating;

	public static ConfigEntry<bool> ShowHint;

	public static ConfigEntry<bool> AllowAirRemove;

	public static ConfigEntry<bool> GhostSolidOn;

	public static ConfigEntry<bool> ShowUnitLabels;

	public static ConfigEntry<float> HeightSpeed;

	public static ConfigEntry<float> BaseDistance;

	public static ConfigEntry<float> MaxDistance;

	public static ConfigEntry<float> Cooldown;

	public static ConfigEntry<float> HoldDelay;

	public static ConfigEntry<float> StackInterval;

	public static ConfigEntry<KeyCode> KeyToggle;

	public static ConfigEntry<KeyCode> KeyHeight;

	public static ConfigEntry<float> HeightStep;

	public static ConfigEntry<float> HeightHoldDelay;

	public static ConfigEntry<float> HeightRepeat;

	public static ConfigEntry<KeyCode> KeyLockX;

	public static ConfigEntry<KeyCode> KeyLockZ;

	public static ConfigEntry<KeyCode> KeyLockY;

	public static ConfigEntry<KeyCode> KeyClearLocks;

	public static ConfigEntry<KeyCode> KeyHint;

	public static bool HintVisible;

	public static bool MouseOverPanel;

	internal static float PanelAlpha = 0f;

	internal static bool BindPanelOpen;

	private static int _bindListen = -1;

	private static float BindSlide;

	private static BindItem[] Binds;

	public static bool TypingInField;

	public static ConfigEntry<KeyCode> KeyStackMode;

	public static bool AirMode;

	public static bool StackMode;

	private GUIStyle _style;

	private Texture2D _bg;

	private float _langTimer;

	private bool _zh = true;

	private bool _checkDone;

	private float _nextCheck;

	private int _checkTimes;

	private static bool _imeOff;

	private GUIStyle _tfStyle;

	private GUIStyle _plainStyle;

	private GUIStyle _noteStyle;

	private string _heightText = "";

	private string[] _axisText = new string[3] { "", "", "" };

	private Font _font;

	internal static bool Fin(float v)
	{
		if (!float.IsNaN(v))
		{
			return !float.IsInfinity(v);
		}
		return false;
	}

	internal static Color WithAlpha(Color c, float a)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		c.a *= a;
		return c;
	}

	private static void FadeTick()
	{
		bool flag = HintVisible && ShowHint != null && ShowHint.Value && ModeGate.Sandbox && AirPlacement.PlacementActive;
		float num = (flag ? 0.18f : 0.13f);
		if (num <= 0f)
		{
			PanelAlpha = (flag ? 1f : 0f);
			return;
		}
		float num2 = Time.unscaledDeltaTime / num;
		PanelAlpha = (flag ? Mathf.Min(1f, PanelAlpha + num2) : Mathf.Max(0f, PanelAlpha - num2));
		bool flag2 = BindPanelOpen && flag;
		float num3 = (flag2 ? 0.22f : 0.16f);
		float num4 = Time.unscaledDeltaTime / num3;
		BindSlide = (flag2 ? Mathf.Min(1f, BindSlide + num4) : Mathf.Max(0f, BindSlide - num4));
		if (!flag)
		{
			BindPanelOpen = false;
			_bindListen = -1;
		}
	}

	private static BindItem MakeBind(ConfigEntry<KeyCode> e, KeyCode def, string zh, string en)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		BindItem bindItem = new BindItem();
		bindItem.Entry = e;
		bindItem.Default = def;
		bindItem.Zh = zh;
		bindItem.En = en;
		return bindItem;
	}

	private static void InitBinds()
	{
		Binds = new BindItem[8];
		Binds[0] = MakeBind(KeyToggle, (KeyCode)283, "悬空模式", "Air mode");
		Binds[1] = MakeBind(KeyStackMode, (KeyCode)111, "堆叠模式", "Stack mode");
		Binds[2] = MakeBind(KeyHeight, (KeyCode)118, "升降高度", "Height key");
		Binds[3] = MakeBind(KeyLockX, (KeyCode)120, "锁定 X 轴", "Lock X");
		Binds[4] = MakeBind(KeyLockZ, (KeyCode)122, "锁定 Z 轴", "Lock Z");
		Binds[5] = MakeBind(KeyLockY, (KeyCode)99, "锁定 Y 轴", "Lock Y");
		Binds[6] = MakeBind(KeyHint, (KeyCode)282, "提示栏", "Hint panel");
		Binds[7] = MakeBind(KeyClearLocks, (KeyCode)0, "清除轴锁", "Clear locks");
	}

	private static bool IsModifierKey(KeyCode k)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Invalid comparison between Unknown and I4
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Invalid comparison between Unknown and I4
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Invalid comparison between Unknown and I4
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Invalid comparison between Unknown and I4
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Invalid comparison between Unknown and I4
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Invalid comparison between Unknown and I4
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Invalid comparison between Unknown and I4
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Invalid comparison between Unknown and I4
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Invalid comparison between Unknown and I4
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Invalid comparison between Unknown and I4
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Invalid comparison between Unknown and I4
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Invalid comparison between Unknown and I4
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Invalid comparison between Unknown and I4
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Invalid comparison between Unknown and I4
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Invalid comparison between Unknown and I4
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Invalid comparison between Unknown and I4
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Invalid comparison between Unknown and I4
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Invalid comparison between Unknown and I4
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Invalid comparison between Unknown and I4
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Invalid comparison between Unknown and I4
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Invalid comparison between Unknown and I4
		if ((int)k != 304 && (int)k != 303 && (int)k != 306 && (int)k != 305 && (int)k != 308 && (int)k != 307 && (int)k != 310 && (int)k != 309 && (int)k != 310 && (int)k != 309 && (int)k != 311 && (int)k != 312 && (int)k != 301 && (int)k != 300 && (int)k != 323 && (int)k != 324 && (int)k != 325 && (int)k != 326 && (int)k != 327 && (int)k != 328)
		{
			return (int)k == 329;
		}
		return true;
	}

	internal static bool BindCaptureTick()
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Invalid comparison between Unknown and I4
		//IL_003f: 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_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Invalid comparison between Unknown and I4
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Invalid comparison between Unknown and I4
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		if (_bindListen < 0)
		{
			return false;
		}
		if (!BindPanelOpen)
		{
			_bindListen = -1;
			return false;
		}
		if (Input.GetKeyDown((KeyCode)27))
		{
			_bindListen = -1;
			Diag.Write("[按键] 改键取消");
			return true;
		}
		for (int i = 1; i <= 329; i++)
		{
			KeyCode val = (KeyCode)i;
			if ((int)val != 27 && !IsModifierKey(val) && Input.GetKeyDown(val))
			{
				if ((int)val == 8 || (int)val == 127)
				{
					ApplyBind(_bindListen, (KeyCode)0);
				}
				else
				{
					ApplyBind(_bindListen, val);
				}
				return true;
			}
		}
		return true;
	}

	private static void SaveKeysNow()
	{
		try
		{
			if ((Object)(object)Inst != (Object)null && ((BaseUnityPlugin)Inst).Config != null)
			{
				((BaseUnityPlugin)Inst).Config.Save();
				Diag.Write("[按键] 已写入配置文件");
			}
		}
		catch (Exception ex)
		{
			Diag.Write("[按键] 写配置失败: " + ex.Message);
		}
	}

	private static void ApplyBind(int index, KeyCode k)
	{
		//IL_0033: 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_0041: 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_0091: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
		_bindListen = -1;
		if (Binds == null || index < 0 || index >= Binds.Length)
		{
			return;
		}
		BindItem bindItem = Binds[index];
		if (bindItem.Entry == null)
		{
			return;
		}
		bindItem.Entry.Value = k;
		SaveKeysNow();
		string text = (((int)k == 0) ? "无" : ((object)k).ToString());
		Diag.Write("[按键] " + bindItem.Zh + " = " + text);
		if ((int)k == 0)
		{
			return;
		}
		for (int i = 0; i < Binds.Length; i++)
		{
			if (i != index)
			{
				BindItem bindItem2 = Binds[i];
				if (bindItem2.Entry != null && (int)bindItem2.Entry.Value != 0 && bindItem2.Entry.Value == k)
				{
					Diag.Write("[按键] 注意:与“" + bindItem2.Zh + "”重复绑定了 " + text);
				}
			}
		}
	}

	private static void ResetAllBinds()
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		_bindListen = -1;
		if (Binds == null)
		{
			return;
		}
		for (int i = 0; i < Binds.Length; i++)
		{
			if (Binds[i].Entry != null)
			{
				Binds[i].Entry.Value = Binds[i].Default;
			}
		}
		SaveKeysNow();
		Diag.Write("[按键] 全部恢复默认");
	}

	private void DrawBindPanel(Rect br, float alpha, bool interactive)
	{
		//IL_0053: 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_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: 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_02f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_01df: Unknown result type (might be due to invalid IL or missing references)
		//IL_0329: Unknown result type (might be due to invalid IL or missing references)
		//IL_0258: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: Unknown result type (might be due to invalid IL or missing references)
		if (Binds == null)
		{
			InitBinds();
		}
		if (Binds == null || (Object)(object)_bg == (Object)null)
		{
			return;
		}
		GUIStyle val = ((_noteStyle != null) ? _noteStyle : _plainStyle);
		if (val == null)
		{
			return;
		}
		GUI.color = new Color(0f, 0f, 0f, 0.6f * alpha);
		GUI.DrawTexture(br, (Texture)(object)_bg);
		GUI.color = new Color(1f, 1f, 1f, alpha);
		GUI.Label(new Rect(((Rect)(ref br)).x + 10f, ((Rect)(ref br)).y + 6f, ((Rect)(ref br)).width - 20f, 22f), _zh ? "按键设置:点按钮,再按任意键" : "KEYS: click, then press a key", val);
		bool enabled = GUI.enabled;
		GUI.enabled = enabled && interactive;
		int num = Binds.Length;
		for (int i = 0; i < num; i++)
		{
			BindItem bindItem = Binds[i];
			float num2 = ((Rect)(ref br)).y + 34f + (float)i * 28f;
			GUI.Label(new Rect(((Rect)(ref br)).x + 10f, num2, 122f, 24f), _zh ? bindItem.Zh : bindItem.En, val);
			string text = ((_bindListen != i) ? KeyText(bindItem.Entry) : (_zh ? "按任意键…" : "press a key..."));
			if (GUI.Button(new Rect(((Rect)(ref br)).x + 134f, num2, 106f, 24f), text))
			{
				_bindListen = ((_bindListen == i) ? (-1) : i);
				Diag.Write("[按键] 等待新按键:" + bindItem.Zh);
			}
			if (GUI.Button(new Rect(((Rect)(ref br)).x + 244f, num2, 48f, 24f), _zh ? "默认" : "DEF"))
			{
				if (_bindListen == i)
				{
					_bindListen = -1;
				}
				if (bindItem.Entry != null)
				{
					bindItem.Entry.Value = bindItem.Default;
				}
				SaveKeysNow();
				Diag.Write("[按键] " + bindItem.Zh + " 恢复默认 = " + bindItem.Default);
			}
		}
		float num3 = ((Rect)(ref br)).y + 34f + (float)num * 28f + 4f;
		if (GUI.Button(new Rect(((Rect)(ref br)).x + 10f, num3, 150f, 24f), _zh ? "全部恢复默认" : "RESET ALL"))
		{
			ResetAllBinds();
		}
		if (GUI.Button(new Rect(((Rect)(ref br)).x + ((Rect)(ref br)).width - 92f, num3, 82f, 24f), _zh ? "关闭" : "CLOSE"))
		{
			BindPanelOpen = false;
			_bindListen = -1;
		}
		GUI.enabled = enabled;
		GUI.color = Color.white;
	}

	private void Awake()
	{
		//IL_041c: Unknown result type (might be due to invalid IL or missing references)
		//IL_043a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0458: Unknown result type (might be due to invalid IL or missing references)
		//IL_0476: Unknown result type (might be due to invalid IL or missing references)
		//IL_0494: Unknown result type (might be due to invalid IL or missing references)
		//IL_06e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_06f7: Expected O, but got Unknown
		//IL_04f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0662: Unknown result type (might be due to invalid IL or missing references)
		//IL_0668: Expected O, but got Unknown
		Inst = this;
		L = ((BaseUnityPlugin)this).Logger;
		TerrainUnlock = ((BaseUnityPlugin)this).Config.Bind<bool>("地形限制", "解除地形放置限制", true, "true = 陡坡/侧壁/水面等原本禁止放置的图层也可以放兵种;false = 还原原版。 / true = steep slopes, walls and water can accept units; false = vanilla rules.");
		AirUnlock = ((BaseUnityPlugin)this).Config.Bind<bool>("悬空放置", "启用悬空放置", true, "true = 可以用快捷键进入悬空模式,在任意高度放置兵种;false = 完全不涉及悬空,只用原版放置。 / true = hotkey-toggled air mode allows placing at any height; false = vanilla placement only.");
		AllowOverlap = ((BaseUnityPlugin)this).Config.Bind<bool>("放置规则", "允许兵种互相重叠", true, "true = 取消“目标位置已有兵种就不能放”的碰撞检查(可以叠在一起放、鼠标停在已有兵种上也能继续放);false = 原版规则。 / true = skip the overlap check, so units can be stacked on top of existing ones; false = vanilla.");
		FreezeFloating = ((BaseUnityPlugin)this).Config.Bind<bool>("悬空放置", "悬空单位开战后保持静止", false, "true = 悬空放下的兵种开战后仍固定停在空中(像雕像,不会下落也不会被推走);false = 开战后按物理自然下落。 / true = airborne units stay frozen in the air after the battle starts; false = they fall naturally.");
		ShowHint = ((BaseUnityPlugin)this).Config.Bind<bool>("界面", "显示屏幕提示", true, "模式提示条显示在屏幕最左侧。 / The hint panel is drawn on the far left of the screen.");
		GhostSolidOn = ((BaseUnityPlugin)this).Config.Bind<bool>("放置规则", "虚化地图部件实体化", true, "true = 原版在放置阶段会把地图上某些部件虚化(半透明 + 关掉碰撞体,鼠标会穿过去)。这里在源头拦掉这次虚化,让这些部件常驻保持实体:看得见、鼠标能停在上面、可以往上放兵,沙盒以外的原版模式同样生效;false = 完全交还原版。提示栏里有同名开关按钮,随时可切。 / true = intercept the vanilla ghosting of map parts (translucent + colliders off) and keep them solid at all times, in every game mode; false = vanilla behaviour.");
		AllowAirRemove = ((BaseUnityPlugin)this).Config.Bind<bool>("放置规则", "允许删除悬空兵种", true, "true = 删除功能不受高度限制,指到天上的兵种也能删掉;false = 只用原版删除规则。 / true = you can delete units up in the air; false = vanilla delete rules.");
		ShowUnitLabels = ((BaseUnityPlugin)this).Config.Bind<bool>("放置规则", "标注兵种位置", false, "true = 在场上每个已放置兵种的落点上方弹出信息框,显示兵种名称和坐标(X/Y/Z),信息框带逐渐延伸出来的展开动画;关闭时整体淡出消失。提示栏里有同名开关按钮,默认关。 / true = draw a name + coordinate tag above every placed unit with a grow-in animation and fade-out; false = no tags. Toggled from the hint panel, off by default.");
		HeightSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("悬空放置", "升降速度(单位/秒)", 2.5f, "按住升降键时,放置面每秒升降多少世界单位。 / World units per second while holding the height key.");
		BaseDistance = ((BaseUnityPlugin)this).Config.Bind<float>("悬空放置", "朝天空时的基础距离", 18f, "视线朝上或打不到水平面时,光标沿视线方向取多远。 / Cursor distance along the view ray when nothing is hit.");
		MaxDistance = ((BaseUnityPlugin)this).Config.Bind<float>("悬空放置", "最大放置距离", 90f, "悬空光标距离相机的最远距离。 / Maximum distance of the air cursor from the camera.");
		Cooldown = ((BaseUnityPlugin)this).Config.Bind<float>("悬空放置", "连续放置间隔(秒)", 0f, "常态(堆叠模式关闭)下长按连放的间隔。默认 0 = 无间隔:每帧都能放一个(实际速度只受帧率限制);堆叠模式下的节奏见“堆叠间隔”。 / Repeat interval while holding the place button in normal mode. 0 = no interval, one unit per frame (limited only by frame rate).");
		HoldDelay = ((BaseUnityPlugin)this).Config.Bind<float>("悬空放置", "长按连放起始延迟(秒)", 0.15f, "按住这么久了才开始连续放置;比这更短的点击只放一个兵种(防止手抖一次冒出好几个)。 / How long the button must be held before auto-repeat starts.");
		StackInterval = ((BaseUnityPlugin)this).Config.Bind<float>("悬空放置", "堆叠间隔(秒)", 0.16f, "堆叠模式(O 键开启)下,在已有兵种的位置长按连放的间隔(默认 0.16 秒一个)。 / Repeat interval when stacking on an occupied spot in stack mode (0.16 s default).");
		KeyStackMode = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("按键", "切换堆叠模式", (KeyCode)111, "按一下开/关堆叠模式。关着时鼠标停在已有兵种上放不进去;开着时才能在已有兵种处连放堆叠。 / Toggles stack mode; when off you cannot place onto an occupied spot, when on you can.");
		KeyToggle = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("按键", "切换悬空模式", (KeyCode)283, "按一下开/关悬空模式(不用指天空,随时可切)。 / Toggles air mode at any time (no need to aim at the sky).");
		HeightStep = ((BaseUnityPlugin)this).Config.Bind<float>("悬空放置", "升降步长(每按一次)", 0.1f, "每按一下升降键,放置面升高/降低多少世界单位(越小越好微调)。 / World units per height-key press.");
		HeightHoldDelay = ((BaseUnityPlugin)this).Config.Bind<float>("悬空放置", "升降长按起始延迟(秒)", 0.25f, "按住升降键超过这么久才开始连续升降;更短的点击只走一个步长。 / Delay before height auto-repeat starts.");
		HeightRepeat = ((BaseUnityPlugin)this).Config.Bind<float>("悬空放置", "升降长按重复间隔(秒)", 0.05f, "开始连升/连降之后,每隔这么久再走一个步长(每次仍是 0.1)。 / Repeat interval of the height step once repeating.");
		KeyHeight = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("按键", "升降放置面", (KeyCode)118, "点一下 = 升降一个步长;按住 Shift 再点 = 降低;按住超过 0.25 秒会每 0.05 秒再走一步。 / Tap = one step up, Shift+tap = one step down, hold = repeat every 0.05 s.");
		KeyLockX = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("按键", "锁定X轴", (KeyCode)120, "按一下把 X 坐标冻结在当前落点,再按一次解除。 / Freezes the X coordinate at the current spot; press again to release.");
		KeyLockZ = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("按键", "锁定Z轴", (KeyCode)122, "按一下把 Z 坐标冻结在当前落点,再按一次解除。 / Freezes the Z coordinate at the current spot; press again to release.");
		KeyLockY = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("按键", "锁定Y轴(高度)", (KeyCode)99, "按一下把高度 Y 冻结在当前落点,再按一次解除。 / Freezes the height (Y) at the current spot; press again to release.");
		KeyClearLocks = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("按键", "清除全部轴锁定", (KeyCode)0, "一次解除 X/Z/Y 三个轴的锁定;默认不绑定(None),三个锁定键各按一次即可解除。 / Releases all three axis locks at once; unbound (None) by default.");
		KeyHint = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("按键", "显示/隐藏提示栏", (KeyCode)282, "按一下显示提示栏,再按一下隐藏;默认启动时不显示,不占视野。 / Shows/hides the hint panel; hidden by default so it never blocks the view.");
		try
		{
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
		}
		catch
		{
		}
		Diag.Init(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
		Diag.Write("[启动] 版本 1.13.8");
		Diag.Write(string.Concat("[配置] 地形解锁=", TerrainUnlock.Value, " 悬空=", AirUnlock.Value, " 重叠=", AllowOverlap.Value, " 悬空保持=", FreezeFloating.Value, " 按键=", KeyToggle.Value, "/升降=", KeyHeight.Value, "/锁X=", KeyLockX.Value, "/锁Z=", KeyLockZ.Value, "/锁Y=", KeyLockY.Value));
		Diag.Write("[内置] 任意地点都能放:常开(主射线打空/只打到水面时自动补全图层广域射线,跳过水面落水底);红蓝阵营分界线保持原版");
		Diag.Write("[虚化] 虚化地图部件实体化=" + (GhostSolidOn != null && GhostSolidOn.Value));
		Diag.Write(string.Concat("[配置] 堆叠模式键=", KeyStackMode.Value, " 常态间隔=", Cooldown.Value, " 堆叠间隔=", StackInterval.Value, " 长按起始=", HoldDelay.Value));
		Lang.Refresh();
		InitBinds();
		Diag.Write("[按键] 从配置文件读到的键(重启不会回默认):堆叠=" + KeyText(KeyStackMode));
		Diag.Write("[按键] 自定义改键就绪:悬空=" + KeyText(KeyToggle) + " 堆叠=" + KeyText(KeyStackMode) + " 升降=" + KeyText(KeyHeight) + " 锁X=" + KeyText(KeyLockX) + " 锁Z=" + KeyText(KeyLockZ) + " 锁Y=" + KeyText(KeyLockY) + " 提示栏=" + KeyText(KeyHint) + " 清锁=" + KeyText(KeyClearLocks));
		AirPlacement.Refresh();
		Harmony val = new Harmony("doubao.tabs.freeplace");
		try
		{
			val.PatchAll(typeof(Plugin).Assembly);
			Diag.Write("[补丁] Harmony 全部应用成功");
			L.LogInfo((object)"[自由放置] 补丁已全部应用");
		}
		catch (Exception ex)
		{
			Diag.Write("[补丁] 失败: " + ex);
			L.LogError((object)("[自由放置] 补丁失败: " + ex));
		}
		try
		{
			MethodInfo methodInfo = GhostSolid.MakeTransparentMethod();
			if (methodInfo != null)
			{
				MethodInfo method = typeof(Patch_GhostTransparent).GetMethod("Prefix", BindingFlags.Static | BindingFlags.NonPublic);
				val.Patch((MethodBase)methodInfo, new HarmonyMethod(method), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Diag.Write("[补丁] 已拦截 PiratePlacementTransparency.MakeTransparent(虚化不再生效)");
			}
			else
			{
				Diag.Write("[补丁] 没找到 MakeTransparent,只能靠逐帧看护");
			}
		}
		catch (Exception ex2)
		{
			Diag.Write("[补丁] 拦截 MakeTransparent 失败: " + ex2.Message);
		}
	}

	private void Update()
	{
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: 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)
		try
		{
			CheckTick();
			Lang.Tick();
			ModeGate.Poll();
			UnitLabels.Tick();
			FadeTick();
			GhostSolid.Tick();
			GhostSolid.Probe();
			if (KeyToggle == null || !ModeGate.Sandbox || TypingInField || BindCaptureTick())
			{
				return;
			}
			if ((Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305)) && Input.GetKeyDown((KeyCode)98))
			{
				AxisLock.Clear();
				AirPlacement.DoResetHeight();
				Diag.Write("[重置] Ctrl+B:X/Y/Z 轴锁定与高度已全部归零");
			}
			if (KeyStackMode != null && (int)KeyStackMode.Value != 0 && Input.GetKeyDown(KeyStackMode.Value))
			{
				StackMode = !StackMode;
				Diag.Write("[模式] 堆叠模式=" + (StackMode ? "开" : "关"));
			}
			if (KeyHint != null && (int)KeyHint.Value != 0 && Input.GetKeyDown(KeyHint.Value))
			{
				HintVisible = !HintVisible;
				Diag.Write("[界面] 提示栏=" + (HintVisible ? "显示" : "隐藏"));
			}
			if (AirUnlock == null || AirUnlock.Value)
			{
				if (Input.GetKeyDown(KeyToggle.Value))
				{
					AirMode = !AirMode;
					AirPlacement.ResetHeight();
					Diag.Write("[模式] 悬空模式=" + (AirMode ? "开" : "关"));
				}
				AirPlacement.KeysTick();
			}
		}
		catch
		{
		}
	}

	private void CheckTick()
	{
		if (_checkDone)
		{
			return;
		}
		float unscaledTime = Time.unscaledTime;
		if (!(unscaledTime < _nextCheck))
		{
			_nextCheck = unscaledTime + 3f;
			_checkTimes++;
			int num = 0;
			num += ReportPatch(typeof(PlacementCursor), "get_MaxPlacementAngleEuler");
			num += ReportPatch(typeof(PlacementCursor), "get_InvalidUnitPlacementMask");
			num += ReportPatch(typeof(BrushBehaviourBase), "CanPlace");
			num += ReportPatch(typeof(UnitPlacementBrush), "Update");
			num += ReportPatch(typeof(BrushBehaviourBase), "Place");
			num += ReportPatch(typeof(Unit), "UnfreezeBody");
			num += ReportPatch(typeof(BrushBehaviourBase), "PrimaryActionOnObject");
			num += ReportPatch(typeof(PlacementCursor), "get_PrimaryActionMask");
			num += ReportPatch(typeof(SandboxPlacementCamera), "Start");
			num += ReportPatch(typeof(SandboxPlacementCamera), "ExitFreeLook");
			num += ReportPatchMI(GhostSolid.MakeTransparentMethod(), "PiratePlacementTransparency.MakeTransparent");
			if (num >= 11 || _checkTimes >= 6)
			{
				_checkDone = true;
				Diag.Write("[补丁自检] 已挂载 " + num + "/11,结束自检");
			}
		}
	}

	private int ReportPatchMI(MethodInfo mi, string label)
	{
		try
		{
			if (mi == null)
			{
				Diag.Write("[补丁自检] 找不到方法 " + label);
				return 0;
			}
			Patches patchInfo = Harmony.GetPatchInfo((MethodBase)mi);
			if (patchInfo == null)
			{
				Diag.Write("[补丁自检] " + label + " 无任何补丁");
				return 0;
			}
			int num = 0;
			foreach (Patch prefix in patchInfo.Prefixes)
			{
				if (prefix.owner == "doubao.tabs.freeplace")
				{
					num++;
				}
			}
			foreach (Patch postfix in patchInfo.Postfixes)
			{
				if (postfix.owner == "doubao.tabs.freeplace")
				{
					num++;
				}
			}
			Diag.Write("[补丁自检] " + label + " 本模组补丁数=" + num);
			return (num > 0) ? 1 : 0;
		}
		catch (Exception ex)
		{
			Diag.Write("[补丁自检] " + label + " 检查失败: " + ex.Message);
			return 0;
		}
	}

	private int ReportPatch(Type t, string method)
	{
		try
		{
			MethodInfo method2 = t.GetMethod(method, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			if (method2 == null)
			{
				Diag.Write("[补丁自检] 找不到方法 " + t.Name + "." + method);
				return 0;
			}
			Patches patchInfo = Harmony.GetPatchInfo((MethodBase)method2);
			if (patchInfo == null)
			{
				Diag.Write("[补丁自检] " + t.Name + "." + method + " 无任何补丁");
				return 0;
			}
			int num = 0;
			foreach (Patch prefix in patchInfo.Prefixes)
			{
				if (prefix.owner == "doubao.tabs.freeplace")
				{
					num++;
				}
			}
			foreach (Patch postfix in patchInfo.Postfixes)
			{
				if (postfix.owner == "doubao.tabs.freeplace")
				{
					num++;
				}
			}
			Diag.Write("[补丁自检] " + t.Name + "." + method + " 本模组补丁数=" + num + "(其它模组 prefix=" + patchInfo.Prefixes.Count + " postfix=" + patchInfo.Postfixes.Count + ")");
			return (num > 0) ? 1 : 0;
		}
		catch (Exception ex)
		{
			Diag.Write("[补丁自检] " + t.Name + "." + method + " 检查失败: " + ex.Message);
			return 0;
		}
	}

	private void OnGUI()
	{
		//IL_085b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Expected O, but got Unknown
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_08cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f4: 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_021f: Unknown result type (might be due to invalid IL or missing references)
		//IL_023f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Unknown result type (might be due to invalid IL or missing references)
		//IL_05fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_02da: Unknown result type (might be due to invalid IL or missing references)
		//IL_0640: Unknown result type (might be due to invalid IL or missing references)
		//IL_0304: Unknown result type (might be due to invalid IL or missing references)
		//IL_070e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0780: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0468: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0525: Unknown result type (might be due to invalid IL or missing references)
		//IL_050f: Unknown result type (might be due to invalid IL or missing references)
		//IL_052f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0559: Unknown result type (might be due to invalid IL or missing references)
		//IL_058d: Unknown result type (might be due to invalid IL or missing references)
		UnitLabels.Draw();
		AirGuide.Draw();
		TypingInField = false;
		MouseOverPanel = false;
		if (ShowHint == null || !ShowHint.Value || PanelAlpha <= 0.001f)
		{
			return;
		}
		bool flag = HintVisible && ModeGate.Sandbox && AirPlacement.PlacementActive;
		try
		{
			_langTimer -= Time.unscaledDeltaTime;
			if (_langTimer <= 0f)
			{
				_langTimer = 0.5f;
				_zh = Lang.Chinese;
			}
			if (_style == null)
			{
				BuildStyle();
			}
			if (_style == null)
			{
				return;
			}
			if ((Object)(object)_bg == (Object)null)
			{
				_bg = new Texture2D(1, 1);
				_bg.SetPixel(0, 0, Color.white);
				_bg.Apply();
			}
			string text = BuildHintText();
			float num = (_zh ? 400f : 440f);
			float num2 = 202f;
			float num3 = num2 + 226f;
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(10f, (float)Screen.height * 0.34f, num, num3);
			bool flag2 = flag;
			float num4 = (_zh ? 316f : 336f);
			Rect br = default(Rect);
			((Rect)(ref br))..ctor(((Rect)(ref val)).x + num + BindSlide * (num4 + 12f) - num4, ((Rect)(ref val)).y, num4, 336f);
			if (BindSlide > 0.001f)
			{
				if (_tfStyle == null)
				{
					BuildFieldStyle();
				}
				if (Event.current != null && flag && ((Rect)(ref br)).Contains(Event.current.mousePosition))
				{
					MouseOverPanel = true;
				}
				DrawBindPanel(br, BindSlide * PanelAlpha, flag2);
			}
			if (Event.current != null && flag && ((Rect)(ref val)).Contains(Event.current.mousePosition))
			{
				MouseOverPanel = true;
			}
			GUI.color = new Color(0f, 0f, 0f, 0.55f * PanelAlpha);
			GUI.DrawTexture(val, (Texture)(object)_bg);
			GUI.color = new Color(1f, 1f, 1f, PanelAlpha);
			GUI.Label(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y, ((Rect)(ref val)).width, num2), text, _style);
			if (_tfStyle == null)
			{
				BuildFieldStyle();
			}
			if (_tfStyle != null && _plainStyle != null)
			{
				bool airMode = AirMode;
				bool enabled = GUI.enabled;
				GUI.enabled = enabled && flag2;
				bool reset = false;
				Rect row = default(Rect);
				((Rect)(ref row))..ctor(((Rect)(ref val)).x + 14f, ((Rect)(ref val)).y + num2 + 6f, num - 28f, 24f);
				GUI.Label(new Rect(((Rect)(ref row)).x, ((Rect)(ref row)).y, 62f, 24f), _zh ? "X 轴:" : "X:", _plainStyle);
				if (AxisField("tabsXField", row, ref _axisText[0], LockedOrLive(0), _zh ? "设定" : "SET", _zh ? "重置" : "RESET", out reset))
				{
					ApplyAxisInput(0);
				}
				if (reset)
				{
					ResetAxisOnly(0);
				}
				Rect row2 = default(Rect);
				((Rect)(ref row2))..ctor(((Rect)(ref val)).x + 14f, ((Rect)(ref val)).y + num2 + 36f, num - 28f, 24f);
				GUI.Label(new Rect(((Rect)(ref row2)).x, ((Rect)(ref row2)).y, 62f, 24f), _zh ? "Z 轴:" : "Z:", _plainStyle);
				if (AxisField("tabsZField", row2, ref _axisText[2], LockedOrLive(2), _zh ? "设定" : "SET", _zh ? "重置" : "RESET", out reset))
				{
					ApplyAxisInput(2);
				}
				if (reset)
				{
					ResetAxisOnly(2);
				}
				Rect row3 = default(Rect);
				((Rect)(ref row3))..ctor(((Rect)(ref val)).x + 14f, ((Rect)(ref val)).y + num2 + 66f, num - 28f, 24f);
				GUI.Label(new Rect(((Rect)(ref row3)).x, ((Rect)(ref row3)).y, 62f, 24f), _zh ? "Y 轴:" : "Y:", _plainStyle);
				GUI.enabled = airMode && flag2;
				if (AxisField("tabsHeightField", row3, ref _heightText, LockedOrLive(1), _zh ? "设定" : "SET", _zh ? "重置" : "RESET", out reset))
				{
					ApplyYInput();
				}
				if (reset)
				{
					ResetHeightOnly();
				}
				GUI.enabled = enabled && flag2;
				GUI.color = WithAlpha(airMode ? new Color(0.7f, 0.9f, 0.7f) : new Color(1f, 0.75f, 0.4f), PanelAlpha);
				GUI.Label(new Rect(((Rect)(ref row3)).x, ((Rect)(ref row3)).y + 30f, num - 18f, 24f), _zh ? "注释:数字实时跟随鼠标,输入后锁定该轴" : "NOTE: coords follow cursor; SET locks the axis", (_noteStyle != null) ? _noteStyle : _plainStyle);
				GUI.color = Color.white;
			}
			if (_noteStyle != null)
			{
				bool enabled2 = GUI.enabled;
				GUI.enabled = enabled2 && flag2;
				Rect val2 = default(Rect);
				((Rect)(ref val2))..ctor(((Rect)(ref val)).x + 14f, ((Rect)(ref val)).y + num2 + 126f, num - 28f, 24f);
				GUI.Label(new Rect(((Rect)(ref val2)).x, ((Rect)(ref val2)).y, 112f, 24f), _zh ? "按键设置:" : "KEYS:", _noteStyle);
				if (GUI.Button(new Rect(((Rect)(ref val2)).x + 114f, ((Rect)(ref val2)).y, 96f, 24f), (!BindPanelOpen) ? (_zh ? "打开面板" : "OPEN") : (_zh ? "关闭面板" : "CLOSE")))
				{
					BindPanelOpen = !BindPanelOpen;
				}
				GUI.enabled = enabled2;
			}
			if (_noteStyle != null)
			{
				bool enabled3 = GUI.enabled;
				GUI.enabled = enabled3 && flag2;
				bool flag3 = GhostSolidOn != null && GhostSolidOn.Value;
				Rect val3 = default(Rect);
				((Rect)(ref val3))..ctor(((Rect)(ref val)).x + 14f, ((Rect)(ref val)).y + num2 + 156f, num - 28f, 24f);
				GUI.Label(new Rect(((Rect)(ref val3)).x, ((Rect)(ref val3)).y, 112f, 24f), _zh ? "虚化地图:" : "GHOSTMAP:", _noteStyle);
				string text2 = ((!flag3) ? (_zh ? "原版虚化(点此变实体)" : "VANILLA (click for solid)") : (_zh ? "常驻实体化(点此交还原版)" : "SOLID (click for vanilla)"));
				if (GUI.Button(new Rect(((Rect)(ref val3)).x + 114f, ((Rect)(ref val3)).y, 214f, 24f), text2))
				{
					if (GhostSolidOn != null)
					{
						GhostSolidOn.Value = !flag3;
					}
					try
					{
						((BaseUnityPlugin)this).Config.Save();
					}
					catch
					{
					}
					GhostSolid.ToggleNow(!flag3);
					Diag.Write("[虚化] 按钮切换:虚化地图部件实体化=" + !flag3);
				}
				GUI.enabled = enabled3;
			}
			if (_noteStyle == null)
			{
				return;
			}
			bool enabled4 = GUI.enabled;
			GUI.enabled = enabled4 && flag2;
			bool flag4 = ShowUnitLabels != null && ShowUnitLabels.Value;
			Rect val4 = default(Rect);
			((Rect)(ref val4))..ctor(((Rect)(ref val)).x + 14f, ((Rect)(ref val)).y + num2 + 186f, num - 28f, 24f);
			GUI.Label(new Rect(((Rect)(ref val4)).x, ((Rect)(ref val4)).y, 112f, 24f), _zh ? "位置标注:" : "TAGS:", _noteStyle);
			string text3 = ((!flag4) ? (_zh ? "关闭(点此标注)" : "OFF (click to tag)") : (_zh ? "显示名称坐标(点此关闭)" : "ON (click to hide)"));
			if (GUI.Button(new Rect(((Rect)(ref val4)).x + 114f, ((Rect)(ref val4)).y, 214f, 24f), text3))
			{
				if (ShowUnitLabels != null)
				{
					ShowUnitLabels.Value = !flag4;
				}
				try
				{
					((BaseUnityPlugin)this).Config.Save();
				}
				catch
				{
				}
				Diag.Write("[标注] 按钮切换:标注兵种位置=" + !flag4);
			}
			GUI.enabled = enabled4;
		}
		catch
		{
		}
	}

	private bool AxisField(string name, Rect row, ref string text, string display, string setLabel, string resetLabel, out bool reset)
	{
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Invalid comparison between Unknown and I4
		//IL_0135: 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_00b8: Invalid comparison between Unknown and I4
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Invalid comparison between Unknown and I4
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Invalid comparison between Unknown and I4
		bool flag = GUI.GetNameOfFocusedControl() == name;
		if (!flag)
		{
			text = display;
		}
		Event current = Event.current;
		if (current != null && flag && (int)current.type == 4 && current.character != 0)
		{
			char character = current.character;
			if (character > ' ' && character != '\u007f' && !IsNumberChar(character))
			{
				current.Use();
			}
		}
		GUI.SetNextControlName(name);
		string s = GUI.TextField(new Rect(((Rect)(ref row)).x + 64f, ((Rect)(ref row)).y, 100f, 24f), text, 10, _tfStyle);
		text = SanitizeNumber(s);
		bool result = false;
		if (GUI.GetNameOfFocusedControl() == name)
		{
			TypingInField = true;
			if (Event.current != null && (int)Event.current.type == 4 && ((int)Event.current.keyCode == 13 || (int)Event.current.keyCode == 271))
			{
				result = true;
				Event.current.Use();
			}
		}
		if (GUI.Button(new Rect(((Rect)(ref row)).x + 168f, ((Rect)(ref row)).y, 64f, 24f), setLabel))
		{
			result = true;
		}
		reset = GUI.Button(new Rect(((Rect)(ref row)).x + 236f, ((Rect)(ref row)).y, 68f, 24f), resetLabel);
		KeepImeOff(GUI.GetNameOfFocusedControl() == name);
		return result;
	}

	private static string LockedOrLive(int i)
	{
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		if (AxisLock.OnX && i == 0)
		{
			return AxisLock.GetAxis(0).ToString("F1", CultureInfo.InvariantCulture);
		}
		if (AxisLock.OnY && i == 1)
		{
			return AxisLock.GetAxis(1).ToString("F1", CultureInfo.InvariantCulture);
		}
		if (AxisLock.OnZ && i == 2)
		{
			return AxisLock.GetAxis(2).ToString("F1", CultureInfo.InvariantCulture);
		}
		try
		{
			if (AirPlacement.HasCursorPoint)
			{
				Vector3 cursorPoint = AirPlacement.CursorPoint;
				return (i switch
				{
					1 => cursorPoint.y, 
					0 => cursorPoint.x, 
					_ => cursorPoint.z, 
				}).ToString("F1", CultureInfo.InvariantCulture);
			}
		}
		catch
		{
		}
		return "--";
	}

	private static string AxisName(int i)
	{
		return i switch
		{
			1 => "Y", 
			0 => "X", 
			_ => "Z", 
		};
	}

	private static bool IsNumberChar(char c)
	{
		if ((c < '0' || c > '9') && c != '.' && c != '-')
		{
			return c == '+';
		}
		return true;
	}

	private static void KeepImeOff(bool focused)
	{
		try
		{
			if (focused)
			{
				if (!_imeOff)
				{
					Input.imeCompositionMode = (IMECompositionMode)2;
					_imeOff = true;
				}
			}
			else if (_imeOff)
			{
				Input.imeCompositionMode = (IMECompositionMode)0;
				_imeOff = false;
			}
		}
		catch
		{
		}
	}

	private static string SanitizeNumber(string s)
	{
		if (string.IsNullOrEmpty(s))
		{
			return "";
		}
		StringBuilder stringBuilder = new StringBuilder();
		bool flag = false;
		bool flag2 = false;
		for (int i = 0; i < s.Length; i++)
		{
			if (stringBuilder.Length >= 12)
			{
				break;
			}
			char c = s[i];
			if (c >= '0' && c <= '9')
			{
				stringBuilder.Append(c);
			}
			else if (c == '-' && stringBuilder.Length == 0 && !flag2)
			{
				stringBuilder.Append(c);
				flag2 = true;
			}
			else if (c == '.' && !flag)
			{
				stringBuilder.Append(c);
				flag = true;
			}
		}
		return stringBuilder.ToString();
	}

	private void ApplyYInput()
	{
		if (!AirMode)
		{
			Diag.Write("[输入] 未开启悬空模式,Y 轴不可调(先按 F2 开启悬空模式)");
			return;
		}
		string text = (_heightText ?? "").Trim();
		if (!float.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
		{
			Diag.Write("[输入] Y 轴数值无效: \"" + text + "\"");
			return;
		}
		AxisLock.SetAxis(1, result);
		Diag.Write("[输入] Y 轴(高度)已锁定为 " + result.ToString("F2"));
	}

	private static void ResetHeightOnly()
	{
		AxisLock.OnY = false;
		AirPlacement.DoResetHeight();
		Diag.Write("[重置] 提示栏按钮:高度已归零(Y 轴锁定解除,升降偏移归 0)");
	}

	private static void ResetAxisOnly(int i)
	{
		AxisLock.ResetAxis(i);
		Diag.Write("[重置] 提示栏按钮:已解除 " + AxisName(i) + " 轴锁定");
	}

	private static void ResetAll()
	{
		AxisLock.Clear();
		AirPlacement.DoResetHeight();
		Diag.Write("[重置] X/Y/Z 轴锁定与高度已全部归零");
	}

	private void ApplyAxisInput(int i)
	{
		string text = (_axisText[i] ?? "").Trim();
		if (!float.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out var result))
		{
			Diag.Write("[输入] " + AxisName(i) + " 数值无效: \"" + text + "\"");
		}
		else
		{
			AxisLock.SetAxis(i, result);
			Diag.Write("[输入] 锁定 " + AxisName(i) + " = " + result.ToString("F2"));
		}
	}

	private void BuildFieldStyle()
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Expected O, but got Unknown
		//IL_005e: 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_007d: Expected O, but got Unknown
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Expected O, but got Unknown
		try
		{
			_plainStyle = new GUIStyle(GUI.skin.label);
			_plainStyle.font = _style.font;
			_plainStyle.fontSize = 14;
			_plainStyle.alignment = (TextAnchor)3;
			_plainStyle.normal.textColor = new Color(1f, 0.93f, 0.5f);
			_tfStyle = new GUIStyle(GUI.skin.textField);
			_tfStyle.font = _style.font;
			_tfStyle.fontSize = 14;
			_tfStyle.alignment = (TextAnchor)3;
			_noteStyle = new GUIStyle(_plainStyle);
			_noteStyle.font = _style.font;
			_noteStyle.fontSize = 13;
			_noteStyle.alignment = (TextAnchor)3;
			_noteStyle.wordWrap = false;
		}
		catch
		{
			_tfStyle = null;
			_noteStyle = null;
		}
	}

	private static string KeyText(ConfigEntry<KeyCode> e)
	{
		//IL_0004: 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)
		if (e == null || (int)e.Value == 0)
		{
			if (!Lang.Chinese)
			{
				return "None";
			}
			return "无";
		}
		return ((object)e.Value).ToString();
	}

	private string BuildHintText()
	{
		string[] array = new string[8];
		bool zh = _zh;
		string text = (zh ? "开" : "ON");
		string text2 = (zh ? "关" : "OFF");
		array[0] = (zh ? ("悬空: " + (AirMode ? text : text2) + " (" + KeyText(KeyToggle) + ")    堆叠: " + (StackMode ? text : text2) + " (" + KeyText(KeyStackMode) + ")") : ("AIR: " + (AirMode ? text : text2) + " (" + KeyText(KeyToggle) + ")    STACK: " + (StackMode ? text : text2) + " (" + KeyText(KeyStackMode) + ")"));
		array[1] = (zh ? "高度: " : "HEIGHT: ") + (AirMode ? AirPlacement.HeightOffsetText() : "-");
		array[2] = (zh ? ("升降: " + KeyText(KeyHeight) + " 升 / Shift + " + KeyText(KeyHeight) + " 降") : ("ADJUST: " + KeyText(KeyHeight) + " up / Shift+" + KeyText(KeyHeight) + " down"));
		array[3] = (zh ? "锁定: " : "LOCK: ") + (AxisLock.Any() ? AxisLock.Describe() : (zh ? "无" : "none"));
		array[4] = (zh ? ("锁轴键: " + KeyText(KeyLockX) + " X / " + KeyText(KeyLockZ) + " Z / " + KeyText(KeyLockY) + " 高度(可同时锁)") : ("LOCK KEYS: " + KeyText(KeyLockX) + " X / " + KeyText(KeyLockZ) + " Z / " + KeyText(KeyLockY) + " Y (combinable)"));
		float num = ((Cooldown == null) ? 0f : Cooldown.Value);
		float num2 = ((StackInterval == null) ? 0.16f : StackInterval.Value);
		string text3 = ((!(num <= 0f)) ? (num.ToString("F2") + (zh ? " 秒" : "s")) : (zh ? "无间隔(每帧一个)" : "no interval (per frame)"));
		array[5] = (zh ? "放置: " : "PLACE: ") + text3 + (zh ? " / 堆叠 " : " / STACK ") + num2.ToString("F2") + (zh ? " 秒" : "s");
		array[6] = (zh ? "提示栏: " : "HINT: ") + KeyText(KeyHint) + (zh ? " 显示/隐藏" : " show/hide");
		array[7] = (zh ? "重置: Ctrl+B 清空 X/Y/Z + 高度" : "RESET: Ctrl+B clears X/Y/Z + height");
		return string.Join("\n", array);
	}

	private static string HeightText()
	{
		return AirPlacement.HeightOffsetText();
	}

	private void BuildStyle()
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Expected O, but got Unknown
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			_fontTry();
			if (!((Object)(object)_font == (Object)null))
			{
				_style = new GUIStyle(GUI.skin.label);
				_style.font = _font;
				_style.fontSize = 14;
				_style.alignment = (TextAnchor)3;
				_style.wordWrap = false;
				_style.padding = new RectOffset(14, 8, 0, 0);
				_style.normal.textColor = new Color(1f, 0.93f, 0.5f);
			}
		}
		catch
		{
			_style = null;
		}
	}

	private void _fontTry()
	{
		if ((Object)(object)_font != (Object)null)
		{
			return;
		}
		try
		{
			_font = Font.CreateDynamicFontFromOSFont(new string[5] { "Microsoft YaHei", "微软雅黑", "SimHei", "SimSun", "Arial" }, 16);
		}
		catch
		{
		}
		if (!((Object)(object)_font == (Object)null))
		{
			return;
		}
		try
		{
			_font = Resources.GetBuiltinResource<Font>("Arial.ttf");
		}
		catch
		{
		}
	}

	public static bool IsChinese()
	{
		return Lang.Chinese;
	}
}
internal static class Lang
{
	public static bool Chinese = true;

	public static string Source = "默认";

	private static bool _resolved;

	private static FieldInfo _fLocale;

	private static float _next;

	private static bool _logged;

	public static void Tick()
	{
		try
		{
			if (!(Time.unscaledTime < _next))
			{
				_next = Time.unscaledTime + 0.5f;
				Refresh();
			}
		}
		catch
		{
		}
	}

	public static void Refresh()
	{
		int code = -1;
		bool flag;
		string text;
		if (TryGameLocale(out code))
		{
			flag = code == 7;
			text = "Localizer.m_locale=" + code;
		}
		else
		{
			string text2 = "";
			try
			{
				if (CultureInfo.CurrentUICulture != null)
				{
					text2 = CultureInfo.CurrentUICulture.Name;
				}
			}
			catch
			{
			}
			if (!string.IsNullOrEmpty(text2))
			{
				flag = text2.ToLowerInvariant().StartsWith("zh");
				text = "CultureInfo=" + text2;
			}
			else
			{
				flag = IsChineseSystemLanguage();
				text = "Application.systemLanguage";
			}
		}
		if (!_logged || flag != Chinese)
		{
			_logged = true;
			Diag.Write("[语言] 界面=" + (flag ? "中文" : "English") + " 中文=" + flag + " 来源=" + text);
		}
		Chinese = flag;
		Source = text;
	}

	private static bool TryGameLocale(out int code)
	{
		code = -1;
		try
		{
			if (!_resolved)
			{
				_resolved = true;
				Type[] array = null;
				try
				{
					array = typeof(SceneSettings).Assembly.GetTypes();
				}
				catch (ReflectionTypeLoadException ex)
				{
					array = ex.Types;
				}
				if (array != null)
				{
					foreach (Type type in array)
					{
						if (!(type == null) && !(type.Name != "Localizer"))
						{
							FieldInfo field = type.GetField("m_locale", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
							if (!(field == null))
							{
								_fLocale = field;
								break;
							}
						}
					}
				}
			}
			if (_fLocale == null)
			{
				return false;
			}
			object value = _fLocale.GetValue(null);
			if (value == null)
			{
				return false;
			}
			code = Convert.ToInt32(value);
			return true;
		}
		catch
		{
			return false;
		}
	}

	private static bool IsChineseSystemLanguage()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Invalid comparison between Unknown and I4
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Invalid comparison between Unknown and I4
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Invalid comparison between Unknown and I4
		try
		{
			SystemLanguage systemLanguage = Application.systemLanguage;
			return (int)systemLanguage == 6 || (int)systemLanguage == 40 || (int)systemLanguage == 41;
		}
		catch
		{
			return true;
		}
	}
}
internal static class GhostSolid
{
	internal static int ExtraMask = 0;

	internal static int Parts = 0;

	internal static int CollidersOn = 0;

	private static Type _type;

	private static FieldInfo _field;

	private static FieldInfo _fieldMaterials;

	private static FieldInfo _fElemMat;

	private static FieldInfo _fElemIdx;

	private static FieldInfo _fElemOld;

	private static MethodInfo _makeVisible;

	private static MethodInfo _makeTransparent;

	private static int _lastParts = -1;

	private static float _probeNext;

	private static int _probeCount = -1;

	private static readonly Dictionary<Object, Material[]> _snapMats = new Dictionary<Object, Material[]>();

	private static readonly Dictionary<Object, bool[]> _snapCols = new Dictionary<Object, bool[]>();

	private static Object[] _objs;

	private static float _nextScan;

	private static int _lastMask = -1;

	private static float _lastLog = -100f;

	private static bool _wasOn;

	private static bool _warned;

	private static bool EnsureType()
	{
		if (_type != null && _field != null)
		{
			return true;
		}
		try
		{
			Type[] types = typeof(SceneSettings).Assembly.GetTypes();
			for (int i = 0; i < types.Length; i++)
			{
				if (!(types[i].Name != "PiratePlacementTransparency"))
				{
					_type = types[i];
					_field = _type.GetField("colliders", BindingFlags.Instance | BindingFlags.Public);
					_fieldMaterials = _type.GetField("Materials", BindingFlags.Instance | BindingFlags.Public);
					Type type = ((_fieldMaterials != null && _fieldMaterials.FieldType.IsArray) ? _fieldMaterials.FieldType.GetElementType() : null);
					if (type != null)
					{
						_fElemMat = type.GetField("m_Material", BindingFlags.Instance | BindingFlags.Public);
						_fElemIdx = type.GetField("m_MaterialIndex", BindingFlags.Instance | BindingFlags.Public);
						_fElemOld = type.GetField("m_oldMaterial", BindingFlags.Instance | BindingFlags.Public);
					}
					_makeVisible = _type.GetMethod("MakeVisable", BindingFlags.Instance | BindingFlags.Public);
					_makeTransparent = _type.GetMethod("MakeTransparent", BindingFlags.Instance | BindingFlags.Public);
					Diag.Write("[虚化] 找到原版虚化组件 " + _type.FullName + " colliders字段=" + (_field != null) + " MakeVisable=" + (_makeVisible != null) + " MakeTransparent=" + (_makeTransparent != null));
					break;
				}
			}
			if (_type == null)
			{
				Diag.Write("[虚化] 这个版本里没有 PiratePlacementTransparency 组件");
			}
		}
		catch (Exception ex)
		{
			Diag.Write("[虚化] 类型探测失败: " + ex.Message);
		}
		if (_type != null)
		{
			return _field != null;
		}
		return false;
	}

	internal static MethodInfo MakeTransparentMethod()
	{
		try
		{
			EnsureType();
		}
		catch
		{
		}
		return _makeTransparent;
	}

	private static bool On()
	{
		if (Plugin.GhostSolidOn != null)
		{
			return Plugin.GhostSolidOn.Value;
		}
		return false;
	}

	internal static bool BeforeTransparent()
	{
		try
		{
			if (!On())
			{
				return false;
			}
			if (!EnsureType())
			{
				return false;
			}
			Apply(forceVisual: true);
			return true;
		}
		catch (Exception ex)
		{
			Diag.Write("[虚化] 拦截虚化失败: " + ex.Message);
			return false;
		}
	}

	internal static void SolidifyNow(bool forceVisual)
	{
		try
		{
			if (On() && EnsureType())
			{
				Apply(forceVisual);
			}
		}
		catch (Exception ex)
		{
			Diag.Write("[虚化] 立即实体化失败: " + ex.Message);
		}
	}

	private static void Apply(bool forceVisual)
	{
		int num = 0;
		int num2 = 0;
		int num3 = 0;
		Object[] array = null;
		try
		{
			array = Object.FindObjectsOfType(_type);
		}
		catch
		{
		}
		if (array != null)
		{
			foreach (Object val in array)
			{
				if (val == (Object)null)
				{
					continue;
				}
				num2++;
				Collider[] array2 = null;
				try
				{
					array2 = _field.GetValue(val) as Collider[];
				}
				catch
				{
				}
				Snapshot(val, array2);
				bool flag = false;
				if (array2 != null)
				{
					foreach (Collider val2 in array2)
					{
						if (!((Object)(object)val2 == (Object)null))
						{
							if (!val2.enabled)
							{
								flag = true;
							}
							num |= 1 << ((Component)val2).gameObject.layer;
						}
					}
				}
				if (_makeVisible != null && (forceVisual || flag))
				{
					try
					{
						_makeVisible.Invoke(val, null);
					}
					catch (Exception ex)
					{
						Diag.Write("[虚化] MakeVisable 调用失败: " + ex.Message);
					}
				}
				if (array2 == null)
				{
					continue;
				}
				foreach (Collider val3 in array2)
				{
					if ((Object)(object)val3 != (Object)null && !val3.enabled)
					{
						val3.enabled = true;
						num3++;
					}
				}
			}
		}
		_objs = array;
		_nextScan = Time.unscaledTime + 0.5f;
		ExtraMask = num;
		Parts = num2;
		CollidersOn = num3;
	}

	internal static void ToggleNow(bool solid)
	{
		try
		{
			if (!EnsureType())
			{
				return;
			}
			if (_objs == null)
			{
				Scan();
			}
			if (_objs == null)
			{
				return;
			}
			if (solid)
			{
				_wasOn = true;
				Apply(forceVisual: true);
				Diag.Write("[虚化] 按钮:已立刻变回实体(部件=" + Parts + ")");
				return;
			}
			int num = 0;
			for (int i = 0; i < _objs.Length; i++)
			{
				Object val = _objs[i];
				if (!(val == (Object)null))
				{
					MakeTransparentDirect(val);
					num++;
				}
			}
			ExtraMask = 0;
			CollidersOn = 0;
			Parts = _objs.Length;
			_wasOn = false;
			_objs = null;
			DumpParts("off");
			Diag.Write("[虚化] 按钮:已立刻交还原版虚化(部件=" + num + ")");
		}
		catch (Exception ex)
		{
			Diag.Write("[虚化] 按钮切换失败: " + ex.Message);
		}
	}

	private static void Snapshot(Object o, Collider[] cs)
	{
		try
		{
			if (_snapMats.ContainsKey(o))
			{
				return;
			}
			Component val = (Component)(object)((o is Component) ? o : null);
			Renderer val2 = (Renderer)(((Object)(object)val == (Object)null) ? null : /*isinst with value type is only supported in some contexts*/);
			Material[] array = (((Object)(object)val2 == (Object)null) ? null : val2.sharedMaterials);
			_snapMats[o] = ((array == null) ? null : ((Material[])array.Clone()));
			bool[] array2 = null;
			if (cs != null)
			{
				array2 = new bool[cs.Length];
				for (int i = 0; i < cs.Length; i++)
				{
					array2[i] = (Object)(object)cs[i] != (Object)null && cs[i].enabled;
				}
			}
			_snapCols[o] = array2;
		}
		catch
		{
		}
	}

	internal static void Probe()
	{
		try
		{
			if (!EnsureType())
			{
				return;
			}
			float unscaledTime = Time.unscaledTime;
			if (unscaledTime - _probeNext < 1.5f)
			{
				return;
			}
			_probeNext = unscaledTime;
			Object[] array = null;
			try
			{
				array = Object.FindObjectsOfType(_type);
			}
			catch
			{
				array = null;
			}
			if (array == null)
			{
				return;
			}
			_objs = array;
			if (array.Length != _probeCount)
			{
				_probeCount = array.Length;
				DumpParts("probe");
			}
			foreach (Object val in array)
			{
				if (!(val == (Object)null))
				{
					Collider[] cs = null;
					try
					{
						cs = ((_field == null) ? null : (_field.GetValue(val) as Collider[]));
					}
					catch
					{
					}
					Snapshot(val, cs);
				}
			}
		}
		catch (Exception ex)
		{
			Diag.Write("[虚化] 探针失败: " + ex.Message);
		}
	}

	private static void Scan()
	{
		try
		{
			_objs = Object.FindObjectsOfType(_type);
		}
		catch
		{
			_objs = null;
		}
		_nextScan = Time.unscaledTime + 0.5f;
	}

	private static string PathName(Component c)
	{
		try
		{
			Transform val = c.transform;
			string text = ((Object)val).name;
			while ((Object)(object)val.parent != (Object)null)
			{
				val = val.parent;
				text = ((Object)val).name + "/" + text;
			}
			return text;
		}
		catch
		{
			return ((Object)(object)c == (Object)null) ? "?" : ((Object)c).name;
		}
	}

	private static void DumpParts(string tag)
	{
		try
		{
			if (_objs == null)
			{
				return;
			}
			for (int i = 0; i < _objs.Length; i++)
			{
				Object val = _objs[i];
				if (val == (Object)null)
				{
					continue;
				}
				Component val2 = (Component)(object)((val is Component) ? val : null);
				Renderer val3 = (Renderer)(((Object)(object)val2 == (Object)null) ? null : /*isinst with value type is only supported in some contexts*/);
				string text = "";
				if ((Object)(object)val3 != (Object)null)
				{
					Material[] sharedMaterials = val3.sharedMaterials;
					if (sharedMaterials != null)
					{
						Material[] array = sharedMaterials;
						foreach (Material val4 in array)
						{
							text = text + (((Object)(object)val4 == (Object)null) ? "<null>" : ((Object)val4).name) + ",";
						}
					}
				}
				int num = 0;
				int num2 = 0;
				Collider[] array2 = null;
				try
				{
					array2 = ((_field == null) ? null : (_field.GetValue(val) as Collider[]));
				}
				catch
				{
				}
				if (array2 != null)
				{
					num = array2.Length;
					Collider[] array3 = array2;
					foreach (Collider val5 in array3)
					{
						if ((Object)(object)val5 != (Object)null && val5.enabled)
						{
							num2++;
						}
					}
				}
				string text2 = "";
				try
				{
					Array array4 = ((_fieldMaterials == null) ? null : (_fieldMaterials.GetValue(val) as Array));
					if (array4 != null)
					{
						for (int l = 0; l < array4.Length; l++)
						{
							object value = array4.GetValue(l);
							Material val6 = (Material)((_fElemMat == null) ? null : /*isinst with value type is only supported in some contexts*/);
							Material val7 = (Material)((_fElemOld == null) ? null : /*isinst with value type is only supported in some contexts*/);
							int num3 = ((_fElemIdx == null) ? l : Convert.ToInt32(_fElemIdx.GetValue(value)));
							object obj2 = text2;
							text2 = string.Concat(obj2, "[", l, "] mat=", ((Object)(object)val6 == (Object)null) ? "<null>" : ((Object)val6).name, " old=", ((Object)(object)val7 == (Object)null) ? "<null>" : ((Object)val7).name, " idx=", num3, "  ");
						}
					}
				}
				catch
				{
				}
				Diag.Write("[虚化][" + tag + "] 部件[" + i + "] " + (((Object)(object)val2 == (Object)null) ? ((object)val).ToString() : PathName(val2)) + " 图层=" + (((Object)(object)val2 == (Object)null) ? "?" : LayerMask.LayerToName(val2.gameObject.layer)) + " 碰撞体=" + num + " 开启=" + num2 + " 材质=" + text + " 字段=" + text2);
			}
		}
		catch (Exception ex)
		{
			Diag.Write("[虚化] 部件清单失败: " + ex.Message);
		}
	}

	private static void RestoreSnapshot(object o0)
	{
		Object val = (Object)((o0 is Object) ? o0 : null);
		if (!_snapMats.TryGetValue(val, out var value))
		{
			MakeTransparentDirect(val);
			return;
		}
		try
		{
			Component val2 = (Component)(object)((val is Component) ? val : null);
			Renderer val3 = (Renderer)(((Object)(object)val2 == (Object)null) ? null : /*isinst with value type is only supported in some contexts*/);
			if ((Object)(object)val3 != (Object)null && value != null)
			{
				val3.sharedMaterials = value;
			}
			_snapCols.TryGetValue(val, out var value2);
			Diag.Write("[虚化] 还原快照 " + PathName(val2) + " 材质数=" + ((value == null) ? (-1) : value.Length) + " 碰撞体数=" + ((value2 == null) ? (-1) : value2.Length));
			Collider[] array = null;
			try
			{
				array = ((_field == null) ? null : (_field.GetValue(val) as Collider[]));
			}
			catch
			{
			}
			if (array == null || value2 == null)
			{
				return;
			}
			for (int i = 0; i < array.Length && i < value2.Length; i++)
			{
				if ((Object)(object)array[i] != (Object)null)
				{
					array[i].enabled = value2[i];
				}
			}
		}
		catch (Exception ex)
		{
			Diag.Write("[虚化] 快照还原失败: " + ex.Message);
		}
	}

	private static void MakeTransparentDirect(object o)
	{
		Component val = (Component)((o is Component) ? o : null);
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		try
		{
			Array array = ((_fieldMaterials == null) ? null : (_fieldMaterials.GetValue(o) as Array));
			Component component = val.GetComponent(typeof(Renderer));
			Renderer val2 = (Renderer)(object)((component is Renderer) ? component : null);
			if (array != null && (Object)(object)val2 != (Object)null)
			{
				Material[] array2 = (Material[])(object)new Material[array.Length];
				for (int i = 0; i < array.Length; i++)
				{
					object value = array.GetValue(i);
					int num = ((_fElemIdx == null) ? i : Convert.ToInt32(_fElemIdx.GetValue(value)));
					Material val3 = (Material)((_fElemMat == null) ? null : /*isinst with value type is only supported in some contexts*/);
					if (num >= 0 && num < array2.Length)
					{
						array2[num] = val3;
					}
				}
				val2.sharedMaterials = array2;
			}
		}
		catch (Exception ex)
		{
			Diag.Write("[虚化] 透明材质还原失败: " + ex.Message);
		}
		try
		{
			Collider[] array3 = ((_field == null) ? null : (_field.GetValue(o) as Collider[]));
			if (array3 == null)
			{
				return;
			}
			for (int j = 0; j < array3.Length; j++)
			{
				if ((Object)(object)array3[j] != (Object)null)
				{
					array3[j].enabled = false;
				}
			}
		}
		catch
		{
		}
	}

	internal static void Tick()
	{
		try
		{
			if (!On())
			{
				if (_wasOn)
				{
					_wasOn = false;
					_objs = null;
					ExtraMask = 0;
					Parts = 0;
					CollidersOn = 0;
					Diag.Write("[虚化] 开关关闭,虚化交还原版");
				}
			}
			else
			{
				if (!EnsureType())
				{
					return;
				}
				if (!_wasOn)
				{
					_wasOn = true;
					Apply(forceVisual: true);
					Diag.Write("[虚化] 开关开启,常驻保持实体化");
					LogState();
					return;
				}
				float unscaledTime = Time.unscaledTime;
				if (_objs == null || unscaledTime >= _nextScan)
				{
					Scan();
				}
				if (_objs == null || _objs.Length == 0)
				{
					ExtraMask = 0;
					Parts = 0;
					CollidersOn = 0;
					return;
				}
				int num = 0;
				int num2 = 0;
				for (int i = 0; i < _objs.Length; i++)
				{
					Object val = _objs[i];
					if (val == (Object)null)
					{
						_objs = null;
						return;
					}
					Collider[] array = null;
					try
					{
						array = _field.GetValue(val) as Collider[];
					}
					catch
					{
					}
					if (array == null)
					{
						continue;
					}
					bool flag = false;
					foreach (Collider val2 in array)
					{
						if (!((Object)(object)val2 == (Object)null))
						{
							if (!val2.enabled)
							{
								flag = true;
							}
							num |= 1 << ((Component)val2).gameObject.layer;
						}
					}
					if (!flag)
					{
						continue;
					}
					if (_makeVisible != null)
					{
						try
						{
							_makeVisible.Invoke(val, null);
						}
						catch (Exception ex)
						{
							Diag.Write("[虚化] 补回失败: " + ex.Message);
						}
					}
					foreach (Collider val3 in array)
					{
						if ((Object)(object)val3 != (Object)null && !val3.enabled)
						{
							val3.enabled = true;
							num2++;
						}
					}
				}
				ExtraMask = num;
				Parts = _objs.Length;
				CollidersOn = num2;
				if (Parts != _lastParts)
				{
					_lastParts = Parts;
					DumpParts("tick");
				}
				if (num2 > 0)
				{
					Diag.Write("[虚化] 当帧补回碰撞体 x" + num2);
				}
				if (num != _lastMask)
				{
					LogState();
				}
			}
		}
		catch (Exception ex2)
		{
			if (!_warned)
			{
				_warned = true;
				Diag.Write("[虚化] Tick 失败: " + ex2.Message);
			}
		}
	}

	private static void LogState()
	{
		//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)
		try
		{
			if (Time.unscaledTime - _lastLog < 3f && _lastMask >= 0)
			{
				return;
			}
			_lastLog = Time.unscaledTime;
			_lastMask = ExtraMask;
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = 0; i < 32; i++)
			{
				if ((ExtraMask & (1 << i)) != 0)
				{
					string text = LayerMask.LayerToName(i);
					stringBuilder.Append(i + ":" + (string.IsNullOrEmpty(text) ? "?" : text) + " ");
				}
			}
			string text2 = "";
			try
			{
				Scene activeScene = SceneManager.GetActiveScene();
				text2 = ((Scene)(ref activeScene)).name;
			}
			catch
			{
			}
			Diag.Write("[虚化] 常驻实体化 地图=" + text2 + " 虚化部件=" + Parts + " 补回碰撞体=" + CollidersOn + " 图层=" + ((stringBuilder.Length == 0) ? "无" : stringBuilder.ToString().Trim()));
		}
		catch
		{
		}
	}
}
internal static class UnitLabels
{
	private sealed class Entry
	{
		internal Unit Unit;

		internal float Prog;

		internal bool Alive;

		internal string Name;

		internal string Raw;

		internal bool Custom;

		internal bool HasBp;

		internal float HeadOffsetY;

		internal string BpName;

		internal string GoName;

		internal bool Sampled;
	}

	private const float FadeInTime = 0.25f;

	private const float FadeOutTime = 0.22f;

	private const float PerUnitIn = 0.22f;

	private const float PerUnitOut = 0.16f;

	private const float StaggerPer = 0.025f;

	private const float StaggerMax = 0.28f;

	private const float BoxGapPx = 22f;

	private const int MaxLabels = 160;

	private const float MaxBoxWidthRatio = 0.55f;

	private static readonly List<Entry> _entries = new List<Entry>();

	private static bool _on;

	private static float _alpha;

	private static float _nextScan;

	private static Camera _cam;

	private static bool _escapeOpen;

	private static float _nextEscapeCheck;

	private static Type _localizerType;

	private static MethodInfo _mLocalize;

	private static Type _escapeType;

	private static FieldInfo _fEscapeGroup;

	private static PropertyInfo _pEscapeActive;

	private static FieldInfo _fUnitHead;

	private static bool _loggedEscape;

	private static GUIStyle _nameStyle;

	private static GUIStyle _coordStyle;

	private static Texture2D _boxTex;

	private static Font _font;

	private static bool _loggedCount;

	private static bool _loggedCustom;

	private static bool _loggedLocalizer;

	private static int _loggedSamples;

	private static readonly Regex _tagRegex = new Regex("<[^>]*>");

	internal static void Tick()
	{
		try
		{
			_nextEscapeCheck -= Time.unscaledDeltaTime;
			if (_nextEscapeCheck <= 0f)
			{
				_nextEscapeCheck = 0.5f;
				_escapeOpen = EscapeMenuOpen();
			}
			bool flag = Plugin.ShowUnitLabels != null && Plugin.ShowUnitLabels.Value && ModeGate.Sandbox && ModeGate.PlacementState && !_escapeOpen;
			if (flag != _on)
			{
				_on = flag;
				Diag.Write(flag ? "[标注] 兵种位置标注 开启" : ("[标注] 兵种位置标注 关闭(Sandbox=" + ModeGate.Sandbox + " 放置阶段=" + ModeGate.PlacementState + " ESC=" + _escapeOpen + " 配置=" + (Plugin.ShowUnitLabels != null && Plugin.ShowUnitLabels.Value) + ")"));
			}
			float num = (_on ? 1f : 0f);
			float num2 = (_on ? 4f : 4.5454545f);
			_alpha = Mathf.MoveTowards(_alpha, num, num2 * Time.unscaledDeltaTime);
			if (_alpha <= 0.001f && !_on)
			{
				if (_entries.Count > 0)
				{
					_entries.Clear();
				}
				_loggedCount = false;
				_loggedCustom = false;
				_loggedSamples = 0;
				return;
			}
			_nextScan -= Time.unscaledDeltaTime;
			if (_nextScan <= 0f)
			{
				_nextScan = 0.5f;
				Scan();
			}
			float num3 = (_on ? 4.5454545f : 6.25f) * Time.unscaledDeltaTime;
			for (int num4 = _entries.Count - 1; num4 >= 0; num4--)
			{
				Entry entry = _entries[num4];
				if ((Object)(object)entry.Unit == (Object)null)
				{
					_entries.RemoveAt(num4);
				}
				else
				{
					float num5 = ((_on && entry.Alive) ? 1f : 0f);
					entry.Prog = Mathf.MoveTowards(entry.Prog, num5, num3);
					if (!_on && entry.Prog <= 0.001f)
					{
						_entries.RemoveAt(num4);
					}
				}
			}
		}
		catch
		{
		}
	}

	private static void Scan()
	{
		try
		{
			Unit[] array = Object.FindObjectsOfType<Unit>();
			foreach (Entry entry5 in _entries)
			{
				entry5.Alive = false;
			}
			Unit[] array2 = array;
			foreach (Unit val in array2)
			{
				if ((Object)(object)val == (Object)null || (Object)(object)((Component)val).gameObject == (Object)null || !((Component)val).gameObject.activeInHierarchy)
				{
					continue;
				}
				Entry entry = null;
				foreach (Entry entry6 in _entries)
				{
					if (object.ReferenceEquals(entry6.Unit, val))
					{
						entry = entry6;
						break;
					}
				}
				if (entry != null)
				{
					entry.Alive = true;
					continue;
				}
				Entry entry2 = new Entry();
				entry2.Unit = val;
				entry2.Prog = 0f;
				entry2.Alive = true;
				Entry entry3 = entry2;
				ResolveEntry(entry3);
				_entries.Add(entry3);
			}
			if (!_loggedCount)
			{
				_loggedCount = true;
				Diag.Write("[标注] 首次扫描到场上兵种=" + _entries.Count);
			}
			for (int j = 0; j < _entries.Count; j++)
			{
				if (_loggedSamples >= 20)
				{
					break;
				}
				Entry entry4 = _entries[j];
				if (!entry4.Sampled)
				{
					entry4.Sampled = true;
					_loggedSamples++;
					Diag.Write("[标注] 样本" + _loggedSamples + " 工坊=" + entry4.Custom + " 蓝图=" + entry4.HasBp + " 头顶高=" + entry4.HeadOffsetY.ToString("F2", CultureInfo.InvariantCulture) + " 蓝图名=[" + entry4.BpName + "] 物体名=[" + entry4.GoName + "] 显示名=[" + entry4.Name + "]");
				}
			}
			if (_loggedCustom)
			{
				return;
			}
			StringBuilder stringBuilder = null;
			int num = 0;
			foreach (Entry entry7 in _entries)
			{
				if (entry7.Custom)
				{
					if (stringBuilder == null)
					{
						stringBuilder = new StringBuilder();
					}
					if (num > 0)
					{
						stringBuilder.Append(", ");
					}
					stringBuilder.Append(entry7.Name);
					num++;
				}
			}
			if (num > 0)
			{
				_loggedCustom = true;
				Diag.Write("[标注] 其中工坊自定义兵种=" + num + ":" + stringBuilder.ToString());
			}
		}
		catch (Exception ex)
		{
			Diag.Write("[标注] 扫描兵种失败: " + ex.Message);
		}
	}

	private static void ResolveEntry(Entry e)
	{
		//IL_0032: 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)
		try
		{
			Unit unit = e.Unit;
			UnitBlueprint val = BlueprintOf(unit);
			e.HasBp = (Object)(object)val != (Object)null;
			Transform val2 = UnitHead(unit);
			float headOffsetY = 1.2f;
			if ((Object)(object)val2 != (Object)null)
			{
				float num = val2.position.y - ((Component)unit).transform.position.y;
				if (num > 0.3f)
				{
					headOffsetY = num;
				}
			}
			e.HeadOffsetY = headOffsetY;
			bool flag = GetBoolProp(val, "IsCustomUnit") || GetBoolProp(val, "IsModUnit") || GetIntProp(val, "ModID") > 0;
			DatabaseEntity val3 = EntityOf(unit, val);
			string text = null;
			if ((Object)(object)val != (Object)null)
			{
				PropertyInfo property = ((object)val).GetType().GetProperty("Name", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				object obj = ((property == null) ? null : property.GetValue(val, null));
				text = obj as string;
			}
			string text2 = ((val3 == null) ? null : val3.Name);
			string text3 = null;
			try
			{
				text3 = ((Object)((Component)unit).gameObject).name;
			}
			catch
			{
				text3 = null;
			}
			string text4 = text;
			if (string.IsNullOrEmpty(text4))
			{
				text4 = text2;
			}
			if (string.IsNullOrEmpty(text4))
			{
				text4 = text3;
			}
			if (string.IsNullOrEmpty(text4))
			{
				text4 = "?";
			}
			e.Custom = flag;
			e.BpName = text;
			e.GoName = text3;
			e.Raw = text4;
			string text5 = CleanDisplayName(text4);
			e.Name = (flag ? text5 : Localize(text5));
		}
		catch
		{
			e.Name = "?";
		}
	}

	internal static void Draw()
	{
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: 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_0159: 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_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_0217: Unknown result type (might be due to invalid IL or missing references)
		//IL_021c: Unknown result type (might be due to invalid IL or missing references)
		//IL_024f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0256: Expected O, but got Unknown
		//IL_0258: Unknown result type (might be due to invalid IL or missing references)
		//IL_025f: Expected O, but got Unknown
		//IL_0266: Unknown result type (might be due to invalid IL or missing references)
		//IL_026b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0274: Unknown result type (might be due to invalid IL or missing references)
		//IL_0279: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_029f: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02da: Unknown result type (might be due to invalid IL or missing references)
		//IL_02df: Unknown result type (might be due to invalid IL or missing references)
		//IL_047b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0458: Unknown result type (might be due to invalid IL or missing references)
		//IL_0480: Unknown result type (might be due to invalid IL or missing references)
		//IL_0482: Unknown result type (might be due to invalid IL or missing references)
		//IL_0484: Unknown result type (might be due to invalid IL or missing references)
		//IL_0486: Unknown result type (might be due to invalid IL or missing references)
		//IL_0490: Unknown result type (might be due to invalid IL or missing references)
		//IL_049f: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_04bc: 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_04ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_04fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_051e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0528: Unknown result type (might be due to invalid IL or missing references)
		//IL_0551: Unknown result type (might be due to invalid IL or missing references)
		//IL_0575: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_05cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_05fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_060b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0659: Unknown result type (might be due to invalid IL or missing references)
		//IL_065d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0671: Unknown result type (might be due to invalid IL or missing references)
		//IL_067e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0690: Unknown result type (might be due to invalid IL or missing references)
		//IL_06ad: Unknown result type (might be due to invalid IL or missing references)
		if (_alpha <= 0.001f || _entries.Count == 0)
		{
			return;
		}
		try
		{
			EnsureStyles();
			_cam = ResolveCamera();
			if ((Object)(object)_cam == (Object)null)
			{
				return;
			}
			_entries.Sort((Entry a, Entry b) => (!((Object)(object)a.Unit == (Object)null) && !((Object)(object)b.Unit == (Object)null)) ? Vector3.Distance(((Component)a.Unit).transform.position, ((Component)_cam).transform.position).CompareTo(Vector3.Distance(((Component)b.Unit).transform.position, ((Component)_cam).transform.position)) : 0);
			float num = (float)Screen.width * 0.55f;
			int num2 = 0;
			Vector2 val2 = default(Vector2);
			Vector2 val5 = default(Vector2);
			Rect val10 = default(Rect);
			for (int num3 = 0; num3 < _entries.Count; num3++)
			{
				if (num2 >= 160)
				{
					break;
				}
				Entry entry = _entries[num3];
				if ((Object)(object)entry.Unit == (Object)null)
				{
					continue;
				}
				float num4 = Mathf.Min((float)num3 * 0.025f, 0.28f);
				float num5 = Mathf.Clamp01((entry.Prog - num4) / Mathf.Max(0.001f, 1f - num4));
				if (num5 <= 0.01f)
				{
					continue;
				}
				Vector3 position = ((Component)entry.Unit).transform.position;
				Vector3 val = _cam.WorldToScreenPoint(position);
				if (!(val.z < 0f))
				{
					((Vector2)(ref val2))..ctor(val.x, (float)Screen.height - val.y);
					float num6 = ((entry.HeadOffsetY > 0.3f) ? entry.HeadOffsetY : 1.2f);
					Vector3 val3 = position + Vector3.up * (num6 + 0.3f);
					Vector3 val4 = _cam.WorldToScreenPoint(val3);
					if (val4.z < 0f)
					{
						val4 = val;
					}
					((Vector2)(ref val5))..ctor(val4.x, (float)Screen.height - val4.y);
					string text = "X " + position.x.ToString("F1", CultureInfo.InvariantCulture) + "  Y " + position.y.ToString("F1", CultureInfo.InvariantCulture) + "  Z " + position.z.ToString("F1", CultureInfo.InvariantCulture);
					Color c = TeamColor(entry.Unit);
					float num7 = _alpha * num5;
					float num8 = EaseOut(num5);
					_nameStyle.fontSize = 13;
					_coordStyle.fontSize = 11;
					GUIContent val6 = new GUIContent(entry.Name);
					GUIContent val7 = new GUIContent(text);
					Vector2 val8 = _nameStyle.CalcSize(val6);
					Vector2 val9 = _coordStyle.CalcSize(val7);
					float num9 = num - 20f;
					while (val8.x > num9 && _nameStyle.fontSize > 10)
					{
						GUIStyle nameStyle = _nameStyle;
						nameStyle.fontSize -= 1;
						val8 = _nameStyle.CalcSize(val6);
					}
					while (val9.x > num9 && _coordStyle.fontSize > 9)
					{
						GUIStyle coordStyle = _coordStyle;
						coordStyle.fontSize -= 1;
						val9 = _coordStyle.CalcSize(val7);
					}
					float num10 = Mathf.Max(18f, _nameStyle.CalcHeight(val6, num9));
					float num11 = Mathf.Max(15f, _coordStyle.CalcHeight(val7, num9));
					float num12 = Mathf.Max(val8.x, val9.x);
					float num13 = Mathf.Clamp(num12 * 1.08f + 20f, 120f, num);
					float num14 = 6f + num10 + 4f + num11 + 6f;
					float num15 = val5.x - num13 * 0.5f;
					num15 = Mathf.Clamp(num15, 4f, (float)Screen.width - num13 - 4f);
					float num16 = val5.y - 22f - num14;
					bool flag = num16 >= 4f;
					float num17 = (flag ? num16 : (val2.y + 22f));
					num17 = Mathf.Clamp(num17, 4f, Mathf.Max(4f, (float)Screen.height - num14 - 4f));
					((Rect)(ref val10))..ctor(num15, num17, num13 * num8, num14);
					if (!(((Rect)(ref val10)).width < 4f) && !(((Rect)(ref val10)).height < 4f))
					{
						Vector2 val11 = (flag ? new Vector2(((Rect)(ref val10)).x + ((Rect)(ref val10)).width * 0.5f, ((Rect)(ref val10)).yMax) : new Vector2(((Rect)(ref val10)).x + ((Rect)(ref val10)).width * 0.5f, ((Rect)(ref val10)).yMin));
						DrawLine(val11, val2, Plugin.WithAlpha(c, 0.85f * num7), 2f);
						DrawArrowHead(val2, val11, Plugin.WithAlpha(c, 0.95f * num7), 7f);
						GUI.color = Plugin.WithAlpha(c, num7);
						GUI.DrawTexture(new Rect(val2.x - 3f, val2.y - 3f, 6f, 6f), (Texture)(object)_boxTex);
						GUI.color = Color.white;
						GUI.color = new Color(0.07f, 0.07f, 0.1f, 0.72f * num7);
						GUI.DrawTexture(val10, (Texture)(object)_boxTex);
						GUI.color = new Color(c.r, c.g, c.b, 0.9f * num7);
						GUI.DrawTexture(new Rect(((Rect)(ref val10)).x, ((Rect)(ref val10)).y, ((Rect)(ref val10)).width, 1f), (Texture)(object)_boxTex);
						GUI.DrawTexture(new Rect(((Rect)(ref val10)).x, ((Rect)(ref val10)).yMax - 1f, ((Rect)(ref val10)).width, 1f), (Texture)(object)_boxTex);
						GUI.DrawTexture(new Rect(((Rect)(ref val10)).x, ((Rect)(ref val10)).y, 1f, ((Rect)(ref val10)).height), (Texture)(object)_boxTex);
						GUI.DrawTexture(new Rect(((Rect)(ref val10)).xMax - 1f, ((Rect)(ref val10)).y, 1f, ((Rect)(ref val10)).height), (Texture)(object)_boxTex);
						GUI.color = Color.white;
						float num18 = ((Rect)(ref val10)).x + 10f;
						float num19 = ((Rect)(ref val10)).width - 20f;
						float num20 = ((Rect)(ref val10)).y + 6f;
						float num21 = num20 + num10 + 4f;
						_nameStyle.normal.textColor = Plugin.WithAlpha(c, num7);
						_coordStyle.normal.textColor = Plugin.WithAlpha(Color.white, num7 * 0.9f);
						GUI.Label(new Rect(num18, num20, num19, num10), entry.Name, _nameStyle);
						GUI.Label(new Rect(num18, num21, num19, num11), text, _coordStyle);
						num2++;
					}
				}
			}
		}
		catch
		{
		}
	}

	private static void DrawArrowHead(Vector2 tip, Vector2 toward, Color c, float size)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: 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_0043: 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_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: 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_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//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)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: 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)
		Vector2 val = toward - tip;
		if (!(((Vector2)(ref val)).magnitude < 1f))
		{
			((Vector2)(ref val)).Normalize();
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0f - val.y, val.x);
			Vector2 b = tip + val * size + val2 * size * 0.55f;
			Vector2 b2 = tip + val * size - val2 * size * 0.55f;
			DrawLine(tip, b, c, 1f);
			DrawLine(tip, b2, c, 1f);
		}
	}

	private static void DrawLine(Vector2 a, Vector2 b, Color c, float width)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: 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)
		Vector2 val = b - a;
		float magnitude = ((Vector2)(ref val)).magnitude;
		if (!(magnitude < 1f))
		{
			float num = Mathf.Atan2(val.y, val.x) * 57.29578f;
			GUI.color = c;
			GUIUtility.RotateAroundPivot(num, a);
			GUI.DrawTexture(new Rect(a.x, a.y - width * 0.5f, magnitude, width), (Texture)(object)_boxTex);
			GUIUtility.RotateAroundPivot(0f - num, a);
			GUI.color = Color.white;
		}
	}

	private static float EaseOut(float t)
	{
		t = Mathf.Clamp01(t);
		return 1f - (1f - t) * (1f - t);
	}

	private static Camera ResolveCamera()
	{
		if ((Object)(object)_cam != (Object)null && (Object)(object)((Component)_cam).gameObject != (Object)null)
		{
			return _cam;
		}
		_cam = null;
		try
		{
			_cam = Camera.main;
		}
		catch
		{
		}
		if ((Object)(object)_cam != (Object)null && (Object)(object)((Component)_cam).gameObject != (Object)null)
		{
			return _cam;
		}
		try
		{
			Object obj2 = Object.FindObjectOfType(typeof(SandboxPlacementCamera));
			MonoBehaviour val = (MonoBehaviour)(object)((obj2 is MonoBehaviour) ? obj2 : null);
			if ((Object)(object)val != (Object)null)
			{
				FieldInfo field = typeof(SandboxPlacementCamera).GetField("m_camera", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				object obj3 = ((field == null) ? null : field.GetValue(val));
				_cam = (Camera)((obj3 is Camera) ? obj3 : null);
			}
		}
		catch
		{
		}
		return _cam;
	}

	private static bool EscapeMenuOpen()
	{
		try
		{
			if (_escapeType == null)
			{
				Type[] array = null;
				try
				{
					array = typeof(SceneSettings).Assembly.GetTypes();
				}
				catch (ReflectionTypeLoadException ex)
				{
					array = ex.Types;
				}
				if (array != null)
				{
					foreach (Type type in array)
					{
						if (!(type == null) && !(type.Name != "EscapeMenuComponent"))
						{
							_escapeType = type;
							_fEscapeGroup = type.GetField("escapeMenuButtonGroup", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
							_pEscapeActive = type.GetProperty("IsActive", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
							break;
						}
					}
				}
				if (!_loggedEscape)
				{
					_loggedEscape = true;
					bool flag = false;
					if (_pEscapeActive != null)
					{
						Object obj = Object.FindObjectOfType(_escapeType);
						Component val = (Component)(object)((obj is Component) ? obj : null);
						if ((Object)(object)val != (Object)null)
						{
							object value = _pEscapeActive.GetValue(val, null);
							try
							{
								flag = (bool)value;
							}
							catch
							{
								flag = false;
							}
						}
					}
					Diag.Write("[标注] ESC菜单组件=" + ((_escapeType == null) ? "未找到" : "找到") + " IsActive属性=" + (_pEscapeActive != null) + " 当前IsActive=" + flag);
				}
				if (_escapeType == null)
				{
					return false;
				}
			}
			Object obj3 = Object.FindObjectOfType(_escapeType);
			Component val2 = (Component)(object)((obj3 is Component) ? obj3 : null);
			if ((Object)(object)val2 == (Object)null)
			{
				return false;
			}
			if (_pEscapeActive != null)
			{
				object value2 = _pEscapeActive.GetValue(val2, null);
				bool result;
				try
				{
					result = (bool)value2;
				}
				catch
				{
					result = false;
				}
				return result;
			}
			if (_fEscapeGroup != null)
			{
				object? value3 = _fEscapeGroup.GetValue(val2);
				CanvasGroup val3 = (CanvasGroup)((value3 is CanvasGroup) ? value3 : null);
				if ((Object)(object)val3 != (Object)null)
				{
					return val3.interactable;
				}
			}
			return false;
		}
		catch
		{
			return false;
		}
	}

	private static void EnsureStyles()
	{
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Expected O, but got Unknown
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Expected O, but got Unknown
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Expected O, but got Unknown
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Expected O, but got Unknown
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_0173: Expected O, but got Unknown
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Expected O, but got Unknown
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Expected O, but got Unknown
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		if (_nameStyle != null && _coordStyle != null && (Object)(object)_boxTex != (Object)null)
		{
			return;
		}
		try
		{
			if ((Object)(object)_font == (Object)null)
			{
				try
				{
					_font = Font.CreateDynamicFontFromOSFont(new string[5] { "Microsoft YaHei", "微软雅黑", "SimHei", "SimSun", "Arial" }, 15);
				}
				catch
				{
				}
				if ((Object)(object)_font == (Object)null)
				{
					try
					{
						_font = Resources.GetBuiltinResource<Font>("Arial.ttf");
					}
					catch
					{
					}
				}
			}
			_nameStyle = new GUIStyle(GUI.skin.label);
			_nameStyle.font = _font;
			_nameStyle.fontSize = 13;
			_nameStyle.alignment = (TextAnchor)4;
			_nameStyle.wordWrap = false;
			_nameStyle.richText = false;
			_nameStyle.padding = new RectOffset(0, 0, 0, 0);
			_nameStyle.margin = new RectOffset(0, 0, 0, 0);
			_nameStyle.fixedHeight = 0f;
			_coordStyle = new GUIStyle(GUI.skin.label);
			_coordStyle.font = _font;
			_coordStyle.fontSize = 11;
			_coordStyle.alignment = (TextAnchor)4;
			_coordStyle.wordWrap = false;
			_coordStyle.richText = false;
			_coordStyle.padding = new RectOffset(0, 0, 0, 0);
			_coordStyle.margin = new RectOffset(0, 0, 0, 0);
			_coordStyle.fixedHeight = 0f;
			_boxTex = new Texture2D(1, 1);
			_boxTex.SetPixel(0, 0, Color.white);
			_boxTex.Apply();
		}
		catch
		{
		}
	}

	private static string CleanDisplayName(string s)
	{
		if (string.IsNullOrEmpty(s))
		{
			return s;
		}
		return _tagRegex.Replace(s, "").Trim();
	}

	private static string Localize(string raw)
	{
		if (string.IsNullOrEmpty(raw))
		{
			return raw;
		}
		try
		{
			if (_mLocalize == null)
			{
				if (_localizerType == null)
				{
					Type[] array = null;
					try
					{
						array = typeof(SceneSettings).Assembly.GetTypes();
					}
					catch (ReflectionTypeLoadException ex)
					{
						array = ex.Types;
					}
					if (array != null)
					{
						foreach (Type type in array)
						{
							if (!(type == null) && !(type.Name != "Localizer"))
							{
								_localizerType = type;
								break;
							}
						}
					}
				}
				if (_localizerType != null)
				{
					_mLocalize = _localizerType.GetMethod("GetSinglePhrase", new Type[2]
					{
						typeof(string),
						typeof(string[])
					});
				}
			}
			if (!_loggedLocalizer)
			{
				_loggedLocalizer = true;
				Diag.Write("[标注] 本地化绑定=" + (_mLocalize != null) + " Localizer类型=" + (_localizerType != null));
			}
			if (_mLocalize == null)
			{
				return raw;
			}
			string text = (raw.StartsWith("[LOCAL] ") ? raw.Substring(8) : raw);
			object obj = _mLocalize.Invoke(null, new object[2] { text, null });
			string text2 = obj as string;
			if (string.IsNullOrEmpty(text2))
			{
				return raw;
			}
			return (text2 == text) ? raw : text2;
		}
		catch
		{
			return raw;
		}
	}

	private static bool GetBoolProp(object obj, string propName)
	{
		try
		{
			PropertyInfo property = obj.GetType().GetProperty(propName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (property == null)
			{
				return false;
			}
			object value = property.GetValue(obj, null);
			bool result;
			try
			{
				result = (bool)value;
			}
			catch
			{
				result = false;
			}
			return result;
		}
		catch
		{
			return false;
		}
	}

	private static int GetIntProp(object obj, string propName)
	{
		if (obj == null)
		{
			return 0;
		}
		try
		{
			PropertyInfo property = obj.GetType().GetProperty(propName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (property == null)
			{
				return 0;
			}
			object value = property.GetValue(obj, null);
			int result;
			try
			{
				result = (int)value;
			}
			catch
			{
				result = 0;
			}
			return result;
		}
		catch
		{
			return 0;
		}
	}

	private static Transform UnitHead(Unit u)
	{
		try
		{
			if ((Object)(object)u == (Object)null)
			{
				return null;
			}
			if (_fUnitHead == null)
			{
				_fUnitHead = typeof(Unit).GetField("Head", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}
			if (_fUnitHead == null)
			{
				return null;
			}
			object? value = _fUnitHead.GetValue(u);
			return (Transform)((value is Transform) ? value : null);
		}
		catch
		{
			return null;
		}
	}

	private static UnitBlueprint BlueprintOf(Unit u)
	{
		try
		{
			FieldInfo field = typeof(Unit).GetField("unitBlueprint", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			object obj = ((field == null) ? null : field.GetValue(u));
			return (UnitBlueprint)((obj is UnitBlueprint) ? obj : null);
		}
		catch
		{
			return null;
		}
	}

	private static DatabaseEntity EntityOf(Unit u, UnitBlueprint bp)
	{
		try
		{
			if ((Object)(object)bp != (Object)null)
			{
				PropertyInfo property = typeof(UnitBlueprint).GetProperty("Entity", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (property != null)
				{
					object? value = property.GetValue(bp, null);
					DatabaseEntity val = (DatabaseEntity)((value is DatabaseEntity) ? value : null);
					if (val != null)
					{
						return val;
					}
				}
				FieldInfo field = typeof(UnitBlueprint).GetField("m_entity", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				object obj = ((field == null) ? null : field.GetValue(bp));
				DatabaseEntity val2 = (DatabaseEntity)((obj is DatabaseEntity) ? obj : null);
				if (val2 != null)
				{
					return val2;
				}
			}
			PropertyInfo property2 = typeof(Unit).GetProperty("Entity", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (property2 != null)
			{
				object? value2 = property2.GetValue(u, null);
				DatabaseEntity val3 = (DatabaseEntity)((value2 is DatabaseEntity) ? value2 : null);
				if (val3 != null)
				{
					return val3;
				}
			}
			FieldInfo field2 = typeof(Unit).GetField("m_entity", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field2 != null)
			{
				object? value3 = field2.GetValue(u);
				DatabaseEntity val4 = (DatabaseEntity)((value3 is DatabaseEntity) ? value3 : null);
				if (val4 != null)
				{
					return val4;
				}
			}
		}
		catch
		{
		}
		return null;
	}

	private static Color TeamColor(Unit u)
	{
		//IL_0036: 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_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Invalid comparison between Unknown and I4
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: 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_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			FieldInfo field = typeof(Unit).GetField("Team", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			object obj = ((field == null) ? null : field.GetValue(u));
			Team val;
			try
			{
				val = (Team)obj;
			}
			catch
			{
				val = (Team)0;
			}
			if ((int)val == 0)
			{
				return new Color(1f, 0.38f, 0.38f);
			}
			if ((int)val == 1)
			{
				return new Color(0.38f, 0.62f, 1f);
			}