Decompiled source of ItemSpawnFix v1.0.1

ItemSpawnFix.dll

Decompiled a day ago
using System;
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 AIGraph;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Hook;
using GTFO.API;
using GTFO.API.Utilities;
using GameData;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppInterop.Runtime.Runtime;
using Il2CppInterop.Runtime.Runtime.VersionSpecific.Class;
using Il2CppInterop.Runtime.Runtime.VersionSpecific.MethodInfo;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using ItemSpawnFix.Patches;
using ItemSpawnFix.Redistribute;
using LevelGeneration;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ItemSpawnFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d90ff65cd8d0eb1f70c2fb5c2dfc2c21c357c70c")]
[assembly: AssemblyProduct("ItemSpawnFix")]
[assembly: AssemblyTitle("ItemSpawnFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace ItemSpawnFix
{
	internal static class Configuration
	{
		private static readonly ConfigEntry<bool> _showDebugMessages;

		private static readonly ConfigFile configFile;

		public static bool ShowDebugMessages => _showDebugMessages.Value;

		static Configuration()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			configFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "ItemSpawnFix.cfg"), true);
			string text = "Debug Settings";
			_showDebugMessages = configFile.Bind<bool>(text, "Enable Logs", false, "Prints information to the logs when redistributing resources.");
		}

		public static void Init()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			LiveEdit.CreateListener(Paths.ConfigPath, "ItemSpawnFix.cfg", false).FileChanged += new LiveEditEventHandler(OnFileChanged);
		}

		private static void OnFileChanged(LiveEditEventArgs _)
		{
			configFile.Reload();
		}
	}
	internal static class DinoLogger
	{
		private static ManualLogSource logger = Logger.CreateLogSource("ItemSpawnFix");

		public static void Log(string format, params object[] args)
		{
			Log(string.Format(format, args));
		}

		public static void Log(string str)
		{
			if (logger != null)
			{
				logger.Log((LogLevel)8, (object)str);
			}
		}

		public static void Warning(string format, params object[] args)
		{
			Warning(string.Format(format, args));
		}

		public static void Warning(string str)
		{
			if (logger != null)
			{
				logger.Log((LogLevel)4, (object)str);
			}
		}

		public static void Error(string format, params object[] args)
		{
			Error(string.Format(format, args));
		}

		public static void Error(string str)
		{
			if (logger != null)
			{
				logger.Log((LogLevel)2, (object)str);
			}
		}

		public static void Debug(string format, params object[] args)
		{
			Debug(string.Format(format, args));
		}

		public static void Debug(string str)
		{
			if (logger != null)
			{
				logger.Log((LogLevel)32, (object)str);
			}
		}
	}
	[BepInPlugin("Dinorush.ItemSpawnFix", "ItemSpawnFix", "1.0.1")]
	internal sealed class EntryPoint : BasePlugin
	{
		public const string MODNAME = "ItemSpawnFix";

		public override void Load()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			Configuration.Init();
			RedistributeUtils.Init();
			LG_DistributionPatches.Init();
			LG_PopulatePatches.Init();
			new Harmony("ItemSpawnFix").PatchAll();
			((BasePlugin)this).Log.LogMessage((object)"Loaded ItemSpawnFix");
		}
	}
}
namespace ItemSpawnFix.Redistribute
{
	[HarmonyPatch]
	public static class RedistributeUtils
	{
		private static readonly List<Transform> _seenAligns = new List<Transform>();

		private static readonly Dictionary<IntPtr, List<(LG_ResourceContainer_Storage storage, StorageTracker slots)>> _nodeToStorages = new Dictionary<IntPtr, List<(LG_ResourceContainer_Storage, StorageTracker)>>();

		private static StorageTracker? _currentTracker;

		public static ExpeditionFunction DistributeFunction { get; set; } = (ExpeditionFunction)0;


		public static void Init()
		{
			LevelAPI.OnBuildStart += ClearSeenData;
			LevelAPI.OnBuildDone += ClearSeenData;
		}

		private static void ClearSeenData()
		{
			_seenAligns.Clear();
		}

