Decompiled source of DyeCommands v0.1.0

BepInEx/plugins/DyeCommands/DyeCommands.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("DyeCommands")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+0b24f12e068b5ee62e3136dc1570d704429fe51a")]
[assembly: AssemblyProduct("DyeCommands")]
[assembly: AssemblyTitle("DyeCommands")]
[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 DyeCommands
{
	internal enum AmourPart
	{
		Helm,
		Chestpiece,
		Leggings,
		Cape,
		All
	}
	internal enum DyeColour
	{
		Grey,
		Blue,
		Green,
		Red
	}
	[BepInPlugin("com.16mb.dyecommands", "DyeCommands", "0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(RaceModelEquipDisplay), "Apply_ArmorDisplay")]
		public static class Apply_ArmorDisplayPatch
		{
			[HarmonyPrefix]
			public static void Apply_ArmorDisplay_Prefix(ScriptableArmor _scriptArmor)
			{
				if (((object)_scriptArmor).GetType() == typeof(ScriptableHelm) && !profileDyeConfigs[ProfileDataManager._current.SelectedFileIndex].HelmDyeEnabled.Value)
				{
					_scriptArmor._canDyeArmor = false;
				}
				else if (((object)_scriptArmor).GetType() == typeof(ScriptableChestpiece) && !profileDyeConfigs[ProfileDataManager._current.SelectedFileIndex].ChestpieceDyeEnabled.Value)
				{
					_scriptArmor._canDyeArmor = false;
				}
				else if (((object)_scriptArmor).GetType() == typeof(ScriptableLeggings) && !profileDyeConfigs[ProfileDataManager._current.SelectedFileIndex].LeggingsDyeEnabled.Value)
				{
					_scriptArmor._canDyeArmor = false;
				}
				else if (((object)_scriptArmor).GetType() == typeof(ScriptableCape) && !profileDyeConfigs[ProfileDataManager._current.SelectedFileIndex].CapeDyeEnabled.Value)
				{
					_scriptArmor._canDyeArmor = false;
				}
				else
				{
					_scriptArmor._canDyeArmor = true;
				}
			}
		}

		[HarmonyPatch(typeof(ChatBehaviour), "Cmd_SendChatMessage")]
		public static class AddCommandssPatch
		{
			[HarmonyPrefix]
			public static bool Cmd_SendChatMessage_Prefix(ChatBehaviour __instance, string _message, ChatChannel _chatChannel)
			{
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_0045: Unknown result type (might be due to invalid IL or missing references)
				//IL_08ec: Unknown result type (might be due to invalid IL or missing references)
				string[] source = _message.ToLower().Split(new char[1] { ' ' });
				if (source.FirstOrDefault() == "/dye")
				{
					__instance.New_ChatMessage(_message);
					PlayerVisual component = ((Component)__instance).GetComponent<PlayerVisual>();
					PlayerAppearanceStruct playerAppearanceStruct = component._playerAppearanceStruct;
					if (new string[2] { "help", "h" }.Contains<string>(source.ElementAtOrDefault(1)))
					{
						__instance.New_ChatMessage("<color=" + chatColourHex + ">[DC] Type \"/dye <Armour> <Dye>\"</color>");
						__instance.New_ChatMessage("<color=" + chatColourHex + ">[DC] Armour: Helm, Chest, Legs, Cape, All</color>");
						__instance.New_ChatMessage("<color=" + chatColourHex + ">[DC] Dye: Grey, Blue, Green, Red, None</color>");
						__instance.New_ChatMessage("<color=" + chatColourHex + ">[DC] This is not case sensitive.</color>");
						return false;
					}
					int num = -1;
					switch (source.ElementAtOrDefault(2))
					{
					case "grey":
					case "white":
					case "w":
					case "0":
						num = 0;
						break;
					case "blue":
					case "b":
					case "1":
						num = 1;
						break;
					case "green":
					case "g":
					case "2":
						num = 2;
						break;
					case "red":
					case "r":
					case "3":
						num = 3;
						break;
					case "none":
					case "n":
					case "4":
						num = 4;
						break;
					}
					int num2 = -1;
					switch (source.ElementAtOrDefault(1))
					{
					case "helm":
					case "h":
					case "0":
						num2 = 0;
						break;
					case "chest":
					case "c":
					case "1":
						num2 = 1;
						break;
					case "legs":
					case "leg":
					case "l":
					case "2":
						num2 = 2;
						break;
					case "cape":
					case "k":
					case "3":
						num2 = 3;
						break;
					case "All":
					case "a":
					case "4":
						num2 = 4;
						break;
					}
					if (num >= 0 && num2 >= 0)
					{
						if (num == 4)
						{
							switch (num2)
							{
							case 0:
								profileDyeConfigs[ProfileDataManager._current.SelectedFileIndex].HelmDyeEnabled.Value = false;
								break;
							case 1:
								profileDyeConfigs[ProfileDataManager._current.SelectedFileIndex].ChestpieceDyeEnabled.Value = false;
								break;
							case 2:
								profileDyeConfigs[ProfileDataManager._current.SelectedFileIndex].LeggingsDyeEnabled.Value = false;
								break;
							case 3:
								profileDyeConfigs[ProfileDataManager._current.SelectedFileIndex].CapeDyeEnabled.Value = false;
								break;
							case 4:
								profileDyeConfigs[ProfileDataManager._current.SelectedFileIndex].HelmDyeEnabled.Value = false;
								profileDyeConfigs[ProfileDataManager._current.SelectedFileIndex].ChestpieceDyeEnabled.Value = false;
								profileDyeConfigs[ProfileDataManager._current.SelectedFileIndex].LeggingsDyeEnabled.Value = false;
								profileDyeConfigs[ProfileDataManager._current.SelectedFileIndex].CapeDyeEnabled.Value = false;
								break;
							}
							__instance.New_ChatMessage($"<color={chatColourHex}>[DC] Cleared {(AmourPart)num2} Dye.</color>");
						}
						else
						{
							switch (num2)
							{
							case 0:
								profileDyeConfigs[ProfileDataManager._current.SelectedFileIndex].HelmDyeEnabled.Value = true;
								playerAppearanceStruct._helmDyeIndex = num;
								break;
							case 1:
								profileDyeConfigs[ProfileDataManager._current.SelectedFileIndex].ChestpieceDyeEnabled.Value = true;
								playerAppearanceStruct._chestDyeIndex = num;
								break;
							case 2:
								profileDyeConfigs[ProfileDataManager._current.SelectedFileIndex].LeggingsDyeEnabled.Value = true;
								playerAppearanceStruct._legsDyeIndex = num;
								break;
							case 3:
								profileDyeConfigs[ProfileDataManager._current.SelectedFileIndex].CapeDyeEnabled.Value = true;
								playerAppearanceStruct._capeDyeIndex = num;
								break;
							case 4:
								profileDyeConfigs[ProfileDataManager._current.SelectedFileIndex].HelmDyeEnabled.Value = true;
								playerAppearanceStruct._helmDyeIndex = num;
								profileDyeConfigs[ProfileDataManager._current.SelectedFileIndex].ChestpieceDyeEnabled.Value = true;
								playerAppearanceStruct._chestDyeIndex = num;
								profileDyeConfigs[ProfileDataManager._current.SelectedFileIndex].LeggingsDyeEnabled.Value = true;
								playerAppearanceStruct._legsDyeIndex = num;
								profileDyeConfigs[ProfileDataManager._current.SelectedFileIndex].CapeDyeEnabled.Value = true;
								playerAppearanceStruct._capeDyeIndex = num;
								break;
							}
							component.Network_playerAppearanceStruct = playerAppearanceStruct;
							__instance.New_ChatMessage($"<color={chatColourHex}>[DC] Dyed {(AmourPart)num2} {(DyeColour)num}.</color>");
						}
					}
					else
					{
						if (num2 < 0 && source.Count() > 1)
						{
							__instance.New_ChatMessage("<color=" + chatColourHex + ">[DC] \"" + source.ElementAtOrDefault(1) + "\" is not a valid amour piece.</color>");
						}
						if (num < 0 && source.Count() > 2)
						{
							__instance.New_ChatMessage("<color=" + chatColourHex + ">[DC] \"" + source.ElementAtOrDefault(2) + "\" is not a valid dye colour.</color>");
						}
						__instance.New_ChatMessage("<color=" + chatColourHex + ">[DC] Type \"/dye help\" for details.</color>");
					}
					return false;
				}
				return true;
			}
		}

		internal static ManualLogSource Logger;

		private static ProfileDyeConfig[] profileDyeConfigs;

		private static string chatColourHex = "#f5ce42";

		private void Awake()
		{
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			profileDyeConfigs = new ProfileDyeConfig[7];
			for (int i = 0; i < profileDyeConfigs.Count(); i++)
			{
				profileDyeConfigs[i] = new ProfileDyeConfig();
				profileDyeConfigs[i].HelmDyeEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>($"CharacterProfile{i}", "HelmDyeEnabled", true, "Whether Dyes are Enabled for this profiles Helm.");
				profileDyeConfigs[i].ChestpieceDyeEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>($"CharacterProfile{i}", "ChestpieceDyeEnabled", true, "Whether Dyes are Enabled for this profiles Chestpiece.");
				profileDyeConfigs[i].LeggingsDyeEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>($"CharacterProfile{i}", "LeggingsDyeEnabled", true, "Whether Dyes are Enabled for this profiles Leggings.");
				profileDyeConfigs[i].CapeDyeEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>($"CharacterProfile{i}", "CapeDyeEnabled", true, "Whether Dyes are Enabled for this profiles Cape.");
			}
			new Harmony("DyeCommands").PatchAll();
			Logger.LogInfo((object)"Plugin DyeCommands is loaded!");
		}
	}
	public class ProfileDyeConfig
	{
		public ConfigEntry<bool> HelmDyeEnabled;

		public ConfigEntry<bool> ChestpieceDyeEnabled;

		public ConfigEntry<bool> LeggingsDyeEnabled;

		public ConfigEntry<bool> CapeDyeEnabled;
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "DyeCommands";

		public const string PLUGIN_NAME = "DyeCommands";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}