Decompiled source of ThronefallMultiplayer v1.0.5

ThronefallMultiplayer_Mod\BepInEx\plugins\ThronefallMultiplayer\com.badwolf.thronefall_mp.dll

Decompiled 4 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using I2.Loc;
using JetBrains.Annotations;
using MPUIKIT;
using Microsoft.CodeAnalysis;
using MoreMountains.Feedbacks;
using On;
using Pathfinding;
using Pathfinding.RVO;
using Rewired;
using Shapes;
using Steamworks;
using TMPro;
using ThronefallMP.Components;
using ThronefallMP.Network;
using ThronefallMP.Network.Packets;
using ThronefallMP.Network.Packets.Administration;
using ThronefallMP.Network.Packets.Game;
using ThronefallMP.Network.Packets.PlayerCommand;
using ThronefallMP.Network.Packets.Sync;
using ThronefallMP.Network.Sync;
using ThronefallMP.Patches;
using ThronefallMP.UI;
using ThronefallMP.UI.Controls;
using ThronefallMP.UI.Dialogs;
using ThronefallMP.UI.Panels;
using ThronefallMP.Utils;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Experimental.Rendering;
using UnityEngine.SceneManagement;
using UnityEngine.TextCore.LowLevel;
using UnityEngine.UI;
using UnityEngine.UIElements.Experimental;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Rikhardur Bjarni Einarsson (BadWolf)")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("All rights reserved")]
[assembly: AssemblyDescription("Multiplayer mod for Thronefall")]
[assembly: AssemblyFileVersion("1.0.5.0")]
[assembly: AssemblyInformationalVersion("1.0.5")]
[assembly: AssemblyProduct("com.badwolf.thronefall_mp")]
[assembly: AssemblyTitle("com.badwolf.thronefall_mp")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.5.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class IsUnmanagedAttribute : Attribute
	{
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ThronefallMP
{
	public class CheatHandler
	{
		private delegate bool CheatMessageHandler(string user, string[] parts);

		private Dictionary<string, CheatMessageHandler> _handlers = new Dictionary<string, CheatMessageHandler>();

		private static bool CheatsEnabled
		{
			get
			{
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				if (Plugin.Instance.Network.Online)
				{
					if (SteamManager.Initialized)
					{
						return SteamMatchmaking.GetLobbyData(Plugin.Instance.Network.Lobby, "cheats_enabled") == "yes";
					}
					return false;
				}
				return true;
			}
		}

		public CheatHandler()
		{
			_handlers.Add("add_coins", AddCoins);
			Plugin.Instance.Network.AddChatMessageHandler(100, OnMessageReceived);
		}

		private bool OnMessageReceived(string user, string message)
		{
			if (!CheatsEnabled || !Plugin.Instance.Network.Server || !message.StartsWith("/"))
			{
				return false;
			}
			message = message.Remove(0, 1);
			Plugin.Log.LogInfo((object)("Parsing cheat '" + message + "'"));
			string[] array = message.Split(' ');
			Plugin.Log.LogInfo((object)("Command '" + array[0] + "'"));
			if (_handlers.TryGetValue(array[0], out var value))
			{
				return value(user, array.Skip(1).ToArray());
			}
			Plugin.Log.LogInfo((object)"Not found");
			return false;
		}

		private bool AddCoins(string user, string[] parts)
		{
			if (parts.Length != 1)
			{
				Plugin.Log.LogInfo((object)"Too many arguments");
				return false;
			}
			if (!int.TryParse(parts[0], out var result))
			{
				Plugin.Log.LogInfo((object)"Failed to parse coins");
				return false;
			}
			GlobalData.Balance += result;
			Plugin.Instance.Network.SendServerMessage($"{user} Cheated in {result} coins.");
			return true;
		}
	}
	public enum Equipment
	{
		Invalid,
		PerkPoint,
		LongBow,
		LightSpear,
		HeavySword,
		LightningWand,
		RoyalMint,
		ArcaneTowers,
		HeavyArmor,
		CastleFortifications,
		RingOfResurrection,
		PumpkinFields,
		ArchitectsCouncil,
		GodsLotion,
		CastleBlueprints,
		GladiatorSchool,
		WarHorse,
		GlassCannon,
		BigHarbours,
		EliteWarriors,
		ArcherySkills,
		FasterResearch,
		TowerSupport,
		FortifiedHouses,
		CommanderMode,
		HealingSpirits,
		IceMagic,
		MeleeResistance,
		PowerTower,
		RangedResistance,
		TreasureHunter,
		IndestructibleMines,
		WarriorMode,
		MeleeDamage,
		FirewingHero,
		AntiAirTelescope,
		RangedDamage,
		StrongerHeroes,
		LizardRiderHero,
		AssassinsTraining,
		MagicArmor,
		GodlyCurse,
		CastleUp,
		MillScarecrow,
		MillWindSpirits,
		TowerHotOil,
		MeleeFlails,
		RangedHunters,
		MeleeBerserkers,
		RangedFireArchers,
		WarGods,
		Turtle,
		Tiger,
		Rat,
		Falcon,
		Destruction,
		Wasp,
		Death,
		Phoenix,
		NoWallsPact,
		NoTowersPact,
		NoUnitsPact
	}
	public static class Equip
	{
		public static readonly HashSet<Equipment> Weapons = new HashSet<Equipment>
		{
			Equipment.LongBow,
			Equipment.LightSpear,
			Equipment.HeavySword,
			Equipment.LightningWand
		};

		private static readonly Dictionary<string, Equipment> NameToEquip = new Dictionary<string, Equipment>
		{
			{
				"",
				Equipment.Invalid
			},
			{
				"Perk Point",
				Equipment.PerkPoint
			},
			{
				"Long Bow",
				Equipment.LongBow
			},
			{
				"Light Spear",
				Equipment.LightSpear
			},
			{
				"Heavy Sword",
				Equipment.HeavySword
			},
			{
				"Lightning Wand",
				Equipment.LightningWand
			},
			{
				"Universal Income",
				Equipment.RoyalMint
			},
			{
				"Arcane Towers",
				Equipment.ArcaneTowers
			},
			{
				"Heavy Armor",
				Equipment.HeavyArmor
			},
			{
				"Castle Fortifications",
				Equipment.CastleFortifications
			},
			{
				"Ring of Resurection",
				Equipment.RingOfResurrection
			},
			{
				"Pumpkin Fields",
				Equipment.PumpkinFields
			},
			{
				"Architect's Council",
				Equipment.ArchitectsCouncil
			},
			{
				"Gods Lotion",
				Equipment.GodsLotion
			},
			{
				"Castle Blueprints",
				Equipment.CastleBlueprints
			},
			{
				"Gladiator School",
				Equipment.GladiatorSchool
			},
			{
				"War Horse",
				Equipment.WarHorse
			},
			{
				"Glass Canon",
				Equipment.GlassCannon
			},
			{
				"Big Harbours",
				Equipment.BigHarbours
			},
			{
				"Ellite Warriors",
				Equipment.EliteWarriors
			},
			{
				"Archery Skills",
				Equipment.ArcherySkills
			},
			{
				"Faster Research",
				Equipment.FasterResearch
			},
			{
				"TowerSupport",
				Equipment.TowerSupport
			},
			{
				"Fortified Houses",
				Equipment.FortifiedHouses
			},
			{
				"Commander Mode",
				Equipment.CommanderMode
			},
			{
				"Healing Spirits",
				Equipment.HealingSpirits
			},
			{
				"Ice Magic",
				Equipment.IceMagic
			},
			{
				"Melee Resistence",
				Equipment.MeleeResistance
			},
			{
				"Power Tower",
				Equipment.PowerTower
			},
			{
				"Ranged Resistence",
				Equipment.RangedResistance
			},
			{
				"Treasure Hunter",
				Equipment.TreasureHunter
			},
			{
				"Indestructible Mines",
				Equipment.IndestructibleMines
			},
			{
				"Warrior Mode",
				Equipment.WarriorMode
			},
			{
				"Melee Damage",
				Equipment.MeleeDamage
			},
			{
				"Firewing Hero",
				Equipment.FirewingHero
			},
			{
				"Anti Air Telescope",
				Equipment.AntiAirTelescope
			},
			{
				"Ranged Damage",
				Equipment.RangedDamage
			},
			{
				"Stronger Heros",
				Equipment.StrongerHeroes
			},
			{
				"LizzardRider Hero",
				Equipment.LizardRiderHero
			},
			{
				"CCAssassinsTraining",
				Equipment.AssassinsTraining
			},
			{
				"CCMagicArmor",
				Equipment.MagicArmor
			},
			{
				"CCGodlyCurse",
				Equipment.GodlyCurse
			},
			{
				"CCCastleUp",
				Equipment.CastleUp
			},
			{
				"MillScarecrow",
				Equipment.MillScarecrow
			},
			{
				"MillWindSpirits",
				Equipment.MillWindSpirits
			},
			{
				"TowerHotOil",
				Equipment.TowerHotOil
			},
			{
				"MeleeFlails",
				Equipment.MeleeFlails
			},
			{
				"RangedHunters",
				Equipment.RangedHunters
			},
			{
				"MeleeBerserks",
				Equipment.MeleeBerserkers
			},
			{
				"RangedFireArchers",
				Equipment.RangedFireArchers
			},
			{
				"Pray to The God of Strength",
				Equipment.WarGods
			},
			{
				"Taunt The Turtle God",
				Equipment.Turtle
			},
			{
				"Taunt The Tiger God",
				Equipment.Tiger
			},
			{
				"Taunt The Rat God",
				Equipment.Rat
			},
			{
				"Taunt The Falcon God",
				Equipment.Falcon
			},
			{
				"Taunt God of Destruction",
				Equipment.Destruction
			},
			{
				"Taunt The Cheese God",
				Equipment.Wasp
			},
			{
				"Taunt The Disease God",
				Equipment.Death
			},
			{
				"Taunt The Phoenix God",
				Equipment.Phoenix
			},
			{
				"No Walls Pact",
				Equipment.NoWallsPact
			},
			{
				"No Towers Pact",
				Equipment.NoTowersPact
			},
			{
				"No Units Pact",
				Equipment.NoUnitsPact
			}
		};

		private static readonly Dictionary<Equipment, Equippable> EquipmentToEquippable = new Dictionary<Equipment, Equippable>();

		private static readonly Dictionary<Equippable, Equipment> EquippableToEquipment = new Dictionary<Equippable, Equipment>();

		private static bool _initialized;

		private static void InitializeDictionaries()
		{
			_initialized = true;
			Traverse<List<MetaLevel>> val = Traverse.Create((object)PerkManager.instance).Field<List<MetaLevel>>("metaLevels");
			Plugin.Log.LogInfoFiltered("Equipment", "Initializing converter dictionary");
			Plugin.Log.LogInfoFiltered("Equipment", "Meta levels");
			foreach (MetaLevel item in val.Value)
			{
				Equipment equipment = Convert(((Object)item.reward).name);
				Plugin.Log.LogInfoFiltered("Equipment", $"- {equipment} = {((Object)item.reward).name}");
				EquipmentToEquippable[equipment] = item.reward;
				EquippableToEquipment[item.reward] = equipment;
			}
			Plugin.Log.LogInfoFiltered("Equipment", "Currently Unlocked");
			foreach (Equippable unlockedEquippable in PerkManager.instance.UnlockedEquippables)
			{
				Equipment equipment2 = Convert(((Object)unlockedEquippable).name);
				Plugin.Log.LogInfoFiltered("Equipment", $"- {equipment2} = {((Object)unlockedEquippable).name}");
				EquipmentToEquippable[equipment2] = unlockedEquippable;
				EquippableToEquipment[unlockedEquippable] = equipment2;
			}
		}

		public static void ClearEquipments()
		{
			Plugin.Log.LogInfoFiltered("Equipment", "Clearing equipment");
			PerkManager.instance.CurrentlyEquipped.Clear();
		}

		public static void EquipEquipment(Equipment equipment)
		{
			if (!_initialized)
			{
				InitializeDictionaries();
			}
			Plugin.Log.LogInfoFiltered("Equipment", $"Equipping {equipment} -> {EquipmentToEquippable[equipment].displayName}");
			PerkManager.instance.CurrentlyEquipped.Add(EquipmentToEquippable[equipment]);
		}

		public static Equipment Convert(Equippable equip)
		{
			if (!_initialized)
			{
				InitializeDictionaries();
			}
			return GeneralExtensions.GetValueSafe<Equippable, Equipment>(EquippableToEquipment, equip);
		}

		public static Equippable Convert(Equipment equip)
		{
			if (!_initialized)
			{
				InitializeDictionaries();
			}
			return GeneralExtensions.GetValueSafe<Equipment, Equippable>(EquipmentToEquippable, equip);
		}

		public static Equipment Convert(string name)
		{
			return GeneralExtensions.GetValueSafe<string, Equipment>(NameToEquip, name);
		}
	}
	public struct InternalGlobalData
	{
		public int Balance;

		public int NetWorth;
	}
	public static class GlobalData
	{
		public static InternalGlobalData Internal;

		public static int LocalBalanceDelta;

		public static int Balance
		{
			get
			{
				if (!Plugin.Instance.Network.Server)
				{
					return Internal.Balance + LocalBalanceDelta;
				}
				return Internal.Balance;
			}
			set
			{
				if (Plugin.Instance.Network.Server)
				{
					Internal.Balance = value;
				}
				else
				{
					LocalBalanceDelta = value - Internal.Balance;
				}
			}
		}

		public static int NetWorth => Internal.NetWorth;
	}
	[BepInPlugin("com.badwolf.thronefall_mp", "Thronefall Multiplayer", "1.0.5")]
	[BepInProcess("Thronefall.exe")]
	public class Plugin : BaseUnityPlugin
	{
		public delegate void LoadCallback();

		public const string VersionString = "thronefall_mp_1.0.5";

		public static readonly Random Random = new Random();

		[UsedImplicitly]
		public PingPongSync PingPongSync = new PingPongSync();

		[UsedImplicitly]
		public LevelDataSync LevelDataSync = new LevelDataSync();

		[UsedImplicitly]
		public ResourceSync ResourceSync = new ResourceSync();

		[UsedImplicitly]
		public InputSync InputSync = new InputSync();

		[UsedImplicitly]
		public PositionSync PositionSync = new PositionSync();

		[UsedImplicitly]
		public HpSync HpSync = new HpSync();

		[UsedImplicitly]
		public AllyPathfinderSync AllyPathfinderSync = new AllyPathfinderSync();

		[UsedImplicitly]
		public EnemyPathfinderSync EnemyPathfinderSync = new EnemyPathfinderSync();

		private static Dictionary<string, List<(bool waitForTransition, LoadCallback callback)>> _loadCallbacks = new Dictionary<string, List<(bool, LoadCallback)>>();

		public static Plugin Instance { get; private set; }

		public static ManualLogSource Log { get; private set; }

		public ThronefallMP.Network.Network Network { get; private set; }

		public PlayerManager PlayerManager { get; private set; }

		public TextureRepository TextureRepository { get; private set; }

		[UsedImplicitly]
		public CheatHandler CheatHandler { get; private set; }

		private void Awake()
		{
			ConfigEntry<bool> val = ((BaseUnityPlugin)this).Config.Bind<bool>("Network", "EnableSimulation", false, "Enable simulation of a bad network for debugging");
			Instance = this;
			TextureRepository = new TextureRepository();
			Network = ((Component)Instance).gameObject.AddComponent<ThronefallMP.Network.Network>();
			PlayerManager = new PlayerManager();
			CheatHandler = new CheatHandler();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin com.badwolf.thronefall_mp is loaded!");
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)$"Little Endian: {BitConverter.IsLittleEndian}");
			if (SteamManager.Initialized)
			{
				SetSteamNetworkConfigValues();
				if (val.Value)
				{
					SetSteamNetworkSimulationValues();
				}
			}
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			BuildingInteractorPatch.Apply();
			BuildSlotPatch.Apply();
			CameraRigPatch.Apply();
			CommandUnitsPatch.Apply();
			CostDisplayPatch.Apply();
			DayNightCyclePatch.Apply();
			EnemySpawnerPatch.Apply();
			GateOpenerPatch.Apply();
			HpPatch.Apply();
			InGameResignUIHelperPatch.Apply();
			LevelBorderPatch.Apply();
			LevelSelectManagerPatch.Apply();
			NightCallPatch.Apply();
			PathFinderMovementEnemyPatch.Apply();
			PathfindMovementPlayerunitPatch.Apply();
			PerkHpModifyerPatch.Apply();
			PerkWeaponModifyerPatch.Apply();
			PlayerAttackPatch.Apply();
			PlayerInteractionPatch.Apply();
			PlayerMovementPatch.Apply();
			PlayerSceptPatch.Apply();
			RevivePanelPatch.Apply();
			SceneTransitionManagerPatch.Apply();
			SteamManagerPatch.Apply();
			TreasuryUIPatch.Apply();
			UIFrameManagerPatch.Apply();
			UIFramePatch.Apply();
			UnitRespawnerForBuildingsPatch.Apply();
			UpgradeAssassinsTrainingPatch.Apply();
			WeaponEquipperPatch.Apply();
			Application.runInBackground = true;
			SceneManager.sceneLoaded += OnSceneChanged;
		}

		private void OnUIInitialized()
		{
			UIManager.Initialize();
			ConfigEntry<bool> val = ((BaseUnityPlugin)this).Config.Bind<bool>("Network", "EnableSimulation", false, "Enable simulation of a bad network for debugging");
			if (val.Value)
			{
				UIManager.CreateMessageDialog("Network Debug Simulation", "Simulation of a bad network is enabled");
			}
		}

		private void OnSceneChanged(Scene scene, LoadSceneMode mode)
		{
			if (((Scene)(ref scene)).name == "_UI")
			{
				OnUIInitialized();
			}
			if (!_loadCallbacks.TryGetValue(((Scene)(ref scene)).name, out List<(bool, LoadCallback)> value))
			{
				return;
			}
			foreach (var item in value)
			{
				if (item.Item1)
				{
					CallbackOnFinishTransition(item.Item2);
				}
				else
				{
					item.Item2();
				}
			}
			value.Clear();
		}

		public static void CallbackOnLoad(string scene, bool waitForTransition, LoadCallback callback)
		{
			if (!_loadCallbacks.TryGetValue(scene, out List<(bool, LoadCallback)> value))
			{
				value = new List<(bool, LoadCallback)>();
				_loadCallbacks[scene] = value;
			}
			value.Add((waitForTransition, callback));
		}

		private static void CallbackOnFinishTransition(LoadCallback callback)
		{
			((MonoBehaviour)Instance).StartCoroutine(WaitForTransition(callback));
		}

		private static IEnumerator WaitForTransition(LoadCallback callback)
		{
			while (SceneTransitionManager.instance.SceneTransitionIsRunning)
			{
				yield return null;
			}
			callback?.Invoke();
		}

		private void SetSteamNetworkConfigValues()
		{
			SetSteamNetworkValue((ESteamNetworkingConfigValue)24, (ESteamNetworkingConfigDataType)1, 1600);
			SetSteamNetworkValue((ESteamNetworkingConfigValue)25, (ESteamNetworkingConfigDataType)1, 3200);
			SetSteamNetworkValue((ESteamNetworkingConfigValue)9, (ESteamNetworkingConfigDataType)1, 4194304);
		}

		private void SetSteamNetworkSimulationValues()
		{
			SetSteamNetworkValue((ESteamNetworkingConfigValue)2, (ESteamNetworkingConfigDataType)3, ((BaseUnityPlugin)this).Config.Bind<float>("Network", "PacketLossSendPercentage", 0.3f, (ConfigDescription)null).Value);
			SetSteamNetworkValue((ESteamNetworkingConfigValue)3, (ESteamNetworkingConfigDataType)3, ((BaseUnityPlugin)this).Config.Bind<float>("Network", "PacketLossReceivePercentage", 0.3f, (ConfigDescription)null).Value);
			SetSteamNetworkValue((ESteamNetworkingConfigValue)4, (ESteamNetworkingConfigDataType)1, ((BaseUnityPlugin)this).Config.Bind<int>("Network", "PacketLagSendMs", 80, (ConfigDescription)null).Value);
			SetSteamNetworkValue((ESteamNetworkingConfigValue)5, (ESteamNetworkingConfigDataType)1, ((BaseUnityPlugin)this).Config.Bind<int>("Network", "PacketLagReceiveMs", 80, (ConfigDescription)null).Value);
			SetSteamNetworkValue((ESteamNetworkingConfigValue)6, (ESteamNetworkingConfigDataType)3, ((BaseUnityPlugin)this).Config.Bind<float>("Network", "PacketReorderPercentageSend", 0.1f, (ConfigDescription)null).Value);
			SetSteamNetworkValue((ESteamNetworkingConfigValue)7, (ESteamNetworkingConfigDataType)3, ((BaseUnityPlugin)this).Config.Bind<float>("Network", "PacketReorderPercentageReceive", 0.1f, (ConfigDescription)null).Value);
			SetSteamNetworkValue((ESteamNetworkingConfigValue)8, (ESteamNetworkingConfigDataType)1, ((BaseUnityPlugin)this).Config.Bind<int>("Network", "PacketReorderTime", 20, (ConfigDescription)null).Value);
			SetSteamNetworkValue((ESteamNetworkingConfigValue)26, (ESteamNetworkingConfigDataType)3, ((BaseUnityPlugin)this).Config.Bind<float>("Network", "PacketDuplicatePercentSend", 0.1f, (ConfigDescription)null).Value);
			SetSteamNetworkValue((ESteamNetworkingConfigValue)26, (ESteamNetworkingConfigDataType)3, ((BaseUnityPlugin)this).Config.Bind<float>("Network", "PacketDuplicatePercentReceive", 0.1f, (ConfigDescription)null).Value);
			SetSteamNetworkValue((ESteamNetworkingConfigValue)28, (ESteamNetworkingConfigDataType)1, ((BaseUnityPlugin)this).Config.Bind<int>("Network", "PacketDuplicateTimeMax", 60, (ConfigDescription)null).Value);
		}

		private static void SetSteamNetworkValue<T>(ESteamNetworkingConfigValue name, ESteamNetworkingConfigDataType type, T value) where T : unmanaged
		{
			//IL_000d: 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)
			GCHandle gCHandle = GCHandle.Alloc(value, GCHandleType.Pinned);
			SteamNetworkingUtils.SetConfigValue(name, (ESteamNetworkingConfigScope)1, IntPtr.Zero, type, gCHandle.AddrOfPinnedObject());
			gCHandle.Free();
		}
	}
	public class PrefabSpawner : MonoBehaviour
	{
		public enum EnemyType
		{
			Unknown,
			Archer,
			Catapult,
			Crossbow,
			Exploder,
			Flyer,
			Hunterling,
			Melee,
			MonsterRider,
			Ogre,
			ProjectileBow,
			Racer,
			Slime,
			StrongSlime,
			Weakling
		}

		private readonly Dictionary<string, EnemyType> _enemyNameToType = new Dictionary<string, EnemyType>();

		private readonly Dictionary<EnemyType, string> _enemyTypeToName = new Dictionary<EnemyType, string>();

		private readonly Dictionary<EnemyType, GameObject> _prefabs = new Dictionary<EnemyType, GameObject>();

		private void Awake()
		{
			AddEnemyEntries(EnemyType.Unknown, "");
			AddEnemyEntries(EnemyType.Archer, "E Archer");
			AddEnemyEntries(EnemyType.Catapult, "E Catapult");
			AddEnemyEntries(EnemyType.Crossbow, "E Crossbow");
			AddEnemyEntries(EnemyType.Exploder, "E Exploder");
			AddEnemyEntries(EnemyType.Flyer, "E Flyer");
			AddEnemyEntries(EnemyType.Hunterling, "E Hunterling");
			AddEnemyEntries(EnemyType.Melee, "E Melee");
			AddEnemyEntries(EnemyType.MonsterRider, "E MonsterRider");
			AddEnemyEntries(EnemyType.Ogre, "E Ogre");
			AddEnemyEntries(EnemyType.ProjectileBow, "E ProjectileBow");
			AddEnemyEntries(EnemyType.Racer, "E Racer");
			AddEnemyEntries(EnemyType.Slime, "E Slime");
			AddEnemyEntries(EnemyType.StrongSlime, "E StrongSlime");
			AddEnemyEntries(EnemyType.Weakling, "E Weakling");
		}

		private void AddEnemyEntries(EnemyType type, string enemy)
		{
			_enemyTypeToName.Add(type, enemy);
			_enemyNameToType.Add(enemy, type);
		}

		private GameObject GetPrefab(EnemyType type)
		{
			if (!_prefabs.TryGetValue(type, out var value) || (Object)(object)value == (Object)null)
			{
				value = GameObject.Find(_enemyTypeToName[type]);
				_prefabs.Add(type, value);
			}
			return value;
		}

		public EnemyType ToEnemy(string enemy)
		{
			if (!_enemyNameToType.TryGetValue(enemy, out var value))
			{
				return EnemyType.Unknown;
			}
			return value;
		}

		public GameObject Spawn(ushort id, EnemyType type)
		{
			GameObject prefab = GetPrefab(type);
			if ((Object)(object)prefab == (Object)null)
			{
				return null;
			}
			GameObject val = Helpers.InstantiateDisabled<GameObject>(prefab, (Transform)null, worldPositionStays: false);
			Identifier identifier = val.AddComponent<Identifier>();
			identifier.SetIdentity(IdentifierType.Enemy, id);
			return val;
		}
	}
	public class TextureRepository
	{
		public readonly Texture2D Crown = LoadTexture("crown.png");

		public readonly Texture2D Lock = LoadTexture("lock-icon.png");

		public readonly Texture2D Blank = LoadTexture("blank.png");

		private static Texture2D LoadTexture(string textureName)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string name = executingAssembly.GetManifestResourceNames().Single((string str) => str.EndsWith(textureName));
			Stream manifestResourceStream = executingAssembly.GetManifestResourceStream(name);
			Texture2D val = new Texture2D(2, 2, (GraphicsFormat)8, 1, (TextureCreationFlags)0);
			using MemoryStream memoryStream = new MemoryStream();
			manifestResourceStream.CopyTo(memoryStream);
			ImageConversion.LoadImage(val, memoryStream.ToArray());
			return val;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "com.badwolf.thronefall_mp";

		public const string PLUGIN_NAME = "com.badwolf.thronefall_mp";

		public const string PLUGIN_VERSION = "1.0.5";
	}
}
namespace ThronefallMP.Utils
{
	public static class Ext
	{
		public static bool LogErrorFiltered(string section)
		{
			return ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Debug", "ShowError" + section, true, (ConfigDescription)null).Value;
		}

