Decompiled source of TwoCards v1.0.0

TwoCards.dll

Decompiled an hour ago
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Panik;
using UnityEngine;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace TwoCards;

[BepInPlugin("cloverpit.twocards", "TwoCards", "1.0.0")]
public class TwoCardsPlugin : BaseUnityPlugin
{
	public const string GUID = "cloverpit.twocards";

	public const string NAME = "TwoCards";

	public const string VERSION = "1.0.0";

	internal static ManualLogSource Log;

	internal static ConfigEntry<bool> Enabled;

	internal static ConfigEntry<bool> ShowHud;

	internal static ConfigEntry<bool> BlockLeaderboard;

	private void Awake()
	{
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Expected O, but got Unknown
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Pick a second card at the start of each run. (Turning this off mid-run keeps an already-picked second card active.)");
		ShowHud = ((BaseUnityPlugin)this).Config.Bind<bool>("Visuals", "ShowCardsOnScreen", true, "Show your two cards in the bottom-left corner during a run, and a 'pick your 2nd card' banner in the deck box.");
		BlockLeaderboard = ((BaseUnityPlugin)this).Config.Bind<bool>("Leaderboard", "BlockLeaderboardUploads", true, "Don't upload to the leaderboard on runs where two cards are active.");
		Two.StateFile = Path.Combine(Paths.ConfigPath, "cloverpit.twocards.run.txt");
		int num = Patches.Apply(new Harmony("cloverpit.twocards"));
		Log.LogMessage((object)("TwoCards v1.0.0 loaded (" + num + " patches, " + Patches.CheckRewrites + " card checks now look at both cards)."));
		GameObject val = new GameObject("CloverPit_TwoCards");
		Object.DontDestroyOnLoad((Object)(object)val);
		((Object)val).hideFlags = (HideFlags)61;
		val.AddComponent<TwoCardsHud>();
	}
}
internal static class Two
{
	internal static int Second;

	internal static bool AwaitingSecond;

	internal static bool WinCredited;

	internal static bool HardcoreWinCredited;

	internal static bool CreditingNow;

	internal static string StateFile;

	internal static bool IsCard(int id)
	{
		return id > 0 && id < 27;
	}