		[HarmonyPatch(typeof(LG_ResourceContainer_Storage), "Setup")]
		[HarmonyPostfix]
		private static void Post_Setup(LG_ResourceContainer_Storage __instance)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			if ((int)DistributeFunction != 10)
			{
				return;
			}
			AIG_CourseNode spawnNode = __instance.m_core.SpawnNode;
			if (spawnNode != null)
			{
				if (!_nodeToStorages.TryGetValue(((Il2CppObjectBase)spawnNode).Pointer, out List<(LG_ResourceContainer_Storage, StorageTracker)> value))
				{
					_nodeToStorages.Add(((Il2CppObjectBase)spawnNode).Pointer, value = new List<(LG_ResourceContainer_Storage, StorageTracker)>());
				}
				value.Add((__instance, _currentTracker = new StorageTracker(__instance)));
			}
		}

		[HarmonyPatch(typeof(LG_ResourceContainer_Storage))]
		[HarmonyPatch("SpawnResourcePack")]
		[HarmonyPatch("SpawnCommodity")]
		[HarmonyPatch("SpawnConsumable")]
		[HarmonyPatch("PlaceKeyCard")]
		[HarmonyPatch("PlaceSmallGenericPickup")]
		[HarmonyPatch("SpawnArtifact")]
		[HarmonyPostfix]
		private static void Post_SpawnItem(LG_ResourceContainer_Storage __instance, Transform align)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			if ((int)DistributeFunction != 10 || _currentTracker == null)
			{
				return;
			}
			AIG_CourseNode spawnNode = __instance.m_core.SpawnNode;
			if (spawnNode != null)
			{
				List<(LG_ResourceContainer_Storage, StorageTracker)> list = _nodeToStorages[((Il2CppObjectBase)spawnNode).Pointer];
				if (_currentTracker.RemoveAndCheckSpace(align))
				{
					list.RemoveAt(list.Count - 1);
				}
			}
		}

		public static bool TryRedistributeItems(AIG_CourseNode node, List<ResourceContainerSpawnData> items, out List<ResourceContainerSpawnData> remainingItems)
		{
			remainingItems = new List<ResourceContainerSpawnData>();
			remainingItems.EnsureCapacity(items.Count);
			Enumerator<ResourceContainerSpawnData> enumerator = items.GetEnumerator();
			while (enumerator.MoveNext())
			{
				ResourceContainerSpawnData current = enumerator.Current;
				remainingItems.Add(current);
			}
			if (!_nodeToStorages.TryGetValue(((Il2CppObjectBase)node).Pointer, out List<(LG_ResourceContainer_Storage, StorageTracker)> value) || value.Count == 0)
			{
				if (Configuration.ShowDebugMessages)
				{
					DinoLogger.Error("No valid containers to place " + GetPackListString(remainingItems) + "!");
				}
				return false;
			}
			if (Configuration.ShowDebugMessages)
			{
				DinoLogger.Log($"Found {value.Count} containers not yet filled ({value.Sum<(LG_ResourceContainer_Storage, StorageTracker)>(((LG_ResourceContainer_Storage storage, StorageTracker slots) pair) => pair.slots.Count)} available slots)");
			}
			StorageTracker currentTracker = _currentTracker;
			_currentTracker = null;
			Il2CppStructArray<int> val = Il2CppStructArray<int>.op_Implicit(Enumerable.Range(0, value.Count).ToArray());
			Builder.SessionSeedRandom.ShuffleArray<int>((Il2CppArrayBase<int>)(object)val);
			List<int> list = new List<int>();
			for (int i = 0; i < ((Il2CppArrayBase<int>)(object)val).Length; i++)
			{
				if (remainingItems.Count <= 0)
				{
					break;
				}
				var (storage, storageTracker) = value[((Il2CppArrayBase<int>)(object)val)[i]];
				while (storageTracker.Count > 0 && remainingItems.Count > 0)
				{
					if (!storageTracker.RemoveRandomAndCheckSpace(out StorageSlot slot))
					{
						list.Add(((Il2CppArrayBase<int>)(object)val)[i]);
					}
					StorageSlot storageSlot = slot;
					List<ResourceContainerSpawnData> obj = remainingItems;
					SpawnItem(storage, storageSlot, obj[obj.Count - 1]);
					remainingItems.RemoveAt(remainingItems.Count - 1);
				}
			}
			list.Sort((int a, int b) => b.CompareTo(a));
			foreach (int item in list)
			{
				value.RemoveAt(item);
			}
			_currentTracker = currentTracker;
			if (remainingItems.Count > 0)
			{
				if (Configuration.ShowDebugMessages)
				{
					DinoLogger.Error("No remaining containers to place " + GetPackListString(remainingItems) + "!");
				}
				return false;
			}
			return true;
		}

		private static void SpawnItem(LG_ResourceContainer_Storage storage, StorageSlot storageSlot, ResourceContainerSpawnData data)
		{
			//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_004f: Expected I4, but got Unknown
			int num = Builder.SessionSeedRandom.Range(0, int.MaxValue, "NO_TAG");
			eResourceContainerSpawnType type = data.m_type;
			switch ((int)type)
			{
			case 0:
			case 1:
			case 2:
			case 9:
				if ((Object)(object)storageSlot.ResourcePack != (Object)null)
				{
					storage.SpawnResourcePack(data, storageSlot.ResourcePack, num);
				}
				break;
			case 3:
				if ((Object)(object)storageSlot.CommoditySmall != (Object)null)
				{
					storage.SpawnCommodity(data, storageSlot.CommoditySmall, num);
				}
				break;
			case 4:
				if ((Object)(object)storageSlot.CommodityMedium != (Object)null)
				{
					storage.SpawnCommodity(data, storageSlot.CommodityMedium, num);
				}
				break;
			case 5:
				if ((Object)(object)storageSlot.CommodityLarge != (Object)null)
				{
					storage.SpawnCommodity(data, storageSlot.CommodityLarge, num);
				}
				break;
			case 6:
				if ((Object)(object)storageSlot.Consumable != (Object)null)
				{
					storage.SpawnConsumable(data, storageSlot.Consumable, num);
				}
				break;
			case 7:
				if ((Object)(object)storageSlot.Keycard != (Object)null)
				{
					storage.PlaceKeyCard(data, storageSlot.Keycard, num);
				}
				break;
			case 8:
				if ((Object)(object)storageSlot.Keycard != (Object)null)
				{
					storage.PlaceSmallGenericPickup(data, storageSlot.Keycard, num);
				}
				break;
			case 10:
				if ((Object)(object)storageSlot.Keycard != (Object)null)
				{
					storage.SpawnArtifact(data, storageSlot.Keycard, num);
				}
				break;
			}
		}

		public static string GetPackListString(List<ResourceContainerSpawnData> packs)
		{
			//IL_0031: 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)
			StringBuilder stringBuilder = new StringBuilder("[");
			for (int i = 0; i < packs.Count - 1; i++)
			{
				StringBuilder stringBuilder2 = stringBuilder;
				StringBuilder stringBuilder3 = stringBuilder2;
				StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(4, 2, stringBuilder2);
				handler.AppendLiteral("(");
				handler.AppendFormatted<eResourceContainerSpawnType>(packs[i].m_type);
				handler.AppendLiteral(":");
				handler.AppendFormatted(packs[i].m_ammo);
				handler.AppendLiteral("),");
				stringBuilder3.Append(ref handler);
			}
			if (packs.Count > 0)
			{
				StringBuilder stringBuilder2 = stringBuilder;
				StringBuilder stringBuilder4 = stringBuilder2;
				StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(3, 2, stringBuilder2);
				handler.AppendLiteral("(");
				handler.AppendFormatted<eResourceContainerSpawnType>(packs[packs.Count - 1].m_type);
				handler.AppendLiteral(":");
				handler.AppendFormatted(packs[packs.Count - 1].m_ammo);
				handler.AppendLiteral(")");
				stringBuilder4.Append(ref handler);
			}
			stringBuilder.Append(']');
			return stringBuilder.ToString();
		}

		public static string GetPackListString(List<ResourceContainerSpawnData> packs)
		{
			//IL_0031: 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)
			StringBuilder stringBuilder = new StringBuilder("[");
			for (int i = 0; i < packs.Count - 1; i++)
			{
				StringBuilder stringBuilder2 = stringBuilder;
				StringBuilder stringBuilder3 = stringBuilder2;
				StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(4, 2, stringBuilder2);
				handler.AppendLiteral("(");
				handler.AppendFormatted<eResourceContainerSpawnType>(packs[i].m_type);
				handler.AppendLiteral(":");
				handler.AppendFormatted(packs[i].m_ammo);
				handler.AppendLiteral("),");
				stringBuilder3.Append(ref handler);
			}
			if (packs.Count > 0)
			{
				StringBuilder stringBuilder2 = stringBuilder;
				StringBuilder stringBuilder4 = stringBuilder2;
				StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(3, 2, stringBuilder2);
				handler.AppendLiteral("(");
				handler.AppendFormatted<eResourceContainerSpawnType>(packs[packs.Count - 1].m_type);
				handler.AppendLiteral(":");
				handler.AppendFormatted(packs[packs.Count - 1].m_ammo);
				handler.AppendLiteral(")");
				stringBuilder4.Append(ref handler);
			}
			stringBuilder.Append(']');
			return stringBuilder.ToString();
		}
	}
	public class StorageTracker
	{
		private readonly List<(StorageSlot slot, HashSet<IntPtr> alignSet)> _slotAligns;

		public int Count => _slotAligns.Count;

		public StorageTracker(LG_ResourceContainer_Storage storage)
		{
			_slotAligns = new List<(StorageSlot, HashSet<IntPtr>)>();
			foreach (StorageSlot item in (Il2CppArrayBase<StorageSlot>)(object)storage.m_storageSlots)
			{
				HashSet<IntPtr> hashSet = new HashSet<IntPtr>();
				_slotAligns.Add((item, hashSet));
				TryAddAlign(item.ResourcePack, hashSet);
				TryAddAlign(item.CommoditySmall, hashSet);
				TryAddAlign(item.CommodityMedium, hashSet);
				TryAddAlign(item.CommodityLarge, hashSet);
				TryAddAlign(item.Consumable, hashSet);
				TryAddAlign(item.Keycard, hashSet);
			}
		}

		private void TryAddAlign(Transform align, HashSet<IntPtr> alignSet)
		{
			if ((Object)(object)align != (Object)null)
			{
				alignSet.Add(((Il2CppObjectBase)align).Pointer);
			}
		}

		public bool RemoveRandomAndCheckSpace(out StorageSlot slot)
		{
			int index = Builder.SessionSeedRandom.Range(0, Count, "NO_TAG");
			slot = _slotAligns[index].slot;
			_slotAligns.RemoveAt(index);
			return Count > 0;
		}

		public bool RemoveAndCheckSpace(Transform align)
		{
			Transform align2 = align;
			(StorageSlot, HashSet<IntPtr>) item = _slotAligns.First<(StorageSlot, HashSet<IntPtr>)>(((StorageSlot slot, HashSet<IntPtr> alignSet) pair) => pair.alignSet.Contains(((Il2CppObjectBase)align2).Pointer));
			_slotAligns.Remove(item);
			return Count > 0;
		}
	}
}
namespace ItemSpawnFix.Patches
{
	[HarmonyPatch]
	internal static class LG_DistributionPatches
	{
		private unsafe delegate void d_Enqueue(IntPtr _this, IntPtr item, Il2CppMethodInfo* methodInfo);

