Decompiled source of VikingHusbandry v0.2.1

VikingHusbandry.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Managers;
using Microsoft.CodeAnalysis;
using UnityEngine;
using VikingHusbandry.Configuration;
using VikingHusbandry.Features;
using VikingHusbandry.Features.Commands;
using VikingHusbandry.Features.Rodeo;
using VikingHusbandry.Features.Trough;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("DigitalVikings")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.1.0")]
[assembly: AssemblyInformationalVersion("0.2.1+ffd991665b8d7573cdefae47b4df573c3fa7a9a7")]
[assembly: AssemblyProduct("VikingHusbandry")]
[assembly: AssemblyTitle("VikingHusbandry")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace VikingHusbandry
{
	[BepInPlugin("com.digitalvikings.vikinghusbandry", "VikingHusbandry", "0.2.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class VikingHusbandryPlugin : BaseUnityPlugin
	{
		public const string ModGuid = "com.digitalvikings.vikinghusbandry";

		public const string ModName = "VikingHusbandry";

		public const string ModVersion = "0.2.1";

		internal static ManualLogSource Log;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"VikingHusbandry v0.2.1 initializing...");
			ModConfig.Init(((BaseUnityPlugin)this).Config);
			_harmony = new Harmony("com.digitalvikings.vikinghusbandry");
			_harmony.PatchAll();
			Log.LogInfo((object)"VikingHusbandry v0.2.1 loaded successfully.");
			if (Chainloader.PluginInfos.ContainsKey("com.jotunn.jotunn"))
			{
				HookJotunnSync();
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void HookJotunnSync()
		{
			SynchronizationManager.OnConfigurationSynchronized += delegate
			{
				Log.LogInfo((object)"Server configuration synchronized successfully.");
			};
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
}
namespace VikingHusbandry.Patches
{
	[HarmonyPatch(typeof(Container))]
	public static class ContainerPatches
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		public static void Awake_Postfix(Container __instance)
		{
			if ((Object)(object)__instance != (Object)null && Object.op_Implicit((Object)(object)__instance) && (Object)(object)((Component)__instance).GetComponentInParent<Piece>() != (Object)null && TroughRegistry.IsValidChest(__instance))
			{
				TroughRegistry.Register(__instance);
				TroughVisualizer.EnsureAttached(__instance);
			}
		}

		[HarmonyPatch("UpdateUseVisual")]
		[HarmonyPostfix]
		public static void UpdateUseVisual_Postfix(Container __instance)
		{
			if ((Object)(object)__instance != (Object)null && Object.op_Implicit((Object)(object)__instance) && TroughRegistry.IsTrough(__instance))
			{
				TroughVisualizer.Get(__instance)?.EnsureChestRenderersHidden();
			}
		}

		[HarmonyPatch("Interact")]
		[HarmonyPrefix]
		public static bool Interact_Prefix(Container __instance, Humanoid character, bool hold, bool alt, ref bool __result)
		{
			if (!ModConfig.ModEnabled.Value || !ModConfig.EnableTroughs.Value || (Object)(object)__instance == (Object)null || !Object.op_Implicit((Object)(object)__instance))
			{
				return true;
			}
			if (hold)
			{
				return true;
			}
			if (!TroughRegistry.IsValidChest(__instance))
			{
				return true;
			}
			if (alt)
			{
				Player player = (Player)(object)((character is Player) ? character : null);
				TroughRegistry.ToggleTrough(__instance, player);
				__result = true;
				return false;
			}
			return true;
		}

		[HarmonyPatch("GetHoverText")]
		[HarmonyPostfix]
		public static void GetHoverText_Postfix(Container __instance, ref string __result)
		{
			if (ModConfig.ModEnabled.Value && ModConfig.EnableTroughs.Value && !((Object)(object)__instance == (Object)null) && Object.op_Implicit((Object)(object)__instance) && TroughRegistry.IsValidChest(__instance))
			{
				string text = Localization.instance.Localize("$KEY_Use");
				if (TroughRegistry.IsTrough(__instance))
				{
					int num = TroughRegistry.CountAcceptableFood(__instance, null);
					string text2 = $"<color=green><b>Feeding Trough</b></color> ({num} items)";
					string text3 = "[<color=yellow><b>Shift+" + text + "</b></color>] Revert to Chest";
					__result = text2 + "\n" + __result + "\n" + text3;
				}
				else
				{
					string text4 = "[<color=yellow><b>Shift+" + text + "</b></color>] Convert to Feeding Trough";
					__result = __result + "\n" + text4;
				}
			}
		}
	}
	[HarmonyPatch(typeof(MonsterAI))]
	public static class MonsterAIPatches
	{
		private static readonly FieldRef<BaseAI, Character>? s_characterRef = AccessTools.FieldRefAccess<BaseAI, Character>("m_character");

		private static readonly FieldRef<BaseAI, Tameable>? s_tamableRef = AccessTools.FieldRefAccess<BaseAI, Tameable>("m_tamable");

		private static readonly FieldRef<BaseAI, ZNetView>? s_nviewRef = AccessTools.FieldRefAccess<BaseAI, ZNetView>("m_nview");

		private static Character? GetCharacter(MonsterAI ai)
		{
			if ((Object)(object)ai == (Object)null || !Object.op_Implicit((Object)(object)ai))
			{
				return null;
			}
			if (s_characterRef != null)
			{
				Character val = s_characterRef.Invoke((BaseAI)(object)ai);
				if ((Object)(object)val != (Object)null && Object.op_Implicit((Object)(object)val))
				{
					return val;
				}
			}
			return ((Component)ai).GetComponent<Character>();
		}

		private static Tameable? GetTameable(MonsterAI ai)
		{
			if ((Object)(object)ai == (Object)null || !Object.op_Implicit((Object)(object)ai))
			{
				return null;
			}
			if (s_tamableRef != null)
			{
				Tameable val = s_tamableRef.Invoke((BaseAI)(object)ai);
				if ((Object)(object)val != (Object)null && Object.op_Implicit((Object)(object)val))
				{
					return val;
				}
			}
			return ((Component)ai).GetComponent<Tameable>();
		}

		private static ZNetView? GetNView(MonsterAI ai)
		{
			if ((Object)(object)ai == (Object)null || !Object.op_Implicit((Object)(object)ai))
			{
				return null;
			}
			if (s_nviewRef != null)
			{
				ZNetView val = s_nviewRef.Invoke((BaseAI)(object)ai);
				if ((Object)(object)val != (Object)null && Object.op_Implicit((Object)(object)val))
				{
					return val;
				}
			}
			return ((Component)ai).GetComponent<ZNetView>();
		}

		[HarmonyPatch("UpdateAI")]
		[HarmonyPrefix]
		public static bool UpdateAI_Prefix(MonsterAI __instance, float dt, ref bool __result)
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			if (!ModConfig.ModEnabled.Value)
			{
				return true;
			}
			if ((Object)(object)__instance == (Object)null || !Object.op_Implicit((Object)(object)__instance))
			{
				return true;
			}
			ZNetView nView = GetNView(__instance);
			if ((Object)(object)nView == (Object)null || !nView.IsValid())
			{
				return true;
			}
			Character character = GetCharacter(__instance);
			if ((Object)(object)character == (Object)null || !Object.op_Implicit((Object)(object)character))
			{
				return true;
			}
			if (RodeoController.IsBeastInTether(character))
			{
				__result = true;
				return false;
			}
			if (RodeoController.IsBeastMounted(character))
			{
				((BaseAI)__instance).StopMoving();
				__result = true;
				return false;
			}
			DownedTamingManager.CheckDownedRecovery(character);
			if (DownedTamingManager.IsDowned(character))
			{
				((BaseAI)__instance).StopMoving();
				Rigidbody component = ((Component)character).GetComponent<Rigidbody>();
				if ((Object)(object)component != (Object)null && !component.isKinematic)
				{
					component.linearVelocity = Vector3.zero;
					component.angularVelocity = Vector3.zero;
				}
				if (!DownedRagdollManager.HasRagdoll(character))
				{
					DownedRagdollManager.CreateDownedRagdoll(character);
				}
				__result = true;
				return false;
			}
			if (DownedRagdollManager.HasRagdoll(character))
			{
				DownedRagdollManager.RemoveDownedRagdoll(character);
			}
			Tameable tameable = GetTameable(__instance);
			if (ModConfig.EnableTroughs.Value && character.IsTamed() && (Object)(object)tameable != (Object)null && tameable.IsHungry() && __instance.m_consumeItems != null && __instance.m_consumeItems.Count > 0)
			{
				Container val = TroughRegistry.FindClosestTroughWithFood(((Component)character).transform.position, __instance.m_consumeItems, ModConfig.ScentRadius.Value);
				if ((Object)(object)val != (Object)null)
				{
					if (Vector3.Distance(((Component)character).transform.position, ((Component)val).transform.position) > 2.5f)
					{
						AIHelper.MoveTo((BaseAI)(object)__instance, dt, ((Component)val).transform.position, 2f, run: false);
						__result = true;
						return false;
					}
					((BaseAI)__instance).StopMoving();
					AIHelper.LookAt((BaseAI)(object)__instance, ((Component)val).transform.position);
					if (TroughRegistry.ConsumeOneFromTrough(val, __instance.m_consumeItems) != null)
					{
						ZSyncAnimation zAnim = character.GetZAnim();
						if ((Object)(object)zAnim != (Object)null)
						{
							zAnim.SetTrigger("consume");
						}
						if (tameable.m_sootheEffect != null)
						{
							tameable.m_sootheEffect.Create(character.GetCenterPoint(), Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID));
						}
						AIHelper.ResetFeedingTimer(tameable);
					}
					__result = true;
					return false;
				}
			}
			return true;
		}

		[HarmonyPatch("IsSleeping")]
		[HarmonyPrefix]
		public static bool IsSleeping_Prefix(MonsterAI __instance, ref bool __result)
		{
			if (!ModConfig.ModEnabled.Value)
			{
				return true;
			}
			if ((Object)(object)__instance == (Object)null || !Object.op_Implicit((Object)(object)__instance))
			{
				return true;
			}
			Character character = GetCharacter(__instance);
			if ((Object)(object)character != (Object)null && DownedTamingManager.IsDowned(character))
			{
				__result = true;
				return false;
			}
			return true;
		}

		[HarmonyPatch("UpdateTarget")]
		[HarmonyPostfix]
		public static void UpdateTarget_Postfix(MonsterAI __instance)
		{
			//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_00a8: Unknown result type (might be due to invalid IL or missing references)
			if (!ModConfig.ModEnabled.Value || !ModConfig.EnableStances.Value || (Object)(object)__instance == (Object)null || !Object.op_Implicit((Object)(object)__instance))
			{
				return;
			}
			Character character = GetCharacter(__instance);
			if ((Object)(object)character == (Object)null || !Object.op_Implicit((Object)(object)character) || !character.IsTamed())
			{
				return;
			}
			StanceType stance = CompanionStanceManager.GetStance(character);
			Vector3 point;
			if (CompanionStanceManager.ShouldRetaliateOnly(stance))
			{
				if (AIHelper.GetTimeSinceHurt((BaseAI)(object)__instance) > 3f)
				{
					AIHelper.SetTargetCreature(__instance, null);
				}
			}
			else if (stance == StanceType.StayGuard && AIHelper.GetPatrolPoint((BaseAI)(object)__instance, out point) && Vector3.Distance(((Component)character).transform.position, point) > ModConfig.GuardLeashRadius.Value)
			{
				AIHelper.SetTargetCreature(__instance, null);
				AIHelper.MoveTo((BaseAI)(object)__instance, Time.deltaTime, point, 1f, run: true);
			}
		}
	}
	[HarmonyPatch(typeof(Procreation))]
	public static class ProcreationPatches
	{
		[HarmonyPatch("Procreate")]
		[HarmonyPrefix]
		public static bool Procreate_Prefix(Procreation __instance)
		{
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			if (!ModConfig.ModEnabled.Value || !ModConfig.AntiChuteHorizontalOnly.Value || (Object)(object)__instance == (Object)null || !Object.op_Implicit((Object)(object)__instance))
			{
				return true;
			}
			ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
			if ((Object)(object)component == (Object)null || !component.IsValid())
			{
				return true;
			}
			if (component.GetZDO().GetLong(ZDOVars.s_pregnant, 0L) != 0L)
			{
				return true;
			}
			if ((Object)(object)ZNetScene.instance == (Object)null)
			{
				return true;
			}
			int prefab = component.GetZDO().GetPrefab();
			GameObject prefab2 = ZNetScene.instance.GetPrefab(prefab);
			if ((Object)(object)prefab2 == (Object)null)
			{
				return true;
			}
			if (PaddockDensityEnforcer.IsPaddockOvercrowded(prefab2, __instance.m_offspring, ((Component)__instance).transform.position, __instance.m_totalCheckRange, __instance.m_maxCreatures))
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Tameable))]
	public static class TameablePatches
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		public static void Awake_Postfix(Tameable __instance)
		{
			if (!((Object)(object)__instance == (Object)null) && Object.op_Implicit((Object)(object)__instance) && ModConfig.ModEnabled.Value && ModConfig.AllowBoarCommands.Value && !__instance.m_commandable)
			{
				__instance.m_commandable = true;
			}
		}

		[HarmonyPatch("Interact")]
		[HarmonyPrefix]
		public static bool Interact_Prefix(Tameable __instance, Humanoid user, bool hold, bool alt, ref bool __result)
		{
			if ((Object)(object)__instance == (Object)null || !Object.op_Implicit((Object)(object)__instance) || !ModConfig.ModEnabled.Value)
			{
				return true;
			}
			if (hold)
			{
				return true;
			}
			Character component = ((Component)__instance).GetComponent<Character>();
			if ((Object)(object)component == (Object)null || !Object.op_Implicit((Object)(object)component))
			{
				return true;
			}
			Player val = (Player)(object)((user is Player) ? user : null);
			MonsterAI component2 = ((Component)__instance).GetComponent<MonsterAI>();
			if (!__instance.IsTamed())
			{
				if (ModConfig.EnableRodeoSubdual.Value)
				{
					if (DownedTamingManager.IsDowned(component))
					{
						if ((Object)(object)val != (Object)null)
						{
							((Character)val).Message((MessageType)1, "Exhausted. Use hotbar food (1-8).", 0, (Sprite)null, false);
						}
						__result = true;
						return false;
					}
					if (DownedTamingManager.CanBeSubdued(component))
					{
						if ((Object)(object)val != (Object)null)
						{
							RodeoController.StartRodeo(val, component);
						}
						__result = true;
						return false;
					}
				}
				return true;
			}
			if (alt)
			{
				return true;
			}
			if (ModConfig.EnableStances.Value && (Object)(object)val != (Object)null && (Object)(object)component2 != (Object)null)
			{
				CompanionStanceManager.CycleStance(component, val, component2);
				__result = true;
				return false;
			}
			return true;
		}

		[HarmonyPatch("GetHoverText")]
		[HarmonyPostfix]
		public static void GetHoverText_Postfix(Tameable __instance, ref string __result)
		{
			if ((Object)(object)__instance == (Object)null || !Object.op_Implicit((Object)(object)__instance) || !ModConfig.ModEnabled.Value)
			{
				return;
			}
			Character component = ((Component)__instance).GetComponent<Character>();
			if ((Object)(object)component == (Object)null || !Object.op_Implicit((Object)(object)component))
			{
				return;
			}
			string text = Localization.instance.Localize("$KEY_Use");
			if (!__instance.IsTamed())
			{
				if (!ModConfig.EnableRodeoSubdual.Value)
				{
					return;
				}
				if (DownedTamingManager.IsDowned(component))
				{
					float downedSecondsRemaining = DownedTamingManager.GetDownedSecondsRemaining(component);
					float remainingTime = AIHelper.GetRemainingTime(__instance);
					int num = Mathf.Clamp(Mathf.RoundToInt((1f - remainingTime / __instance.m_tamingTime) * 100f), 0, 100);
					string arg = ((num > 0) ? $" (Tamed {num}%)" : "");
					__result += $"\n<color=orange><b>Downed ({Mathf.CeilToInt(downedSecondsRemaining)}s)</b></color>{arg} - [<color=yellow><b>1-8</b></color>] Feed to tame";
					return;
				}
				int num2 = Mathf.Clamp(Mathf.RoundToInt(DownedTamingManager.GetSubdualProgress(component) * 100f), 0, 100);
				string text2 = ((((Object)component).name.StartsWith("Boar") || (component.m_name != null && component.m_name.ToLower().Contains("boar"))) ? "Leash" : "Subdue");
				if (DownedTamingManager.CanBeSubdued(component))
				{
					string text3 = ((num2 > 0) ? $" ({num2}%)" : "");
					__result = __result + "\n[<color=yellow><b>" + text + "</b></color>] " + text2 + text3;
				}
				else if (num2 > 0)
				{
					__result += $"\n<color=yellow>[Subdual: {num2}% - Parry or Sneak to {text2.ToLower()}]</color>";
				}
			}
			else if (ModConfig.EnableStances.Value)
			{
				string stanceDisplayName = CompanionStanceManager.GetStanceDisplayName(CompanionStanceManager.GetStance(component));
				__result = __result + "\n<color=#55ffff>[" + stanceDisplayName + "]</color>";
			}
		}

		[HarmonyPatch("UseItem")]
		[HarmonyPrefix]
		public static bool UseItem_Prefix(Tameable __instance, Humanoid user, ItemData item, ref bool __result)
		{
			if ((Object)(object)__instance == (Object)null || !Object.op_Implicit((Object)(object)__instance) || !ModConfig.ModEnabled.Value || !ModConfig.EnableRodeoSubdual.Value)
			{
				return true;
			}
			Character component = ((Component)__instance).GetComponent<Character>();
			if ((Object)(object)component == (Object)null || !Object.op_Implicit((Object)(object)component) || !DownedTamingManager.IsDowned(component))
			{
				return true;
			}
			MonsterAI component2 = ((Component)__instance).GetComponent<MonsterAI>();
			if ((Object)(object)component2 == (Object)null || !Object.op_Implicit((Object)(object)component2))
			{
				return true;
			}
			if (DownedTamingManager.TryForceFeed(user, item, __instance, component2))
			{
				__result = true;
				return false;
			}
			return true;
		}
	}
}
namespace VikingHusbandry.Features
{
	public static class AIHelper
	{
		private static readonly MethodInfo? s_moveToMethod = AccessTools.Method(typeof(BaseAI), "MoveTo", new Type[4]
		{
			typeof(float),
			typeof(Vector3),
			typeof(float),
			typeof(bool)
		}, (Type[])null);

