Decompiled source of ColorAssist v0.1.2

ColorAssist.dll

Decompiled 3 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using NineSolsAPI;
using NineSolsAPI.Utils;
using UnityEngine;
using UnityEngine.SceneManagement;

[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("ColorAssist")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("ColorAssist")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ColorAssist")]
[assembly: AssemblyTitle("ColorAssist")]
[assembly: AssemblyVersion("1.0.0.0")]
[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.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;
		}
	}
	[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;
		}
	}
}
internal sealed class ConfigurationManagerAttributes
{
	public delegate void CustomHotkeyDrawerFunc(ConfigEntryBase setting, ref bool isCurrentlyAcceptingInput);

	public bool? ShowRangeAsPercent;

	public Action<ConfigEntryBase> CustomDrawer;

	public CustomHotkeyDrawerFunc CustomHotkeyDrawer;

	public bool? Browsable;

	public string Category;

	public object DefaultValue;

	public bool? HideDefaultButton;

	public bool? HideSettingName;

	public string Description;

	public string DispName;

	public int? Order;

	public bool? ReadOnly;

	public bool? IsAdvanced;

	public Func<object, string> ObjToStr;

	public Func<string, object> StrToObj;
}
namespace ColorAssist
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("ColorAssist", "ColorAssist", "1.0.0")]
	public class ColorAssist : BaseUnityPlugin
	{
		private ConfigEntry<bool> enableSomethingConfig;

		private ConfigEntry<KeyboardShortcut> somethingKeyboardShortcut;

		public ConfigEntry<string> curFilter;

		private ConfigEntry<bool> isEnableFilter;

		private ConfigEntry<bool> isProtanopia;

		private ConfigEntry<bool> isProtanomaly;

		private ConfigEntry<bool> isDeuteranopia;

		private ConfigEntry<bool> isDeuteranomaly;

		private ConfigEntry<bool> isTritanopia;

		private ConfigEntry<bool> isTritanomaly;

		private ConfigEntry<bool> isAchromatopsia;

		private ConfigEntry<bool> isAchromatomaly;

		public ConfigEntry<bool> isHeealthBar;

		public ConfigEntry<int> R;

		public ConfigEntry<int> G;

		public ConfigEntry<int> B;

		public ConfigEntry<int> A;

		private const string Protanopia = "Protanopia";

		private const string Protanomaly = "Protanomaly";

		private const string Deuteranopia = "Deuteranopia";

		private const string Deuteranomaly = "Deuteranomaly";

		private const string Tritanopia = "Tritanopia";

		private const string Tritanomaly = "Tritanomaly";

		private const string Achromatopsia = "Achromatopsia";

		private const string Achromatomaly = "Achromatomaly";

		public Material[] colorBlindMaterials;

		private AssetBundle shader;

		private ColorblindFilter colorblindFilter;

		private Harmony harmony;

		public static ColorAssist Instance { get; private set; }

		private void Awake()
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Expected O, but got Unknown
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Expected O, but got Unknown
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Expected O, but got Unknown
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Expected O, but got Unknown
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Expected O, but got Unknown
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Expected O, but got Unknown
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Expected O, but got Unknown
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Expected O, but got Unknown
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Expected O, but got Unknown
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Expected O, but got Unknown
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Expected O, but got Unknown
			//IL_038b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0395: Expected O, but got Unknown
			//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d6: Expected O, but got Unknown
			//IL_0411: Unknown result type (might be due to invalid IL or missing references)
			//IL_041b: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			RCGLifeCycle.DontDestroyForever(((Component)this).gameObject);
			harmony = Harmony.CreateAndPatchAll(typeof(ColorAssist).Assembly, (string)null);
			Instance = this;
			curFilter = ((BaseUnityPlugin)this).Config.Bind<string>("", "Current Filter", "", new ConfigDescription("", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 14
				}
			}));
			isEnableFilter = ((BaseUnityPlugin)this).Config.Bind<bool>("", "Enable Filter", false, new ConfigDescription("", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 13
				}
			}));
			isProtanopia = ((BaseUnityPlugin)this).Config.Bind<bool>("", "Protanopia", false, new ConfigDescription("", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 12
				}
			}));
			isProtanomaly = ((BaseUnityPlugin)this).Config.Bind<bool>("", "Protanomaly", false, new ConfigDescription("", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 11
				}
			}));
			isDeuteranopia = ((BaseUnityPlugin)this).Config.Bind<bool>("", "Deuteranopia", false, new ConfigDescription("", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 10
				}
			}));
			isDeuteranomaly = ((BaseUnityPlugin)this).Config.Bind<bool>("", "Deuteranomaly", false, new ConfigDescription("", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 9
				}
			}));
			isTritanopia = ((BaseUnityPlugin)this).Config.Bind<bool>("", "Tritanopia", false, new ConfigDescription("", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 8
				}
			}));
			isTritanomaly = ((BaseUnityPlugin)this).Config.Bind<bool>("", "Tritanomaly", false, new ConfigDescription("", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 7
				}
			}));
			isAchromatopsia = ((BaseUnityPlugin)this).Config.Bind<bool>("", "Achromatopsia", false, new ConfigDescription("", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 6
				}
			}));
			isAchromatomaly = ((BaseUnityPlugin)this).Config.Bind<bool>("", "Achromatomaly", false, new ConfigDescription("", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 5
				}
			}));
			isHeealthBar = ((BaseUnityPlugin)this).Config.Bind<bool>("", "Enable HeealthBar Color", false, new ConfigDescription("", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 5
				}
			}));
			R = ((BaseUnityPlugin)this).Config.Bind<int>("", "Red", 255, new ConfigDescription("", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 4
				}
			}));
			G = ((BaseUnityPlugin)this).Config.Bind<int>("", "Green", 255, new ConfigDescription("", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 3
				}
			}));
			B = ((BaseUnityPlugin)this).Config.Bind<int>("", "Blue", 0, new ConfigDescription("", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 2
				}
			}));
			A = ((BaseUnityPlugin)this).Config.Bind<int>("", "Alpha", 255, new ConfigDescription("", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 1
				}
			}));
			colorBlindMaterials = LoadColorBlindMaterials();
			isEnableFilter.SettingChanged += delegate
			{
				UpdateFilterUsage();
			};
			isProtanopia.SettingChanged += delegate
			{
				ChangeFilter("Protanopia");
			};
			isProtanomaly.SettingChanged += delegate
			{
				ChangeFilter("Protanomaly");
			};
			isDeuteranopia.SettingChanged += delegate
			{
				ChangeFilter("Deuteranopia");
			};
			isDeuteranomaly.SettingChanged += delegate
			{
				ChangeFilter("Deuteranomaly");
			};
			isTritanopia.SettingChanged += delegate
			{
				ChangeFilter("Tritanopia");
			};
			isTritanomaly.SettingChanged += delegate
			{
				ChangeFilter("Tritanomaly");
			};
			isAchromatopsia.SettingChanged += delegate
			{
				ChangeFilter("Achromatopsia");
			};
			isAchromatomaly.SettingChanged += delegate
			{
				ChangeFilter("Achromatomaly");
			};
			isHeealthBar.SettingChanged += delegate
			{
				UpdateHealthColor();
			};
			R.SettingChanged += delegate
			{
				UpdateHealthColor();
			};
			G.SettingChanged += delegate
			{
				UpdateHealthColor();
			};
			B.SettingChanged += delegate
			{
				UpdateHealthColor();
			};
			A.SettingChanged += delegate
			{
				UpdateHealthColor();
			};
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin ColorAssist is loaded!");
		}

		private void Start()
		{
			SceneManager.sceneLoaded += OnSceneLoaded;
		}

		private Material[] LoadColorBlindMaterials()
		{
			shader = AssemblyUtils.GetEmbeddedAssetBundle("ColorAssist.Resources.shader");
			return (Material[])(object)new Material[8]
			{
				shader.LoadAsset<Material>("Protanopia"),
				shader.LoadAsset<Material>("Protanomaly"),
				shader.LoadAsset<Material>("Deuteranopia"),
				shader.LoadAsset<Material>("Deuteranomaly"),
				shader.LoadAsset<Material>("Tritanopia"),
				shader.LoadAsset<Material>("Tritanomaly"),
				shader.LoadAsset<Material>("Achromatopsia"),
				shader.LoadAsset<Material>("Achromatomaly")
			};
		}

		private void UpdateFilterUsage()
		{
			if ((Object)(object)colorblindFilter == (Object)null)
			{
				AttachColorblindFilter();
			}
			colorblindFilter?.SetUseFilter(isEnableFilter.Value);
		}

		private void AttachColorblindFilter()
		{
			Camera[] allCameras = Camera.allCameras;
			foreach (Camera val in allCameras)
			{
				if (((Object)((Component)val).gameObject).name == "ApplicationUICam")
				{
					colorblindFilter = ((Component)val).gameObject.GetComponent<ColorblindFilter>() ?? ((Component)val).gameObject.AddComponent<ColorblindFilter>();
					break;
				}
			}
		}

		private void SetFilterMaterial(Material filterMaterial)
		{
			AttachColorblindFilter();
			if ((Object)(object)colorblindFilter != (Object)null)
			{
				colorblindFilter.setMaterial(filterMaterial);
				curFilter.Value = ((Object)filterMaterial).name;
			}
		}

		private void TestMethod()
		{
			if (enableSomethingConfig.Value)
			{
				ToastManager.Toast((object)"TestMethod Triggered");
				AttachColorblindFilter();
			}
		}

		private void ChangeFilter(string filterName)
		{
			string filterName2 = filterName;
			Material val = Array.Find(colorBlindMaterials, (Material m) => ((Object)m).name == filterName2);
			if ((Object)(object)val != (Object)null)
			{
				SetFilterMaterial(val);
			}
			isEnableFilter.Value = true;
		}

		private void UpdateHealthColor()
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("GameCore(Clone)/RCG LifeCycle/UIManager/GameplayUICamera/HideUIAbilityCheck/[Activate] PlayerUI Folder/PlayerInGameUI renderer/LeftTop/HealthBarBase/HealthBar/BG renderer/RecoverableHealth");
			if (Object.op_Implicit((Object)(object)val))
			{
				if (isHeealthBar.Value)
				{
					val.GetComponent<SpriteRenderer>().color = new Color((float)R.Value / 255f, (float)G.Value / 255f, (float)B.Value / 255f, (float)A.Value / 255f);
				}
				else
				{
					val.GetComponent<SpriteRenderer>().color = new Color(0.566f, 0f, 0.161f, 0.706f);
				}
			}
			GameObject val2 = GameObject.Find("GameCore(Clone)/RCG LifeCycle/UIManager/GameplayUICamera/MonsterHPRoot/BossHPRoot/UIBossHP(Clone)/Offset(DontKeyAnimationOnThisNode)/AnimationOffset/HealthBar/BG/MaxHealth/Internal Injury");
			if (Object.op_Implicit((Object)(object)val2))
			{
				if (isHeealthBar.Value)
				{
					val2.GetComponent<SpriteRenderer>().color = new Color((float)R.Value / 255f, (float)G.Value / 255f, (float)B.Value / 255f, (float)A.Value / 255f);
				}
				else
				{
					val2.GetComponent<SpriteRenderer>().color = new Color(0.481f, 0f, 0.242f, 1f);
				}
			}
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			if (((Scene)(ref scene)).name == "TitleScreenMenu")
			{
				AttachColorblindFilter();
				UpdateFilterUsage();
			}
			UpdateHealthColor();
		}

		private void OnDestroy()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
			AssetBundle obj = shader;
			if (obj != null)
			{
				obj.Unload(false);
			}
			harmony.UnpatchSelf();
		}
	}
	public class ColorblindFilter : MonoBehaviour
	{
		[SerializeField]
		private bool _useFilter = true;

		private Material _mat;

		public bool UseFilter => _useFilter;

		private void Awake()
		{
			string value = ColorAssist.Instance.curFilter.Value;
			_mat = GetMaterialByName(value) ?? ColorAssist.Instance.colorBlindMaterials[0];
		}

		public void setMaterial(Material m)
		{
			_mat = m;
		}

		private void OnRenderImage(RenderTexture src, RenderTexture dst)
		{
			if (_useFilter)
			{
				Graphics.Blit((Texture)(object)src, dst, _mat);
			}
			else
			{
				Graphics.Blit((Texture)(object)src, dst);
			}
		}

		private Material GetMaterialByName(string materialName)
		{
			Material[] colorBlindMaterials = ColorAssist.Instance.colorBlindMaterials;
			foreach (Material val in colorBlindMaterials)
			{
				if (((Object)val).name == materialName)
				{
					return val;
				}
			}
			return null;
		}

		public void SetUseFilter(bool useFilter)
		{
			_useFilter = useFilter;
		}
	}
	internal static class Log
	{
		private static ManualLogSource? logSource;

		internal static void Init(ManualLogSource logSource)
		{
			Log.logSource = logSource;
		}

		internal static void Debug(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogDebug(data);
			}
		}

		internal static void Error(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogError(data);
			}
		}

		internal static void Fatal(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogFatal(data);
			}
		}

		internal static void Info(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogInfo(data);
			}
		}

		internal static void Message(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogMessage(data);
			}
		}

		internal static void Warning(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogWarning(data);
			}
		}
	}
	[HarmonyPatch]
	public class Patches
	{
		[HarmonyPatch(typeof(SpriteRendererRCGExt), "Awake")]
		[HarmonyPrefix]
		private static bool hookSpriteRendererRCGExt(ref SpriteRendererRCGExt __instance)
		{
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			if (!(((Object)((Component)__instance).gameObject).name == "Internal Injury"))
			{
				return true;
			}
			if (!ColorAssist.Instance.isHeealthBar.Value)
			{
				return true;
			}
			((Component)__instance).gameObject.GetComponent<SpriteRenderer>().color = new Color((float)ColorAssist.Instance.R.Value / 255f, (float)ColorAssist.Instance.G.Value / 255f, (float)ColorAssist.Instance.B.Value / 255f, (float)ColorAssist.Instance.A.Value / 255f);
			return true;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "ColorAssist";

		public const string PLUGIN_NAME = "ColorAssist";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}