Decompiled source of LootSorter v1.3.2

plugins/LootSorter.dll

Decompiled 6 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Fusion;
using HarmonyLib;
using I2.Loc;
using Micosmo.SensorToolkit;
using SecureVariables;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.UI;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace CrimeSimLootSorter;

internal static class BoxContents
{
	public static List<Pickupable> Seller(Runner r)
	{
		List<Pickupable> list = new List<Pickupable>();
		if ((Object)(object)r.sellerComp == (Object)null || (Object)(object)r.sellerComp.itemsSensor == (Object)null)
		{
			return list;
		}
		foreach (GameObject item in ((IEnumerable<GameObject>)((Sensor)r.sellerComp.itemsSensor).Detections).ToList())
		{
			if (!((Object)(object)item == (Object)null))
			{
				Pickupable component = item.GetComponent<Pickupable>();
				if ((Object)(object)component != (Object)null && (Object)(object)component.assignedItem != (Object)null && !list.Contains(component))
				{
					list.Add(component);
				}
			}
		}
		return list;
	}

	public static List<Pickupable> Safe(Runner r)
	{
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		List<Pickupable> list = new List<Pickupable>();
		if (!RenderBounds((!((Object)(object)r.safeRoot != (Object)null)) ? null : r.safeRoot.transform, out var b))
		{
			return list;
		}
		Collider[] array = Physics.OverlapBox(((Bounds)(ref b)).center, ((Bounds)(ref b)).extents + new Vector3(0.05f, 0.3f, 0.05f), Quaternion.identity, -1, (QueryTriggerInteraction)1);
		Collider[] array2 = array;
		foreach (Collider val in array2)
		{
			Pickupable componentInParent = ((Component)val).GetComponentInParent<Pickupable>();
			if ((Object)(object)componentInParent != (Object)null && (Object)(object)componentInParent.assignedItem != (Object)null && !list.Contains(componentInParent))
			{
				list.Add(componentInParent);
			}
		}
		return list;
	}

	public static long Value(IEnumerable<Pickupable> items)
	{
		//IL_006c: 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)
		long num = 0L;
		WorldManager instance = WorldManager.Instance;
		foreach (Pickupable item in items)
		{
			if (!((Object)(object)item == (Object)null) && !((Object)(object)item.assignedItem == (Object)null))
			{
				try
				{
					num += instance.ReturnItemValueDamaged(SecureInt.op_Implicit(item.assignedItem.value), item.currentDamage, false);
				}
				catch
				{
					num += SecureInt.op_Implicit(item.assignedItem.value);
				}
			}
		}
		return num;
	}

	public static bool RenderBounds(Transform root, out Bounds b)
	{
		//IL_0001: 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_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		b = default(Bounds);
		if ((Object)(object)root == (Object)null)
		{
			return false;
		}
		bool flag = false;
		MeshRenderer[] componentsInChildren = ((Component)root).GetComponentsInChildren<MeshRenderer>(false);
		foreach (MeshRenderer val in componentsInChildren)
		{
			if (!((Object)(object)((Component)val).GetComponentInParent<TMP_Text>() != (Object)null) && !((Component)((Component)val).transform).GetComponentsInParent<Component>(true).Any((Component c) => (Object)(object)c != (Object)null && ((object)c).GetType().Name == "Canvas"))
			{
				if (!flag)
				{
					b = ((Renderer)val).bounds;
					flag = true;
				}
				else
				{
					((Bounds)(ref b)).Encapsulate(((Renderer)val).bounds);
				}
			}
		}
		return flag;
	}
}
internal class BoxLabels
{
	private readonly Runner r;

	private TextMeshPro sellerLabel;

	private TextMeshPro safeLabel;

	public BoxLabels(Runner runner)
	{
		r = runner;
	}

	public void Tick()
	{
		if ((Object)(object)r.sellerBox == (Object)null || (Object)(object)r.safeRoot == (Object)null)
		{
			if ((Object)(object)sellerLabel != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)sellerLabel).gameObject);
			}
			if ((Object)(object)safeLabel != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)safeLabel).gameObject);
			}
			return;
		}
		if ((Object)(object)sellerLabel == (Object)null)
		{
			sellerLabel = Create("LootSorter_SellerLabel");
		}
		if ((Object)(object)safeLabel == (Object)null)
		{
			safeLabel = Create("LootSorter_SafeLabel");
		}
		if (!((Object)(object)sellerLabel == (Object)null) && !((Object)(object)safeLabel == (Object)null))
		{
			Update(sellerLabel, r.sellerBox, BoxContents.Seller(r));
			Update(safeLabel, r.safeRoot.transform, BoxContents.Safe(r));
		}
	}

	private void Update(TextMeshPro label, Transform box, List<Pickupable> items)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		if (BoxContents.RenderBounds(box, out var b))
		{
			label.transform.position = new Vector3(((Bounds)(ref b)).center.x, ((Bounds)(ref b)).max.y + 0.45f, ((Bounds)(ref b)).center.z);
			((TMP_Text)label).text = "$" + BoxContents.Value(items).ToString("N0") + "\n<size=70%>" + items.Count + Loc.T(" itens", " items") + "</size>";
		}
	}

	public void Face()
	{
		//IL_004f: 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_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		Camera main = Camera.main;
		if ((Object)(object)main == (Object)null)
		{
			return;
		}
		TextMeshPro[] array = (TextMeshPro[])(object)new TextMeshPro[2] { sellerLabel, safeLabel };
		foreach (TextMeshPro val in array)
		{
			if ((Object)(object)val != (Object)null)
			{
				val.transform.rotation = Quaternion.LookRotation(val.transform.position - ((Component)main).transform.position);
			}
		}
	}

	private TextMeshPro Create(string name)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject(name);
		TextMeshPro val2 = val.AddComponent<TextMeshPro>();
		TMP_Text val3 = Object.FindObjectOfType<TMP_Text>();
		if ((Object)(object)val3 != (Object)null && (Object)(object)val3.font != (Object)null)
		{
			((TMP_Text)val2).font = val3.font;
		}
		((TMP_Text)val2).fontSize = 3f;
		((TMP_Text)val2).fontStyle = (FontStyles)1;
		((TMP_Text)val2).alignment = (TextAlignmentOptions)514;
		((TMP_Text)val2).textWrappingMode = (TextWrappingModes)0;
		((Graphic)val2).color = Color.white;
		((TMP_Text)val2).outlineWidth = 0.2f;
		((TMP_Text)val2).outlineColor = new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue);
		((TMP_Text)val2).rectTransform.sizeDelta = new Vector2(4f, 1f);
		return val2;
	}
}
internal static class LeverTracker
{
	public static IEnumerator Track(Runner r, Action done)
	{
		List<Pickupable> snapshot = Runner.TruckPickups();
		foreach (Pickupable item in r.truckCache)
		{
			if ((Object)(object)item != (Object)null && !snapshot.Contains(item))
			{
				snapshot.Add(item);
			}
		}
		float start = Time.time;
		int lastCount = -1;
		float stableSince = Time.time;
		while (Time.time - start < 12f)
		{
			yield return (object)new WaitForSeconds(0.5f);
			List<Pickupable> inTruck = Runner.TruckPickups();
			int c = snapshot.Count((Pickupable p) => (Object)(object)p != (Object)null && inTruck.Contains(p));
			if (c != lastCount)
			{
				lastCount = c;
				stableSince = Time.time;
			}
			else if (Time.time - start > 1.5f && Time.time - stableSince >= 1.5f)
			{
				break;
			}
		}
		yield return (object)new WaitForSeconds(1f);
		List<Pickupable> truck = Runner.TruckPickups();
		List<Pickupable> seller = BoxContents.Seller(r);
		List<Pickupable> safe = BoxContents.Safe(r);
		int nSeller = 0;
		int nSafe = 0;
		int nTruck = 0;
		foreach (Pickupable item2 in snapshot)
		{
			if (!((Object)(object)item2 == (Object)null))
			{
				if (seller.Contains(item2))
				{
					nSeller++;
				}
				else if (safe.Contains(item2))
				{
					nSafe++;
				}
				else if (truck.Contains(item2))
				{
					nTruck++;
				}
			}
		}
		r.ShowToast(string.Format("Seller: {0} {3}   |   Safe: {1} {3}   |   {4}: {2} {3}", nSeller, nSafe, nTruck, Loc.T("itens", "items"), Loc.T("Caminhão", "Truck")), 5f);
		done();
	}
}
[HarmonyPatch(typeof(MagicLever), "RPC_TriggerLever")]
internal static class LeverTriggerPatch
{
	private static void Prefix()
	{
		try
		{
			if ((Object)(object)Plugin.Inst != (Object)null && (Object)(object)Plugin.Inst.Run != (Object)null)
			{
				Plugin.Inst.Run.BeginLeverTracking();
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("Lever tracking error: " + ex.Message));
		}
	}
}
internal static class DeathSound
{
	private static AudioClip clip;

	private static AudioSource source;

	private static float lastPlay = -10f;

	public static IEnumerator Load(MonoBehaviour host)
	{
		string dir = Path.GetDirectoryName(((BaseUnityPlugin)Plugin.Inst).Info.Location);
		string[][] candidates = new string[3][]
		{
			new string[2] { "death_cry.ogg", "OGGVORBIS" },
			new string[2] { "death_cry.wav", "WAV" },
			new string[2] { "death_cry.mp3", "MPEG" }
		};
		string[][] array = candidates;
		foreach (string[] c in array)
		{
			string path = Path.Combine(dir, c[0]);
			if (!File.Exists(path))
			{
				continue;
			}
			AudioType type = (AudioType)Enum.Parse(typeof(AudioType), c[1]);
			UnityWebRequest req = UnityWebRequestMultimedia.GetAudioClip(new Uri(path).AbsoluteUri, type);
			try
			{
				yield return req.SendWebRequest();
				if ((int)req.result != 1)
				{
					Plugin.Log.LogWarning((object)("Death sound load failed (" + c[0] + "): " + req.error));
					continue;
				}
				clip = DownloadHandlerAudioClip.GetContent(req);
				if ((Object)(object)clip != (Object)null)
				{
					((Object)clip).name = "LootSorter_DeathCry";
					source = ((Component)host).gameObject.AddComponent<AudioSource>();
					source.playOnAwake = false;
					source.spatialBlend = 0f;
					break;
				}
			}
			finally
			{
				((IDisposable)req)?.Dispose();
			}
		}
	}

	public static void Play()
	{
		if (Plugin.Inst.DeathSoundEnabled.Value && !((Object)(object)clip == (Object)null) && !((Object)(object)source == (Object)null) && !(Time.unscaledTime - lastPlay < 3f))
		{
			lastPlay = Time.unscaledTime;
			source.PlayOneShot(clip, Mathf.Clamp01(Plugin.Inst.DeathSoundVolume.Value));
		}
	}

	public static bool IsLocal(FPP_Player p)
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			NetworkObject val = ((SimulationBehaviour)p).Object;
			if ((Object)(object)val == (Object)null || (Object)(object)((SimulationBehaviour)p).Runner == (Object)null)
			{
				return false;
			}
			if (val.InputAuthority != PlayerRef.None)
			{
				return val.InputAuthority == ((SimulationBehaviour)p).Runner.LocalPlayer;
			}
			return val.HasStateAuthority;
		}
		catch
		{
			return false;
		}
	}
}
[HarmonyPatch(typeof(FPP_Player), "PlayerDeath")]
internal static class PlayerDeathPatch
{
	private static void Prefix(FPP_Player __instance, out bool __state)
	{
		__state = false;
		try
		{
			__state = __instance.isDead;
		}
		catch
		{
		}
	}

