Decompiled source of ValheimProfiler v1.0.0

ValheimProfiler.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using ValheimProfiler.Configuration;
using ValheimProfiler.Core;
using ValheimProfiler.Core.Logging;
using ValheimProfiler.Core.Profiling;
using ValheimProfiler.Server;
using ValheimProfiler.Tools.LogMonitor;
using ValheimProfiler.Tools.MonoBehaviourCallProfiler;
using ValheimProfiler.Tools.MonoBehaviourProfiler;
using ValheimProfiler.Tools.NetworkProfiler;
using ValheimProfiler.Tools.PatchProfiler;
using ValheimProfiler.Tools.ServerLogMonitor;
using ValheimProfiler.Tools.ValheimUpdateProfiler;
using ValheimProfiler.UI;
using ValheimProfiler.Valheim;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("ValheimProfiler")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+87c9dc75dea5601eb74fd122b36ec1687652ddf4")]
[assembly: AssemblyProduct("ValheimProfiler")]
[assembly: AssemblyTitle("ValheimProfiler")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ValheimProfiler
{
	[BepInPlugin("shudnal.ValheimProfiler", "Valheim Profiler", "1.0.0")]
	public sealed class ValheimProfilerPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "shudnal.ValheimProfiler";

		public const string PluginName = "Valheim Profiler";

		public const string PluginVersion = "1.0.0";

		internal const string CoreHarmonyId = "shudnal.ValheimProfiler.Core";

		private Harmony _coreHarmony;

		private bool _headlessServerBackend;

		internal static ValheimProfilerPlugin Instance { get; private set; }

		internal ValheimProfilerApp App { get; private set; }

		internal ServerLogService ServerLogService { get; private set; }

		internal NetworkProfilerService NetworkProfilerService { get; private set; }

		private void Awake()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Invalid comparison between Unknown and I4
			Instance = this;
			ValheimProfilerConfig config = new ValheimProfilerConfig(((BaseUnityPlugin)this).Config);
			_coreHarmony = new Harmony("shudnal.ValheimProfiler.Core");
			_headlessServerBackend = (int)SystemInfo.graphicsDeviceType == 4;
			if (_headlessServerBackend)
			{
				ServerLogService = new ServerLogService(config);
				NetworkProfilerService = new NetworkProfilerService();
				PatchHeadlessNetworkBridges();
				ServerLogRpcBridge.RegisterForCurrentNetwork();
				NetworkProfilerRpcBridge.RegisterForCurrentNetwork();
			}
			else
			{
				App = new ValheimProfilerApp(config, ((BaseUnityPlugin)this).Logger);
				_coreHarmony.PatchAll(typeof(ValheimProfilerPlugin).Assembly);
				App.Initialize();
				ServerLogRpcBridge.RegisterForCurrentNetwork();
				NetworkProfilerRpcBridge.RegisterForCurrentNetwork();
			}
		}

		private void PatchHeadlessNetworkBridges()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			_coreHarmony.Patch((MethodBase)AccessTools.Method(typeof(ZNet), "Awake", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(ZNetAwakeServerLogPatch), "Postfix", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			_coreHarmony.Patch((MethodBase)AccessTools.Method(typeof(ZNet), "OnDestroy", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.Method(typeof(ZNetOnDestroyServerLogPatch), "Prefix", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		private void Start()
		{
			App?.MarkGameWindowReady();
		}

		private void Update()
		{
			if (_headlessServerBackend)
			{
				ServerLogService?.Update();
				NetworkProfilerService?.Update();
			}
			else
			{
				App?.Update();
			}
		}

		private void LateUpdate()
		{
			App?.LateUpdate();
		}

		private void OnGUI()
		{
			App?.OnGUI();
		}

		private void OnDisable()
		{
			App?.SetUiVisible(visible: false);
			App?.ReleaseCursorAndPause();
		}

		private void OnDestroy()
		{
			try
			{
				App?.Shutdown();
				ServerLogService?.Shutdown();
				NetworkProfilerService?.Shutdown();
			}
			finally
			{
				Harmony coreHarmony = _coreHarmony;
				if (coreHarmony != null)
				{
					coreHarmony.UnpatchSelf();
				}
				_coreHarmony = null;
				App = null;
				ServerLogService = null;
				NetworkProfilerService = null;
				ServerLogTransport.Clear();
				NetworkProfilerTransport.Clear();
				if ((Object)(object)Instance == (Object)(object)this)
				{
					Instance = null;
				}
			}
		}
	}
}
namespace ValheimProfiler.Valheim
{
	[HarmonyPatch]
	internal static class GuiPointScalingPatch
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			yield return AccessTools.Method(typeof(GUIUtility), "ScreenToGUIPoint", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(GUIUtility), "GUIToScreenPoint", (Type[])null, (Type[])null);
		}

		[HarmonyPriority(800)]
		private static void Prefix(ref Matrix4x4 __state)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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)
			ValheimProfilerPlugin instance = ValheimProfilerPlugin.Instance;
			if (instance != null && instance.App?.IsDrawingUi == true)
			{
				__state = GUI.matrix;
				GUI.matrix = Matrix4x4.identity;
			}
		}

		[HarmonyPriority(800)]
		private static void Postfix(Matrix4x4 __state)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			ValheimProfilerPlugin instance = ValheimProfilerPlugin.Instance;
			if (instance != null && instance.App?.IsDrawingUi == true)
			{
				GUI.matrix = __state;
			}
		}
	}
	internal sealed class ValheimCursorController
	{
		private bool _captured;

		private CursorLockMode _previousLockState;

		private bool _previousVisible;

		internal void Update(bool active)
		{
			if (active)
			{
				Unlock();
			}
			else
			{
				Release();
			}
		}

		internal void LateUpdate(bool active)
		{
			if (active)
			{
				Unlock();
			}
		}

		internal void OnGUI(bool active)
		{
			if (active)
			{
				Unlock();
			}
		}

		internal void Release()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			if (_captured)
			{
				Cursor.lockState = _previousLockState;
				Cursor.visible = _previousVisible;
				_captured = false;
			}
		}

		internal void OverrideReleaseState(CursorLockMode lockState, bool visible)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			if (_captured)
			{
				_previousLockState = lockState;
				_previousVisible = visible;
			}
		}

		private void Unlock()
		{
			//IL_0009: 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)
			if (!_captured || (int)Cursor.lockState != 0 || !Cursor.visible)
			{
				_previousLockState = Cursor.lockState;
				_previousVisible = Cursor.visible;
				_captured = true;
			}
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
		}
	}
	[HarmonyPatch(typeof(FejdStartup), "Start")]
	internal static class FejdStartupStartCursorPatch
	{
		private static void Postfix()
		{
			ValheimProfilerPlugin.Instance?.App?.OverrideCursorReleaseState((CursorLockMode)0, visible: true);
		}
	}
	[HarmonyPatch(typeof(FejdStartup), "OnDestroy")]
	internal static class FejdStartupOnDestroyCursorPatch
	{
		private static void Prefix()
		{
			ValheimProfilerPlugin.Instance?.App?.OverrideCursorReleaseState((CursorLockMode)1, visible: false);
		}
	}
	internal static class ValheimInputState
	{
		internal static bool ShouldBlockAll
		{
			get
			{
				ValheimProfilerPlugin instance = ValheimProfilerPlugin.Instance;
				return instance != null && instance.App?.ShouldBlockGameInput == true;
			}
		}

		internal static bool ShouldBlockMouse
		{
			get
			{
				ValheimProfilerPlugin instance = ValheimProfilerPlugin.Instance;
				return instance != null && instance.App?.ShouldBlockMouseInput == true;
			}
		}
	}
	internal static class ZInputPatchMethods
	{
		private const BindingFlags AllMethods = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

		internal static IEnumerable<MethodBase> FindBooleanMethods(params string[] names)
		{
			HashSet<string> acceptedNames = new HashSet<string>(names ?? Array.Empty<string>(), StringComparer.Ordinal);
			return (from method in typeof(ZInput).GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
				where method.ReturnType == typeof(bool) && acceptedNames.Contains(method.Name)
				select method).Cast<MethodBase>().Distinct();
		}

		internal static IEnumerable<MethodBase> FindStringButtonMethods()
		{
			return FindBooleanMethods("GetButton", "GetButtonDown", "GetButtonUp").Where(delegate(MethodBase method)
			{
				ParameterInfo[] parameters = method.GetParameters();
				return parameters.Length != 0 && parameters[0].ParameterType == typeof(string);
			});
		}
	}
	internal static class ZInputMouseBindingResolver
	{
		private sealed class CachedMouseBindings
		{
			public bool DefinitionFound;

			public bool BindingSourceResolved;

			public object ButtonAction;

			public object[] MouseControls = Array.Empty<object>();

			public int MouseButtonMask;
		}

		private const BindingFlags InstanceMembers = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

		private static readonly Dictionary<string, CachedMouseBindings> BindingCache = new Dictionary<string, CachedMouseBindings>(StringComparer.Ordinal);

		internal static void ClearCache()
		{
			BindingCache.Clear();
		}

		internal static void Invalidate(string action)
		{
			if (!string.IsNullOrWhiteSpace(action))
			{
				BindingCache.Remove(action);
			}
		}

		internal static bool IsMouseBindingActive(string action, string queryMethodName, bool actionResultIsKnownTrue = false)
		{
			if (string.IsNullOrWhiteSpace(action))
			{
				return false;
			}
			CachedMouseBindings configuredMouseBindings = GetConfiguredMouseBindings(action);
			if (configuredMouseBindings.DefinitionFound)
			{
				object memberValue = GetMemberValue(configuredMouseBindings.ButtonAction, "activeControl");
				if (memberValue != null)
				{
					bool flag = IsMouseControl(memberValue);
					bool flag2 = IsControlActive(memberValue, queryMethodName);
					if (flag && (actionResultIsKnownTrue || flag2))
					{
						return true;
					}
					if (!flag && (actionResultIsKnownTrue || flag2))
					{
						return false;
					}
				}
				for (int i = 0; i < configuredMouseBindings.MouseControls.Length; i++)
				{
					if (IsControlActive(configuredMouseBindings.MouseControls[i], queryMethodName))
					{
						return true;
					}
				}
				int num = configuredMouseBindings.MouseButtonMask;
				int num2 = 0;
				while (num != 0 && num2 < 31)
				{
					if ((num & 1) != 0 && IsMouseButtonActive(num2, queryMethodName))
					{
						return true;
					}
					num2++;
					num >>= 1;
				}
				if (configuredMouseBindings.BindingSourceResolved)
				{
					return false;
				}
			}
			if (1 == 0)
			{
			}
			int num3;
			switch (action)
			{
			case "Attack":
				num3 = 0;
				break;
			case "Block":
			case "BuildMenu":
				num3 = 1;
				break;
			case "SecondaryAttack":
			case "Remove":
				num3 = 2;
				break;
			default:
				num3 = -1;
				break;
			}
			if (1 == 0)
			{
			}
			int num4 = num3;
			return num4 >= 0 && IsMouseButtonActive(num4, queryMethodName);
		}

		private static CachedMouseBindings GetConfiguredMouseBindings(string action)
		{
			if (BindingCache.TryGetValue(action, out var value))
			{
				return value;
			}
			CachedMouseBindings cachedMouseBindings = ResolveConfiguredMouseBindings(action);
			BindingCache[action] = cachedMouseBindings;
			return cachedMouseBindings;
		}

		private static CachedMouseBindings ResolveConfiguredMouseBindings(string action)
		{
			CachedMouseBindings cachedMouseBindings = new CachedMouseBindings();
			try
			{
				ZInput instance = ZInput.instance;
				if (instance?.m_buttons == null || !instance.m_buttons.TryGetValue(action, out var value))
				{
					return cachedMouseBindings;
				}
				cachedMouseBindings.DefinitionFound = true;
				ResolveDirectButtonDefinition(value, cachedMouseBindings);
				object memberValue = GetMemberValue(value, "ButtonAction");
				if (memberValue == null)
				{
					memberValue = GetMemberValue(value, "m_buttonAction");
				}
				if (memberValue == null)
				{
					return cachedMouseBindings;
				}
				cachedMouseBindings.BindingSourceResolved = true;
				cachedMouseBindings.ButtonAction = memberValue;
				object memberValue2 = GetMemberValue(memberValue, "bindings");
				if (memberValue2 is IEnumerable enumerable)
				{
					foreach (object item in enumerable)
					{
						string text = GetMemberValue(item, "effectivePath") as string;
						if (string.IsNullOrWhiteSpace(text))
						{
							text = GetMemberValue(item, "path") as string;
						}
						if (TryParseMouseButton(text, out var mouseButton) && mouseButton < 31)
						{
							cachedMouseBindings.MouseButtonMask |= 1 << mouseButton;
						}
					}
				}
				object memberValue3 = GetMemberValue(memberValue, "controls");
				if (memberValue3 is IEnumerable enumerable2)
				{
					List<object> list = new List<object>();
					foreach (object item2 in enumerable2)
					{
						if (item2 != null && IsMouseControl(item2))
						{
							list.Add(item2);
						}
					}
					cachedMouseBindings.MouseControls = list.ToArray();
				}
			}
			catch
			{
				return new CachedMouseBindings();
			}
			return cachedMouseBindings;
		}

		private static void ResolveDirectButtonDefinition(object definition, CachedMouseBindings resolved)
		{
			if (definition == null || resolved == null)
			{
				return;
			}
			bool value;
			bool flag = TryGetBooleanMember(definition, "m_bMouseButtonSet", out value) || TryGetBooleanMember(definition, "m_mouseButtonSet", out value);
			object memberValue = GetMemberValue(definition, "m_mouseButton");
			int mouseButton2;
			if (flag)
			{
				resolved.BindingSourceResolved = true;
				if (value && TryConvertMouseButton(memberValue, out var mouseButton))
				{
					resolved.MouseButtonMask |= 1 << mouseButton;
				}
			}
			else if (memberValue != null && TryConvertMouseButton(memberValue, out mouseButton2))
			{
				string text = memberValue.ToString() ?? string.Empty;
				if (!text.Equals("None", StringComparison.OrdinalIgnoreCase) && !text.Equals("Back", StringComparison.OrdinalIgnoreCase))
				{
					resolved.BindingSourceResolved = true;
					resolved.MouseButtonMask |= 1 << mouseButton2;
				}
			}
			object memberValue2 = GetMemberValue(definition, "m_key");
			if (memberValue2 != null)
			{
				string text2 = memberValue2.ToString() ?? string.Empty;
				if (TryParseLegacyMouseKeyName(text2, out var mouseButton3))
				{
					resolved.BindingSourceResolved = true;
					resolved.MouseButtonMask |= 1 << mouseButton3;
				}
				else if (!text2.Equals("None", StringComparison.OrdinalIgnoreCase))
				{
					resolved.BindingSourceResolved = true;
				}
			}
		}

		private static bool TryConvertMouseButton(object value, out int mouseButton)
		{
			mouseButton = -1;
			if (value == null)
			{
				return false;
			}
			string text = value.ToString() ?? string.Empty;
			if (text.Equals("Left", StringComparison.OrdinalIgnoreCase) || text.Equals("LeftButton", StringComparison.OrdinalIgnoreCase))
			{
				mouseButton = 0;
				return true;
			}
			if (text.Equals("Right", StringComparison.OrdinalIgnoreCase) || text.Equals("RightButton", StringComparison.OrdinalIgnoreCase))
			{
				mouseButton = 1;
				return true;
			}
			if (text.Equals("Middle", StringComparison.OrdinalIgnoreCase) || text.Equals("MiddleButton", StringComparison.OrdinalIgnoreCase))
			{
				mouseButton = 2;
				return true;
			}
			if (text.Equals("Forward", StringComparison.OrdinalIgnoreCase) || text.Equals("ForwardButton", StringComparison.OrdinalIgnoreCase))
			{
				mouseButton = 3;
				return true;
			}
			if (text.Equals("Back", StringComparison.OrdinalIgnoreCase) || text.Equals("BackButton", StringComparison.OrdinalIgnoreCase))
			{
				mouseButton = 4;
				return true;
			}
			try
			{
				int num = Convert.ToInt32(value);
				if (num >= 0 && num < 31)
				{
					mouseButton = num;
					return true;
				}
			}
			catch
			{
			}
			return false;
		}

		private static bool TryParseLegacyMouseKeyName(string keyName, out int mouseButton)
		{
			mouseButton = -1;
			if (string.IsNullOrWhiteSpace(keyName) || !keyName.StartsWith("Mouse", StringComparison.OrdinalIgnoreCase))
			{
				return false;
			}
			return int.TryParse(keyName.Substring(5), out mouseButton) && mouseButton >= 0 && mouseButton < 31;
		}

		private static object GetMemberValue(object instance, string memberName)
		{
			if (instance == null || string.IsNullOrEmpty(memberName))
			{
				return null;
			}
			try
			{
				Type type = instance.GetType();
				PropertyInfo property = type.GetProperty(memberName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (property != null && property.GetIndexParameters().Length == 0)
				{
					return property.GetValue(instance, null);
				}
				return type.GetField(memberName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(instance);
			}
			catch
			{
				return null;
			}
		}

		private static bool TryGetBooleanMember(object instance, string memberName, out bool value)
		{
			value = false;
			if (!(GetMemberValue(instance, memberName) is bool flag) || 1 == 0)
			{
				return false;
			}
			value = flag;
			return true;
		}

		private static bool IsMouseControl(object control)
		{
			if (control == null)
			{
				return false;
			}
			string text = GetMemberValue(control, "path") as string;
			if (!string.IsNullOrWhiteSpace(text) && text.IndexOf("/Mouse/", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
			object memberValue = GetMemberValue(control, "device");
			string text2 = memberValue?.GetType().FullName ?? string.Empty;
			if (text2.EndsWith(".Mouse", StringComparison.Ordinal) || string.Equals(memberValue?.GetType().Name, "Mouse", StringComparison.Ordinal))
			{
				return true;
			}
			string a = GetMemberValue(memberValue, "displayName") as string;
			return string.Equals(a, "Mouse", StringComparison.OrdinalIgnoreCase);
		}

		private static bool IsControlActive(object control, string queryMethodName)
		{
			if (control == null)
			{
				return false;
			}
			if (1 == 0)
			{
			}
			string text = ((queryMethodName == "GetButtonDown") ? "wasPressedThisFrame" : ((!(queryMethodName == "GetButtonUp")) ? "isPressed" : "wasReleasedThisFrame"));
			if (1 == 0)
			{
			}
			string memberName = text;
			if (TryGetBooleanMember(control, memberName, out var value))
			{
				return value;
			}
			MethodInfo method = control.GetType().GetMethod("ReadValueAsButton", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null);
			if (method != null && method.ReturnType == typeof(bool))
			{
				try
				{
					return (bool)method.Invoke(control, null);
				}
				catch
				{
				}
			}
			return false;
		}

		private static bool TryParseMouseButton(string path, out int mouseButton)
		{
			mouseButton = -1;
			if (string.IsNullOrWhiteSpace(path) || path.IndexOf("<Mouse>", StringComparison.OrdinalIgnoreCase) < 0)
			{
				return false;
			}
			string text = path.Replace(" ", string.Empty).ToLowerInvariant();
			if (text.EndsWith("/leftbutton", StringComparison.Ordinal))
			{
				mouseButton = 0;
			}
			else if (text.EndsWith("/rightbutton", StringComparison.Ordinal))
			{
				mouseButton = 1;
			}
			else if (text.EndsWith("/middlebutton", StringComparison.Ordinal))
			{
				mouseButton = 2;
			}
			else if (text.EndsWith("/forwardbutton", StringComparison.Ordinal))
			{
				mouseButton = 3;
			}
			else if (text.EndsWith("/backbutton", StringComparison.Ordinal))
			{
				mouseButton = 4;
			}
			else
			{
				int num = text.LastIndexOf("/button", StringComparison.Ordinal);
				if (num < 0 || !int.TryParse(text.Substring(num + 7), out mouseButton))
				{
					return false;
				}
			}
			return mouseButton >= 0;
		}

		private static bool IsMouseButtonActive(int mouseButton, string queryMethodName)
		{
			if (TryGetInputSystemMouseButton(mouseButton, out var control) && IsControlActive(control, queryMethodName))
			{
				return true;
			}
			try
			{
				if (1 == 0)
				{
				}
				bool result = ((queryMethodName == "GetButtonDown") ? Input.GetMouseButtonDown(mouseButton) : ((!(queryMethodName == "GetButtonUp")) ? Input.GetMouseButton(mouseButton) : Input.GetMouseButtonUp(mouseButton)));
				if (1 == 0)
				{
				}
				return result;
			}
			catch
			{
				return false;
			}
		}

		private static bool TryGetInputSystemMouseButton(int mouseButton, out object control)
		{
			control = null;
			try
			{
				object obj = Type.GetType("UnityEngine.InputSystem.Mouse, Unity.InputSystem", throwOnError: false)?.GetProperty("current", BindingFlags.Static | BindingFlags.Public)?.GetValue(null, null);
				if (obj == null)
				{
					return false;
				}
				if (1 == 0)
				{
				}
				string text = mouseButton switch
				{
					0 => "leftButton", 
					1 => "rightButton", 
					2 => "middleButton", 
					3 => "forwardButton", 
					4 => "backButton", 
					_ => null, 
				};
				if (1 == 0)
				{
				}
				string text2 = text;
				if (text2 == null)
				{
					return false;
				}
				control = GetMemberValue(obj, text2);
				return control != null;
			}
			catch
			{
				return false;
			}
		}
	}
	[HarmonyPatch]
	internal static class ZInputMouseBindingCachePatch
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			return typeof(ZInput).GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).Where(delegate(MethodInfo method)
			{
				if (method.Name == "Load")
				{
					return true;
				}
				if (method.Name != "AddButton")
				{
					return false;
				}
				ParameterInfo[] parameters = method.GetParameters();
				return parameters.Length != 0 && parameters[0].ParameterType == typeof(string);
			}).Cast<MethodBase>()
				.Distinct();
		}

		private static void Postfix(MethodBase __originalMethod, object[] __args)
		{
			if (__originalMethod?.Name == "Load")
			{
				ZInputMouseBindingResolver.ClearCache();
				return;
			}
			string action = ((__args != null && __args.Length != 0) ? (__args[0] as string) : null);
			ZInputMouseBindingResolver.Invalidate(action);
		}
	}
	[HarmonyPatch(typeof(PlayerController), "TakeInput")]
	[HarmonyPriority(0)]
	internal static class PlayerControllerTakeInputPatch
	{
		private static void Postfix(ref bool __result)
		{
			if (ValheimInputState.ShouldBlockAll)
			{
				__result = false;
			}
		}
	}
	[HarmonyPatch(typeof(TextInput), "IsVisible")]
	[HarmonyPriority(0)]
	internal static class TextInputIsVisiblePatch
	{
		private static void Postfix(ref bool __result)
		{
			if (ValheimInputState.ShouldBlockAll)
			{
				__result = true;
			}
		}
	}
	[HarmonyPatch]
	internal static class ValheimMouseInteractionBlockPatch
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			return new MethodInfo[7]
			{
				AccessTools.Method(typeof(InventoryGrid), "OnLeftClick", (Type[])null, (Type[])null),
				AccessTools.Method(typeof(InventoryGrid), "OnRightClick", (Type[])null, (Type[])null),
				AccessTools.Method(typeof(InventoryGui), "OnSelectedItem", (Type[])null, (Type[])null),
				AccessTools.Method(typeof(InventoryGui), "OnRightClickItem", (Type[])null, (Type[])null),
				AccessTools.Method(typeof(Toggle), "OnPointerClick", (Type[])null, (Type[])null),
				AccessTools.Method(typeof(Button), "OnPointerClick", (Type[])null, (Type[])null),
				AccessTools.Method(typeof(ScrollRect), "OnScroll", (Type[])null, (Type[])null)
			}.Where((MethodInfo method) => method != null);
		}

		[HarmonyPriority(800)]
		private static bool Prefix()
		{
			return !ValheimInputState.ShouldBlockMouse;
		}
	}
	[HarmonyPatch]
	internal static class ValheimAllInputInteractionBlockPatch
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			return new MethodInfo[4]
			{
				AccessTools.Method(typeof(Toggle), "OnSubmit", (Type[])null, (Type[])null),
				AccessTools.Method(typeof(Button), "OnSubmit", (Type[])null, (Type[])null),
				AccessTools.Method(typeof(Button), "Press", (Type[])null, (Type[])null),
				AccessTools.Method(typeof(Player), "UseHotbarItem", (Type[])null, (Type[])null)
			}.Where((MethodInfo method) => method != null);
		}

		[HarmonyPriority(800)]
		private static bool Prefix()
		{
			return !ValheimInputState.ShouldBlockAll;
		}
	}
	[HarmonyPatch]
	internal static class ZInputAllBooleanBlockPatch
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			return ZInputPatchMethods.FindBooleanMethods("ShouldAcceptInputFromSource", "GetKey", "GetKeyUp", "GetKeyDown", "GetButton", "GetButtonDown", "GetButtonUp", "GetRadialTap", "GetRadialMultiTap");
		}

		[HarmonyPriority(800)]
		private static bool Prefix(ref bool __result)
		{
			if (!ValheimInputState.ShouldBlockAll)
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
	[HarmonyPatch]
	internal static class ZInputMouseMappedButtonBlockPatch
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			return ZInputPatchMethods.FindStringButtonMethods();
		}

		[HarmonyPriority(0)]
		private static Exception Finalizer(Exception __exception, MethodBase __originalMethod, object[] __args, ref bool __result)
		{
			if (__exception != null || !__result || ValheimInputState.ShouldBlockAll || !ValheimInputState.ShouldBlockMouse)
			{
				return __exception;
			}
			string action = ((__args != null && __args.Length != 0) ? (__args[0] as string) : null);
			if (ZInputMouseBindingResolver.IsMouseBindingActive(action, __originalMethod?.Name, actionResultIsKnownTrue: true))
			{
				__result = false;
			}
			return __exception;
		}
	}
	[HarmonyPatch]
	internal static class PlayerSetControlsMouseBlockPatch
	{
		private const BindingFlags AllMethods = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

		private static IEnumerable<MethodBase> TargetMethods()
		{
			string[] requiredNames = new string[6] { "attack", "attackHold", "secondaryAttack", "secondaryAttackHold", "block", "blockHold" };
			return (from method in typeof(Player).GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
				where method.Name == "SetControls"
				select method).Where(delegate(MethodInfo method)
			{
				HashSet<string> hashSet = new HashSet<string>(from parameter in method.GetParameters()
					select parameter.Name, StringComparer.Ordinal);
				return requiredNames.All(hashSet.Contains);
			}).Cast<MethodBase>().Distinct();
		}

		[HarmonyPriority(0)]
		private static void Prefix(ref bool attack, ref bool attackHold, ref bool secondaryAttack, ref bool secondaryAttackHold, ref bool block, ref bool blockHold)
		{
			if (ValheimInputState.ShouldBlockMouse && !ValheimInputState.ShouldBlockAll)
			{
				if ((attack | attackHold) && ZInputMouseBindingResolver.IsMouseBindingActive("Attack", "GetButton", actionResultIsKnownTrue: true))
				{
					attack = false;
					attackHold = false;
				}
				if ((secondaryAttack | secondaryAttackHold) && ZInputMouseBindingResolver.IsMouseBindingActive("SecondaryAttack", "GetButton", actionResultIsKnownTrue: true))
				{
					secondaryAttack = false;
					secondaryAttackHold = false;
				}
				if ((block | blockHold) && ZInputMouseBindingResolver.IsMouseBindingActive("Block", "GetButton", actionResultIsKnownTrue: true))
				{
					block = false;
					blockHold = false;
				}
			}
		}
	}
	[HarmonyPatch]
	internal static class ZInputMouseBooleanBlockPatch
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			return ZInputPatchMethods.FindBooleanMethods("GetMouseButton", "GetMouseButtonDown", "GetMouseButtonUp");
		}

		[HarmonyPriority(800)]
		private static bool Prefix(ref bool __result)
		{
			if (!ValheimInputState.ShouldBlockMouse)
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
	[HarmonyPatch]
	internal static class ZInputAllFloatBlockPatch
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			return new MethodInfo[6]
			{
				AccessTools.Method(typeof(ZInput), "GetJoyLeftStickX", (Type[])null, (Type[])null),
				AccessTools.Method(typeof(ZInput), "GetJoyLeftStickY", (Type[])null, (Type[])null),
				AccessTools.Method(typeof(ZInput), "GetJoyRTrigger", (Type[])null, (Type[])null),
				AccessTools.Method(typeof(ZInput), "GetJoyLTrigger", (Type[])null, (Type[])null),
				AccessTools.Method(typeof(ZInput), "GetJoyRightStickX", (Type[])null, (Type[])null),
				AccessTools.Method(typeof(ZInput), "GetJoyRightStickY", (Type[])null, (Type[])null)
			}.Where((MethodInfo method) => method != null);
		}

		[HarmonyPriority(0)]
		private static void Postfix(ref float __result)
		{
			if (ValheimInputState.ShouldBlockAll)
			{
				__result = 0f;
			}
		}
	}
	[HarmonyPatch(typeof(ZInput), "GetMouseScrollWheel")]
	internal static class ZInputMouseScrollBlockPatch
	{
		[HarmonyPriority(0)]
		private static void Postfix(ref float __result)
		{
			if (ValheimInputState.ShouldBlockMouse)
			{
				__result = 0f;
			}
		}
	}
	[HarmonyPatch(typeof(ZInput), "GetMouseDelta")]
	internal static class ZInputMouseDeltaBlockPatch
	{
		[HarmonyPriority(0)]
		private static void Postfix(ref Vector2 __result)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			if (ValheimInputState.ShouldBlockMouse)
			{
				__result = Vector2.zero;
			}
		}
	}
	internal sealed class ValheimPauseController
	{
		private readonly ValheimProfilerConfig _config;

		private bool _pausedByProfiler;

		internal ValheimPauseController(ValheimProfilerConfig config)
		{
			_config = config;
		}

		internal void Update(bool hasVisibleWindows)
		{
			if (!_config.PauseGame.Value || !Object.op_Implicit((Object)(object)Game.instance))
			{
				if (_pausedByProfiler)
				{
					Release();
				}
			}
			else if (hasVisibleWindows)
			{
				if (!_pausedByProfiler && !Game.IsPaused() && Game.CanPause())
				{
					Game.Pause();
					_pausedByProfiler = true;
				}
			}
			else if (_pausedByProfiler)
			{
				Release();
			}
		}

		internal void Release()
		{
			if (_pausedByProfiler && Object.op_Implicit((Object)(object)Game.instance) && !Menu.IsActive() && Game.IsPaused())
			{
				Game.Unpause();
			}
			_pausedByProfiler = false;
		}
	}
}
namespace ValheimProfiler.UI
{
	internal sealed class GuiScaleController
	{
		private readonly ValheimProfilerConfig _config;

