Decompiled source of LethalCreature v3.2.1

BepInEx/plugins/CackleCrewMR.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using CackleCrew.Helpers;
using CackleCrew.ThisIsMagical;
using CackleCrewMR.Helpers;
using CreatureModelReplacement;
using GameNetcodeStuff;
using HarmonyLib;
using ModelReplacement;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Rendering;
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("CackleCrewMR")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+a0f596654c391411c90e6dd0afb987fe40852359")]
[assembly: AssemblyProduct("CackleCrewMR")]
[assembly: AssemblyTitle("CackleCrewMR")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace CackleCrewMR.Helpers
{
	public static class SavedProfileHelper
	{
		public static Dictionary<string, ConfigEntry<string>> savedConfigs = new Dictionary<string, ConfigEntry<string>>();

		public static ConfigEntry<string> currentConfig;

		public static ConfigEntry<string> outfitEnabledConfig;

		public static string CurrentConfig => currentConfig.Value;

		public static bool UseOutfits
		{
			get
			{
				return outfitEnabledConfig.Value == "TRUE";
			}
			set
			{
				outfitEnabledConfig.Value = (value ? "TRUE" : "FALSE");
			}
		}

		public static void Init()
		{
			CreateDefaultProfileConfig();
			currentConfig = CreateProfileConfig("Current");
			CreateProfileConfig("A");
			CreateProfileConfig("B");
			CreateProfileConfig("C");
			CreateProfileConfig("D");
		}

		public static void CreateDefaultProfileConfig()
		{
			outfitEnabledConfig = Plugin.config.Bind<string>("Saved Profiles", "Use Suit Outfits", "TRUE", (ConfigDescription)null);
		}

		public static ConfigEntry<string> CreateProfileConfig(string configName)
		{
			if (savedConfigs.ContainsKey(configName))
			{
				return savedConfigs[configName];
			}
			ConfigEntry<string> val = Plugin.config.Bind<string>("Saved Profiles", "Profile " + configName, "None", (ConfigDescription)null);
			savedConfigs.Add(configName, val);
			return val;
		}

		public static void UpdatePlayerProfile(Profile profile)
		{
			if (CompatibilityKit.IsOldProfileData(currentConfig.Value))
			{
				CompatibilityKit.Deserialize_OldProfileData(profile, currentConfig.Value);
			}
			else
			{
				profile.Deserialize(currentConfig.Value);
			}
			if (UseOutfits)
			{
				profile.SetData("OUTFIT", "TRUE");
			}
			else
			{
				profile.SetData("OUTFIT", "FALSE");
			}
		}

		public static void UpdatePlayerProfile(string profileName)
		{
			UpdatePlayerProfile(ProfileHelper.TouchPlayerProfile(profileName));
		}

		public static void UpdateConfig(Profile profile)
		{
			string value = profile.Serialize();
			if (string.IsNullOrWhiteSpace(value))
			{
				currentConfig.Value = "None";
			}
			else
			{
				currentConfig.Value = value;
			}
		}

		public static void UpdateConfig(string profileName)
		{
			UpdateConfig(ProfileHelper.TouchPlayerProfile(profileName));
		}

		public static void SaveConfig(string configName)
		{
			if (savedConfigs.TryGetValue(configName, out var value))
			{
				value.Value = currentConfig.Value;
			}
		}

		public static void LoadConfig(string configName)
		{
			if (savedConfigs.TryGetValue(configName, out var value))
			{
				currentConfig.Value = value.Value;
			}
		}
	}
}
namespace CackleCrew.UI
{
	internal static class UIManager
	{
		public static CackleCrewUIHandler cacklecrewUI;

		public static CackleCrewUITogglerHandler cacklecrewtogglerUI;

		public static QuickMenuManager currentMenuManager;

		public static void Init(QuickMenuManager quickMenuManager)
		{
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			currentMenuManager = quickMenuManager;
			if ((Object)(object)cacklecrewUI == (Object)null)
			{
				GameObject val = Assets.CustomizationAssetBundle.LoadAsset<GameObject>("CCUIProfile");
				GameObject val2 = Object.Instantiate<GameObject>(val, quickMenuManager.menuContainer.transform);
				cacklecrewUI = val2.AddComponent<CackleCrewUIHandler>();
			}
			if ((Object)(object)cacklecrewtogglerUI == (Object)null)
			{
				GameObject val3 = Assets.CustomizationAssetBundle.LoadAsset<GameObject>("CCToggle");
				GameObject val4 = Object.Instantiate<GameObject>(val3, quickMenuManager.menuContainer.transform);
				cacklecrewtogglerUI = val4.AddComponent<CackleCrewUITogglerHandler>();
				((UnityEvent)((Component)cacklecrewtogglerUI).GetComponent<Button>().onClick).AddListener(new UnityAction(ToggleCrewUIButtonClicked));
			}
		}

		public static void ToggleCrewUI(bool open)
		{
			if ((Object)(object)currentMenuManager != (Object)null)
			{
				if (open && !((Component)cacklecrewUI).gameObject.activeSelf)
				{
					currentMenuManager.mainButtonsPanel.SetActive(false);
					currentMenuManager.EnableUIPanel(((Component)cacklecrewUI).gameObject);
					cacklecrewUI.UpdateProfileOptions();
				}
				else if (!open && ((Component)cacklecrewUI).gameObject.activeSelf)
				{
					currentMenuManager.mainButtonsPanel.SetActive(true);
					currentMenuManager.DisableUIPanel(((Component)cacklecrewUI).gameObject);
					cacklecrewUI.ApplyProfileOptions();
					ProfileHelper.ForceSyncUpdate();
				}
			}
		}

		public static void ToggleCrewUIButton(bool open)
		{
			if ((Object)(object)currentMenuManager != (Object)null && (Object)(object)cacklecrewtogglerUI != (Object)null)
			{
				((Component)cacklecrewtogglerUI).gameObject.SetActive(open);
			}
		}

		public static void ToggleCrewUIButtonClicked()
		{
			ToggleCrewUIButton(open: false);
			ToggleCrewUI(open: true);
		}

		public static void CrewUIExitButtonClicked()
		{
			ToggleCrewUI(open: false);
			ToggleCrewUIButton(open: true);
		}
	}
	[HarmonyPatch]
	internal static class UIManagerPatches
	{
		[HarmonyPatch(typeof(QuickMenuManager), "OpenQuickMenu")]
		[HarmonyPostfix]
		public static void OpenQuickMenu_Postfix_Patch(QuickMenuManager __instance)
		{
			UIManager.Init(__instance);
			UIManager.ToggleCrewUI(open: false);
		}

		[HarmonyPatch(typeof(QuickMenuManager), "EnableUIPanel")]
		[HarmonyPostfix]
		public static void EnableUIPanel_Postfix_Patch(QuickMenuManager __instance, GameObject enablePanel)
		{
			if ((Object)(object)enablePanel == (Object)(object)__instance.mainButtonsPanel)
			{
				UIManager.ToggleCrewUIButton(open: true);
			}
			else
			{
				UIManager.ToggleCrewUIButton(open: false);
			}
		}

		[HarmonyPatch(typeof(QuickMenuManager), "CloseQuickMenuPanels")]
		[HarmonyPostfix]
		public static void CloseQuickMenuPanels_Postfix_Patch(QuickMenuManager __instance)
		{
			UIManager.ToggleCrewUIButton(open: true);
		}

		[HarmonyPatch(typeof(QuickMenuManager), "CloseQuickMenu")]
		[HarmonyPostfix]
		public static void CloseQuickMenu_Postfix_Patch(QuickMenuManager __instance)
		{
			UIManager.Init(__instance);
			UIManager.ToggleCrewUI(open: false);
		}
	}
	internal class CackleCrewUIHandler : MonoBehaviour
	{
		public ModelPickerUIHandler modelPicker;

		public ColorPickerUIHandler colorPicker;

		public OptionsPickerUIHandler optionPicker;

		public ClipboardUIHandler clipboardHandler;

		public MenuToggleUIHandler suitPrimaryColor;

		public MenuToggleUIHandler suitSecondaryColor;

		public MenuToggleUIHandler lensColor;

		public MenuToggleUIHandler tankColor;

		public MenuToggleUIHandler patternOption;

		public MenuToggleUIHandler patternColor;

		public MenuToggleUIHandler paintOption;

		public MenuToggleUIHandler paintColor;

		public ProfileSavesUIHandler profileSaves;

		public Toggle useOutfit;

		public Button exitButton;

		public GameObject optionHider;

		public bool initialized = false;

		private void Start()
		{
			//IL_040d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0417: Expected O, but got Unknown
			modelPicker = ((Component)((Component)this).transform.Find("CrewSelection")).gameObject.AddComponent<ModelPickerUIHandler>();
			colorPicker = ((Component)((Component)this).transform.Find("Pickers/ColorPicker")).gameObject.AddComponent<ColorPickerUIHandler>();
			optionPicker = ((Component)((Component)this).transform.Find("Pickers/OptionPicker")).gameObject.AddComponent<OptionsPickerUIHandler>();
			clipboardHandler = ((Component)((Component)this).transform.Find("Profiles/ClipboardComponent")).gameObject.AddComponent<ClipboardUIHandler>();
			suitPrimaryColor = ((Component)((Component)this).transform.Find("ColorStuff/SuitOptions/PrimaryColor")).gameObject.AddComponent<MenuToggleUIHandler>();
			suitSecondaryColor = ((Component)((Component)this).transform.Find("ColorStuff/SuitOptions/SecondaryColor")).gameObject.AddComponent<MenuToggleUIHandler>();
			lensColor = ((Component)((Component)this).transform.Find("ColorStuff/GearOptions/LensColor")).gameObject.AddComponent<MenuToggleUIHandler>();
			tankColor = ((Component)((Component)this).transform.Find("ColorStuff/GearOptions/TankColor")).gameObject.AddComponent<MenuToggleUIHandler>();
			patternOption = ((Component)((Component)this).transform.Find("ColorStuff/PatternOptions/PatternOption")).gameObject.AddComponent<MenuToggleUIHandler>();
			patternColor = ((Component)((Component)this).transform.Find("ColorStuff/PatternOptions/PatternColor")).gameObject.AddComponent<MenuToggleUIHandler>();
			paintOption = ((Component)((Component)this).transform.Find("ColorStuff/MarkingOptions/MarkingOption")).gameObject.AddComponent<MenuToggleUIHandler>();
			paintColor = ((Component)((Component)this).transform.Find("ColorStuff/MarkingOptions/MarkingColor")).gameObject.AddComponent<MenuToggleUIHandler>();
			profileSaves = ((Component)((Component)this).transform.Find("Profiles/ProfileList")).gameObject.AddComponent<ProfileSavesUIHandler>();
			useOutfit = ((Component)((Component)this).transform.Find("UseOutfits")).GetComponent<Toggle>();
			exitButton = ((Component)((Component)this).transform.Find("Back")).gameObject.GetComponent<Button>();
			optionHider = ((Component)((Component)this).transform.Find("SuitBGone")).gameObject;
			suitPrimaryColor.target = ((Component)colorPicker).transform;
			suitSecondaryColor.target = ((Component)colorPicker).transform;
			lensColor.target = ((Component)colorPicker).transform;
			tankColor.target = ((Component)colorPicker).transform;
			patternOption.target = ((Component)optionPicker).transform;
			patternColor.target = ((Component)colorPicker).transform;
			paintOption.target = ((Component)optionPicker).transform;
			paintColor.target = ((Component)colorPicker).transform;
			clipboardHandler.handler = this;
			suitPrimaryColor.Init();
			suitSecondaryColor.Init();
			lensColor.Init();
			tankColor.Init();
			patternOption.Init();
			patternColor.Init();
			paintOption.Init();
			paintColor.Init();
			modelPicker.Init();
			colorPicker.Init();
			optionPicker.Init();
			clipboardHandler.Init();
			profileSaves.Init();
			profileSaves.RegisterProfileOption("A", "ProA");
			profileSaves.RegisterProfileOption("B", "ProB");
			profileSaves.RegisterProfileOption("C", "ProC");
			profileSaves.RegisterProfileOption("D", "ProD");
			profileSaves.OnSaveClicked += SaveConfig;
			profileSaves.OnLoadClicked += LoadConfig;
			((Component)colorPicker).gameObject.SetActive(false);
			((Component)optionPicker).gameObject.SetActive(false);
			((UnityEvent)exitButton.onClick).AddListener(new UnityAction(UIManager.CrewUIExitButtonClicked));
			((UnityEvent<bool>)(object)useOutfit.onValueChanged).AddListener((UnityAction<bool>)ToggleCustomization);
			LoadDefaultConfig();
			initialized = true;
		}

		public void ToggleCustomization(bool enabled)
		{
			((Component)suitPrimaryColor).gameObject.SetActive(enabled);
			((Component)suitSecondaryColor).gameObject.SetActive(enabled);
			((Component)lensColor).gameObject.SetActive(enabled);
			((Component)tankColor).gameObject.SetActive(enabled);
			((Component)patternOption).gameObject.SetActive(enabled);
			((Component)patternColor).gameObject.SetActive(enabled);
			((Component)paintOption).gameObject.SetActive(enabled);
			((Component)paintColor).gameObject.SetActive(enabled);
			optionHider.SetActive(!enabled);
		}

		public void SaveConfig()
		{
			PlayerControllerB player;
			Profile profile = ProfileHelper.TouchLocalPlayerProfile(out player);
			if (profile != null)
			{
				ApplyProfileOptions();
				SavedProfileHelper.UpdateConfig(profile);
				SavedProfileHelper.SaveConfig(profileSaves.currentOption);
			}
		}

		public void LoadConfig()
		{
			PlayerControllerB player;
			Profile profile = ProfileHelper.TouchLocalPlayerProfile(out player);
			if (profile != null)
			{
				SavedProfileHelper.LoadConfig(profileSaves.currentOption);
				SavedProfileHelper.UpdatePlayerProfile(profile);
				UpdateProfileOptions();
			}
		}

		public void LoadDefaultConfig()
		{
			PlayerControllerB player;
			Profile profile = ProfileHelper.TouchLocalPlayerProfile(out player);
			if (profile != null)
			{
				SavedProfileHelper.UpdatePlayerProfile(profile);
				UpdateProfileOptions();
			}
		}

		public void UpdateProfileOptions()
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)modelPicker == (Object)null)
			{
				return;
			}
			PlayerControllerB player;
			Profile profile = ProfileHelper.TouchLocalPlayerProfile(out player);
			if (profile != null)
			{
				useOutfit.isOn = SavedProfileHelper.UseOutfits;
				ToggleCustomization(useOutfit.isOn);
				Color color = default(Color);
				if (ColorUtility.TryParseHtmlString(profile.GetData("PRIMARY"), ref color))
				{
					suitPrimaryColor.SetColor(color);
				}
				Color color2 = default(Color);
				if (ColorUtility.TryParseHtmlString(profile.GetData("HOOD"), ref color2))
				{
					suitSecondaryColor.SetColor(color2);
				}
				Color color3 = default(Color);
				if (ColorUtility.TryParseHtmlString(profile.GetData("LENS"), ref color3))
				{
					lensColor.SetColor(color3);
				}
				Color color4 = default(Color);
				if (ColorUtility.TryParseHtmlString(profile.GetData("TANK"), ref color4))
				{
					tankColor.SetColor(color4);
				}
				Color color5 = default(Color);
				if (ColorUtility.TryParseHtmlString(profile.GetData("SECONDARY"), ref color5))
				{
					patternColor.SetColor(color5);
				}
				Color color6 = default(Color);
				if (ColorUtility.TryParseHtmlString(profile.GetData("PAINTCOLOR"), ref color6))
				{
					paintColor.SetColor(color6);
				}
				patternOption.SetOption(profile.GetData("PATTERN"));
				paintOption.SetOption(profile.GetData("PAINT"));
				modelPicker.ChangeOption(profile.GetData("MODEL"));
			}
		}

		public void ApplyProfileOptions()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)modelPicker == (Object)null)
			{
				return;
			}
			PlayerControllerB player;
			Profile profile = ProfileHelper.TouchLocalPlayerProfile(out player);
			if (profile != null)
			{
				profile.SetData("PRIMARY", ColorUtility.ToHtmlStringRGB(((Graphic)suitPrimaryColor.shape).color), isRaw: true);
				profile.SetData("HOOD", ColorUtility.ToHtmlStringRGB(((Graphic)suitSecondaryColor.shape).color), isRaw: true);
				profile.SetData("LENS", ColorUtility.ToHtmlStringRGB(((Graphic)lensColor.shape).color), isRaw: true);
				profile.SetData("TANK", ColorUtility.ToHtmlStringRGB(((Graphic)tankColor.shape).color), isRaw: true);
				profile.SetData("SECONDARY", ColorUtility.ToHtmlStringRGB(((Graphic)patternColor.shape).color), isRaw: true);
				profile.SetData("PAINTCOLOR", ColorUtility.ToHtmlStringRGB(((Graphic)paintColor.shape).color), isRaw: true);
				profile.SetData("PATTERN", patternOption.data);
				profile.SetData("PAINT", paintOption.data);
				profile.SetData("MODEL", modelPicker.selected);
				SavedProfileHelper.UpdateConfig(profile);
				if (useOutfit.isOn || (!initialized && !SavedProfileHelper.UseOutfits))
				{
					SavedProfileHelper.UseOutfits = true;
					profile.SetData("OUTFIT", "TRUE");
				}
				else
				{
					SavedProfileHelper.UseOutfits = false;
					profile.SetData("OUTFIT", "FALSE");
				}
			}
		}
	}
	internal class CackleCrewUITogglerHandler : MonoBehaviour
	{
		private Button button;

		private void Start()
		{
		}
	}
	internal class ClipboardUIHandler : MonoBehaviour
	{
		public const string CLIPBOARD_PROFILE_PREFIX = "CAv1";

		public const string CLIPBOARD_PROFILE_PATTERN = "^CAv1[a-zA-Z][A-C][01][\\dA-F]{36}[0-4]{2}$";

		public CackleCrewUIHandler handler;

		public Button pasteButton;

		public Button copyButton;

		public void Init()
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			pasteButton = ((Component)((Component)this).transform.Find("Paste")).GetComponentInChildren<Button>();
			copyButton = ((Component)((Component)this).transform.Find("Copy")).GetComponentInChildren<Button>();
			((UnityEvent)pasteButton.onClick).AddListener(new UnityAction(PasteProfileFromClipboard));
			((UnityEvent)copyButton.onClick).AddListener(new UnityAction(CopyProfileToClipboard));
		}

		private void PasteProfileFromClipboard()
		{
			string text = FromClipboard();
			bool flag = CompatibilityKit.IsOldProfileData(text);
			PlayerControllerB player;
			Profile profile = ProfileHelper.TouchLocalPlayerProfile(out player);
			if (profile != null && (ValidateProfileData(text, out var profileData) || flag))
			{
				if (flag)
				{
					CompatibilityKit.Deserialize_OldProfileData(profile, text);
				}
				else
				{
					profile.Deserialize(profileData);
				}
				handler.UpdateProfileOptions();
			}
		}

		private void CopyProfileToClipboard()
		{
			PlayerControllerB player;
			Profile profile = ProfileHelper.TouchLocalPlayerProfile(out player);
			if (profile != null)
			{
				handler.ApplyProfileOptions();
				string text = profile.Serialize();
				ToClipboard("CAv1" + text);
			}
		}

		private bool ValidateProfileData(string input, out string profileData)
		{
			profileData = null;
			input = input.Trim();
			if (!Regex.IsMatch(input, "^CAv1[a-zA-Z][A-C][01][\\dA-F]{36}[0-4]{2}$"))
			{
				return false;
			}
			profileData = input.Substring("CAv1".Length);
			return true;
		}

		private string FromClipboard()
		{
			return GUIUtility.systemCopyBuffer;
		}

		private void ToClipboard(string text)
		{
			GUIUtility.systemCopyBuffer = text;
		}
	}
	internal class ColorPickerUIHandler : MonoBehaviour
	{
		public Color currentPickedColor;

		public Slider hueSlider;

		public Slider saturationSlider;

		public Slider valueSlider;

		public Image colorPreview;

		public Image saturationPreview;

		public Image saturationOverlayPreview;

		public Image valuePreview;

		public MenuToggleUIHandler watcher;

		public TMP_InputField hueInput;

		public TMP_InputField saturationInput;

		public TMP_InputField valueInput;

		public TMP_InputField webcolorInput;

		public Button webcolorApply;

		public void Init()
		{
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Expected O, but got Unknown
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			hueSlider = ((Component)((Component)this).transform.Find("PickerHue")).GetComponentInChildren<Slider>();
			saturationSlider = ((Component)((Component)this).transform.Find("PickerSaturation")).GetComponentInChildren<Slider>();
			valueSlider = ((Component)((Component)this).transform.Find("PickerValue")).GetComponentInChildren<Slider>();
			colorPreview = ((Component)((Component)this).transform.Find("Color")).GetComponent<Image>();
			saturationPreview = ((Component)((Component)this).transform.Find("PickerSaturation").Find("Hue")).GetComponent<Image>();
			saturationOverlayPreview = ((Component)((Component)this).transform.Find("PickerSaturation").Find("Saturation")).GetComponent<Image>();
			valuePreview = ((Component)((Component)this).transform.Find("PickerValue").Find("Hue")).GetComponent<Image>();
			hueInput = ((Component)((Component)this).transform.Find("InputHue")).GetComponent<TMP_InputField>();
			saturationInput = ((Component)((Component)this).transform.Find("InputSaturation")).GetComponent<TMP_InputField>();
			valueInput = ((Component)((Component)this).transform.Find("InputValue")).GetComponent<TMP_InputField>();
			webcolorInput = ((Component)((Component)this).transform.Find("InputWebColor")).GetComponent<TMP_InputField>();
			webcolorApply = ((Component)((Component)this).transform.Find("Apply")).GetComponent<Button>();
			((UnityEvent<float>)(object)hueSlider.onValueChanged).AddListener((UnityAction<float>)UpdateColor);
			((UnityEvent<float>)(object)saturationSlider.onValueChanged).AddListener((UnityAction<float>)UpdateColor);
			((UnityEvent<float>)(object)valueSlider.onValueChanged).AddListener((UnityAction<float>)UpdateColor);
			((UnityEvent<string>)(object)hueInput.onSubmit).AddListener((UnityAction<string>)CheckInputs);
			((UnityEvent<string>)(object)saturationInput.onSubmit).AddListener((UnityAction<string>)CheckInputs);
			((UnityEvent<string>)(object)valueInput.onSubmit).AddListener((UnityAction<string>)CheckInputs);
			((UnityEvent)webcolorApply.onClick).AddListener(new UnityAction(ApplyWebColor));
			SetColor(Color.red);
		}

		public void SetColor(Color color)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			float value = default(float);
			float value2 = default(float);
			float value3 = default(float);
			Color.RGBToHSV(color, ref value, ref value2, ref value3);
			hueSlider.value = value;
			saturationSlider.value = value2;
			valueSlider.value = value3;
			UpdateColor();
		}

		public void UpdateColor(float _ = 0f)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			currentPickedColor = Color.HSVToRGB(hueSlider.value, saturationSlider.value, valueSlider.value);
			Color color = Color.HSVToRGB(hueSlider.value, 1f, valueSlider.value);
			Color color2 = Color.HSVToRGB(hueSlider.value, 0f, valueSlider.value);
			Color color3 = Color.HSVToRGB(hueSlider.value, saturationSlider.value, 1f);
			((Graphic)colorPreview).color = currentPickedColor;
			((Graphic)saturationPreview).color = color;
			((Graphic)saturationOverlayPreview).color = color2;
			((Graphic)valuePreview).color = color3;
			UpdatePreview();
		}

		public void UpdatePreview()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)watcher != (Object)null)
			{
				((Graphic)watcher.shape).color = currentPickedColor;
			}
			UpdateInputs();
		}

		public void UpdateInputs()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			float num = default(float);
			float num2 = default(float);
			float num3 = default(float);
			Color.RGBToHSV(currentPickedColor, ref num, ref num2, ref num3);
			hueInput.text = ((int)(num * 100f)).ToString();
			saturationInput.text = ((int)(num2 * 100f)).ToString();
			valueInput.text = ((int)(num3 * 100f)).ToString();
			webcolorInput.text = ColorUtility.ToHtmlStringRGB(currentPickedColor);
		}

		public void CheckInputs(string text)
		{
			//IL_0002: 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)
			float default_value = default(float);
			float default_value2 = default(float);
			float default_value3 = default(float);
			Color.RGBToHSV(currentPickedColor, ref default_value, ref default_value2, ref default_value3);
			float num = CheckValueInput(hueInput.text, default_value);
			float num2 = CheckValueInput(saturationInput.text, default_value2);
			float num3 = CheckValueInput(valueInput.text, default_value3);
			SetColor(Color.HSVToRGB(num, num2, num3));
		}

		public float CheckValueInput(string input, float default_value)
		{
			if (!float.TryParse(input, out var result))
			{
				return default_value;
			}
			return Mathf.Clamp(result / 100f, 0f, 1f);
		}

		public void ApplyWebColor()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			Color color = default(Color);
			if (ColorUtility.TryParseHtmlString(CheckHTMLString(webcolorInput.text), ref color))
			{
				SetColor(color);
			}
		}

		public string CheckHTMLString(string text)
		{
			return "#" + text.Replace("#", string.Empty);
		}
	}
	internal class MenuToggleUIHandler : MonoBehaviour
	{
		public Button button;

		public Image shape;

		public Transform target;

		public string data;

		public void Init()
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			button = ((Component)((Component)this).transform.Find("Button")).GetComponent<Button>();
			shape = ((Component)((Component)this).transform.Find("Shape")).GetComponent<Image>();
			((UnityEvent)button.onClick).AddListener(new UnityAction(ToggleUI));
		}

		public void ToggleUI()
		{
			if ((Object)(object)target != (Object)null)
			{
				SetUIActive(!((Component)target).gameObject.activeSelf);
				if (((Component)target).gameObject.activeSelf)
				{
					EventSystem.current.SetSelectedGameObject(((Component)target).gameObject);
				}
			}
		}

		public void SetSprite(Sprite sprite)
		{
			shape.sprite = sprite;
		}

		public void SetColor(Color color)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			((Graphic)shape).color = color;
		}

		public void SetOption(string data)
		{
			this.data = data;
			Component val = default(Component);
			if (((Component)target).TryGetComponent(typeof(OptionsPickerUIHandler), ref val))
			{
				OptionsPickerUIHandler optionsPickerUIHandler = (OptionsPickerUIHandler)(object)val;
				SetSprite(optionsPickerUIHandler.GetOptionSprite(data));
			}
		}

		public void SetUIActive(bool visible)
		{
			//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)
			if ((Object)(object)target != (Object)null)
			{
				((Component)target).gameObject.SetActive(visible);
				target.position = ((Component)button).transform.position;
				Component val = default(Component);
				if (((Component)target).TryGetComponent(typeof(ColorPickerUIHandler), ref val))
				{
					ColorPickerUIHandler colorPickerUIHandler = (ColorPickerUIHandler)(object)val;
					colorPickerUIHandler.watcher = this;
					colorPickerUIHandler.SetColor(((Graphic)shape).color);
				}
				if (((Component)target).TryGetComponent(typeof(OptionsPickerUIHandler), ref val))
				{
					OptionsPickerUIHandler optionsPickerUIHandler = (OptionsPickerUIHandler)(object)val;
					optionsPickerUIHandler.watcher = this;
					optionsPickerUIHandler.SetOption(data);
				}
				if (visible)
				{
					EventSystem.current.SetSelectedGameObject(((Component)target).gameObject);
				}
			}
		}

		private void Update()
		{
			if ((Object)(object)target != (Object)null && ((Component)target).gameObject.activeSelf && !IsUIFocused(((Component)target).gameObject) && !IsUIFocused(((Component)button).gameObject))
			{
				SetUIActive(visible: false);
			}
		}

		private bool IsUIFocused(GameObject go)
		{
			return (Object)(object)EventSystem.current.currentSelectedGameObject != (Object)null && ((Object)(object)EventSystem.current.currentSelectedGameObject == (Object)(object)go || EventSystem.current.currentSelectedGameObject.transform.IsChildOf(go.transform));
		}
	}
	internal class ModelButtonUIHandler : MonoBehaviour
	{
		public Color selectedColor;

		public Color unselectedColor;

		public Image panel;

		public Image image;

		public TMP_Text text;

		public void Init()
		{
			ColorUtility.TryParseHtmlString("#FFE7C9", ref selectedColor);
			ColorUtility.TryParseHtmlString("#FD7D3E", ref unselectedColor);
			unselectedColor.a = 0.3f;
			panel = ((Component)((Component)this).transform.Find("Panel")).GetComponent<Image>();
			image = ((Component)((Component)this).transform.Find("Image")).GetComponent<Image>();
			text = ((Component)((Component)this).transform.Find("Text")).GetComponent<TMP_Text>();
		}

		public void ToggleUI(bool selected)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			Color color = ((Graphic)image).color;
			Color color2 = ((Graphic)text).color;
			if (selected)
			{
				((Graphic)panel).color = selectedColor;
				color.a = 1f;
				color2.a = 1f;
			}
			else
			{
				((Graphic)panel).color = unselectedColor;
				color.a = 0.75f;
				color2.a = 0.75f;
			}
			((Graphic)image).color = color;
			((Graphic)text).color = color2;
		}
	}
	internal class ModelPickerUIHandler : MonoBehaviour
	{
		public Dictionary<string, ModelButtonUIHandler> options = new Dictionary<string, ModelButtonUIHandler>();

		public string selected;

		public void Init()
		{
			ScanForOptions();
			ChangeOption(options.Keys.First());
		}

		private void ScanForOptions()
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			for (int i = 0; i < ((Component)this).transform.childCount; i++)
			{
				GameObject child = ((Component)((Component)this).transform.GetChild(i)).gameObject;
				ModelButtonUIHandler modelButtonUIHandler = child.AddComponent<ModelButtonUIHandler>();
				modelButtonUIHandler.Init();
				options.Add(((Object)child).name, modelButtonUIHandler);
				((UnityEvent)((Component)((Component)modelButtonUIHandler).transform).GetComponent<Button>().onClick).AddListener((UnityAction)delegate
				{
					ChangeOption(((Object)child).name);
				});
			}
		}

		public void ChangeOption(string name)
		{
			foreach (KeyValuePair<string, ModelButtonUIHandler> option in options)
			{
				if (option.Key != name)
				{
					option.Value.ToggleUI(selected: false);
				}
				else
				{
					option.Value.ToggleUI(selected: true);
				}
			}
			selected = name;
		}

		private void OnEnable()
		{
			PlayerControllerB player;
			Profile profile = ProfileHelper.TouchLocalPlayerProfile(out player);
			if (profile != null)
			{
				ChangeOption(profile.GetData("MODEL"));
			}
		}
	}
	internal class OptionsPickerUIHandler : MonoBehaviour
	{
		public Dictionary<Image, Image> pairedOptions = new Dictionary<Image, Image>();

		public MenuToggleUIHandler watcher;

		public string currentOption;

		public void Init()
		{
			ScanForOptions();
		}

		public void ToggleUI()
		{
			((Component)this).gameObject.SetActive(!((Component)this).gameObject.activeSelf);
		}

		private void ScanForOptions()
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			Transform val = ((Component)this).transform.Find("Options");
			for (int i = 0; i < val.childCount; i++)
			{
				Image childImage = ((Component)val.GetChild(i)).GetComponent<Image>();
				Image component = ((Component)((Component)childImage).transform.Find("Shape")).GetComponent<Image>();
				Button component2 = ((Component)childImage).GetComponent<Button>();
				pairedOptions.Add(childImage, component);
				((UnityEvent)component2.onClick).AddListener((UnityAction)delegate
				{
					OptionSelected(childImage);
				});
			}
			OptionSelected(pairedOptions.Keys.First(), toggle: false);
		}

		private void OptionSelected(Image origin, bool toggle = true)
		{
			SetOption(((Object)((Component)origin).gameObject).name);
			if (toggle)
			{
				ToggleUI();
			}
		}

		public void SetOption(string name)
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			foreach (KeyValuePair<Image, Image> pairedOption in pairedOptions)
			{
				if (((Object)((Component)pairedOption.Key).gameObject).name != name)
				{
					Color color = ((Graphic)pairedOption.Key).color;
					color.a = 0f;
					((Graphic)pairedOption.Key).color = color;
					continue;
				}
				Color color2 = ((Graphic)pairedOption.Key).color;
				color2.a = 1f;
				((Graphic)pairedOption.Key).color = color2;
				if ((Object)(object)watcher != (Object)null)
				{
					watcher.SetOption(name);
				}
				currentOption = name;
			}
		}

		public Sprite GetOptionSprite(string name)
		{
			foreach (KeyValuePair<Image, Image> pairedOption in pairedOptions)
			{
				if (((Object)((Component)pairedOption.Key).gameObject).name == name)
				{
					return pairedOption.Value.sprite;
				}
			}
			return null;
		}
	}
	internal class ProfileSavesUIHandler : MonoBehaviour
	{
		public delegate void profileSelected(string profileName);

		public delegate void buttonClicked();

		private struct UIOption
		{
			public Button button;

			public Image image;
		}

		private Dictionary<string, UIOption> options = new Dictionary<string, UIOption>();

		public string currentOption = string.Empty;

		private Color selectedColor;

		private Color deselectedColor;

		private Button saveButton;

		private Button loadButton;

		public event profileSelected OnProfileSelected;

		public event buttonClicked OnSaveClicked;

		public event buttonClicked OnLoadClicked;

		public void Init()
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			saveButton = ((Component)((Component)this).transform.Find("Save")).GetComponent<Button>();
			loadButton = ((Component)((Component)this).transform.Find("Load")).GetComponent<Button>();
			ColorUtility.TryParseHtmlString("#FFE7C9", ref selectedColor);
			ColorUtility.TryParseHtmlString("#A04C23", ref deselectedColor);
			((UnityEvent)saveButton.onClick).AddListener((UnityAction)delegate
			{
				this.OnSaveClicked?.Invoke();
			});
			((UnityEvent)loadButton.onClick).AddListener((UnityAction)delegate
			{
				this.OnLoadClicked?.Invoke();
			});
		}

		public void RegisterProfileOption(string profileName, string child)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			Transform val = ((Component)this).transform.Find(child);
			if (Object.op_Implicit((Object)(object)val))
			{
				UIOption uIOption = default(UIOption);
				uIOption.button = ((Component)val).GetComponent<Button>();
				uIOption.image = ((Component)val).GetComponent<Image>();
				UIOption value = uIOption;
				((UnityEvent)value.button.onClick).AddListener((UnityAction)delegate
				{
					Option_OnClick(profileName);
				});
				options.Add(profileName, value);
				if (options.Count == 1)
				{
					Option_OnClick(profileName);
				}
			}
		}

		public void Option_OnClick(string profileName)
		{
			this.OnProfileSelected?.Invoke(profileName);
			currentOption = profileName;
			UpdateVisuals();
		}

		public void UpdateVisuals()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			foreach (KeyValuePair<string, UIOption> option in options)
			{
				if (option.Key != currentOption)
				{
					((Graphic)option.Value.image).color = deselectedColor;
				}
				else
				{
					((Graphic)option.Value.image).color = selectedColor;
				}
			}
		}
	}
}
namespace CackleCrew.ThisIsMagical
{
	internal static class Options
	{
		public static void Init()
		{
			SetDefaultProfile();
			RegisterAssets();
			SavedProfileHelper.Init();
		}

