Decompiled source of FindStuff v0.0.9

FindStuff.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
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 BepInEx;
using Colossal.Entities;
using Colossal.Localization;
using Colossal.Mathematics;
using Colossal.Serialization.Entities;
using Colossal.UI;
using FindStuff.Configuration;
using FindStuff.Helper;
using FindStuff.Indexing;
using FindStuff.Prefabs;
using FindStuff.Systems;
using FindStuff.UI;
using Game;
using Game.Buildings;
using Game.Common;
using Game.Net;
using Game.Notifications;
using Game.Objects;
using Game.Prefabs;
using Game.Rendering;
using Game.SceneFlow;
using Game.Settings;
using Game.Tools;
using Game.UI;
using Game.UI.InGame;
using Game.UI.Localization;
using Game.UI.Widgets;
using Game.Vehicles;
using Game.Zones;
using Gooee;
using Gooee.Plugins;
using Gooee.Plugins.Attributes;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Unity.Burst.Intrinsics;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Scripting;
using cohtml.Net;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("FindStuff")]
[assembly: AssemblyConfiguration("Release - 89")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d1399b264b33adb122343c4884ad777fb271945b")]
[assembly: AssemblyProduct("FindStuff")]
[assembly: AssemblyTitle("FindStuff")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 FindStuff
{
	[BepInPlugin("FindStuff", "FindStuff", "0.0.9")]
	public class Plugin : BaseUnityPlugin
	{
		private void Awake()
		{
			Harmony val = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "FindStuff_Cities2Harmony");
			MethodBase[] array = val.GetPatchedMethods().ToArray();
			((BaseUnityPlugin)this).Logger.LogInfo((object)(Environment.NewLine + " +-+-+-+-+ +-+-+-+-+-+\r\n |F|i|n|d| |S|t|u|f|f|\r\n +-+-+-+-+ +-+-+-+-+-+"));
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Plugin FindStuff is loaded! Patched methods: " + array.Length));
			MethodBase[] array2 = array;
			foreach (MethodBase methodBase in array2)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Patched method: " + methodBase.Module.Name + ":" + methodBase.Name));
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "FindStuff";

		public const string PLUGIN_NAME = "FindStuff";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace FindStuff.UI
{
	[ControllerDepends(/*Could not decode attribute arguments.*/)]
	public class FindStuffController : Controller<FindStuffViewModel>
	{
		private ToolSystem _toolSystem;

		private DefaultToolSystem _defaulToolSystem;

		private PickerToolSystem _pickerToolSystem;

		private PrefabSystem _prefabSystem;

		private ImageSystem _imageSystem;

		private ToolbarUISystem _toolbarUISystem;

		private PloppableRICOSystem _ploppableRICOSystem;

		private InputAction _enableAction;

		private static FieldInfo _prefabsField = typeof(PrefabSystem).GetField("m_Prefabs", BindingFlags.Instance | BindingFlags.NonPublic);

		private Dictionary<string, PrefabBase> _prefabInstances = new Dictionary<string, PrefabBase>();

		private EntityArchetype _entityArchetype;

		private EndFrameBarrier _endFrameBarrier;

		private static MethodInfo _selectAsset = typeof(ToolbarUISystem).GetMethods(BindingFlags.Instance | BindingFlags.NonPublic).FirstOrDefault((MethodInfo m) => m.Name == "SelectAsset" && m.GetParameters().Length == 1);

		public static readonly FindStuffConfig _config = ConfigBase.Load<FindStuffConfig>();

		private IBaseHelper[] _baseHelper;

		private PrefabIndexer _indexer;

		private LocalizationManager _localizationManager;

		private static HashSet<string> TypesWithNoThumbnails = new HashSet<string> { "Surface", "PropMisc", "Billboards", "Fences", "SignsAndPosters", "Accessory" };

		private static HashSet<string> ModdedComponents = new HashSet<string> { "CustomSurface", "CustomDecal", "CustomSurfaceComponent" };

		private string _lastQueryKey = "";

		private Queue<(string Key, string Json)> _queryResults = new Queue<(string, string)>();

		private FindStuffSettings _modSettings;

		private static readonly HashSet<string> GetEvilPrefabs = new HashSet<string> { "lane editor container", "traffic spawner", "NA_DeliveryVan01", "EU_DeliveryVan01", "MotorbikeDelivery01" };

		private bool IsPickingShortcut { get; set; }

		public bool IsPicking => base.Model.IsPicking;

		public bool EnableShortcut => base.Model.EnableShortcut;

		public bool ExpertMode => base.Model.ExpertMode;

		public override FindStuffViewModel Configure()
		{
			//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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			SetupResourceHandler();
			_toolSystem = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<ToolSystem>();
			_defaulToolSystem = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<DefaultToolSystem>();
			_prefabSystem = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<PrefabSystem>();
			_imageSystem = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<ImageSystem>();
			_endFrameBarrier = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<EndFrameBarrier>();
			_toolbarUISystem = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<ToolbarUISystem>();
			_pickerToolSystem = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<PickerToolSystem>();
			_ploppableRICOSystem = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<PloppableRICOSystem>();
			_localizationManager = GameManager.instance.localizationManager;
			EntityManager entityManager = ((ComponentSystemBase)this).EntityManager;
			_entityArchetype = ((EntityManager)(ref entityManager)).CreateArchetype((ComponentType[])(object)new ComponentType[2]
			{
				ComponentType.ReadWrite<Unlock>(),
				ComponentType.ReadWrite<Event>()
			});
			FindStuffViewModel findStuffViewModel = new FindStuffViewModel();
			findStuffViewModel.Favourites = _config.Favourites.ToList();
			findStuffViewModel.ViewMode = _config.ViewMode;
			findStuffViewModel.Filter = _config.Filter;
			findStuffViewModel.SubFilter = _config.SubFilter;
			if (_config.ExpertMode && findStuffViewModel.SubFilter == SubFilter.Vehicle)
			{
				findStuffViewModel.SubFilter = SubFilter.None;
			}
			findStuffViewModel.OrderByAscending = _config.OrderByAscending;
			findStuffViewModel.EnableShortcut = _config.EnableShortcut;
			findStuffViewModel.ExpertMode = _config.ExpertMode;
			findStuffViewModel.OperationMode = _config.OperationMode;
			return findStuffViewModel;
		}

		private bool CheckForModdedComponents(Entity entity)
		{
			//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_000c: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = ((ComponentSystemBase)this).EntityManager;
			List<string> list = ((IEnumerable<ComponentType>)(object)((EntityManager)(ref entityManager)).GetComponentTypes(entity, (Allocator)2)).Select((ComponentType ct) => ((ComponentType)(ref ct)).GetManagedType().FullName).ToList();
			if (list != null && list.Count > 0)
			{
				foreach (string moddedComponent in ModdedComponents)
				{
					if (list.Count((string c) => c.ToLowerInvariant().EndsWith(moddedComponent.ToLowerInvariant())) > 0)
					{
						return true;
					}
				}
			}
			return false;
		}

		protected override void OnGameLoadingComplete(Purpose purpose, GameMode mode)
		{
			//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_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_0091: 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_00a6: 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_00bb: 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_00fa: Expected O, but got Unknown
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: 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_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: 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_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			((GameSystemBase)this).OnGameLoadingComplete(purpose, mode);
			if ((int)mode != 2)
			{
				return;
			}
			FindStuffPlugin findStuffPlugin = base.Plugin as FindStuffPlugin;
			if (findStuffPlugin.Settings is FindStuffSettings modSettings)
			{
				_modSettings = modSettings;
			}
			UpdateFromSettings();
			if (_enableAction != null)
			{
				_enableAction.Disable();
				_enableAction.Dispose();
			}
			_enableAction = new InputAction("FindStuff_Toggle", (InputActionType)0, (string)null, (string)null, (string)null, (string)null);
			CompositeSyntax val = InputActionSetupExtensions.AddCompositeBinding(_enableAction, "ButtonWithOneModifier", (string)null, (string)null);
			val = ((CompositeSyntax)(ref val)).With("Modifier", "<Keyboard>/CTRL", (string)null, (string)null);
			((CompositeSyntax)(ref val)).With("Button", "<Keyboard>/f", (string)null, (string)null);
			_enableAction.performed += delegate
			{
				OnToggleVisible();
			};
			_enableAction.Enable();
			_enableAction = new InputAction("FindStuff_Escape", (InputActionType)0, (string)null, (string)null, (string)null, (string)null);
			InputActionSetupExtensions.AddBinding(_enableAction, "<Keyboard>/escape", (string)null, (string)null, (string)null);
			_enableAction.performed += delegate
			{
				OnEscapePressed();
			};
			_enableAction.Enable();
			List<PrefabBase> list = (List<PrefabBase>)_prefabsField.GetValue(_prefabSystem);
			Debug.Log((object)$"Getting {list.Count} prefabs");
			List<PrefabItem> list2 = new List<PrefabItem>();
			_baseHelper = new IBaseHelper[9]
			{
				new PlantHelper(((ComponentSystemBase)this).EntityManager),
				new TreeHelper(((ComponentSystemBase)this).EntityManager),
				new SurfaceHelper(((ComponentSystemBase)this).EntityManager),
				new CityServiceHelper(((ComponentSystemBase)this).EntityManager),
				new NetworkHelper(((ComponentSystemBase)this).EntityManager, ExpertMode),
				new SignatureBuildingHelper(((ComponentSystemBase)this).EntityManager),
				new VehicleHelper(((ComponentSystemBase)this).EntityManager, ExpertMode),
				new ZoneBuildingHelper(((ComponentSystemBase)this).EntityManager, _prefabSystem),
				new PropHelper(((ComponentSystemBase)this).EntityManager)
			};
			foreach (PrefabBase item2 in list)
			{
				if (!GetEvilPrefabs.Contains(((Object)item2).name.ToLower()) && ProcessPrefab(item2, out var prefabType, out var categoryType, out var tags, out var meta, out var thumbnailOverride))
				{
					string text = "";
					Entity entity = _prefabSystem.GetEntity(item2);
					string thumbnail = _imageSystem.GetThumbnail(entity);
					string typeIcon = GetTypeIcon(prefabType, item2, entity);
					text = ((thumbnail != null && !(thumbnail == _imageSystem.placeholderIcon)) ? thumbnail : typeIcon);
					PrefabItem item = new PrefabItem
					{
						ID = entity.Index,
						Name = ((Object)item2).name,
						IsModded = CheckForModdedComponents(entity),
						Type = prefabType,
						Category = categoryType,
						Thumbnail = ((!string.IsNullOrEmpty(thumbnailOverride)) ? thumbnailOverride : ((categoryType == "Zones") ? CheckForZoneIcon(item2, entity) : (TypesWithNoThumbnails.Contains(prefabType) ? typeIcon : text))),
						TypeIcon = typeIcon,
						Meta = meta,
						Tags = tags
					};
					list2.Add(item);
					if (_prefabInstances.ContainsKey(((Object)item2).name))
					{
						_prefabInstances.Remove(((Object)item2).name);
					}
					_prefabInstances.Add(((Object)item2).name, item2);
				}
			}
			_indexer = PrefabIndexer._instance;
			_indexer.Build(list2);
			base.Model.Prefabs = list2;
			base.TriggerUpdate();
		}

		private string CheckForZoneIcon(PrefabBase prefabBase, Entity entity)
		{
			//IL_0002: 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)
			ZoneBuildingHelper zoneBuildingHelper = new ZoneBuildingHelper(((ComponentSystemBase)this).EntityManager, _prefabSystem);
			return zoneBuildingHelper.GetZoneTypeIcon(prefabBase, entity);
		}

		protected override void OnDestroy()
		{
			((UISystemBase)this).OnDestroy();
			InputAction enableAction = _enableAction;
			if (enableAction != null)
			{
				enableAction.Disable();
			}
			InputAction enableAction2 = _enableAction;
			if (enableAction2 != null)
			{
				enableAction2.Dispose();
			}
		}

		private bool ProcessPrefab(PrefabBase prefab, out string prefabType, out string categoryType, out List<string> tags, out Dictionary<string, object> meta, out string thumbnailOverride)
		{
			//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_0047: 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_0067: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			thumbnailOverride = null;
			tags = new List<string>();
			meta = new Dictionary<string, object>();
			Entity entity = _prefabSystem.GetEntity(prefab);
			bool result = false;
			prefabType = "Unknown";
			categoryType = "None";
			IBaseHelper[] baseHelper = _baseHelper;
			foreach (IBaseHelper baseHelper2 in baseHelper)
			{
				if (baseHelper2.IsValidPrefab(prefab, entity))
				{
					result = true;
					tags = baseHelper2.CreateTags(prefab, entity);
					meta = baseHelper2.CreateMeta(prefab, entity);
					prefabType = baseHelper2.PrefabType;
					categoryType = baseHelper2.CategoryType;
					break;
				}
			}
			if (prefab is SurfacePrefab)
			{
				EntityManager entityManager = ((ComponentSystemBase)this).EntityManager;
				if (((EntityManager)(ref entityManager)).HasComponent<RenderedAreaData>(entity))
				{
					entityManager = ((ComponentSystemBase)this).EntityManager;
					if (((EntityManager)(ref entityManager)).HasComponent<SurfaceData>(entity))
					{
						entityManager = ((ComponentSystemBase)this).EntityManager;
						if (((EntityManager)(ref entityManager)).HasComponent<PrefabData>(entity))
						{
							UIObject component = ((ComponentBase)prefab).GetComponent<UIObject>();
							if ((Object)(object)component != (Object)null)
							{
								string icon = component.m_Icon;
								if (icon != null && icon.ToLowerInvariant().Contains("customsurfaces/"))
								{
									thumbnailOverride = component.m_Icon;
									goto IL_0123;
								}
							}
							thumbnailOverride = SurfaceExporter.Export(prefab);
						}
					}
				}
			}
			goto IL_0123;
			IL_0123:
			return result;
		}

		public static void SetupResourceHandler()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			GameUIResourceHandler val = (GameUIResourceHandler)GameManager.instance.userInterface.view.uiSystem.resourceHandler;
			if (val == null || ((DefaultResourceHandler)val).HostLocationsMap.ContainsKey("findstuffui"))
			{
				Debug.LogError((object)"Failed to setup resource handler for FindStuff.");
				return;
			}
			Debug.Log((object)"Setup resource handler for FindStuff.");
			((DefaultResourceHandler)val).HostLocationsMap.Add("findstuffui", new List<string> { ConfigBase.MOD_PATH });
		}

		public bool IsValidPrefab(PrefabBase prefabBase, Entity entity)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			IBaseHelper[] baseHelper = _baseHelper;
			foreach (IBaseHelper baseHelper2 in baseHelper)
			{
				if (baseHelper2.IsValidPrefab(prefabBase, entity))
				{
					return true;
				}
			}
			return false;
		}

		public bool IsValidPrefab(PrefabBase prefabBase, Entity entity, out IBaseHelper prefabHelper)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			prefabHelper = _baseHelper.FirstOrDefault();
			IBaseHelper[] baseHelper = _baseHelper;
			foreach (IBaseHelper baseHelper2 in baseHelper)
			{
				if (baseHelper2.IsValidPrefab(prefabBase, entity))
				{
					prefabHelper = baseHelper2;
					return true;
				}
			}
			return false;
		}

		private string GetTypeIcon(string type, PrefabBase prefabBase, Entity entity)
		{
			return type switch
			{
				"Plant" => "Media/Game/Icons/Forest.svg", 
				"Tree" => "Media/Game/Icons/Forest.svg", 
				"Network" => "Media/Game/Icons/Roads.svg", 
				"ServiceBuilding" => "Media/Game/Icons/Services.svg", 
				"SignatureBuilding" => "Media/Game/Icons/ZoneSignature.svg", 
				"Zoneable" => "Media/Game/Icons/Zones.svg", 
				"ZoneResidential" => "Media/Game/Icons/ZoneResidential.svg", 
				"ZoneCommercial" => "Media/Game/Icons/ZoneCommercial.svg", 
				"ZoneIndustrial" => "Media/Game/Icons/ZoneIndustrial.svg", 
				"ZoneOffice" => "Media/Game/Icons/ZoneOffice.svg", 
				"Vehicle" => "Media/Game/Icons/Traffic.svg", 
				"Surface" => "Media/Game/Icons/LotTool.svg", 
				"PropMisc" => "fa:solid-cube", 
				"SignsAndPosters" => "fa:solid-clipboard-user", 
				"Fences" => "fa:solid-xmarks-lines", 
				"Billboards" => "fa:solid-rectangle-ad", 
				"Pavement" => "Media/Game/Icons/Pathways.svg", 
				"SmallRoad" => "Media/Game/Icons/SmallRoad.svg", 
				"MediumRoad" => "Media/Game/Icons/MediumRoad.svg", 
				"LargeRoad" => "Media/Game/Icons/LargeRoad.svg", 
				"Highway" => "Media/Game/Icons/Highways.svg", 
				"RoadTool" => "Media/Game/Icons/RoadsServices.svg", 
				"OtherNetwork" => "Media/Game/Icons/Roads.svg", 
				"Park" => "Media/Game/Icons/ParksAndRecreation.svg", 
				"Parking" => "Media/Game/Icons/Parking.svg", 
				"Roundabout" => "Media/Game/Icons/Roundabouts.svg", 
				"Accessory" => "fa:solid-tree-city", 
				_ => "", 
			};
		}

		protected override void OnUpdate()
		{
			((UISystemBase)this).OnUpdate();
			if (!IsPickingShortcut && _toolSystem.activeTool == _defaulToolSystem && PickerShortcutTrigger() && !IsPicking)
			{
				IsPickingShortcut = true;
				UpdatePicker(isPicking: true);
			}
			else if (IsPickingShortcut && !PickerShortcutTrigger() && IsPicking)
			{
				IsPickingShortcut = false;
				_pickerToolSystem.RemoveLastHighlighted();
				UpdatePicker(isPicking: false);
			}
			if (_queryResults.Any() && _queryResults.TryDequeue(out (string, string) result))
			{
				GameManager.instance.userInterface.view.View.TriggerEvent<string, string>("findstuff.onReceiveResults", result.Item1, result.Item2);
			}
		}

		[OnTrigger]
		private void OnTestClick()
		{
		}

		[OnTrigger]
		private void OnTogglePicker()
		{
			UpdatePicker(!base.Model.IsPicking);
		}

		private void OnEscapePressed()
		{
			if (base.Model.IsVisible || base.Model.IsPicking)
			{
				if (base.Model.IsPicking)
				{
					UpdatePicker(isPicking: false);
					_pickerToolSystem.RemoveLastHighlighted();
				}
				else
				{
					OnToggleVisible();
				}
			}
		}

		[OnTrigger]
		private void OnToggleVisible()
		{
			base.Model.IsVisible = !base.Model.IsVisible;
			if (base.Model.OperationMode == "MoveFindStuff" && base.Model.IsVisible && !base.Model.Shifted && _toolSystem.activeTool != _defaulToolSystem)
			{
				base.Model.Shifted = true;
			}
			base.TriggerUpdate();
		}

		[OnTrigger]
		private void OnShow()
		{
			base.Model.IsVisible = true;
			base.TriggerUpdate();
		}

		[OnTrigger]
		private void OnHide()
		{
			base.Model.IsVisible = false;
			base.TriggerUpdate();
		}

		[OnTrigger]
		private void OnSelectPrefab(string name)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: 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)
			if (string.IsNullOrEmpty(name))
			{
				return;
			}
			PrefabBase val = ((List<PrefabBase>)_prefabsField.GetValue(_prefabSystem))?.FirstOrDefault((Func<PrefabBase, bool>)((PrefabBase p) => ((Object)p).name == name));
			if (!((Object)(object)val != (Object)null))
			{
				return;
			}
			Entity entity = _prefabSystem.GetEntity(val);
			if (entity != Entity.Null)
			{
				_toolSystem.ActivatePrefabTool(val);
				EntityCommandBuffer commandBuffer = ((SafeCommandBufferSystem)_endFrameBarrier).CreateCommandBuffer();
				if (IsValidPrefab(val, entity, out var prefabHelper) && prefabHelper is ZoneBuildingHelper)
				{
					_ploppableRICOSystem.MakePloppable(entity, commandBuffer);
				}
				Entity val2 = ((EntityCommandBuffer)(ref commandBuffer)).CreateEntity(_entityArchetype);
				((EntityCommandBuffer)(ref commandBuffer)).SetComponent<Unlock>(val2, new Unlock(entity));
				GameManager.instance.userInterface.view.View.ExecuteScript($"engine.trigger('toolbar.selectAsset',{{index: {entity.Index}, version: {entity.Version}}});");
			}
		}

		[OnTrigger]
		private void OnToggleFavourite(string name)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrEmpty(name))
			{
				return;
			}
			PrefabBase val = ((List<PrefabBase>)_prefabsField.GetValue(_prefabSystem))?.FirstOrDefault((Func<PrefabBase, bool>)((PrefabBase p) => ((Object)p).name == name));
			if (!((Object)(object)val != (Object)null))
			{
				return;
			}
			Entity entity = _prefabSystem.GetEntity(val);
			if (entity != Entity.Null)
			{
				if (_config.Favourites.Contains(name))
				{
					_config.Favourites.Remove(name);
				}
				else
				{
					_config.Favourites.Add(name);
				}
				_config.Save();
				base.Model.Favourites = _config.Favourites.ToList();
				base.TriggerUpdate();
			}
		}

		protected override void OnModelUpdated()
		{
			if (_config.ViewMode != base.Model.ViewMode || _config.Filter != base.Model.Filter || _config.SubFilter != base.Model.SubFilter || _config.ExpertMode != base.Model.ExpertMode || _config.OperationMode != base.Model.OperationMode || _config.EnableShortcut != base.Model.EnableShortcut || _config.OrderByAscending != base.Model.OrderByAscending)
			{
				_config.ViewMode = base.Model.ViewMode;
				_config.Filter = base.Model.Filter;
				_config.SubFilter = base.Model.SubFilter;
				_config.OrderByAscending = base.Model.OrderByAscending;
				_config.ExpertMode = base.Model.ExpertMode;
				_config.OperationMode = base.Model.OperationMode;
				_config.EnableShortcut = base.Model.EnableShortcut;
				_config.Save();
			}
			UpdateFromSettings();
		}

		private void UpdateFromSettings()
		{
			if (_modSettings != null)
			{
				if (_modSettings.EnableShortcut != base.Model.EnableShortcut)
				{
					base.Model.EnableShortcut = _modSettings.EnableShortcut;
					base.TriggerUpdate();
				}
				if (_modSettings.OperationMode != base.Model.OperationMode)
				{
					base.Model.OperationMode = _modSettings.OperationMode;
					base.TriggerUpdate();
				}
				if (_modSettings.ExpertMode != base.Model.ExpertMode)
				{
					base.Model.ExpertMode = _modSettings.ExpertMode;
					base.TriggerUpdate();
				}
			}
		}

		[OnTrigger]
		private void OnUpdateQuery()
		{
			if (base.Model == null || (Object)(object)_indexer == (Object)null)
			{
				return;
			}
			string text = _indexer.GenerateKey(base.Model);
			if (text == _lastQueryKey)
			{
				return;
			}
			_indexer.Query(Enum.TryParse<SearchSpeed>(_modSettings.SearchSpeed, out var result2) ? result2 : SearchSpeed.Medium, base.Model, delegate(string key, (string Json, int Count) result)
			{
				if (string.IsNullOrEmpty(result.Json))
				{
					Debug.LogWarning((object)"Empty JSON payload for query");
				}
				else
				{
					_queryResults.Enqueue((key, result.Json));
				}
			}, delegate
			{
				GameManager.instance.userInterface.view.View.TriggerEvent("findstuff.onShowLoader");
			});
			_lastQueryKey = text;
		}

		private bool PickerShortcutTrigger()
		{
			return EnableShortcut && Input.GetKey((KeyCode)306);
		}

		public void UpdatePicker(bool isPicking)
		{
			base.Model.IsPicking = isPicking;
			if (base.Model.IsPicking && _toolSystem.activeTool != _pickerToolSystem)
			{
				_toolSystem.activeTool = (ToolBaseSystem)(object)_pickerToolSystem;
			}
			else if (!base.Model.IsPicking && _toolSystem.activeTool == _pickerToolSystem)
			{
				_toolSystem.activeTool = (ToolBaseSystem)(object)_defaulToolSystem;
			}
			if (!base.Model.IsPicking)
			{
				IsPickingShortcut = false;
			}
			base.TriggerUpdate();
		}

		public void UpdatePrefabFromPicker(string prefabName)
		{
			(PrefabItem, Filter, SubFilter) prefab = _indexer.GetPrefab(prefabName);
			if (prefab.Item1 != null)
			{
				base.Model.Selected = prefab.Item1;
				if (!base.Model.IsVisible && base.Model.OperationMode == "HideAssetMenu")
				{
					base.Model.Filter = prefab.Item2;
					base.Model.SubFilter = prefab.Item3;
				}
			}
		}

		[OnTrigger]
		private void OnNeedHighlightPrefab(string idString)
		{
			if (string.IsNullOrEmpty(idString) || !int.TryParse(idString, out var result))
			{
				return;
			}
			(PrefabItem, Filter, SubFilter) prefab = _indexer.GetPrefab(result);
			if (prefab.Item1 != null)
			{
				base.Model.Selected = prefab.Item1;
				if (!base.Model.IsVisible && base.Model.OperationMode == "HideAssetMenu")
				{
					base.Model.Filter = prefab.Item2;
					base.Model.SubFilter = prefab.Item3;
				}
				base.TriggerUpdate();
			}
		}
	}
	[ControllerTypes(new Type[] { typeof(FindStuffController) })]
	[GooeeSettingsMenu(typeof(FindStuffSettings))]
	[PluginToolbar(typeof(FindStuffController), "OnToggleVisible", null, "Media/Game/Icons/Zones.svg")]
	public class FindStuffPlugin : IGooeePluginWithControllers, IGooeePlugin, IGooeeChangeLog, IGooeeSettings, IGooeeLanguages, IGooeeStyleSheet
	{
		public string Name => "FindStuff";

		public string Version => "1.0.0";

		public string ScriptResource => "FindStuff.Resources.ui.js";

		public string ChangeLogResource => "FindStuff.Resources.changelog.md";

		public string StyleResource => "FindStuff.Resources.ui.css";

		public IController[] Controllers { get; set; }

		public string LanguageResourceFolder => "FindStuff.Resources.lang";

		public GooeeSettings Settings { get; set; }
	}
	internal class FindStuffSettings : GooeeSettings
	{
		[SettingsUISection("Toggles")]
		public string OperationMode { get; set; }

		[SettingsUISection("Toggles")]
		public bool EnableShortcut { get; set; }

		[SettingsUISection("Toggles")]
		public bool ExpertMode { get; set; }

		[SettingsUISection("Toggles")]
		public string SearchSpeed { get; set; }

		[SettingsUIHidden]
		protected override string UIResource => "FindStuff.Resources.settings.xml";

		public override void SetDefaults()
		{
			OperationMode = "HideFindStuff";
			ExpertMode = false;
			EnableShortcut = false;
			SearchSpeed = "Medium";
		}

		[Preserve]
		public static DropdownItem<string>[] GetOperationModes()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			LocalizationManager localizationManager = GameManager.instance.localizationManager;
			return new DropdownItem<string>[3]
			{
				new DropdownItem<string>
				{
					value = "MoveFindStuff",
					displayName = LocalizedString.op_Implicit(localizationManager.GetLocalizedName("FindStuff.FindStuffSettings.MoveFindStuff"))
				},
				new DropdownItem<string>
				{
					value = "HideFindStuff",
					displayName = LocalizedString.op_Implicit(localizationManager.GetLocalizedName("FindStuff.FindStuffSettings.HideFindStuff"))
				},
				new DropdownItem<string>
				{
					value = "HideAssetMenu",
					displayName = LocalizedString.op_Implicit(localizationManager.GetLocalizedName("FindStuff.FindStuffSettings.HideAssetMenu"))
				}
			};
		}

		[Preserve]
		public static DropdownItem<string>[] GetSearchSpeeds()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
			LocalizationManager localizationManager = GameManager.instance.localizationManager;
			return new DropdownItem<string>[5]
			{
				new DropdownItem<string>
				{
					value = "VeryLow",
					displayName = LocalizedString.op_Implicit(localizationManager.GetLocalizedName("FindStuff.FindStuffSettings.SearchSpeed.VeryLow"))
				},
				new DropdownItem<string>
				{
					value = "Low",
					displayName = LocalizedString.op_Implicit(localizationManager.GetLocalizedName("FindStuff.FindStuffSettings.SearchSpeed.Low"))
				},
				new DropdownItem<string>
				{
					value = "Medium",
					displayName = LocalizedString.op_Implicit(localizationManager.GetLocalizedName("FindStuff.FindStuffSettings.SearchSpeed.Medium"))
				},
				new DropdownItem<string>
				{
					value = "High",
					displayName = LocalizedString.op_Implicit(localizationManager.GetLocalizedName("FindStuff.FindStuffSettings.SearchSpeed.High"))
				},
				new DropdownItem<string>
				{
					value = "VeryHigh",
					displayName = LocalizedString.op_Implicit(localizationManager.GetLocalizedName("FindStuff.FindStuffSettings.SearchSpeed.VeryHigh"))
				}
			};
		}
	}
	public class FindStuffViewModel : Model
	{
		public bool IsVisible { get; set; }

		public bool IsPicking { get; set; }

		public List<Category> Categories { get; set; } = PrefabIndexer._filterMappings.Select((KeyValuePair<Filter, SubFilter[]> kvp) => new Category
		{
			Filter = kvp.Key,
			SubFilters = kvp.Value.ToList()
		}).ToList();


		public bool IsWaitingQuery { get; set; }

		[JsonIgnore]
		public List<PrefabItem> Prefabs { get; set; } = new List<PrefabItem>();


		public bool OrderByAscending { get; set; } = true;


		public ViewMode ViewMode { get; set; } = ViewMode.IconGrid;


		public string Search { get; set; }

		public Filter Filter { get; set; } = Filter.None;


		public SubFilter SubFilter { get; set; } = SubFilter.None;


		public List<string> Favourites { get; set; } = new List<string>();


		public string OperationMode { get; set; }

		public bool EnableShortcut { get; set; }

		public bool ExpertMode { get; set; }

		public bool Shifted { get; set; }

		public PrefabItem Selected { get; set; }
	}
	public class PrefabItem
	{
		public int ID { get; set; }

		public string Name { get; set; }

		public string Category { get; set; }

		public string Type { get; set; }

		public string Description { get; set; }

		public string Thumbnail { get; set; }

		public string TypeIcon { get; set; }

		public bool IsModded { get; set; }

		public Dictionary<string, object> Meta { get; set; }

		public List<string> Tags { get; set; }
	}
	public class Category
	{
		public Filter Filter { get; set; }

		public List<SubFilter> SubFilters { get; set; }
	}
	public enum ViewMode
	{
		Rows = 0,
		Columns = 2,
		IconGrid = 3,
		IconGridLarge = 4,
		Detailed = 5
	}
	public enum Filter
	{
		None = 0,
		Favourite = 1,
		Foliage = 2,
		Buildings = 4,
		Zones = 5,
		Props = 6,
		Misc = 20,
		Network = 3
	}
	public enum SubFilter : long
	{
		None,
		ZoneResidential,
		ZoneCommercial,
		ZoneOffice,
		ZoneIndustrial,
		ServiceBuilding,
		SignatureBuilding,
		Park,
		Parking,
		Vehicle,
		Tree,
		Plant,
		PropMisc,
		Surface,
		SignsAndPosters,
		Fences,
		Billboards,
		Accessory,
		RoadTool,
		SmallRoad,
		MediumRoad,
		LargeRoad,
		Highway,
		Pavement,
		Roundabout,
		OtherNetwork
	}
	public enum SearchSpeed
	{
		VeryLow,
		Low,
		Medium,
		High,
		VeryHigh
	}
}
namespace FindStuff.Systems
{
	public class CheckPloppableRICOSystem : GameSystemBase
	{
		public struct MakeSignatureTypeHandle
		{
			public ComponentTypeHandle<PrefabRef> PrefabRefTypeHandle;

