Decompiled source of SkillContorl v1.3.1

SkillControlMod.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Landfall.TABS;
using Landfall.TABS.GameState;
using Landfall.TABS.UnitEditor;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = "")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace SkillControlMod;

[BepInPlugin("com.skillcontrol.tabsmod", "Skill Control Mod", "1.1.0")]
public class Plugin : BaseUnityPlugin
{
	public static Plugin Instance;

	public static ManualLogSource Log;

	private static Harmony _harmony;

	private void Awake()
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Expected O, but got Unknown
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Expected O, but got Unknown
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		SkillControlConfig.Init(((BaseUnityPlugin)this).Config);
		SkillStateManager stateManager = new SkillStateManager();
		SkillControlPatches.Initialize(stateManager);
		_harmony = new Harmony("com.skillcontrol.tabsmod");
		_harmony.PatchAll(typeof(SkillControlPatches).Assembly);
		Log.LogInfo((object)"[SkillControl] Harmony补丁已应用 (隐藏原生UI/拦截技能触发/注入设置)");
		GameObject val = new GameObject("SkillControlUI");
		Object.DontDestroyOnLoad((Object)(object)val);
		SkillBarManager skillBarManager = val.AddComponent<SkillBarManager>();
		skillBarManager.Initialize(stateManager);
		Log.LogInfo((object)"[SkillControl] 技能控制mod加载完成! 设置请在游戏原生设置菜单的'控制'选项卡修改");
	}
}
public static class SkillControlConfig
{
	public static ConfigEntry<KeyCode>[] SkillKeys = new ConfigEntry<KeyCode>[9];

	public static ConfigEntry<bool> ShowSkillBar;

	public static ConfigEntry<float> UIScale;

	public static ConfigEntry<bool> FreeCastMode;

	public static void Init(ConfigFile config)
	{
		KeyCode[] array = (KeyCode[])(object)new KeyCode[9]
		{
			(KeyCode)49,
			(KeyCode)50,
			(KeyCode)51,
			(KeyCode)52,
			(KeyCode)53,
			(KeyCode)54,
			(KeyCode)55,
			(KeyCode)56,
			(KeyCode)57
		};
		for (int i = 0; i < 9; i++)
		{
			SkillKeys[i] = config.Bind<KeyCode>("KeyBindings", "SkillSlot" + (i + 1), array[i], "技能槽位 " + (i + 1) + " 的按键");
		}
		MigrateKeypadToAlpha();
		ShowSkillBar = config.Bind<bool>("UI", "ShowSkillBar", true, "显示技能栏UI");
		UIScale = config.Bind<float>("UI", "UIScale", 1f, "UI缩放比例 (0.5 ~ 2.0)");
		FreeCastMode = config.Bind<bool>("Gameplay", "FreeCastMode", true, "自由释放模式:忽略距离/角度/血量等条件限制,只保留冷却和死亡检查");
	}

	private static void MigrateKeypadToAlpha()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Invalid comparison between Unknown and I4
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Invalid comparison between Unknown and I4
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Expected I4, but got Unknown
		bool flag = false;
		for (int i = 0; i < 9; i++)
		{
			KeyCode value = SkillKeys[i].Value;
			if ((int)value >= 257 && (int)value <= 265)
			{
				int num = value - 257 + 1;
				SkillKeys[i].Value = (KeyCode)(49 + (num - 1));
				flag = true;
			}
		}
		if (flag)
		{
			Plugin.Log.LogInfo((object)"[SkillControl] 配置迁移:检测到旧版小键盘按键,已自动修正为大键盘数字键(Alpha1-9)");
		}
	}
}
public class SkillBarManager : MonoBehaviour
{
	private const float POSSESS_SEARCH_INTERVAL = 2f;

	private SkillStateManager _stateManager;

	private CameraAbilityPossess _possessController;

	private GameStateManager _gameStateManager;

	private bool _wasPossessing;

	private Unit _lastUnit;

	private ConditionalEvent[] _skillSlots = (ConditionalEvent[])(object)new ConditionalEvent[9];

	private string[] _skillNames = new string[9];

	private float[] _cdTotal = new float[9];

	private float[] _cdRemaining = new float[9];

	private bool[] _keyWasDown = new bool[9];

	private bool[] _skillAvailable = new bool[9];

	private Sprite[] _skillIcons = (Sprite[])(object)new Sprite[9];

	private bool _stylesInited;