		public static void RegisterAssets()
		{
			RegisterVanillaModels();
			RegisterSuitMaterials();
			RegisterMoreSuitsMaterials();
		}

		public static void RegisterSuitMaterials()
		{
			RegisterProfileData("A:Default", "vA1A93C14C38F68FF8E001DD44DFDD9C9E0BB9F10");
			RegisterProfileData("A:Orange suit", "vA1A93C14C38F68FF8E001DD44DFDD9C9E0BB9F10");
			RegisterProfileData("A:Green suit", "SA1687600F1DCC7D67825FFD6C69A952CB9835A12");
			RegisterProfileData("A:Hazard suit", "YA1E2913DE2913DC35220FF4400B24E1C4F342733");
			RegisterProfileData("A:Pajama suit", "YA164937DE0C3A6F56C0FFF7D01E0C3A6ECA87511");
			RegisterProfileData("A:Purple Suit", "lA1733B90733B90CF7A24FF9C00A15F3CBE866442");
			RegisterProfileData("B:Default", "rB19A421FCC8E269A948F6DC57DCC9882B2836613");
			RegisterProfileData("B:Orange suit", "rB19A421FCC8E269A948F6DC57DCC9882B2836613");
			RegisterProfileData("B:Green suit", "QB171730E623F13C3930DF8CA89E3A931B2836612");
			RegisterProfileData("B:Hazard suit", "jB1DB8205BE3C11E9B283EC310A9C1A0767350F33");
			RegisterProfileData("B:Pajama suit", "nB1578A73B28366C86025FF8414B99B71B2836611");
			RegisterProfileData("B:Purple Suit", "rB17E43B4CC8E26935B83FFA0009C5B3FB2836624");
			RegisterProfileData("C:Default", "rC1A44810C36E10FF9D0441CF55D4BA9FE0BB9F11");
			RegisterProfileData("C:Orange suit", "rC1A44810C36E10FF9D0441CF55D4BA9FE0BB9F11");
			RegisterProfileData("C:Green suit", "zC167781DE27E0CBC3026F1C689D4BA9FE0BB9F10");
			RegisterProfileData("C:Hazard suit", "MC1D17919873BECE02E00E02E0072381F542F1532");
			RegisterProfileData("C:Pajama suit", "SC15C9F69FF9E00FF5F04FF5F04DEEE98E0BB9F13");
			RegisterProfileData("C:Purple Suit", "QC17243B9FF8600C9B9A1D42A1BC5884DE0BB9F44");
		}