			public ComponentLookup<SignatureBuildingData> SignatureBuildingDataLookup;

			public ComponentLookup<PloppableBuilding> PloppableBuildingLookup;

			public ComponentLookup<SpawnableBuildingData> SpawnableBuildingDataLookup;

			public ComponentLookup<Condemned> CondemnedLookup;

			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			public void AssignHandles(ref SystemState state)
			{
				//IL_0004: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_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_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_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				PrefabRefTypeHandle = ((SystemState)(ref state)).GetComponentTypeHandle<PrefabRef>(false);
				SignatureBuildingDataLookup = ((SystemState)(ref state)).GetComponentLookup<SignatureBuildingData>(false);
				PloppableBuildingLookup = ((SystemState)(ref state)).GetComponentLookup<PloppableBuilding>(false);
				SpawnableBuildingDataLookup = ((SystemState)(ref state)).GetComponentLookup<SpawnableBuildingData>(false);
				CondemnedLookup = ((SystemState)(ref state)).GetComponentLookup<Condemned>(false);
			}
		}

		public struct MakeSignatureJob : IJobChunk
		{
			public ParallelWriter Ecb;

			public IconCommandBuffer Icb;

			public EntityTypeHandle EntityTypeHandle;

			public ComponentTypeHandle<PrefabRef> PrefabRefTypeHandle;