		private bool _temporaryUnity6000Window = true;

		internal float ScaleFactor
		{
			get
			{
				float num = Mathf.Clamp(_config.UiScale.Value, 0.25f, 4f);
				if (_config.UseValheimGuiScale.Value)
				{
					num *= GetValheimGuiScale();
				}
				return Mathf.Max(0.01f, num);
			}
		}

		internal int PhysicalWidth => _temporaryUnity6000Window ? GetDisplayWidth() : Mathf.Max(1, Screen.width);

		internal int PhysicalHeight => _temporaryUnity6000Window ? GetDisplayHeight() : Mathf.Max(1, Screen.height);

		internal float LogicalWidth => (float)PhysicalWidth / ScaleFactor;

		internal float LogicalHeight => (float)PhysicalHeight / ScaleFactor;

		internal Matrix4x4 Matrix => Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(ScaleFactor, ScaleFactor, 1f));

		internal GuiScaleController(ValheimProfilerConfig config)
		{
			_config = config;
		}

		internal void MarkGameWindowReady()
		{
			_temporaryUnity6000Window = false;
		}

		internal Vector2 GetLogicalMousePosition()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: 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_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			Matrix4x4 val = Matrix;
			val = ((Matrix4x4)(ref val)).inverse;
			Vector3 val2 = ((Matrix4x4)(ref val)).MultiplyPoint(UnityInput.Current.mousePosition);
			return new Vector2(val2.x, LogicalHeight - val2.y);
		}

		private float GetValheimGuiScale()
		{
			try
			{
				float num = (float)PhysicalWidth / (float)GuiScaler.m_minWidth;
				float num2 = (float)PhysicalHeight / (float)GuiScaler.m_minHeight;
				return Mathf.Max(0.01f, Mathf.Min(num, num2) * GuiScaler.m_largeGuiScale);
			}
			catch
			{
				return 1f;
			}
		}

		private static int GetDisplayWidth()
		{
			try
			{
				return (Display.main != null) ? Mathf.Max(1, Display.main.systemWidth) : Mathf.Max(1, Screen.width);
			}
			catch
			{
				return Mathf.Max(1, Screen.width);
			}
		}

		private static int GetDisplayHeight()
		{
			try
			{
				return (Display.main != null) ? Mathf.Max(1, Display.main.systemHeight) : Mathf.Max(1, Screen.height);
			}
			catch
			{
				return Mathf.Max(1, Screen.height);
			}
		}
	}
	internal static class ProfilerGui
	{
		internal static bool ToggleLayout(ThemeManager theme, bool value, GUIContent content, float width, GUIStyle labelStyle = null, float verticalOffset = 1f)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			GUIStyle val = labelStyle ?? GUI.skin.label;
			float num = Mathf.Max(18f, val.lineHeight + 4f);
			Rect rect = GUILayoutUtility.GetRect(width, num, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(width),
				GUILayout.Height(num)
			});
			return Toggle(theme, rect, value, content, val, verticalOffset);
		}

		internal static bool Toggle(ThemeManager theme, Rect rect, bool value, GUIContent content, GUIStyle labelStyle = null, float verticalOffset = 1f)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Expected O, but got Unknown
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Expected O, but got Unknown
			GUIStyle val = labelStyle ?? GUI.skin.label;
			string text = ((content != null) ? content.tooltip : null) ?? string.Empty;
			GUIContent val2 = new GUIContent(string.Empty, text);
			bool flag = GUI.Toggle(rect, value, val2, GUIStyle.none);
			float num = theme?.CompactToggleSize ?? 10f;
			float num2 = Mathf.Ceil(Mathf.Max(0f, (((Rect)(ref rect)).height - num) * 0.5f));
			Rect val3 = default(Rect);
			((Rect)(ref val3))..ctor(((Rect)(ref rect)).x + 1f, ((Rect)(ref rect)).y + num2 + verticalOffset, num, num);
			GUI.Box(val3, new GUIContent(string.Empty, text), flag ? theme.CompactToggleOnStyle : theme.CompactToggleOffStyle);
			string text2 = ((content != null) ? content.text : null) ?? string.Empty;
			if (!string.IsNullOrEmpty(text2))
			{
				float num3 = ((Rect)(ref val3)).xMax + 4f;
				GUI.Label(new Rect(num3, ((Rect)(ref rect)).y, Mathf.Max(0f, ((Rect)(ref rect)).xMax - num3), ((Rect)(ref rect)).height), new GUIContent(text2, text), val);
			}
			return flag;
		}
	}
	internal sealed class ProfilerWindow : IDisposable
	{
		private readonly ConfigEntry<Vector2> _positionConfig;

		private readonly ConfigEntry<Vector2> _sizeConfig;

		private readonly object _layoutSync = new object();

		private bool _layoutChangePending;

		private Vector2 _pendingPosition;

		private Vector2 _pendingSize;

		internal string Key { get; }

		internal string Title { get; set; }

		internal int WindowId { get; }

		internal Rect DefaultRect { get; }

		internal Vector2 MinimumSize { get; }

		internal bool Resizable { get; }

		internal bool CenterWhenPositionIsNegative { get; }

		internal bool AllowTooltipOverflow { get; }

		internal Action<int> DrawContents { get; }

		internal WindowFunction WindowFunction { get; set; }

		internal bool RequestedVisible { get; set; }

		internal Rect Rect { get; set; }

		internal bool LayoutDirty { get; set; }

		internal float SaveAfterRealtime { get; set; }

		internal ProfilerWindow(string key, string title, Rect defaultRect, Vector2 minimumSize, bool resizable, bool requestedVisible, Action<int> drawContents, ConfigEntry<Vector2> positionConfig = null, ConfigEntry<Vector2> sizeConfig = null, bool centerWhenPositionIsNegative = false, bool allowTooltipOverflow = false)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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_009c: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			Key = key;
			Title = title;
			MinimumSize = minimumSize;
			Resizable = resizable;
			RequestedVisible = requestedVisible;
			DrawContents = drawContents ?? throw new ArgumentNullException("drawContents");
			_positionConfig = positionConfig;
			_sizeConfig = sizeConfig;
			CenterWhenPositionIsNegative = centerWhenPositionIsNegative;
			AllowTooltipOverflow = allowTooltipOverflow;
			Vector2 val = positionConfig?.Value ?? ((Rect)(ref defaultRect)).position;
			Vector2 val2 = ResolveConfiguredSize(sizeConfig?.Value ?? ((Rect)(ref defaultRect)).size, ((Rect)(ref defaultRect)).size);
			DefaultRect = new Rect(((Rect)(ref defaultRect)).position, ((Rect)(ref defaultRect)).size);
			Rect = new Rect(val, val2);
			WindowId = StableHash(key);
			if (_sizeConfig != null && (_sizeConfig.Value.x <= 0f || _sizeConfig.Value.y <= 0f))
			{
				_sizeConfig.Value = val2;
			}
			if (_positionConfig != null)
			{
				_positionConfig.SettingChanged += OnLayoutConfigChanged;
			}
			if (_sizeConfig != null)
			{
				_sizeConfig.SettingChanged += OnLayoutConfigChanged;
			}
		}

		internal void ApplyPendingLayoutChanges()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			Vector2 pendingPosition;
			Vector2 pendingSize;
			lock (_layoutSync)
			{
				if (!_layoutChangePending)
				{
					return;
				}
				pendingPosition = _pendingPosition;
				pendingSize = _pendingSize;
				_layoutChangePending = false;
			}
			Rect rect = Rect;
			if (_positionConfig != null)
			{
				((Rect)(ref rect)).position = pendingPosition;
			}
			if (_sizeConfig != null)
			{
				Rect defaultRect = DefaultRect;
				((Rect)(ref rect)).size = ResolveConfiguredSize(pendingSize, ((Rect)(ref defaultRect)).size);
			}
			Rect = rect;
			LayoutDirty = false;
		}

		internal void ResetLayoutToDefault()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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)
			Rect defaultRect = DefaultRect;
			if (_sizeConfig == null)
			{
				Rect rect = Rect;
				((Rect)(ref defaultRect)).size = ((Rect)(ref rect)).size;
			}
			Rect = defaultRect;
			LayoutDirty = false;
		}

		internal void SaveLayout()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			Rect rect;
			if (_positionConfig != null)
			{
				ConfigEntry<Vector2> positionConfig = _positionConfig;
				rect = Rect;
				positionConfig.Value = ((Rect)(ref rect)).position;
			}
			if (_sizeConfig != null)
			{
				ConfigEntry<Vector2> sizeConfig = _sizeConfig;
				rect = Rect;
				sizeConfig.Value = ((Rect)(ref rect)).size;
			}
			LayoutDirty = false;
		}

		public void Dispose()
		{
			if (_positionConfig != null)
			{
				_positionConfig.SettingChanged -= OnLayoutConfigChanged;
			}
			if (_sizeConfig != null)
			{
				_sizeConfig.SettingChanged -= OnLayoutConfigChanged;
			}
		}

		private void OnLayoutConfigChanged(object sender, EventArgs e)
		{
			//IL_002f: 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)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			lock (_layoutSync)
			{
				ConfigEntry<Vector2> positionConfig = _positionConfig;
				Rect rect;
				Vector2 pendingPosition;
				if (positionConfig == null)
				{
					rect = Rect;
					pendingPosition = ((Rect)(ref rect)).position;
				}
				else
				{
					pendingPosition = positionConfig.Value;
				}
				_pendingPosition = pendingPosition;
				ConfigEntry<Vector2> sizeConfig = _sizeConfig;
				Vector2 pendingSize;
				if (sizeConfig == null)
				{
					rect = Rect;
					pendingSize = ((Rect)(ref rect)).size;
				}
				else
				{
					pendingSize = sizeConfig.Value;
				}
				_pendingSize = pendingSize;
				_layoutChangePending = true;
			}
		}

		private static Vector2 ResolveConfiguredSize(Vector2 configured, Vector2 fallback)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			return new Vector2((configured.x > 0f) ? configured.x : fallback.x, (configured.y > 0f) ? configured.y : fallback.y);
		}

		private static int StableHash(string value)
		{
			uint num = 2166136261u;
			string text = value ?? string.Empty;
			foreach (char c in text)
			{
				num ^= c;
				num *= 16777619;
			}
			int num2 = (int)(num & 0x7FFFFFFF);
			return (num2 == 0) ? 1 : num2;
		}
	}
	internal sealed class ThemeManager
	{
		private readonly ValheimProfilerConfig _config;

		private GUISkin _sourceSkin;

		private GUISkin _runtimeSkin;

		private bool _dirty = true;

		private Texture2D _windowTexture;

		private Texture2D _borderTexture;

		private Texture2D _entryTexture;

		private Texture2D _buttonTexture;

		private Texture2D _buttonHoverTexture;

		private Texture2D _buttonActiveTexture;

		private Texture2D _accentTexture;

		private Texture2D _accentHoverTexture;

		private Texture2D _scrollbarTrackTexture;

		private Texture2D _tooltipTexture;

		private Texture2D _toggleOffTexture;

		private Texture2D _toggleOnTexture;

		private Texture2D _toggleOffHoverTexture;

		private Texture2D _toggleOnHoverTexture;

		private GUIStyle _accentButtonStyle;

		private GUIStyle _accentLabelStyle;

		private GUIStyle _tooltipStyle;

		private GUIStyle _resizeHandleStyle;

		private GUIStyle _compactToggleOffStyle;

		private GUIStyle _compactToggleOnStyle;

		internal Color TextColor => _config.TextColor.Value;

		internal Color HeaderTextColor => _config.HeaderTextColor.Value;

		internal Color AccentColor => _config.AccentColor.Value;

		internal GUISkin Skin
		{
			get
			{
				EnsureStyles();
				return _runtimeSkin ?? GUI.skin;
			}
		}

		internal Texture2D WindowTexture
		{
			get
			{
				EnsureStyles();
				return _windowTexture;
			}
		}

		internal Texture2D BorderTexture
		{
			get
			{
				EnsureStyles();
				return _borderTexture;
			}
		}

		internal GUIStyle AccentButtonStyle
		{
			get
			{
				EnsureStyles();
				return _accentButtonStyle ?? GUI.skin.button;
			}
		}

		internal GUIStyle AccentLabelStyle
		{
			get
			{
				EnsureStyles();
				return _accentLabelStyle ?? GUI.skin.label;
			}
		}

		internal GUIStyle TooltipStyle
		{
			get
			{
				EnsureStyles();
				return _tooltipStyle ?? GUI.skin.box;
			}
		}

		internal GUIStyle ResizeHandleStyle
		{
			get
			{
				EnsureStyles();
				return _resizeHandleStyle ?? GUI.skin.box;
			}
		}

		internal GUIStyle CompactToggleOffStyle
		{
			get
			{
				EnsureStyles();
				return _compactToggleOffStyle ?? GUI.skin.box;
			}
		}

		internal GUIStyle CompactToggleOnStyle
		{
			get
			{
				EnsureStyles();
				return _compactToggleOnStyle ?? GUI.skin.box;
			}
		}

		internal float CompactToggleSize
		{
			get
			{
				EnsureStyles();
				return Mathf.Clamp((float)_config.FontSize.Value - 2f, 9f, 16f);
			}
		}

		internal ThemeManager(ValheimProfilerConfig config)
		{
			_config = config;
			_config.FontSize.SettingChanged += OnThemeChanged;
			_config.WindowBackground.SettingChanged += OnThemeChanged;
			_config.WindowBorder.SettingChanged += OnThemeChanged;
			_config.EntryBackground.SettingChanged += OnThemeChanged;
			_config.TextColor.SettingChanged += OnThemeChanged;
			_config.HeaderTextColor.SettingChanged += OnThemeChanged;
			_config.ButtonBackground.SettingChanged += OnThemeChanged;
			_config.ButtonTextColor.SettingChanged += OnThemeChanged;
			_config.AccentColor.SettingChanged += OnThemeChanged;
		}

		internal void EnsureStyles()
		{
			GUISkin skin = GUI.skin;
			if (_dirty || !((Object)(object)_runtimeSkin != (Object)null) || (!((Object)(object)_sourceSkin == (Object)(object)skin) && !((Object)(object)_runtimeSkin == (Object)(object)skin)))
			{
				Rebuild(((Object)(object)skin == (Object)(object)_runtimeSkin) ? _sourceSkin : skin);
			}
		}

		internal void Shutdown()
		{
			_config.FontSize.SettingChanged -= OnThemeChanged;
			_config.WindowBackground.SettingChanged -= OnThemeChanged;
			_config.WindowBorder.SettingChanged -= OnThemeChanged;
			_config.EntryBackground.SettingChanged -= OnThemeChanged;
			_config.TextColor.SettingChanged -= OnThemeChanged;
			_config.HeaderTextColor.SettingChanged -= OnThemeChanged;
			_config.ButtonBackground.SettingChanged -= OnThemeChanged;
			_config.ButtonTextColor.SettingChanged -= OnThemeChanged;
			_config.AccentColor.SettingChanged -= OnThemeChanged;
			DestroyResources();
		}

		private void OnThemeChanged(object sender, EventArgs e)
		{
			_dirty = true;
		}

		private void Rebuild(GUISkin baseSkin)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: 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_0099: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: 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_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: 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_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: 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_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: 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_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Expected O, but got Unknown
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Expected O, but got Unknown
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_0320: Expected O, but got Unknown
			//IL_0347: Unknown result type (might be due to invalid IL or missing references)
			//IL_0351: Expected O, but got Unknown
			//IL_0361: Unknown result type (might be due to invalid IL or missing references)
			//IL_036b: Expected O, but got Unknown
			//IL_037b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0385: Expected O, but got Unknown
			//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b6: Expected O, but got Unknown
			//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d0: Expected O, but got Unknown
			//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ea: Expected O, but got Unknown
			//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0404: Expected O, but got Unknown
			//IL_0414: Unknown result type (might be due to invalid IL or missing references)
			//IL_041e: Expected O, but got Unknown
			//IL_042e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0438: Expected O, but got Unknown
			//IL_0448: Unknown result type (might be due to invalid IL or missing references)
			//IL_0452: Expected O, but got Unknown
			//IL_0462: Unknown result type (might be due to invalid IL or missing references)
			//IL_046c: Expected O, but got Unknown
			//IL_0498: Unknown result type (might be due to invalid IL or missing references)
			//IL_049d: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ae: Expected O, but got Unknown
			//IL_0528: Unknown result type (might be due to invalid IL or missing references)
			//IL_052d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0539: Unknown result type (might be due to invalid IL or missing references)
			//IL_0541: Unknown result type (might be due to invalid IL or missing references)
			//IL_054e: Expected O, but got Unknown
			//IL_0554: Unknown result type (might be due to invalid IL or missing references)
			//IL_055a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0573: Unknown result type (might be due to invalid IL or missing references)
			//IL_0578: Unknown result type (might be due to invalid IL or missing references)
			//IL_0584: Unknown result type (might be due to invalid IL or missing references)
			//IL_058c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0594: Unknown result type (might be due to invalid IL or missing references)
			//IL_059c: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ad: Expected O, but got Unknown
			//IL_05ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05bd: Expected O, but got Unknown
			//IL_05be: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05cd: Expected O, but got Unknown
			//IL_05d3: Expected O, but got Unknown
			//IL_05d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0601: Unknown result type (might be due to invalid IL or missing references)
			//IL_0606: Unknown result type (might be due to invalid IL or missing references)
			//IL_0612: Unknown result type (might be due to invalid IL or missing references)
			//IL_0617: Unknown result type (might be due to invalid IL or missing references)
			//IL_0621: Expected O, but got Unknown
			//IL_0622: Unknown result type (might be due to invalid IL or missing references)
			//IL_0627: Unknown result type (might be due to invalid IL or missing references)
			//IL_0631: Expected O, but got Unknown
			//IL_0632: Unknown result type (might be due to invalid IL or missing references)
			//IL_0637: Unknown result type (might be due to invalid IL or missing references)
			//IL_0641: Expected O, but got Unknown
			//IL_0647: Expected O, but got Unknown
			//IL_0693: Unknown result type (might be due to invalid IL or missing references)
			//IL_0698: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b3: Expected O, but got Unknown
			//IL_06b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c3: Expected O, but got Unknown
			//IL_06c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d3: Expected O, but got Unknown
			//IL_06d9: Expected O, but got Unknown
			//IL_0720: Unknown result type (might be due to invalid IL or missing references)
			//IL_0725: Unknown result type (might be due to invalid IL or missing references)
			//IL_0731: Unknown result type (might be due to invalid IL or missing references)
			//IL_0736: Unknown result type (might be due to invalid IL or missing references)
			//IL_0740: Expected O, but got Unknown
			//IL_0746: Expected O, but got Unknown
			DestroyResources();
			_sourceSkin = baseSkin;
			if (!((Object)(object)baseSkin == (Object)null))
			{
				Color value = _config.WindowBackground.Value;
				Color value2 = _config.EntryBackground.Value;
				Color value3 = _config.ButtonBackground.Value;
				Color value4 = _config.AccentColor.Value;
				_windowTexture = CreateTexture(value);
				_borderTexture = CreateTexture(_config.WindowBorder.Value);
				_entryTexture = CreateTexture(value2);
				_buttonTexture = CreateTexture(value3);
				_buttonHoverTexture = CreateTexture(Lighten(value3, 0.12f));
				_buttonActiveTexture = CreateTexture(Darken(value4, 0.1f));
				_accentTexture = CreateTexture(value4);
				_accentHoverTexture = CreateTexture(Lighten(value4, 0.12f));
				_scrollbarTrackTexture = CreateTexture(Darken(value2, 0.08f));
				_tooltipTexture = CreateTexture(new Color(value2.r, value2.g, value2.b, 1f));
				Color val = CreateNeutralToggleColor(value2, value3);
				Color value5 = _config.WindowBorder.Value;
				_toggleOffTexture = CreateBorderedTexture(val, value5);
				_toggleOnTexture = CreateBorderedTexture(value4, value5);
				_toggleOffHoverTexture = CreateBorderedTexture(Lighten(val, 0.12f), Lighten(value5, 0.2f));
				_toggleOnHoverTexture = CreateBorderedTexture(Lighten(value4, 0.12f), Lighten(value5, 0.2f));
				_runtimeSkin = Object.Instantiate<GUISkin>(baseSkin);
				((Object)_runtimeSkin).name = "ValheimProfilerSkin";
				((Object)_runtimeSkin).hideFlags = (HideFlags)61;
				int fontSize = Mathf.Clamp(_config.FontSize.Value, 9, 28);
				Color value6 = _config.TextColor.Value;
				Color value7 = _config.HeaderTextColor.Value;
				Color value8 = _config.ButtonTextColor.Value;
				ConfigureTextStyle(_runtimeSkin.label, value6, fontSize);
				ConfigureTextStyle(_runtimeSkin.box, value6, fontSize);
				ConfigureTextStyle(_runtimeSkin.window, value7, fontSize);
				ConfigureTextStyle(_runtimeSkin.button, value8, fontSize);
				ConfigureTextStyle(_runtimeSkin.toggle, value6, fontSize);
				ConfigureTextStyle(_runtimeSkin.textField, value6, fontSize);
				ConfigureTextStyle(_runtimeSkin.textArea, value6, fontSize);
				SetAllBackgrounds(_runtimeSkin.window, _windowTexture);
				_runtimeSkin.window.padding = new RectOffset(4, 4, 21, 4);
				_runtimeSkin.window.margin = new RectOffset(0, 0, 0, 0);
				_runtimeSkin.window.border = new RectOffset(0, 0, 0, 0);
				SetAllBackgrounds(_runtimeSkin.box, _entryTexture);
				_runtimeSkin.box.padding = new RectOffset(4, 4, 3, 3);
				_runtimeSkin.box.margin = new RectOffset(1, 1, 1, 1);
				_runtimeSkin.box.border = new RectOffset(0, 0, 0, 0);
				SetAllBackgrounds(_runtimeSkin.textField, _entryTexture);
				_runtimeSkin.textField.padding = new RectOffset(4, 4, 1, 1);
				_runtimeSkin.textField.margin = new RectOffset(1, 1, 1, 1);
				_runtimeSkin.textField.border = new RectOffset(0, 0, 0, 0);
				_runtimeSkin.button.padding = new RectOffset(5, 5, 2, 2);
				_runtimeSkin.button.margin = new RectOffset(2, 2, 1, 1);
				_runtimeSkin.button.border = new RectOffset(0, 0, 0, 0);
				_runtimeSkin.toggle.margin = new RectOffset(1, 1, 1, 1);
				_runtimeSkin.label.margin = new RectOffset(1, 1, 0, 0);
				SetButtonBackgrounds(_runtimeSkin.button);
				ConfigureSquareScrollbars(_runtimeSkin);
				_accentButtonStyle = new GUIStyle(_runtimeSkin.button)
				{
					name = "ValheimProfilerAccentButton"
				};
				SetAllBackgrounds(_accentButtonStyle, _accentTexture);
				_accentButtonStyle.hover.background = _accentHoverTexture;
				_accentButtonStyle.onHover.background = _accentHoverTexture;
				_accentButtonStyle.active.background = _buttonActiveTexture;
				_accentButtonStyle.onActive.background = _buttonActiveTexture;
				_accentLabelStyle = new GUIStyle(_runtimeSkin.label)
				{
					name = "ValheimProfilerAccentLabel",
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)3
				};
				ConfigureTextStyle(_accentLabelStyle, Lighten(value4, 0.35f), fontSize);
				_tooltipStyle = new GUIStyle(_runtimeSkin.box)
				{
					name = "ValheimProfilerTooltip",
					wordWrap = true,
					richText = false,
					alignment = (TextAnchor)3,
					padding = new RectOffset(10, 10, 5, 5),
					margin = new RectOffset(0, 0, 0, 0),
					border = new RectOffset(0, 0, 0, 0)
				};
				ConfigureTextStyle(_tooltipStyle, value6, fontSize);
				SetAllBackgrounds(_tooltipStyle, _tooltipTexture);
				_resizeHandleStyle = new GUIStyle(_runtimeSkin.box)
				{
					name = "ValheimProfilerResizeHandle",
					padding = new RectOffset(0, 0, 0, 0),
					margin = new RectOffset(0, 0, 0, 0),
					border = new RectOffset(0, 0, 0, 0)
				};
				SetAllBackgrounds(_resizeHandleStyle, _accentTexture);
				_resizeHandleStyle.hover.background = _accentHoverTexture;
				_resizeHandleStyle.active.background = _buttonActiveTexture;
				_compactToggleOffStyle = new GUIStyle(_runtimeSkin.box)
				{
					name = "ValheimProfilerCompactToggleOff",
					padding = new RectOffset(0, 0, 0, 0),
					margin = new RectOffset(0, 0, 0, 0),
					border = new RectOffset(1, 1, 1, 1)
				};
				SetAllBackgrounds(_compactToggleOffStyle, _toggleOffTexture);
				_compactToggleOffStyle.hover.background = _toggleOffHoverTexture;
				_compactToggleOffStyle.active.background = _toggleOffHoverTexture;
				_compactToggleOnStyle = new GUIStyle(_compactToggleOffStyle)
				{
					name = "ValheimProfilerCompactToggleOn",
					border = new RectOffset(1, 1, 1, 1)
				};
				SetAllBackgrounds(_compactToggleOnStyle, _toggleOnTexture);
				_compactToggleOnStyle.hover.background = _toggleOnHoverTexture;
				_compactToggleOnStyle.active.background = _toggleOnHoverTexture;
				_dirty = false;
			}
		}

		private void ConfigureSquareScrollbars(GUISkin skin)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			if (skin.scrollView != null)
			{
				RectOffset padding = skin.scrollView.padding;
				skin.scrollView.padding = new RectOffset((padding != null) ? padding.left : 0, Mathf.Max(1, (padding != null) ? padding.right : 0), (padding != null) ? padding.top : 0, (padding != null) ? padding.bottom : 0);
			}
			ConfigureScrollbarTrack(skin.horizontalScrollbar, horizontal: true, 13f);
			ConfigureScrollbarTrack(skin.verticalScrollbar, horizontal: false, 13f);
			ConfigureScrollbarThumb(skin.horizontalScrollbarThumb, horizontal: true, 13f);
			ConfigureScrollbarThumb(skin.verticalScrollbarThumb, horizontal: false, 13f);
			HideScrollbarButton(skin.horizontalScrollbarLeftButton);
			HideScrollbarButton(skin.horizontalScrollbarRightButton);
			HideScrollbarButton(skin.verticalScrollbarUpButton);
			HideScrollbarButton(skin.verticalScrollbarDownButton);
		}

		private void ConfigureScrollbarTrack(GUIStyle style, bool horizontal, float size)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			if (style != null)
			{
				SetAllBackgrounds(style, _scrollbarTrackTexture);
				style.border = new RectOffset(0, 0, 0, 0);
				style.margin = (horizontal ? new RectOffset(0, 0, 0, 0) : new RectOffset(0, 1, 0, 0));
				style.padding = new RectOffset(0, 0, 0, 0);
				if (horizontal)
				{
					style.fixedHeight = size;
				}
				else
				{
					style.fixedWidth = size;
				}
			}
		}

		private void ConfigureScrollbarThumb(GUIStyle style, bool horizontal, float size)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			if (style != null)
			{
				SetAllBackgrounds(style, _accentTexture);
				style.hover.background = _accentHoverTexture;
				style.active.background = _buttonActiveTexture;
				style.border = new RectOffset(0, 0, 0, 0);
				style.margin = new RectOffset(1, 1, 1, 1);
				style.padding = new RectOffset(0, 0, 0, 0);
				if (horizontal)
				{
					style.fixedHeight = Mathf.Max(1f, size - 2f);
				}
				else
				{
					style.fixedWidth = Mathf.Max(1f, size - 2f);
				}
			}
		}

		private static void HideScrollbarButton(GUIStyle style)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			if (style != null)
			{
				SetAllBackgrounds(style, null);
				style.border = new RectOffset(0, 0, 0, 0);
				style.margin = new RectOffset(0, 0, 0, 0);
				style.padding = new RectOffset(0, 0, 0, 0);
				style.fixedWidth = 0f;
				style.fixedHeight = 0f;
				style.stretchWidth = false;
				style.stretchHeight = false;
			}
		}

		private void SetButtonBackgrounds(GUIStyle style)
		{
			if (style != null)
			{
				style.normal.background = _buttonTexture;
				style.onNormal.background = _accentTexture;
				style.hover.background = _buttonHoverTexture;
				style.onHover.background = _buttonHoverTexture;
				style.active.background = _buttonActiveTexture;
				style.onActive.background = _buttonActiveTexture;
				style.focused.background = _buttonTexture;
				style.onFocused.background = _accentTexture;
			}
		}

		private static void SetAllBackgrounds(GUIStyle style, Texture2D texture)
		{
			if (style != null)
			{
				style.normal.background = texture;
				style.hover.background = texture;
				style.active.background = texture;
				style.focused.background = texture;
				style.onNormal.background = texture;
				style.onHover.background = texture;
				style.onActive.background = texture;
				style.onFocused.background = texture;
			}
		}

		private static void ConfigureTextStyle(GUIStyle style, Color color, int fontSize)
		{
			//IL_0019: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_0067: 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)
			if (style != null)
			{
				style.fontSize = fontSize;
				SetTextColor(style.normal, color);
				SetTextColor(style.hover, color);
				SetTextColor(style.active, color);
				SetTextColor(style.focused, color);
				SetTextColor(style.onNormal, color);
				SetTextColor(style.onHover, color);
				SetTextColor(style.onActive, color);
				SetTextColor(style.onFocused, color);
			}
		}

		private static void SetTextColor(GUIStyleState state, Color color)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			if (state != null)
			{
				state.textColor = color;
			}
		}

		private static Texture2D CreateTexture(Color color)
		{
			//IL_0005: 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_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false)
			{
				hideFlags = (HideFlags)61,
				name = "ValheimProfilerColor"
			};
			val.SetPixel(0, 0, color);
			val.Apply(false, true);
			return val;
		}

		private static Texture2D CreateBorderedTexture(Color fill, Color border)
		{
			//IL_0005: 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_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_003d: 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)
			Texture2D val = new Texture2D(3, 3, (TextureFormat)4, false)
			{
				hideFlags = (HideFlags)61,
				name = "ValheimProfilerBorderedColor"
			};
			for (int i = 0; i < 3; i++)
			{
				for (int j = 0; j < 3; j++)
				{
					val.SetPixel(j, i, (j == 0 || i == 0 || j == 2 || i == 2) ? border : fill);
				}
			}
			val.Apply(false, true);
			return val;
		}

		private static Color Lighten(Color color, float amount)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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)
			return new Color(Mathf.Lerp(color.r, 1f, amount), Mathf.Lerp(color.g, 1f, amount), Mathf.Lerp(color.b, 1f, amount), color.a);
		}

		private static Color Darken(Color color, float amount)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			return new Color(color.r * (1f - amount), color.g * (1f - amount), color.b * (1f - amount), color.a);
		}

		private static Color CreateNeutralToggleColor(Color entry, Color button)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: 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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			Color val = Color.Lerp(entry, button, 0.55f);
			float num = val.r * 0.299f + val.g * 0.587f + val.b * 0.114f;
			num = Mathf.Lerp(num, 1f, 0.08f);
			return new Color(num, num, num, 1f);
		}

		private void DestroyResources()
		{
			Destroy((Object)(object)_runtimeSkin);
			Destroy((Object)(object)_windowTexture);
			Destroy((Object)(object)_borderTexture);
			Destroy((Object)(object)_entryTexture);
			Destroy((Object)(object)_buttonTexture);
			Destroy((Object)(object)_buttonHoverTexture);
			Destroy((Object)(object)_buttonActiveTexture);
			Destroy((Object)(object)_accentTexture);
			Destroy((Object)(object)_accentHoverTexture);
			Destroy((Object)(object)_scrollbarTrackTexture);
			Destroy((Object)(object)_tooltipTexture);
			Destroy((Object)(object)_toggleOffTexture);
			Destroy((Object)(object)_toggleOnTexture);
			Destroy((Object)(object)_toggleOffHoverTexture);
			Destroy((Object)(object)_toggleOnHoverTexture);
			_runtimeSkin = null;
			_windowTexture = null;
			_borderTexture = null;
			_entryTexture = null;
			_buttonTexture = null;
			_buttonHoverTexture = null;
			_buttonActiveTexture = null;
			_accentTexture = null;
			_accentHoverTexture = null;
			_scrollbarTrackTexture = null;
			_tooltipTexture = null;
			_toggleOffTexture = null;
			_toggleOnTexture = null;
			_toggleOffHoverTexture = null;
			_toggleOnHoverTexture = null;
			_accentButtonStyle = null;
			_accentLabelStyle = null;
			_tooltipStyle = null;
			_resizeHandleStyle = null;
			_compactToggleOffStyle = null;
			_compactToggleOnStyle = null;
		}

		private static void Destroy(Object value)
		{
			if (value != (Object)null)
			{
				Object.Destroy(value);
			}
		}
	}
	internal sealed class TooltipManager
	{
		private const float PointerOffsetY = 25f;

		private const float MaxAbsoluteWidth = 620f;

		private const float MaxRelativeWidth = 0.8f;

		private const float ExtraHeight = 10f;

		private readonly ThemeManager _theme;

		internal TooltipManager(ThemeManager theme)
		{
			_theme = theme;
		}

		internal void Draw(Rect area)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Draw(GUI.tooltip, Event.current.mousePosition, area);
		}

		internal void Draw(string rawTooltip, Vector2 pointerPosition, Rect area)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			//IL_00fd: 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_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: 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)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrEmpty(rawTooltip))
			{
				return;
			}
			GUIStyle tooltipStyle = _theme.TooltipStyle;
			if (tooltipStyle != null)
			{
				string text = rawTooltip.Replace("\r\n", "\n").Replace('\r', '\n');
				GUIContent val = new GUIContent(text);
				float num = 0f;
				string[] array = text.Split(new char[1] { '\n' });
				float num2 = default(float);
				float num3 = default(float);
				for (int i = 0; i < array.Length; i++)
				{
					tooltipStyle.CalcMinMaxWidth(new GUIContent(array[i]), ref num2, ref num3);
					num = Mathf.Max(num, num3);
				}
				float num4 = Mathf.Max(1f, Mathf.Min(620f, ((Rect)(ref area)).width * 0.8f));
				num = Mathf.Clamp(num + 2f, 1f, num4);
				float num5 = Mathf.Min(tooltipStyle.CalcHeight(val, num) + 10f, Mathf.Max(1f, ((Rect)(ref area)).height));
				float num6 = ((pointerPosition.x + num > ((Rect)(ref area)).xMax) ? (((Rect)(ref area)).xMax - num) : pointerPosition.x);
				float num7 = ((pointerPosition.y + 25f + num5 > ((Rect)(ref area)).yMax) ? (pointerPosition.y - num5) : (pointerPosition.y + 25f));
				num6 = Mathf.Clamp(num6, ((Rect)(ref area)).xMin, Mathf.Max(((Rect)(ref area)).xMin, ((Rect)(ref area)).xMax - num));
				num7 = Mathf.Clamp(num7, ((Rect)(ref area)).yMin, Mathf.Max(((Rect)(ref area)).yMin, ((Rect)(ref area)).yMax - num5));
				GUI.Box(new Rect(num6, num7, num, num5), text, tooltipStyle);
			}
		}
	}
	internal sealed class WindowManager
	{
		internal const float DefaultToolWindowWidthFraction = 0.75f;

		internal const float DefaultCompactWindowWidthFraction = 0.25f;

		private const float TitleBarHeight = 22f;

		private const float ResizeEdgeHitSize = 4f;

		private const float ResizeHandleHitSize = 12f;

		private const float ResizeHandleVisualSize = 8f;

		private const float WindowBorderWidth = 1f;

		private const float LayoutSaveDelay = 0.5f;

		private readonly ValheimProfilerConfig _config;

		private readonly GuiScaleController _scale;

		private readonly ThemeManager _theme;

		private readonly TooltipManager _tooltips;

		private readonly List<ProfilerWindow> _windows = new List<ProfilerWindow>();

		private ProfilerWindow _resizingWindow;

		private Vector2 _resizeStartMouse;

		private Rect _resizeStartRect;

		private bool _resizeWidth;

		private bool _resizeHeight;

		private int _bringToFrontId;

		private bool _resetLayoutRequested;

		private string _overflowTooltip = string.Empty;

		private Vector2 _overflowTooltipPointer;

		internal IReadOnlyList<ProfilerWindow> Windows => _windows;

		internal bool HasRequestedVisibleWindows
		{
			get
			{
				for (int i = 0; i < _windows.Count; i++)
				{
					if (_windows[i].RequestedVisible)
					{
						return true;
					}
				}
				return false;
			}
		}

		internal WindowManager(ValheimProfilerConfig config, GuiScaleController scale, ThemeManager theme, TooltipManager tooltips)
		{
			_config = config;
			_scale = scale;
			_theme = theme;
			_tooltips = tooltips;
		}

		internal Vector2 GetDefaultToolWindowSize(float preferredHeight, Vector2 minimumSize)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return GetDefaultWindowSize(preferredHeight, minimumSize, 0.75f);
		}

		internal Vector2 GetDefaultCompactWindowSize(float preferredHeight, Vector2 minimumSize)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return GetDefaultWindowSize(preferredHeight, minimumSize, 0.25f);
		}

		private Vector2 GetDefaultWindowSize(float preferredHeight, Vector2 minimumSize, float widthFraction)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Max(minimumSize.x, _scale.LogicalWidth * widthFraction);
			float num2 = Mathf.Clamp(preferredHeight, minimumSize.y, Mathf.Max(minimumSize.y, _scale.LogicalHeight * 0.9f));
			return new Vector2(num, num2);
		}

		internal ProfilerWindow Register(ProfilerWindow window)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			if (window == null)
			{
				throw new ArgumentNullException("window");
			}
			window.WindowFunction = (WindowFunction)delegate(int id)
			{
				DrawWindow(window, id);
			};
			_windows.Add(window);
			return window;
		}

		internal void BringToFront(ProfilerWindow window)
		{
			if (window != null)
			{
				_bringToFrontId = window.WindowId;
			}
		}

		internal void DrawAll()
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			_overflowTooltip = string.Empty;
			if (_resetLayoutRequested)
			{
				ResetLayoutNow();
			}
			for (int i = 0; i < _windows.Count; i++)
			{
				ProfilerWindow profilerWindow = _windows[i];
				profilerWindow.ApplyPendingLayoutChanges();
				if (profilerWindow.RequestedVisible)
				{
					ResolveInitialPosition(profilerWindow);
					profilerWindow.Rect = ClampRect(profilerWindow, profilerWindow.Rect);
					Rect rect = profilerWindow.Rect;
					profilerWindow.Rect = GUI.Window(profilerWindow.WindowId, profilerWindow.Rect, profilerWindow.WindowFunction, profilerWindow.Title, GUI.skin.window);
					profilerWindow.Rect = ClampRect(profilerWindow, profilerWindow.Rect);
					if (RectChanged(rect, profilerWindow.Rect))
					{
						MarkLayoutDirty(profilerWindow);
					}
				}
			}
			if (_bringToFrontId != 0)
			{
				GUI.BringWindowToFront(_bringToFrontId);
				_bringToFrontId = 0;
			}
			if (!string.IsNullOrEmpty(_overflowTooltip))
			{
				_tooltips.Draw(_overflowTooltip, _overflowTooltipPointer, new Rect(0f, 0f, _scale.LogicalWidth, _scale.LogicalHeight));
			}
		}

		internal void RequestResetLayout()
		{
			_resetLayoutRequested = true;
		}

		internal void UpdatePersistence()
		{
			if (_resizingWindow != null && !UnityInput.Current.GetKey((KeyCode)323))
			{
				ClearResizeState();
			}
			float realtimeSinceStartup = Time.realtimeSinceStartup;
			bool flag = false;
			for (int i = 0; i < _windows.Count; i++)
			{
				ProfilerWindow profilerWindow = _windows[i];
				profilerWindow.ApplyPendingLayoutChanges();
				if (profilerWindow.LayoutDirty && !(realtimeSinceStartup < profilerWindow.SaveAfterRealtime))
				{
					profilerWindow.SaveLayout();
					flag = true;
				}
			}
			if (flag)
			{
				_config.ConfigFile.Save();
			}
		}

		internal void SaveAll()
		{
			for (int i = 0; i < _windows.Count; i++)
			{
				_windows[i].SaveLayout();
			}
			_config.ConfigFile.Save();
		}

		internal void Shutdown()
		{
			for (int i = 0; i < _windows.Count; i++)
			{
				_windows[i].Dispose();
			}
			_windows.Clear();
			ClearResizeState();
		}

		private void ResetLayoutNow()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			_resetLayoutRequested = false;
			ClearResizeState();
			for (int i = 0; i < _windows.Count; i++)
			{
				ProfilerWindow profilerWindow = _windows[i];
				profilerWindow.ResetLayoutToDefault();
				ResolveInitialPosition(profilerWindow);
				profilerWindow.Rect = ClampRect(profilerWindow, profilerWindow.Rect);
				profilerWindow.SaveLayout();
			}
			_config.ConfigFile.Save();
		}

		private void DrawWindow(ProfilerWindow window, int id)
		{
			//IL_001f: 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_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: 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_00b7: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			_theme.EnsureStyles();
			GUI.tooltip = string.Empty;
			Event current = Event.current;
			Vector2 mousePosition = current.mousePosition;
			bool flag = TryApplyRealtimeMousePosition(window, current);
			try
			{
				HandleResizeInput(window);
				try
				{
					window.DrawContents(id);
				}
				catch (Exception ex)
				{
					GUILayout.Label("Window error: " + ex.GetType().Name + ": " + ex.Message, Array.Empty<GUILayoutOption>());
				}
				DrawWindowBorder(window);
				DrawResizeHandle(window);
				Rect rect;
				if (window.AllowTooltipOverflow)
				{
					string tooltip = GUI.tooltip;
					if (!string.IsNullOrEmpty(tooltip))
					{
						_overflowTooltip = tooltip;
						rect = window.Rect;
						_overflowTooltipPointer = ((Rect)(ref rect)).position + current.mousePosition;
					}
				}
				else
				{
					TooltipManager tooltips = _tooltips;
					rect = window.Rect;
					float width = ((Rect)(ref rect)).width;
					rect = window.Rect;
					tooltips.Draw(new Rect(0f, 0f, width, ((Rect)(ref rect)).height));
				}
				rect = window.Rect;
				GUI.DragWindow(new Rect(0f, 0f, Mathf.Max(0f, ((Rect)(ref rect)).width - 4f), 22f));
			}
			finally
			{
				if (flag)
				{
					current.mousePosition = mousePosition;
				}
			}
		}

		private bool TryApplyRealtimeMousePosition(ProfilerWindow window, Event current)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Invalid comparison between Unknown and I4
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Invalid comparison between Unknown and I4
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			if (window == null || current == null)
			{
				return false;
			}
			if ((int)current.type != 7 && (int)current.type != 8)
			{
				return false;
			}
			Vector2 logicalMousePosition = _scale.GetLogicalMousePosition();
			Rect rect = window.Rect;
			Vector2 val = logicalMousePosition - ((Rect)(ref rect)).position;
			if (!IsFinite(val.x) || !IsFinite(val.y))
			{
				return false;
			}
			current.mousePosition = val;
			return true;
		}

		private static bool IsFinite(float value)
		{
			return !float.IsNaN(value) && !float.IsInfinity(value);
		}

		private void HandleResizeInput(ProfilerWindow window)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: 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_00e3: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Invalid comparison between Unknown and I4
			if (!window.Resizable)
			{
				return;
			}
			Event current = Event.current;
			Vector2 mousePosition = current.mousePosition;
			Rect resizeHandleHitRect = GetResizeHandleHitRect(window);
			bool flag = ((Rect)(ref resizeHandleHitRect)).Contains(mousePosition);
			Rect rect;
			int num;
			if (!flag)
			{
				float x = mousePosition.x;
				rect = window.Rect;
				if (x >= ((Rect)(ref rect)).width - 4f)
				{
					float x2 = mousePosition.x;
					rect = window.Rect;
					if (x2 <= ((Rect)(ref rect)).width && mousePosition.y >= 22f)
					{
						num = ((mousePosition.y < ((Rect)(ref resizeHandleHitRect)).yMin) ? 1 : 0);
						goto IL_0088;
					}
				}
			}
			num = 0;
			goto IL_0088;
			IL_00e0:
			int num2;
			bool flag2 = (byte)num2 != 0;
			bool flag3;
			if ((int)current.type == 0 && current.button == 0 && (flag || flag3 || flag2))
			{
				_resizingWindow = window;
				_resizeStartMouse = _scale.GetLogicalMousePosition();
				_resizeStartRect = window.Rect;
				_resizeWidth = flag || flag3;
				_resizeHeight = flag || flag2;
				current.Use();
			}
			if (_resizingWindow != window)
			{
				return;
			}
			if (UnityInput.Current.GetKey((KeyCode)323))
			{
				Vector2 val = _scale.GetLogicalMousePosition() - _resizeStartMouse;
				Rect resizeStartRect = _resizeStartRect;
				if (_resizeWidth)
				{
					((Rect)(ref resizeStartRect)).width = ((Rect)(ref _resizeStartRect)).width + val.x;
				}
				if (_resizeHeight)
				{
					((Rect)(ref resizeStartRect)).height = ((Rect)(ref _resizeStartRect)).height + val.y;
				}
				window.Rect = ClampRect(window, resizeStartRect);
				MarkLayoutDirty(window);
				EventType type = current.type;
				if (((int)type == 0 || (int)type == 3) ? true : false)
				{
					current.Use();
				}
			}
			if (UnityInput.Current.GetKeyUp((KeyCode)323))
			{
				ClearResizeState();
			}
			return;
			IL_0088:
			flag3 = (byte)num != 0;
			if (!flag)
			{
				float y = mousePosition.y;
				rect = window.Rect;
				if (y >= ((Rect)(ref rect)).height - 4f)
				{
					float y2 = mousePosition.y;
					rect = window.Rect;
					if (y2 <= ((Rect)(ref rect)).height && mousePosition.x >= 0f)
					{
						num2 = ((mousePosition.x < ((Rect)(ref resizeHandleHitRect)).xMin) ? 1 : 0);
						goto IL_00e0;
					}
				}
			}
			num2 = 0;
			goto IL_00e0;
		}

		private void DrawWindowBorder(ProfilerWindow window)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to i