		public static void RegisterMoreSuitsMaterials()
		{
			Profile.CloneProfile("A:CARed", "A:Default");
			Profile.CloneProfile("A:CAGreen", "A:Green suit");
			Profile.CloneProfile("A:CAHaz", "A:Hazard suit");
			Profile.CloneProfile("A:CAPajam", "A:Pajama suit");
			Profile.CloneProfile("A:CAPurple", "A:Purple Suit");
			Profile.CloneProfile("B:CARed", "B:Default");
			Profile.CloneProfile("B:CAGreen", "B:Green suit");
			Profile.CloneProfile("B:CAHaz", "B:Hazard suit");
			Profile.CloneProfile("B:CAPajam", "B:Pajama suit");
			Profile.CloneProfile("B:CAPurple", "B:Purple Suit");
			Profile.CloneProfile("C:CARed", "C:Default");
			Profile.CloneProfile("C:CAGreen", "C:Green suit");
			Profile.CloneProfile("C:CAHaz", "C:Hazard suit");
			Profile.CloneProfile("C:CAPajam", "C:Pajama suit");
			Profile.CloneProfile("C:CAPurple", "C:Purple Suit");
		}

		public static void RegisterVanillaModels()
		{
			ModelKit.RegisterModel("A", Assets.MainAssetBundle.LoadAsset<GameObject>("CreatureA"));
			ModelKit.RegisterModel("B", Assets.MainAssetBundle.LoadAsset<GameObject>("CreatureB"));
			ModelKit.RegisterModel("C", Assets.MainAssetBundle.LoadAsset<GameObject>("CreatureC"));
		}