			public ComponentLookup<SignatureBuildingData> SignatureBuildingDataLookup;

			public ComponentLookup<PloppableBuilding> PloppableBuildingLookup;

			public ComponentLookup<SpawnableBuildingData> SpawnableBuildingDataLookup;

			public ComponentLookup<Condemned> CondemnedLookup;

			public BuildingConfigurationData BuildingConfigurationData;

			public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
			{
				//IL_0003: 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_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				//IL_0055: Unknown result type (might be due to invalid IL or missing references)
				//IL_005a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: 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_008f: Unknown result type (might be due to invalid IL or missing references)
				//IL_009e: 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_00ee: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
				//IL_0102: 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_0111: Unknown result type (might be due to invalid IL or missing references)
				//IL_0117: Unknown result type (might be due to invalid IL or missing references)
				//IL_0127: Unknown result type (might be due to invalid IL or missing references)
				//IL_00dc: 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)
				NativeArray<Entity> nativeArray = ((ArchetypeChunk)(ref chunk)).GetNativeArray(EntityTypeHandle);
				NativeArray<PrefabRef> nativeArray2 = ((ArchetypeChunk)(ref chunk)).GetNativeArray<PrefabRef>(ref PrefabRefTypeHandle);
				ChunkEntityEnumerator val = default(ChunkEntityEnumerator);
				((ChunkEntityEnumerator)(ref val))..ctor(useEnabledMask, chunkEnabledMask, ((ArchetypeChunk)(ref chunk)).Count);
				int num = default(int);
				SpawnableBuildingData val3 = default(SpawnableBuildingData);
				while (((ChunkEntityEnumerator)(ref val)).NextEntityIndex(ref num))
				{
					Entity val2 = nativeArray[num];
					Entity prefab = nativeArray2[num].m_Prefab;
					if (!SignatureBuildingDataLookup.HasComponent(prefab) && !PloppableBuildingLookup.HasComponent(prefab))
					{
						((ParallelWriter)(ref Ecb)).AddComponent<SignatureBuildingData>(num, prefab);
						((ParallelWriter)(ref Ecb)).AddComponent<PloppableBuilding>(num, prefab);
						if (SpawnableBuildingDataLookup.TryGetComponent(prefab, ref val3) && val3.m_Level < 5)
						{
							val3.m_Level = 5;
							((ParallelWriter)(ref Ecb)).SetComponent<SpawnableBuildingData>(num, prefab, val3);
						}
						if (CondemnedLookup.HasComponent(val2))
						{
							((IconCommandBuffer)(ref Icb)).Remove(val2, BuildingConfigurationData.m_CondemnedNotification, default(Entity), (IconFlags)0);
							((ParallelWriter)(ref Ecb)).RemoveComponent<Condemned>(num, val2);
						}
					}
				}
				nativeArray2.Dispose();
			}