		private static readonly MethodInfo? s_lookAtMethod = AccessTools.Method(typeof(BaseAI), "LookAt", new Type[1] { typeof(Vector3) }, (Type[])null);

		private static readonly MethodInfo? s_getPatrolPointMethod = AccessTools.Method(typeof(BaseAI), "GetPatrolPoint", new Type[1] { typeof(Vector3).MakeByRefType() }, (Type[])null);

		private static readonly FieldInfo? s_targetCreatureField = AccessTools.Field(typeof(MonsterAI), "m_targetCreature");

		private static readonly FieldInfo? s_timeSinceHurtField = AccessTools.Field(typeof(BaseAI), "m_timeSinceHurt");

		private static readonly MethodInfo? s_fleeMethod = AccessTools.Method(typeof(BaseAI), "Flee", new Type[2]
		{
			typeof(float),
			typeof(Vector3)
		}, (Type[])null);

		public static void Flee(BaseAI ai, float dt, Vector3 point)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)ai == (Object)null) && !(s_fleeMethod == null))
			{
				s_fleeMethod.Invoke(ai, new object[2] { dt, point });
			}
		}

		public static bool MoveTo(BaseAI ai, float dt, Vector3 point, float dist, bool run)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ai == (Object)null || s_moveToMethod == null)
			{
				return false;
			}
			return (bool)s_moveToMethod.Invoke(ai, new object[4] { dt, point, dist, run });
		}

		public static void LookAt(BaseAI ai, Vector3 point)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)ai == (Object)null) && !(s_lookAtMethod == null))
			{
				s_lookAtMethod.Invoke(ai, new object[1] { point });
			}
		}

		public static bool GetPatrolPoint(BaseAI ai, out Vector3 point)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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)
			point = Vector3.zero;
			if ((Object)(object)ai == (Object)null || s_getPatrolPointMethod == null)
			{
				return false;
			}
			object[] array = new object[1] { Vector3.zero };
			bool result = (bool)s_getPatrolPointMethod.Invoke(ai, array);
			point = (Vector3)array[0];
			return result;
		}

		public static void SetTargetCreature(MonsterAI ai, Character? target)
		{
			if (!((Object)(object)ai == (Object)null) && !(s_targetCreatureField == null))
			{
				s_targetCreatureField.SetValue(ai, target);
			}
		}

		public static Character? GetTargetCreature(MonsterAI ai)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			if ((Object)(object)ai == (Object)null || s_targetCreatureField == null)
			{
				return null;
			}
			return (Character)s_targetCreatureField.GetValue(ai);
		}

		public static float GetTimeSinceHurt(BaseAI ai)
		{
			if ((Object)(object)ai == (Object)null || s_timeSinceHurtField == null)
			{
				return 999f;
			}
			return (float)s_timeSinceHurtField.GetValue(ai);
		}

		public static float GetRemainingTime(Tameable tameable)
		{
			if ((Object)(object)tameable == (Object)null)
			{
				return 0f;
			}
			ZNetView component = ((Component)tameable).GetComponent<ZNetView>();
			if ((Object)(object)component == (Object)null || !component.IsValid())
			{
				return tameable.m_tamingTime;
			}
			return component.GetZDO().GetFloat(ZDOVars.s_tameTimeLeft, tameable.m_tamingTime);
		}

		public static void DecreaseRemainingTime(Tameable tameable, float time)
		{
			if (!((Object)(object)tameable == (Object)null))
			{
				ZNetView component = ((Component)tameable).GetComponent<ZNetView>();
				if (!((Object)(object)component == (Object)null) && component.IsValid())
				{
					float remainingTime = GetRemainingTime(tameable);
					float num = Mathf.Max(0f, remainingTime - time);
					component.GetZDO().Set(ZDOVars.s_tameTimeLeft, num);
				}
			}
		}

		public static void ResetFeedingTimer(Tameable tameable)
		{
			if (!((Object)(object)tameable == (Object)null) && !((Object)(object)ZNet.instance == (Object)null))
			{
				ZNetView component = ((Component)tameable).GetComponent<ZNetView>();
				if (!((Object)(object)component == (Object)null) && component.IsValid())
				{
					component.GetZDO().Set(ZDOVars.s_tameLastFeeding, ZNet.instance.GetTime().Ticks);
				}
			}
		}

		public static void Tame(Tameable tameable, MonsterAI monsterAI)
		{
			if ((Object)(object)tameable == (Object)null)
			{
				return;
			}
			ZNetView component = ((Component)tameable).GetComponent<ZNetView>();
			if ((Object)(object)component != (Object)null && component.IsValid())
			{
				component.GetZDO().Set(ZDOVars.s_tameTimeLeft, 0f);
			}
			if ((Object)(object)monsterAI != (Object)null)
			{
				monsterAI.MakeTame();
				return;
			}
			Character component2 = ((Component)tameable).GetComponent<Character>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.SetTamed(true);
			}
		}
	}
}
namespace VikingHusbandry.Features.Trough
{
	public static class PaddockDensityEnforcer
	{
		public static int GetNrOfInstancesHorizontal(GameObject prefab, Vector3 center, float maxRange, bool procreationOnly)
		{
			//IL_0083: 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_008e: 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)
			if ((Object)(object)prefab == (Object)null)
			{
				return 0;
			}
			string text = ((Object)prefab).name + "(Clone)";
			int num = 0;
			float num2 = maxRange * maxRange;
			List<BaseAI> baseAIInstances = BaseAI.BaseAIInstances;
			if (baseAIInstances != null)
			{
				foreach (BaseAI item in baseAIInstances)
				{
					if ((Object)(object)item == (Object)null || (Object)(object)((Component)item).gameObject == (Object)null || ((Object)((Component)item).gameObject).name != text)
					{
						continue;
					}
					if (maxRange > 0f)
					{
						Vector3 position = ((Component)item).transform.position;
						float num3 = position.x - center.x;
						float num4 = position.z - center.z;
						if (num3 * num3 + num4 * num4 > num2)
						{
							continue;
						}
					}
					if (procreationOnly)
					{
						Procreation component = ((Component)item).GetComponent<Procreation>();
						if ((Object)(object)component == (Object)null || !component.ReadyForProcreation())
						{
							continue;
						}
					}
					num++;
				}
			}
			return num;
		}

