Decompiled source of SkinColorSliders v1.0.0

SkinColorSliders/SkinColorSliders.dll

Decompiled a day ago
using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using Zorro.Core;
using Zorro.Core.Serizalization;

[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: AssemblyCompany("SkinColorSliders")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SkinColorSliders")]
[assembly: AssemblyTitle("SkinColorSliders")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace SkinColorSliders
{
	public class ColorSlidersUI : MonoBehaviour
	{
		private Slider rSlider;

		private Slider gSlider;

		private Slider bSlider;

		private Button applyButton;

		private GameObject colorSlidersPrefab;

		public Color initialColor;

		private void SetupColorPickerUI()
		{
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			PassportManager instance = PassportManager.instance;
			if ((Object)(object)colorSlidersPrefab == (Object)null)
			{
				colorSlidersPrefab = SkinColorSliders.Instance.colorPickerUIBundle.LoadAsset<GameObject>("ColorPicker");
			}
			GameObject val = Object.Instantiate<GameObject>(colorSlidersPrefab);
			rSlider = ((Component)val.transform.Find("r_Slider")).GetComponent<Slider>();
			gSlider = ((Component)val.transform.Find("g_Slider")).GetComponent<Slider>();
			bSlider = ((Component)val.transform.Find("b_Slider")).GetComponent<Slider>();
			applyButton = ((Component)val.transform.Find("ApplyButton")).GetComponent<Button>();
			TextMeshProUGUI component = ((Component)((Component)instance).transform.Find("PassportUI/Canvas/Panel/Panel/BG/Text/Name/Title")).GetComponent<TextMeshProUGUI>();
			((TMP_Text)((Component)rSlider).GetComponentInChildren<TextMeshProUGUI>()).font = ((TMP_Text)component).font;
			((TMP_Text)((Component)gSlider).GetComponentInChildren<TextMeshProUGUI>()).font = ((TMP_Text)component).font;
			((TMP_Text)((Component)bSlider).GetComponentInChildren<TextMeshProUGUI>()).font = ((TMP_Text)component).font;
			((TMP_Text)((Component)applyButton).GetComponentInChildren<TextMeshProUGUI>()).font = ((TMP_Text)component).font;
			rSlider.value = initialColor.r * 255f;
			gSlider.value = initialColor.g * 255f;
			bSlider.value = initialColor.b * 255f;
			Transform val2 = ((Component)instance).transform.Find("PassportUI/Canvas/Panel/Panel/BG");
			val.transform.SetParent(val2, false);
			val.transform.localScale = new Vector3(0.75f, 0.75f, 1f);
			val.transform.localPosition = new Vector3(-163.6328f, -149.4868f, 0f);
		}

		private void Start()
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			SetupColorPickerUI();
			((UnityEvent<float>)(object)rSlider.onValueChanged).AddListener((UnityAction<float>)delegate
			{
				UpdatePreview();
			});
			((UnityEvent<float>)(object)gSlider.onValueChanged).AddListener((UnityAction<float>)delegate
			{
				UpdatePreview();
			});
			((UnityEvent<float>)(object)bSlider.onValueChanged).AddListener((UnityAction<float>)delegate
			{
				UpdatePreview();
			});
			((UnityEvent)applyButton.onClick).AddListener(new UnityAction(ApplyColor));
			UpdatePreview();
		}

		private void UpdatePreview()
		{
			//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_0014: 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)
			Color selectedColor = GetSelectedColor();
			Singleton<Customization>.Instance.skins[0].color = selectedColor;
			PassportManager.instance.dummy.SetPlayerColor(0);
		}

		private Color GetSelectedColor()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			return new Color(rSlider.value / 255f, gSlider.value / 255f, bSlider.value / 255f, 1f);
		}

		private void ApplyColor()
		{
			//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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			Color selectedColor = GetSelectedColor();
			PersistentPlayerData playerData = GameHandler.GetService<PersistentPlayerDataService>().GetPlayerData(PhotonNetwork.LocalPlayer);
			CharacterCustomizationData customizationData = playerData.customizationData;
			SkinColorSliders.CustomColorStorage.colorTable.GetOrCreateValue(customizationData).color = selectedColor;
			SkinColorSliders.Instance.configColor.Value = selectedColor;
			CharacterCustomization.SetCharacterSkinColor(0);
		}
	}
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Resource1
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					ResourceManager resourceManager = new ResourceManager("SkinColorSliders.Resource1", typeof(Resource1).Assembly);
					resourceMan = resourceManager;
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal static byte[] colorpicker
		{
			get
			{
				object @object = ResourceManager.GetObject("colorpicker", resourceCulture);
				return (byte[])@object;
			}
		}

		internal Resource1()
		{
		}
	}
	[BepInPlugin("com.snosz.skincolorsliders", "SkinColorSliders", "1.0.0.0")]
	[BepInProcess("PEAK.exe")]
	public class SkinColorSliders : BaseUnityPlugin
	{
		public static class CustomColorStorage
		{
			public class SkinColorData
			{
				public Color color = Color.white;
			}

			public static readonly ConditionalWeakTable<CharacterCustomizationData, SkinColorData> colorTable = new ConditionalWeakTable<CharacterCustomizationData, SkinColorData>();
		}

		[HarmonyPatch(typeof(Character), "Awake")]
		private class CharacterAwakePatch
		{
			private static void Postfix(Character __instance)
			{
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0041: Unknown result type (might be due to invalid IL or missing references)
				if (__instance.IsLocal)
				{
					PersistentPlayerData playerData = GameHandler.GetService<PersistentPlayerDataService>().GetPlayerData(PhotonNetwork.LocalPlayer);
					CharacterCustomizationData customizationData = playerData.customizationData;
					CustomColorStorage.colorTable.GetOrCreateValue(customizationData).color = Instance.configColor.Value;
				}
			}
		}

		[HarmonyPatch(typeof(CharacterCustomizationData), "Serialize")]
		public static class SerializePatch
		{
			private static void Postfix(CharacterCustomizationData __instance, BinarySerializer serializer)
			{
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0013: 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_002d: Unknown result type (might be due to invalid IL or missing references)
				Color color = CustomColorStorage.colorTable.GetOrCreateValue(__instance).color;
				serializer.WriteFloat(color.r);
				serializer.WriteFloat(color.g);
				serializer.WriteFloat(color.b);
			}
		}

		[HarmonyPatch(typeof(CharacterCustomizationData), "Deserialize")]
		public static class DeserializePatch
		{
			private static void Postfix(CharacterCustomizationData __instance, BinaryDeserializer deserializer)
			{
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_002b: Unknown result type (might be due to invalid IL or missing references)
				Color color = default(Color);
				((Color)(ref color))..ctor(deserializer.ReadFloat(), deserializer.ReadFloat(), deserializer.ReadFloat(), 1f);
				CustomColorStorage.colorTable.GetOrCreateValue(__instance).color = color;
			}
		}

		[HarmonyPatch(typeof(CharacterCustomization), "OnPlayerDataChange")]
		public static class OnPlayerDataChangePatch
		{
			private static void Postfix(CharacterCustomization __instance, PersistentPlayerData playerData)
			{
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				Color color = CustomColorStorage.colorTable.GetOrCreateValue(playerData.customizationData).color;
				int shaderID = Shader.PropertyToID("_SkinColor");
				ApplyColorToRenderers(__instance.refs.PlayerRenderers, color, shaderID);
				ApplyColorToRenderers(__instance.refs.EyeRenderers, color, shaderID);
			}

			private static void ApplyColorToRenderers(Renderer[] renderers, Color color, int shaderID)
			{
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				foreach (Renderer val in renderers)
				{
					val.material.SetColor(shaderID, color);
				}
			}
		}

		[HarmonyPatch(typeof(PassportManager), "Awake")]
		public static class PassportManagerPatch
		{
			private static void Postfix(PassportManager __instance)
			{
				//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)
				ColorSlidersUI colorSlidersUI = ((Component)__instance).gameObject.AddComponent<ColorSlidersUI>();
				colorSlidersUI.initialColor = Instance.configColor.Value;
			}
		}

		public ConfigEntry<Color> configColor;

		public static SkinColorSliders Instance;

		public AssetBundle colorPickerUIBundle;

		private void Awake()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			byte[] colorpicker = Resource1.colorpicker;
			colorPickerUIBundle = AssetBundle.LoadFromMemory(colorpicker);
			configColor = ((BaseUnityPlugin)this).Config.Bind<Color>("General", "SkinColor", Color.white, "Skin color to apply.");
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
			new Harmony("com.snosz.skincolorsliders").PatchAll();
		}
	}
}