			void IJobChunk.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
			{
				Execute(in chunk, unfilteredChunkIndex, useEnabledMask, in chunkEnabledMask);
			}
		}

		private EndFrameBarrier _barrier;

		private IconCommandSystem _iconCommandSystem;

		private EntityQuery _ploppedBuildingsGroup;

		private EntityQuery _buildingSettingsQuery;

		private MakeSignatureTypeHandle _makeSignatureTypeHandle;

		protected override void OnCreate()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//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_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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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)
			((GameSystemBase)this).OnCreate();
			_barrier = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<EndFrameBarrier>();
			_iconCommandSystem = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<IconCommandSystem>();
			EntityQueryDesc[] array = new EntityQueryDesc[1];
			EntityQueryDesc val = new EntityQueryDesc();
			val.All = (ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<PloppableBuildingData>() };
			val.None = (ComponentType[])(object)new ComponentType[2]
			{
				ComponentType.Exclude<Deleted>(),
				ComponentType.Exclude<Temp>()
			};
			array[0] = val;
			_ploppedBuildingsGroup = ((ComponentSystemBase)this).GetEntityQuery((EntityQueryDesc[])(object)array);
			_buildingSettingsQuery = ((ComponentSystemBase)this).GetEntityQuery((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<BuildingConfigurationData>() });
		}