		public static void RegisterProfileData(string profileName, string profileData)
		{
			Profile profile = ProfileHelper.TouchPlayerProfile(profileName);
			profile.Deserialize(profileData);
			profile.SetData("OUTFIT", "FALSE");
		}

		public static void SetDefaultProfile()
		{
			Profile profile = Profile.CreateProfile(ProfileHelper.DefaultProfile);
			profile.SetData("MODEL", "A", isRaw: false, ProfileDataType.Character);
			profile.SetData("OUTFIT", "FALSE", isRaw: false, ProfileDataType.Boolean);
			profile.SetData("PRIMARY", "#A93C14", isRaw: false, ProfileDataType.Color);
			profile.SetData("HOOD", "#C38F68", isRaw: false, ProfileDataType.Color);
			profile.SetData("TANK", "#FF8E00", isRaw: false, ProfileDataType.Color);
			profile.SetData("LENS", "#1DD44D", isRaw: false, ProfileDataType.Color);
			profile.SetData("SECONDARY", "#FDD9C9", isRaw: false, ProfileDataType.Color);
			profile.SetData("PAINTCOLOR", "#E0BB9F", isRaw: false, ProfileDataType.Color);
			profile.SetData("PAINT", "A", isRaw: false, ProfileDataType.ShaderOption);
			profile.SetData("PATTERN", "NONE", isRaw: false, ProfileDataType.ShaderOption);
		}
	}
	[HarmonyPatch]
	internal static class OptionsPatch
	{
		[HarmonyPatch(typeof(StartOfRound), "OnDestroy")]
		[HarmonyPostfix]
		public static void OnDestroy_Postfix(ref StartOfRound __instance)
		{
			Profile.FilterDeleteProfiles(new string[1] { "DEFAULT" }, new string[1] { ":Config" });
			MaterialKit.ClearMaterials();
		}
	}
	internal static class ProfileHelper
	{
		public const string DEFAULT_PROFILE_ID = "DEFAULT";

		public const string PROFILE_POSTFIX = ":Config";

		public static string DefaultProfile => "DEFAULT:Config";

		public static string LocalProfile
		{
			get
			{
				PlayerControllerB player;
				return GetProfileName(TryGetLocalPlayer(out player) ? 999999 : ((NetworkBehaviour)player).OwnerClientId);
			}
		}

		public static string GetProfileName(ulong ownerClientID)
		{
			return ownerClientID + ":Config";
		}

		public static void ForceSyncUpdate()
		{
			if (TouchLocalPlayerProfile(out var player) != null)
			{
				ModelReplacementAPI.ResetPlayerModelReplacement(player);
				SyncManager.SyncPlayerConfig(player);
			}
		}

		public static Profile TouchPlayerProfile(ulong ownerClientID, out PlayerControllerB player)
		{
			if (!TryGetPlayer(ownerClientID, out player))
			{
				return null;
			}
			string profileName = GetProfileName(ownerClientID);
			if (!Profile.TryGetProfile(profileName, out var profile))
			{
				profile = Profile.CloneProfile(profileName, DefaultProfile);
			}
			return profile;
		}

		public static Profile TouchPlayerProfile(string profileName)
		{
			if (!Profile.TryGetProfile(profileName, out var profile))
			{
				return Profile.CloneProfile(profileName, DefaultProfile);
			}
			return profile;
		}

		public static Profile TouchLocalPlayerProfile(out PlayerControllerB player)
		{
			if (!TryGetLocalPlayer(out player))
			{
				return null;
			}
			string profileName = GetProfileName(((NetworkBehaviour)player).OwnerClientId);
			return TouchPlayerProfile(profileName);
		}

		public static PlayerControllerB GetLocalPlayer()
		{
			return StartOfRound.Instance?.localPlayerController;
		}

		public static bool TryGetLocalPlayer(out PlayerControllerB player)
		{
			player = StartOfRound.Instance?.localPlayerController;
			return (Object)(object)player != (Object)null;
		}