	private static void Postfix(FPP_Player __instance, bool __state)
	{
		try
		{
			if (!__state && __instance.isDead && DeathSound.IsLocal(__instance))
			{
				DeathSound.Play();
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("Death sound error: " + ex.Message));
		}
	}
}
internal static class DefaultRules
{
	public const string Text = "100 Gift Card|Seller\n16gb pendrive|Seller\n16gb ram|Seller\n1930 newspaper|Seller\n250 Gift Card|Seller\n250V Power Supply|Seller\n2tb hard drive|Seller\n32gb pendrive|Seller\n32gb ram|Seller\n3d printer Atom|Seller\n3d printer Rx-t7|Seller\n48gb ram|Seller\n50 Gift Card|Seller\n8gb pendrive|Seller\nAcetaminophen|Seller\nAcetylene tank|Seller\nAcoustic Guitar|Seller\nAlarm clock|Seller\nAlcohol Disinfectant|Seller\nAmateur camera|Seller\nAmericanOakWhiskey|Seller\nAmmo box|Truck\nAnalog camera|Seller\nAntique Clock|Seller\nArbalest HERO GPU|Seller\nAstar Smartphone|Seller\nAstar Tablet|Seller\nAstar Tablet Locked|Safe\nAudio speaker|Seller\nBanjo|Seller\nBasic printer|Seller\nBench grinder|Seller\nBigBox Game Console|Seller\nBigBox Game Console Locked|Safe\nBigBox Gamepad|Seller\nBlack Foldable Phone FoldPhone|Seller\nBlack Foldable Phone FoldPhone Locked|Safe\nBlack camcorder|Seller\nBlack leather wallet|Seller\nBlack wall clock|Seller\nBlacklight|Safe\nBlender|Seller\nBloodroot|Safe\nBlue Brick Game|Seller\nBlue Foldable Phone FoldPhone|Seller\nBlue Foldable Phone FoldPhone Locked|Safe\nBlue Meth Bag|Safe\nBlue MiniPhone|Seller\nBlue MiniPhone Locked|Safe\nBlue Vase|Seller\nBlue toy phone|Seller\nBlue wall clock|Seller\nBrasseur microscope|Seller\nCPU Cooler 1|Seller\nCPU Cooler 2|Seller\nCPU Cooler 3|Seller\nCar air filter|Seller\nCar battery|Seller\nCar toolbox|Seller\nCard Reward Box|Truck\nCastleWine|Seller\nCheap toaster|Seller\nChemical sample A|Safe\nChemical sample B|Safe\nChemical sample C|Safe\nChemical sample D|Safe\nCigarettes|Seller\nClassic revolver|Truck\nCleansing cream|Seller\nCoffee machine Express|Seller\nCold & Flu Capsules|Seller\nColorful Vase|Seller\nComputer keyboard 1|Seller\nComputer keyboard 2|Seller\nComputer keyboard 3|Seller\nComputer monitor 1|Seller\nComputer monitor 2|Seller\nCooking pot|Seller\nCreekWine|Seller\nCryptocurrency miner|Seller\nDVD Drive|Seller\nDesk phone|Seller\nDiamond necklace|Safe\nDirty camcorder|Seller\nDual coffee maker|Seller\nElectric kettle|Seller\nElectric piano|Seller\nElectric scooter|Seller\nExpensive perfume|Seller\nFabulous Guitar 1|Seller\nFabulous Guitar 2|Seller\nFabulous Guitar 3|Seller\nFlu reliever|Seller\nFuturistic VR Headset|Seller\nGamepad|Seller\nGamestation Locked|Safe\nGamestation Unlocked|Seller\nGaming PC|Seller\nGaming PC Locked|Safe\nGaming chair|Seller\nGaming keyboard|Seller\nGaming monitor|Seller\nGaming mouse|Seller\nGaming wheel|Seller\nGarant Rifle|Truck\nGarant Rifle 2|Truck\nGecon Gamepad|Seller\nGecon Gamepad Station|Seller\nGecon Gaming Console|Seller\nGecon Headphones|Seller\nGenerator|Seller\nGhostlight|Safe\nGold Watch Rubio|Safe\nGold bar|Seller\nGold necklace 1|Safe\nGold necklace 2|Safe\nGold necklace 3|Safe\nGold necklace 4|Safe\nGold ring 1|Safe\nGold ring 2|Safe\nGold ring 3|Safe\nGold ring 4|Safe\nGold ring 5|Safe\nGolden Vase|Seller\nGolden bracelet 1|Safe\nGolden bracelet 2|Safe\nGolden bracelet 3|Safe\nGreen Brick Game|Seller\nGreen toy phone|Seller\nHandheld console|Seller\nHeavy-Duty Car Battery|Seller\nHigh performance motor oil|Seller\nHome audio system|Seller\nHome router|Seller\nHypernova|Safe\nIbuprofen 1|Seller\nIbuprofen 2|Seller\nInsulin injector|Seller\nInternet Modem|Seller\nJuniper Gin|Seller\nLandline phone|Seller\nLeather wallet|Seller\nLoaded leather wallet|Seller\nM98k Rifle|Truck\nM98k Rifle 2|Truck\nMETA Core D5 CPU|Seller\nMagic sketcher|Seller\nMagnesium Supplement|Seller\nMassage Cream|Seller\nMicrowave|Seller\nMilitary crate|Seller\nMilitary crate locked|Safe\nMilitary server|Seller\nMilitary server Locked|Safe\nModern PC|Seller\nModern PC Locked|Safe\nModern TV|Seller\nModern laptop|Seller\nModern laptop locked|Safe\nMotherboard 1|Seller\nMotherboard 2|Seller\nMotherboard 3|Seller\nMountain Bike|Seller\nNanoByte CPU|Seller\nNefastil|Seller\nNeon Rush|Safe\nNewborn nappies|Seller\nNicotine patch|Seller\nNokke Smartphone|Seller\nNokke Smartphone Locked|Safe\nNokke Tablet|Seller\nNokke Tablet Locked|Safe\nOffice computer|Seller\nOld Ballantruan|Seller\nOld coffee machine|Seller\nOld laptop|Seller\nOld mans phone|Seller\nOld portable TV|Seller\nOld radio|Seller\nOmega|Safe\nOverdrive|Safe\nPC Mouse 1|Seller\nPC Mouse 2|Seller\nPackage to plant|Safe\nPainting Abstraction|Seller\nPainting Before the Storm|Seller\nPainting Black|Seller\nPainting Blood|Seller\nPainting Blue Bricks|Seller\nPainting Blue Shapes|Seller\nPainting Blue Stroke|Seller\nPainting Brick Red White|Seller\nPainting City|Seller\nPainting Colored Shapes|Seller\nPainting Eerie Forest|Seller\nPainting Green Blue Shapes|Seller\nPainting Grey Spot|Seller\nPainting Haunted House|Seller\nPainting Purple Circles|Seller\nPainting Purple Shapes|Seller\nPainting Purple Swipe|Seller\nPainting Radiation|Seller\nPainting Rectangles|Seller\nPainting Red Stroke|Seller\nPainting Red Swipe|Seller\nPainting River|Seller\nPainting Yellow Autumn|Seller\nPearl bracelet|Safe\nPearl necklace|Safe\nPhotocopier|Seller\nPiano|Seller\nPink toy phone|Seller\nPortable heater|Seller\nPortable scanner|Seller\nPregnancy test|Seller\nPrism|Safe\nProfessional camera|Seller\nProjector|Seller\nPulsefire|Safe\nQ Smartphone|Seller\nQ Smartphone Locked|Safe\nRGB Headphone Stand|Seller\nRGB Headphones 1|Seller\nRGB Headphones 2|Seller\nRandom loot box|Truck\nRandom tool box|Truck\nRecord player|Seller\nRed Brick Game|Seller\nRed MiniPhone|Seller\nRed MiniPhone Locked|Safe\nResearch Center Plan|Truck\nRestinol|Seller\nRetro gaming console Super Games|Seller\nRetro gaming handheld Super Games|Seller\nRetro portable TV|Seller\nRetro printer SnapPrint 449|Seller\nRobertWine|Seller\nRobot teacher|Seller\nRusty Wheel Classico|Seller\nServer rack 1|Seller\nServer rack 1 Locked|Safe\nServer rack 2|Seller\nServer rack 2 Locked|Safe\nShaver|Seller\nShaver Red|Seller\nSilver Foldable Phone FoldPhone|Seller\nSilver Foldable Phone FoldPhone Locked|Safe\nSilver MiniPhone|Seller\nSilver MiniPhone Locked|Safe\nSilver Watch Casso|Safe\nSilver bar|Seller\nSilver bracelet 1|Safe\nSilver bracelet 2|Safe\nSilver bracelet 3|Safe\nSilver necklace 1|Safe\nSilver necklace 2|Safe\nSilver necklace 3|Safe\nSilver ring 1|Safe\nSilver ring 2|Safe\nSilver ring 3|Safe\nSilver ring 4|Safe\nSkill leaflet Box Level 1|Truck\nSkill leaflet Box Level 2-3|Truck\nSlow cooker|Seller\nSmall TV|Seller\nSmart Speaker|Seller\nSonaro dream machine|Seller\nSpectra|Safe\nSpy Camera|Truck\nStylish wall clock|Seller\nSuperRadio 2000|Seller\nTV Receiver 1|Seller\nTV Receiver 2|Seller\nTable fan|Seller\nTachivol|Seller\nThermometer|Seller\nTower figure|Seller\nTrain Station Plan|Truck\nTranquidicil|Seller\nTundra XT GPU|Seller\nUltrasonic Cleaner|Seller\nUnpacked GPU CR-2050|Seller\nUnpacked LED Monitor|Seller\nUnpacked MB NX-790|Seller\nUnpacked PSU C-1200X|Seller\nUnpacked budget PC|Seller\nUnpacked budget smartphone|Seller\nUnpacked camera C6400|Seller\nUnpacked camera TSM 7S|Seller\nVR Headset|Seller\nVacuum cleaner|Seller\nVintage Civil Defense Kit|Seller\nVintage Geiger Counter|Seller\nVintage TV|Seller\nVintage radio|Seller\nVintage table clock|Seller\nVintage walkie talkie|Seller\nVintage wall clock|Seller\nVintage wooden TV|Seller\nViper|Safe\nVortex OMEGA CPU|Seller\nWall TV|Seller\nWall clock|Seller\nWater cooler|Seller\nWeeU Gamepad Black|Seller\nWeeU Gamepad White|Seller\nWeeU Gaming Console Black|Seller\nWeeU Gaming Console White|Seller\nWeed bag|Safe\nWeed seeds|Safe\nWheel TurboTread|Seller\nWheel Vintage Velocity|Seller\nWheel balancer|Seller\nWhite wall clock|Seller\nWindstorm GPU|Seller\nWine box|Seller\nWireless headphones|Seller\nWork laptop locked|Safe\nWork laptop unlocked|Seller\nZinc Capsules|Seller\nuPod|Seller\n";
}
internal static class ItemDump
{
	public static void Run()
	{
		HashSet<Item> hashSet = new HashSet<Item>();
		Computer val = Object.FindObjectOfType<Computer>();
		if ((Object)(object)val != (Object)null && val.itemScripts != null)
		{
			foreach (Item itemScript in val.itemScripts)
			{
				if ((Object)(object)itemScript != (Object)null)
				{
					hashSet.Add(itemScript);
				}
			}
		}
		Item[] array = Resources.FindObjectsOfTypeAll<Item>();
		foreach (Item val2 in array)
		{
			if ((Object)(object)val2 != (Object)null)
			{
				hashSet.Add(val2);
			}
		}
		Dictionary<Item, List<string>> dictionary = new Dictionary<Item, List<string>>();
		RequestCategoryButton[] array2 = Resources.FindObjectsOfTypeAll<RequestCategoryButton>();
		foreach (RequestCategoryButton val3 in array2)
		{
			if ((Object)(object)val3 == (Object)null || val3.requests == null)
			{
				continue;
			}
			foreach (ItemRequestUI request in val3.requests)
			{
				if ((Object)(object)request == (Object)null || request.requests == null)
				{
					continue;
				}
				foreach (ItemRequest request2 in request.requests)
				{
					if (request2 != null && !((Object)(object)request2.requestedItem == (Object)null))
					{
						if (!dictionary.TryGetValue(request2.requestedItem, out var value))
						{
							value = (dictionary[request2.requestedItem] = new List<string>());
						}
						if (!value.Contains(((Object)val3).name))
						{
							value.Add(((Object)val3).name);
						}
						hashSet.Add(request2.requestedItem);
					}
				}
			}
		}
		Dictionary<Item, Item> dictionary2 = new Dictionary<Item, Item>();
		foreach (Item item in hashSet)
		{
			if (item.isElectronicallyLocked && (Object)(object)item.unlockedItem != (Object)null)
			{
				dictionary2[item.unlockedItem] = item;
			}
		}
		FieldInfo field = typeof(Item).GetField("itemTypeForScanner");
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.AppendLine("key\tdisplay\titemName\tvalue\tcategories\tscanner\teligible\tunlockedItem\tlockedVersion\tflags");
		foreach (Item item2 in from x in hashSet
			orderby !x.isLoot, ((Object)x).name
			select x)
		{
			List<string> list2 = new List<string>();
			if (item2.isLoot)
			{
				list2.Add("loot");
			}
			if (item2.isJewelry)
			{
				list2.Add("jewelry");
			}
			if (item2.isElectronicallyLocked)
			{
				list2.Add("locked");
			}
			if (item2.isVIPItem)
			{
				list2.Add("vip");
			}
			if (item2.hasToBeCarried)
			{
				list2.Add("carried");
			}
			if (item2.isMoney)
			{
				list2.Add("money");
			}
			if (item2.isCreditCard)
			{
				list2.Add("creditcard");
			}
			if (item2.isGoldenCard)
			{
				list2.Add("goldencard");
			}
			if (item2.isVoucher)
			{
				list2.Add("voucher");
			}
			if (item2.isDrone)
			{
				list2.Add("drone");
			}
			if (item2.isItemUpgrade)
			{
				list2.Add("upgrade");
			}
			if (item2.isSkillBook)
			{
				list2.Add("skillbook");
			}
			if (item2.isWeapon)
			{
				list2.Add("weapon");
			}
			if (item2.isKey)
			{
				list2.Add("key");
			}
			if (item2.isAccessCard)
			{
				list2.Add("accesscard");
			}
			if (item2.isAmmo)
			{
				list2.Add("ammo");
			}
			if (item2.isFirstAid)
			{
				list2.Add("firstaid");
			}
			if (item2.isArmorVest)
			{
				list2.Add("armor");
			}
			if (item2.isCarFuel)
			{
				list2.Add("fuel");
			}
			if (item2.canBeRepaired)
			{
				list2.Add("repairable");
			}
			string s = string.Empty;
			try
			{
				object obj = ((!(field != null)) ? null : field.GetValue(item2));
				s = ((obj != null) ? obj.ToString() : string.Empty);
			}
			catch
			{
			}
			stringBuilder.AppendLine(string.Join("\t", ((Object)item2).name, Clean(Plugin.DisplayName(item2)), Clean(item2.itemName), ((object)Unsafe.As<SecureInt, SecureInt>(ref item2.value)/*cast due to .constrained prefix*/).ToString(), (!dictionary.TryGetValue(item2, out var value2)) ? string.Empty : string.Join(",", value2.ToArray()), Clean(s), (!item2.magicLeverEgible) ? "0" : "1", (!((Object)(object)item2.unlockedItem != (Object)null)) ? string.Empty : ((Object)item2.unlockedItem).name, (!dictionary2.TryGetValue(item2, out var value3)) ? string.Empty : ((Object)value3).name, string.Join(",", list2.ToArray())));
		}
		string text = Path.Combine(Paths.BepInExRootPath, "CrimeSim_items.txt");
		File.WriteAllText(text, stringBuilder.ToString());
		Plugin.Log.LogInfo((object)("Item dump saved to " + text + " (" + hashSet.Count + " items)"));
	}

