Decompiled source of ScoutExpressions v0.2.5

plugins/ScoutExpressions.dll

Decompiled 17 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Photon.Pun;
using Photon.Realtime;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.LowLevel;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using Zorro.Core.CLI;
using Zorro.UI.Modal;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Retro Tsunami")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.5.0")]
[assembly: AssemblyInformationalVersion("0.2.5")]
[assembly: AssemblyProduct("ScoutExpressions")]
[assembly: AssemblyTitle("ScoutExpressions")]
[assembly: AssemblyVersion("0.2.5.0")]
namespace ScoutExpressions;

internal enum IdleReceiver
{
	Unavailable,
	Standard,
	WithMessageInfo
}
internal static class IdleProtocol
{
	internal const string Message = "SetCharacterIdle_RPC";

	internal static IdleReceiver Detect(Type customization)
	{
		if (Matches(new Type[2]
		{
			typeof(int),
			typeof(PhotonMessageInfo)
		}))
		{
			return IdleReceiver.WithMessageInfo;
		}
		if (Matches(new Type[1] { typeof(int) }))
		{
			return IdleReceiver.Standard;
		}
		return IdleReceiver.Unavailable;
		bool Matches(Type[] parameters)
		{
			MethodInfo method = customization.GetMethod("SetCharacterIdle_RPC", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, parameters, null);
			if (method != null && method.ReturnType == typeof(void))
			{
				return method.IsDefined(typeof(PunRPC), inherit: false);
			}
			return false;
		}
	}
}
internal sealed class NativePortraits : IDisposable
{
	private readonly WheelRenderer wheel;

	private readonly ManualLogSource log;

	private readonly Texture2D[] tiles = (Texture2D[])(object)new Texture2D[8];

	private readonly bool[] attempted = new bool[8];

	private readonly HashSet<ulong> fingerprints = new HashSet<ulong>();

	private PassportStudio studio;

	private Character owner;

	private int scene;

	private int ready;

	private string look;

	private string lastIssue;

	private float pollAt;

	private float retryAt;

	internal NativePortraits(WheelRenderer wheel, ManualLogSource log)
	{
		this.wheel = wheel;
		this.log = log;
	}

	internal void Wake()
	{
		pollAt = 0f;
	}

	internal void Tick(int hovered)
	{
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		float unscaledTime = Time.unscaledTime;
		if (studio == null && unscaledTime < pollAt)
		{
			return;
		}
		pollAt = unscaledTime + 2f;
		try
		{
			Character localCharacter = Character.localCharacter;
			if (LoadingScreenHandler.loading || !Stances.Ready(localCharacter) || PhotonNetwork.LocalPlayer == null)
			{
				CloseStudio();
				return;
			}
			int num = Stances.Count(localCharacter);
			string text = Appearance(num);
			if (text != look)
			{
				Dispose();
				look = text;
			}
			if (text == null || num == 0 || ready == num)
			{
				return;
			}
			Scene val2;
			if (studio != null)
			{
				if (!((Object)(object)owner != (Object)(object)localCharacter))
				{
					SceneHandle val = SceneHandle.op_Implicit(scene);
					val2 = ((Component)localCharacter).gameObject.scene;
					if (!(val != ((Scene)(ref val2)).handle))
					{
						goto IL_00cb;
					}
				}
				CloseStudio();
			}
			goto IL_00cb;
			IL_00cb:
			if (unscaledTime < retryAt)
			{
				return;
			}
			if (studio == null)
			{
				PassportManager val3 = PassportManager.instance;
				if (!Object.op_Implicit((Object)(object)val3) || !Object.op_Implicit((Object)(object)val3.dummy))
				{
					PassportManager[] array = Resources.FindObjectsOfTypeAll<PassportManager>();
					foreach (PassportManager val4 in array)
					{
						if (Object.op_Implicit((Object)(object)val4) && Object.op_Implicit((Object)(object)val4.dummy))
						{
							val3 = val4;
							break;
						}
					}
				}
				if (!Object.op_Implicit((Object)(object)val3) || !Object.op_Implicit((Object)(object)val3.dummy))
				{
					RecordIssue("Waiting for PEAK's passport model.");
					retryAt = unscaledTime + 6f;
					return;
				}
				studio = new PassportStudio(val3, localCharacter.refs.customization.refs);
				log.LogInfo((object)("Portrait face materials: " + studio.FaceMaterials));
				owner = localCharacter;
				val2 = ((Component)localCharacter).gameObject.scene;
				scene = SceneHandle.op_Implicit(((Scene)(ref val2)).handle);
				Array.Clear(attempted, 0, attempted.Length);
			}
			int num2 = NextSlot(hovered, num);
			if (num2 >= 0)
			{
				attempted[num2] = true;
				try
				{
					Capture(num2);
				}
				catch (Exception ex)
				{
					RecordIssue($"Slot {num2}. {ex.GetType().Name}: {ex.Message}");
				}
			}
			if (ready == num)
			{
				CloseStudio();
				lastIssue = null;
				log.LogInfo((object)$"Native portraits ready. Captured {num} local scout stances.");
			}
			else if (NextSlot(-1, num) < 0)
			{
				CloseStudio();
				retryAt = unscaledTime + 30f;
			}
		}
		catch (Exception ex2)
		{
			CloseStudio();
			RecordIssue(ex2.GetType().Name + ": " + ex2.Message);
			retryAt = unscaledTime + 30f;
			pollAt = retryAt;
		}
	}

	private int NextSlot(int hovered, int count)
	{
		if (hovered >= 0 && hovered < count && !Object.op_Implicit((Object)(object)tiles[hovered]) && !attempted[hovered])
		{
			return hovered;
		}
		for (int i = 0; i < count; i++)
		{
			if (!Object.op_Implicit((Object)(object)tiles[i]) && !attempted[i])
			{
				return i;
			}
		}
		return -1;
	}

	private void Capture(int slot)
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		ulong fingerprint;
		Color32[] pixels = studio.Capture(slot, out fingerprint);
		if (fingerprints.Contains(fingerprint))
		{
			throw new InvalidOperationException("Captured the same image as another stance.");
		}
		Texture2D val = new Texture2D(256, 256, (TextureFormat)4, false);
		try
		{
			((Texture)val).wrapMode = (TextureWrapMode)1;
			((Texture)val).filterMode = (FilterMode)1;
			val.SetPixels32(pixels);
			val.Apply(false, true);
			wheel.SetPortrait(slot, val);
		}
		catch
		{
			Object.Destroy((Object)(object)val);
			throw;
		}
		tiles[slot] = val;
		fingerprints.Add(fingerprint);
		ready++;
	}

	private static string Appearance(int count)
	{
		PersistentPlayerDataService service = GameHandler.GetService<PersistentPlayerDataService>();
		CharacterCustomizationData val = ((service == null) ? null : service.GetPlayerData(PhotonNetwork.LocalPlayer)?.customizationData);
		if (val == null)
		{
			return null;
		}
		return $"{count}/{val.currentSkin}/{val.currentEyes}/{val.currentMouth}/{val.currentAccessory}/{val.currentHat}/{val.currentOutfit}/{val.currentSash}/{val.currentMedal}";
	}

	private void RecordIssue(string reason)
	{
		if (lastIssue != reason)
		{
			log.LogInfo((object)("Native portrait pending. " + reason));
		}
		lastIssue = reason;
	}

	private void CloseStudio()
	{
		studio?.Dispose();
		studio = null;
		owner = null;
	}

	public void Dispose()
	{
		CloseStudio();
		for (int i = 0; i < tiles.Length; i++)
		{
			if (Object.op_Implicit((Object)(object)tiles[i]))
			{
				wheel.SetPortrait(i, null);
				Object.Destroy((Object)(object)tiles[i]);
				tiles[i] = null;
			}
		}
		fingerprints.Clear();
		ready = 0;
		look = (lastIssue = null);
		retryAt = (pollAt = 0f);
	}
}
internal sealed class PassportStudio : IDisposable
{
	private const int Size = 512;

