Decompiled source of LethalCabin v1.2.0

ConfigurableEmissions.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using DiskCardGame;
using InscryptionAPI.Card;
using InscryptionAPI.Helpers;
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(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("ConfigurableEmissions")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ConfigurableEmissions")]
[assembly: AssemblyTitle("ConfigurableEmissions")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ConfigurableEmissions;

public class ConfigurableBackground : CardAppearanceBehaviour
{
	public static Dictionary<string, Texture2D> pathToTexture = new Dictionary<string, Texture2D>();

	public override void ApplyAppearance()
	{
		try
		{
			Texture2D value = null;
			string extendedProperty = CardExtensions.GetExtendedProperty(((CardAppearanceBehaviour)this).Card.Info, "customBackground");
			if (extendedProperty != null)
			{
				if (!pathToTexture.TryGetValue(extendedProperty, out value))
				{
					pathToTexture.Add(extendedProperty, value = TextureHelper.GetImageAsTexture(extendedProperty, (FilterMode)0));
				}
				if ((Object)(object)value != (Object)null)
				{
					((CardAppearanceBehaviour)this).Card.RenderInfo.baseTextureOverride = (Texture)(object)value;
				}
			}
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("Failed setting custom background: " + ex));
		}
	}

	public override void ResetAppearance()
	{
		((CardAppearanceBehaviour)this).Card.RenderInfo.baseTextureOverride = ResourceBank.Get<Texture>("Art/Cards/card_empty");
	}
}
public class ConfigurableEmission : CardAppearanceBehaviour
{
	public override void ApplyAppearance()
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (((CardAppearanceBehaviour)this).Card.Info.TryGetColorFromCardInfo("customEmissionColor", out var color))
			{
				((CardAppearanceBehaviour)this).Card.StatsLayer.SetEmissionColor(color);
			}
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("Failed setting custom emission color: " + ex));
		}
	}

	public override void ResetAppearance()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			((CardAppearanceBehaviour)this).Card.StatsLayer.SetEmissionColor(GameColors.Instance.glowSeafoam);
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("Failed resetting custom emission color: " + ex));
		}
	}
}
public class ConfigurableStatColors : CardAppearanceBehaviour
{
	public override void ApplyAppearance()
	{
		//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_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_0085: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (((CardAppearanceBehaviour)this).Card.Info.TryGetColorFromCardInfo("customPortraitColor", out var color))
			{
				((CardAppearanceBehaviour)this).Card.RenderInfo.portraitColor = color;
			}
			if (((CardAppearanceBehaviour)this).Card.Info.TryGetColorFromCardInfo("customAttackColor", out color))
			{
				((CardAppearanceBehaviour)this).Card.RenderInfo.attackTextColor = color;
			}
			if (((CardAppearanceBehaviour)this).Card.Info.TryGetColorFromCardInfo("customHealthColor", out color))
			{
				((CardAppearanceBehaviour)this).Card.RenderInfo.healthTextColor = color;
			}
			if (((CardAppearanceBehaviour)this).Card.Info.TryGetColorFromCardInfo("customNameColor", out color))
			{
				((CardAppearanceBehaviour)this).Card.RenderInfo.nameTextColor = color;
			}
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("Failed setting custom portrait color: " + ex));
		}
	}

	public override void ResetAppearance()
	{
		//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)
		try
		{
			((CardAppearanceBehaviour)this).Card.RenderInfo.portraitColor = Color.black;
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("Failed resetting custom portrait color: " + ex));
		}
	}
}
public static class CustomColorHelper
{
	public static bool TryGetColorFromCardInfo(this CardInfo card, string prefix, out Color color)
	{
		return TryGetColorFromHex(CardExtensions.GetExtendedProperty(card, prefix + "HEX"), out color) || TryGetRGBFromString32(CardExtensions.GetExtendedProperty(card, prefix + "255"), out color) || TryGetRGBFromString(CardExtensions.GetExtendedProperty(card, prefix + "1"), out color) || TryGetRGBFromHSVString32(CardExtensions.GetExtendedProperty(card, prefix + "HSV"), out color) || TryGetRGBFromHSVString(CardExtensions.GetExtendedProperty(card, prefix + "HSV1"), out color) || TryGetColorFromHex(CardExtensions.GetExtendedProperty(card, prefix), out color) || TryGetRGBFromString32(CardExtensions.GetExtendedProperty(card, prefix), out color);
	}