		protected override void OnGameLoadingComplete(Purpose purpose, GameMode mode)
		{
			//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_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			//IL_006b: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: 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_00db: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: 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_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			((GameSystemBase)this).OnGameLoadingComplete(purpose, mode);
			if ((int)mode == 2 && !((EntityQuery)(ref _ploppedBuildingsGroup)).IsEmptyIgnoreFilter)
			{
				int num = ((EntityQuery)(ref _ploppedBuildingsGroup)).CalculateEntityCount();
				Debug.Log((object)$"FindStuff: Found {num} entities to update...");
				_makeSignatureTypeHandle.AssignHandles(ref ((SystemBase)this).CheckedStateRef);
				MakeSignatureJob makeSignatureJob = default(MakeSignatureJob);
				EntityCommandBuffer val = ((SafeCommandBufferSystem)_barrier).CreateCommandBuffer();
				makeSignatureJob.Ecb = ((EntityCommandBuffer)(ref val)).AsParallelWriter();
				makeSignatureJob.Icb = _iconCommandSystem.CreateCommandBuffer();
				makeSignatureJob.EntityTypeHandle = ((ComponentSystemBase)this).GetEntityTypeHandle();
				makeSignatureJob.PrefabRefTypeHandle = _makeSignatureTypeHandle.PrefabRefTypeHandle;
				makeSignatureJob.SignatureBuildingDataLookup = _makeSignatureTypeHandle.SignatureBuildingDataLookup;
				makeSignatureJob.PloppableBuildingLookup = _makeSignatureTypeHandle.PloppableBuildingLookup;
				makeSignatureJob.SpawnableBuildingDataLookup = _makeSignatureTypeHandle.SpawnableBuildingDataLookup;
				makeSignatureJob.CondemnedLookup = _makeSignatureTypeHandle.CondemnedLookup;
				makeSignatureJob.BuildingConfigurationData = ((EntityQuery)(ref _buildingSettingsQuery)).GetSingleton<BuildingConfigurationData>();
				MakeSignatureJob makeSignatureJob2 = makeSignatureJob;
				JobHandle val2 = JobChunkExtensions.ScheduleParallel<MakeSignatureJob>(makeSignatureJob2, _ploppedBuildingsGroup, ((SystemBase)this).Dependency);
				_barrier.AddJobHandleForProducer(val2);
				((SystemBase)this).Dependency = val2;
			}
		}