	private Texture2D _texReady;

	private Texture2D _texCooldown;

	private Texture2D _texEmpty;

	private Texture2D _texPanel;

	private Texture2D _texDark;

	private GUIStyle _styleName;

	private GUIStyle _styleKey;

	private GUIStyle _styleIcon;

	private GUIStyle _styleCD;

	private static MethodInfo _getPhraseMethod;

	private float _possessSearchTimer;

	public void Initialize(SkillStateManager stateManager)
	{
		_stateManager = stateManager;
	}

	private void Start()
	{
		InitTextures();
	}

	private void Update()
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: 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_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Invalid comparison between Unknown and I4
		SkillControlPatches.SyncSettingsToConfig();
		if (_gameStateManager == null)
		{
			_gameStateManager = ServiceLocator.GetService<GameStateManager>();
		}
		if (_gameStateManager != null)
		{
			GameState gameState = _gameStateManager.GameState;
			if ((int)gameState != 0 && (int)gameState != 1)
			{
				if ((Object)(object)_possessController != (Object)null)
				{
					if (_wasPossessing)
					{
						OnPossessEnd();
					}
					_possessController = null;
				}
				return;
			}
		}
		if ((Object)(object)_possessController == (Object)null)
		{
			_possessSearchTimer += Time.deltaTime;
			if (_possessSearchTimer >= 2f)
			{
				_possessSearchTimer = 0f;
				_possessController = Object.FindObjectOfType<CameraAbilityPossess>();
			}
		}
		else if (!((Object)(object)_possessController == (Object)null))
		{
			bool isPossessing = _possessController.IsPossessing;
			if (isPossessing && !_wasPossessing)
			{
				OnPossessStart();
			}
			else if (!isPossessing && _wasPossessing)
			{
				OnPossessEnd();
			}
			if (isPossessing && (Object)(object)_possessController.currentUnit != (Object)(object)_lastUnit)
			{
				OnPossessEnd();
				OnPossessStart();
			}
			_wasPossessing = isPossessing;
			if (isPossessing)
			{
				HandleSkillInputs();
				UpdateCooldowns();
			}
		}
	}

	private void OnGUI()
	{
		InitStyles();
		if (_wasPossessing && SkillControlConfig.ShowSkillBar.Value)
		{
			DrawSkillBar();
		}
	}

	private void OnDestroy()
	{
		OnPossessEnd();
	}

	private void OnPossessStart()
	{
		if ((Object)(object)_possessController == (Object)null || (Object)(object)_possessController.currentUnit == (Object)null)
		{
			return;
		}
		_lastUnit = _possessController.currentUnit;
		Unit currentUnit = _possessController.currentUnit;
		_stateManager.ClearManagedSkills();
		ConditionalEvent[] componentsInChildren = ((Component)currentUnit).GetComponentsInChildren<ConditionalEvent>();
		if (componentsInChildren == null || componentsInChildren.Length == 0)
		{
			Plugin.Log.LogInfo((object)"[SkillControl] 当前单位没有技能");
			return;
		}
		int num = 0;
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			if (num >= 9)
			{
				break;
			}
			ConditionalEvent val = componentsInChildren[i];
			if (!((Object)(object)val == (Object)null) && val.controllableByPlayer)
			{
				_skillSlots[num] = val;
				_skillNames[num] = GetSkillDisplayName(val);
				_cdTotal[num] = GetCooldownTotal(val);
				_skillIcons[num] = GetSkillIcon(val);
				_stateManager.AddManagedSkill(val);
				num++;
			}
		}
		for (int j = num; j < 9; j++)
		{
			_skillSlots[j] = null;
			_skillNames[j] = "";
			_cdTotal[j] = 0f;
			_cdRemaining[j] = 0f;
			_skillIcons[j] = null;
		}
		Plugin.Log.LogInfo((object)("[SkillControl] 已映射 " + num + " 个技能到槽位"));
	}

	private void OnPossessEnd()
	{
		_lastUnit = null;
		for (int i = 0; i < 9; i++)
		{
			_skillSlots[i] = null;
			_skillNames[i] = "";
			_cdRemaining[i] = 0f;
			_cdTotal[i] = 0f;
			_keyWasDown[i] = false;
		}
		_stateManager.ClearManagedSkills();
	}

	private void HandleSkillInputs()
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < 9; i++)
		{
			if ((Object)(object)_skillSlots[i] == (Object)null)
			{
				continue;
			}
			KeyCode value = SkillControlConfig.SkillKeys[i].Value;
			if (Input.GetKeyDown(value))
			{
				using (_stateManager.BeginSelfInvocation())
				{
					_skillSlots[i].CheckConditionsUpdate(false);
				}
				_keyWasDown[i] = true;
			}
			else if (Input.GetKeyUp(value) && _keyWasDown[i])
			{
				using (_stateManager.BeginSelfInvocation())
				{
					_skillSlots[i].CheckConditionsUpdate(true);
				}
				_keyWasDown[i] = false;
			}
		}
	}

	private void UpdateCooldowns()
	{
		for (int i = 0; i < 9; i++)
		{
			if ((Object)(object)_skillSlots[i] == (Object)null)
			{
				_cdRemaining[i] = 0f;
				_skillAvailable[i] = false;
				continue;
			}
			_cdRemaining[i] = GetCooldownRemaining(_skillSlots[i]);
			if (SkillControlConfig.FreeCastMode.Value)
			{
				_skillAvailable[i] = _cdRemaining[i] <= 0.01f;
			}
			else
			{
				_skillAvailable[i] = IsSkillAvailable(_skillSlots[i]) && _cdRemaining[i] <= 0.01f;
			}
		}
	}

	private bool IsSkillAvailable(ConditionalEvent evt)
	{
		if (evt.events == null || evt.events.Length == 0)
		{
			return true;
		}
		bool[] array = new bool[evt.events.Length];
		for (int i = 0; i < evt.events.Length; i++)
		{
			if (evt.events[i] != null)
			{
				array[i] = evt.events[i].checkAutomatically;
			}
		}
		bool result = true;
		for (int j = 0; j < evt.events.Length; j++)
		{
			ConditionalEventInstance val = evt.events[j];
			if (val == null)
			{
				continue;
			}
			try
			{
				if (!evt.CheckConditions(val, (ConditionType)8, true, false))
				{
					result = false;
					break;
				}
			}
			catch
			{
				result = false;
				break;
			}
		}
		for (int k = 0; k < evt.events.Length; k++)
		{
			if (evt.events[k] != null)
			{
				evt.events[k].checkAutomatically = array[k];
			}
		}
		return result;
	}

	private float GetCooldownRemaining(ConditionalEvent evt)
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		if (evt.events == null)
		{
			return 0f;
		}
		for (int i = 0; i < evt.events.Length; i++)
		{
			ConditionalEventInstance val = evt.events[i];
			if (val == null || val.conditions == null)
			{
				continue;
			}
			for (int j = 0; j < val.conditions.Length; j++)
			{
				EventCondition val2 = val.conditions[j];
				if ((int)val2.conditionType == 0)
				{
					return Mathf.Max(0f, val2.value - val2.counter);
				}
			}
		}
		return 0f;
	}

	private float GetCooldownTotal(ConditionalEvent evt)
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		if (evt.events == null)
		{
			return 1f;
		}
		for (int i = 0; i < evt.events.Length; i++)
		{
			ConditionalEventInstance val = evt.events[i];
			if (val == null || val.conditions == null)
			{
				continue;
			}
			for (int j = 0; j < val.conditions.Length; j++)
			{
				EventCondition val2 = val.conditions[j];
				if ((int)val2.conditionType == 0)
				{
					return Mathf.Max(0.1f, val2.value);
				}
			}
		}
		return 1f;
	}

	private void DrawSkillBar()
	{
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		float value = SkillControlConfig.UIScale.Value;
		float num = 72f * value;
		float num2 = 4f * value;
		float num3 = 9f * num + 8f * num2;
		float num4 = (float)Screen.width - num3 - 20f;
		float num5 = (float)Screen.height - num - 20f;
		GUI.DrawTexture(new Rect(num4 - 6f, num5 - 6f, num3 + 12f, num + 12f), (Texture)(object)_texPanel);
		Rect r = default(Rect);
		for (int i = 0; i < 9; i++)
		{
			((Rect)(ref r))..ctor(num4 + (float)i * (num + num2), num5, num, num);
			DrawSlot(r, i, value);
		}
	}

	private void DrawSkillIcon(Rect r, int idx, float scale)
	{
		//IL_0122: 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_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		Sprite val = _skillIcons[idx];
		if ((Object)(object)val != (Object)null)
		{
			float num = ((Rect)(ref r)).width - 10f * scale;
			float num2 = ((Rect)(ref r)).x + (((Rect)(ref r)).width - num) / 2f;
			float num3 = ((Rect)(ref r)).y + 15f * scale;
			Rect val2 = default(Rect);
			((Rect)(ref val2))..ctor(num2, num3, num, num);
			Rect textureRect = val.textureRect;
			float num4 = ((Rect)(ref textureRect)).x / (float)((Texture)val.texture).width;
			Rect textureRect2 = val.textureRect;
			float num5 = ((Rect)(ref textureRect2)).y / (float)((Texture)val.texture).height;
			Rect textureRect3 = val.textureRect;
			float num6 = ((Rect)(ref textureRect3)).width / (float)((Texture)val.texture).width;
			Rect textureRect4 = val.textureRect;
			Rect val3 = default(Rect);
			((Rect)(ref val3))..ctor(num4, num5, num6, ((Rect)(ref textureRect4)).height / (float)((Texture)val.texture).height);
			GUI.DrawTextureWithTexCoords(val2, (Texture)(object)val.texture, val3);
		}
		else
		{
			_styleIcon.fontSize = Mathf.RoundToInt(18f * scale);
			GUI.Label(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y + 15f * scale, ((Rect)(ref r)).width, ((Rect)(ref r)).height - 25f * scale), IconText(_skillNames[idx]), _styleIcon);
		}
	}

	private void DrawSlot(Rect r, int idx, float scale)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_021a: 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_0235: Unknown result type (might be due to invalid IL or missing references)
		//IL_0240: Unknown result type (might be due to invalid IL or missing references)
		//IL_0248: Unknown result type (might be due to invalid IL or missing references)
		//IL_0280: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0312: Unknown result type (might be due to invalid IL or missing references)
		//IL_0317: Unknown result type (might be due to invalid IL or missing references)
		//IL_032d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0360: Unknown result type (might be due to invalid IL or missing references)
		//IL_036f: Unknown result type (might be due to invalid IL or missing references)
		ConditionalEvent val = _skillSlots[idx];
		if ((Object)(object)val == (Object)null)
		{
			GUI.DrawTexture(r, (Texture)(object)_texEmpty);
			return;
		}
		float num = _cdRemaining[idx];
		bool flag = num > 0.01f;
		bool flag2 = _skillAvailable[idx];
		Color c = default(Color);
		if (flag)
		{
			GUI.DrawTexture(r, (Texture)(object)_texCooldown);
			((Color)(ref c))..ctor(0.15f, 0.15f, 0.2f);
		}
		else if (!flag2)
		{
			GUI.DrawTexture(r, (Texture)(object)_texCooldown);
			((Color)(ref c))..ctor(0.8f, 0.4f, 0.1f);
		}
		else
		{
			GUI.DrawTexture(r, (Texture)(object)_texReady);
			((Color)(ref c))..ctor(0f, 0.75f, 1f);
		}
		DrawBorder(r, c, 2f);
		_styleName.fontSize = Mathf.RoundToInt(9f * scale);
		GUI.Label(new Rect(((Rect)(ref r)).x + 3f, ((Rect)(ref r)).y + 2f, ((Rect)(ref r)).width - 30f * scale, 14f * scale), Shorten(_skillNames[idx], 6), _styleName);
		_styleKey.fontSize = Mathf.RoundToInt(11f * scale);
		GUI.Label(new Rect(((Rect)(ref r)).x + ((Rect)(ref r)).width - 28f * scale, ((Rect)(ref r)).y + 2f, 24f * scale, 14f * scale), KeyName(SkillControlConfig.SkillKeys[idx].Value), _styleKey);
		if (flag)
		{
			_styleCD.fontSize = Mathf.RoundToInt(16f * scale);
			_styleCD.normal.textColor = new Color(1f, 0.4f, 0.4f);
			GUI.Label(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y + 15f * scale, ((Rect)(ref r)).width, ((Rect)(ref r)).height - 25f * scale), num.ToString("F1"), _styleCD);
		}
		else if (!flag2)
		{
			Color color = GUI.color;
			GUI.color = new Color(0.5f, 0.5f, 0.5f, 0.5f);
			DrawSkillIcon(r, idx, scale);
			GUI.color = color;
			_styleCD.fontSize = Mathf.RoundToInt(11f * scale);
			_styleCD.normal.textColor = new Color(1f, 0.6f, 0.2f);
			GUI.Label(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y + 15f * scale, ((Rect)(ref r)).width, ((Rect)(ref r)).height - 25f * scale), "不可用", _styleCD);
		}
		else
		{
			DrawSkillIcon(r, idx, scale);
		}
		if (flag && _cdTotal[idx] > 0f)
		{
			float num2 = 1f - num / _cdTotal[idx];
			float num3 = (((Rect)(ref r)).width - 6f) * num2;
			Color color2 = GUI.color;
			GUI.color = new Color(0f, 0.75f, 1f, 0.7f);
			GUI.DrawTexture(new Rect(((Rect)(ref r)).x + 3f, ((Rect)(ref r)).y + ((Rect)(ref r)).height - 5f, num3, 3f), (Texture)(object)Texture2D.whiteTexture);
			GUI.color = color2;
		}
	}

	private void InitTextures()
	{
		//IL_0015: 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_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		_texReady = MakeTex(new Color(0.04f, 0.12f, 0.24f, 0.92f));
		_texCooldown = MakeTex(new Color(0.04f, 0.06f, 0.12f, 0.92f));
		_texEmpty = MakeTex(new Color(0.02f, 0.02f, 0.03f, 0.5f));
		_texPanel = MakeTex(new Color(0.03f, 0.06f, 0.12f, 0.95f));
		_texDark = MakeTex(new Color(0.02f, 0.04f, 0.08f, 0.97f));
	}

	private void InitStyles()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		//IL_0048: 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_0063: Expected O, but got Unknown
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Expected O, but got Unknown
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Expected O, but got Unknown
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		if (!_stylesInited)
		{
			_stylesInited = true;
			GUIStyle val = new GUIStyle(GUI.skin.label);
			val.fontSize = 9;
			val.fontStyle = (FontStyle)1;
			val.alignment = (TextAnchor)0;
			_styleName = val;
			_styleName.normal.textColor = Color.white;
			GUIStyle val2 = new GUIStyle(GUI.skin.label);
			val2.fontSize = 11;
			val2.fontStyle = (FontStyle)1;
			val2.alignment = (TextAnchor)2;
			_styleKey = val2;
			_styleKey.normal.textColor = new Color(1f, 0.85f, 0.2f);
			GUIStyle val3 = new GUIStyle(GUI.skin.label);
			val3.fontSize = 18;
			val3.fontStyle = (FontStyle)1;
			val3.alignment = (TextAnchor)4;
			_styleIcon = val3;
			_styleIcon.normal.textColor = new Color(0.6f, 0.85f, 1f);
			GUIStyle val4 = new GUIStyle(GUI.skin.label);
			val4.fontSize = 16;
			val4.fontStyle = (FontStyle)1;
			val4.alignment = (TextAnchor)4;
			_styleCD = val4;
			_styleCD.normal.textColor = new Color(1f, 0.4f, 0.4f);
		}
	}

	private static Texture2D MakeTex(Color c)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Expected O, but got Unknown
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(2, 2);
		Color[] array = (Color[])(object)new Color[4];
		for (int i = 0; i < 4; i++)
		{
			array[i] = c;
		}
		val.SetPixels(array);
		val.Apply();
		return val;
	}

	private static void DrawBorder(Rect r, Color c, float t)
	{
		//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_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		Color color = GUI.color;
		GUI.color = c;
		GUI.DrawTexture(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, ((Rect)(ref r)).width, t), (Texture)(object)Texture2D.whiteTexture);
		GUI.DrawTexture(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y + ((Rect)(ref r)).height - t, ((Rect)(ref r)).width, t), (Texture)(object)Texture2D.whiteTexture);
		GUI.DrawTexture(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, t, ((Rect)(ref r)).height), (Texture)(object)Texture2D.whiteTexture);
		GUI.DrawTexture(new Rect(((Rect)(ref r)).x + ((Rect)(ref r)).width - t, ((Rect)(ref r)).y, t, ((Rect)(ref r)).height), (Texture)(object)Texture2D.whiteTexture);
		GUI.color = color;
	}

	private static string Shorten(string s, int max)
	{
		if (string.IsNullOrEmpty(s))
		{
			return "";
		}
		if (s.Length > max)
		{
			return s.Substring(0, max) + "..";
		}
		return s;
	}

	private static string IconText(string s)
	{
		if (string.IsNullOrEmpty(s))
		{
			return "?";
		}
		if (s.Length < 2)
		{
			return s;
		}
		return s.Substring(0, 2);
	}

	private static string KeyName(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_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Invalid comparison between Unknown and I4
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Invalid comparison between Unknown and I4
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Invalid comparison between Unknown and I4
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Invalid comparison between Unknown and I4
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected I4, but got Unknown
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Invalid comparison between Unknown and I4
		//IL_0031: 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_0036: Expected I4, but got Unknown
		//IL_0053: 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_005f: Expected I4, but got Unknown
		if ((int)k >= 256 && (int)k <= 265)
		{
			return "N" + (k - 256);
		}
		if ((int)k >= 48 && (int)k <= 57)
		{
			return (k - 48).ToString();
		}
		if ((int)k >= 323 && (int)k <= 329)
		{
			return "M" + (k - 323);
		}
		return ((object)k).ToString();
	}

	private string GetSkillDisplayName(ConditionalEvent evt)
	{
		string name = ((Object)((Component)evt).gameObject).name;
		SpecialAbility component = ((Component)evt).GetComponent<SpecialAbility>();
		if ((Object)(object)component != (Object)null && ((CharacterItem)component).Entity != null && !string.IsNullOrEmpty(((CharacterItem)component).Entity.Name))
		{
			name = ((CharacterItem)component).Entity.Name;
		}
		return Translate(name);
	}

	private Sprite GetSkillIcon(ConditionalEvent evt)
	{
		try
		{
			SpecialAbility component = ((Component)evt).GetComponent<SpecialAbility>();
			if ((Object)(object)component != (Object)null && ((CharacterItem)component).Entity != null)
			{
				return ((CharacterItem)component).Entity.SpriteIcon;
			}
		}
		catch
		{
		}
		return null;
	}

	private static string Translate(string key)
	{
		try
		{
			if (_getPhraseMethod == null)
			{
				_getPhraseMethod = typeof(Localizer).GetMethod("GetSinglePhrase", BindingFlags.Static | BindingFlags.Public);
			}
			if (_getPhraseMethod != null)
			{
				string text = _getPhraseMethod.Invoke(null, new object[1] { key }) as string;
				if (!string.IsNullOrEmpty(text))
				{
					return text;
				}
			}
		}
		catch
		{
		}
		return key;
	}
}
public static class SkillControlPatches
{
	public const string SETTINGS_KEY_PREFIX = "SKILL_CONTROL_SLOT_";