	private readonly Color32[] dark = (Color32[])(object)new Color32[262144];

	private readonly Color32[] lightPixels = (Color32[])(object)new Color32[262144];

	private readonly GameObject stage;

	private readonly PlayerCustomizationDummy dummy;

	private readonly Camera camera;

	private readonly RenderTexture target;

	private readonly Texture2D readback;

	private readonly HashSet<Material> ownedMaterials = new HashSet<Material>();

	private readonly Vector3 lookDirection;

	private readonly Mesh bakedBody;

	private static readonly int Idle = Animator.StringToHash("Idle");

	internal string FaceMaterials { get; }

	internal PassportStudio(PassportManager passport, CustomizationRefs liveFace)
	{
		//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_0146: 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_010a: 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_011f: 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_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Expected O, but got Unknown
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_0216: Unknown result type (might be due to invalid IL or missing references)
		//IL_0227: Unknown result type (might be due to invalid IL or missing references)
		//IL_0239: Unknown result type (might be due to invalid IL or missing references)
		//IL_041a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0420: Invalid comparison between Unknown and I4
		//IL_0557: Unknown result type (might be due to invalid IL or missing references)
		//IL_055e: Expected O, but got Unknown
		//IL_0644: Unknown result type (might be due to invalid IL or missing references)
		//IL_0649: Unknown result type (might be due to invalid IL or missing references)
		//IL_064e: Unknown result type (might be due to invalid IL or missing references)
		//IL_065d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0662: Unknown result type (might be due to invalid IL or missing references)
		//IL_0679: Unknown result type (might be due to invalid IL or missing references)
		//IL_06c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_06df: Unknown result type (might be due to invalid IL or missing references)
		//IL_06e9: Expected O, but got Unknown
		//IL_071f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0729: Expected O, but got Unknown
		//IL_072a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0734: Expected O, but got Unknown
		PlayerCustomizationDummy val = passport.dummy;
		if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val.anim) || !Object.op_Implicit((Object)(object)val.refs) || !Object.op_Implicit((Object)(object)val.refs.mainRenderer))
		{
			throw new InvalidOperationException("The passport preview rig is incomplete.");
		}
		Transform val2 = ((Component)val).transform;
		while (Object.op_Implicit((Object)(object)val2) && (!((Component)val.anim).transform.IsChildOf(val2) || !((Component)val.refs).transform.IsChildOf(val2) || !((Component)val.refs.mainRenderer).transform.IsChildOf(val2)))
		{
			val2 = val2.parent;
		}
		if (!Object.op_Implicit((Object)(object)val2) || Object.op_Implicit((Object)(object)((Component)val2).GetComponentInChildren<PhotonView>(true)) || Object.op_Implicit((Object)(object)((Component)val2).GetComponentInChildren<PassportManager>(true)))
		{
			throw new InvalidOperationException("Could not isolate a visual-only passport rig.");
		}
		Vector3 val3 = (Object.op_Implicit((Object)(object)passport.dummyCamera) ? (Quaternion.Inverse(val2.rotation) * ((Component)passport.dummyCamera).transform.forward) : (Quaternion.Inverse(val2.rotation) * -((Component)val.anim).transform.forward));
		Vector3 val4 = Vector3.ProjectOnPlane(val3, Vector3.up);
		lookDirection = ((Vector3)(ref val4)).normalized;
		if (((Vector3)(ref lookDirection)).sqrMagnitude < 0.5f)
		{
			lookDirection = Vector3.back;
		}
		stage = new GameObject("Scout Expressions • Portrait studio");
		stage.SetActive(false);
		Vector3 val5 = (Object.op_Implicit((Object)(object)passport.dummyCamera) ? ((Component)passport.dummyCamera).transform.right : val2.right);
		stage.transform.position = val2.position + ((Vector3)(ref val5)).normalized * 16f;
		try
		{
			GameObject val6 = Object.Instantiate<GameObject>(((Component)val2).gameObject, stage.transform, false);
			val6.transform.localPosition = Vector3.zero;
			val6.transform.localRotation = Quaternion.identity;
			val6.transform.localScale = val2.lossyScale;
			val6.SetActive(true);
			dummy = val6.GetComponentInChildren<PlayerCustomizationDummy>(true);
			if (!Object.op_Implicit((Object)(object)dummy) || !Object.op_Implicit((Object)(object)dummy.anim) || !Object.op_Implicit((Object)(object)dummy.refs) || !((Component)dummy.anim).transform.IsChildOf(val6.transform))
			{
				throw new InvalidOperationException("The cloned passport has no local animator.");
			}
			ValidateReferences(dummy.refs, val6.transform);
			Behaviour[] componentsInChildren = val6.GetComponentsInChildren<Behaviour>(true);
			foreach (Behaviour val7 in componentsInChildren)
			{
				if ((Object)(object)val7 != (Object)(object)dummy.anim && (Object)(object)val7 != (Object)(object)dummy && (Object)(object)val7 != (Object)(object)dummy.refs)
				{
					val7.enabled = false;
				}
			}
			Collider[] componentsInChildren2 = val6.GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				componentsInChildren2[i].enabled = false;
			}
			Rigidbody[] componentsInChildren3 = val6.GetComponentsInChildren<Rigidbody>(true);
			foreach (Rigidbody obj in componentsInChildren3)
			{
				obj.isKinematic = true;
				obj.detectCollisions = false;
			}
			int num = 0;
			Renderer[] componentsInChildren4 = val6.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val8 in componentsInChildren4)
			{
				num |= 1 << ((Component)val8).gameObject.layer;
			}
			SkinnedMeshRenderer mainRenderer = dummy.refs.mainRenderer;
			Transform val9 = ((Component)mainRenderer).transform;
			while ((Object)(object)val9 != (Object)(object)stage.transform)
			{
				((Component)val9).gameObject.SetActive(true);
				val9 = val9.parent;
			}
			((Renderer)mainRenderer).enabled = true;
			((Renderer)mainRenderer).forceRenderingOff = false;
			if ((int)((Renderer)mainRenderer).shadowCastingMode == 3)
			{
				((Renderer)mainRenderer).shadowCastingMode = (ShadowCastingMode)1;
			}
			SkinnedMeshRenderer[] componentsInChildren5 = val6.GetComponentsInChildren<SkinnedMeshRenderer>(true);
			for (int i = 0; i < componentsInChildren5.Length; i++)
			{
				componentsInChildren5[i].updateWhenOffscreen = true;
			}
			Transform val10 = ((Component)dummy.anim).transform;
			while ((Object)(object)val10 != (Object)(object)stage.transform)
			{
				((Component)val10).gameObject.SetActive(true);
				val10 = val10.parent;
			}
			((Behaviour)dummy.anim).enabled = true;
			dummy.anim.cullingMode = (AnimatorCullingMode)0;
			dummy.anim.applyRootMotion = false;
			dummy.anim.fireEvents = false;
			stage.SetActive(true);
			if (!Array.Exists(dummy.anim.parameters, (AnimatorControllerParameter p) => p.nameHash == Idle && (int)p.type == 1))
			{
				throw new InvalidOperationException("Passport animator has no Idle float.");
			}
			ApplyLocalLook(val6);
			FaceMaterials = PortraitFaceMaterials.Apply(dummy.refs, liveFace, ownedMaterials);
			stage.SetActive(false);
			GameObject val11 = new GameObject("Portrait camera");
			val11.transform.SetParent(stage.transform, false);
			camera = val11.AddComponent<Camera>();
			((Behaviour)camera).enabled = false;
			camera.orthographic = true;
			camera.aspect = 1f;
			camera.nearClipPlane = 0.01f;
			Camera dummyCamera = passport.dummyCamera;
			camera.cullingMask = ((Object.op_Implicit((Object)(object)dummyCamera) && (dummyCamera.cullingMask & (1 << ((Component)mainRenderer).gameObject.layer)) != 0) ? (dummyCamera.cullingMask & num) : num);
			MatchPassportRenderer(dummyCamera);
			camera.clearFlags = (CameraClearFlags)2;
			camera.allowHDR = false;
			camera.allowMSAA = false;
			camera.useOcclusionCulling = false;
			((Component)camera).transform.rotation = Quaternion.LookRotation(lookDirection, Vector3.up);
			GameObject val12 = new GameObject("Portrait light");
			val12.transform.SetParent(((Component)camera).transform, false);
			Light obj2 = val12.AddComponent<Light>();
			obj2.type = (LightType)2;
			obj2.intensity = 0.8f;
			obj2.range = 12f;
			obj2.cullingMask = camera.cullingMask;
			obj2.shadows = (LightShadows)0;
			val12.transform.localPosition = new Vector3(-1f, 1.4f, 0.8f);
			target = new RenderTexture(512, 512, 24, (RenderTextureFormat)0);
			if (!target.Create())
			{
				throw new InvalidOperationException("Could not allocate camera target.");
			}
			camera.targetTexture = target;
			readback = new Texture2D(512, 512, (TextureFormat)4, false);
			bakedBody = new Mesh();
		}
		catch
		{
			Dispose();
			throw;
		}
	}

	private void MatchPassportRenderer(Camera source)
	{
		RenderPipelineAsset currentRenderPipeline = GraphicsSettings.currentRenderPipeline;
		UniversalRenderPipelineAsset val = (UniversalRenderPipelineAsset)(object)((currentRenderPipeline is UniversalRenderPipelineAsset) ? currentRenderPipeline : null);
		if (val == null)
		{
			return;
		}
		UniversalAdditionalCameraData val2 = ((Component)camera).gameObject.AddComponent<UniversalAdditionalCameraData>();
		val2.renderPostProcessing = false;
		val2.requiresDepthTexture = true;
		val2.requiresColorTexture = true;
		UniversalAdditionalCameraData val3 = default(UniversalAdditionalCameraData);
		if (!Object.op_Implicit((Object)(object)source) || !((Component)source).TryGetComponent<UniversalAdditionalCameraData>(ref val3))
		{
			return;
		}
		ScriptableRenderer scriptableRenderer = val3.scriptableRenderer;
		ReadOnlySpan<ScriptableRenderer> renderers = val.renderers;
		int num = 0;
		while (scriptableRenderer != null && num < renderers.Length)
		{
			if (renderers[num] == scriptableRenderer)
			{
				val2.SetRenderer(num);
				break;
			}
			num++;
		}
	}

	private static void ValidateReferences(CustomizationRefs refs, Transform root)
	{
		if (!Object.op_Implicit((Object)(object)refs) || !((Component)refs).transform.IsChildOf(root))
		{
			throw new InvalidOperationException("External customization rig.");
		}
		FieldInfo[] fields = typeof(CustomizationRefs).GetFields();
		foreach (FieldInfo fieldInfo in fields)
		{
			if (fieldInfo.Name == "customization")
			{
				continue;
			}
			object value = fieldInfo.GetValue(refs);
			if (value is Array array)
			{
				foreach (object item in array)
				{
					RequireLocal(item);
				}
			}
			else
			{
				RequireLocal(value);
			}
		}
		void RequireLocal(object obj)
		{
			Component val = (Component)((obj is Component) ? obj : null);
			object obj2;
			if (val == null || !Object.op_Implicit((Object)(object)val))
			{
				GameObject val2 = (GameObject)((obj is GameObject) ? obj : null);
				obj2 = ((val2 != null && Object.op_Implicit((Object)(object)val2)) ? val2.transform : null);
			}
			else
			{
				obj2 = val.transform;
			}
			Transform val3 = (Transform)obj2;
			if (Object.op_Implicit((Object)(object)val3) && !val3.IsChildOf(root))
			{
				throw new InvalidOperationException("A passport cosmetic references an external object.");
			}
		}
	}

	private void ApplyLocalLook(GameObject clone)
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Expected O, but got Unknown
		Renderer[] componentsInChildren = clone.GetComponentsInChildren<Renderer>(true);
		HashSet<Material> hashSet = new HashSet<Material>(Resources.FindObjectsOfTypeAll<Material>());
		Renderer[] array = componentsInChildren;
		foreach (Renderer val in array)
		{
			Material[] sharedMaterials = val.sharedMaterials;
			for (int j = 0; j < sharedMaterials.Length; j++)
			{
				if (Object.op_Implicit((Object)(object)sharedMaterials[j]))
				{
					sharedMaterials[j] = new Material(sharedMaterials[j]);
					ownedMaterials.Add(sharedMaterials[j]);
				}
			}
			val.materials = sharedMaterials;
		}
		try
		{
			dummy.UpdateDummy(PhotonNetwork.LocalPlayer);
		}
		finally
		{
			array = componentsInChildren;
			for (int i = 0; i < array.Length; i++)
			{
				Material[] sharedMaterials2 = array[i].sharedMaterials;
				foreach (Material val2 in sharedMaterials2)
				{
					if (Object.op_Implicit((Object)(object)val2) && !hashSet.Contains(val2) && ((Object)val2).name.EndsWith(" (Instance)", StringComparison.Ordinal))
					{
						ownedMaterials.Add(val2);
					}
				}
			}
		}
	}

	internal Color32[] Capture(int slot, out ulong fingerprint)
	{
		//IL_005b: 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)
		stage.SetActive(true);
		RenderTexture active = RenderTexture.active;
		try
		{
			Animator anim = dummy.anim;
			anim.Rebind();
			anim.SetFloat(Idle, (float)slot);
			anim.speed = 1f;
			for (int i = 0; i < 16; i++)
			{
				anim.Update(1f / 30f);
			}
			FrameScout();
			ReadFrame(Color.black, dark);
			ReadFrame(Color.white, lightPixels);
			try
			{
				return PortraitTile.Compose(dark, lightPixels, slot, out fingerprint);
			}
			catch (InvalidOperationException ex)
			{
				SkinnedMeshRenderer mainRenderer = dummy.refs.mainRenderer;
				string text = $"{ex.Message} Body {((Object)mainRenderer).name}, layer {((Component)mainRenderer).gameObject.layer}, ";
				string text2 = $"active {((Component)mainRenderer).gameObject.activeInHierarchy}, enabled {((Renderer)mainRenderer).enabled}, camera mask 0x{camera.cullingMask:X8}, ";
				object arg = camera.orthographicSize;
				RenderPipelineAsset currentRenderPipeline = GraphicsSettings.currentRenderPipeline;
				throw new InvalidOperationException(text + text2 + string.Format("ortho {0:F3}, pipeline {1}.", arg, ((currentRenderPipeline != null) ? ((Object)currentRenderPipeline).name : null) ?? "built-in"), ex);
			}
		}
		finally
		{
			RenderTexture.active = active;
			stage.SetActive(false);
		}
	}

	private void ReadFrame(Color background, Color32[] destination)
	{
		//IL_0006: 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_002a: Expected O, but got Unknown
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Expected O, but got Unknown
		//IL_00ad: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
		camera.backgroundColor = background;
		if (GraphicsSettings.currentRenderPipeline is UniversalRenderPipelineAsset)
		{
			SingleCameraRequest val = new SingleCameraRequest
			{
				destination = target
			};
			RenderPipeline.SubmitRenderRequest<SingleCameraRequest>(camera, val);
		}
		else if (Object.op_Implicit((Object)(object)GraphicsSettings.currentRenderPipeline))
		{
			StandardRequest val2 = new StandardRequest
			{
				destination = target
			};
			if (!RenderPipeline.SupportsRenderRequest<StandardRequest>(camera, val2))
			{
				throw new InvalidOperationException("Active pipeline does not support offscreen portraits.");
			}
			RenderPipeline.SubmitRenderRequest<StandardRequest>(camera, val2);
		}
		else
		{
			camera.Render();
		}
		RenderTexture.active = target;
		readback.ReadPixels(new Rect(0f, 0f, 512f, 512f), 0, 0, false);
		readback.GetRawTextureData<Color32>().CopyTo(destination);
	}

	private void FrameScout()
	{
		//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_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: 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_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0201: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: 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_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		SkinnedMeshRenderer mainRenderer = dummy.refs.mainRenderer;
		mainRenderer.BakeMesh(bakedBody);
		bakedBody.RecalculateBounds();
		Bounds bounds = bakedBody.bounds;
		Bounds val = default(Bounds);
		((Bounds)(ref val))..ctor(((Component)mainRenderer).transform.TransformPoint(((Bounds)(ref bounds)).center), Vector3.zero);
		Vector3 val2 = default(Vector3);
		for (int i = 0; i < 8; i++)
		{
			((Vector3)(ref val2))..ctor(((i & 1) == 0) ? ((Bounds)(ref bounds)).min.x : ((Bounds)(ref bounds)).max.x, ((i & 2) == 0) ? ((Bounds)(ref bounds)).min.y : ((Bounds)(ref bounds)).max.y, ((i & 4) == 0) ? ((Bounds)(ref bounds)).min.z : ((Bounds)(ref bounds)).max.z);
			((Bounds)(ref val)).Encapsulate(((Component)mainRenderer).transform.TransformPoint(val2));
		}
		Renderer[] playerHats = dummy.refs.playerHats;
		foreach (Renderer val3 in playerHats)
		{
			if (Object.op_Implicit((Object)(object)val3) && val3.enabled && ((Component)val3).gameObject.activeInHierarchy)
			{
				((Bounds)(ref val)).Encapsulate(val3.bounds);
			}
		}
		Vector3 extents = ((Bounds)(ref val)).extents;
		float num = Mathf.Abs(((Component)camera).transform.right.x) * extents.x + Mathf.Abs(((Component)camera).transform.right.z) * extents.z;
		float num2 = Mathf.Max(extents.y, num) * 1.12f;
		if (!(num2 > 0.005f) || !(num2 < 100f))
		{
			throw new InvalidOperationException("Unexpected scout mesh bounds.");
		}
		camera.orthographicSize = num2;
		float num3 = Mathf.Max(((Vector3)(ref extents)).magnitude * 2f, 2f);
		((Component)camera).transform.position = ((Bounds)(ref val)).center - lookDirection * num3;
		camera.farClipPlane = num3 + ((Vector3)(ref extents)).magnitude + 1f;
	}

	public void Dispose()
	{
		if (Object.op_Implicit((Object)(object)stage))
		{
			stage.SetActive(false);
			Object.Destroy((Object)(object)stage);
		}
		if (Object.op_Implicit((Object)(object)target))
		{
			if (Object.op_Implicit((Object)(object)camera))
			{
				camera.targetTexture = null;
			}
			target.Release();
			Object.Destroy((Object)(object)target);
		}
		if (Object.op_Implicit((Object)(object)readback))
		{
			Object.Destroy((Object)(object)readback);
		}
		if (Object.op_Implicit((Object)(object)bakedBody))
		{
			Object.Destroy((Object)(object)bakedBody);
		}
		foreach (Material ownedMaterial in ownedMaterials)
		{
			if (Object.op_Implicit((Object)(object)ownedMaterial))
			{
				Object.Destroy((Object)(object)ownedMaterial);
			}
		}
	}
}
[BepInPlugin("RetroTsunami.ScoutExpressions", "Scout Expressions", "0.2.5")]
public sealed class Plugin : BaseUnityPlugin
{
	private ConfigEntry<Key> key;

