Decompiled source of SillyThings v1.0.0

Silly_Things.dll

Decompiled 15 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 System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using MoreCompany;
using MoreCompany.Cosmetics;
using Silly_Things.NetcodePatcher;
using Silly_Things.codes.MorphingCase;
using Steamworks;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Silly_Things")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+997e4318c37434fee9bfd57235c87efa3743b8bc")]
[assembly: AssemblyProduct("Silly_Things")]
[assembly: AssemblyTitle("Silly_Things")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: NetcodePatchedAssembly]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace Silly_Things
{
	internal class Config
	{
		public ConfigEntry<bool> EnableDebugMode { get; private set; }

		public ConfigEntry<int> MorphingCaseItemRarity { get; private set; }

		public Config(ConfigFile configFile)
		{
			MorphingCaseItemRarity = configFile.Bind<int>("Spawn Rates", "MorphingCaseItemRarity", 10, "Rarity of the Morphing Case Item (higher = more common).");
		}
	}
	[BepInPlugin("POUY.SILLY_THINGS", "Silly Things", "0.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		private const string GUID = "POUY.SILLY_THINGS";

		private const string NAME = "Silly Things";

		private const string VERSION = "0.0.1";

		public readonly Harmony harmony = new Harmony("POUY.SILLY_THINGS");

		public GameObject? UI_MorphingCase;

		public AudioClip SoundOpenUI = null;

		public AudioClip SoundCloseUI = null;

		public static Plugin Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Config SillyThingsConfig { get; private set; }

		internal ManageCosmetics CosmeticsManager { get; private set; } = null;


		public void Awake()
		{
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			SillyThingsConfig = new Config(((BaseUnityPlugin)this).Config);
			CosmeticsManager = new ManageCosmetics();
			if (PlayerPrefs.HasKey("MorphingCase_PreviousCosmetics"))
			{
				CosmeticsManager.RestorePreviousCosmetics();
				PlayerPrefs.DeleteKey("MorphingCase_PreviousCosmetics");
				PlayerPrefs.DeleteKey("MorphingCase_PreviousSuit");
			}
			LoadAssetBundle();
			Logger.LogMessage((object)"Silly things Loaded !");
			harmony.PatchAll();
		}

		private void LoadAssetBundle()
		{
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			string text = Path.Combine(directoryName, "sillythings");
			AssetBundle val = AssetBundle.LoadFromFile(text);
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogError((object)"Failed to load asset bundle");
				return;
			}
			LoadUIMorphingCase(val);
			LoadMorphingCase(val);
			LoadAudioSourceMorphingCase(val);
		}

		public void LoadAudioSourceMorphingCase(AssetBundle bundle)
		{
			SoundOpenUI = bundle.LoadAsset<AudioClip>("Assets/LethalModding/sounds/open.ogg");
			SoundCloseUI = bundle.LoadAsset<AudioClip>("Assets/LethalModding/sounds/close.ogg");
			if ((Object)(object)SoundCloseUI == (Object)null || (Object)(object)SoundOpenUI == (Object)null)
			{
				Logger.LogError((object)"Sounds Morphing Case load fail");
			}
		}

		public void OnApplicationQuit()
		{
			CosmeticsManager.RestorePreviousCosmetics();
		}

		public void LoadUIMorphingCase(AssetBundle bundle)
		{
			UI_MorphingCase = bundle.LoadAsset<GameObject>("Assets/LethalModding/MorphingCase/UI/UICase.prefab");
			if ((Object)(object)UI_MorphingCase == (Object)null)
			{
				Logger.LogError((object)"UI Morphing Case load fail");
			}
		}

		public void LoadMorphingCase(AssetBundle bundle)
		{
			Item val = bundle.LoadAsset<Item>("Assets/LethalModding/MorphingCase/Case/ShapeshiftCaseItem.asset");
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogError((object)"Morphing Case is NULL");
				return;
			}
			if ((Object)(object)val.spawnPrefab == (Object)null)
			{
				Logger.LogError((object)"Morphing Case spawnPrefab is NULL");
				return;
			}
			MorphingCase morphingCase = val.spawnPrefab.AddComponent<MorphingCase>();
			((GrabbableObject)morphingCase).grabbable = true;
			((GrabbableObject)morphingCase).grabbableToEnemies = true;
			((GrabbableObject)morphingCase).itemProperties = val;
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			Utilities.FixMixerGroups(val.spawnPrefab);
			Items.RegisterScrap(val, SillyThingsConfig.MorphingCaseItemRarity.Value, (LevelTypes)(-1));
			Logger.LogInfo((object)"Morphing Case loaded successfully");
		}
	}
}
namespace Silly_Things.codes.MorphingCase
{
	internal class ManageCosmetics
	{
		private List<string>? previousCosmetics;