	internal static int Primary()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Expected I4, but got Unknown
		try
		{
			return (int)GameplayData.RunModifier_GetCurrent();
		}
		catch
		{
			return 0;
		}
	}

	public static int Pick(int k)
	{
		int num = Primary();
		if (num == k)
		{
			return k;
		}
		if (IsCard(Second) && Second == k)
		{
			return k;
		}
		return num;
	}

	internal static bool Has(int k)
	{
		return Primary() == k || (IsCard(Second) && Second == k);
	}

	public static string CombinedTitle(Identifier id)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Invalid comparison between Unknown and I4
		string text = RunModifierScript.TitleGet(id);
		if ((int)id == Primary() && IsCard(Second))
		{
			text = text + " + " + RunModifierScript.TitleGet((Identifier)Second);
		}
		return text;
	}

	internal static int Seed()
	{
		try
		{
			return GameplayData.SeedGet();
		}
		catch
		{
			return 0;
		}
	}

	internal static void Persist()
	{
		try
		{
			File.WriteAllText(StateFile, "seed=" + Seed() + ";primary=" + Primary() + ";second=" + Second + ";win=" + (WinCredited ? 1 : 0) + ";hc=" + (HardcoreWinCredited ? 1 : 0));
		}
		catch (Exception ex)
		{
			TwoCardsPlugin.Log.LogWarning((object)("Couldn't save the second card: " + ex.Message));
		}
	}

	internal static void Restore(int loadedSeed, int loadedPrimary)
	{
		Second = 0;
		AwaitingSecond = false;
		WinCredited = (HardcoreWinCredited = false);
		try
		{
			if (StateFile == null || !File.Exists(StateFile))
			{
				return;
			}
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			string[] array = File.ReadAllText(StateFile).Split(';');
			foreach (string text in array)
			{
				string[] array2 = text.Split('=');
				if (array2.Length == 2 && int.TryParse(array2[1], out var result))
				{
					dictionary[array2[0].Trim()] = result;
				}
			}
			if (dictionary.TryGetValue("seed", out var value) && dictionary.TryGetValue("primary", out var value2) && dictionary.TryGetValue("second", out var value3) && value == loadedSeed && value2 == loadedPrimary && IsCard(value2) && IsCard(value3))
			{
				Second = value3;
				WinCredited = dictionary.TryGetValue("win", out var value4) && value4 == 1;
				HardcoreWinCredited = dictionary.TryGetValue("hc", out var value5) && value5 == 1;
				TwoCardsPlugin.Log.LogInfo((object)("Second card restored: " + (object)(Identifier)value3));
			}
		}
		catch (Exception ex)
		{
			TwoCardsPlugin.Log.LogWarning((object)("Couldn't read the second card: " + ex.Message));
		}
	}

	internal static void ApplySecond(Identifier id)
	{
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: 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_0045: 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)
		if (!GameplayMaster.IsCustomSeed())
		{
			GameData game = Data.game;
			game.RunModifier_PlayedTimes_Set(id, game.RunModifier_PlayedTimes_Get(id) + 1);
			if (game.DesiredFoilLevelGet(id) < 2 && game.RunModifier_FoilLevel_Get(id) < 2)
			{
				int num = game.RunModifier_OwnedCount_Get(id);
				if (num > 0)
				{
					num--;
				}
				game.RunModifier_OwnedCount_Set(id, num);
			}
		}
		RunModifierScript.OnRunModifierSet(id);
	}
}
internal static class Patches
{
	internal static int CheckRewrites;

	private static readonly string[][] CheckTargets = new string[26][]
	{
		new string[2] { "GameplayData", "InterestRateGet" },
		new string[2] { "GameplayData", "_GetDebtRoundDeadline_NextIncrement" },
		new string[2] { "GameplayData", "DebtGetExt" },
		new string[2] { "GameplayData", "SixSixSix_ChanceGet" },
		new string[2] { "GameplayData", "RedButtonActivationsMultiplierGet" },
		new string[2] { "GameplayData", "PhonePickMultiplierGet" },
		new string[2] { "GameplayData", "RunModifier_BonusPacksThisTime_Get" },
		new string[2] { "GameplayMaster", "CutscenePhaseBehaviour" },
		new string[2] { "GameplayMaster", "FCall_SlotMachineTurnOnTry" },
		new string[2] { "GameplayMaster", "_GotoGambling" },
		new string[2] { "GameplayMaster", "FCall_DebtNext" },
		new string[2] { "Strings", "Sanitize" },
		new string[2] { "AbilityScript", "CanBePicked" },
		new string[3] { "ATMScript", "DebtClearCoroutine", "iterator" },
		new string[2] { "PowerupScript", "IsBanned" },
		new string[2] { "RunModifierScript", "MFunc_LivingOnTheEdge_DontAllowDeposit" },
		new string[2] { "RunModifierScript", "MFunc_Consequences_CostGet" },
		new string[2] { "RunModifierScript", "MFunc_HerdMentality_CopyModChance" },
		new string[2] { "RunModifierScript", "MFunc_StuckInRoutine_IsActive" },
		new string[2] { "RunModifierScript", "MFunc_BrightOutsideDarkInside_IsActive" },
		new string[3] { "SlotMachineScript", "PatternsCompute_Coroutine", "iterator" },
		new string[2] { "StoreCapsuleScript", "PowerupDiscountGet" },
		new string[2] { "StoreCapsuleScript", "IsEnabled" },
		new string[2] { "StoreCapsuleScript", "Restock" },
		new string[3] { "SurgeryMachine", "SurgeryInProgress", "iterator" },
		new string[2] { "PhoneUiScript", "DefinePhoneStuff" }
	};