	private ConfigEntry<bool> controller;

	private ConfigEntry<GamepadButton> padButton;

	private ConfigEntry<bool> verbose;

	private ConfigEntry<string> accent;

	private NativePortraits portraitCache;

	private readonly ConfigEntry<string>[] labels = new ConfigEntry<string>[8];

	private readonly string[] names = new string[8];

	private Action<MenuWindow> openWindow;

	private Action<MenuWindow> closeWindow;

	private StanceWindow window;

	private WheelRenderer renderer;

	private Character owner;

	private ButtonControl activation;

	private int selected = -1;

	private int count;

	private bool movedMouse;

	private Color highlight;

	private int activatedScene;

	private IdleReceiver receiver;

	private void Awake()
	{
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Expected O, but got Unknown
		//IL_01df: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			key = ((BaseUnityPlugin)this).Config.Bind<Key>("Controls", "WheelKey", (Key)34, "Hold this Unity Input System key and release to select. None disables keyboard activation.");
			controller = ((BaseUnityPlugin)this).Config.Bind<bool>("Controls", "EnableController", false, "Enable the optional gamepad binding.");
			padButton = ((BaseUnityPlugin)this).Config.Bind<GamepadButton>("Controls", "WheelButton", (GamepadButton)8, "Hold this button and aim the right stick. Choose a free binding.");
			verbose = ((BaseUnityPlugin)this).Config.Bind<bool>("Diagnostics", "Verbose", true, "Log the available idle range when the wheel opens and the outcome on selection.");
			accent = ((BaseUnityPlugin)this).Config.Bind<string>("Appearance", "Highlight", "#A3336B", "Selected sector color as an HTML hex color, e.g. #A3336B.");
			for (int i = 0; i < labels.Length; i++)
			{
				labels[i] = ((BaseUnityPlugin)this).Config.Bind<string>("Labels", "Idle" + i, Stances.Names[i], "Short wheel label for native idle " + i + ".");
			}
			openWindow = BindWindow("Open");
			closeWindow = BindWindow("Close");
			receiver = IdleProtocol.Detect(typeof(CharacterCustomization));
			if (receiver == IdleReceiver.Unavailable)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"No compatible native idle RPC found. Selections will animate locally.");
			}
			GameObject val = new GameObject("Scout Expressions");
			val.SetActive(false);
			val.transform.SetParent(((Component)this).transform, false);
			window = val.AddComponent<StanceWindow>();
			renderer = new WheelRenderer();
			portraitCache = new NativePortraits(renderer, ((BaseUnityPlugin)this).Logger);
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Scout Expressions ready. PEAK {Application.version}, game assembly {typeof(Character).Module.ModuleVersionId}, wheel key {key.Value}, idle RPC {receiver}.");
		}
		catch (Exception error)
		{
			DisableAfterError(error);
		}
	}

	private void Start()
	{
		if (Chainloader.PluginInfos.ContainsKey("cl.skylin3.idlestancewheel"))
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"IdleStanceWheel is also loaded. Disable it for a clean playtest of the wheel and native random idles.");
		}
	}

	private static Action<MenuWindow> BindWindow(string name)
	{
		MethodInfo methodInfo = AccessTools.DeclaredMethod(typeof(MenuWindow), name, Type.EmptyTypes, (Type[])null);
		if (methodInfo == null || methodInfo.ReturnType != typeof(void))
		{
			throw new MissingMethodException(typeof(MenuWindow).FullName, name);
		}
		return (Action<MenuWindow>)Delegate.CreateDelegate(typeof(Action<MenuWindow>), methodInfo);
	}

	private void Update()
	{
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (activation != null)
			{
				PollOpenWheel();
				return;
			}
			Keyboard current = Keyboard.current;
			Gamepad current2 = Gamepad.current;
			ButtonControl val = null;
			if (current != null && (int)key.Value != 0 && ((ButtonControl)current[key.Value]).wasPressedThisFrame)
			{
				val = (ButtonControl)(object)current[key.Value];
			}
			else if (controller.Value && current2 != null && current2[padButton.Value].wasPressedThisFrame)
			{
				val = current2[padButton.Value];
			}
			if (val != null && val.isPressed)
			{
				TryOpen(val);
			}
		}
		catch (Exception error)
		{
			DisableAfterError(error);
		}
	}

	private void TryOpen(ButtonControl button)
	{
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		GUIManager instance = GUIManager.instance;
		Character localCharacter = Character.localCharacter;
		string text = null;
		text = ((((InputControl)button).device is Keyboard && Mouse.current == null) ? "no active mouse" : ((!Stances.Ready(localCharacter)) ? "local scout is unavailable, incapacitated or not locally controlled" : (Object.op_Implicit((Object)(object)instance) ? BlockingWindow(instance) : "game UI is unavailable")));
		if (text == null && (instance.windowBlockingInput || instance.windowShowingCursor))
		{
			text = "PEAK is using the cursor or blocking gameplay input";
		}
		if (text != null)
		{
			if (verbose.Value)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Wheel blocked: " + text + "."));
			}
			return;
		}
		count = Stances.Count(localCharacter);
		if (verbose.Value)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Wheel requested. maxIdles={localCharacter.refs.customization.maxIdles}, available={count}, view={localCharacter.refs.view.ViewID}.");
		}
		if (count != 0)
		{
			for (int i = 0; i < count; i++)
			{
				names[i] = (string.IsNullOrWhiteSpace(labels[i].Value) ? Stances.Names[i] : labels[i].Value.Trim());
			}
			if (!ColorUtility.TryParseHtmlString(accent.Value, ref highlight))
			{
				highlight = Color32.op_Implicit(new Color32((byte)163, (byte)51, (byte)107, byte.MaxValue));
			}
			highlight.a = 1f;
			Scene scene = ((Component)localCharacter).gameObject.scene;
			activatedScene = SceneHandle.op_Implicit(((Scene)(ref scene)).handle);
			owner = localCharacter;
			activation = button;
			selected = -1;
			movedMouse = false;
			openWindow((MenuWindow)(object)window);
			instance.UpdateWindowStatus();
			portraitCache.Wake();
			string text2 = renderer.Show(instance, names, count, highlight);
			if (verbose.Value)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Wheel typeface: " + text2 + "."));
			}
		}
	}

	private string BlockingWindow(GUIManager gui)
	{
		if (!Application.isFocused || LoadingScreenHandler.loading)
		{
			return "game is unfocused or loading";
		}
		if ((Object.op_Implicit((Object)(object)gui.emoteWheel) && gui.emoteWheel.activeSelf) || (Object.op_Implicit((Object)(object)gui.backpackWheel) && ((Component)gui.backpackWheel).gameObject.activeSelf))
		{
			return "vanilla wheel is open";
		}
		if (GUIManager.InPauseMenu || DebugUIHandler.IsOpen || Modal.IsOpen)
		{
			return "pause, console or modal is open";
		}
		foreach (MenuWindow allActiveWindow in MenuWindow.AllActiveWindows)
		{
			if (Object.op_Implicit((Object)(object)allActiveWindow) && (Object)(object)allActiveWindow != (Object)(object)window && (allActiveWindow.blocksPlayerInput || allActiveWindow.showCursorWhileOpen))
			{
				return "open menu " + ((object)allActiveWindow).GetType().Name;
			}
		}
		GameObject val = (Object.op_Implicit((Object)(object)EventSystem.current) ? EventSystem.current.currentSelectedGameObject : null);
		TMP_InputField val2 = default(TMP_InputField);
		InputField val3 = default(InputField);
		if (!Object.op_Implicit((Object)(object)val) || ((!val.TryGetComponent<TMP_InputField>(ref val2) || !val2.isFocused) && (!val.TryGetComponent<InputField>(ref val3) || !val3.isFocused)))
		{
			return null;
		}
		return "text field has keyboard focus";
	}

	private void PollOpenWheel()
	{
		//IL_0061: 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_006a: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Invalid comparison between Unknown and I4
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_016b: Unknown result type (might be due to invalid IL or missing references)
		//IL_016e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		GUIManager instance = GUIManager.instance;
		if (((MenuWindow)window).isOpen && ((InputControl)activation).device.added && Object.op_Implicit((Object)(object)instance) && (!(((InputControl)activation).device is Keyboard) || Mouse.current != null) && Stances.Ready(owner))
		{
			Scene scene = ((Component)owner).gameObject.scene;
			if (!(((Scene)(ref scene)).handle != SceneHandle.op_Implicit(activatedScene)) && BlockingWindow(instance) == null)
			{
				Keyboard current = Keyboard.current;
				if (current == null || !((ButtonControl)current.escapeKey).wasPressedThisFrame)
				{
					InputDevice device = ((InputControl)activation).device;
					Gamepad val = (Gamepad)(object)((device is Gamepad) ? device : null);
					if (val != null)
					{
						Vector2 val2 = ((InputControl<Vector2>)(object)val.rightStick).ReadValue();
						selected = WheelGeometry.Hit(val2.x, val2.y, 0.4f, count);
					}
					else if (Mouse.current != null && (int)Cursor.lockState != 1)
					{
						bool num = movedMouse;
						Vector2 val3 = ((InputControl<Vector2>)(object)((Pointer)Mouse.current).delta).ReadValue();
						movedMouse = num | (((Vector2)(ref val3)).sqrMagnitude > 0f);
						if (movedMouse)
						{
							Vector2 val4 = ((InputControl<Vector2>)(object)((Pointer)Mouse.current).position).ReadValue() - new Vector2((float)Screen.width, (float)Screen.height) * 0.5f;
							selected = WheelGeometry.Hit(val4.x, val4.y, WheelRenderer.Diameter * 0.22265625f, count);
						}
					}
					if (activation.isPressed)
					{
						renderer.UpdateSelection(selected);
						return;
					}
					Character scout = owner;
					int num2 = (activation.wasReleasedThisFrame ? selected : (-1));
					CloseWheel();
					if (num2 >= 0)
					{
						string text = Stances.Apply(scout, num2, receiver);
						if (verbose.Value)
						{
							((BaseUnityPlugin)this).Logger.LogInfo((object)text);
						}
					}
					return;
				}
			}
		}
		CloseWheel();
	}

	private void CloseWheel()
	{
		activation = null;
		owner = null;
		selected = -1;
		renderer?.Hide();
		if (Object.op_Implicit((Object)(object)window) && ((MenuWindow)window).isOpen)
		{
			closeWindow((MenuWindow)(object)window);
		}
	}

	private void OnApplicationFocus(bool focused)
	{
		if (!focused)
		{
			CloseWheel();
		}
	}

	private void LateUpdate()
	{
		portraitCache?.Tick(selected);
	}

	private void OnDisable()
	{
		CloseWheel();
		portraitCache?.Dispose();
	}

	private void OnDestroy()
	{
		CloseWheel();
		portraitCache?.Dispose();
		renderer?.Dispose();
		if (Object.op_Implicit((Object)(object)window))
		{
			Object.Destroy((Object)(object)((Component)window).gameObject);
		}
	}

	private void DisableAfterError(Exception error)
	{
		((BaseUnityPlugin)this).Logger.LogError((object)("Scout Expressions disabled after an initialization or input error. " + error));
		((Behaviour)this).enabled = false;
	}
}
internal static class PortraitFaceMaterials
{
	internal static string Apply(CustomizationRefs face, CustomizationRefs live, HashSet<Material> owned)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Expected O, but got Unknown
		List<string> details = new List<string>();
		HashSet<Renderer> visited = new HashSet<Renderer>();
		MaterialPropertyBlock block = new MaterialPropertyBlock();
		Renderer[] eyeRenderers = face.EyeRenderers;
		int num = 0;
		while (eyeRenderers != null && num < eyeRenderers.Length)
		{
			Renderer[] array = (Object.op_Implicit((Object)(object)live) ? live.EyeRenderers : null);
			ApplyLayer(eyeRenderers[num], (array != null && num < array.Length) ? array[num] : null, "eye");
			num++;
		}
		ApplyLayer(face.mouthRenderer, Object.op_Implicit((Object)(object)live) ? live.mouthRenderer : null, "mouth");
		ApplyLayer(face.accessoryRenderer, Object.op_Implicit((Object)(object)live) ? live.accessoryRenderer : null, "accessory");
		return string.Join(", ", details) + ".";
		void ApplyLayer(Renderer target, Renderer source, string label)
		{
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			if (Object.op_Implicit((Object)(object)target) && visited.Add(target))
			{
				Material[] sharedMaterials = target.sharedMaterials;
				if (sharedMaterials.Length != 0 && Object.op_Implicit((Object)(object)sharedMaterials[0]))
				{
					Material val = sharedMaterials[0];
					Texture val2 = (val.HasProperty("_MainTex") ? val.GetTexture("_MainTex") : null);
					Material val3 = (Object.op_Implicit((Object)(object)source) ? source.sharedMaterial : null);
					bool flag = Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)val3) && Object.op_Implicit((Object)(object)val3.shader) && val3.shader.isSupported && val3.HasProperty("_MainTex") && (Object)(object)val3.GetTexture("_MainTex") == (Object)(object)val2;
					if (flag)
					{
						sharedMaterials[0] = new Material(val3);
						owned.Add(sharedMaterials[0]);
						target.sharedMaterials = sharedMaterials;
						source.GetPropertyBlock(block);
						target.SetPropertyBlock(block.isEmpty ? null : block);
						source.GetPropertyBlock(block, 0);
						target.SetPropertyBlock(block.isEmpty ? null : block, 0);
					}
					Material val4 = sharedMaterials[0];
					details.Add(label + "=" + (flag ? "scout" : "passport") + "/" + ((Object)val4.shader).name + "/" + (Object.op_Implicit((Object)(object)val2) ? ((Object)val2).name : "no map"));
				}
			}
		}
	}
}
internal static class PortraitTile
{
	internal const int CaptureSize = 512;

