Decompiled source of REPOBlacklist v0.2.3

REPOBlacklist.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("REPOBlacklist")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.3.0")]
[assembly: AssemblyInformationalVersion("0.2.3")]
[assembly: AssemblyProduct("REPOBlacklist")]
[assembly: AssemblyTitle("REPOBlacklist")]
[assembly: AssemblyVersion("0.2.3.0")]
namespace REPOBlacklist;

internal static class BlacklistFilter
{
	private static readonly List<string> ActiveHooks = new List<string>();

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

	private static readonly HashSet<string> ReportedFailures = new HashSet<string>();

	private static MethodInfo _upgradeRoll;

	private static bool _rerollingUpgrade;

	private static int _enemyPicksFiltered;

	public static string HookSummary
	{
		get
		{
			string text = ((ActiveHooks.Count > 0) ? string.Join(", ", ActiveHooks) : "none");
			if (FailedHooks.Count > 0)
			{
				text = text + " (not available in this game version: " + string.Join(", ", FailedHooks) + ")";
			}
			return text;
		}
	}

	public static bool AnyHookFailed => FailedHooks.Count > 0;

	public static void Install(Harmony harmony)
	{
		Hook("shop items", delegate
		{
			harmony.Patch((MethodBase)Find(typeof(ShopManager), "GetAllItemsFromStatsManager"), (HarmonyMethod)null, Mine("ShopPoolsPostfix"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		});
		Hook("upgrade stand", delegate
		{
			_upgradeRoll = Find(typeof(UpgradeStand), "GetWeightedUpgradeExcluding");
			harmony.Patch((MethodBase)_upgradeRoll, (HarmonyMethod)null, Mine("UpgradeRollPostfix"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		});
		Hook("enemies", delegate
		{
			harmony.Patch((MethodBase)Find(typeof(EnemyDirector), "AmountSetup"), (HarmonyMethod)null, Mine("AmountSetupPostfix"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)Find(typeof(EnemyDirector), "PickEnemies"), Mine("PickEnemiesPrefix"), Mine("PickEnemiesPostfix"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		});
		Hook("valuables", delegate
		{
			harmony.Patch((MethodBase)Find(typeof(ValuableDirector), "SetupHost"), (HarmonyMethod)null, Mine("SetupHostPostfix"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		});
	}

	private static void Hook(string name, Action install)
	{
		try
		{
			install();
			ActiveHooks.Add(name);
		}
		catch (Exception ex)
		{
			FailedHooks.Add(name);
			Plugin.Log.LogError((object)("The " + name + " blacklist cannot work with this game version: " + ex.Message));
		}
	}

	private static MethodInfo Find(Type type, string name)
	{
		MethodInfo? method = type.GetMethod(name, AccessTools.all);
		if (method == null)
		{
			throw new MissingMethodException(type.Name + "." + name + " was not found");
		}
		return method;
	}

	private static HarmonyMethod Mine(string name)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Expected O, but got Unknown
		return new HarmonyMethod(typeof(BlacklistFilter).GetMethod(name, AccessTools.all));
	}

	private static bool IsHost()
	{
		return SemiFunc.IsMasterClientOrSingleplayer();
	}

	private static bool Blocked(BlacklistCategory category, string name)
	{
		return Plugin.Store.IsBlacklisted(category, name);
	}

	private static void ReportOnce(string where, Exception e)
	{
		if (ReportedFailures.Add(where))
		{
			Plugin.Log.LogError((object)$"The {where} blacklist failed and was skipped: {e}");
		}
	}

	private static void ShopPoolsPostfix(ShopManager __instance)
	{
		try
		{
			if (Plugin.Store.Count(BlacklistCategory.Item) == 0 || !IsHost())
			{
				return;
			}
			HashSet<string> hashSet = new HashSet<string>(StringComparer.Ordinal);
			RemoveBlocked(__instance.potentialItems, hashSet);
			RemoveBlocked(__instance.potentialItemConsumables, hashSet);
			RemoveBlocked(__instance.potentialItemUpgrades, hashSet);
			RemoveBlocked(__instance.potentialItemHealthPacks, hashSet);
			if (__instance.potentialSecretItems != null)
			{
				foreach (List<Item> value in __instance.potentialSecretItems.Values)
				{
					RemoveBlocked(value, hashSet);
				}
			}
			if (hashSet.Count > 0)
			{
				Plugin.Log.LogInfo((object)string.Format("Shop: left out {0} blacklisted item(s): {1}.", hashSet.Count, string.Join(", ", hashSet.OrderBy((string n) => n))));
			}
		}
		catch (Exception e)
		{
			ReportOnce("shop items", e);
		}
	}

	private static void RemoveBlocked(List<Item> pool, HashSet<string> leftOut)
	{
		if (pool == null)
		{
			return;
		}
		for (int num = pool.Count - 1; num >= 0; num--)
		{
			Item val = pool[num];
			if (!((Object)(object)val == (Object)null))
			{
				string name = ((Object)val).name;
				if (Blocked(BlacklistCategory.Item, name))
				{
					leftOut.Add(name);
					pool.RemoveAt(num);
				}
			}
		}
	}

	private static void UpgradeRollPostfix(UpgradeStand __instance, ref Item __result, Item excludeItem, Dictionary<string, int> displayedCounts, Dictionary<string, int> selectedDuringReroll)
	{
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Expected O, but got Unknown
		if (_rerollingUpgrade || (Object)(object)__result == (Object)null)
		{
			return;
		}
		try
		{
			if (!Blocked(BlacklistCategory.Item, ((Object)__result).name) || !IsHost())
			{
				return;
			}
			_rerollingUpgrade = true;
			Item val = null;
			for (int i = 0; i < 12; i++)
			{
				Item val2 = (Item)_upgradeRoll.Invoke(__instance, new object[4] { excludeItem, displayedCounts, selectedDuringReroll, false });
				if ((Object)(object)val2 == (Object)null)
				{
					break;
				}
				if (!Blocked(BlacklistCategory.Item, ((Object)val2).name))
				{
					val = val2;
					break;
				}
			}
			__result = val;
		}
		catch (Exception e)
		{
			ReportOnce("upgrade stand", e);
		}
		finally
		{
			_rerollingUpgrade = false;
		}
	}

	private static void PickEnemiesPrefix(ref List<EnemySetup> _enemiesList, out bool __state)
	{
		__state = false;
		try
		{
			if (_enemiesList == null || Plugin.Store.Count(BlacklistCategory.Enemy) == 0 || !IsHost())
			{
				return;
			}
			List<EnemySetup> list = null;
			for (int i = 0; i < _enemiesList.Count; i++)
			{
				EnemySetup val = _enemiesList[i];
				bool flag = (Object)(object)val != (Object)null && Blocked(BlacklistCategory.Enemy, ((Object)val).name);
				if (flag && list == null)
				{
					list = _enemiesList.GetRange(0, i);
				}
				else if (!flag)
				{
					list?.Add(val);
				}
			}
			if (list != null)
			{
				_enemiesList = list;
				__state = true;
				_enemyPicksFiltered++;
			}
		}
		catch (Exception e)
		{
			ReportOnce("enemies", e);
		}
	}

	private static void PickEnemiesPostfix(bool __state, List<EnemySetup> ___enemyListCurrent, List<EnemySetup> ___enemyList)
	{
		if (__state)
		{
			DropEmptyLastSlot(___enemyListCurrent);
			DropEmptyLastSlot(___enemyList);
		}
	}

	private static void DropEmptyLastSlot(List<EnemySetup> list)
	{
		if (list != null && list.Count > 0 && (Object)(object)list[list.Count - 1] == (Object)null)
		{
			list.RemoveAt(list.Count - 1);
		}
	}

	private static void AmountSetupPostfix(ref int ___totalAmount, List<EnemySetup> ___enemyListCurrent)
	{
		int enemyPicksFiltered = _enemyPicksFiltered;
		_enemyPicksFiltered = 0;
		if (enemyPicksFiltered != 0 && ___enemyListCurrent != null)
		{
			int num = ___totalAmount;
			if (___enemyListCurrent.Count < num)
			{
				___totalAmount = ___enemyListCurrent.Count;
			}
			string text = $"Enemies: blacklist used for {enemyPicksFiltered} of {num} pick(s) in this level";
			if (___totalAmount < num)
			{
				text += $"; {num - ___totalAmount} left empty because every enemy of that difficulty is blacklisted";
			}
			Plugin.Log.LogInfo((object)(text + "."));
		}
	}

	private static void SetupHostPostfix(ref IEnumerator __result)
	{
		if (__result != null)
		{
			__result = FilteredSetup(__result);
		}
	}

	private static IEnumerator FilteredSetup(IEnumerator original)
	{
		List<KeyValuePair<List<PrefabRef>, PrefabRef[]>> list = new List<KeyValuePair<List<PrefabRef>, PrefabRef[]>>();
		bool flag;
		try
		{
			HideBlacklistedValuables(list);
			flag = original.MoveNext();
		}
		finally
		{
			foreach (KeyValuePair<List<PrefabRef>, PrefabRef[]> item in list)
			{
				item.Key.Clear();
				item.Key.AddRange(item.Value);
			}
		}
		while (flag)
		{
			yield return original.Current;
			flag = original.MoveNext();
		}
	}

	private static void HideBlacklistedValuables(List<KeyValuePair<List<PrefabRef>, PrefabRef[]>> hidden)
	{
		try
		{
			if (Plugin.Store.Count(BlacklistCategory.Valuable) == 0 || !IsHost())
			{
				return;
			}
			LevelGenerator instance = LevelGenerator.Instance;
			Level val = (((Object)(object)instance != (Object)null) ? instance.Level : null);
			if ((Object)(object)val == (Object)null || val.ValuablePresets == null)
			{
				return;
			}
			HashSet<List<PrefabRef>> hashSet = new HashSet<List<PrefabRef>>();
			foreach (LevelValuables valuablePreset in val.ValuablePresets)
			{
				foreach (List<PrefabRef> item in SizePools(valuablePreset))
				{
					hashSet.Add(item);
				}
			}
			int num = 0;
			int num2 = 0;
			HashSet<string> hashSet2 = new HashSet<string>(StringComparer.Ordinal);
			foreach (List<PrefabRef> item2 in hashSet)
			{
				foreach (PrefabRef item3 in item2)
				{
					num++;
					if (IsBlocked(item3))
					{
						num2++;
						hashSet2.Add(((PrefabRef<GameObject>)(object)item3).PrefabName);
					}
				}
			}
			if (num2 == 0)
			{
				return;
			}
			foreach (List<PrefabRef> item4 in hashSet)
			{
				if (item4.Any(IsBlocked))
				{
					hidden.Add(new KeyValuePair<List<PrefabRef>, PrefabRef[]>(item4, item4.ToArray()));
					item4.RemoveAll(IsBlocked);
				}
			}
			if (num2 >= num)
			{
				Plugin.Log.LogInfo((object)$"Valuables: all {hashSet2.Count} valuable(s) of this level are blacklisted, so this level has none.");
				return;
			}
			Plugin.Log.LogInfo((object)string.Format("Valuables: left out {0} blacklisted valuable(s) in this level: {1}.", hashSet2.Count, string.Join(", ", hashSet2.OrderBy((string n) => n))));
		}
		catch (Exception e)
		{
			ReportOnce("valuables", e);
		}
	}

	private static bool IsBlocked(PrefabRef valuable)
	{
		if (valuable != null)
		{
			return Blocked(BlacklistCategory.Valuable, ((PrefabRef<GameObject>)(object)valuable).PrefabName);
		}
		return false;
	}

	private static IEnumerable<List<PrefabRef>> SizePools(LevelValuables preset)
	{
		if (!((Object)(object)preset == (Object)null))
		{
			if (preset.tiny != null)
			{
				yield return preset.tiny;
			}
			if (preset.small != null)
			{
				yield return preset.small;
			}
			if (preset.medium != null)
			{
				yield return preset.medium;
			}
			if (preset.big != null)
			{
				yield return preset.big;
			}
			if (preset.wide != null)
			{
				yield return preset.wide;
			}
			if (preset.tall != null)
			{
				yield return preset.tall;
			}
			if (preset.veryTall != null)
			{
				yield return preset.veryTall;
			}
		}
	}

	public static List<string> Discover(BlacklistCategory category)
	{
		HashSet<string> hashSet = new HashSet<string>(StringComparer.Ordinal);
		try
		{
			switch (category)
			{
			case BlacklistCategory.Item:
				if (!((Object)(object)StatsManager.instance != (Object)null) || StatsManager.instance.itemDictionary == null)
				{
					break;
				}
				foreach (Item value in StatsManager.instance.itemDictionary.Values)
				{
					if ((Object)(object)value != (Object)null)
					{
						hashSet.Add(((Object)value).name);
					}
				}
				break;
			case BlacklistCategory.Enemy:
			{
				EnemyDirector instance = EnemyDirector.instance;
				if ((Object)(object)instance != (Object)null)
				{
					AddEnemies(hashSet, instance.enemiesDifficulty1);
					AddEnemies(hashSet, instance.enemiesDifficulty2);
					AddEnemies(hashSet, instance.enemiesDifficulty3);
				}
				if (hashSet.Count == 0)
				{
					AddEnemies(hashSet, Resources.FindObjectsOfTypeAll<EnemySetup>());
				}
				break;
			}
			case BlacklistCategory.Valuable:
			{
				HashSet<LevelValuables> hashSet2 = new HashSet<LevelValuables>(Resources.FindObjectsOfTypeAll<LevelValuables>());
				if ((Object)(object)RunManager.instance != (Object)null && RunManager.instance.levels != null)
				{
					foreach (Level level in RunManager.instance.levels)
					{
						if ((Object)(object)level == (Object)null || level.ValuablePresets == null)
						{
							continue;
						}
						foreach (LevelValuables valuablePreset in level.ValuablePresets)
						{
							hashSet2.Add(valuablePreset);
						}
					}
				}
				foreach (LevelValuables item in hashSet2)
				{
					foreach (List<PrefabRef> item2 in SizePools(item))
					{
						foreach (PrefabRef item3 in item2)
						{
							if (item3 != null)
							{
								hashSet.Add(((PrefabRef<GameObject>)(object)item3).PrefabName);
							}
						}
					}
				}
				break;
			}
			}
		}
		catch (Exception e)
		{
			ReportOnce(category.ToString() + " list", e);
		}
		hashSet.Remove(null);
		hashSet.Remove("");
		List<string> list = hashSet.ToList();
		list.Sort(StringComparer.OrdinalIgnoreCase);
		return list;
	}

	private static void AddEnemies(HashSet<string> names, IEnumerable<EnemySetup> enemies)
	{
		if (enemies == null)
		{
			return;
		}
		foreach (EnemySetup enemy in enemies)
		{
			if ((Object)(object)enemy != (Object)null)
			{
				names.Add(((Object)enemy).name);
			}
		}
	}

	public static void Dump()
	{
		ManualLogSource log = Plugin.Log;
		log.LogInfo((object)("[dump] REPOBlacklist 0.2.3, hooks: " + HookSummary));
		try
		{
			log.LogInfo((object)("[dump] Host or singleplayer: " + IsHost()));
		}
		catch (Exception)
		{
			log.LogInfo((object)"[dump] Host or singleplayer: unknown (no game running)");
		}
		foreach (BlacklistCategory value in Enum.GetValues(typeof(BlacklistCategory)))
		{
			List<string> list = Discover(value);
			List<string> list2 = Plugin.Store.Snapshot(value).OrderBy<string, string>((string n) => n, StringComparer.OrdinalIgnoreCase).ToList();
			log.LogInfo((object)string.Format("[dump] {0}: {1} blacklisted: {2}", value, list2.Count, string.Join(", ", list2)));
			log.LogInfo((object)string.Format("[dump] {0}: {1} found in the game: {2}", value, list.Count, string.Join(", ", list)));
		}
	}
}
public enum BlacklistCategory
{
	Item,
	Valuable,
	Enemy
}
public class BlacklistStore
{
	[Serializable]
	private class Dto
	{
		public List<string> items = new List<string>();

		public List<string> valuables = new List<string>();

		public List<string> enemies = new List<string>();
	}

	private readonly string _path;

	private readonly ManualLogSource _log;

	private readonly HashSet<string> _items = new HashSet<string>(StringComparer.Ordinal);

	private readonly HashSet<string> _valuables = new HashSet<string>(StringComparer.Ordinal);

	private readonly HashSet<string> _enemies = new HashSet<string>(StringComparer.Ordinal);

	public int Total => _items.Count + _valuables.Count + _enemies.Count;

	public BlacklistStore(string path, ManualLogSource log)
	{
		_path = path;
		_log = log;
		Load();
	}

	public bool IsBlacklisted(BlacklistCategory cat, string name)
	{
		if (string.IsNullOrEmpty(name))
		{
			return false;
		}
		return Names(cat).Contains(name);
	}

	public int Count(BlacklistCategory cat)
	{
		return Names(cat).Count;
	}

	public IReadOnlyCollection<string> Snapshot(BlacklistCategory cat)
	{
		return Names(cat);
	}

	public void Set(BlacklistCategory cat, string name, bool blacklisted)
	{
		if (!string.IsNullOrEmpty(name))
		{
			HashSet<string> hashSet = Names(cat);
			if (blacklisted ? hashSet.Add(name) : hashSet.Remove(name))
			{
				Save();
			}
		}
	}

	public void Clear(BlacklistCategory cat)
	{
		HashSet<string> hashSet = Names(cat);
		if (hashSet.Count != 0)
		{
			hashSet.Clear();
			Save();
		}
	}

	private HashSet<string> Names(BlacklistCategory cat)
	{
		return cat switch
		{
			BlacklistCategory.Item => _items, 
			BlacklistCategory.Valuable => _valuables, 
			BlacklistCategory.Enemy => _enemies, 
			_ => throw new ArgumentOutOfRangeException("cat"), 
		};
	}

	private void Load()
	{
		if (!File.Exists(_path))
		{
			return;
		}
		try
		{
			string text = File.ReadAllText(_path);
			if (!string.IsNullOrWhiteSpace(text))
			{
				Dto dto = JsonUtility.FromJson<Dto>(text);
				if (dto == null)
				{
					throw new FormatException("no blacklist found in the file");
				}
				Fill(_items, dto.items);
				Fill(_valuables, dto.valuables);
				Fill(_enemies, dto.enemies);
			}
		}
		catch (Exception ex)
		{
			string fileName = Path.GetFileName(_path);
			string text2 = "";
			try
			{
				File.Copy(_path, _path + ".bak", overwrite: true);
				text2 = " A copy was kept as " + fileName + ".bak.";
			}
			catch (Exception)
			{
			}
			_items.Clear();
			_valuables.Clear();
			_enemies.Clear();
			_log.LogError((object)("Could not read " + fileName + ", so the blacklist starts empty." + text2 + " (" + ex.Message + ")"));
		}
	}

	private static void Fill(HashSet<string> target, List<string> names)
	{
		target.Clear();
		if (names == null)
		{
			return;
		}
		foreach (string name in names)
		{
			if (!string.IsNullOrEmpty(name))
			{
				target.Add(name);
			}
		}
	}

	private void Save()
	{
		try
		{
			Directory.CreateDirectory(Path.GetDirectoryName(_path));
			Dto dto = new Dto
			{
				items = new List<string>(_items),
				valuables = new List<string>(_valuables),
				enemies = new List<string>(_enemies)
			};
			dto.items.Sort(StringComparer.Ordinal);
			dto.valuables.Sort(StringComparer.Ordinal);
			dto.enemies.Sort(StringComparer.Ordinal);
			string text = _path + ".tmp";
			File.WriteAllText(text, JsonUtility.ToJson((object)dto, true));
			if (File.Exists(_path))
			{
				try
				{
					File.Replace(text, _path, null);
					return;
				}
				catch (Exception)
				{
					File.Copy(text, _path, overwrite: true);
					File.Delete(text);
					return;
				}
			}
			File.Move(text, _path);
		}
		catch (Exception ex2)
		{
			_log.LogError((object)("Could not save " + Path.GetFileName(_path) + ": " + ex2.Message));
		}
	}
}
public class BlacklistUI : MonoBehaviour
{
	private struct Row
	{
		public string Name;

		public string Label;
	}

	private bool _open;

	private Rect _window = new Rect(60f, 60f, 560f, 660f);

	private BlacklistCategory _tab;

	private string _filter = "";

	private Vector2 _scroll;

	private readonly Dictionary<BlacklistCategory, List<Row>> _rows = new Dictionary<BlacklistCategory, List<Row>>();

	private GUIStyle _windowStyle;

	private GUIStyle _toggleStyle;

	private GUIStyle _noteStyle;

	private bool _stylesReady;

	private bool _wasCursorVisible;

	private bool _isHost = true;

	private BlacklistCategory? _resetArmed;

	private void Update()
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)Plugin.Instance == (Object)null)
		{
			return;
		}
		IInputSystem current = UnityInput.Current;
		if (current.GetKeyDown(Plugin.Instance.MenuToggleKey.Value))
		{
			if (_open)
			{
				Close();
			}
			else
			{
				Open();
			}
		}
		else if (_open && current.GetKeyDown((KeyCode)27))
		{
			Close();
		}
		if (_open)
		{
			GameInput.HoldThisFrame();
		}
	}

	private void OnDisable()
	{
		if (_open)
		{
			Close();
		}
	}

	private void Open()
	{
		_open = true;
		_resetArmed = null;
		_wasCursorVisible = Cursor.visible;
		Refresh();
	}

	private void Close()
	{
		_open = false;
		_resetArmed = null;
		Cursor.visible = _wasCursorVisible;
	}

	private void Refresh()
	{
		foreach (BlacklistCategory value in Enum.GetValues(typeof(BlacklistCategory)))
		{
			List<string> list = BlacklistFilter.Discover(value);
			HashSet<string> hashSet = new HashSet<string>(list, StringComparer.Ordinal);
			List<Row> list2 = new List<Row>(list.Count);
			foreach (string item in list)
			{
				list2.Add(new Row
				{
					Name = item,
					Label = item
				});
			}
			foreach (string item2 in Plugin.Store.Snapshot(value))
			{
				if (!hashSet.Contains(item2))
				{
					list2.Add(new Row
					{
						Name = item2,
						Label = item2 + "   (not found right now)"
					});
				}
			}
			list2.Sort((Row a, Row b) => string.Compare(a.Name, b.Name, StringComparison.OrdinalIgnoreCase));
			_rows[value] = list2;
		}
		try
		{
			_isHost = SemiFunc.IsMasterClientOrSingleplayer();
		}
		catch (Exception)
		{
			_isHost = true;
		}
	}

	private void OnGUI()
	{
		//IL_000f: 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_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Expected O, but got Unknown
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		if (_open)
		{
			EnsureStyles();
			if ((int)Cursor.lockState != 0)
			{
				Cursor.lockState = (CursorLockMode)0;
			}
			if (!Cursor.visible)
			{
				Cursor.visible = true;
			}
			_window = GUI.Window(((Object)this).GetInstanceID() ^ 0x1B71A57, _window, new WindowFunction(DrawWindow), "REPO Blacklist", _windowStyle);
		}
	}

	private void EnsureStyles()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected O, but got Unknown
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Expected O, but got Unknown
		if (!_stylesReady)
		{
			_windowStyle = new GUIStyle(GUI.skin.window);
			_toggleStyle = new GUIStyle(GUI.skin.toggle)
			{
				wordWrap = true
			};
			_noteStyle = new GUIStyle(GUI.skin.label)
			{
				wordWrap = true
			};
			_stylesReady = true;
		}
	}

	private void DrawWindow(int id)
	{
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_0282: Unknown result type (might be due to invalid IL or missing references)
		//IL_028c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0291: Unknown result type (might be due to invalid IL or missing references)
		//IL_0363: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		DrawTabButton("Items", BlacklistCategory.Item);
		DrawTabButton("Valuables", BlacklistCategory.Valuable);
		DrawTabButton("Enemies", BlacklistCategory.Enemy);
		GUILayout.FlexibleSpace();
		if (GUILayout.Button("Refresh", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(72f) }))
		{
			Refresh();
		}
		if (GUILayout.Button("Dump", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) }))
		{
			BlacklistFilter.Dump();
		}
		if (GUILayout.Button("Close", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) }))
		{
			Close();
		}
		GUILayout.EndHorizontal();
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.Label("Filter:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) });
		_filter = GUILayout.TextField(_filter ?? "", Array.Empty<GUILayoutOption>());
		if (GUILayout.Button("X", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(24f) }))
		{
			_filter = "";
		}
		GUILayout.EndHorizontal();
		if (!_rows.TryGetValue(_tab, out var value) || value == null || value.Count == 0)
		{
			GUILayout.FlexibleSpace();
			GUILayout.Label($"Nothing found for {_tab} yet.\nStart or join a game, then press Refresh.", _noteStyle, Array.Empty<GUILayoutOption>());
			GUILayout.FlexibleSpace();
			DrawFooter();
			GUI.DragWindow(new Rect(0f, 0f, 10000f, 20f));
			return;
		}
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.Label($"{Plugin.Store.Count(_tab)} / {value.Count} blacklisted", Array.Empty<GUILayoutOption>());
		GUILayout.FlexibleSpace();
		if (GUILayout.Button((_resetArmed == _tab) ? "Confirm clear?" : $"Clear {_tab}", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(140f) }))
		{
			if (_resetArmed == _tab)
			{
				Plugin.Store.Clear(_tab);
				_resetArmed = null;
			}
			else
			{
				_resetArmed = _tab;
			}
		}
		GUILayout.EndHorizontal();
		_scroll = GUILayout.BeginScrollView(_scroll, Array.Empty<GUILayoutOption>());
		string text = (_filter ?? "").Trim();
		foreach (Row item in value)
		{
			if (text.Length <= 0 || item.Name.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0)
			{
				bool flag = Plugin.Store.IsBlacklisted(_tab, item.Name);
				bool flag2 = GUILayout.Toggle(flag, item.Label, _toggleStyle, Array.Empty<GUILayoutOption>());
				if (flag2 != flag)
				{
					Plugin.Store.Set(_tab, item.Name, flag2);
				}
			}
		}
		GUILayout.EndScrollView();
		DrawFooter();
		GUI.DragWindow(new Rect(0f, 0f, 10000f, 20f));
	}

	private void DrawFooter()
	{
		string text = (_isHost ? "Ticked things are left out from the next shop or level on." : "You are not the host here. Your list is used when you host.");
		if (BlacklistFilter.AnyHookFailed)
		{
			text = text + "\nWorking in this game version: " + BlacklistFilter.HookSummary + ".";
		}
		GUILayout.Label(text, _noteStyle, Array.Empty<GUILayoutOption>());
	}

	private void DrawTabButton(string label, BlacklistCategory cat)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: 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)
		Color backgroundColor = GUI.backgroundColor;
		if (_tab == cat)
		{
			GUI.backgroundColor = new Color(0.4f, 0.7f, 1f);
		}
		if (GUILayout.Button(label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(90f) }))
		{
			_tab = cat;
			_resetArmed = null;
		}
		GUI.backgroundColor = backgroundColor;
	}
}
internal static class GameInput
{
	private const float HoldSeconds = 0.25f;