		protected override void OnUpdate()
		{
		}
	}
	public class PickerToolSystem : ToolBaseSystem
	{
		private PrefabSystem _prefabSystem;

		private PloppableRICOSystem _ploppableRICOSystem;

		private FindStuffController _controller;

		private Buffer _overlay;

		private ToolOutputBarrier _outputBarrier;

		private Entity _lastEntity = Entity.Null;

		public override string toolID => "PickStuff";

		[Preserve]
		public PickerToolSystem()
		{
		}//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)


		[Preserve]
		protected override void OnCreate()
		{
			_prefabSystem = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<PrefabSystem>();
			_ploppableRICOSystem = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<PloppableRICOSystem>();
			_outputBarrier = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<ToolOutputBarrier>();
			((ToolBaseSystem)this).OnCreate();
		}

		public override void InitializeRaycast()
		{
			//IL_002a: 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_004f: 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)
			((ToolBaseSystem)this).InitializeRaycast();
			base.m_ToolRaycastSystem.netLayerMask = (Layer)(-1);
			base.m_ToolRaycastSystem.typeMask = (TypeMask)14;
			ToolRaycastSystem toolRaycastSystem = base.m_ToolRaycastSystem;
			toolRaycastSystem.raycastFlags = (RaycastFlags)(toolRaycastSystem.raycastFlags | 0x40E0);
			base.m_ToolRaycastSystem.collisionMask = (CollisionMask)3;
			ToolRaycastSystem toolRaycastSystem2 = base.m_ToolRaycastSystem;
			toolRaycastSystem2.raycastFlags = (RaycastFlags)(toolRaycastSystem2.raycastFlags & -9);
		}

		private void DrawNetCurve(NetCompositionData compositionData, EdgeGeometry edgeGeometry)
		{
			//IL_001c: 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)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_0049: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			Color val = default(Color);
			((Color)(ref val))..ctor(1f, 1f, 0f, 0.5f);
			float num = compositionData.m_Width / 2f;
			Bezier4x3 val2 = NetUtils.OffsetCurveLeftSmooth(edgeGeometry.m_Start.m_Left, float2.op_Implicit(0f - num));
			((Buffer)(ref _overlay)).DrawCurve(val, val2, compositionData.m_Width);
			Bezier4x3 val3 = NetUtils.OffsetCurveLeftSmooth(edgeGeometry.m_End.m_Left, float2.op_Implicit(0f - num));
			((Buffer)(ref _overlay)).DrawCurve(val, val3, compositionData.m_Width);
		}

		[Preserve]
		protected override JobHandle OnUpdate(JobHandle inputDeps)
		{
			//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_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: 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_010f: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_0136: 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_015f: 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_014a: 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_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_01cb: 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_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: 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_01e0: 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_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			RemoveLastHighlighted();
			if (_prefabSystem != null)
			{
				OverlayRenderSystem existingSystemManaged = ((ComponentSystemBase)this).World.GetExistingSystemManaged<OverlayRenderSystem>();
				if (existingSystemManaged != null)
				{
					_controller = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<FindStuffController>();
					JobHandle val = default(JobHandle);
					_overlay = existingSystemManaged.GetBuffer(ref val);
				}
			}
			Entity val2 = default(Entity);
			RaycastHit val3 = default(RaycastHit);
			if (_controller.IsPicking && _controller != null && ((ToolBaseSystem)this).GetRaycastResult(ref val2, ref val3))
			{
				PrefabRef val4 = default(PrefabRef);
				PrefabBase val5 = default(PrefabBase);
				if (EntitiesExtensions.TryGetComponent<PrefabRef>(((ComponentSystemBase)this).EntityManager, val2, ref val4) && _prefabSystem.TryGetPrefab<PrefabBase>(val4.m_Prefab, ref val5) && (_controller.IsValidPrefab(val5, val2) || HasComponents(val2)))
				{
					Color val6 = default(Color);
					((Color)(ref val6))..ctor(1f, 1f, 0f, 0.2f);
					Transform val7 = default(Transform);
					if (EntitiesExtensions.TryGetComponent<Transform>(((ComponentSystemBase)this).EntityManager, val2, ref val7))
					{
						((Buffer)(ref _overlay)).DrawCircle(val6, val7.m_Position, 8f);
					}
					Curve val8 = default(Curve);
					Composition val9 = default(Composition);
					NetCompositionData compositionData = default(NetCompositionData);
					EdgeGeometry edgeGeometry = default(EdgeGeometry);
					if (EntitiesExtensions.TryGetComponent<Curve>(((ComponentSystemBase)this).EntityManager, val2, ref val8) && EntitiesExtensions.TryGetComponent<Composition>(((ComponentSystemBase)this).EntityManager, val2, ref val9) && EntitiesExtensions.TryGetComponent<NetCompositionData>(((ComponentSystemBase)this).EntityManager, val9.m_Edge, ref compositionData) && EntitiesExtensions.TryGetComponent<EdgeGeometry>(((ComponentSystemBase)this).EntityManager, val2, ref edgeGeometry))
					{
						DrawNetCurve(compositionData, edgeGeometry);
					}
					if (Input.GetKeyDown((KeyCode)323))
					{
						base.m_ToolSystem.activeTool = (ToolBaseSystem)(object)base.m_DefaultToolSystem;
						_controller.UpdatePrefabFromPicker(((Object)val5).name);
						_controller.UpdatePicker(isPicking: false);
						base.m_ToolSystem.ActivatePrefabTool(val5);
						if (_ploppableRICOSystem.IsPloppable(val5, val4.m_Prefab, val2))
						{
							Entity entity = _prefabSystem.GetEntity(val5);
							_ploppableRICOSystem.MakePloppable(entity, ((SafeCommandBufferSystem)_outputBarrier).CreateCommandBuffer());
						}
						Unhighlight(val2);
						return ((ToolBaseSystem)this).OnUpdate(inputDeps);
					}
					Highlight(val2);
				}
				_lastEntity = val2;
			}
			return ((ToolBaseSystem)this).OnUpdate(inputDeps);
		}

		private void Highlight(Entity entity)
		{
			//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_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_001f: 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_002f: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = ((ComponentSystemBase)this).EntityManager;
			if (!((EntityManager)(ref entityManager)).HasComponent<Highlighted>(entity))
			{
				entityManager = ((ComponentSystemBase)this).EntityManager;
				((EntityManager)(ref entityManager)).AddComponent<Highlighted>(entity);
				entityManager = ((ComponentSystemBase)this).EntityManager;
				((EntityManager)(ref entityManager)).AddComponent<Updated>(entity);
			}
		}

		private void Unhighlight(Entity entity)
		{
			//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_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = ((ComponentSystemBase)this).EntityManager;
			if (((EntityManager)(ref entityManager)).HasComponent<Highlighted>(entity))
			{
				entityManager = ((ComponentSystemBase)this).EntityManager;
				((EntityManager)(ref entityManager)).RemoveComponent<Highlighted>(entity);
				entityManager = ((ComponentSystemBase)this).EntityManager;
				((EntityManager)(ref entityManager)).AddComponent<Updated>(entity);
			}
		}

		public void RemoveLastHighlighted()
		{
			//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_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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_0039: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			if (_lastEntity != Entity.Null)
			{
				EntityManager entityManager = ((ComponentSystemBase)this).EntityManager;
				if (((EntityManager)(ref entityManager)).HasComponent<Highlighted>(_lastEntity))
				{
					entityManager = ((ComponentSystemBase)this).EntityManager;
					((EntityManager)(ref entityManager)).RemoveComponent<Highlighted>(_lastEntity);
					entityManager = ((ComponentSystemBase)this).EntityManager;
					((EntityManager)(ref entityManager)).AddComponent<Updated>(_lastEntity);
				}
			}
		}

		private bool HasComponents(Entity entity)
		{
			//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_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_001b: 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_0032: 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_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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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_0065: 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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = ((ComponentSystemBase)this).EntityManager;
			int result;
			if (!((EntityManager)(ref entityManager)).HasComponent<Deleted>(entity))
			{
				entityManager = ((ComponentSystemBase)this).EntityManager;
				if (!((EntityManager)(ref entityManager)).HasComponent<Temp>(entity))
				{
					entityManager = ((ComponentSystemBase)this).EntityManager;
					if (!((EntityManager)(ref entityManager)).HasComponent<Building>(entity))
					{
						entityManager = ((ComponentSystemBase)this).EntityManager;
						if (!((EntityManager)(ref entityManager)).HasComponent<Vehicle>(entity))
						{
							entityManager = ((ComponentSystemBase)this).EntityManager;
							if (!((EntityManager)(ref entityManager)).HasComponent<Tree>(entity))
							{
								entityManager = ((ComponentSystemBase)this).EntityManager;
								if (!((EntityManager)(ref entityManager)).HasComponent<Node>(entity))
								{
									entityManager = ((ComponentSystemBase)this).EntityManager;
									if (!((EntityManager)(ref entityManager)).HasComponent<Edge>(entity))
									{
										entityManager = ((ComponentSystemBase)this).EntityManager;
										if (!((EntityManager)(ref entityManager)).HasComponent<Plant>(entity))
										{
											entityManager = ((ComponentSystemBase)this).EntityManager;
											result = (((EntityManager)(ref entityManager)).HasComponent<Curve>(entity) ? 1 : 0);
											goto IL_00a4;
										}
									}
								}
							}
						}
					}
					result = 1;
					goto IL_00a4;
				}
			}
			return false;
			IL_00a4:
			return (byte)result != 0;
		}

		public override PrefabBase GetPrefab()
		{
			return null;
		}

		public override bool TrySetPrefab(PrefabBase prefab)
		{
			return false;
		}
	}
	public class PloppableRICOSystem : GameSystemBase
	{
		public struct MakePloppableTypeHandle
		{
			public EntityTypeHandle EntityTypeHandle;

			public ComponentTypeHandle<PrefabRef> PrefabRefTypeHandle;

			public ComponentLookup<PloppableBuilding> PloppableBuildingLookup;

			public ComponentLookup<Condemned> CondemnedLookup;

			[MethodImpl(MethodImplOptions.AggressiveInlining)]
			public void AssignHandles(ref SystemState state)
			{
				//IL_0003: 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_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_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_002f: Unknown result type (might be due to invalid IL or missing references)
				EntityTypeHandle = ((SystemState)(ref state)).GetEntityTypeHandle();
				PrefabRefTypeHandle = ((SystemState)(ref state)).GetComponentTypeHandle<PrefabRef>(false);
				PloppableBuildingLookup = ((SystemState)(ref state)).GetComponentLookup<PloppableBuilding>(false);
				CondemnedLookup = ((SystemState)(ref state)).GetComponentLookup<Condemned>(false);
			}
		}

		public struct MakePloppableJob : IJobChunk
		{
			public ParallelWriter Ecb;

			public IconCommandBuffer Icb;

			public BuildingConfigurationData BuildingConfigurationData;

			public EntityTypeHandle EntityHandle;

			public ComponentTypeHandle<PrefabRef> PrefabRefTypeHandle;

			public ComponentLookup<PloppableBuilding> PloppableBuildingLookup;

			public ComponentLookup<Condemned> CondemnedLookup;

			public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
			{
				//IL_0003: 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_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				//IL_0055: Unknown result type (might be due to invalid IL or missing references)
				//IL_005a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: 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_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0088: Unknown result type (might be due to invalid IL or missing references)
				//IL_0096: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
				NativeArray<Entity> nativeArray = ((ArchetypeChunk)(ref chunk)).GetNativeArray(EntityHandle);
				NativeArray<PrefabRef> nativeArray2 = ((ArchetypeChunk)(ref chunk)).GetNativeArray<PrefabRef>(ref PrefabRefTypeHandle);
				ChunkEntityEnumerator val = default(ChunkEntityEnumerator);
				((ChunkEntityEnumerator)(ref val))..ctor(useEnabledMask, chunkEnabledMask, ((ArchetypeChunk)(ref chunk)).Count);
				int num = default(int);
				while (((ChunkEntityEnumerator)(ref val)).NextEntityIndex(ref num))
				{
					Entity val2 = nativeArray[num];
					Entity prefab = nativeArray2[num].m_Prefab;
					if (PloppableBuildingLookup.HasComponent(prefab) && val2 != Entity.Null)
					{
						((ParallelWriter)(ref Ecb)).AddComponent<PloppableBuildingData>(num, val2);
						if (CondemnedLookup.HasComponent(val2))
						{
							((IconCommandBuffer)(ref Icb)).Remove(val2, BuildingConfigurationData.m_CondemnedNotification, default(Entity), (IconFlags)0);
							((ParallelWriter)(ref Ecb)).RemoveComponent<Condemned>(num, val2);
						}
					}
				}
				nativeArray2.Dispose();
				nativeArray.Dispose();
			}

			void IJobChunk.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
			{
				Execute(in chunk, unfilteredChunkIndex, useEnabledMask, in chunkEnabledMask);
			}
		}

		private ModificationBarrier5 _barrier;

		private IconCommandSystem _iconCommandSystem;

		private EntityQuery _freshlyPlacedBuildingsGroup;

		private EntityQuery _buildingSettingsQuery;

		private MakePloppableTypeHandle _makePloppableTypeHandle;

		protected override void OnCreate()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: 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_00fc: 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_0110: 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_011a: 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_0126: Unknown result type (might be due to invalid IL or missing references)
			((GameSystemBase)this).OnCreate();
			_barrier = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<ModificationBarrier5>();
			_iconCommandSystem = ((ComponentSystemBase)this).World.GetOrCreateSystemManaged<IconCommandSystem>();
			EntityQueryDesc[] array = new EntityQueryDesc[1];
			EntityQueryDesc val = new EntityQueryDesc();
			val.All = (ComponentType[])(object)new ComponentType[4]
			{
				ComponentType.ReadOnly<Building>(),
				ComponentType.ReadOnly<PrefabRef>(),
				ComponentType.ReadOnly<PropertyToBeOnMarket>(),
				ComponentType.ReadOnly<BuildingCondition>()
			};
			val.Any = (ComponentType[])(object)new ComponentType[4]
			{
				ComponentType.ReadOnly<ResidentialProperty>(),
				ComponentType.ReadOnly<CommercialProperty>(),
				ComponentType.ReadOnly<IndustrialProperty>(),
				ComponentType.ReadOnly<OfficeProperty>()
			};
			val.None = (ComponentType[])(object)new ComponentType[5]
			{
				ComponentType.Exclude<PropertyOnMarket>(),
				ComponentType.Exclude<UnderConstruction>(),
				ComponentType.Exclude<PloppableBuildingData>(),
				ComponentType.Exclude<Deleted>(),
				ComponentType.Exclude<Temp>()
			};
			array[0] = val;
			_freshlyPlacedBuildingsGroup = ((ComponentSystemBase)this).GetEntityQuery((EntityQueryDesc[])(object)array);
			_buildingSettingsQuery = ((ComponentSystemBase)this).GetEntityQuery((ComponentType[])(object)new ComponentType[1] { ComponentType.ReadOnly<BuildingConfigurationData>() });
			((ComponentSystemBase)this).RequireForUpdate(_freshlyPlacedBuildingsGroup);
		}

		protected override void OnGameLoadingComplete(Purpose purpose, GameMode mode)
		{
			//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)
			((GameSystemBase)this).OnGameLoadingComplete(purpose, mode);
		}

		protected override void OnUpdate()
		{
			//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_0052: 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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			if (!((EntityQuery)(ref _freshlyPlacedBuildingsGroup)).IsEmptyIgnoreFilter && !((EntityQuery)(ref _buildingSettingsQuery)).IsEmptyIgnoreFilter)
			{
				_makePloppableTypeHandle.AssignHandles(ref ((SystemBase)this).CheckedStateRef);
				MakePloppableJob makePloppableJob = default(MakePloppableJob);
				EntityCommandBuffer val = ((SafeCommandBufferSystem)_barrier).CreateCommandBuffer();
				makePloppableJob.Ecb = ((EntityCommandBuffer)(ref val)).AsParallelWriter();
				makePloppableJob.Icb = _iconCommandSystem.CreateCommandBuffer();
				makePloppableJob.BuildingConfigurationData = ((EntityQuery)(ref _buildingSettingsQuery)).GetSingleton<BuildingConfigurationData>();
				makePloppableJob.EntityHandle = _makePloppableTypeHandle.EntityTypeHandle;
				makePloppableJob.PrefabRefTypeHandle = _makePloppableTypeHandle.PrefabRefTypeHandle;
				makePloppableJob.PloppableBuildingLookup = _makePloppableTypeHandle.PloppableBuildingLookup;
				makePloppableJob.CondemnedLookup = _makePloppableTypeHandle.CondemnedLookup;
				MakePloppableJob makePloppableJob2 = makePloppableJob;
				JobHandle val2 = JobChunkExtensions.ScheduleParallel<MakePloppableJob>(makePloppableJob2, _freshlyPlacedBuildingsGroup, ((SystemBase)this).Dependency);
				((EntityCommandBufferSystem)_barrier).AddJobHandleForProducer(val2);
				((SystemBase)this).Dependency = val2;
			}
		}

		public bool IsPloppable(PrefabBase prefabBase, Entity prefabEntity, Entity originalEntity)
		{
			//IL_0001: 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_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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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)
			if (originalEntity == Entity.Null || prefabEntity == Entity.Null)
			{
				return false;
			}
			EntityManager entityManager = ((ComponentSystemBase)this).EntityManager;
			if (((EntityManager)(ref entityManager)).HasComponent<Signature>(originalEntity))
			{
				return false;
			}
			if (!(prefabBase is BuildingPrefab))
			{
				return false;
			}
			SpawnableBuildingData val = default(SpawnableBuildingData);
			return EntitiesExtensions.TryGetComponent<SpawnableBuildingData>(((ComponentSystemBase)this).EntityManager, prefabEntity, ref val) && val.m_ZonePrefab != Entity.Null;
		}

		public void MakePloppable(Entity entity)
		{
			//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_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: 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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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)
			SpawnableBuildingData val = default(SpawnableBuildingData);
			if (EntitiesExtensions.TryGetComponent<SpawnableBuildingData>(((ComponentSystemBase)this).EntityManager, entity, ref val))
			{
				EntityCommandBuffer val2 = ((SafeCommandBufferSystem)_barrier).CreateCommandBuffer();
				((EntityCommandBuffer)(ref val2)).AddComponent<PloppableBuilding>(entity, default(PloppableBuilding));
				((EntityCommandBuffer)(ref val2)).AddComponent<SignatureBuildingData>(entity, default(SignatureBuildingData));
				val.m_Level = 5;
				((EntityCommandBuffer)(ref val2)).SetComponent<SpawnableBuildingData>(entity, val);
			}
		}

		public void MakePloppable(Entity entity, EntityCommandBuffer commandBuffer)
		{
			//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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			SpawnableBuildingData val = default(SpawnableBuildingData);
			if (EntitiesExtensions.TryGetComponent<SpawnableBuildingData>(((ComponentSystemBase)this).EntityManager, entity, ref val))
			{
				((EntityCommandBuffer)(ref commandBuffer)).AddComponent<PloppableBuilding>(entity, default(PloppableBuilding));
				((EntityCommandBuffer)(ref commandBuffer)).AddComponent<SignatureBuildingData>(entity, default(SignatureBuildingData));
				val.m_Level = 5;
				((EntityCommandBuffer)(ref commandBuffer)).SetComponent<SpawnableBuildingData>(entity, val);
			}
		}
	}
}
namespace FindStuff.Prefabs
{
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	public struct PloppableBuilding : IComponentData, IQueryTypeParameter, IEmptySerializable
	{
	}
	[StructLayout(LayoutKind.Sequential, Size = 1)]
	public struct PloppableBuildingData : IComponentData, IQueryTypeParameter, IEmptySerializable
	{
	}
}
namespace FindStuff.Patches
{
	[HarmonyPatch(typeof(BulldozeToolSystem))]
	public static class BulldozeToolSystem_Patches
	{
		[HarmonyPatch("ConfirmationNeeded")]
		[HarmonyPrefix]
		public static bool Prefix(BulldozeToolSystem __instance, ref bool __result)
		{
			//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_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0048: 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_0051: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			EntityQuery value = Traverse.Create((object)__instance).Field<EntityQuery>("m_BuildingQuery").Value;
			EntityManager entityManager = ((ComponentSystemBase)__instance).EntityManager;
			NativeArray<Entity> val = ((EntityQuery)(ref value)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)3));
			bool flag = false;
			PrefabRef val3 = default(PrefabRef);
			for (int i = 0; i < val.Length; i++)
			{
				Entity val2 = val[i];
				if ((((EntityManager)(ref entityManager)).GetComponentData<Temp>(val2).m_Flags & 2) != 0 && EntitiesExtensions.TryGetComponent<PrefabRef>(entityManager, val2, ref val3) && (!((EntityManager)(ref entityManager)).HasComponent<SpawnableBuildingData>(val3.m_Prefab) || (!((EntityManager)(ref entityManager)).HasComponent<PloppableBuilding>(val3.m_Prefab) && ((EntityManager)(ref entityManager)).HasComponent<SignatureBuildingData>(val3.m_Prefab))))
				{
					flag = true;
				}
			}
			val.Dispose();
			__result = flag;
			return false;
		}
	}
	[HarmonyPatch(typeof(SystemOrder))]
	internal class SystemOrderPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(SystemOrder), "Initialize")]
		public static void GetSystemOrder(UpdateSystem updateSystem)
		{
			if (updateSystem != null)
			{
				updateSystem.UpdateAt<CheckPloppableRICOSystem>((SystemUpdatePhase)12);
			}
			if (updateSystem != null)
			{
				updateSystem.UpdateAt<PloppableRICOSystem>((SystemUpdatePhase)8);
			}
		}
	}
}
namespace FindStuff.Indexing
{
	public class PrefabIndexer : MonoBehaviour
	{
		private static JsonSerializerSettings _jsonSettings;