	private static string Clean(string s)
	{
		return (!string.IsNullOrEmpty(s)) ? s.Replace("\t", " ").Replace("\r", string.Empty).Replace("\n", " ") : string.Empty;
	}
}
public enum Dest
{
	Seller,
	Safe,
	Truck
}
public enum Lang
{
	Auto,
	English,
	Portuguese
}
internal static class Loc
{
	public static bool IsPt()
	{
		Plugin inst = Plugin.Inst;
		if ((Object)(object)inst != (Object)null && inst.Language != null)
		{
			if (inst.Language.Value == Lang.Portuguese)
			{
				return true;
			}
			if (inst.Language.Value == Lang.English)
			{
				return false;
			}
		}
		try
		{
			string currentLanguageCode = LocalizationManager.CurrentLanguageCode;
			return !string.IsNullOrEmpty(currentLanguageCode) && currentLanguageCode.StartsWith("pt", StringComparison.OrdinalIgnoreCase);
		}
		catch
		{
			return false;
		}
	}

	public static string T(string pt, string en)
	{
		return (!IsPt()) ? en : pt;
	}
}
[BepInPlugin("LordValdomod.LootSorter", "Loot Sorter", "1.3.2")]
public class Plugin : BaseUnityPlugin
{
	internal static Plugin Inst;

	internal static ManualLogSource Log;

	internal ConfigEntry<KeyCode> MenuKey;

	internal ConfigEntry<KeyCode> DumpKey;

	internal ConfigEntry<Lang> Language;

	internal ConfigEntry<bool> EnableDumps;

	internal ConfigEntry<bool> DeathSoundEnabled;

	internal ConfigEntry<float> DeathSoundVolume;

	internal ConfigEntry<float> SafeForward;

	internal ConfigEntry<float> SafeRight;

	internal ConfigEntry<float> SafeUp;

	internal ConfigEntry<float> SafeRotY;

	internal ConfigEntry<float> Spread;

	internal ConfigEntry<float> SellerScale;

	internal ConfigEntry<float> SellerHeightScale;

	internal ConfigEntry<float> SellerAdvance;

	internal ConfigEntry<float> SellerVertical;

	internal ConfigEntry<float> SafeScale;

	internal ConfigEntry<float> DropHeight;

	internal ConfigEntry<int> BatchSize;

	internal ConfigEntry<float> BatchInterval;

	internal ConfigEntry<Dest> DefaultDest;

	internal ConfigEntry<bool> IgnoreEligibility;

	internal ConfigEntry<string> SafeColor;

	internal readonly Dictionary<string, Dest> Rules = new Dictionary<string, Dest>();

	private string rulesPath;

	internal Runner Run;