		public static PlayerControllerB GetPlayer(ulong ownerClientID)
		{
			if (!StartOfRound.Instance.ClientPlayerList.TryGetValue(ownerClientID, out var value))
			{
				return null;
			}
			return StartOfRound.Instance.allPlayerObjects[value].GetComponent<PlayerControllerB>();
		}

		public static bool TryGetPlayer(ulong ownerClientID, out PlayerControllerB player)
		{
			player = GetPlayer(ownerClientID);
			return (Object)(object)player != (Object)null;
		}

		public static bool IsLocalPlayer(ulong ownerClientID)
		{
			if ((Object)(object)StartOfRound.Instance.localPlayerController != (Object)null)
			{
				return ((NetworkBehaviour)StartOfRound.Instance.localPlayerController).OwnerClientId == ownerClientID;
			}
			return ((NetworkBehaviour)StartOfRound.Instance).NetworkObjectId == ownerClientID;
		}

		public static bool IsLocalPlayer(PlayerControllerB player)
		{
			return IsLocalPlayer(((NetworkBehaviour)player).OwnerClientId);
		}

		public static bool IsServerHost()
		{
			NetworkManager networkManager = ((NetworkBehaviour)HUDManager.Instance).NetworkManager;
			return networkManager.IsServer || networkManager.IsHost;
		}
	}
	internal static class SyncManager
	{
		public const string CACKLECREW_TAG = "[CA]";

		public static void SyncPlayerConfig(PlayerControllerB controller)
		{
			if (ProfileHelper.IsLocalPlayer(((NetworkBehaviour)controller).OwnerClientId))
			{
				SuitKit.SwitchSuitOfPlayer(controller, controller.currentSuitID);
				SendPlayerConfig(controller);
			}
		}

		public static void SendPlayerConfig(PlayerControllerB controller)
		{
			List<string> list = new List<string>();
			ulong ownerClientId = ((NetworkBehaviour)controller).OwnerClientId;
			string profileName = ProfileHelper.GetProfileName(ownerClientId);
			Profile profile = ProfileHelper.TouchPlayerProfile(profileName);
			SavedProfileHelper.UpdatePlayerProfile(profileName);
			list.Add(ownerClientId.ToString());
			list.Add("=");
			if (profile.GetData("OUTFIT") == "FALSE")
			{
				list.Add(profile.GetData("MODEL", isRaw: true));
			}
			else
			{
				list.Add(profile.Serialize());
			}
			SyncDataKit.SendChatData(string.Join(null, list), "[CA]");
		}

		public static void ReceivePlayerConfig(string chatData)
		{
			int num = chatData.IndexOf('=');
			ulong result;
			if (num == -1)
			{
				Debug.LogWarning((object)"Chat Data Received is Wrong...!");
				Debug.LogWarning((object)"Ignoring Chat Data...");
			}
			else if (!ulong.TryParse(chatData.Substring(0, num), out result))
			{
				Debug.LogWarning((object)"Unable to Parge ID from chat data...!");
			}
			else
			{
				if (ProfileHelper.IsLocalPlayer(result))
				{
					return;
				}
				PlayerControllerB player;
				Profile profile = ProfileHelper.TouchPlayerProfile(result, out player);
				if (profile == null)
				{
					Debug.LogWarning((object)"Config Profile Does not exist!");
					return;
				}
				string text = chatData.Substring(++num);
				if (text.Length == 1)
				{
					profile.SetData("OUTFIT", "FALSE");
					profile.SetData("MODEL", text, isRaw: true);
				}
				else
				{
					profile.Deserialize(text);
				}
				SuitKit.SwitchSuitOfPlayer(player, player.currentSuitID);
				ModelReplacementAPI.ResetPlayerModelReplacement(player);
			}
		}
	}
	[HarmonyPatch]
	internal static class SyncManager_Patches
	{
		[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
		[HarmonyPostfix]
		private static void ConnectClientToPlayerObject_Postfix(PlayerControllerB __instance)
		{
			ModelReplacementAPI.ResetPlayerModelReplacement(__instance);
			SyncManager.SyncPlayerConfig(__instance);
		}

		[HarmonyPatch(typeof(StartOfRound), "SyncShipUnlockablesClientRpc")]
		[HarmonyPostfix]
		private static void SyncShipUnlockablesClientRpc_Postfix(StartOfRound __instance)
		{
			if (!ProfileHelper.IsServerHost() && ProfileHelper.TryGetLocalPlayer(out var player))
			{
				SyncManager.SyncPlayerConfig(player);
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "SyncShipUnlockablesServerRpc")]
		[HarmonyPostfix]
		private static void SyncShipUnlockablesServerRpc_Postfix(StartOfRound __instance)
		{
			if (ProfileHelper.TryGetLocalPlayer(out var player))
			{
				SyncManager.SyncPlayerConfig(player);
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "Start")]
		[HarmonyPostfix]
		public static void Start_Postfix(ref StartOfRound __instance)
		{
			SyncDataKit.AttachListener("[CA]", SyncManager.ReceivePlayerConfig);
		}

		[HarmonyPatch(typeof(StartOfRound), "OnDestroy")]
		[HarmonyPostfix]
		public static void OnDestroy_Postfix(ref StartOfRound __instance)
		{
			SyncDataKit.RemoveListener("[CA]", SyncManager.ReceivePlayerConfig);
		}
	}
	internal class CompatibilityKit
	{
		public static bool Has_x753MoreSuits => HasPluginGUID("x753.More_Suits");

		public static bool HasPluginGUID(string pluginGUID)
		{
			bool result = false;
			foreach (KeyValuePair<string, PluginInfo> pluginInfo in Chainloader.PluginInfos)
			{
				if (pluginInfo.Value.Metadata.GUID.Equals(pluginGUID))
				{
					result = true;
					break;
				}
			}
			return result;
		}

		public static void ValidateSavedProfiles()
		{
			Profile profile = Profile.CloneProfile("TEMP:PROFILE:IGNORE", ProfileHelper.DefaultProfile);
			if (IsOldProfileData(SavedProfileHelper.currentConfig.Value))
			{
				Deserialize_OldProfileData(profile, SavedProfileHelper.currentConfig.Value);
				SavedProfileHelper.currentConfig.Value = profile.Serialize();
			}
			foreach (KeyValuePair<string, ConfigEntry<string>> savedConfig in SavedProfileHelper.savedConfigs)
			{
				profile = Profile.ReflectProfile("TEMP:PROFILE:IGNORE", ProfileHelper.DefaultProfile);
				if (IsOldProfileData(savedConfig.Value.Value))
				{
					Deserialize_OldProfileData(profile, savedConfig.Value.Value);
					savedConfig.Value.Value = profile.Serialize();
				}
			}
			Profile.DeleteProfile("TEMP:PROFILE:IGNORE");
		}

		public static bool IsOldProfileData(string profileData)
		{
			return profileData.StartsWith("LCpf");
		}

		public static void Deserialize_OldProfileData(Profile profile, string profileData)
		{
			if (!IsOldProfileData(profileData))
			{
				return;
			}
			try
			{
				string text = DecompressString(profileData.Substring(4));
				string[] array = text.Split(';');
				for (int i = 0; i < array.Length; i += 2)
				{
					profile.SetData("OUTFIT", "FALSE");
					string text2 = array[i];
					string text3 = text2;
					if (text3 == "MODEL")
					{
						string text4 = array[i + 1];
						string text5 = text4;
						string value = ((text5 == "Comms") ? "B" : ((!(text5 == "Sentry")) ? "A" : "C"));
						profile.SetData("MODEL", value);
					}
					else if (profile.HasData(array[i]))
					{
						profile.SetData(array[i], array[i + 1]);
					}
				}
			}
			catch (Exception ex)
			{
				Debug.LogError((object)"Provided tokenString could not be Deserialized or Read.");
				Debug.LogError((object)ex);
			}
		}

		private static string DecompressString(string input)
		{
			byte[] buffer = Convert.FromBase64String(input);
			using MemoryStream stream = new MemoryStream(buffer);
			using MemoryStream memoryStream = new MemoryStream();
			using (GZipStream gZipStream = new GZipStream(stream, CompressionMode.Decompress))
			{
				gZipStream.CopyTo(memoryStream);
			}
			return Encoding.UTF8.GetString(memoryStream.ToArray());
		}
	}
	public static class MaterialKit
	{
		private static Dictionary<string, Material> _MaterialPool = new Dictionary<string, Material>();

		public static bool TryGetMaterial(string name, out Material material)
		{
			return _MaterialPool.TryGetValue(name, out material);
		}

		public static void SetMaterial(string name, Material material)
		{
			if (_MaterialPool.ContainsKey(name))
			{
				_MaterialPool.Remove(name);
			}
			_MaterialPool.Add(name, material);
		}

		public static void ClearMaterials()
		{
			_MaterialPool.Clear();
		}
	}
	public static class ModelKit
	{
		public static Dictionary<string, GameObject> registeredModels = new Dictionary<string, GameObject>();

		public static GameObject GetModel(string modelName)
		{
			if (registeredModels.Count == 0)
			{
				Debug.LogError((object)"NO MODELS REGISTERED!!!");
				return null;
			}
			if (string.IsNullOrEmpty(modelName))
			{
				modelName = registeredModels.Keys.First();
			}
			if (!registeredModels.TryGetValue(modelName, out var value))
			{
				Debug.LogWarning((object)(modelName + " Model Doesn't Exist."));
			}
			if ((Object)(object)value == (Object)null)
			{
				value = registeredModels.Values.First();
			}
			return value;
		}

		public static bool HasModel(string modelName)
		{
			string key = (string.IsNullOrEmpty(modelName) ? string.Empty : modelName);
			return registeredModels.ContainsKey(key);
		}

		public static void RegisterModel(string modelName, GameObject prefab)
		{
			if (!string.IsNullOrWhiteSpace(modelName))
			{
				if (registeredModels.TryGetValue(modelName, out var _))
				{
					registeredModels.Remove(modelName);
				}
				registeredModels.Add(modelName, prefab);
			}
		}

		public static string GetDefaultModel()
		{
			return registeredModels.Keys.First();
		}

		public static void ClearModels()
		{
			registeredModels.Clear();
		}
	}
	public static class PixelKit
	{
		public static void HSV(ref Color original, float H, float S, float V)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			original = Color.HSVToRGB(H, S, V);
		}

		public static void HV(ref Color original, float H, float V)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			float num = default(float);
			float num2 = default(float);
			float num3 = default(float);
			Color.RGBToHSV(original, ref num, ref num2, ref num3);
			original = Color.HSVToRGB(H, num2, V);
		}

