Decompiled source of BattleBoar v1.0.0

BattleBoar.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyCompany("BattleBoar")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BattleBoar")]
[assembly: AssemblyTitle("BattleBoar")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BattleBoar
{
	public class BattleBoarController : MonoBehaviour
	{
		public enum BoarState
		{
			Following,
			Staying,
			Mounted
		}

		private Character character;

		private MonsterAI monsterAI;

		private Tameable tameable;

		private Sadle sadle;

		public BoarState CurrentState { get; private set; } = BoarState.Following;


		public Player Owner { get; private set; }

		public bool IsValid => (Object)(object)this != (Object)null && (Object)(object)((Component)this).gameObject != (Object)null && ((Component)this).gameObject.activeInHierarchy;

		private void Awake()
		{
			character = ((Component)this).GetComponent<Character>();
			monsterAI = ((Component)this).GetComponent<MonsterAI>();
			tameable = ((Component)this).GetComponent<Tameable>();
			sadle = ((Component)this).GetComponentInChildren<Sadle>();
		}

		public void Initialize(Player player)
		{
			Owner = player;
			CurrentState = BoarState.Following;
			if ((Object)(object)monsterAI == (Object)null)
			{
				monsterAI = ((Component)this).GetComponent<MonsterAI>();
			}
			if ((Object)(object)sadle == (Object)null)
			{
				sadle = ((Component)this).GetComponentInChildren<Sadle>();
			}
		}

		private void LateUpdate()
		{
			//IL_0029: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			if (CurrentState == BoarState.Staying)
			{
				Rigidbody component = ((Component)this).GetComponent<Rigidbody>();
				if ((Object)(object)component != (Object)null)
				{
					component.linearVelocity = new Vector3(0f, component.linearVelocity.y, 0f);
					component.angularVelocity = Vector3.zero;
				}
			}
		}

		public void ToggleFollowStay()
		{
			//IL_006c: 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)
			if (!OwnerAlive())
			{
				return;
			}
			if (CurrentState == BoarState.Following)
			{
				CurrentState = BoarState.Staying;
				if ((Object)(object)monsterAI != (Object)null)
				{
					monsterAI.SetFollowTarget((GameObject)null);
					((BaseAI)monsterAI).SetPatrolPoint();
					Rigidbody component = ((Component)this).GetComponent<Rigidbody>();
					if ((Object)(object)component != (Object)null)
					{
						component.linearVelocity = Vector3.zero;
						component.angularVelocity = Vector3.zero;
					}
				}
				((Character)Owner).Message((MessageType)2, "BattleBoar: Stay!", 0, (Sprite)null);
				BattleBoarPlugin.Log("BattleBoar set to Stay.");
			}
			else
			{
				CurrentState = BoarState.Following;
				if ((Object)(object)monsterAI != (Object)null)
				{
					monsterAI.SetFollowTarget(((Component)Owner).gameObject);
				}
				((Character)Owner).Message((MessageType)2, "BattleBoar: Follow!", 0, (Sprite)null);
				BattleBoarPlugin.Log("BattleBoar set to Follow.");
			}
		}

		public void OnMounted()
		{
			CurrentState = BoarState.Mounted;
			if ((Object)(object)monsterAI != (Object)null)
			{
				monsterAI.SetFollowTarget((GameObject)null);
			}
			BattleBoarPlugin.Log("BattleBoar mounted.");
		}

		public void OnDismounted()
		{
			CurrentState = BoarState.Following;
			if ((Object)(object)monsterAI != (Object)null && OwnerAlive())
			{
				monsterAI.SetFollowTarget(((Component)Owner).gameObject);
			}
			BattleBoarPlugin.Log("BattleBoar dismounted, resuming follow.");
		}

		public string GetCustomHoverText()
		{
			return CurrentState switch
			{
				BoarState.Mounted => "BattleBoar", 
				BoarState.Following => "BattleBoar (Following)\n[<color=yellow><b>E</b></color>] Mount\n[<color=yellow><b>Shift+E</b></color>] Stay", 
				BoarState.Staying => "BattleBoar (Staying)\n[<color=yellow><b>E</b></color>] Mount\n[<color=yellow><b>Shift+E</b></color>] Follow", 
				_ => "BattleBoar", 
			};
		}

		public void ClearOwner()
		{
			Owner = null;
		}

		private bool OwnerAlive()
		{
			return (Object)(object)Owner != (Object)null && (Object)(object)((Component)Owner).gameObject != (Object)null && ((Component)Owner).gameObject.activeInHierarchy;
		}
	}
	public class BattleBoarSpawner : MonoBehaviour
	{
		[CompilerGenerated]
		private sealed class <SetupAI>d__13 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public GameObject boarObj;

			public Player player;

			public Tameable tameable;

			public Character character;

			public ZNetView nview;

			public BattleBoarSpawner <>4__this;

			private Transform <visual>5__1;

			private MonsterAI <monsterAI>5__2;

			private float <scale>5__3;

			private Transform <spineBone>5__4;

			private Transform <saddleParent>5__5;

			private GameObject <saddleGO>5__6;

			private SphereCollider <col>5__7;

			private GameObject <mountPoint>5__8;

			private Sadle <sadle>5__9;

			private FieldInfo <nviewF>5__10;

			private FieldInfo <charF>5__11;

			private FieldInfo <tambF>5__12;

			private FieldInfo <aiF>5__13;

			private BattleBoarController <controller>5__14;

			private string <msg>5__15;

			private FieldInfo <field>5__16;

			private MethodInfo <setSaddle>5__17;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <SetupAI>d__13(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<visual>5__1 = null;
				<monsterAI>5__2 = null;
				<spineBone>5__4 = null;
				<saddleParent>5__5 = null;
				<saddleGO>5__6 = null;
				<col>5__7 = null;
				<mountPoint>5__8 = null;
				<sadle>5__9 = null;
				<nviewF>5__10 = null;
				<charF>5__11 = null;
				<tambF>5__12 = null;
				<aiF>5__13 = null;
				<controller>5__14 = null;
				<msg>5__15 = null;
				<field>5__16 = null;
				<setSaddle>5__17 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_012b: Unknown result type (might be due to invalid IL or missing references)
				//IL_038e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0398: Expected O, but got Unknown
				//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
				//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
				//IL_0413: Unknown result type (might be due to invalid IL or missing references)
				//IL_046a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0474: Expected O, but got Unknown
				//IL_04a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_04ca: Unknown result type (might be due to invalid IL or missing references)
				//IL_05a7: Unknown result type (might be due to invalid IL or missing references)
				//IL_05ac: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					if ((Object)(object)boarObj == (Object)null)
					{
						return false;
					}
					<visual>5__1 = boarObj.transform.Find("Visual");
					if ((Object)(object)<visual>5__1 != (Object)null && !((Component)<visual>5__1).gameObject.activeSelf)
					{
						((Component)<visual>5__1).gameObject.SetActive(true);
					}
					<monsterAI>5__2 = boarObj.GetComponent<MonsterAI>();
					if ((Object)(object)<monsterAI>5__2 == (Object)null)
					{
						<monsterAI>5__2 = boarObj.AddComponent<MonsterAI>();
						((BaseAI)<monsterAI>5__2).m_viewRange = 60f;
						((BaseAI)<monsterAI>5__2).m_viewAngle = 360f;
						((BaseAI)<monsterAI>5__2).m_hearRange = 60f;
						((BaseAI)<monsterAI>5__2).m_pathAgentType = (AgentType)1;
						((BaseAI)<monsterAI>5__2).m_smoothMovement = true;
						((BaseAI)<monsterAI>5__2).m_avoidFire = false;
						((BaseAI)<monsterAI>5__2).m_afraidOfFire = false;
						((BaseAI)<monsterAI>5__2).m_avoidWater = false;
						((BaseAI)<monsterAI>5__2).m_aggravatable = false;
						<monsterAI>5__2.m_fleeIfNotAlerted = false;
						<monsterAI>5__2.m_fleeIfLowHealth = 0f;
						<monsterAI>5__2.m_fleeIfHurtWhenTargetCantBeReached = false;
						<monsterAI>5__2.m_fleeInLava = false;
						((BaseAI)<monsterAI>5__2).m_avoidLava = false;
						((BaseAI)<monsterAI>5__2).m_avoidLavaFlee = false;
						((BaseAI)<monsterAI>5__2).m_fleeRange = 0f;
						<monsterAI>5__2.m_fleeTimeSinceHurt = 0f;
					}
					if ((Object)(object)tameable != (Object)null)
					{
						<field>5__16 = AccessTools.Field(typeof(Tameable), "m_monsterAI");
						if (<field>5__16 != null)
						{
							<field>5__16.SetValue(tameable, <monsterAI>5__2);
						}
						<field>5__16 = null;
					}
					<>2__current = null;
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 3;
					return true;
				case 3:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 4;
					return true;
				case 4:
					<>1__state = -1;
					if ((Object)(object)boarObj == (Object)null)
					{
						return false;
					}
					if ((Object)(object)player == (Object)null || (Object)(object)((Component)player).gameObject == (Object)null)
					{
						return false;
					}
					<monsterAI>5__2.SetFollowTarget(((Component)player).gameObject);
					BattleBoarPlugin.Log("MonsterAI: follow target set.");
					<scale>5__3 = BattleBoarPlugin.BoarScale.Value;
					<visual>5__1 = boarObj.transform.Find("Visual");
					<spineBone>5__4 = null;
					if ((Object)(object)<visual>5__1 != (Object)null)
					{
						<spineBone>5__4 = <visual>5__1.Find("CG/Pelvis/Spine/Spine1");
					}
					<saddleParent>5__5 = (((Object)(object)<spineBone>5__4 != (Object)null) ? <spineBone>5__4 : boarObj.transform);
					if ((Object)(object)<spineBone>5__4 != (Object)null)
					{
						BattleBoarPlugin.Log("Found spine bone: CG/Pelvis/Spine/Spine1");
					}
					else
					{
						BattleBoarPlugin.LogWarn("Spine bone not found — parenting saddle to root.");
					}
					<saddleGO>5__6 = new GameObject("BattleBoarSaddle");
					<saddleGO>5__6.transform.SetParent(<saddleParent>5__5);
					<saddleGO>5__6.transform.localPosition = new Vector3(0.0189f, -0.283f, 0f);
					<saddleGO>5__6.transform.localEulerAngles = new Vector3(0f, -90f, 180f);
					<saddleGO>5__6.transform.localScale = new Vector3(0.9f, 1f, 1f);
					<saddleGO>5__6.layer = boarObj.layer;
					<col>5__7 = <saddleGO>5__6.AddComponent<SphereCollider>();
					<col>5__7.radius = 0.5f;
					((Collider)<col>5__7).isTrigger = false;
					<mountPoint>5__8 = new GameObject("MountPoint");
					<mountPoint>5__8.transform.SetParent(<saddleParent>5__5);
					<mountPoint>5__8.transform.localPosition = new Vector3(-0.01f, -0.22f, 0f);
					<mountPoint>5__8.transform.localEulerAngles = new Vector3(0f, 270f, 180f);
					<>4__this.mountPointTransform = <mountPoint>5__8.transform;
					<sadle>5__9 = <saddleGO>5__6.AddComponent<Sadle>();
					<sadle>5__9.m_attachPoint = <mountPoint>5__8.transform;
					<sadle>5__9.m_maxUseRange = 10f;
					<sadle>5__9.m_hoverText = "BattleBoar";
					<sadle>5__9.m_attachAnimation = "attach_asksvin";
					<sadle>5__9.m_maxStamina = 9999f;
					<sadle>5__9.m_runStaminaDrain = 0f;
					<sadle>5__9.m_swimStaminaDrain = 0f;
					<sadle>5__9.m_staminaRegen = 100f;
					<sadle>5__9.m_staminaRegenHungry = 100f;
					<sadle>5__9.m_detachOffset = new Vector3(0f, 0.5f, -1f);
					<nviewF>5__10 = AccessTools.Field(typeof(Sadle), "m_nview");
					<charF>5__11 = AccessTools.Field(typeof(Sadle), "m_character");
					<tambF>5__12 = AccessTools.Field(typeof(Sadle), "m_tambable");
					<aiF>5__13 = AccessTools.Field(typeof(Sadle), "m_monsterAI");
					BattleBoarPlugin.Log($"Fresh Sadle: nview={<nviewF>5__10?.GetValue(<sadle>5__9) != null}, " + $"char={<charF>5__11?.GetValue(<sadle>5__9) != null}, " + $"tamb={<tambF>5__12?.GetValue(<sadle>5__9) != null}, " + $"ai={<aiF>5__13?.GetValue(<sadle>5__9) != null}");
					<>4__this.AddSaddleVisual(<saddleGO>5__6);
					if ((Object)(object)tameable != (Object)null)
					{
						tameable.m_saddle = <sadle>5__9;
						tameable.m_dropSaddleOnDeath = false;
						<setSaddle>5__17 = AccessTools.Method(typeof(Tameable), "SetSaddle", (Type[])null, (Type[])null);
						<setSaddle>5__17?.Invoke(tameable, new object[1] { true });
						BattleBoarPlugin.Log($"SetSaddle(true). Active={<saddleGO>5__6.activeSelf}");
						<setSaddle>5__17 = null;
					}
					<>4__this.AttachArmorPieces(boarObj);
					<controller>5__14 = boarObj.AddComponent<BattleBoarController>();
					<controller>5__14.Initialize(player);
					<>4__this.ActiveBoar = <controller>5__14;
					<>4__this.heartCoroutine = ((MonoBehaviour)<>4__this).StartCoroutine(<>4__this.SpawnHeartEffects(boarObj, player, tameable));
					<msg>5__15 = "BattleBoar summoned!";
					if ((Object)(object)player != (Object)null && (Object)(object)((Component)player).gameObject != (Object)null)
					{
						((Character)player).Message((MessageType)2, <msg>5__15, 0, (Sprite)null);
					}
					BattleBoarPlugin.Log(<msg>5__15);
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <SpawnHeartEffects>d__34 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public GameObject boarObj;

			public Player player;

			public Tameable tameable;

			public BattleBoarSpawner <>4__this;

			private EffectList <effectToUse>5__1;

			private float <elapsed>5__2;

			private FieldInfo <petField>5__3;

			private FieldInfo <tamedField>5__4;

			private float <dist>5__5;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <SpawnHeartEffects>d__34(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<effectToUse>5__1 = null;
				<petField>5__3 = null;
				<tamedField>5__4 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0130: Unknown result type (might be due to invalid IL or missing references)
				//IL_0140: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
				//IL_01eb: Expected O, but got Unknown
				//IL_0188: 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_0197: Unknown result type (might be due to invalid IL or missing references)
				//IL_019c: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					if ((Object)(object)boarObj == (Object)null || (Object)(object)player == (Object)null)
					{
						return false;
					}
					<effectToUse>5__1 = null;
					if ((Object)(object)tameable != (Object)null)
					{
						<petField>5__3 = typeof(Tameable).GetField("m_petEffect", BindingFlags.Instance | BindingFlags.Public);
						if (<petField>5__3 != null)
						{
							ref EffectList reference = ref <effectToUse>5__1;
							object? value = <petField>5__3.GetValue(tameable);
							reference = (EffectList)((value is EffectList) ? value : null);
						}
						if (<effectToUse>5__1 == null)
						{
							<tamedField>5__4 = typeof(Tameable).GetField("m_tamedEffect", BindingFlags.Instance | BindingFlags.Public);
							if (<tamedField>5__4 != null)
							{
								ref EffectList reference2 = ref <effectToUse>5__1;
								object? value2 = <tamedField>5__4.GetValue(tameable);
								reference2 = (EffectList)((value2 is EffectList) ? value2 : null);
							}
							<tamedField>5__4 = null;
						}
						<petField>5__3 = null;
					}
					<elapsed>5__2 = 0f;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (<elapsed>5__2 < 15f && (Object)(object)boarObj != (Object)null && (Object)(object)player != (Object)null && (Object)(object)((Component)player).gameObject != (Object)null && ((Component)player).gameObject.activeInHierarchy)
				{
					<dist>5__5 = Vector3.Distance(boarObj.transform.position, ((Component)player).transform.position);
					if (!(<dist>5__5 < 5f))
					{
						if (<effectToUse>5__1 != null)
						{
							<effectToUse>5__1.Create(boarObj.transform.position + Vector3.up * 1.5f, boarObj.transform.rotation, boarObj.transform, 1f, -1);
						}
						<elapsed>5__2 += 0.5f;
						<>2__current = (object)new WaitForSeconds(0.5f);
						<>1__state = 1;
						return true;
					}
				}
				<>4__this.heartCoroutine = null;
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private Coroutine heartCoroutine;

		private Coroutine setupCoroutine;

		public bool saddleAdjustMode = false;

		private int adjustTarget = 0;

		private float saddleCutoffY = -0.9f;

		private Transform saddleVisualTransform;

		private Transform mountPointTransform;

		private Transform leftShieldTransform;

		private Transform rightShieldTransform;

		private Transform headWeaponTransform;

		public float jumpForce = 30f;

		public static BattleBoarSpawner Instance { get; private set; }

		public BattleBoarController ActiveBoar { get; private set; }

		private void Awake()
		{
			Instance = this;
		}

		private void Update()
		{
			if ((Object)(object)ActiveBoar != (Object)null && !Object.op_Implicit((Object)(object)ActiveBoar))
			{
				ActiveBoar = null;
			}
		}

		public void SummonOrRecall()
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: 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)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ZNetScene.instance == (Object)null)
			{
				return;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return;
			}
			if ((Object)(object)ActiveBoar != (Object)null)
			{
				DespawnBoar();
				((Character)localPlayer).Message((MessageType)2, "BattleBoar dismissed!", 0, (Sprite)null);
				return;
			}
			float value = BattleBoarPlugin.SpawnDistance.Value;
			Vector3 val = ((Component)localPlayer).transform.position + ((Component)localPlayer).transform.forward * value;
			float y = default(float);
			if ((Object)(object)ZoneSystem.instance != (Object)null && ZoneSystem.instance.GetGroundHeight(val, ref y))
			{
				val.y = y;
			}
			GameObject prefab = ZNetScene.instance.GetPrefab("Boar");
			if ((Object)(object)prefab == (Object)null)
			{
				BattleBoarPlugin.LogWarn("Boar prefab not found.");
				return;
			}
			GameObject val2 = Object.Instantiate<GameObject>(prefab, val, Quaternion.identity);
			Rigidbody component = val2.GetComponent<Rigidbody>();
			if ((Object)(object)component != (Object)null)
			{
				component.interpolation = (RigidbodyInterpolation)1;
			}
			Vector3 val3 = ((Component)localPlayer).transform.position - val;
			val3.y = 0f;
			if (((Vector3)(ref val3)).sqrMagnitude > 0.1f)
			{
				val2.transform.rotation = Quaternion.LookRotation(((Vector3)(ref val3)).normalized);
			}
			float value2 = BattleBoarPlugin.BoarScale.Value;
			Transform val4 = val2.transform.Find("Visual");
			if ((Object)(object)val4 != (Object)null)
			{
				val4.localScale = Vector3.one * value2;
			}
			ZNetView component2 = val2.GetComponent<ZNetView>();
			if ((Object)(object)component2 != (Object)null && component2.IsValid())
			{
				component2.m_persistent = false;
				FieldInfo fieldInfo = AccessTools.Field(typeof(ZDO), "m_persistent") ?? AccessTools.Field(typeof(ZDO), "m_tempRemoveEarmark") ?? AccessTools.Field(typeof(ZDO), "m_noPersist");
				if (fieldInfo != null && fieldInfo.FieldType == typeof(bool))
				{
					fieldInfo.SetValue(component2.GetZDO(), (!fieldInfo.Name.Contains("persist")) ? true : false);
				}
				component2.GetZDO().Set("tamed", true);
				component2.GetZDO().Set(StringExtensionMethods.GetStableHashCode("haveSaddle"), true);
				component2.GetZDO().Set("TamedName", "BattleBoar");
			}
			Character component3 = val2.GetComponent<Character>();
			if ((Object)(object)component3 != (Object)null)
			{
				component3.m_faction = (Faction)0;
				float value3 = BattleBoarPlugin.BoarHealth.Value;
				component3.SetMaxHealth(value3);
				component3.SetHealth(value3);
				component3.m_speed = BattleBoarPlugin.BoarRunSpeed.Value * 0.5f;
				component3.m_runSpeed = BattleBoarPlugin.BoarRunSpeed.Value;
				component3.m_tolerateWater = true;
				component3.m_tolerateFire = true;
				component3.m_tolerateSmoke = true;
			}
			Tameable component4 = val2.GetComponent<Tameable>();
			if ((Object)(object)component4 != (Object)null)
			{
				component4.m_tamingTime = 0f;
				component4.m_commandable = true;
				component4.m_fedDuration = 999999f;
				TryInvokeMethod(component4, "Tame");
				ZNetView component5 = val2.GetComponent<ZNetView>();
				if ((Object)(object)component5 != (Object)null && component5.IsValid())
				{
					component5.GetZDO().Set(StringExtensionMethods.GetStableHashCode("TameLastFeeding"), ZNet.instance.GetTime().Ticks);
				}
			}
			AnimalAI component6 = val2.GetComponent<AnimalAI>();
			if ((Object)(object)component6 != (Object)null)
			{
				Object.Destroy((Object)(object)component6);
			}
			setupCoroutine = ((MonoBehaviour)this).StartCoroutine(SetupAI(val2, localPlayer, component4, component3, component2));
		}

		[IteratorStateMachine(typeof(<SetupAI>d__13))]
		private IEnumerator SetupAI(GameObject boarObj, Player player, Tameable tameable, Character character, ZNetView nview)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <SetupAI>d__13(0)
			{
				<>4__this = this,
				boarObj = boarObj,
				player = player,
				tameable = tameable,
				character = character,
				nview = nview
			};
		}

		private void AddSaddleVisual(GameObject saddleGO)
		{
			//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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Expected O, but got Unknown
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Expected O, but got Unknown
			//IL_0121: 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_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				ZNetScene instance = ZNetScene.instance;
				GameObject val = ((instance != null) ? instance.GetPrefab("Asksvin") : null);
				if ((Object)(object)val != (Object)null)
				{
					GameObject val2 = Object.Instantiate<GameObject>(val, new Vector3(0f, -500f, 0f), Quaternion.identity);
					Sadle componentInChildren = val2.GetComponentInChildren<Sadle>(true);
					SkinnedMeshRenderer val3 = ((componentInChildren != null) ? ((Component)componentInChildren).GetComponentInChildren<SkinnedMeshRenderer>(true) : null);
					if ((Object)(object)val3 != (Object)null && (Object)(object)componentInChildren != (Object)null)
					{
						if (!string.IsNullOrEmpty(componentInChildren.m_attachAnimation))
						{
							Sadle component = saddleGO.GetComponent<Sadle>();
							if ((Object)(object)component != (Object)null)
							{
								component.m_attachAnimation = componentInChildren.m_attachAnimation;
								BattleBoarPlugin.Log("Using Asksvin attach animation: " + componentInChildren.m_attachAnimation);
							}
						}
						Mesh val4 = new Mesh();
						val3.BakeMesh(val4);
						GameObject val5 = new GameObject("SaddleVisual");
						val5.transform.SetParent(saddleGO.transform);
						saddleVisualTransform = val5.transform;
						val5.transform.localPosition = new Vector3(0f, 0f, -0.15f);
						val5.transform.localRotation = Quaternion.Euler(300f, 0f, 0f);
						float num = 0.6f;
						val5.transform.localScale = new Vector3(num, num, num);
						val5.layer = saddleGO.layer;
						Mesh val6 = SplitMeshAboveY(val4, saddleCutoffY);
						val5.AddComponent<MeshFilter>().sharedMesh = val6;
						((Renderer)val5.AddComponent<MeshRenderer>()).sharedMaterials = ((Renderer)val3).sharedMaterials;
						BattleBoarPlugin.Log($"Saddle visual: original={val4.vertexCount} verts, " + $"after cut(Y>{saddleCutoffY:F1})={val6.vertexCount} verts, " + $"bounds={val6.bounds}");
					}
					ZNetView component2 = val2.GetComponent<ZNetView>();
					if ((Object)(object)component2 != (Object)null && component2.IsValid())
					{
						component2.Destroy();
					}
					else
					{
						Object.Destroy((Object)(object)val2);
					}
				}
				else
				{
					BattleBoarPlugin.LogWarn("Asksvin prefab not found — using cube placeholder.");
					AddCubePlaceholder(saddleGO);
				}
			}
			catch (Exception ex)
			{
				BattleBoarPlugin.LogWarn("Saddle visual failed: " + ex.Message + " — using cube placeholder.");
				AddCubePlaceholder(saddleGO);
			}
		}

		private void AttachArmorPieces(GameObject boarObj)
		{
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: 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_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			Transform val = boarObj.transform.Find("Visual");
			if (!((Object)(object)val == (Object)null))
			{
				Transform val2 = val.Find("CG/Pelvis/Spine/Spine1");
				Transform val3 = val.Find("CG/Pelvis/Spine/Spine1/Neck/Head");
				if ((Object)(object)val3 == (Object)null)
				{
					val3 = val.Find("CG/Pelvis/Spine/Spine1/Neck");
				}
				if ((Object)(object)val3 == (Object)null)
				{
					val3 = val2;
				}
				Transform val4 = val2 ?? boarObj.transform;
				leftShieldTransform = AttachItemMesh("ShieldFlametal", val4, new Vector3(-0.4f, -0.1f, -0.25f), Quaternion.Euler(0f, 0f, 90f), new Vector3(0.4f, 0.4f, 0.4f), "LeftShield");
				rightShieldTransform = AttachItemMesh("ShieldFlametal", val4, new Vector3(-0.35f, -0.1f, 0.25f), Quaternion.Euler(0f, 180f, 270f), new Vector3(0.4f, 0.4f, 0.4f), "RightShield");
				headWeaponTransform = AttachItemMesh("SpearSplitner", val3 ?? val4, new Vector3(-0.5f, -0.25f, 0f), Quaternion.Euler(274.1f, 267.9f, 184.4f), new Vector3(0.5f, 0.5f, 0.5f), "HeadWeapon");
				int num = (((Object)(object)leftShieldTransform != (Object)null) ? 1 : 0) + (((Object)(object)rightShieldTransform != (Object)null) ? 1 : 0) + (((Object)(object)headWeaponTransform != (Object)null) ? 1 : 0);
				BattleBoarPlugin.Log($"Armor pieces attached: {num}/3");
			}
		}

		private Transform AttachItemMesh(string itemName, Transform parent, Vector3 localPos, Quaternion localRot, Vector3 localScale, string goName)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Expected O, but got Unknown
			//IL_0142: 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_015d: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				ZNetScene instance = ZNetScene.instance;
				GameObject val = ((instance != null) ? instance.GetPrefab(itemName) : null);
				if ((Object)(object)val == (Object)null)
				{
					BattleBoarPlugin.LogWarn("Armor item '" + itemName + "' not found in ZNetScene.");
					return null;
				}
				MeshFilter val2 = null;
				MeshRenderer val3 = null;
				foreach (Transform item in val.transform)
				{
					Transform val4 = item;
					MeshFilter component = ((Component)val4).GetComponent<MeshFilter>();
					MeshRenderer component2 = ((Component)val4).GetComponent<MeshRenderer>();
					if ((Object)(object)component != (Object)null && (Object)(object)component2 != (Object)null && (Object)(object)component.sharedMesh != (Object)null)
					{
						val2 = component;
						val3 = component2;
						break;
					}
				}
				if ((Object)(object)val2 == (Object)null)
				{
					val2 = val.GetComponentInChildren<MeshFilter>(true);
					val3 = val.GetComponentInChildren<MeshRenderer>(true);
				}
				if ((Object)(object)val2 == (Object)null || (Object)(object)val2.sharedMesh == (Object)null)
				{
					BattleBoarPlugin.LogWarn("No mesh found on '" + itemName + "'.");
					return null;
				}
				GameObject val5 = new GameObject(goName);
				val5.transform.SetParent(parent);
				val5.transform.localPosition = localPos;
				val5.transform.localRotation = localRot;
				val5.transform.localScale = localScale;
				val5.layer = ((Component)parent).gameObject.layer;
				val5.AddComponent<MeshFilter>().sharedMesh = val2.sharedMesh;
				((Renderer)val5.AddComponent<MeshRenderer>()).sharedMaterials = ((Renderer)val3).sharedMaterials;
				BattleBoarPlugin.Log("Armor '" + goName + "': mesh=" + ((Object)val2.sharedMesh).name + " from " + itemName + ", " + $"verts={val2.sharedMesh.vertexCount}");
				return val5.transform;
			}
			catch (Exception ex)
			{
				BattleBoarPlugin.LogWarn("Failed to attach '" + itemName + "': " + ex.Message);
				return null;
			}
		}

		private void AddCubePlaceholder(GameObject saddleGO)
		{
			//IL_002c: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)3);
			((Object)val).name = "SaddleVisual";
			val.transform.SetParent(saddleGO.transform);
			val.transform.localPosition = Vector3.zero;
			val.transform.localRotation = Quaternion.identity;
			val.transform.localScale = new Vector3(0.5f, 0.1f, 0.6f);
			val.layer = saddleGO.layer;
			Collider component = val.GetComponent<Collider>();
			if ((Object)(object)component != (Object)null)
			{
				Object.Destroy((Object)(object)component);
			}
			Renderer component2 = val.GetComponent<Renderer>();
			if ((Object)(object)component2 != (Object)null && (Object)(object)component2.material != (Object)null)
			{
				component2.material.color = new Color(0.35f, 0.22f, 0.1f);
			}
		}

		public void ToggleSaddleAdjust()
		{
			adjustTarget = (adjustTarget + 1) % 10;
			saddleAdjustMode = adjustTarget != 0;
			string[] array = new string[10]
			{
				"Adjust OFF",
				"1: SADDLE VISUAL\nArrows=rot  Alt+Arrows=pos  Ctrl=fine",
				"2: MOUNT POINT\nAlt+Arrows=pos  Ctrl=fine",
				"3: BOAR SIZE\nUp/Down=scale  Ctrl=fine",
				"4: SADDLE SIZE\nUp/Down=scale  Ctrl=fine",
				$"5: MESH CUTOFF (Y>{saddleCutoffY:F1})\nUp/Down=cut more/less  Ctrl=fine\nRe-summon with N to apply",
				"6: LEFT SHIELD\nArrows=rot  Alt+Arrows=pos  Ctrl=fine",
				"7: RIGHT SHIELD\nArrows=rot  Alt+Arrows=pos  Ctrl=fine",
				"8: HEAD WEAPON\nArrows=rot  Alt+Arrows=pos  Ctrl=fine",
				$"9: JUMP POWER ({jumpForce:F1})\nUp/Down=more/less  Ctrl=fine"
			};
			Player localPlayer = Player.m_localPlayer;
			if (localPlayer != null)
			{
				((Character)localPlayer).Message((MessageType)2, array[adjustTarget], 0, (Sprite)null);
			}
		}

		private Transform GetAdjustTarget()
		{
			return (Transform)(adjustTarget switch
			{
				1 => saddleVisualTransform, 
				2 => mountPointTransform, 
				6 => leftShieldTransform, 
				7 => rightShieldTransform, 
				8 => headWeaponTransform, 
				_ => null, 
			});
		}

		public void AdjustSaddleRotation(float dx, float dy, float dz)
		{
			if (adjustTarget >= 3 && adjustTarget != 6 && adjustTarget != 7 && adjustTarget != 8)
			{
				float num = ((dx > 0f) ? 0.05f : ((dx < 0f) ? (-0.05f) : 0f));
				if (Input.GetKey((KeyCode)306))
				{
					num *= 0.4f;
				}
				if (num == 0f)
				{
					return;
				}
				if (adjustTarget == 5)
				{
					saddleCutoffY += num;
					string text = $"Mesh Cutoff Y: {saddleCutoffY:F2} (re-summon with N to apply)";
					BattleBoarPlugin.Log(text);
					Player localPlayer = Player.m_localPlayer;
					if (localPlayer != null)
					{
						((Character)localPlayer).Message((MessageType)1, text, 0, (Sprite)null);
					}
				}
				else if (adjustTarget == 9)
				{
					float num2 = ((dx > 0f) ? 1f : (-1f));
					if (Input.GetKey((KeyCode)306))
					{
						num2 *= 0.2f;
					}
					jumpForce = Mathf.Clamp(jumpForce + num2, 1f, 30f);
					string text2 = $"Jump Power: {jumpForce:F1}";
					BattleBoarPlugin.Log(text2);
					Player localPlayer2 = Player.m_localPlayer;
					if (localPlayer2 != null)
					{
						((Character)localPlayer2).Message((MessageType)1, text2, 0, (Sprite)null);
					}
				}
				else
				{
					AdjustScale(num);
				}
			}
			else
			{
				Transform val = GetAdjustTarget();
				if (!((Object)(object)val == (Object)null))
				{
					val.Rotate(dx, dy, dz, (Space)1);
					LogAdjust(val);
				}
			}
		}

		public void AdjustSaddlePosition(float dx, float dy, float dz)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//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)
			Transform val = GetAdjustTarget();
			if (!((Object)(object)val == (Object)null))
			{
				val.localPosition += new Vector3(dx, dy, dz);
				LogAdjust(val);
			}
		}

		private void AdjustScale(float delta)
		{
			//IL_0050: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ActiveBoar == (Object)null)
			{
				return;
			}
			if (adjustTarget == 3)
			{
				Transform val = ((Component)ActiveBoar).transform.Find("Visual");
				if (!((Object)(object)val == (Object)null))
				{
					float x = val.localScale.x;
					float num = Mathf.Clamp(x + delta, 0.5f, 3f);
					val.localScale = Vector3.one * num;
					string text = $"Boar Scale: {num:F2}";
					BattleBoarPlugin.Log(text);
					Player localPlayer = Player.m_localPlayer;
					if (localPlayer != null)
					{
						((Character)localPlayer).Message((MessageType)1, text, 0, (Sprite)null);
					}
				}
			}
			else if (adjustTarget == 4 && !((Object)(object)saddleVisualTransform == (Object)null))
			{
				float x2 = saddleVisualTransform.localScale.x;
				float num2 = Mathf.Clamp(x2 + delta, 0.1f, 2f);
				saddleVisualTransform.localScale = Vector3.one * num2;
				string text2 = $"Saddle Scale: {num2:F2}";
				BattleBoarPlugin.Log(text2);
				Player localPlayer2 = Player.m_localPlayer;
				if (localPlayer2 != null)
				{
					((Character)localPlayer2).Message((MessageType)1, text2, 0, (Sprite)null);
				}
			}
		}

		private static Mesh SplitMeshAboveY(Mesh source, float cutoffY)
		{
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Expected O, but got Unknown
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] vertices = source.vertices;
			Vector3[] normals = source.normals;
			Vector2[] uv = source.uv;
			Color[] colors = source.colors;
			Dictionary<int, int> dictionary = new Dictionary<int, int>();
			List<Vector3> list = new List<Vector3>();
			List<Vector3> list2 = new List<Vector3>();
			List<Vector2> list3 = new List<Vector2>();
			List<Color> list4 = new List<Color>();
			int subMeshCount = source.subMeshCount;
			List<List<int>> list5 = new List<List<int>>();
			for (int i = 0; i < subMeshCount; i++)
			{
				int[] triangles = source.GetTriangles(i);
				List<int> list6 = new List<int>();
				for (int j = 0; j < triangles.Length; j += 3)
				{
					int num = triangles[j];
					int num2 = triangles[j + 1];
					int num3 = triangles[j + 2];
					if (!(vertices[num].y > cutoffY) || !(vertices[num2].y > cutoffY) || !(vertices[num3].y > cutoffY))
					{
						continue;
					}
					int[] array = new int[3] { num, num2, num3 };
					foreach (int num4 in array)
					{
						if (!dictionary.ContainsKey(num4))
						{
							dictionary[num4] = list.Count;
							list.Add(vertices[num4]);
							if (normals.Length > num4)
							{
								list2.Add(normals[num4]);
							}
							if (uv.Length > num4)
							{
								list3.Add(uv[num4]);
							}
							if (colors.Length > num4)
							{
								list4.Add(colors[num4]);
							}
						}
						list6.Add(dictionary[num4]);
					}
				}
				list5.Add(list6);
			}
			Mesh val = new Mesh();
			val.vertices = list.ToArray();
			if (list2.Count == list.Count)
			{
				val.normals = list2.ToArray();
			}
			if (list3.Count == list.Count)
			{
				val.uv = list3.ToArray();
			}
			if (list4.Count == list.Count)
			{
				val.colors = list4.ToArray();
			}
			val.subMeshCount = subMeshCount;
			for (int l = 0; l < subMeshCount; l++)
			{
				val.SetTriangles(list5[l].ToArray(), l);
			}
			val.RecalculateBounds();
			return val;
		}

		private void LogAdjust(Transform t)
		{
			//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_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_0077: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			Vector3 localEulerAngles = t.localEulerAngles;
			Vector3 localPosition = t.localPosition;
			string[] array = new string[9] { "", "Saddle", "MountPt", "BoarSz", "SadlSz", "Cut", "LShield", "RShield", "HeadWpn" };
			string text = $"{array[adjustTarget]} Rot:({localEulerAngles.x:F1},{localEulerAngles.y:F1},{localEulerAngles.z:F1}) Pos:({localPosition.x:F2},{localPosition.y:F2},{localPosition.z:F2})";
			BattleBoarPlugin.Log(text);
			Player localPlayer = Player.m_localPlayer;
			if (localPlayer != null)
			{
				((Character)localPlayer).Message((MessageType)1, text, 0, (Sprite)null);
			}
		}

		[IteratorStateMachine(typeof(<SpawnHeartEffects>d__34))]
		private IEnumerator SpawnHeartEffects(GameObject boarObj, Player player, Tameable tameable)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <SpawnHeartEffects>d__34(0)
			{
				<>4__this = this,
				boarObj = boarObj,
				player = player,
				tameable = tameable
			};
		}

		public void DespawnBoar()
		{
			if (setupCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(setupCoroutine);
				setupCoroutine = null;
			}
			if (heartCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(heartCoroutine);
				heartCoroutine = null;
			}
			if ((Object)(object)ActiveBoar != (Object)null && (Object)(object)((Component)ActiveBoar).gameObject != (Object)null)
			{
				ActiveBoar.ClearOwner();
				ZNetView component = ((Component)ActiveBoar).GetComponent<ZNetView>();
				if ((Object)(object)component != (Object)null && component.IsValid())
				{
					component.ClaimOwnership();
					component.Destroy();
				}
				else
				{
					Object.Destroy((Object)(object)((Component)ActiveBoar).gameObject);
				}
			}
			ActiveBoar = null;
		}

		public void OnBoarDied()
		{
			if ((Object)(object)ActiveBoar != (Object)null)
			{
				ActiveBoar.ClearOwner();
			}
			ActiveBoar = null;
		}

		private bool TryInvokeMethod(object target, string methodName)
		{
			MethodInfo method = target.GetType().GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (method == null)
			{
				BattleBoarPlugin.LogWarn(target.GetType().Name + "." + methodName + "() not found");
				return false;
			}
			try
			{
				method.Invoke(target, null);
				return true;
			}
			catch (Exception ex)
			{
				BattleBoarPlugin.LogWarn(methodName + "(): " + (ex.InnerException?.Message ?? ex.Message));
				return false;
			}
		}
	}
	public static class Patches
	{
		[HarmonyPatch(typeof(Sadle), "Interact")]
		public static class SadleInteract_Patch
		{
			private static bool Prefix(Sadle __instance, Humanoid character, bool alt, ref bool __result)
			{
				BattleBoarController componentInParent = ((Component)__instance).GetComponentInParent<BattleBoarController>();
				if ((Object)(object)componentInParent == (Object)null)
				{
					return true;
				}
				if (alt)
				{
					componentInParent.ToggleFollowStay();
					__result = true;
					return false;
				}
				return true;
			}

			private static void Postfix(Sadle __instance, bool alt, bool __result)
			{
				if (!(!__result || alt))
				{
					((Component)__instance).GetComponentInParent<BattleBoarController>()?.OnMounted();
				}
			}
		}

		[HarmonyPatch(typeof(Sadle), "OnUseStop")]
		public static class SadleOnUseStop_Patch
		{
			private static void Postfix(Sadle __instance)
			{
				BattleBoarController componentInParent = ((Component)__instance).GetComponentInParent<BattleBoarController>();
				if ((Object)(object)componentInParent != (Object)null && componentInParent.CurrentState == BattleBoarController.BoarState.Mounted)
				{
					componentInParent.OnDismounted();
				}
			}
		}

		[HarmonyPatch(typeof(Tameable), "Interact")]
		public static class TameableInteract_Patch
		{
			private static bool Prefix(Tameable __instance, Humanoid user, bool hold, bool alt, ref bool __result)
			{
				BattleBoarController component = ((Component)__instance).GetComponent<BattleBoarController>();
				if ((Object)(object)component == (Object)null)
				{
					return true;
				}
				if (hold)
				{
					__result = false;
					return false;
				}
				if (alt)
				{
					component.ToggleFollowStay();
					__result = true;
					return false;
				}
				if ((Object)(object)__instance.m_saddle != (Object)null)
				{
					__instance.m_saddle.Interact(user, hold, alt);
					__result = true;
					return false;
				}
				BattleBoarPlugin.LogWarn("Tameable.Interact: m_saddle is null — mount failed!");
				__result = false;
				return false;
			}
		}

		[HarmonyPatch(typeof(Tameable), "GetHoverText")]
		public static class TameableHoverText_Patch
		{
			private static bool Prefix(Tameable __instance, ref string __result)
			{
				BattleBoarController component = ((Component)__instance).GetComponent<BattleBoarController>();
				if ((Object)(object)component == (Object)null)
				{
					return true;
				}
				__result = component.GetCustomHoverText();
				return false;
			}
		}

		[HarmonyPatch(typeof(Sadle), "GetHoverText")]
		public static class SadleHoverText_Patch
		{
			private static bool Prefix(Sadle __instance, ref string __result)
			{
				BattleBoarController componentInParent = ((Component)__instance).GetComponentInParent<BattleBoarController>();
				if ((Object)(object)componentInParent == (Object)null)
				{
					return true;
				}
				__result = componentInParent.GetCustomHoverText();
				return false;
			}
		}

		[HarmonyPatch(typeof(Tameable), "GetHoverName")]
		public static class TameableHoverName_Patch
		{
			private static bool Prefix(Tameable __instance, ref string __result)
			{
				BattleBoarController component = ((Component)__instance).GetComponent<BattleBoarController>();
				if ((Object)(object)component == (Object)null)
				{
					return true;
				}
				__result = "BattleBoar";
				return false;
			}
		}

		[HarmonyPatch(typeof(Character), "GetHoverName")]
		public static class CharacterHoverName_Patch
		{
			private static bool Prefix(Character __instance, ref string __result)
			{
				BattleBoarController component = ((Component)__instance).GetComponent<BattleBoarController>();
				if ((Object)(object)component == (Object)null)
				{
					return true;
				}
				__result = "BattleBoar";
				return false;
			}
		}

		[HarmonyPatch(typeof(Sadle), "GetHoverName")]
		public static class SadleHoverName_Patch
		{
			private static bool Prefix(Sadle __instance, ref string __result)
			{
				BattleBoarController componentInParent = ((Component)__instance).GetComponentInParent<BattleBoarController>();
				if ((Object)(object)componentInParent == (Object)null)
				{
					return true;
				}
				__result = "BattleBoar";
				return false;
			}
		}

		[HarmonyPatch(typeof(BaseAI), "IsEnemy", new Type[]
		{
			typeof(Character),
			typeof(Character)
		})]
		public static class IsEnemy_Patch
		{
			private static void Postfix(Character a, Character b, ref bool __result)
			{
				if (__result)
				{
					bool flag = (Object)(object)a != (Object)null && (Object)(object)((Component)a).GetComponent<BattleBoarController>() != (Object)null;
					bool flag2 = (Object)(object)b != (Object)null && (Object)(object)((Component)b).GetComponent<BattleBoarController>() != (Object)null;
					if (flag && b is Player)
					{
						__result = false;
					}
					else if (a is Player && flag2)
					{
						__result = false;
					}
				}
			}
		}

		[HarmonyPatch(typeof(Character), "Damage")]
		public static class NoDamageFromOwner_Patch
		{
			private static bool Prefix(Character __instance, HitData hit)
			{
				Player val = (Player)(object)((__instance is Player) ? __instance : null);
				if (val != null && ((Character)val).IsRiding())
				{
					IDoodadController doodadController = val.GetDoodadController();
					Sadle val2 = (Sadle)(object)((doodadController is Sadle) ? doodadController : null);
					if ((Object)(object)val2 != (Object)null && (Object)(object)((Component)val2).GetComponentInParent<BattleBoarController>() != (Object)null)
					{
						return false;
					}
				}
				if ((Object)(object)((Component)__instance).GetComponent<BattleBoarController>() != (Object)null)
				{
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(CharacterDrop), "OnDeath")]
		public static class NoLootDrops_Patch
		{
			private static bool Prefix(CharacterDrop __instance)
			{
				if ((Object)(object)((Component)__instance).GetComponent<BattleBoarController>() != (Object)null)
				{
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Character), "OnDeath")]
		public static class BoarDeath_Patch
		{
			private static void Postfix(Character __instance)
			{
				BattleBoarController component = ((Component)__instance).GetComponent<BattleBoarController>();
				if (!((Object)(object)component == (Object)null))
				{
					BattleBoarSpawner.Instance?.OnBoarDied();
					Player localPlayer = Player.m_localPlayer;
					if ((Object)(object)localPlayer != (Object)null)
					{
						((Character)localPlayer).Message((MessageType)2, "BattleBoar has fallen!", 0, (Sprite)null);
					}
					BattleBoarPlugin.Log("BattleBoar died.");
				}
			}
		}

		[HarmonyPatch(typeof(Game), "OnDestroy")]
		public static class GameCleanup_Patch
		{
			private static void Prefix()
			{
				BattleBoarSpawner.Instance?.DespawnBoar();
				BattleBoarPlugin.Log("World unloading — BattleBoar despawned.");
			}
		}

		[HarmonyPatch(typeof(Game), "Start")]
		public static class GameStart_Cleanup_Patch
		{
			[CompilerGenerated]
			private sealed class <CleanupLeftoverBoars>d__1 : IEnumerator<object>, IDisposable, IEnumerator
			{
				private int <>1__state;

				private object <>2__current;

				private int <cleaned>5__1;

				private List<Character> <allChars>5__2;

				private List<Character>.Enumerator <>s__3;

				private Character <c>5__4;

				private ZNetView <nview>5__5;

				private ZDO <zdo>5__6;

				private string <tamedName>5__7;

				object IEnumerator<object>.Current
				{
					[DebuggerHidden]
					get
					{
						return <>2__current;
					}
				}

				object IEnumerator.Current
				{
					[DebuggerHidden]
					get
					{
						return <>2__current;
					}
				}

				[DebuggerHidden]
				public <CleanupLeftoverBoars>d__1(int <>1__state)
				{
					this.<>1__state = <>1__state;
				}

				[DebuggerHidden]
				void IDisposable.Dispose()
				{
					<allChars>5__2 = null;
					<>s__3 = default(List<Character>.Enumerator);
					<c>5__4 = null;
					<nview>5__5 = null;
					<zdo>5__6 = null;
					<tamedName>5__7 = null;
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					//IL_0026: Unknown result type (might be due to invalid IL or missing references)
					//IL_0030: Expected O, but got Unknown
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<>2__current = (object)new WaitForSeconds(5f);
						<>1__state = 1;
						return true;
					case 1:
						<>1__state = -1;
						<cleaned>5__1 = 0;
						<allChars>5__2 = Character.GetAllCharacters();
						<>s__3 = <allChars>5__2.GetEnumerator();
						try
						{
							while (<>s__3.MoveNext())
							{
								<c>5__4 = <>s__3.Current;
								if ((Object)(object)<c>5__4 == (Object)null)
								{
									continue;
								}
								<nview>5__5 = ((Component)<c>5__4).GetComponent<ZNetView>();
								if ((Object)(object)<nview>5__5 == (Object)null || !<nview>5__5.IsValid())
								{
									continue;
								}
								<zdo>5__6 = <nview>5__5.GetZDO();
								if (<zdo>5__6 != null)
								{
									<tamedName>5__7 = <zdo>5__6.GetString("TamedName", "");
									if (<tamedName>5__7 == "BattleBoar")
									{
										<nview>5__5.ClaimOwnership();
										<nview>5__5.Destroy();
										<cleaned>5__1++;
									}
									<nview>5__5 = null;
									<zdo>5__6 = null;
									<tamedName>5__7 = null;
									<c>5__4 = null;
								}
							}
						}
						finally
						{
							((IDisposable)<>s__3).Dispose();
						}
						<>s__3 = default(List<Character>.Enumerator);
						if (<cleaned>5__1 > 0)
						{
							BattleBoarPlugin.Log($"Cleaned up {<cleaned>5__1} leftover BattleBoar(s) from previous session.");
						}
						return false;
					}
				}

				bool IEnumerator.MoveNext()
				{
					//ILSpy generated this explicit interface implementation from .override directive in MoveNext
					return this.MoveNext();
				}

				[DebuggerHidden]
				void IEnumerator.Reset()
				{
					throw new NotSupportedException();
				}
			}

			private static void Postfix()
			{
				BattleBoarPlugin instance = BattleBoarPlugin.Instance;
				if (instance != null)
				{
					((MonoBehaviour)instance).StartCoroutine(CleanupLeftoverBoars());
				}
			}

			[IteratorStateMachine(typeof(<CleanupLeftoverBoars>d__1))]
			private static IEnumerator CleanupLeftoverBoars()
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <CleanupLeftoverBoars>d__1(0);
			}
		}

		[HarmonyPatch(typeof(Player), "Update")]
		public static class PlayerUpdate_Riding_Patch
		{
			private static void Postfix(Player __instance)
			{
				//IL_0054: 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)
				if (!((Character)__instance).IsRiding())
				{
					return;
				}
				FieldInfo fieldInfo = AccessTools.Field(typeof(Character), "m_attachPoint");
				if (!(fieldInfo == null))
				{
					object? value = fieldInfo.GetValue(__instance);
					Transform val = (Transform)((value is Transform) ? value : null);
					if ((Object)(object)val != (Object)null)
					{
						((Component)__instance).transform.position = val.position;
						((Component)__instance).transform.rotation = val.rotation;
					}
				}
			}
		}

		[HarmonyPatch(typeof(Player), "SetControls")]
		public static class PlayerSetControls_Patch
		{
			private static void Prefix(Player __instance, ref bool jump, ref bool crouch, ref bool attack, ref bool secondaryAttack)
			{
				//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ba: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d3: 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_0284: Unknown result type (might be due to invalid IL or missing references)
				//IL_0289: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ee: 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_0108: Unknown result type (might be due to invalid IL or missing references)
				//IL_010a: Unknown result type (might be due to invalid IL or missing references)
				//IL_010c: Unknown result type (might be due to invalid IL or missing references)
				//IL_018f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0196: Unknown result type (might be due to invalid IL or missing references)
				//IL_03c5: Unknown result type (might be due to invalid IL or missing references)
				//IL_0717: Unknown result type (might be due to invalid IL or missing references)
				//IL_06a0: Unknown result type (might be due to invalid IL or missing references)
				//IL_06a7: Unknown result type (might be due to invalid IL or missing references)
				//IL_06b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_06c7: Unknown result type (might be due to invalid IL or missing references)
				//IL_06ce: Unknown result type (might be due to invalid IL or missing references)
				//IL_06d8: Unknown result type (might be due to invalid IL or missing references)
				//IL_06e4: Unknown result type (might be due to invalid IL or missing references)
				//IL_0303: Unknown result type (might be due to invalid IL or missing references)
				//IL_030c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0325: Unknown result type (might be due to invalid IL or missing references)
				//IL_032c: Expected O, but got Unknown
				//IL_0354: Unknown result type (might be due to invalid IL or missing references)
				//IL_0359: Unknown result type (might be due to invalid IL or missing references)
				//IL_0367: Unknown result type (might be due to invalid IL or missing references)
				//IL_036c: Unknown result type (might be due to invalid IL or missing references)
				//IL_036e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0373: Unknown result type (might be due to invalid IL or missing references)
				//IL_0377: Unknown result type (might be due to invalid IL or missing references)
				//IL_037c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0516: Unknown result type (might be due to invalid IL or missing references)
				//IL_0518: Unknown result type (might be due to invalid IL or missing references)
				//IL_042c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0433: Expected O, but got Unknown
				//IL_046f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0474: Unknown result type (might be due to invalid IL or missing references)
				//IL_0482: Unknown result type (might be due to invalid IL or missing references)
				//IL_0487: Unknown result type (might be due to invalid IL or missing references)
				//IL_0489: Unknown result type (might be due to invalid IL or missing references)
				//IL_048e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0492: Unknown result type (might be due to invalid IL or missing references)
				//IL_0497: Unknown result type (might be due to invalid IL or missing references)
				//IL_0588: Unknown result type (might be due to invalid IL or missing references)
				//IL_058a: Unknown result type (might be due to invalid IL or missing references)
				if (!((Character)__instance).IsRiding())
				{
					return;
				}
				IDoodadController doodadController = __instance.GetDoodadController();
				Sadle val = (Sadle)(object)((doodadController is Sadle) ? doodadController : null);
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				BattleBoarController componentInParent = ((Component)val).GetComponentInParent<BattleBoarController>();
				if ((Object)(object)componentInParent == (Object)null)
				{
					return;
				}
				if (attack)
				{
					try
					{
						ZNetScene instance = ZNetScene.instance;
						GameObject val2 = ((instance != null) ? instance.GetPrefab("staff_fireball_projectile") : null);
						if ((Object)(object)val2 != (Object)null)
						{
							Character sadleCharacter = GetSadleCharacter(val);
							if ((Object)(object)sadleCharacter != (Object)null)
							{
								Vector3 val3 = ((Component)sadleCharacter).transform.position + ((Component)sadleCharacter).transform.forward * 1.5f + Vector3.up * 1.5f;
								Vector3 val4 = (((Object)(object)GameCamera.instance != (Object)null) ? ((Component)GameCamera.instance).transform.forward : ((Component)sadleCharacter).transform.forward);
								GameObject val5 = Object.Instantiate<GameObject>(val2, val3, Quaternion.LookRotation(val4));
								Projectile component = val5.GetComponent<Projectile>();
								if ((Object)(object)component != (Object)null)
								{
									component.m_gravity = 0.3f;
									component.m_damage.m_fire = 120f;
									component.m_damage.m_blunt = 60f;
									component.m_damage.m_chop = 40f;
									component.m_damage.m_pickaxe = 40f;
									component.m_aoe = 4f;
									component.Setup((Character)(object)__instance, val4 * 25f, -1f, (HitData)null, (ItemData)null, (ItemData)null);
								}
								Rigidbody component2 = val5.GetComponent<Rigidbody>();
								if ((Object)(object)component2 != (Object)null)
								{
									component2.useGravity = false;
								}
							}
						}
					}
					catch (Exception ex)
					{
						BattleBoarPlugin.LogWarn("Fireball failed: " + ex.Message);
					}
					attack = false;
				}
				if (secondaryAttack || ZInput.GetButtonDown("Block") || ZInput.GetButtonDown("JoyBlock"))
				{
					try
					{
						Character sadleCharacter2 = GetSadleCharacter(val);
						if ((Object)(object)sadleCharacter2 != (Object)null)
						{
							Animator componentInChildren = ((Component)sadleCharacter2).GetComponentInChildren<Animator>();
							if ((Object)(object)componentInChildren != (Object)null)
							{
								componentInChildren.SetTrigger("attack");
							}
							ZSyncAnimation component3 = ((Component)sadleCharacter2).GetComponent<ZSyncAnimation>();
							if ((Object)(object)component3 != (Object)null)
							{
								component3.SetTrigger("attack");
							}
							Vector3 position = ((Component)sadleCharacter2).transform.position;
							float num = 8f;
							float blunt = 120f;
							int num2 = 0;
							Vector3 val7;
							foreach (Character allCharacter in Character.GetAllCharacters())
							{
								if (!((Object)(object)allCharacter == (Object)(object)sadleCharacter2) && !((Object)(object)allCharacter == (Object)(object)__instance) && !((Object)(object)((Component)allCharacter).GetComponent<BattleBoarController>() != (Object)null) && !allCharacter.IsTamed() && !(Vector3.Distance(position, ((Component)allCharacter).transform.position) > num))
								{
									HitData val6 = new HitData();
									val6.m_damage.m_blunt = blunt;
									val6.m_damage.m_chop = 80f;
									val6.m_point = ((Component)allCharacter).transform.position;
									val7 = ((Component)allCharacter).transform.position - position;
									val6.m_dir = ((Vector3)(ref val7)).normalized;
									val6.m_pushForce = 20f;
									val6.SetAttacker((Character)(object)__instance);
									allCharacter.Damage(val6);
									num2++;
								}
							}
							Collider[] array = Physics.OverlapSphere(position, num);
							foreach (Collider val8 in array)
							{
								if (!((Object)(object)val8 == (Object)null) && !((Object)(object)((Component)val8).transform == (Object)null))
								{
									IDestructible componentInParent2 = ((Component)val8).GetComponentInParent<IDestructible>();
									if (componentInParent2 != null && !(componentInParent2 is Character))
									{
										HitData val9 = new HitData();
										val9.m_damage.m_chop = 200f;
										val9.m_damage.m_pickaxe = 200f;
										val9.m_damage.m_blunt = 100f;
										val9.m_point = ((Component)val8).transform.position;
										val7 = ((Component)val8).transform.position - position;
										val9.m_dir = ((Vector3)(ref val7)).normalized;
										val9.SetAttacker((Character)(object)__instance);
										componentInParent2.Damage(val9);
									}
								}
							}
							string[] array2 = new string[3] { "fx_troll_groundslam", "vfx_troll_groundslam", "fx_eikthyr_stomp" };
							foreach (string text in array2)
							{
								ZNetScene instance2 = ZNetScene.instance;
								GameObject val10 = ((instance2 != null) ? instance2.GetPrefab(text) : null);
								if ((Object)(object)val10 != (Object)null)
								{
									Object.Instantiate<GameObject>(val10, position, Quaternion.identity);
									break;
								}
							}
							string[] array3 = new string[3] { "sfx_troll_groundslam", "sfx_troll_attack_hit", "sfx_stone_hit" };
							foreach (string text2 in array3)
							{
								ZNetScene instance3 = ZNetScene.instance;
								GameObject val11 = ((instance3 != null) ? instance3.GetPrefab(text2) : null);
								if ((Object)(object)val11 != (Object)null)
								{
									Object.Instantiate<GameObject>(val11, position, Quaternion.identity);
									break;
								}
							}
						}
					}
					catch (Exception ex2)
					{
						BattleBoarPlugin.LogWarn("Ground slam failed: " + ex2.Message);
					}
					secondaryAttack = false;
				}
				if (ZInput.GetButton("Jump") || ZInput.GetButtonDown("JoyJump"))
				{
					try
					{
						object? obj = AccessTools.Field(typeof(Sadle), "m_monsterAI")?.GetValue(val);
						MonsterAI val12 = (MonsterAI)((obj is MonsterAI) ? obj : null);
						if ((Object)(object)val12 != (Object)null)
						{
							object? obj2 = AccessTools.Field(typeof(BaseAI), "m_character")?.GetValue(val12);
							Character val13 = (Character)((obj2 is Character) ? obj2 : null);
							if ((Object)(object)val13 != (Object)null)
							{
								Rigidbody component4 = ((Component)val13).GetComponent<Rigidbody>();
								if ((Object)(object)component4 != (Object)null)
								{
									float num3 = BattleBoarSpawner.Instance?.jumpForce ?? 15f;
									component4.AddForce(Vector3.up * num3 * component4.mass);
									component4.AddForce(((Component)val13).transform.forward * num3 * 0.3f * component4.mass);
								}
								AccessTools.Field(typeof(Character), "m_maxAirAltitude")?.SetValue(val13, ((Component)val13).transform.position.y);
							}
						}
					}
					catch
					{
					}
				}
				jump = false;
			}
		}

		private static Character GetSadleCharacter(Sadle sadle)
		{
			if ((Object)(object)sadle == (Object)null)
			{
				return null;
			}
			object? obj = AccessTools.Field(typeof(Sadle), "m_monsterAI")?.GetValue(sadle);
			MonsterAI val = (MonsterAI)((obj is MonsterAI) ? obj : null);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			object? obj2 = AccessTools.Field(typeof(BaseAI), "m_character")?.GetValue(val);
			return (Character)((obj2 is Character) ? obj2 : null);
		}
	}
	[BepInPlugin("com.mitch.battleboar", "BattleBoar", "1.0.0")]
	public class BattleBoarPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "com.mitch.battleboar";

		public const string PluginName = "BattleBoar";

		public const string PluginVersion = "1.0.0";

		public static ConfigEntry<KeyCode> SummonKey;

		public static ConfigEntry<float> BoarHealth;

		public static ConfigEntry<float> BoarScale;

		public static ConfigEntry<float> BoarRunSpeed;

		public static ConfigEntry<float> SpawnDistance;

		private Harmony harmony;

		public static BattleBoarPlugin Instance { get; private set; }

		private void Awake()
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected O, but got Unknown
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Expected O, but got Unknown
			Instance = this;
			SummonKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "SummonKey", (KeyCode)110, "Key to summon or recall your BattleBoar.");
			BoarHealth = ((BaseUnityPlugin)this).Config.Bind<float>("Stats", "BoarHealth", 500f, "Health of the BattleBoar.");
			BoarScale = ((BaseUnityPlugin)this).Config.Bind<float>("Stats", "BoarScale", 1.5f, new ConfigDescription("Scale multiplier for the BattleBoar (1.5 = 50% larger than normal boar).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 3f), Array.Empty<object>()));
			BoarRunSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Stats", "BoarRunSpeed", 8f, "Run speed of the BattleBoar.");
			SpawnDistance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "SpawnDistance", 15f, "How far ahead the BattleBoar spawns before running to you.");
			harmony = new Harmony("com.mitch.battleboar");
			harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"BattleBoar v1.0.0 loaded!");
		}

		private void Start()
		{
			((Component)this).gameObject.AddComponent<BattleBoarSpawner>();
		}

		private void Update()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Player.m_localPlayer == (Object)null || IsGuiOpen())
			{
				return;
			}
			if (Input.GetKeyDown(SummonKey.Value))
			{
				bool flag = Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303);
				bool flag2 = Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305);
				if (flag && flag2)
				{
					BattleBoarSpawner.Instance?.ToggleSaddleAdjust();
				}
				else
				{
					BattleBoarSpawner.Instance?.SummonOrRecall();
				}
			}
			if (!((Object)(object)BattleBoarSpawner.Instance != (Object)null) || !BattleBoarSpawner.Instance.saddleAdjustMode)
			{
				return;
			}
			bool flag3 = Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307);
			float num = (Input.GetKey((KeyCode)306) ? 5f : 15f);
			float num2 = (Input.GetKey((KeyCode)306) ? 0.02f : 0.05f);
			if (flag3)
			{
				if (Input.GetKeyDown((KeyCode)273))
				{
					BattleBoarSpawner.Instance.AdjustSaddlePosition(0f, 0f, num2);
				}
				if (Input.GetKeyDown((KeyCode)274))
				{
					BattleBoarSpawner.Instance.AdjustSaddlePosition(0f, 0f, 0f - num2);
				}
				if (Input.GetKeyDown((KeyCode)276))
				{
					BattleBoarSpawner.Instance.AdjustSaddlePosition(0f - num2, 0f, 0f);
				}
				if (Input.GetKeyDown((KeyCode)275))
				{
					BattleBoarSpawner.Instance.AdjustSaddlePosition(num2, 0f, 0f);
				}
				if (Input.GetKeyDown((KeyCode)280))
				{
					BattleBoarSpawner.Instance.AdjustSaddlePosition(0f, num2, 0f);
				}
				if (Input.GetKeyDown((KeyCode)281))
				{
					BattleBoarSpawner.Instance.AdjustSaddlePosition(0f, 0f - num2, 0f);
				}
			}
			else
			{
				if (Input.GetKeyDown((KeyCode)273))
				{
					BattleBoarSpawner.Instance.AdjustSaddleRotation(num, 0f, 0f);
				}
				if (Input.GetKeyDown((KeyCode)274))
				{
					BattleBoarSpawner.Instance.AdjustSaddleRotation(0f - num, 0f, 0f);
				}
				if (Input.GetKeyDown((KeyCode)276))
				{
					BattleBoarSpawner.Instance.AdjustSaddleRotation(0f, 0f - num, 0f);
				}
				if (Input.GetKeyDown((KeyCode)275))
				{
					BattleBoarSpawner.Instance.AdjustSaddleRotation(0f, num, 0f);
				}
				if (Input.GetKeyDown((KeyCode)280))
				{
					BattleBoarSpawner.Instance.AdjustSaddleRotation(0f, 0f, num);
				}
				if (Input.GetKeyDown((KeyCode)281))
				{
					BattleBoarSpawner.Instance.AdjustSaddleRotation(0f, 0f, 0f - num);
				}
			}
		}

		private bool IsGuiOpen()
		{
			if ((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus())
			{
				return true;
			}
			if (Console.IsVisible())
			{
				return true;
			}
			if (TextInput.IsVisible())
			{
				return true;
			}
			if (StoreGui.IsVisible())
			{
				return true;
			}
			if (InventoryGui.IsVisible())
			{
				return true;
			}
			if (Menu.IsVisible())
			{
				return true;
			}
			if (Minimap.IsOpen())
			{
				return true;
			}
			return false;
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}

		public static void Log(string msg)
		{
			BattleBoarPlugin instance = Instance;
			if (instance != null)
			{
				((BaseUnityPlugin)instance).Logger.LogInfo((object)msg);
			}
		}

		public static void LogWarn(string msg)
		{
			BattleBoarPlugin instance = Instance;
			if (instance != null)
			{
				((BaseUnityPlugin)instance).Logger.LogWarning((object)msg);
			}
		}

		public static void LogErr(string msg)
		{
			BattleBoarPlugin instance = Instance;
			if (instance != null)
			{
				((BaseUnityPlugin)instance).Logger.LogError((object)msg);
			}
		}
	}
}