Decompiled source of Cheats v1.0.1

meadworks.cheats.dll

Decompiled 29 minutes ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using MeadWorks.Core;
using MeadWorks.UI;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_guiutils")]
[assembly: IgnoresAccessChecksTo("assembly_utils")]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("expDARE")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright (c) 2026 expDARE")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("meadworks.cheats")]
[assembly: AssemblyTitle("meadworks.cheats")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MeadWorks.Cheats
{
	public static class BoatWindRules
	{
		public static bool Applies(bool enabled, long localPlayer, long steeringPlayer)
		{
			if (enabled && localPlayer != 0L)
			{
				return localPlayer == steeringPlayer;
			}
			return false;
		}
	}
	internal static class BoatWind
	{
		[HarmonyPatch(typeof(EnvMan), "GetWindDir")]
		private static class Patches
		{
			[HarmonyPostfix]
			private static void Direction(ref Vector3 __result)
			{
				//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_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)
				Ship val = ControlledShip();
				if (!((Object)(object)val == (Object)null))
				{
					Vector3 forward = ((Component)val).transform.forward;
					forward.y = 0f;
					if (((Vector3)(ref forward)).sqrMagnitude > 0.0001f)
					{
						__result = ((Vector3)(ref forward)).normalized;
					}
				}
			}
		}

		private static Setting<bool> _on;

		internal static bool Active => (Object)(object)ControlledShip() != (Object)null;

		public static void Init(SettingsPage page)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			_on = page.Toggle("boat_wind", "Wind behind the boat", false, (SettingPolicy)3, false);
			Harmony val = new Harmony("expdare.meadworks.cheats.boatwind");
			val.PatchAll(typeof(Patches));
			LedgerTrack.Patch(val, "cheats boat wind");
			Ledger.Add("cheats boat wind state", (Action)delegate
			{
				_on = null;
			});
		}

		private static Ship ControlledShip()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return null;
			}
			Ship localShip = Ship.GetLocalShip();
			if ((Object)(object)localShip == (Object)null || (Object)(object)localShip.m_shipControlls == (Object)null)
			{
				return null;
			}
			if (!BoatWindRules.Applies(_on != null && _on.Value, localPlayer.GetPlayerID(), localShip.m_shipControlls.GetUser()))
			{
				return null;
			}
			return localShip;
		}
	}
	public static class CarriedMarksRules
	{
		public static bool Applies(bool hasNet, bool server, ServerPresence presence, bool hasClear, bool hasReport)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Invalid comparison between Unknown and I4
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Invalid comparison between Unknown and I4
			if (!(!hasNet || server) && (int)presence != 2)
			{
				return (int)presence == 1 && hasClear && hasReport;
			}
			return true;
		}

		public static int Process(IEnumerable<ItemData> items, bool enabled, bool local, bool reportOnly, Action<ItemData> cleaned = null)
		{
			if (!enabled || !local || items == null)
			{
				return 0;
			}
			int num = 0;
			foreach (ItemData item in items)
			{
				if (item != null && item.m_cheated)
				{
					num++;
					if (!reportOnly)
					{
						item.m_cheated = false;
						cleaned?.Invoke(item);
					}
				}
			}
			return num;
		}
	}
	public static class CheatPolicyRules
	{
		public static bool Enabled(bool value, bool authority, bool serverInEffect)
		{
			if (value)
			{
				return authority || serverInEffect;
			}
			return false;
		}
	}
	internal static class CheatsActions
	{
		internal static bool Allowed
		{
			get
			{
				if ((Object)(object)Player.m_localPlayer != (Object)null && !((Character)Player.m_localPlayer).IsDead())
				{
					return Settings.CanAdmin;
				}
				return false;
			}
		}

		internal static int CreatureMaxStars
		{
			get
			{
				Setting<bool> val = Settings.Find("creatures.elites") as Setting<bool>;
				Setting<string> val2 = Settings.Find("creatures.elite_preset") as Setting<string>;
				Setting val3 = Settings.Find("creatures.elite_max_level");
				return CreatureSpawnRules.MaxStars(val != null && val.Value && val2?.Value != "Off", (int)((val3 != null) ? val3.Max : 2f));
			}
		}

		internal static string SpawnCreature(GameObject prefab, int count, int stars)
		{
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			if (!Allowed)
			{
				return Lang.T("cheats.only_a_solo_player_host_or_admin_can_use_cheats", "Only a solo player, host or admin can use cheats.");
			}
			ZNetScene instance = ZNetScene.instance;
			bool eligible = (Object)(object)instance != (Object)null && (Object)(object)prefab != (Object)null && instance.m_prefabs.Contains(prefab) && CheatsWindow.CatalogCreature(prefab, "");
			if (!CreatureSpawnRules.TryRequest(Allowed, eligible, count, stars, elites: true, CreatureMaxStars, out var amount, out var level))
			{
				return Lang.T("cheats.choose_a_creature", "Choose a creature.");
			}
			Player localPlayer = Player.m_localPlayer;
			for (int i = 0; i < amount; i++)
			{
				Vector3 val = ((Component)localPlayer).transform.position + ((Component)localPlayer).transform.forward * 2f + Vector3.up;
				if (amount > 1)
				{
					val += Random.insideUnitSphere * 0.5f;
				}
				GameObject obj = Object.Instantiate<GameObject>(prefab, val, Quaternion.identity);
				ZNetView component = obj.GetComponent<ZNetView>();
				if (component != null)
				{
					ZDO zDO = component.GetZDO();
					if (zDO != null)
					{
						CheatUtils.SetCheated(zDO, !PlayerProfile.s_bypassCheatChecks);
					}
				}
				obj.GetComponent<Character>().SetLevel(level);
			}
			return Lang.T("cheats.spawned", "Spawned: {0}.", new object[1] { amount });
		}

		internal static string Spawn(GameObject prefab, string amountText, int quality, bool give, bool showBoss)
		{
			if (!Allowed)
			{
				return Lang.T("cheats.only_a_solo_player_host_or_admin_can_use_cheats", "Only a solo player, host or admin can use cheats.");
			}
			Player player = Player.m_localPlayer;
			ItemDrop val = (((Object)(object)prefab != (Object)null && (Object)(object)ObjectDB.instance != (Object)null && ObjectDB.instance.m_items.Contains(prefab)) ? prefab.GetComponent<ItemDrop>() : null);
			SharedData val2 = val?.m_itemData?.m_shared;
			if (val2 == null || !CheatsWindow.CatalogItem(val, showBoss, ""))
			{
				return Lang.T("cheats.choose_an_item", "Choose an item.");
			}
			if (!CheatsWindowRules.TryAmount(amountText, out var amount))
			{
				return Lang.T("cheats.amount_must_be_1_to_1000", "Amount must be 1 to 1000.");
			}
			Inventory inventory = ((Humanoid)player).GetInventory();
			if (inventory == null)
			{
				return Lang.T("cheats.inventory_is_unavailable", "Inventory is unavailable.");
			}
			ItemData prototype = val.m_itemData.Clone();
			prototype.m_dropPrefab = prefab;
			prototype.m_quality = CheatsWindowRules.Quality(quality, val2.m_maxQuality);
			prototype.m_variant = 0;
			prototype.m_equipped = false;
			prototype.m_durability = prototype.GetMaxDurability();
			prototype.m_cheated = true;
			ItemData remainder = null;
			int num = CheatsWindowRules.Deliver(amount, val2.m_maxStackSize, give ? ((Func<int, int>)delegate(int count)
			{
				remainder = Stack(count);
				return (!inventory.AddItem(remainder)) ? remainder.m_stack : 0;
			}) : null, delegate(int count)
			{
				//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_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_0047: Unknown result type (might be due to invalid IL or missing references)
				ItemData obj = remainder ?? Stack(count);
				LootMultiplier.PreventMultiplication(obj);
				ItemDrop.DropItem(obj, count, ((Component)player).transform.position + Vector3.up * 0.5f, ((Component)player).transform.rotation);
			});
			if (!give)
			{
				return Lang.T("cheats.dropped", "Dropped: {0}.", new object[1] { amount });
			}
			return Lang.T("cheats.given_dropped", "Given: {0}. Dropped: {1}.", new object[2]
			{
				num,
				amount - num
			});
			ItemData Stack(int count)
			{
				ItemData obj = prototype.Clone();
				obj.m_stack = count;
				Unmarked.PrepareSpawned(obj);
				return obj;
			}
		}

		internal static string Heal()
		{
			if (!Allowed)
			{
				return Lang.T("cheats.only_a_solo_player_host_or_admin_can_use_cheats", "Only a solo player, host or admin can use cheats.");
			}
			Player localPlayer = Player.m_localPlayer;
			((Character)localPlayer).Heal(((Character)localPlayer).GetMaxHealth(), true);
			((Character)localPlayer).AddStamina(((Character)localPlayer).GetMaxStamina());
			((Character)localPlayer).AddEitr(((Character)localPlayer).GetMaxEitr());
			return Lang.T("cheats.health_stamina_and_eitr_restored", "Health, stamina and eitr restored.");
		}

		internal static string Repair()
		{
			if (!Allowed)
			{
				return Lang.T("cheats.only_a_solo_player_host_or_admin_can_use_cheats", "Only a solo player, host or admin can use cheats.");
			}
			Inventory inventory = ((Humanoid)Player.m_localPlayer).GetInventory();
			if (inventory == null)
			{
				return Lang.T("cheats.inventory_is_unavailable", "Inventory is unavailable.");
			}
			int num = 0;
			foreach (ItemData allItem in inventory.GetAllItems())
			{
				if (allItem?.m_shared != null && allItem.m_shared.m_useDurability)
				{
					float maxDurability = allItem.GetMaxDurability();
					if (!(allItem.m_durability >= maxDurability))
					{
						allItem.m_durability = maxDurability;
						num++;
					}
				}
			}
			if (num > 0)
			{
				inventory.Changed(false, false);
			}
			return Lang.T("cheats.repaired", "Repaired: {0}.", new object[1] { num });
		}
	}
	[BepInPlugin("expdare.meadworks.cheats", "Meadworks: Cheats", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class CheatsPlugin : BaseUnityPlugin
	{
		public const string Guid = "expdare.meadworks.cheats";

		public const string DisplayName = "Meadworks: Cheats";

		private void Awake()
		{
			ModuleLife.Start("cheats", (Action)Init);
		}

		private void OnDisable()
		{
			ModuleLife.Leaving("cheats");
		}

		private void OnDestroy()
		{
			ModuleLife.End("cheats");
		}

		private void Init()
		{
			SettingsPage obj = Settings.Page(((BaseUnityPlugin)this).Config, "cheats", "Cheats");
			NativeCheats.Init(obj);
			PlayerModes.Init(obj);
			OneHitKill.Init(obj);
			PinTravel.Init();
			CheatsWindow.Init();
			obj.Button("window", "Cheats window", "Open", (Action)CheatsWindow.Open, false);
			DestroyTools.Init(obj);
			BoatWind.Init(obj);
			SafeStamina.Init(obj);
			SafeStamina.MoveActionDefaults(((BaseUnityPlugin)this).Config);
			LootMultiplier.Init(obj);
			FlagsTab.Init(obj);
			Unmarked.Init(obj);
			Settings.DropRetired(((BaseUnityPlugin)this).Config, new string[2] { "safe_swim", "unmarked_objects" });
			MwLog.Debug((object)"cheats ready");
		}
	}
	internal sealed class CheatsWindow : MonoBehaviour
	{
		private RectTransform _creatures;

		private KitTab _creaturesTab;

		private KitList _creatureList;

		private KitSearch _creatureSearch;

		private KitStepper _creatureCount;

		private KitStepper _creatureStars;

		private KitButton _creaturePrevious;

		private KitButton _creatureNext;

		private KitButton _creatureSpawn;

		private TMP_Text _creatureSelection;

		private TMP_Text _creaturePageLabel;

		private GameObject _creatureSelected;

		private KitRow _creatureSelectedRow;

		private readonly List<GameObject> _creatureCatalog = new List<GameObject>();

		private List<GameObject> _creatureMatches = new List<GameObject>();

		private int _creaturePage;

		private static CheatsWindow _open;

		private Player _player;

		private KitPanel _panel;

		private RectTransform _items;

		private RectTransform _recovery;

		private KitTab _itemsTab;

		private KitTab _playerTab;

		private KitList _list;

		private KitSearch _search;

		private KitTextField _amount;

		private KitStepper _quality;

		private KitButton _previous;

		private KitButton _next;

		private KitButton _give;

		private KitButton _drop;

		private KitButton _return;

		private TMP_Text _selection;

		private TMP_Text _pageLabel;

		private TMP_Text _result;

		private GameObject _selected;

		private KitRow _selectedRow;

		private readonly List<GameObject> _catalog = new List<GameObject>();

		private List<GameObject> _matches = new List<GameObject>();

		private bool _showBoss;

		private int _page;

		private Vector2 _screen;

		private float _nextAuthorityCheck;

		private void BuildCreatures()
		{
			_creatureSearch = Kit.Search((Transform)(object)_creatures, Lang.T("cheats.search_creatures", "Search creatures"), (Action<string>)delegate
			{
				FilterCreatures();
			});
			_creatureList = Kit.List((Transform)(object)_creatures, 0f);
			((Component)_creatureList).GetComponent<LayoutElement>().flexibleHeight = 1f;
			RectTransform val = TipParts.Stack((Transform)(object)_creatures, "Pages", true, 8f, (RectOffset)null);
			_creaturePrevious = Kit.Button((Transform)(object)val, Lang.T("cheats.previous", "Previous"), (Action)delegate
			{
				_creaturePage--;
				FillCreatures();
			}, false);
			_creaturePageLabel = (TMP_Text)(object)Kit.Label((Transform)(object)val, "Page", "");
			_creatureNext = Kit.Button((Transform)(object)val, Lang.T("cheats.next", "Next"), (Action)delegate
			{
				_creaturePage++;
				FillCreatures();
			}, false);
			_creatureSelection = (TMP_Text)(object)Kit.Label((Transform)(object)_creatures, "Selected", Lang.T("cheats.choose_a_creature_2", "Choose a creature"));
			Kit.WrapText(_creatureSelection);
			RectTransform obj = TipParts.Stack((Transform)(object)_creatures, "Values", true, 12f, (RectOffset)null);
			RectTransform val2 = TipParts.Stack((Transform)(object)obj, "Count", false, 4f, (RectOffset)null);
			Kit.Label((Transform)(object)val2, "Label", "Count");
			_creatureCount = Kit.Stepper((Transform)(object)val2, 1, 1, 10, (Action<int>)delegate
			{
			}, (string)null);
			RectTransform val3 = TipParts.Stack((Transform)(object)obj, "Stars", false, 4f, (RectOffset)null);
			Kit.Label((Transform)(object)val3, "Label", "Stars");
			_creatureStars = Kit.Stepper((Transform)(object)val3, 0, 0, CheatsActions.CreatureMaxStars, (Action<int>)delegate
			{
			}, (string)null);
			_creatureSpawn = Kit.Button((Transform)(object)_creatures, Lang.T("cheats.spawn", "Spawn"), (Action)delegate
			{
				Result(CheatsActions.SpawnCreature(_creatureSelected, _creatureCount.Value, _creatureStars.Value));
			}, true);
			if ((Object)(object)ZNetScene.instance != (Object)null)
			{
				foreach (GameObject prefab in ZNetScene.instance.m_prefabs)
				{
					if (CatalogCreature(prefab, "") && !_creatureCatalog.Contains(prefab))
					{
						_creatureCatalog.Add(prefab);
					}
				}
			}
			_creatureCatalog.Sort((GameObject a, GameObject b) => string.Compare(CreatureName(a), CreatureName(b), StringComparison.CurrentCultureIgnoreCase));
			FilterCreatures();
		}

		internal static bool CatalogCreature(GameObject prefab, string query)
		{
			Character val = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<Character>() : null);
			if ((Object)(object)val != (Object)null)
			{
				return CreatureSpawnRules.Visible(CreatureName(prefab), character: true, val.IsPlayer() || (Object)(object)prefab.GetComponent<Player>() != (Object)null, query);
			}
			return false;
		}

		private static string CreatureName(GameObject prefab)
		{
			string name = prefab.GetComponent<Character>().m_name;
			if (Localization.instance == null)
			{
				return name;
			}
			return Localization.instance.Localize(name);
		}

		private void FilterCreatures()
		{
			if (!((Object)(object)_creatureSpawn == (Object)null))
			{
				_creatureMatches = _creatureCatalog.Where((GameObject p) => CatalogCreature(p, _creatureSearch.Query)).ToList();
				_creaturePage = 0;
				if ((Object)(object)_creatureSelected != (Object)null && !_creatureMatches.Contains(_creatureSelected))
				{
					SelectCreature(null, null);
				}
				FillCreatures();
			}
		}

		private void FillCreatures()
		{
			_creatureList.Clear();
			_creatureSelectedRow = null;
			int num = Math.Max(1, (_creatureMatches.Count + 40 - 1) / 40);
			_creaturePage = Math.Max(0, Math.Min(_creaturePage, num - 1));
			foreach (GameObject prefab in _creatureMatches.Skip(_creaturePage * 40).Take(40))
			{
				KitRow row = _creatureList.AddRow(CreatureName(prefab));
				row.Selected = (Object)(object)prefab == (Object)(object)_creatureSelected;
				if (row.Selected)
				{
					_creatureSelectedRow = row;
				}
				row.OnClick = delegate
				{
					SelectCreature(prefab, row);
				};
			}
			if (_creatureMatches.Count == 0)
			{
				_creatureList.AddRow(Lang.T("cheats.no_matching_creatures", "No matching creatures"));
			}
			_creaturePageLabel.text = _creaturePage + 1 + " / " + num;
			((Selectable)_creaturePrevious).interactable = _creaturePage > 0;
			((Selectable)_creatureNext).interactable = _creaturePage + 1 < num;
			RefreshCreatureActions();
		}

		private void SelectCreature(GameObject prefab, KitRow row)
		{
			if ((Object)(object)_creatureSelectedRow != (Object)null)
			{
				_creatureSelectedRow.Selected = false;
			}
			_creatureSelected = prefab;
			_creatureSelectedRow = row;
			if ((Object)(object)row != (Object)null)
			{
				row.Selected = true;
			}
			_creatureSelection.text = (((Object)(object)prefab != (Object)null) ? CreatureName(prefab) : Lang.T("cheats.choose_a_creature_2", "Choose a creature"));
			((Component)_result).gameObject.SetActive(false);
			RefreshCreatureActions();
		}

		private void RefreshCreatureActions()
		{
			if (!((Object)(object)_creatureSpawn == (Object)null))
			{
				_creatureStars.SetRange(0, CheatsActions.CreatureMaxStars);
				((Selectable)_creatureSpawn).interactable = (Object)(object)_creatureSelected != (Object)null && CheatsActions.Allowed;
				_creatureStars.Interactable = (Object)(object)_creatureSelected != (Object)null;
			}
		}

		internal static void Init()
		{
			Ledger.Add("cheats window", (Action)delegate
			{
				if ((Object)(object)_open != (Object)null)
				{
					_open.Close();
				}
			});
		}

		internal static void Open()
		{
			if ((Object)(object)_open != (Object)null)
			{
				return;
			}
			if (!CheatsActions.Allowed)
			{
				Player localPlayer = Player.m_localPlayer;
				if (localPlayer != null)
				{
					((Character)localPlayer).Message((MessageType)2, Lang.T("cheats.only_a_solo_player_host_or_admin_can_use_cheats", "Only a solo player, host or admin can use cheats."), 0, (Sprite)null, false);
				}
			}
			else
			{
				SettingsWindow.Close();
				KitPanel val = Kit.Window(Lang.T("cheats.cheats", "Cheats"), 800f, 1f);
				_open = ((Component)val).gameObject.AddComponent<CheatsWindow>();
				_open._panel = val;
				_open._player = Player.m_localPlayer;
				_open.Build();
			}
		}

		private void Build()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			_panel.AddClose((Action)Close);
			ContentSizeFitter component = ((Component)_panel).GetComponent<ContentSizeFitter>();
			FitMode horizontalFit = (FitMode)0;
			component.verticalFit = (FitMode)0;
			component.horizontalFit = horizontalFit;
			KitTabStrip val = Kit.TabStrip((Transform)(object)_panel.Content);
			_itemsTab = val.Tab(Lang.T("cheats.items", "Items"), (Action)delegate
			{
				Show(0);
			});
			_creaturesTab = val.Tab(Lang.T("cheats.creatures", "Creatures"), (Action)delegate
			{
				Show(1);
			});
			_playerTab = val.Tab(Lang.T("cheats.player", "Player"), (Action)delegate
			{
				Show(2);
			});
			_items = Page("Items");
			_creatures = Page("Creatures");
			_recovery = Page("Player");
			_result = (TMP_Text)(object)Kit.Label((Transform)(object)_panel.Content, "Result", "");
			Kit.WrapText(_result);
			((Component)_result).gameObject.SetActive(false);
			BuildItems();
			BuildCreatures();
			Kit.Button((Transform)(object)_recovery, Lang.T("cheats.heal", "Heal"), (Action)delegate
			{
				Result(CheatsActions.Heal());
			}, false);
			Kit.Button((Transform)(object)_recovery, Lang.T("cheats.repair", "Repair"), (Action)delegate
			{
				Result(CheatsActions.Repair());
			}, false);
			Kit.Button((Transform)(object)_recovery, Lang.T("cheats.clear_ground_items", "Clear ground items"), (Action)delegate
			{
				Result(DestroyTools.ClearGround());
			}, false);
			_return = Kit.Button((Transform)(object)_recovery, Lang.T("cheats.return", "Return"), (Action)delegate
			{
				Result(PinTravel.Return());
			}, false);
			((Selectable)_return).interactable = PinTravel.CanReturn;
			Show(0);
			Fit();
		}

		private RectTransform Page(string name)
		{
			RectTransform obj = TipParts.Stack((Transform)(object)_panel.Content, name, false, 8f, (RectOffset)null);
			LayoutElement obj2 = ((Component)obj).gameObject.AddComponent<LayoutElement>();
			float num = (obj2.preferredHeight = 0f);
			float minWidth = (obj2.minHeight = num);
			obj2.minWidth = minWidth;
			obj2.flexibleHeight = 1f;
			return obj;
		}

		private void Show(int page)
		{
			((Component)_items).gameObject.SetActive(page == 0);
			((Component)_creatures).gameObject.SetActive(page == 1);
			((Component)_recovery).gameObject.SetActive(page == 2);
			_itemsTab.Open = page == 0;
			_creaturesTab.Open = page == 1;
			_playerTab.Open = page == 2;
			((Component)_result).gameObject.SetActive(false);
		}

		private void BuildItems()
		{
			_search = Kit.Search((Transform)(object)_items, Lang.T("cheats.search_items", "Search items"), (Action<string>)delegate
			{
				Filter();
			});
			Kit.Toggle((Transform)(object)TipParts.Stack((Transform)(object)_items, "BossItems", true, 8f, (RectOffset)null), Lang.T("cheats.show_boss_and_key_items", "Show boss and key items"), false, (Action<bool>)delegate(bool value)
			{
				_showBoss = value;
				Filter();
			});
			_list = Kit.List((Transform)(object)_items, 0f);
			((Component)_list).GetComponent<LayoutElement>().flexibleHeight = 1f;
			RectTransform val = TipParts.Stack((Transform)(object)_items, "Pages", true, 8f, (RectOffset)null);
			_previous = Kit.Button((Transform)(object)val, Lang.T("cheats.previous", "Previous"), (Action)delegate
			{
				_page--;
				Fill();
			}, false);
			_pageLabel = (TMP_Text)(object)Kit.Label((Transform)(object)val, "Page", "");
			_next = Kit.Button((Transform)(object)val, Lang.T("cheats.next", "Next"), (Action)delegate
			{
				_page++;
				Fill();
			}, false);
			_selection = (TMP_Text)(object)Kit.Label((Transform)(object)_items, "Selected", Lang.T("cheats.choose_an_item_2", "Choose an item"));
			Kit.WrapText(_selection);
			RectTransform obj = TipParts.Stack((Transform)(object)_items, "Values", true, 12f, (RectOffset)null);
			RectTransform val2 = TipParts.Stack((Transform)(object)obj, "Amount", false, 4f, (RectOffset)null);
			((Component)val2).gameObject.AddComponent<LayoutElement>().flexibleWidth = 1f;
			Kit.Label((Transform)(object)val2, "Label", "Amount");
			_amount = Kit.TextField((Transform)(object)val2, "1", (Action<string>)delegate
			{
				RefreshActions();
			});
			_amount.Live = true;
			_amount.MaxLength = 4;
			Kit.HoverName((Component)(object)_amount, Lang.T("cheats.amount_1_1000", "Amount (1–1000)"));
			LayoutElement component = ((Component)_amount).GetComponent<LayoutElement>();
			float minWidth = (component.preferredWidth = 0f);
			component.minWidth = minWidth;
			component.flexibleWidth = 1f;
			RectTransform val3 = TipParts.Stack((Transform)(object)obj, "Quality", false, 4f, (RectOffset)null);
			Kit.Label((Transform)(object)val3, "Label", "Quality");
			_quality = Kit.Stepper((Transform)(object)val3, 1, 1, 1, (Action<int>)delegate
			{
			}, (string)null);
			RectTransform val4 = TipParts.Stack((Transform)(object)_items, "Actions", true, 8f, (RectOffset)null);
			_give = Kit.Button((Transform)(object)val4, Lang.T("cheats.give", "Give"), (Action)delegate
			{
				Spawn(give: true);
			}, true);
			_drop = Kit.Button((Transform)(object)val4, Lang.T("cheats.drop", "Drop"), (Action)delegate
			{
				Spawn(give: false);
			}, false);
			if ((Object)(object)ObjectDB.instance != (Object)null)
			{
				foreach (GameObject item in ObjectDB.instance.m_items)
				{
					if (CatalogItem(((Object)(object)item != (Object)null) ? item.GetComponent<ItemDrop>() : null, showBoss: true, "") && !_catalog.Contains(item))
					{
						_catalog.Add(item);
					}
				}
			}
			_catalog.Sort((GameObject a, GameObject b) => string.Compare(Name(a), Name(b), StringComparison.CurrentCultureIgnoreCase));
			Filter();
		}

		internal static bool CatalogItem(ItemDrop item, bool showBoss, string query)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Invalid comparison between Unknown and I4
			//IL_0043: 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_0052: Invalid comparison between Unknown and I4
			SharedData val = item?.m_itemData?.m_shared;
			if (val != null)
			{
				return CheatsWindowRules.Visible(((Object)((Component)item).gameObject).name, Name(((Component)item).gameObject), (int)val.m_itemType == 13, val.m_questItem, (int)val.m_itemType != 0 && (int)val.m_itemType != 10 && val.m_maxStackSize > 0 && val.m_maxQuality > 0 && (Object)(object)ItemIcons.Default(val) != (Object)null, showBoss, query);
			}
			return false;
		}

		private static string Name(GameObject prefab)
		{
			string name = prefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_name;
			if (Localization.instance == null)
			{
				return name;
			}
			return Localization.instance.Localize(name);
		}

		private void Filter()
		{
			if (!((Object)(object)_list == (Object)null) && !((Object)(object)_give == (Object)null))
			{
				_matches = _catalog.Where((GameObject p) => (Object)(object)p != (Object)null && CatalogItem(p.GetComponent<ItemDrop>(), _showBoss, _search.Query)).ToList();
				_page = 0;
				if ((Object)(object)_selected != (Object)null && !_matches.Contains(_selected))
				{
					Select(null, null);
				}
				Fill();
			}
		}

		private void Fill()
		{
			_list.Clear();
			_selectedRow = null;
			int num = Math.Max(1, (_matches.Count + 40 - 1) / 40);
			_page = Math.Max(0, Math.Min(_page, num - 1));
			foreach (GameObject prefab in _matches.Skip(_page * 40).Take(40))
			{
				KitRow row = _list.AddRow(Name(prefab));
				Kit.Slot((Transform)(object)row.Lead, (SlotSize)3).Icon = ItemIcons.Default(prefab.GetComponent<ItemDrop>());
				row.Selected = (Object)(object)prefab == (Object)(object)_selected;
				if (row.Selected)
				{
					_selectedRow = row;
				}
				row.OnClick = delegate
				{
					Select(prefab, row);
				};
			}
			if (_matches.Count == 0)
			{
				_list.AddRow(Lang.T("cheats.no_matching_items", "No matching items"));
			}
			_pageLabel.text = _page + 1 + " / " + num;
			((Selectable)_previous).interactable = _page > 0;
			((Selectable)_next).interactable = _page + 1 < num;
			RefreshActions();
		}

		private void Select(GameObject prefab, KitRow row)
		{
			if ((Object)(object)_selectedRow != (Object)null)
			{
				_selectedRow.Selected = false;
			}
			_selected = prefab;
			_selectedRow = row;
			if ((Object)(object)row != (Object)null)
			{
				row.Selected = true;
			}
			int num = ((!((Object)(object)prefab != (Object)null)) ? 1 : prefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_maxQuality);
			_quality.SetRange(1, num);
			_selection.text = (((Object)(object)prefab != (Object)null) ? Name(prefab) : Lang.T("cheats.choose_an_item_2", "Choose an item"));
			((Component)_result).gameObject.SetActive(false);
			RefreshActions();
		}

		private void RefreshActions()
		{
			KitButton give = _give;
			int amount;
			bool interactable = (((Selectable)_drop).interactable = (Object)(object)_selected != (Object)null && CheatsWindowRules.TryAmount(_amount.Value, out amount));
			((Selectable)give).interactable = interactable;
			_quality.Interactable = (Object)(object)_selected != (Object)null;
		}

		private void Spawn(bool give)
		{
			Result(CheatsActions.Spawn(_selected, _amount.Value, _quality.Value, give, _showBoss));
		}

		private void Result(string message)
		{
			_result.text = message;
			((Component)_result).gameObject.SetActive(true);
		}

		private void Fit()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = Root.Transform;
			RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			if (!((Object)(object)val == (Object)null))
			{
				Rect rect = val.rect;
				Vector2 size = ((Rect)(ref rect)).size;
				if (!(_screen == size))
				{
					_screen = size;
					RectTransform val2 = (RectTransform)((Component)this).transform;
					val2.SetSizeWithCurrentAnchors((Axis)0, Mathf.Min(800f, size.x - 32f));
					val2.SetSizeWithCurrentAnchors((Axis)1, Mathf.Min(720f, size.y - 32f));
				}
			}
		}

		private void Update()
		{
			if ((Object)(object)_player != (Object)(object)Player.m_localPlayer)
			{
				Close();
				return;
			}
			if (Time.unscaledTime >= _nextAuthorityCheck)
			{
				_nextAuthorityCheck = Time.unscaledTime + 0.25f;
				if (!CheatsActions.Allowed)
				{
					Close();
					return;
				}
				((Selectable)_return).interactable = PinTravel.CanReturn;
				RefreshCreatureActions();
			}
			Fit();
		}

		private void Close()
		{
			if ((Object)(object)_open == (Object)(object)this)
			{
				_open = null;
			}
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}

		private void OnDestroy()
		{
			if ((Object)(object)_open == (Object)(object)this)
			{
				_open = null;
			}
		}
	}
	public static class CheatsWindowRules
	{
		public const int MaxAmount = 1000;

		public const int PageSize = 40;

		public static bool TryAmount(string text, out int amount)
		{
			if (int.TryParse(text, NumberStyles.None, CultureInfo.InvariantCulture, out amount) && amount >= 1)
			{
				return amount <= 1000;
			}
			return false;
		}

		public static int Quality(int value, int nativeMax)
		{
			return Math.Max(1, Math.Min(value, Math.Max(1, nativeMax)));
		}

		public static bool Visible(string prefab, string name, bool trophy, bool quest, bool normal, bool showBoss, string query)
		{
			if (!normal || string.IsNullOrWhiteSpace(name))
			{
				return false;
			}
			string text = name.Trim();
			if (text.StartsWith("[", StringComparison.Ordinal) && text.EndsWith("]", StringComparison.Ordinal))
			{
				return false;
			}
			if (text.StartsWith("$", StringComparison.Ordinal))
			{
				return false;
			}
			string[] debugItems = RoundRules.DebugItems;
			for (int i = 0; i < debugItems.Length; i++)
			{
				if (string.Equals(debugItems[i], prefab, StringComparison.OrdinalIgnoreCase))
				{
					return false;
				}
			}
			if (!showBoss && (quest || LootRules.IsBoss(prefab, trophy)))
			{
				return false;
			}
			return name.IndexOf((query ?? "").Trim(), StringComparison.CurrentCultureIgnoreCase) >= 0;
		}

		public static int Deliver(int amount, int maxStack, Func<int, int> giveRemaining, Action<int> drop)
		{
			if (amount < 1 || amount > 1000 || maxStack < 1)
			{
				return 0;
			}
			int num = 0;
			foreach (int item in LootRules.Chunks(amount, maxStack))
			{
				int num2 = giveRemaining?.Invoke(item) ?? item;
				num += item - num2;
				if (num2 > 0)
				{
					drop(num2);
				}
			}
			return num;
		}
	}
	public static class CreatureSpawnRules
	{
		public static bool Visible(string name, bool character, bool player, string query)
		{
			if (!character || player || string.IsNullOrWhiteSpace(name))
			{
				return false;
			}
			string text = name.Trim();
			if (text.StartsWith("$", StringComparison.Ordinal) || (text.StartsWith("[", StringComparison.Ordinal) && text.EndsWith("]", StringComparison.Ordinal)))
			{
				return false;
			}
			return name.IndexOf((query ?? "").Trim(), StringComparison.CurrentCultureIgnoreCase) >= 0;
		}

		public static int MaxStars(bool elites, int eliteMax)
		{
			if (!elites)
			{
				return 2;
			}
			return Math.Max(2, Math.Min(8, eliteMax));
		}

		public static bool TryRequest(bool allowed, bool eligible, int count, int stars, bool elites, int eliteMax, out int amount, out int level)
		{
			amount = (level = 0);
			if (!allowed || !eligible)
			{
				return false;
			}
			amount = Math.Max(1, Math.Min(10, count));
			level = Math.Max(0, Math.Min(MaxStars(elites, eliteMax), stars)) + 1;
			return true;
		}
	}
	public enum DeleteAim
	{
		Nothing,
		Kept,
		Delete
	}
	public static class DestroyRules
	{
		public const float GroundRadius = 30f;

		public static bool Enabled(bool on, bool allowed)
		{
			return on && allowed;
		}

		public static bool GroundItem(bool networked, bool piece, bool swimmingFish, float distance)
		{
			if (networked && !piece && !swimmingFish)
			{
				return distance <= 30f;
			}
			return false;
		}

		public static bool InReach(float distance, float reach, float offset)
		{
			return distance < reach + offset;
		}

		public static DeleteAim Aim(bool networked, bool player, bool grave, bool altar, bool location)
		{
			if (!(player || grave || altar || location))
			{
				if (!networked)
				{
					return DeleteAim.Nothing;
				}
				return DeleteAim.Delete;
			}
			return DeleteAim.Kept;
		}
	}
	internal static class DestroyTools
	{
		private const string DeleteKey = "cheats.delete";

		private static Setting<bool> _delete;

		private static readonly RaycastHit[] Hits = (RaycastHit[])(object)new RaycastHit[64];

		private static readonly List<ItemDrop> Drops = new List<ItemDrop>();

		internal static bool DeleteActive
		{
			get
			{
				if (_delete != null)
				{
					return DestroyRules.Enabled(_delete.Value, CheatsActions.Allowed);
				}
				return false;
			}
		}

		internal static void Init(SettingsPage page)
		{
			page.Toggle("trash_anything", "Trash anything", false, (SettingPolicy)3, false);
			_delete = page.Toggle("delete_tool", "Delete tool", false, (SettingPolicy)3, false);
			Keys.Register("cheats.delete", "Delete", (Action)DeleteAimed, (KeyScope)1);
			page.Key("delete_key", "cheats.delete", "Delete aimed object", false);
			Ledger.Add("cheats destroy tools", (Action)delegate
			{
				_delete = null;
				Drops.Clear();
			});
		}

		internal static string ClearGround()
		{
			//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_00be: 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)
			if (!CheatsActions.Allowed)
			{
				return Lang.T("cheats.only_a_solo_player_host_or_admin_can_use_cheats", "Only a solo player, host or admin can use cheats.");
			}
			Player localPlayer = Player.m_localPlayer;
			Vector3 position = ((Component)localPlayer).transform.position;
			Drops.Clear();
			Drops.AddRange(ItemDrop.s_instances);
			int num = 0;
			foreach (ItemDrop drop in Drops)
			{
				if (!((Object)(object)drop == (Object)null))
				{
					ZNetView component = ((Component)drop).GetComponent<ZNetView>();
					Fish component2 = ((Component)drop).GetComponent<Fish>();
					if (DestroyRules.GroundItem((Object)(object)component != (Object)null && component.IsValid(), drop.IsPiece() || (Object)(object)((Component)drop).GetComponent<Piece>() != (Object)null, (Object)(object)component2 != (Object)null && !component2.IsOutOfWater(), Vector3.Distance(position, ((Component)drop).transform.position)) && Remove(component))
					{
						num++;
					}
				}
			}
			Drops.Clear();
			string text = Lang.T("cheats.removed_ground_items", "Removed ground items: {0}.", new object[1] { num });
			((Character)localPlayer).Message((MessageType)1, text, 0, (Sprite)null, false);
			return text;
		}

		private static void DeleteAimed()
		{
			Player localPlayer = Player.m_localPlayer;
			if (!DeleteActive || (Object)(object)GameCamera.instance == (Object)null || !((Character)localPlayer).TakeInput())
			{
				return;
			}
			GameObject hitObject;
			ZNetView val = Aimed(localPlayer, out hitObject);
			GameObject val2 = (((Object)(object)val != (Object)null) ? ((Component)val).gameObject : hitObject);
			string text = (((Object)(object)val2 != (Object)null) ? Utils.GetPath(val2.transform) : "");
			switch (DestroyRules.Aim((Object)(object)val != (Object)null && val.IsValid(), Has<Player>(val2), Has<TombStone>(val2), Has<OfferingBowl>(val2) || Has<BossStone>(val2) || Has<Vegvisir>(val2) || GuardianStand(val2) || text.Contains("BossStone") || text.Contains("StartTemple"), Has<LocationProxy>(val2) || Has<Location>(val2) || Has<DungeonGenerator>(val2) || Has<Room>(val2) || Has<Valkyrie>(val2) || Has<Game>(val2)))
			{
			case DeleteAim.Kept:
				((Character)localPlayer).Message((MessageType)1, Lang.T("cheats.this_cannot_be_deleted", "This cannot be deleted."), 0, (Sprite)null, false);
				break;
			case DeleteAim.Delete:
			{
				string text2 = Name(val2);
				if (Remove(val))
				{
					((Character)localPlayer).Message((MessageType)1, Lang.T("cheats.deleted", "Deleted: {0}.", new object[1] { text2 }), 0, (Sprite)null, false);
				}
				break;
			}
			}
		}

		private static bool Has<T>(GameObject target) where T : Component
		{
			if ((Object)(object)target != (Object)null)
			{
				if (!((Object)(object)target.GetComponentInParent<T>() != (Object)null))
				{
					return (Object)(object)target.GetComponentInChildren<T>(true) != (Object)null;
				}
				return true;
			}
			return false;
		}

		private static bool GuardianStand(GameObject target)
		{
			if ((Object)(object)target == (Object)null)
			{
				return false;
			}
			ItemStand componentInParent = target.GetComponentInParent<ItemStand>();
			if ((Object)(object)componentInParent != (Object)null && (Object)(object)componentInParent.m_guardianPower != (Object)null)
			{
				return true;
			}
			ItemStand[] componentsInChildren = target.GetComponentsInChildren<ItemStand>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				if ((Object)(object)componentsInChildren[i].m_guardianPower != (Object)null)
				{
					return true;
				}
			}
			return false;
		}

		private static ZNetView Aimed(Player player, out GameObject hitObject)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: 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)
			hitObject = null;
			Transform transform = ((Component)GameCamera.instance).transform;
			int num = Physics.RaycastNonAlloc(transform.position, transform.forward, Hits, 50f, player.m_interactMask);
			int num2 = -1;
			for (int i = 0; i < num; i++)
			{
				Rigidbody attachedRigidbody = ((RaycastHit)(ref Hits[i])).collider.attachedRigidbody;
				if ((!((Object)(object)attachedRigidbody != (Object)null) || !((Object)(object)((Component)attachedRigidbody).gameObject == (Object)(object)((Component)player).gameObject)) && (num2 < 0 || ((RaycastHit)(ref Hits[i])).distance < ((RaycastHit)(ref Hits[num2])).distance))
				{
					num2 = i;
				}
			}
			if (num2 < 0)
			{
				return null;
			}
			RaycastHit val = Hits[num2];
			hitObject = ((Component)((RaycastHit)(ref val)).collider).gameObject;
			Hoverable componentInParent = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<Hoverable>();
			if (!DestroyRules.InReach(Vector3.Distance(((Character)player).m_eye.position, ((RaycastHit)(ref val)).point), player.m_maxInteractDistance, (componentInParent != null) ? componentInParent.GetHoverOffset() : 0f))
			{
				return null;
			}
			return ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<ZNetView>();
		}

		private static string Name(GameObject target)
		{
			Piece component = target.GetComponent<Piece>();
			Hoverable component2 = target.GetComponent<Hoverable>();
			string text = (((Object)(object)component != (Object)null) ? component.m_name : ((component2 != null) ? component2.GetHoverName() : null));
			if (string.IsNullOrEmpty(text))
			{
				text = Utils.GetPrefabName(((Object)target).name);
			}
			if (Localization.instance == null)
			{
				return text;
			}
			return Localization.instance.Localize(text);
		}

		private static bool Remove(ZNetView view)
		{
			if ((Object)(object)view == (Object)null || !view.IsValid() || (Object)(object)ZNetScene.instance == (Object)null)
			{
				return false;
			}
			view.ClaimOwnership();
			ZNetScene.instance.Destroy(((Component)view).gameObject);
			return true;
		}
	}
	public static class FlagPlaceRules
	{
		public const float Gap = 8f;

		public static bool PlaceUnderCompass(float centre, float top, float w, float h, float[] boxes, int count, float width, float height, float floor, out float ox, out float oy)
		{
			ox = centre - w * 0.5f;
			oy = top;
			float num = ((floor > 0f) ? Math.Min(height, floor) : height);
			if (w <= 0f || h <= 0f || ox < 0f || ox + w > width || top < 0f)
			{
				return false;
			}
			for (int i = 0; i <= count; i++)
			{
				if (oy + h > num)
				{
					return false;
				}
				float num2 = oy;
				for (int j = 0; j < count; j++)
				{
					int num3 = j * 4;
					if (Hits(ox, oy, w, h, boxes[num3], boxes[num3 + 1], boxes[num3 + 2], boxes[num3 + 3]))
					{
						num2 = Math.Max(num2, boxes[num3 + 3] + 8f);
					}
				}
				if (num2 == oy)
				{
					return true;
				}
				oy = num2;
			}
			return false;
		}

		public static bool Hits(float x, float y, float w, float h, float left, float top, float right, float bottom)
		{
			if (w <= 0f || h <= 0f || right <= left || bottom <= top)
			{
				return false;
			}
			if (x < right && x + w > left && y < bottom)
			{
				return y + h > top;
			}
			return false;
		}

		public static bool PlaceOnScreen(float x, float y, float w, float h, float[] boxes, int count, float width, float height, float floor, out float ox, out float oy)
		{
			if (w <= 0f || h <= 0f || width <= 0f || height <= 0f)
			{
				ox = (oy = 0f);
				return false;
			}
			Place(x, y, w, h, boxes, count, width, floor, out ox, out oy);
			float bottom = ((floor > 0f) ? Math.Min(height, floor) : height);
			if (Fits(ox, oy))
			{
				return true;
			}
			for (int i = -3; i < count * 2; i++)
			{
				float num = i switch
				{
					-1 => width - w - 8f, 
					-2 => 8f, 
					-3 => (width - w) / 2f, 
					_ => (i % 2 == 0) ? (boxes[i / 2 * 4] - w - 8f) : (boxes[i / 2 * 4 + 2] + 8f), 
				};
				for (int j = -3; j < count * 2; j++)
				{
					float num2 = j switch
					{
						-1 => bottom - h - 8f, 
						-2 => 8f, 
						-3 => 96f, 
						_ => (j % 2 == 0) ? (boxes[j / 2 * 4 + 1] - h - 8f) : (boxes[j / 2 * 4 + 3] + 8f), 
					};
					if (Fits(num, num2))
					{
						ox = num;
						oy = num2;
						return true;
					}
				}
			}
			return false;
			bool Fits(float cx, float cy)
			{
				if (cx >= 0f && cy >= 0f && cx + w <= width && cy + h <= bottom)
				{
					return Free(cx, cy, w, h, boxes, count);
				}
				return false;
			}
		}

		public static void Place(float x, float y, float w, float h, float[] boxes, int count, float limit, out float ox, out float oy)
		{
			Place(x, y, w, h, boxes, count, limit, 0f, out ox, out oy);
		}

		public static void Place(float x, float y, float w, float h, float[] boxes, int count, float limit, float floor, out float ox, out float oy)
		{
			ox = x;
			oy = y;
			if (count > 0 && limit > 0f)
			{
				float num = boxes[0];
				float num2 = boxes[1];
				for (int i = 1; i < count; i++)
				{
					num = Math.Min(num, boxes[i * 4]);
					num2 = Math.Min(num2, boxes[i * 4 + 1]);
				}
				if (x >= 0f && x + w <= limit && y >= 0f && y + h <= num2 && Free(x, y, w, h, boxes, count))
				{
					return;
				}
				float num3 = float.PositiveInfinity;
				for (int j = 0; j < count; j++)
				{
					if (boxes[j * 4] < num + w && boxes[j * 4 + 2] > num)
					{
						num3 = Math.Min(num3, boxes[j * 4 + 1]);
					}
				}
				float num4 = num3 - 8f - h;
				if (num >= 0f && num4 >= 0f && num + w <= limit && Free(num, num4, w, h, boxes, count))
				{
					ox = num;
					oy = num4;
					return;
				}
			}
			bool flag = false;
			for (int k = 0; k < count; k++)
			{
				bool flag2 = false;
				for (int l = 0; l < count; l++)
				{
					int num5 = l * 4;
					if (Hits(ox, oy, w, h, boxes[num5], boxes[num5 + 1], boxes[num5 + 2], boxes[num5 + 3]))
					{
						ox = boxes[num5 + 2] + 8f;
						flag2 = (flag = true);
					}
				}
				if (!flag2)
				{
					break;
				}
			}
			if (!flag || limit <= 0f || ox + w <= limit)
			{
				return;
			}
			bool flag3 = false;
			float num6 = x;
			float num7 = y;
			for (int m = -1; m < count; m++)
			{
				float num8 = ((m < 0) ? x : (boxes[m * 4 + 2] + 8f));
				if (num8 < 0f || num8 + w > limit || (flag3 && num6 == x && num8 != x))
				{
					continue;
				}
				for (int n = -1; n < count; n++)
				{
					float num9 = ((n < 0) ? y : (boxes[n * 4 + 3] + 8f));
					if (!(num9 < y) && (!(floor > 0f) || !(num9 + h > floor)) && Free(num8, num9, w, h, boxes, count) && (!flag3 || (!(num9 > num7) && (num9 != num7 || !(Math.Abs(num8 - x) >= Math.Abs(num6 - x))))))
					{
						flag3 = true;
						num6 = num8;
						num7 = num9;
					}
				}
			}
			if (flag3)
			{
				ox = num6;
				oy = num7;
				return;
			}
			float num10 = y;
			for (int num11 = 0; num11 < count; num11++)
			{
				if (boxes[num11 * 4 + 3] > num10)
				{
					num10 = boxes[num11 * 4 + 3];
				}
			}
			ox = x;
			oy = num10 + 8f;
			if (floor > 0f && oy + h > floor)
			{
				oy = Math.Max(y, floor - h);
			}
		}

		private static bool Free(float x, float y, float w, float h, float[] boxes, int count)
		{
			for (int i = 0; i < count; i++)
			{
				if (Hits(x, y, w, h, boxes[i * 4], boxes[i * 4 + 1], boxes[i * 4 + 2], boxes[i * 4 + 3]))
				{
					return false;
				}
			}
			return true;
		}
	}
	public static class FlagRules
	{
		public static List<string> Current(bool player, bool wind, bool god, bool ghost, bool fly, bool noCost, bool dev, bool safe, SafeAction actions, bool encumbered, bool loot, int multiplier, bool noCarry = false, bool noDurability = false, bool delete = false)
		{
			List<string> list = new List<string>();
			if (player)
			{
				if (wind)
				{
					list.Add("WIND");
				}
				if (god)
				{
					list.Add("GOD");
				}
				if (ghost)
				{
					list.Add("GHOST");
				}
				if (fly)
				{
					list.Add("FLY");
				}
				if (noCost)
				{
					list.Add("NO COST");
				}
				if (noCarry)
				{
					list.Add("NO CARRY LIMIT");
				}
				if (noDurability)
				{
					list.Add("NO DURABILITY LOSS");
				}
				if (delete)
				{
					list.Add("DELETE");
				}
				if (safe)
				{
					list.Add("SAFE STAMINA");
					if ((actions & SafeAction.Sprint) != SafeAction.None)
					{
						list.Add("FREE SPRINT");
					}
					if ((actions & SafeAction.Jump) != SafeAction.None)
					{
						list.Add("FREE JUMP");
					}
					if ((actions & SafeAction.Build) != SafeAction.None)
					{
						list.Add("FREE BUILD");
					}
					if ((actions & SafeAction.Attack) != SafeAction.None)
					{
						list.Add("FREE ATTACKS");
					}
					if ((actions & SafeAction.Sneak) != SafeAction.None)
					{
						list.Add("FREE SNEAK");
					}
					if (encumbered && actions != SafeAction.None)
					{
						list.Add("ENCUMBERED");
					}
				}
				if (loot)
				{
					list.Add("LOOT X" + multiplier.ToString(CultureInfo.InvariantCulture));
				}
			}
			if (dev)
			{
				list.Add("DEVCOMMANDS");
			}
			return list;
		}

		public static string Label(string flag)
		{
			if (flag.StartsWith("LOOT X", StringComparison.Ordinal))
			{
				return Lang.T("cheats.loot_x", "Loot x{0}", new object[1] { flag.Substring(6) });
			}
			return flag switch
			{
				"WIND" => Lang.T("cheats.wind", "Wind"), 
				"GOD" => Lang.T("cheats.god", "God"), 
				"GHOST" => Lang.T("cheats.ghost", "Ghost"), 
				"FLY" => Lang.T("cheats.fly", "Fly"), 
				"NO COST" => Lang.T("cheats.no_cost", "No cost"), 
				"NO CARRY LIMIT" => Lang.T("cheats.no_carry_limit", "No carry limit"), 
				"NO DURABILITY LOSS" => Lang.T("cheats.no_durability_loss", "No durability loss"), 
				"DELETE" => Lang.T("cheats.delete", "Delete"), 
				"SAFE STAMINA" => Lang.T("cheats.safe_stamina", "Safe stamina"), 
				"FREE SPRINT" => Lang.T("cheats.free_sprint", "Free sprint"), 
				"FREE JUMP" => Lang.T("cheats.free_jump", "Free jump"), 
				"FREE BUILD" => Lang.T("cheats.free_build", "Free build"), 
				"FREE ATTACKS" => Lang.T("cheats.free_attacks", "Free attacks"), 
				"FREE SNEAK" => Lang.T("cheats.free_sneak", "Free sneak"), 
				"ENCUMBERED" => Lang.T("cheats.encumbered", "Encumbered"), 
				_ => Lang.T("cheats.dev", "Dev"), 
			};
		}

		public static string Glyph(string flag)
		{
			if (flag.StartsWith("LOOT X", StringComparison.Ordinal))
			{
				return "loot";
			}
			if (!flag.StartsWith("FREE ", StringComparison.Ordinal))
			{
				switch (flag)
				{
				case "SAFE STAMINA":
				case "ENCUMBERED":
					break;
				default:
					switch (flag.Length)
					{
					case 3:
						switch (flag[0])
						{
						case 'G':
							if (!(flag == "GOD"))
							{
								break;
							}
							return "god";
						case 'F':
							if (!(flag == "FLY"))
							{
								break;
							}
							return "fly";
						}
						break;
					case 4:
						if (!(flag == "WIND"))
						{
							break;
						}
						return "wind";
					case 5:
						if (!(flag == "GHOST"))
						{
							break;
						}
						return "ghost";
					case 7:
						if (!(flag == "NO COST"))
						{
							break;
						}
						return "nocost";
					case 14:
						if (!(flag == "NO CARRY LIMIT"))
						{
							break;
						}
						return "loot";
					case 18:
						if (!(flag == "NO DURABILITY LOSS"))
						{
							break;
						}
						return "god";
					case 6:
						if (!(flag == "DELETE"))
						{
							break;
						}
						return "warn";
					}
					goto case null;
				case null:
					return "dev";
				}
			}
			return "stamina";
		}
	}
	public static class FlagsTab
	{
		private sealed class Driver : MonoBehaviour
		{
			private readonly Vector3[] _corners = (Vector3[])(object)new Vector3[4];

			private float[] _boxes = new float[32];

			private GameObject _tab;

			private RectTransform[] _tags;

			private float[] _widths;

			private CanvasGroup _visibility;

			private string _key = "";

			private float _next;

			internal bool Shown
			{
				get
				{
					if ((Object)(object)_tab != (Object)null)
					{
						return _visibility.alpha > 0f;
					}
					return false;
				}
			}

			private void OnEnable()
			{
				ScreenWindows.Changed += QueuePlace;
				HudParts.CompassChanged += QueuePlace;
				QueuePlace();
			}

			private void OnDisable()
			{
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Expected O, but got Unknown
				ScreenWindows.Changed -= QueuePlace;
				HudParts.CompassChanged -= QueuePlace;
				Canvas.willRenderCanvases -= new WillRenderCanvases(Place);
			}

			private void OnRectTransformDimensionsChange()
			{
				QueuePlace();
			}

			internal void QueuePlace()
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Expected O, but got Unknown
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_002b: Expected O, but got Unknown
				if (((Behaviour)this).isActiveAndEnabled)
				{
					Canvas.willRenderCanvases -= new WillRenderCanvases(Place);
					Canvas.willRenderCanvases += new WillRenderCanvases(Place);
				}
			}

			private void Update()
			{
				if (!(Time.unscaledTime < _next))
				{
					_next = Time.unscaledTime + 0.25f;
					Refresh();
				}
			}

			internal void Refresh()
			{
				List<string> list = Current();
				string text = string.Join("|", list.ToArray());
				if (!(text == _key))
				{
					_key = text;
					if ((Object)(object)_tab != (Object)null)
					{
						Object.DestroyImmediate((Object)(object)_tab);
					}
					_tab = ((list.Count == 0) ? null : Build(list));
					QueuePlace();
				}
			}

			private void Place()
			{
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Expected O, but got Unknown
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_0039: Expected O, but got Unknown
				//IL_0041: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Expected O, but got Unknown
				//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_0077: Unknown result type (might be due to invalid IL or missing references)
				//IL_007c: Unknown result type (might be due to invalid IL or missing references)
				//IL_017c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0181: Unknown result type (might be due to invalid IL or missing references)
				//IL_0184: 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_0192: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00db: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_0104: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_012e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0133: Unknown result type (might be due to invalid IL or missing references)
				//IL_013c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0143: 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_0160: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b5: 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_0513: Unknown result type (might be due to invalid IL or missing references)
				//IL_051e: Unknown result type (might be due to invalid IL or missing references)
				//IL_053a: Unknown result type (might be due to invalid IL or missing references)
				//IL_053f: Unknown result type (might be due to invalid IL or missing references)
				//IL_054e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0553: Unknown result type (might be due to invalid IL or missing references)
				//IL_0576: Unknown result type (might be due to invalid IL or missing references)
				//IL_057b: Unknown result type (might be due to invalid IL or missing references)
				//IL_057d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0582: Unknown result type (might be due to invalid IL or missing references)
				//IL_034a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0593: Unknown result type (might be due to invalid IL or missing references)
				//IL_04b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_04b7: Expected O, but got Unknown
				//IL_04bb: Unknown result type (might be due to invalid IL or missing references)
				//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_04e6: Unknown result type (might be due to invalid IL or missing references)
				//IL_04eb: Unknown result type (might be due to invalid IL or missing references)
				//IL_04f6: Unknown result type (might be due to invalid IL or missing references)
				//IL_04fe: Unknown result type (might be due to invalid IL or missing references)
				Canvas.willRenderCanvases -= new WillRenderCanvases(Place);
				if ((Object)(object)_tab == (Object)null)
				{
					return;
				}
				RectTransform val = (RectTransform)_tab.transform;
				RectTransform parent = (RectTransform)((Transform)val).parent;
				Rect rect = parent.rect;
				float num = ((Rect)(ref rect)).width * 0.5f;
				float num2 = 70f;
				rect = parent.rect;
				float num3 = Mathf.Min(600f, ((Rect)(ref rect)).width);
				RectTransform val2 = (RectTransform)(((Object)(object)HudParts.CompassSlot != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
				if ((Object)(object)val2 != (Object)null)
				{
					val2.GetWorldCorners(_corners);
					Vector2 val3 = ScreenWindows.In(val2, _corners[0], parent);
					Vector2 val4 = ScreenWindows.In(val2, _corners[3], parent);
					float num4 = (val3.x + val4.x) * 0.5f;
					rect = parent.rect;
					num = num4 - ((Rect)(ref rect)).xMin;
					rect = parent.rect;
					num2 = ((Rect)(ref rect)).yMax - Mathf.Min(val3.y, val4.y) + 10f;
					num3 = Mathf.Min(num3, val4.x - val3.x);
				}
				float[] array = default(float[]);
				float[] array2 = default(float[]);
				ChipSize val5 = TagMath.ChipRows(_widths, num3, ref array, ref array2, true);
				val.sizeDelta = new Vector2(val5.Width, val5.Height);
				for (int i = 0; i < _tags.Length; i++)
				{
					_tags[i].anchoredPosition = new Vector2(array[i], 0f - array2[i]);
				}
				Vector2 val6 = default(Vector2);
				((Vector2)(ref val6))..ctor(num - val5.Width * 0.5f, 0f - num2);
				int count = 0;
				InventoryGui instance = InventoryGui.instance;
				int num5 = ScreenWindows.Count + 7;
				if (_boxes.Length < num5 * 4)
				{
					_boxes = new float[num5 * 4];
				}
				if (InventoryGui.IsVisible() && (Object)(object)instance != (Object)null && (Object)(object)instance.m_player != (Object)null)
				{
					bool any = false;
					float left = 0f;
					float top = 0f;
					float right = 0f;
					float bottom = 0f;
					if (!ScreenWindows.HasSurface(instance.m_player))
					{
						Take(instance.m_player, parent, ref any, ref left, ref top, ref right, ref bottom);
					}
					count = Box(count, any, left, top, right, bottom);
					any = false;
					if ((Object)(object)instance.m_currentContainer != (Object)null && !ScreenWindows.HasSurface(instance.m_container))
					{
						Take(instance.m_container, parent, ref any, ref left, ref top, ref right, ref bottom);
					}
					count = Box(count, any, left, top, right, bottom);
					any = false;
					if (!SideColumn.Folded && (Object)(object)instance.m_crafting != (Object)null)
					{
						KitHostStrip componentInChildren = ((Component)instance.m_crafting).GetComponentInChildren<KitHostStrip>();
						Take((RectTransform)((!((Object)(object)componentInChildren != (Object)null)) ? ((object)instance.m_crafting) : ((object)(RectTransform)((Component)componentInChildren).transform)), parent, ref any, ref left, ref top, ref right, ref bottom);
					}
					count = Box(count, any, left, top, right, bottom);
				}
				for (int j = 0; j < ScreenWindows.Count; j++)
				{
					RectTransform val7 = ScreenWindows.Shown(j);
					if (!((Object)(object)val7 == (Object)null))
					{
						bool any2 = false;
						float left2 = 0f;
						float top2 = 0f;
						float right2 = 0f;
						float bottom2 = 0f;
						Take(val7, parent, ref any2, ref left2, ref top2, ref right2, ref bottom2);
						count = Box(count, any2, left2, top2, right2, bottom2);
					}
				}
				HudBox(val2);
				HotkeyBar componentInChildren2 = Hud.instance.m_rootObject.GetComponentInChildren<HotkeyBar>();
				HudBox((RectTransform)(((Object)(object)componentInChildren2 != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null));
				HudBox((RectTransform)(((Object)(object)Minimap.instance != (Object)null && (Object)(object)Minimap.instance.m_smallRoot != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null));
				HudBox(HudMapSide.Bounds);
				float floor = 0f;
				if (count > 0 && (Object)(object)instance != (Object)null && !float.IsNaN(ScreenWindows.Floor))
				{
					RectTransform val8 = (RectTransform)((Component)instance).transform;
					Vector3 val9 = default(Vector3);
					((Vector3)(ref val9))..ctor(((Transform)val8).position.x, ScreenWindows.Floor, ((Transform)val8).position.z);
					rect = parent.rect;
					floor = Mathf.Max(0f, ((Rect)(ref rect)).yMax - ScreenWindows.In(val8, val9, parent).y);
				}
				float centre = num;
				float top3 = num2;
				float x = val.sizeDelta.x;
				float y = val.sizeDelta.y;
				float[] boxes = _boxes;
				int count2 = count;
				rect = parent.rect;
				float width = ((Rect)(ref rect)).width;
				rect = parent.rect;
				float ox;
				float oy;
				bool flag = FlagPlaceRules.PlaceUnderCompass(centre, top3, x, y, boxes, count2, width, ((Rect)(ref rect)).height, floor, out ox, out oy);
				((Vector2)(ref val6))..ctor(ox, 0f - oy);
				Vector2 val10 = val.anchoredPosition - val6;
				if (((Vector2)(ref val10)).sqrMagnitude > 0.25f)
				{
					val.anchoredPosition = val6;
				}
				_visibility.alpha = (flag ? 1f : 0f);
				void HudBox(RectTransform val11)
				{
					if (!((Object)(object)val11 == (Object)null))
					{
						CanvasGroup component = ((Component)val11).GetComponent<CanvasGroup>();
						if (!((Object)(object)component != (Object)null) || !(component.alpha <= 0f))
						{
							bool any3 = false;
							float left3 = 0f;
							float top4 = 0f;
							float right3 = 0f;
							float bottom3 = 0f;
							Take(val11, parent, ref any3, ref left3, ref top4, ref right3, ref bottom3);
							count = Box(count, any3, left3, top4, right3, bottom3);
						}
					}
				}
			}

			private int Box(int count, bool any, float left, float top, float right, float bottom)
			{
				if (!any)
				{
					return count;
				}
				int num = count * 4;
				_boxes[num] = left;
				_boxes[num + 1] = top;
				_boxes[num + 2] = right;
				_boxes[num + 3] = bottom;
				return count + 1;
			}

			private void Take(RectTransform row, RectTransform space, ref bool any, ref float left, ref float top, ref float right, ref float bottom)
			{
				//IL_0050: 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_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0063: Unknown result type (might be due to invalid IL or missing references)
				//IL_0068: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_0082: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)row == (Object)null || !((Component)row).gameObject.activeInHierarchy)
				{
					return;
				}
				CanvasGroup component = ((Component)row).GetComponent<CanvasGroup>();
				if ((Object)(object)component != (Object)null && component.alpha <= 0f)
				{
					return;
				}
				row.GetWorldCorners(_corners);
				for (int i = 0; i < 4; i++)
				{
					Vector2 val = ScreenWindows.In(row, _corners[i], space);
					float x = val.x;
					Rect rect = space.rect;
					float num = x - ((Rect)(ref rect)).xMin;
					rect = space.rect;
					float num2 = ((Rect)(ref rect)).yMax - val.y;
					if (!any)
					{
						left = (right = num);
						top = (bottom = num2);
						any = true;
						continue;
					}
					if (num < left)
					{
						left = num;
					}
					if (num > right)
					{
						right = num;
					}
					if (num2 < top)
					{
						top = num2;
					}
					if (num2 > bottom)
					{
						bottom = num2;
					}
				}
			}

			private GameObject Build(List<string> flags)
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Expected O, but got Unknown
				//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_0060: Unknown result type (might be due to invalid IL or missing references)
				//IL_0061: Unknown result type (might be due to invalid IL or missing references)
				//IL_0073: 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_007a: 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_0081: 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_0125: Unknown result type (might be due to invalid IL or missing references)
				//IL_012b: Unknown result type (might be due to invalid IL or missing references)
				//IL_012c: Unknown result type (might be due to invalid IL or missing references)
				//IL_012d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0133: Unknown result type (might be due to invalid IL or missing references)
				//IL_0150: Unknown result type (might be due to invalid IL or missing references)
				GameObject val = new GameObject("MeadWorks.FlagsTab", new Type[1] { typeof(RectTransform) });
				val.transform.SetParent(((Component)this).transform, false);
				_visibility = val.AddComponent<CanvasGroup>();
				_visibility.blocksRaycasts = false;
				_visibility.interactable = false;
				RectTransform val2 = (RectTransform)val.transform;
				Vector2 val3 = default(Vector2);
				((Vector2)(ref val3))..ctor(0f, 1f);
				val2.pivot = val3;
				Vector2 anchorMin = (val2.anchorMax = val3);
				val2.anchorMin = anchorMin;
				val2.anchoredPosition = new Vector2(0f, -96f);
				_tags = (RectTransform[])(object)new RectTransform[flags.Count];
				_widths = new float[flags.Count];
				for (int i = 0; i < flags.Count; i++)
				{
					_tags[i] = Tag(val.transform, flags[i], out _widths[i]);
				}
				for (int j = 0; j < flags.Count; j++)
				{
					RectTransform obj = _tags[j];
					RectTransform obj2 = _tags[j];
					RectTransform obj3 = _tags[j];
					((Vector2)(ref val3))..ctor(0f, 1f);
					obj3.pivot = val3;
					anchorMin = (obj2.anchorMax = val3);
					obj.anchorMin = anchorMin;
					_tags[j].sizeDelta = new Vector2(_widths[j], 26f);
				}
				return val;
			}

			private static RectTransform Tag(Transform parent, string flag, out float width)
			{
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Expected O, but got Unknown
				//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_0069: Unknown result type (might be due to invalid IL or missing references)
				//IL_009e: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c0: 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_00d7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
				//IL_0100: Unknown result type (might be due to invalid IL or missing references)
				//IL_012d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0144: Unknown result type (might be due to invalid IL or missing references)
				//IL_016c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0172: Unknown result type (might be due to invalid IL or missing references)
				//IL_0183: Unknown result type (might be due to invalid IL or missing references)
				//IL_0198: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c6: Expected O, but got Unknown
				GameObject val = new GameObject("Flag " + flag, new Type[1] { typeof(RectTransform) });
				val.transform.SetParent(parent, false);
				HudParts.Box(val.transform, Theme.PanelHud, Theme.Border, 6f, 1f);
				Image obj = new GameObject("Icon", new Type[1] { typeof(RectTransform) }).AddComponent<Image>();
				((Component)obj).transform.SetParent(val.transform, false);
				((Graphic)obj).raycastTarget = false;
				obj.sprite = HudGlyphs.Get(FlagRules.Glyph(flag));
				((Graphic)obj).color = Theme.Bad;
				RectTransform rectTransform = ((Graphic)obj).rectTransform;
				Vector2 val2 = default(Vector2);
				((Vector2)(ref val2))..ctor(0f, 0.5f);
				rectTransform.anchorMax = val2;
				rectTransform.anchorMin = val2;
				rectTransform.pivot = new Vector2(0f, 0.5f);
				rectTransform.anchoredPosition = new Vector2(9f, 0f);
				rectTransform.sizeDelta = new Vector2(13f, 13f);
				string text = FlagRules.Label(flag);
				TextMeshProUGUI obj2 = HudParts.Label(val.transform, "Name", text, 13f, 0f);
				((Graphic)obj2).color = Theme.Bad;
				((TMP_Text)obj2).alignment = (TextAlignmentOptions)4097;
				float num = Mathf.Ceil(((TMP_Text)obj2).GetPreferredValues(text).x);
				RectTransform rectTransform2 = ((TMP_Text)obj2).rectTransform;
				((Vector2)(ref val2))..ctor(0f, 0.5f);
				rectTransform2.anchorMax = val2;
				rectTransform2.anchorMin = val2;
				rectTransform2.pivot = new Vector2(0f, 0.5f);
				rectTransform2.anchoredPosition = new Vector2(27f, 0f);
				rectTransform2.sizeDelta = new Vector2(num, 20f);
				width = TagMath.ChipWidth(num);
				return (RectTransform)val.transform;
			}
		}

		private static class Patches
		{
			[HarmonyPatch(typeof(Hud), "Awake")]
			[HarmonyPostfix]
			private static void Awake()
			{
				Rebuild();
			}

			[HarmonyPatch(typeof(InventoryGui), "Show")]
			[HarmonyPostfix]
			private static void WindowShown()
			{
				ScreenWindows.Invalidate();
			}

			[HarmonyPatch(typeof(InventoryGui), "Hide")]
			[HarmonyPostfix]
			private static void WindowHidden()
			{
				ScreenWindows.Invalidate();
			}
		}

		private static Setting<bool> _on;

		private static GameObject _driver;

		public static void Init(SettingsPage page)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			_on = page.Toggle("flags_tab", "Cheat flags tab", false, (SettingPolicy)3, false);
			((Setting)_on).Changed += Rebuild;
			Theme.Changed += Rebuild;
			Harmony val = new Harmony("expdare.meadworks.cheats.flags");
			val.PatchAll(typeof(Patches));
			LedgerTrack.Patch(val, "cheats flags tab");
			Ledger.Add("cheats flags tab", (Action)delegate
			{
				((Setting)_on).Changed -= Rebuild;
				Theme.Changed -= Rebuild;
				Remove();
				_on = null;
			});
			Rebuild();
		}

		public static string Status()
		{
			Driver driver = (((Object)(object)_driver != (Object)null) ? _driver.GetComponent<Driver>() : null);
			if ((Object)(object)driver != (Object)null)
			{
				driver.Refresh();
			}
			return "flags=" + string.Join(",", Current().ToArray()) + " tab=" + ((Object)(object)driver != (Object)null && driver.Shown);
		}

		internal static List<string> Current()
		{
			Player localPlayer = Player.m_localPlayer;
			return FlagRules.Current((Object)(object)localPlayer != (Object)null, BoatWind.Active, (Object)(object)localPlayer != (Object)null && ((Character)localPlayer).InGodMode(), (Object)(object)localPlayer != (Object)null && ((Character)localPlayer).InGhostMode(), (Object)(object)localPlayer != (Object)null && ((Character)localPlayer).IsDebugFlying(), (Object)(object)localPlayer != (Object)null && localPlayer.NoCostCheat(), Terminal.m_cheat, SafeStamina.Enabled, SafeStamina.Actions, SafeStamina.Encumbered, LootMultiplier.Enabled, LootMultiplier.Amount, PlayerModes.NoCarry, PlayerModes.NoDurability, DestroyTools.DeleteActive);
		}

		private static void Remove()
		{
			if ((Object)(object)_driver != (Object)null)
			{
				Object.Destroy((Object)(object)_driver);
			}
			_driver = null;
		}

		private static void Rebuild()
		{
			Remove();
			if (_on != null && _on.Value && !((Object)(object)Hud.instance == (Object)null))
			{
				_driver = ((Component)HudParts.Stretch("MeadWorks.Flags", Hud.instance.m_rootObject.transform)).gameObject;
				HudParts.AboveWindows(_driver);
				HudParts.HideOnMap(_driver);
				_driver.AddComponent<Driver>().Refresh();
			}
		}
	}
	public static class GodRules
	{
		public static bool Protects(bool godMode, bool localPlayer, bool owner)
		{
			return godMode && localPlayer && owner;
		}

		public static bool Restore(bool remembered, bool allowed)
		{
			return remembered && allowed;
		}

		public static float Health(bool protect, float current, float requested, float maximum = float.PositiveInfinity, bool loading = false)
		{
			if (!protect || loading || !(requested < current))
			{
				return requested;
			}
			return Math.Max(requested, Math.Min(current, maximum));
		}
	}
	public static class LootMultiplier
	{
		private sealed class State
		{
			public ItemData Item;

			public ItemData Prototype;

			public int Stack;

			public bool Marked;
		}

		private static class Patches
		{
			[HarmonyPatch(typeof(Humanoid), "Pickup")]
			[HarmonyPrefix]
			private static void Pickup(Humanoid __instance, GameObject go, out object __state)
			{
				__state = Before(__instance, go);
			}

			[HarmonyPatch(typeof(Humanoid), "Pickup")]
			[HarmonyPostfix]
			private static void PickupDone(Humanoid __instance, bool __result, object __state)
			{
				After(__instance, __result, __state as State);
			}
		}

		private const string Mark = "meadworks.cheats.nomult";

		private static Setting<bool> _on;

		private static Setting<float> _amount;

		private static Setting<string> _never;

		private static Harmony _harmony;

		internal static bool Enabled
		{
			get
			{
				if (_on != null)
				{
					return _on.Value;
				}
				return false;
			}
		}

		internal static int Amount
		{
			get
			{
				if (_amount != null)
				{
					return (int)Math.Round(_amount.Value);
				}
				return 2;
			}
		}

		internal static void PreventMultiplication(ItemData item)
		{
			item.m_customData["meadworks.cheats.nomult"] = "1";
		}

		public static void Init(SettingsPage page)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			_on = page.Toggle("loot", "Loot multiplier", false, (SettingPolicy)3, false);
			_amount = page.Slider("loot_amount", "Multiplier", 2f, 2f, 10f, 1f, (SettingPolicy)3, true);
			_never = page.Text("loot_never", "Never multiply", "", (SettingPolicy)3, true);
			_harmony = new Harmony("expdare.meadworks.cheats.loot");
			_harmony.PatchAll(typeof(Patches));
			LedgerTrack.Patch(_harmony, "cheats loot");
			Ledger.Add("cheats loot state", (Action)delegate
			{
				_on = null;
				_amount = null;
				_never = null;
			});
		}

		private static State Before(Humanoid who, GameObject go)
		{
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Invalid comparison between Unknown and I4
			if (_on == null || _amount == null || _never == null || !_on.Value || (Object)(object)who == (Object)null || who.GetInventory() == null || (Object)(object)go == (Object)null)
			{
				return null;
			}
			if ((object)who != Player.m_localPlayer)
			{
				return null;
			}
			ItemDrop component = go.GetComponent<ItemDrop>();
			if ((Object)(object)component == (Object)null || (Object)(object)go.GetComponent<Fish>() != (Object)null)
			{
				return null;
			}
			component.Load();
			ItemData itemData = component.m_itemData;
			if (itemData == null || itemData.m_shared == null || itemData.m_customData == null || (Object)(object)itemData.m_dropPrefab == (Object)null)
			{
				return null;
			}
			if (itemData.m_customData.ContainsKey("meadworks.cheats.nomult"))
			{
				return new State
				{
					Item = itemData,
					Marked = true
				};
			}
			if (who.GetInventory().ContainsItem(itemData))
			{
				return null;
			}
			string prefab = (((Object)(object)itemData.m_dropPrefab != (Object)null) ? ((Object)itemData.m_dropPrefab).name : Utils.GetPrefabName(go));
			bool isTrophy = (int)itemData.m_shared.m_itemType == 13;
			if (LootRules.NeverMultiply(prefab, isTrophy, LootRules.ParseNever(_never.Value)))
			{
				return null;
			}
			return new State
			{
				Item = itemData,
				Prototype = itemData.Clone(),
				Stack = itemData.m_stack
			};
		}

		private static void After(Humanoid who, bool picked, State state)
		{
			if (state == null || (Object)(object)who == (Object)null || who.GetInventory() == null || _amount == null)
			{
				return;
			}
			if (state.Marked)
			{
				if (picked)
				{
					state.Item.m_customData.Remove("meadworks.cheats.nomult");
				}
				return;
			}
			int num = LootRules.Extra(LootRules.Taken(state.Stack, state.Item.m_stack, picked), (int)Math.Round(_amount.Value));
			if (num <= 0)
			{
				return;
			}
			Inventory inventory = who.GetInventory();
			bool flag = false;
			foreach (int item in LootRules.Chunks(num, state.Prototype.m_shared.m_maxStackSize))
			{
				ItemData val = state.Prototype.Clone();
				val.m_stack = item;
				val.m_cheated |= !PlayerProfile.s_bypassCheatChecks;
				if (flag || !inventory.CanAddItem(val, item) || !inventory.AddItem(val))
				{
					flag = true;
					Drop(who, val);
				}
			}
		}

		private static void Drop(Humanoid who, ItemData data)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			if (data.m_stack > 0)
			{
				data.m_customData["meadworks.cheats.nomult"] = "1";
				Transform transform = ((Component)who).transform;
				ItemDrop.DropItem(data, data.m_stack, transform.position + transform.forward + transform.up, transform.rotation);
			}
		}
	}
	public static class LootRules
	{
		public static readonly string[] BossDrops = new string[9] { "HardAntler", "CryptKey", "Wishbone", "DragonTear", "YagluthDrop", "QueenDrop", "FaderDrop", "FrozenKingDrop", "CrownJewel" };

		public static readonly string[] BossTrophies = new string[7] { "TrophyEikthyr", "TrophyTheElder", "TrophyBonemass", "TrophyDragonQueen", "TrophyGoblinKing", "TrophySeekerQueen", "TrophyFader" };

		public static HashSet<string> ParseNever(string text)
		{
			HashSet<string> hashSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
			if (string.IsNullOrEmpty(text))
			{
				return hashSet;
			}
			string[] array = text.Split(new char[6] { ',', ';', ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
			foreach (string text2 in array)
			{
				hashSet.Add(text2.Trim());
			}
			return hashSet;
		}

		public static bool IsBoss(string prefab, bool isTrophy)
		{
			string[] bossDrops = BossDrops;
			for (int i = 0; i < bossDrops.Length; i++)
			{
				if (string.Equals(bossDrops[i], prefab, StringComparison.OrdinalIgnoreCase))
				{
					return true;
				}
			}
			if (isTrophy)
			{
				bossDrops = BossTrophies;
				for (int i = 0; i < bossDrops.Length; i++)
				{
					if (string.Equals(bossDrops[i], prefab, StringComparison.OrdinalIgnoreCase))
					{
						return true;
					}
				}
			}
			return false;
		}

		public static bool IsFish(string prefab)
		{
			if (string.IsNullOrEmpty(prefab) || prefab.Length <= 4 || !prefab.StartsWith("Fish", StringComparison.OrdinalIgnoreCase))
			{
				return false;
			}
			for (int i = 4; i < prefab.Length; i++)
			{
				if (!char.IsDigit(prefab[i]))
				{
					return false;
				}
			}
			return true;
		}

		public static bool IsRuneOrGem(string prefab)
		{
			if (!string.IsNullOrEmpty(prefab))
			{
				if (!prefab.StartsWith("MW_Rune_", StringComparison.OrdinalIgnoreCase))
				{
					return prefab.StartsWith("MW_Gem_", StringComparison.OrdinalIgnoreCase);
				}
				return true;
			}
			return false;
		}

		public static bool NeverMultiply(string prefab, bool isTrophy, HashSet<string> never)
		{
			if (!string.IsNullOrEmpty(prefab) && !IsBoss(prefab, isTrophy) && !IsFish(prefab) && !IsRuneOrGem(prefab))
			{
				return never.Contains(prefab);
			}
			return true;
		}

		public static int Taken(int before, int remaining, bool picked)
		{
			if (before <= 0)
			{
				return 0;
			}
			if (picked)
			{
				return before;
			}
			return Math.Max(0, Math.Min(before, before - remaining));
		}

		public static int Extra(int pickedUp, int multiplier)
		{
			if (pickedUp <= 0 || multiplier < 2)
			{
				return 0;
			}
			return pickedUp * (multiplier - 1);
		}

		public static List<int> Chunks(int amount, int maxStack)
		{
			List<int> list = new List<int>();
			int val = Math.Max(1, maxStack);
			while (amount > 0)
			{
				int num = Math.Min(amount, val);
				list.Add(num);
				amount -= num;
			}
			return list;
		}
	}
	public struct MarkPass
	{
		public bool Clear;

		public bool Objects;

		public HashSet<int> Unwanted;

		public bool Take;

		public bool Flag;

		public long Deadline;

		public bool Bounded;
	}
	public static class MarkZdo
	{
		private struct Limits
		{
			public bool Found;

			public string Name;

			public int MaxStack;

			public int MaxQuality;
		}

		private const int Slots = 10;

		private const int InventoryHeader = 6;

		private const int InventoryCountAt = 4;

		private static int[] _slotHashes;

		private static int[] _slotItemHashes;

		private static readonly List<int> Starts = new List<int>();

		private static readonly List<int> Ends = new List<int>();

		private static readonly List<bool> Drop = new List<bool>();

		private static readonly List<ItemData> Doomed = new List<ItemData>();

		private static readonly List<string> TakenNames = new List<string>();

		private static readonly List<int> TakenCounts = new List<int>();

		private static HashSet<int> _heldUnwanted;

		private static int _pageHash;

		private static int _recoveryPageHash;

		private static readonly Func<Record, bool> HeldDoomed = (Record record) => HeldUnwanted(record.Data, _heldUnwanted);

		private static readonly Func<Record, byte[]> HeldCleared = (Record record) => HeldUnmarked(record.Data);

		private static readonly List<int> Marked = new List<int>();

		private static readonly List<bool> Listed = new List<bool>();

		private static readonly List<string> Noted = new List<string>();

		private static readonly List<string> ScanNotes = new List<string>();

		private static byte[] _scanData;

		private static HashSet<int> _scanUnwanted;

		private static bool _scanFlag;

		private static bool _scanDone;

		private static int _scanIndex;

		private static int _scanPos;

		private static Tally _scanFound;

		private static ZDO _slotZdo;

		private static ZDOID _slotId;

		private static uint _slotRevision;

		private static MarkPass _slotPass;

		private static int _nextSlot;

		private static Tally _slotFound;

		private static readonly List<string> SlotNotes = new List<string>();

		private static Tally _carried;

		private static ZDO _storeZdo;

		private static readonly Action<byte[]> StoreItems = delegate(byte[] bytes)
		{
			_storeZdo.Set(ZDOVars.s_items, bytes);
		};

		private static readonly Dictionary<int, Limits> Known = new Dictionary<int, Limits>();

		private static ObjectDB _knownFrom;

		public static bool Unfinished { get; private set; }

		public static Tally StoppedWith { get; private set; }

		public static bool Deferred { get; private set; }

		public static bool Retry { get; private set; }

		public static int SlotHash(int slot)
		{
			if (_slotHashes == null)
			{
				int[] array = new int[10];
				for (int i = 0; i < 10; i++)
				{
					array[i] = StringExtensionMethods.GetStableHashCode(i + "_itemData");
				}
				_slotHashes = array;
			}
			return _slotHashes[slot];
		}

		private static int SlotItemHash(int slot)
		{
			if (_slotItemHashes == null)
			{
				int[] array = new int[10];
				for (int i = 0; i < 10; i++)
				{
					array[i] = StringExtensionMethods.GetStableHashCode(i + "_item");
				}
				_slotItemHashes = array;
			}
			return _slotItemHashes[slot];
		}

		public static void Forget()
		{
			Known.Clear();
			_knownFrom = null;
			ForgetScan();
			ForgetSlots();
		}

		private static void ForgetSlots()
		{
			_slotZdo = null;
			_nextSlot = 0;
			_slotFound = default(Tally);
			SlotNotes.Clear();
		}

		private static bool Oversized(byte[] bytes, MarkPass pass)
		{
			if (!RoundRules.TooLargeForRound(pass.Bounded, (bytes != null) ? bytes.Length : 0))
			{
				return false;
			}
			MwLog.WarnOnce("cheats round item size", (object)("unmarked: an item blob above " + 262144 + " bytes is left to the world load sweep"));
			return true;
		}

		private static Tally Pause(ZDO zdo, MarkPass pass, int slot, Tally found, List<string> notes)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			_slotZdo = zdo;
			_slotId = zdo.m_uid;
			_slotRevision = zdo.DataRevision;
			_slotPass = pass;
			_nextSlot = slot;
			_slotFound = found;
			SlotNotes.Clear();
			if (notes != null)
			{
				SlotNotes.AddRange(notes);
			}
			Unfinished = true;
			StoppedWith = new Tally
			{
				Items = found.Items - _carried.Items,
				Pieces = found.Pieces - _carried.Pieces,
				Removed = found.Removed - _carried.Removed,
				Impossible = found.Impossible - _carried.Impossible
			};
			return default(Tally);
		}

		public static void ForgetPause()
		{
			ForgetScan();
			ForgetSlots();
		}

		private static void ForgetScan()
		{
			_scanData = null;
			_scanUnwanted = null;
			_scanDone = false;
			_scanFlag = false;
			_scanIndex = 0;
			_scanPos = 0;
			_scanFound = default(Tally);
			Starts.Clear();
			Ends.Clear();
			Marked.Clear();
			Listed.Clear();
			Noted.Clear();
			ScanNotes.Clear();
			Unfinished = false;
		}

		private static void Defer(bool retry)
		{
			Deferred = true;
			Retry = retry;
		}

		public static bool IsContainer(ZDO zdo)
		{
			if (zdo == null)
			{
				return false;
			}
			PageHashes();
			if (zdo.GetByteArray(ZDOVars.s_items, (byte[])null) == null && zdo.GetByteArray(_recoveryPageHash, (byte[])null) == null)
			{
				return zdo.GetByteArray(_pageHash, (byte[])null) != null;
			}
			return true;
		}

		private static void PageHashes()
		{
			if (_pageHash == 0)
			{
				_pageHash = StringExtensionMethods.GetStableHashCode("expdare.meadworks.overflow.v1");
				_recoveryPageHash = StringExtensionMethods.GetStableHashCode("expdare.meadworks.overflow.v1.recovery:");
			}
		}

		public static Tally Process(ZDO zdo, bool clear, bool objects = true)
		{
			return Process(zdo, new MarkPass
			{
				Clear = clear,
				Objects = objects
			}, null);
		}

		public static Tally Process(ZDO zdo, MarkPass pass, List<string> notes)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			Tally r = default(Tally);
			Unfinished = false;
			Deferred = false;
			Retry = false;
			StoppedWith = default(Tally);
			_carried = default(Tally);
			if (zdo == null)
			{
				return r;
			}
			bool flag = pass.Deadline != 0L && zdo == _slotZdo && zdo.m_uid == _slotId && zdo.DataRevision == _slotRevision && pass.Clear == _slotPass.Clear && pass.Take == _slotPass.Take && pass.Flag == _slotPass.Flag && pass.Objects == _slotPass.Objects && pass.Bounded == _slotPass.Bounded && pass.Unwanted == _slotPass.Unwanted;
			if (flag)
			{
				r = (_carried = _slotFound);
				notes?.AddRange(SlotNotes);
			}
			else if (pass.Deadline != 0L)
			{
				ForgetSlots();
			}
			byte[] byteArray = zdo.GetByteArray(ZDOVars.s_items, (byte[])null);
			if (!flag && !Oversized(byteArray, pass))
			{
				bool loaded = false;
				bool flag2 = pass.Clear || pass.Take;
				bool flag3 = flag2 && Memory(zdo, pass, ref r, notes, out loaded);
				if (Deferred)
				{
					return default(Tally);
				}
				if (!flag3)
				{
					if (!loaded)
					{
						TakenNames.Clear();
						TakenCounts.Clear();
					}
					if (flag2 && !loaded && !Custody(zdo, pass, ref r, loaded: false, out var changed))
					{
						TakenNames.Clear();
						TakenCounts.Clear();
						Defer(retry: false);
						return default(Tally);
					}
					byteArray = zdo.GetByteArray(ZDOVars.s_items, (byte[])null);
					if (byteArray != null)
					{
						Inventory(zdo, byteArray, pass, ref r, notes);
					}
					if (Unfinished)
					{
						return r;
					}
					if (!flag2 && !loaded)
					{
						Custody(zdo, pass, ref r, loaded: false, out changed);
					}
					if (!loaded)
					{
						FlushTaken(notes);
					}
				}
			}
			byteArray = zdo.GetByteArray(ZDOVars.s_itemData, (byte[])null);
			if ((!flag || _nextSlot < 0) && byteArray != null && !Oversized(byteArray, pass))
			{
				if (!flag && pass.Deadline != 0L && Stopwatch.GetTimestamp() >= pass.Deadline)
				{
					return Pause(zdo, pass, -1, r, notes);
				}
				int num = zdo.GetInt(ZDOVars.s_item, 0);
				bool flag4 = num == 0 && Lookup(zdo.GetPrefab()).Found;
				int holderItem = ((num != 0) ? num : (flag4 ? zdo.GetPrefab() : 0));
				if (Single(zdo, ZDOVars.s_itemData, byteArray, holderItem, pass, ref r, notes))
				{
					if (flag4)
					{
						Destroy(zdo);
						return r;
					}
					zdo.Set(ZDOVars.s_item, 0, false);
				}
			}
			for (int i = (flag ? Math.Max(0, _nextSlot) : 0); i < 10; i++)
			{
				if (pass.Deadline != 0L && Stopwatch.GetTimestamp() >= pass.Deadline && (!flag || i > _nextSlot))
				{
					return Pause(zdo, pass, i, r, notes);
				}
				int num2 = SlotHash(i);
				byteArray = zdo.GetByteArray(num2, (byte[])null);
				if (byteArray != null && Single(zdo, num2, byteArray, zdo.GetInt(SlotItemHash(i), 0), pass, ref r, notes))
				{
					zdo.Set(SlotItemHash(i), 0, false);
				}
			}
			if (pass.Deadline != 0L)
			{
				ForgetSlots();
			}
			if (!pass.Objects)
			{
				return r;
			}
			bool flag5 = false;
			if (zdo.GetInt(ZDOVars.s_cheated, 0) != 0)
			{
				flag5 = true;
				if (pass.Clear)
				{
					Clear(zdo, ZDOVars.s_cheated);
				}
			}
			for (int j = 0; j < 10; j++)
			{
				int num3 = ZDOVars.s_cheatedQueued + j;
				if (zdo.GetInt(num3, 0) != 0)
				{
					flag5 = true;
					if (pass.Clear)
					{
						Clear(zdo, num3);
					}
				}
			}
			if (flag5)
			{
				r.Pieces++;
			}
			return r;
		}

		private static void Clear(ZDO zdo, int hash)
		{
			zdo.Set(hash, 0, false);
		}

		private static bool Memory(ZDO zdo, MarkPass pass, ref Tally r, List<string> notes, out bool loaded)
		{
			loaded = false;
			ZNetView val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.FindInstance(zdo) : null);
			Container val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<Container>() : null);
			Inventory val3 = (((Object)(object)val2 != (Object)null) ? val2.GetInventory() : null);
			if (val3 == null)
			{
				return false;
			}
			loaded = true;
			if (zdo.IsOwner())
			{
				val2.Load();
			}
			if (UnmarkedRules.LoadedWaits(zdo.IsOwner(), val2.m_lastRevision, zdo.DataRevision))
			{
				Defer(retry: true);
				return false;
			}
			TakenNames.Clear();
			TakenCounts.Clear();
			if (!Custody(zdo, pass, ref r, loaded: true, out var changed))
			{
				TakenNames.Clear();
				TakenCounts.Clear();
				Defer(retry: false);
				return false;
			}
			Doomed.Clear();
			int num = 0;
			foreach (ItemData allItem in val3.GetAllItems())
			{
				if (allItem != null)
				{
					if (pass.Clear && allItem.m_cheated)
					{
						num++;
					}
					if (pass.Clear)
					{
						allItem.m_cheated = false;
					}
					if (pass.Take && pass.Unwanted != null && (Object)(object)allItem.m_dropPrefab != (Object)null && pass.Unwanted.Contains(StringExtensionMethods.GetStableHashCode(((Object)allItem.m_dropPrefab).name)))
					{
						Doomed.Add(allItem);
					}
				}
			}
			bool flag = Doomed.Count > 0 || changed;
			for (int i = 0; i < Doomed.Count; i++)
			{
				Took(((Object)Doomed[i].m_dropPrefab).name, Doomed[i].m_stack);
			}
			for (int j = 0; j < Doomed.Count; j++)
			{
				val3.m_inventory.Remove(Doomed[j]);
			}
			if (flag)
			{
				r.Items += num;
				r.Removed += Doomed.Count;
			}
			Doomed.Clear();
			FlushTaken(notes);
			if (flag)
			{
				val3.Changed(false, false);
			}
			return flag;
		}

		private static void Took(string name, int count)
		{
			int num = TakenNames.IndexOf(name);
			if (num < 0)
			{
				TakenNames.Add(name);
				TakenCounts.Add(count);
			}
			else
			{
				TakenCounts[num] += count;
			}
		}

		private static void FlushTaken(List<string> notes)
		{
			if (notes != null)
			{
				RoundRules.TakenNotes(TakenNames, TakenCounts, notes);
			}
			TakenNames.Clear();
			TakenCounts.Clear();
		}

		public static bool ReadHeld(byte[] data, out int prefab, out ItemData item)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			prefab = 0;
			item = null;
			if (data == null || data.Length == 0)
			{
				return false;
			}
			try
			{
				ZPackage val = new ZPackage(data);
				(int, ItemData) tuple = ItemData.Load(val, (Item)110);
				if (val.GetPos() != data.Length)
				{
					return false;
				}
				(prefab, item) = tuple;
				return true;
			}
			catch (Exception)
			{
				return false;
			}
		}

		public static bool HeldUnwanted(byte[] data, HashSet<int> unwanted)
		{
			if (unwanted != null && ReadHeld(data, out var prefab, out var _) && prefab != 0)
			{
				return unwanted.Contains(prefab);
			}
			return false;
		}

		public static byte[] HeldUnmarked(byte[] data)
		{
			if (!ReadHeld(data, out var _, out var item) || !item.m_cheated)
			{
				return null;
			}
			byte[] array = (byte[])data.Clone();
			array[^1] = (byte)(array[^1] & -2);
			return array;
		}

		private static bool Custody(ZDO zdo, MarkPass pass, ref Tally r, bool loaded, out bool changed)
		{
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Invalid comparison between Unknown and I4
			changed = false;
			PageHashes();
			if (!loaded && !ContainerCustodyRules.MayHold(zdo.GetByteArray(_recoveryPageHash, (byte[])null), zdo.GetByteArray(_pageHash, (byte[])null)))
			{
				return true;
			}
			int num = (pass.Bounded ? 262144 : 0);
			int prefab;
			ItemData item;
			if (!pass.Clear && !pass.Take)
			{
				IList<Record> list = InventoryPersistence.ContainerCustody(zdo, num);
				for (int i = 0; i < list.Count; i++)
				{
					if (ReadHeld(list[i].Data, out prefab, out item))
					{
						if (item.m_cheated)
						{
							r.Items++;
						}
						if (prefab != 0 && pass.Unwanted != null && pass.Unwanted.Contains(prefab))
						{
							r.Removed++;
							Took(Name(prefab), list[i].Count);
						}
					}
				}
				return true;
			}
			_heldUnwanted = (pass.Take ? pass.Unwanted : null);
			EditStatus val;
			Edit val2 = default(Edit);
			try
			{
				val = InventoryPersistence.EditContainerCustody(zdo, (_heldUnwanted != null) ? HeldDoomed : null, pass.Clear ? HeldCleared : null, num, ref val2);
			}
			finally
			{
				_heldUnwanted = null;
			}
			if ((int)val == 2)
			{
				MwLog.WarnOnce("cheats custody refused", (object)"unmarked: a container whose held items cannot be worked on is left as it is");
				return false;
			}
			if (val2 == null)
			{
				return true;
			}
			r.Items += val2.Rewritten;
			r.Removed += val2.Removed.Count;
			for (int j = 0; j < val2.Removed.Count; j++)
			{
				if (ReadHeld(val2.Removed[j].Data, out prefab, out item))
				{
					Took(Name(prefab), val2.Removed[j].Count);
				}
			}
			changed = val2.Removed.Count > 0 || val2.Rewritten > 0;
			return true;
		}

		private static void Destroy(ZDO zdo)
		{
			if (ZDOMan.instance != null)
			{
				if (!zdo.IsOwner())
				{
					zdo.SetOwner(ZDOMan.GetSessionID());
				}
				ZNetView val = (((Object)(object)ZNetScene.instance != (Object)null) ? ZNetScene.instance.FindInstance(zdo) : null);
				if ((Object)(object)val != (Object)null)
				{
					ZNetScene.instance.Destroy(((Component)val).gameObject);
				}
				else
				{
					ZDOMan.instance.DestroyZDO(zdo);