	internal const int IconSize = 256;

	private const double TileWidth = 180.0;

	private const double SlotRadius = 177.0;

	private static readonly double HalfAngle = Math.Tan(Math.PI * 17.0 / 144.0);

	internal static bool InsideSlot(double x, double y, int slot)
	{
		double num = (double)slot * Math.PI / 4.0;
		return InsideSlot(x, y, Math.Sin(num), Math.Cos(num));
	}

	private static bool InsideSlot(double x, double y, double sin, double cos)
	{
		double num = 177.0 + x * sin + y * cos;
		double num2 = x * cos - y * sin;
		double num3 = num * num + num2 * num2;
		if (num3 >= 13225.0 && num3 <= 60516.0)
		{
			return Math.Abs(num2) < num * HalfAngle;
		}
		return false;
	}

	private static int Brightness(Color32 p)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		return p.r + p.g + p.b;
	}

	private static Color32 Corner(Color32[] pixels)
	{
		//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_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_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		Color32[] obj = new Color32[4]
		{
			pixels[0],
			pixels[511],
			pixels[^512],
			pixels[^1]
		};
		Array.Sort((Color32[])(object)obj, (Color32 a, Color32 b) => Brightness(a).CompareTo(Brightness(b)));
		return obj[1];
	}

	private static byte Unmix(byte channel, byte backdrop, int alpha)
	{
		return (byte)Math.Max(0, Math.Min(255, (255 * channel - (255 - alpha) * backdrop) / alpha));
	}

	internal static Color32[] Compose(Color32[] pixels, Color32[] whitePass, int slot, out ulong fingerprint)
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: 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_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0258: Unknown result type (might be due to invalid IL or missing references)
		//IL_0266: Unknown result type (might be due to invalid IL or missing references)
		//IL_0274: Unknown result type (might be due to invalid IL or missing references)
		//IL_0282: Unknown result type (might be due to invalid IL or missing references)
		//IL_0290: Unknown result type (might be due to invalid IL or missing references)
		//IL_029e: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ba: 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_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: 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_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_016e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0673: Unknown result type (might be due to invalid IL or missing references)
		//IL_0678: Unknown result type (might be due to invalid IL or missing references)
		//IL_059e: 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_05bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f5: Unknown result type (might be due to invalid IL or missing references)
		if (pixels.Length != 262144 || whitePass.Length != pixels.Length)
		{
			throw new ArgumentException("Unexpected camera tile size.");
		}
		Color32 val = Corner(pixels);
		Color32 val2 = Corner(whitePass);
		int num = Brightness(val2) - Brightness(val);
		int num2 = 512;
		int num3 = -1;
		int num4 = 512;
		int num5 = -1;
		int num6 = 0;
		fingerprint = 14695981039346656037uL;
		for (int i = 0; i < pixels.Length; i++)
		{
			Color32 val3 = pixels[i];
			if (num > 96)
			{
				int num7 = Brightness(whitePass[i]) - Brightness(val3);
				int num8 = Math.Max(0, Math.Min(255, 255 - 255 * num7 / num));
				if (num8 < 12)
				{
					pixels[i] = default(Color32);
					continue;
				}
				((Color32)(ref val3))..ctor(Unmix(val3.r, val.r, num8), Unmix(val3.g, val.g, num8), Unmix(val3.b, val.b, num8), (byte)num8);
			}
			else
			{
				if (Math.Abs(val3.r - val.r) <= 4 && Math.Abs(val3.g - val.g) <= 4 && Math.Abs(val3.b - val.b) <= 4 && Math.Abs(val3.a - val.a) <= 4)
				{
					pixels[i] = default(Color32);
					continue;
				}
				val3.a = byte.MaxValue;
			}
			pixels[i] = val3;
			int val4 = i % 512;
			int val5 = i / 512;
			num2 = Math.Min(num2, val4);
			num3 = Math.Max(num3, val4);
			num4 = Math.Min(num4, val5);
			num5 = Math.Max(num5, val5);
			num6++;
			fingerprint = (fingerprint ^ (uint)(i + (val3.r << 16) + (val3.g << 8) + val3.b)) * 1099511628211L;
		}
		if (num6 < 2621 || (double)num6 > 246415.36)
		{
			throw new InvalidOperationException($"Portrait slot {slot}: {num6}/{pixels.Length} foreground pixels; " + $"backdrops ({val.r},{val.g},{val.b},{val.a}) and ({val2.r},{val2.g},{val2.b},{val2.a}).");
		}
		num4 += (num5 - num4 + 1) * 30 / 100;
		double num9 = num3 - num2 + 1;
		double num10 = num5 - num4 + 1;
		double num11 = 0.0;
		double num12 = 178.0 / Math.Max(num9, num10);
		for (int j = 0; j < 12; j++)
		{
			double num13 = (num11 + num12) * 0.5;
			double num14 = num13 * num9 / 2.0;
			double num15 = num13 * num10 / 2.0;
			bool flag = true;
			for (int k = -1; k <= 1 && flag; k++)
			{
				for (int l = -1; l <= 1 && flag; l++)
				{
					flag = InsideSlot(num14 * (double)l, num15 * (double)k, slot);
				}
			}
			if (flag)
			{
				num11 = num13;
			}
			else
			{
				num12 = num13;
			}
		}
		Color32[] array = (Color32[])(object)new Color32[65536];
		double num16 = (double)slot * Math.PI / 4.0;
		double sin = Math.Sin(num16);
		double cos = Math.Cos(num16);
		double num17 = Math.Max(1.0, 180.0 / (256.0 * num11));
		for (int m = 0; m < 256; m++)
		{
			for (int n = 0; n < 256; n++)
			{
				double num18 = (((double)n + 0.5) / 256.0 - 0.5) * 180.0;
				double num19 = (((double)m + 0.5) / 256.0 - 0.5) * 180.0;
				if (!InsideSlot(num18, num19, sin, cos))
				{
					continue;
				}
				double num20 = (double)num2 + num9 / 2.0 + num18 / num11;
				double num21 = (double)num4 + num10 / 2.0 + num19 / num11;
				double num22 = num20 - num17 / 2.0;
				double num23 = num21 - num17 / 2.0;
				double num24 = num20 + num17 / 2.0;
				double num25 = num21 + num17 / 2.0;
				int num26 = Math.Max(num2, (int)Math.Floor(num22));
				int num27 = Math.Min(num3, (int)Math.Ceiling(num24) - 1);
				int num28 = Math.Max(num4, (int)Math.Floor(num23));
				int num29 = Math.Min(num5, (int)Math.Ceiling(num25) - 1);
				double num30 = 0.0;
				double num31 = 0.0;
				double num32 = 0.0;
				double num33 = 0.0;
				for (int num34 = num28; num34 <= num29; num34++)
				{
					double num35 = Math.Min(num25, num34 + 1) - Math.Max(num23, num34);
					for (int num36 = num26; num36 <= num27; num36++)
					{
						Color32 val6 = pixels[num34 * 512 + num36];
						double num37 = num35 * (Math.Min(num24, num36 + 1) - Math.Max(num22, num36)) * (double)(int)val6.a;
						num30 += num37;
						num31 += num37 * (double)(int)val6.r;
						num32 += num37 * (double)(int)val6.g;
						num33 += num37 * (double)(int)val6.b;
					}
				}
				if (num30 > 0.0)
				{
					array[m * 256 + n] = new Color32((byte)Math.Round(num31 / num30), (byte)Math.Round(num32 / num30), (byte)Math.Round(num33 / num30), (byte)Math.Min(255.0, Math.Round(num30 / (num17 * num17))));
				}
			}
		}
		return array;
	}
}
internal static class Stances
{
	internal static readonly string[] Names = new string[8] { "Confident", "Determined", "Focused", "Observant", "Excited", "Centered", "Hidden Hands", "Prepared" };

