Decompiled source of PossessionModes v1.0.1

PossessionModes.dll

Decompiled 16 hours 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 InControl;
using Landfall.TABS;
using Landfall.TABS.AI;
using Landfall.TABS_Input;
using TFBGames;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace Saucein.TABS.PossessionModes;

[BepInPlugin("saucein.tabs.possessionmodes", "TABS Possession Modes", "1.3.1")]
public class PossessionModesPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(GlobalSettingsHandler), "OnStorageReady")]
	private static class Patch_GlobalSettingsHandler_OnStorageReady
	{
		private static readonly FieldInfo GameplayField = AccessTools.Field(typeof(GlobalSettingsHandler), "m_gameplaySettings");

		private static readonly FieldInfo DictField = AccessTools.Field(typeof(GlobalSettingsHandler), "m_settingsDict");

		private static void Prefix(GlobalSettingsHandler __instance)
		{
			try
			{
				if (GameplayField == null || ModSetting == null || !(GameplayField.GetValue(__instance) is SettingsInstance[] array))
				{
					return;
				}
				bool flag = false;
				for (int i = 0; i < array.Length; i++)
				{
					if (array[i] != null && array[i].m_settingsKey == "MOD_POSSESS_MODE")
					{
						flag = true;
						break;
					}
				}
				bool flag2 = false;
				if (DictField != null)
				{
					flag2 = DictField.GetValue(__instance) is Dictionary<string, SettingsInstance> dictionary && dictionary.ContainsKey("MOD_POSSESS_MODE");
				}
				if (!flag && !flag2)
				{
					SettingsInstance[] array2 = (SettingsInstance[])(object)new SettingsInstance[array.Length + 1];
					Array.Copy(array, array2, array.Length);
					array2[array.Length] = ModSetting;
					GameplayField.SetValue(__instance, array2);
					Log.LogInfo((object)"Added possession mode setting to Settings -> Gameplay.");
				}
				else if (!flag)
				{
					SettingsInstance[] array3 = (SettingsInstance[])(object)new SettingsInstance[array.Length + 1];
					Array.Copy(array, array3, array.Length);
					array3[array.Length] = ModSetting;
					GameplayField.SetValue(__instance, array3);
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Failed to add gameplay setting: " + ex.Message));
			}
		}
	}

	[HarmonyPatch(typeof(Localizer), "GetSinglePhrase", new Type[]
	{
		typeof(string),
		typeof(string[])
	})]
	private static class Patch_Localizer_GetSinglePhrase
	{
		private static bool Prefix(string phraseID, ref string __result)
		{
			if (TryGetText(phraseID, out var text))
			{
				__result = text;
				return false;
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(CameraAbilityPossess), "EnterUnit")]
	private static class Patch_CameraAbilityPossess_EnterUnit
	{
		private static void Postfix(CameraAbilityPossess __instance, Unit unitAPI)
		{
			if ((Object)(object)unitAPI == (Object)null)
			{
				return;
			}
			int currentMode = CurrentMode;
			State.Possess = __instance;
			State.Unit = unitAPI;
			State.UnitAPI = ((Component)unitAPI).GetComponent<UnitAPI>();
			State.PlayerActions = State.GetPlayerActions(__instance);
			State.GeneralInput = ((Component)unitAPI).GetComponentInChildren<GeneralInput>();
			State.WeaponHandler = ((Component)unitAPI).GetComponentInChildren<WeaponHandler>();
			State.ConditionalEvents = ((Component)unitAPI).GetComponentsInChildren<ConditionalEvent>(true);
			State.HybridControlActive = false;
			State.LastPlayerInputTime = Time.unscaledTime;
			State.LastPlayerMoveTime = -1000f;
			State.LastPlayerAttackTime = -1000f;
			State.LastPlayerSkillTime = -1000f;
			if (currentMode == 1 || currentMode == 2)
			{
				if ((Object)(object)State.UnitAPI != (Object)null)
				{
					State.UnitAPI.SetActive(true, (bool?)true);
				}
				if ((Object)(object)State.GeneralInput != (Object)null)
				{
					State.GeneralInput.hasControl = false;
				}
				State.SetRotatingMouseLook(value: true);
			}
			else if (currentMode >= 4 && (Object)(object)State.UnitAPI != (Object)null)
			{
				State.UnitAPI.SetActive(true, (bool?)true);
			}
		}
	}

	[HarmonyPatch(typeof(CameraAbilityPossess), "ExitUnit")]
	private static class Patch_CameraAbilityPossess_ExitUnit
	{
		private static void Postfix()
		{
			State.Clear();
		}
	}

	[HarmonyPatch(typeof(CameraAbilityPossess), "LateUpdate")]
	private static class Patch_CameraAbilityPossess_LateUpdate
	{
		private static void Prefix(CameraAbilityPossess __instance)
		{
			int currentMode = CurrentMode;
			if ((Object)(object)State.Unit == (Object)null || currentMode == 0 || currentMode == 3)
			{
				return;
			}
			PlayerActions actions = (State.PlayerActions = State.PlayerActions ?? State.GetPlayerActions(__instance));
			if (currentMode >= 4)
			{
				State.UpdateChannelInput(actions);
				return;
			}
			if (currentMode == 2)
			{
				State.SuppressPlayerAttackActions(__instance, actions);
				return;
			}
			if (State.HasPlayerInput(actions))
			{
				State.LastPlayerInputTime = Time.unscaledTime;
			}
			float num = ((HybridIdleDelay == null) ? 0.1f : Mathf.Max(0.05f, HybridIdleDelay.Value));
			bool flag = Time.unscaledTime - State.LastPlayerInputTime <= num;
			if (flag != State.HybridControlActive)
			{
				State.ApplyHybridControl(flag);
			}
			if (!flag)
			{
				State.SuppressPlayerAttackActions(__instance, actions);
			}
		}

		private static void Postfix()
		{
			State.RestorePlayerAttackActions();
		}
	}

	[HarmonyPatch(typeof(GeneralInput), "Update")]
	private static class Patch_GeneralInput_Update
	{
		private static void Prefix(GeneralInput __instance, out Vector3 __state)
		{
			//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)
			__state = __instance.inputDirection;
			if (!((Object)(object)State.GeneralInput == (Object)null) && __instance == State.GeneralInput)
			{
				switch (CurrentMode)
				{
				case 2:
					__instance.hasControl = false;
					break;
				case 1:
					__instance.hasControl = State.HybridControlActive;
					break;
				}
			}
		}

		private static void Postfix(GeneralInput __instance, Vector3 __state)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			if (CurrentMode >= 4 && !((Object)(object)State.GeneralInput == (Object)null) && __instance == State.GeneralInput && State.AiCanMove && !State.PlayerMoveHeld)
			{
				__instance.inputDirection = __state;
			}
		}
	}

	[HarmonyPatch(typeof(UnitAPI), "SetMovementSpeed")]
	private static class Patch_UnitAPI_SetMovementSpeed
	{
		private static bool Prefix(UnitAPI __instance)
		{
			if (CurrentMode < 4 || !State.IsCurrentUnitApi(__instance))
			{
				return true;
			}
			return State.AiCanMove;
		}
	}

	[HarmonyPatch(typeof(UnitAPI), "SetLookDirection")]
	private static class Patch_UnitAPI_SetLookDirection
	{
		private static bool Prefix(UnitAPI __instance)
		{
			if (CurrentMode < 4 || !State.IsCurrentUnitApi(__instance))
			{
				return true;
			}
			return State.AiCanLook;
		}
	}

	[HarmonyPatch(typeof(UnitAPI), "SetAttackTarget")]
	private static class Patch_UnitAPI_SetAttackTarget
	{
		private static void Prefix(UnitAPI __instance, ref bool startAttack)
		{
			if (CurrentMode >= 4 && State.IsCurrentUnitApi(__instance) && !State.AiCanAttack)
			{
				startAttack = false;
			}
		}
	}

	[HarmonyPatch(typeof(WeaponHandler), "Attack")]
	private static class Patch_WeaponHandler_Attack
	{
		private static bool Prefix(WeaponHandler __instance, Vector3 position, Rigidbody targetRig, Vector3 forceDirection, ForceWeapon forceWeapon)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			if ((int)forceWeapon == 0)
			{
				return true;
			}
			if ((Object)(object)State.WeaponHandler == (Object)null || __instance != State.WeaponHandler)
			{
				return true;
			}
			return !IsSuppressed;
		}
	}

	[HarmonyPatch(typeof(ConditionalEvent), "Update")]
	private static class Patch_ConditionalEvent_Update
	{
		private static void Prefix(ConditionalEvent __instance)
		{
			State.BeginAiSkillDecision(__instance);
		}

		private static void Postfix()
		{
			State.EndAiSkillDecision();
		}
	}

	[HarmonyPatch(typeof(ConditionalEvent), "OnUnitAttacked")]
	private static class Patch_ConditionalEvent_OnUnitAttacked
	{
		private static void Prefix(ConditionalEvent __instance)
		{
			State.BeginAiSkillDecision(__instance);
		}

		private static void Postfix()
		{
			State.EndAiSkillDecision();
		}
	}

	[HarmonyPatch(typeof(ConditionalEvent), "OnUnitDamaged")]
	private static class Patch_ConditionalEvent_OnUnitDamaged
	{
		private static void Prefix(ConditionalEvent __instance)
		{
			State.BeginAiSkillDecision(__instance);
		}

		private static void Postfix()
		{
			State.EndAiSkillDecision();
		}
	}

	[HarmonyPatch(typeof(ConditionalEvent), "OnDealDamage")]
	private static class Patch_ConditionalEvent_OnDealDamage
	{
		private static void Prefix(ConditionalEvent __instance)
		{
			State.BeginAiSkillDecision(__instance);
		}

		private static void Postfix()
		{
			State.EndAiSkillDecision();
		}
	}

	[HarmonyPatch(typeof(ConditionalEvent), "OnUnitAttack")]
	private static class Patch_ConditionalEvent_OnUnitAttack
	{
		private static void Prefix(ConditionalEvent __instance)
		{
			State.BeginAiSkillDecision(__instance);
		}

		private static void Postfix()
		{
			State.EndAiSkillDecision();
		}
	}

	[HarmonyPatch(typeof(ConditionalEvent), "CheckConditionsUpdate")]
	private static class Patch_ConditionalEvent_CheckConditionsUpdate
	{
		private static bool Prefix(ConditionalEvent __instance, bool forceFail)
		{
			if (!forceFail || !ShouldSuppressForceFail)
			{
				return true;
			}
			return !State.IsCurrentConditionalEvent(__instance);
		}
	}

	private static class State
	{
		internal static CameraAbilityPossess Possess;

		internal static Unit Unit;

		internal static UnitAPI UnitAPI;

		internal static PlayerActions PlayerActions;

		internal static GeneralInput GeneralInput;

		internal static WeaponHandler WeaponHandler;

		internal static ConditionalEvent[] ConditionalEvents;

		internal static bool HybridControlActive;

		internal static float LastPlayerInputTime;

		internal static float LastPlayerMoveTime;

		internal static float LastPlayerAttackTime;

		internal static float LastPlayerSkillTime;

		private static int aiSkillDecisionDepth;

		private static bool aiSkillRestoreControl;

		private static readonly FieldInfo PlayerCameraField = AccessTools.Field(typeof(CameraAbilityPossess), "m_playerCamera");

		private static readonly FieldInfo RotatingMouseLookField = AccessTools.Field(typeof(CameraAbilityPossess), "m_rotatingMouseLook");

		private static readonly List<PlayerAction> SuppressedActions = new List<PlayerAction>();

		private static readonly List<bool> SuppressedEnabled = new List<bool>();

		private static float IdleDelay
		{
			get
			{
				if (HybridIdleDelay != null)
				{
					return Mathf.Max(0.05f, HybridIdleDelay.Value);
				}
				return 0.1f;
			}
		}

		internal static bool PlayerMoveHeld
		{
			get
			{
				if (PlayerActions != null)
				{
					if (!(Mathf.Abs(((TwoAxisInputControl)PlayerActions.m_move).X) > 0.05f))
					{
						return Mathf.Abs(((TwoAxisInputControl)PlayerActions.m_move).Y) > 0.05f;
					}
					return true;
				}
				return false;
			}
		}

		internal static bool PlayerAttackHeld
		{
			get
			{
				if (PlayerActions != null)
				{
					if (!IsPressed(PlayerActions.m_possessAttack1))
					{
						return IsPressed(PlayerActions.m_possessAttack2);
					}
					return true;
				}
				return false;
			}
		}

		internal static bool PlayerSkillHeld
		{
			get
			{
				if (PlayerActions != null)
				{
					return IsPressed(PlayerActions.m_possessAttack3);
				}
				return false;
			}
		}

		internal static bool AiCanMove
		{
			get
			{
				switch (CurrentMode)
				{
				case 4:
					return true;
				case 5:
				case 7:
				case 8:
					return !PlayerRecently(LastPlayerMoveTime);
				default:
					return false;
				}
			}
		}

		internal static bool AiCanAttack
		{
			get
			{
				switch (CurrentMode)
				{
				case 4:
					return true;
				case 5:
				case 6:
				case 9:
					return !PlayerRecently(LastPlayerAttackTime);
				default:
					return false;
				}
			}
		}

		internal static bool AiCanSkill
		{
			get
			{
				switch (CurrentMode)
				{
				case 3:
				case 4:
					return true;
				case 6:
				case 7:
					return !PlayerRecently(LastPlayerSkillTime);
				default:
					return false;
				}
			}
		}

		internal static bool AiCanLook
		{
			get
			{
				if (CurrentMode < 4 || PlayerRecently(LastPlayerMoveTime))
				{
					return false;
				}
				if (!AiCanMove && !AiCanAttack)
				{
					return AiCanSkill;
				}
				return true;
			}
		}

		private static bool PlayerRecently(float time)
		{
			return Time.unscaledTime - time <= IdleDelay;
		}

		internal static void UpdateChannelInput(PlayerActions actions)
		{
			PlayerActions = actions;
			float unscaledTime = Time.unscaledTime;
			if (PlayerMoveHeld)
			{
				LastPlayerMoveTime = unscaledTime;
			}
			if (PlayerAttackHeld)
			{
				LastPlayerAttackTime = unscaledTime;
			}
			if (PlayerSkillHeld)
			{
				LastPlayerSkillTime = unscaledTime;
			}
			SetRotatingMouseLook(!PlayerMoveHeld);
		}

		internal static bool IsCurrentUnitApi(UnitAPI api)
		{
			if ((Object)(object)api != (Object)null && (Object)(object)UnitAPI != (Object)null)
			{
				return api == UnitAPI;
			}
			return false;
		}

		internal static PlayerActions GetPlayerActions(CameraAbilityPossess possess)
		{
			if ((Object)(object)possess == (Object)null || PlayerCameraField == null)
			{
				return null;
			}
			object? value = PlayerCameraField.GetValue(possess);
			PlayerCamera val = (PlayerCamera)((value is PlayerCamera) ? value : null);
			if (!((Object)(object)val == (Object)null))
			{
				return val.Actions;
			}
			return null;
		}

		internal static void SetRotatingMouseLook(bool value)
		{
			if ((Object)(object)Possess != (Object)null && RotatingMouseLookField != null)
			{
				RotatingMouseLookField.SetValue(Possess, value);
			}
		}

		internal static bool HasPlayerInput(PlayerActions actions)
		{
			if (actions == null)
			{
				return false;
			}
			if (Mathf.Abs(((TwoAxisInputControl)actions.m_move).X) > 0.05f || Mathf.Abs(((TwoAxisInputControl)actions.m_move).Y) > 0.05f)
			{
				return true;
			}
			if (IsPressed(actions.m_possessAttack1) || IsPressed(actions.m_possessAttack2) || IsPressed(actions.m_possessAttack3) || IsPressed(actions.m_moveFast))
			{
				return true;
			}
			return false;
		}

		private static bool IsPressed(PlayerAction action)
		{
			if (action != null)
			{
				if (!((OneAxisInputControl)action).IsPressed)
				{
					return ((OneAxisInputControl)action).WasPressed;
				}
				return true;
			}
			return false;
		}

		internal static void ApplyHybridControl(bool controlling)
		{
			HybridControlActive = controlling;
			if ((Object)(object)Unit != (Object)null)
			{
				UnitAPI component = ((Component)Unit).GetComponent<UnitAPI>();
				if ((Object)(object)component != (Object)null)
				{
					component.SetActive(!controlling, (bool?)true);
				}
			}
			if ((Object)(object)GeneralInput != (Object)null)
			{
				GeneralInput.hasControl = controlling;
			}
			SetRotatingMouseLook(!controlling);
		}

		internal static void SuppressPlayerAttackActions(CameraAbilityPossess possess, PlayerActions actions)
		{
			RestorePlayerAttackActions();
			if (actions != null)
			{
				AddIfEnabled(actions.m_possessAttack1);
				AddIfEnabled(actions.m_possessAttack2);
				AddIfEnabled(actions.m_possessAttack3);
			}
			SetRotatingMouseLook(value: true);
		}

		private static void AddIfEnabled(PlayerAction action)
		{
			if (action != null && ((OneAxisInputControl)action).Enabled)
			{
				SuppressedActions.Add(action);
				SuppressedEnabled.Add(item: true);
				((OneAxisInputControl)action).Enabled = false;
			}
		}

		internal static void RestorePlayerAttackActions()
		{
			for (int i = 0; i < SuppressedActions.Count; i++)
			{
				try
				{
					((OneAxisInputControl)SuppressedActions[i]).Enabled = SuppressedEnabled[i];
				}
				catch (Exception)
				{
				}
			}
			SuppressedActions.Clear();
			SuppressedEnabled.Clear();
		}

		internal static void BeginAiSkillDecision(ConditionalEvent conditionalEvent)
		{
			if (AiCanSkill && !((Object)(object)GeneralInput == (Object)null) && IsCurrentConditionalEvent(conditionalEvent))
			{
				if (aiSkillDecisionDepth == 0 && GeneralInput.hasControl)
				{
					GeneralInput.hasControl = false;
					aiSkillRestoreControl = true;
				}
				aiSkillDecisionDepth++;
			}
		}

		internal static void EndAiSkillDecision()
		{
			if (aiSkillDecisionDepth == 0)
			{
				return;
			}
			aiSkillDecisionDepth--;
			if (aiSkillDecisionDepth == 0)
			{
				if (aiSkillRestoreControl && (Object)(object)GeneralInput != (Object)null)
				{
					GeneralInput.hasControl = true;
				}
				aiSkillRestoreControl = false;
			}
		}

		internal static bool IsCurrentConditionalEvent(ConditionalEvent conditionalEvent)
		{
			if (ConditionalEvents == null || (Object)(object)conditionalEvent == (Object)null)
			{
				return false;
			}
			for (int i = 0; i < ConditionalEvents.Length; i++)
			{
				if (ConditionalEvents[i] == conditionalEvent)
				{
					return true;
				}
			}
			return false;
		}

		internal static void Clear()
		{
			RestorePlayerAttackActions();
			Possess = null;
			Unit = null;
			UnitAPI = null;
			PlayerActions = null;
			GeneralInput = null;
			WeaponHandler = null;
			ConditionalEvents = null;
			HybridControlActive = false;
			LastPlayerInputTime = 0f;
			LastPlayerMoveTime = 0f;
			LastPlayerAttackTime = 0f;
			LastPlayerSkillTime = 0f;
			aiSkillDecisionDepth = 0;
			aiSkillRestoreControl = false;
		}
	}

	public const string PluginGuid = "saucein.tabs.possessionmodes";

	public const string PluginName = "TABS Possession Modes";

	public const string PluginVersion = "1.3.1";

	private const string SettingKey = "MOD_POSSESS_MODE";

	internal static ManualLogSource Log;

	internal static SettingsInstance ModSetting;

	internal static ConfigEntry<float> HybridIdleDelay;

	private static readonly Dictionary<string, string> ChineseText = new Dictionary<string, string>
	{
		{ "MOD_POSSESS_MODE", "控制模式" },
		{ "MOD_POSSESS_MODE_FULL", "原版控制" },
		{ "MOD_POSSESS_MODE_HYBRID", "挂机托管" },
		{ "MOD_POSSESS_MODE_SPECTATE", "旁观者" },
		{ "MOD_POSSESS_MODE_AUTO_SKILL", "AI控制技能" },
		{ "MOD_POSSESS_MODE_DUAL", "双重人格" },
		{ "MOD_POSSESS_MODE_MOVE_ATTACK", "AI控制移动和攻击" },
		{ "MOD_POSSESS_MODE_ATTACK_SKILL", "AI控制攻击和技能" },
		{ "MOD_POSSESS_MODE_MOVE_SKILL", "AI控制移动和技能" },
		{ "MOD_POSSESS_MODE_MOVE", "AI控制移动" },
		{ "MOD_POSSESS_MODE_ATTACK", "AI控制攻击" },
		{ "MOD_POSSESS_MODE_TOOLTIP", "控制兵种时生效" }
	};

	private static readonly Dictionary<string, string> EnglishText = new Dictionary<string, string>
	{
		{ "MOD_POSSESS_MODE", "Possession Mode" },
		{ "MOD_POSSESS_MODE_FULL", "Vanilla Possess" },
		{ "MOD_POSSESS_MODE_HYBRID", "Hybrid (AI when idle)" },
		{ "MOD_POSSESS_MODE_SPECTATE", "Spectator (AI control)" },
		{ "MOD_POSSESS_MODE_AUTO_SKILL", "AI Ability" },
		{ "MOD_POSSESS_MODE_DUAL", "Dual Personality" },
		{ "MOD_POSSESS_MODE_MOVE_ATTACK", "AI Move+Attack" },
		{ "MOD_POSSESS_MODE_ATTACK_SKILL", "AI Attack+Ability" },
		{ "MOD_POSSESS_MODE_MOVE_SKILL", "AI Move+Ability" },
		{ "MOD_POSSESS_MODE_MOVE", "AI Move" },
		{ "MOD_POSSESS_MODE_ATTACK", "AI Attack" },
		{ "MOD_POSSESS_MODE_TOOLTIP", "Active while possessing a unit" }
	};

	internal static int CurrentMode
	{
		get
		{
			if (ModSetting != null)
			{
				return Mathf.Clamp(ModSetting.currentValue, 0, 9);
			}
			try
			{
				GlobalSettingsHandler service = ServiceLocator.GetService<GlobalSettingsHandler>();
				SettingsInstance val = (((Object)(object)service == (Object)null) ? null : service.GetSettingsInstance("MOD_POSSESS_MODE"));
				return (val != null) ? Mathf.Clamp(val.currentValue, 0, 9) : 0;
			}
			catch (Exception)
			{
				return 0;
			}
		}
	}

	private static bool IsSuppressed => CurrentMode switch
	{
		2 => true, 
		1 => !State.HybridControlActive, 
		_ => false, 
	};

	private static bool ShouldSuppressForceFail
	{
		get
		{
			int currentMode = CurrentMode;
			if (currentMode != 3 && !IsSuppressed)
			{
				if (currentMode >= 4)
				{
					return State.AiCanSkill;
				}
				return false;
			}
			return true;
		}
	}

	private void Awake()
	{
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		HybridIdleDelay = ((BaseUnityPlugin)this).Config.Bind<float>("General", "HybridIdleDelay", 0.1f, "半操控模式下,停止输入后多久恢复兵种 AI(秒)。");
		ModSetting = CreateSetting();
		new Harmony("saucein.tabs.possessionmodes").PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"TABS Possession Modes loaded. Setting: 設定-游戏 -> 操控模式.");
	}

	private static SettingsInstance CreateSetting()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Expected O, but got Unknown
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		SettingsInstance val = new SettingsInstance();
		val.m_settingsKey = "MOD_POSSESS_MODE";
		val.m_platform = (Platform)1;
		val.settingsType = (SettingsType)0;
		val.localizeOptions = true;
		val.options = new string[10] { "MOD_POSSESS_MODE_FULL", "MOD_POSSESS_MODE_HYBRID", "MOD_POSSESS_MODE_SPECTATE", "MOD_POSSESS_MODE_AUTO_SKILL", "MOD_POSSESS_MODE_DUAL", "MOD_POSSESS_MODE_MOVE_ATTACK", "MOD_POSSESS_MODE_ATTACK_SKILL", "MOD_POSSESS_MODE_MOVE_SKILL", "MOD_POSSESS_MODE_MOVE", "MOD_POSSESS_MODE_ATTACK" };
		val.defaultValue = 0;
		val.currentValue = 0;
		val.toolTip = "MOD_POSSESS_MODE_TOOLTIP";
		return val;
	}

	private static bool TryGetText(string key, out string text)
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Invalid comparison between Unknown and I4
		if (string.IsNullOrEmpty(key))
		{
			text = null;
			return false;
		}
		bool flag = true;
		try
		{
			FieldInfo fieldInfo = AccessTools.Field(typeof(Localizer), "m_locale");
			object obj = ((fieldInfo == null) ? null : fieldInfo.GetValue(null));
			flag = obj is Language && (int)(Language)obj == 7;
		}
		catch (Exception)
		{
			flag = true;
		}
		if ((flag ? ChineseText : EnglishText).TryGetValue(key, out text))
		{
			return true;
		}
		text = null;
		return false;
	}
}