	internal static SkillStateManager _stateManager;

	private static SettingsInstance[] _cachedSkillSettings = null;

	public static readonly KeyCode[] AvailableKeys = (KeyCode[])(object)new KeyCode[32]
	{
		(KeyCode)49,
		(KeyCode)50,
		(KeyCode)51,
		(KeyCode)52,
		(KeyCode)53,
		(KeyCode)54,
		(KeyCode)55,
		(KeyCode)56,
		(KeyCode)57,
		(KeyCode)257,
		(KeyCode)258,
		(KeyCode)259,
		(KeyCode)260,
		(KeyCode)261,
		(KeyCode)262,
		(KeyCode)263,
		(KeyCode)264,
		(KeyCode)265,
		(KeyCode)113,
		(KeyCode)101,
		(KeyCode)114,
		(KeyCode)116,
		(KeyCode)122,
		(KeyCode)120,
		(KeyCode)99,
		(KeyCode)118,
		(KeyCode)98,
		(KeyCode)282,
		(KeyCode)283,
		(KeyCode)284,
		(KeyCode)285,
		(KeyCode)286
	};

	public static readonly string[] AvailableKeyNames = new string[32]
	{
		"1", "2", "3", "4", "5", "6", "7", "8", "9", "小键盘1",
		"小键盘2", "小键盘3", "小键盘4", "小键盘5", "小键盘6", "小键盘7", "小键盘8", "小键盘9", "Q", "E",
		"R", "T", "Z", "X", "C", "V", "B", "F1", "F2", "F3",
		"F4", "F5"
	};