	private static readonly List<InputKey> AllowedKeys = new List<InputKey> { (InputKey)25 };

	public static void HoldThisFrame()
	{
		InputManager instance = InputManager.instance;
		if ((Object)(object)instance != (Object)null)
		{
			instance.DisableMovement(0.25f);
			instance.DisableAiming(0.25f);
			instance.DisableControlsExcept(0.25f, AllowedKeys);
		}
		CursorManager instance2 = CursorManager.instance;
		if ((Object)(object)instance2 != (Object)null)
		{
			instance2.Unlock(0.25f);
		}
	}
}
[BepInPlugin("isaia.repoblacklist", "REPOBlacklist", "0.2.3")]
public class Plugin : BaseUnityPlugin
{
	public const string GUID = "isaia.repoblacklist";

	public const string NAME = "REPOBlacklist";

	public const string VERSION = "0.2.3";

	private const string StoreFileName = "REPOBlacklist.json";

	public ConfigEntry<KeyCode> MenuToggleKey;

	private Harmony _harmony;

	public static Plugin Instance { get; private set; }

	public static ManualLogSource Log { get; private set; }

	public static BlacklistStore Store { get; private set; }

	private void Awake()
	{
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Expected O, but got Unknown
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		MenuToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("UI", "MenuToggleKey", (KeyCode)284, "Key that opens/closes the in-game blacklist menu.");
		Store = new BlacklistStore(Path.Combine(Paths.ConfigPath, "REPOBlacklist.json"), Log);
		_harmony = new Harmony("isaia.repoblacklist");
		BlacklistFilter.Install(_harmony);
		((Component)this).gameObject.AddComponent<BlacklistUI>();
		Log.LogInfo((object)string.Format("{0} {1} loaded. Menu: {2}. {3} blacklisted in {4}. Working: {5}.", "REPOBlacklist", "0.2.3", MenuToggleKey.Value, Store.Total, "REPOBlacklist.json", BlacklistFilter.HookSummary));
	}

	private void OnDestroy()
	{
		Harmony harmony = _harmony;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
	}
}
public static class MyPluginInfo
{
	public const string PLUGIN_GUID = "REPOBlacklist";

	public const string PLUGIN_NAME = "REPOBlacklist";

	public const string PLUGIN_VERSION = "0.2.3";
}
internal static class PluginVersion
{
	public const string Value = "0.2.3";
}