Decompiled source of CustomColors v1.0.0

CustomColors.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CustomColors")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A mod for REPO that lets you change your color with RGB sliders")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+1f21fcb678a641ed47e6a1e2723f5a6b8e5382e5")]
[assembly: AssemblyProduct("CustomColors")]
[assembly: AssemblyTitle("CustomColors")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CustomColors
{
	[BepInPlugin("x753.CustomColors", "CustomColors", "1.0.0")]
	public class CustomColorsMod : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(PlayerAvatar), "Awake")]
		private class PlayerAvatar_Awake_Patch
		{
			[HarmonyPostfix]
			public static void PlayerAvatar_Awake_Postfix(PlayerAvatar __instance)
			{
				((Component)__instance).gameObject.AddComponent<ModdedColorPlayerAvatar>();
			}
		}

		public class ModdedColorPlayerAvatar : MonoBehaviour, IPunObservable
		{
			public Color moddedColor;

			public static Color LocalColor = new Color(1f, 0f, 0f);

			public PlayerAvatar avatar;

			public PlayerAvatarVisuals visuals;

			public Material bodyMaterial;

			private static FieldInfo BodyMaterial = typeof(PlayerHealth).GetField("bodyMaterial", BindingFlags.Instance | BindingFlags.NonPublic);

			private static FieldInfo VisualsColor = typeof(PlayerAvatarVisuals).GetField("color", BindingFlags.Instance | BindingFlags.NonPublic);

			private static FieldInfo ColorSet = typeof(PlayerAvatarVisuals).GetField("colorSet", BindingFlags.Instance | BindingFlags.NonPublic);

			private static FieldInfo MenuPlayerListedList = typeof(MenuPageLobby).GetField("menuPlayerListedList", BindingFlags.Instance | BindingFlags.NonPublic);

			private static FieldInfo MenuPlayerListed_PlayerAvatar = typeof(MenuPlayerListed).GetField("playerAvatar", BindingFlags.Instance | BindingFlags.NonPublic);

			public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
			{
				throw new NotImplementedException();
			}

			private void Awake()
			{
				avatar = ((Component)this).gameObject.GetComponent<PlayerAvatar>();
				visuals = avatar.playerAvatarVisuals;
			}

			public static void LocalPlayerAvatarSetColor()
			{
				//IL_009b: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a1: Expected O, but got Unknown
				if (!GameManager.Multiplayer())
				{
					((Component)PlayerAvatar.instance).GetComponent<ModdedColorPlayerAvatar>().ModdedSetColorRPC(LocalColor.r, LocalColor.g, LocalColor.b);
				}
				else
				{
					PlayerAvatar.instance.photonView.RPC("ModdedSetColorRPC", (RpcTarget)3, new object[3] { LocalColor.r, LocalColor.g, LocalColor.b });
				}
				ES3Settings val = new ES3Settings("ModSettingsData.es3", new Enum[1] { (Enum)(object)(Location)0 });
				ES3.Save<string>("PlayerBodyColorR", LocalColor.r.ToString(), val);
				ES3.Save<string>("PlayerBodyColorG", LocalColor.g.ToString(), val);
				ES3.Save<string>("PlayerBodyColorB", LocalColor.b.ToString(), val);
			}

			[PunRPC]
			public void ModdedSetColorRPC(float r, float g, float b)
			{
				//IL_000b: 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_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0065: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0055: Expected O, but got Unknown
				//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bd: Expected O, but got Unknown
				//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
				Color val = default(Color);
				((Color)(ref val))..ctor(r, g, b);
				moddedColor = val;
				VisualsColor.SetValue(visuals, val);
				if ((Object)(object)bodyMaterial == (Object)null)
				{
					bodyMaterial = (Material)BodyMaterial.GetValue(avatar.playerHealth);
				}
				bodyMaterial.SetColor(Shader.PropertyToID("_AlbedoColor"), val);
				if (SemiFunc.RunIsLobbyMenu() && Object.op_Implicit((Object)(object)MenuPageLobby.instance))
				{
					foreach (MenuPlayerListed item in (List<MenuPlayerListed>)MenuPlayerListedList.GetValue(MenuPageLobby.instance))
					{
						if ((Object)(PlayerAvatar)MenuPlayerListed_PlayerAvatar.GetValue(item) == (Object)(object)avatar)
						{
							item.playerHead.SetColor(val);
							break;
						}
					}
				}
				ColorSet.SetValue(visuals, true);
			}
		}

		public class SliderReinitializer : MonoBehaviour
		{
			public string elementName = "";

			public MenuSlider menuSlider;

			public float startValue;

			public void Start()
			{
				((Component)this).gameObject.GetComponent<MenuSlider>().elementName = elementName;
				((TMP_Text)((Component)((Component)this).gameObject.transform.Find("Element Name")).GetComponent<TextMeshProUGUI>()).SetText(elementName, true);
				((Object)((Component)this).gameObject).name = "Slider - " + elementName;
				menuSlider.SetBar(startValue);
			}
		}

		[HarmonyPatch(typeof(MenuPageColor), "Start")]
		private class MenuPageColor_Start_Patch
		{
			[HarmonyPostfix]
			public static void MenuPageColor_Start_Postfix(MenuPageColor __instance)
			{
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
				//IL_0115: Unknown result type (might be due to invalid IL or missing references)
				//IL_011f: Unknown result type (might be due to invalid IL or missing references)
				//IL_014e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0158: Unknown result type (might be due to invalid IL or missing references)
				((Component)__instance).transform.Find("Color Button Holder");
				((Component)__instance).transform.Find("Menu Button - Confirm").localPosition = new Vector3(330f, 80f, 0f);
				foreach (MenuPages menuPage2 in MenuManager.instance.menuPages)
				{
					GameObject menuPage = menuPage2.menuPage;
					if (((Object)menuPage).name == "Menu Page Settings Audio")
					{
						Transform obj = menuPage.transform.Find("Menu Scroll Box");
						Transform obj2 = ((obj != null) ? obj.Find("Mask") : null);
						Transform obj3 = ((obj2 != null) ? obj2.Find("Scroller") : null);
						Transform val = ((obj3 != null) ? obj3.Find("Slider - Master volume") : null);
						if ((Object)(object)val != (Object)null)
						{
							RedSlider = CreateColorSlider(((Component)val).gameObject, ((Component)__instance).transform, new Vector3(60f, 525f, 0f), "Color [RED]", Color.red, 753);
							GreenSlider = CreateColorSlider(((Component)val).gameObject, ((Component)__instance).transform, new Vector3(60f, 495f, 0f), "Color [GREEN]", Color.green, 754);
							BlueSlider = CreateColorSlider(((Component)val).gameObject, ((Component)__instance).transform, new Vector3(60f, 465f, 0f), "Color [BLUE]", Color.blue, 755);
						}
					}
				}
			}
		}

		[HarmonyPatch(typeof(PlayerAvatar), "PlayerAvatarSetColor")]
		private class PlayerAvatar_PlayerAvatarSetColor_Patch
		{
			[HarmonyPostfix]
			public static void PlayerAvatar_PlayerAvatarSetColor_Postfix(PlayerAvatar __instance, int colorIndex)
			{
				//IL_000d: Unknown result type (might be due to invalid IL or missing references)
				ModdedColorPlayerAvatar component = ((Component)__instance).GetComponent<ModdedColorPlayerAvatar>();
				if (component != null)
				{
					_ = component.moddedColor;
					if (true)
					{
						ModdedColorPlayerAvatar.LocalPlayerAvatarSetColor();
					}
				}
			}
		}

		[HarmonyPatch(typeof(PlayerAvatarVisuals), "MenuAvatarGetColorsFromRealAvatar")]
		private class PlayerAvatarVisuals_MenuAvatarGetColorsFromRealAvatar_Patch
		{
			public static Material bodyMaterial;

			private static FieldInfo BodyMaterial = typeof(PlayerHealth).GetField("bodyMaterial", BindingFlags.Instance | BindingFlags.NonPublic);

			[HarmonyPrefix]
			public static bool PlayerAvatarVisuals_MenuAvatarGetColorsFromRealAvatar_Prefix(PlayerAvatarVisuals __instance)
			{
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Expected O, but got Unknown
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				if (__instance.isMenuAvatar && !Object.op_Implicit((Object)(object)__instance.playerAvatar))
				{
					__instance.playerAvatar = PlayerAvatar.instance;
				}
				bodyMaterial = (Material)BodyMaterial.GetValue(((Component)((Component)__instance).transform).GetComponentInParent<PlayerHealth>());
				bodyMaterial.SetColor(Shader.PropertyToID("_AlbedoColor"), ModdedColorPlayerAvatar.LocalColor);
				return false;
			}
		}

		[HarmonyPatch(typeof(MenuColorSelected), "SetColor")]
		private class MenuColorSelected_SetColor_Patch
		{
			[HarmonyPostfix]
			public static void MenuColorSelected_SetColor_Postfix(MenuColorSelected __instance, Color color, Vector3 position)
			{
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				//IL_002f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0057: 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)
				//IL_004c: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)RedSlider != (Object)null)
				{
					RedSlider.SetBar(color.r);
				}
				if ((Object)(object)GreenSlider != (Object)null)
				{
					GreenSlider.SetBar(color.g);
				}
				if ((Object)(object)BlueSlider != (Object)null)
				{
					BlueSlider.SetBar(color.b);
				}
				ModdedColorPlayerAvatar.LocalColor = color;
			}
		}

		[HarmonyPatch(typeof(MenuPageColor), "ConfirmButton")]
		private class MenuPageColor_ConfirmButton_Patch
		{
			[HarmonyPrefix]
			public static void MenuPageColor_ConfirmButton_Prefix(MenuPageColor __instance)
			{
				ModdedColorPlayerAvatar.LocalPlayerAvatarSetColor();
			}
		}

		[HarmonyPatch(typeof(DataDirector), "SettingValueSet")]
		private class DataDirector_SettingValueSet_Patch
		{
			[HarmonyPrefix]
			public static bool DataDirector_SettingValueSet_Prefix(DataDirector __instance, Setting setting, int value)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Invalid comparison between Unknown and I4
				//IL_001c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Invalid comparison between Unknown and I4
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Invalid comparison between Unknown and I4
				if ((int)setting == 753)
				{
					ModdedColorPlayerAvatar.LocalColor.r = (float)value / 100f;
					return false;
				}
				if ((int)setting == 754)
				{
					ModdedColorPlayerAvatar.LocalColor.g = (float)value / 100f;
					return false;
				}
				if ((int)setting == 755)
				{
					ModdedColorPlayerAvatar.LocalColor.b = (float)value / 100f;
					return false;
				}
				return true;
			}
		}

		private const string modGUID = "x753.CustomColors";

		private const string modName = "CustomColors";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("x753.CustomColors");

		private static CustomColorsMod Instance;

		public static MenuSlider RedSlider;

		public static MenuSlider GreenSlider;

		public static MenuSlider BlueSlider;

		private void Awake()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin CustomColors is loaded!");
			ES3Settings val = new ES3Settings("ModSettingsData.es3", new Enum[1] { (Enum)(object)(Location)0 });
			if (ES3.KeyExists("PlayerBodyColorR", val))
			{
				string s = ES3.Load<string>("PlayerBodyColorR", "0", val);
				string s2 = ES3.Load<string>("PlayerBodyColorG", "1", val);
				string s3 = ES3.Load<string>("PlayerBodyColorB", "0", val);
				ModdedColorPlayerAvatar.LocalColor.r = float.Parse(s);
				ModdedColorPlayerAvatar.LocalColor.g = float.Parse(s2);
				ModdedColorPlayerAvatar.LocalColor.b = float.Parse(s3);
			}
		}

		public static MenuSlider CreateColorSlider(GameObject sliderPrefab, Transform parentTransform, Vector3 position, string elementName, Color color, int settingNum)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = Object.Instantiate<GameObject>(sliderPrefab, parentTransform);
			obj.transform.position = position;
			((Graphic)((Component)obj.transform.Find("SliderBG").Find("RawImage (1)")).GetComponent<RawImage>()).color = Color.black;
			((Component)obj.transform.Find("SliderBG").Find("RawImage (2)")).gameObject.SetActive(false);
			((Graphic)((Component)obj.transform.Find("SliderBG").Find("RawImage (3)")).GetComponent<RawImage>()).color = new Color(0.1f, 0.1f, 0.1f);
			((Component)obj.transform.Find("MaskedText")).gameObject.SetActive(false);
			((Graphic)((Component)obj.transform.Find("Bar").Find("RawImage")).GetComponent<RawImage>()).color = color;
			MenuSlider component = obj.GetComponent<MenuSlider>();
			component.pointerSegmentJump = 1;
			component.buttonSegmentJump = 1;
			obj.GetComponent<MenuSetting>().setting = (Setting)settingNum;
			Object.Destroy((Object)(object)obj.GetComponent<MenuSettingElement>());
			SliderReinitializer sliderReinitializer = obj.AddComponent<SliderReinitializer>();
			sliderReinitializer.menuSlider = component;
			sliderReinitializer.elementName = elementName;
			if (color == Color.red)
			{
				sliderReinitializer.startValue = ModdedColorPlayerAvatar.LocalColor.r;
			}
			else if (color == Color.green)
			{
				sliderReinitializer.startValue = ModdedColorPlayerAvatar.LocalColor.g;
			}
			else if (color == Color.blue)
			{
				sliderReinitializer.startValue = ModdedColorPlayerAvatar.LocalColor.b;
			}
			return component;
		}
	}
}