		public static void LogErrorFiltered(this ManualLogSource source, string section, object obj)
		{
			ConfigEntry<bool> val = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Debug", "ShowError" + section, true, (ConfigDescription)null);
			if (val.Value)
			{
				source.LogError((object)(section + "> " + obj));
			}
		}

		public static bool LogWarningFiltered(string section)
		{
			return ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Debug", "ShowWarning" + section, true, (ConfigDescription)null).Value;
		}

		public static void LogWarningFiltered(this ManualLogSource source, string section, object obj)
		{
			ConfigEntry<bool> val = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Debug", "ShowWarning" + section, true, (ConfigDescription)null);
			if (val.Value)
			{
				source.LogWarning((object)(section + "> " + obj));
			}
		}

		public static bool LogInfoFiltered(string section)
		{
			return ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Debug", "ShowInfo" + section, true, (ConfigDescription)null).Value;
		}

		public static void LogInfoFiltered(this ManualLogSource source, string section, object obj)
		{
			ConfigEntry<bool> val = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Debug", "ShowInfo" + section, true, (ConfigDescription)null);
			if (val.Value)
			{
				source.LogInfo((object)(section + "> " + obj));
			}
		}

		public static bool LogDebugFiltered(string section)
		{
			return ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Debug", "ShowDebug" + section, true, (ConfigDescription)null).Value;
		}