	private void Awake()
	{
		//IL_034d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0353: Expected O, but got Unknown
		//IL_0372: Unknown result type (might be due to invalid IL or missing references)
		//IL_0378: Expected O, but got Unknown
		Inst = this;
		Log = ((BaseUnityPlugin)this).Logger;
		Language = ((BaseUnityPlugin)this).Config.Bind<Lang>("General", "Language", Lang.Auto, "Text language. Auto follows the game language");
		MenuKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "FallbackMenuKey", (KeyCode)289, "Opens the fallback rules window (the main menu is the Sorter icon on the truck PC)");
		DeathSoundEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("DeathSound", "Enabled", true, "Plays a custom sound when you die (only you hear it)");
		DeathSoundVolume = ((BaseUnityPlugin)this).Config.Bind<float>("DeathSound", "Volume", 1f, "Death sound volume (0 to 1)");
		EnableDumps = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "EnableDumps", false, "Enables the dump key (PC UI, Seller Box and item list files)");
		DumpKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Debug", "DumpKey", (KeyCode)287, "Key that writes the debug dumps");
		DefaultDest = ((BaseUnityPlugin)this).Config.Bind<Dest>("Rules", "DefaultDestination", Dest.Seller, "Destination for loot without manual or automatic rule");
		IgnoreEligibility = ((BaseUnityPlugin)this).Config.Bind<bool>("Rules", "IgnoreLeverEligibility", false, "If true, also moves items the original lever ignores");
		BatchSize = ((BaseUnityPlugin)this).Config.Bind<int>("Movement", "ItemsPerBatch", 4, "Items moved per batch");
		BatchInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Movement", "BatchInterval", 0.15f, "Seconds between batches");
		Spread = ((BaseUnityPlugin)this).Config.Bind<float>("Movement", "Spread", 0.5f, "Random X/Z spread at the destination");
		DropHeight = ((BaseUnityPlugin)this).Config.Bind<float>("Movement", "DropHeightOffset", 0f, "Meters added to the drop point height (negative drops items lower)");
		SellerScale = ((BaseUnityPlugin)this).Config.Bind<float>("SellerBox", "Scale", 1.65f, "Seller Box width and length scale (1 = original). All players must use the same value");
		SellerHeightScale = ((BaseUnityPlugin)this).Config.Bind<float>("SellerBox", "HeightScale", 1f, "Seller Box height scale (1 = original)");
		SellerAdvance = ((BaseUnityPlugin)this).Config.Bind<float>("SellerBox", "Advance", 0.3f, "Meters the Seller Box moves towards the Safe Box (negative moves it back)");
		SellerVertical = ((BaseUnityPlugin)this).Config.Bind<float>("SellerBox", "VerticalOffset", 0f, "Meters the Seller Box moves up (negative moves it down)");
		SafeForward = ((BaseUnityPlugin)this).Config.Bind<float>("SafeBox", "OffsetForward", 0f, "Meters along the Seller Box forward axis");
		SafeRight = ((BaseUnityPlugin)this).Config.Bind<float>("SafeBox", "OffsetRight", -13f, "Meters along the Seller Box right axis");
		SafeUp = ((BaseUnityPlugin)this).Config.Bind<float>("SafeBox", "OffsetUp", -0.1f, "Height adjustment");
		SafeScale = ((BaseUnityPlugin)this).Config.Bind<float>("SafeBox", "Scale", 1.25f, "Safe Box width and length scale (height stays original)");
		SafeRotY = ((BaseUnityPlugin)this).Config.Bind<float>("SafeBox", "RotationY", 180f, "Extra rotation in degrees");
		SafeColor = ((BaseUnityPlugin)this).Config.Bind<string>("SafeBox", "Color", "#3CC83C", "Safe Box color in hex");
		ResetLayoutIfOld();
		rulesPath = Path.Combine(Paths.ConfigPath, "LordValdomod.LootSorter.rules.txt");
		LoadRules();
		GameObject val = new GameObject("LootSorterRunner");
		((Object)val).hideFlags = (HideFlags)61;
		Object.DontDestroyOnLoad((Object)(object)val);
		Run = val.AddComponent<Runner>();
		Harmony val2 = new Harmony("LordValdomod.LootSorter");
		val2.PatchAll(typeof(LeverPatch));
		val2.PatchAll(typeof(LeverTriggerPatch));
		val2.PatchAll(typeof(PlayerDeathPatch));
		Log.LogInfo((object)"Loot Sorter loaded");
	}

	private void ResetLayoutIfOld()
	{
		ConfigEntry<int> val = ((BaseUnityPlugin)this).Config.Bind<int>("General", "LayoutVersion", 0, "Internal, do not edit");
		if (val.Value < 3)
		{
			SellerScale.Value = (float)((ConfigEntryBase)SellerScale).DefaultValue;
			SellerHeightScale.Value = (float)((ConfigEntryBase)SellerHeightScale).DefaultValue;
			SellerAdvance.Value = (float)((ConfigEntryBase)SellerAdvance).DefaultValue;
			SellerVertical.Value = (float)((ConfigEntryBase)SellerVertical).DefaultValue;
			SafeUp.Value = (float)((ConfigEntryBase)SafeUp).DefaultValue;
			SafeScale.Value = (float)((ConfigEntryBase)SafeScale).DefaultValue;
			DropHeight.Value = (float)((ConfigEntryBase)DropHeight).DefaultValue;
			val.Value = 3;
			((BaseUnityPlugin)this).Config.Save();
		}
	}

	private void LoadRules()
	{
		Rules.Clear();
		if (!File.Exists(rulesPath))
		{
			try
			{
				File.WriteAllText(rulesPath, "100 Gift Card|Seller\n16gb pendrive|Seller\n16gb ram|Seller\n1930 newspaper|Seller\n250 Gift Card|Seller\n250V Power Supply|Seller\n2tb hard drive|Seller\n32gb pendrive|Seller\n32gb ram|Seller\n3d printer Atom|Seller\n3d printer Rx-t7|Seller\n48gb ram|Seller\n50 Gift Card|Seller\n8gb pendrive|Seller\nAcetaminophen|Seller\nAcetylene tank|Seller\nAcoustic Guitar|Seller\nAlarm clock|Seller\nAlcohol Disinfectant|Seller\nAmateur camera|Seller\nAmericanOakWhiskey|Seller\nAmmo box|Truck\nAnalog camera|Seller\nAntique Clock|Seller\nArbalest HERO GPU|Seller\nAstar Smartphone|Seller\nAstar Tablet|Seller\nAstar Tablet Locked|Safe\nAudio speaker|Seller\nBanjo|Seller\nBasic printer|Seller\nBench grinder|Seller\nBigBox Game Console|Seller\nBigBox Game Console Locked|Safe\nBigBox Gamepad|Seller\nBlack Foldable Phone FoldPhone|Seller\nBlack Foldable Phone FoldPhone Locked|Safe\nBlack camcorder|Seller\nBlack leather wallet|Seller\nBlack wall clock|Seller\nBlacklight|Safe\nBlender|Seller\nBloodroot|Safe\nBlue Brick Game|Seller\nBlue Foldable Phone FoldPhone|Seller\nBlue Foldable Phone FoldPhone Locked|Safe\nBlue Meth Bag|Safe\nBlue MiniPhone|Seller\nBlue MiniPhone Locked|Safe\nBlue Vase|Seller\nBlue toy phone|Seller\nBlue wall clock|Seller\nBrasseur microscope|Seller\nCPU Cooler 1|Seller\nCPU Cooler 2|Seller\nCPU Cooler 3|Seller\nCar air filter|Seller\nCar battery|Seller\nCar toolbox|Seller\nCard Reward Box|Truck\nCastleWine|Seller\nCheap toaster|Seller\nChemical sample A|Safe\nChemical sample B|Safe\nChemical sample C|Safe\nChemical sample D|Safe\nCigarettes|Seller\nClassic revolver|Truck\nCleansing cream|Seller\nCoffee machine Express|Seller\nCold & Flu Capsules|Seller\nColorful Vase|Seller\nComputer keyboard 1|Seller\nComputer keyboard 2|Seller\nComputer keyboard 3|Seller\nComputer monitor 1|Seller\nComputer monitor 2|Seller\nCooking pot|Seller\nCreekWine|Seller\nCryptocurrency miner|Seller\nDVD Drive|Seller\nDesk phone|Seller\nDiamond necklace|Safe\nDirty camcorder|Seller\nDual coffee maker|Seller\nElectric kettle|Seller\nElectric piano|Seller\nElectric scooter|Seller\nExpensive perfume|Seller\nFabulous Guitar 1|Seller\nFabulous Guitar 2|Seller\nFabulous Guitar 3|Seller\nFlu reliever|Seller\nFuturistic VR Headset|Seller\nGamepad|Seller\nGamestation Locked|Safe\nGamestation Unlocked|Seller\nGaming PC|Seller\nGaming PC Locked|Safe\nGaming chair|Seller\nGaming keyboard|Seller\nGaming monitor|Seller\nGaming mouse|Seller\nGaming wheel|Seller\nGarant Rifle|Truck\nGarant Rifle 2|Truck\nGecon Gamepad|Seller\nGecon Gamepad Station|Seller\nGecon Gaming Console|Seller\nGecon Headphones|Seller\nGenerator|Seller\nGhostlight|Safe\nGold Watch Rubio|Safe\nGold bar|Seller\nGold necklace 1|Safe\nGold necklace 2|Safe\nGold necklace 3|Safe\nGold necklace 4|Safe\nGold ring 1|Safe\nGold ring 2|Safe\nGold ring 3|Safe\nGold ring 4|Safe\nGold ring 5|Safe\nGolden Vase|Seller\nGolden bracelet 1|Safe\nGolden bracelet 2|Safe\nGolden bracelet 3|Safe\nGreen Brick Game|Seller\nGreen toy phone|Seller\nHandheld console|Seller\nHeavy-Duty Car Battery|Seller\nHigh performance motor oil|Seller\nHome audio system|Seller\nHome router|Seller\nHypernova|Safe\nIbuprofen 1|Seller\nIbuprofen 2|Seller\nInsulin injector|Seller\nInternet Modem|Seller\nJuniper Gin|Seller\nLandline phone|Seller\nLeather wallet|Seller\nLoaded leather wallet|Seller\nM98k Rifle|Truck\nM98k Rifle 2|Truck\nMETA Core D5 CPU|Seller\nMagic sketcher|Seller\nMagnesium Supplement|Seller\nMassage Cream|Seller\nMicrowave|Seller\nMilitary crate|Seller\nMilitary crate locked|Safe\nMilitary server|Seller\nMilitary server Locked|Safe\nModern PC|Seller\nModern PC Locked|Safe\nModern TV|Seller\nModern laptop|Seller\nModern laptop locked|Safe\nMotherboard 1|Seller\nMotherboard 2|Seller\nMotherboard 3|Seller\nMountain Bike|Seller\nNanoByte CPU|Seller\nNefastil|Seller\nNeon Rush|Safe\nNewborn nappies|Seller\nNicotine patch|Seller\nNokke Smartphone|Seller\nNokke Smartphone Locked|Safe\nNokke Tablet|Seller\nNokke Tablet Locked|Safe\nOffice computer|Seller\nOld Ballantruan|Seller\nOld coffee machine|Seller\nOld laptop|Seller\nOld mans phone|Seller\nOld portable TV|Seller\nOld radio|Seller\nOmega|Safe\nOverdrive|Safe\nPC Mouse 1|Seller\nPC Mouse 2|Seller\nPackage to plant|Safe\nPainting Abstraction|Seller\nPainting Before the Storm|Seller\nPainting Black|Seller\nPainting Blood|Seller\nPainting Blue Bricks|Seller\nPainting Blue Shapes|Seller\nPainting Blue Stroke|Seller\nPainting Brick Red White|Seller\nPainting City|Seller\nPainting Colored Shapes|Seller\nPainting Eerie Forest|Seller\nPainting Green Blue Shapes|Seller\nPainting Grey Spot|Seller\nPainting Haunted House|Seller\nPainting Purple Circles|Seller\nPainting Purple Shapes|Seller\nPainting Purple Swipe|Seller\nPainting Radiation|Seller\nPainting Rectangles|Seller\nPainting Red Stroke|Seller\nPainting Red Swipe|Seller\nPainting River|Seller\nPainting Yellow Autumn|Seller\nPearl bracelet|Safe\nPearl necklace|Safe\nPhotocopier|Seller\nPiano|Seller\nPink toy phone|Seller\nPortable heater|Seller\nPortable scanner|Seller\nPregnancy test|Seller\nPrism|Safe\nProfessional camera|Seller\nProjector|Seller\nPulsefire|Safe\nQ Smartphone|Seller\nQ Smartphone Locked|Safe\nRGB Headphone Stand|Seller\nRGB Headphones 1|Seller\nRGB Headphones 2|Seller\nRandom loot box|Truck\nRandom tool box|Truck\nRecord player|Seller\nRed Brick Game|Seller\nRed MiniPhone|Seller\nRed MiniPhone Locked|Safe\nResearch Center Plan|Truck\nRestinol|Seller\nRetro gaming console Super Games|Seller\nRetro gaming handheld Super Games|Seller\nRetro portable TV|Seller\nRetro printer SnapPrint 449|Seller\nRobertWine|Seller\nRobot teacher|Seller\nRusty Wheel Classico|Seller\nServer rack 1|Seller\nServer rack 1 Locked|Safe\nServer rack 2|Seller\nServer rack 2 Locked|Safe\nShaver|Seller\nShaver Red|Seller\nSilver Foldable Phone FoldPhone|Seller\nSilver Foldable Phone FoldPhone Locked|Safe\nSilver MiniPhone|Seller\nSilver MiniPhone Locked|Safe\nSilver Watch Casso|Safe\nSilver bar|Seller\nSilver bracelet 1|Safe\nSilver bracelet 2|Safe\nSilver bracelet 3|Safe\nSilver necklace 1|Safe\nSilver necklace 2|Safe\nSilver necklace 3|Safe\nSilver ring 1|Safe\nSilver ring 2|Safe\nSilver ring 3|Safe\nSilver ring 4|Safe\nSkill leaflet Box Level 1|Truck\nSkill leaflet Box Level 2-3|Truck\nSlow cooker|Seller\nSmall TV|Seller\nSmart Speaker|Seller\nSonaro dream machine|Seller\nSpectra|Safe\nSpy Camera|Truck\nStylish wall clock|Seller\nSuperRadio 2000|Seller\nTV Receiver 1|Seller\nTV Receiver 2|Seller\nTable fan|Seller\nTachivol|Seller\nThermometer|Seller\nTower figure|Seller\nTrain Station Plan|Truck\nTranquidicil|Seller\nTundra XT GPU|Seller\nUltrasonic Cleaner|Seller\nUnpacked GPU CR-2050|Seller\nUnpacked LED Monitor|Seller\nUnpacked MB NX-790|Seller\nUnpacked PSU C-1200X|Seller\nUnpacked budget PC|Seller\nUnpacked budget smartphone|Seller\nUnpacked camera C6400|Seller\nUnpacked camera TSM 7S|Seller\nVR Headset|Seller\nVacuum cleaner|Seller\nVintage Civil Defense Kit|Seller\nVintage Geiger Counter|Seller\nVintage TV|Seller\nVintage radio|Seller\nVintage table clock|Seller\nVintage walkie talkie|Seller\nVintage wall clock|Seller\nVintage wooden TV|Seller\nViper|Safe\nVortex OMEGA CPU|Seller\nWall TV|Seller\nWall clock|Seller\nWater cooler|Seller\nWeeU Gamepad Black|Seller\nWeeU Gamepad White|Seller\nWeeU Gaming Console Black|Seller\nWeeU Gaming Console White|Seller\nWeed bag|Safe\nWeed seeds|Safe\nWheel TurboTread|Seller\nWheel Vintage Velocity|Seller\nWheel balancer|Seller\nWhite wall clock|Seller\nWindstorm GPU|Seller\nWine box|Seller\nWireless headphones|Seller\nWork laptop locked|Safe\nWork laptop unlocked|Seller\nZinc Capsules|Seller\nuPod|Seller\n");
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Failed to write default rules: " + ex.Message));
				return;
			}
		}
		string[] array = File.ReadAllLines(rulesPath);
		foreach (string text in array)
		{
			int num = text.LastIndexOf('|');
			if (num > 0)
			{
				try
				{
					Rules[text.Substring(0, num)] = (Dest)Enum.Parse(typeof(Dest), text.Substring(num + 1));
				}
				catch
				{
				}
			}
		}
	}

	internal void SaveRules()
	{
		try
		{
			File.WriteAllLines(rulesPath, (from k in Rules
				orderby k.Key
				select k.Key + "|" + k.Value).ToArray());
		}
		catch (Exception ex)
		{
			Log.LogError((object)("Failed to save rules: " + ex.Message));
		}
	}

	internal static bool IsHardTruck(Item i)
	{
		return !i.isLoot || i.isMoney || i.isCreditCard || i.isGoldenCard || i.isVoucher || i.isDrone || i.isItemUpgrade || i.isSkillBook || i.isWeapon || i.isKey || i.isAccessCard || i.isAmmo || i.isFirstAid || i.isArmorVest || i.isCarFuel;
	}

	internal Dest Resolve(Item i, out string reason)
	{
		if (Rules.TryGetValue(((Object)i).name, out var value))
		{
			reason = "Manual";
			return value;
		}
		if (IsHardTruck(i))
		{
			reason = Loc.T("Ferramenta", "Tool");
			return Dest.Truck;
		}
		if (!i.magicLeverEgible && !IgnoreEligibility.Value)
		{
			reason = Loc.T("Auto (grande)", "Auto (large)");
			return Dest.Truck;
		}
		if (i.isJewelry)
		{
			reason = Loc.T("Auto (joia)", "Auto (jewelry)");
			return Dest.Safe;
		}
		if (i.isElectronicallyLocked)
		{
			reason = Loc.T("Auto (bloqueado)", "Auto (locked)");
			return Dest.Safe;
		}
		reason = Loc.T("Padrão", "Default");
		return DefaultDest.Value;
	}

	internal static string DisplayName(Item i)
	{
		try
		{
			string itemName = i.GetItemName(false);
			if (!string.IsNullOrEmpty(itemName))
			{
				return itemName;
			}
		}
		catch
		{
		}
		return (!string.IsNullOrEmpty(i.itemName)) ? i.itemName : ((Object)i).name;
	}
}
[HarmonyPatch(typeof(MagicLever), "MoveLootFromTruck")]
internal static class LeverPatch
{
	private static bool Prefix(MagicLever __instance)
	{
		try
		{
			if (!((NetworkBehaviour)__instance).HasStateAuthority)
			{
				return false;
			}
			Plugin.Inst.Run.StartSort();
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("Lever error: " + ex));
		}
		return false;
	}
}
public class Runner : MonoBehaviour
{
	private bool busy;