		public static bool IsPaddockOvercrowded(GameObject myPrefab, GameObject? offspringPrefab, Vector3 position, float range, int maxCreatures)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)myPrefab == (Object)null)
			{
				return false;
			}
			float maxRange = ((ModConfig.PaddockRadius.Value > 0f) ? ModConfig.PaddockRadius.Value : range);
			int num = GetNrOfInstancesHorizontal(myPrefab, position, maxRange, procreationOnly: false);
			if ((Object)(object)offspringPrefab != (Object)null && (Object)(object)offspringPrefab != (Object)(object)myPrefab)
			{
				num += GetNrOfInstancesHorizontal(offspringPrefab, position, maxRange, procreationOnly: false);
			}
			return num >= maxCreatures;
		}
	}
	public static class TroughMeshBuilder
	{
		private static Mesh? s_troughMesh;

		private static Mesh? s_feedMesh;

		public static Mesh GetOrCreateTroughMesh()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: 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_00e5: 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_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: 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_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: 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_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Expected O, but got Unknown
			if ((Object)(object)s_troughMesh != (Object)null)
			{
				return s_troughMesh;
			}
			Mesh val = new Mesh
			{
				name = "VH_ProceduralTroughMesh"
			};
			List<Vector3> list = new List<Vector3>();
			List<Vector3> list2 = new List<Vector3>();
			List<Vector2> list3 = new List<Vector2>();
			List<int> list4 = new List<int>();
			float num = 0.08f;
			float num2 = 0.54f;
			float num3 = 0.56f;
			float num4 = 0.26f;
			AddBox(list, list2, list3, list4, new Vector3(0f - num3, num2 * 0.5f, 0f - num4), new Vector3(num, num2, num));
			AddBox(list, list2, list3, list4, new Vector3(num3, num2 * 0.5f, 0f - num4), new Vector3(num, num2, num));
			AddBox(list, list2, list3, list4, new Vector3(0f - num3, num2 * 0.5f, num4), new Vector3(num, num2, num));
			AddBox(list, list2, list3, list4, new Vector3(num3, num2 * 0.5f, num4), new Vector3(num, num2, num));
			float num5 = 0.06f;
			float num6 = 0.07f;
			float num7 = num4 * 2f + num + 0.04f;
			AddBox(list, list2, list3, list4, new Vector3(0f - num3, num5 * 0.5f, 0f), new Vector3(num6, num5, num7));
			AddBox(list, list2, list3, list4, new Vector3(num3, num5 * 0.5f, 0f), new Vector3(num6, num5, num7));
			float num8 = 0.18f;
			float num9 = 0.04f;
			float num10 = num3 * 2f - num;
			float num11 = num4 * 2f - num;
			AddBox(list, list2, list3, list4, new Vector3(0f, num8 + num9 * 0.5f, 0f), new Vector3(num10, num9, num11));
			float num12 = num2 - num8;
			float num13 = 0.045f;
			float num14 = num8 + num12 * 0.5f;
			AddBox(list, list2, list3, list4, new Vector3(0f, num14, 0f - num4), new Vector3(num10, num12, num13));
			AddBox(list, list2, list3, list4, new Vector3(0f, num14, num4), new Vector3(num10, num12, num13));
			AddBox(list, list2, list3, list4, new Vector3(0f - num3, num14, 0f), new Vector3(num13, num12, num11));
			AddBox(list, list2, list3, list4, new Vector3(num3, num14, 0f), new Vector3(num13, num12, num11));
			val.SetVertices(list);
			val.SetNormals(list2);
			val.SetUVs(0, list3);
			val.SetTriangles(list4, 0);
			val.RecalculateBounds();
			s_troughMesh = val;
			return s_troughMesh;
		}

		public static Mesh GetOrCreateFeedMesh()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)s_feedMesh != (Object)null)
			{
				return s_feedMesh;
			}
			Mesh val = new Mesh
			{
				name = "VH_ProceduralFeedMesh"
			};
			int num = 7;
			int num2 = 4;
			float num3 = 0.98f;
			float num4 = 0.44f;
			List<Vector3> list = new List<Vector3>();
			List<Vector3> list2 = new List<Vector3>();
			List<Vector2> list3 = new List<Vector2>();
			List<int> list4 = new List<int>();
			for (int i = 0; i <= num2; i++)
			{
				float num5 = (float)i / (float)num2;
				float num6 = Mathf.Lerp((0f - num4) * 0.5f, num4 * 0.5f, num5);
				for (int j = 0; j <= num; j++)
				{
					float num7 = (float)j / (float)num;
					float num8 = Mathf.Lerp((0f - num3) * 0.5f, num3 * 0.5f, num7);
					float num9 = Mathf.Sin(num7 * MathF.PI);
					float num10 = Mathf.Sin(num5 * MathF.PI);
					float num11 = num9 * num10 * 0.07f;
					list.Add(new Vector3(num8, num11, num6));
					list2.Add(Vector3.up);
					list3.Add(new Vector2(num7 * 2.5f, num5 * 1.5f));
				}
			}
			for (int k = 0; k < num2; k++)
			{
				for (int l = 0; l < num; l++)
				{
					int num12 = k * (num + 1) + l;
					int item = num12 + 1;
					int num13 = (k + 1) * (num + 1) + l;
					int item2 = num13 + 1;
					list4.Add(num12);
					list4.Add(num13);
					list4.Add(item);
					list4.Add(item);
					list4.Add(num13);
					list4.Add(item2);
				}
			}
			val.SetVertices(list);
			val.SetNormals(list2);
			val.SetUVs(0, list3);
			val.SetTriangles(list4, 0);
			val.RecalculateNormals();
			val.RecalculateBounds();
			s_feedMesh = val;
			return s_feedMesh;
		}

		private static void AddBox(List<Vector3> verts, List<Vector3> norms, List<Vector2> uvs, List<int> tris, Vector3 center, Vector3 size)
		{
			//IL_0000: 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_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_0040: 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_004b: 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_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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)
			//IL_006e: 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_0076: 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_0083: 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_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: 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_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: 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_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: 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_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: 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_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: 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_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: 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_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: 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_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: 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_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_0335: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_034a: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_035c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_0368: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0381: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: 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_0391: Unknown result type (might be due to invalid IL or missing references)
			//IL_0396: Unknown result type (might be due to invalid IL or missing references)
			//IL_039d: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = size * 0.5f;
			AddQuad(verts, norms, uvs, tris, center + new Vector3(0f - val.x, val.y, 0f - val.z), center + new Vector3(0f - val.x, val.y, val.z), center + new Vector3(val.x, val.y, val.z), center + new Vector3(val.x, val.y, 0f - val.z), Vector3.up, size.x, size.z);
			AddQuad(verts, norms, uvs, tris, center + new Vector3(0f - val.x, 0f - val.y, val.z), center + new Vector3(0f - val.x, 0f - val.y, 0f - val.z), center + new Vector3(val.x, 0f - val.y, 0f - val.z), center + new Vector3(val.x, 0f - val.y, val.z), Vector3.down, size.x, size.z);
			AddQuad(verts, norms, uvs, tris, center + new Vector3(0f - val.x, 0f - val.y, 0f - val.z), center + new Vector3(0f - val.x, val.y, 0f - val.z), center + new Vector3(val.x, val.y, 0f - val.z), center + new Vector3(val.x, 0f - val.y, 0f - val.z), Vector3.back, size.x, size.y);
			AddQuad(verts, norms, uvs, tris, center + new Vector3(val.x, 0f - val.y, val.z), center + new Vector3(val.x, val.y, val.z), center + new Vector3(0f - val.x, val.y, val.z), center + new Vector3(0f - val.x, 0f - val.y, val.z), Vector3.forward, size.x, size.y);
			AddQuad(verts, norms, uvs, tris, center + new Vector3(0f - val.x, 0f - val.y, val.z), center + new Vector3(0f - val.x, val.y, val.z), center + new Vector3(0f - val.x, val.y, 0f - val.z), center + new Vector3(0f - val.x, 0f - val.y, 0f - val.z), Vector3.left, size.z, size.y);
			AddQuad(verts, norms, uvs, tris, center + new Vector3(val.x, 0f - val.y, 0f - val.z), center + new Vector3(val.x, val.y, 0f - val.z), center + new Vector3(val.x, val.y, val.z), center + new Vector3(val.x, 0f - val.y, val.z), Vector3.right, size.z, size.y);
		}

		private static void AddQuad(List<Vector3> verts, List<Vector3> norms, List<Vector2> uvs, List<int> tris, Vector3 v0, Vector3 v1, Vector3 v2, Vector3 v3, Vector3 normal, float uvWidth, float uvHeight)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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_0038: 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_0058: 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_007f: 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)
			int count = verts.Count;
			verts.Add(v0);
			verts.Add(v1);
			verts.Add(v2);
			verts.Add(v3);
			norms.Add(normal);
			norms.Add(normal);
			norms.Add(normal);
			norms.Add(normal);
			float num = 1f;
			uvs.Add(new Vector2(0f, 0f));
			uvs.Add(new Vector2(0f, uvHeight * num));
			uvs.Add(new Vector2(uvWidth * num, uvHeight * num));
			uvs.Add(new Vector2(uvWidth * num, 0f));
			tris.Add(count);
			tris.Add(count + 1);
			tris.Add(count + 2);
			tris.Add(count);
			tris.Add(count + 2);
			tris.Add(count + 3);
		}
	}
	public static class TroughRegistry
	{
		private static readonly int s_isTroughHash = StringExtensionMethods.GetStableHashCode("VH_IsTrough");

		private static readonly List<Container> s_activeTroughs = new List<Container>();

		public static bool IsValidChest(Container container)
		{
			if ((Object)(object)container == (Object)null)
			{
				return false;
			}
			if ((Object)(object)container.m_wagon != (Object)null)
			{
				return false;
			}
			if ((Object)(object)((Component)container).GetComponentInParent<Piece>() == (Object)null)
			{
				return false;
			}
			if ((Object)(object)((Component)container).GetComponentInParent<Character>() != (Object)null)
			{
				return false;
			}
			if ((Object)(object)((Component)container).GetComponentInParent<Incinerator>() != (Object)null)
			{
				return false;
			}
			if ((Object)(object)((Component)container).GetComponentInParent<Ship>() != (Object)null)
			{
				return false;
			}
			string text = ((Object)((Component)container).gameObject).name.ToLower();
			if (text.Contains("barrel") || text.Contains("wagon") || text.Contains("cart") || text.Contains("ship") || text.Contains("karve"))
			{
				return false;
			}
			return text.Contains("chest");
		}

		public static void Register(Container container)
		{
			if ((Object)(object)container != (Object)null && IsValidChest(container) && !s_activeTroughs.Contains(container))
			{
				s_activeTroughs.Add(container);
			}
		}

		public static void Unregister(Container container)
		{
			if ((Object)(object)container != (Object)null)
			{
				s_activeTroughs.Remove(container);
			}
		}

		public static bool IsTrough(Container container)
		{
			if ((Object)(object)container == (Object)null)
			{
				return false;
			}
			ZNetView component = ((Component)container).GetComponent<ZNetView>();
			if ((Object)(object)component == (Object)null || !component.IsValid())
			{
				return false;
			}
			return component.GetZDO().GetInt(s_isTroughHash, 0) == 1;
		}

		public static void ToggleTrough(Container container, Player? player)
		{
			if ((Object)(object)container == (Object)null)
			{
				return;
			}
			ZNetView component = ((Component)container).GetComponent<ZNetView>();
			if (!((Object)(object)component == (Object)null) && component.IsValid())
			{
				int num = ((!IsTrough(container)) ? 1 : 0);
				component.GetZDO().Set(s_isTroughHash, num, false);
				TroughVisualizer.Get(container)?.SetVisualState(num == 1);
				if ((Object)(object)player != (Object)null)
				{
					string text = ((num == 1) ? "Feeding Trough" : "Standard Chest");
					((Character)player).Message((MessageType)1, text, 0, (Sprite)null, false);
				}
			}
		}

		public static int CountAcceptableFood(Container container, List<ItemDrop>? consumeItems)
		{
			if ((Object)(object)container == (Object)null || container.GetInventory() == null)
			{
				return 0;
			}
			int num = 0;
			foreach (ItemData allItem in container.GetInventory().GetAllItems())
			{
				if (allItem == null)
				{
					continue;
				}
				if (consumeItems == null || consumeItems.Count == 0)
				{
					num += allItem.m_stack;
					continue;
				}
				foreach (ItemDrop consumeItem in consumeItems)
				{
					if ((Object)(object)consumeItem != (Object)null && consumeItem.m_itemData != null && consumeItem.m_itemData.m_shared.m_name == allItem.m_shared.m_name)
					{
						num += allItem.m_stack;
						break;
					}
				}
			}
			return num;
		}

		public static Container? FindClosestTroughWithFood(Vector3 position, List<ItemDrop> consumeItems, float maxRadius)
		{
			//IL_0054: 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)
			Container result = null;
			float num = maxRadius;
			s_activeTroughs.RemoveAll((Container c) => (Object)(object)c == (Object)null || (Object)(object)((Component)c).gameObject == (Object)null);
			foreach (Container s_activeTrough in s_activeTroughs)
			{
				if (!((Object)(object)s_activeTrough == (Object)null) && IsTrough(s_activeTrough))
				{
					float num2 = Vector3.Distance(position, ((Component)s_activeTrough).transform.position);
					if (!(num2 > maxRadius) && !(num2 >= num) && CountAcceptableFood(s_activeTrough, consumeItems) > 0)
					{
						result = s_activeTrough;
						num = num2;
					}
				}
			}
			return result;
		}

		public static ItemData? ConsumeOneFromTrough(Container container, List<ItemDrop> consumeItems)
		{
			if ((Object)(object)container == (Object)null || container.GetInventory() == null)
			{
				return null;
			}
			foreach (ItemData allItem in container.GetInventory().GetAllItems())
			{
				if (allItem == null)
				{
					continue;
				}
				foreach (ItemDrop consumeItem in consumeItems)
				{
					if ((Object)(object)consumeItem != (Object)null && consumeItem.m_itemData != null && consumeItem.m_itemData.m_shared.m_name == allItem.m_shared.m_name)
					{
						container.GetInventory().RemoveOneItem(allItem);
						return allItem;
					}
				}
			}
			return null;
		}
	}
	public class TroughVisualizer : MonoBehaviour
	{
		private Container? _container;

		private GameObject? _troughVisualObj;

		private GameObject? _feedMoundObj;

		private Renderer[] _chestRenderers = Array.Empty<Renderer>();

		private bool _isTroughVisualActive;

		private float _syncTimer;

		private static Material? s_strawMaterial;

		public static TroughVisualizer? Get(Container container)
		{
			if ((Object)(object)container == (Object)null || !Object.op_Implicit((Object)(object)container))
			{
				return null;
			}
			return ((Component)container).GetComponent<TroughVisualizer>();
		}

		public static TroughVisualizer? EnsureAttached(Container container)
		{
			if ((Object)(object)container == (Object)null || !Object.op_Implicit((Object)(object)container))
			{
				return null;
			}
			TroughVisualizer troughVisualizer = ((Component)container).GetComponent<TroughVisualizer>();
			if ((Object)(object)troughVisualizer == (Object)null)
			{
				troughVisualizer = ((Component)container).gameObject.AddComponent<TroughVisualizer>();
			}
			return troughVisualizer;
		}

		private void Awake()
		{
			_container = ((Component)this).GetComponent<Container>();
			if (!((Object)(object)_container == (Object)null) && Object.op_Implicit((Object)(object)_container))
			{
				CacheChestRenderers();
			}
		}

		private void Start()
		{
			if ((Object)(object)_container != (Object)null && Object.op_Implicit((Object)(object)_container) && _container.GetInventory() != null)
			{
				Inventory inventory = _container.GetInventory();
				inventory.m_onChanged = (Action)Delegate.Combine(inventory.m_onChanged, new Action(OnInventoryChanged));
			}
			SyncVisualState(immediate: true);
		}

		private void OnDestroy()
		{
			if ((Object)(object)_container != (Object)null && Object.op_Implicit((Object)(object)_container) && _container.GetInventory() != null)
			{
				Inventory inventory = _container.GetInventory();
				inventory.m_onChanged = (Action)Delegate.Remove(inventory.m_onChanged, new Action(OnInventoryChanged));
			}
			if ((Object)(object)_troughVisualObj != (Object)null)
			{
				Object.Destroy((Object)(object)_troughVisualObj);
				_troughVisualObj = null;
			}
		}

		private void CacheChestRenderers()
		{
			Transform val = ((Component)this).transform.Find("New");
			if ((Object)(object)val != (Object)null)
			{
				_chestRenderers = ((Component)val).GetComponentsInChildren<Renderer>(true);
			}
			else
			{
				_chestRenderers = ((Component)this).GetComponentsInChildren<Renderer>(true);
			}
		}

		private void Update()
		{
			if (!((Object)(object)_container == (Object)null))
			{
				_syncTimer += Time.deltaTime;
				if (_syncTimer >= 1f)
				{
					_syncTimer = 0f;
					SyncVisualState();
				}
			}
		}

		public void SyncVisualState(bool immediate = false)
		{
			if (!((Object)(object)_container == (Object)null))
			{
				bool isTrough = ModConfig.ModEnabled.Value && ModConfig.EnableTroughs.Value && TroughRegistry.IsTrough(_container);
				SetVisualState(isTrough, immediate);
			}
		}

		public void SetVisualState(bool isTrough, bool force = false)
		{
			if (isTrough == _isTroughVisualActive && !force)
			{
				return;
			}
			_isTroughVisualActive = isTrough;
			if (isTrough)
			{
				EnsureTroughModelBuilt();
				if ((Object)(object)_troughVisualObj != (Object)null)
				{
					_troughVisualObj.SetActive(true);
				}
				SetChestRenderersVisible(visible: false);
				UpdateFeedFill();
			}
			else
			{
				if ((Object)(object)_troughVisualObj != (Object)null)
				{
					_troughVisualObj.SetActive(false);
				}
				SetChestRenderersVisible(visible: true);
			}
		}

		public void EnsureChestRenderersHidden()
		{
			if (_isTroughVisualActive)
			{
				SetChestRenderersVisible(visible: false);
			}
		}

		private void SetChestRenderersVisible(bool visible)
		{
			if (_chestRenderers == null || _chestRenderers.Length == 0)
			{
				CacheChestRenderers();
			}
			if (_chestRenderers == null)
			{
				return;
			}
			Renderer[] chestRenderers = _chestRenderers;
			foreach (Renderer val in chestRenderers)
			{
				if ((Object)(object)val != (Object)null && (Object)(object)((Component)val).gameObject != (Object)null && (!((Component)val).transform.IsChildOf(((Component)this).transform) || !((Object)((Component)val).gameObject).name.StartsWith("VH_")))
				{
					val.enabled = visible;
				}
			}
		}

		private void EnsureTroughModelBuilt()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: 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_0116: Expected O, but got Unknown
			//IL_014c: 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)
			if ((Object)(object)_troughVisualObj != (Object)null)
			{
				return;
			}
			_troughVisualObj = new GameObject("VH_TroughVisual");
			_troughVisualObj.transform.SetParent(((Component)this).transform, false);
			_troughVisualObj.transform.localPosition = Vector3.zero;
			_troughVisualObj.transform.localRotation = Quaternion.identity;
			Material val = null;
			Renderer[] chestRenderers = _chestRenderers;
			foreach (Renderer val2 in chestRenderers)
			{
				if ((Object)(object)val2 != (Object)null && (Object)(object)val2.sharedMaterial != (Object)null)
				{
					val = val2.sharedMaterial;
					break;
				}
			}
			GameObject val3 = new GameObject("VH_TroughFrame");
			val3.transform.SetParent(_troughVisualObj.transform, false);
			val3.transform.localPosition = Vector3.zero;
			val3.transform.localRotation = Quaternion.identity;
			val3.AddComponent<MeshFilter>().sharedMesh = TroughMeshBuilder.GetOrCreateTroughMesh();
			MeshRenderer val4 = val3.AddComponent<MeshRenderer>();
			if ((Object)(object)val != (Object)null)
			{
				((Renderer)val4).sharedMaterial = val;
			}
			_feedMoundObj = new GameObject("VH_FeedMound");
			_feedMoundObj.transform.SetParent(_troughVisualObj.transform, false);
			_feedMoundObj.transform.localPosition = new Vector3(0f, 0.22f, 0f);
			_feedMoundObj.transform.localRotation = Quaternion.identity;
			_feedMoundObj.AddComponent<MeshFilter>().sharedMesh = TroughMeshBuilder.GetOrCreateFeedMesh();
			((Renderer)_feedMoundObj.AddComponent<MeshRenderer>()).sharedMaterial = GetStrawMaterial(val);
		}

		private Material GetStrawMaterial(Material? fallbackMat)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)s_strawMaterial != (Object)null)
			{
				return s_strawMaterial;
			}
			if ((Object)(object)ZNetScene.instance != (Object)null)
			{
				GameObject prefab = ZNetScene.instance.GetPrefab("rug_straw");
				if ((Object)(object)prefab != (Object)null)
				{
					Renderer componentInChildren = prefab.GetComponentInChildren<Renderer>();
					if ((Object)(object)componentInChildren != (Object)null && (Object)(object)componentInChildren.sharedMaterial != (Object)null)
					{
						s_strawMaterial = componentInChildren.sharedMaterial;
						return s_strawMaterial;
					}
				}
			}
			return (Material)(((object)fallbackMat) ?? ((object)new Material(Shader.Find("Standard"))));
		}

		private void OnInventoryChanged()
		{
			if (_isTroughVisualActive)
			{
				UpdateFeedFill();
			}
		}

		public void UpdateFeedFill()
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_feedMoundObj == (Object)null) && !((Object)(object)_container == (Object)null))
			{
				int num = TroughRegistry.CountAcceptableFood(_container, null);
				if (num <= 0)
				{
					_feedMoundObj.SetActive(false);
					return;
				}
				_feedMoundObj.SetActive(true);
				float num2 = Mathf.Clamp01((float)num / 30f);
				float num3 = Mathf.Lerp(0.2f, 0.44f, num2);
				_feedMoundObj.transform.localPosition = new Vector3(0f, num3, 0f);
			}
		}
	}
}
namespace VikingHusbandry.Features.Rodeo
{
	public static class DownedRagdollManager
	{
		private class DownedState
		{
			public GameObject RagdollObj;

