Decompiled source of SmartQuickStash v0.1.2

SmartQuickStash.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.CastleBuilding;
using ProjectM.Scripting;
using ProjectM.UI;
using Stunlock.Core;
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using VampireCommandFramework;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("SmartQuickStash")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.2.0")]
[assembly: AssemblyInformationalVersion("0.1.2")]
[assembly: AssemblyProduct("SmartQuickStash")]
[assembly: AssemblyTitle("SmartQuickStash")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.2.0")]
[module: UnverifiableCode]
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;
		}
	}
}
namespace SmartQuickStash
{
	internal static class Commands
	{
		[Command("smartstash", "sstash", null, "Smart-stash nearby inventory items.", null, false)]
		public static void SmartStash(ChatCommandContext ctx)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			SmartStashService.Result result = SmartStashService.Stash(ctx.Event.SenderCharacterEntity);
			ctx.Reply($"Smart stash: moved {result.Moved} item(s), {result.Remaining} left; {result.Containers} container(s) scanned.");
		}
	}
	internal static class Core
	{
		internal static World Server => FindWorld("Server") ?? throw new InvalidOperationException("Server world is not ready.");

		internal static EntityManager EntityManager => Server.EntityManager;

		internal static PrefabCollectionSystem Prefabs => Server.GetExistingSystemManaged<PrefabCollectionSystem>();

		internal static ServerScriptMapper ScriptMapper => Server.GetExistingSystemManaged<ServerScriptMapper>();

		internal static ServerGameManager GameManager => ScriptMapper.GetServerGameManager();

		private static World? FindWorld(string name)
		{
			Enumerator<World> enumerator = World.s_AllWorlds.GetEnumerator();
			while (enumerator.MoveNext())
			{
				if (enumerator.Current.Name == name)
				{
					return enumerator.Current;
				}
			}
			return null;
		}
	}
	internal static class EcsExtensions
	{
		public 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_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_0010: 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_0014: Unknown result type (might be due to invalid IL or missing references)
			ComponentType val = ComponentType.ReadOnly(Il2CppType.Of<T>());
			EntityManager entityManager = Core.EntityManager;
			return ((EntityManager)(ref entityManager)).HasComponent(entity, val);
		}

		public 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_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_0010: 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_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)
			ComponentType val = ComponentType.ReadOnly(Il2CppType.Of<T>());
			EntityManager entityManager = Core.EntityManager;
			return Marshal.PtrToStructure<T>(new IntPtr(((EntityManager)(ref entityManager)).GetComponentDataRawRO(entity, val.TypeIndex)));
		}

		public static DynamicBuffer<T> ReadBuffer<T>(this Entity entity) where T : struct
		{
			//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_0008: 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)
			EntityManager entityManager = Core.EntityManager;
			return ((EntityManager)(ref entityManager)).GetBuffer<T>(entity, false);
		}
	}
	[HarmonyPatch(typeof(ClientChatSystem), "OnUpdate")]
	internal static class HotkeyPatch
	{
		private static readonly MethodInfo? Submit = AccessTools.Method(typeof(ClientChatSystem), "_OnInputEndEdit", (Type[])null, (Type[])null);

		private static DateTime _lastUse;

		[HarmonyPostfix]
		private static void Postfix(ClientChatSystem __instance)
		{
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Expected O, but got Unknown
			//IL_004a: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			bool flag = default(bool);
			try
			{
				Keyboard current = Keyboard.current;
				if (current == null || DateTime.UtcNow - _lastUse < TimeSpan.FromMilliseconds(400.0))
				{
					return;
				}
				if (!Enum.TryParse<Key>(Plugin.Hotkey.Value, ignoreCase: true, out Key result))
				{
					result = (Key)21;
				}
				if (((ButtonControl)current[result]).wasPressedThisFrame)
				{
					_lastUse = DateTime.UtcNow;
					ManualLogSource log = ((BasePlugin)Plugin.Instance).Log;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(40, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Hotkey ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Key>(result);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" pressed; requesting smart stash.");
					}
					log.LogInfo(val);
					Submit?.Invoke(__instance, new object[1] { ".smartstash" });
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = ((BasePlugin)Plugin.Instance).Log;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(15, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Hotkey failed: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
				}
				log2.LogError(val2);
			}
		}
	}
	[BepInPlugin("kaern.vrising.smartquickstash", "Smart Quick Stash", "0.1.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BasePlugin
	{
		public const string Guid = "kaern.vrising.smartquickstash";

		public const string Name = "Smart Quick Stash";

		public const string Version = "0.1.2";

		internal static Plugin Instance { get; private set; }

		internal static ConfigEntry<float> Range { get; private set; }

		internal static ConfigEntry<string> Hotkey { get; private set; }

		internal static ConfigEntry<bool> SkipUniqueItems { get; private set; }

		internal static Harmony Harmony { get; private set; }

		public override void Load()
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Expected O, but got Unknown
			Instance = this;
			Range = ((BasePlugin)this).Config.Bind<float>("Storage", "Range", 50f, "Maximum stash range in world units. About 5 units is one floor tile.");
			Hotkey = ((BasePlugin)this).Config.Bind<string>("Input", "Hotkey", "G", "Client hotkey from Unity InputSystem.Key, for example G, H, F6.");
			SkipUniqueItems = ((BasePlugin)this).Config.Bind<bool>("Safety", "SkipUniqueItems", true, "Skip item-entity stacks such as modified equipment to preserve instance data.");
			((BasePlugin)this).Config.Save();
			Harmony = new Harmony("kaern.vrising.smartquickstash");
			Harmony.PatchAll(Assembly.GetExecutingAssembly());
			CommandRegistry.RegisterAll();
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(26, 4, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Smart Quick Stash");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("0.1.2");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded; hotkey=");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(Hotkey.Value);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", range=");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(Range.Value);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
			}
			log.LogInfo(val);
		}

		public override bool Unload()
		{
			CommandRegistry.UnregisterAssembly();
			Harmony.UnpatchSelf();
			return true;
		}
	}
	internal static class SmartStashService
	{
		internal readonly record struct Result(int Moved, int Remaining, int Containers);

		private readonly record struct Target(Entity Owner, Entity Inventory, float Distance, PrefabGUID RestrictedType, long RestrictedCategory)
		{
			internal bool IsSpecialized
			{
				get
				{
					//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)
					PrefabGUID restrictedType = RestrictedType;
					if (((PrefabGUID)(ref restrictedType)).GuidHash == 0)
					{
						return RestrictedCategory != 0;
					}
					return true;
				}
			}

			[CompilerGenerated]
			private bool PrintMembers(StringBuilder builder)
			{
				//IL_000e: 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_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_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)
				builder.Append("Owner = ");
				builder.Append(((object)Owner/*cast due to .constrained prefix*/).ToString());
				builder.Append(", Inventory = ");
				builder.Append(((object)Inventory/*cast due to .constrained prefix*/).ToString());
				builder.Append(", Distance = ");
				builder.Append(Distance.ToString());
				builder.Append(", RestrictedType = ");
				builder.Append(((object)RestrictedType/*cast due to .constrained prefix*/).ToString());
				builder.Append(", RestrictedCategory = ");
				builder.Append(RestrictedCategory.ToString());
				return true;
			}
		}

		private static readonly PrefabGUID ExternalInventoryPrefab = new PrefabGUID(1183666186);

		internal static Result Stash(Entity character)
		{
			//IL_0006: 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_0016: 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_002f: 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_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_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_00df: 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_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: 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_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: 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_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = Core.EntityManager;
			ServerGameManager manager = Core.GameManager;
			Entity playerInventory = default(Entity);
			if (!InventoryUtilities.TryGetInventoryEntity<EntityManager>(entityManager, character, ref playerInventory, 0))
			{
				return new Result(0, 0, 0);
			}
			float3 value = character.Read<Translation>().Value;
			List<Target> list = (from x in FindTargets(character, value, Plugin.Range.Value)
				where x.Inventory != Entity.Null && x.Inventory != playerInventory
				group x by x.Inventory into g
				select g.OrderByDescending((Target x) => x.IsSpecialized).First() into x
				orderby x.Distance
				select x).ToList();
			Dictionary<PrefabGUID, int> dictionary = new Dictionary<PrefabGUID, int>();
			DynamicBuffer<InventoryBuffer> val = playerInventory.ReadBuffer<InventoryBuffer>();
			for (int num = 8; num < val.Length; num++)
			{
				InventoryBuffer val2 = val[num];
				if (((PrefabGUID)(ref val2.ItemType)).GuidHash == 0 || val2.Amount <= 0)
				{
					continue;
				}
				if (Plugin.SkipUniqueItems.Value)
				{
					ref NetworkedEntity itemEntity = ref val2.ItemEntity;
					object obj = NetworkedEntity.Empty;
					if (!((object)Unsafe.As<NetworkedEntity, NetworkedEntity>(ref itemEntity)/*cast due to .constrained prefix*/).Equals(obj))
					{
						continue;
					}
				}
				dictionary.TryGetValue(val2.ItemType, out var value2);
				dictionary[val2.ItemType] = value2 + val2.Amount;
			}
			int num2 = 0;
			int num3 = 0;
			foreach (KeyValuePair<PrefabGUID, int> pair in dictionary)
			{
				int value3 = pair.Value;
				value3 = TransferTo(manager, playerInventory, pair.Key, value3, list.Where((Target t) => ((ServerGameManager)(ref manager)).GetInventoryItemCount(t.Inventory, pair.Key) > 0));
				if (value3 > 0 && TryGetItemCategory(pair.Key, out var category))
				{
					value3 = TransferTo(manager, playerInventory, pair.Key, value3, list.Where((Target t) => t.IsSpecialized && Accepts(t, pair.Key, category)));
				}
				if (value3 > 0)
				{
					value3 = TransferTo(manager, playerInventory, pair.Key, value3, list.Where((Target t) => !t.IsSpecialized));
				}
				num2 += pair.Value - value3;
				num3 += value3;
			}
			return new Result(num2, num3, list.Count);
		}

		private static bool Accepts(Target target, PrefabGUID item, long category)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			PrefabGUID restrictedType = target.RestrictedType;
			if (((PrefabGUID)(ref restrictedType)).GuidHash == 0 || target.RestrictedType == item)
			{
				if (target.RestrictedCategory != 0L)
				{
					return (target.RestrictedCategory & category) != 0;
				}
				return true;
			}
			return false;
		}

		private static int TransferTo(ServerGameManager manager, Entity source, PrefabGUID item, int amount, IEnumerable<Target> targets)
		{
			//IL_0018: 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)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			foreach (Target target in targets)
			{
				if (amount <= 0)
				{
					break;
				}
				amount -= Transfer(manager, source, target.Inventory, item, amount);
			}
			return amount;
		}

		private static int Transfer(ServerGameManager manager, Entity source, Entity destination, PrefabGUID item, int amount)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: 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_0012: 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_001b: 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_0026: 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_0031: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			if (!((ServerGameManager)(ref manager)).TryRemoveInventoryItem(source, item, amount))
			{
				return 0;
			}
			AddItemResponse val = ((ServerGameManager)(ref manager)).TryAddInventoryItem(destination, item, amount);
			if ((int)val.Result == 0)
			{
				return amount;
			}
			if (val.RemainingAmount > 0)
			{
				((ServerGameManager)(ref manager)).TryAddInventoryItem(source, item, val.RemainingAmount);
			}
			return amount - val.RemainingAmount;
		}

		private static bool TryGetItemCategory(PrefabGUID item, out long category)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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_0022: 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_0039: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected I8, but got Unknown
			category = 0L;
			Entity val = Entity.Null;
			PrefabLookupMap prefabLookupMap = Core.Prefabs._PrefabLookupMap;
			if (!((PrefabLookupMap)(ref prefabLookupMap)).TryGetValue(item, ref val) || val == Entity.Null || !val.Has<ItemData>())
			{
				return false;
			}
			category = (long)val.Read<ItemData>().ItemCategory;
			return true;
		}

		private static List<Target> FindTargets(Entity character, float3 origin, float range)
		{
			//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_0006: 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_001e: 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_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_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_003f: 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_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_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)
			//IL_006c: 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_0078: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: 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_00de: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: 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_0154: 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_00ed: 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_00f4: 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)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: 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_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: 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_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//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_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: 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_01c4: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = Core.EntityManager;
			if (!TryGetAlliedCastleHeart(character, out var castleHeart) || !castleHeart.Has<SharedCastleInventoryConnection>())
			{
				return new List<Target>();
			}
			SharedCastleInventoryConnection val = castleHeart.Read<SharedCastleInventoryConnection>();
			Entity entityOnServer = ((NetworkedEntity)(ref val.SharedInventoryManager)).GetEntityOnServer();
			if (entityOnServer == Entity.Null || !entityOnServer.Has<SharedCastleInventories>())
			{
				return new List<Target>();
			}
			List<Target> list = new List<Target>();
			Enumerator<SharedCastleInventories> enumerator = entityOnServer.ReadBuffer<SharedCastleInventories>().GetEnumerator();
			while (enumerator.MoveNext())
			{
				Entity inventorySource = enumerator.Current.InventorySource;
				if (inventorySource == Entity.Null || !((EntityManager)(ref entityManager)).Exists(inventorySource) || !inventorySource.Has<Translation>())
				{
					continue;
				}
				float2 xz = ((float3)(ref origin)).xz;
				Translation val2 = inventorySource.Read<Translation>();
				float num = math.distance(xz, ((float3)(ref val2.Value)).xz);
				if (num > range)
				{
					continue;
				}
				if (inventorySource.Has<InventoryInstanceElement>())
				{
					Enumerator<InventoryInstanceElement> enumerator2 = inventorySource.ReadBuffer<InventoryInstanceElement>().GetEnumerator();
					while (enumerator2.MoveNext())
					{
						InventoryInstanceElement current = enumerator2.Current;
						NetworkedEntity externalInventoryEntity = current.ExternalInventoryEntity;
						Entity entityOnServer2 = ((NetworkedEntity)(ref externalInventoryEntity)).GetEntityOnServer();
						if (entityOnServer2 != Entity.Null)
						{
							list.Add(new Target(inventorySource, entityOnServer2, num, current.RestrictedType, current.RestrictedCategory));
						}
					}
				}
				if (!inventorySource.Has<AttachedBuffer>())
				{
					continue;
				}
				Enumerator<AttachedBuffer> enumerator3 = inventorySource.ReadBuffer<AttachedBuffer>().GetEnumerator();
				while (enumerator3.MoveNext())
				{
					AttachedBuffer current2 = enumerator3.Current;
					Entity entity = current2.Entity;
					if (entity.Has<PrefabGUID>() && !(entity.Read<PrefabGUID>() != ExternalInventoryPrefab) && list.All((Target t) => t.Inventory != entity))
					{
						list.Add(new Target(inventorySource, entity, num, PrefabGUID.Empty, 0L));
					}
				}
			}
			return list;
		}

		private static bool TryGetAlliedCastleHeart(Entity character, out Entity castleHeart)
		{
			//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_000b: 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_001b: 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_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_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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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_0054: 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_006c: 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_0073: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: 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_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: 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_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_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: 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_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: 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_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: 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)
			castleHeart = Entity.Null;
			if (!character.Has<TilePosition>())
			{
				return false;
			}
			EntityManager entityManager = Core.EntityManager;
			TilePosition val = character.Read<TilePosition>();
			EntityQuery val2 = ((EntityManager)(ref entityManager)).CreateEntityQuery((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly(Il2CppType.Of<CastleTerritory>()) });
			NativeArray<Entity> val3 = ((EntityQuery)(ref val2)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			Entity val4 = Entity.Null;
			try
			{
				Enumerator<Entity> enumerator = val3.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					CastleTerritory val5 = default(CastleTerritory);
					if (CastleTerritoryExtensions.IsTileInTerritory(entityManager, val.Tile, ref current, ref val5))
					{
						val4 = current;
						break;
					}
				}
			}
			finally
			{
				val3.Dispose();
				((EntityQuery)(ref val2)).Dispose();
			}
			if (val4 == Entity.Null)
			{
				return false;
			}
			EntityQuery val6 = ((EntityManager)(ref entityManager)).CreateEntityQuery((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly(Il2CppType.Of<CastleHeart>()) });
			NativeArray<Entity> val7 = ((EntityQuery)(ref val6)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			try
			{
				Enumerator<Entity> enumerator = val7.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current2 = enumerator.Current;
					if (!(current2.Read<CastleHeart>().CastleTerritoryEntity != val4))
					{
						if (!Team.IsAllies(entityManager, character, current2))
						{
							return false;
						}
						castleHeart = current2;
						return true;
					}
				}
			}
			finally
			{
				val7.Dispose();
				((EntityQuery)(ref val6)).Dispose();
			}
			return false;
		}
	}
}