	internal GameObject safeRoot;

	internal Transform sellerBox;

	internal DeliveryBox sellerComp;

	private BoxLabels labels;

	internal List<Pickupable> truckCache = new List<Pickupable>();

	private string toast;

	private float toastUntil;

	private GUIStyle toastStyle;

	private bool tracking;

	private float checkTimer;

	private bool menuOpen;

	private Rect win = new Rect(80f, 80f, 620f, 520f);

	private Vector2 scroll;

	private List<Item> menuItems = new List<Item>();

	private DeliveryBox origBox;

	private Vector3 origPos;

	private Vector3 origScale;

	private Vector3 advanceDir;

	private Quaternion origRot;

	private Vector3 centerCorrection;

	private Plugin P => Plugin.Inst;

	private void Start()
	{
		labels = new BoxLabels(this);
		((MonoBehaviour)this).StartCoroutine(DeathSound.Load((MonoBehaviour)(object)this));
		((MonoBehaviour)this).StartCoroutine(LabelLoop());
	}

	private IEnumerator LabelLoop()
	{
		while (true)
		{
			try
			{
				truckCache = TruckPickups();
			}
			catch
			{
			}
			try
			{
				labels.Tick();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Box labels error: " + ex.Message));
			}
			yield return (object)new WaitForSeconds(1f);
		}
	}

	internal void ShowToast(string msg, float seconds)
	{
		toast = msg;
		toastUntil = Time.unscaledTime + seconds;
	}

	internal void BeginLeverTracking()
	{
		if (!tracking)
		{
			((MonoBehaviour)this).StartCoroutine(LeverTracker.Track(this, delegate
			{
				tracking = false;
			}));
			tracking = true;
		}
	}