		public static void HS(ref Color original, float H, float S)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			float num = default(float);
			float num2 = default(float);
			float num3 = default(float);
			Color.RGBToHSV(original, ref num, ref num2, ref num3);
			original = Color.HSVToRGB(H, S, num3);
		}

		public static void SV(ref Color original, float S, float V)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			float num = default(float);
			float num2 = default(float);
			float num3 = default(float);
			Color.RGBToHSV(original, ref num, ref num2, ref num3);
			original = Color.HSVToRGB(num, S, V);
		}

		public static void Hue(ref Color original, float amount)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			float num = default(float);
			float num2 = default(float);
			float num3 = default(float);
			Color.RGBToHSV(original, ref num, ref num2, ref num3);
			original = Color.HSVToRGB(amount, num2, num3);
		}

		public static void Saturate(ref Color original, float amount)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			float num = default(float);
			float num2 = default(float);
			float num3 = default(float);
			Color.RGBToHSV(original, ref num, ref num2, ref num3);
			original = Color.HSVToRGB(num, amount, num3);
		}

		public static void Value(ref Color original, float amount)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			float num = default(float);
			float num2 = default(float);
			float num3 = default(float);
			Color.RGBToHSV(original, ref num, ref num2, ref num3);
			original = Color.HSVToRGB(num, num2, amount);
		}

		public static float SoftLight(float a, float b)
		{
			return 2f * (a * b) + a * a - 2f * (a * a) * b;
		}

		public static Color SoftLight(Color original, Color color)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			Color val = original;
			val.r = SoftLight(val.r, color.r);
			val.b = SoftLight(val.b, color.b);
			val.g = SoftLight(val.g, color.g);
			return val;
		}

		public static void SoftLight(ref Color original, Color color)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			original = SoftLight(original, color);
		}

		public static void SoftLight_Mask(ref Color original, Color mask, Color color)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			original = Color.Lerp(original, SoftLight(original, color), 1f - mask.r);
		}

		public static void SoftLight_Alpha(ref Color original, Color color)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			original = Color.Lerp(original, SoftLight(original, color), color.a);
		}

		public static void Multiply(ref Color original, Color color)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			original *= color;
		}

		public static void Multiply_Mask(ref Color original, Color mask, Color color)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			original = Color.Lerp(original, original * color, 1f - mask.r);
		}

		public static void Invert(ref Color original)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			original -= Color.white;
		}

		public static void Invert_Mask(ref Color original, Color mask)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			original = Color.Lerp(original, original - Color.white, 1f - mask.r);
		}

		public static void Lerp_Mask(ref Color original, Color mask, Color color)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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_001a: Unknown result type (might be due to invalid IL or missing references)
			original = Color.Lerp(original, color, 1f - mask.r);
		}

		public static void Lerp_Alpha(ref Color original, Color reference)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: 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_0014: Unknown result type (might be due to invalid IL or missing references)
			original = Color.Lerp(original, reference, reference.a);
		}

		public static void SoftLight(ref Color[] original, Color color)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < original.Length; i++)
			{
				SoftLight(ref original[i], color);
			}
		}

		public static void SoftLight_Mask(ref Color[] original, Color[] mask, Color color)
		{
			//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)
			for (int i = 0; i < original.Length; i++)
			{
				SoftLight_Mask(ref original[i], mask[i], color);
			}
		}

		public static void SoftLight_Alpha(ref Color[] original, Color[] reference)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < original.Length; i++)
			{
				SoftLight_Alpha(ref original[i], reference[i]);
			}
		}

		public static void Multiply(ref Color[] original, Color color)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < original.Length; i++)
			{
				Multiply(ref original[i], color);
			}
		}

		public static void Multiply(ref Color[] original, Color[] colors)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < original.Length; i++)
			{
				Multiply(ref original[i], colors[i]);
			}
		}

		public static void Multiply_Mask(ref Color[] original, Color[] mask, Color color)
		{
			//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)
			for (int i = 0; i < original.Length; i++)
			{
				Multiply_Mask(ref original[i], mask[i], color);
			}
		}

		public static void Multiply_Mask(ref Color[] original, Color[] mask, Color[] colors)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < original.Length; i++)
			{
				Multiply_Mask(ref original[i], mask[i], colors[i]);
			}
		}

		public static void Invert(ref Color[] original)
		{
			for (int i = 0; i < original.Length; i++)
			{
				Invert(ref original[i]);
			}
		}

		public static void Invert_Mask(ref Color[] original, Color[] mask)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < original.Length; i++)
			{
				Invert_Mask(ref original[i], mask[i]);
			}
		}

		public static void Lerp_Mask(ref Color[] original, Color[] mask, Color color)
		{
			//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)
			for (int i = 0; i < original.Length; i++)
			{
				Lerp_Mask(ref original[i], mask[i], color);
			}
		}

		public static void Lerp_Mask(ref Color[] original, Color[] mask, Color[] colors)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < original.Length; i++)
			{
				Lerp_Mask(ref original[i], mask[i], colors[i]);
			}
		}

		public static void Lerp_Alpha(ref Color[] original, Color[] reference)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < original.Length; i++)
			{
				Lerp_Alpha(ref original[i], reference[i]);
			}
		}

		public static Color[] GenerateColorBlock(Color color, Vector2Int size)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			int num = ((Vector2Int)(ref size)).x * ((Vector2Int)(ref size)).y;
			Color[] array = (Color[])(object)new Color[num];
			for (int i = 0; i < num; i++)
			{
				array[i] = color;
			}
			return array;
		}
	}
	public static class ShaderKit
	{
		public static void ClearKeywords(ref Material material, string keyword)
		{
			//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)
			LocalKeyword[] enabledKeywords = material.enabledKeywords;
			for (int i = 0; i < enabledKeywords.Length; i++)
			{
				LocalKeyword val = enabledKeywords[i];
				if (((LocalKeyword)(ref val)).name.Contains(keyword))
				{
					material.DisableKeyword(((LocalKeyword)(ref val)).name);
				}
			}
		}

		public static void SetKeyword(ref Material material, string keyword, string option)
		{
			material.EnableKeyword("_" + keyword + "_" + option);
		}
	}
	internal static class SuitKit
	{
		private static Dictionary<int, int> LastSuits = new Dictionary<int, int>();

		private static Dictionary<int, int> CurrentSuits = new Dictionary<int, int>();

		public static string GetSuitName(int suitID)
		{
			return StartOfRound.Instance.unlockablesList.unlockables[suitID].unlockableName;
		}

		public static int GetSuitID(string suitName)
		{
			List<UnlockableItem> unlockables = StartOfRound.Instance.unlockablesList.unlockables;
			for (int i = 0; i < unlockables.Count; i++)
			{
				UnlockableItem val = unlockables[i];
				if (val.unlockableName == suitName)
				{
					return i;
				}
			}
			return 0;
		}

		public static Material GetSuitMaterial(int suitID)
		{
			Material result = null;
			if (suitID >= 0 && suitID < StartOfRound.Instance.unlockablesList.unlockables.Count)
			{
				result = StartOfRound.Instance.unlockablesList.unlockables[suitID].suitMaterial;
			}
			return result;
		}

		public static Material GetSuitMaterial(string suitName)
		{
			return GetSuitMaterial(GetSuitID(suitName));
		}

		public static int GetCurrentSuitID(PlayerControllerB player)
		{
			if (!StartOfRound.Instance.ClientPlayerList.TryGetValue(((NetworkBehaviour)player).OwnerClientId, out var value))
			{
				return 0;
			}
			CurrentSuits.TryGetValue(value, out var value2);
			return value2;
		}

		public static int GetLastSuitID(PlayerControllerB player)
		{
			if (!StartOfRound.Instance.ClientPlayerList.TryGetValue(((NetworkBehaviour)player).OwnerClientId, out var value))
			{
				return 0;
			}
			LastSuits.TryGetValue(value, out var value2);
			return value2;
		}

		public static string GetCurrentSuitName(PlayerControllerB player)
		{
			return GetSuitName(GetCurrentSuitID(player));
		}

		public static string GetLastSuitName(PlayerControllerB player)
		{
			return GetSuitName(GetLastSuitID(player));
		}

		public static void SetSuit(PlayerControllerB player, string suitName)
		{
			SetSuit(player, GetSuitID(suitName));
		}

		public static void SetSuit(PlayerControllerB player, int suitID)
		{
			if (!StartOfRound.Instance.ClientPlayerList.TryGetValue(((NetworkBehaviour)player).OwnerClientId, out var value))
			{
				return;
			}
			if (CurrentSuits.ContainsKey(value))
			{
				if (suitID != CurrentSuits[value])
				{
					LastSuits[value] = CurrentSuits[value];
					CurrentSuits[value] = suitID;
				}
			}
			else
			{
				LastSuits.Add(value, 0);
				CurrentSuits.Add(value, suitID);
			}
		}

		public static void ClearSuits()
		{
			CurrentSuits.Clear();
			LastSuits.Clear();
		}

		public static void SwitchSuitOfPlayer(PlayerControllerB controller, int suitID)
		{
			if (suitID >= 0 && StartOfRound.Instance.unlockablesList.unlockables.Count - 1 >= suitID)
			{
				UnlockableSuit.SwitchSuitForPlayer(controller, suitID, false);
			}
			else
			{
				Debug.LogWarning((object)$"Suit ID {suitID} is not valid.");
			}
			UnlockableSuit val = null;
			foreach (KeyValuePair<int, GameObject> spawnedShipUnlockable in StartOfRound.Instance.SpawnedShipUnlockables)
			{
				if (spawnedShipUnlockable.Key == suitID)
				{
					val = spawnedShipUnlockable.Value.GetComponent<UnlockableSuit>();
					break;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				UnlockableSuit[] array = Object.FindObjectsOfType<UnlockableSuit>();
				foreach (UnlockableSuit val2 in array)
				{
					if (val2.suitID == suitID)
					{
						val = val2;
						break;
					}
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				val.SwitchSuitServerRpc((int)((NetworkBehaviour)controller).OwnerClientId);
			}
			else
			{
				Debug.LogWarning((object)"Could Not Find UnlockableSuit!");
			}
		}

		public static void SampleSuitColors(Texture2D suitTexture, out Color bootColor, out Color suitColor, out Color clothColor, out Color tankColor)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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_008d: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			bootColor = Color.black;
			suitColor = Color.white;
			clothColor = Color.gray;
			tankColor = Color.yellow;
			try
			{
				int width = ((Texture)suitTexture).width;
				int height = ((Texture)suitTexture).height;
				bootColor = suitTexture.GetPixel((int)((float)width * 0.597259f), (int)((float)height * 0.365158f));
				suitColor = suitTexture.GetPixel((int)((float)width * 0.62027f), (int)((float)height * 0.365158f));
				clothColor = suitTexture.GetPixel((int)((float)width * 0.685685f), (int)((float)height * 0.365158f));
				tankColor = suitTexture.GetPixel((int)((float)width * 0.026545f), (int)((float)height * 0.916508f));
			}
			catch (Exception)
			{
				Debug.LogWarning((object)("Texture \"" + ((Object)suitTexture).name + "\" is not Read/Writtable colors could not be extracted."));
			}
		}
	}
	[HarmonyPatch]
	internal static class SuitKit_Patches
	{
		[HarmonyPatch(typeof(UnlockableSuit), "SwitchSuitForPlayer")]
		[HarmonyPrefix]
		public static void SwitchSuitForPlayer_Postfix(PlayerControllerB player, int suitID, bool playAudio = true)
		{
			SuitKit.SetSuit(player, suitID);
		}

		[HarmonyPatch(typeof(StartOfRound), "OnDestroy")]
		[HarmonyPrefix]
		public static void OnDestoy_Postfix(ref StartOfRound __instance)
		{
			SuitKit.ClearSuits();
		}
	}
	internal static class SyncDataKit
	{
		public const int DATAKIT_ID = 49362;

		private static Dictionary<string, List<Action<string>>> listeners = new Dictionary<string, List<Action<string>>>();

		private static readonly MethodInfo _AddPlayerChatMessageServerRpc = AccessTools.Method(typeof(HUDManager), "AddPlayerChatMessageServerRpc", (Type[])null, (Type[])null);

		public static void SendChatData(string chatMessage, string tag)
		{
			if (chatMessage.Length > 50 - tag.Length)
			{
				Debug.LogError((object)"CHAT MESSAGE BEING SENT IS LONGER THAN 50 CHARACTERS!!!");
				Debug.LogError((object)"AND WILL PROBABLY NOT BE RECEIVED BY THE OTHER CLIENTS!!!");
				Debug.LogError((object)(tag + chatMessage));
			}
			Debug.LogWarning((object)"== Ignore the Following Error ==");
			Debug.LogWarning((object)"== IndexOutOfRangeException : AddPlayerChatMessageClientRpc ==");
			try
			{
				object[] parameters = new object[2]
				{
					tag + chatMessage,
					49362
				};
				_AddPlayerChatMessageServerRpc.Invoke(HUDManager.Instance, parameters);
			}
			catch (Exception)
			{
			}
		}

		public static void HandleChatData(string chatMessage, string tag)
		{
			if (!listeners.TryGetValue(tag, out var value))
			{
				return;
			}
			foreach (Action<string> item in value)
			{
				item(chatMessage.Substring(tag.Length));
			}
		}

		public static int ValidateChatData(string chatMessage, out string tag)
		{
			tag = null;
			foreach (KeyValuePair<string, List<Action<string>>> listener in listeners)
			{
				if (chatMessage.StartsWith(listener.Key))
				{
					tag = listener.Key;
					return 1;
				}
			}
			return 0;
		}

		public static void AttachListener(string tag, Action<string> action)
		{
			if (!listeners.TryGetValue(tag, out var value))
			{
				value = new List<Action<string>>();
				listeners.Add(tag, value);
			}
			if (!value.Contains(action))
			{
				value.Add(action);
			}
		}

		public static void RemoveListener(string tag, Action<string> action)
		{
			if (listeners.TryGetValue(tag, out var value))
			{
				value.Remove(action);
				if (value.Count == 0)
				{
					listeners.Remove(tag);
				}
			}
		}

		public static void PurgeListeners()
		{
			listeners.Clear();
		}
	}
	[HarmonyPatch]
	internal static class ChatDataKitPatches
	{
		private static string lastMessage;

		private static void HandleChatDataMessage(string chatMessage, string tag)
		{
			if (lastMessage != chatMessage)
			{
				lastMessage = chatMessage;
				SyncDataKit.HandleChatData(chatMessage, tag);
			}
		}

		[HarmonyPatch(typeof(HUDManager), "AddPlayerChatMessageClientRpc")]
		[HarmonyPrefix]
		public static bool AddPlayerChatMessageClientRpc_Prefix_Patch(HUDManager __instance, string chatMessage, int playerId)
		{
			if (SyncDataKit.ValidateChatData(chatMessage, out var tag) == 0)
			{
				return true;
			}
			HandleChatDataMessage(chatMessage, tag);
			return ProfileHelper.IsServerHost();
		}

		[HarmonyPatch(typeof(HUDManager), "AddTextToChatOnServer")]
		[HarmonyPrefix]
		public static bool AddTextToChatOnServer(HUDManager __instance, string chatMessage, int playerId = -1)
		{
			if (SyncDataKit.ValidateChatData(chatMessage, out var _) != 0 && playerId != 49362)
			{
				return false;
			}
			return true;
		}
	}
	public class Profile
	{
		private static Dictionary<string, Profile> profiles = new Dictionary<string, Profile>();

		private Dictionary<string, ProfileData> _data = new Dictionary<string, ProfileData>();

		private List<string> _order = new List<string>();

		private const char GENERIC_TOKEN = ';';

		public int Count => _order.Count;

		public Dictionary<string, ProfileData> Data => _data;

		public static Profile CreateProfile(string profileName)
		{
			if (TryGetProfile(profileName, out var profile))
			{
				return profile;
			}
			profile = new Profile();
			profiles.Add(profileName, profile);
			return profile;
		}

		public static Profile GetProfile(string profileName)
		{
			TryGetProfile(profileName, out var profile);
			return profile;
		}

		public static bool TryGetProfile(string profileName, out Profile profile)
		{
			return profiles.TryGetValue(profileName, out profile);
		}

		public static bool HasProfile(string profileName)
		{
			return profiles.ContainsKey(profileName);
		}

		public static Profile CloneProfile(string profileName, string reference)
		{
			if (!TryGetProfile(reference, out var profile))
			{
				Debug.LogWarning((object)("Profile.CloneProfile does not contain the reference profile " + reference));
				Debug.LogWarning((object)("Profile.CloneProfile could not clone to profile " + profileName));
				return null;
			}
			if (!TryGetProfile(profileName, out var profile2))
			{
				profile2 = CreateProfile(profileName);
			}
			foreach (KeyValuePair<string, ProfileData> datum in profile.Data)
			{
				profile2.SetData(datum.Key, datum.Value.Data, isRaw: true, datum.Value.Type);
			}
			return profile2;
		}

		public static Profile ReflectProfile(string profileName, string reference)
		{
			if (!TryGetProfile(reference, out var profile))
			{
				Debug.LogWarning((object)("Profile.ReflectProfile does not contain the reference profile " + reference));
				Debug.LogWarning((object)("Profile.ReflectProfile could not reflect to profile " + profileName));
				return null;
			}
			if (!TryGetProfile(profileName, out var profile2))
			{
				Debug.LogWarning((object)("Profile.ReflectProfile does not contain the profile " + reference));
				Debug.LogWarning((object)("Profile.ReflectProfile could not reflect to profile " + profileName));
				return null;
			}
			foreach (KeyValuePair<string, ProfileData> datum in profile2.Data)
			{
				profile2.SetData(datum.Key, profile.GetData(datum.Key, isRaw: true), isRaw: true);
			}
			return profile2;
		}

		public static void DeleteProfile(string profileName)
		{
			if (profiles.TryGetValue(profileName, out var value))
			{
				value.PurgeData();
				profiles.Remove(profileName);
			}
		}

		public static void FilterDeleteProfiles(string[] keywords)
		{
			Queue<string> queue = new Queue<string>();
			foreach (KeyValuePair<string, Profile> profile in profiles)
			{
				foreach (string value in keywords)
				{
					if (profile.Key.Contains(value))
					{
						queue.Enqueue(profile.Key);
						break;
					}
				}
			}
			string result;
			while (queue.TryDequeue(out result))
			{
				DeleteProfile(result);
			}
		}

		public static void FilterDeleteProfiles(string[] ignoredKeywords, string[] keywords)
		{
			Queue<string> queue = new Queue<string>();
			foreach (KeyValuePair<string, Profile> profile in profiles)
			{
				bool flag = false;
				foreach (string value in ignoredKeywords)
				{
					if (profile.Key.Contains(value))
					{
						flag = true;
						break;
					}
				}
				if (flag)
				{
					continue;
				}
				foreach (string value2 in keywords)
				{
					if (profile.Key.Contains(value2))
					{
						queue.Enqueue(profile.Key);
						break;
					}
				}
			}
			string result;
			while (queue.TryDequeue(out result))
			{
				DeleteProfile(result);
			}
		}

		public static void PurgeProfiles(string profileName)
		{
			foreach (KeyValuePair<string, Profile> profile in profiles)
			{
				profile.Value.PurgeData();
			}
			profiles.Clear();
		}

		public void SetData(string key, string value, bool isRaw = false, ProfileDataType type = ProfileDataType.Generic)
		{
			if (!_data.TryGetValue(key, out var value2))
			{
				value2 = new ProfileData
				{
					Type = type
				};
				_data.Add(key, value2);
				_order.Add(key);
			}
			if (isRaw)
			{
				value2.Data = value;
			}
			else
			{
				value2.DecodeData(value);
			}
		}

		public string GetData(string key, bool isRaw = false)
		{
			TryGetData(key, out var value, isRaw);
			return value;
		}

		public bool TryGetData(string key, out string value, bool isRaw = false)
		{
			value = string.Empty;
			if (_data.TryGetValue(key, out var value2))
			{
				if (isRaw)
				{
					value = value2.Data;
				}
				else
				{
					value = value2.EncodeData();
				}
			}
			return string.IsNullOrEmpty(value);
		}

		public bool HasData(string key)
		{
			return _data.ContainsKey(key);
		}

		public void DeleteData(string key)
		{
			if (HasData(key))
			{
				_data[key] = null;
				_data.Remove(key);
				_order.Remove(key);
			}
		}

		public void PurgeData()
		{
			_data.Clear();
			_order.Clear();
		}

		public void SetDataIndex(string key, int index)
		{
			if (_order.Contains(key))
			{
				_order.Remove(key);
				_order.Insert(index, key);
			}
		}

		public int GetDataIndex(string key)
		{
			return _order.IndexOf(key);
		}

		public int GetDataSize(string key)
		{
			if (_data.TryGetValue(key, out var value))
			{
				return value.Size;
			}
			return -1;
		}

		public string Serialize()
		{
			List<string> list = new List<string>();
			for (int i = 0; i < Count; i++)
			{
				list.Add(string.Empty);
			}
			foreach (KeyValuePair<string, ProfileData> datum in _data)
			{
				ProfileData value = datum.Value;
				string text = value.Data;
				if (value.Type == ProfileDataType.Generic)
				{
					text += ";";
				}
				list[GetDataIndex(datum.Key)] = text;
			}
			string text2 = string.Join(string.Empty, list);
			return GenerateChecksum(text2) + text2;
		}

		public void Deserialize(string profileData, bool validate = true)
		{
			int num = 1;
			if (validate)
			{
				foreach (KeyValuePair<string, ProfileData> datum in _data)
				{
					if (datum.Value.Type == ProfileDataType.Generic)
					{
						num++;
					}
					num += datum.Value.Size;
				}
			}
			if (validate && profileData.Length != num)
			{
				Debug.LogWarning((object)"Profile data provided does not match expected size--");
				Debug.LogWarning((object)"...Ignoring");
				return;
			}
			if (validate && !ValidateChecksum(profileData))
			{
				Debug.LogWarning((object)"Profile data does not match checksum--");
				Debug.LogWarning((object)"data may be incorrect... Ignoring");
				return;
			}
			int num2 = 1;
			foreach (KeyValuePair<string, ProfileData> datum2 in _data)
			{
				int num3 = datum2.Value.Size;
				if (datum2.Value.Type == ProfileDataType.Generic)
				{
					num3 = profileData.IndexOf(';', num2) - num2;
				}
				string data = profileData.Substring(num2, num3);
				if (datum2.Value.Type == ProfileDataType.Generic)
				{
					num2++;
				}
				datum2.Value.Data = data;
				num2 += num3;
			}
		}

		private bool ValidateChecksum(string profileData)
		{
			char c = profileData[0];
			char c2 = GenerateChecksum(profileData, 1);
			return c == c2;
		}

		private char GenerateChecksum(string profileData, int offset = 0)
		{
			int i = offset;
			char c = '#';
			for (; i < profileData.Length; i++)
			{
				char c2 = profileData[i];
				c ^= c2;
				bool flag = c % 2 == 0;
				c = (char)(c % 26 + 65);
				c = (flag ? char.ToUpper(c) : char.ToLower(c));
			}
			return c;
		}
	}
	public enum ProfileDataType
	{
		Generic,
		Boolean,
		Color,
		Character,
		ShaderOption
	}
	public class ProfileData
	{
		private string _data;

		private ProfileDataType _type;

		public string Data
		{
			get
			{
				return _data;
			}
			set
			{
				_data = value;
			}
		}

		public ProfileDataType Type
		{
			get
			{
				return _type;
			}
			set
			{
				_type = value;
			}
		}

		public int Size => DataSize();

		public int DataSize()
		{
			return _type switch
			{
				ProfileDataType.Boolean => 1, 
				ProfileDataType.Color => 6, 
				ProfileDataType.Character => 1, 
				ProfileDataType.ShaderOption => 1, 
				_ => _data.Length, 
			};
		}

		public string EncodeData()
		{
			return _type switch
			{
				ProfileDataType.Boolean => EncodeBooleanData(_data), 
				ProfileDataType.Color => EncodeColorData(_data), 
				ProfileDataType.Character => EncodeCharacterData(_data), 
				ProfileDataType.ShaderOption => EncodeShaderData(_data), 
				_ => _data, 
			};
		}

		public string DecodeData(string value)
		{
			switch (_type)
			{
			case ProfileDataType.Boolean:
				_data = DecodeBooleanData(value);
				break;
			case ProfileDataType.Color:
				_data = DecodeColorData(value);
				break;
			case ProfileDataType.Character:
				_data = DecodeCharacterData(value);
				break;
			case ProfileDataType.ShaderOption:
				_data = DecodeShaderData(value);
				break;
			default:
				_data = value;
				break;
			}
			return _data;
		}

		private string EncodeBooleanData(string value)
		{
			if (value == "1")
			{
				return "TRUE";
			}
			return "FALSE";
		}

		private string DecodeBooleanData(string value)
		{
			string text = value.ToUpper();
			string text2 = text;
			if (text2 == "TRUE")
			{
				return "1";
			}
			return "0";
		}

		private string EncodeColorData(string value)
		{
			return string.IsNullOrEmpty(value) ? value : ("#" + value);
		}

		private string DecodeColorData(string value)
		{
			if (value.StartsWith("#"))
			{
				return value.Substring(value.LastIndexOf('#') + 1);
			}
			return value;
		}

		private string EncodeCharacterData(string value)
		{
			return value.Substring(0, 1);
		}

		private string DecodeCharacterData(string value)
		{
			return EncodeCharacterData(value);
		}

		private string EncodeShaderData(string value)
		{
			return value switch
			{
				"1" => "A", 
				"2" => "B", 
				"3" => "C", 
				"4" => "D", 
				_ => "None", 
			};
		}

		private string DecodeShaderData(string value)
		{
			return value switch
			{
				"A" => "1", 
				"B" => "2", 
				"C" => "3", 
				"D" => "4", 
				_ => "0", 
			};
		}
	}
}
namespace CackleCrew.Helpers
{
	internal static class CustomizationHelper
	{
		public static GameObject GenerateCustomModel(PlayerControllerB controller)
		{
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Expected O, but got Unknown
			ulong ownerClientId = ((NetworkBehaviour)controller).OwnerClientId;
			string profileName = ProfileHelper.GetProfileName(ownerClientId);
			bool flag = !Profile.HasProfile(profileName);
			Profile profile = ProfileHelper.TouchPlayerProfile(profileName);
			if (flag && ProfileHelper.IsLocalPlayer(ownerClientId))
			{
				SavedProfileHelper.UpdatePlayerProfile(profileName);
				if (SavedProfileHelper.UseOutfits)
				{
					profile.SetData("OUTFIT", "TRUE");
				}
			}
			string data = profile.GetData("MODEL");
			int currentSuitID = SuitKit.GetCurrentSuitID(controller);
			string suitName = SuitKit.GetSuitName(currentSuitID);
			GameObject model = ModelKit.GetModel(data);
			SkinnedMeshRenderer[] componentsInChildren = model.GetComponentsInChildren<SkinnedMeshRenderer>();
			string text = (((profile.GetData("OUTFIT").ToUpper() == "TRUE") ? true : false) ? profileName : (data + ":" + suitName));
			if (!MaterialKit.TryGetMaterial(data + ":" + text, out var material))
			{
				material = new Material(((Renderer)componentsInChildren[0]).material);
				((Object)material).name = data + ":" + text + "(CustomMaterial)";
				MaterialKit.SetMaterial(data + ":" + text, material);
			}
			ApplyProfileToMaterial(ref material, text);
			((Renderer)componentsInChildren[0]).material = material;
			return model;
		}