	internal static int Count(Character scout)
	{
		return Mathf.Clamp(scout.refs.customization.maxIdles, 0, Names.Length);
	}

	internal static bool Ready(Character scout)
	{
		if (Object.op_Implicit((Object)(object)scout) && (Object)(object)scout == (Object)(object)Character.localCharacter && !scout.isBot && Object.op_Implicit((Object)(object)scout.data) && !scout.data.dead && !scout.data.passedOut && scout.refs != null && Object.op_Implicit((Object)(object)scout.refs.animations) && Object.op_Implicit((Object)(object)scout.refs.customization) && Object.op_Implicit((Object)(object)scout.refs.view))
		{
			return scout.refs.view.IsMine;
		}
		return false;
	}

	internal static string Apply(Character scout, int index, IdleReceiver receiver)
	{
		//IL_00a2: 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_00e2: Unknown result type (might be due to invalid IL or missing references)
		if (!Ready(scout) || index < 0 || index >= Count(scout))
		{
			return "Skipped selection because the scout or idle range changed.";
		}
		if (!PhotonNetwork.InRoom || PhotonNetwork.OfflineMode || receiver == IdleReceiver.Unavailable)
		{
			scout.refs.animations.SetIdle(index);
			return $"Applied idle {index} locally.";
		}
		PhotonView view = scout.refs.view;
		Player localPlayer = PhotonNetwork.LocalPlayer;
		if (localPlayer == null || view.ViewID <= 0 || view.Owner != localPlayer)
		{
			return "Skipped selection because the local scout's network view is not ready.";
		}
		bool flag = PhotonNetwork.RemoveBufferedRPCs(view.ViewID, "SetCharacterIdle_RPC", new int[1] { localPlayer.ActorNumber });
		RpcTarget val = (RpcTarget)(flag ? 3 : 0);
		view.RPC("SetCharacterIdle_RPC", val, new object[1] { index });
		return $"Sent idle {index} on owned view {view.ViewID} ({val}, cache replacement queued={flag}).";
	}
}
internal sealed class StanceWindow : MenuWindow
{
	public override bool openOnStart => false;