	private void Update()
	{
		//IL_000b: 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)
		if (Input.GetKeyDown(P.MenuKey.Value))
		{
			menuOpen = !menuOpen;
			if (menuOpen)
			{
				RefreshMenu();
			}
			else
			{
				Cursor.lockState = (CursorLockMode)1;
				Cursor.visible = false;
			}
		}
		if (P.EnableDumps.Value && Input.GetKeyDown(P.DumpKey.Value))
		{
			try
			{
				PcDump.Run();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("PC dump failed: " + ex));
			}
			try
			{
				ItemDump.Run();
			}
			catch (Exception ex2)
			{
				Plugin.Log.LogError((object)("Item dump failed: " + ex2));
			}
		}
		checkTimer -= Time.unscaledDeltaTime;
		if (checkTimer <= 0f)
		{
			checkTimer = 2f;
			if ((Object)(object)safeRoot == (Object)null)
			{
				TryBuildSafeBox();
			}
			else
			{
				EnsureSellerTransform();
			}
			try
			{
				PcInstaller.TryInstall();
			}
			catch (Exception ex3)
			{
				Plugin.Log.LogError((object)("PC page install failed: " + ex3));
			}
		}
	}

	private void LateUpdate()
	{
		LateUpdateLabels();
		if (menuOpen)
		{
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
		}
	}

	internal static Sensor TruckSensor()
	{
		WorldManager instance = WorldManager.Instance;
		if ((Object)(object)instance == (Object)null || (Object)(object)instance.truckItemsSaver == (Object)null)
		{
			return null;
		}
		return (Sensor)(object)instance.truckItemsSaver.sensor;
	}

	internal static List<Pickupable> TruckPickups()
	{
		//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_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		List<Pickupable> list = new List<Pickupable>();
		Sensor val = TruckSensor();
		if ((Object)(object)val == (Object)null)
		{
			return list;
		}
		foreach (GameObject item in ((IEnumerable<GameObject>)val.Detections).ToList())
		{
			if (!((Object)(object)item == (Object)null))
			{
				Pickupable component = item.GetComponent<Pickupable>();
				if ((Object)(object)component != (Object)null && (Object)(object)component.assignedItem != (Object)null && !list.Contains(component))
				{
					list.Add(component);
				}
			}
		}
		Collider[] components = ((Component)val).GetComponents<Collider>();
		foreach (Collider val2 in components)
		{
			Bounds bounds = val2.bounds;
			Collider[] array = Physics.OverlapBox(((Bounds)(ref bounds)).center, ((Bounds)(ref bounds)).extents, Quaternion.identity, -1, (QueryTriggerInteraction)1);
			foreach (Collider val3 in array)
			{
				Pickupable componentInParent = ((Component)val3).GetComponentInParent<Pickupable>();
				if ((Object)(object)componentInParent != (Object)null && (Object)(object)componentInParent.assignedItem != (Object)null && !list.Contains(componentInParent))
				{
					list.Add(componentInParent);
				}
			}
		}
		return list;
	}

	public void StartSort()
	{
		if (!busy)
		{
			((MonoBehaviour)this).StartCoroutine(SortRoutine());
		}
	}

	private IEnumerator SortRoutine()
	{
		busy = true;
		GameObject spawn = GameObject.FindGameObjectWithTag("DeliveryBoxSpawn");
		if ((Object)(object)spawn == (Object)null)
		{
			busy = false;
			yield break;
		}
		if ((Object)(object)safeRoot == (Object)null)
		{
			TryBuildSafeBox();
		}
		Vector3 sellerPos = SellerSpawnPos(spawn.transform);
		Vector3? safePos = SafeSpawnPos(sellerPos);
		List<KeyValuePair<Pickupable, Dest>> jobs = new List<KeyValuePair<Pickupable, Dest>>();
		int seller = 0;
		int safe = 0;
		int truck = 0;
		foreach (Pickupable item in TruckPickups())
		{
			string reason;
			Dest dest = P.Resolve(item.assignedItem, out reason);
			if (dest == Dest.Safe && !safePos.HasValue)
			{
				dest = Dest.Truck;
			}
			switch (dest)
			{
			case Dest.Truck:
				truck++;
				continue;
			case Dest.Safe:
				safe++;
				break;
			default:
				seller++;
				break;
			}
			jobs.Add(new KeyValuePair<Pickupable, Dest>(item, dest));
		}
		int batch = Mathf.Max(1, P.BatchSize.Value);
		for (int i = 0; i < jobs.Count; i++)
		{
			Pickupable pk = jobs[i].Key;
			if ((Object)(object)pk != (Object)null && (Object)(object)pk.assignedItem != (Object)null)
			{
				try
				{
					Vector3 val = ((jobs[i].Value != Dest.Safe) ? sellerPos : safePos.Value) + Vector3.up * P.DropHeight.Value;
					float num = P.Spread.Value * ((jobs[i].Value != Dest.Seller) ? 1f : ScaleRatio().x);
					pk.RPC_SetPosition(val + new Vector3(Random.Range(0f - num, num), 0f, Random.Range(0f - num, num)));
					pk.RPC_SetToKinematic(false);
				}
				catch (Exception ex)
				{
					Plugin.Log.LogError((object)("Failed to move item: " + ex.Message));
				}
			}
			if ((i + 1) % batch == 0)
			{
				yield return (object)new WaitForSeconds(P.BatchInterval.Value);
			}
		}
		busy = false;
	}

	private Vector3? SafeSpawnPos(Vector3 sellerSpawn)
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: 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_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)safeRoot == (Object)null || (Object)(object)sellerBox == (Object)null)
		{
			return null;
		}
		Vector3 val = Quaternion.Inverse(sellerBox.rotation) * (sellerSpawn - sellerBox.position);
		Vector3 val2 = ScaleRatio();
		((Vector3)(ref val))..ctor(val.x / val2.x, val.y / val2.y, val.z / val2.z);
		return safeRoot.transform.position + safeRoot.transform.rotation * val;
	}

	private Vector3 SellerSpawnPos(Transform spawn)
	{
		//IL_0034: 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_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_006d: 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_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_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)sellerBox == (Object)null || (Object)(object)origBox == (Object)null || spawn.IsChildOf(sellerBox))
		{
			return spawn.position;
		}
		Vector3 val = Quaternion.Inverse(origRot) * (spawn.position - origPos);
		return sellerBox.position + sellerBox.rotation * Vector3.Scale(val, ScaleRatio());
	}

	private Vector3 ScaleRatio()
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Max(0.1f, P.SellerScale.Value);
		float num2 = Mathf.Max(0.1f, P.SellerHeightScale.Value);
		return new Vector3(num, num2, num);
	}

	private void CaptureOriginal(DeliveryBox box)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)origBox == (Object)(object)box))
		{
			origBox = box;
			Transform transform = ((Component)box).transform;
			origPos = transform.position;
			origRot = transform.rotation;
			origScale = transform.localScale;
		}
	}

	private Vector3 SafeTargetFromOriginal()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: 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_0078: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = origRot * Vector3.forward;
		Vector3 val2 = origRot * Vector3.right;
		return origPos + val * P.SafeForward.Value + val2 * P.SafeRight.Value + Vector3.up * P.SafeUp.Value;
	}

	private void EnsureSellerTransform()
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: 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_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_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_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: 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_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_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: 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)
		if (!((Object)(object)origBox == (Object)null) && !((Object)(object)sellerBox == (Object)null))
		{
			Vector3 val = origPos + centerCorrection + advanceDir * P.SellerAdvance.Value + Vector3.up * P.SellerVertical.Value;
			Vector3 val2 = Vector3.Scale(origScale, ScaleRatio());
			Vector3 val3 = sellerBox.position - val;
			if (((Vector3)(ref val3)).sqrMagnitude > 0.0001f)
			{
				sellerBox.position = val;
			}
			Vector3 val4 = sellerBox.localScale - val2;
			if (((Vector3)(ref val4)).sqrMagnitude > 0.0001f)
			{
				sellerBox.localScale = val2;
			}
		}
	}

	private void TryBuildSafeBox()
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00ad: 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_00b2: 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_00c7: Expected O, but got Unknown
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Unknown result type (might be due to invalid IL or missing references)
		//IL_0255: Unknown result type (might be due to invalid IL or missing references)
		//IL_026a: 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_0275: Unknown result type (might be due to invalid IL or missing references)
		//IL_0294: Unknown result type (might be due to invalid IL or missing references)
		//IL_0299: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02de: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e3: 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_02f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0300: Unknown result type (might be due to invalid IL or missing references)
		//IL_034c: Unknown result type (might be due to invalid IL or missing references)
		//IL_031f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0326: Unknown result type (might be due to invalid IL or missing references)
		//IL_032b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0330: Unknown result type (might be due to invalid IL or missing references)
		DeliveryBox val = Object.FindObjectOfType<DeliveryBox>();
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		sellerComp = val;
		CaptureOriginal(val);
		sellerBox = ((Component)val).transform;
		sellerBox.SetPositionAndRotation(origPos, origRot);
		sellerBox.localScale = origScale;
		Bounds b;
		bool flag = BoxContents.RenderBounds(sellerBox, out b);
		Vector3 val2 = SafeTargetFromOriginal();
		Vector3 val3 = val2 - origPos;
		val3.y = 0f;
		advanceDir = ((!(((Vector3)(ref val3)).sqrMagnitude > 0.0001f)) ? (origRot * Vector3.forward) : ((Vector3)(ref val3)).normalized);
		safeRoot = new GameObject("LootSorter_SafeBox");
		safeRoot.transform.SetPositionAndRotation(origPos, origRot);
		Dictionary<Transform, Transform> map = new Dictionary<Transform, Transform>();
		int num = 0;
		int num2 = 0;
		MeshRenderer[] componentsInChildren = ((Component)sellerBox).GetComponentsInChildren<MeshRenderer>(false);
		foreach (MeshRenderer val4 in componentsInChildren)
		{
			if (!IsTextOrUI(((Component)val4).gameObject))
			{
				MeshFilter component = ((Component)val4).GetComponent<MeshFilter>();
				if (!((Object)(object)component == (Object)null) && !((Object)(object)component.sharedMesh == (Object)null))
				{
					Transform val5 = CloneNode(((Component)val4).transform, map);
					((Component)val5).gameObject.AddComponent<MeshFilter>().sharedMesh = component.sharedMesh;
					MeshRenderer val6 = ((Component)val5).gameObject.AddComponent<MeshRenderer>();
					((Renderer)val6).sharedMaterials = TintMaterials(((Renderer)val4).sharedMaterials);
					((Renderer)val6).shadowCastingMode = ((Renderer)val4).shadowCastingMode;
					((Renderer)val6).receiveShadows = ((Renderer)val4).receiveShadows;
					num++;
				}
			}
		}
		Collider[] componentsInChildren2 = ((Component)sellerBox).GetComponentsInChildren<Collider>(false);
		foreach (Collider val7 in componentsInChildren2)
		{
			if (!val7.isTrigger && !IsTextOrUI(((Component)val7).gameObject))
			{
				Transform val8 = CloneNode(((Component)val7).transform, map);
				if (CopyCollider(val7, ((Component)val8).gameObject))
				{
					num2++;
				}
			}
		}
		safeRoot.transform.SetPositionAndRotation(val2 + advanceDir * P.SellerAdvance.Value, origRot * Quaternion.Euler(0f, P.SafeRotY.Value, 0f));
		float num3 = Mathf.Max(0.1f, P.SafeScale.Value);
		safeRoot.transform.localScale = new Vector3(num3, 1f, num3);
		centerCorrection = Vector3.zero;
		if (flag)
		{
			sellerBox.localScale = Vector3.Scale(origScale, ScaleRatio());
			if (BoxContents.RenderBounds(sellerBox, out var b2))
			{
				centerCorrection = ((Bounds)(ref b)).center - ((Bounds)(ref b2)).center;
				centerCorrection.y = 0f;
			}
			sellerBox.localScale = origScale;
		}
		EnsureSellerTransform();
	}

	private Material[] TintMaterials(Material[] src)
	{
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Expected O, but got Unknown
		//IL_0074: 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)
		Color val = default(Color);
		if (!ColorUtility.TryParseHtmlString(P.SafeColor.Value, ref val))
		{
			((Color)(ref val))..ctor(0.235f, 0.784f, 0.235f);
		}
		Material[] array = (Material[])(object)new Material[src.Length];
		for (int i = 0; i < src.Length; i++)
		{
			if (!((Object)(object)src[i] == (Object)null))
			{
				Material val2 = new Material(src[i]);
				if (val2.HasProperty("_Color"))
				{
					val2.SetColor("_Color", val);
				}
				if (val2.HasProperty("_BaseColor"))
				{
					val2.SetColor("_BaseColor", val);
				}
				array[i] = val2;
			}
		}
		return array;
	}

	private Transform CloneNode(Transform src, Dictionary<Transform, Transform> map)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		//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_005a: Unknown result type (might be due to invalid IL or missing references)
		if (map.TryGetValue(src, out var value))
		{
			return value;
		}
		GameObject val = new GameObject(((Object)src).name);
		val.layer = ((Component)src).gameObject.layer;
		value = val.transform;
		value.SetParent(safeRoot.transform, false);
		value.SetPositionAndRotation(src.position, src.rotation);
		value.localScale = src.lossyScale;
		map[src] = value;
		return value;
	}

	private static bool IsTextOrUI(GameObject go)
	{
		Component[] componentsInParent = go.GetComponentsInParent<Component>(true);
		foreach (Component val in componentsInParent)
		{
			if (!((Object)(object)val == (Object)null))
			{
				string name = ((object)val).GetType().Name;
				if (name == "Canvas" || name.Contains("TextMeshPro") || name.StartsWith("TMP"))
				{
					return true;
				}
			}
		}
		return false;
	}

	private static bool CopyCollider(Collider c, GameObject dst)
	{
		//IL_001c: 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_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		BoxCollider val = (BoxCollider)(object)((c is BoxCollider) ? c : null);
		if ((Object)(object)val != (Object)null)
		{
			BoxCollider val2 = dst.AddComponent<BoxCollider>();
			val2.center = val.center;
			val2.size = val.size;
			((Collider)val2).sharedMaterial = ((Collider)val).sharedMaterial;
			return true;
		}
		SphereCollider val3 = (SphereCollider)(object)((c is SphereCollider) ? c : null);
		if ((Object)(object)val3 != (Object)null)
		{
			SphereCollider val4 = dst.AddComponent<SphereCollider>();
			val4.center = val3.center;
			val4.radius = val3.radius;
			((Collider)val4).sharedMaterial = ((Collider)val3).sharedMaterial;
			return true;
		}
		CapsuleCollider val5 = (CapsuleCollider)(object)((c is CapsuleCollider) ? c : null);
		if ((Object)(object)val5 != (Object)null)
		{
			CapsuleCollider val6 = dst.AddComponent<CapsuleCollider>();
			val6.center = val5.center;
			val6.radius = val5.radius;
			val6.height = val5.height;
			val6.direction = val5.direction;
			((Collider)val6).sharedMaterial = ((Collider)val5).sharedMaterial;
			return true;
		}
		MeshCollider val7 = (MeshCollider)(object)((c is MeshCollider) ? c : null);
		if ((Object)(object)val7 != (Object)null && (Object)(object)val7.sharedMesh != (Object)null)
		{
			MeshCollider val8 = dst.AddComponent<MeshCollider>();
			val8.sharedMesh = val7.sharedMesh;
			val8.convex = val7.convex;
			((Collider)val8).sharedMaterial = ((Collider)val7).sharedMaterial;
			return true;
		}
		return false;
	}

	private void RefreshMenu()
	{
		menuItems.Clear();
		foreach (Pickupable item in TruckPickups())
		{
			if (!menuItems.Contains(item.assignedItem))
			{
				menuItems.Add(item.assignedItem);
			}
		}
		menuItems = menuItems.OrderBy(Plugin.DisplayName).ToList();
	}

	internal static bool IsHost()
	{
		NetworkRunner val = ((NetworkRunner.Instances == null || NetworkRunner.Instances.Count <= 0) ? null : NetworkRunner.Instances[0]);
		if ((Object)(object)val == (Object)null || !val.IsRunning)
		{
			return true;
		}
		return val.IsServer || val.IsSharedModeMasterClient;
	}

	private void LateUpdateLabels()
	{
		if (labels != null)
		{
			labels.Face();
		}
	}

	private void OnGUI()
	{
		//IL_00e1: 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_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Expected O, but got Unknown
		//IL_0120: 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_00b8: 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_003b: Expected O, but got Unknown
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		if (toast != null && Time.unscaledTime < toastUntil)
		{
			if (toastStyle == null)
			{
				toastStyle = new GUIStyle(GUI.skin.box);
				toastStyle.fontSize = 24;
				toastStyle.fontStyle = (FontStyle)1;
				toastStyle.alignment = (TextAnchor)4;
				toastStyle.normal.textColor = Color.white;
				toastStyle.wordWrap = true;
			}
			float num = Mathf.Min(900f, (float)Screen.width - 40f);
			GUI.Box(new Rect(((float)Screen.width - num) / 2f, (float)Screen.height * 0.22f, num, 60f), toast, toastStyle);
		}
		if (menuOpen)
		{
			win = GUI.Window(19539, win, new WindowFunction(DrawWindow), string.Concat("Loot Sorter  (", P.MenuKey.Value, Loc.T(" fecha)", " closes)")));
		}
	}

	private void DrawWindow(int id)
	{
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
		if (!IsHost())
		{
			GUILayout.Label(Loc.T("As regras são definidas pelo host.", "Rules are set by the host."), Array.Empty<GUILayoutOption>());
			GUI.DragWindow();
			return;
		}
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		if (GUILayout.Button(Loc.T("Atualizar lista", "Refresh list"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(130f) }))
		{
			RefreshMenu();
		}
		GUILayout.Label(Loc.T("Itens no caminhão: ", "Items in truck: ") + menuItems.Count + Loc.T("   Regras salvas: ", "   Saved rules: ") + P.Rules.Count, Array.Empty<GUILayoutOption>());
		GUILayout.EndHorizontal();
		GUILayout.Label((!((Object)(object)safeRoot != (Object)null)) ? Loc.T("Safe Box: não criada (itens Safe ficam no caminhão)", "Safe Box: not created (Safe items stay in truck)") : Loc.T("Safe Box: ativa", "Safe Box: active"), Array.Empty<GUILayoutOption>());
		scroll = GUILayout.BeginScrollView(scroll, Array.Empty<GUILayoutOption>());
		foreach (Item menuItem in menuItems)
		{
			if ((Object)(object)menuItem == (Object)null)
			{
				continue;
			}
			string reason;
			Dest dest = P.Resolve(menuItem, out reason);
			GUILayout.BeginHorizontal(GUIStyle.op_Implicit("box"), Array.Empty<GUILayoutOption>());
			GUILayout.Label(Plugin.DisplayName(menuItem), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(210f) });
			GUILayout.Label(string.Concat(dest, " [", reason, "]"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(150f) });
			if (Plugin.IsHardTruck(menuItem))
			{
				GUILayout.Label(Loc.T("fica no caminhão", "stays in truck"), Array.Empty<GUILayoutOption>());
			}
			else
			{
				if (GUILayout.Button("Seller", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(55f) }))
				{
					SetRule(menuItem, Dest.Seller);
				}
				if (GUILayout.Button("Safe", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) }))
				{
					SetRule(menuItem, Dest.Safe);
				}
				if (GUILayout.Button("Truck", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(55f) }))
				{
					SetRule(menuItem, Dest.Truck);
				}
			}
			GUILayout.EndHorizontal();
		}
		GUILayout.EndScrollView();
		GUI.DragWindow(new Rect(0f, 0f, 10000f, 22f));
	}

	private void SetRule(Item item, Dest d)
	{
		P.Rules[((Object)item).name] = d;
		P.SaveRules();
	}
}
internal static class PcDump
{
	public static void Run()
	{
		//IL_026b: Unknown result type (might be due to invalid IL or missing references)
		StringBuilder stringBuilder = new StringBuilder();
		Computer val = Object.FindObjectOfType<Computer>();
		if ((Object)(object)val == (Object)null)
		{
			Plugin.Log.LogWarning((object)"PC dump: Computer not found");
			return;
		}
		stringBuilder.AppendLine("Computer: " + PathOf(((Component)val).transform) + " ativo=" + val.computerActive);
		List<Transform> list = new List<Transform>();
		if (val.pages != null)
		{
			stringBuilder.AppendLine("== pages (" + val.pages.Count + ")");
			for (int i = 0; i < val.pages.Count; i++)
			{
				GameObject val2 = val.pages[i];
				stringBuilder.AppendLine("  [" + i + "] " + ((!((Object)(object)val2 == (Object)null)) ? (PathOf(val2.transform) + " ativo=" + val2.activeSelf) : "null"));
				if ((Object)(object)val2 != (Object)null)
				{
					AddRoot(list, val2.transform);
				}
			}
		}
		CustomizationWebsite[] array = Object.FindObjectsOfType<CustomizationWebsite>(true);
		foreach (CustomizationWebsite val3 in array)
		{
			stringBuilder.AppendLine("CustomizationWebsite: " + PathOf(((Component)val3).transform));
		}
		Canvas[] componentsInChildren = ((Component)val).GetComponentsInChildren<Canvas>(true);
		foreach (Canvas val4 in componentsInChildren)
		{
			AddRoot(list, ((Component)val4).transform);
		}
		foreach (Transform item in list)
		{
			stringBuilder.AppendLine();
			stringBuilder.AppendLine("==================== ROOT " + PathOf(item));
			DumpNode(item, 0, stringBuilder);
		}
		DeliveryBox val5 = Object.FindObjectOfType<DeliveryBox>();
		if ((Object)(object)val5 != (Object)null)
		{
			StringBuilder stringBuilder2 = new StringBuilder();
			stringBuilder2.AppendLine("DeliveryBox: " + PathOf(((Component)val5).transform) + " scale=" + ((Component)val5).transform.localScale);
			GameObject val6 = GameObject.FindGameObjectWithTag("DeliveryBoxSpawn");
			if ((Object)(object)val6 != (Object)null)
			{
				stringBuilder2.AppendLine("DeliveryBoxSpawn: " + PathOf(val6.transform) + " filho=" + val6.transform.IsChildOf(((Component)val5).transform));
			}
			DumpNode(((Component)val5).transform, 0, stringBuilder2);
			File.WriteAllText(Path.Combine(Paths.BepInExRootPath, "CrimeSimSeller_dump.txt"), stringBuilder2.ToString());
		}
		string text = Path.Combine(Paths.BepInExRootPath, "CrimeSimPC_dump.txt");
		File.WriteAllText(text, stringBuilder.ToString());
		Plugin.Log.LogInfo((object)("PC dump saved to " + text));
	}