	public static bool TryGetRGBFromString(string str, out Color c)
	{
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		if (str != null)
		{
			try
			{
				string[] array = str.Split(new char[1] { ',' });
				if (array.Length != 0)
				{
					float.TryParse(array[0].Trim(), out var result);
					float result2 = 0f;
					float result3 = 0f;
					float result4 = 1f;
					if (array.Length > 1)
					{
						float.TryParse(array[1].Trim(), out result2);
						if (array.Length > 2)
						{
							float.TryParse(array[2].Trim(), out result3);
							if (array.Length > 3)
							{
								float.TryParse(array[3].Trim(), out result4);
							}
						}
					}
					c = new Color(result, result2, result3, result4);
					return true;
				}
			}
			catch
			{
			}
		}
		c = Color.clear;
		return false;
	}

	public static bool TryGetRGBFromHSVString(string str, out Color c)
	{
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		if (str != null)
		{
			try
			{
				string[] array = str.Split(new char[1] { ',' });
				if (array.Length != 0)
				{
					float.TryParse(array[0].Trim(), out var result);
					float result2 = 0f;
					float result3 = 0f;
					float result4 = 1f;
					if (array.Length > 1)
					{
						float.TryParse(array[1].Trim(), out result2);
						if (array.Length > 2)
						{
							float.TryParse(array[2].Trim(), out result3);
							if (array.Length > 3)
							{
								float.TryParse(array[3].Trim(), out result4);
							}
						}
					}
					c = Color.HSVToRGB(result, result2, result3);
					c.a = result4;
					return true;
				}
			}
			catch
			{
			}
		}
		c = Color.clear;
		return false;
	}

	public static bool TryGetRGBFromHSVString32(string str, out Color c)
	{
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		if (str != null)
		{
			try
			{
				string[] array = str.Split(new char[1] { ',' });
				if (array.Length != 0)
				{
					byte.TryParse(array[0].Trim(), out var result);
					byte result2 = 0;
					byte result3 = 0;
					byte result4 = 1;
					if (array.Length > 1)
					{
						byte.TryParse(array[1].Trim(), out result2);
						if (array.Length > 2)
						{
							byte.TryParse(array[2].Trim(), out result3);
							if (array.Length > 3)
							{
								byte.TryParse(array[3].Trim(), out result4);
							}
						}
					}
					c = Color.HSVToRGB((float)(int)result / 360f, (float)(int)result2 / 100f, (float)(int)result3 / 100f);
					c.a = (float)(int)result4 / 255f;
					return true;
				}
			}
			catch
			{
			}
		}
		c = Color.clear;
		return false;
	}

	public static bool TryGetRGBFromString32(string str, out Color c)
	{
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: 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)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		if (str != null)
		{
			try
			{
				string[] array = str.Split(new char[1] { ',' });
				if (array.Length != 0)
				{
					byte.TryParse(array[0].Trim(), out var result);
					byte result2 = 0;
					byte result3 = 0;
					byte result4 = byte.MaxValue;
					if (array.Length > 1)
					{
						byte.TryParse(array[1].Trim(), out result2);
						if (array.Length > 2)
						{
							byte.TryParse(array[2].Trim(), out result3);
							if (array.Length > 3)
							{
								byte.TryParse(array[3].Trim(), out result4);
							}
						}
					}
					c = Color32.op_Implicit(new Color32(result, result2, result3, result4));
					return true;
				}
			}
			catch
			{
			}
		}
		c = Color.clear;
		return false;
	}

	public static bool TryGetColorFromHex(string hex, out Color c)
	{
		//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)
		try
		{
			return ColorUtility.TryParseHtmlString(hex, ref c);
		}
		catch
		{
			c = Color.clear;
			return false;
		}
	}
}
public class ExpandedPortrait : CardAppearanceBehaviour
{
	public override void ApplyAppearance()
	{
		try
		{
			((CardAppearanceBehaviour)this).Card.RenderInfo.expandedPortrait = true;
		}
		catch (Exception ex)
		{
			Debug.Log((object)("Failed setting expanded portrait: " + ex));
		}
	}

	public override void ResetAppearance()
	{
		try
		{
			((CardAppearanceBehaviour)this).Card.RenderInfo.expandedPortrait = false;
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("Failed resetting expanded portrait: " + ex));
		}
	}
}
[BepInPlugin("spapi.inscryption.configemissions", "Configurable Emissions", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	public const string GUID = "spapi.inscryption.configemissions";

	public const string NAME = "Configurable Emissions";

	public const string VERSION = "1.0.0";

	public void Awake()
	{
		CardAppearanceBehaviourManager.Add("spapi.inscryption.configemissions", "ConfigurableEmissionColor", typeof(ConfigurableEmission));
		CardAppearanceBehaviourManager.Add("spapi.inscryption.configemissions", "ConfigurableBackground", typeof(ConfigurableBackground));
		CardAppearanceBehaviourManager.Add("spapi.inscryption.configemissions", "ConfigurableStatColors", typeof(ConfigurableStatColors));
		CardAppearanceBehaviourManager.Add("spapi.inscryption.configemissions", "ExpandedPortrait", typeof(ExpandedPortrait));
	}
}