Decompiled source of Character Disabler v1.1.3

plugins/konflame-Character_Disabler/Konflame.CharacterDisabler.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using Gunfiguration;
using HarmonyLib;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace Konflame.CharacterDisabler;

public sealed class CharacterRow
{
	public string Id;

	public string Name;

	public string Kind;

	public bool Selectable;

	public bool Coop;
}
public static class Settings
{
	public static HashSet<string> ReadDisabled(string directory)
	{
		string path = Path.Combine(directory, "disabled.txt");
		return new HashSet<string>(File.Exists(path) ? (from s in File.ReadAllLines(path)
			where s.Trim().Length > 0
			select s.Trim()) : new string[0], StringComparer.OrdinalIgnoreCase);
	}

	public static void WriteAtomic(string path, IEnumerable<string> lines)
	{
		Directory.CreateDirectory(Path.GetDirectoryName(path));
		string text = path + "." + Guid.NewGuid().ToString("N") + ".tmp";
		File.WriteAllLines(text, lines.ToArray(), new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
		try
		{
			if (File.Exists(path))
			{
				File.Replace(text, path, null);
			}
			else
			{
				File.Move(text, path);
			}
		}
		finally
		{
			if (File.Exists(text))
			{
				File.Delete(text);
			}
		}
	}

	public static void SaveDisabled(string directory, IEnumerable<string> ids)
	{
		WriteAtomic(Path.Combine(directory, "disabled.txt"), ids.OrderBy<string, string>((string s) => s, StringComparer.OrdinalIgnoreCase));
	}

	public static string Encode(CharacterRow r)
	{
		return string.Join("\t", Uri.EscapeDataString(r.Id), Uri.EscapeDataString(r.Name), Uri.EscapeDataString(r.Kind), r.Selectable ? "1" : "0", r.Coop ? "1" : "0");
	}

	public static List<CharacterRow> ReadRoster(string directory)
	{
		string path = Path.Combine(directory, "roster.tsv");
		List<CharacterRow> list = new List<CharacterRow>();
		if (!File.Exists(path))
		{
			return list;
		}
		string[] array = File.ReadAllLines(path);
		foreach (string text in array)
		{
			string[] array2 = text.Split(new char[1] { '\t' });
			if (array2.Length == 5)
			{
				list.Add(new CharacterRow
				{
					Id = Uri.UnescapeDataString(array2[0]),
					Name = Uri.UnescapeDataString(array2[1]),
					Kind = Uri.UnescapeDataString(array2[2]),
					Selectable = (array2[3] == "1"),
					Coop = (array2[4] == "1")
				});
			}
		}
		return list;
	}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("konflame.etg.characterdisabler", "Character Disabler", "1.1.3")]
public sealed class CharacterDisabler : BaseUnityPlugin
{
	public const string Guid = "konflame.etg.characterdisabler";

	public static CharacterDisabler Instance;

	private readonly List<FoyerCharacterSelectFlag> flags = new List<FoyerCharacterSelectFlag>();

	private readonly HashSet<FoyerCharacterSelectFlag> hidden = new HashSet<FoyerCharacterSelectFlag>();

	private Harmony harmony;

	private int sceneHandle = -1;

	private float nextScan;

	private string rosterText = "";

	private string fallback;

	private bool ready;

	private static readonly Dictionary<string, string> Names = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
	{
		{ "PlayerRogue", "The Pilot" },
		{ "PlayerConvict", "The Convict" },
		{ "PlayerMarine", "The Marine" },
		{ "PlayerGuide", "The Hunter" },
		{ "PlayerRobot", "The Robot" },
		{ "PlayerBullet", "The Bullet" },
		{ "PlayerEevee", "The Paradox" },
		{ "PlayerGunslinger", "The Gunslinger" },
		{ "PlayerCoopCultist", "The Cultist" }
	};

	private bool ownedPause;

	private bool oldPreventPause;

	private bool oldCursor;

	private CursorLockMode oldLock;

	private int menuScene;

	private Vector2 scroll;

	private GUIStyle heading;

	private GUIStyle label;

	private GUIStyle small;

	private GUIStyle button;

	private GUIStyle toggle;

	private Texture2D onIcon;

	private Texture2D offIcon;

	private Texture2D modIcon;

