Decompiled source of UnlimitedTrinkets v1.0.0

UnlimitedTrinketsJ.dll

Decompiled 12 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.VisualScripting;
using UnityEngine;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("UnlimitedTrinketsJ")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("UnlimitedTrinketsJ")]
[assembly: AssemblyTitle("UnlimitedTrinketsJ")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 UnlimitedTrinketsJ
{
	[BepInPlugin("UnlimitedTrinketsJ", "UnlimitedTrinketsJ", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static ManualLogSource Logger;

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Harmony.CreateAndPatchAll(typeof(Patches), (string)null);
		}
	}
	public class Patches
	{
		[HarmonyPatch(typeof(UI_TrinketPicker), "SelectTrinket")]
		[HarmonyPrefix]
		[HarmonyWrapSafe]
		public static bool SelectTrinket(UI_TrinketPicker __instance, Trinket t)
		{
			__instance.ShowTrinketDescription(t);
			int num = 0;
			int num2 = 1;
			bool flag = __instance.selectedTrinkets.Any((Trinket x) => ((Object)x).name == ((Object)t).name);
			bool mouseButtonUp = Input.GetMouseButtonUp(1);
			if (flag && (mouseButtonUp || t.isBinding))
			{
				if (__instance.selectedTrinkets.Remove(t))
				{
					AudioManager.PlayUISound(t.isBinding ? __instance.bindingDeselectClip : __instance.trinketDeselectClip, 1f, 1f);
				}
			}
			else
			{
				AudioManager.PlayUISound(t.isBinding ? __instance.bindingSelectClip : __instance.trinketSelectClip, 1f, 1f);
			}
			foreach (Trinket selectedTrinket in __instance.selectedTrinkets)
			{
				if (!selectedTrinket.isBinding)
				{
					num += selectedTrinket.cost;
				}
				else
				{
					num2 += selectedTrinket.cost;
				}
			}
			if (!mouseButtonUp || (t.isBinding && !flag))
			{
				if (t.isBinding)
				{
					if (!flag)
					{
						num2 += t.cost;
						__instance.selectedTrinkets.Add(t);
					}
				}
				else
				{
					num += t.cost;
					__instance.selectedTrinkets.Add(t);
				}
			}
			((Selectable)__instance.playButton).interactable = true;
			__instance.costText.text = "";
			StatManager.saveData.SetGamemodeTrinkets(__instance.currentGamemode.GetGamemodeName(true), __instance.selectedTrinkets.Select((Trinket x) => ((Object)x).name).ToList());
			StatManager.saveData.SetSetting(__instance.currentGamemode.GetGamemodeName(true), "trinketsOvermax", num > num2);
			__instance.UpdateTrinketActivation();
			return false;
		}

		[HarmonyPatch(typeof(UI_TrinketPicker), "UpdateTrinketActivation")]
		[HarmonyTranspiler]
		[HarmonyWrapSafe]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			int num = -1;
			int num2 = -1;
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			for (int i = 0; i < list.Count; i++)
			{
				CodeInstruction val = list[i];
				if (num != -1 && num2 == -1 && val.opcode == OpCodes.Ldc_I4_0)
				{
					num2 = i;
					break;
				}
				if (((object)val).ToString() == "ldstr \"<color=\\\"red\\\">Too expensive!\"")
				{
					num = i;
				}
			}
			list[num].operand = "<color=\"yellow\">Leaderboards disabled.";
			list[num2].opcode = OpCodes.Ldc_I4_1;
			return list.AsEnumerable();
		}

		[HarmonyPatch(typeof(CL_GameManager), "Start")]
		[HarmonyPrefix]
		[HarmonyWrapSafe]
		public static void LeaderboardPatch(CL_GameManager __instance)
		{
			if (__instance.baseGamemode.HasActiveSetting("trinketsOvermax"))
			{
				CommandConsole.hasCheated = true;
				Plugin.Logger.LogMessage((object)"Run has overmax trinkets. Enabling cheats");
			}
		}

		[HarmonyPatch(typeof(UI_TrinketPicker_Icon), "SetTrinket")]
		[HarmonyPostfix]
		[HarmonyWrapSafe]
		private static void PatchSetTrinket(UI_TrinketPicker_Icon __instance, Trinket t, UI_TrinketPicker picker = null)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Expected O, but got Unknown
			//IL_0083: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)picker == (Object)null) && !t.isBinding)
			{
				RectTransform val = (RectTransform)((Component)__instance).transform.Find("CountText");
				if (!((Object)(object)val != (Object)null))
				{
					val = (RectTransform)Object.Instantiate<GameObject>(((Component)picker.costText).gameObject, ((Component)__instance).transform).transform;
					TMP_Text component = ((Component)val).GetComponent<TMP_Text>();
					((Object)val).name = "CountText";
					val.pivot = new Vector2(0f, 0f);
					val.anchoredPosition = new Vector2(0f, -64f);
					((Transform)val).SetSiblingIndex(3);
					component.margin = new Vector4(0f, 0f, 0f, 0f);
					component.text = "";
					((Graphic)component).color = Color.yellow;
					component.fontStyle = (FontStyles)1;
					component.fontSize = 16f;
					((Graphic)component).raycastTarget = false;
					component.alignment = (TextAlignmentOptions)1025;
					TrinketCountHandler trinketCountHandler = ComponentHolderProtocol.AddComponent<TrinketCountHandler>((Object)(object)val);
					trinketCountHandler.text = component;
					trinketCountHandler.parent = picker;
					trinketCountHandler.trinketName = ((Object)t).name;
				}
			}
		}
	}
	internal class TrinketCountHandler : MonoBehaviour
	{
		public TMP_Text text;

		public UI_TrinketPicker parent;

		public string trinketName;

		private void Update()
		{
			GameModeData gameMode = StatManager.saveData.GetGameMode(parent.currentGamemode.GetGamemodeName(true));
			if (gameMode != null)
			{
				int num = gameMode.activeTrinkets.Count((string x) => x == trinketName);
				if (num <= 1)
				{
					text.text = "";
				}
				else
				{
					text.text = $"{num}x";
				}
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "UnlimitedTrinketsJ";

		public const string PLUGIN_NAME = "UnlimitedTrinketsJ";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}