	private static void AddRoot(List<Transform> roots, Transform t)
	{
		Canvas componentInParent = ((Component)t).GetComponentInParent<Canvas>(true);
		Transform item = ((!((Object)(object)componentInParent != (Object)null)) ? t : ((Component)componentInParent.rootCanvas).transform);
		if (!roots.Contains(item))
		{
			roots.Add(item);
		}
	}

	private static void DumpNode(Transform t, int depth, StringBuilder sb)
	{
		//IL_006a: 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_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		string text = new string(' ', depth * 2);
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.Append(text).Append(((Object)t).name).Append((!((Component)t).gameObject.activeSelf) ? " (off)" : string.Empty);
		RectTransform val = (RectTransform)(object)((t is RectTransform) ? t : null);
		if ((Object)(object)val != (Object)null)
		{
			stringBuilder.AppendFormat(" pos={0} size={1} anchor={2}-{3}", V(val.anchoredPosition), V(val.sizeDelta), V(val.anchorMin), V(val.anchorMax));
		}
		List<string> list = new List<string>();
		Component[] components = ((Component)t).GetComponents<Component>();
		foreach (Component val2 in components)
		{
			if (!((Object)(object)val2 == (Object)null) && !(val2 is Transform))
			{
				list.Add(((object)val2).GetType().Name);
			}
		}
		if (list.Count > 0)
		{
			stringBuilder.Append(" {").Append(string.Join(",", list.ToArray())).Append("}");
		}
		TMP_Text component = ((Component)t).GetComponent<TMP_Text>();
		if ((Object)(object)component != (Object)null)
		{
			stringBuilder.Append(" txt=\"").Append(Short(component.text)).Append("\"");
		}
		Text component2 = ((Component)t).GetComponent<Text>();
		if ((Object)(object)component2 != (Object)null)
		{
			stringBuilder.Append(" txt=\"").Append(Short(component2.text)).Append("\"");
		}
		Image component3 = ((Component)t).GetComponent<Image>();
		if ((Object)(object)component3 != (Object)null && (Object)(object)component3.sprite != (Object)null)
		{
			stringBuilder.Append(" sprite=").Append(((Object)component3.sprite).name);
		}
		Collider[] components2 = ((Component)t).GetComponents<Collider>();
		foreach (Collider val3 in components2)
		{
			BoxCollider val4 = (BoxCollider)(object)((val3 is BoxCollider) ? val3 : null);
			stringBuilder.Append(" [col ").Append(((object)val3).GetType().Name).Append((!val3.isTrigger) ? string.Empty : " trigger");
			if ((Object)(object)val4 != (Object)null)
			{
				stringBuilder.Append(" size=").Append(val4.size);
			}
			stringBuilder.Append("]");
		}
		sb.AppendLine(stringBuilder.ToString());
		Button component4 = ((Component)t).GetComponent<Button>();
		if ((Object)(object)component4 != (Object)null)
		{
			DumpEvent((UnityEventBase)(object)component4.onClick, text + "    onClick", sb);
		}
		for (int k = 0; k < t.childCount; k++)
		{
			DumpNode(t.GetChild(k), depth + 1, sb);
		}
	}

