Decompiled source of LeadAHorseToWater v0.8.0

LeadAHorseToWater.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using LeadAHorseToWater.Compat;
using LeadAHorseToWater.Processes;
using LeadAHorseToWater.VCFCompat;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.CastleBuilding;
using ProjectM.Network;
using SemanticVersioning;
using Stunlock.Core;
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;
using VampireCommandFramework;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("LeadAHorseToWater")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Lead a horse to a well to make it drink.")]
[assembly: AssemblyFileVersion("0.8.0.0")]
[assembly: AssemblyInformationalVersion("0.8.0+7.Branch.main.Sha.3a4f86d79ddaf80b1994addd34afd69104ed7425")]
[assembly: AssemblyProduct("LeadAHorseToWater")]
[assembly: AssemblyTitle("LeadAHorseToWater")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.8.0.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;
		}
	}
}
internal static class ECSExtensions
{
	internal static void With<T>(this Entity entity, VExtensions.ActionRef<T> action) where T : struct
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		T item = entity.RW<T>();
		action(ref item);
		EntityManager entityManager = VWorld.Game.EntityManager;
		((EntityManager)(ref entityManager)).SetComponentData<T>(entity, item);
	}

	internal static bool Has<T>(this Entity entity) where T : struct
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: 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_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		int num = TypeIndex.op_Implicit(TypeManager.GetTypeIndex(Il2CppType.Of<T>()));
		EntityManager entityManager = VWorld.Game.EntityManager;
		return ((EntityManager)(ref entityManager)).HasComponentRaw(entity, TypeIndex.op_Implicit(num));
	}

	internal unsafe static T RW<T>(this Entity entity) where T : struct
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: 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_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		int num = TypeIndex.op_Implicit(TypeManager.GetTypeIndex(Il2CppType.Of<T>()));
		EntityManager entityManager = VWorld.Game.EntityManager;
		T* componentDataRawRW = (T*)((EntityManager)(ref entityManager)).GetComponentDataRawRW(entity, TypeIndex.op_Implicit(num));
		if (componentDataRawRW == null)
		{
			throw new InvalidOperationException($"Failure to access ReadWrite <{typeof(T).Name}> typeIndex({num}) on entity({entity}).");
		}
		return *componentDataRawRW;
	}

	internal unsafe static T Read<T>(this Entity entity) where T : struct
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: 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_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		int num = TypeIndex.op_Implicit(TypeManager.GetTypeIndex(Il2CppType.Of<T>()));
		EntityManager entityManager = VWorld.Game.EntityManager;
		T* componentDataRawRO = (T*)((EntityManager)(ref entityManager)).GetComponentDataRawRO(entity, TypeIndex.op_Implicit(num));
		if (componentDataRawRO == null)
		{
			throw new InvalidOperationException($"Failure to access ReadOnly <{typeof(T).Name}> typeIndex({num}) on entity({entity}).");
		}
		return *componentDataRawRO;
	}
}
namespace LeadAHorseToWater
{
	[BepInPlugin("LeadAHorseToWater", "LeadAHorseToWater", "0.8.0")]
	[BepInProcess("VRisingServer.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		private Harmony _harmony;

		public static ManualLogSource LogInstance { get; private set; }

		public override void Load()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			LogInstance = ((BasePlugin)this).Log;
			Settings.Initialize(((BasePlugin)this).Config);
			_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(42, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("LeadAHorseToWater");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded! (Bloodstone-free build)");
			}
			log.LogInfo(val);
			((BasePlugin)this).Log.LogInfo((object)"Trying to find VCF:");
			if (Commands.Enabled)
			{
				Commands.Register();
			}
			else
			{
				((BasePlugin)this).Log.LogError((object)"This mod has commands, you need to install VampireCommandFramework to use them, find whereever you get mods or : https://a.deca.gg/vcf .");
			}
		}

		public override bool Unload()
		{
			if (Commands.Enabled)
			{
				Commands.Unregister();
			}
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			return true;
		}
	}
	public static class Settings
	{
		public static ConfigEntry<float> DISTANCE_REQUIRED;

		public static ConfigEntry<int> SECONDS_DRINK_PER_TICK;

		public static ConfigEntry<int> MAX_DRINK_AMOUNT;

		public static ConfigEntry<bool> ENABLE_RENAME;

		public static ConfigEntry<string> ENABLED_WELL_PREFAB;

		public static HashSet<int> EnabledWellPrefabs = new HashSet<int>();

		private static Dictionary<string, int> _fountains = new Dictionary<string, int>
		{
			{ "stone", 986517450 },
			{ "iron", 1247163010 },
			{ "bronze", -1790149989 },
			{ "small", 549920910 },
			{ "large", 177891172 }
		};

		private static ManualLogSource log => Plugin.LogInstance;

		public static ConfigEntry<int> HORSE_BREED_PREFAB { get; private set; }

		public static ConfigEntry<string> HORSE_BREED_ITEM_NAME { get; private set; }

		public static ConfigEntry<int> HORSE_BREED_COST { get; private set; }

		public static ConfigEntry<float> HORSE_BREED_MUTATION_RANGE { get; private set; }

		public static ConfigEntry<float> HORSE_BREED_MAX_SPEED { get; private set; }

		public static ConfigEntry<float> HORSE_BREED_MAX_ROTATION { get; private set; }

		public static ConfigEntry<float> HORSE_BREED_MAX_ACCELERATION { get; private set; }

		internal static void Initialize(ConfigFile config)
		{
			DISTANCE_REQUIRED = config.Bind<float>("Server", "DistanceRequired", 5f, "Horses must be within this distance from well. (5 =1 tile)");
			SECONDS_DRINK_PER_TICK = config.Bind<int>("Server", "SecondsDrinkPerTick", 30, "How many seconds added per drink tick (~1.5seconds), default values would be about 24 minutes for the default max amount at fountain.");
			MAX_DRINK_AMOUNT = config.Bind<int>("Server", "MaxDrinkAmount", 28800, "Time in seconds, default value is roughly amount of time when you take wild horses.");
			ENABLE_RENAME = config.Bind<bool>("Server", "EnableRename", true, "If true will rename horses in drinking range with a symbol");
			ENABLED_WELL_PREFAB = config.Bind<string>("Server", "EnabledWellPrefabs", "Stone, Large", "This is a comma seperated list of prefabs to use for the well. You can choose from one of (stone, iron, bronze, small, big) or (advanced: at your own risk) you can also include an arbitrary guid hash of of a castle connected placeable.");
			HORSE_BREED_PREFAB = config.Bind<int>("Breeding", "BreedingRequiredItem", -570287766, "This prefab is consumed as a cost to breed horses.");
			HORSE_BREED_ITEM_NAME = config.Bind<string>("Breeding", "BreedingCostItemName", "special fish (twilight snapper)", "This is the name of the required item that will be consumed.");
			HORSE_BREED_COST = config.Bind<int>("Breeding", "BreedingCostAmount", 1, "This is the amount of the required item consumed.");
			HORSE_BREED_MUTATION_RANGE = config.Bind<float>("Breeding", "MutationRange", 0.05f, "This is the half range +/- this value for applied for mutation.");
			HORSE_BREED_MAX_SPEED = config.Bind<float>("Breeding", "MaxSpeed", 14f, "The absolute maximum speed for horses including selective breeding and mutations.");
			HORSE_BREED_MAX_ROTATION = config.Bind<float>("Breeding", "MaxRotation", 16f, "The absolute maximum rotation for horses including selective breeding and mutations.");
			HORSE_BREED_MAX_ACCELERATION = config.Bind<float>("Breeding", "MaxAcceleration", 9f, "The absolute maximum acceleration for horses including selective breeding and mutations.");
			ENABLED_WELL_PREFAB.SettingChanged += delegate
			{
				ParseEnabledWells();
			};
			ParseEnabledWells();
		}