	internal static List<MethodBase> CheckMethods()
	{
		List<MethodBase> list = new List<MethodBase>();
		Assembly assembly = typeof(GameplayData).Assembly;
		string[][] checkTargets = CheckTargets;
		foreach (string[] array in checkTargets)
		{
			try
			{
				Type type = assembly.GetType(array[0]);
				MethodInfo methodInfo = ((!(type == null)) ? AccessTools.Method(type, array[1], (Type[])null, (Type[])null) : null);
				if (methodInfo != null && array.Length > 2)
				{
					methodInfo = AccessTools.EnumeratorMoveNext((MethodBase)methodInfo);
				}
				if (methodInfo == null)
				{
					TwoCardsPlugin.Log.LogWarning((object)("Card check not found (game updated?): " + array[0] + "." + array[1]));
				}
				else
				{
					list.Add(methodInfo);
				}
			}
			catch (Exception ex)
			{
				TwoCardsPlugin.Log.LogWarning((object)("Card check lookup failed for " + array[0] + "." + array[1] + ": " + ex.Message));
			}
		}
		return list;
	}

	internal static int Apply(Harmony h)
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Expected O, but got Unknown
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Expected O, but got Unknown
		int num = 0;
		foreach (MethodBase item in CheckMethods())
		{
			try
			{
				MethodBase methodBase = item;
				HarmonyMethod val = new HarmonyMethod(typeof(Patches), "Checks_Transpiler", (Type[])null);
				h.Patch(methodBase, (HarmonyMethod)null, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null);
				num++;
			}
			catch (Exception ex)
			{
				TwoCardsPlugin.Log.LogWarning((object)("Couldn't patch " + item.DeclaringType.Name + "." + item.Name + ": " + ex.Message));
			}
		}
		num += P(h, typeof(GameplayData), "RunModifier_AlreadyPicked", null, "AlreadyPicked_Postfix");
		num += P(h, typeof(GameplayData), "RunModifier_SetCurrent", "SetCurrent_Prefix", "SetCurrent_Postfix");
		num += P(h, typeof(DeckBoxUI), "CanPickCard", null, "CanPickCard_Postfix");
		num += P(h, typeof(RunModifierScript), "TriggerAnimation_IfEquipped", "TriggerAnim_Prefix", null);
		num += P(h, typeof(GameplayData), "Load_Format", null, "Load_Postfix");
		num += P(h, typeof(GameData), "RunModifier_WonTimes_Set", null, "WonTimes_Postfix");
		num += P(h, typeof(GameData), "RunModifier_WonTimesHARDCORE_Set", null, "WonTimesHardcore_Postfix");
		num += P(h, typeof(GameplayData), "SeedIsVerifiable", null, "Verifiable_Postfix");
		try
		{
			MethodInfo methodInfo = AccessTools.Method(typeof(StatsScript), "UpdateTextString", (Type[])null, (Type[])null);
			HarmonyMethod val = new HarmonyMethod(typeof(Patches), "StatsTitle_Transpiler", (Type[])null);
			h.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null);
			num++;
		}
		catch (Exception ex2)
		{
			TwoCardsPlugin.Log.LogWarning((object)("Stats screen patch skipped: " + ex2.Message));
		}
		return num;
	}

	private static int P(Harmony h, Type t, string method, string prefix, string postfix)
	{
		//IL_0051: 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)
		try
		{
			MethodInfo methodInfo = AccessTools.Method(t, method, (Type[])null, (Type[])null);
			if (methodInfo == null)
			{
				TwoCardsPlugin.Log.LogWarning((object)("Not found (game updated?): " + t.Name + "." + method));
				return 0;
			}
			h.Patch((MethodBase)methodInfo, (prefix == null) ? ((HarmonyMethod)null) : new HarmonyMethod(typeof(Patches), prefix, (Type[])null), (postfix == null) ? ((HarmonyMethod)null) : new HarmonyMethod(typeof(Patches), postfix, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			return 1;
		}
		catch (Exception ex)
		{
			TwoCardsPlugin.Log.LogWarning((object)("Couldn't patch " + t.Name + "." + method + ": " + ex.Message));
			return 0;
		}
	}

	private static bool IsLdcI4(CodeInstruction ci, out int k)
	{
		k = 0;
		OpCode opcode = ci.opcode;
		if (opcode == OpCodes.Ldc_I4_M1)
		{
			k = -1;
			return true;
		}
		if (opcode == OpCodes.Ldc_I4_0)
		{
			k = 0;
			return true;
		}
		if (opcode == OpCodes.Ldc_I4_1)
		{
			k = 1;
			return true;
		}
		if (opcode == OpCodes.Ldc_I4_2)
		{
			k = 2;
			return true;
		}
		if (opcode == OpCodes.Ldc_I4_3)
		{
			k = 3;
			return true;
		}
		if (opcode == OpCodes.Ldc_I4_4)
		{
			k = 4;
			return true;
		}
		if (opcode == OpCodes.Ldc_I4_5)
		{
			k = 5;
			return true;
		}
		if (opcode == OpCodes.Ldc_I4_6)
		{
			k = 6;
			return true;
		}
		if (opcode == OpCodes.Ldc_I4_7)
		{
			k = 7;
			return true;
		}
		if (opcode == OpCodes.Ldc_I4_8)
		{
			k = 8;
			return true;
		}
		if (opcode == OpCodes.Ldc_I4_S)
		{
			k = Convert.ToInt32(ci.operand);
			return true;
		}
		if (opcode == OpCodes.Ldc_I4)
		{
			k = Convert.ToInt32(ci.operand);
			return true;
		}
		return false;
	}

	private static bool IsCompare(CodeInstruction ci)
	{
		OpCode opcode = ci.opcode;
		return opcode == OpCodes.Beq || opcode == OpCodes.Beq_S || opcode == OpCodes.Bne_Un || opcode == OpCodes.Bne_Un_S || opcode == OpCodes.Ceq;
	}

	private static int StoreIndex(CodeInstruction ci)
	{
		OpCode opcode = ci.opcode;
		if (opcode == OpCodes.Stloc_0)
		{
			return 0;
		}
		if (opcode == OpCodes.Stloc_1)
		{
			return 1;
		}
		if (opcode == OpCodes.Stloc_2)
		{
			return 2;
		}
		if (opcode == OpCodes.Stloc_3)
		{
			return 3;
		}
		if (opcode == OpCodes.Stloc_S || opcode == OpCodes.Stloc)
		{
			if (ci.operand is LocalVariableInfo localVariableInfo)
			{
				return localVariableInfo.LocalIndex;
			}
			if (ci.operand is int)
			{
				return (int)ci.operand;
			}
			if (ci.operand is byte)
			{
				return (byte)ci.operand;
			}
		}
		return -1;
	}

	private static int LoadIndex(CodeInstruction ci)
	{
		OpCode opcode = ci.opcode;
		if (opcode == OpCodes.Ldloc_0)
		{
			return 0;
		}
		if (opcode == OpCodes.Ldloc_1)
		{
			return 1;
		}
		if (opcode == OpCodes.Ldloc_2)
		{
			return 2;
		}
		if (opcode == OpCodes.Ldloc_3)
		{
			return 3;
		}
		if (opcode == OpCodes.Ldloc_S || opcode == OpCodes.Ldloc)
		{
			if (ci.operand is LocalVariableInfo localVariableInfo)
			{
				return localVariableInfo.LocalIndex;
			}
			if (ci.operand is int)
			{
				return (int)ci.operand;
			}
			if (ci.operand is byte)
			{
				return (byte)ci.operand;
			}
		}
		return -1;
	}

	private static bool IsBranchOrTarget(CodeInstruction ci)
	{
		return ci.labels.Count > 0 || ci.opcode.FlowControl == FlowControl.Branch || ci.opcode.FlowControl == FlowControl.Cond_Branch || ci.opcode.FlowControl == FlowControl.Return || ci.opcode.FlowControl == FlowControl.Throw;
	}

	internal static IEnumerable<CodeInstruction> Checks_Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Expected O, but got Unknown
		//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02dd: Expected O, but got Unknown
		List<CodeInstruction> list = new List<CodeInstruction>(instructions);
		MethodInfo objB = AccessTools.Method(typeof(GameplayData), "RunModifier_GetCurrent", (Type[])null, (Type[])null);
		MethodInfo methodInfo = AccessTools.Method(typeof(Two), "Pick", (Type[])null, (Type[])null);
		for (int i = 0; i < list.Count - 1; i++)
		{
			if (!(list[i].opcode == OpCodes.Call) || !object.Equals(list[i].operand, objB))
			{
				continue;
			}
			CodeInstruction val = list[i + 1];
			int num = StoreIndex(val);
			int k;
			if (num >= 0)
			{
				for (int j = i + 2; j + 2 < list.Count; j++)
				{
					if (LoadIndex(list[j]) == num && IsLdcI4(list[j + 1], out k) && IsCompare(list[j + 2]))
					{
						list[j].opcode = OpCodes.Ldc_I4;
						list[j].operand = k;
						list.Insert(j + 1, new CodeInstruction(OpCodes.Call, (object)methodInfo));
						CheckRewrites++;
					}
				}
				continue;
			}
			if (val.opcode == OpCodes.Stfld)
			{
				FieldInfo objB2 = val.operand as FieldInfo;
				for (int l = i + 2; l + 3 < list.Count; l++)
				{
					if (list[l].opcode == OpCodes.Ldarg_0 && list[l + 1].opcode == OpCodes.Ldfld && object.Equals(list[l + 1].operand, objB2) && IsLdcI4(list[l + 2], out k) && IsCompare(list[l + 3]))
					{
						list[l].opcode = OpCodes.Ldc_I4;
						list[l].operand = k;
						list[l + 1].opcode = OpCodes.Call;
						list[l + 1].operand = methodInfo;
						CheckRewrites++;
					}
				}
				continue;
			}
			for (int m = i + 1; m + 1 < list.Count && m < i + 40 && !IsBranchOrTarget(list[m]); m++)
			{
				if (IsLdcI4(list[m], out k) && IsCompare(list[m + 1]))
				{
					list[i].opcode = OpCodes.Ldc_I4;
					list[i].operand = k;
					list.Insert(i + 1, new CodeInstruction(OpCodes.Call, (object)methodInfo));
					CheckRewrites++;
					break;
				}
			}
		}
		return list;
	}

	private static IEnumerable<CodeInstruction> StatsTitle_Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		List<CodeInstruction> list = new List<CodeInstruction>(instructions);
		MethodInfo objB = AccessTools.Method(typeof(GameplayData), "RunModifier_GetCurrent", (Type[])null, (Type[])null);
		MethodInfo objB2 = AccessTools.Method(typeof(RunModifierScript), "TitleGet", (Type[])null, (Type[])null);
		MethodInfo operand = AccessTools.Method(typeof(Two), "CombinedTitle", (Type[])null, (Type[])null);
		for (int i = 0; i + 1 < list.Count; i++)
		{
			if (list[i].opcode == OpCodes.Call && object.Equals(list[i].operand, objB) && list[i + 1].opcode == OpCodes.Call && object.Equals(list[i + 1].operand, objB2))
			{
				list[i + 1].operand = operand;
			}
		}
		return list;
	}

	private static void AlreadyPicked_Postfix(ref bool __result)
	{
		if (Two.AwaitingSecond)
		{
			__result = false;
		}
	}

	private static bool SetCurrent_Prefix(Identifier identifier, bool setByPlayer, out bool __state)
	{
		//IL_006c: 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_0020: Expected I4, but got Unknown
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		__state = false;
		if (!Two.AwaitingSecond || !setByPlayer)
		{
			return true;
		}
		__state = true;
		Two.AwaitingSecond = false;
		int num = (int)identifier;
		if (Two.IsCard(num) && num != Two.Primary())
		{
			Two.Second = num;
			try
			{
				Two.ApplySecond(identifier);
			}
			catch (Exception ex)
			{
				TwoCardsPlugin.Log.LogError((object)("Applying the second card failed: " + ex));
			}
			TwoCardsPlugin.Log.LogMessage((object)("Second card: " + identifier));
		}
		else
		{
			Two.Second = 0;
		}
		Two.Persist();
		return false;
	}

	private static void SetCurrent_Postfix(Identifier identifier, bool setByPlayer, bool __state)
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Expected I4, but got Unknown
		if (!__state)
		{
			Two.Second = 0;
			Two.WinCredited = (Two.HardcoreWinCredited = false);
			Two.AwaitingSecond = TwoCardsPlugin.Enabled.Value && setByPlayer && Two.IsCard((int)identifier);
			Two.Persist();
		}
	}

	private static void CanPickCard_Postfix(DeckBoxUI __instance, ref bool __result)
	{
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Invalid comparison between Unknown and I4
		if (!__result || !Two.AwaitingSecond)
		{
			return;
		}
		try
		{
			List<CardScript> list = (List<CardScript>)AccessTools.Field(typeof(DeckBoxUI), "_cardsList").GetValue(__instance);
			int num = (int)AccessTools.Field(typeof(DeckBoxUI), "cardNavigationIndex").GetValue(__instance);
			if (list != null && num >= 0 && num < list.Count && (int)list[num].identifier == Two.Primary())
			{
				__result = false;
			}
		}
		catch
		{
		}
	}

	private static bool TriggerAnim_Prefix(Identifier desiredRunModifier)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Expected I4, but got Unknown
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		if (Two.Has((int)desiredRunModifier))
		{
			RunModifierScript.TriggerAnimation(desiredRunModifier);
		}
		return false;
	}

	private static void Load_Postfix(GameplayData __instance)
	{
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Expected I4, but got Unknown
		int loadedSeed = 0;
		int loadedPrimary = 0;
		try
		{
			loadedSeed = (int)AccessTools.Field(typeof(GameplayData), "seed").GetValue(__instance);
			loadedPrimary = (int)(Identifier)AccessTools.Field(typeof(GameplayData), "runModifierPicked").GetValue(__instance);
		}
		catch
		{
		}
		Two.Restore(loadedSeed, loadedPrimary);
	}

	private static void WonTimes_Postfix(GameData __instance, Identifier identifier)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Invalid comparison between Unknown and I4
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		if (Two.CreditingNow || Two.WinCredited || !Two.IsCard(Two.Second) || (int)identifier != Two.Primary())
		{
			return;
		}
		Two.CreditingNow = true;
		try
		{
			Identifier val = (Identifier)Two.Second;
			__instance.RunModifier_WonTimes_Set(val, __instance.RunModifier_WonTimes_Get(val) + 1);
			Two.WinCredited = true;
			Two.Persist();
		}
		finally
		{
			Two.CreditingNow = false;
		}
	}

	private static void WonTimesHardcore_Postfix(GameData __instance, Identifier identifier)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Invalid comparison between Unknown and I4
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		if (Two.CreditingNow || Two.HardcoreWinCredited || !Two.IsCard(Two.Second) || (int)identifier != Two.Primary())
		{
			return;
		}
		Two.CreditingNow = true;
		try
		{
			Identifier val = (Identifier)Two.Second;
			__instance.RunModifier_WonTimesHARDCORE_Set(val, __instance.RunModifier_WonTimesHARDCORE_Get(val) + 1);
			Two.HardcoreWinCredited = true;
			Two.Persist();
		}
		finally
		{
			Two.CreditingNow = false;
		}
	}

	private static void Verifiable_Postfix(ref bool __result)
	{
		if (TwoCardsPlugin.BlockLeaderboard.Value && Two.IsCard(Two.Second))
		{
			__result = false;
		}
	}
}
public class TwoCardsHud : MonoBehaviour
{
	private static readonly Regex Tags = new Regex("<[^>]*>");