		public static void ApplyProfileToMaterial(ref Material material, string profileName)
		{
			//IL_0015: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			Profile profile = Touch_OutfitProfile(profileName);
			material.SetColor("_SuitColor", GetColorFromProfile(profile, "PRIMARY"));
			material.SetColor("_PatternColor", GetColorFromProfile(profile, "SECONDARY"));
			material.SetColor("_HoodColor", GetColorFromProfile(profile, "HOOD"));
			material.SetColor("_TankColor", GetColorFromProfile(profile, "TANK"));
			material.SetColor("_LensColor", GetColorFromProfile(profile, "LENS"));
			material.SetColor("_PaintColor", GetColorFromProfile(profile, "PAINTCOLOR"));
			ApplyConfigFromProfile(ref material, profile, "PATTERN");
			ApplyConfigFromProfile(ref material, profile, "PAINT");
		}

		public static Color GetColorFromProfile(Profile profile, string name)
		{
			//IL_0029: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			string text = ((profile != null) ? profile.GetData(name) : string.Empty);
			Color result = default(Color);
			if (!ColorUtility.TryParseHtmlString(text, ref result))
			{
				return Color.white;
			}
			return result;
		}

		public static void ApplyConfigFromProfile(ref Material material, Profile profile, string name)
		{
			ShaderKit.ClearKeywords(ref material, name);
			string option = ((profile != null) ? profile.GetData(name) : "None");
			ShaderKit.SetKeyword(ref material, name, option);
		}