		private static void ParseEnabledWells()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Expected O, but got Unknown
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Expected O, but got Unknown
			EnabledWellPrefabs.Clear();
			string value = ENABLED_WELL_PREFAB.Value;
			string[] array = value.Split(",", StringSplitOptions.RemoveEmptyEntries);
			ManualLogSource obj = log;
			bool flag = default(bool);
			BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(29, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Parsing ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(value);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is value ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string[]>(array);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" are values");
			}
			obj.LogDebug(val);
			string[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				string text = array2[i].Trim().ToLowerInvariant();
				int value2;
				if (int.TryParse(text, out var result))
				{
					EnabledWellPrefabs.Add(result);
					ManualLogSource obj2 = log;
					val = new BepInExDebugLogInterpolatedStringHandler(20, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(result);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is acting well type");
					}
					obj2.LogDebug(val);
				}
				else if (_fountains.TryGetValue(text, out value2))
				{
					EnabledWellPrefabs.Add(value2);
					ManualLogSource obj3 = log;
					val = new BepInExDebugLogInterpolatedStringHandler(14, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(value2);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" well type");
					}
					obj3.LogDebug(val);
				}
				else
				{
					ManualLogSource obj4 = log;
					BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(27, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Unknown well prefab value: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(text);
					}
					obj4.LogWarning(val2);
				}
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "LeadAHorseToWater";

		public const string PLUGIN_NAME = "LeadAHorseToWater";

		public const string PLUGIN_VERSION = "0.8.0";
	}
}
namespace LeadAHorseToWater.Processes
{
	public record BabyHorseData(string name, Team team, float3 position, float speed, float acceleration, float rotation, int parentId1, int parentId2, DateTime notBefore);
	public static class BreedHorseProcess
	{
		public static BabyHorseData NextBabyData = null;

		private static HashSet<int> _knownHorses = new HashSet<int>();

		private static ManualLogSource _log => Plugin.LogInstance;