	private readonly Color ink = new Color(0.94f, 0.92f, 0.86f);

	private readonly Color muted = new Color(0.65f, 0.65f, 0.62f);

	private readonly Color green = new Color(0.35f, 1f, 0.18f);

	private readonly Color red = new Color(1f, 0.3f, 0.3f);

	private static readonly FieldInfo PreventPause = AccessTools.Field(typeof(GameManager), "m_preventUnpausing");

	public HashSet<string> Disabled { get; private set; }

	public List<CharacterRow> Roster { get; private set; }

	public string DataDirectory { get; private set; }

	public int SetupPasses { get; private set; }

	public bool MenuOpen { get; private set; }

	public HashSet<string> Draft { get; private set; }

	public string MenuStatus { get; private set; }

	private void Awake()
	{
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Expected O, but got Unknown
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Expected O, but got Unknown
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Expected O, but got Unknown
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Expected O, but got Unknown
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Expected O, but got Unknown
		Instance = this;
		DataDirectory = Path.Combine(Paths.ConfigPath, "konflame.CharacterDisabler");
		Disabled = Settings.ReadDisabled(DataDirectory);
		Roster = new List<CharacterRow>();
		harmony = new Harmony("konflame.etg.characterdisabler");
		int num = 0;
		Type[] nestedTypes = typeof(Foyer).GetNestedTypes(BindingFlags.Public | BindingFlags.NonPublic);
		foreach (Type type in nestedTypes)
		{
			if (type.Name.Contains("<Start>") || type.Name.Contains("<HandleCharacterSelect>"))
			{
				MethodInfo methodInfo = AccessTools.Method(type, "MoveNext", (Type[])null, (Type[])null);
				if ((object)methodInfo != null)
				{
					harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(CharacterDisabler), "AfterSetup", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null);
					num++;
				}
			}
		}
		if (num != 2)
		{
			throw new InvalidOperationException("Expected both Breach setup coroutines; found " + num);
		}
		harmony.Patch((MethodBase)AccessTools.Method(typeof(FoyerCharacterSelectFlag), "OnSelectedCharacterCallback", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(CharacterDisabler), "Reapply", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		harmony.Patch((MethodBase)AccessTools.Method(typeof(FoyerCharacterSelectFlag), "OnCoopChangedCallback", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(CharacterDisabler), "Reapply", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		harmony.Patch((MethodBase)AccessTools.Method(typeof(dfInputManager), "Update", (Type[])null, (Type[])null), new HarmonyMethod(typeof(CharacterDisabler), "AllowUnderlyingUI", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		Gunfig.Get("Character Disabler").AddButton("open", "Open Character Disabler [F6]", (Action<string, string>)delegate
		{
			OpenMenu();
		});
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Character Disabler 1.1.3 by konflame. F6 opens the menu. Changes apply next launch.");
	}

	private static IEnumerable<CodeInstruction> AfterSetup(IEnumerable<CodeInstruction> instructions)
	{
		bool found = false;
		foreach (CodeInstruction instruction in instructions)
		{
			yield return instruction;
			if (instruction.operand is MethodInfo method && (object)method.DeclaringType == typeof(Foyer) && method.Name == "SetUpCharacterCallbacks")
			{
				found = true;
				yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(CharacterDisabler), "FilterSelection", (Type[])null, (Type[])null));
			}
		}
		if (!found)
		{
			throw new InvalidOperationException("Breach setup call was not found; refusing an incomplete patch.");
		}
	}

	public static List<FoyerCharacterSelectFlag> FilterSelection(List<FoyerCharacterSelectFlag> source)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		CharacterDisabler mod = Instance;
		mod.sceneHandle = ((object)SceneManager.GetActiveScene()/*cast due to .constrained prefix*/).GetHashCode();
		mod.flags.Clear();
		mod.hidden.Clear();
		mod.fallback = null;
		mod.Discover();
		List<FoyerCharacterSelectFlag> list = source.Where((FoyerCharacterSelectFlag f) => Object.op_Implicit((Object)(object)f) && !f.IsCoopCharacter && mod.Available(f)).ToList();
		List<FoyerCharacterSelectFlag> list2 = list.Where((FoyerCharacterSelectFlag f) => !mod.Disabled.Contains(f.CharacterPrefabPath)).ToList();
		if (list2.Count == 0 && list.Count > 0)
		{
			mod.fallback = list[0].CharacterPrefabPath;
			list2.Add(list[0]);
			((BaseUnityPlugin)mod).Logger.LogWarning((object)("All available solo characters were disabled. Keeping " + mod.fallback + " available to prevent an empty selector."));
		}
		mod.ready = true;
		mod.SetupPasses++;
		mod.Refresh();
		((BaseUnityPlugin)mod).Logger.LogInfo((object)("Breach ready: " + mod.Roster.Count + " unlocked characters; " + list2.Count + " initial choices."));
		return list2;
	}

	private bool Unlocked(FoyerCharacterSelectFlag flag)
	{
		try
		{
			return flag.prerequisites == null || flag.PrerequisitesFulfilled();
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Cannot check " + flag.CharacterPrefabPath + ": " + ex.Message));
			return false;
		}
	}

	private bool Available(FoyerCharacterSelectFlag flag)
	{
		if (!Unlocked(flag))
		{
			return false;
		}
		try
		{
			return flag.CanBeSelected();
		}
		catch
		{
			return false;
		}
	}

	private bool Suppressed(FoyerCharacterSelectFlag flag)
	{
		if (Available(flag))
		{
			if (Disabled.Contains(flag.CharacterPrefabPath))
			{
				return !string.Equals(fallback, flag.CharacterPrefabPath, StringComparison.OrdinalIgnoreCase);
			}
			return false;
		}
		return true;
	}

	private void Discover()
	{
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		flags.RemoveAll((FoyerCharacterSelectFlag f) => !Object.op_Implicit((Object)(object)f));
		hidden.RemoveWhere((FoyerCharacterSelectFlag f) => !Object.op_Implicit((Object)(object)f));
		FoyerCharacterSelectFlag[] array = Resources.FindObjectsOfTypeAll<FoyerCharacterSelectFlag>();
		foreach (FoyerCharacterSelectFlag val in array)
		{
			if (!Object.op_Implicit((Object)(object)val))
			{
				continue;
			}
			Scene scene = ((Component)val).gameObject.scene;
			if (((Scene)(ref scene)).IsValid())
			{
				Scene scene2 = ((Component)val).gameObject.scene;
				if (((Scene)(ref scene2)).isLoaded && !string.IsNullOrEmpty(val.CharacterPrefabPath) && !flags.Contains(val))
				{
					flags.Add(val);
				}
			}
		}
	}

	public void Refresh()
	{
		Discover();
		foreach (FoyerCharacterSelectFlag flag in flags)
		{
			Enforce(flag);
		}
		Roster = (from g in flags.Where(Unlocked).GroupBy<FoyerCharacterSelectFlag, string>((FoyerCharacterSelectFlag f) => f.CharacterPrefabPath, StringComparer.OrdinalIgnoreCase)
			select Row(g.First()) into r
			orderby r.Kind, r.Name
			select r).ToList();
		string text = string.Join("\n", Roster.Select(Settings.Encode).ToArray());
		if (text == rosterText)
		{
			return;
		}
		try
		{
			Settings.WriteAtomic(Path.Combine(DataDirectory, "roster.tsv"), Roster.Select(Settings.Encode));
			rosterText = text;
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not update character list: " + ex.Message));
		}
	}

	public void Enforce(FoyerCharacterSelectFlag flag)
	{
		if (!Object.op_Implicit((Object)(object)flag))
		{
			return;
		}
		if (Suppressed(flag))
		{
			if (((Component)flag).gameObject.activeSelf)
			{
				hidden.Add(flag);
				if (Object.op_Implicit((Object)(object)((BraveBehaviour)flag).sprite))
				{
					SpriteOutlineManager.ToggleOutlineRenderers(((BraveBehaviour)flag).sprite, false);
				}
				flag.ClearOverheadElement();
				if (Object.op_Implicit((Object)(object)((BraveBehaviour)flag).talkDoer))
				{
					((BraveBehaviour)flag).talkDoer.IsInteractable = false;
				}
				((Component)flag).gameObject.SetActive(false);
			}
		}
		else if (hidden.Remove(flag) && !IsCurrent(flag))
		{
			((Component)flag).gameObject.SetActive(true);
			if (Object.op_Implicit((Object)(object)((BraveBehaviour)flag).specRigidbody))
			{
				((Behaviour)((BraveBehaviour)flag).specRigidbody).enabled = true;
			}
			if (Object.op_Implicit((Object)(object)((BraveBehaviour)flag).talkDoer))
			{
				((BraveBehaviour)flag).talkDoer.IsInteractable = true;
			}
		}
	}

	private static bool IsCurrent(FoyerCharacterSelectFlag f)
	{
		if (!GameManager.HasInstance)
		{
			return false;
		}
		PlayerController val = (f.IsCoopCharacter ? GameManager.Instance.SecondaryPlayer : GameManager.Instance.PrimaryPlayer);
		if (Object.op_Implicit((Object)(object)val))
		{
			return ((Object)val).name.IndexOf(f.CharacterPrefabPath, StringComparison.OrdinalIgnoreCase) >= 0;
		}
		return false;
	}

	private static void Reapply(FoyerCharacterSelectFlag __instance)
	{
		if (Object.op_Implicit((Object)(object)Instance) && Instance.ready)
		{
			Instance.Enforce(__instance);
		}
	}

	private CharacterRow Row(FoyerCharacterSelectFlag flag)
	{
		string value;
		bool flag2 = Names.TryGetValue(flag.CharacterPrefabPath, out value);
		if (!flag2)
		{
			value = flag.CharacterPrefabPath;
			Component[] components = ((Component)flag).GetComponents<Component>();
			foreach (Component val in components)
			{
				if (!Object.op_Implicit((Object)(object)val) || ((object)val).GetType().Name != "CustomCharacterFoyerController")
				{
					continue;
				}
				object obj = AccessTools.Field(((object)val).GetType(), "data")?.GetValue(val);
				if (obj != null)
				{
					FieldInfo fieldInfo = AccessTools.Field(obj.GetType(), "name");
					string text = (((object)fieldInfo == null) ? null : (fieldInfo.GetValue(obj) as string));
					if (!string.IsNullOrEmpty(text))
					{
						value = text;
					}
				}
			}
			if (Object.op_Implicit((Object)(object)flag.OverheadElement))
			{
				dfLabel[] componentsInChildren = flag.OverheadElement.GetComponentsInChildren<dfLabel>(true);
				foreach (dfLabel val2 in componentsInChildren)
				{
					if (!(((Object)val2).name != "NameLabel") && !string.IsNullOrEmpty(val2.Text))
					{
						string text2 = val2.Text;
						if (text2.StartsWith("#"))
						{
							text2 = ((dfControl)val2).ForceGetLocalizedValue(text2);
						}
						if (!string.IsNullOrEmpty(text2) && !text2.StartsWith("#") && text2.Length < 65)
						{
							value = text2;
							break;
						}
					}
				}
			}
		}
		CharacterRow characterRow = new CharacterRow();
		characterRow.Id = flag.CharacterPrefabPath;
		characterRow.Name = value.Replace("\n", " ").Trim();
		characterRow.Kind = (flag2 ? "Base game" : "Modded");
		characterRow.Selectable = Available(flag);
		characterRow.Coop = flag.IsCoopCharacter;
		return characterRow;
	}

	private void Update()
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		MenuInput();
		if (ready)
		{
			if (((object)SceneManager.GetActiveScene()/*cast due to .constrained prefix*/).GetHashCode() != sceneHandle)
			{
				ready = false;
				flags.Clear();
				hidden.Clear();
			}
			else if (!(Time.realtimeSinceStartup < nextScan))
			{
				nextScan = Time.realtimeSinceStartup + 1f;
				Refresh();
			}
		}
	}

	private void OnDestroy()
	{
		CloseMenu();
		DisposeIcons();
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
		if ((Object)(object)Instance == (Object)(object)this)
		{
			Instance = null;
		}
	}

	private static bool AllowUnderlyingUI()
	{
		if (Object.op_Implicit((Object)(object)Instance))
		{
			return !Instance.MenuOpen;
		}
		return true;
	}

	public void OpenMenu()
	{
		//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_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: 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)
		if (!MenuOpen && GameManager.HasInstance && !GameManager.Instance.IsLoadingLevel && Object.op_Implicit((Object)(object)GameUIRoot.Instance))
		{
			Draft = Settings.ReadDisabled(DataDirectory);
			MenuStatus = "";
			scroll = Vector2.zero;
			menuScene = ((object)SceneManager.GetActiveScene()/*cast due to .constrained prefix*/).GetHashCode();
			oldPreventPause = (bool)PreventPause.GetValue(GameManager.Instance);
			ownedPause = !GameManager.Instance.IsPaused;
			if (ownedPause)
			{
				GameManager.Instance.PauseRaw(true);
			}
			else
			{
				PreventPause.SetValue(GameManager.Instance, true);
			}
			oldCursor = Cursor.visible;
			oldLock = Cursor.lockState;
			Cursor.visible = true;
			Cursor.lockState = (CursorLockMode)0;
			MenuOpen = true;
			BraveInput.FlushAll();
		}
	}

	public void CloseMenu()
	{
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		if (!MenuOpen)
		{
			return;
		}
		MenuOpen = false;
		if (GameManager.HasInstance)
		{
			PreventPause.SetValue(GameManager.Instance, oldPreventPause);
			if (ownedPause)
			{
				GameManager.Instance.Unpause();
				BraveTime.ClearMultiplier(((Component)GameManager.Instance).gameObject);
			}
		}
		Cursor.visible = oldCursor;
		Cursor.lockState = oldLock;
		BraveInput.FlushAll();
	}

	public bool ApplyDraft()
	{
		if (Draft == null)
		{
			return false;
		}
		List<CharacterRow> list = Roster.Where((CharacterRow r) => r.Selectable && !r.Coop).ToList();
		if (list.Count > 0 && list.All((CharacterRow r) => Draft.Contains(r.Id)))
		{
			MenuStatus = "Leave at least one solo character on.";
			return false;
		}
		try
		{
			Settings.SaveDisabled(DataDirectory, Draft);
			MenuStatus = "Changes saved.";
			return true;
		}
		catch (Exception ex)
		{
			MenuStatus = "Couldn't save your changes. Try again.";
			((BaseUnityPlugin)this).Logger.LogError((object)ex);
			return false;
		}
	}

	public void ResetDraft()
	{
		Draft.Clear();
		MenuStatus = "Everyone is on. Apply Changes to save.";
	}

	private void ToggleRow(CharacterRow row)
	{
		if (!Draft.Remove(row.Id))
		{
			Draft.Add(row.Id);
		}
		MenuStatus = "You have unsaved changes.";
	}

	private void MenuInput()
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		if (Input.GetKeyDown((KeyCode)287))
		{
			if (MenuOpen)
			{
				CloseMenu();
			}
			else
			{
				OpenMenu();
			}
		}
		else if (MenuOpen)
		{
			if (((object)SceneManager.GetActiveScene()/*cast due to .constrained prefix*/).GetHashCode() != menuScene)
			{
				CloseMenu();
			}
			else if (Input.GetKeyDown((KeyCode)27))
			{
				CloseMenu();
			}
		}
	}

