Decompiled source of LoxSaddleBags v1.0.3

BepInEx/plugins/LoxSaddleBags/Loxsaddle.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Loxsaddle")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Loxsaddle")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b26fab7c-490a-447b-9602-2d6c8ce582f3")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
public static class LoxTrinketPanel
{
	private static GameObject _panel;

	public static void Create(Transform parent)
	{
	}

	public static void Show()
	{
		if ((Object)(object)_panel != (Object)null)
		{
			_panel.SetActive(true);
		}
	}

	public static void Hide()
	{
		if ((Object)(object)_panel != (Object)null)
		{
			_panel.SetActive(false);
		}
	}
}
namespace LoxSaddleBags
{
	[BepInPlugin("pl.twojnick.loxsaddlebags", "Lox Saddle Bags", "0.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		public class LoxBagInput : MonoBehaviour
		{
			private void Update()
			{
				if (!Input.GetKeyDown((KeyCode)122) || (Object)(object)Player.m_localPlayer == (Object)null)
				{
					return;
				}
				GameObject hoverObject = ((Humanoid)Player.m_localPlayer).GetHoverObject();
				if ((Object)(object)hoverObject == (Object)null)
				{
					return;
				}
				Tameable componentInParent = hoverObject.GetComponentInParent<Tameable>();
				if ((Object)(object)componentInParent == (Object)null)
				{
					return;
				}
				ZNetView component = ((Component)componentInParent).GetComponent<ZNetView>();
				if ((Object)(object)component == (Object)null || !component.IsValid() || !component.GetZDO().GetBool("LoxSaddleBags", false))
				{
					return;
				}
				bool flag = component.GetZDO().GetBool("EnchantedLoxSaddleBags", false);
				Container component2 = ((Component)componentInParent).GetComponent<Container>();
				Debug.Log((object)$"CONTAINER FOUND: {(Object)(object)component2 != (Object)null}");
				if ((Object)(object)component2 == (Object)null)
				{
					return;
				}
				if (InventoryGui.instance.IsContainerOpen())
				{
					InventoryGui.instance.Hide();
					Debug.Log((object)"CLOSE CONTAINER");
					return;
				}
				InventoryGui.instance.Show(component2, 1);
				if (flag)
				{
					Transform parent = ((Component)InventoryGui.instance).transform.Find("root");
					LoxTrinketGrid.OpenForLox(componentInParent, component2, parent);
				}
				else
				{
					LoxTrinketGrid.Hide();
				}
				Debug.Log((object)"OPEN CONTAINER");
			}
		}

		[HarmonyPatch(typeof(Tameable), "SetSaddle")]
		public static class TestModelPatch
		{
			private static void Postfix(Tameable __instance, bool enabled)
			{
				//IL_039d: Unknown result type (might be due to invalid IL or missing references)
				//IL_03be: Unknown result type (might be due to invalid IL or missing references)
				//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
				Debug.Log((object)("HAS VANILLA SADDLE: " + ((Component)__instance).GetComponent<ZNetView>().GetZDO().GetBool(ZDOVars.s_haveSaddleHash, false)));
				Debug.Log((object)$"SETSADDLE PATCH FIRED: {enabled}");
				if (!enabled)
				{
					Transform val = ((IEnumerable<Transform>)((Component)__instance).GetComponentsInChildren<Transform>(true)).FirstOrDefault((Func<Transform, bool>)((Transform x) => ((Object)x).name == "TEST_BAGS"));
					if ((Object)(object)val != (Object)null)
					{
						Object.Destroy((Object)(object)((Component)val).gameObject);
						Debug.Log((object)"TEST_BAGS REMOVED");
					}
					Transform val2 = ((IEnumerable<Transform>)((Component)__instance).GetComponentsInChildren<Transform>(true)).FirstOrDefault((Func<Transform, bool>)((Transform x) => ((Object)x).name == "Sadel"));
					if ((Object)(object)val2 != (Object)null)
					{
						Renderer[] componentsInChildren = ((Component)val2).GetComponentsInChildren<Renderer>(true);
						foreach (Renderer val3 in componentsInChildren)
						{
							val3.enabled = true;
						}
						Debug.Log((object)"VANILLA SADDLE RESTORED");
					}
					return;
				}
				ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
				if ((Object)(object)component == (Object)null || !component.IsValid())
				{
					return;
				}
				bool flag = component.GetZDO().GetBool("LoxSaddleBags", false);
				Debug.Log((object)$"MODEL PATCH HAS BAGS: {flag}");
				if (!flag)
				{
					return;
				}
				bool flag2 = component.GetZDO().GetBool("EnchantedLoxSaddleBags", false);
				GameObject val4 = (flag2 ? EnchantedSaddleModel : SaddleModel);
				if ((Object)(object)val4 == (Object)null)
				{
					Debug.Log((object)"MODEL TO SPAWN IS NULL");
					return;
				}
				Transform val5 = ((IEnumerable<Transform>)((Component)__instance).GetComponentsInChildren<Transform>(true)).FirstOrDefault((Func<Transform, bool>)((Transform x) => ((Object)x).name == "Sadel"));
				Debug.Log((object)$"SADDLE FOUND: {(Object)(object)val5 != (Object)null}");
				if ((Object)(object)val5 != (Object)null)
				{
					if ((Object)(object)val5 != (Object)null)
					{
						Renderer[] componentsInChildren2 = ((Component)val5).GetComponentsInChildren<Renderer>(true);
						foreach (Renderer val6 in componentsInChildren2)
						{
							val6.enabled = false;
						}
						Debug.Log((object)"VANILLA SADDLE HIDDEN");
					}
					Renderer[] componentsInChildren3 = ((Component)val5).GetComponentsInChildren<Renderer>(true);
					foreach (Renderer val7 in componentsInChildren3)
					{
						Debug.Log((object)("RENDERER: " + ((Object)val7).name));
					}
					SkinnedMeshRenderer[] componentsInChildren4 = ((Component)val5).GetComponentsInChildren<SkinnedMeshRenderer>(true);
					foreach (SkinnedMeshRenderer val8 in componentsInChildren4)
					{
						Debug.Log((object)("SMR: " + ((Object)val8).name));
					}
				}
				Transform val9 = ((IEnumerable<Transform>)((Component)__instance).GetComponentsInChildren<Transform>(true)).FirstOrDefault((Func<Transform, bool>)((Transform x) => ((Object)x).name == "Mount"));
				if ((Object)(object)val9 == (Object)null)
				{
					Debug.Log((object)"MOUNT NOT FOUND");
				}
				else if (!((Object)(object)val9.Find("TEST_BAGS") != (Object)null))
				{
					Debug.Log((object)("SPAWNING MODEL: " + (flag2 ? "ENCHANTED" : "NORMAL")));
					GameObject val10 = Object.Instantiate<GameObject>(val4, val9);
					((Object)val10).name = "TEST_BAGS";
					val10.transform.localPosition = new Vector3(0f, -0.017f, 0.01f);
					val10.transform.localRotation = Quaternion.Euler(255f, 0f, 0f);
					val10.transform.localScale = Vector3.one;
					Debug.Log((object)"TEST MODEL SPAWNED");
				}
			}
		}

		[HarmonyPatch(typeof(Character), "GetSlideAngle")]
		public static class LoxMistlandsTrinketSlopePatch
		{
			private static bool Prefix(Character __instance, ref float __result)
			{
				if ((Object)(object)__instance == (Object)null)
				{
					return true;
				}
				Tameable component = ((Component)__instance).GetComponent<Tameable>();
				if ((Object)(object)component == (Object)null)
				{
					return true;
				}
				if (!((Object)__instance).name.StartsWith("Lox"))
				{
					return true;
				}
				if (!LoxTrinketGrid.HasEquippedTrinket(component, "LoxTrinketMistlandsItem"))
				{
					return true;
				}
				__result = 90f;
				return false;
			}
		}

		[HarmonyPatch(typeof(MonsterAI), "Awake")]
		public static class LoxFoodPatch
		{
			private static void Postfix(MonsterAI __instance)
			{
				if (((Object)__instance).name.StartsWith("Lox"))
				{
					GameObject itemPrefab = ObjectDB.instance.GetItemPrefab("LoxHealingTreat");
					ItemDrop val = ((itemPrefab != null) ? itemPrefab.GetComponent<ItemDrop>() : null);
					GameObject itemPrefab2 = ObjectDB.instance.GetItemPrefab("LoxEnergyTreat");
					ItemDrop val2 = ((itemPrefab2 != null) ? itemPrefab2.GetComponent<ItemDrop>() : null);
					if ((Object)(object)val != (Object)null && !__instance.m_consumeItems.Contains(val))
					{
						__instance.m_consumeItems.Add(val);
					}
					if ((Object)(object)val2 != (Object)null && !__instance.m_consumeItems.Contains(val2))
					{
						__instance.m_consumeItems.Add(val2);
					}
				}
			}
		}

		[HarmonyPatch(typeof(Tameable), "OnConsumedItem")]
		public static class LoxTreatPatch
		{
			private static void Postfix(Tameable __instance, ItemDrop item)
			{
				if ((Object)(object)__instance == (Object)null || (Object)(object)item == (Object)null)
				{
					return;
				}
				ItemData itemData = item.m_itemData;
				object obj;
				if (itemData == null)
				{
					obj = null;
				}
				else
				{
					GameObject dropPrefab = itemData.m_dropPrefab;
					obj = ((dropPrefab != null) ? ((Object)dropPrefab).name : null);
				}
				string text = (string)obj;
				Debug.Log((object)("CONSUMED: " + text));
				Character component = ((Component)__instance).GetComponent<Character>();
				if ((Object)(object)component == (Object)null)
				{
					return;
				}
				if (text == "LoxHealingTreat")
				{
					component.Heal(99999f, true);
					Debug.Log((object)"LOX HEALED TO FULL");
				}
				else
				{
					if (!(text == "LoxEnergyTreat"))
					{
						return;
					}
					Sadle componentInChildren = ((Component)__instance).GetComponentInChildren<Sadle>(true);
					if ((Object)(object)componentInChildren == (Object)null)
					{
						Debug.LogError((object)"LOX ENERGY TREAT: SADLE NOT FOUND");
						return;
					}
					ZNetView component2 = ((Component)__instance).GetComponent<ZNetView>();
					if ((Object)(object)component2 == (Object)null || !component2.IsValid())
					{
						Debug.LogError((object)"LOX ENERGY TREAT: ZNETVIEW INVALID");
						return;
					}
					float maxStamina = componentInChildren.GetMaxStamina();
					component2.GetZDO().Set(ZDOVars.s_stamina, maxStamina);
					Debug.Log((object)$"LOX STAMINA RESTORED TO {maxStamina}");
				}
			}
		}

		[HarmonyPatch(typeof(Sadle), "RPC_RemoveSaddle")]
		public static class PreventRemoveSaddlePatch
		{
			private static bool Prefix(Sadle __instance, long sender, Vector3 userPoint)
			{
				Tameable tameable = __instance.GetTameable();
				if ((Object)(object)tameable == (Object)null)
				{
					return true;
				}
				Container component = ((Component)tameable).GetComponent<Container>();
				if ((Object)(object)component == (Object)null)
				{
					return true;
				}
				int num = component.GetInventory().NrOfItems();
				Debug.Log((object)$"ITEMS IN BAGS: {num}");
				if (num > 0)
				{
					((Character)Player.m_localPlayer).Message((MessageType)2, "first empty lox's inventory", 0, (Sprite)null);
					return false;
				}
				ZNetView component2 = ((Component)tameable).GetComponent<ZNetView>();
				Object.Destroy((Object)(object)component);
				Debug.Log((object)"CONTAINER REMOVED");
				return true;
			}
		}

		[HarmonyPatch(typeof(Sadle), "Interact")]
		public static class SaddleDebugPatch
		{
			private static void Prefix(Sadle __instance)
			{
				Debug.Log((object)"SADDLE INTERACT");
			}
		}

		[HarmonyPatch(typeof(Tameable), "Awake")]
		public static class RestoreContainerPatch
		{
			private static void Postfix(Tameable __instance)
			{
				ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
				if ((Object)(object)component == (Object)null || !component.IsValid())
				{
					return;
				}
				bool flag = component.GetZDO().GetBool("LoxSaddleBags", false);
				bool flag2 = component.GetZDO().GetBool("EnchantedLoxSaddleBags", false);
				if (flag)
				{
					GetOrCreateContainer(__instance);
					Debug.Log((object)"OPEN CONTAINER");
					if (flag2)
					{
						UpdateEnchantedState(__instance, enabled: true);
					}
				}
			}
		}

		[HarmonyPatch(typeof(BaseAI), "FindEnemy")]
		public static class EnchantedLoxFindEnemyPatch
		{
			private static bool Prefix(BaseAI __instance, ref Character __result)
			{
				Tameable component = ((Component)__instance).GetComponent<Tameable>();
				if ((Object)(object)component == (Object)null)
				{
					return true;
				}
				ZNetView component2 = ((Component)component).GetComponent<ZNetView>();
				if ((Object)(object)component2 == (Object)null || !component2.IsValid())
				{
					return true;
				}
				if (!component2.GetZDO().GetBool("EnchantedLoxSaddleBags", false))
				{
					return true;
				}
				__result = null;
				return false;
			}
		}

		[HarmonyPatch(typeof(MonsterAI), "OnDamaged")]
		public static class EnchantedLoxOnDamagedPatch
		{
			private static bool Prefix(MonsterAI __instance, float damage, Character attacker)
			{
				Tameable component = ((Component)__instance).GetComponent<Tameable>();
				if ((Object)(object)component == (Object)null)
				{
					return true;
				}
				ZNetView component2 = ((Component)component).GetComponent<ZNetView>();
				if ((Object)(object)component2 == (Object)null || !component2.IsValid())
				{
					return true;
				}
				if (!component2.GetZDO().GetBool("EnchantedLoxSaddleBags", false))
				{
					return true;
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(Sadle), "RPC_RemoveSaddle")]
		public static class RemoveSaddleDebugPatch
		{
			private static void Prefix()
			{
				Debug.Log((object)"RPC_REMOVE_SADDLE");
			}

			private static void Postfix()
			{
				Debug.Log((object)"RPC_REMOVE_SADDLE DONE");
			}
		}

		[HarmonyPatch(typeof(Tameable), "UseItem")]
		public static class SaddleBagUsePatch
		{
			private static bool Prefix(Tameable __instance, Humanoid user, ItemData item, ref bool __result)
			{
				object obj;
				if (item == null)
				{
					obj = null;
				}
				else
				{
					GameObject dropPrefab = item.m_dropPrefab;
					obj = ((dropPrefab != null) ? ((Object)dropPrefab).name : null);
				}
				string text = (string)obj;
				bool flag = text == "LoxSaddleBags";
				bool flag2 = text == "EnchantedLoxSaddleBags";
				if (!flag && !flag2)
				{
					return true;
				}
				ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
				if ((Object)(object)component == (Object)null || !component.IsValid())
				{
					__result = false;
					return false;
				}
				if (!__instance.IsTamed())
				{
					__result = false;
					return false;
				}
				if (component.GetZDO().GetBool(ZDOVars.s_haveSaddleHash, false))
				{
					((Character)user).Message((MessageType)2, __instance.GetHoverName() + " $hud_saddle_already", 0, (Sprite)null);
					__result = true;
					return false;
				}
				component.GetZDO().Set("LoxSaddleBags", true);
				if (flag2)
				{
					component.GetZDO().Set("EnchantedLoxSaddleBags", true);
					UpdateEnchantedState(__instance, enabled: true);
					Debug.Log((object)("LOX AI: " + ((object)((Component)__instance).GetComponent<BaseAI>())?.GetType().Name));
				}
				Debug.Log((object)("ENCHANTED BEFORE ADDSADDLE: " + component.GetZDO().GetBool("EnchantedLoxSaddleBags", false)));
				component.InvokeRPC("AddSaddle", Array.Empty<object>());
				Debug.Log((object)("AFTER ADDSADDLE: " + component.GetZDO().GetBool(ZDOVars.s_haveSaddleHash, false)));
				user.GetInventory().RemoveOneItem(item);
				((Character)user).Message((MessageType)2, __instance.GetHoverName() + " $hud_saddle_ready", 0, (Sprite)null);
				Debug.Log((object)"TRYING TO SPAWN MODEL FROM USEITEM");
				GetOrCreateContainer(__instance);
				__result = true;
				return false;
			}
		}

		[HarmonyPatch(typeof(Container), "Awake")]
		public static class ContainerAwakePatch
		{
			private static void Prefix(Container __instance)
			{
				if (!((Object)(object)((Component)__instance).GetComponent<Tameable>() == (Object)null))
				{
					__instance.m_name = "Saddle bags";
					__instance.m_width = 6;
					__instance.m_height = 4;
					Debug.Log((object)"PATCHED CONTAINER BEFORE AWAKE");
				}
			}
		}

		[HarmonyPatch(typeof(Tameable), "GetHoverText")]
		public static class TameableHoverPatch
		{
			private static void Postfix(Tameable __instance, ref string __result)
			{
				ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
				if (!((Object)(object)component == (Object)null) && component.IsValid() && component.GetZDO().GetBool("LoxSaddleBags", false))
				{
					__result += "\n[<color=yellow><b>Z</b></color>] Open saddle bags";
				}
			}
		}

		[HarmonyPatch(typeof(ObjectDB), "Awake")]
		public static class ObjectDBAwakePatch
		{
			private static void PatchItem(ObjectDB db, string prefabName, string name, string description)
			{
				GameObject itemPrefab = db.GetItemPrefab(prefabName);
				if ((Object)(object)itemPrefab == (Object)null)
				{
					Debug.Log((object)(prefabName + " prefab not found"));
					return;
				}
				ItemDrop component = itemPrefab.GetComponent<ItemDrop>();
				if (!((Object)(object)component == (Object)null))
				{
					component.m_itemData.m_shared.m_name = name;
					component.m_itemData.m_shared.m_description = description;
				}
			}

			private static void Postfix(ObjectDB __instance)
			{
				GameObject itemPrefab = __instance.GetItemPrefab("LoxSaddleBags");
				if ((Object)(object)itemPrefab == (Object)null)
				{
					Debug.Log((object)"LoxSaddleBags prefab not found");
					return;
				}
				GameObject itemPrefab2 = __instance.GetItemPrefab("EnchantedLoxSaddleBags");
				if ((Object)(object)itemPrefab2 != (Object)null)
				{
					ItemDrop component = itemPrefab2.GetComponent<ItemDrop>();
					component.m_itemData.m_shared.m_name = "Enchanted Lox Saddle Bags";
					component.m_itemData.m_shared.m_description = "Magical saddle for lox with containers. It has an aura of peace. The lox does not fight and is not attacked by enemies.";
				}
				ItemDrop component2 = itemPrefab.GetComponent<ItemDrop>();
				if (!((Object)(object)component2 == (Object)null))
				{
					component2.m_itemData.m_shared.m_name = "Lox Saddle Bags";
					component2.m_itemData.m_shared.m_description = "A durable saddle with containers for lox. This saddle allows you to carry heavy loads and supplies.";
					Debug.Log((object)"LOX SADDLE BAGS NAME PATCHED");
					GameObject itemPrefab3 = __instance.GetItemPrefab("LoxHealingTreat");
					if ((Object)(object)itemPrefab3 != (Object)null)
					{
						ItemDrop component3 = itemPrefab3.GetComponent<ItemDrop>();
						component3.m_itemData.m_shared.m_name = "Eir's Lox Morsel";
						component3.m_itemData.m_shared.m_description = "Nutritious snack that restores lox's health.";
					}
					GameObject itemPrefab4 = __instance.GetItemPrefab("LoxEnergyTreat");
					if ((Object)(object)itemPrefab4 != (Object)null)
					{
						ItemDrop component4 = itemPrefab4.GetComponent<ItemDrop>();
						component4.m_itemData.m_shared.m_name = "Tanngrisnir's Lox Morsel";
						component4.m_itemData.m_shared.m_description = "Sweet treat that restores lox's energy.";
					}
					PatchItem(__instance, "LoxTrinketOceanItem", "Lox Trinket: Serpent's Blessing", "Allows your Lox to swim without losing stamina.");
					PatchItem(__instance, "LoxTrinketMistlandsItem", "Lox Trinket: Seeker's Grip", "Allows your Lox to climb extremely steep slopes.");
					PatchItem(__instance, "LoxTrinketAshlandsItem", "Lox Trinket: Charred Ward", "Protects your Lox from the dangers of Ashlands.");
					PatchItem(__instance, "LoxFlute", "Enchanted ocarina", "A magical flute that calls nearby Loxes equipped with enchanted saddle.");
				}
			}
		}

		public const string ModGUID = "pl.twojnick.loxsaddlebags";

		public const string ModName = "Lox Saddle Bags";

		public const string ModVersion = "0.0.1";

		public static AssetBundle Bundle;

		public static GameObject SaddleModel;

		public static GameObject EnchantedSaddleModel;

		public static GameObject DropSaddleModel;

		public static GameObject EnchantedDropSaddleModel;

		public static GameObject HealingTreatModel;

		public static GameObject EnergyTreatModel;

		public static GameObject FluteModel;

		public static GameObject OceanTrinketModel;

		public static GameObject MistlandsTrinketModel;

		public static GameObject AshlandsTrinketModel;

		public static AudioClip[] FluteSounds;

		public static Sprite OceanTrinketIcon;

		public static Sprite MistlandsTrinketIcon;

		public static Sprite AshlandsTrinketIcon;

		public static Sprite FluteIcon;

		public static Sprite HealingTreatIcon;

		public static Sprite EnergyTreatIcon;

		public static Sprite SaddleIcon;

		public static Sprite EnchantedSaddleIcon;

		private void Awake()
		{
			//IL_04e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e9: Expected O, but got Unknown
			string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "loxbundle");
			Bundle = AssetBundle.LoadFromFile(text);
			Debug.Log((object)$"BUNDLE LOADED: {(Object)(object)Bundle != (Object)null}");
			if ((Object)(object)Bundle != (Object)null)
			{
				string[] allAssetNames = Bundle.GetAllAssetNames();
				foreach (string text2 in allAssetNames)
				{
					Debug.Log((object)("ASSET: " + text2));
				}
				GameObject val = Bundle.LoadAsset<GameObject>("assets/loxbundle/loxsaddlebagsmodel.prefab");
				Debug.Log((object)$"MODEL LOADED: {(Object)(object)val != (Object)null}");
				SaddleModel = val;
				GameObject val2 = Bundle.LoadAsset<GameObject>("assets/loxbundle/enchantedsaddlemodel.prefab");
				Debug.Log((object)$"NORMAL MODEL: {(Object)(object)val != (Object)null}");
				Debug.Log((object)$"ENCHANTED MODEL: {(Object)(object)val2 != (Object)null}");
				Debug.Log((object)$"ENCHANTED MODEL LOADED: {(Object)(object)val2 != (Object)null}");
				EnchantedSaddleModel = val2;
				string[] allAssetNames2 = Bundle.GetAllAssetNames();
				foreach (string text3 in allAssetNames2)
				{
					Debug.Log((object)("ASSET: " + text3));
				}
				if ((Object)(object)val != (Object)null)
				{
					SkinnedMeshRenderer[] componentsInChildren = val.GetComponentsInChildren<SkinnedMeshRenderer>(true);
					foreach (SkinnedMeshRenderer val3 in componentsInChildren)
					{
						Debug.Log((object)("SMR: " + ((Object)val3).name));
					}
					MeshFilter[] componentsInChildren2 = val.GetComponentsInChildren<MeshFilter>(true);
					foreach (MeshFilter val4 in componentsInChildren2)
					{
						Debug.Log((object)("MESHFILTER: " + ((Object)val4).name));
					}
				}
				DropSaddleModel = Bundle.LoadAsset<GameObject>("assets/loxbundle/dropsaddlebags.prefab");
				EnchantedDropSaddleModel = Bundle.LoadAsset<GameObject>("assets/loxbundle/enchantedsaddle.prefab");
				HealingTreatModel = Bundle.LoadAsset<GameObject>("assets/loxbundle/loxtreathealth.prefab");
				EnergyTreatModel = Bundle.LoadAsset<GameObject>("assets/loxbundle/loxtreatstamina.prefab");
				OceanTrinketModel = Bundle.LoadAsset<GameObject>("assets/loxbundle/loxtrinketocean.prefab");
				MistlandsTrinketModel = Bundle.LoadAsset<GameObject>("assets/loxbundle/loxtrinketmistlands.prefab");
				AshlandsTrinketModel = Bundle.LoadAsset<GameObject>("assets/loxbundle/loxtrinketashlands.prefab");
				Debug.Log((object)$"OCEAN MODEL: {(Object)(object)OceanTrinketModel != (Object)null}");
				Debug.Log((object)$"MISTLANDS MODEL: {(Object)(object)MistlandsTrinketModel != (Object)null}");
				Debug.Log((object)$"ASHLANDS MODEL: {(Object)(object)AshlandsTrinketModel != (Object)null}");
				FluteModel = Bundle.LoadAsset<GameObject>("assets/loxbundle/flute.prefab");
				Debug.Log((object)$"DROP MODEL: {(Object)(object)DropSaddleModel != (Object)null}");
				Debug.Log((object)$"ENCHANTED DROP MODEL: {(Object)(object)EnchantedDropSaddleModel != (Object)null}");
				SaddleIcon = Bundle.LoadAsset<Sprite>("assets/icons/icon_loxsaddlebags.png");
				EnchantedSaddleIcon = Bundle.LoadAsset<Sprite>("assets/icons/icon_enchantedloxsaddlebags.png");
				HealingTreatIcon = Bundle.LoadAsset<Sprite>("assets/icons/icon_treathealth.png");
				FluteIcon = Bundle.LoadAsset<Sprite>("assets/icons/icon_flute.png");
				string[] array = (from path in Bundle.GetAllAssetNames()
					where path.Contains("loxflutesound") && (path.EndsWith(".wav") || path.EndsWith(".ogg") || path.EndsWith(".mp3"))
					orderby path
					select path).ToArray();
				string[] array2 = array;
				foreach (string text4 in array2)
				{
					Debug.Log((object)("FLUTE SOUND PATH FOUND: " + text4));
				}
				FluteSounds = (from path in array
					select Bundle.LoadAsset<AudioClip>(path) into clip
					where (Object)(object)clip != (Object)null
					select clip).ToArray();
				Debug.Log((object)$"FLUTE SOUNDS LOADED: {FluteSounds.Length}");
				EnergyTreatIcon = Bundle.LoadAsset<Sprite>("assets/icons/icon_treatstamina.png");
				OceanTrinketIcon = Bundle.LoadAsset<Sprite>("assets/icons/icon_loxtrinketocean.png");
				MistlandsTrinketIcon = Bundle.LoadAsset<Sprite>("assets/icons/icon_loxtrinketmistlands.png");
				AshlandsTrinketIcon = Bundle.LoadAsset<Sprite>("assets/icons/icon_loxtrinketashlands.png");
			}
			Harmony val5 = new Harmony("pl.twojnick.loxsaddlebags");
			val5.PatchAll();
			MethodInfo methodInfo = AccessTools.Method(typeof(Character), "GetSlideAngle", (Type[])null, (Type[])null);
			Debug.Log((object)("[MISTLANDS DEBUG] GetSlideAngle method found = " + $"{methodInfo != null}"));
			if (methodInfo != null)
			{
				Patches patchInfo = Harmony.GetPatchInfo((MethodBase)methodInfo);
				Debug.Log((object)("[MISTLANDS DEBUG] GetSlideAngle has patches = " + $"{patchInfo != null}"));
				if (patchInfo != null)
				{
					foreach (string owner in patchInfo.Owners)
					{
						Debug.Log((object)("[MISTLANDS DEBUG] Patch owner: " + owner));
					}
				}
			}
			PrefabManager.OnVanillaPrefabsAvailable += AddItems;
			((Component)this).gameObject.AddComponent<LoxBagInput>();
			((Component)this).gameObject.AddComponent<EnchantedLoxRiderProtectionUpdater>();
			GameObject prefab = PrefabManager.Instance.GetPrefab("InventoryGui");
			Debug.Log((object)$"InventoryGui prefab = {(Object)(object)prefab != (Object)null}");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"PLUGIN TEST 999");
		}

		public static void UpdateEnchantedState(Tameable tameable, bool enabled)
		{
			Character component = ((Component)tameable).GetComponent<Character>();
			if (!((Object)(object)component == (Object)null))
			{
				component.m_aiSkipTarget = enabled;
				Debug.Log((object)$"ENCHANTED STATE: {enabled}");
			}
		}

		private static void DropBagContents(Tameable tameable, Container container)
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)container == (Object)null)
			{
				return;
			}
			Inventory inventory = container.GetInventory();
			if (inventory == null)
			{
				return;
			}
			List<ItemData> list = new List<ItemData>(inventory.GetAllItems());
			Debug.Log((object)$"DROPPING {list.Count} ITEMS");
			foreach (ItemData item in list)
			{
				ItemDrop.DropItem(item, item.m_stack, ((Component)tameable).transform.position + Vector3.up, Quaternion.identity);
			}
			inventory.RemoveAll();
		}

		public static Container GetOrCreateContainer(Tameable tameable)
		{
			Container container = ((Component)tameable).GetComponent<Container>();
			Character component = ((Component)tameable).GetComponent<Character>();
			if ((Object)(object)component != (Object)null)
			{
				component.m_onDeath = (Action)Delegate.Combine(component.m_onDeath, (Action)delegate
				{
					DropBagContents(tameable, container);
				});
				Debug.Log((object)"REGISTERED DEATH HANDLER");
			}
			if ((Object)(object)container == (Object)null)
			{
				container = ((Component)tameable).gameObject.AddComponent<Container>();
			}
			return container;
		}

		private Vector3 GetTrinketPosition(string prefabName)
		{
			//IL_003d: 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_007b: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			return (Vector3)(prefabName switch
			{
				"LoxTrinketAshlandsItem" => new Vector3(0f, 0.08f, 0f), 
				"LoxTrinketOceanItem" => new Vector3(0f, 0.08f, 0f), 
				"LoxTrinketMistlandsItem" => new Vector3(0f, 0.08f, 0f), 
				_ => Vector3.zero, 
			});
		}

		private Quaternion GetTrinketRotation(string prefabName)
		{
			//IL_003d: 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_007b: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			return (Quaternion)(prefabName switch
			{
				"LoxTrinketOceanItem" => Quaternion.Euler(270f, 0f, 0f), 
				"LoxTrinketMistlandsItem" => Quaternion.Euler(270f, 0f, 0f), 
				"LoxTrinketAshlandsItem" => Quaternion.Euler(270f, 0f, 0f), 
				_ => Quaternion.identity, 
			});
		}

		private Vector3 GetTrinketScale(string prefabName)
		{
			//IL_002e: 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_003d: 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_0040: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			return (Vector3)(prefabName switch
			{
				"LoxTrinketAshlandsItem" => Vector3.one * 180f, 
				"LoxTrinketOceanItem" => Vector3.one * 1f, 
				"LoxTrinketMistlandsItem" => Vector3.one * 1f, 
				_ => Vector3.one, 
			});
		}

		private void CreateTrinket(string prefabName, GameObject model, Sprite icon, string craftingStation, params RequirementConfig[] requirements)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Expected O, but got Unknown
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			ItemConfig val = new ItemConfig();
			val.CraftingStation = craftingStation;
			foreach (RequirementConfig val2 in requirements)
			{
				val.AddRequirement(val2);
			}
			CustomItem val3 = new CustomItem(prefabName, "Amber", val);
			ItemDrop component = val3.ItemPrefab.GetComponent<ItemDrop>();
			Rigidbody val4 = val3.ItemPrefab.GetComponent<Rigidbody>();
			if ((Object)(object)val4 == (Object)null)
			{
				val4 = val3.ItemPrefab.AddComponent<Rigidbody>();
			}
			val4.useGravity = true;
			val4.isKinematic = false;
			val4.mass = 1f;
			val4.drag = 2f;
			val4.angularDrag = 8f;
			val4.collisionDetectionMode = (CollisionDetectionMode)0;
			Collider component2 = val3.ItemPrefab.GetComponent<Collider>();
			if ((Object)(object)component2 != (Object)null)
			{
				Object.Destroy((Object)(object)component2);
			}
			BoxCollider val5 = val3.ItemPrefab.AddComponent<BoxCollider>();
			val5.size = new Vector3(0.45f, 0.18f, 0.45f);
			val5.center = new Vector3(0f, 0.09f, 0f);
			int num = LayerMask.NameToLayer("item");
			if (num >= 0)
			{
				val3.ItemPrefab.layer = num;
			}
			if ((Object)(object)component != (Object)null)
			{
				component.m_itemData.m_shared.m_name = prefabName;
				component.m_itemData.m_shared.m_description = "Lox trinket.";
				component.m_itemData.m_shared.m_itemType = (ItemType)1;
				component.m_itemData.m_shared.m_maxStackSize = 1;
				if ((Object)(object)icon != (Object)null)
				{
					component.m_itemData.m_shared.m_icons = (Sprite[])(object)new Sprite[1] { icon };
				}
				Transform val6 = val3.ItemPrefab.transform.Find("attach");
				if ((Object)(object)val6 != (Object)null)
				{
					foreach (Transform item in val6)
					{
						Transform val7 = item;
						Object.Destroy((Object)(object)((Component)val7).gameObject);
					}
					if ((Object)(object)model == (Object)null)
					{
						Debug.LogError((object)("MODEL IS NULL FOR " + prefabName));
					}
					else
					{
						GameObject val8 = Object.Instantiate<GameObject>(model, val6);
						((Object)val8).name = prefabName + "_visual";
						val8.transform.localPosition = GetTrinketPosition(prefabName);
						val8.transform.localRotation = GetTrinketRotation(prefabName);
						val8.transform.localScale = GetTrinketScale(prefabName);
						val8.SetActive(true);
						Renderer[] componentsInChildren = val8.GetComponentsInChildren<Renderer>(true);
						Debug.Log((object)$"{prefabName} visual renderers: {componentsInChildren.Length}");
						Renderer[] array = componentsInChildren;
						foreach (Renderer val9 in array)
						{
							val9.enabled = true;
							((Component)val9).gameObject.SetActive(true);
							Debug.Log((object)$"{prefabName} renderer: {((Object)val9).name}, enabled={val9.enabled}");
						}
					}
				}
			}
			ItemManager.Instance.AddItem(val3);
			Debug.Log((object)("REGISTERED TRINKET: " + prefabName));
		}

		private void CreateLoxTetherRope()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//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)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			ItemConfig val = new ItemConfig();
			val.CraftingStation = "piece_workbench";
			val.AddRequirement(new RequirementConfig
			{
				Item = "LeatherScraps",
				Amount = 10
			});
			val.AddRequirement(new RequirementConfig
			{
				Item = "DeerHide",
				Amount = 4
			});
			val.AddRequirement(new RequirementConfig
			{
				Item = "BronzeNails",
				Amount = 2
			});
			CustomItem val2 = new CustomItem("LoxTetherRope", "LeatherScraps", val);
			ItemDrop component = val2.ItemPrefab.GetComponent<ItemDrop>();
			if ((Object)(object)component != (Object)null)
			{
				SharedData shared = component.m_itemData.m_shared;
				shared.m_name = "Lox Tether";
				shared.m_description = "A heavy rope used to tether a tamed Lox to the ground.";
				shared.m_itemType = (ItemType)1;
				shared.m_maxStackSize = 1;
				shared.m_weight = 1f;
			}
			ItemManager.Instance.AddItem(val2);
			Debug.Log((object)"REGISTERED LOX TETHER ROPE");
		}

		private void CreateLoxFlute()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Expected O, but got Unknown
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			Debug.Log((object)"CREATE LOX FLUTE START");
			ItemConfig val = new ItemConfig();
			val.CraftingStation = "piece_magetable";
			val.AddRequirement(new RequirementConfig
			{
				Item = "Copper",
				Amount = 15
			});
			val.AddRequirement(new RequirementConfig
			{
				Item = "Chitin",
				Amount = 1
			});
			val.AddRequirement(new RequirementConfig
			{
				Item = "Wisp",
				Amount = 1
			});
			CustomItem val2 = new CustomItem("LoxFlute", "CookedLoxMeat", val);
			Debug.Log((object)("LOX FLUTE PREFAB CREATED: " + $"{(Object)(object)val2.ItemPrefab != (Object)null}"));
			ItemDrop component = val2.ItemPrefab.GetComponent<ItemDrop>();
			if ((Object)(object)component != (Object)null)
			{
				SharedData shared = component.m_itemData.m_shared;
				shared.m_name = "Enchanted Ocarina";
				shared.m_description = "A magical flute that calls nearby Loxes equipped with enchanted saddle.";
				shared.m_maxStackSize = 1;
				shared.m_itemType = (ItemType)2;
				shared.m_food = 0f;
				shared.m_foodStamina = 0f;
				shared.m_foodBurnTime = 0f;
				shared.m_foodRegen = 0f;
				if ((Object)(object)FluteIcon != (Object)null)
				{
					shared.m_icons = (Sprite[])(object)new Sprite[1] { FluteIcon };
				}
				Transform val3 = val2.ItemPrefab.transform.Find("attach");
				if ((Object)(object)val3 != (Object)null && (Object)(object)FluteModel != (Object)null)
				{
					Renderer[] componentsInChildren = ((Component)val3).GetComponentsInChildren<Renderer>(true);
					foreach (Renderer val4 in componentsInChildren)
					{
						val4.enabled = false;
					}
					GameObject val5 = Object.Instantiate<GameObject>(FluteModel, val3);
					((Object)val5).name = "LoxFlute_visual";
					val5.transform.localPosition = Vector3.zero;
					val5.transform.localRotation = Quaternion.identity;
					val5.transform.localScale = Vector3.one;
					val5.SetActive(true);
					Renderer[] componentsInChildren2 = val5.GetComponentsInChildren<Renderer>(true);
					foreach (Renderer val6 in componentsInChildren2)
					{
						val6.enabled = true;
					}
				}
			}
			ItemManager.Instance.AddItem(val2);
			Debug.Log((object)"REGISTERED LOX FLUTE");
		}

		private void AddItems()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//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)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_0056: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Expected O, but got Unknown
			//IL_00b8: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Expected O, but got Unknown
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Expected O, but got Unknown
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Expected O, but got Unknown
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Expected O, but got Unknown
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Expected O, but got Unknown
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Expected O, but got Unknown
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Expected O, but got Unknown
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Expected O, but got Unknown
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Expected O, but got Unknown
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Expected O, but got Unknown
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Expected O, but got Unknown
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0416: Unknown result type (might be due to invalid IL or missing references)
			//IL_041d: Expected O, but got Unknown
			//IL_0436: Unknown result type (might be due to invalid IL or missing references)
			//IL_043b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0447: Unknown result type (might be due to invalid IL or missing references)
			//IL_0455: Expected O, but got Unknown
			//IL_0458: Unknown result type (might be due to invalid IL or missing references)
			//IL_045d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0469: Unknown result type (might be due to invalid IL or missing references)
			//IL_0476: Expected O, but got Unknown
			//IL_0479: Unknown result type (might be due to invalid IL or missing references)
			//IL_047e: Unknown result type (might be due to invalid IL or missing references)
			//IL_048a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0498: Expected O, but got Unknown
			//IL_049b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ba: Expected O, but got Unknown
			//IL_04c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ce: Expected O, but got Unknown
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_038c: Unknown result type (might be due to invalid IL or missing references)
			//IL_039e: Unknown result type (might be due to invalid IL or missing references)
			//IL_060e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0615: Expected O, but got Unknown
			//IL_062e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0633: Unknown result type (might be due to invalid IL or missing references)
			//IL_063f: Unknown result type (might be due to invalid IL or missing references)
			//IL_064d: Expected O, but got Unknown
			//IL_0650: Unknown result type (might be due to invalid IL or missing references)
			//IL_0655: Unknown result type (might be due to invalid IL or missing references)
			//IL_0661: Unknown result type (might be due to invalid IL or missing references)
			//IL_066f: Expected O, but got Unknown
			//IL_0672: Unknown result type (might be due to invalid IL or missing references)
			//IL_0677: Unknown result type (might be due to invalid IL or missing references)
			//IL_0683: Unknown result type (might be due to invalid IL or missing references)
			//IL_0691: Expected O, but got Unknown
			//IL_0694: Unknown result type (might be due to invalid IL or missing references)
			//IL_0699: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b2: Expected O, but got Unknown
			//IL_06bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c6: Expected O, but got Unknown
			//IL_0823: Unknown result type (might be due to invalid IL or missing references)
			//IL_0828: Unknown result type (might be due to invalid IL or missing references)
			//IL_0834: Unknown result type (might be due to invalid IL or missing references)
			//IL_083d: Expected O, but got Unknown
			//IL_083f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0844: Unknown result type (might be due to invalid IL or missing references)
			//IL_0850: Unknown result type (might be due to invalid IL or missing references)
			//IL_0859: Expected O, but got Unknown
			//IL_085b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0860: Unknown result type (might be due to invalid IL or missing references)
			//IL_086c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0875: Expected O, but got Unknown
			//IL_0877: Unknown result type (might be due to invalid IL or missing references)
			//IL_087c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0888: Unknown result type (might be due to invalid IL or missing references)
			//IL_0892: Expected O, but got Unknown
			//IL_08b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_08c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_08cf: Expected O, but got Unknown
			//IL_08d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_08e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_08eb: Expected O, but got Unknown
			//IL_08ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_08f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_08fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0907: Expected O, but got Unknown
			//IL_0909: Unknown result type (might be due to invalid IL or missing references)
			//IL_090e: Unknown result type (might be due to invalid IL or missing references)
			//IL_091a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0924: Expected O, but got Unknown
			//IL_0947: Unknown result type (might be due to invalid IL or missing references)
			//IL_094c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0958: Unknown result type (might be due to invalid IL or missing references)
			//IL_0961: Expected O, but got Unknown
			//IL_0963: Unknown result type (might be due to invalid IL or missing references)
			//IL_0968: Unknown result type (might be due to invalid IL or missing references)
			//IL_0974: Unknown result type (might be due to invalid IL or missing references)
			//IL_097d: Expected O, but got Unknown
			//IL_097f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0984: Unknown result type (might be due to invalid IL or missing references)
			//IL_0990: Unknown result type (might be due to invalid IL or missing references)
			//IL_0999: Expected O, but got Unknown
			//IL_099b: Unknown result type (might be due to invalid IL or missing references)
			//IL_09a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_09b6: Expected O, but got Unknown
			//IL_05dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0601: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_07e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_07f9: Unknown result type (might be due to invalid IL or missing references)
			ItemConfig val = new ItemConfig();
			val.CraftingStation = "piece_artisanstation";
			val.AddRequirement(new RequirementConfig
			{
				Item = "BlackMetal",
				Amount = 15
			});
			val.AddRequirement(new RequirementConfig
			{
				Item = "Iron",
				Amount = 15
			});
			val.AddRequirement(new RequirementConfig
			{
				Item = "WolfPelt",
				Amount = 10
			});
			val.AddRequirement(new RequirementConfig
			{
				Item = "LinenThread",
				Amount = 20
			});
			val.AddRequirement(new RequirementConfig
			{
				Item = "BarrelRings",
				Amount = 4
			});
			val.AddRequirement(new RequirementConfig
			{
				Item = "Wood",
				Amount = 30
			});
			CustomItem val2 = new CustomItem("LoxSaddleBags", "SaddleLox", val);
			if ((Object)(object)DropSaddleModel != (Object)null)
			{
				Transform val3 = val2.ItemPrefab.transform.Find("attach");
				if ((Object)(object)val3 != (Object)null)
				{
					Renderer[] componentsInChildren = ((Component)val3).GetComponentsInChildren<Renderer>(true);
					foreach (Renderer val4 in componentsInChildren)
					{
						val4.enabled = false;
					}
					GameObject val5 = Object.Instantiate<GameObject>(DropSaddleModel, val3);
					val5.transform.localPosition = Vector3.zero;
					val5.transform.localRotation = Quaternion.identity;
					val5.transform.localScale = Vector3.one;
				}
			}
			ItemManager.Instance.AddItem(val2);
			ItemDrop component = val2.ItemPrefab.GetComponent<ItemDrop>();
			if ((Object)(object)component != (Object)null && (Object)(object)SaddleIcon != (Object)null)
			{
				component.m_itemData.m_shared.m_icons = (Sprite[])(object)new Sprite[1] { SaddleIcon };
			}
			ItemConfig val6 = new ItemConfig();
			val6.CraftingStation = "piece_magetable";
			val6.AddRequirement(new RequirementConfig
			{
				Item = "LinenThread",
				Amount = 20
			});
			val6.AddRequirement(new RequirementConfig
			{
				Item = "BlackMetal",
				Amount = 15
			});
			val6.AddRequirement(new RequirementConfig
			{
				Item = "Copper",
				Amount = 15
			});
			val6.AddRequirement(new RequirementConfig
			{
				Item = "YggdrasilWood",
				Amount = 30
			});
			val6.AddRequirement(new RequirementConfig
			{
				Item = "JuteRed",
				Amount = 10
			});
			val6.AddRequirement(new RequirementConfig
			{
				Item = "JuteBlue",
				Amount = 10
			});
			val6.AddRequirement(new RequirementConfig
			{
				Item = "Lantern",
				Amount = 2
			});
			CustomItem val7 = new CustomItem("EnchantedLoxSaddleBags", "SaddleLox", val6);
			if ((Object)(object)EnchantedDropSaddleModel != (Object)null)
			{
				Transform val8 = val7.ItemPrefab.transform.Find("attach");
				if ((Object)(object)val8 != (Object)null)
				{
					Renderer[] componentsInChildren2 = ((Component)val8).GetComponentsInChildren<Renderer>(true);
					foreach (Renderer val9 in componentsInChildren2)
					{
						val9.enabled = false;
					}
					GameObject val10 = Object.Instantiate<GameObject>(EnchantedDropSaddleModel, val8);
					val10.transform.localPosition = Vector3.zero;
					val10.transform.localRotation = Quaternion.identity;
					val10.transform.localScale = Vector3.one;
				}
			}
			ItemManager.Instance.AddItem(val7);
			ItemDrop component2 = val7.ItemPrefab.GetComponent<ItemDrop>();
			if ((Object)(object)component2 != (Object)null && (Object)(object)EnchantedSaddleIcon != (Object)null)
			{
				component2.m_itemData.m_shared.m_icons = (Sprite[])(object)new Sprite[1] { EnchantedSaddleIcon };
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Lox saddle bags added");
			ItemConfig val11 = new ItemConfig();
			val11.CraftingStation = "piece_preptable";
			val11.Amount = 10;
			val11.AddRequirement(new RequirementConfig
			{
				Item = "FragrantBundle",
				Amount = 10
			});
			val11.AddRequirement(new RequirementConfig
			{
				Item = "SpicePlains",
				Amount = 1
			});
			val11.AddRequirement(new RequirementConfig
			{
				Item = "Honey",
				Amount = 10
			});
			val11.AddRequirement(new RequirementConfig
			{
				Item = "Dandelion",
				Amount = 10
			});
			CustomItem val12 = new CustomItem("LoxHealingTreat", "CookedLoxMeat", val11);
			ItemManager.Instance.AddItem(val12);
			ItemDrop component3 = val12.ItemPrefab.GetComponent<ItemDrop>();
			if ((Object)(object)component3 != (Object)null)
			{
				SharedData shared = component3.m_itemData.m_shared;
				shared.m_food = 0f;
				shared.m_foodStamina = 0f;
				shared.m_foodBurnTime = 0f;
				shared.m_foodRegen = 0f;
				if ((Object)(object)HealingTreatIcon != (Object)null)
				{
					shared.m_icons = (Sprite[])(object)new Sprite[1] { HealingTreatIcon };
				}
				Transform val13 = val12.ItemPrefab.transform.Find("attach");
				if ((Object)(object)val13 != (Object)null && (Object)(object)HealingTreatModel != (Object)null)
				{
					Renderer[] componentsInChildren3 = ((Component)val13).GetComponentsInChildren<Renderer>(true);
					foreach (Renderer val14 in componentsInChildren3)
					{
						val14.enabled = false;
					}
					GameObject val15 = Object.Instantiate<GameObject>(HealingTreatModel, val13);
					val15.transform.localPosition = Vector3.zero;
					val15.transform.localRotation = Quaternion.identity;
					val15.transform.localScale = Vector3.one;
				}
			}
			ItemConfig val16 = new ItemConfig();
			val16.CraftingStation = "piece_preptable";
			val16.Amount = 10;
			val16.AddRequirement(new RequirementConfig
			{
				Item = "Cloudberry",
				Amount = 10
			});
			val16.AddRequirement(new RequirementConfig
			{
				Item = "Honey",
				Amount = 10
			});
			val16.AddRequirement(new RequirementConfig
			{
				Item = "Blueberries",
				Amount = 10
			});
			val16.AddRequirement(new RequirementConfig
			{
				Item = "FreezeGland",
				Amount = 5
			});
			CustomItem val17 = new CustomItem("LoxEnergyTreat", "CookedLoxMeat", val16);
			ItemManager.Instance.AddItem(val17);
			ItemDrop component4 = val17.ItemPrefab.GetComponent<ItemDrop>();
			if ((Object)(object)component4 != (Object)null)
			{
				SharedData shared2 = component4.m_itemData.m_shared;
				shared2.m_food = 0f;
				shared2.m_foodStamina = 0f;
				shared2.m_foodBurnTime = 0f;
				shared2.m_foodRegen = 0f;
				if ((Object)(object)EnergyTreatIcon != (Object)null)
				{
					shared2.m_icons = (Sprite[])(object)new Sprite[1] { EnergyTreatIcon };
				}
				Transform val18 = val17.ItemPrefab.transform.Find("attach");
				if ((Object)(object)val18 != (Object)null && (Object)(object)EnergyTreatModel != (Object)null)
				{
					Renderer[] componentsInChildren4 = ((Component)val18).GetComponentsInChildren<Renderer>(true);
					foreach (Renderer val19 in componentsInChildren4)
					{
						val19.enabled = false;
					}
					GameObject val20 = Object.Instantiate<GameObject>(EnergyTreatModel, val18);
					val20.transform.localPosition = Vector3.zero;
					val20.transform.localRotation = Quaternion.identity;
					val20.transform.localScale = Vector3.one;
				}
			}
			CreateTrinket("LoxTrinketOceanItem", OceanTrinketModel, OceanTrinketIcon, "piece_magetable", new RequirementConfig
			{
				Item = "Fish12",
				Amount = 1
			}, new RequirementConfig
			{
				Item = "TrophySerpent",
				Amount = 1
			}, new RequirementConfig
			{
				Item = "AmberPearl",
				Amount = 1
			}, new RequirementConfig
			{
				Item = "Bronze",
				Amount = 10
			});
			CreateTrinket("LoxTrinketMistlandsItem", MistlandsTrinketModel, MistlandsTrinketIcon, "piece_magetable", new RequirementConfig
			{
				Item = "TrophySGolem",
				Amount = 1
			}, new RequirementConfig
			{
				Item = "Wisp",
				Amount = 1
			}, new RequirementConfig
			{
				Item = "Mandible",
				Amount = 2
			}, new RequirementConfig
			{
				Item = "Copper",
				Amount = 10
			});
			CreateTrinket("LoxTrinketAshlandsItem", AshlandsTrinketModel, AshlandsTrinketIcon, "piece_magetable", new RequirementConfig
			{
				Item = "ProustitePowder",
				Amount = 1
			}, new RequirementConfig
			{
				Item = "MoltenCore",
				Amount = 1
			}, new RequirementConfig
			{
				Item = "CelestialFeather",
				Amount = 2
			}, new RequirementConfig
			{
				Item = "Silver",
				Amount = 10
			});
			Debug.Log((object)"ABOUT TO CREATE LOX FLUTE");
			CreateLoxTetherRope();
			CreateLoxFlute();
			Debug.Log((object)"ADD ITEMS FINISHED");
		}
	}
	[HarmonyPatch(typeof(Tameable), "SpawnSaddle")]
	public static class SpawnSaddlePatch
	{
		private static bool Prefix(Tameable __instance, Vector3 flyDirection)
		{
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: 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_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			Debug.Log((object)"SPAWN SADDLE PATCH");
			ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
			if ((Object)(object)component == (Object)null || !component.IsValid())
			{
				return true;
			}
			bool flag = component.GetZDO().GetBool("LoxSaddleBags", false);
			bool flag2 = component.GetZDO().GetBool("EnchantedLoxSaddleBags", false);
			Plugin.UpdateEnchantedState(__instance, enabled: false);
			Debug.Log((object)$"HAS BAGS: {flag}");
			if (!flag)
			{
				return true;
			}
			Debug.Log((object)$"HAS BAGS: {flag}");
			string text = (flag2 ? "EnchantedLoxSaddleBags" : "LoxSaddleBags");
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(text);
			if ((Object)(object)itemPrefab == (Object)null)
			{
				Debug.Log((object)"LoxSaddleBags prefab not found");
				return true;
			}
			Rigidbody component2 = Object.Instantiate<GameObject>(itemPrefab, ((Component)__instance).transform.TransformPoint(__instance.m_dropSaddleOffset), Quaternion.identity).GetComponent<Rigidbody>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				Vector3 val = Vector3.up;
				if (((Vector3)(ref flyDirection)).magnitude > 0.1f)
				{
					flyDirection.y = 0f;
					((Vector3)(ref flyDirection)).Normalize();
					val += flyDirection;
				}
				component2.AddForce(val * __instance.m_dropItemVel, (ForceMode)2);
			}
			component.GetZDO().Set("LoxSaddleBags", false);
			component.GetZDO().Set("EnchantedLoxSaddleBags", false);
			Debug.Log((object)("DROPPING: " + text));
			Debug.Log((object)"DROPPED BAG SADDLE");
			Debug.Log((object)"SPAWNING BAG SADDLE");
			return false;
		}
	}
	public class EnchantedLoxRiderProtectionUpdater : MonoBehaviour
	{
		private bool _protectionApplied;

		private bool _previousSkipTargetValue;

		private void Update()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			if (IsRidingEnchantedLox(localPlayer))
			{
				if (!_protectionApplied)
				{
					_previousSkipTargetValue = ((Character)localPlayer).m_aiSkipTarget;
					_protectionApplied = true;
				}
				((Character)localPlayer).m_aiSkipTarget = true;
			}
			else if (_protectionApplied)
			{
				((Character)localPlayer).m_aiSkipTarget = _previousSkipTargetValue;
				_protectionApplied = false;
			}
		}

		private static bool IsRidingEnchantedLox(Player player)
		{
			if ((Object)(object)player == (Object)null)
			{
				return false;
			}
			IDoodadController doodadController = player.GetDoodadController();
			Sadle val = (Sadle)(object)((doodadController is Sadle) ? doodadController : null);
			if (val == null)
			{
				return false;
			}
			Tameable tameable = val.GetTameable();
			if ((Object)(object)tameable == (Object)null)
			{
				return false;
			}
			Character character = val.GetCharacter();
			if ((Object)(object)character == (Object)null)
			{
				return false;
			}
			if (!((Object)character).name.StartsWith("Lox"))
			{
				return false;
			}
			ZNetView component = ((Component)tameable).GetComponent<ZNetView>();
			if ((Object)(object)component == (Object)null || !component.IsValid())
			{
				return false;
			}
			return component.GetZDO().GetBool("EnchantedLoxSaddleBags", false);
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "OnRightClickItem")]
	public static class LoxTrinketRightClickPatch
	{
		private static bool Prefix(InventoryGrid grid, ItemData item, Vector2i pos)
		{
			if ((Object)(object)InventoryGui.instance == (Object)null)
			{
				return true;
			}
			if (!LoxTrinketGrid.IsOpen)
			{
				return true;
			}
			if ((Object)(object)grid == (Object)null)
			{
				return true;
			}
			Inventory inventory = grid.GetInventory();
			if (!LoxTrinketGrid.IsValidTrinketSource(inventory))
			{
				return true;
			}
			if (LoxTrinketGrid.TryEquipFromInventory(item, inventory))
			{
				return false;
			}
			return true;
		}
	}
	internal static class LoxAshlandsTrinketHelper
	{
		public static bool HasAshlandsTrinket(Character character)
		{
			if ((Object)(object)character == (Object)null)
			{
				return false;
			}
			if (!((Object)character).name.StartsWith("Lox"))
			{
				return false;
			}
			Tameable component = ((Component)character).GetComponent<Tameable>();
			if ((Object)(object)component == (Object)null)
			{
				return false;
			}
			return LoxTrinketGrid.HasEquippedTrinket(component, "LoxTrinketAshlandsItem");
		}
	}
	[HarmonyPatch(typeof(Character), "Damage")]
	public static class LoxAshlandsTrinketDamagePatch
	{
		private static void Prefix(Character __instance, HitData hit)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Invalid comparison between Unknown and I4
			if (!((Object)(object)__instance == (Object)null) && hit != null && LoxAshlandsTrinketHelper.HasAshlandsTrinket(__instance))
			{
				hit.m_damage.m_fire = 0f;
				if ((int)hit.m_hitType == 5)
				{
					hit.m_damage.m_damage = 0f;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Character), "UpdateLava")]
	public static class LoxAshlandsTrinketLavaPatch
	{
		private static readonly FieldInfo LavaHeatLevelField = AccessTools.Field(typeof(Character), "m_lavaHeatLevel");

		private static void Postfix(Character __instance)
		{
			if (LoxAshlandsTrinketHelper.HasAshlandsTrinket(__instance))
			{
				LavaHeatLevelField?.SetValue(__instance, 0f);
			}
		}
	}
	public static class LoxFlute
	{
		private static GameObject _activeUseVisual;

		private static Coroutine _highlightCoroutine;

		private static readonly FieldInfo RightHandField = AccessTools.Field(typeof(Humanoid), "m_rightHand");

		private static readonly FieldInfo ZanimField = AccessTools.Field(typeof(Character), "m_zanim");

		public const string PrefabName = "LoxFlute";

		public const float SummonRadius = 100f;

		private static int _lastSoundIndex = -1;

		public static bool IsFlute(ItemData item)
		{
			if ((Object)(object)item?.m_dropPrefab == (Object)null)
			{
				return false;
			}
			return ((Object)item.m_dropPrefab).name == "LoxFlute";
		}

		public static void Use(Player player, ItemData item)
		{
			if (!((Object)(object)player == (Object)null))
			{
				HighlightInventoryIcon(player, item);
				PlayUseAnimation(player);
				PlayUseVisual(player);
				PlayFluteSound(player);
				int num = SummonEnchantedLoxes(player);
				switch (num)
				{
				case 0:
					((Character)player).Message((MessageType)2, "No lox heard your calls.", 0, (Sprite)null);
					break;
				case 1:
					((Character)player).Message((MessageType)2, "Lox is coming.", 0, (Sprite)null);
					break;
				default:
					((Character)player).Message((MessageType)2, num + "Loxes are coming.", 0, (Sprite)null);
					break;
				}
			}
		}

		private static void HighlightInventoryIcon(Player player, ItemData item)
		{
			if (!((Object)(object)player == (Object)null) && item != null)
			{
				if (_highlightCoroutine != null)
				{
					((MonoBehaviour)player).StopCoroutine(_highlightCoroutine);
					_highlightCoroutine = null;
				}
				_highlightCoroutine = ((MonoBehaviour)player).StartCoroutine(HighlightInventoryIconRoutine(item));
			}
		}

		private static IEnumerator HighlightInventoryIconRoutine(ItemData item)
		{
			if (item != null)
			{
				item.m_equipped = true;
				yield return (object)new WaitForSeconds(0.8f);
				if (item != null)
				{
					item.m_equipped = false;
				}
				_highlightCoroutine = null;
			}
		}

		private static void PlayUseAnimation(Player player)
		{
			if ((Object)(object)player == (Object)null)
			{
				return;
			}
			object obj = ZanimField?.GetValue(player);
			if (obj == null)
			{
				Debug.LogError((object)"LOX FLUTE: m_zanim not found");
				return;
			}
			MethodInfo methodInfo = AccessTools.Method(obj.GetType(), "SetTrigger", new Type[1] { typeof(string) }, (Type[])null);
			if (methodInfo == null)
			{
				Debug.LogError((object)"LOX FLUTE: SetTrigger not found");
				return;
			}
			methodInfo.Invoke(obj, new object[1] { "eat" });
			Debug.Log((object)"LOX FLUTE: eat animation triggered");
		}

		private static void PlayUseVisual(Player player)
		{
			if ((Object)(object)player == (Object)null)
			{
				return;
			}
			if ((Object)(object)Plugin.FluteModel == (Object)null)
			{
				Debug.LogError((object)"LOX FLUTE: FluteModel is null");
				return;
			}
			Transform rightHand = GetRightHand(player);
			if ((Object)(object)rightHand == (Object)null)
			{
				Debug.LogError((object)"LOX FLUTE: right hand not found");
			}
			else
			{
				((MonoBehaviour)player).StartCoroutine(UseVisualRoutine(rightHand));
			}
		}

		private static IEnumerator UseVisualRoutine(Transform hand)
		{
			if ((Object)(object)_activeUseVisual != (Object)null)
			{
				Object.Destroy((Object)(object)_activeUseVisual);
			}
			_activeUseVisual = Object.Instantiate<GameObject>(Plugin.FluteModel, hand, false);
			((Object)_activeUseVisual).name = "LoxFlute_UseVisual";
			_activeUseVisual.transform.localPosition = new Vector3(0.0005f, 0.0015f, 0.0014f);
			_activeUseVisual.transform.localRotation = Quaternion.Euler(20f, 345f, 70f);
			_activeUseVisual.transform.localScale = Vector3.one * 0.005f;
			Collider[] componentsInChildren = _activeUseVisual.GetComponentsInChildren<Collider>(true);
			foreach (Collider collider in componentsInChildren)
			{
				collider.enabled = false;
			}
			Rigidbody[] componentsInChildren2 = _activeUseVisual.GetComponentsInChildren<Rigidbody>(true);
			foreach (Rigidbody rb in componentsInChildren2)
			{
				Object.Destroy((Object)(object)rb);
			}
			Renderer[] componentsInChildren3 = _activeUseVisual.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer renderer in componentsInChildren3)
			{
				renderer.enabled = true;
				((Component)renderer).gameObject.SetActive(true);
			}
			yield return (object)new WaitForSeconds(1.5f);
			if ((Object)(object)_activeUseVisual != (Object)null)
			{
				Object.Destroy((Object)(object)_activeUseVisual);
				_activeUseVisual = null;
			}
		}

		private static Transform GetRightHand(Player player)
		{
			if ((Object)(object)player == (Object)null)
			{
				return null;
			}
			object? obj = RightHandField?.GetValue(player);
			Transform val = (Transform)((obj is Transform) ? obj : null);
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			Transform[] componentsInChildren = ((Component)player).GetComponentsInChildren<Transform>(true);
			Transform[] array = componentsInChildren;
			foreach (Transform val2 in array)
			{
				string text = ((Object)val2).name.ToLowerInvariant();
				if (text.Contains("righthand") || text.Contains("right_hand") || text.Contains("hand.r") || text.Contains("hand_r"))
				{
					return val2;
				}
			}
			return null;
		}

		private static int SummonEnchantedLoxes(Player player)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			Vector3 position = ((Component)player).transform.position;
			foreach (Character allCharacter in Character.GetAllCharacters())
			{
				if ((Object)(object)allCharacter == (Object)null || !((Object)allCharacter).name.StartsWith("Lox") || allCharacter.IsDead())
				{
					continue;
				}
				float num2 = Vector3.Distance(position, ((Component)allCharacter).transform.position);
				if (num2 > 100f)
				{
					continue;
				}
				Tameable component = ((Component)allCharacter).GetComponent<Tameable>();
				if ((Object)(object)component == (Object)null || !component.IsTamed())
				{
					continue;
				}
				ZNetView component2 = ((Component)allCharacter).GetComponent<ZNetView>();
				if ((Object)(object)component2 == (Object)null || !component2.IsValid() || !component2.GetZDO().GetBool("EnchantedLoxSaddleBags", false))
				{
					continue;
				}
				MonsterAI component3 = ((Component)allCharacter).GetComponent<MonsterAI>();
				if (!((Object)(object)component3 == (Object)null))
				{
					((BaseAI)component3).ResetPatrolPoint();
					component3.SetFollowTarget(((Component)player).gameObject);
					if (component2.IsOwner())
					{
						component2.GetZDO().Set(ZDOVars.s_follow, player.GetPlayerName());
					}
					num++;
					Debug.Log((object)("LOX FLUTE: summoned " + ((Object)allCharacter).name + ", " + $"distance = {num2:F1}"));
				}
			}
			return num;
		}

		public static bool IsEquipped(Player player)
		{
			if ((Object)(object)player == (Object)null)
			{
				return false;
			}
			ItemData currentWeapon = ((Humanoid)player).GetCurrentWeapon();
			return IsFlute(currentWeapon);
		}

		private static void PlayFluteSound(Player player)
		{
			if ((Object)(object)player == (Object)null)
			{
				return;
			}
			if (Plugin.FluteSounds == null || Plugin.FluteSounds.Length == 0)
			{
				Debug.LogError((object)"LOX FLUTE SOUNDS ARE EMPTY");
				return;
			}
			AudioClip randomFluteSound = GetRandomFluteSound();
			if ((Object)(object)randomFluteSound == (Object)null)
			{
				Debug.LogError((object)"LOX FLUTE RANDOM CLIP IS NULL");
				return;
			}
			AudioSource val = ((Component)player).GetComponent<AudioSource>();
			if ((Object)(object)val == (Object)null)
			{
				val = ((Component)player).gameObject.AddComponent<AudioSource>();
				val.playOnAwake = false;
				val.spatialBlend = 0f;
			}
			val.PlayOneShot(randomFluteSound, 1f);
			Debug.Log((object)("LOX FLUTE SOUND PLAYED: " + ((Object)randomFluteSound).name));
		}

		private static AudioClip GetRandomFluteSound()
		{
			if (Plugin.FluteSounds == null || Plugin.FluteSounds.Length == 0)
			{
				return null;
			}
			if (Plugin.FluteSounds.Length == 1)
			{
				_lastSoundIndex = 0;
				return Plugin.FluteSounds[0];
			}
			int num = Random.Range(0, Plugin.FluteSounds.Length);
			int num2 = 0;
			while (num == _lastSoundIndex && num2 < 10)
			{
				num = Random.Range(0, Plugin.FluteSounds.Length);
				num2++;
			}
			_lastSoundIndex = num;
			return Plugin.FluteSounds[num];
		}
	}
	public static class LoxInventory
	{
		public static Inventory Bags;

		public static Inventory Trinkets;

		public static void Create()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			if (Bags == null)
			{
				Bags = new Inventory("Lox Bags", (Sprite)null, 2, 3);
			}
			if (Trinkets == null)
			{
				Trinkets = new Inventory("Lox Trinkets", (Sprite)null, 2, 2);
			}
			Debug.Log((object)"Lox inventories created");
		}
	}
	[HarmonyPatch(typeof(Sadle), "UseStamina")]
	public static class LoxOceanTrinketStaminaPatch
	{
		private static bool Prefix(Sadle __instance, float v)
		{
			if ((Object)(object)__instance == (Object)null)
			{
				return true;
			}
			Character character = __instance.GetCharacter();
			if ((Object)(object)character == (Object)null)
			{
				return true;
			}
			if (!((Object)character).name.StartsWith("Lox"))
			{
				return true;
			}
			if (!character.IsSwimming())
			{
				return true;
			}
			Tameable tameable = __instance.GetTameable();
			if ((Object)(object)tameable == (Object)null)
			{
				return true;
			}
			if (!LoxTrinketGrid.HasEquippedTrinket(tameable, "LoxTrinketOceanItem"))
			{
				return true;
			}
			return false;
		}
	}
	public static class LoxTether
	{
		public const string PrefabName = "LoxTetherRope";

		public const float DefaultLength = 14f;

		public const string KeyTethered = "LoxTethered";

		public const string KeyAnchorX = "LoxTetherAnchorX";

		public const string KeyAnchorY = "LoxTetherAnchorY";

		public const string KeyAnchorZ = "LoxTetherAnchorZ";

		public const string KeyLength = "LoxTetherLength";

		public static bool IsTetherItem(ItemData item)
		{
			if ((Object)(object)item?.m_dropPrefab == (Object)null)
			{
				return false;
			}
			return ((Object)item.m_dropPrefab).name == "LoxTetherRope";
		}

		public static bool IsLox(Tameable tameable)
		{
			if ((Object)(object)tameable == (Object)null)
			{
				return false;
			}
			Character component = ((Component)tameable).GetComponent<Character>();
			if ((Object)(object)component == (Object)null)
			{
				return false;
			}
			return ((Object)component).name.StartsWith("Lox");
		}

		public static bool IsTethered(ZNetView nview)
		{
			if ((Object)(object)nview == (Object)null || !nview.IsValid())
			{
				return false;
			}
			return nview.GetZDO().GetBool("LoxTethered", false);
		}

		public static void SetTethered(ZNetView nview, Vector3 anchor, float length)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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)
			if (!((Object)(object)nview == (Object)null) && nview.IsValid())
			{
				ZDO zDO = nview.GetZDO();
				zDO.Set("LoxTethered", true);
				zDO.Set("LoxTetherAnchorX", anchor.x);
				zDO.Set("LoxTetherAnchorY", anchor.y);
				zDO.Set("LoxTetherAnchorZ", anchor.z);
				zDO.Set("LoxTetherLength", length);
				EnsureController(((Component)nview).gameObject);
			}
		}

		public static void SetUntethered(ZNetView nview)
		{
			if (!((Object)(object)nview == (Object)null) && nview.IsValid())
			{
				nview.GetZDO().Set("LoxTethered", false);
			}
		}

		public static bool TryGetTetherData(ZNetView nview, out Vector3 anchor, out float length)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			anchor = Vector3.zero;
			length = 14f;
			if ((Object)(object)nview == (Object)null || !nview.IsValid())
			{
				return false;
			}
			ZDO zDO = nview.GetZDO();
			if (!zDO.GetBool("LoxTethered", false))
			{
				return false;
			}
			anchor = new Vector3(zDO.GetFloat("LoxTetherAnchorX", 0f), zDO.GetFloat("LoxTetherAnchorY", 0f), zDO.GetFloat("LoxTetherAnchorZ", 0f));
			length = zDO.GetFloat("LoxTetherLength", 14f);
			return true;
		}

		public static void EnsureController(GameObject obj)
		{
			if (!((Object)(object)obj == (Object)null) && !((Object)(object)obj.GetComponent<LoxTetherController>() != (Object)null))
			{
				obj.AddComponent<LoxTetherController>();
			}
		}
	}
	public class LoxTetherController : MonoBehaviour
	{
		private ZNetView _nview;

		private Character _character;

		private Rigidbody _rigidbody;

		private LineRenderer _line;

		private const float PullStrength = 28f;

		private const float HardLimitBuffer = 1.5f;

		private void Awake()
		{
			_nview = ((Component)this).GetComponent<ZNetView>();
			_character = ((Component)this).GetComponent<Character>();
			_rigidbody = ((Component)this).GetComponent<Rigidbody>();
			CreateLine();
		}

		private void FixedUpdate()
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_nview == (Object)null || !_nview.IsValid())
			{
				HideLine();
				return;
			}
			if ((Object)(object)_character != (Object)null && _character.IsDead())
			{
				HideLine();
				return;
			}
			if (!LoxTether.TryGetTetherData(_nview, out var anchor, out var length))
			{
				HideLine();
				return;
			}
			UpdateLine(anchor);
			if (_nview.IsOwner())
			{
				EnforceLimit(anchor, length);
			}
		}

		private void EnforceLimit(Vector3 anchor, float length)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: 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_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//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)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: 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)
			Vector3 position = ((Component)this).transform.position;
			Vector3 val = position - anchor;
			val.y = 0f;
			float magnitude = ((Vector3)(ref val)).magnitude;
			if (magnitude <= length)
			{
				return;
			}
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			if ((Object)(object)_rigidbody != (Object)null)
			{
				Vector3 velocity = _rigidbody.velocity;
				Vector3 val2 = default(Vector3);
				((Vector3)(ref val2))..ctor(velocity.x, 0f, velocity.z);
				float num = Vector3.Dot(val2, normalized);
				if (num > 0f)
				{
					val2 -= normalized * num;
					_rigidbody.velocity = new Vector3(val2.x, velocity.y, val2.z);
				}
				_rigidbody.AddForce(-normalized * 28f, (ForceMode)5);
			}
			if (magnitude > length + 1.5f)
			{
				Vector3 val3 = anchor + normalized * length;
				val3.y = position.y;
				((Component)this).transform.position = Vector3.Lerp(position, val3, Time.fixedDeltaTime * 8f);
			}
		}

		private void CreateLine()
		{
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Expected O, but got Unknown
			if (!((Object)(object)_line != (Object)null))
			{
				_line = ((Component)this).gameObject.AddComponent<LineRenderer>();
				_line.positionCount = 16;
				_line.useWorldSpace = true;
				((Renderer)_line).enabled = false;
				_line.startWidth = 0.035f;
				_line.endWidth = 0.028f;
				_line.numCapVertices = 2;
				_line.numCornerVertices = 2;
				Shader val = Shader.Find("Sprites/Default");
				if ((Object)(object)val != (Object)null)
				{
					((Renderer)_line).material = new Material(val);
				}
				Color val2 = default(Color);
				((Color)(ref val2))..ctor(0.34f, 0.22f, 0.11f, 0.95f);
				_line.startColor = val2;
				_line.endColor = val2;
			}
		}

		private void UpdateLine(Vector3 anchor)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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)
			//IL_0060: 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)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: 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)
			if (!((Object)(object)_line == (Object)null))
			{
				((Renderer)_line).enabled = true;
				Vector3 val = anchor + Vector3.up * 0.18f;
				Vector3 val2 = ((Component)this).transform.position + Vector3.up * 1.25f + ((Component)this).transform.forward * 0.25f;
				int num = 16;
				_line.positionCount = num;
				float num2 = Vector3.Distance(val, val2);
				float num3 = Mathf.Clamp(num2 * 0.08f, 0.15f, 0.75f);
				for (int i = 0; i < num; i++)
				{
					float num4 = (float)i / (float)(num - 1);
					Vector3 val3 = Vector3.Lerp(val, val2, num4);
					float num5 = Mathf.Sin(num4 * (float)Math.PI) * num3;
					val3.y -= num5;
					_line.SetPosition(i, val3);
				}
			}
		}

		private void HideLine()
		{
			if ((Object)(object)_line != (Object)null)
			{
				((Renderer)_line).enabled = false;
			}
		}
	}
	[HarmonyPatch(typeof(Tameable), "UseItem")]
	public static class LoxTetherUsePatch
	{
		private static bool Prefix(Tameable __instance, Humanoid user, ItemData item, ref bool __result)
		{
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			if (!LoxTether.IsTetherItem(item))
			{
				return true;
			}
			Player val = (Player)(object)((user is Player) ? user : null);
			if ((Object)(object)val == (Object)null)
			{
				__result = false;
				return false;
			}
			if (!LoxTether.IsLox(__instance))
			{
				((Character)val).Message((MessageType)2, "This tether is made for Lox.", 0, (Sprite)null);
				__result = false;
				return false;
			}
			if (!__instance.IsTamed())
			{
				((Character)val).Message((MessageType)2, "The Lox must be tamed first.", 0, (Sprite)null);
				__result = false;
				return false;
			}
			ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
			if ((Object)(object)component == (Object)null || !component.IsValid())
			{
				__result = false;
				return false;
			}
			if (LoxTether.IsTethered(component))
			{
				LoxTether.SetUntethered(component);
				((Character)val).Message((MessageType)2, "Lox untethered.", 0, (Sprite)null);
				__result = true;
				return false;
			}
			Vector3 position = ((Component)val).transform.position;
			LoxTether.SetTethered(component, position, 14f);
			((Character)val).Message((MessageType)2, "Lox tethered.", 0, (Sprite)null);
			__result = true;
			return false;
		}
	}
	[HarmonyPatch(typeof(Tameable), "Awake")]
	public static class LoxTetherRestorePatch
	{
		private static void Postfix(Tameable __instance)
		{
			if (LoxTether.IsLox(__instance))
			{
				ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
				if (!((Object)(object)component == (Object)null) && component.IsValid() && LoxTether.IsTethered(component))
				{
					LoxTether.EnsureController(((Component)__instance).gameObject);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Tameable), "GetHoverText")]
	public static class LoxTetherHoverPatch
	{
		private static void Postfix(Tameable __instance, ref string __result)
		{
			if (LoxTether.IsLox(__instance))
			{
				ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
				if (!((Object)(object)component == (Object)null) && component.IsValid() && LoxTether.IsTethered(component))
				{
					__result += "\n<color=yellow>Tethered</color>";
				}
			}
		}
	}
	[HarmonyPatch(typeof(Humanoid), "UseItem", new Type[]
	{
		typeof(Inventory),
		typeof(ItemData),
		typeof(bool)
	})]
	public static class LoxHumanoidUseItemPatch
	{
		private static bool Prefix(Humanoid __instance, Inventory inventory, ItemData item, bool fromInventoryGui)
		{
			if ((Object)(object)__instance == (Object)null || item == null)
			{
				return true;
			}
			Player val = (Player)(object)((__instance is Player) ? __instance : null);
			if (val == null)
			{
				return true;
			}
			if (IsLoxTreat(item))
			{
				((Character)val).Message((MessageType)2, "This treat is only for Lox.", 0, (Sprite)null);
				return false;
			}
			if (LoxFlute.IsFlute(item))
			{
				LoxFlute.Use(val, item);
				return false;
			}
			return true;
		}

		private static bool IsLoxTreat(ItemData item)
		{
			if ((Object)(object)item?.m_dropPrefab == (Object)null)
			{
				return false;
			}
			string name = ((Object)item.m_dropPrefab).name;
			return name == "LoxEnergyTreat" || name == "LoxHealingTreat";
		}
	}
	public static class LoxTrinketGrid
	{
		private static GameObject _panel;

		private static LoxTrinketPanelAnimator _animator;

		private const int SlotCount = 3;

		private static readonly GameObject[] _slots = (GameObject[])(object)new GameObject[3];

		private static ZNetView _currentLoxView;

		private static Container _currentContainer;

		public static bool IsOpen => (Object)(object)_panel != (Object)null && _panel.activeInHierarchy;

		public static void Create(Transform parent)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_0054: 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)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_panel != (Object)null)
			{
				return;
			}
			InventoryGui instance = InventoryGui.instance;
			_panel = new GameObject("LoxTrinkets");
			_panel.transform.SetParent(parent, false);
			RectTransform val = _panel.AddComponent<RectTransform>();
			val.anchorMin = new Vector2(0f, 1f);
			val.anchorMax = new Vector2(0f, 1f);
			val.pivot = new Vector2(0f, 1f);
			val.sizeDelta = new Vector2(250f, 155f);
			val.anchoredPosition = new Vector2(35f, -720f);
			_animator = ((Component)InventoryGui.instance).gameObject.GetComponent<LoxTrinketPanelAnimator>();
			if ((Object)(object)_animator == (Object)null)
			{
				_animator = ((Component)InventoryGui.instance).gameObject.AddComponent<LoxTrinketPanelAnimator>();
			}
			_animator.Initialize(_panel, val, val.anchoredPosition);
			Transform val2 = ((Component)instance).transform.Find("root/Container/Bkg");
			if ((Object)(object)val2 != (Object)null)
			{
				GameObject val3 = Object.Instantiate<GameObject>(((Component)val2).gameObject, _panel.transform, false);
				((Object)val3).name = "Background";
				RectTransform component = val3.GetComponent<RectTransform>();
				component.anchorMin = Vector2.zero;
				component.anchorMax = Vector2.one;
				component.offsetMin = Vector2.zero;
				component.offsetMax = Vector2.zero;
				val3.transform.SetAsFirstSibling();
			}
			Transform val4 = ((Component)instance).transform.Find("root/Container/container_name");
			if ((Object)(object)val4 != (Object)null)
			{
				GameObject val5 = Object.Instantiate<GameObject>(((Component)val4).gameObject, _panel.transform, false);
				((Object)val5).name = "Title";
				TMP_Text component2 = val5.GetComponent<TMP_Text>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.text = "LOX TRINKETS";
				}
				RectTransform component3 = val5.GetComponent<RectTransform>();
				if ((Object)(object)component3 != (Object)null)
				{
					component3.anchorMin = new Vector2(0.5f, 1f);
					component3.anchorMax = new Vector2(0.5f, 1f);
					component3.pivot = new Vector2(0.5f, 1f);
					component3.anchoredPosition = new Vector2(0f, -24f);
				}
			}
			CreateSlots();
		}

		public static void OpenForLox(Tameable lox, Container container, Transform parent)
		{
			if (!((Object)(object)lox == (Object)null))
			{
				_currentLoxView = ((Component)lox).GetComponent<ZNetView>();
				_currentContainer = container;
				if (!((Object)(object)_currentLoxView == (Object)null) && _currentLoxView.IsValid())
				{
					Create(parent);
					UpdateSlots();
					Show();
				}
			}
		}

		private static string GetSlotKey(int index)
		{
			return "LoxTrinketSlot" + index;
		}

		private static string GetSlotItem(int index)
		{
			if ((Object)(object)_currentLoxView == (Object)null || !_currentLoxView.IsValid())
			{
				return "";
			}
			return _currentLoxView.GetZDO().GetString(GetSlotKey(index), "");
		}

		private static void SetSlotItem(int index, string prefabName)
		{
			if (!((Object)(object)_currentLoxView == (Object)null) && _currentLoxView.IsValid())
			{
				_currentLoxView.GetZDO().Set(GetSlotKey(index), prefabName);
			}
		}

		public static bool IsLoxTrinket(ItemData item)
		{
			object obj;
			if (item == null)
			{
				obj = null;
			}
			else
			{
				GameObject dropPrefab = item.m_dropPrefab;
				obj = ((dropPrefab != null) ? ((Object)dropPrefab).name : null);
			}
			string prefabName = (string)obj;
			return IsLoxTrinket(prefabName);
		}

		public static bool IsLoxTrinket(string prefabName)
		{
			return prefabName == "LoxTrinketOceanItem" || prefabName == "LoxTrinketMistlandsItem" || prefabName == "LoxTrinketAshlandsItem";
		}

		public static bool IsValidTrinketSource(Inventory inventory)
		{
			if (inventory == null)
			{
				return false;
			}
			if ((Object)(object)Player.m_localPlayer != (Object)null && inventory == ((Humanoid)Player.m_localPlayer).GetInventory())
			{
				return true;
			}
			if ((Object)(object)_currentContainer != (Object)null && inventory == _currentContainer.GetInventory())
			{
				return true;
			}
			return false;
		}

		public static bool TryEquipFromInventory(ItemData item, Inventory sourceInventory)
		{
			if (!IsOpen)
			{
				return false;
			}
			if (!IsLoxTrinket(item))
			{
				return false;
			}
			if (sourceInventory == null)
			{
				return false;
			}
			string name = ((Object)item.m_dropPrefab).name;
			for (int i = 0; i < 3; i++)
			{
				if (GetSlotItem(i) == name)
				{
					((Character)Player.m_localPlayer).Message((MessageType)2, "This Lox trinket is already equipped.", 0, (Sprite)null);
					return true;
				}
			}
			for (int j = 0; j < 3; j++)
			{
				if (string.IsNullOrEmpty(GetSlotItem(j)))
				{
					SetSlotItem(j, name);
					sourceInventory.RemoveOneItem(item);
					UpdateSlots();
					((Character)Player.m_localPlayer).Message((MessageType)2, "Lox trinket equipped.", 0, (Sprite)null);
					return true;
				}
			}
			((Character)Player.m_localPlayer).Message((MessageType)2, "No free Lox Trinket slot.", 0, (Sprite)null);
			return true;
		}

		public static void Show()
		{
			if (!((Object)(object)_panel == (Object)null))
			{
				if ((Object)(object)_animator != (Object)null)
				{
					_animator.PlayShow();
				}
				else
				{
					_panel.SetActive(true);
				}
			}
		}

		public static void Hide()
		{
			if (!((Object)(object)_panel == (Object)null))
			{
				if ((Object)(object)_animator != (Object)null)
				{
					_animator.PlayHide();
				}
				else
				{
					_panel.SetActive(false);
				}
			}
		}

		public static void HideAnimated()
		{
			if (!((Object)(object)_panel == (Object)null))
			{
				if ((Object)(object)_animator != (Object)null)
				{
					_animator.PlayHide();
				}
				else
				{
					_panel.SetActive(false);
				}
			}
		}

		public static void Update()
		{
		}

		private static void CreateSlots()
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			InventoryGui instance = InventoryGui.instance;
			int num = 20;
			int num2 = 70;
			int num3 = 72;
			for (int i = 0; i < 3; i++)
			{
				GameObject val = Object.Instantiate<GameObject>(instance.m_playerGrid.m_elementPrefab, _panel.transform, false);
				((Object)val).name = "Slot" + i;
				_slots[i] = val;
				RectTransform component = val.GetComponent<RectTransform>();
				componen