Decompiled source of oathbound addon v1.0.1

OathboundAddon.dll

Decompiled a month 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 Splatform;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using Warrior.Core;
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.1")]
	[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.1";

		public static OathboundAddonPlugin Instance;

		public static ManualLogSource Log;

		private Harmony _harmony;

		public static FieldRef<MonsterAI, Character> TargetCreatureRef;

		private static FieldInfo _pluginInstanceField;

		private static FieldInfo _stateField;

		private static FieldInfo _progressHudClassIdField;

		private static FieldInfo _hunterPetField;

		private static FieldInfo _progressHudField;

		private static FieldInfo _spellHintField;

		private static FieldInfo _hunterHealthField;

		public const string SavedWolfNameKey = "oathbound.addon.wolfname";

		private static float _nextPetSearchTime = 0f;

		private static float _nextHudCheckTime = 0f;

		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 ConfigEntry<float> AbilityPromptOffsetX;

		public static ConfigEntry<float> AbilityPromptOffsetY;

		public static ConfigEntry<float> ProgressHudOffsetX;

		public static ConfigEntry<float> ProgressHudOffsetY;

		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 static RectTransform _cachedProgressHudRt;

		private static Vector2 _cachedProgressHudOffset = Vector2.zero;

		private static Component _lastSpellHint;

		private static Vector2 _baseSpellHintPos;

		private static bool _hasBaseSpellHintPos;

		private static Component _lastHunterHealth;

		private static Vector2 _baseHunterHealthPos;

		private static bool _hasBaseHunterHealthPos;

		private static float _lastAppliedPromptX = float.NaN;

		private static float _lastAppliedPromptY = float.NaN;

		private static Character _lastNamedWolf;

		private static bool _wolfNameApplied = false;

		private static object _cachedPluginInstance;

		private static bool _isHunterCached = false;

		private static float _nextHunterCheckTime = 0f;

		private void Awake()
		{
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Expected O, but got Unknown
			//IL_0405: Unknown result type (might be due to invalid IL or missing references)
			//IL_0412: 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).");
			AbilityPromptOffsetX = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "AbilityPromptOffsetX", 0f, "Horizontal offset (X) for the class ability prompt text and companion health bar.");
			AbilityPromptOffsetY = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "AbilityPromptOffsetY", 0f, "Vertical offset (Y) for the class ability prompt text and companion health bar.");
			ProgressHudOffsetX = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "ProgressHudOffsetX", 0f, "Horizontal offset (X) for the Oathbound class level and XP progress bar.");
			ProgressHudOffsetY = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "ProgressHudOffsetY", 0f, "Vertical offset (Y) for the Oathbound class level and XP progress bar.");
			AbilityPromptOffsetX.SettingChanged += delegate
			{
				ApplyOathboundHudOffsets();
			};
			AbilityPromptOffsetY.SettingChanged += delegate
			{
				ApplyOathboundHudOffsets();
			};
			ProgressHudOffsetX.SettingChanged += delegate
			{
				UpdateProgressHudOffset();
			};
			ProgressHudOffsetY.SettingChanged += delegate
			{
				UpdateProgressHudOffset();
			};
			BadgePosX.SettingChanged += delegate
			{
				UpdateBadgePosition();
			};
			BadgePosY.SettingChanged += delegate
			{
				UpdateBadgePosition();
			};
			UpdateProgressHudOffset();
			try
			{
				TargetCreatureRef = AccessTools.FieldRefAccess<MonsterAI, Character>("m_targetCreature");
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Failed to bind TargetCreatureRef: " + ex.Message));
			}
			try
			{
				Type type = typeof(HunterCompanion).Assembly.GetType("Warrior.Mod.Plugin");
				if (type != null)
				{
					_pluginInstanceField = AccessTools.Field(type, "Instance");
					_stateField = AccessTools.Field(type, "_state");
					_progressHudClassIdField = AccessTools.Field(type, "_progressHudClassId");
					_hunterPetField = AccessTools.Field(type, "_hunterPet");
					_progressHudField = AccessTools.Field(type, "_progressHud");
					_spellHintField = AccessTools.Field(type, "_spellHint");
					_hunterHealthField = AccessTools.Field(type, "_hunterHealth");
				}
			}
			catch (Exception ex2)
			{
				Log.LogError((object)("Failed to reflect Oathbound Plugin fields: " + ex2.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));
			TryPatch(typeof(Patch_Tameable_RPC_SetName));
			try
			{
				Type type2 = typeof(HunterCompanion).Assembly.GetType("Warrior.Mod.Plugin");
				if (type2 != null)
				{
					MethodInfo methodInfo = AccessTools.Method(type2, "LateUpdate", (Type[])null, (Type[])null);
					if (methodInfo != null)
					{
						MethodInfo methodInfo2 = AccessTools.Method(typeof(OathboundAddonPlugin), "OnOathboundLateUpdatePostfix", (Type[])null, (Type[])null);
						_harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						Log.LogInfo((object)"Successfully hooked Oathbound Plugin.LateUpdate for ProgressHud positioning.");
					}
				}
			}
			catch (Exception ex3)
			{
				Log.LogError((object)("Failed to hook Oathbound LateUpdate: " + ex3.Message));
			}
			Log.LogInfo((object)"Oathbound Addon v1.0.1 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>();
				ApplySavedWolfName(ActiveWolfCharacter);
				UpdateHudBadge();
				SetHudBadgeVisible(!IsWindowOpen);
			}
		}

		private void Update()
		{
			//IL_0115: 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)
			if (Time.time >= _nextHudCheckTime)
			{
				_nextHudCheckTime = Time.time + 1.5f;
				ApplyOathboundHudOffsets();
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead() || !IsLocalPlayerHunter(localPlayer))
			{
				if (IsWindowOpen)
				{
					CloseCommandWindow();
				}
				if ((Object)(object)_hudBadgeObj != (Object)null && _hudBadgeObj.activeSelf)
				{
					_hudBadgeObj.SetActive(false);
				}
				return;
			}
			if (Time.time >= _nextPetSearchTime)
			{
				_nextPetSearchTime = Time.time + 1.5f;
				if ((Object)(object)ActiveWolfCharacter == (Object)null || ActiveWolfCharacter.IsDead())
				{
					FindLocalHunterPet(localPlayer);
				}
				else
				{
					ApplySavedWolfName(ActiveWolfCharacter);
				}
			}
			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 (!visible || !ShowHudBadge.Value || !IsLocalPlayerHunter(Player.m_localPlayer) || !((Object)(object)ActiveWolfCharacter != (Object)null) || ActiveWolfCharacter.IsDead())
			{
				if ((Object)(object)_hudBadgeObj != (Object)null && _hudBadgeObj.activeSelf)
				{
					_hudBadgeObj.SetActive(false);
				}
				return;
			}
			if ((Object)(object)_hudBadgeObj == (Object)null)
			{
				EnsureHudBadgeBuilt();
			}
			UpdateHudBadge();
			if ((Object)(object)_hudBadgeObj != (Object)null && !_hudBadgeObj.activeSelf)
			{
				_hudBadgeObj.SetActive(true);
			}
		}

		public static void UpdateHudBadge()
		{
			if ((Object)(object)_hudBadgeText != (Object)null)
			{
				((TMP_Text)_hudBadgeText).text = "WOLF: " + GetStanceName(CurrentStance).ToUpper();
			}
		}

		public static void UpdateBadgePosition()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_hudBadgeObj != (Object)null)
			{
				RectTransform component = _hudBadgeObj.GetComponent<RectTransform>();
				if ((Object)(object)component != (Object)null)
				{
					Vector2 val = default(Vector2);
					((Vector2)(ref val))..ctor(BadgePosX.Value, BadgePosY.Value);
					component.anchorMin = val;
					component.anchorMax = val;
					component.anchoredPosition = Vector2.zero;
				}
			}
		}

		public static void UpdateProgressHudOffset()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			_cachedProgressHudOffset = new Vector2(ProgressHudOffsetX.Value, ProgressHudOffsetY.Value);
		}

		public static void OnOathboundLateUpdatePostfix(object __instance)
		{
			//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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			if (!(_cachedProgressHudOffset == Vector2.zero))
			{
				if ((Object)(object)_cachedProgressHudRt == (Object)null && _progressHudField != null && __instance != null)
				{
					object? value = _progressHudField.GetValue(__instance);
					_cachedProgressHudRt = (RectTransform)((value is RectTransform) ? value : null);
				}
				if ((Object)(object)_cachedProgressHudRt != (Object)null)
				{
					RectTransform cachedProgressHudRt = _cachedProgressHudRt;
					cachedProgressHudRt.anchoredPosition += _cachedProgressHudOffset;
				}
			}
		}

		public static void ApplyOathboundHudOffsets()
		{
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			if (AbilityPromptOffsetX.Value == 0f && AbilityPromptOffsetY.Value == 0f)
			{
				return;
			}
			try
			{
				object pluginInstance = GetPluginInstance();
				if (pluginInstance == null)
				{
					return;
				}
				bool flag = _lastAppliedPromptX != AbilityPromptOffsetX.Value || _lastAppliedPromptY != AbilityPromptOffsetY.Value;
				if (_spellHintField != null)
				{
					object? value = _spellHintField.GetValue(pluginInstance);
					Component val = (Component)((value is Component) ? value : null);
					if ((Object)(object)val != (Object)null)
					{
						RectTransform component = val.GetComponent<RectTransform>();
						if ((Object)(object)component != (Object)null)
						{
							if ((Object)(object)val != (Object)(object)_lastSpellHint || !_hasBaseSpellHintPos)
							{
								_lastSpellHint = val;
								_baseSpellHintPos = component.anchoredPosition;
								_hasBaseSpellHintPos = true;
								flag = true;
							}
							if (flag)
							{
								component.anchoredPosition = _baseSpellHintPos + new Vector2(AbilityPromptOffsetX.Value, AbilityPromptOffsetY.Value);
							}
						}
					}
					else
					{
						_lastSpellHint = null;
						_hasBaseSpellHintPos = false;
					}
				}
				if (_hunterHealthField != null)
				{
					object? value2 = _hunterHealthField.GetValue(pluginInstance);
					Component val2 = (Component)((value2 is Component) ? value2 : null);
					if ((Object)(object)val2 != (Object)null)
					{
						RectTransform component2 = val2.GetComponent<RectTransform>();
						if ((Object)(object)component2 != (Object)null)
						{
							if ((Object)(object)val2 != (Object)(object)_lastHunterHealth || !_hasBaseHunterHealthPos)
							{
								_lastHunterHealth = val2;
								_baseHunterHealthPos = component2.anchoredPosition;
								_hasBaseHunterHealthPos = true;
								flag = true;
							}
							if (flag)
							{
								component2.anchoredPosition = _baseHunterHealthPos + new Vector2(AbilityPromptOffsetX.Value, AbilityPromptOffsetY.Value);
							}
						}
					}
					else
					{
						_lastHunterHealth = null;
						_hasBaseHunterHealthPos = false;
					}
				}
				_lastAppliedPromptX = AbilityPromptOffsetX.Value;
				_lastAppliedPromptY = AbilityPromptOffsetY.Value;
			}
			catch (Exception ex)
			{
				ManualLogSource log = Log;
				if (log != null)
				{
					log.LogWarning((object)("Error applying Oathbound HUD offsets: " + ex.Message));
				}
			}
		}

		public static bool IsWolfCompanion(GameObject go)
		{
			if ((Object)(object)go == (Object)null)
			{
				return false;
			}
			if ((Object)(object)ActiveWolfCharacter != (Object)null && (Object)(object)go == (Object)(object)((Component)ActiveWolfCharacter).gameObject)
			{
				return true;
			}
			if ((Object)(object)go.GetComponent<HunterCompanion>() != (Object)null)
			{
				return true;
			}
			return false;
		}

		public static void SaveWolfName(string name)
		{
			_wolfNameApplied = false;
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer != (Object)null)
			{
				if (localPlayer.m_customData != null)
				{
					if (string.IsNullOrEmpty(name))
					{
						localPlayer.m_customData.Remove("oathbound.addon.wolfname");
					}
					else
					{
						localPlayer.m_customData["oathbound.addon.wolfname"] = name;
					}
				}
				ZNetView component = ((Component)localPlayer).GetComponent<ZNetView>();
				if (component != null)
				{
					ZDO zDO = component.GetZDO();
					if (zDO != null)
					{
						zDO.Set("oathbound.addon.wolfname", name ?? "");
					}
				}
			}
			ManualLogSource log = Log;
			if (log != null)
			{
				log.LogInfo((object)("Saved Hunter companion wolf name: " + (string.IsNullOrEmpty(name) ? "<cleared>" : name)));
			}
		}

		public static string GetSavedWolfName()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return null;
			}
			if (localPlayer.m_customData != null && localPlayer.m_customData.TryGetValue("oathbound.addon.wolfname", out var value) && !string.IsNullOrEmpty(value))
			{
				return value;
			}
			ZNetView component = ((Component)localPlayer).GetComponent<ZNetView>();
			ZDO val = ((component != null) ? component.GetZDO() : null);
			if (val != null)
			{
				string text = val.GetString("oathbound.addon.wolfname", "");
				if (!string.IsNullOrEmpty(text))
				{
					return text;
				}
			}
			return null;
		}

		private static string GetCurrentPlatformAuthor()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (PlatformManager.DistributionPlatform != null && PlatformManager.DistributionPlatform.LocalUser != null && PlatformManager.DistributionPlatform.LocalUser.IsSignedIn)
				{
					return ((object)((IUser)PlatformManager.DistributionPlatform.LocalUser).PlatformUserID/*cast due to .constrained prefix*/).ToString();
				}
			}
			catch
			{
			}
			return "host";
		}

		public static void ApplySavedWolfName(Character wolf)
		{
			if ((Object)(object)wolf == (Object)null || ((Object)(object)wolf == (Object)(object)_lastNamedWolf && _wolfNameApplied))
			{
				return;
			}
			ZNetView component = ((Component)wolf).GetComponent<ZNetView>();
			if ((Object)(object)component == (Object)null || !component.IsValid())
			{
				return;
			}
			ZDO zDO = component.GetZDO();
			if (zDO == null)
			{
				return;
			}
			string text = zDO.GetString(ZDOVars.s_tamedName, "");
			if (!string.IsNullOrEmpty(text))
			{
				if (GetSavedWolfName() != text)
				{
					SaveWolfName(text);
				}
				string text2 = zDO.GetString(ZDOVars.s_tamedNameAuthor, "");
				Player localPlayer = Player.m_localPlayer;
				string text3 = ((localPlayer != null) ? localPlayer.GetPlayerName() : null);
				if (!string.IsNullOrEmpty(text2) && !string.IsNullOrEmpty(text3) && text2 == text3)
				{
					string currentPlatformAuthor = GetCurrentPlatformAuthor();
					if (component.IsOwner())
					{
						zDO.Set(ZDOVars.s_tamedNameAuthor, currentPlatformAuthor);
					}
					else
					{
						component.InvokeRPC("SetName", new object[2] { text, currentPlatformAuthor });
					}
				}
				_lastNamedWolf = wolf;
				_wolfNameApplied = true;
				return;
			}
			string savedWolfName = GetSavedWolfName();
			if (!string.IsNullOrEmpty(savedWolfName))
			{
				string currentPlatformAuthor2 = GetCurrentPlatformAuthor();
				if (component.IsOwner())
				{
					zDO.Set(ZDOVars.s_tamedName, savedWolfName);
					zDO.Set(ZDOVars.s_tamedNameAuthor, currentPlatformAuthor2);
				}
				else
				{
					component.InvokeRPC("SetName", new object[2] { savedWolfName, currentPlatformAuthor2 });
				}
				_lastNamedWolf = wolf;
				_wolfNameApplied = true;
				ManualLogSource log = Log;
				if (log != null)
				{
					log.LogInfo((object)("Restored Hunter companion wolf name: " + savedWolfName));
				}
			}
		}

		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);
			}
			UpdateHudBadge();
			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);
			}
			UpdateHudBadge();
			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 object GetPluginInstance()
		{
			if (_cachedPluginInstance != null)
			{
				return _cachedPluginInstance;
			}
			if (_pluginInstanceField != null)
			{
				_cachedPluginInstance = _pluginInstanceField.GetValue(null);
			}
			return _cachedPluginInstance;
		}

		public static bool IsLocalPlayerHunter(Player p)
		{
			if ((Object)(object)p == (Object)null)
			{
				return false;
			}
			if (Time.time < _nextHunterCheckTime)
			{
				return _isHunterCached;
			}
			_nextHunterCheckTime = Time.time + 1f;
			try
			{
				object pluginInstance = GetPluginInstance();
				if (pluginInstance != null)
				{
					if (_progressHudClassIdField != null)
					{
						string text = (string)_progressHudClassIdField.GetValue(pluginInstance);
						if (!string.IsNullOrEmpty(text))
						{
							_isHunterCached = string.Equals(text, "hunter", StringComparison.OrdinalIgnoreCase);
							return _isHunterCached;
						}
					}
					if (_stateField != null)
					{
						object? value = _stateField.GetValue(pluginInstance);
						Progression val = (Progression)((value is Progression) ? value : null);
						if (val != null && !string.IsNullOrEmpty(val.ClassId))
						{
							_isHunterCached = string.Equals(val.ClassId, "hunter", StringComparison.OrdinalIgnoreCase);
							return _isHunterCached;
						}
					}
				}
			}
			catch
			{
			}
			_isHunterCached = false;
			return false;
		}

		public static void FindLocalHunterPet(Player player)
		{
			//IL_00a5: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player == (Object)null || !IsLocalPlayerHunter(player))
			{
				return;
			}
			if (_hunterPetField != null)
			{
				try
				{
					object pluginInstance = GetPluginInstance();
					if (pluginInstance != null)
					{
						ZDOID val = (ZDOID)_hunterPetField.GetValue(pluginInstance);
						if (!((ZDOID)(ref val)).IsNone() && (Object)(object)ZNetScene.instance != (Object)null)
						{
							GameObject val2 = ZNetScene.instance.FindInstance(val);
							if ((Object)(object)val2 != (Object)null)
							{
								HunterCompanion component = val2.GetComponent<HunterCompanion>();
								if ((Object)(object)component != (Object)null)
								{
									RegisterCompanion(component);
									return;
								}
							}
						}
					}
				}
				catch
				{
				}
			}
			HunterCompanion[] array = Object.FindObjectsByType<HunterCompanion>((FindObjectsSortMode)0);
			if (array == null || array.Length == 0)
			{
				return;
			}
			HunterCompanion val3 = null;
			float num = float.MaxValue;
			Vector3 position = ((Component)player).transform.position;
			HunterCompanion[] array2 = array;
			foreach (HunterCompanion val4 in array2)
			{
				if (!((Object)(object)val4 == (Object)null))
				{
					float num2 = Vector3.Distance(position, ((Component)val4).transform.position);
					if (num2 < num)
					{
						num = num2;
						val3 = val4;
					}
				}
			}
			if ((Object)(object)val3 != (Object)null)
			{
				RegisterCompanion(val3);
			}
		}
	}
	[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)
		{
			if (!((Object)(object)__instance == (Object)null))
			{
				Player localPlayer = Player.m_localPlayer;
				if (!((Object)(object)localPlayer == (Object)null) && OathboundAddonPlugin.IsLocalPlayerHunter(localPlayer))
				{
					OathboundAddonPlugin.RegisterCompanion(__instance);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Tameable), "RPC_SetName")]
	public static class Patch_Tameable_RPC_SetName
	{
		[HarmonyPostfix]
		public static void Postfix(Tameable __instance, string name)
		{
			if (!((Object)(object)__instance == (Object)null) && OathboundAddonPlugin.IsWolfCompanion(((Component)__instance).gameObject))
			{
				OathboundAddonPlugin.SaveWolfName(name);
				OathboundAddonPlugin.UpdateHudBadge();
			}
		}
	}
	[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;
			}
		}
	}
}