Decompiled source of Rarity Colour v0.2.0

RarityColour.dll

Decompiled 2 days ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Battle.Attacks;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Peglin.ClassSystem;
using PeglinUI.LoadoutManager;
using PeglinUI.PostBattle;
using Relics;
using Scenarios.Shop;
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("RarityColour")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Re-colours orb and relic offers to show their rarity")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyInformationalVersion("0.2+9a65881b50100107bac368e2842d9bdeaa3c260b")]
[assembly: AssemblyProduct("Relic Colour")]
[assembly: AssemblyTitle("RarityColour")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.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 RarityColour
{
	[BepInPlugin("com.mrphlip.peglin.RelicColour", "Relic Colour", "0.2")]
	[BepInProcess("Peglin.exe")]
	[HarmonyPatch]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("com.mrphlip.peglin.RelicColour");

		internal static ManualLogSource Logger;

		private static readonly ColorBlock COMMON = MakeColorBlock(0.5f, 0.25f, 0.25f);

		private static readonly ColorBlock COMMON_LV2 = MakeColorBlock(0.5f, 0.5f, 0.5f);

		private static readonly ColorBlock COMMON_LV3 = MakeColorBlock(0.9f, 0.55f, 0.3f);

		private static readonly ColorBlock UNCOMMON = MakeColorBlock(0.25f, 0.75f, 0.25f);

		private static readonly ColorBlock RARE = MakeColorBlock(0.25f, 0.25f, 0.75f);

		private static readonly ColorBlock BOSS = MakeColorBlock(0.75f, 0.25f, 0.75f);

		private static readonly ColorBlock SPECIAL = MakeColorBlock(0.75f, 0.5f, 0.25f);

		private static readonly Sprite ItemBackground1 = MakeSprite("ItemBackground1.png");

		private static readonly Sprite ItemBackground2 = MakeSprite("ItemBackground2.png");

		private static readonly Sprite ItemBackground3 = MakeSprite("ItemBackground3.png");

		private static readonly Sprite ItemBackgroundSold = MakeSprite("ItemBackgroundSold.png");

		private static readonly Sprite ShopBackground = MakeSprite("ShopBackground.png");

		private void Awake()
		{
			harmony.PatchAll();
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin com.mrphlip.peglin.RelicColour is loaded!");
		}

		private static ColorBlock MakeColorBlock(float r, float g, float b)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			ColorBlock result = default(ColorBlock);
			((ColorBlock)(ref result)).normalColor = new Color(r * 0.7f, g * 0.7f, b * 0.7f, 1f);
			((ColorBlock)(ref result)).highlightedColor = new Color(r, g, b, 1f);
			((ColorBlock)(ref result)).pressedColor = new Color(r, g, b, 1f);
			((ColorBlock)(ref result)).selectedColor = new Color(r * 0.95f, g * 0.95f, b * 0.95f, 1f);
			((ColorBlock)(ref result)).disabledColor = new Color(r * 0.8f, g * 0.8f, b * 0.8f, 1f);
			((ColorBlock)(ref result)).colorMultiplier = 1f;
			((ColorBlock)(ref result)).fadeDuration = 0.1f;
			return result;
		}

		private static byte[] GetAsset(string assetname)
		{
			Assembly assembly = typeof(Plugin).Assembly;
			string name = assembly.GetName().Name + ".assets." + assetname;
			Stream manifestResourceStream = assembly.GetManifestResourceStream(name);
			int num = (int)manifestResourceStream.Length;
			int i = 0;
			byte[] array = new byte[num];
			int num2;
			for (; i < num; i += num2)
			{
				num2 = manifestResourceStream.Read(array, i, num - i);
				if (num2 == 0)
				{
					break;
				}
			}
			return array;
		}

		private static Sprite MakeSprite(string assetname)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			ImageConversion.LoadImage(val, GetAsset(assetname));
			((Texture)val).filterMode = (FilterMode)0;
			((Texture)val).wrapMode = (TextureWrapMode)1;
			((Texture)val).wrapModeU = (TextureWrapMode)1;
			((Texture)val).wrapModeV = (TextureWrapMode)1;
			((Texture)val).wrapModeW = (TextureWrapMode)1;
			return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
		}

		private static (OrbRarity, int) GetOrbProps(GameObject orb)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			DeckManager[] array = Resources.FindObjectsOfTypeAll<DeckManager>();
			if (array.Length == 0)
			{
				Logger.LogError((object)"Couldn't find DeckManager!");
				return ((OrbRarity)1, 1);
			}
			DeckManager obj = array[0];
			Class val = (Class)typeof(DeckManager).GetField("_selectedClass", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(obj);
			OrbRarity val2 = (OrbRarity)typeof(DeckManager).GetMethod("GetFinalRarityForOrb", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(obj, new object[2] { orb, val });
			if ((int)val2 == 0)
			{
				val2 = orb.GetComponent<PachinkoBall>().orbRarity;
			}
			Attack component = orb.GetComponent<Attack>();
			int item = component.Level;
			if (component is AssemballAttack)
			{
				item = ((AssemballAttack)((component is AssemballAttack) ? component : null)).GetAssemballDisplayLevel();
			}
			return (val2, item);
		}

		private static ColorBlock GetOrbColour(OrbRarity rarity, int level)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected I4, but got Unknown
			//IL_0034: 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)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			switch ((int)rarity)
			{
			default:
				if (level <= 1)
				{
					return COMMON;
				}
				if (level == 2)
				{
					return COMMON_LV2;
				}
				return COMMON_LV3;
			case 2:
				return UNCOMMON;
			case 3:
				return RARE;
			case 4:
				return SPECIAL;
			}
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPostfix]
		private static void PatchOfferOrb(UpgradeOption __instance, GameObject value)
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			Button component = ((Component)__instance).gameObject.GetComponent<Button>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				Logger.LogError((object)("Couldn't find UnityEngine.UI.Button on " + ((Object)__instance).name + "!"));
				return;
			}
			Graphic targetGraphic = ((Selectable)component).targetGraphic;
			Image val = (Image)(object)((targetGraphic is Image) ? targetGraphic : null);
			if (!((Object)(object)val == (Object)null) && !(((Object)val).name != "OrbBackground"))
			{
				var (rarity, num) = GetOrbProps(value);
				((Selectable)component).colors = GetOrbColour(rarity, num);
				if (num <= 1)
				{
					val.sprite = ItemBackground1;
				}
				else if (num == 2)
				{
					val.sprite = ItemBackground2;
				}
				else if (num >= 3)
				{
					val.sprite = ItemBackground3;
				}
			}
		}

		[HarmonyPatch(typeof(UpgradeOption), "SetOptionInactive")]
		[HarmonyPostfix]
		private static void PatchPurchaseOrb(UpgradeOption __instance)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			Button component = ((Component)__instance).gameObject.GetComponent<Button>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				Logger.LogError((object)("Couldn't find UnityEngine.UI.Button on " + ((Object)__instance).name + "!"));
				return;
			}
			Graphic targetGraphic = ((Selectable)component).targetGraphic;
			Image val = (Image)(object)((targetGraphic is Image) ? targetGraphic : null);
			if (!((Object)(object)val == (Object)null) && !(((Object)val).name != "OrbBackground"))
			{
				val.sprite = ItemBackgroundSold;
				if (((Selectable)component).colors == COMMON_LV2 || ((Selectable)component).colors == COMMON_LV3)
				{
					((Selectable)component).colors = COMMON;
				}
			}
		}

		private static RelicRarity GetRelicRarity(Relic relic)
		{
			//IL_003b: 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)
			//IL_0073: 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_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Invalid comparison between Unknown and I4
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			RelicManager[] array = Resources.FindObjectsOfTypeAll<RelicManager>();
			if (array.Length == 0)
			{
				Logger.LogError((object)"Couldn't find RelicManager!");
				return (RelicRarity)1;
			}
			RelicManager obj = array[0];
			Class val = (Class)typeof(RelicManager).GetField("_selectedClass", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(obj);
			ClassLoadoutPairs[] array2 = (ClassLoadoutPairs[])typeof(RelicManager).GetField("_classLoadouts", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(obj);
			ClassLoadoutData val2 = null;
			for (int i = 0; i < array2.Length; i++)
			{
				if (array2[i].Class == val)
				{
					val2 = array2[i].Loadout;
					break;
				}
			}
			RelicRarity val3;
			if ((Object)(object)val2 != (Object)null)
			{
				val3 = (RelicRarity)typeof(RelicManager).GetMethod("GetFinalRarityForRelic", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(obj, new object[2] { relic, val2 });
				if ((int)val3 == 4)
				{
					val3 = relic.globalRarity;
				}
			}
			else
			{
				val3 = relic.globalRarity;
			}
			return val3;
		}

		private static ColorBlock GetRelicColor(RelicRarity rarity)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected I4, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			return (ColorBlock)((int)rarity switch
			{
				2 => RARE, 
				3 => BOSS, 
				0 => SPECIAL, 
				_ => COMMON, 
			});
		}

		[HarmonyPatch(typeof(RelicIcon), "SetRelic")]
		[HarmonyPostfix]
		private static void PatchOfferRelic(RelicIcon __instance, Relic r)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			Button componentInParent = ((Component)__instance).gameObject.GetComponentInParent<Button>();
			if (Object.op_Implicit((Object)(object)componentInParent))
			{
				RelicRarity relicRarity = GetRelicRarity(r);
				((Selectable)componentInParent).colors = GetRelicColor(relicRarity);
				Graphic targetGraphic = ((Selectable)componentInParent).targetGraphic;
				Image val = (Image)(object)((targetGraphic is Image) ? targetGraphic : null);
				if ((Object)(object)val != (Object)null)
				{
					val.sprite = ItemBackgroundSold;
				}
			}
		}

		[HarmonyPatch(typeof(ShopItem), "Initialize")]
		[HarmonyPostfix]
		private static void PatchShop(ShopItem __instance, IPurchasableItem item, ShopManager sm)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			PurchasableOrb val = (PurchasableOrb)(object)((item is PurchasableOrb) ? item : null);
			PurchasableRelic val2 = (PurchasableRelic)(object)((item is PurchasableRelic) ? item : null);
			Image component = __instance.itemBackground.GetComponent<Image>();
			ColorBlock val3;
			if (val != null)
			{
				OrbRarity item2 = GetOrbProps((GameObject)typeof(PurchasableOrb).GetField("_orbPrefab", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(val)).Item1;
				val3 = GetOrbColour(item2, 1);
				((Graphic)component).color = ((ColorBlock)(ref val3)).normalColor;
				component.sprite = ShopBackground;
			}
			else if (val2 != null)
			{
				RelicRarity relicRarity = GetRelicRarity((Relic)typeof(PurchasableRelic).GetField("_relic", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(val2));
				val3 = GetRelicColor(relicRarity);
				((Graphic)component).color = ((ColorBlock)(ref val3)).normalColor;
				component.sprite = ShopBackground;
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.mrphlip.peglin.RelicColour";

		public const string PLUGIN_NAME = "Relic Colour";

		public const string PLUGIN_VERSION = "0.2";
	}
}