	private static readonly KeyCode[] DefaultKeys = (KeyCode[])(object)new KeyCode[9]
	{
		(KeyCode)49,
		(KeyCode)50,
		(KeyCode)51,
		(KeyCode)52,
		(KeyCode)53,
		(KeyCode)54,
		(KeyCode)55,
		(KeyCode)56,
		(KeyCode)57
	};

	public static void Initialize(SkillStateManager stateManager)
	{
		_stateManager = stateManager;
	}

	public static SettingsInstance[] GetSkillSettings()
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Expected O, but got Unknown
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Expected O, but got Unknown
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Expected O, but got Unknown
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
		if (_cachedSkillSettings != null)
		{
			return _cachedSkillSettings;
		}
		FieldInfo field = typeof(SettingsInstance).GetField("m_saveInPlayerPrefs", BindingFlags.Instance | BindingFlags.NonPublic);
		List<SettingsInstance> list = new List<SettingsInstance>();
		SettingsInstance val = new SettingsInstance();
		val.m_settingsKey = "SKILL_CONTROL_SLOT_TITLE";
		val.settingName = "技能控制";
		val.settingsType = (SettingsType)0;
		val.options = new string[1] { "" };
		val.localizeOptions = false;
		val.defaultValue = 0;
		val.currentValue = 0;
		if (field != null)
		{
			field.SetValue(val, false);
		}
		list.Add(val);
		SettingsInstance val2 = new SettingsInstance();
		val2.m_settingsKey = "SKILL_CONTROL_SLOT_FREE_CAST";
		val2.settingName = "自由释放模式";
		val2.settingsType = (SettingsType)0;
		val2.options = new string[2] { "关闭", "开启" };
		val2.localizeOptions = false;
		val2.defaultValue = 1;
		val2.currentValue = ((SkillControlConfig.FreeCastMode != null && SkillControlConfig.FreeCastMode.Value) ? 1 : 0);
		if (field != null)
		{
			field.SetValue(val2, false);
		}
		val2.OnValueChanged += delegate(int value)
		{
			if (SkillControlConfig.FreeCastMode != null)
			{
				SkillControlConfig.FreeCastMode.Value = value == 1;
				Plugin.Log.LogInfo((object)("[SkillControl] 自由释放模式: " + ((value == 1) ? "开启" : "关闭")));
			}
		};
		list.Add(val2);
		for (int num = 0; num < 9; num++)
		{
			SettingsInstance val3 = new SettingsInstance();
			val3.m_settingsKey = "SKILL_CONTROL_SLOT_" + (num + 1);
			val3.settingName = "技能槽位 " + (num + 1);
			val3.settingsType = (SettingsType)0;
			val3.options = AvailableKeyNames;
			val3.localizeOptions = false;
			val3.defaultValue = GetKeyIndex(DefaultKeys[num]);
			val3.currentValue = GetKeyIndex(SkillControlConfig.SkillKeys[num].Value);
			if (field != null)
			{
				field.SetValue(val3, false);
			}
			int slot = num;
			val3.OnValueChanged += delegate(int value)
			{
				if (value >= 0 && value < AvailableKeys.Length)
				{
					SkillControlConfig.SkillKeys[slot].Value = AvailableKeys[value];
					Plugin.Log.LogInfo((object)("[SkillControl] 槽位 " + (slot + 1) + " 按键改为: " + AvailableKeyNames[value]));
				}
			};
			list.Add(val3);
		}
		_cachedSkillSettings = list.ToArray();
		Plugin.Log.LogInfo((object)("[SkillControl] 已创建 " + _cachedSkillSettings.Length + " 个原生设置项 (含标题和自由释放模式)"));
		return _cachedSkillSettings;
	}

	public static int GetKeyIndex(KeyCode key)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Invalid comparison between I4 and Unknown
		for (int i = 0; i < AvailableKeys.Length; i++)
		{
			if ((int)AvailableKeys[i] == (int)key)
			{
				return i;
			}
		}
		return 0;
	}

	public static void SyncConfigToSettings()
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		if (_cachedSkillSettings == null)
		{
			return;
		}
		for (int i = 0; i < 9; i++)
		{
			int num = i + 2;
			if (num >= _cachedSkillSettings.Length)
			{
				break;
			}
			_cachedSkillSettings[num].currentValue = GetKeyIndex(SkillControlConfig.SkillKeys[i].Value);
		}
	}

	public static void SyncSettingsToConfig()
	{
		if (_cachedSkillSettings == null)
		{
			return;
		}
		for (int i = 0; i < 9; i++)
		{
			int num = i + 2;
			if (num >= _cachedSkillSettings.Length)
			{
				break;
			}
			SettingsInstance val = _cachedSkillSettings[num];
			int currentValue = val.currentValue;
			if (currentValue >= 0 && currentValue < AvailableKeys.Length)
			{
				SkillControlConfig.SkillKeys[i].Value = AvailableKeys[currentValue];
			}
		}
	}
}
[HarmonyPatch(typeof(CameraAbilityPossessUI), "StartPossess")]
public static class Patch_HidePossessUI_Start
{
	private static bool Prefix()
	{
		return false;
	}
}
[HarmonyPatch(typeof(CameraAbilityPossessUI), "UpdateCooldowns")]
public static class Patch_HidePossessUI_UpdateCD
{
	private static bool Prefix()
	{
		return false;
	}
}
[HarmonyPatch(typeof(CameraAbilityPossessUI), "UpdateHealth")]
public static class Patch_HidePossessUI_UpdateHP
{
	private static bool Prefix()
	{
		return false;
	}
}
[HarmonyPatch(typeof(CameraAbilityPossessUI), "EndPossess")]
public static class Patch_HidePossessUI_End
{
	private static bool Prefix()
	{
		return false;
	}
}
[HarmonyPatch(typeof(ConditionalEvent), "CheckConditionsUpdate")]
public static class Patch_SkillTrigger
{
	private static bool Prefix(ConditionalEvent __instance, bool forceFail)
	{
		if (SkillControlPatches._stateManager == null)
		{
			return true;
		}
		if (SkillControlPatches._stateManager.SelfInvoking)
		{
			return true;
		}
		if (SkillControlPatches._stateManager.IsManagedSkill(__instance))
		{
			return false;
		}
		return true;
	}
}
[HarmonyPatch(typeof(ConditionalEvent), "CheckCondition")]
public static class Patch_FreeCast
{
	private static bool Prefix(ConditionalEvent __instance, EventCondition condition, ref bool __result)
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		if (SkillControlPatches._stateManager == null)
		{
			return true;
		}
		if (!SkillControlPatches._stateManager.SelfInvoking)
		{
			return true;
		}
		if (SkillControlConfig.FreeCastMode == null || !SkillControlConfig.FreeCastMode.Value)
		{
			return true;
		}
		if ((int)condition.conditionType == 0)
		{
			return true;
		}
		if ((Object)(object)__instance.data == (Object)null || __instance.data.Dead)
		{
			__result = false;
			return false;
		}
		__result = true;
		return false;
	}
}
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
public static class Patch_InjectSettings
{
	private static void Postfix(ref SettingsInstance[] __result)
	{
		try
		{
			SettingsInstance[] skillSettings = SkillControlPatches.GetSkillSettings();
			if (skillSettings == null || skillSettings.Length == 0)
			{
				return;
			}
			bool flag = false;
			if (__result != null)
			{
				SettingsInstance[] array = __result;
				foreach (SettingsInstance val in array)
				{
					if (val != null && val.m_settingsKey != null && val.m_settingsKey.StartsWith("SKILL_CONTROL_SLOT_"))
					{
						flag = true;
						break;
					}
				}
			}
			if (!flag)
			{
				List<SettingsInstance> list = new List<SettingsInstance>((IEnumerable<SettingsInstance>)(((object)__result) ?? ((object)new SettingsInstance[0])));
				list.AddRange(skillSettings);
				__result = list.ToArray();
			}
		}
		catch (Exception ex)
		{
			if (Plugin.Log != null)
			{
				Plugin.Log.LogError((object)("[SkillControl] 注入设置失败: " + ex));
			}
		}
	}
}
public class SkillStateManager
{
	private class SelfInvocationScope : IDisposable
	{
		private readonly SkillStateManager _manager;

		public SelfInvocationScope(SkillStateManager manager)
		{
			_manager = manager;
		}

		public void Dispose()
		{
			_manager._selfInvokingCounter--;
		}
	}

	private readonly HashSet<ConditionalEvent> _managedSkills = new HashSet<ConditionalEvent>();

	private int _selfInvokingCounter;

	public bool SelfInvoking => _selfInvokingCounter > 0;

	public void ClearManagedSkills()
	{
		_managedSkills.Clear();
	}

	public void AddManagedSkill(ConditionalEvent skill)
	{
		_managedSkills.Add(skill);
	}

	public bool IsManagedSkill(ConditionalEvent skill)
	{
		return _managedSkills.Contains(skill);
	}

	public IDisposable BeginSelfInvocation()
	{
		_selfInvokingCounter++;
		return new SelfInvocationScope(this);
	}
}