	public override bool selectOnOpen => false;
}
internal static class WheelGeometry
{
	internal static int Hit(float x, float y, float deadZone, int count)
	{
		if (x * x + y * y <= deadZone * deadZone)
		{
			return -1;
		}
		int num = (int)Math.Floor(Math.Atan2(x, y) * 4.0 / Math.PI + 0.5 + 8.0) % 8;
		if (num >= count)
		{
			return -1;
		}
		return num;
	}
}
internal sealed class WheelRenderer : IDisposable
{
	private const float DesignSize = 512f;

	private readonly GameObject overlay;

	private readonly RectTransform dial;

	private readonly RawImage selectedFace;

	private readonly RawImage pointer;

	private string[] stanceNames;

	private readonly RawImage[] portraits = (RawImage[])(object)new RawImage[8];

	private readonly TextMeshProUGUI[] waitingNames = (TextMeshProUGUI[])(object)new TextMeshProUGUI[8];

	private readonly List<Texture2D> textures = new List<Texture2D>();

	private readonly TextMeshProUGUI title;

	private readonly RawImage caption;

	private int lastSlot = -2;

	internal static float Diameter => Mathf.Min(new float[3]
	{
		(float)Screen.height * 0.64f,
		(float)Screen.width * 0.83f,
		620f
	});