	private static Texture2D LoadIcon(string name)
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Expected O, but got Unknown
		using Stream stream = typeof(CharacterDisabler).Assembly.GetManifestResourceStream(name);
		if (stream == null)
		{
			throw new InvalidOperationException("Missing icon: " + name);
		}
		byte[] array = new BinaryReader(stream).ReadBytes((int)stream.Length);
		Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
		if (!ImageConversion.LoadImage(val, array))
		{
			Object.Destroy((Object)(object)val);
			throw new InvalidOperationException("Invalid icon: " + name);
		}
		((Texture)val).filterMode = (FilterMode)0;
		((Texture)val).wrapMode = (TextureWrapMode)1;
		return val;
	}

	private void Styles()
	{
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Expected O, but got Unknown
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Expected O, but got Unknown
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Expected O, but got Unknown
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Expected O, but got Unknown
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Expected O, but got Unknown
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: 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_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		if (heading == null)
		{
			onIcon = LoadIcon("CharacterDisabler.on.png");
			offIcon = LoadIcon("CharacterDisabler.off.png");
			modIcon = LoadIcon("CharacterDisabler.icon.png");
			GUIStyle val = new GUIStyle(GUI.skin.label);
			val.fontSize = 27;
			val.fontStyle = (FontStyle)1;
			val.alignment = (TextAnchor)3;
			heading = val;
			GUIStyle val2 = new GUIStyle(GUI.skin.label);
			val2.fontSize = 17;
			val2.fontStyle = (FontStyle)1;
			val2.alignment = (TextAnchor)3;
			val2.clipping = (TextClipping)1;
			label = val2;
			GUIStyle val3 = new GUIStyle(GUI.skin.label);
			val3.fontSize = 13;
			val3.wordWrap = true;
			val3.alignment = (TextAnchor)3;
			small = val3;
			GUIStyle val4 = new GUIStyle(GUI.skin.label);
			val4.fontSize = 16;
			val4.fontStyle = (FontStyle)1;
			val4.alignment = (TextAnchor)4;
			button = val4;
			GUIStyle val5 = new GUIStyle(button);
			val5.fontSize = 17;
			toggle = val5;
			GUIStyleState normal = heading.normal;
			GUIStyleState normal2 = label.normal;
			Color val6 = (button.normal.textColor = ink);
			Color textColor = (normal2.textColor = val6);
			normal.textColor = textColor;
			small.normal.textColor = muted;
		}
	}

