Decompiled source of KindredLogistics v1.5.7

KindredLogistics.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using KindredLogistics;
using KindredLogistics.Commands.Converters;
using KindredLogistics.Services;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.CastleBuilding;
using ProjectM.CastleBuilding.Rebuilding;
using ProjectM.Network;
using ProjectM.Physics;
using ProjectM.Scripting;
using ProjectM.Shared;
using ProjectM.Shared.Systems;
using ProjectM.Terrain;
using Stunlock.Core;
using Stunlock.Localization;
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Physics;
using Unity.Scenes;
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("KindredLogistics")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Inventory management mod. Stashing, craftpulling, finding chests, etc")]
[assembly: AssemblyFileVersion("1.5.7.0")]
[assembly: AssemblyInformationalVersion("1.5.7+0.Branch.main.Sha.62bb8fcf39ee2ebe62410e48ec8f8fdc72e85b10.efae0cea067fb0c9fdc8855713f86a671af22049")]
[assembly: AssemblyProduct("KindredLogistics")]
[assembly: AssemblyTitle("KindredLogistics")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.5.7.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace KindreddLogistics.Patches
{
	[HarmonyPatch]
	public class SortSingleInventorySystemPatch
	{
		private static List<(ulong, double)> lastSort = new List<(ulong, double)>();

		[HarmonyPatch(typeof(SortSingleInventorySystem), "OnUpdate")]
		[HarmonyPrefix]
		private static void Prefix(SortSingleInventorySystem __instance)
		{
			//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_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_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_001c: 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_0029: 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_003b: 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_0043: 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_004a: 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)
			EntityQuery eventQuery = __instance._EventQuery;
			NativeArray<Entity> val = ((EntityQuery)(ref eventQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			try
			{
				Enumerator<Entity> enumerator = val.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					if (((Entity)(ref current)).Equals(Entity.Null))
					{
						continue;
					}
					FromCharacter val2 = current.Read<FromCharacter>();
					ulong platformId = val2.User.Read<User>().PlatformId;
					if (!Core.PlayerSettings.IsSortStashEnabled(platformId))
					{
						continue;
					}
					double serverTime = Core.ServerTime;
					bool flag = false;
					for (int i = 0; i < lastSort.Count; i++)
					{
						if (lastSort[i].Item1 == platformId)
						{
							double item = lastSort[i].Item2;
							if (serverTime - item < 1.0)
							{
								flag = true;
								Core.Stash.StashCharacterInventory(val2.Character);
							}
							lastSort.RemoveAt(i);
							break;
						}
					}
					if (!flag)
					{
						lastSort.Add((platformId, serverTime));
					}
				}
			}
			catch (Exception ex)
			{
				Core.Log.LogError((object)ex);
			}
			finally
			{
				val.Dispose();
			}
		}
	}
}
namespace Logistics.Commands
{
	[CommandGroup("logistics", "l")]
	public static class LogisticsCommands
	{
		[Command("sortstash", "ss", ".l ss", "Toggles autostashing on double clicking sort button for player.", null, false)]
		public static void TogglePlayerAutoStash(ChatCommandContext ctx)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			ulong platformId = ctx.Event.User.PlatformId;
			bool flag = Core.PlayerSettings.ToggleSortStash(platformId);
			ctx.Reply("SortStash is " + (flag ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + ".");
		}

		[Command("craftpull", "cr", ".l cr", "Toggles right-clicking on recipes for missing ingredients.", null, false)]
		public static void TogglePlayerAutoPull(ChatCommandContext ctx)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			ulong platformId = ctx.Event.User.PlatformId;
			bool flag = Core.PlayerSettings.ToggleCraftPull(platformId);
			ctx.Reply("CraftPull is " + (flag ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + ".");
		}

		[Command("dontpulllast", "dpl", ".l dpl", "Toggles the ability to not pull the last item from a container for Logistics commands.", null, false)]
		public static void ToggleDontPullLast(ChatCommandContext ctx)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			ulong platformId = ctx.Event.User.PlatformId;
			bool flag = Core.PlayerSettings.ToggleDontPullLast(platformId);
			ctx.Reply("DontPullLast is " + (flag ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + ".");
		}

		[Command("autostashmissions", "asm", ".l asm", "Toggles autostashing for servant missions.", null, false)]
		public static void ToggleServantAutoStash(ChatCommandContext ctx)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			ulong platformId = ctx.Event.User.PlatformId;
			bool flag = Core.PlayerSettings.ToggleAutoStashMissions(platformId);
			ctx.Reply("AutoStash for missions is " + (flag ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + ".");
		}

		[Command("conveyor", "co", ".l co", "Toggles the ability of sender/receiver's to move items around.", null, false)]
		public static void ToggleConveyor(ChatCommandContext ctx)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			ulong platformId = ctx.Event.User.PlatformId;
			bool flag = Core.PlayerSettings.ToggleConveyor(platformId);
			ctx.Reply("Conveyor is " + (flag ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + ".");
		}

		[Command("salvage", "sal", ".l sal", "Toggles the ability to salvage items from a chest named 'salvage'.", null, false)]
		public static void ToggleSalvage(ChatCommandContext ctx)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			ulong platformId = ctx.Event.User.PlatformId;
			bool flag = Core.PlayerSettings.ToggleSalvage(platformId);
			ctx.Reply("Salvage is " + (flag ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + ".");
		}

		[Command("unitspawner", "us", ".l sp", "Toggles the ability to fill unit stations from a chest named 'spawner'.", null, false)]
		public static void ToggleUnitSpawner(ChatCommandContext ctx)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			ulong platformId = ctx.Event.User.PlatformId;
			bool flag = Core.PlayerSettings.ToggleUnitSpawner(platformId);
			ctx.Reply("Spawner is " + (flag ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + ".");
		}

		[Command("brazier", "bz", ".l bz", "Toggles the ability to fill braziers from a chest named 'brazier'.", null, false)]
		public static void ToggleBrazier(ChatCommandContext ctx)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			ulong platformId = ctx.Event.User.PlatformId;
			bool flag = Core.PlayerSettings.ToggleBrazier(platformId);
			ctx.Reply("Brazier is " + (flag ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + ".");
		}

		[Command("silentpull", "sp", null, "Toggles the ability to not send messages when pulling about where they came from.", null, false)]
		public static void ToggleSilentCraftPull(ChatCommandContext ctx)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			ulong platformId = ctx.Event.User.PlatformId;
			bool flag = Core.PlayerSettings.ToggleSilentPull(platformId);
			ctx.Reply("SilentPull is " + (flag ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + ".");
		}

		[Command("silentstash", "ssh", null, "Toggles the ability to not send messages when stashing items about where they go.", null, false)]
		public static void ToggleSilentStash(ChatCommandContext ctx)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			ulong platformId = ctx.Event.User.PlatformId;
			bool flag = Core.PlayerSettings.ToggleSilentStash(platformId);
			ctx.Reply("SilentStash is " + (flag ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + ".");
		}

		[Command("settings", "s", ".l s", "Displays current settings.", null, false)]
		public static void DisplaySettings(ChatCommandContext ctx)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			ulong platformId = ctx.Event.User.PlatformId;
			PlayerSettingsService.PlayerSettings settings = Core.PlayerSettings.GetSettings(platformId);
			PlayerSettingsService.PlayerSettings globalSettings = Core.PlayerSettings.GetGlobalSettings();
			ctx.Reply("KindredLogistics Settings:\nSortStash: " + ((!globalSettings.SortStash) ? "<color=red>Server Off</color>" : (settings.SortStash ? "<color=green>On</color>" : "<color=red>Off</color>")) + "\nPull (Global) : " + (globalSettings.Pull ? "<color=green>Server On</color>" : "<color=red>Server Off</color>") + "\nCraftPull: " + ((!globalSettings.CraftPull) ? "<color=red>Server Off</color>" : (settings.CraftPull ? "<color=green>On</color>" : "<color=red>Off</color>")) + "\nDontPullLast: " + (settings.DontPullLast ? "<color=green>On</color>" : "<color=red>Off</color>") + "\nAutoStashMissions: " + ((!globalSettings.AutoStashMissions) ? "<color=red>Server Off</color>" : (settings.AutoStashMissions ? "<color=green>On</color>" : "<color=red>Off</color>")) + "\nConveyor: " + ((!globalSettings.Conveyor) ? "<color=red>Server Off</color>" : (settings.Conveyor ? "<color=green>On</color>" : "<color=red>Off</color>")) + "\nSalvage: " + ((!globalSettings.Salvage) ? "<color=red>Server Off</color>" : (settings.Salvage ? "<color=green>On</color>" : "<color=red>Off</color>")) + "\nUnitSpawner: " + ((!globalSettings.UnitSpawner) ? "<color=red>Server Off</color>" : (settings.UnitSpawner ? "<color=green>On</color>" : "<color=red>Off</color>")) + "\nBrazier: " + ((!globalSettings.Brazier) ? "<color=red>Server Off</color>" : (settings.Brazier ? "<color=green>On</color>" : "<color=red>Off</color>")) + " | Named: " + (globalSettings.Named ? "<color=green>Server On</color>" : "<color=red>Server Off</color>") + "\nSilent (Pull: " + (settings.SilentPull ? "<color=green>On</color>" : "<color=red>Off</color>") + " | Stash: " + (settings.SilentStash ? "<color=green>On</color>" : "<color=red>Off</color>") + ")");
		}
	}
	[CommandGroup("logisticsglobal", "lg")]
	public static class LogisticsGlobal
	{
		[Command("sortstash", "ss", ".lg ss", "Toggles autostashing on double clicking sort button for player.", null, true)]
		public static void TogglePlayerAutoStash(ChatCommandContext ctx)
		{
			bool flag = Core.PlayerSettings.ToggleSortStash(0uL);
			ctx.Reply("Global SortStash is " + (flag ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + ".");
		}

		[Command("pull", "p", ".lg p", "Toggles the ability to pull items from containers.", null, true)]
		public static void TogglePlayerPull(ChatCommandContext ctx)
		{
			bool flag = Core.PlayerSettings.TogglePull();
			ctx.Reply("Global Pull is " + (flag ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + ".");
		}

		[Command("craftpull", "cr", ".lg cr", "Toggles right-clicking on recipes for missing ingredients.", null, true)]
		public static void TogglePlayerAutoPull(ChatCommandContext ctx)
		{
			bool flag = Core.PlayerSettings.ToggleCraftPull(0uL);
			ctx.Reply("CraftPull is " + (flag ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + ".");
		}

		[Command("autostashmissions", "asm", ".lg asm", "Toggles autostashing for servant missions.", null, true)]
		public static void ToggleServantAutoStash(ChatCommandContext ctx)
		{
			bool flag = Core.PlayerSettings.ToggleAutoStashMissions(0uL);
			ctx.Reply("Global AutoStash for missions is " + (flag ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + ".");
		}

		[Command("conveyor", "co", ".lg co", "Toggles the ability of sender/receiver's to move items around.", null, true)]
		public static void ToggleConveyor(ChatCommandContext ctx)
		{
			bool flag = Core.PlayerSettings.ToggleConveyor(0uL);
			ctx.Reply("Global Conveyor is " + (flag ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + ".");
		}

		[Command("salvage", "sal", ".lg sal", "Toggles the ability to salvage items from a chest named 'salvage'.", null, true)]
		public static void ToggleSalvage(ChatCommandContext ctx)
		{
			bool flag = Core.PlayerSettings.ToggleSalvage(0uL);
			ctx.Reply("Global Salvage is " + (flag ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + ".");
		}

		[Command("unitspawner", "us", ".lg sp", "Toggles the ability to fill unit stations from a chest named 'spawner'.", null, true)]
		public static void ToggleUnitSpawner(ChatCommandContext ctx)
		{
			bool flag = Core.PlayerSettings.ToggleUnitSpawner(0uL);
			ctx.Reply("Global Spawner is " + (flag ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + ".");
		}

		[Command("brazier", "bz", ".lg bz", "Toggles the ability to fill braziers from a chest named 'brazier'.", null, true)]
		public static void ToggleBrazier(ChatCommandContext ctx)
		{
			bool flag = Core.PlayerSettings.ToggleBrazier(0uL);
			ctx.Reply("Global Brazier is " + (flag ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + ".");
		}

		[Command("named", "nam", ".lg nam", "Toggles the ability allow night/proximity controlled braziers.", null, true)]
		public static void ToggleSolar(ChatCommandContext ctx)
		{
			bool flag = Core.PlayerSettings.ToggleSolar(0uL);
			ctx.Reply("Global Named is " + (flag ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + ".");
		}

		[Command("settings", "s", ".lg s", "Displays current settings.", null, true)]
		public static void DisplaySettings(ChatCommandContext ctx)
		{
			PlayerSettingsService.PlayerSettings globalSettings = Core.PlayerSettings.GetGlobalSettings();
			ctx.Reply("KindredLogistics Global settings:\nSortStash: " + (globalSettings.SortStash ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + "\nPull: " + (globalSettings.Pull ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + "\nCraftPull: " + (globalSettings.CraftPull ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + "\nAutoStashMissions: " + (globalSettings.AutoStashMissions ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + "\nConveyor: " + (globalSettings.Conveyor ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + "\nSalvage: " + (globalSettings.Salvage ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + "\nUnitSpawner: " + (globalSettings.UnitSpawner ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + "\nBrazier: " + (globalSettings.Brazier ? "<color=green>enabled</color>" : "<color=red>disabled</color>") + "\nNamed: " + (globalSettings.Named ? "<color=green>enabled</color>" : "<color=red>disabled</color>"));
		}
	}
	public static class AdditionalCommands
	{
		[Command("stash", null, null, "Stashes all items in your inventory.", null, false)]
		public static void StashInventory(ChatCommandContext ctx)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			Core.Stash.StashCharacterInventory(ctx.Event.SenderCharacterEntity);
		}

		[Command("pull", null, null, "Pulls specified item from containers.", null, false)]
		public static void PullItem(ChatCommandContext ctx, FoundItem item, int quantity = 1)
		{
			//IL_0006: 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)
			PullService.PullItem(ctx.Event.SenderCharacterEntity, item.prefab, quantity);
		}

		[Command("finditem", "fi", null, "Finds the specified item in containers", null, false)]
		public static void FindItem(ChatCommandContext ctx, FoundItem item)
		{
			//IL_000b: 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)
			Core.Stash.ReportWhereItemIsLocated(ctx.Event.SenderCharacterEntity, item.prefab);
		}
	}
}
namespace KindredLogistics
{
	internal class Buffs
	{
		public delegate void BuffCreated(Entity buffEntity);

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

			private object <>2__current;

			public Entity targetEntity;

			public PrefabGUID buffPrefab;

			public Entity userEntity;

			public float duration;

			public BuffCreated callback;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0018: 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_0041: 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: Unknown result type (might be due to invalid IL or missing references)
				//IL_0052: Unknown result type (might be due to invalid IL or missing references)
				//IL_005f: 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_006b: Unknown result type (might be due to invalid IL or missing references)
				//IL_008a: 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_0096: Unknown result type (might be due to invalid IL or missing references)
				//IL_009b: Unknown result type (might be due to invalid IL or missing references)
				//IL_00af: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					RemoveBuff(targetEntity, buffPrefab);
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (BuffUtility.HasBuff<EntityManager>(Core.EntityManager, targetEntity, PrefabIdentifier.op_Implicit(buffPrefab)))
				{
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				AddBuff(userEntity, targetEntity, buffPrefab, duration);
				Entity buffEntity = default(Entity);
				if (callback != null && BuffUtility.TryGetBuff<EntityManager>(Core.Server.EntityManager, targetEntity, PrefabIdentifier.op_Implicit(buffPrefab), ref buffEntity))
				{
					callback(buffEntity);
				}
				return false;
			}

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

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

		public static bool AddBuff(Entity User, Entity Character, PrefabGUID buffPrefab, float duration = 0f, bool immortal = true)
		{
			//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_0016: 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_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_0028: 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_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_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_0057: 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_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_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_007b: 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_0083: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: 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_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_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: 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_00f4: 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_0103: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			DebugEventsSystem existingSystemManaged = Core.Server.GetExistingSystemManaged<DebugEventsSystem>();
			ApplyBuffDebugEvent val = default(ApplyBuffDebugEvent);
			val.BuffPrefabGUID = buffPrefab;
			ApplyBuffDebugEvent val2 = val;
			FromCharacter val3 = default(FromCharacter);
			val3.User = User;
			val3.Character = Character;
			FromCharacter val4 = val3;
			Entity entity = default(Entity);
			if (!BuffUtility.TryGetBuff<EntityManager>(Core.Server.EntityManager, Character, PrefabIdentifier.op_Implicit(buffPrefab), ref entity))
			{
				existingSystemManaged.ApplyBuff(val4, val2);
				if (BuffUtility.TryGetBuff<EntityManager>(Core.Server.EntityManager, Character, PrefabIdentifier.op_Implicit(buffPrefab), ref entity))
				{
					if (entity.Has<CreateGameplayEventsOnSpawn>())
					{
						entity.Remove<CreateGameplayEventsOnSpawn>();
					}
					if (entity.Has<GameplayEventListeners>())
					{
						entity.Remove<GameplayEventListeners>();
					}
					if (immortal)
					{
						entity.Add<Buff_Persists_Through_Death>();
						if (entity.Has<RemoveBuffOnGameplayEvent>())
						{
							entity.Remove<RemoveBuffOnGameplayEvent>();
						}
						if (entity.Has<RemoveBuffOnGameplayEventEntry>())
						{
							entity.Remove<RemoveBuffOnGameplayEventEntry>();
						}
					}
					if (duration > -1f && duration != 0f)
					{
						if (!entity.Has<LifeTime>())
						{
							entity.Add<LifeTime>();
							entity.Write<LifeTime>(new LifeTime
							{
								EndAction = (LifeTimeEndAction)2
							});
						}
						LifeTime componentData = entity.Read<LifeTime>();
						componentData.Duration = duration;
						entity.Write<LifeTime>(componentData);
					}
					else if (duration == -1f)
					{
						if (entity.Has<LifeTime>())
						{
							LifeTime componentData2 = entity.Read<LifeTime>();
							componentData2.Duration = -1f;
							componentData2.EndAction = (LifeTimeEndAction)0;
							entity.Write<LifeTime>(componentData2);
						}
						if (entity.Has<RemoveBuffOnGameplayEvent>())
						{
							entity.Remove<RemoveBuffOnGameplayEvent>();
						}
						if (entity.Has<RemoveBuffOnGameplayEventEntry>())
						{
							entity.Remove<RemoveBuffOnGameplayEventEntry>();
						}
					}
					return true;
				}
				return false;
			}
			return false;
		}

		public static void RemoveBuff(Entity Character, PrefabGUID buffPrefab)
		{
			//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_0007: 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)
			Entity val = default(Entity);
			if (BuffUtility.TryGetBuff<EntityManager>(Core.EntityManager, Character, PrefabIdentifier.op_Implicit(buffPrefab), ref val))
			{
				DestroyUtility.Destroy(Core.EntityManager, val, (DestroyDebugReason)13, (string)null, 0);
			}
		}

		public static void RemoveAndAddBuff(Entity userEntity, Entity targetEntity, PrefabGUID buffPrefab, float duration = -1f, BuffCreated callback = null)
		{
			//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_0007: 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_0046: 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_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)
			//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_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_003e: Unknown result type (might be due to invalid IL or missing references)
			if (!BuffUtility.HasBuff<EntityManager>(Core.EntityManager, targetEntity, PrefabIdentifier.op_Implicit(buffPrefab)))
			{
				AddBuff(userEntity, targetEntity, buffPrefab, duration);
				Entity buffEntity = default(Entity);
				if (callback != null && BuffUtility.TryGetBuff<EntityManager>(Core.Server.EntityManager, targetEntity, PrefabIdentifier.op_Implicit(buffPrefab), ref buffEntity))
				{
					callback(buffEntity);
				}
			}
			else
			{
				Core.StartCoroutine(RemoveAndAddBuffCoroutine(userEntity, targetEntity, buffPrefab, duration, callback));
			}
		}

		[IteratorStateMachine(typeof(<RemoveAndAddBuffCoroutine>d__4))]
		private static IEnumerator RemoveAndAddBuffCoroutine(Entity userEntity, Entity targetEntity, PrefabGUID buffPrefab, float duration, BuffCreated callback)
		{
			//IL_0007: 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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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)
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <RemoveAndAddBuffCoroutine>d__4(0)
			{
				userEntity = userEntity,
				targetEntity = targetEntity,
				buffPrefab = buffPrefab,
				duration = duration,
				callback = callback
			};
		}
	}
	internal class Const
	{
		public const string RECEIVER_REGEX = "r(\\d+)";

		public const string SENDER_REGEX = "s(\\d+)";
	}
	internal static class Core
	{
		public const int MAX_REPLY_LENGTH = 509;

		private static bool hasInitialized;

		private static MonoBehaviour monoBehaviour;

		public static World Server { get; } = GetWorld("Server") ?? throw new Exception("There is no Server world (yet). Did you install a server mod on the client?");


		public static EntityManager EntityManager { get; } = Server.EntityManager;


		public static GameDataSystem GameDataSystem { get; } = Server.GetExistingSystemManaged<GameDataSystem>();


		public static PrefabCollectionSystem PrefabCollectionSystem { get; internal set; }

		public static ServerGameSettingsSystem ServerGameSettingsSystem { get; internal set; }

		public static ServerScriptMapper ServerScriptMapper { get; internal set; }

		public static DebugEventsSystem DebugEventsSystem { get; internal set; }

		public static double ServerTime => ServerGameManager.ServerTime;

		public static ServerGameManager ServerGameManager => ServerScriptMapper.GetServerGameManager();

		public static ManualLogSource Log => Plugin.LogInstance;

		public static ConveyorService ConveyorService { get; internal set; }

		public static LocalizationService Localization { get; } = new LocalizationService();


		public static PlayerSettingsService PlayerSettings { get; } = new PlayerSettingsService();


		public static RefinementStationsService RefinementStations { get; internal set; }

		public static RegionService RegionService { get; internal set; }

		public static SalvageService SalvageService { get; internal set; }

		public static StashService Stash { get; } = new StashService();


		public static TerritoryService TerritoryService { get; internal set; }

		public static UnitSpawnerstationService UnitSpawnerstationService { get; internal set; }

		public static BrazierService BrazierService { get; internal set; }

		public static void LogException(Exception e, [CallerMemberName] string caller = null)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			ManualLogSource log = Log;
			bool flag = default(bool);
			BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(51, 5, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Failure in ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(caller);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\nMessage: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(e.Message);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" Inner:");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(e.InnerException?.Message);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\n\nStack: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(e.StackTrace);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\nInner Stack: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(e.InnerException?.StackTrace);
			}
			log.LogError(val);
		}

		public static void Initialize()
		{
			if (!hasInitialized)
			{
				PrefabCollectionSystem = Server.GetExistingSystemManaged<PrefabCollectionSystem>();
				ServerGameSettingsSystem = Server.GetExistingSystemManaged<ServerGameSettingsSystem>();
				DebugEventsSystem = Server.GetExistingSystemManaged<DebugEventsSystem>();
				ServerScriptMapper = Server.GetExistingSystemManaged<ServerScriptMapper>();
				RefinementStations = new RefinementStationsService();
				RegionService = new RegionService();
				SalvageService = new SalvageService();
				TerritoryService = new TerritoryService();
				UnitSpawnerstationService = new UnitSpawnerstationService();
				BrazierService = new BrazierService();
				ConveyorService = new ConveyorService();
				FoundItemConverter.LoadItemNames();
				Log.LogInfo((object)"KindredLogistics initialized");
				hasInitialized = true;
			}
		}

		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;
		}

		public static void StartCoroutine(IEnumerator routine)
		{
			//IL_0012: 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_0027: Expected O, but got Unknown
			if ((Object)(object)monoBehaviour == (Object)null)
			{
				GameObject val = new GameObject("KindredLogistics");
				monoBehaviour = (MonoBehaviour)(object)val.AddComponent<IgnorePhysicsDebugSystem>();
				Object.DontDestroyOnLoad((Object)val);
			}
			monoBehaviour.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(routine));
		}
	}
	public static class ECSExtensions
	{
		private static EntityManager EntityManager { get; } = Core.Server.EntityManager;


		public unsafe static void Write<T>(this Entity entity, T componentData) where T : struct
		{
			//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_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)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			byte[] array = StructureToByteArray(componentData);
			int num = Marshal.SizeOf<T>();
			fixed (byte* ptr = array)
			{
				EntityManager entityManager = EntityManager;
				((EntityManager)(ref entityManager)).SetComponentDataRaw(entity, val.TypeIndex, (void*)ptr, num);
			}
		}

		private static byte[] StructureToByteArray<T>(T structure) where T : struct
		{
			int num = Marshal.SizeOf(structure);
			byte[] array = new byte[num];
			IntPtr intPtr = Marshal.AllocHGlobal(num);
			Marshal.StructureToPtr(structure, intPtr, fDeleteOld: true);
			Marshal.Copy(intPtr, array, 0, num);
			Marshal.FreeHGlobal(intPtr);
			return array;
		}

		public unsafe static T Read<T>(this Entity entity) where T : struct
		{
			//IL_000d: 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_0016: 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)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = 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_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_000f: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = Core.Server.EntityManager;
			return ((EntityManager)(ref entityManager)).GetBuffer<T>(entity, false);
		}

		public static bool Has<T>(this Entity entity)
		{
			//IL_000d: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = EntityManager;
			return ((EntityManager)(ref entityManager)).HasComponent(entity, val);
		}

		public static string LookupName(this PrefabGUID prefabGuid)
		{
			//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_0012: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			PrefabLookupMap prefabLookupMap = Core.Server.GetExistingSystemManaged<PrefabCollectionSystem>()._PrefabLookupMap;
			string text = default(string);
			object obj;
			if (!((PrefabLookupMap)(ref prefabLookupMap)).TryGetName(prefabGuid, ref text))
			{
				obj = "GUID Not Found";
			}
			else
			{
				string text2 = text;
				PrefabGUID val = prefabGuid;
				obj = text2 + " " + ((object)(PrefabGUID)(ref val)).ToString();
			}
			return obj.ToString();
		}

		public static string PrefabName(this PrefabGUID prefabGuid)
		{
			//IL_0005: 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)
			string prefabName = Core.Localization.GetPrefabName(prefabGuid);
			if (!string.IsNullOrEmpty(prefabName))
			{
				return prefabName;
			}
			return prefabGuid.LookupName();
		}

		public static string EntityName(this Entity entity)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//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_0022: 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)
			NameableInteractable val = entity.Read<NameableInteractable>();
			string text = ((object)(FixedString64Bytes)(ref val.Name)).ToString();
			if (string.IsNullOrEmpty(text) && entity.Has<PrefabGUID>())
			{
				text = entity.Read<PrefabGUID>().PrefabName();
			}
			if (string.IsNullOrEmpty(text))
			{
				text = ((object)(Entity)(ref entity)).ToString();
			}
			return text;
		}

		public static void Add<T>(this Entity entity)
		{
			//IL_000d: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = EntityManager;
			((EntityManager)(ref entityManager)).AddComponent(entity, val);
		}

		public static void Remove<T>(this Entity entity)
		{
			//IL_000d: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			ComponentType val = default(ComponentType);
			((ComponentType)(ref val))..ctor(Il2CppType.Of<T>(), (AccessMode)0);
			EntityManager entityManager = EntityManager;
			((EntityManager)(ref entityManager)).RemoveComponent(entity, val);
		}
	}
	[BepInPlugin("KindredLogistics", "KindredLogistics", "1.5.7")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		private static Plugin plugin;

		private Harmony _harmony;

		public static Harmony Harmony => plugin._harmony;

		public static ManualLogSource LogInstance => ((BasePlugin)plugin).Log;

		public override void Load()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			plugin = this;
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(27, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("KindredLogistics");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" version ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.5.7");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
			}
			log.LogInfo(val);
			_harmony = new Harmony("KindredLogistics");
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			CommandRegistry.RegisterAll();
		}

		public override bool Unload()
		{
			CommandRegistry.UnregisterAssembly();
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			return true;
		}
	}
	public class Utilities
	{
		public static readonly ComponentType[] StashQuery = (ComponentType[])(object)new ComponentType[4]
		{
			ComponentType.ReadOnly(Il2CppType.Of<InventoryOwner>()),
			ComponentType.ReadOnly(Il2CppType.Of<CastleHeartConnection>()),
			ComponentType.ReadOnly(Il2CppType.Of<AttachedBuffer>()),
			ComponentType.ReadOnly(Il2CppType.Of<NameableInteractable>())
		};

		public static readonly ComponentType[] RefinementStationQuery = (ComponentType[])(object)new ComponentType[4]
		{
			ComponentType.ReadOnly(Il2CppType.Of<Team>()),
			ComponentType.ReadOnly(Il2CppType.Of<CastleHeartConnection>()),
			ComponentType.ReadOnly(Il2CppType.Of<Refinementstation>()),
			ComponentType.ReadOnly(Il2CppType.Of<NameableInteractable>())
		};

		public static readonly ComponentType[] UserEntityQuery = (ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly(Il2CppType.Of<User>()) };

		public static void StashServantInventory(Entity servant)
		{
			//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_0012: Unknown result type (might be due to invalid IL or missing references)
			Entity inventory = default(Entity);
			if (InventoryUtilities.TryGetInventoryEntity<EntityManager>(Core.EntityManager, servant, ref inventory, 0))
			{
				StashInventoryEntity(servant, inventory, "spoils");
			}
		}

		public static void StashInventoryEntity(Entity entityWithTerritory, Entity inventory, string overflowStashName)
		{
			//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_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_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Expected O, but got Unknown
			//IL_0023: 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_0045: 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_0056: 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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: 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_008a: 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_00a5: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: 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_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_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: 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_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: 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_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			ServerGameManager serverGameManager = Core.ServerGameManager;
			Dictionary<PrefabGUID, List<(Entity, Entity)>> dictionary = new Dictionary<PrefabGUID, List<(Entity, Entity)>>(100);
			(Entity, Entity) tuple = (Entity.Null, Entity.Null);
			try
			{
				Entity val2 = default(Entity);
				DynamicBuffer<AttachedBuffer> val3 = default(DynamicBuffer<AttachedBuffer>);
				foreach (Entity stash in Core.Stash.GetAllAlliedStashesOnTerritory(entityWithTerritory))
				{
					NameableInteractable val = stash.Read<NameableInteractable>();
					if (((object)(FixedString64Bytes)(ref val.Name)).ToString().ToLower().Contains(overflowStashName) && ((Entity)(ref tuple.Item1)).Equals(Entity.Null))
					{
						if (!InventoryUtilities.TryGetInventoryEntity<EntityManager>(Core.EntityManager, stash, ref val2, 0))
						{
							continue;
						}
						if (!((ServerGameManager)(ref serverGameManager)).HasFullInventory(val2))
						{
							tuple = (stash, val2);
							continue;
						}
					}
					if (!((ServerGameManager)(ref serverGameManager)).TryGetBuffer<AttachedBuffer>(stash, ref val3))
					{
						continue;
					}
					Enumerator<AttachedBuffer> enumerator2 = val3.GetEnumerator();
					while (enumerator2.MoveNext())
					{
						Entity entity = enumerator2.Current.Entity;
						if (!entity.Has<PrefabGUID>())
						{
							continue;
						}
						PrefabGUID val4 = entity.Read<PrefabGUID>();
						if (!((PrefabGUID)(ref val4)).Equals(StashService.ExternalInventoryPrefab))
						{
							continue;
						}
						Enumerator<InventoryBuffer> enumerator3 = entity.ReadBuffer<InventoryBuffer>().GetEnumerator();
						while (enumerator3.MoveNext())
						{
							PrefabGUID itemType = enumerator3.Current.ItemType;
							if (((PrefabGUID)(ref itemType)).GuidHash != 0)
							{
								if (!dictionary.TryGetValue(itemType, out var value))
								{
									value = (dictionary[itemType] = new List<(Entity, Entity)>());
								}
								else if (value.Any<(Entity, Entity)>(((Entity stash, Entity inventory) x) => x.stash == stash))
								{
									continue;
								}
								value.Add((stash, entity));
							}
						}
					}
				}
				DynamicBuffer<InventoryBuffer> val5 = default(DynamicBuffer<InventoryBuffer>);
				if (!((ServerGameManager)(ref serverGameManager)).TryGetBuffer<InventoryBuffer>(inventory, ref val5))
				{
					return;
				}
				for (int i = 0; i < val5.Length; i++)
				{
					PrefabGUID itemType2 = val5[i].ItemType;
					int num = ((ServerGameManager)(ref serverGameManager)).GetInventoryItemCount(inventory, itemType2);
					if (dictionary.TryGetValue(itemType2, out var value2))
					{
						foreach (var item in value2)
						{
							num -= TransferItems(serverGameManager, inventory, item.Item2, itemType2, num);
							if (num <= 0)
							{
								break;
							}
						}
					}
					if (num > 0 && !((Entity)(ref tuple.Item1)).Equals(Entity.Null))
					{
						TransferItems(serverGameManager, inventory, tuple.Item2, itemType2, num);
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = Core.Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val6 = new BepInExErrorLogInterpolatedStringHandler(36, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val6).AppendLiteral("Exited StashServantInventory early: ");
					((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<Exception>(ex);
				}
				log.LogError(val6);
			}
		}

		public static bool TerritoryCheck(Entity character, Entity target)
		{
			//IL_0000: 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_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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			if (!target.Has<CastleHeartConnection>())
			{
				return false;
			}
			TilePosition val = character.Read<TilePosition>();
			CastleHeartConnection val2 = target.Read<CastleHeartConnection>();
			Entity castleTerritoryEntity = ((NetworkedEntity)(ref val2.CastleHeartEntity)).GetEntityOnServer().Read<CastleHeart>().CastleTerritoryEntity;
			CastleTerritory val3 = default(CastleTerritory);
			return CastleTerritoryExtensions.IsTileInTerritory(Core.EntityManager, val.Tile, ref castleTerritoryEntity, ref val3);
		}

		public static bool SharedHeartConnection(Entity input, Entity ouput)
		{
			//IL_0000: 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_0010: 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_001b: 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_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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			if (input.Has<CastleHeartConnection>() && ouput.Has<CastleHeartConnection>())
			{
				Entity entity = input.Read<CastleHeartConnection>().CastleHeartEntity._Entity;
				Entity entity2 = ouput.Read<CastleHeartConnection>().CastleHeartEntity._Entity;
				return ((Entity)(ref entity)).Equals(entity2);
			}
			return false;
		}

		public static bool TransferItemEntities(Entity outputInventory, Entity inputInventory, PrefabGUID itemPrefab, int transferAmount, ref int startInputSlot, out int amountTransferred)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//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_0007: 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_000d: 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_0029: 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_004c: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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_0085: 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_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)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			DynamicBuffer<InventoryBuffer> val = outputInventory.ReadBuffer<InventoryBuffer>();
			DynamicBuffer<InventoryBuffer> val2 = inputInventory.ReadBuffer<InventoryBuffer>();
			amountTransferred = 0;
			for (int i = 0; i < val.Length; i++)
			{
				InventoryBuffer val3 = val[i];
				if (!((PrefabGUID)(ref val3.ItemType)).Equals(itemPrefab))
				{
					continue;
				}
				while (startInputSlot < val2.Length)
				{
					InventoryBuffer val4 = val2[startInputSlot];
					if (!((PrefabGUID)(ref val4.ItemType)).Equals(PrefabGUID.Empty))
					{
						startInputSlot++;
						continue;
					}
					val2[startInputSlot] = val3;
					val[i] = val4;
					Entity entityOnServer = ((NetworkedEntity)(ref val3.ItemEntity)).GetEntityOnServer();
					if (entityOnServer.Has<InventoryItem>())
					{
						InventoryItem componentData = entityOnServer.Read<InventoryItem>();
						componentData.ContainerEntity = inputInventory;
						entityOnServer.Write<InventoryItem>(componentData);
					}
					startInputSlot++;
					amountTransferred++;
					break;
				}
				if (amountTransferred >= transferAmount)
				{
					return false;
				}
				if (val2.Length <= startInputSlot)
				{
					return true;
				}
			}
			return false;
		}

		public static int TransferItems(ServerGameManager serverGameManager, Entity outputInventory, Entity inputInventory, PrefabGUID itemGuid, int transferAmount)
		{
			//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_000f: 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_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_001a: 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_0028: 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_0033: 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)
			if (((ServerGameManager)(ref serverGameManager)).TryRemoveInventoryItem(outputInventory, itemGuid, transferAmount))
			{
				AddItemResponse val = ((ServerGameManager)(ref serverGameManager)).TryAddInventoryItem(inputInventory, itemGuid, transferAmount);
				if ((int)val.Result == 0)
				{
					return transferAmount;
				}
				_ = ((ServerGameManager)(ref serverGameManager)).TryAddInventoryItem(outputInventory, itemGuid, val.RemainingAmount).Result;
				return transferAmount - val.RemainingAmount;
			}
			return 0;
		}

		public static AddItemSettings GetAddItemSettings()
		{
			//IL_0002: 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_000f: 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_001b: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			AddItemSettings result = default(AddItemSettings);
			result.EntityManager = Core.EntityManager;
			ServerGameManager serverGameManager = Core.ServerGameManager;
			result.ItemDataMap = ((ServerGameManager)(ref serverGameManager)).ItemLookupMap;
			return result;
		}

		public static void SendSystemMessageToClient(EntityManager entityManager, User user, string message)
		{
			//IL_0008: 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)
			FixedString512Bytes val = default(FixedString512Bytes);
			((FixedString512Bytes)(ref val))..ctor(message);
			ServerChatUtils.SendSystemMessageToClient(entityManager, user, ref val);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "KindredLogistics";

		public const string PLUGIN_NAME = "KindredLogistics";

		public const string PLUGIN_VERSION = "1.5.7";
	}
}
namespace KindredLogistics.Services
{
	internal class BrazierService
	{
		[CompilerGenerated]
		private sealed class <GetAllBraziers>d__3 : IEnumerable<Entity>, IEnumerable, IEnumerator<Entity>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private Entity <>2__current;

			private int <>l__initialThreadId;

			public BrazierService <>4__this;

			private int territoryId;

			public int <>3__territoryId;

			private NativeArray<Entity> <brazierArray>5__2;

			private Enumerator<Entity> <>7__wrap2;

			Entity IEnumerator<Entity>.Current
			{
				[DebuggerHidden]
				get
				{
					//IL_0001: Unknown result type (might be due to invalid IL or missing references)
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					//IL_0001: Unknown result type (might be due to invalid IL or missing references)
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <GetAllBraziers>d__3(int <>1__state)
			{
				this.<>1__state = <>1__state;
				<>l__initialThreadId = Environment.CurrentManagedThreadId;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || num == 1)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//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_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_005b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: Unknown result type (might be due to invalid IL or missing references)
				//IL_0066: 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_0076: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					int num = <>1__state;
					BrazierService brazierService = <>4__this;
					switch (num)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<brazierArray>5__2 = ((EntityQuery)(ref brazierService.brazierQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
						<>1__state = -3;
						<>7__wrap2 = <brazierArray>5__2.GetEnumerator();
						break;
					case 1:
						<>1__state = -3;
						break;
					}
					while (<>7__wrap2.MoveNext())
					{
						Entity current = <>7__wrap2.Current;
						if (Core.TerritoryService.GetTerritoryId(current) == territoryId)
						{
							<>2__current = current;
							<>1__state = 1;
							return true;
						}
					}
					<>m__Finally1();
					return false;
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
			}

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

			private void <>m__Finally1()
			{
				<>1__state = -1;
				<brazierArray>5__2.Dispose();
			}

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

			[DebuggerHidden]
			IEnumerator<Entity> IEnumerable<Entity>.GetEnumerator()
			{
				<GetAllBraziers>d__3 <GetAllBraziers>d__;
				if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
				{
					<>1__state = 0;
					<GetAllBraziers>d__ = this;
				}
				else
				{
					<GetAllBraziers>d__ = new <GetAllBraziers>d__3(0)
					{
						<>4__this = <>4__this
					};
				}
				<GetAllBraziers>d__.territoryId = <>3__territoryId;
				return <GetAllBraziers>d__;
			}

			[DebuggerHidden]
			IEnumerator IEnumerable.GetEnumerator()
			{
				return ((IEnumerable<Entity>)this).GetEnumerator();
			}
		}

		private EntityQuery brazierQuery;

		private Dictionary<int, HashSet<Entity>> modifiedBraziers = new Dictionary<int, HashSet<Entity>>();

		public BrazierService()
		{
			//IL_0012: 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_001c: 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_0029: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			EntityQueryBuilder val = new EntityQueryBuilder(AllocatorHandle.op_Implicit((Allocator)2));
			EntityQueryBuilder val2 = ((EntityQueryBuilder)(ref val)).AddAll(ComponentType.ReadOnly(Il2CppType.Of<Bonfire>()));
			EntityManager entityManager = Core.EntityManager;
			brazierQuery = ((EntityManager)(ref entityManager)).CreateEntityQuery(ref val2);
			((EntityQueryBuilder)(ref val2)).Dispose();
			Core.TerritoryService.RegisterTerritoryUpdateCallback(UpdateIfBraziersActiveOnTerritory);
			for (int i = 0; i <= 146; i++)
			{
				modifiedBraziers.Add(i, new HashSet<Entity>());
			}
		}

		[IteratorStateMachine(typeof(<GetAllBraziers>d__3))]
		public IEnumerable<Entity> GetAllBraziers(int territoryId)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <GetAllBraziers>d__3(-2)
			{
				<>4__this = this,
				<>3__territoryId = territoryId
			};
		}

		private void UpdateIfBraziersActiveOnTerritory(int territoryId, Entity castleHeartEntity)
		{
			//IL_000f: 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_0015: 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_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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: 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_0073: 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_00d0: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: 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_00fd: 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_0112: 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_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: 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_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: 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_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: 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_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			if (!Core.PlayerSettings.IsSolarEnabled(0uL))
			{
				return;
			}
			UserOwner val = castleHeartEntity.Read<UserOwner>();
			if (((NetworkedEntity)(ref val.Owner)).GetEntityOnServer() == Entity.Null)
			{
				return;
			}
			List<Entity> list = new List<Entity>();
			bool flag = true;
			User val2 = ((NetworkedEntity)(ref val.Owner)).GetEntityOnServer().Read<User>();
			Entity entityOnServer = ((NetworkedEntity)(ref val2.ClanEntity)).GetEntityOnServer();
			if (entityOnServer == Entity.Null)
			{
				Entity entityOnServer2 = ((NetworkedEntity)(ref val2.LocalCharacter)).GetEntityOnServer();
				if (!val2.IsConnected || Core.TerritoryService.GetTerritoryId(entityOnServer2) != territoryId)
				{
					flag = false;
				}
				else
				{
					list.Add(entityOnServer2);
				}
			}
			else
			{
				bool flag2 = false;
				EntityManager entityManager = Core.EntityManager;
				DynamicBuffer<ClanMemberStatus> buffer = ((EntityManager)(ref entityManager)).GetBuffer<ClanMemberStatus>(entityOnServer, false);
				entityManager = Core.EntityManager;
				DynamicBuffer<SyncToUserBuffer> buffer2 = ((EntityManager)(ref entityManager)).GetBuffer<SyncToUserBuffer>(entityOnServer, false);
				for (int i = 0; i < buffer.Length; i++)
				{
					if (buffer[i].IsConnected)
					{
						User val3 = buffer2[i].UserEntity.Read<User>();
						Entity entityOnServer3 = ((NetworkedEntity)(ref val3.LocalCharacter)).GetEntityOnServer();
						if (Core.TerritoryService.GetTerritoryId(entityOnServer3) == territoryId)
						{
							flag2 = true;
							list.Add(entityOnServer3);
						}
					}
				}
				if (!flag2)
				{
					flag = false;
					list.Clear();
				}
			}
			IEnumerable<Entity> allBraziers = GetAllBraziers(territoryId);
			HashSet<Entity> hashSet = modifiedBraziers[territoryId];
			foreach (Entity item in allBraziers)
			{
				NameableInteractable val4 = item.Read<NameableInteractable>();
				if (((object)(FixedString64Bytes)(ref val4.Name)).ToString().ToLower().Contains("prox"))
				{
					bool flag3 = flag;
					if (flag3)
					{
						Translation val5 = item.Read<Translation>();
						float2 xz = ((float3)(ref val5.Value)).xz;
						flag3 = false;
						foreach (Entity item2 in list)
						{
							val5 = item2.Read<Translation>();
							float2 xz2 = ((float3)(ref val5.Value)).xz;
							if (Vector2.Distance(float2.op_Implicit(xz), float2.op_Implicit(xz2)) <= 20f)
							{
								flag3 = true;
								break;
							}
						}
					}
					BurnContainer val6 = item.Read<BurnContainer>();
					if (val6.Enabled != flag3)
					{
						val6.Enabled = flag3;
						item.Write<BurnContainer>(val6);
						if (!hashSet.Contains(item))
						{
							Bonfire componentData = item.Read<Bonfire>();
							componentData.TimeToGetToFullStrength = 0.5f;
							item.Write<Bonfire>(componentData);
							hashSet.Add(item);
						}
					}
				}
				else if (hashSet.Contains(item))
				{
					hashSet.Remove(item);
					Bonfire componentData2 = item.Read<Bonfire>();
					componentData2.TimeToGetToFullStrength = 15f;
					item.Write<Bonfire>(componentData2);
				}
			}
		}
	}
	internal class ConveyorService
	{
		private readonly Random random = new Random();

		private readonly List<Entity> distributionList = new List<Entity>();

		private readonly Dictionary<Entity, int> amountReceiving = new Dictionary<Entity, int>();

		public ConveyorService()
		{
			Core.TerritoryService.RegisterTerritoryUpdateCallback(ProcessConveyors);
			Core.TerritoryService.RegisterTerritoryUpdateCallback(ProcessSalvagers);
			Core.TerritoryService.RegisterTerritoryUpdateCallback(ProcessUnitSpawners);
			Core.TerritoryService.RegisterTerritoryUpdateCallback(ProcessBraziers);
		}

		private void ProcessConveyors(int territoryId, Entity castleHeartEntity)
		{
			//IL_000f: 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_0015: 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_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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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_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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_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_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: 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_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			//IL_0368: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			//IL_037b: Unknown result type (might be due to invalid IL or missing references)
			//IL_037f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: 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_017a: 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_038d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0390: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: 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)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03db: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0408: Unknown result type (might be due to invalid IL or missing references)
			//IL_040a: Unknown result type (might be due to invalid IL or missing references)
			//IL_040f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: Unknown result type (might be due to invalid IL or missing references)
			//IL_0421: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Unknown result type (might be due to invalid IL or missing references)
			if (!Core.PlayerSettings.IsConveyorEnabled(0uL))
			{
				return;
			}
			UserOwner val = castleHeartEntity.Read<UserOwner>();
			if (((NetworkedEntity)(ref val.Owner)).GetEntityOnServer() == Entity.Null)
			{
				return;
			}
			ulong platformId = ((NetworkedEntity)(ref val.Owner)).GetEntityOnServer().Read<User>().PlatformId;
			if (!Core.PlayerSettings.IsConveyorEnabled(platformId))
			{
				return;
			}
			ServerGameManager serverGameManager = Core.ServerGameManager;
			Dictionary<(int, PrefabGUID), List<(Entity, int)>> dictionary = new Dictionary<(int, PrefabGUID), List<(Entity, int)>>();
			PrefabGUID val5;
			foreach (var allReceivingStation in Core.RefinementStations.GetAllReceivingStations(territoryId))
			{
				int item = allReceivingStation.group;
				Entity item2 = allReceivingStation.station;
				Refinementstation val2 = item2.Read<Refinementstation>();
				CastleWorkstation val3 = item2.Read<CastleWorkstation>();
				float num = (((Enum)val3.WorkstationLevel).HasFlag((Enum)(object)(WorkstationLevel)2) ? 0.75f : 1f);
				Entity entityOnServer = ((NetworkedEntity)(ref val2.InputInventoryEntity)).GetEntityOnServer();
				DynamicBuffer<InventoryBuffer> val4 = entityOnServer.ReadBuffer<InventoryBuffer>();
				Enumerator<RefinementstationRecipesBuffer> enumerator2 = item2.ReadBuffer<RefinementstationRecipesBuffer>().GetEnumerator();
				while (enumerator2.MoveNext())
				{
					RefinementstationRecipesBuffer current2 = enumerator2.Current;
					if (!current2.Unlocked || current2.Disabled)
					{
						continue;
					}
					Enumerator<RecipeRequirementBuffer> enumerator3 = Core.PrefabCollectionSystem._PrefabGuidToEntityMap[current2.RecipeGuid].ReadBuffer<RecipeRequirementBuffer>().GetEnumerator();
					while (enumerator3.MoveNext())
					{
						RecipeRequirementBuffer current3 = enumerator3.Current;
						int num2 = 2 * Mathf.RoundToInt((float)current3.Amount * num);
						Enumerator<InventoryBuffer> enumerator4 = val4.GetEnumerator();
						while (enumerator4.MoveNext())
						{
							InventoryBuffer current4 = enumerator4.Current;
							val5 = current4.ItemType;
							if (((PrefabGUID)(ref val5)).Equals(current3.Guid))
							{
								num2 -= current4.Amount;
							}
						}
						if (num2 > 0)
						{
							if (!dictionary.TryGetValue((item, current3.Guid), out var value))
							{
								value = new List<(Entity, int)>();
								dictionary[(item, current3.Guid)] = value;
							}
							value.Add((entityOnServer, num2));
						}
					}
				}
			}
			DynamicBuffer<AttachedBuffer> val7 = default(DynamicBuffer<AttachedBuffer>);
			foreach (var (item3, val6) in Core.Stash.GetAllReceivingStashes(territoryId))
			{
				if (!((ServerGameManager)(ref serverGameManager)).TryGetBuffer<AttachedBuffer>(val6, ref val7))
				{
					continue;
				}
				Enumerator<AttachedBuffer> enumerator5 = val7.GetEnumerator();
				while (enumerator5.MoveNext())
				{
					Entity entity = enumerator5.Current.Entity;
					if (!entity.Has<PrefabGUID>())
					{
						continue;
					}
					val5 = entity.Read<PrefabGUID>();
					if (!((PrefabGUID)(ref val5)).Equals(StashService.ExternalInventoryPrefab))
					{
						continue;
					}
					Enumerator<InventoryBuffer> enumerator4 = entity.ReadBuffer<InventoryBuffer>().GetEnumerator();
					while (enumerator4.MoveNext())
					{
						InventoryBuffer current5 = enumerator4.Current;
						val5 = current5.ItemType;
						if (((PrefabGUID)(ref val5)).GuidHash != 0)
						{
							if (!dictionary.TryGetValue((item3, current5.ItemType), out var value2))
							{
								value2 = new List<(Entity, int)>();
								dictionary[(item3, current5.ItemType)] = value2;
							}
							value2.Add((entity, 1));
						}
					}
				}
			}
			if (dictionary.Count == 0)
			{
				return;
			}
			foreach (var allSendingStation in Core.RefinementStations.GetAllSendingStations(territoryId))
			{
				int item4 = allSendingStation.group;
				Refinementstation val8 = allSendingStation.station.Read<Refinementstation>();
				Entity entityOnServer2 = ((NetworkedEntity)(ref val8.OutputInventoryEntity)).GetEntityOnServer();
				if (!((Entity)(ref entityOnServer2)).Equals(Entity.Null))
				{
					DistributeInventory(dictionary, serverGameManager, item4, entityOnServer2);
				}
			}
			DynamicBuffer<AttachedBuffer> val10 = default(DynamicBuffer<AttachedBuffer>);
			foreach (var (group, val9) in Core.Stash.GetAllSendingStashes(territoryId))
			{
				if (!((ServerGameManager)(ref serverGameManager)).TryGetBuffer<AttachedBuffer>(val9, ref val10))
				{
					continue;
				}
				Enumerator<AttachedBuffer> enumerator5 = val10.GetEnumerator();
				while (enumerator5.MoveNext())
				{
					Entity entity2 = enumerator5.Current.Entity;
					if (entity2.Has<PrefabGUID>())
					{
						val5 = entity2.Read<PrefabGUID>();
						if (((PrefabGUID)(ref val5)).Equals(StashService.ExternalInventoryPrefab))
						{
							DistributeInventory(dictionary, serverGameManager, group, entity2, 1);
						}
					}
				}
			}
		}

		private void DistributeInventory(Dictionary<(int group, PrefabGUID item), List<(Entity receiver, int amount)>> receivingNeeds, ServerGameManager serverGameManager, int group, Entity inventoryEntity, int retain = 0)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//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_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_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_001d: 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_0033: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: 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_0174: 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_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			Enumerator<InventoryBuffer> enumerator = inventoryEntity.ReadBuffer<InventoryBuffer>().GetEnumerator();
			while (enumerator.MoveNext())
			{
				InventoryBuffer current = enumerator.Current;
				PrefabGUID itemType = current.ItemType;
				if (((PrefabGUID)(ref itemType)).GuidHash == 0 || !receivingNeeds.TryGetValue((group, current.ItemType), out List<(Entity, int)> value))
				{
					continue;
				}
				int num = current.Amount - retain;
				if (num <= 0)
				{
					continue;
				}
				if (value.Sum<(Entity, int)>(((Entity receiver, int amount) x) => x.amount) < num)
				{
					foreach (var (inputInventory, transferAmount) in value)
					{
						Utilities.TransferItems(serverGameManager, inventoryEntity, inputInventory, current.ItemType, transferAmount);
					}
					value.Clear();
					continue;
				}
				distributionList.Clear();
				foreach (var item3 in value)
				{
					Entity item = item3.Item1;
					int item2 = item3.Item2;
					for (int i = 0; i < item2; i++)
					{
						distributionList.Add(item);
					}
				}
				amountReceiving.Clear();
				for (int j = 0; j < num; j++)
				{
					int index = random.Next(distributionList.Count);
					Entity key = distributionList[index];
					if (!amountReceiving.TryGetValue(key, out var value2))
					{
						amountReceiving[key] = 1;
					}
					else
					{
						amountReceiving[key] = value2 + 1;
					}
				}
				foreach (var (val2, num3) in amountReceiving)
				{
					Utilities.TransferItems(serverGameManager, inventoryEntity, val2, current.ItemType, num3);
					int num4 = num3;
					for (int num5 = value.Count - 1; num5 >= 0; num5--)
					{
						(Entity, int) tuple2 = value[nu