	internal WheelRenderer()
	{
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Expected O, but got Unknown
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: 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_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_0242: Unknown result type (might be due to invalid IL or missing references)
		//IL_0253: Unknown result type (might be due to invalid IL or missing references)
		overlay = new GameObject("Scout Expressions • Wheel", new Type[2]
		{
			typeof(RectTransform),
			typeof(Canvas)
		});
		overlay.SetActive(false);
		Object.DontDestroyOnLoad((Object)(object)overlay);
		try
		{
			Canvas component = overlay.GetComponent<Canvas>();
			component.renderMode = (RenderMode)0;
			component.sortingOrder = 25000;
			dial = Rect("Dial", overlay.transform, 512f, 512f);
			Image("Dial face", (Texture)(object)Load("ring"), (Transform)(object)dial, 512f);
			selectedFace = Image("Selection", (Texture)(object)Load("sector"), (Transform)(object)dial, 512f);
			pointer = Image("Active rim", (Texture)(object)Load("marker"), (Transform)(object)dial, 512f);
			for (int i = 0; i < portraits.Length; i++)
			{
				float num = (float)Math.PI * (float)i / 4f;
				Vector2 val = new Vector2(Mathf.Sin(num), Mathf.Cos(num)) * 177f;
				RawImage obj = (portraits[i] = Image("Scout pose " + i, null, (Transform)(object)dial, 180f));
				((Graphic)obj).rectTransform.anchoredPosition = val;
				((Behaviour)obj).enabled = false;
				((Graphic)(waitingNames[i] = Label("Stance " + i, val, 104f, 50f, 17f))).color = Color32.op_Implicit(new Color32((byte)62, (byte)48, (byte)46, byte.MaxValue));
			}
			((Component)pointer).transform.SetAsLastSibling();
			caption = Image("Stance name background", (Texture)(object)Load("caption"), (Transform)(object)dial, 150f);
			((Graphic)caption).rectTransform.sizeDelta = new Vector2(150f, 42f);
			title = Label("Selected stance", Vector2.zero, 138f, 37f, 21f);
		}
		catch
		{
			Dispose();
			throw;
		}
	}