		private static bool _inDistribute;

		private static INativeDetour? GetDistributionDetour;

		private static d_Enqueue? orig_Enqueue;

		[HarmonyPatch(typeof(LG_Distribute_ResourcePacksPerZone), "Build")]
		[HarmonyPrefix]
		private static void Pre_Build()
		{
			_inDistribute = true;
		}

		[HarmonyPatch(typeof(LG_Distribute_ResourcePacksPerZone), "Build")]
		[HarmonyPostfix]
		private static void Post_Build()
		{
			_inDistribute = false;
		}

		public unsafe static void Init()
		{
			INativeClassStruct val = UnityVersionHandler.Wrap((Il2CppClass*)(void*)Il2CppClassPointerStore<DistributeItemQueueWrapper<LG_DistributeResourceContainer>>.NativeClassPtr);
			for (int i = 0; i < val.MethodCount; i++)
			{
				INativeMethodInfoStruct val2 = UnityVersionHandler.Wrap(val.Methods[i]);
				if (Marshal.PtrToStringAnsi(val2.Name) == "Enqueue")
				{
					GetDistributionDetour = INativeDetour.CreateAndApply<d_Enqueue>(val2.MethodPointer, (d_Enqueue)EnqueuePatch, ref orig_Enqueue);
					break;
				}
			}
		}