		public static void LogDebugFiltered(this ManualLogSource source, string section, object obj)
		{
			ConfigEntry<bool> val = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Debug", "ShowDebug" + section, true, (ConfigDescription)null);
			if (val.Value)
			{
				source.LogDebug(obj);
			}
		}
	}
	[Serializable]
	public struct Half : IComparable, IFormattable, IConvertible, IComparable<Half>, IEquatable<Half>
	{
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		internal ushort value;

		public static readonly Half Epsilon = ToHalf(1);

		public static readonly Half MaxValue = ToHalf(31743);

		public static readonly Half MinValue = ToHalf(64511);

		public static readonly Half NaN = ToHalf(65024);

		public static readonly Half NegativeInfinity = ToHalf(64512);

		public static readonly Half PositiveInfinity = ToHalf(31744);

		public Half(float value)
		{
			this = HalfHelper.SingleToHalf(value);
		}

		public Half(int value)
			: this((float)value)
		{
		}

		public Half(long value)
			: this((float)value)
		{
		}

		public Half(double value)
			: this((float)value)
		{
		}

		public Half(decimal value)
			: this((float)value)
		{
		}

		public Half(uint value)
			: this((float)value)
		{
		}

		public Half(ulong value)
			: this((float)value)
		{
		}

		public static Half Negate(Half half)
		{
			return -half;
		}

		public static Half Add(Half half1, Half half2)
		{
			return half1 + half2;
		}

		public static Half Subtract(Half half1, Half half2)
		{
			return half1 - half2;
		}

		public static Half Multiply(Half half1, Half half2)
		{
			return half1 * half2;
		}

		public static Half Divide(Half half1, Half half2)
		{
			return half1 / half2;
		}

		public static Half operator +(Half half)
		{
			return half;
		}

		public static Half operator -(Half half)
		{
			return HalfHelper.Negate(half);
		}

		public static Half operator ++(Half half)
		{
			return (Half)((float)half + 1f);
		}

		public static Half operator --(Half half)
		{
			return (Half)((float)half - 1f);
		}

		public static Half operator +(Half half1, Half half2)
		{
			return (Half)((float)half1 + (float)half2);
		}

		public static Half operator -(Half half1, Half half2)
		{
			return (Half)((float)half1 - (float)half2);
		}

		public static Half operator *(Half half1, Half half2)
		{
			return (Half)((float)half1 * (float)half2);
		}

		public static Half operator /(Half half1, Half half2)
		{
			return (Half)((float)half1 / (float)half2);
		}

		public static bool operator ==(Half half1, Half half2)
		{
			if (!IsNaN(half1))
			{
				return half1.value == half2.value;
			}
			return false;
		}

		public static bool operator !=(Half half1, Half half2)
		{
			return half1.value != half2.value;
		}

		public static bool operator <(Half half1, Half half2)
		{
			return (float)half1 < (float)half2;
		}

		public static bool operator >(Half half1, Half half2)
		{
			return (float)half1 > (float)half2;
		}

		public static bool operator <=(Half half1, Half half2)
		{
			if (!(half1 == half2))
			{
				return half1 < half2;
			}
			return true;
		}

		public static bool operator >=(Half half1, Half half2)
		{
			if (!(half1 == half2))
			{
				return half1 > half2;
			}
			return true;
		}

		public static implicit operator Half(byte value)
		{
			return new Half((float)(int)value);
		}

		public static implicit operator Half(short value)
		{
			return new Half((float)value);
		}

		public static implicit operator Half(char value)
		{
			return new Half((float)(int)value);
		}

		public static implicit operator Half(int value)
		{
			return new Half((float)value);
		}

		public static implicit operator Half(long value)
		{
			return new Half((float)value);
		}

		public static explicit operator Half(float value)
		{
			return new Half(value);
		}

		public static explicit operator Half(double value)
		{
			return new Half((float)value);
		}

		public static explicit operator Half(decimal value)
		{
			return new Half((float)value);
		}

		public static explicit operator byte(Half value)
		{
			return (byte)(float)value;
		}

		public static explicit operator char(Half value)
		{
			return (char)(float)value;
		}

		public static explicit operator short(Half value)
		{
			return (short)(float)value;
		}

		public static explicit operator int(Half value)
		{
			return (int)(float)value;
		}

		public static explicit operator long(Half value)
		{
			return (long)(float)value;
		}

		public static implicit operator float(Half value)
		{
			return HalfHelper.HalfToSingle(value);
		}

		public static implicit operator double(Half value)
		{
			return (float)value;
		}

		public static explicit operator decimal(Half value)
		{
			return (decimal)(float)value;
		}

		public static implicit operator Half(sbyte value)
		{
			return new Half((float)value);
		}

		public static implicit operator Half(ushort value)
		{
			return new Half((float)(int)value);
		}

		public static implicit operator Half(uint value)
		{
			return new Half((float)value);
		}

		public static implicit operator Half(ulong value)
		{
			return new Half((float)value);
		}

		public static explicit operator sbyte(Half value)
		{
			return (sbyte)(float)value;
		}

		public static explicit operator ushort(Half value)
		{
			return (ushort)(float)value;
		}

		public static explicit operator uint(Half value)
		{
			return (uint)(float)value;
		}

		public static explicit operator ulong(Half value)
		{
			return (ulong)(float)value;
		}

		public int CompareTo(Half other)
		{
			int result = 0;
			if (this < other)
			{
				result = -1;
			}
			else if (this > other)
			{
				result = 1;
			}
			else if (this != other)
			{
				if (!IsNaN(this))
				{
					result = 1;
				}
				else if (!IsNaN(other))
				{
					result = -1;
				}
			}
			return result;
		}

		public int CompareTo(object obj)
		{
			int num = 0;
			if (obj == null)
			{
				return 1;
			}
			if (obj is Half)
			{
				return CompareTo((Half)obj);
			}
			throw new ArgumentException("Object must be of type Half.");
		}

		public bool Equals(Half other)
		{
			if (!(other == this))
			{
				if (IsNaN(other))
				{
					return IsNaN(this);
				}
				return false;
			}
			return true;
		}

		public override bool Equals(object obj)
		{
			bool result = false;
			if (obj is Half half && (half == this || (IsNaN(half) && IsNaN(this))))
			{
				result = true;
			}
			return result;
		}

		public override int GetHashCode()
		{
			return value.GetHashCode();
		}

		public TypeCode GetTypeCode()
		{
			return (TypeCode)255;
		}

		public static byte[] GetBytes(Half value)
		{
			return BitConverter.GetBytes(value.value);
		}

		public static ushort GetBits(Half value)
		{
			return value.value;
		}

		public static Half ToHalf(byte[] value, int startIndex)
		{
			return ToHalf((ushort)BitConverter.ToInt16(value, startIndex));
		}

		public static Half ToHalf(ushort bits)
		{
			Half result = default(Half);
			result.value = bits;
			return result;
		}

		public static int Sign(Half value)
		{
			if (value < 0)
			{
				return -1;
			}
			if (value > 0)
			{
				return 1;
			}
			if (value != 0)
			{
				throw new ArithmeticException("Function does not accept floating point Not-a-Number values.");
			}
			return 0;
		}

		public static Half Abs(Half value)
		{
			return HalfHelper.Abs(value);
		}

		public static Half Max(Half value1, Half value2)
		{
			if (!(value1 < value2))
			{
				return value1;
			}
			return value2;
		}

		public static Half Min(Half value1, Half value2)
		{
			if (!(value1 < value2))
			{
				return value2;
			}
			return value1;
		}

		public static bool IsNaN(Half half)
		{
			return HalfHelper.IsNaN(half);
		}

		public static bool IsInfinity(Half half)
		{
			return HalfHelper.IsInfinity(half);
		}

		public static bool IsNegativeInfinity(Half half)
		{
			return HalfHelper.IsNegativeInfinity(half);
		}