	internal void SetPortrait(int slot, Texture2D texture)
	{
		RawImage obj = portraits[slot];
		obj.texture = (Texture)(object)texture;
		((Behaviour)obj).enabled = Object.op_Implicit((Object)(object)texture);
		((Behaviour)waitingNames[slot]).enabled = !Object.op_Implicit((Object)(object)texture);
	}

	private Texture2D Load(string name)
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Expected O, but got Unknown
		using Stream stream = typeof(WheelRenderer).Assembly.GetManifestResourceStream("ScoutExpressions." + name + ".png");
		using MemoryStream memoryStream = new MemoryStream();
		stream.CopyTo(memoryStream);
		Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
		textures.Add(val);
		if (!ImageConversion.LoadImage(val, memoryStream.ToArray(), true))
		{
			throw new InvalidDataException("Invalid wheel texture: " + name);
		}
		((Texture)val).wrapMode = (TextureWrapMode)1;
		((Texture)val).filterMode = (FilterMode)1;
		return val;
	}

	private static RectTransform Rect(string name, Transform parent, float width, float height)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: 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_002d: 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_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: 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_0054: 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_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Expected O, but got Unknown
		RectTransform val = (RectTransform)new GameObject(name, new Type[1] { typeof(RectTransform) }).transform;
		((Transform)val).SetParent(parent, false);
		Vector2 val2 = default(Vector2);
		((Vector2)(ref val2))..ctor(0.5f, 0.5f);
		val.pivot = val2;
		Vector2 anchorMin = (val.anchorMax = val2);
		val.anchorMin = anchorMin;
		val.anchoredPosition = Vector2.zero;
		val.sizeDelta = new Vector2(width, height);
		return val;
	}

	private static RawImage Image(string name, Texture texture, Transform parent, float size)
	{
		RawImage obj = ((Component)Rect(name, parent, size, size)).gameObject.AddComponent<RawImage>();
		obj.texture = texture;
		((Graphic)obj).raycastTarget = false;
		return obj;
	}

	private TextMeshProUGUI Label(string name, Vector2 position, float width, float height, float maxSize)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		RectTransform obj = Rect(name, (Transform)(object)dial, width, height);
		obj.anchoredPosition = position;
		TextMeshProUGUI obj2 = ((Component)obj).gameObject.AddComponent<TextMeshProUGUI>();
		((TMP_Text)obj2).alignment = (TextAlignmentOptions)514;
		((Graphic)obj2).color = Color32.op_Implicit(new Color32(byte.MaxValue, (byte)245, (byte)224, byte.MaxValue));
		((TMP_Text)obj2).richText = false;
		((Graphic)obj2).raycastTarget = false;
		((TMP_Text)obj2).enableAutoSizing = true;
		((TMP_Text)obj2).fontSizeMax = maxSize;
		((TMP_Text)obj2).fontSizeMin = maxSize * 0.65f;
		((TMP_Text)obj2).textWrappingMode = (TextWrappingModes)1;
		((TMP_Text)obj2).overflowMode = (TextOverflowModes)1;
		return obj2;
	}

	private static void UseTypeface(TextMeshProUGUI label, TMP_Text source, TMP_FontAsset font)
	{
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)font))
		{
			((TMP_Text)label).font = font;
			((TMP_Text)label).fontSharedMaterial = ((Object.op_Implicit((Object)(object)source) && Object.op_Implicit((Object)(object)source.fontSharedMaterial)) ? source.fontSharedMaterial : ((TMP_Asset)font).material);
			((TMP_Text)label).fontStyle = (FontStyles)(Object.op_Implicit((Object)(object)source) ? ((int)source.fontStyle) : 0);
			((TMP_Text)label).characterSpacing = (Object.op_Implicit((Object)(object)source) ? source.characterSpacing : 0f);
		}
	}

	internal string Show(GUIManager gui, string[] names, int count, Color accent)
	{
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		EmoteWheel val = (Object.op_Implicit((Object)(object)gui.emoteWheel) ? gui.emoteWheel.GetComponentInChildren<EmoteWheel>(true) : null);
		TextMeshProUGUI val2 = (Object.op_Implicit((Object)(object)val) ? val.selectedEmoteName : null);
		if (!Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)((TMP_Text)val2).font))
		{
			val2 = ((Component)gui).GetComponentInChildren<TextMeshProUGUI>(true);
		}
		TMP_FontAsset val3 = ((Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)((TMP_Text)val2).font)) ? ((TMP_Text)val2).font : TMP_Settings.defaultFontAsset);
		if (!Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)((TMP_Text)val2).font))
		{
			val2 = null;
		}
		stanceNames = names;
		for (int i = 0; i < portraits.Length; i++)
		{
			((Component)portraits[i]).gameObject.SetActive(i < count);
			TextMeshProUGUI val4 = waitingNames[i];
			((Component)val4).gameObject.SetActive(i < count);
			if (i < count)
			{
				UseTypeface(val4, (TMP_Text)(object)val2, val3);
				((TMP_Text)val4).text = names[i];
			}
		}
		UseTypeface(title, (TMP_Text)(object)val2, val3);
		((Graphic)selectedFace).color = Color.Lerp(Color32.op_Implicit(new Color32((byte)247, (byte)232, (byte)196, byte.MaxValue)), accent, 0.48f);
		lastSlot = -2;
		UpdateSelection(-1);
		overlay.SetActive(true);
		if (!Object.op_Implicit((Object)(object)val3))
		{
			return "TMP default";
		}
		return ((Object)val3).name;
	}

	internal void UpdateSelection(int slot)
	{
		//IL_0000: 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)
		//IL_0015: 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_002f: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = Vector3.one * (Diameter / 512f);
		if (((Transform)dial).localScale != val)
		{
			((Transform)dial).localScale = val;
		}
		if (slot != lastSlot)
		{
			lastSlot = slot;
			bool flag = slot >= 0;
			RawImage obj = selectedFace;
			RawImage obj2 = pointer;
			RawImage obj3 = caption;
			bool flag2 = (((Behaviour)title).enabled = flag);
			bool flag4 = (((Behaviour)obj3).enabled = flag2);
			bool enabled = (((Behaviour)obj2).enabled = flag4);
			((Behaviour)obj).enabled = enabled;
			if (flag)
			{
				Quaternion val2 = Quaternion.Euler(0f, 0f, -45f * (float)slot);
				RectTransform rectTransform = ((Graphic)pointer).rectTransform;
				Quaternion localRotation = (((Transform)((Graphic)selectedFace).rectTransform).localRotation = val2);
				((Transform)rectTransform).localRotation = localRotation;
			}
			if (flag)
			{
				((TMP_Text)title).text = stanceNames[slot];
			}
		}
	}

	internal void Hide()
	{
		if (Object.op_Implicit((Object)(object)overlay))
		{
			overlay.SetActive(false);
		}
	}

	public void Dispose()
	{
		if (Object.op_Implicit((Object)(object)overlay))
		{
			Object.Destroy((Object)(object)overlay);
		}
		foreach (Texture2D texture in textures)
		{
			Object.Destroy((Object)(object)texture);
		}
	}
}