	private static void DumpEvent(UnityEventBase ev, string prefix, StringBuilder sb)
	{
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		int persistentEventCount = ev.GetPersistentEventCount();
		object obj = null;
		try
		{
			FieldInfo field = typeof(UnityEventBase).GetField("m_PersistentCalls", BindingFlags.Instance | BindingFlags.NonPublic);
			object value = field.GetValue(ev);
			obj = value.GetType().GetField("m_Calls", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(value);
		}
		catch
		{
		}
		for (int i = 0; i < persistentEventCount; i++)
		{
			Object persistentTarget = ev.GetPersistentTarget(i);
			string text = string.Empty;
			try
			{
				object obj3 = ((IList)obj)[i];
				object value2 = obj3.GetType().GetField("m_Arguments", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(obj3);
				Type type = value2.GetType();
				BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic;
				text = string.Format(" int={0} str={1} bool={2}", type.GetField("m_IntArgument", bindingAttr).GetValue(value2), type.GetField("m_StringArgument", bindingAttr).GetValue(value2), type.GetField("m_BoolArgument", bindingAttr).GetValue(value2));
			}
			catch
			{
			}
			string text2 = ((!(persistentTarget == (Object)null)) ? (((object)persistentTarget).GetType().Name + "@" + ((!(persistentTarget is Component)) ? persistentTarget.name : PathOf(((Component)persistentTarget).transform))) : "null");
			sb.AppendLine(prefix + "[" + i + "] " + text2 + "." + ev.GetPersistentMethodName(i) + text);
		}
	}

	private static string PathOf(Transform t)
	{
		string text = ((Object)t).name;
		while ((Object)(object)t.parent != (Object)null)
		{
			t = t.parent;
			text = ((Object)t).name + "/" + text;
		}
		return text;
	}

	private static string V(Vector2 v)
	{
		return $"({v.x:0.#},{v.y:0.#})";
	}

	private static string Short(string s)
	{
		if (s == null)
		{
			return string.Empty;
		}
		s = s.Replace("\n", " ").Replace("\r", string.Empty);
		return (s.Length <= 50) ? s : (s.Substring(0, 50) + "...");
	}
}
internal static class PcInstaller
{
	private const string PageName = "LOOT SORTER";

	private const string IconName = "LOOT SORTER BUTTON";

	private static TMP_Text iconLabel;

	public static void TryInstall()
	{
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Expected O, but got Unknown
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Expected O, but got Unknown
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_0225: Unknown result type (might be due to invalid IL or missing references)
		//IL_022c: Expected O, but got Unknown
		//IL_0449: Unknown result type (might be due to invalid IL or missing references)
		//IL_0453: Expected O, but got Unknown
		//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
		Computer pc = Object.FindObjectOfType<Computer>();
		if ((Object)(object)pc == (Object)null || pc.pages == null)
		{
			return;
		}
		if (pc.pages.Any((GameObject p) => (Object)(object)p != (Object)null && ((Object)p).name == "LOOT SORTER"))
		{
			if ((Object)(object)iconLabel != (Object)null)
			{
				string text = Loc.T("Organizador", "Sorter");
				if (iconLabel.text != text)
				{
					iconLabel.text = text;
				}
			}
			return;
		}
		GameObject val = ((IEnumerable<GameObject>)pc.pages).FirstOrDefault((Func<GameObject, bool>)((GameObject p) => (Object)(object)p != (Object)null && ((Object)p).name == "CUSTOMIZATION"));
		GameObject val2 = ((IEnumerable<GameObject>)pc.pages).FirstOrDefault((Func<GameObject, bool>)((GameObject p) => (Object)(object)p != (Object)null && ((Object)p).name == "MAIN PAGE"));
		if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
		{
			return;
		}
		Transform parent = val.transform.parent;
		GameObject val3 = new GameObject("LOOT SORTER", new Type[1] { typeof(RectTransform) });
		RectTransform val4 = (RectTransform)val3.transform;
		((Transform)val4).SetParent(parent, false);
		val4.anchorMin = Vector2.zero;
		val4.anchorMax = Vector2.one;
		val4.offsetMin = Vector2.zero;
		val4.offsetMax = Vector2.zero;
		val3.SetActive(false);
		pc.pages.Add(val3);
		int index = pc.pages.Count - 1;
		LootSorterPage lootSorterPage = val3.AddComponent<LootSorterPage>();
		lootSorterPage.Build(pc, parent, val2.transform);
		Transform val5 = val2.transform.Find("BUTTONS");
		Transform val6 = ((!((Object)(object)val5 != (Object)null)) ? null : val5.Find("CUSTOMIZATION BUTTON"));
		if ((Object)(object)val6 == (Object)null)
		{
			return;
		}
		GameObject val7 = new GameObject("tmpHolder");
		val7.SetActive(false);
		GameObject val8 = Object.Instantiate<GameObject>(((Component)val6).gameObject, val7.transform, false);
		((Object)val8).name = "LOOT SORTER BUTTON";
		WebsiteButton component = val8.GetComponent<WebsiteButton>();
		if ((Object)(object)component != (Object)null)
		{
			Object.DestroyImmediate((Object)(object)component);
		}
		Component[] componentsInChildren = val8.GetComponentsInChildren<Component>(true);
		foreach (Component val9 in componentsInChildren)
		{
			if ((Object)(object)val9 != (Object)null && ((object)val9).GetType().Name == "Localize")
			{
				Object.DestroyImmediate((Object)(object)val9);
			}
		}
		Transform val10 = val8.transform.Find("locked");
		if ((Object)(object)val10 != (Object)null)
		{
			((Component)val10).gameObject.SetActive(false);
		}
		Transform val11 = val8.transform.Find("normal");
		if ((Object)(object)val11 != (Object)null)
		{
			((Component)val11).gameObject.SetActive(true);
			Transform val12 = val11.Find("img");
			if ((Object)(object)val12 != (Object)null)
			{
				Image component2 = ((Component)val12).GetComponent<Image>();
				Sprite val13 = ((IEnumerable<Sprite>)Resources.FindObjectsOfTypeAll<Sprite>()).FirstOrDefault((Func<Sprite, bool>)((Sprite sp) => (Object)(object)sp != (Object)null && ((Object)sp).name == "Diamond"));
				if ((Object)(object)component2 != (Object)null && (Object)(object)val13 != (Object)null)
				{
					component2.sprite = val13;
					component2.preserveAspect = true;
				}
				if ((Object)(object)component2 != (Object)null)
				{
					((Graphic)component2).color = new Color(1f, 0.83f, 0f);
				}
			}
		}
		TMP_Text componentInChildren = val8.GetComponentInChildren<TMP_Text>(true);
		if ((Object)(object)componentInChildren != (Object)null)
		{
			componentInChildren.text = Loc.T("Organizador", "Sorter");
		}
		iconLabel = componentInChildren;
		Button component3 = val8.GetComponent<Button>();
		((Selectable)component3).interactable = true;
		for (int num2 = 0; num2 < ((UnityEventBase)component3.onClick).GetPersistentEventCount(); num2++)
		{
			((UnityEventBase)component3.onClick).SetPersistentListenerState(num2, (UnityEventCallState)0);
		}
		((UnityEvent)component3.onClick).AddListener((UnityAction)delegate
		{
			pc.ActivatePage(index);
		});
		val8.transform.SetParent(val5, false);
		val8.transform.SetSiblingIndex(val6.GetSiblingIndex() + 1);
		Object.Destroy((Object)(object)val7);
	}
}
public class LootSorterPage : MonoBehaviour
{
	private enum Filter
	{
		All,
		Seller,
		Safe,
		Truck
	}

	private static readonly Color ColSeller = new Color(0.95f, 0.6f, 0.15f);

	private static readonly Color ColSafe = new Color(0.3f, 0.8f, 0.3f);

	private static readonly Color ColTruck = new Color(0.6f, 0.6f, 0.66f);

	private static readonly Color ColAccent = new Color(0.3f, 0.5f, 0.85f);

	private static readonly Color ColOff = new Color(0.22f, 0.22f, 0.26f);

	private Filter filter;

	private TMP_FontAsset font;

	private RectTransform content;

	private TMP_Text header;

	private TMP_Text info;

	private TMP_Text refreshLabel;

	private TMP_Text soundLabel;

	private Image soundImg;

	private GameObject listArea;

	private GameObject tabsRow;

	private readonly Dictionary<Filter, Image> tabImgs = new Dictionary<Filter, Image>();

	private readonly Dictionary<Filter, TMP_Text> tabTxts = new Dictionary<Filter, TMP_Text>();

	public void Build(Computer pc, Transform canvas, Transform mainPage)
	{
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Expected O, but got Unknown
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: 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_0136: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: 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_0215: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: Expected O, but got Unknown
		//IL_0291: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_032e: Unknown result type (might be due to invalid IL or missing references)
		//IL_033d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0342: Unknown result type (might be due to invalid IL or missing references)
		//IL_0385: Unknown result type (might be due to invalid IL or missing references)
		//IL_038f: Expected O, but got Unknown
		//IL_039a: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a1: Expected O, but got Unknown
		//IL_03b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0439: Unknown result type (might be due to invalid IL or missing references)
		//IL_0440: Expected O, but got Unknown
		//IL_0448: Unknown result type (might be due to invalid IL or missing references)
		//IL_0452: Expected O, but got Unknown
		//IL_0475: Unknown result type (might be due to invalid IL or missing references)
		//IL_048f: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c3: Unknown result type (might be due to invalid IL or missing references)
		TMP_Text componentInChildren = ((Component)mainPage).GetComponentInChildren<TMP_Text>(true);
		font = ((!((Object)(object)componentInChildren != (Object)null)) ? null : componentInChildren.font);
		RectTransform val = (RectTransform)((Component)this).transform;
		Image val2 = MakeImage((Transform)(object)val, "BG", new Color(0.08f, 0.09f, 0.12f, 0.97f));
		Stretch(((Graphic)val2).rectTransform, 20f, 4f);
		header = MakeText((Transform)(object)val, string.Empty, 13f, (TextAlignmentOptions)513, new Vector2(-65f, 124f), new Vector2(340f, 18f));
		header.fontStyle = (FontStyles)1;
		Transform val3 = canvas.Find("STORE/Main Store/CLOSE");
		if ((Object)(object)val3 != (Object)null)
		{
			GameObject val4 = Object.Instantiate<GameObject>(((Component)val3).gameObject, (Transform)(object)val, false);
			((RectTransform)val4.transform).anchoredPosition = new Vector2(232f, 123f);
		}
		else
		{
			MakeButton((Transform)(object)val, "X", new Vector2(232f, 123f), new Vector2(18f, 18f), new Color(0.7f, 0.2f, 0.2f), 11f, delegate
			{
				pc.ActivatePage(0);
			});
		}
		RectTransform val5 = MakeButton((Transform)(object)val, string.Empty, new Vector2(163f, 123f), new Vector2(104f, 16f), ColOff, 8.5f, delegate
		{
			Plugin.Inst.DeathSoundEnabled.Value = !Plugin.Inst.DeathSoundEnabled.Value;
			((BaseUnityPlugin)Plugin.Inst).Config.Save();
			Refresh();
		});
		soundImg = ((Component)val5).GetComponent<Image>();
		soundLabel = ((Component)val5).GetComponentInChildren<TMP_Text>();
		info = MakeText((Transform)(object)val, string.Empty, 9.5f, (TextAlignmentOptions)513, new Vector2(-132f, 104f), new Vector2(216f, 16f));
		tabsRow = new GameObject("Tabs", new Type[1] { typeof(RectTransform) });
		tabsRow.transform.SetParent((Transform)(object)val, false);
		float num = -8f;
		foreach (Filter value in Enum.GetValues(typeof(Filter)))
		{
			Filter ff = value;
			RectTransform val6 = MakeButton(tabsRow.transform, string.Empty, new Vector2(num, 104f), new Vector2(50f, 16f), ColOff, 9.5f, delegate
			{
				filter = ff;
				Refresh();
			});
			tabImgs[value] = ((Component)val6).GetComponent<Image>();
			tabTxts[value] = ((Component)val6).GetComponentInChildren<TMP_Text>();
			num += 53f;
		}
		RectTransform val7 = MakeButton((Transform)(object)val, string.Empty, new Vector2(212f, 104f), new Vector2(62f, 16f), ColAccent, 8.5f, Refresh);
		refreshLabel = ((Component)val7).GetComponentInChildren<TMP_Text>();
		listArea = new GameObject("List", new Type[1] { typeof(RectTransform) });
		RectTransform val8 = (RectTransform)listArea.transform;
		((Transform)val8).SetParent((Transform)(object)val, false);
		val8.anchoredPosition = new Vector2(0f, -22f);
		val8.sizeDelta = new Vector2(480f, 226f);
		Image val9 = MakeImage((Transform)(object)val8, "Viewport", new Color(0f, 0f, 0f, 0.25f));
		Stretch(((Graphic)val9).rectTransform, 0f, 0f);
		((Component)val9).gameObject.AddComponent<RectMask2D>();
		GameObject val10 = new GameObject("Content", new Type[1] { typeof(RectTransform) });
		content = (RectTransform)val10.transform;
		((Transform)content).SetParent((Transform)(object)((Graphic)val9).rectTransform, false);
		content.anchorMin = new Vector2(0f, 1f);
		content.anchorMax = new Vector2(1f, 1f);
		content.pivot = new Vector2(0.5f, 1f);
		content.sizeDelta = new Vector2(0f, 0f);
		ScrollRect val11 = listArea.AddComponent<ScrollRect>();
		val11.viewport = ((Graphic)val9).rectTransform;
		val11.content = content;
		val11.horizontal = false;
		val11.movementType = (MovementType)2;
		val11.scrollSensitivity = 20f;
	}

	private void OnEnable()
	{
		Refresh();
	}

	private static string DestName(Dest d)
	{
		return d switch
		{
			Dest.Seller => "Seller", 
			Dest.Safe => "Safe", 
			_ => Loc.T("Caminhão", "Truck"), 
		};
	}

	private static Color DestColor(Dest d)
	{
		//IL_0007: 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_0017: Unknown result type (might be due to invalid IL or missing references)
		return (Color)(d switch
		{
			Dest.Safe => ColSafe, 
			Dest.Seller => ColSeller, 
			_ => ColTruck, 
		});
	}

	private void Refresh()
	{
		//IL_00cd: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_045c: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)content == (Object)null)
		{
			return;
		}
		header.text = Loc.T("Organizador de Loot", "Loot Sorter");
		if ((Object)(object)refreshLabel != (Object)null)
		{
			refreshLabel.text = Loc.T("Atualizar", "Refresh");
		}
		bool value = Plugin.Inst.DeathSoundEnabled.Value;
		soundLabel.text = Loc.T("Som de morte: ", "Death sound: ") + ((!value) ? "OFF" : "ON");
		((Graphic)soundImg).color = (Color)((!value) ? ColOff : new Color(0.16f, 0.45f, 0.2f));
		((Graphic)soundLabel).color = Color.white;
		tabTxts[Filter.All].text = Loc.T("Todos", "All");
		tabTxts[Filter.Seller].text = "Seller";
		tabTxts[Filter.Safe].text = "Safe";
		tabTxts[Filter.Truck].text = Loc.T("Caminhão", "Truck");
		foreach (KeyValuePair<Filter, Image> tabImg in tabImgs)
		{
			((Graphic)tabImg.Value).color = ((tabImg.Key == filter) ? ((tabImg.Key != Filter.Seller) ? ((tabImg.Key != Filter.Safe) ? ((tabImg.Key != Filter.Truck) ? ColAccent : ColTruck) : ColSafe) : ColSeller) : ColOff);
		}
		for (int num = ((Transform)content).childCount - 1; num >= 0; num--)
		{
			Object.Destroy((Object)(object)((Component)((Transform)content).GetChild(num)).gameObject);
		}
		if (!Runner.IsHost())
		{
			info.text = Loc.T("As regras são definidas pelo host.", "Rules are set by the host.");
			listArea.SetActive(false);
			tabsRow.SetActive(false);
			return;
		}
		listArea.SetActive(true);
		tabsRow.SetActive(true);
		List<Item> list = (from p in Runner.TruckPickups()
			select p.assignedItem into i
			where (Object)(object)i != (Object)null
			select i).Distinct().ToList();
		string reason;
		List<Item> list2 = list.Where(delegate(Item i)
		{
			if (filter == Filter.All)
			{
				return true;
			}
			Dest dest = Plugin.Inst.Resolve(i, out reason);
			return (filter == Filter.Seller && dest == Dest.Seller) || (filter == Filter.Safe && dest == Dest.Safe) || (filter == Filter.Truck && dest == Dest.Truck);
		}).OrderBy(Plugin.IsHardTruck).ThenBy(Plugin.DisplayName)
			.ToList();
		info.text = Loc.T("No caminhão: ", "In truck: ") + list.Count + ((filter != Filter.All) ? (Loc.T("   Exibindo: ", "   Showing: ") + list2.Count) : string.Empty) + ((!list2.Any(Plugin.IsHardTruck)) ? string.Empty : Loc.T("   (! = ferramenta)", "   (! = tool)"));
		float num2 = -2f;
		foreach (Item item in list2)
		{
			AddRow(item, num2, 22f);
			num2 -= 24f;
		}
		content.sizeDelta = new Vector2(0f, 0f - num2 + 2f);
	}

	private void AddRow(Item item, float y, float h)
	{
		//IL_0064: 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_0081: 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_00ab: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0245: Unknown result type (might be due to invalid IL or missing references)
		//IL_023b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0281: Unknown result type (might be due to invalid IL or missing references)
		//IL_0277: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
		bool flag = Plugin.IsHardTruck(item);
		Image val = MakeImage((Transform)(object)content, "Row", (!flag) ? new Color(1f, 1f, 1f, 0.05f) : new Color(0.95f, 0.45f, 0.1f, 0.14f));
		RectTransform rectTransform = ((Graphic)val).rectTransform;
		rectTransform.anchorMin = new Vector2(0f, 1f);
		rectTransform.anchorMax = new Vector2(1f, 1f);
		rectTransform.pivot = new Vector2(0.5f, 1f);
		rectTransform.anchoredPosition = new Vector2(0f, y);
		rectTransform.sizeDelta = new Vector2(-6f, h);
		string reason;
		Dest dest = Plugin.Inst.Resolve(item, out reason);
		Image val2 = MakeImage((Transform)(object)rectTransform, "Bar", DestColor(dest));
		((Graphic)val2).rectTransform.sizeDelta = new Vector2(4f, h);
		Pin(((Graphic)val2).rectTransform, 0f);
		TMP_Text val3 = MakeText((Transform)(object)rectTransform, ((!flag) ? string.Empty : "! ") + Plugin.DisplayName(item), 10.5f, (TextAlignmentOptions)513, Vector2.zero, new Vector2(215f, h));
		val3.fontStyle = (FontStyles)1;
		if (flag)
		{
			((Graphic)val3).color = new Color(1f, 0.78f, 0.45f);
		}
		Pin(val3.rectTransform, 9f);
		TMP_Text val4 = MakeText((Transform)(object)rectTransform, DestName(dest), 10f, (TextAlignmentOptions)513, Vector2.zero, new Vector2(70f, h));
		((Graphic)val4).color = DestColor(dest);
		Pin(val4.rectTransform, 228f);
		Dest value;
		Dest dest2 = ((!Plugin.Inst.Rules.TryGetValue(((Object)item).name, out value)) ? dest : value);
		float num = 300f;
		AddChoice(rectTransform, "Seller", num, h, (dest2 != Dest.Seller) ? ColOff : ColSeller, delegate
		{
			SetRule(item, Dest.Seller);
		});
		num += 57f;
		AddChoice(rectTransform, "Safe", num, h, (dest2 != Dest.Safe) ? ColOff : ColSafe, delegate
		{
			SetRule(item, Dest.Safe);
		});
		num += 57f;
		AddChoice(rectTransform, Loc.T("Caminhão", "Truck"), num, h, (dest2 != Dest.Truck) ? ColOff : ColTruck, delegate
		{
			SetRule(item, Dest.Truck);
		});
	}

	private void AddChoice(RectTransform row, string label, float x, float h, Color col, Action onClick)
	{
		//IL_0003: 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)
		RectTransform rt = MakeButton((Transform)(object)row, label, Vector2.zero, new Vector2(54f, h - 4f), col, 9.5f, onClick);
		Pin(rt, x);
	}

	private void SetRule(Item item, Dest d)
	{
		Plugin.Inst.Rules[((Object)item).name] = d;
		Plugin.Inst.SaveRules();
		Refresh();
	}

	private static void Pin(RectTransform rt, float left)
	{
		//IL_000b: 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_0035: 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)
		rt.anchorMin = new Vector2(0f, 0.5f);
		rt.anchorMax = new Vector2(0f, 0.5f);
		rt.pivot = new Vector2(0f, 0.5f);
		rt.anchoredPosition = new Vector2(left, 0f);
	}

	private static void Stretch(RectTransform rt, float padX, float padY)
	{
		//IL_0001: 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 reference