		public static void Update(NativeArray<Entity> horses)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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_0030: 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_0036: 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_0039: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Expected O, but got Unknown
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: 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_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: 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_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_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: 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_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: 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_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Expected O, but got Unknown
			//IL_01eb: 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_01bf: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Enumerator<Entity> enumerator = horses.GetEnumerator();
				bool flag = default(bool);
				BepInExDebugLogInterpolatedStringHandler val3;
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					if (!_knownHorses.Contains(current.Index))
					{
						NetworkId val = current.Read<NetworkId>();
						Translation val2 = current.Read<Translation>();
						ManualLogSource log = _log;
						val3 = new BepInExDebugLogInterpolatedStringHandler(27, 3, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Found horse ");
							((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(current.Index);
							((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" NetworkId=");
							((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<NetworkId>(val);
							((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" at ");
							((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<Translation>(val2);
						}
						log.LogDebug(val3);
						_knownHorses.Add(current.Index);
					}
				}
				if (NextBabyData == null || DateTime.Now < NextBabyData.notBefore)
				{
					return;
				}
				ManualLogSource log2 = _log;
				val3 = new BepInExDebugLogInterpolatedStringHandler(24, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("We're expecting a baby: ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<BabyHorseData>(NextBabyData);
				}
				log2.LogDebug(val3);
				Entity baby = Entity.Null;
				float num = float.MaxValue;
				enumerator = horses.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current2 = enumerator.Current;
					if (current2.Index == NextBabyData.parentId1 || current2.Index == NextBabyData.parentId2)
					{
						continue;
					}
					float num2 = Vector3.Distance(float3.op_Implicit(current2.Read<Translation>().Value), float3.op_Implicit(NextBabyData.position));
					if (num2 < num)
					{
						ManualLogSource log3 = _log;
						val3 = new BepInExDebugLogInterpolatedStringHandler(19, 2, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Closest horse <");
							((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(current2.Index);
							((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("> - ");
							((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<float>(num2);
						}
						log3.LogDebug(val3);
						num = num2;
						baby = current2;
					}
				}
				if (num > 8f)
				{
					_log.LogDebug((object)"Closest horse is too far so I give up, resetting baby data");
					NextBabyData = null;
					return;
				}
				EntityManager entityManager = VWorld.Server.EntityManager;
				((EntityManager)(ref entityManager)).SetComponentData<Team>(baby, new Team
				{
					Value = NextBabyData.team.Value
				});
				baby.With<NameableInteractable>((VExtensions.ActionRef<NameableInteractable>)delegate(ref NameableInteractable ni)
				{
					//IL_000b: Unknown result type (might be due to invalid IL or missing references)
					//IL_0010: Unknown result type (might be due to invalid IL or missing references)
					ni.Name = FixedString64Bytes.op_Implicit(NextBabyData.name);
				});
				baby.With<Mountable>((VExtensions.ActionRef<Mountable>)delegate(ref Mountable mount)
				{
					//IL_003a: Unknown result type (might be due to invalid IL or missing references)
					//IL_0040: Expected O, but got Unknown
					mount.MaxSpeed = NextBabyData.speed;
					mount.Acceleration = NextBabyData.acceleration;
					mount.RotationSpeed = NextBabyData.rotation;
					ManualLogSource log5 = _log;
					bool flag2 = default(bool);
					BepInExDebugLogInterpolatedStringHandler val4 = new BepInExDebugLogInterpolatedStringHandler(48, 4, ref flag2);
					if (flag2)
					{
						((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("Updated baby ");
						((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(baby.Index);
						((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" \n Speed ");
						((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<float>(mount.MaxSpeed);
						((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("\n Acceleration ");
						((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<float>(mount.Acceleration);
						((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("\n Rotation ");
						((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<float>(mount.RotationSpeed);
					}
					log5.LogDebug(val4);
				});
				NextBabyData = null;
			}
			catch (Exception ex)
			{
				ManualLogSource log4 = _log;
				if (log4 != null)
				{
					log4.LogError((object)ex);
				}
				NextBabyData = null;
			}
		}
	}
	public class WellCacheProcess
	{
		private const int MAX_BATCH = 1000;

		private bool _initialized;

		private Queue<Entity> _possibleWells = new Queue<Entity>();

		private bool _scanForAdded;

		private static ManualLogSource _log => Plugin.LogInstance;

		public Dictionary<Entity, (bool IsInvalidated, float3 Location)> Cache { get; } = new Dictionary<Entity, (bool, float3)>();

		public IEnumerable<float3> Positions => Cache.Values.Select(((bool IsInvalidated, float3 Location) x) => x.Location);

		public void PlanScanForAdded()
		{
			_scanForAdded = true;
		}

		public void InvalidateEntity(Entity e)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			if (Cache.ContainsKey(e))
			{
				Cache[e] = (true, Cache[e].Location);
			}
		}

		public void InvalidateAll()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			foreach (Entity item in Cache.Keys.ToList())
			{
				Cache[item] = (true, Cache[item].Location);
			}
		}

		public void Update()
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Expected O, but got Unknown
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Expected O, but got Unknown
			if (!_initialized)
			{
				_initialized = true;
				QueryForPossible(includeDisabled: true);
			}
			else if (_scanForAdded)
			{
				QueryForPossible(includeDisabled: false);
				_scanForAdded = false;
			}
			bool flag = default(bool);
			ManualLogSource log;
			if (_possibleWells.Any())
			{
				Stopwatch stopwatch = new Stopwatch();
				stopwatch.Start();
				int num = Math.Min(1000, _possibleWells.Count);
				for (int i = 0; i < num; i++)
				{
					Entity entity = _possibleWells.Dequeue();
					UpdateCache(entity);
				}
				log = _log;
				if (log != null)
				{
					BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(48, 3, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Updated ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" entities in ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<long>(stopwatch.ElapsedMilliseconds);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("ms, ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(_possibleWells.Count);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" remain, ending update.");
					}
					log.LogDebug(val);
				}
				return;
			}
			List<KeyValuePair<Entity, (bool, float3)>> list = Cache.Where((KeyValuePair<Entity, (bool IsInvalidated, float3 Location)> x) => x.Value.IsInvalidated).ToList();
			if (!list.Any())
			{
				return;
			}
			Stopwatch stopwatch2 = new Stopwatch();
			stopwatch2.Start();
			foreach (KeyValuePair<Entity, (bool, float3)> item in list)
			{
				Entity key = item.Key;
				UpdateCache(key);
			}
			log = _log;
			if (log != null)
			{
				BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(43, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Invalidated ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(list.Count);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" entities in ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<long>(stopwatch2.ElapsedMilliseconds);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("ms, ending update.");
				}
				log.LogDebug(val);
			}
		}

		public static bool IsWellPrefab(PrefabGUID guid)
		{
			return Settings.EnabledWellPrefabs.Contains(((PrefabGUID)(ref guid)).GuidHash);
		}

		private void UpdateCache(Entity entity)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Expected O, but got Unknown
			//IL_0059: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: 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_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = VWorld.Server.EntityManager;
			bool flag = default(bool);
			ManualLogSource log;
			if (((EntityManager)(ref entityManager)).HasComponent<BlueprintData>(entity))
			{
				entityManager = VWorld.Server.EntityManager;
				if (((EntityManager)(ref entityManager)).HasComponent<LocalToWorld>(entity))
				{
					entityManager = VWorld.Server.EntityManager;
					BlueprintData componentData = ((EntityManager)(ref entityManager)).GetComponentData<BlueprintData>(entity);
					if (IsWellPrefab(componentData.Guid))
					{
						entityManager = VWorld.Server.EntityManager;
						LocalToWorld componentData2 = ((EntityManager)(ref entityManager)).GetComponentData<LocalToWorld>(entity);
						log = _log;
						if (log != null)
						{
							BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(39, 2, ref flag);
							if (flag)
							{
								((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Well Found:  Blueprint GUID=");
								((BepInExLogInterpolatedStringHandler)val).AppendFormatted<PrefabGUID>(componentData.Guid);
								((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", Location=");
								((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float3>(((LocalToWorld)(ref componentData2)).Position);
							}
							log.LogDebug(val);
						}
						(bool, float3) value = (false, ((LocalToWorld)(ref componentData2)).Position);
						if (Cache.ContainsKey(entity))
						{
							Cache[entity] = value;
						}
						else
						{
							Cache.Add(entity, value);
						}
						return;
					}
				}
			}
			if (!Cache.Remove(entity))
			{
				return;
			}
			log = _log;
			if (log != null)
			{
				BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(37, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Updating ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(entity.Index);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" but no longer matches well.");
				}
				log.LogDebug(val);
			}
		}

		public void QueryForPossible(bool includeDisabled)
		{
			//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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_00d5: 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_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Expected O, but got Unknown
			ManualLogSource log = _log;
			bool flag = default(bool);
			if (log != null)
			{
				BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(27, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Querying for Wells FullMap=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(includeDisabled);
				}
				log.LogDebug(val);
			}
			Stopwatch stopwatch = new Stopwatch();
			stopwatch.Start();
			EntityManager entityManager = VWorld.Server.EntityManager;
			EntityQueryDesc[] array = new EntityQueryDesc[1];
			EntityQueryDesc val2 = new EntityQueryDesc();
			val2.All = Il2CppStructArray<ComponentType>.op_Implicit((ComponentType[])(object)new ComponentType[7]
			{
				ComponentType.ReadOnly<Team>(),
				ComponentType.ReadOnly<CastleHeartConnection>(),
				ComponentType.ReadOnly<BlueprintData>(),
				ComponentType.ReadOnly<LocalToWorld>(),
				ComponentType.ReadOnly<CastleAreaRequirement>(),
				ComponentType.ReadOnly<BlobAssetOwner>(),
				ComponentType.ReadOnly<TileModelRegistrationState>()
			});
			val2.Options = (EntityQueryOptions)(includeDisabled ? 2 : 0);
			array[0] = val2;
			EntityQuery val3 = ((EntityManager)(ref entityManager)).CreateEntityQuery((EntityQueryDesc[])(object)array);
			_possibleWells = new Queue<Entity>((IEnumerable<Entity>)((EntityQuery)(ref val3)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2)).ToArray());
			log = _log;
			if (log != null)
			{
				BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(15, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Enqueued ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(_possibleWells.Count);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" in ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<long>(stopwatch.ElapsedMilliseconds);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("ms");
				}
				log.LogDebug(val);
			}
		}
	}
}
namespace LeadAHorseToWater.Patches
{
	[HarmonyPatch(typeof(CheckInSunSystem), "OnUpdate")]
	public static class LeadAHorseToWaterSystem
	{
		private static DateTime NoUpdateBefore = DateTime.MinValue;

		private const string DRINKING_PREFIX = "♻ ";

		private static ManualLogSource _log => Plugin.LogInstance;

		public static WellCacheProcess Wells { get; } = new WellCacheProcess();

		public static void Prefix(CheckInSunSystem __instance)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (NoUpdateBefore > DateTime.Now)
				{
					return;
				}
				NoUpdateBefore = DateTime.Now.AddSeconds(1.5);
				NativeArray<Entity> horses = HorseUtil.GetHorses();
				if (horses.Length == 0)
				{
					return;
				}
				Wells.Update();
				BreedHorseProcess.Update(horses);
				Enumerator<Entity> enumerator = horses.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					if (!IsHorseWeFeed(current))
					{
						continue;
					}
					EntityManager entityManager = VWorld.Server.EntityManager;
					LocalToWorld componentData = ((EntityManager)(ref entityManager)).GetComponentData<LocalToWorld>(current);
					float3 position = ((LocalToWorld)(ref componentData)).Position;
					bool flag = false;
					foreach (float3 position2 in Wells.Positions)
					{
						if (Vector3.Distance(float3.op_Implicit(position2), float3.op_Implicit(position)) < Settings.DISTANCE_REQUIRED.Value)
						{
							flag = true;
							break;
						}
					}
					HandleRename(current, flag);
					if (flag)
					{
						current.WithComponentData<FeedableInventory>((VExtensions.ActionRef<FeedableInventory>)delegate(ref FeedableInventory inventory)
						{
							inventory.FeedProgressTime = Mathf.Max(inventory.FeedProgressTime, Mathf.Min(inventory.FeedProgressTime + (float)Settings.SECONDS_DRINK_PER_TICK.Value, (float)Settings.MAX_DRINK_AMOUNT.Value));
							inventory.IsFed = true;
						});
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = _log;
				if (log != null)
				{
					log.LogError((object)ex.ToString());
				}
			}
		}

		private static void HandleRename(Entity horseEntity, bool closeEnough)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			if (!Settings.ENABLE_RENAME.Value)
			{
				return;
			}
			horseEntity.WithComponentData<NameableInteractable>((VExtensions.ActionRef<NameableInteractable>)delegate(ref NameableInteractable nameable)
			{
				//IL_003c: 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_005e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0063: Unknown result type (might be due to invalid IL or missing references)
				string text = ((object)Unsafe.As<FixedString64Bytes, FixedString64Bytes>(ref nameable.Name)/*cast due to .constrained prefix*/).ToString();
				bool flag = text.StartsWith("♻ ");
				if (!closeEnough && flag)
				{
					nameable.Name = FixedString64Bytes.op_Implicit(text.Substring("♻ ".Length));
				}
				else if (closeEnough && !flag)
				{
					nameable.Name = FixedString64Bytes.op_Implicit("♻ " + text);
				}
			});
		}

		private static bool IsHorseWeFeed(Entity horse)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_001d: 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_002a: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_005d: 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)
			EntityManager entityManager = VWorld.Server.EntityManager;
			if (!horse.Has<FeedableInventory>())
			{
				return false;
			}
			ComponentLookup<Team> componentLookup = ((EntityManager)(ref entityManager)).GetComponentLookup<Team>(true);
			if (((EntityManager)(ref entityManager)).HasComponent<Team>(horse))
			{
				return !Team.IsInUnitTeam(componentLookup[horse]);
			}
			ManualLogSource log = _log;
			if (log != null)
			{
				bool flag = default(bool);
				BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(39, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Horse <");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(horse.Index);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("> does not have Team component. ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Entity>(horse);
				}
				log.LogDebug(val);
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(PlaceTileModelSystem))]
	public static class PlaceTileModelSystem_Patch
	{
		private static ManualLogSource _log => Plugin.LogInstance;

		[HarmonyPostfix]
		[HarmonyPatch("ClearEditing")]
		public static void Moving(PlaceTileModelSystem __instance, EntityManager entityManager, Entity tileModelEntity, Entity character)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			LeadAHorseToWaterSystem.Wells.InvalidateEntity(tileModelEntity);
			ManualLogSource log = _log;
			if (log != null)
			{
				bool flag = default(bool);
				BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(27, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Pseudo Moving Event Entity:");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(tileModelEntity.Index);
				}
				log.LogDebug(val);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("VerifyCanBuildTileModels")]
		public static void Destroying(PlaceTileModelSystem __instance, EntityManager entityManager, Entity character)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			LeadAHorseToWaterSystem.Wells.InvalidateAll();
			ManualLogSource log = _log;
			if (log != null)
			{
				bool flag = default(bool);
				BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(20, 0, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Pseudo Destroy Event");
				}
				log.LogDebug(val);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("HasUnlockedBlueprint")]
		public static void Building(PlaceTileModelSystem __instance, Entity user, PrefabGUID prefabGuid, Entity prefab)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_0036: 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 (!WellCacheProcess.IsWellPrefab(prefabGuid))
			{
				return;
			}
			LeadAHorseToWaterSystem.Wells.PlanScanForAdded();
			ManualLogSource log = _log;
			if (log != null)
			{
				bool flag = default(bool);
				BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(40, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Pseudo Building Event prefab: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<PrefabGUID>(prefabGuid);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", entity: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(prefab.Index);
				}
				log.LogDebug(val);
			}
		}
	}
}
namespace LeadAHorseToWater.Compat
{
	internal static class EntityExtensions
	{
		internal static void WithComponentData<T>(this Entity entity, VExtensions.ActionRef<T> action) where T : struct
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			entity.With(action);
		}
	}
	public static class VExtensions
	{
		public delegate void ActionRef<T>(ref T item);
	}
	public static class VWorld
	{
		private static World _server;

		public static World Server
		{
			get
			{
				if (_server != null && _server.IsCreated)
				{
					return _server;
				}
				_server = GetWorld("Server");
				return _server;
			}
		}

		public static World Game => Server;

		public static bool IsServer => true;

		public static bool IsClient => false;

		private static World GetWorld(string name)
		{
			Enumerator<World> enumerator = World.s_AllWorlds.GetEnumerator();
			while (enumerator.MoveNext())
			{
				World current = enumerator.Current;
				if (current.Name == name)
				{
					return current;
				}
			}
			return null;
		}
	}
}
namespace LeadAHorseToWater.VCFCompat
{
	public static class Commands
	{
		public record Horse(Entity Entity);

		public class NamedHorseConverter : CommandArgumentConverter<Horse, ChatCommandContext>
		{
			[CommandGroup("horse", "h")]
			public class HorseCommands
			{
				private static PrefabGUID BreedItemType = new PrefabGUID(-570287766);

				private const string TagColor = "#BF5";

				private Horse GetRequiredClosestHorse(ChatCommandContext ctx)
				{
					//IL_0006: 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)
					Entity? closetHorse = HorseUtil.GetClosetHorse(ctx.Event.SenderCharacterEntity);
					if (!closetHorse.HasValue)
					{
						throw ctx.Error("No closest horse and expected to find one based on usage.");
					}
					return new Horse(closetHorse.Value);
				}

				[Command("breed", null, null, null, null, false)]
				public void Breed(ChatCommandContext ctx)
				{
					//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_0030: Unknown result type (might be due to invalid IL or missing references)
					//IL_0035: Unknown result type (might be due to invalid IL or missing references)
					//IL_004c: Unknown result type (might be due to invalid IL or missing references)
					//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
					//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
					//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
					//IL_011d: Unknown result type (might be due to invalid IL or missing references)
					//IL_0122: Unknown result type (might be due to invalid IL or missing references)
					//IL_0127: 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_0133: Unknown result type (might be due to invalid IL or missing references)
					//IL_0138: Unknown result type (might be due to invalid IL or missing references)
					//IL_013d: 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_0144: Unknown result type (might be due to invalid IL or missing references)
					//IL_0146: Unknown result type (might be due to invalid IL or missing references)
					//IL_0150: 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_0159: Unknown result type (might be due to invalid IL or missing references)
					//IL_015e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0163: 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_0176: Expected O, but got Unknown
					//IL_01f0: 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_01fa: Unknown result type (might be due to invalid IL or missing references)
					//IL_0206: Unknown result type (might be due to invalid IL or missing references)
					//IL_020d: Expected O, but got Unknown
					//IL_018a: 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_01c1: Unknown result type (might be due to invalid IL or missing references)
					//IL_01db: 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_02ba: 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_02df: Unknown result type (might be due to invalid IL or missing references)
					//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
					//IL_0309: Unknown result type (might be due to invalid IL or missing references)
					//IL_0329: Unknown result type (might be due to invalid IL or missing references)
					//IL_032e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0333: Unknown result type (might be due to invalid IL or missing references)
					//IL_0336: Unknown result type (might be due to invalid IL or missing references)
					//IL_0338: Unknown result type (might be due to invalid IL or missing references)
					//IL_0369: Unknown result type (might be due to invalid IL or missing references)
					//IL_036b: 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_0380: 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_0221: Unknown result type (might be due to invalid IL or missing references)
					//IL_023e: 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_0272: Unknown result type (might be due to invalid IL or missing references)
					Entity senderCharacterEntity = ctx.Event.SenderCharacterEntity;
					if (BreedHorseProcess.NextBabyData != null)
					{
						throw ctx.Error("There's already a pair breeding, try again in a few seconds.");
					}
					Entity val = default(Entity);
					if (!InventoryUtilities.TryGetInventoryEntity<EntityManager>(VWorld.Server.EntityManager, senderCharacterEntity, ref val, 0))
					{
						throw ctx.Error("Could not find inventory, have you not created a character yet?");
					}
					List<Entity> list = HorseUtil.ClosestHorses(senderCharacterEntity);
					if (list.Count != 2)
					{
						throw ctx.Error($"Must have only two nearby horses, found {list.Count}");
					}
					PrefabGUID val2 = default(PrefabGUID);
					((PrefabGUID)(ref val2))..ctor(Settings.HORSE_BREED_PREFAB.Value);
					int value = Settings.HORSE_BREED_COST.Value;
					if (!InventoryUtilitiesServer.TryRemoveItem(VWorld.Server.EntityManager, val, val2, value))
					{
						throw ctx.Error($"You must have at least {value} {Settings.HORSE_BREED_ITEM_NAME.Value} in your inventory.");
					}
					float3 value2 = list[0].Read<Translation>().Value;
					float3 value3 = list[1].Read<Translation>().Value;
					Vector3 val3 = Vector3.Lerp(float3.op_Implicit(value2), float3.op_Implicit(value3), 0.5f);
					Mountable val4 = list[0].Read<Mountable>();
					ManualLogSource log = _log;
					bool flag = default(bool);
					BepInExDebugLogInterpolatedStringHandler val5 = new BepInExDebugLogInterpolatedStringHandler(44, 4, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("Parent ");
						((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<int>(list[0].Index);
						((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("\n Speed: ");
						((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<float>(val4.MaxSpeed);
						((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("\n Acceleration: ");
						((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<float>(val4.Acceleration);
						((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("\n Rotation: ");
						((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<float>(val4.RotationSpeed);
					}
					log.LogDebug(val5);
					Mountable val6 = list[1].Read<Mountable>();
					ManualLogSource log2 = _log;
					val5 = new BepInExDebugLogInterpolatedStringHandler(44, 4, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("Parent ");
						((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<int>(list[1].Index);
						((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("\n Speed: ");
						((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<float>(val6.MaxSpeed);
						((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("\n Acceleration: ");
						((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<float>(val6.Acceleration);
						((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("\n Rotation: ");
						((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<float>(val6.RotationSpeed);
					}
					log2.LogDebug(val5);
					StringBuilder sb = new StringBuilder();
					sb.AppendLine("Offspring Details");
					Func<string, float, float, float, float> obj = delegate(string label, float parent1, float parent2, float maxValue)
					{
						string text = parent1.ToString("F1");
						string text2 = parent2.ToString("F2");
						float num2;
						string value4;
						if (_random.NextDouble() > 0.5)
						{
							num2 = parent1;
							value4 = $"( {Format.Underline(text)} | {Format.Color(text2, "#888")} )";
						}
						else
						{
							num2 = parent2;
							value4 = $"( {Format.Color(text, "#888")} | {Format.Underline(text2)} )";
						}
						float num3 = maxValue * Settings.HORSE_BREED_MUTATION_RANGE.Value;
						float num4 = (float)(_random.NextDouble() * 2.0 - 1.0);
						float num5 = num4 * num3;
						char? value5 = ((num4 > 0f) ? new char?('+') : ((char?)null));
						string value6 = Format.Color($"{value5}{num5:F1}[{num4:P}]", (num5 > 0f) ? "#1d1" : "#d11");
						float num6 = MathF.Min(num2 + num5, maxValue);
						string value7 = ((num6 == maxValue) ? Format.Color(" [MAX]", "#e0e") : "");
						string value8 = Format.Bold($"{num6:F1}{value7}");
						StringBuilder stringBuilder = sb;
						StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(5, 4, stringBuilder);
						handler.AppendFormatted(Format.Color(Format.Bold(label), Color.White));
						handler.AppendLiteral(" ");
						handler.AppendFormatted(value4);
						handler.AppendLiteral(" ");
						handler.AppendFormatted(value6);
						handler.AppendLiteral(" = ");
						handler.AppendFormatted(value8);
						stringBuilder.AppendLine(ref handler);
						return num6;
					};
					float speed = obj("Speed", val4.MaxSpeed, val6.MaxSpeed, Settings.HORSE_BREED_MAX_SPEED.Value);
					float acceleration = obj("Acceleration", val4.Acceleration, val6.Acceleration, Settings.HORSE_BREED_MAX_ACCELERATION.Value);
					float num = obj("Rotation", val4.RotationSpeed / 10f, val6.RotationSpeed / 10f, Settings.HORSE_BREED_MAX_ROTATION.Value);
					Team team = list[0].Read<Team>();
					HorseUtil.SpawnHorse(1, float3.op_Implicit(val3));
					ctx.Reply(sb.ToString());
					BreedHorseProcess.NextBabyData = new BabyHorseData("Baby Horse " + StatTag(speed, acceleration, num), team, float3.op_Implicit(val3), speed, acceleration, num * 10f, list[0].Index, list[1].Index, DateTime.Now.AddSeconds(1.5));
				}

				private string StatTag(float speed, float acceleration, float rotation)
				{
					return $"<color={"#BF5"}>Ⓢ {speed:F1} Ⓐ {acceleration:F1} Ⓡ {rotation:F1}";
				}

				[Command("tag-stats", null, null, null, null, false)]
				public unsafe void TagStats(ChatCommandContext ctx, Horse horse = null)
				{
					//IL_0017: Unknown result type (might be due to invalid IL or missing references)
					//IL_001c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0021: Unknown result type (might be due to invalid IL or missing references)
					//IL_0026: Unknown result type (might be due to invalid IL or missing references)
					//IL_002b: Unknown result type (might be due to invalid IL or missing references)
					//IL_00df: Unknown result type (might be due to invalid IL or missing references)
					//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
					//IL_00e9: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
					//IL_010f: Unknown result type (might be due to invalid IL or missing references)
					if ((object)horse == null)
					{
						horse = GetRequiredClosestHorse(ctx);
					}
					EntityManager entityManager = VWorld.Server.EntityManager;
					NameableInteractable componentData = ((EntityManager)(ref entityManager)).GetComponentData<NameableInteractable>(horse.Entity);
					string name = ((object)(*(FixedString64Bytes*)(&componentData.Name))/*cast due to .constrained prefix*/).ToString();
					int num = name.LastIndexOf("Ⓢ", StringComparison.Ordinal);
					if (num > 0)
					{
						int num2 = name.LastIndexOf("<color=", StringComparison.Ordinal);
						if (num2 > 0 && num2 < num)
						{
							name = name.Substring(0, num2 - 1);
						}
					}
					if (name.Length >= 20)
					{
						ctx.Reply($"Name is too long, must be less than 20 characters, currently [without tag] {name.Length} characters");
					}
					else
					{
						Mountable val = horse.Entity.Read<Mountable>();
						string tag = StatTag(val.MaxSpeed, val.Acceleration, val.RotationSpeed / 10f);
						horse.Entity.With<NameableInteractable>((VExtensions.ActionRef<NameableInteractable>)delegate(ref NameableInteractable nameInteract)
						{
							//IL_0017: Unknown result type (might be due to invalid IL or missing references)
							//IL_001c: Unknown result type (might be due to invalid IL or missing references)
							nameInteract.Name = FixedString64Bytes.op_Implicit(name + " " + tag);
						});
					}
				}

				[Command("speed", null, null, null, null, true)]
				public void SetSpeed(ChatCommandContext ctx, float speed)
				{
					SetSpeed(ctx, GetRequiredClosestHorse(ctx), speed);
				}

				[Command("speed", null, null, null, null, true)]
				public void SetSpeed(ChatCommandContext ctx, Horse horse, float speed)
				{
					//IL_000e: Unknown result type (might be due to invalid IL or missing references)
					horse.Entity.With<Mountable>((VExtensions.ActionRef<Mountable>)delegate(ref Mountable mount)
					{
						mount.MaxSpeed = speed;
					});
					ctx.Reply($"Horse speed set to {speed}");
				}

				[Command("acceleration", "accel", null, null, null, true)]
				public void SetAcceleration(ChatCommandContext ctx, float acceleration)
				{
					SetAcceleration(ctx, GetRequiredClosestHorse(ctx), acceleration);
				}

				[Command("acceleration", "accel", null, null, null, true)]
				public void SetAcceleration(ChatCommandContext ctx, Horse horse, float acceleration)
				{
					//IL_000e: Unknown result type (might be due to invalid IL or missing references)
					horse.Entity.With<Mountable>((VExtensions.ActionRef<Mountable>)delegate(ref Mountable mount)
					{
						mount.Acceleration = acceleration;
					});
					ctx.Reply($"Horse acceleration set to {acceleration}");
				}

				[Command("rotation", null, null, null, null, true)]
				public void SetRotation(ChatCommandContext ctx, float rotation)
				{
					SetRotation(ctx, GetRequiredClosestHorse(ctx), rotation);
				}

				[Command("rotation", null, null, null, null, true)]
				public void SetRotation(ChatCommandContext ctx, Horse horse, float rotation)
				{
					//IL_000e: Unknown result type (might be due to invalid IL or missing references)
					horse.Entity.With<Mountable>((VExtensions.ActionRef<Mountable>)delegate(ref Mountable mount)
					{
						mount.RotationSpeed = rotation * 10f;
					});
					ctx.Reply($"Horse rotation set to {rotation}");
				}

				[Command("warp", null, null, null, null, true)]
				public void WarpHorse(ChatCommandContext ctx, Horse horse = null)
				{
					//IL_0011: Unknown result type (might be due to invalid IL or missing references)
					//IL_0016: 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_001f: Unknown result type (might be due to invalid IL or missing references)
					//IL_0024: Unknown result type (might be due to invalid IL or missing references)
					//IL_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_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 references)
					//IL_0042: Unknown result type (might be due to invalid IL or missing references)
					//IL_0047: Unknown result type (might be due to invalid IL or missing references)
					//IL_004e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0053: 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_005d: Unknown result type (might be due to invalid IL or missing references)
					//IL_0063: Unknown result type (might be due to invalid IL or missing references)
					//IL_0068: Unknown result type (might be due to invalid IL or missing references)
					//IL_006b: 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_007c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0081: Unknown result type (might be due to invalid IL or missing references)
					//IL_008e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0093: Unknown result type (might be due to invalid IL or missing references)
					//IL_0098: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
					//IL_00af: Unknown result type (might be due to invalid IL or missing references)
					//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
					//IL_00be: Unknown result type (might be due to invalid IL or missing references)
					//IL_00c6: 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)
					if ((object)horse == null)
					{
						horse = GetRequiredClosestHorse(ctx);
					}
					EntityManager entityManager = VWorld.Server.EntityManager;
					LocalToWorld componentData = ((EntityManager)(ref entityManager)).GetComponentData<LocalToWorld>(horse.Entity);
					float3 position = ((LocalToWorld)(ref componentData)).Position;
					entityManager = VWorld.Server.EntityManager;
					Entity val = ((EntityManager)(ref entityManager)).CreateEntity((ComponentType[])(object)new ComponentType[2]
					{
						ComponentType.ReadWrite<FromCharacter>(),
						ComponentType.ReadWrite<PlayerTeleportDebugEvent>()
					});
					entityManager = VWorld.Server.EntityManager;
					((EntityManager)(ref entityManager)).SetComponentData<FromCharacter>(val, new FromCharacter
					{
						User = ctx.Event.SenderUserEntity,
						Character = ctx.Event.SenderCharacterEntity
					});
					entityManager = VWorld.Server.EntityManager;
					((EntityManager)(ref entityManager)).SetComponentData<PlayerTeleportDebugEvent>(val, new PlayerTeleportDebugEvent
					{
						Position = ((float3)(ref position)).xyz,
						Target = (TeleportTarget)0
					});
					ctx.Reply("Warped to horse.");
				}

				[Command("spawn", null, null, null, null, true)]
				public void HorseMe(ChatCommandContext ctx, int num = 1)
				{
					//IL_0005: Unknown result type (might be due to invalid IL or missing references)
					//IL_000a: 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_0018: Unknown result type (might be due to invalid IL or missing references)
					//IL_001d: Unknown result type (might be due to invalid IL or missing references)
					//IL_0022: Unknown result type (might be due to invalid IL or missing references)
					//IL_0024: Unknown result type (might be due to invalid IL or missing references)
					EntityManager entityManager = VWorld.Server.EntityManager;
					float3 value = ((EntityManager)(ref entityManager)).GetComponentData<Translation>(ctx.Event.SenderUserEntity).Value;
					HorseUtil.SpawnHorse(num, value);
					ctx.Reply($"Spawned {num} horse{((num > 1) ? "s" : "")} near you.");
				}

				[Command("whistle", "w", null, null, null, true)]
				public void Whistle(ChatCommandContext ctx, Horse horse = null)
				{
					//IL_0018: Unknown result type (might be due to invalid IL or missing references)
					//IL_001d: Unknown result type (might be due to invalid IL or missing references)
					//IL_0026: Unknown result type (might be due to invalid IL or missing references)
					//IL_002b: Unknown result type (might be due to invalid IL or missing references)
					//IL_0030: Unknown result type (might be due to invalid IL or missing references)
					//IL_0035: Unknown result type (might be due to invalid IL or missing references)
					//IL_003f: Unknown result type (might be due to invalid IL or missing references)
					//IL_0044: Unknown result type (might be due to invalid IL or missing references)
					//IL_0048: 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)
					//IL_0054: Unknown result type (might be due to invalid IL or missing references)
					if ((object)horse == null)
					{
						horse = GetRequiredClosestHorse(ctx);
					}
					EntityManager entityManager = VWorld.Server.EntityManager;
					float3 userPos = ((EntityManager)(ref entityManager)).GetComponentData<Translation>(ctx.Event.SenderUserEntity).Value;
					entityManager = VWorld.Server.EntityManager;
					((EntityManager)(ref entityManager)).GetComponentData<Translation>(horse.Entity);
					horse.Entity.With<Translation>((VExtensions.ActionRef<Translation>)delegate(ref Translation t)
					{
						//IL_0002: Unknown result type (might be due to invalid IL or missing references)
						//IL_0007: Unknown result type (might be due to invalid IL or missing references)
						t.Value = userPos;
					});
					ctx.Reply("Horse moved to you.");
				}

				[Command("rename", null, null, null, null, true)]
				public void Rename(ChatCommandContext ctx, string newName)
				{
					Rename(ctx, GetRequiredClosestHorse(ctx), newName);
				}

				[Command("rename", null, null, null, null, true)]
				public void Rename(ChatCommandContext ctx, Horse horse, string newName)
				{
					//IL_0019: Unknown result type (might be due to invalid IL or missing references)
					string oldName = "";
					horse.Entity.With<NameableInteractable>((VExtensions.ActionRef<NameableInteractable>)delegate(ref NameableInteractable t)
					{
						//IL_001e: Unknown result type (might be due to invalid IL or missing references)
						//IL_0023: Unknown result type (might be due to invalid IL or missing references)
						oldName = ((object)Unsafe.As<FixedString64Bytes, FixedString64Bytes>(ref t.Name)/*cast due to .constrained prefix*/).ToString();
						t.Name = FixedString64Bytes.op_Implicit(newName);
					});
					ctx.Reply($"Horse '{oldName}' renamed to '{newName}'.");
				}

				[Command("kill", null, null, null, null, true)]
				public void Kill(ChatCommandContext ctx, Horse horse = null)
				{
					//IL_000d: Unknown result type (might be due to invalid IL or missing references)
					if ((object)horse == null)
					{
						horse = GetRequiredClosestHorse(ctx);
					}
					HorseUtil.KillWithNoDrops(horse.Entity);
					ctx.Reply("Horse removed.");
				}

				[Command("cull", null, null, null, null, true)]
				public void Kill(ChatCommandContext ctx, float radius = 5f, float percentage = 1f)
				{
					//IL_0006: 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_0036: Unknown result type (might be due to invalid IL or missing references)
					//IL_003d: Unknown result type (might be due to invalid IL or missing references)
					List<Entity> list = HorseUtil.ClosestHorses(ctx.Event.SenderCharacterEntity, radius);
					int count = list.Count;
					int num = Math.Clamp((int)((float)count * percentage), 0, count);
					int num2 = num;
					foreach (Entity item in list)
					{
						if (num2 == 0)
						{
							break;
						}
						HorseUtil.KillWithNoDrops(item);
						num2--;
					}
					ctx.Reply($"Removed {num} horses.");
				}

				[Command("famish", null, null, null, null, true)]
				public void Famish(ChatCommandContext ctx, float radius = 5f)
				{
					//IL_000c: 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_002d: Unknown result type (might be due to invalid IL or missing references)
					//IL_002e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0036: Unknown result type (might be due to invalid IL or missing references)
					List<Entity> list = HorseUtil.ClosestHorses(ctx.Event.SenderCharacterEntity, radius);
					int hungryCount = 0;
					foreach (Entity item in list)
					{
						if (item.Has<FeedableInventory>())
						{
							item.With<FeedableInventory>((VExtensions.ActionRef<FeedableInventory>)delegate(ref FeedableInventory t)
							{
								t.FeedProgressTime = 0f;
								hungryCount++;
							});
						}
					}
					ctx.Reply($"{hungryCount} horses have been made hungry.");
				}
			}

			private const float radius = 25f;

			public unsafe override Horse Parse(ChatCommandContext ctx, string input)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: 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_0032: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_0054: Unknown result type (might be due to invalid IL or missing references)
				foreach (Entity item in HorseUtil.ClosestHorses(ctx.Event.SenderCharacterEntity, 25f))
				{
					EntityManager entityManager = VWorld.Server.EntityManager;
					NameableInteractable componentData = ((EntityManager)(ref entityManager)).GetComponentData<NameableInteractable>(item);
					if (((object)(*(FixedString64Bytes*)(&componentData.Name))/*cast due to .constrained prefix*/).ToString().Contains(input, StringComparison.OrdinalIgnoreCase))
					{
						return new Horse(item);
					}
				}
				throw ctx.Error($"Could not find a horse within {25f:F1} units named like \"{input}\"");
			}
		}

		private static Random _random;

		private static ManualLogSource _log => Plugin.LogInstance;

		public static bool Enabled { get; private set; }

		static Commands()
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			_random = new Random();
			Enabled = ((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.TryGetValue("gg.deca.VampireCommandFramework", out var value);
			if (Enabled)
			{
				ManualLogSource log = _log;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(13, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("VCF Version: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Version>(value.Metadata.Version);
				}
				log.LogWarning(val);
			}
		}

		public static void Register()
		{
			CommandRegistry.RegisterAll();
		}

		public static void Unregister()
		{
			CommandRegistry.UnregisterAssembly();
		}
	}
	internal static class HorseUtil
	{
		private static Entity empty_entity = default(Entity);

		public static PrefabGUID DeadVampHorseBuffGuid = new PrefabGUID(525019977);

		private static Dictionary<string, PrefabGUID> HorseGuids = new Dictionary<string, PrefabGUID>
		{
			{
				"Regular",
				new PrefabGUID(1149585723)
			},
			{
				"Spectral",
				new PrefabGUID(2022889449)
			}
		};

		internal static void SpawnHorse(int countlocal, float3 localPos)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			PrefabGUID val = HorseGuids["Regular"];
			VWorld.Server.GetExistingSystemManaged<UnitSpawnerUpdateSystem>().SpawnUnit(empty_entity, val, localPos, countlocal, 1f, 2f, -1f);
		}

		internal static NativeArray<Entity> GetHorses()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_0048: 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)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = VWorld.Server.EntityManager;
			EntityQueryDesc[] array = new EntityQueryDesc[1];
			EntityQueryDesc val = new EntityQueryDesc();
			val.All = Il2CppStructArray<ComponentType>.op_Implicit((ComponentType[])(object)new ComponentType[4]
			{
				ComponentType.ReadWrite<NameableInteractable>(),
				ComponentType.ReadWrite<Mountable>(),
				ComponentType.ReadOnly<LocalToWorld>(),
				ComponentType.ReadOnly<Team>()
			});
			val.None = Il2CppStructArray<ComponentType>.op_Implicit((ComponentType[])(object)new ComponentType[2]
			{
				ComponentType.ReadOnly<Dead>(),
				ComponentType.ReadOnly<DestroyTag>()
			});
			array[0] = val;
			EntityQuery val2 = ((EntityManager)(ref entityManager)).CreateEntityQuery((EntityQueryDesc[])(object)array);
			return ((EntityQuery)(ref val2)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
		}

		internal static Entity? GetClosetHorse(Entity e)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			NativeArray<Entity> horses = GetHorses();
			EntityManager entityManager = VWorld.Server.EntityManager;
			LocalToWorld componentData = ((EntityManager)(ref entityManager)).GetComponentData<LocalToWorld>(e);
			float3 position = ((LocalToWorld)(ref componentData)).Position;
			float num = float.MaxValue;
			Entity? result = null;
			Enumerator<Entity> enumerator = horses.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				entityManager = VWorld.Server.EntityManager;
				componentData = ((EntityManager)(ref entityManager)).GetComponentData<LocalToWorld>(current);
				float3 position2 = ((LocalToWorld)(ref componentData)).Position;
				float num2 = Vector3.Distance(float3.op_Implicit(position), float3.op_Implicit(position2));
				if (num2 < num)
				{
					num = num2;
					result = current;
				}
			}
			return result;
		}

		internal static List<Entity> ClosestHorses(Entity e, float radius = 5f)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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_002b: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			NativeArray<Entity> horses = GetHorses();
			List<Entity> list = new List<Entity>();
			EntityManager entityManager = VWorld.Server.EntityManager;
			LocalToWorld componentData = ((EntityManager)(ref entityManager)).GetComponentData<LocalToWorld>(e);
			float3 position = ((LocalToWorld)(ref componentData)).Position;
			Enumerator<Entity> enumerator = horses.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity current = enumerator.Current;
				entityManager = VWorld.Server.EntityManager;
				componentData = ((EntityManager)(ref entityManager)).GetComponentData<LocalToWorld>(current);
				float3 position2 = ((LocalToWorld)(ref componentData)).Position;
				if (Vector3.Distance(float3.op_Implicit(position), float3.op_Implicit(position2)) < radius)
				{
					list.Add(current);
				}
			}
			return list;
		}

		internal static void KillWithNoDrops(Entity horse)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_0032: 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_003b: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: 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)
			if (horse.Has<Immortal>())
			{
				DebugEventsSystem existingSystemManaged = VWorld.Server.GetExistingSystemManaged<DebugEventsSystem>();
				ApplyBuffDebugEvent val = new ApplyBuffDebugEvent
				{
					BuffPrefabGUID = DeadVampHorseBuffGuid
				};
				FromCharacter val2 = new FromCharacter
				{
					User = horse,
					Character = horse
				};
				existingSystemManaged.ApplyBuff(val2, val);
			}
			else
			{
				horse.With<Health>((VExtensions.ActionRef<Health>)delegate(ref Health t)
				{
					t.IsDead = true;
				});
				EntityManager entityManager = VWorld.Server.EntityManager;
				((EntityManager)(ref entityManager)).AddComponent(horse, ComponentType.op_Implicit(Il2CppType.Of<Dead>()));
			}
		}
	}
}