Decompiled source of RarityToggle v1.0.3

RarityMenu.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using RarityLib.Utils;
using TMPro;
using UnboundLib;
using UnboundLib.Networking;
using UnboundLib.Utils;
using UnboundLib.Utils.UI;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
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("RarityMenu")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+ca87bf44bf6f793133c0e5ff433ed98b9f64548c")]
[assembly: AssemblyProduct("RarityMenu")]
[assembly: AssemblyTitle("RarityMenu")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
		}
	}
}
namespace RarntyMenu
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("Rarity.Toggle", "Rarity Toggle", "1.0.3")]
	[BepInProcess("Rounds.exe")]
	public class RarityMenu : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Func<Card, CardInfo> <>9__14_0;

			public static Comparison<CardInfo> <>9__14_1;

			public static UnityAction<Scene, LoadSceneMode> <>9__22_2;

			public static Func<ConfigEntry<string>, string> <>9__23_0;

			public static Func<string, string> <>9__26_0;

			public static UnityAction <>9__26_1;

			internal CardInfo <get_allCards>b__14_0(Card v)
			{
				return v.cardInfo;
			}

			internal int <get_allCards>b__14_1(CardInfo c1, CardInfo c2)
			{
				return c1.cardName.CompareTo(c2.cardName);
			}

			internal void <Start>b__22_2(Scene r, LoadSceneMode d)
			{
				first = true;
			}

			internal string <OnHandShakeCompleted>b__23_0(ConfigEntry<string> c)
			{
				return c.Value;
			}

			internal string <NewGUI>b__26_0(string m)
			{
				if (!(m == "Vanilla"))
				{
					return "Z" + m;
				}
				return m;
			}

			internal void <NewGUI>b__26_1()
			{
			}
		}

		private const string ModId = "Rarity.Toggle";

		private const string ModName = "Rarity Toggle";

		public const string Version = "1.0.3";

		private bool ready;

		private int maxRarity = 2;

		private static bool first = true;

		public static Dictionary<string, ConfigEntry<string>> CardRaritys = new Dictionary<string, ConfigEntry<string>>();

		public static Dictionary<string, Rarity> CardDefaultRaritys = new Dictionary<string, Rarity>();

		public static Dictionary<string, TextMeshProUGUI> CardRaritysTexts = new Dictionary<string, TextMeshProUGUI>();

		public static Dictionary<string, List<CardInfo>> ModCards = new Dictionary<string, List<CardInfo>>();

		private static readonly Regex sanitizeRegex = new Regex("[\\n\\t\\\\\"'\\[\\]]+", RegexOptions.Compiled);

		internal static List<CardInfo> defaultCards => ((CardInfo[])typeof(CardManager).GetField("defaultCards", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null)).ToList();

		internal static List<CardInfo> activeCards => ((ObservableCollection<CardInfo>)typeof(CardManager).GetField("activeCards", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null)).ToList();

		internal static List<CardInfo> inactiveCards
		{
			get
			{
				return (List<CardInfo>)typeof(CardManager).GetField("inactiveCards", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
			}
			set
			{
			}
		}

		internal static List<CardInfo> allCards
		{
			get
			{
				List<CardInfo> list = CardManager.cards.Values.Select((Card v) => v.cardInfo).ToList();
				list.Sort((CardInfo c1, CardInfo c2) => c1.cardName.CompareTo(c2.cardName));
				return list;
			}
			set
			{
			}
		}

		public void Awake()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("Rarity.Toggle").PatchAll();
		}

		public void Start()
		{
			ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)Unbound.Instance, 60, (Action)delegate
			{
				//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
				//IL_010c: Unknown result type (might be due to invalid IL or missing references)
				//IL_010e: 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_00ef: Unknown result type (might be due to invalid IL or missing references)
				string text = "Vanilla";
				foreach (CardInfo card in allCards)
				{
					text = CardManager.cards.Values.First((Card c) => (Object)(object)c.cardInfo == (Object)(object)card).category;
					string text2 = SanitizeText(((Object)card).name);
					CardRaritys[text2] = ((BaseUnityPlugin)this).Config.Bind<string>("Rarity.Toggle", text2, "DEFAULT", "Rarity value of card " + card.cardName + " from " + text);
					CardDefaultRaritys[text2] = card.rarity;
					Rarity val = RarityUtils.GetRarity(CardRaritys[text2].Value);
					if ((int)val == 0 && CardRaritys[text2].Value != "Common")
					{
						val = CardDefaultRaritys[text2];
						CardRaritys[text2].Value = "DEFAULT";
					}
					card.rarity = val;
					if (!ModCards.ContainsKey(text))
					{
						ModCards.Add(text, new List<CardInfo>());
					}
					ModCards[text].Add(card);
				}
				maxRarity = Enum.GetValues(typeof(Rarity)).Length - 1;
				ready = true;
			});
			Unbound.RegisterMenu("Rarity Toggle", (UnityAction)null, (Action<GameObject>)delegate(GameObject menu)
			{
				((MonoBehaviour)Unbound.Instance).StartCoroutine(SetupGUI(menu));
			}, (GameObject)null, false);
			Unbound.RegisterHandshake("Rarity.Toggle", (Action)OnHandShakeCompleted);
			SceneManager.sceneLoaded += delegate
			{
				first = true;
			};
		}

		private void OnHandShakeCompleted()
		{
			if (PhotonNetwork.IsMasterClient)
			{
				NetworkingManager.RPC(typeof(RarityMenu), "SyncSettings", new object[2]
				{
					CardRaritys.Keys.ToArray(),
					CardRaritys.Values.Select((ConfigEntry<string> c) => c.Value).ToArray()
				});
			}
		}

		[UnboundRPC]
		private static void SyncSettings(string[] cards, string[] rarities)
		{
			if (first)
			{
				first = false;
				Dictionary<string, string> cardRarities = new Dictionary<string, string>();
				for (int i = 0; i < cards.Length; i++)
				{
					cardRarities[cards[i]] = rarities[i];
				}
				allCards.ForEach(delegate(CardInfo c)
				{
					//IL_0041: Unknown result type (might be due to invalid IL or missing references)
					//IL_0029: 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)
					c.rarity = ((cardRarities[((Object)c).name] != "DEFAULT") ? RarityUtils.GetRarity(cardRarities[((Object)c).name]) : CardDefaultRaritys[((Object)c).name]);
				});
			}
		}

		private IEnumerator SetupGUI(GameObject menu)
		{
			yield return (object)new WaitUntil((Func<bool>)(() => ready));
			yield return (object)new WaitForSecondsRealtime(0.1f);
			NewGUI(menu);
		}

		private void NewGUI(GameObject menu)
		{
			//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)
			//IL_0085: Expected O, but got Unknown
			TextMeshProUGUI val = default(TextMeshProUGUI);
			MenuHandler.CreateText("Rarity Toggle", menu, ref val, 60, false, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
			foreach (string item in ModCards.Keys.OrderBy((string m) => (!(m == "Vanilla")) ? ("Z" + m) : m))
			{
				object obj = <>c.<>9__26_1;
				if (obj == null)
				{
					UnityAction val2 = delegate
					{
					};
					<>c.<>9__26_1 = val2;
					obj = (object)val2;
				}
				ModGUI(MenuHandler.CreateMenu(item, (UnityAction)obj, menu, 60, true, true, ((Component)menu.transform.parent).gameObject, true, -1), item);
			}
		}

		private void ModGUI(GameObject menu, string mod)
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI val = default(TextMeshProUGUI);
			MenuHandler.CreateText(mod.ToUpper(), menu, ref val, 60, false, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
			foreach (CardInfo card in ModCards[mod])
			{
				string safeCardName = SanitizeText(((Object)card).name);
				MenuHandler.CreateText(card.cardName, menu, ref val, 30, true, (Color?)CardChoice.instance.GetCardColor(card.colorTheme), (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
				_ = RarityUtils.GetRarityData((CardRaritys[safeCardName].Value != "DEFAULT") ? RarityUtils.GetRarity(CardRaritys[safeCardName].Value) : CardDefaultRaritys[safeCardName]).colorOff;
				Dictionary<string, TextMeshProUGUI> cardRaritysTexts = CardRaritysTexts;
				string key = safeCardName;
				string value2 = CardRaritys[safeCardName].Value;
				float maxValue = maxRarity;
				float defaultValue = ((CardRaritys[safeCardName].Value == "DEFAULT") ? (-1) : ((int)RarityUtils.GetRarity(CardRaritys[safeCardName].Value)));
				UnityAction<float> onValueChangedAction = delegate(float value)
				{
					//IL_0093: Unknown result type (might be due to invalid IL or missing references)
					//IL_0077: 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_00e5: Unknown result type (might be due to invalid IL or missing references)
					//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
					//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
					//IL_0150: Unknown result type (might be due to invalid IL or missing references)
					if (value >= 0f)
					{
						CardRaritys[safeCardName].Value = RarityUtils.GetRarityData((Rarity)(int)value).name;
					}
					else
					{
						CardRaritys[safeCardName].Value = "DEFAULT";
					}
					card.rarity = ((CardRaritys[safeCardName].Value != "DEFAULT") ? RarityUtils.GetRarity(CardRaritys[safeCardName].Value) : CardDefaultRaritys[safeCardName]);
					try
					{
						_ = RarityUtils.GetRarityData((CardRaritys[safeCardName].Value != "DEFAULT") ? RarityUtils.GetRarity(CardRaritys[safeCardName].Value) : CardDefaultRaritys[safeCardName]).colorOff;
						((TMP_Text)CardRaritysTexts[safeCardName]).text = ((value >= 0f) ? ((object)(Rarity)(ref card.rarity)).ToString().ToUpper() : "DEFAULT");
						((Graphic)CardRaritysTexts[safeCardName]).color = GetCardRarityColor(card);
					}
					catch
					{
					}
				};
				Color? color = GetCardRarityColor(card);
				cardRaritysTexts[key] = CreateSliderWithoutInput(value2, menu, 30, -1f, maxValue, defaultValue, onValueChangedAction, out Slider _, wholeNumbers: true, null, (Direction)0, forceUpper: true, color).GetComponentsInChildren<TextMeshProUGUI>()[2];
			}
		}

		private Color GetCardRarityColor(CardInfo card)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			Color colorOff = RarityUtils.GetRarityData(card.rarity).colorOff;
			if (!((double)Mathf.Max(new float[3] { colorOff.r, colorOff.g, colorOff.b }) < 0.2))
			{
				return colorOff;
			}
			return Color.white;
		}

		private static GameObject CreateSliderWithoutInput(string text, GameObject parent, int fontSize, float minValue, float maxValue, float defaultValue, UnityAction<float> onValueChangedAction, out Slider slider, bool wholeNumbers = false, Color? sliderColor = null, Direction direction = 0, bool forceUpper = true, Color? color = null, TMP_FontAsset font = null, Material fontMaterial = null, TextAlignmentOptions? alignmentOptions = null)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = MenuHandler.CreateSlider(text, parent, fontSize, minValue, maxValue, defaultValue, onValueChangedAction, ref slider, wholeNumbers, sliderColor, direction, forceUpper, color, font, fontMaterial, alignmentOptions);
			Object.Destroy((Object)(object)((Component)obj.GetComponentInChildren<TMP_InputField>()).gameObject);
			return obj;
		}

		internal static string SanitizeText(string text)
		{
			return sanitizeRegex.Replace(text, "");
		}
	}
	[Serializable]
	[HarmonyPatch(typeof(ToggleCardsMenuHandler), "UpdateVisualsCardObj")]
	public class Patch
	{
		public static void Prefix(GameObject cardObject)
		{
			GameObject cardObject2 = cardObject;
			ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)Unbound.Instance, 15, (Action)delegate
			{
				//IL_008b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0074: Unknown result type (might be due to invalid IL or missing references)
				//IL_0090: Unknown result type (might be due to invalid IL or missing references)
				if (ToggleCardsMenuHandler.cardMenuCanvas.gameObject.activeSelf)
				{
					string key = RarityMenu.SanitizeText(((Object)cardObject2.GetComponentInChildren<CardInfo>()).name.Substring(0, ((Object)cardObject2.GetComponentInChildren<CardInfo>()).name.Length - 7));
					cardObject2.GetComponentInChildren<CardInfo>().rarity = ((RarityMenu.CardRaritys[key].Value != "DEFAULT") ? RarityUtils.GetRarity(RarityMenu.CardRaritys[key].Value) : RarityMenu.CardDefaultRaritys[key]);
					cardObject2.GetComponentsInChildren<CardRarityColor>().ToList().ForEach(delegate(CardRarityColor r)
					{
						r.Toggle(true);
					});
				}
			});
		}
	}
}