		private int previousSuitId = -1;

		public bool HasStoredCosmetics => previousCosmetics != null;

		public void MorphToPlayer(PlayerControllerB source)
		{
			PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController;
			if (!((Object)(object)source == (Object)null) && !((Object)(object)localPlayerController == (Object)null) && localPlayerController.isPlayerControlled)
			{
				SavePreviousState(localPlayerController);
				ApplyCosmetics(localPlayerController, source);
				ApplySuit(localPlayerController, source);
			}
		}

		public void RestorePreviousCosmetics()
		{
			PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController;
			if (!((Object)(object)localPlayerController == (Object)null) && previousCosmetics != null)
			{
				RestoreCosmetics(localPlayerController);
				RestoreSuit(localPlayerController);
				previousCosmetics = null;
				previousSuitId = -1;
			}
		}

		private void SavePreviousState(PlayerControllerB target)
		{
			previousCosmetics = new List<string>(CosmeticRegistry.locallySelectedCosmetics);
			previousSuitId = target.currentSuitID;
		}

		private void ApplyCosmetics(PlayerControllerB target, PlayerControllerB source)
		{
			if (MainClass.playerIdsAndCosmetics.TryGetValue((int)source.playerClientId, out var value))
			{
				CosmeticRegistry.locallySelectedCosmetics.Clear();
				CosmeticRegistry.locallySelectedCosmetics.AddRange(value);
				CosmeticSyncPatch.SyncCosmeticsToOtherClients((PlayerControllerB)null, false, false);
			}
		}

		private void RestoreCosmetics(PlayerControllerB target)
		{
			target.movementAudio.PlayOneShot(StartOfRound.Instance.changeSuitSFX);
			CosmeticRegistry.locallySelectedCosmetics.Clear();
			CosmeticRegistry.locallySelectedCosmetics.AddRange(previousCosmetics);
			CosmeticSyncPatch.SyncCosmeticsToOtherClients((PlayerControllerB)null, false, false);
		}

		private void ApplySuit(PlayerControllerB target, PlayerControllerB source)
		{
			target.currentSuitID = source.currentSuitID;
			target.movementAudio.PlayOneShot(StartOfRound.Instance.changeSuitSFX);
			MorphingCase.Instance?.ChangeSuitServerRpc(target.playerClientId, source.currentSuitID);
		}

		private void RestoreSuit(PlayerControllerB target)
		{
			if (previousSuitId != -1)
			{
				MorphingCase.Instance?.ChangeSuitServerRpc(target.playerClientId, previousSuitId);
			}
		}

		public static bool IsValidPlayer(PlayerControllerB player)
		{
			return (Object)(object)player != (Object)null && player.isPlayerControlled && !string.IsNullOrEmpty(player.playerUsername);
		}
	}
	public class MorphingCase : PhysicsProp
	{
		private readonly MorphingCaseUi ui = new MorphingCaseUi();

		public static MorphingCase? Instance { get; set; }

		public override void OnNetworkSpawn()
		{
			((NetworkBehaviour)this).OnNetworkSpawn();
			Instance = this;
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (((NetworkBehaviour)((GrabbableObject)this).playerHeldBy).IsOwner && !ui.IsOpen)
			{
				ui.OpenUI();
			}
		}

		public override void DiscardItem()
		{
			((GrabbableObject)this).DiscardItem();
			Plugin.Instance.CosmeticsManager.RestorePreviousCosmetics();
			ui.ForceCloseUI();
		}