		public static readonly Dictionary<Filter, SubFilter[]> _filterMappings;

		private static readonly LocalizationManager _localisationManager;

		private ReadOnlyDictionary<int, PrefabItem> _prefabs;

		private ReadOnlyDictionary<int, string> _prefabNames;

		private ReadOnlyDictionary<int, string> _prefabTypesNames;

		private ReadOnlyDictionary<int, string> _prefabDisplayNames;

		private ReadOnlyDictionary<int, HashSet<string>> _prefabTags;

		private readonly HashSet<Filter> _filters;

		private readonly HashSet<SubFilter> _subFilters;

		private ReadOnlyDictionary<Filter, int[]> _filterPrefabs;

		private ReadOnlyDictionary<SubFilter, int[]> _subFilterPrefabs;

		private HashSet<int> _favouritePrefabs;

		private Stopwatch _stopWatch;

		private int _searchFrameBatches;

		private Queue<int> _prefabSearchQueue;

		public static readonly PrefabIndexer _instance;

		private WorkingSearchData WorkingSet { get; set; }

		private string LastWorkingSetKey { get; set; }

		private Dictionary<string, (string Json, int Count)> BigQueryCache { get; set; }

		public bool QueryInProgress => WorkingSet != null;

		static PrefabIndexer()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Expected O, but got Unknown
			JsonSerializerSettings val = new JsonSerializerSettings();
			val.DefaultValueHandling = (DefaultValueHandling)2;
			val.NullValueHandling = (NullValueHandling)0;
			val.Converters = (IList<JsonConverter>)(object)new StringEnumConverter[1]
			{
				new StringEnumConverter()
			};
			_jsonSettings = val;
			_filterMappings = new Dictionary<Filter, SubFilter[]>
			{
				{
					Filter.Foliage,
					new SubFilter[2]
					{
						SubFilter.Tree,
						SubFilter.Plant
					}
				},
				{
					Filter.Buildings,
					new SubFilter[4]
					{
						SubFilter.ServiceBuilding,
						SubFilter.SignatureBuilding,
						SubFilter.Park,
						SubFilter.Parking
					}
				},
				{
					Filter.Zones,
					new SubFilter[4]
					{
						SubFilter.ZoneResidential,
						SubFilter.ZoneCommercial,
						SubFilter.ZoneIndustrial,
						SubFilter.ZoneOffice
					}
				},
				{
					Filter.Props,
					new SubFilter[5]
					{
						SubFilter.Billboards,
						SubFilter.Fences,
						SubFilter.SignsAndPosters,
						SubFilter.Accessory,
						SubFilter.PropMisc
					}
				},
				{
					Filter.Network,
					new SubFilter[8]
					{
						SubFilter.RoadTool,
						SubFilter.SmallRoad,
						SubFilter.MediumRoad,
						SubFilter.LargeRoad,
						SubFilter.Highway,
						SubFilter.Roundabout,
						SubFilter.Pavement,
						SubFilter.OtherNetwork
					}
				},
				{
					Filter.Misc,
					new SubFilter[1] { SubFilter.Surface }
				}
			};
			_localisationManager = GameManager.instance.localizationManager;
			if (!((Object)(object)_instance != (Object)null))
			{
				GameObject val2 = GameObject.Find("FindStuff_PrefabIndexer");
				if ((Object)(object)val2 != (Object)null)
				{
					Object.Destroy((Object)(object)val2);
				}
				GameObject val3 = new GameObject("FindStuff_PrefabIndexer");
				Object.DontDestroyOnLoad((Object)(object)val3);
				_instance = val3.AddComponent<PrefabIndexer>();
			}
		}

