Decompiled source of FancyCardBar v1.3.4

FancyCardBar.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using ModdingUtils.Utils;
using TMPro;
using UnboundLib;
using UnboundLib.Extensions;
using UnboundLib.GameModes;
using UnboundLib.Utils.UI;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[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.7.1", FrameworkDisplayName = ".NET Framework 4.7.1")]
[assembly: AssemblyVersion("0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace FancyCardBar
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.rsmind.rounds.fancycardbar", "Fancy Card Bar", "1.3.4")]
	[BepInProcess("Rounds.exe")]
	public class FancyCardBar : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__10_0;

			public static UnityAction<bool> <>9__19_0;

			public static UnityAction<bool> <>9__19_1;

			internal void <Start>b__10_0()
			{
			}

			internal void <NewGUI>b__19_0(bool val)
			{
				modActive = val;
			}

			internal void <NewGUI>b__19_1(bool val)
			{
				genIcons = val;
			}
		}

		[CompilerGenerated]
		private sealed class <GameStart>d__11 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public IGameModeHandler gm;

			public FancyCardBar <>4__this;

			private List<Player>.Enumerator <>s__1;

			private Player <player>5__2;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <GameStart>d__11(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<player>5__2 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				if (<>1__state != 0)
				{
					return false;
				}
				<>1__state = -1;
				<>s__1 = PlayerManager.instance.players.GetEnumerator();
				try
				{
					while (<>s__1.MoveNext())
					{
						<player>5__2 = <>s__1.Current;
						if (PlayerExtensions.GetAdditionalData(<player>5__2).colorID == 165)
						{
							rsCardBar = CardBarUtils.instance.PlayersCardBar(<player>5__2.playerID);
						}
						<player>5__2 = null;
					}
				}
				finally
				{
					((IDisposable)<>s__1).Dispose();
				}
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private const string ModId = "com.rsmind.rounds.fancycardbar";

		private const string ModName = "Fancy Card Bar";

		private const string CompatibilityModName = "FancyCardBar";

		public const string Version = "1.3.4";

		public const string ModInitials = "FCB";

		public static bool Debug;

		internal static AssetBundle assets;

		internal static GameObject blankIcon;

		internal static GameObject rgbIcon;

		internal static CardBar rsCardBar;

		public static FancyCardBar instance { get; private set; }

		public static bool modActive
		{
			get
			{
				return PlayerPrefs.GetInt(GetConfigKey("modActive"), 1) == 1;
			}
			internal set
			{
				PlayerPrefs.SetInt(GetConfigKey("modActive"), value ? 1 : 0);
			}
		}

		public static bool genIcons
		{
			get
			{
				return PlayerPrefs.GetInt(GetConfigKey("genIcons"), 0) == 1;
			}
			internal set
			{
				PlayerPrefs.SetInt(GetConfigKey("genIcons"), value ? 1 : 0);
			}
		}

		private void Awake()
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			Unbound.RegisterClientSideMod("com.rsmind.rounds.fancycardbar");
			assets = AssetUtils.LoadAssetBundleFromResources("fancycardbar", typeof(FancyCardBar).Assembly);
			if ((Object)(object)assets == (Object)null)
			{
				Debug.Log((object)"Failed to load Fancy Card Bar asset bundle");
			}
			Harmony val = new Harmony("com.rsmind.rounds.fancycardbar");
			val.PatchAll();
		}

		private void Start()
		{
			//IL_0049: 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_0054: Expected O, but got Unknown
			instance = this;
			blankIcon = assets.LoadAsset<GameObject>("I_Template");
			rgbIcon = assets.LoadAsset<GameObject>("I_RGB");
			object obj = <>c.<>9__10_0;
			if (obj == null)
			{
				UnityAction val = delegate
				{
				};
				<>c.<>9__10_0 = val;
				obj = (object)val;
			}
			Unbound.RegisterMenu("Fancy Card Bar", (UnityAction)obj, (Action<GameObject>)NewGUI, (GameObject)null, false);
			GameModeManager.AddHook("GameStart", (Func<IGameModeHandler, IEnumerator>)GameStart);
		}

		[IteratorStateMachine(typeof(<GameStart>d__11))]
		private IEnumerator GameStart(IGameModeHandler gm)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <GameStart>d__11(0)
			{
				<>4__this = this,
				gm = gm
			};
		}

		internal static string GetConfigKey(string name)
		{
			return "FancyCardBar_" + name.ToLower();
		}

		private static void NewGUI(GameObject menu)
		{
			TextMeshProUGUI val2 = default(TextMeshProUGUI);
			MenuHandler.CreateText("Fancy Card Bar Options", menu, ref val2, 60, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
			MenuHandler.CreateText(" ", menu, ref val2, 30, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
			MenuHandler.CreateToggle(modActive, "Use Fancy Icons", menu, (UnityAction<bool>)delegate(bool val)
			{
				modActive = val;
			}, 60, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
			MenuHandler.CreateText(" ", menu, ref val2, 30, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
			MenuHandler.CreateToggle(genIcons, "Automatically Generate Card Icons", menu, (UnityAction<bool>)delegate(bool val)
			{
				genIcons = val;
			}, 60, true, (Color?)null, (TMP_FontAsset)null, (Material)null, (TextAlignmentOptions?)null);
		}
	}
	public class FancyIcon : MonoBehaviour
	{
		public GameObject fancyIcon;
	}
	public class RGBColorShift : MonoBehaviour
	{
		private static float hue;

		public Image image;

		private void Update()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			float num = default(float);
			float num2 = default(float);
			float num3 = default(float);
			Color.RGBToHSV(((Graphic)image).color, ref num, ref num2, ref num3);
			hue = Time.realtimeSinceStartup * 0.5f % 1f;
			((Graphic)image).color = Color.HSVToRGB(hue, num2, num3);
		}
	}
}
namespace FancyCardBar.Patches
{
	internal class FancyIconAdder
	{
		internal static void addIcon(CardBar __instance)
		{
			//IL_0048: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Expected O, but got Unknown
			//IL_00d2: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			GameObject gameObject = ((Component)((Component)__instance).transform.GetChild(((Component)__instance).transform.childCount - 1)).gameObject;
			GameObject val = null;
			if ((Object)(object)__instance == (Object)(object)FancyCardBar.rsCardBar)
			{
				val = Object.Instantiate<GameObject>(FancyCardBar.rgbIcon, gameObject.transform);
				val.transform.localScale = Vector3.one * (gameObject.GetComponent<RectTransform>().sizeDelta.x / 128f);
			}
			if (!FancyCardBar.modActive)
			{
				return;
			}
			FancyIcon component = ((Component)(CardInfo)ExtensionMethods.GetFieldValue((object)gameObject.GetComponent<CardBarButton>(), "card")).GetComponent<FancyIcon>();
			if (component != null)
			{
				GameObject fancyIcon = component.fancyIcon;
				if (fancyIcon != null)
				{
					GameObject val2 = Object.Instantiate<GameObject>(fancyIcon, gameObject.transform);
					val2.transform.localScale = Vector3.one * (gameObject.GetComponent<RectTransform>().sizeDelta.x / 128f);
					((Behaviour)gameObject.GetComponentInChildren<TextMeshProUGUI>()).enabled = false;
				}
			}
			else if (FancyCardBar.genIcons)
			{
				GameObject val3 = (GameObject)ExtensionMethods.GetFieldValue(ExtensionMethods.GetFieldValue((object)gameObject.GetComponent<CardBarButton>(), "card"), "cardArt");
				if (val3 != null)
				{
					GameObject val4 = Object.Instantiate<GameObject>(FancyCardBar.blankIcon, gameObject.transform);
					GameObject val5 = Object.Instantiate<GameObject>(val3, val4.transform);
					val5.transform.SetAsFirstSibling();
					val5.transform.localScale = new Vector3(0.15f, 0.15f, 0.15f);
					Animator[] components = val5.GetComponents<Animator>();
					Animator[] array = components;
					foreach (Animator val6 in array)
					{
						Object.Destroy((Object)(object)val6);
					}
					components = val5.GetComponentsInChildren<Animator>();
					Animator[] array2 = components;
					foreach (Animator val7 in array2)
					{
						Object.Destroy((Object)(object)val7);
					}
					val4.transform.localScale = Vector3.one * (gameObject.GetComponent<RectTransform>().sizeDelta.x / 128f);
					((Behaviour)gameObject.GetComponentInChildren<TextMeshProUGUI>()).enabled = false;
				}
			}
			if ((Object)(object)__instance == (Object)(object)FancyCardBar.rsCardBar)
			{
				val.transform.SetAsLastSibling();
			}
		}
	}
	[HarmonyPatch(typeof(CardBar), "AddCard")]
	internal class CardBarPatch
	{
		private static void Postfix(CardBar __instance)
		{
			FancyIconAdder.addIcon(__instance);
		}
	}
	[HarmonyPatch(typeof(Cards), "SilentAddToCardBar", new Type[]
	{
		typeof(int),
		typeof(CardInfo),
		typeof(string),
		typeof(float),
		typeof(float)
	})]
	internal class CardBarUtilsPatch
	{
		private static void Postfix(int playerID)
		{
			CardBar _instance = CardBarUtils.instance.PlayersCardBar(playerID);
			FancyIconAdder.addIcon(_instance);
		}
	}
	[HarmonyPatch(typeof(CardBarUtils), "SilentAddToCardBar", new Type[]
	{
		typeof(int),
		typeof(CardInfo),
		typeof(string)
	})]
	internal class CardBarUtilsPatch2
	{
		private static void Postfix(int playerID)
		{
			CardBar _instance = CardBarUtils.instance.PlayersCardBar(playerID);
			FancyIconAdder.addIcon(_instance);
		}
	}
	[Serializable]
	[HarmonyPatch(typeof(CardBarUtils))]
	internal class ModdingUtilsPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("ResetPlayersLineColor", new Type[] { typeof(int) })]
		public static bool FixResetPlayersLineColor(int playerID)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)CardBarUtils.instance.PlayersCardBar(playerID)).transform;
			for (int i = 1; i < transform.childCount; i++)
			{
				Transform child = transform.GetChild(i);
				((Component)child).GetComponent<Graphic>().color = new Color(0.462f, 0.462f, 0.462f, 1f);
				((Component)child.GetChild(1)).GetComponent<Graphic>().color = new Color(0.6509f, 0.6509f, 0.6509f, 1f);
			}
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("ChangePlayersLineColor", new Type[]
		{
			typeof(int),
			typeof(Color)
		})]
		public static bool FixChangePlayersLineColor(int playerID, Color color)
		{
			//IL_0025: 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)
			Transform transform = ((Component)CardBarUtils.instance.PlayersCardBar(playerID)).transform;
			for (int i = 1; i < transform.childCount; i++)
			{
				Transform child = transform.GetChild(i);
				((Component)child).GetComponent<Graphic>().color = color;
				((Component)child.GetChild(1)).GetComponent<Graphic>().color = color;
			}
			return false;
		}
	}
}