	private GUIStyle _banner;

	private GUIStyle _corner;

	private Texture2D _bg;

	private static string Title(int id)
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			return Tags.Replace(RunModifierScript.TitleGet((Identifier)id) ?? string.Empty, string.Empty).Trim();
		}
		catch
		{
			return ((object)(Identifier)id/*cast due to .constrained prefix*/).ToString();
		}
	}

	private void OnGUI()
	{
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_017a: 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_002c: Expected O, but got Unknown
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Expected O, but got Unknown
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Expected O, but got Unknown
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Expected O, but got Unknown
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_0292: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: 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_020f: Invalid comparison between Unknown and I4
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0251: Unknown result type (might be due to invalid IL or missing references)
		//IL_025b: Expected O, but got Unknown
		//IL_0256: Unknown result type (might be due to invalid IL or missing references)
		//IL_025b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0280: Unknown result type (might be due to invalid IL or missing references)
		//IL_0214: Unknown result type (might be due to invalid IL or missing references)
		//IL_0217: Invalid comparison between Unknown and I4
		//IL_021c: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: Invalid comparison between Unknown and I4
		try
		{
			if (!TwoCardsPlugin.ShowHud.Value)
			{
				return;
			}
			if (_banner == null)
			{
				_bg = new Texture2D(1, 1);
				_bg.SetPixel(0, 0, new Color(0.07f, 0.06f, 0.09f, 0.88f));
				_bg.Apply();
				((Object)_bg).hideFlags = (HideFlags)61;
				GUIStyle val = new GUIStyle(GUI.skin.box);
				val.fontSize = 22;
				val.alignment = (TextAnchor)4;
				val.fontStyle = (FontStyle)1;
				_banner = val;
				_banner.normal.background = _bg;
				_banner.normal.textColor = new Color(0.95f, 0.76f, 0.31f);
				val = new GUIStyle(GUI.skin.box);
				val.fontSize = 15;
				val.alignment = (TextAnchor)3;
				val.padding = new RectOffset(10, 10, 4, 4);
				_corner = val;
				_corner.normal.background = _bg;
				_corner.normal.textColor = new Color(0.93f, 0.91f, 0.86f);
			}
			float num = Mathf.Clamp((float)Screen.height / 1080f, 0.6f, 3f);
			Matrix4x4 matrix = GUI.matrix;
			GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(num, num, 1f));
			float num2 = (float)Screen.width / num;
			float num3 = (float)Screen.height / num;
			if (Two.AwaitingSecond && DeckBoxUI.IsPickingCard(true))
			{
				GUI.Box(new Rect((num2 - 640f) / 2f, 26f, 640f, 46f), "Pick your 2nd card  (" + Title(Two.Primary()) + " is your 1st)", _banner);
			}
			else if (Two.IsCard(Two.Second))
			{
				GamePhase gamePhase = GameplayMaster.GetGamePhase();
				if ((int)gamePhase == 3 || (int)gamePhase == 4 || (int)gamePhase == 5)
				{
					string text = "Cards: " + Title(Two.Primary()) + "  +  " + Title(Two.Second);
					Vector2 val2 = _corner.CalcSize(new GUIContent(text));
					GUI.Box(new Rect(14f, num3 - val2.y - 14f, val2.x, val2.y), text, _corner);
				}
			}
			GUI.matrix = matrix;
		}
		catch
		{
		}
	}
}