			public Vector3 OriginalColCenter;

			public float OriginalColHeight;

			public float OriginalColRadius;

			public int OriginalColDirection;

			public RigidbodyConstraints OriginalConstraints;
		}

		private static readonly Dictionary<Character, DownedState> s_activeStates = new Dictionary<Character, DownedState>();

		public static bool HasRagdoll(Character character)
		{
			if ((Object)(object)character == (Object)null)
			{
				return false;
			}
			if (s_activeStates.TryGetValue(character, out DownedState value))
			{
				return (Object)(object)value.RagdollObj != (Object)null;
			}
			return false;
		}

		public static void CreateDownedRagdoll(Character character)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)character == (Object)null || !Object.op_Implicit((Object)(object)character) || HasRagdoll(character))
			{
				return;
			}
			GameObject val = FindRagdollPrefab(character);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			GameObject val2 = Object.Instantiate<GameObject>(val, ((Component)character).transform.position, ((Component)character).transform.rotation);
			val2.transform.localScale = ((Component)character).transform.localScale;
			Rigidbody[] componentsInChildren = val2.GetComponentsInChildren<Rigidbody>();
			foreach (Rigidbody val3 in componentsInChildren)
			{
				if ((Object)(object)val3 != (Object)null && !val3.isKinematic)
				{
					val3.linearVelocity = Vector3.zero;
					val3.angularVelocity = Vector3.zero;
				}
			}
			Ragdoll component = val2.GetComponent<Ragdoll>();
			if ((Object)(object)component != (Object)null)
			{
				((MonoBehaviour)component).CancelInvoke();
				Object.Destroy((Object)(object)component);
			}
			ZNetView component2 = val2.GetComponent<ZNetView>();
			if ((Object)(object)component2 != (Object)null)
			{
				Object.Destroy((Object)(object)component2);
			}
			Collider collider = (Collider)(object)character.GetCollider();
			if ((Object)(object)collider != (Object)null)
			{
				Collider[] componentsInChildren2 = val2.GetComponentsInChildren<Collider>();
				foreach (Collider val4 in componentsInChildren2)
				{
					if ((Object)(object)val4 != (Object)null)
					{
						Physics.IgnoreCollision(collider, val4, true);
					}
				}
			}
			CapsuleCollider collider2 = character.GetCollider();
			Rigidbody component3 = ((Component)character).GetComponent<Rigidbody>();
			DownedState value = new DownedState
			{
				RagdollObj = val2,
				OriginalColCenter = (((Object)(object)collider2 != (Object)null) ? collider2.center : Vector3.zero),
				OriginalColHeight = (((Object)(object)collider2 != (Object)null) ? collider2.height : 0.8f),
				OriginalColRadius = (((Object)(object)collider2 != (Object)null) ? collider2.radius : 0.4f),
				OriginalColDirection = ((!((Object)(object)collider2 != (Object)null)) ? 1 : collider2.direction),
				OriginalConstraints = (RigidbodyConstraints)(((Object)(object)component3 != (Object)null) ? ((int)component3.constraints) : 0)
			};
			if ((Object)(object)collider2 != (Object)null)
			{
				collider2.direction = 2;
				collider2.center = new Vector3(0f, 0.22f, 0f);
				collider2.height = 1f;
				collider2.radius = 0.35f;
			}
			if ((Object)(object)component3 != (Object)null)
			{
				if (!component3.isKinematic)
				{
					component3.linearVelocity = Vector3.zero;
					component3.angularVelocity = Vector3.zero;
				}
				component3.constraints = (RigidbodyConstraints)126;
			}
			if ((Object)(object)Player.m_localPlayer != (Object)null && (Object)(object)((Character)Player.m_localPlayer).GetCollider() != (Object)null && (Object)(object)collider != (Object)null)
			{
				Physics.IgnoreCollision((Collider)(object)((Character)Player.m_localPlayer).GetCollider(), collider, true);
			}
			LevelEffects componentInChildren = ((Component)character).GetComponentInChildren<LevelEffects>();
			LevelEffects componentInChildren2 = val2.GetComponentInChildren<LevelEffects>();
			if ((Object)(object)componentInChildren != (Object)null && (Object)(object)componentInChildren2 != (Object)null)
			{
				float num = default(float);
				float num2 = default(float);
				float num3 = default(float);
				componentInChildren.GetColorChanges(ref num, ref num2, ref num3);
				if ((Object)(object)componentInChildren2.m_mainRender != (Object)null && (Object)(object)componentInChildren2.m_mainRender.material != (Object)null)
				{
					componentInChildren2.m_mainRender.material.SetFloat("_Hue", num);
					componentInChildren2.m_mainRender.material.SetFloat("_Saturation", num2);
					componentInChildren2.m_mainRender.material.SetFloat("_Value", num3);
				}
			}
			Transform val5 = ((Component)character).transform.Find("Visual");
			if ((Object)(object)val5 != (Object)null)
			{
				((Component)val5).gameObject.SetActive(false);
			}
			val2.AddComponent<DownedRagdollController>().Setup(character);
			s_activeStates[character] = value;
		}

		public static void RemoveDownedRagdoll(Character character)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)character == (Object)null)
			{
				return;
			}
			if (s_activeStates.TryGetValue(character, out DownedState value))
			{
				if ((Object)(object)value.RagdollObj != (Object)null)
				{
					((Component)character).transform.position = value.RagdollObj.transform.position;
					Object.Destroy((Object)(object)value.RagdollObj);
				}
				CapsuleCollider collider = character.GetCollider();
				if ((Object)(object)collider != (Object)null)
				{
					collider.direction = value.OriginalColDirection;
					collider.center = value.OriginalColCenter;
					collider.height = value.OriginalColHeight;
					collider.radius = value.OriginalColRadius;
				}
				Rigidbody component = ((Component)character).GetComponent<Rigidbody>();
				if ((Object)(object)component != (Object)null)
				{
					component.constraints = value.OriginalConstraints;
				}
				Collider collider2 = (Collider)(object)character.GetCollider();
				if ((Object)(object)Player.m_localPlayer != (Object)null && (Object)(object)((Character)Player.m_localPlayer).GetCollider() != (Object)null && (Object)(object)collider2 != (Object)null)
				{
					Physics.IgnoreCollision((Collider)(object)((Character)Player.m_localPlayer).GetCollider(), collider2, false);
				}
				s_activeStates.Remove(character);
			}
			if (Object.op_Implicit((Object)(object)character))
			{
				Transform val = ((Component)character).transform.Find("Visual");
				if ((Object)(object)val != (Object)null)
				{
					((Component)val).gameObject.SetActive(true);
				}
			}
		}

		private static GameObject? FindRagdollPrefab(Character character)
		{
			if (character.m_deathEffects != null && character.m_deathEffects.m_effectPrefabs != null)
			{
				EffectData[] effectPrefabs = character.m_deathEffects.m_effectPrefabs;
				foreach (EffectData val in effectPrefabs)
				{
					if ((Object)(object)val.m_prefab != (Object)null && (Object)(object)val.m_prefab.GetComponent<Ragdoll>() != (Object)null)
					{
						return val.m_prefab;
					}
				}
			}
			string text = ((Object)character).name.Replace("(Clone)", "").Trim();
			if ((Object)(object)ZNetScene.instance != (Object)null)
			{
				GameObject prefab = ZNetScene.instance.GetPrefab(text + "_ragdoll");
				if ((Object)(object)prefab != (Object)null)
				{
					return prefab;
				}
			}
			return null;
		}
	}
	public class DownedRagdollController : MonoBehaviour
	{
		private Character? _character;

		private Transform? _pelvis;

		private Rigidbody[]? _bodies;

		private float _timer;

		private bool _frozen;

		public void Setup(Character character)
		{
			_character = character;
			_pelvis = Utils.FindChild(((Component)this).transform, "Pelvis", (IterativeSearchType)0);
			_bodies = ((Component)this).GetComponentsInChildren<Rigidbody>();
		}

		private void Update()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_character != (Object)null && Object.op_Implicit((Object)(object)_character))
			{
				Vector3 position = (((Object)(object)_pelvis != (Object)null) ? _pelvis.position : ((Component)this).transform.position);
				((Component)_character).transform.position = position;
			}
			if (_frozen)
			{
				return;
			}
			_timer += Time.deltaTime;
			if (!(_timer >= 0.8f))
			{
				return;
			}
			_frozen = true;
			if (_bodies == null)
			{
				return;
			}
			Rigidbody[] bodies = _bodies;
			foreach (Rigidbody val in bodies)
			{
				if ((Object)(object)val != (Object)null)
				{
					val.isKinematic = true;
				}
			}
		}
	}
	public static class DownedTamingManager
	{
		private static readonly int s_downedUntilHash = StringExtensionMethods.GetStableHashCode("VH_DownedUntil");

		private static readonly int s_subdualProgressHash = StringExtensionMethods.GetStableHashCode("VH_Subdual");

		private static readonly int s_sleepingAnimHash = StringExtensionMethods.GetStableHashCode("sleeping");

		private static readonly FieldRef<Character, ZNetView>? s_charNViewRef = AccessTools.FieldRefAccess<Character, ZNetView>("m_nview");

		private static ZNetView? GetNView(Character character)
		{
			if ((Object)(object)character == (Object)null || !Object.op_Implicit((Object)(object)character))
			{
				return null;
			}
			if (s_charNViewRef != null)
			{
				ZNetView val = s_charNViewRef.Invoke(character);
				if ((Object)(object)val != (Object)null && Object.op_Implicit((Object)(object)val))
				{
					return val;
				}
			}
			return ((Component)character).GetComponent<ZNetView>();
		}

		public static float GetSubdualProgress(Character character)
		{
			if ((Object)(object)character == (Object)null || !Object.op_Implicit((Object)(object)character))
			{
				return 0f;
			}
			CheckDownedRecovery(character);
			ZNetView nView = GetNView(character);
			if ((Object)(object)nView == (Object)null || !nView.IsValid())
			{
				return 0f;
			}
			return nView.GetZDO().GetFloat(s_subdualProgressHash, 0f);
		}

		public static void SetSubdualProgress(Character character, float progress)
		{
			if (!((Object)(object)character == (Object)null) && Object.op_Implicit((Object)(object)character))
			{
				ZNetView nView = GetNView(character);
				if (!((Object)(object)nView == (Object)null) && nView.IsValid())
				{
					nView.GetZDO().Set(s_subdualProgressHash, Mathf.Clamp01(progress));
				}
			}
		}

		public static bool IsDowned(Character character)
		{
			CheckDownedRecovery(character);
			return GetDownedSecondsRemaining(character) > 0f;
		}

		public static float GetDownedSecondsRemaining(Character character)
		{
			if ((Object)(object)character == (Object)null || !Object.op_Implicit((Object)(object)character) || (Object)(object)ZNet.instance == (Object)null)
			{
				return 0f;
			}
			CheckDownedRecovery(character);
			ZNetView nView = GetNView(character);
			if ((Object)(object)nView == (Object)null || !nView.IsValid())
			{
				return 0f;
			}
			long num = nView.GetZDO().GetLong(s_downedUntilHash, 0L);
			if (num == 0L)
			{
				return 0f;
			}
			return Mathf.Max(0f, (float)(new DateTime(num) - ZNet.instance.GetTime()).TotalSeconds);
		}

		public static void SetDowned(Character character, float durationSeconds)
		{
			if (!((Object)(object)character == (Object)null) && Object.op_Implicit((Object)(object)character) && !((Object)(object)ZNet.instance == (Object)null))
			{
				ZNetView nView = GetNView(character);
				if (!((Object)(object)nView == (Object)null) && nView.IsValid())
				{
					DateTime dateTime = ZNet.instance.GetTime().AddSeconds(durationSeconds);
					nView.GetZDO().Set(s_downedUntilHash, dateTime.Ticks);
					nView.GetZDO().Set(ZDOVars.s_sleeping, true);
					DownedRagdollManager.CreateDownedRagdoll(character);
				}
			}
		}

		public static void CheckDownedRecovery(Character character)
		{
			if ((Object)(object)character == (Object)null || !Object.op_Implicit((Object)(object)character) || (Object)(object)ZNet.instance == (Object)null)
			{
				return;
			}
			ZNetView nView = GetNView(character);
			if ((Object)(object)nView == (Object)null || !nView.IsValid())
			{
				return;
			}
			long num = nView.GetZDO().GetLong(s_downedUntilHash, 0L);
			if (num != 0L && ZNet.instance.GetTime().Ticks >= num)
			{
				nView.GetZDO().Set(s_downedUntilHash, 0L);
				nView.GetZDO().Set(s_subdualProgressHash, 0f);
				nView.GetZDO().Set(ZDOVars.s_sleeping, false);
				DownedRagdollManager.RemoveDownedRagdoll(character);
				ZSyncAnimation zAnim = character.GetZAnim();
				if ((Object)(object)zAnim != (Object)null)
				{
					zAnim.SetTrigger("stagger");
				}
			}
		}

		public static void ClearDowned(Character character)
		{
			if (!((Object)(object)character == (Object)null) && Object.op_Implicit((Object)(object)character))
			{
				ZNetView nView = GetNView(character);
				if (!((Object)(object)nView == (Object)null) && nView.IsValid())
				{
					nView.GetZDO().Set(s_downedUntilHash, 0L);
					nView.GetZDO().Set(s_subdualProgressHash, 0f);
					nView.GetZDO().Set(ZDOVars.s_sleeping, false);
					DownedRagdollManager.RemoveDownedRagdoll(character);
				}
			}
		}

		public static bool CanBeSubdued(Character character)
		{
			if ((Object)(object)character == (Object)null || !Object.op_Implicit((Object)(object)character) || character.IsTamed())
			{
				return false;
			}
			CheckDownedRecovery(character);
			if (IsDowned(character))
			{
				return false;
			}
			if (character.IsStaggering())
			{
				return true;
			}
			BaseAI baseAI = character.GetBaseAI();
			if ((Object)(object)baseAI != (Object)null && !baseAI.IsAlerted())
			{
				return true;
			}
			return false;
		}

		public static bool TryForceFeed(Humanoid user, ItemData item, Tameable tameable, MonsterAI monsterAI)
		{
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: 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_013f: 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)
			if ((Object)(object)user == (Object)null || item == null || (Object)(object)tameable == (Object)null || (Object)(object)monsterAI == (Object)null)
			{
				return false;
			}
			Character component = ((Component)tameable).GetComponent<Character>();
			if ((Object)(object)component == (Object)null || !Object.op_Implicit((Object)(object)component) || !IsDowned(component))
			{
				return false;
			}
			if (!IsAcceptableFood(monsterAI, item))
			{
				((Character)user).Message((MessageType)1, "Food refused.", 0, (Sprite)null, false);
				return false;
			}
			float remainingTime = AIHelper.GetRemainingTime(tameable);
			float num = ((tameable.m_fedDuration > 0f) ? tameable.m_fedDuration : 300f);
			int num2 = Mathf.Max(1, Mathf.CeilToInt(remainingTime / num));
			int stack = item.m_stack;
			int num3 = Mathf.Min(num2, stack);
			user.GetInventory().RemoveItem(item, num3);
			float time = (float)num3 * num;
			AIHelper.DecreaseRemainingTime(tameable, time);
			if (tameable.m_sootheEffect != null)
			{
				tameable.m_sootheEffect.Create(component.GetCenterPoint(), Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID));
			}
			if (AIHelper.GetRemainingTime(tameable) <= 0f)
			{
				AIHelper.Tame(tameable, monsterAI);
				ClearDowned(component);
				((Character)user).Message((MessageType)1, component.GetHoverName() + " tamed!", 0, (Sprite)null, false);
				if (tameable.m_tamedEffect != null)
				{
					tameable.m_tamedEffect.Create(component.GetCenterPoint(), Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID));
				}
			}
			else
			{
				int num4 = Mathf.RoundToInt((1f - AIHelper.GetRemainingTime(tameable) / tameable.m_tamingTime) * 100f);
				((Character)user).Message((MessageType)1, $"Tamed {num4}%", 0, (Sprite)null, false);
			}
			return true;
		}

		public static bool IsAcceptableFood(MonsterAI monsterAI, ItemData item)
		{
			if ((Object)(object)monsterAI == (Object)null || monsterAI.m_consumeItems == null || item == null)
			{
				return false;
			}
			foreach (ItemDrop consumeItem in monsterAI.m_consumeItems)
			{
				if ((Object)(object)consumeItem != (Object)null && consumeItem.m_itemData != null && consumeItem.m_itemData.m_shared.m_name == item.m_shared.m_name)
				{
					return true;
				}
			}
			return false;
		}
	}
	public class RodeoController : MonoBehaviour
	{
		private Player? _player;

		private Character? _beast;

		private MonsterAI? _beastAI;

		private GameObject? _tempMountPoint;

		private GameObject? _lineObj;

		private bool _isTetherMode;

		private float _rodeoTimer;

		private float _thrashTimer;

		private float _lastProgressUpdateTimer;

		private int _lastPercentShown = -1;

		private Vector3 _baseLocalPos;

		private float _basePitch;

		private float _buckImpulse;

		public static RodeoController? Instance { get; private set; }

		public bool IsRodeoActive
		{
			get
			{
				if ((Object)(object)_player != (Object)null)
				{
					return (Object)(object)_beast != (Object)null;
				}
				return false;
			}
		}

		public Player? ActivePlayer => _player;

		public static bool IsBeastInTether(Character character)
		{
			if ((Object)(object)Instance != (Object)null && Instance.IsRodeoActive && Instance._isTetherMode)
			{
				return (Object)(object)Instance._beast == (Object)(object)character;
			}
			return false;
		}

		public static bool IsBeastMounted(Character character)
		{
			if ((Object)(object)Instance != (Object)null && Instance.IsRodeoActive && !Instance._isTetherMode)
			{
				return (Object)(object)Instance._beast == (Object)(object)character;
			}
			return false;
		}

		private void Awake()
		{
			Instance = this;
		}

		public static void StartRodeo(Player player, Character beast)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			if (!((Object)(object)player == (Object)null) && !((Object)(object)beast == (Object)null))
			{
				if ((Object)(object)Instance == (Object)null)
				{
					GameObject val = new GameObject("VH_RodeoHost");
					Object.DontDestroyOnLoad((Object)val);
					val.AddComponent<RodeoController>();
				}
				Instance.Begin(player, beast);
			}
		}

		public void Begin(Player player, Character beast)
		{
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Expected O, but got Unknown
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0312: 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)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			_player = player;
			_beast = beast;
			_beastAI = ((Component)beast).GetComponent<MonsterAI>();
			_rodeoTimer = 0f;
			_thrashTimer = 0f;
			_lastProgressUpdateTimer = 0f;
			_lastPercentShown = -1;
			_buckImpulse = 0f;
			if ((Object)(object)_tempMountPoint != (Object)null)
			{
				Object.Destroy((Object)(object)_tempMountPoint);
				_tempMountPoint = null;
			}
			if ((Object)(object)_lineObj != (Object)null)
			{
				if ((Object)(object)ZNetScene.instance != (Object)null)
				{
					ZNetScene.instance.Destroy(_lineObj);
				}
				else
				{
					Object.Destroy((Object)(object)_lineObj);
				}
				_lineObj = null;
			}
			bool isTetherMode = ((Object)beast).name.StartsWith("Boar") || (beast.m_name != null && beast.m_name.ToLower().Contains("boar"));
			_isTetherMode = isTetherMode;
			if (_isTetherMode)
			{
				((Humanoid)player).HideHandItems(true, false);
				if ((Object)(object)_beastAI != (Object)null)
				{
					((BaseAI)_beastAI).Alert();
				}
				GameObject val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.GetPrefab("vfx_Harpooned") : null);
				if ((Object)(object)val != (Object)null)
				{
					_lineObj = Object.Instantiate<GameObject>(val, ((Component)beast).transform.position, Quaternion.identity);
					LineRenderer[] componentsInChildren = _lineObj.GetComponentsInChildren<LineRenderer>();
					foreach (LineRenderer val2 in componentsInChildren)
					{
						if ((Object)(object)val2 != (Object)null)
						{
							val2.positionCount = 2;
						}
					}
					LineConnect component = _lineObj.GetComponent<LineConnect>();
					if ((Object)(object)component != (Object)null)
					{
						component.SetPeer(((Component)player).GetComponent<ZNetView>());
						component.m_dynamicSlack = false;
						component.SetSlack(0.01f);
						component.m_minThickness = 0.04f;
						component.m_maxThickness = 0.05f;
					}
				}
				((Character)player).Message((MessageType)1, "Leashed! Hold the line...", 0, (Sprite)null, false);
			}
			else
			{
				_tempMountPoint = new GameObject("VH_MountPoint");
				_tempMountPoint.transform.SetParent(((Component)beast).transform);
				string text = (((Object)beast).name.Contains("Lox") ? "attach_lox" : (((Object)beast).name.Contains("Asksvin") ? "attach_asksvin" : "attach_chair"));
				_basePitch = 0f;
				float num = 0.7f;
				float num2 = -0.1f;
				CapsuleCollider collider = beast.GetCollider();
				if ((Object)(object)collider != (Object)null)
				{
					num = Mathf.Max(0.55f, collider.height * 0.65f);
					num2 = -0.15f;
				}
				_baseLocalPos = new Vector3(0f, num, num2);
				_tempMountPoint.transform.localPosition = _baseLocalPos;
				_tempMountPoint.transform.localRotation = Quaternion.identity;
				Vector3 val3 = default(Vector3);
				((Vector3)(ref val3))..ctor(0f, 0.5f, -1.5f);
				((Character)player).Message((MessageType)1, "Mounted! Hold on...", 0, (Sprite)null, false);
				((Character)player).AttachStart(_tempMountPoint.transform, ((Component)beast).gameObject, true, false, false, text, val3, (Transform)null);
			}
		}

		private void Update()
		{
			//IL_058b: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: 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_064f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0654: Unknown result type (might be due to invalid IL or missing references)
			//IL_0659: Unknown result type (might be due to invalid IL or missing references)
			//IL_0666: Unknown result type (might be due to invalid IL or missing references)
			//IL_066b: Unknown result type (might be due to invalid IL or missing references)
			//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_067c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0685: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: 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_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: 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)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0368: 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_03db: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0409: Unknown result type (might be due to invalid IL or missing references)
			//IL_040e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0417: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
			if (!IsRodeoActive || (Object)(object)_player == (Object)null || (Object)(object)_beast == (Object)null)
			{
				return;
			}
			if (((Character)_player).IsDead() || _beast.IsDead())
			{
				EndRodeo(bucked: false, released: false);
				return;
			}
			float deltaTime = Time.deltaTime;
			_rodeoTimer += deltaTime;
			float subdualProgress = DownedTamingManager.GetSubdualProgress(_beast);
			subdualProgress += deltaTime / Mathf.Max(1f, ModConfig.RodeoDuration.Value);
			DownedTamingManager.SetSubdualProgress(_beast, subdualProgress);
			_lastProgressUpdateTimer += deltaTime;
			int num = Mathf.Clamp(Mathf.RoundToInt(subdualProgress * 100f), 0, 100);
			if (_lastProgressUpdateTimer >= 0.5f || (num % 10 == 0 && num != _lastPercentShown))
			{
				_lastProgressUpdateTimer = 0f;
				_lastPercentShown = num;
				((Character)_player).Message((MessageType)1, $"Subduing {num}% (Space: Release)", 0, (Sprite)null, false);
			}
			if (_isTetherMode)
			{
				if ((Object)(object)_lineObj != (Object)null)
				{
					_lineObj.transform.position = _beast.GetCenterPoint();
					LineRenderer[] componentsInChildren = _lineObj.GetComponentsInChildren<LineRenderer>();
					foreach (LineRenderer val in componentsInChildren)
					{
						if ((Object)(object)val != (Object)null && val.positionCount != 2)
						{
							val.positionCount = 2;
						}
					}
					LineConnect component = _lineObj.GetComponent<LineConnect>();
					if ((Object)(object)component != (Object)null)
					{
						component.m_dynamicSlack = false;
						component.SetSlack(0.01f);
					}
				}
				float num2 = Vector3.Distance(((Component)_player).transform.position, ((Component)_beast).transform.position);
				Vector3 val2 = ((Component)_player).transform.position - ((Component)_beast).transform.position;
				val2.y = 0f;
				float magnitude = ((Vector3)(ref val2)).magnitude;
				val2 = ((!(magnitude < 0.1f)) ? (val2 / magnitude) : (-((Component)_beast).transform.forward));
				Vector3 val3 = -val2;
				Vector3 moveDir = ((Character)_player).GetMoveDir();
				float num3 = 0f;
				if (((Vector3)(ref moveDir)).sqrMagnitude > 0.01f)
				{
					num3 = Mathf.Clamp01(Vector3.Dot(((Vector3)(ref moveDir)).normalized, val2));
				}
				if ((Object)(object)_beastAI != (Object)null)
				{
					float num4 = Mathf.Sin(_rodeoTimer * 3f) * 35f;
					Vector3 val4 = Quaternion.Euler(0f, num4, 0f) * val3;
					float num5 = Mathf.Lerp(4.5f, 2f, num3);
					Vector3 point = ((Component)_beast).transform.position + val4 * num5;
					((BaseAI)_beastAI).StopMoving();
					AIHelper.MoveTo((BaseAI)(object)_beastAI, deltaTime, point, 0.5f, run: true);
					_beast.SetRun(true);
				}
				if (num2 > 3.6f)
				{
					float num6 = Mathf.Clamp01((num2 - 3.6f) / 1.4000001f);
					float num7 = Mathf.Lerp(7f, 14f, num6);
					Rigidbody component2 = ((Component)_player).GetComponent<Rigidbody>();
					if ((Object)(object)component2 != (Object)null && !component2.isKinematic)
					{
						component2.AddForce(val3 * num7, (ForceMode)5);
					}
					float num8 = Mathf.Lerp(4f, 9.5f, num3) * Mathf.Max(0.4f, num6);
					Rigidbody component3 = ((Component)_beast).GetComponent<Rigidbody>();
					if ((Object)(object)component3 != (Object)null && !component3.isKinematic)
					{
						component3.AddForce(val2 * num8, (ForceMode)5);
					}
					if (num2 > 5f)
					{
						Vector3 val5 = ((Component)_beast).transform.position + val2 * 5f;
						((Component)_player).transform.position = Vector3.Lerp(((Component)_player).transform.position, val5, deltaTime * 8f);
					}
					float num9 = ModConfig.RodeoStaminaDrain.Value * (1f + num3 * 0.4f);
					((Character)_player).UseStamina(num9 * deltaTime);
				}
				if (subdualProgress >= 1f)
				{
					((Character)_player).Message((MessageType)1, "Exhausted! Feed to tame.", 0, (Sprite)null, false);
					DownedTamingManager.SetSubdualProgress(_beast, 1f);
					DownedTamingManager.SetDowned(_beast, ModConfig.DownedDuration.Value);
					EndRodeo(bucked: false, released: false);
				}
				else if (_rodeoTimer > 0.5f)
				{
					if (_player.GetStamina() <= 1f)
					{
						EndRodeo(bucked: true, released: false);
					}
					else if (ZInput.GetButtonDown("Jump"))
					{
						EndRodeo(bucked: false, released: true);
					}
				}
				return;
			}
			float num10 = ModConfig.RodeoStaminaDrain.Value * deltaTime;
			((Character)_player).UseStamina(num10);
			_buckImpulse = Mathf.Lerp(_buckImpulse, 0f, deltaTime * 5f);
			float num11 = Mathf.Sin(_rodeoTimer * 12f) * 4f + _buckImpulse;
			float num12 = Mathf.Cos(_rodeoTimer * 10f) * 6f;
			float num13 = Mathf.Sin(_rodeoTimer * 8f) * 4f;
			if ((Object)(object)_tempMountPoint != (Object)null)
			{
				_tempMountPoint.transform.localRotation = Quaternion.Euler(_basePitch - num11, num13, num12);
				_tempMountPoint.transform.localPosition = _baseLocalPos + new Vector3(Mathf.Sin(_rodeoTimer * 10f) * 0.015f, Mathf.Abs(Mathf.Sin(_rodeoTimer * 16f)) * 0.02f, (0f - _buckImpulse / 25f) * 0.04f);
			}
			_thrashTimer += deltaTime;
			if ((Object)(object)_beastAI != (Object)null)
			{
				float num14 = Mathf.Sin(_rodeoTimer * 3.5f) * 35f;
				Vector3 val6 = Quaternion.Euler(0f, num14, 0f) * ((Component)_beast).transform.forward;
				Vector3 point2 = ((Component)_beast).transform.position + val6 * 4f;
				AIHelper.MoveTo((BaseAI)(object)_beastAI, deltaTime, point2, 1f, run: true);
				if (_thrashTimer >= 2.2f)
				{
					_thrashTimer = 0f;
					_buckImpulse = 24f;
					ZSyncAnimation zAnim = _beast.GetZAnim();
					if ((Object)(object)zAnim != (Object)null)
					{
						zAnim.SetTrigger("attack");
					}
				}
			}
			if (subdualProgress >= 1f)
			{
				((Character)_player).Message((MessageType)1, "Subdued! Feed to tame.", 0, (Sprite)null, false);
				DownedTamingManager.SetSubdualProgress(_beast, 1f);
				DownedTamingManager.SetDowned(_beast, ModConfig.DownedDuration.Value);
				EndRodeo(bucked: false, released: false);
			}
			else if (_rodeoTimer > 0.5f && (_player.GetStamina() <= 1f || ZInput.GetButtonDown("Jump")))
			{
				EndRodeo(bucked: true, released: false);
			}
		}

		public void EndRodeo(bool bucked, bool released)
		{
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing