Decompiled source of oathbound addon v1.0.0

OathboundAddon.dll

Decompiled a week ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using Warrior.Mod;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace OathboundAddon
{
	public enum WolfStance
	{
		FreeHunt,
		Stay,
		Heel
	}
	[BepInPlugin("com.aitod.valheim.oathboundaddon", "Oathbound Addon", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class OathboundAddonPlugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__CloseCommandWindow;
		}

		public const string ModGUID = "com.aitod.valheim.oathboundaddon";

		public const string ModName = "Oathbound Addon";

		public const string ModVersion = "1.0.0";

		public static OathboundAddonPlugin Instance;

		public static ManualLogSource Log;

		private Harmony _harmony;

		public static FieldRef<MonsterAI, Character> TargetCreatureRef;

		public static ConfigEntry<KeyCode> CommandWindowKey;

		public static ConfigEntry<bool> HoldMode;

		public static ConfigEntry<bool> ShowHudBadge;

		public static ConfigEntry<float> BadgePosX;

		public static ConfigEntry<float> BadgePosY;

		public static WolfStance CurrentStance = WolfStance.FreeHunt;

		public static bool IsWindowOpen = false;

		public static Vector3 StayPosition = Vector3.zero;

		public static HunterCompanion ActiveCompanion;

		public static Character ActiveWolfCharacter;

		public static MonsterAI ActiveWolfMonsterAI;

		public static BaseAI ActiveWolfBaseAI;

		public const string ZdoStanceKey = "oathbound.addon.stance";

		private static bool _skinsLoaded = false;

		private static Image _panelSkin;

		private static Image _cardSkin;

		private static Button _buttonSkin;

		private static TMP_Text _headingSkin;

		private static TMP_Text _detailSkin;

		private static GameObject _windowUi;

		private static TextMeshProUGUI[] _cardStateTexts = (TextMeshProUGUI[])(object)new TextMeshProUGUI[4];

		private static Image[] _cardBackgrounds = (Image[])(object)new Image[4];

		private static GameObject _hudBadgeObj;

		private static TextMeshProUGUI _hudBadgeText;

		private void Awake()
		{
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			CommandWindowKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "CommandWindowKey", (KeyCode)103, "Key to open/toggle the Hunter Companion command window.");
			HoldMode = ((BaseUnityPlugin)this).Config.Bind<bool>("Controls", "HoldMode", false, "If true, hold key to display window and release to close. If false (default), press key to toggle window.");
			ShowHudBadge = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "ShowHudBadge", true, "Show the subtle, semi-transparent wolf stance badge on your HUD.");
			BadgePosX = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "BadgePosX", 0.5f, "Horizontal screen position of the HUD stance badge (0.0 to 1.0, 0.5 = center).");
			BadgePosY = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "BadgePosY", 0.88f, "Vertical screen position of the HUD stance badge (0.0 = top, 1.0 = bottom).");
			try
			{
				TargetCreatureRef = AccessTools.FieldRefAccess<MonsterAI, Character>("m_targetCreature");
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Failed to bind TargetCreatureRef: " + ex.Message));
			}
			_harmony = new Harmony("com.aitod.valheim.oathboundaddon");
			TryPatch(typeof(Patch_MonsterAI_UpdateAI));
			TryPatch(typeof(Patch_BaseAI_CanSenseTarget));
			TryPatch(typeof(Patch_HunterCompanion_Awake));
			TryPatch(typeof(Patch_Character_OnDeath));
			TryPatch(typeof(Patch_GameCamera_UpdateMouseCapture));
			TryPatch(typeof(Patch_PlayerController_InInventoryEtc));
			Log.LogInfo((object)"Oathbound Addon v1.0.0 initialization complete!");
		}

		private void TryPatch(Type t)
		{
			try
			{
				_harmony.PatchAll(t);
				Log.LogInfo((object)("Successfully applied patch: " + t.Name));
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Failed to apply patch " + t.Name + ": " + ex.Message));
			}
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			if ((Object)(object)_windowUi != (Object)null)
			{
				Object.Destroy((Object)(object)_windowUi);
			}
			if ((Object)(object)_hudBadgeObj != (Object)null)
			{
				Object.Destroy((Object)(object)_hudBadgeObj);
			}
		}

		public static void RegisterCompanion(HunterCompanion comp)
		{
			if ((Object)(object)comp == (Object)null)
			{
				ActiveCompanion = null;
				ActiveWolfCharacter = null;
				ActiveWolfMonsterAI = null;
				ActiveWolfBaseAI = null;
				SetHudBadgeVisible(visible: false);
			}
			else
			{
				ActiveCompanion = comp;
				ActiveWolfCharacter = ((Component)comp).GetComponent<Character>();
				ActiveWolfMonsterAI = ((Component)comp).GetComponent<MonsterAI>();
				ActiveWolfBaseAI = ((Component)comp).GetComponent<BaseAI>();
				SetHudBadgeVisible(!IsWindowOpen);
			}
		}

		private void Update()
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead())
			{
				if (IsWindowOpen)
				{
					CloseCommandWindow();
				}
				return;
			}
			if (IsWindowOpen)
			{
				if ((Object)(object)ActiveWolfCharacter == (Object)null || ActiveWolfCharacter.IsDead())
				{
					CloseCommandWindow();
					return;
				}
				if (Input.GetKeyDown((KeyCode)27))
				{
					CloseCommandWindow();
					return;
				}
				if (HoldMode.Value && Input.GetKeyUp(CommandWindowKey.Value))
				{
					CloseCommandWindow();
					return;
				}
			}
			if (!Input.GetKeyDown(CommandWindowKey.Value))
			{
				return;
			}
			if (IsWindowOpen)
			{
				CloseCommandWindow();
				return;
			}
			Chat instance = Chat.instance;
			if ((instance != null && instance.IsChatDialogWindowVisible()) || Console.IsVisible() || InventoryGui.IsVisible() || Menu.IsVisible())
			{
				return;
			}
			if (!IsLocalPlayerHunter(localPlayer))
			{
				MessageHud instance2 = MessageHud.instance;
				if (instance2 != null)
				{
					instance2.ShowMessage((MessageType)2, "<color=#E74C3C>Wolf Command: Only available for Hunter class</color>", 0, (Sprite)null, false, true);
				}
				return;
			}
			if ((Object)(object)ActiveWolfCharacter == (Object)null || ActiveWolfCharacter.IsDead())
			{
				FindLocalHunterPet(localPlayer);
			}
			if ((Object)(object)ActiveWolfCharacter == (Object)null || ActiveWolfCharacter.IsDead())
			{
				MessageHud instance3 = MessageHud.instance;
				if (instance3 != null)
				{
					instance3.ShowMessage((MessageType)2, "<color=#E67E22>Wolf Command: Wolf not summoned (Aim & Press H to call)</color>", 0, (Sprite)null, false, true);
				}
			}
			else
			{
				OpenCommandWindow(localPlayer, ActiveWolfCharacter);
			}
		}

		public static void OpenCommandWindow(Player player, Character pet)
		{
			if (!((Object)(object)player == (Object)null) && !((Object)(object)pet == (Object)null))
			{
				LoadUiSkins();
				EnsureCommandWindowBuilt(player, pet);
				if ((Object)(object)_windowUi != (Object)null)
				{
					_windowUi.SetActive(true);
					UpdateCardStates();
					IsWindowOpen = true;
					ZCursor.LockState = (CursorLockMode)0;
					ZCursor.Show();
					SetHudBadgeVisible(visible: false);
				}
			}
		}

		public static void CloseCommandWindow()
		{
			if (!IsWindowOpen)
			{
				return;
			}
			IsWindowOpen = false;
			if ((Object)(object)_windowUi != (Object)null)
			{
				_windowUi.SetActive(false);
			}
			if ((Object)(object)Player.m_localPlayer != (Object)null && !InventoryGui.IsVisible())
			{
				Chat instance = Chat.instance;
				if ((instance == null || !instance.IsChatDialogWindowVisible()) && !Menu.IsVisible())
				{
					ZCursor.LockState = (CursorLockMode)1;
					ZCursor.Hide();
				}
			}
			SetHudBadgeVisible((Object)(object)ActiveWolfCharacter != (Object)null && !ActiveWolfCharacter.IsDead());
		}

		private static void LoadUiSkins()
		{
			if ((_skinsLoaded && (Object)(object)_panelSkin != (Object)null) || (Object)(object)InventoryGui.instance == (Object)null)
			{
				return;
			}
			try
			{
				Transform val = ((Component)InventoryGui.instance).transform.Find("root/Skills/SkillsFrame");
				if ((Object)(object)val != (Object)null)
				{
					Transform obj = val.Find("bkg");
					_panelSkin = ((obj != null) ? ((Component)obj).GetComponent<Image>() : null);
					Transform obj2 = val.Find("Skills/SkillList");
					_cardSkin = ((obj2 != null) ? ((Component)obj2).GetComponent<Image>() : null);
					Transform obj3 = val.Find("Closebutton");
					_buttonSkin = ((obj3 != null) ? ((Component)obj3).GetComponent<Button>() : null);
					Transform obj4 = val.Find("topic");
					_headingSkin = ((obj4 != null) ? ((Component)obj4).GetComponent<TMP_Text>() : null);
					Transform obj5 = val.Find("Skills/SkillList/SkillElement/levelbar/leveltext");
					_detailSkin = ((obj5 != null) ? ((Component)obj5).GetComponent<TMP_Text>() : null);
					_skinsLoaded = true;
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = Log;
				if (log != null)
				{
					log.LogWarning((object)("Failed to load native UI skins: " + ex.Message));
				}
			}
		}

		private static RectTransform CreateRect(Transform parent, string name, float x, float y, float w, float h, Vector2 pivot, Vector2 anchorMin, Vector2 anchorMax)
		{
			//IL_0014: 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_002f: 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_0042: 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)
			RectTransform component = new GameObject(name, new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>();
			((Transform)component).SetParent(parent, false);
			component.pivot = pivot;
			component.anchorMin = anchorMin;
			component.anchorMax = anchorMax;
			component.anchoredPosition = new Vector2(x, 0f - y);
			component.sizeDelta = new Vector2(w, h);
			return component;
		}

		private static Image SkinImage(RectTransform rt, Image template, Color color)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			Image val = ((Component)rt).gameObject.AddComponent<Image>();
			if ((Object)(object)template != (Object)null)
			{
				val.sprite = template.sprite;
				val.type = template.type;
				((Graphic)val).material = ((Graphic)template).material;
				val.pixelsPerUnitMultiplier = template.pixelsPerUnitMultiplier;
			}
			((Graphic)val).color = color;
			((Graphic)val).raycastTarget = false;
			return val;
		}

		private static TextMeshProUGUI CreateText(Transform parent, string name, string text, float x, float y, float w, float h, float size, TMP_Text skin, Color color, TextAlignmentOptions alignment)
		{
			//IL_0013: 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_0031: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI val = ((Component)CreateRect(parent, name, x, y, w, h, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(0f, 1f))).gameObject.AddComponent<TextMeshProUGUI>();
			if ((Object)(object)skin != (Object)null)
			{
				((TMP_Text)val).font = skin.font;
				((TMP_Text)val).fontSharedMaterial = skin.fontSharedMaterial;
			}
			((TMP_Text)val).fontSize = size;
			((Graphic)val).color = color;
			((TMP_Text)val).alignment = alignment;
			((TMP_Text)val).textWrappingMode = (TextWrappingModes)1;
			((TMP_Text)val).richText = true;
			((Graphic)val).raycastTarget = false;
			((TMP_Text)val).text = text;
			return val;
		}

		private static Sprite GetItemIcon(string prefabName)
		{
			try
			{
				if ((Object)(object)ObjectDB.instance != (Object)null)
				{
					GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(prefabName);
					if ((Object)(object)itemPrefab != (Object)null)
					{
						ItemDrop component = itemPrefab.GetComponent<ItemDrop>();
						if ((Object)(object)component != (Object)null && component.m_itemData != null)
						{
							return component.m_itemData.GetIcon();
						}
					}
				}
			}
			catch
			{
			}
			return null;
		}

		private static void EnsureCommandWindowBuilt(Player player, Character pet)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Expected O, but got Unknown
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_040d: Unknown result type (might be due to invalid IL or missing references)
			//IL_041c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0443: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04af: Expected O, but got Unknown
			//IL_04d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_048c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0553: Unknown result type (might be due to invalid IL or missing references)
			//IL_0531: Unknown result type (might be due to invalid IL or missing references)
			//IL_058f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0579: Unknown result type (might be due to invalid IL or missing references)
			//IL_0594: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0606: Unknown result type (might be due to invalid IL or missing references)
			//IL_0656: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_windowUi != (Object)null || (Object)(object)InventoryGui.instance == (Object)null)
			{
				return;
			}
			_windowUi = new GameObject("OathboundHunterCommandWindow", new Type[4]
			{
				typeof(RectTransform),
				typeof(Canvas),
				typeof(CanvasScaler),
				typeof(GraphicRaycaster)
			});
			_windowUi.transform.SetParent(((Component)InventoryGui.instance).transform.parent, false);
			Canvas component = _windowUi.GetComponent<Canvas>();
			component.renderMode = (RenderMode)0;
			component.sortingOrder = ((Component)InventoryGui.instance).GetComponentInParent<Canvas>().sortingOrder + 1;
			CanvasScaler component2 = _windowUi.GetComponent<CanvasScaler>();
			component2.uiScaleMode = (ScaleMode)1;
			component2.referenceResolution = new Vector2(1280f, 800f);
			component2.screenMatchMode = (ScreenMatchMode)0;
			component2.matchWidthOrHeight = 0.5f;
			float w = 800f;
			float h = 310f;
			RectTransform val = CreateRect(_windowUi.transform, "Panel", 0f, 0f, w, h, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f));
			val.anchoredPosition = Vector2.zero;
			((Graphic)SkinImage(val, _panelSkin, new Color(0.12f, 0.1f, 0.08f, 0.96f))).raycastTarget = true;
			CreateText((Transform)(object)val, "Title", "HUNTER COMPANION COMMANDS", 24f, 16f, 720f, 34f, 24f, _headingSkin, new Color(1f, 0.85f, 0.4f), (TextAlignmentOptions)514);
			CreateText((Transform)(object)val, "Subtitle", "Click a command to set stance · Press Esc to close · Aim & Press H to Set Upon", 24f, 50f, 720f, 22f, 13f, _detailSkin, new Color(0.8f, 0.75f, 0.65f), (TextAlignmentOptions)514);
			RectTransform obj = CreateRect((Transform)(object)val, "CloseBtn", 756f, 14f, 28f, 28f, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(0f, 1f));
			Image val2 = SkinImage(obj, _cardSkin, new Color(0.35f, 0.2f, 0.18f, 0.95f));
			((Graphic)val2).raycastTarget = true;
			Button val3 = ((Component)obj).gameObject.AddComponent<Button>();
			((Selectable)val3).targetGraphic = (Graphic)(object)val2;
			if ((Object)(object)_buttonSkin != (Object)null)
			{
				((Selectable)val3).colors = ((Selectable)_buttonSkin).colors;
			}
			ButtonClickedEvent onClick = val3.onClick;
			object obj2 = <>O.<0>__CloseCommandWindow;
			if (obj2 == null)
			{
				UnityAction val4 = CloseCommandWindow;
				<>O.<0>__CloseCommandWindow = val4;
				obj2 = (object)val4;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj2);
			CreateText((Transform)(object)obj, "Text", "X", 0f, 2f, 28f, 24f, 16f, _headingSkin, Color.white, (TextAlignmentOptions)514);
			string[] array = new string[4] { "FREE HUNT", "STAY", "HEEL", "RECALL" };
			string[] array2 = new string[4] { "Aggressive. Wolf attacks nearby enemies freely.", "Guard Ground. Wolf holds its current position.", "Passive. Stays glued to your heel; never attacks.", "Emergency. Clears aggro target and dashes to your side." };
			string[] array3 = new string[4] { "TrophyWolf", "ShieldWood", "WolfPelt", "StaffShield" };
			float w2 = 360f;
			float h2 = 96f;
			float[] array4 = new float[4] { 30f, 410f, 30f, 410f };
			float[] array5 = new float[4] { 80f, 80f, 192f, 192f };
			for (int i = 0; i < 4; i++)
			{
				int index = i;
				float x = array4[i];
				float y = array5[i];
				RectTransform val5 = CreateRect((Transform)(object)val, "Card_" + array[i], x, y, w2, h2, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(0f, 1f));
				Image val6 = SkinImage(val5, _cardSkin, new Color(0.18f, 0.15f, 0.12f, 0.95f));
				((Graphic)val6).raycastTarget = true;
				_cardBackgrounds[i] = val6;
				Button val7 = ((Component)val5).gameObject.AddComponent<Button>();
				((Selectable)val7).targetGraphic = (Graphic)(object)val6;
				if ((Object)(object)_buttonSkin != (Object)null)
				{
					((Selectable)val7).colors = ((Selectable)_buttonSkin).colors;
				}
				((UnityEvent)val7.onClick).AddListener((UnityAction)delegate
				{
					Player localPlayer = Player.m_localPlayer;
					Character activeWolfCharacter = ActiveWolfCharacter;
					if ((Object)(object)localPlayer != (Object)null && (Object)(object)activeWolfCharacter != (Object)null)
					{
						if (index < 3)
						{
							SetStance((WolfStance)index, localPlayer, activeWolfCharacter);
						}
						else
						{
							TriggerRecall(localPlayer, activeWolfCharacter);
						}
					}
					CloseCommandWindow();
				});
				Image val8 = ((Component)CreateRect((Transform)(object)val5, "Icon", 12f, 12f, 42f, 42f, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(0f, 1f))).gameObject.AddComponent<Image>();
				Sprite itemIcon = GetItemIcon(array3[i]);
				if ((Object)(object)itemIcon != (Object)null)
				{
					val8.sprite = itemIcon;
					val8.preserveAspect = true;
					((Graphic)val8).color = Color.white;
				}
				else
				{
					((Graphic)val8).color = new Color(0.4f, 0.35f, 0.3f, 0.6f);
				}
				((Graphic)val8).raycastTarget = false;
				Color color = ((i == 3) ? new Color(0.95f, 0.5f, 0.4f) : new Color(0.95f, 0.85f, 0.5f));
				CreateText((Transform)(object)val5, "Name", array[i], 62f, 10f, 286f, 34f, 16f, _headingSkin, color, (TextAlignmentOptions)513);
				CreateText((Transform)(object)val5, "Desc", array2[i], 14f, 52f, 332f, 20f, 11.5f, _detailSkin, new Color(0.78f, 0.76f, 0.72f), (TextAlignmentOptions)513);
				_cardStateTexts[i] = CreateText((Transform)(object)val5, "State", "Click to select", 14f, 72f, 332f, 18f, 11f, _detailSkin, new Color(0.6f, 0.6f, 0.6f), (TextAlignmentOptions)513);
			}
		}

		private static void UpdateCardStates()
		{
			//IL_00f9: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < 4; i++)
			{
				if ((Object)(object)_cardStateTexts[i] == (Object)null)
				{
					continue;
				}
				if (i < 3)
				{
					if (CurrentStance == (WolfStance)i)
					{
						((TMP_Text)_cardStateTexts[i]).text = "<color=#F1C40F>★ ACTIVE STANCE</color>";
						if ((Object)(object)_cardBackgrounds[i] != (Object)null)
						{
							((Graphic)_cardBackgrounds[i]).color = new Color(0.28f, 0.22f, 0.12f, 0.98f);
						}
					}
					else
					{
						((TMP_Text)_cardStateTexts[i]).text = "<color=#95A5A6>Click to select</color>";
						if ((Object)(object)_cardBackgrounds[i] != (Object)null)
						{
							((Graphic)_cardBackgrounds[i]).color = new Color(0.18f, 0.15f, 0.12f, 0.95f);
						}
					}
				}
				else
				{
					((TMP_Text)_cardStateTexts[3]).text = "<color=#E67E22>Click to execute</color>";
					if ((Object)(object)_cardBackgrounds[3] != (Object)null)
					{
						((Graphic)_cardBackgrounds[3]).color = new Color(0.24f, 0.14f, 0.14f, 0.95f);
					}
				}
			}
		}

		public static void EnsureHudBadgeBuilt()
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: 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_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_hudBadgeObj != (Object)null || (Object)(object)Hud.instance == (Object)null || (Object)(object)Hud.instance.m_rootObject == (Object)null)
			{
				return;
			}
			try
			{
				LoadUiSkins();
				_hudBadgeObj = new GameObject("OathboundHunterHudBadge", new Type[1] { typeof(RectTransform) });
				_hudBadgeObj.transform.SetParent(Hud.instance.m_rootObject.transform, false);
				RectTransform component = _hudBadgeObj.GetComponent<RectTransform>();
				component.pivot = new Vector2(0.5f, 0.5f);
				component.anchorMin = new Vector2(BadgePosX.Value, BadgePosY.Value);
				component.anchorMax = new Vector2(BadgePosX.Value, BadgePosY.Value);
				component.anchoredPosition = Vector2.zero;
				component.sizeDelta = new Vector2(170f, 26f);
				((Graphic)SkinImage(component, _cardSkin, new Color(0.08f, 0.08f, 0.08f, 0.85f))).raycastTarget = false;
				_hudBadgeText = CreateText((Transform)(object)component, "Text", "WOLF: " + GetStanceName(CurrentStance).ToUpper(), 0f, 2f, 170f, 22f, 12f, _headingSkin, new Color(0.95f, 0.82f, 0.4f, 0.95f), (TextAlignmentOptions)514);
				((TMP_Text)_hudBadgeText).fontStyle = (FontStyles)1;
			}
			catch (Exception ex)
			{
				ManualLogSource log = Log;
				if (log != null)
				{
					log.LogWarning((object)("Failed to build native HUD badge: " + ex.Message));
				}
			}
		}

		public static void SetHudBadgeVisible(bool visible)
		{
			if (!ShowHudBadge.Value)
			{
				if ((Object)(object)_hudBadgeObj != (Object)null && _hudBadgeObj.activeSelf)
				{
					_hudBadgeObj.SetActive(false);
				}
				return;
			}
			if (visible && (Object)(object)_hudBadgeObj == (Object)null)
			{
				EnsureHudBadgeBuilt();
			}
			if ((Object)(object)_hudBadgeObj != (Object)null && _hudBadgeObj.activeSelf != visible)
			{
				_hudBadgeObj.SetActive(visible);
			}
		}

		public static void SetStance(WolfStance stance, Player player, Character pet)
		{
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			CurrentStance = stance;
			if (player != null)
			{
				ZNetView component = ((Component)player).GetComponent<ZNetView>();
				if (component != null)
				{
					ZDO zDO = component.GetZDO();
					if (zDO != null)
					{
						zDO.Set("oathbound.addon.stance", (int)stance);
					}
				}
			}
			if ((Object)(object)pet != (Object)null)
			{
				ZNetView component2 = ((Component)pet).GetComponent<ZNetView>();
				if (component2 != null)
				{
					ZDO zDO2 = component2.GetZDO();
					if (zDO2 != null)
					{
						zDO2.Set("oathbound.addon.stance", (int)stance);
					}
				}
				MonsterAI component3 = ((Component)pet).GetComponent<MonsterAI>();
				if ((Object)(object)component3 != (Object)null)
				{
					switch (stance)
					{
					case WolfStance.Heel:
						if (TargetCreatureRef != null)
						{
							TargetCreatureRef.Invoke(component3) = null;
						}
						((BaseAI)component3).ResetPatrolPoint();
						component3.SetFollowTarget(((Component)player).gameObject);
						break;
					case WolfStance.Stay:
						StayPosition = ((Component)pet).transform.position;
						if (TargetCreatureRef != null)
						{
							TargetCreatureRef.Invoke(component3) = null;
						}
						component3.SetFollowTarget((GameObject)null);
						((BaseAI)component3).ResetPatrolPoint();
						break;
					case WolfStance.FreeHunt:
						component3.SetFollowTarget(((Component)player).gameObject);
						break;
					}
				}
			}
			MessageHud instance = MessageHud.instance;
			if (instance != null)
			{
				instance.ShowMessage((MessageType)2, "<color=#F1C40F>Wolf Stance: " + GetStanceName(stance) + "</color>", 0, (Sprite)null, false, true);
			}
			if ((Object)(object)_hudBadgeText != (Object)null)
			{
				((TMP_Text)_hudBadgeText).text = "WOLF: " + GetStanceName(CurrentStance).ToUpper();
			}
			SetHudBadgeVisible(!IsWindowOpen);
		}

		public static void TriggerRecall(Player player, Character pet)
		{
			//IL_0073: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: 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_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_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			CurrentStance = WolfStance.Heel;
			if (player != null)
			{
				ZNetView component = ((Component)player).GetComponent<ZNetView>();
				if (component != null)
				{
					ZDO zDO = component.GetZDO();
					if (zDO != null)
					{
						zDO.Set("oathbound.addon.stance", 2);
					}
				}
			}
			if ((Object)(object)pet != (Object)null)
			{
				MonsterAI component2 = ((Component)pet).GetComponent<MonsterAI>();
				if ((Object)(object)component2 != (Object)null)
				{
					if (TargetCreatureRef != null)
					{
						TargetCreatureRef.Invoke(component2) = null;
					}
					((BaseAI)component2).ResetPatrolPoint();
					component2.SetFollowTarget(((Component)player).gameObject);
				}
				if (Vector3.Distance(((Component)pet).transform.position, ((Component)player).transform.position) > 12f)
				{
					Vector3 position = ((Component)player).transform.position - ((Component)player).transform.forward * 2f;
					position.y = ((Component)player).transform.position.y;
					((Component)pet).transform.position = position;
					Rigidbody component3 = ((Component)pet).GetComponent<Rigidbody>();
					if ((Object)(object)component3 != (Object)null)
					{
						component3.position = position;
						component3.linearVelocity = Vector3.zero;
					}
				}
			}
			MessageHud instance = MessageHud.instance;
			if (instance != null)
			{
				instance.ShowMessage((MessageType)2, "<color=#E67E22>Wolf Command: RECALL (Heel)</color>", 0, (Sprite)null, false, true);
			}
			if ((Object)(object)_hudBadgeText != (Object)null)
			{
				((TMP_Text)_hudBadgeText).text = "WOLF: " + GetStanceName(CurrentStance).ToUpper();
			}
			SetHudBadgeVisible(!IsWindowOpen);
		}

		public static string GetStanceName(WolfStance stance)
		{
			return stance switch
			{
				WolfStance.FreeHunt => "Free Hunt", 
				WolfStance.Stay => "Stay", 
				WolfStance.Heel => "Heel (Passive)", 
				_ => "Unknown", 
			};
		}

		public static bool IsLocalPlayerHunter(Player p)
		{
			if ((Object)(object)p == (Object)null)
			{
				return false;
			}
			ZNetView component = ((Component)p).GetComponent<ZNetView>();
			if ((Object)(object)component != (Object)null && component.IsValid() && string.Equals(component.GetZDO().GetString("oathbound.activeclass", ""), "hunter", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			return (Object)(object)ActiveCompanion != (Object)null;
		}

		public static void FindLocalHunterPet(Player player)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player == (Object)null)
			{
				return;
			}
			ZDOID zDOID = ((Character)player).GetZDOID();
			HunterCompanion[] array = Object.FindObjectsByType<HunterCompanion>((FindObjectsSortMode)0);
			foreach (HunterCompanion val in array)
			{
				if (!((Object)(object)val == (Object)null))
				{
					ZNetView component = ((Component)val).GetComponent<ZNetView>();
					if ((Object)(object)component != (Object)null && component.IsValid() && component.GetZDO().GetZDOID("oathbound.hunter.owner") == zDOID)
					{
						RegisterCompanion(val);
						break;
					}
				}
			}
		}
	}
	[HarmonyPatch(typeof(GameCamera), "UpdateMouseCapture")]
	public static class Patch_GameCamera_UpdateMouseCapture
	{
		[HarmonyPrefix]
		public static bool Prefix()
		{
			if (OathboundAddonPlugin.IsWindowOpen)
			{
				ZCursor.LockState = (CursorLockMode)0;
				ZCursor.Show();
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(PlayerController), "InInventoryEtc")]
	public static class Patch_PlayerController_InInventoryEtc
	{
		[HarmonyPostfix]
		public static void Postfix(ref bool __result)
		{
			if (OathboundAddonPlugin.IsWindowOpen)
			{
				__result = true;
			}
		}
	}
	[HarmonyPatch(typeof(HunterCompanion), "Awake")]
	public static class Patch_HunterCompanion_Awake
	{
		[HarmonyPostfix]
		public static void Postfix(HunterCompanion __instance)
		{
			//IL_003c: 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)
			if ((Object)(object)__instance == (Object)null)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer != (Object)null)
			{
				ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
				if ((Object)(object)component != (Object)null && component.IsValid())
				{
					_ = component.GetZDO().GetZDOID("oathbound.hunter.owner") == ((Character)localPlayer).GetZDOID();
					OathboundAddonPlugin.RegisterCompanion(__instance);
					return;
				}
			}
			OathboundAddonPlugin.RegisterCompanion(__instance);
		}
	}
	[HarmonyPatch(typeof(Character), "OnDeath")]
	public static class Patch_Character_OnDeath
	{
		[HarmonyPostfix]
		public static void Postfix(Character __instance)
		{
			if ((Object)(object)__instance != (Object)null && (Object)(object)__instance == (Object)(object)OathboundAddonPlugin.ActiveWolfCharacter)
			{
				OathboundAddonPlugin.RegisterCompanion(null);
			}
		}
	}
	[HarmonyPatch(typeof(BaseAI), "CanSenseTarget", new Type[] { typeof(Character) })]
	public static class Patch_BaseAI_CanSenseTarget
	{
		[HarmonyPrefix]
		public static bool Prefix(BaseAI __instance, Character target, ref bool __result)
		{
			if ((Object)(object)OathboundAddonPlugin.ActiveWolfBaseAI == (Object)null || (Object)(object)__instance != (Object)(object)OathboundAddonPlugin.ActiveWolfBaseAI)
			{
				return true;
			}
			WolfStance currentStance = OathboundAddonPlugin.CurrentStance;
			if (currentStance == WolfStance.Heel || currentStance == WolfStance.Stay)
			{
				__result = false;
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(MonsterAI), "UpdateAI", new Type[] { typeof(float) })]
	public static class Patch_MonsterAI_UpdateAI
	{
		[HarmonyPrefix]
		public static bool Prefix(MonsterAI __instance, float dt)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_006c: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)OathboundAddonPlugin.ActiveWolfMonsterAI == (Object)null || (Object)(object)__instance != (Object)(object)OathboundAddonPlugin.ActiveWolfMonsterAI)
			{
				return true;
			}
			if (OathboundAddonPlugin.CurrentStance == WolfStance.Stay)
			{
				if (OathboundAddonPlugin.TargetCreatureRef != null)
				{
					OathboundAddonPlugin.TargetCreatureRef.Invoke(__instance) = null;
				}
				__instance.SetFollowTarget((GameObject)null);
				if (Vector3.Distance(((Component)__instance).transform.position, OathboundAddonPlugin.StayPosition) > 2f && OathboundAddonPlugin.StayPosition != Vector3.zero)
				{
					Vector3 val = OathboundAddonPlugin.StayPosition - ((Component)__instance).transform.position;
					Vector3 normalized = ((Vector3)(ref val)).normalized;
					((BaseAI)__instance).MoveTowards(normalized, false);
					return false;
				}
				((BaseAI)__instance).StopMoving();
				return false;
			}
			return true;
		}

		[HarmonyPostfix]
		public static void Postfix(MonsterAI __instance, float dt)
		{
			if ((Object)(object)OathboundAddonPlugin.ActiveWolfMonsterAI == (Object)null || (Object)(object)__instance != (Object)(object)OathboundAddonPlugin.ActiveWolfMonsterAI)
			{
				return;
			}
			switch (OathboundAddonPlugin.CurrentStance)
			{
			case WolfStance.Heel:
			{
				if (OathboundAddonPlugin.TargetCreatureRef != null)
				{
					OathboundAddonPlugin.TargetCreatureRef.Invoke(__instance) = null;
				}
				Player localPlayer = Player.m_localPlayer;
				if ((Object)(object)localPlayer != (Object)null)
				{
					__instance.SetFollowTarget(((Component)localPlayer).gameObject);
				}
				break;
			}
			case WolfStance.Stay:
				if (OathboundAddonPlugin.TargetCreatureRef != null)
				{
					OathboundAddonPlugin.TargetCreatureRef.Invoke(__instance) = null;
				}
				__instance.SetFollowTarget((GameObject)null);
				break;
			}
		}
	}
}