		public static bool IsPositiveInfinity(Half half)
		{
			return HalfHelper.IsPositiveInfinity(half);
		}

		public static Half Parse(string value)
		{
			return (Half)float.Parse(value, CultureInfo.InvariantCulture);
		}

		public static Half Parse(string value, IFormatProvider provider)
		{
			return (Half)float.Parse(value, provider);
		}

		public static Half Parse(string value, NumberStyles style)
		{
			return (Half)float.Parse(value, style, CultureInfo.InvariantCulture);
		}

		public static Half Parse(string value, NumberStyles style, IFormatProvider provider)
		{
			return (Half)float.Parse(value, style, provider);
		}

		public static bool TryParse(string value, out Half result)
		{
			if (float.TryParse(value, out var result2))
			{
				result = (Half)result2;
				return true;
			}
			result = default(Half);
			return false;
		}

		public static bool TryParse(string value, NumberStyles style, IFormatProvider provider, out Half result)
		{
			bool result2 = false;
			if (float.TryParse(value, style, provider, out var result3))
			{
				result = (Half)result3;
				result2 = true;
			}
			else
			{
				result = default(Half);
			}
			return result2;
		}

		public override string ToString()
		{
			return ((float)this).ToString(CultureInfo.InvariantCulture);
		}

		public string ToString(IFormatProvider formatProvider)
		{
			return ((float)this).ToString(formatProvider);
		}

		public string ToString(string format)
		{
			return ((float)this).ToString(format, CultureInfo.InvariantCulture);
		}

		public string ToString(string format, IFormatProvider formatProvider)
		{
			return ((float)this).ToString(format, formatProvider);
		}

		float IConvertible.ToSingle(IFormatProvider provider)
		{
			return this;
		}

		TypeCode IConvertible.GetTypeCode()
		{
			return GetTypeCode();
		}

		bool IConvertible.ToBoolean(IFormatProvider provider)
		{
			return Convert.ToBoolean(this);
		}

		byte IConvertible.ToByte(IFormatProvider provider)
		{
			return Convert.ToByte(this);
		}

		char IConvertible.ToChar(IFormatProvider provider)
		{
			throw new InvalidCastException(string.Format(CultureInfo.CurrentCulture, "Invalid cast from '{0}' to '{1}'.", "Half", "Char"));
		}

		DateTime IConvertible.ToDateTime(IFormatProvider provider)
		{
			throw new InvalidCastException(string.Format(CultureInfo.CurrentCulture, "Invalid cast from '{0}' to '{1}'.", "Half", "DateTime"));
		}

		decimal IConvertible.ToDecimal(IFormatProvider provider)
		{
			return Convert.ToDecimal(this);
		}

		double IConvertible.ToDouble(IFormatProvider provider)
		{
			return Convert.ToDouble(this);
		}

		short IConvertible.ToInt16(IFormatProvider provider)
		{
			return Convert.ToInt16(this);
		}

		int IConvertible.ToInt32(IFormatProvider provider)
		{
			return Convert.ToInt32(this);
		}

		long IConvertible.ToInt64(IFormatProvider provider)
		{
			return Convert.ToInt64(this);
		}

		sbyte IConvertible.ToSByte(IFormatProvider provider)
		{
			return Convert.ToSByte(this);
		}

		string IConvertible.ToString(IFormatProvider provider)
		{
			return Convert.ToString(this, CultureInfo.InvariantCulture);
		}

		object IConvertible.ToType(Type conversionType, IFormatProvider provider)
		{
			return ((IConvertible)(float)this).ToType(conversionType, provider);
		}

		ushort IConvertible.ToUInt16(IFormatProvider provider)
		{
			return Convert.ToUInt16(this);
		}

		uint IConvertible.ToUInt32(IFormatProvider provider)
		{
			return Convert.ToUInt32(this);
		}

		ulong IConvertible.ToUInt64(IFormatProvider provider)
		{
			return Convert.ToUInt64(this);
		}
	}
	[ComVisible(false)]
	internal static class HalfHelper
	{
		private static readonly uint[] mantissaTable = GenerateMantissaTable();

		private static readonly uint[] exponentTable = GenerateExponentTable();

		private static readonly ushort[] offsetTable = GenerateOffsetTable();

		private static readonly ushort[] baseTable = GenerateBaseTable();

		private static readonly sbyte[] shiftTable = GenerateShiftTable();

		private static uint ConvertMantissa(int i)
		{
			uint num = (uint)(i << 13);
			uint num2 = 0u;
			while ((num & 0x800000) == 0)
			{
				num2 -= 8388608;
				num <<= 1;
			}
			num &= 0xFF7FFFFFu;
			num2 += 947912704;
			return num | num2;
		}

		private static uint[] GenerateMantissaTable()
		{
			uint[] array = new uint[2048];
			array[0] = 0u;
			for (int i = 1; i < 1024; i++)
			{
				array[i] = ConvertMantissa(i);
			}
			for (int j = 1024; j < 2048; j++)
			{
				array[j] = (uint)(939524096 + (j - 1024 << 13));
			}
			return array;
		}

		private static uint[] GenerateExponentTable()
		{
			uint[] array = new uint[64];
			array[0] = 0u;
			for (int i = 1; i < 31; i++)
			{
				array[i] = (uint)(i << 23);
			}
			array[31] = 1199570944u;
			array[32] = 2147483648u;
			for (int j = 33; j < 63; j++)
			{
				array[j] = (uint)(2147483648u + (j - 32 << 23));
			}
			array[63] = 3347054592u;
			return array;
		}

		private static ushort[] GenerateOffsetTable()
		{
			ushort[] array = new ushort[64];
			array[0] = 0;
			for (int i = 1; i < 32; i++)
			{
				array[i] = 1024;
			}
			array[32] = 0;
			for (int j = 33; j < 64; j++)
			{
				array[j] = 1024;
			}
			return array;
		}

		private static ushort[] GenerateBaseTable()
		{
			ushort[] array = new ushort[512];
			for (int i = 0; i < 256; i++)
			{
				sbyte b = (sbyte)(127 - i);
				if (b > 24)
				{
					array[i | 0] = 0;
					array[i | 0x100] = 32768;
				}
				else if (b > 14)
				{
					array[i | 0] = (ushort)(1024 >> 18 + b);
					array[i | 0x100] = (ushort)((uint)(1024 >> 18 + b) | 0x8000u);
				}
				else if (b >= -15)
				{
					array[i | 0] = (ushort)(15 - b << 10);
					array[i | 0x100] = (ushort)((uint)(15 - b << 10) | 0x8000u);
				}
				else if (b > sbyte.MinValue)
				{
					array[i | 0] = 31744;
					array[i | 0x100] = 64512;
				}
				else
				{
					array[i | 0] = 31744;
					array[i | 0x100] = 64512;
				}
			}
			return array;
		}

		private static sbyte[] GenerateShiftTable()
		{
			sbyte[] array = new sbyte[512];
			for (int i = 0; i < 256; i++)
			{
				sbyte b = (sbyte)(127 - i);
				if (b > 24)
				{
					array[i | 0] = 24;
					array[i | 0x100] = 24;
				}
				else if (b > 14)
				{
					array[i | 0] = (sbyte)(b - 1);
					array[i | 0x100] = (sbyte)(b - 1);
				}
				else if (b >= -15)
				{
					array[i | 0] = 13;
					array[i | 0x100] = 13;
				}
				else if (b > sbyte.MinValue)
				{
					array[i | 0] = 24;
					array[i | 0x100] = 24;
				}
				else
				{
					array[i | 0] = 13;
					array[i | 0x100] = 13;
				}
			}
			return array;
		}

		public unsafe static float HalfToSingle(Half half)
		{
			uint num = mantissaTable[offsetTable[half.value >> 10] + (half.value & 0x3FF)] + exponentTable[half.value >> 10];
			return *(float*)(&num);
		}

		public unsafe static Half SingleToHalf(float single)
		{
			uint num = *(uint*)(&single);
			ushort bits = (ushort)(baseTable[(num >> 23) & 0x1FF] + ((num & 0x7FFFFF) >> (int)shiftTable[num >> 23]));
			return Half.ToHalf(bits);
		}

		public static Half Negate(Half half)
		{
			return Half.ToHalf((ushort)(half.value ^ 0x8000u));
		}

		public static Half Abs(Half half)
		{
			return Half.ToHalf((ushort)(half.value & 0x7FFFu));
		}

		public static bool IsNaN(Half half)
		{
			return (half.value & 0x7FFF) > 31744;
		}

		public static bool IsInfinity(Half half)
		{
			return (half.value & 0x7FFF) == 31744;
		}

		public static bool IsPositiveInfinity(Half half)
		{
			return half.value == 31744;
		}

		public static bool IsNegativeInfinity(Half half)
		{
			return half.value == 64512;
		}
	}
	public static class Helpers
	{
		public const float Epsilon = 1.8E-43f;

		public const float EpsilonSqr = 9E-44f;

		private const float SpawnRadiusIncrement = 5f;

		private const int SpawnAngleIncrement = 60;

		private const int SpawnAngleEvenOffset = 30;

		public static Vector3 GetSpawnLocation(Vector3 position, int playerId)
		{
			//IL_0004: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			if (playerId == -1)
			{
				return position;
			}
			float num = 5f;
			int num2 = 0;
			bool flag = false;
			while (playerId > 0)
			{
				num2 += 60;
				if (num2 >= 360)
				{
					num2 = 0;
					num += 5f;
					flag = !flag;
				}
				playerId--;
			}
			Vector3 val = default(Vector3);
			val.x = num;
			Vector3 val2 = val;
			val2 = Quaternion.AngleAxis((float)(num2 + (flag ? 30 : 0)), Vector3.up) * val2;
			return position + val2;
		}

		public static string GetPath(Transform tr)
		{
			Transform parent = tr.parent;
			if (!((Object)(object)parent == (Object)null))
			{
				return GetPath(parent) + "/" + ((Object)tr).name;
			}
			return ((Object)tr).name;
		}

		public static bool UnityNullCheck(object a)
		{
			if (a != null)
			{
				Object val = (Object)((a is Object) ? a : null);
				if (val != null)
				{
					return val != (Object)null;
				}
				return true;
			}
			return false;
		}

		public static PlayerInteraction FindClosest(PlayerInteraction[] players, Vector3 pos)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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)
			float num = float.MaxValue;
			PlayerInteraction result = null;
			foreach (PlayerInteraction val in players)
			{
				Vector3 val2 = ((Component)val).transform.position - pos;
				float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
				if (sqrMagnitude < num)
				{
					num = sqrMagnitude;
					result = val;
				}
			}
			return result;
		}

		public static T InstantiateDisabled<T>(T original, Transform parent = null, bool worldPositionStays = false) where T : Object
		{
			if (!GetActiveState(original))
			{
				return Object.Instantiate<T>(original, parent, worldPositionStays);
			}
			(GameObject coreObject, Transform coreObjectTransform) tuple = CreateDisabledCoreObject(parent);
			GameObject item = tuple.coreObject;
			Transform item2 = tuple.coreObjectTransform;
			T val = Object.Instantiate<T>(original, item2, worldPositionStays);
			SetActiveState(val, state: false);
			SetParent(val, parent, worldPositionStays);
			Object.Destroy((Object)(object)item);
			return val;
		}

		public static T InstantiateDisabled<T>(T original, Vector3 position, Quaternion rotation, Transform parent = null) where T : Object
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			if (!GetActiveState(original))
			{
				return Object.Instantiate<T>(original, position, rotation, parent);
			}
			(GameObject coreObject, Transform coreObjectTransform) tuple = CreateDisabledCoreObject(parent);
			GameObject item = tuple.coreObject;
			Transform item2 = tuple.coreObjectTransform;
			T val = Object.Instantiate<T>(original, position, rotation, item2);
			SetActiveState(val, state: false);
			SetParent(val, parent, worldPositionStays: false);
			Object.Destroy((Object)(object)item);
			return val;
		}

		private static (GameObject coreObject, Transform coreObjectTransform) CreateDisabledCoreObject(Transform parent = null)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			GameObject val = new GameObject(string.Empty);
			val.SetActive(false);
			Transform transform = val.transform;
			transform.SetParent(parent);
			return (val, transform);
		}

		private static bool GetActiveState<T>(T @object) where T : Object
		{
			object obj = @object;
			GameObject val = (GameObject)((obj is GameObject) ? obj : null);
			if (val != null)
			{
				return val.activeSelf;
			}
			object obj2 = @object;
			Component val2 = (Component)((obj2 is Component) ? obj2 : null);
			if (val2 != null)
			{
				return val2.gameObject.activeSelf;
			}
			return false;
		}

		private static void SetActiveState<T>(T @object, bool state) where T : Object
		{
			object obj = @object;
			GameObject val = (GameObject)((obj is GameObject) ? obj : null);
			if (val == null)
			{
				object obj2 = @object;
				Component val2 = (Component)((obj2 is Component) ? obj2 : null);
				if (val2 != null)
				{
					val2.gameObject.SetActive(state);
				}
			}
			else
			{
				val.SetActive(state);
			}
		}

		private static void SetParent<T>(T @object, Transform parent, bool worldPositionStays) where T : Object
		{
			object obj = @object;
			GameObject val = (GameObject)((obj is GameObject) ? obj : null);
			if (val == null)
			{
				object obj2 = @object;
				Component val2 = (Component)((obj2 is Component) ? obj2 : null);
				if (val2 != null)
				{
					val2.transform.SetParent(parent, worldPositionStays);
				}
			}
			else
			{
				val.transform.SetParent(parent, worldPositionStays);
			}
		}
	}
}
namespace ThronefallMP.UI
{
	public abstract class BaseUI : MonoBehaviour
	{
		public Canvas Canvas { get; set; }