		private void Start()
		{
		}

		private void Update()
		{
			if (_prefabSearchQueue.Any())
			{
				((MonoBehaviour)this).StartCoroutine(ProcessSearchQueue());
			}
		}

		private IEnumerator ProcessSearchQueue()
		{
			if (_prefabSearchQueue.Count == 0 || WorkingSet == null)
			{
				yield return null;
			}
			int searchCount = Math.Min(_searchFrameBatches, _prefabSearchQueue.Count);
			for (int i = 0; i < searchCount; i++)
			{
				if (WorkingSet == null)
				{
					yield return null;
				}
				if (_prefabSearchQueue.TryDequeue(out var id))
				{
					WorkingSet.Add(id, (string search, int orderByAscending) => StringSearch(search, id) || WordSearch(search, id));
				}
				if (i >= _prefabSearchQueue.Count - 1)
				{
					break;
				}
			}
			if (_prefabSearchQueue.Count == 0 && WorkingSet != null)
			{
				ProcessOrderBy();
				GatherResult();
				PresentResults();
			}
			yield return null;
		}

		private void PresentResults()
		{
			if (WorkingSet != null)
			{
				WorkingSet.OnComplete?.Invoke(WorkingSet.Key, WorkingSet.Cache);
				ClearWorkingSet();
			}
		}

		private bool IsFilterPrefab(PrefabItem prefab)
		{
			if (!Enum.TryParse<Filter>(prefab.Type, out var result))
			{
				return false;
			}
			return _filters.Contains(result);
		}

		private bool IsSubFilterPrefab(PrefabItem prefab)
		{
			if (!Enum.TryParse<SubFilter>(prefab.Type, out var result))
			{
				return false;
			}
			return _subFilters.Contains(result);
		}

		private void CacheFilterPrefabs()
		{
			Dictionary<Filter, int[]> dictionary = (from p in _prefabs.Values.Where(IsFilterPrefab)
				group p by Enum.Parse<Filter>(p.Type)).ToDictionary((IGrouping<Filter, PrefabItem> g) => g.Key, (IGrouping<Filter, PrefabItem> g) => g.Select((PrefabItem p) => p.ID).ToArray());
			_filterPrefabs = new ReadOnlyDictionary<Filter, int[]>(dictionary);
		}

		private void CacheSubFilterPrefabs()
		{
			Dictionary<SubFilter, int[]> dictionary = (from p in _prefabs.Values.Where(IsSubFilterPrefab)
				group p by Enum.Parse<SubFilter>(p.Type)).ToDictionary((IGrouping<SubFilter, PrefabItem> g) => g.Key, (IGrouping<SubFilter, PrefabItem> g) => g.Select((PrefabItem p) => p.ID).ToArray());
			_subFilterPrefabs = new ReadOnlyDictionary<SubFilter, int[]>(dictionary);
		}

		public void Build(List<PrefabItem> prefabs)
		{
			_stopWatch.Restart();
			_prefabs = new ReadOnlyDictionary<int, PrefabItem>(prefabs.ToDictionary((PrefabItem p) => p.ID, (PrefabItem p) => p));
			_prefabNames = new ReadOnlyDictionary<int, string>(_prefabs.ToDictionary((KeyValuePair<int, PrefabItem> p) => p.Key, (KeyValuePair<int, PrefabItem> p) => p.Value.Name));
			_prefabTypesNames = new ReadOnlyDictionary<int, string>(_prefabs.ToDictionary((KeyValuePair<int, PrefabItem> p) => p.Key, (KeyValuePair<int, PrefabItem> p) => p.Value.Type));
			_prefabDisplayNames = new ReadOnlyDictionary<int, string>(_prefabs.ToDictionary((KeyValuePair<int, PrefabItem> p) => p.Key, (KeyValuePair<int, PrefabItem> p) => ResolvePrefabName(_localisationManager, p.Value.Name)));
			_prefabTags = new ReadOnlyDictionary<int, HashSet<string>>(_prefabs.ToDictionary((KeyValuePair<int, PrefabItem> p) => p.Key, (KeyValuePair<int, PrefabItem> p) => (from t in p.Value.Tags.Distinct()
				select ResolveTagName(_localisationManager, t.ToLowerInvariant()).ToLowerInvariant()).ToHashSet()));
			CacheFilterPrefabs();
			CacheSubFilterPrefabs();
			_stopWatch.Stop();
			Debug.Log((object)$"[PrefabIndexer] Build took {_stopWatch.ElapsedMilliseconds} ms.");
		}

		private void ClearWorkingSet()
		{
			WorkingSet = null;
			_prefabSearchQueue.Clear();
		}

		public (PrefabItem Prefab, Filter Filter, SubFilter SubFilter) GetPrefab(int id)
		{
			if (!_prefabs.ContainsKey(id))
			{
				return default((PrefabItem, Filter, SubFilter));
			}
			PrefabItem prefabItem = _prefabs[id];
			Filter item = Filter.None;
			SubFilter item2 = SubFilter.None;
			Filter result2;
			SubFilter result3;
			if (!string.IsNullOrEmpty(prefabItem.Type) && Enum.TryParse<Filter>(prefabItem.Type, out var result) && !_filterMappings.ContainsKey(result))
			{
				item = result;
			}
			else if (!string.IsNullOrEmpty(prefabItem.Category) && Enum.TryParse<Filter>(prefabItem.Category, out result2) && Enum.TryParse<SubFilter>(prefabItem.Type, out result3) && _filterMappings.ContainsKey(result2))
			{
				SubFilter[] source = _filterMappings[result2];
				if (source.Contains(result3))
				{
					item = result2;
					item2 = result3;
				}
			}
			return (prefabItem, item, item2);
		}

		public (PrefabItem Prefab, Filter Filter, SubFilter SubFilter) GetPrefab(string name)
		{
			int key = _prefabNames.FirstOrDefault((KeyValuePair<int, string> kvp) => kvp.Value == name).Key;
			if (!_prefabs.ContainsKey(key))
			{
				return default((PrefabItem, Filter, SubFilter));
			}
			PrefabItem prefabItem = _prefabs[key];
			Filter item = Filter.None;
			SubFilter item2 = SubFilter.None;
			Filter result2;
			SubFilter result3;
			if (!string.IsNullOrEmpty(prefabItem.Type) && Enum.TryParse<Filter>(prefabItem.Type, out var result) && !_filterMappings.ContainsKey(result))
			{
				item = result;
			}
			else if (!string.IsNullOrEmpty(prefabItem.Category) && Enum.TryParse<Filter>(prefabItem.Category, out result2) && Enum.TryParse<SubFilter>(prefabItem.Type, out result3) && _filterMappings.ContainsKey(result2))
			{
				SubFilter[] source = _filterMappings[result2];
				if (source.Contains(result3))
				{
					item = result2;
					item2 = result3;
				}
			}
			return (prefabItem, item, item2);
		}

		public PrefabItem GetByName(string name)
		{
			return _prefabs.Select((KeyValuePair<int, PrefabItem> kvp) => kvp.Value).FirstOrDefault((PrefabItem n) => n.Name == name);
		}

		private bool WordSearch(string search, int prefabID)
		{
			if (string.IsNullOrEmpty(search))
			{
				return false;
			}
			string[] array = search.Split(' ', StringSplitOptions.RemoveEmptyEntries);
			if (array != null && array.Length != 0)
			{
				string[] array2 = array;
				foreach (string search2 in array2)
				{
					if (StringSearch(search2, prefabID))
					{
						return true;
					}
				}
			}
			return false;
		}

		private bool StringSearch(string search, int prefabID)
		{
			if (string.IsNullOrEmpty(search))
			{
				return false;
			}
			string text = _prefabNames[prefabID].ToLowerInvariant();
			string text2 = _prefabDisplayNames[prefabID].ToLowerInvariant();
			string text3 = _prefabTypesNames[prefabID].ToLowerInvariant();
			HashSet<string> source = _prefabTags[prefabID];
			return text.Contains(search) || text2.Contains(search) || text3.Contains(search) || source.Count((string t) => t.Contains(search)) > 0;
		}

		private void AddToWorkingSet(FindStuffViewModel model, int[] prefabIDs)
		{
			if (prefabIDs == null || prefabIDs.Length == 0)
			{
				return;
			}
			bool flag = !string.IsNullOrEmpty(model.Search);
			foreach (int num in prefabIDs)
			{
				if (WorkingSet.Data.Contains(num))
				{
					continue;
				}
				if (flag)
				{
					string search = model.Search.ToLowerInvariant().Trim();
					if (StringSearch(search, num) || WordSearch(search, num))
					{
						WorkingSet.Data.Add(num);
					}
				}
				else
				{
					WorkingSet.