	private void DisposeIcons()
	{
		if (Object.op_Implicit((Object)(object)onIcon))
		{
			Object.Destroy((Object)(object)onIcon);
		}
		if (Object.op_Implicit((Object)(object)offIcon))
		{
			Object.Destroy((Object)(object)offIcon);
		}
		if (Object.op_Implicit((Object)(object)modIcon))
		{
			Object.Destroy((Object)(object)modIcon);
		}
	}

	private static void Fill(Rect rect, Color color)
	{
		//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_0006: 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)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		Color color2 = GUI.color;
		GUI.color = color;
		GUI.DrawTexture(rect, (Texture)(object)Texture2D.whiteTexture);
		GUI.color = color2;
	}

	private bool DrawButton(Rect rect, string text, bool primary)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: 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_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		bool flag = ((Rect)(ref rect)).Contains(Event.current.mousePosition);
		Fill(rect, primary ? new Color(0.55f, 0.48f, 0.3f) : new Color(0.32f, 0.32f, 0.3f));
		Fill(new Rect(((Rect)(ref rect)).x + 1f, ((Rect)(ref rect)).y + 1f, ((Rect)(ref rect)).width - 2f, ((Rect)(ref rect)).height - 2f), primary ? new Color(flag ? 0.36f : 0.29f, 0.26f, 0.18f) : new Color(flag ? 0.25f : 0.19f, 0.19f, 0.18f));
		return GUI.Button(rect, text, button);
	}

	private bool DrawToggle(Rect rect, bool enabled)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: 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_0079: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: 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)
		bool flag = ((Rect)(ref rect)).Contains(Event.current.mousePosition);
		Fill(rect, enabled ? new Color(0.24f, 0.4f, 0.18f) : new Color(0.46f, 0.22f, 0.22f));
		Fill(new Rect(((Rect)(ref rect)).x + 1f, ((Rect)(ref rect)).y + 1f, ((Rect)(ref rect)).width - 2f, ((Rect)(ref rect)).height - 2f), new Color(flag ? 0.22f : 0.14f, 0.15f, 0.13f));
		bool result = GUI.Button(rect, GUIContent.none, GUIStyle.none);
		GUI.DrawTexture(new Rect(((Rect)(ref rect)).x + 7f, ((Rect)(ref rect)).y + 3f, 44f, 38f), (Texture)(object)(enabled ? onIcon : offIcon), (ScaleMode)2, true);
		toggle.normal.textColor = (enabled ? green : red);
		GUI.Label(new Rect(((Rect)(ref rect)).x + 55f, ((Rect)(ref rect)).y, ((Rect)(ref rect)).width - 60f, ((Rect)(ref rect)).height), enabled ? "ON" : "OFF", toggle);
		return result;
	}

	private void OnGUI()
	{
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: 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_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: 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_01de: Unknown result type (might be due to invalid IL or missing references)
		//IL_0204: Unknown result type (might be due to invalid IL or missing references)
		//IL_022e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0289: Unknown result type (might be due to invalid IL or missing references)
		//IL_029d: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0365: Unknown result type (might be due to invalid IL or missing references)
		//IL_0393: Unknown result type (might be due to invalid IL or missing references)
		//IL_0330: Unknown result type (might be due to invalid IL or missing references)
		//IL_0344: Unknown result type (might be due to invalid IL or missing references)
		//IL_0464: Unknown result type (might be due to invalid IL or missing references)
		//IL_048f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0436: Unknown result type (might be due to invalid IL or missing references)
		//IL_04bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e9: 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)
		//IL_0504: Unknown result type (might be due to invalid IL or missing references)
		if (!GameManager.HasInstance || !Object.op_Implicit((Object)(object)GameUIRoot.Instance) || GameManager.Instance.IsLoadingLevel)
		{
			return;
		}
		Styles();
		if (!MenuOpen)
		{
			if (ready && !GameManager.Instance.IsPaused && GUI.Button(new Rect(18f, (float)(Screen.height - 46), 260f, 30f), "Character Disabler  [F6]", small))
			{
				OpenMenu();
			}
			return;
		}
		int depth = GUI.depth;
		Matrix4x4 matrix = GUI.matrix;
		Color color = GUI.color;
		GUI.depth = -10000;
		GUI.color = Color.white;
		float num = Mathf.Min(1.35f, Mathf.Min((float)Screen.width / 610f, (float)Screen.height / 750f));
		GUI.matrix = Matrix4x4.TRS(new Vector3(Mathf.Round(((float)Screen.width - 550f * num) * 0.5f), Mathf.Round(((float)Screen.height - 700f * num) * 0.5f), 0f), Quaternion.identity, new Vector3(num, num, 1f));
		Fill(new Rect((float)(-Screen.width) / num, (float)(-Screen.height) / num, (float)(Screen.width * 3) / num, (float)(Screen.height * 3) / num), new Color(0.02f, 0.02f, 0.02f, 0.88f));
		Fill(new Rect(-2f, -2f, 554f, 704f), new Color(0.39f, 0.38f, 0.34f));
		Fill(new Rect(0f, 0f, 550f, 700f), new Color(0.12f, 0.12f, 0.115f));
		GUI.DrawTexture(new Rect(26f, 22f, 56f, 56f), (Texture)(object)modIcon, (ScaleMode)2, true);
		GUI.Label(new Rect(96f, 23f, 402f, 44f), "Character Disabler", heading);
		if (DrawButton(new Rect(506f, 8f, 34f, 28f), "X", primary: false))
		{
			CloseMenu();
		}
		List<CharacterRow> list = Roster.Where((CharacterRow r) => r.Selectable).ToList();
		Fill(new Rect(26f, 102f, 498f, 474f), new Color(0.075f, 0.075f, 0.07f));
		scroll = GUI.BeginScrollView(new Rect(26f, 102f, 498f, 474f), scroll, new Rect(0f, 0f, 473f, (float)Mathf.Max(472, list.Count * 60 + 8)));
		for (int num2 = 0; num2 < list.Count; num2++)
		{
			CharacterRow characterRow = list[num2];
			float num3 = num2 * 60 + 5;
			if (num2 % 2 == 0)
			{
				Fill(new Rect(3f, num3, 468f, 58f), new Color(0.105f, 0.105f, 0.098f));
			}
			GUI.Label(new Rect(14f, num3 + 4f, 321f, 27f), characterRow.Name, label);
			GUI.Label(new Rect(15f, num3 + 30f, 320f, 20f), characterRow.Kind + (characterRow.Coop ? " (Co-op)" : ""), small);
			if (DrawToggle(new Rect(346f, num3 + 7f, 116f, 44f), !Draft.Contains(characterRow.Id)))
			{
				ToggleRow(characterRow);
			}
		}
		if (list.Count == 0)
		{
			GUI.Label(new Rect(14f, 20f, 445f, 75f), "Your characters will appear here once you visit the Breach.", small);
		}
		GUI.EndScrollView();
		GUI.Label(new Rect(26f, 584f, 498f, 35f), MenuStatus, small);
		if (DrawButton(new Rect(26f, 629f, 180f, 41f), "Reset Defaults", primary: false))
		{
			ResetDraft();
		}
		if (DrawButton(new Rect(222f, 629f, 302f, 41f), "Apply Changes", primary: true))
		{
			ApplyDraft();
		}
		GUI.Label(new Rect(26f, 674f, 498f, 23f), "Restart the game after applying changes.", small);
		GUI.matrix = matrix;
		GUI.color = color;
		GUI.depth = depth;
	}
}