		public GameObject PanelRoot { get; set; }

		public bool Enabled
		{
			get
			{
				return PanelRoot.activeSelf;
			}
			set
			{
				PanelRoot.SetActive(value);
			}
		}

		public abstract string Name { get; }

		public abstract void ConstructPanelContent();

		public static T Create<T>(GameObject canvas, GameObject container) where T : BaseUI
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Temp", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(container.transform, false);
			T val2 = val.AddComponent<T>();
			val2.Canvas = canvas.GetComponent<Canvas>();
			val2.PanelRoot = val;
			((Object)val2.PanelRoot).name = val2.Name;
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0f, 0f);
			component.anchorMax = new Vector2(1f, 1f);
			component.offsetMin = new Vector2(0f, 0f);
			component.offsetMax = new Vector2(0f, 0f);
			val2.ConstructPanelContent();
			val2.Enabled = false;
			return val2;
		}
	}
	public static class UIHelper
	{
		public static GameObject CreateBox(GameObject root, string name, Color color)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = CreateUIObject(name, root);
			bool? childControlWidth = true;
			bool? childControlHeight = true;
			UIHelper.SetLayoutGroup<HorizontalLayoutGroup>(val, (bool?)null, (bool?)null, childControlWidth, childControlHeight, (int?)null, (int?)null, (int?)null, (int?)null, (int?)null, (TextAnchor?)null);
			Image val2 = val.AddComponent<Image>();
			val2.type = (Type)1;
			((Graphic)val2).color = color;
			return val;
		}

		public static TextMeshProUGUI CreateText(GameObject root, string name, string text, TMP_FontAsset font = null)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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)
			GameObject val = CreateUIObject(name, root);
			TextMeshProUGUI val2 = val.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val2).text = text;
			((Graphic)val2).color = UIManager.TextColor;
			((TMP_Text)val2).font = (Object.op_Implicit((Object)(object)font) ? font : UIManager.DefaultFont);
			((TMP_Text)val2).fontSize = 24f;
			((TMP_Text)val2).alignment = (TextAlignmentOptions)514;
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.sizeDelta = Vector2.zero;
			return val2;
		}

		public static ButtonControl CreateButton(GameObject root, string name, string text)
		{
			//IL_0012: 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_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Expected O, but got Unknown
			GameObject val = CreateUIObject(name, root, new Vector2(25f, 25f));
			GameObject val2 = CreateUIObject("text", val);
			Button button = val.AddComponent<Button>();
			Navigation navigation = ((Selectable)button).navigation;
			((Navigation)(ref navigation)).mode = (Mode)4;
			Navigation navigation2 = navigation;
			((Selectable)button).navigation = navigation2;
			TextMeshProUGUI val3 = val2.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val3).text = text;
			((TMP_Text)val3).font = UIManager.DefaultFont;
			((TMP_Text)val3).alignment = (TextAlignmentOptions)514;
			RectTransform component = val2.GetComponent<RectTransform>();
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.sizeDelta = Vector2.zero;
			((UnityEvent)button.onClick).AddListener((UnityAction)delegate
			{
				((Selectable)button).OnDeselect((BaseEventData)null);
			});
			SetLayoutElement(val, 20, 20);
			val.AddComponent<EventTrigger>();
			return val.AddComponent<ButtonControl>();
		}

		public static GameObject CreateCheck(GameObject root, string name, bool startsOn = false)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_007f: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: 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_00fe: 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_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: 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)
			GameObject val = CreateUIObject(name, root, new Vector2(25f, 25f));
			Toggle val2 = val.AddComponent<Toggle>();
			((Graphic)val.AddComponent<Image>()).color = Color.clear;
			val2.isOn = startsOn;
			UIHelper.SetLayoutGroup<HorizontalLayoutGroup>(val, (bool?)false, (bool?)false, (bool?)true, (bool?)true, (int?)10, (int?)0, (int?)0, (int?)0, (int?)0, (TextAnchor?)(TextAnchor)3);
			Navigation navigation = ((Selectable)val2).navigation;
			((Navigation)(ref navigation)).mode = (Mode)4;
			Navigation navigation2 = navigation;
			((Selectable)val2).navigation = navigation2;
			GameObject val3 = CreateUIObject("checkmark", val);
			int? flexibleWidth = 0;
			int? flexibleHeight = 0;
			SetLayoutElement(val3, null, null, flexibleWidth, flexibleHeight);
			RectTransform component = CreateUIObject("background", val3).GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0.1f, 0.1f);
			component.anchorMax = new Vector2(0.9f, 0.9f);
			RectTransform component2 = CreateUIObject("check", val3).GetComponent<RectTransform>();
			component2.anchorMin = new Vector2(0.3f, 0.3f);
			component2.anchorMax = new Vector2(0.7f, 0.7f);
			Image val4 = val3.gameObject.AddComponent<Image>();
			val4.type = (Type)1;
			val4 = ((Component)component).gameObject.AddComponent<Image>();
			val4.type = (Type)1;
			val4 = ((Component)component2).gameObject.AddComponent<Image>();
			val4.type = (Type)1;
			return val;
		}

		public static ToggleControl CreateLeftToggle(GameObject root, string name, string text, bool startsOn = false)
		{
			//IL_0011: 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)
			GameObject val = CreateCheck(root, name, startsOn);
			GameObject val2 = CreateUIObject("text", val);
			TextMeshProUGUI val3 = val2.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val3).text = text;
			((TMP_Text)val3).font = UIManager.DefaultFont;
			((TMP_Text)val3).alignment = (TextAlignmentOptions)513;
			ContentSizeFitter val4 = val2.AddComponent<ContentSizeFitter>();
			val4.horizontalFit = (FitMode)2;
			val4.verticalFit = (FitMode)2;
			SetLayoutElement(val, 20, 20);
			val.AddComponent<EventTrigger>();
			return val.AddComponent<ToggleControl>();
		}

		public static ToggleControl CreateRightToggle(GameObject root, string name, string text, bool startsOn = false)
		{
			//IL_0011: 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)
			GameObject val = CreateCheck(root, name, startsOn);
			GameObject val2 = CreateUIObject("text", val);
			TextMeshProUGUI val3 = val2.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val3).text = text;
			((TMP_Text)val3).font = UIManager.DefaultFont;
			((TMP_Text)val3).alignment = (TextAlignmentOptions)513;
			ContentSizeFitter val4 = val2.AddComponent<ContentSizeFitter>();
			val4.horizontalFit = (FitMode)2;
			val4.verticalFit = (FitMode)2;
			val2.transform.SetSiblingIndex(0);
			SetLayoutElement(val, 20, 20);
			val.AddComponent<EventTrigger>();
			return val.AddComponent<ToggleControl>();
		}

		public static ToggleControl CreateToggle(GameObject root, string name, bool startsOn = false)
		{
			GameObject val = CreateCheck(root, name, startsOn);
			SetLayoutElement(val, 20, 20);
			val.AddComponent<EventTrigger>();
			return val.AddComponent<ToggleControl>();
		}

		public static TMP_InputField CreateInputField(GameObject panel, string name, string label, string value, int? labelWidth = null, int limit = 32, TMP_FontAsset font = null)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Expected O, but got Unknown
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_034c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_0378: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = CreateUIObject(name + "Group", panel);
			UIHelper.SetLayoutGroup<HorizontalLayoutGroup>(val, (bool?)false, (bool?)false, (bool?)true, (bool?)false, (int?)20, (int?)5, (int?)5, (int?)5, (int?)5, (TextAnchor?)(TextAnchor)3);
			int? flexibleWidth = 1;
			SetLayoutElement(val, null, null, flexibleWidth);
			if (label != null)
			{
				GameObject val2 = CreateBox(val, name + "_label_bg", Color.clear);
				bool? childControlWidth = true;
				TextAnchor? childAlignment = (TextAnchor)3;
				UIHelper.SetLayoutGroup<HorizontalLayoutGroup>(val2, (bool?)null, (bool?)null, childControlWidth, (bool?)null, (int?)null, (int?)null, (int?)null, (int?)null, (int?)null, childAlignment);
				GameObject gameObject = val2.gameObject;
				flexibleWidth = 0;
				SetLayoutElement(gameObject, labelWidth, null, flexibleWidth);
				val2.AddComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
				TextMeshProUGUI val3 = CreateText(val2, name + "_label", label + ": ", font);
				((TMP_Text)val3).alignment = (TextAlignmentOptions)513;
			}
			GameObject val4 = CreateBox(val, name + "_bg", new Color(0.2f, 0.2f, 0.2f));
			flexibleWidth = 1;
			SetLayoutElement(val4, null, null, flexibleWidth);
			val4.AddComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
			TMP_InputField val5 = val4.AddComponent<TMP_InputField>();
			val5.textViewport = ((Component)((Component)val5).transform.parent).GetComponent<RectTransform>();
			((Selectable)val5).targetGraphic = (Graphic)(object)val4.GetComponent<Image>();
			GameObject val6 = new GameObject("area", new Type[1] { typeof(RectTransform) });
			val5.textViewport = val6.GetComponent<RectTransform>();
			val6.transform.SetParent(val4.transform);
			((Transform)val5.textViewport).localPosition = Vector3.zero;
			val5.textViewport.anchorMin = new Vector2(0f, 0f);
			val5.textViewport.anchorMax = new Vector2(1f, 1f);
			val6.AddComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
			TextMeshProUGUI val7 = CreateText(val6, name ?? "", value ?? "", font);
			((Graphic)val7).color = UIManager.TextColor;
			((TMP_Text)val7).fontSize = 20f;
			val5.textComponent = (TMP_Text)(object)val7;
			val5.text = ((TMP_Text)val7).text;
			val5.characterLimit = limit;
			RectTransform component = ((Component)val7).GetComponent<RectTransform>();
			((Transform)component).localPosition = Vector3.zero;
			component.anchorMin = new Vector2(0f, 0f);
			component.anchorMax = new Vector2(1f, 1f);
			val5.onFocusSelectAll = false;
			return val5;
		}

		public static void AddEvent(GameObject button, EventTriggerType type, UnityAction<BaseEventData> action)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			EventTrigger component = button.GetComponent<EventTrigger>();
			TriggerEvent val = new TriggerEvent();
			((UnityEvent<BaseEventData>)(object)val).AddListener(action);
			component.triggers.Add(new Entry
			{
				eventID = type,
				callback = val
			});
		}

		public static T SetLayoutGroup<T>(GameObject gameObject, bool? forceWidth = null, bool? forceHeight = null, bool? childControlWidth = null, bool? childControlHeight = null, int? spacing = null, int? padTop = null, int? padBottom = null, int? padLeft = null, int? padRight = null, TextAnchor? childAlignment = null) where T : HorizontalOrVerticalLayoutGroup
		{
			T val = gameObject.GetComponent<T>();
			if (!Object.op_Implicit((Object)(object)val))
			{
				val = gameObject.AddComponent<T>();
			}
			return SetLayoutGroup(val, forceWidth, forceHeight, childControlWidth, childControlHeight, spacing, padTop, padBottom, padLeft, padRight, childAlignment);
		}

		public static T SetLayoutGroup<T>(T group, bool? forceWidth = null, bool? forceHeight = null, bool? childControlWidth = null, bool? childControlHeight = null, int? spacing = null, int? padTop = null, int? padBottom = null, int? padLeft = null, int? padRight = null, TextAnchor? childAlignment = null) where T : HorizontalOrVerticalLayoutGroup
		{
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			if (forceWidth.HasValue)
			{
				((HorizontalOrVerticalLayoutGroup)group).childForceExpandWidth = forceWidth.Value;
			}
			if (forceHeight.HasValue)
			{
				((HorizontalOrVerticalLayoutGroup)group).childForceExpandHeight = forceHeight.Value;
			}
			if (childControlWidth.HasValue)
			{
				((HorizontalOrVerticalLayoutGroup)(object)group).SetChildControlWidth(childControlWidth.Value);
			}
			if (childControlHeight.HasValue)
			{
				((HorizontalOrVerticalLayoutGroup)(object)group).SetChildControlHeight(childControlHeight.Value);
			}
			if (spacing.HasValue)
			{
				((HorizontalOrVerticalLayoutGroup)group).spacing = spacing.Value;
			}
			if (padTop.HasValue)
			{
				((LayoutGroup)(object)group).padding.top = padTop.Value;
			}
			if (padBottom.HasValue)
			{
				((LayoutGroup)(object)group).padding.bottom = padBottom.Value;
			}
			if (padLeft.HasValue)
			{
				((LayoutGroup)(object)group).padding.left = padLeft.Value;
			}
			if (padRight.HasValue)
			{
				((LayoutGroup)(object)group).padding.right = padRight.Value;
			}
			if (childAlignment.HasValue)
			{
				((LayoutGroup)(object)group).childAlignment = childAlignment.Value;
			}
			return group;
		}

		public static GameObject CreateUIObject(string name, GameObject parent, Vector2 sizeDelta = default(Vector2))
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name)
			{
				layer = 5,
				hideFlags = (HideFlags)61
			};
			if (Object.op_Implicit((Object)(object)parent))
			{
				val.transform.SetParent(parent.transform, false);
			}
			val.AddComponent<RectTransform>().sizeDelta = sizeDelta;
			return val;
		}

		public static LayoutElement SetLayoutElement(GameObject gameObject, int? minWidth = null, int? minHeight = null, int? flexibleWidth = null, int? flexibleHeight = null, int? preferredWidth = null, int? preferredHeight = null, bool? ignoreLayout = null)
		{
			LayoutElement val = gameObject.GetComponent<LayoutElement>();
			if (!Object.op_Implicit((Object)(object)val))
			{
				val = gameObject.AddComponent<LayoutElement>();
			}
			if (minWidth.HasValue)
			{
				val.minWidth = minWidth.Value;
			}
			if (minHeight.HasValue)
			{
				val.minHeight = minHeight.Value;
			}
			if (flexibleWidth.HasValue)
			{
				val.flexibleWidth = flexibleWidth.Value;
			}
			if (flexibleHeight.HasValue)
			{
				val.flexibleHeight = flexibleHeight.Value;
			}
			if (preferredWidth.HasValue)
			{
				val.preferredWidth = preferredWidth.Value;
			}
			if (preferredHeight.HasValue)
			{
				val.preferredHeight = preferredHeight.Value;
			}
			if (ignoreLayout.HasValue)
			{
				val.ignoreLayout = ignoreLayout.Value;
			}
			return val;
		}

		public static void SetChildControlHeight(this HorizontalOrVerticalLayoutGroup group, bool value)
		{
			group.childControlHeight = value;
		}

		public static void SetChildControlWidth(this HorizontalOrVerticalLayoutGroup group, bool value)
		{
			group.childControlWidth = value;
		}
	}
	public static class UIManager
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__34_0;

			internal void <Initialize>b__34_0()
			{
				LobbyListPanel.Open();
				TitleScreen.SetActive(false);
			}
		}

		public static bool ExitHandled = false;

		public static readonly Color DarkBackgroundColor = new Color(0.06f, 0.06f, 0.06f, 1f);

		public static readonly Color BackgroundColor = new Color(0.11f, 0.11f, 0.11f, 1f);

		public static readonly Color TransparentBackgroundColor = new Color(0f, 0f, 0f, 0.3f);

		public static readonly Color SelectedTransparentBackgroundColor = new Color(0.2f, 0.2f, 0.2f, 0.3f);

		public static readonly Color TextColor = new Color(0.78f, 0.65f, 0.46f, 1f);

		public static readonly Color ButtonTextColor = new Color(0.97f, 0.88f, 0.75f, 1f);

		public static readonly Color NoninteractiveButtonTextColor = new Color(0.3f, 0.3f, 0.4f, 1f);

		public static readonly Color ButtonHoverTextColor = new Color(0f, 0.41f, 0.11f);

		public static readonly Color ExitButtonColor = new Color(0.176f, 0.165f, 0.149f);

		public static TMP_FontAsset DefaultFont;

		private static bool _initialized;

		private static GameObject _canvas;

		private static GameObject _container;

		public static GameObject TitleScreen { get; private set; }

		public static LobbyListPanel LobbyListPanel { get; private set; }

		public static HostPanel HostPanel { get; private set; }

		public static ChatPanel ChatPanel { get; private set; }

		public static GameStatusPanel GameStatusPanel { get; private set; }

		public static void Initialize()
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Expected O, but got Unknown
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			if (_initialized)
			{
				return;
			}
			_canvas = GameObject.Find("UI Canvas");
			if ((Object)(object)_canvas.GetComponent<StandaloneInputModule>() == (Object)null)
			{
				_canvas.AddComponent<StandaloneInputModule>();
			}
			_container = new GameObject("Mod UI", new Type[1] { typeof(RectTransform) });
			RectTransform component = _container.GetComponent<RectTransform>();
			((Transform)component).SetParent(_canvas.transform, false);
			component.anchorMin = new Vector2(0f, 0f);
			component.anchorMax = new Vector2(1f, 1f);
			component.offsetMin = new Vector2(0f, 0f);
			component.offsetMax = new Vector2(0f, 0f);
			TitleScreen = GameObject.Find("UI Canvas/Title Frame").gameObject;
			ThronefallUIElement component2 = ((Component)TitleScreen.transform.Find("Menu Items/Play")).GetComponent<ThronefallUIElement>();
			ThronefallUIElement component3 = ((Component)TitleScreen.transform.Find("Menu Items/Settings")).GetComponent<ThronefallUIElement>();
			DefaultFont = ((TMP_Text)((Component)component3).GetComponent<TextMeshProUGUI>()).font;
			LobbyListPanel = BaseUI.Create<LobbyListPanel>(_canvas, _container);
			HostPanel = BaseUI.Create<HostPanel>(_canvas, _container);
			ChatPanel = BaseUI.Create<ChatPanel>(_canvas, _container);
			GameStatusPanel = BaseUI.Create<GameStatusPanel>(_canvas, _container);
			ChatPanel.Enabled = true;
			GameStatusPanel.Enabled = true;
			GameObject val = Helpers.InstantiateDisabled<GameObject>(((Component)component3).gameObject, ((Component)component3).transform.parent, worldPositionStays: false);
			((Object)val).name = "Multiplayer";
			val.transform.SetSiblingIndex(1);
			Object.DestroyImmediate((Object)(object)val.GetComponent<Localize>());
			TextMeshProUGUI component4 = val.GetComponent<TextMeshProUGUI>();
			((TMP_Text)component4).text = "Multiplayer";
			TFUITextButton component5 = val.GetComponent<TFUITextButton>();
			((UnityEventBase)((ThronefallUIElement)component5).onSelectionStateChange).m_PersistentCalls.m_Calls.Clear();
			((UnityEventBase)((ThronefallUIElement)component5).onApply).m_PersistentCalls.m_Calls.Clear();
			UnityEvent onApply = ((ThronefallUIElement)component5).onApply;
			object obj = <>c.<>9__34_0;
			if (obj == null)
			{
				UnityAction val2 = delegate
				{
					LobbyListPanel.Open();
					TitleScreen.SetActive(false);
				};
				<>c.<>9__34_0 = val2;
				obj = (object)val2;
			}
			onApply.AddListener((UnityAction)obj);
			((ThronefallUIElement)component5).rightNav = component3;
			if (SteamManager.Initialized)
			{
				component2.rightNav = (ThronefallUIElement)(object)component5;
				component3.leftNav = (ThronefallUIElement)(object)component5;
			}
			else
			{
				((ThronefallUIElement)component5).ignoreMouse = true;
				((ThronefallUIElement)component5).cannotBeSelected = true;
				((Graphic)component4).color = NoninteractiveButtonTextColor;
			}
			val.SetActive(true);
			_initialized = true;
		}

		public static void CloseAllPanels()
		{
			LobbyListPanel.Enabled = false;
			HostPanel.Enabled = false;
		}

		public static WeaponDialog CreateWeaponDialog()
		{
			WeaponDialog weaponDialog = BaseUI.Create<WeaponDialog>(_canvas, _container);
			weaponDialog.Enabled = true;
			return weaponDialog;
		}

		public static PasswordDialog CreatePasswordDialog(PasswordDialog.Confirm confirm, PasswordDialog.Cancel cancel)
		{
			PasswordDialog passwordDialog = BaseUI.Create<PasswordDialog>(_canvas, _container);
			passwordDialog.OnConfirm = (PasswordDialog.Confirm)Delegate.Combine(passwordDialog.OnConfirm, confirm);
			passwordDialog.OnCancel = (PasswordDialog.Cancel)Delegate.Combine(passwordDialog.OnCancel, cancel);
			passwordDialog.Enabled = true;
			return passwordDialog;
		}

		public static MessageDialog CreateMessageDialog(string title, string message, string button = null, Color? color = null, MessageDialog.ClickDelegate onClick = null)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			MessageDialog messageDialog = BaseUI.Create<MessageDialog>(_canvas, _container);
			messageDialog.Title = title;
			messageDialog.Message = message;
			if (color.HasValue)
			{
				messageDialog.Color = color.Value;
			}
			if (button != null)
			{
				messageDialog.ButtonText = button;
			}
			if (onClick != null)
			{
				messageDialog.OnClick = (MessageDialog.ClickDelegate)Delegate.Combine(messageDialog.OnClick, onClick);
			}
			messageDialog.Enabled = true;
			return messageDialog;
		}
	}
}
namespace ThronefallMP.UI.Panels
{
	public class ChatPanel : BaseUI
	{
		private class Message
		{
			public GameObject Line;