		[ServerRpc(RequireOwnership = false)]
		public void ChangeSuitServerRpc(ulong playerId, int sourceSuitId)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(329689628u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, playerId);
					BytePacker.WriteValueBitPacked(val2, sourceSuitId);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 329689628u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					((NetworkBehaviour)this).__rpc_exec_stage = (__RpcExecStage)0;
					ChangeSuitClientRpc(playerId, sourceSuitId);
				}
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void SyncSoundsServerRpc(int idSound)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2943084615u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, idSound);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2943084615u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					((NetworkBehaviour)this).__rpc_exec_stage = (__RpcExecStage)0;
					SyncSoundsClientRpc(idSound);
				}
			}
		}

		[ClientRpc]
		public void SyncSoundsClientRpc(int idSound)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(215669224u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, idSound);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 215669224u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				((NetworkBehaviour)this).__rpc_exec_stage = (__RpcExecStage)0;
				switch (idSound)
				{
				case 0:
					HUDManager.Instance.UIAudio.PlayOneShot(Plugin.Instance.SoundOpenUI);
					break;
				case 1:
					HUDManager.Instance.UIAudio.PlayOneShot(Plugin.Instance.SoundCloseUI);
					break;
				}
			}
		}

		[ClientRpc]
		public void ChangeSuitClientRpc(ulong playerId, int sourceSuitId)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(880211545u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, playerId);
					BytePacker.WriteValueBitPacked(val2, sourceSuitId);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 880211545u, val, (RpcDelivery)0);
				}
				if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					((NetworkBehaviour)this).__rpc_exec_stage = (__RpcExecStage)0;
					PlayerControllerB val3 = StartOfRound.Instance.allPlayerScripts[playerId];
					UnlockableSuit.SwitchSuitForPlayer(val3, sourceSuitId, true);
				}
			}
		}

		protected override void __initializeVariables()
		{
			((PhysicsProp)this).__initializeVariables();
		}

		protected override void __initializeRpcs()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			((NetworkBehaviour)this).__registerRpc(329689628u, new RpcReceiveHandler(__rpc_handler_329689628), "ChangeSuitServerRpc");
			((NetworkBehaviour)this).__registerRpc(2943084615u, new RpcReceiveHandler(__rpc_handler_2943084615), "SyncSoundsServerRpc");
			((NetworkBehaviour)this).__registerRpc(215669224u, new RpcReceiveHandler(__rpc_handler_215669224), "SyncSoundsClientRpc");
			((NetworkBehaviour)this).__registerRpc(880211545u, new RpcReceiveHandler(__rpc_handler_880211545), "ChangeSuitClientRpc");
			((PhysicsProp)this).__initializeRpcs();
		}

		private static void __rpc_handler_329689628(NetworkBehaviour? target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: 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_0043: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				ulong playerId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref playerId);
				int sourceSuitId = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref sourceSuitId);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((MorphingCase)(object)target).ChangeSuitServerRpc(playerId, sourceSuitId);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2943084615(NetworkBehaviour? target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int idSound = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref idSound);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((MorphingCase)(object)target).SyncSoundsServerRpc(idSound);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_215669224(NetworkBehaviour? target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int idSound = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref idSound);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((MorphingCase)(object)target).SyncSoundsClientRpc(idSound);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_880211545(NetworkBehaviour? target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: 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_0043: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				ulong playerId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref playerId);
				int sourceSuitId = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref sourceSuitId);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((MorphingCase)(object)target).ChangeSuitClientRpc(playerId, sourceSuitId);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string? __getTypeName()
		{
			return "MorphingCase";
		}
	}
	internal class MorphingCaseUi
	{
		private bool isUIOpen;

		private GameObject? uiInstance;

		private Button? closeButton;

		private Button? resetButton;

		private Button? buttonLeft;

		private Button? buttonRight;

		private Transform? content;

		private Transform? contentRight;

		private Transform? playerTemplate;

		private ManageCosmetics? cosmeticsManager;

		private List<PlayerControllerB> overflowPlayers = new List<PlayerControllerB>();

		private int currentPage = 0;

		private const int playersPerPage = 6;

		public bool IsOpen => isUIOpen;

		public bool CanOpenUI(bool buttonDown)
		{
			return buttonDown && !isUIOpen && (Object)(object)Plugin.Instance.UI_MorphingCase != (Object)null;
		}

		public void OpenUI()
		{
			MorphingCase.Instance?.SyncSoundsServerRpc(0);
			uiInstance = Object.Instantiate<GameObject>(Plugin.Instance.UI_MorphingCase);
			if ((Object)(object)uiInstance == (Object)null)
			{
				Plugin.Logger.LogError((object)"UI instance null");
				return;
			}
			cosmeticsManager = Plugin.Instance.CosmeticsManager;
			CacheUIRefs();
			if ((Object)(object)resetButton != (Object)null)
			{
				((Selectable)resetButton).interactable = Plugin.Instance.CosmeticsManager.HasStoredCosmetics;
			}
			EnableCursor(state: true);
			BuildPlayerList();
			isUIOpen = true;
		}

		public void ForceCloseUI()
		{
			MorphingCase.Instance?.SyncSoundsServerRpc(1);
			if ((Object)(object)uiInstance != (Object)null)
			{
				Object.Destroy((Object)(object)uiInstance);
			}
			uiInstance = null;
			isUIOpen = false;
			EnableCursor(state: false);
		}

		private void CacheUIRefs()
		{
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Expected O, but got Unknown
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Expected O, but got Unknown
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Expected O, but got Unknown
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Expected O, but got Unknown
			Transform obj = uiInstance.transform.Find("Panel/Panel/ButtonClose");
			closeButton = ((obj != null) ? ((Component)obj).GetComponent<Button>() : null);
			Transform obj2 = uiInstance.transform.Find("Panel/Panel/ButtonReset");
			resetButton = ((obj2 != null) ? ((Component)obj2).GetComponent<Button>() : null);
			Transform obj3 = uiInstance.transform.Find("Panel/ButtonLeft");
			buttonLeft = ((obj3 != null) ? ((Component)obj3).GetComponent<Button>() : null);
			Transform obj4 = uiInstance.transform.Find("Panel/ButtonRight");
			buttonRight = ((obj4 != null) ? ((Component)obj4).GetComponent<Button>() : null);
			content = uiInstance.transform.Find("Panel/Panel/PanelLeft/Viewport/Content");
			contentRight = uiInstance.transform.Find("Panel/Panel/PanelRight/Viewport/Content");
			playerTemplate = content.Find("PlayerNames");
			if ((Object)(object)closeButton != (Object)null)
			{
				((UnityEvent)closeButton.onClick).AddListener(new UnityAction(ForceCloseUI));
			}
			if ((Object)(object)resetButton != (Object)null)
			{
				((UnityEvent)resetButton.onClick).AddListener((UnityAction)delegate
				{
					cosmeticsManager.RestorePreviousCosmetics();
					((Selectable)resetButton).interactable = false;
				});
				((Selectable)resetButton).interactable = false;
			}
			if ((Object)(object)buttonLeft != (Object)null)
			{
				((UnityEvent)buttonLeft.onClick).AddListener((UnityAction)delegate
				{
					ChangePage(-1);
				});
			}
			if ((Object)(object)buttonRight != (Object)null)
			{
				((UnityEvent)buttonRight.onClick).AddListener((UnityAction)delegate
				{
					ChangePage(1);
				});
			}
			if ((Object)(object)playerTemplate != (Object)null)
			{
				((Component)playerTemplate).gameObject.SetActive(false);
			}
		}

		private void BuildPlayerList()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Expected O, but got Unknown
			if ((Object)(object)content == (Object)null || (Object)(object)contentRight == (Object)null || (Object)(object)playerTemplate == (Object)null)
			{
				return;
			}
			foreach (Transform item in content)
			{
				Transform val = item;
				if ((Object)(object)val != (Object)(object)playerTemplate)
				{
					Object.Destroy((Object)(object)((Component)val).gameObject);
				}
			}
			foreach (Transform item2 in contentRight)
			{
				Transform val2 = item2;
				if ((Object)(object)val2 != (Object)(object)playerTemplate)
				{
					Object.Destroy((Object)(object)((Component)val2).gameObject);
				}
			}
			overflowPlayers.Clear();
			currentPage = 0;
			PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController;
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val3 in allPlayerScripts)
			{
				if (ManageCosmetics.IsValidPlayer(val3) && !((Object)(object)val3 == (Object)(object)localPlayerController))
				{
					overflowPlayers.Add(val3);
				}
			}
			RefreshPage();
		}

		private void CreatePlayerEntry(PlayerControllerB source, Transform parentContent)
		{
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB source2 = source;
			GameObject val = Object.Instantiate<GameObject>(((Component)playerTemplate).gameObject, parentContent);
			val.SetActive(true);
			Transform obj = val.transform.Find("ButtonPlayer/PlayerName");
			TMP_Text val2 = ((obj != null) ? ((Component)obj).GetComponent<TMP_Text>() : null);
			if ((Object)(object)val2 != (Object)null)
			{
				val2.text = source2.playerUsername;
			}
			Transform obj2 = val.transform.Find("ButtonPlayer");
			Button val3 = ((obj2 != null) ? ((Component)obj2).GetComponent<Button>() : null);
			if ((Object)(object)val3 != (Object)null)
			{
				((UnityEventBase)val3.onClick).RemoveAllListeners();
				((UnityEvent)val3.onClick).AddListener((UnityAction)delegate
				{
					cosmeticsManager.MorphToPlayer(source2);
					if ((Object)(object)resetButton != (Object)null)
					{
						((Selectable)resetButton).interactable = true;
					}
				});
			}
			RawImage componentInChildren = val.GetComponentInChildren<RawImage>(true);
			bool flag = !GameNetworkManager.Instance.disableSteam;
			if ((Object)(object)componentInChildren != (Object)null)
			{
				if (flag)
				{
					HUDManager.FillImageWithSteamProfile(componentInChildren, SteamId.op_Implicit(source2.playerSteamId), true);
				}
				else
				{
					((Component)componentInChildren).gameObject.SetActive(false);
				}
			}
			else
			{
				Plugin.Logger.LogError((object)"avatar fail to clone");
			}
		}

		private void ChangePage(int delta)
		{
			int num = Mathf.Max(0, Mathf.CeilToInt((float)overflowPlayers.Count / 6f) - 1);
			currentPage = Mathf.Clamp(currentPage + delta, 0, num);
			RefreshPage();
		}

		private void RefreshPage()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Expected O, but got Unknown
			foreach (Transform item in content)
			{
				Transform val = item;
				if ((Object)(object)val != (Object)(object)playerTemplate)
				{
					Object.Destroy((Object)(object)((Component)val).gameObject);
				}
			}
			foreach (Transform item2 in contentRight)
			{
				Transform val2 = item2;
				if ((Object)(object)val2 != (Object)(object)playerTemplate)
				{
					Object.Destroy((Object)(object)((Component)val2).gameObject);
				}
			}
			int num = currentPage * 6;
			int num2 = Mathf.Min(num + 6, overflowPlayers.Count);
			for (int i = num; i < num2; i++)
			{
				PlayerControllerB source = overflowPlayers[i];
				Transform parentContent = ((i - num < 3) ? content : contentRight);
				CreatePlayerEntry(source, parentContent);
			}
			int num3 = Mathf.Max(0, Mathf.CeilToInt((float)overflowPlayers.Count / 6f) - 1);
			bool flag = num3 > 0;
			if ((Object)(object)buttonLeft != (Object)null)
			{
				((Component)buttonLeft).gameObject.SetActive(flag);
				((Selectable)buttonLeft).interactable = flag && currentPage > 0;
			}
			if ((Object)(object)buttonRight != (Object)null)
			{
				((Component)buttonRight).gameObject.SetActive(flag);
				((Selectable)buttonRight).interactable = flag && currentPage < num3;
			}
		}

		private static void EnableCursor(bool state)
		{
			Cursor.visible = state;
			Cursor.lockState = (CursorLockMode)((!state) ? 1 : 0);
			StartOfRound.Instance.localPlayerController.disableLookInput = state;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace __GEN
{
	internal class NetworkVariableSerializationHelper
	{
		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeSerialization()
		{
		}
	}
}
namespace Silly_Things.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}