		public static Profile Touch_OutfitProfile(string profileName)
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			if (Profile.TryGetProfile(profileName, out var profile))
			{
				return profile;
			}
			string suitName = profileName;
			if (profileName.Contains(':'))
			{
				suitName = profileName.Substring(profileName.IndexOf(':') + 1);
			}
			int suitID = SuitKit.GetSuitID(suitName);
			Texture mainTexture = SuitKit.GetSuitMaterial(suitID).mainTexture;
			Texture2D suitTexture = (Texture2D)(object)((mainTexture is Texture2D) ? mainTexture : null);
			SuitKit.SampleSuitColors(suitTexture, out var _, out var suitColor, out var clothColor, out var tankColor);
			profile = Profile.CloneProfile(profileName, ProfileHelper.DefaultProfile);
			profile.SetData("PRIMARY", ColorUtility.ToHtmlStringRGB(suitColor), isRaw: true);
			profile.SetData("HOOD", ColorUtility.ToHtmlStringRGB(clothColor), isRaw: true);
			profile.SetData("TANK", ColorUtility.ToHtmlStringRGB(tankColor), isRaw: true);
			return profile;
		}
	}
}
namespace CreatureModelReplacement
{
	public class BodyReplacement : BodyReplacementBase
	{
		protected override GameObject LoadAssetsAndReturnModel()
		{
			return CustomizationHelper.GenerateCustomModel(((BodyReplacementBase)this).controller);
		}
	}
	[BepInPlugin("CreatureReplacement", "Cackle Crew", "3.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static ConfigFile config;

		public static ConfigEntry<bool> enableModelForAllSuits { get; private set; }

		public static ConfigEntry<bool> enableModelAsDefault { get; private set; }

		public static ConfigEntry<string> suitNamesToEnableModel { get; private set; }

		private static void InitConfig()
		{
			enableModelForAllSuits = config.Bind<bool>("Suits to Replace Settings", "Enable Model for all Suits", false, "Enable to replace every suit with Model. Set to false to specify suits");
			enableModelAsDefault = config.Bind<bool>("Suits to Replace Settings", "Enable Model as default", false, "Enable to replace every suit that hasn't been otherwise registered with Model.");
			suitNamesToEnableModel = config.Bind<string>("Suits to Replace Settings", "Suits to enable Model for", "Default,Orange suit,Green suit,Pajama suit,Hazard suit,Purple Suit", "For use with Moresuits, replace list with: CARed,CAGreen,CAHaz,CAPajam,CAPurp");
		}

		private void Awake()
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			config = ((BaseUnityPlugin)this).Config;
			InitConfig();
			Assets.PopulateAssets();
			if (enableModelForAllSuits.Value)
			{
				ModelReplacementAPI.RegisterModelReplacementOverride(typeof(BodyReplacement));
			}
			if (enableModelAsDefault.Value)
			{
				ModelReplacementAPI.RegisterModelReplacementDefault(typeof(BodyReplacement));
			}
			string[] array = suitNamesToEnableModel.Value.Split(',');
			string[] array2 = array;
			foreach (string text in array2)
			{
				ModelReplacementAPI.RegisterSuitModelReplacement(text, typeof(BodyReplacement));
			}
			Harmony val = new Harmony("LeCreature");
			val.PatchAll();
			Options.Init();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin CreatureReplacement is loaded!");
		}
	}
	public static class Assets
	{
		public static string mainAssetBundleName = "lecreature";

		public static string customizationAssetBundleName = "lecustomization";

		public static AssetBundle MainAssetBundle = null;

		public static AssetBundle CustomizationAssetBundle = null;

		private static string GetAssemblyName()
		{
			return Assembly.GetExecutingAssembly().FullName.Split(',')[0];
		}

		public static void PopulateAssets()
		{
			if ((Object)(object)MainAssetBundle == (Object)null)
			{
				using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(GetAssemblyName() + "." + mainAssetBundleName);
				MainAssetBundle = AssetBundle.LoadFromStream(stream);
			}
			if ((Object)(object)CustomizationAssetBundle == (Object)null)
			{
				using (Stream stream2 = Assembly.GetExecutingAssembly().GetManifestResourceStream(GetAssemblyName() + "." + customizationAssetBundleName))
				{
					CustomizationAssetBundle = AssetBundle.LoadFromStream(stream2);
				}
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}