			public TMP_Text Text;

			public float Time;

			public bool Faded;
		}

		private const int MaxLines = 8;

		private const float MessageTimeout = 3f;

		private const float MessageFadeTime = 0.5f;

		private static readonly Color BackgroundColor = new Color(0.07f, 0.07f, 0.07f, 1f);

		private static readonly Color InputColor = new Color(0.9f, 0.9f, 0.9f, 1f);

		private static readonly Color ChatColor = new Color(0.9f, 0.9f, 0.9f, 1f);

		private static readonly Color32 ChatBorderColor = new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue);

		private GameObject _container;

		private GameObject _chatBoxContainer;

		private TMP_InputField _chatBox;

		private readonly List<Message> _lines = new List<Message>();

		private TMP_FontAsset _chatBoxFont;

		private TMP_FontAsset _chatFont;

		private bool _justClosed;

		public override string Name => "Chat Panel";

		private Font CreateFont()
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			Dictionary<string, int> dictionary = new Dictionary<string, int>
			{
				{ "arial", 0 },
				{ "times", 1 },
				{ "verdana", 2 },
				{ "cour", 3 }
			};
			int num = int.MaxValue;
			string text = Font.GetPathsToOSFonts()[0];
			string[] pathsToOSFonts = Font.GetPathsToOSFonts();
			foreach (string text2 in pathsToOSFonts)
			{
				string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text2);
				if (dictionary.TryGetValue(fileNameWithoutExtension, out var value) && value < num)
				{
					text = text2;
					num = value;
					if (num == 0)
					{
						break;
					}
				}
			}
			Plugin.Log.LogInfo((object)("Loaded font '" + text + "' for chat messages."));
			return new Font(text);
		}

		public override void ConstructPanelContent()
		{
			//IL_008b: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Unknown result type (might be due to invalid IL or missing references)
			Font val = CreateFont();
			_chatBoxFont = TMP_FontAsset.CreateFontAsset(val, 90, 9, (GlyphRenderMode)4165, 1024, 1024, (AtlasPopulationMode)1, true);
			_chatFont = TMP_FontAsset.CreateFontAsset(val, 90, 9, (GlyphRenderMode)4165, 1024, 1024, (AtlasPopulationMode)1, true);
			ShaderUtilities.GetShaderPropertyIDs();
			((TMP_Asset)_chatFont).material.EnableKeyword(ShaderUtilities.Keyword_Outline);
			((TMP_Asset)_chatFont).material.SetFloat(ShaderUtilities.ID_FaceDilate, 0.3f);
			_container = UIHelper.CreateUIObject("container", base.PanelRoot);
			RectTransform component = _container.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0f, 0.5f);
			component.anchorMax = new Vector2(0.35f, 0.8f);
			UIHelper.SetLayoutGroup<VerticalLayoutGroup>(_container, (bool?)true, (bool?)false, (bool?)true, (bool?)true, (int?)0, (int?)10, (int?)10, (int?)10, (int?)10, (TextAnchor?)(TextAnchor)6);
			GameObject val2 = UIHelper.CreateUIObject("chat_box_container", base.PanelRoot);
			RectTransform component2 = val2.GetComponent<RectTransform>();
			component2.anchorMin = new Vector2(0.4f, 0.4f);
			component2.anchorMax = new Vector2(0.6f, 0.5f);
			UIHelper.SetLayoutGroup<HorizontalLayoutGroup>(val2, (bool?)true, (bool?)false, (bool?)true, (bool?)true, (int?)0, (int?)0, (int?)0, (int?)0, (int?)0, (TextAnchor?)(TextAnchor)4);
			TMP_FontAsset chatBoxFont = _chatBoxFont;
			_chatBox = UIHelper.CreateInputField(val2, "chat_box", null, "", null, 32, chatBoxFont);
			((Component)_chatBox).gameObject.AddComponent<Mask>();
			((Graphic)_chatBox.textComponent).color = InputColor;
			_chatBox.textComponent.alignment = (TextAlignmentOptions)513;
			_chatBox.characterLimit = 0;
			_chatBox.lineLimit = 1;
			((UnityEvent<string>)(object)_chatBox.onSubmit).AddListener((UnityAction<string>)OnSendMessage);
			_chatBoxContainer = ((Component)((Component)_chatBox).transform.parent).gameObject;
			Image val3 = _chatBoxContainer.AddComponent<Image>();
			val3.type = (Type)1;
			((Graphic)val3).color = BackgroundColor;
			UIHelper.SetLayoutGroup<HorizontalLayoutGroup>(_chatBoxContainer, (bool?)true, (bool?)false, (bool?)true, (bool?)false, (int?)0, (int?)3, (int?)3, (int?)3, (int?)3, (TextAnchor?)(TextAnchor)4);
			RectTransform component3 = _chatBoxContainer.GetComponent<RectTransform>();
			LayoutRebuilder.ForceRebuildLayoutImmediate(component3);
			_chatBoxContainer.SetActive(false);
			Plugin.Instance.Network.AddChatMessageHandler(0, OnMessageReceived);
		}

		public void Update()
		{
			if (!Plugin.Instance.Network.Online)
			{
				foreach (Message line in _lines)
				{
					Object.Destroy((Object)(object)line.Line);
				}
				_lines.Clear();
				return;
			}
			foreach (Message line2 in _lines)
			{
				if (line2.Faded && _chatBoxContainer.activeSelf)
				{
					line2.Time = Time.unscaledTime;
					((Graphic)line2.Text).CrossFadeAlpha(1f, 0f, true);
					line2.Faded = false;
				}
				else if (!line2.Faded && line2.Time + 3f < Time.unscaledTime)
				{
					((Graphic)line2.Text).CrossFadeAlpha(0f, 0.5f, true);
					line2.Faded = true;
				}
			}
			if (!_chatBoxContainer.activeSelf)
			{
				if (_justClosed)
				{
					_justClosed = Input.GetKeyDown((KeyCode)13);
				}
				else if (Input.GetKeyDown((KeyCode)13))
				{
					_chatBoxContainer.SetActive(true);
					LocalGamestate.Instance.SetPlayerFreezeState(true);
				}
			}
			else if (!_chatBox.isFocused)
			{
				((Selectable)_chatBox).Select();
				_chatBox.ActivateInputField();
			}
		}

		private void OnSendMessage(string text)
		{
			if (!string.IsNullOrEmpty(text))
			{
				Plugin.Instance.Network.SendChatMessage(text);
			}
			_chatBox.text = "";
			_chatBoxContainer.SetActive(false);
			LocalGamestate.Instance.SetPlayerFreezeState(false);
			_justClosed = true;
		}

		private bool OnMessageReceived(string user, string message)
		{
			//IL_0063: 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)
			while (_lines.Count >= 8)
			{
				Message message2 = _lines[0];
				_lines.RemoveAt(0);
				Object.Destroy((Object)(object)message2.Line);
			}
			TextMeshProUGUI val = UIHelper.CreateText(_container, "message", user + ": " + message, _chatFont);
			((TMP_Text)val).alignment = (TextAlignmentOptions)513;
			((Graphic)val).color = ChatColor;
			((TMP_Text)val).fontSize = 20f;
			((TMP_Text)val).outlineColor = ChatBorderColor;
			((TMP_Text)val).outlineWidth = 0.3f;
			_lines.Add(new Message
			{
				Line = ((Component)val).gameObject,
				Text = (TMP_Text)(object)val,
				Time = Time.unscaledTime
			});
			return true;
		}
	}
	public class GameStatusPanel : BaseUI
	{
		private static readonly Color BackgroundColor = new Color(0.11f, 0.11f, 0.11f, 0.95f);

		private static readonly Color EntryColor = new Color(0.2f, 0.2f, 0.2f, 1f);

		private GameObject _playerList;

		public override string Name => "Game Status Panel";

		public override void ConstructPanelContent()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: 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_0162: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = UIHelper.CreateUIObject("container", base.PanelRoot);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0f, 0.5f);
			component.anchorMax = new Vector2(0.25f, 1f);
			UIHelper.SetLayoutGroup<VerticalLayoutGroup>(val, (bool?)true, (bool?)false, (bool?)true, (bool?)true, (int?)0, (int?)10, (int?)10, (int?)10, (int?)10, (TextAnchor?)(TextAnchor)0);
			_playerList = UIHelper.CreateUIObject("background", val);
			_playerList.AddComponent<Mask>();
			Image val2 = _playerList.AddComponent<Image>();
			val2.type = (Type)1;
			((Graphic)val2).color = BackgroundColor;
			RectTransform component2 = _playerList.GetComponent<RectTransform>();
			component2.anchorMin = Vector2.zero;
			component2.anchorMax = Vector2.one;
			UIHelper.SetLayoutGroup<VerticalLayoutGroup>(_playerList, (bool?)true, (bool?)false, (bool?)true, (bool?)true, (int?)5, (int?)10, (int?)10, (int?)10, (int?)10, (TextAnchor?)(TextAnchor)0);
			GameObject val3 = UIHelper.CreateUIObject("player_header", _playerList);
			UIHelper.SetLayoutGroup<HorizontalLayoutGroup>(val3, (bool?)false, (bool?)false, (bool?)true, (bool?)true, (int?)0, (int?)0, (int?)0, (int?)15, (int?)15, (TextAnchor?)(TextAnchor)1);
			TextMeshProUGUI val4 = UIHelper.CreateText(val3, "name", "Name", UIManager.DefaultFont);
			((TMP_Text)val4).alignment = (TextAlignmentOptions)513;
			((Component)val4).gameObject.AddComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
			GameObject gameObject = ((Component)val4).gameObject;
			int? flexibleWidth = 1;
			UIHelper.SetLayoutElement(gameObject, null, null, flexibleWidth);
			TextMeshProUGUI val5 = UIHelper.CreateText(val3, "ping", "Ping", UIManager.DefaultFont);
			((TMP_Text)val5).alignment = (TextAlignmentOptions)514;
			((Component)val5).gameObject.AddComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
			UIHelper.SetLayoutElement(((Component)val5).gameObject, 40);
			LayoutRebuilder.ForceRebuildLayoutImmediate(_playerList.GetComponent<RectTransform>());
			foreach (PlayerManager.Player allPlayer in Plugin.Instance.PlayerManager.GetAllPlayers())
			{
				CreatePlayerLine(allPlayer);
			}
			Plugin.Instance.PlayerManager.OnPlayerAdded += CreatePlayerLine;
			LayoutRebuilder.ForceRebuildLayoutImmediate(_playerList.GetComponent<RectTransform>());
			_playerList.SetActive(false);
		}

		private void Update()
		{
			if (Plugin.Instance.Network.Online && Input.GetKeyDown((KeyCode)96))
			{
				_playerList.SetActive(!_playerList.activeSelf);
				Plugin.Log.LogInfo((object)$"List toggled {_playerList.activeSelf}");
			}
		}

		public void CreatePlayerLine(PlayerManager.Player player)
		{
			//IL_001b: 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_0080: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = UIHelper.CreateBox(_playerList, $"player_{player.Id}", EntryColor);
			val.SetActive(false);
			UIHelper.SetLayoutGroup<HorizontalLayoutGroup>(val, (bool?)false, (bool?)false, (bool?)true, (bool?)true, (int?)5, (int?)5, (int?)5, (int?)15, (int?)15, (TextAnchor?)(TextAnchor)4);
			GameObject val2 = UIHelper.CreateUIObject("is_host", val);
			Image val3 = val2.AddComponent<Image>();
			val3.type = (Type)3;
			Texture2D crown = Plugin.Instance.TextureRepository.Crown;
			val3.sprite = Sprite.Create(crown, new Rect(0f, 0f, (float)((Texture)crown).width, (float)((Texture)crown).height), new Vector2(0.5f, 0.5f));
			UIHelper.SetLayoutElement(val2, 24);
			TextMeshProUGUI val4 = UIHelper.CreateText(val, "name", "", UIManager.DefaultFont);
			((TMP_Text)val4).alignment = (TextAlignmentOptions)513;
			((Component)val4).gameObject.AddComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
			GameObject gameObject = ((Component)val4).gameObject;
			int? flexibleWidth = 1;
			UIHelper.SetLayoutElement(gameObject, null, null, flexibleWidth);
			TextMeshProUGUI val5 = UIHelper.CreateText(val, "ping", "", UIManager.DefaultFont);
			((TMP_Text)val5).alignment = (TextAlignmentOptions)514;
			((Component)val5).gameObject.AddComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
			UIHelper.SetLayoutElement(((Component)val5).gameObject, 40);
			PlayerInfoControl playerInfoControl = val.AddComponent<PlayerInfoControl>();
			playerInfoControl.playerId = player.Id;
			playerInfoControl.hostIdentifier = val2;
			playerInfoControl.container = val;
			playerInfoControl.playerName = (TMP_Text)(object)val4;
			playerInfoControl.ping = (TMP_Text)(object)val5;
			val.SetActive(true);
			LayoutRebuilder.ForceRebuildLayoutImmediate(_playerList.GetComponent<RectTransform>());
		}
	}
	public class HostPanel : BaseUI
	{
		private struct LobbyCreationRequest
		{
			public string Name;

			public string Password;

			public int MaxPlayers;

			public bool CheatsEnabled;

			public ELobbyType Type;
		}

		private const int LabelWidth = 140;

		private readonly CallResult<LobbyCreated_t> _onLobbyCreatedCallResult;

		private LobbyCreationRequest? _currentRequest;

		private GameObject _window;

		public override string Name => "Host Panel";

		public ButtonControl Host { get; private set; }

		public HostPanel()
		{
			if (SteamManager.Initialized)
			{
				_onLobbyCreatedCallResult = CallResult<LobbyCreated_t>.Create((APIDispatchDelegate<LobbyCreated_t>)OnLobbyCreated);
			}
		}

		public override void ConstructPanelContent()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: 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_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_037d: 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_04a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04da: Unknown result type (might be due to invalid IL or missing references)
			//IL_04df: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_050e: 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_0534: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = UIHelper.CreateUIObject("background", base.PanelRoot);
			Image val2 = val.AddComponent<Image>();
			val2.type = (Type)1;
			((Graphic)val2).color = UIManager.TransparentBackgroundColor;
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0f, 0f);
			component.anchorMax = new Vector2(1f, 1f);
			_window = UIHelper.CreateUIObject("panel", val);
			Image val3 = _window.AddComponent<Image>();
			val3.type = (Type)1;
			((Graphic)val3).color = UIManager.DarkBackgroundColor;
			UIHelper.SetLayoutGroup<VerticalLayoutGroup>(_window, (bool?)true, (bool?)true, (bool?)true, (bool?)true, (int?)0, (int?)5, (int?)5, (int?)5, (int?)5, (TextAnchor?)(TextAnchor)3);
			RectTransform component2 = _window.GetComponent<RectTransform>();
			component2.anchorMin = new Vector2(0.35f, 0.3f);
			component2.anchorMax = new Vector2(0.65f, 0.7f);
			GameObject val4 = UIHelper.CreateUIObject("panel", _window);
			Image val5 = val4.AddComponent<Image>();
			val5.type = (Type)1;
			((Graphic)val5).color = UIManager.BackgroundColor;
			UIHelper.SetLayoutGroup<VerticalLayoutGroup>(val4, (bool?)false, (bool?)false, (bool?)true, (bool?)true, (int?)5, (int?)20, (int?)80, (int?)60, (int?)60, (TextAnchor?)(TextAnchor)3);
			RectTransform component3 = val4.GetComponent<RectTransform>();
			component3.anchorMin = new Vector2(0f, 0f);
			component3.anchorMax = new Vector2(1f, 1f);
			string text = (SteamManager.Initialized ? SteamFriends.GetPersonaName() : "Unavailable");
			TMP_InputField nameField = UIHelper.CreateInputField(val4, "name", "Name", text + "'s Game", 140, 24);
			TMP_InputField passwordField = UIHelper.CreateInputField(val4, "password", "Password", "", 140, 24);
			passwordField.contentType = (ContentType)7;
			TMP_InputField maxPlayersField = UIHelper.CreateInputField(val4, "max_players", "Players", "8", 140, 2);
			maxPlayersField.contentType = (ContentType)3;
			ToggleControl friendsOnlyToggle = CreateToggle(val4, "friends_only", "Friends Only", value: false);
			ToggleControl enableCheatsToggle = CreateToggle(val4, "cheats_enabled", "Enable Cheats", value: false);
			GameObject val6 = UIHelper.CreateUIObject("buttons", val4);
			UIHelper.SetLayoutGroup<HorizontalLayoutGroup>(val6, (bool?)false, (bool?)false, (bool?)true, (bool?)true, (int?)20, (int?)0, (int?)0, (int?)0, (int?)0, (TextAnchor?)(TextAnchor)4);
			bool? ignoreLayout = true;
			UIHelper.SetLayoutElement(val6, null, null, null, null, null, null, ignoreLayout);
			RectTransform component4 = val6.GetComponent<RectTransform>();
			component4.anchorMin = new Vector2(0f, 0.1f);
			component4.anchorMax = new Vector2(1f, 0.3f);
			Host = UIHelper.CreateButton(val6, "host", "Host");
			UIHelper.SetLayoutElement(((Component)Host).gameObject, 100);
			Host.OnClick += delegate
			{
				//IL_00af: Unknown result type (might be due to invalid IL or missing references)
				Plugin.Log.LogInfo((object)("Creating " + (friendsOnlyToggle.Toggle.isOn ? "friends only" : "public") + " lobby"));
				CreateLobby(new LobbyCreationRequest
				{
					Name = nameField.text,
					MaxPlayers = int.Parse(maxPlayersField.text),
					Password = passwordField.text,
					CheatsEnabled = enableCheatsToggle.Toggle.isOn,
					Type = (ELobbyType)(friendsOnlyToggle.Toggle.isOn ? 1 : 2)
				});
				ThronefallAudioManager.Oneshot((AudioOneShot)11);
			};
			ButtonControl buttonControl = UIHelper.CreateButton(val6, "back", "Back");
			UIHelper.SetLayoutElement(((Component)buttonControl).gameObject, 100);
			buttonControl.OnClick += delegate
			{
				base.Enabled = false;
				((Selectable)UIManager.LobbyListPanel.Host.Button).Select();
				ThronefallAudioManager.Oneshot((AudioOneShot)11);
			};
			TMP_InputField obj = nameField;
			Navigation navigation = ((Selectable)nameField).navigation;
			((Navigation)(ref navigation)).selectOnDown = (Selectable)(object)passwordField;
			((Navigation)(ref navigation)).selectOnUp = (Selectable)(object)Host.Button;
			((Selectable)obj).navigation = navigation;
			TMP_InputField obj2 = passwordField;
			navigation = ((Selectable)passwordField).navigation;
			((Navigation)(ref navigation)).selectOnDown = (Selectable)(object)maxPlayersField;
			((Navigation)(ref navigation)).selectOnUp = (Selectable)(object)nameField;
			((Selectable)obj2).navigation = navigation;
			TMP_InputField obj3 = maxPlayersField;
			navigation = ((Selectable)maxPlayersField).navigation;
			((Navigation)(ref navigation)).selectOnDown = (Selectable)(object)friendsOnlyToggle.Toggle;
			((Navigation)(ref navigation)).selectOnUp = (Selectable)(object)passwordField;
			((Selectable)obj3).navigation = navigation;
			friendsOnlyToggle.NavUp = (Selectable)(object)maxPlayersField;
			friendsOnlyToggle.NavDown = (Selectable)(object)Host.Button;
			Host.NavUp = (Selectable)(object)friendsOnlyToggle.Toggle;
			Host.NavDown = (Selectable)(object)nameField;
			Host.NavLeft = (Selectable)(object)buttonControl.Button;
			Host.NavRight = (Selectable)(object)buttonControl.Button;
			buttonControl.NavUp = (Selectable)(object)friendsOnlyToggle.Toggle;
			buttonControl.NavDown = (Selectable)(object)nameField;
			buttonControl.NavLeft = (Selectable)(object)Host.Button;
			buttonControl.NavRight = (Selectable)(object)Host.Button;
			LayoutRebuilder.ForceRebuildLayoutImmediate(_window.GetComponent<RectTransform>());
		}

		private static ToggleControl CreateToggle(GameObject panel, string name, string label, bool value)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = UIHelper.CreateUIObject(name + "Group", panel);
			UIHelper.SetLayoutGroup<HorizontalLayoutGroup>(val, (bool?)false, (bool?)false, (bool?)true, (bool?)false, (int?)20, (int?)5, (int?)5, (int?)5, (int?)5, (TextAnchor?)(TextAnchor)3);
			int? flexibleWidth = 1;
			UIHelper.SetLayoutElement(val, null, null, flexibleWidth);
			GameObject val2 = UIHelper.CreateBox(val, name + "_label_bg", Color.clear);
			GameObject gameObject = val2;
			bool? childControlWidth = true;
			TextAnchor? childAlignment = (TextAnchor)3;
			UIHelper.SetLayoutGroup<HorizontalLayoutGroup>(gameObject, (bool?)null, (bool?)null, childControlWidth, (bool?)null, (int?)null, (int?)null, (int?)null, (int?)null, (int?)null, childAlignment);
			GameObject gameObject2 = val2.gameObject;
			int? minWidth = 140;
			flexibleWidth = 0;
			UIHelper.SetLayoutElement(gameObject2, minWidth, null, flexibleWidth);
			val2.AddComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
			TextMeshProUGUI val3 = UIHelper.CreateText(val2, name + "_label", label + ": ");
			((TMP_Text)val3).alignment = (TextAlignmentOptions)513;
			val2 = UIHelper.CreateBox(val, name + "_bg", Color.clear);
			GameObject gameObject3 = val2;
			childControlWidth = true;
			childAlignment = (TextAnchor)4;
			UIHelper.SetLayoutGroup<HorizontalLayoutGroup>(gameObject3, (bool?)null, (bool?)null, childControlWidth, (bool?)null, (int?)null, (int?)null, (int?)null, (int?)null, (int?)null, childAlignment);
			GameObject gameObject4 = val2.gameObject;
			flexibleWidth = 1;
			UIHelper.SetLayoutElement(gameObject4, null, null, flexibleWidth);
			val2.AddComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
			ToggleControl toggleControl = UIHelper.CreateToggle(val2, name ?? "", value);
			GameObject gameObject5 = ((Component)toggleControl).gameObject;
			childAlignment = (TextAnchor)4;
			UIHelper.SetLayoutGroup<HorizontalLayoutGroup>(gameObject5, (bool?)null, (bool?)null, (bool?)null, (bool?)null, (int?)null, (int?)null, (int?)null, (int?)null, (int?)null, childAlignment);
			return toggleControl;
		}

		public void Update()
		{
			if (!UIManager.ExitHandled && Input.GetKeyDown((KeyCode)27))
			{
				base.Enabled = false;
				UIManager.ExitHandled = true;
				ThronefallAudioManager.Oneshot((AudioOneShot)11);
			}
		}

		private bool CreateLobby(LobbyCreationRequest request)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			if (_currentRequest.HasValue)
			{
				return false;
			}
			_window.SetActive(false);
			_currentRequest = request;
			if (request.Password == string.Empty)
			{
				request.Password = null;
			}
			_onLobbyCreatedCallResult.Set(SteamMatchmaking.CreateLobby(request.Type, request.MaxPlayers), (APIDispatchDelegate<LobbyCreated_t>)null);
			return true;
		}

		private void OnLobbyCreated(LobbyCreated_t created, bool ioFailure)
		{
			//IL_0038: 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: Invalid comparison between Unknown and I4
			//IL_006e: 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_004b: 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_00a5: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			_window.SetActive(true);
			if (ioFailure)
			{
				UIManager.CreateMessageDialog("Error creating lobby", "Lobby creation failed with io error'");
				return;
			}
			if ((int)created.m_eResult != 1)
			{
				UIManager.CreateMessageDialog("Error creating lobby", $"Lobby creation failed with error '{created.m_eResult}'");
				return;
			}
			CSteamID id = new CSteamID(created.m_ulSteamIDLobby);
			string password = _currentRequest.Value.Password;
			string text = (string.IsNullOrEmpty(password) ? "no" : "yes");
			SteamMatchmaking.SetLobbyData(id, "name", _currentRequest.Value.Name);
			SteamMatchmaking.SetLobbyData(id, "password", text);
			SteamMatchmaking.SetLobbyData(id, "version", "thronefall_mp_1.0.5");
			SteamMatchmaking.SetLobbyData(id, "cheats_enabled", _curr