		private unsafe static void EnqueuePatch(IntPtr _this, IntPtr item, Il2CppMethodInfo* methodInfo)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_002a: 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)
			orig_Enqueue(_this, item, methodInfo);
			if (_inDistribute)
			{
				LG_DistributeItem val = new LG_DistributeItem(item);
				val.m_assignedNode.FunctionDistributionPerAreaLookup[val.m_function].Add(val);
				if (Configuration.ShowDebugMessages)
				{
					DinoLogger.Log($"New distribution created for {((Object)val.m_assignedNode.m_zone.NavInfo).ToString()} {((Object)val.m_assignedNode.m_area.m_navInfo).ToString()} of type {val.m_function} added to lookup");
				}
			}
		}
	}
	[HarmonyPatch]
	internal static class LG_PopulatePatches
	{
		private unsafe delegate void d_BuildFunc(IntPtr _this, IntPtr builder, IntPtr distItem, out IntPtr deepestSpawner, bool debug, Il2CppMethodInfo* methodInfo);

		private static INativeDetour? TriggerFunctionBuilderDetour;

		private static d_BuildFunc? orig_TriggerFunctionBuilder;

		[HarmonyPatch(typeof(LG_PopulateFunctionMarkersInZoneJob), "BuildBothFunctionAndPropMarkerAndRemoveSurplus")]
		[HarmonyWrapSafe]
		[HarmonyPriority(200)]
		[HarmonyPrefix]
		private static bool OverrideFallbackLogic(LG_PopulateFunctionMarkersInZoneJob __instance, LG_FunctionMarkerBuilder builder, LG_DistributeItem distItem)
		{
			//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_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected I4, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			if (!__instance.m_fallbackMode)
			{
				return true;
			}
			ExpeditionFunction function = distItem.m_function;
			switch (function - 8)
			{
			default:
				return true;
			case 0:
			case 2:
			case 4:
			{
				RedistributeUtils.DistributeFunction = distItem.m_function;
				LG_MarkerSpawner val = default(LG_MarkerSpawner);
				__instance.TriggerFunctionBuilder(builder, distItem, ref val, false);
				return false;
			}
			}
		}

		public unsafe static void Init()
		{
			TriggerFunctionBuilderDetour = INativeDetour.CreateAndApply<d_BuildFunc>((IntPtr)(nint)Il2CppAPI.GetIl2CppMethod<LG_PopulateFunctionMarkersInZoneJob>("TriggerFunctionBuilder", typeof(void).Name, false, new string[4]
			{
				"LG_FunctionMarkerBuilder",
				"LG_DistributeItem",
				typeof(LG_MarkerSpawner).MakeByRefType().FullName,
				typeof(bool).Name
			}), (d_BuildFunc)TriggerFunctionBuilderPatch, ref orig_TriggerFunctionBuilder);
		}

		private unsafe static void TriggerFunctionBuilderPatch(IntPtr _this, IntPtr builder, IntPtr distItem, out IntPtr deepestSpawner, bool debug, Il2CppMethodInfo* methodInfo)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//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_0018: 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: Invalid comparison between Unknown and I4
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Expected O, but got Unknown
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Invalid comparison between Unknown and I4
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Invalid comparison between Unknown and I4
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Invalid comparison between Unknown and I4
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			LG_PopulateFunctionMarkersInZoneJob val = new LG_PopulateFunctionMarkersInZoneJob(_this);
			RedistributeUtils.DistributeFunction = new LG_FunctionMarkerBuilder(builder).GetFunction();
			new LG_DistributeItem(distItem);
			if (val.m_fallbackMode && (int)RedistributeUtils.DistributeFunction == 10)
			{
				LG_DistributeResourceContainer val2 = new LG_DistributeResourceContainer(distItem);
				if (Configuration.ShowDebugMessages)
				{
					DinoLogger.Log($"No markers left in {((Object)((LG_DistributeItem)val2).m_assignedNode.m_zone.NavInfo).ToString()} {((Object)((LG_DistributeItem)val2).m_assignedNode.m_area.m_navInfo).ToString()}, redistributing {RedistributeUtils.GetPackListString(val2.m_packs)}");
				}
				deepestSpawner = IntPtr.Zero;
				if (RedistributeUtils.TryRedistributeItems(((LG_DistributeItem)val2).m_assignedNode, val2.m_packs, out List<ResourceContainerSpawnData> remainingItems))
				{
					RedistributeUtils.DistributeFunction = (ExpeditionFunction)0;
					return;
				}
				if (Configuration.ShowDebugMessages)
				{
					DinoLogger.Log("Sending remaining items to floor spawns: " + RedistributeUtils.GetPackListString(remainingItems));
				}
				val2.m_packs.Clear();
				foreach (ResourceContainerSpawnData item in remainingItems)
				{
					val2.m_packs.Add(item);
				}
				new LG_ResourceContainerBuilder(builder).m_packs = val2.m_packs;
			}
			orig_TriggerFunctionBuilder(_this, builder, distItem, out deepestSpawner, debug, methodInfo);
			if (!val.m_fallbackMode && deepestSpawner == IntPtr.Zero)
			{
				LG_DistributeItem val3 = new LG_DistributeItem(distItem);
				if (val3.m_allowFunctionFallback)
				{
					if (Configuration.ShowDebugMessages)
					{
						DinoLogger.Log($"No markers remaining for {((Object)val3.m_assignedNode.m_zone.NavInfo).ToString()} {((Object)val3.m_assignedNode.m_area.m_navInfo).ToString()}, moving to floor fallback");
					}
					ChangeGenericFallbackToSpecific(val, val3);
				}
				else
				{
					if (Configuration.ShowDebugMessages)
					{
						DinoLogger.Log($"No marker spawner found for {((Object)val3.m_assignedNode.m_zone.NavInfo).ToString()} {((Object)val3.m_assignedNode.m_area.m_navInfo).ToString()}, moving to floor fallback");
					}
					LG_ZoneDistribution distributionDataFallback = val.m_zone.DistributionDataFallback;
					if ((int)val3.m_function == 10)
					{
						distributionDataFallback.ResourceContainerItems.Enqueue(((Il2CppObjectBase)val3).Cast<LG_DistributeResourceContainer>());
					}
					else if ((int)val3.m_function == 8 || (int)val3.m_function == 12)
					{
						distributionDataFallback.PickupItems.Enqueue(((Il2CppObjectBase)val3).Cast<LG_DistributePickUpItem>());
					}
					else
					{
						distributionDataFallback.GenericFunctionItems.Enqueue(val3);
					}
				}
			}
			RedistributeUtils.DistributeFunction = (ExpeditionFunction)0;
		}

		private static void ChangeGenericFallbackToSpecific(LG_PopulateFunctionMarkersInZoneJob job, LG_DistributeItem distItem)
		{
			//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_0013: 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_002f: Expected I4, but got Unknown
			LG_ZoneDistribution distributionDataFallback = job.m_zone.DistributionDataFallback;
			ExpeditionFunction function = distItem.m_function;
			switch (function - 8)
			{
			default:
				return;
			case 2:
				distributionDataFallback.ResourceContainerItems.Enqueue(((Il2CppObjectBase)distItem).Cast<LG_DistributeResourceContainer>());
				break;
			case 0:
			case 4:
				distributionDataFallback.PickupItems.Enqueue(((Il2CppObjectBase)distItem).Cast<LG_DistributePickUpItem>());
				break;
			case 1:
			case 3:
				return;
			}
			Queue<LG_DistributeItem> itemQueue = distributionDataFallback.GenericFunctionItems.m_itemQueue;
			int num = (itemQueue._tail - 1 + itemQueue._array.Count) % itemQueue._array.Count;
			if (((Il2CppObjectBase)itemQueue._array[num]).Pointer == ((Il2CppObjectBase)distItem).Pointer)
			{
				itemQueue._array[num] = null;
				itemQueue._tail = num;
				int size = itemQueue._size;
				itemQueue._size = size - 1;
			}
		}
	}
}