using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
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 UnityEngine;
using UnityEngine.UIElements;
[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("StonewardsUndoRingSelection")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyInformationalVersion("0.1.1+792ac312b5d311683bf184ffd92f06899ca7f3bc")]
[assembly: AssemblyProduct("StonewardsUndoRingSelection")]
[assembly: AssemblyTitle("StonewardsUndoRingSelection")]
[assembly: AssemblyVersion("0.1.1.0")]
[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 StonewardsUndoRingSelection
{
[BepInPlugin("com.thereisnouser.stonewards.undoringselection", "Undo Ring Selection", "0.1.1")]
public sealed class UndoRingSelectionPlugin : BaseUnityPlugin
{
private sealed class PendingChoice
{
internal RogueLikeUpgradeMenu Menu;
internal object[] Args;
internal VisualElement Panel;
internal Label Description;
}
[HarmonyPatch]
private static class CardClickPatch
{
private static MethodBase TargetMethod()
{
return AccessTools.Method(AccessTools.Inner(typeof(UpgradePopupController), "UpgradeButton"), "OnClicked", new Type[1] { typeof(ClickEvent) }, (Type[])null);
}
private static bool Prefix(object __instance)
{
return InterceptCard(__instance);
}
}
[HarmonyPatch]
private static class CardSubmitPatch
{
private static MethodBase TargetMethod()
{
return AccessTools.Method(AccessTools.Inner(typeof(UpgradePopupController), "UpgradeButton"), "OnSubmitted", new Type[1] { typeof(NavigationSubmitEvent) }, (Type[])null);
}
private static bool Prefix(object __instance, NavigationSubmitEvent evt)
{
if (InterceptCard(__instance))
{
return true;
}
if (evt != null)
{
((EventBase)evt).StopPropagation();
}
return false;
}
}
[HarmonyPatch(typeof(RogueLikeUpgradeMenu), "OnUpgradeDraftGenerated")]
private static class DraftGeneratedPatch
{
private static void Postfix(RogueLikeUpgradeMenu __instance)
{
if (_pending != null && _pending.Menu == __instance)
{
Cancel();
}
}
}
[HarmonyPatch(typeof(UpgradePopupController), "Setup", new Type[] { typeof(List<UpgradeDraftChoice>) })]
private static class CardsSetupPatch
{
private static void Postfix()
{
Cancel();
}
}
[HarmonyPatch(typeof(BaseMenu), "Close")]
private static class MenuClosedPatch
{
private static void Postfix(BaseMenu __instance)
{
if (__instance is RogueLikeUpgradeMenu && _pending != null && (object)__instance == _pending.Menu)
{
Cancel();
}
}
}
public const string PluginGuid = "com.thereisnouser.stonewards.undoringselection";
public const string PluginName = "Undo Ring Selection";
public const string PluginVersion = "0.1.1";
private static UndoRingSelectionPlugin _plugin;
private static ConfigEntry<bool> _enabled;
private Harmony _harmony;
private static MethodInfo _onUpgradeClicked;
private static PendingChoice _pending;
private const int FrameTextureSize = 32;
private const int CornerSlice = 12;
private static Texture2D _windowFrame;
private static Texture2D _confirmFrame;
private static Texture2D _confirmHoverFrame;
private static Texture2D _cancelFrame;
private static Texture2D _cancelHoverFrame;
private static readonly Color FrameGold = new Color(0.72f, 0.64f, 0.48f, 1f);
private static readonly Color FrameHoverGold = new Color(0.97f, 0.85f, 0.6f, 1f);
private static readonly Color WindowBackground = new Color(0.07450981f, 0.09019608f, 0.1254902f, 0.98f);
private static readonly Color HeaderBackground = new Color(0.29803923f, 0.18039216f, 16f / 85f, 1f);
private void Awake()
{
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Expected O, but got Unknown
_plugin = this;
_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Confirm a manually clicked ring before the game's click animation/selection runs. Cancel or choose another ring.");
_onUpgradeClicked = AccessTools.Method(typeof(RogueLikeUpgradeMenu), "OnUpgradeClicked", (Type[])null, (Type[])null);
if (_onUpgradeClicked == null)
{
((BaseUnityPlugin)this).Logger.LogError((object)"RogueLikeUpgradeMenu.OnUpgradeClicked not found. Plugin disabled for this game version.");
return;
}
try
{
_harmony = new Harmony("com.thereisnouser.stonewards.undoringselection");
_harmony.PatchAll(typeof(UndoRingSelectionPlugin).Assembly);
ParameterInfo[] parameters = _onUpgradeClicked.GetParameters();
List<string> list = new List<string>();
ParameterInfo[] array = parameters;
foreach (ParameterInfo parameterInfo in array)
{
list.Add(parameterInfo.ParameterType.Name + " " + parameterInfo.Name);
}
((BaseUnityPlugin)this).Logger.LogInfo((object)("Undo Ring Selection 0.1.1 loaded. Native callback (" + string.Join(", ", list) + "); card clicks intercepted before PerformAction."));
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)("Failed to install ring-choice patches: " + ex));
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
}
private void OnDestroy()
{
Cancel();
DisposeFrameTextures();
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
private static bool Intercept(RogueLikeUpgradeMenu menu, object[] args)
{
if (_enabled == null || !_enabled.Value || (Object)(object)menu == (Object)null || menu.IsUpgradeSelected)
{
return true;
}
try
{
if (_pending != null && _pending.Menu != menu)
{
Cancel();
}
if (_pending == null)
{
_pending = new PendingChoice
{
Menu = menu
};
}
_pending.Args = ((args != null) ? ((object[])args.Clone()) : Array.Empty<object>());
EnsurePanel(_pending);
if (_pending.Description != null)
{
((TextElement)_pending.Description).text = "RING: " + DescribeSelection(menu, _pending.Args);
}
((BaseUnityPlugin)_plugin).Logger.LogDebug((object)("Ring click held for confirmation; args=" + _pending.Args.Length));
return false;
}
catch (Exception ex)
{
((BaseUnityPlugin)_plugin).Logger.LogError((object)("Ring confirmation failed; allowing vanilla click: " + ex));
Cancel();
return true;
}
}
private static void EnsurePanel(PendingChoice choice)
{
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Expected O, but got Unknown
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Expected O, but got Unknown
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_011c: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
//IL_014b: Unknown result type (might be due to invalid IL or missing references)
//IL_015b: Unknown result type (might be due to invalid IL or missing references)
//IL_0160: Unknown result type (might be due to invalid IL or missing references)
//IL_017c: Unknown result type (might be due to invalid IL or missing references)
//IL_0181: Unknown result type (might be due to invalid IL or missing references)
//IL_0189: Expected O, but got Unknown
//IL_0190: Unknown result type (might be due to invalid IL or missing references)
//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
//IL_01f9: 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_020f: Unknown result type (might be due to invalid IL or missing references)
//IL_0218: Expected O, but got Unknown
//IL_0220: Unknown result type (might be due to invalid IL or missing references)
//IL_0236: Unknown result type (might be due to invalid IL or missing references)
//IL_024c: Unknown result type (might be due to invalid IL or missing references)
//IL_0262: Unknown result type (might be due to invalid IL or missing references)
//IL_0278: Unknown result type (might be due to invalid IL or missing references)
//IL_0289: Unknown result type (might be due to invalid IL or missing references)
//IL_028e: Unknown result type (might be due to invalid IL or missing references)
//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
//IL_02ac: Expected O, but got Unknown
//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
//IL_02de: Unknown result type (might be due to invalid IL or missing references)
//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
//IL_030a: Unknown result type (might be due to invalid IL or missing references)
//IL_0320: Unknown result type (might be due to invalid IL or missing references)
//IL_0336: Unknown result type (might be due to invalid IL or missing references)
//IL_0348: Unknown result type (might be due to invalid IL or missing references)
//IL_036d: Unknown result type (might be due to invalid IL or missing references)
//IL_0372: Unknown result type (might be due to invalid IL or missing references)
//IL_0384: Unknown result type (might be due to invalid IL or missing references)
//IL_039b: Unknown result type (might be due to invalid IL or missing references)
//IL_03a2: Expected O, but got Unknown
//IL_03be: Unknown result type (might be due to invalid IL or missing references)
//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
//IL_0400: Unknown result type (might be due to invalid IL or missing references)
//IL_0416: Unknown result type (might be due to invalid IL or missing references)
//IL_042c: Unknown result type (might be due to invalid IL or missing references)
//IL_043e: Unknown result type (might be due to invalid IL or missing references)
//IL_0463: Unknown result type (might be due to invalid IL or missing references)
//IL_0468: Unknown result type (might be due to invalid IL or missing references)
//IL_047a: Unknown result type (might be due to invalid IL or missing references)
//IL_0491: Unknown result type (might be due to invalid IL or missing references)
//IL_0498: Expected O, but got Unknown
//IL_04a8: Unknown result type (might be due to invalid IL or missing references)
//IL_04be: Unknown result type (might be due to invalid IL or missing references)
//IL_04d4: Unknown result type (might be due to invalid IL or missing references)
//IL_04ea: Unknown result type (might be due to invalid IL or missing references)
//IL_0500: Unknown result type (might be due to invalid IL or missing references)
//IL_0516: Unknown result type (might be due to invalid IL or missing references)
//IL_0528: Unknown result type (might be due to invalid IL or missing references)
//IL_054d: Unknown result type (might be due to invalid IL or missing references)
//IL_0552: Unknown result type (might be due to invalid IL or missing references)
//IL_0564: Unknown result type (might be due to invalid IL or missing references)
//IL_0576: Unknown result type (might be due to invalid IL or missing references)
//IL_057d: Expected O, but got Unknown
//IL_0585: Unknown result type (might be due to invalid IL or missing references)
//IL_059b: Unknown result type (might be due to invalid IL or missing references)
//IL_05b1: Unknown result type (might be due to invalid IL or missing references)
//IL_05c7: Unknown result type (might be due to invalid IL or missing references)
//IL_05dd: Unknown result type (might be due to invalid IL or missing references)
//IL_05ef: Unknown result type (might be due to invalid IL or missing references)
//IL_0601: Unknown result type (might be due to invalid IL or missing references)
//IL_0613: Unknown result type (might be due to invalid IL or missing references)
if (choice.Panel == null || choice.Panel.parent == null)
{
VisualElement obj = choice.Menu.rogueLikeUpgradeScreen ?? throw new InvalidOperationException("rogueLikeUpgradeScreen is unavailable");
EnsureFrameTextures();
VisualElement val = new VisualElement
{
name = "stonewards-undo-ring-selection-anchor",
pickingMode = (PickingMode)1
};
val.style.position = StyleEnum<Position>.op_Implicit((Position)1);
val.style.left = StyleLength.op_Implicit(0f);
val.style.right = StyleLength.op_Implicit(0f);
val.style.bottom = StyleLength.op_Implicit(18f);
val.style.alignItems = StyleEnum<Align>.op_Implicit((Align)2);
val.style.justifyContent = StyleEnum<Justify>.op_Implicit((Justify)1);
VisualElement val2 = new VisualElement
{
name = "stonewards-undo-ring-selection-confirmation"
};
val2.style.position = StyleEnum<Position>.op_Implicit((Position)0);
val2.style.width = StyleLength.op_Implicit(680f);
val2.style.maxWidth = StyleLength.op_Implicit(Length.Percent(95f));
val2.style.height = StyleLength.op_Implicit(230f);
val2.style.flexShrink = StyleFloat.op_Implicit(1f);
val2.style.backgroundColor = StyleColor.op_Implicit(Color.clear);
ApplyPixelFrame(val2, _windowFrame);
val.Add(val2);
VisualElement val3 = new VisualElement
{
pickingMode = (PickingMode)1
};
val3.style.position = StyleEnum<Position>.op_Implicit((Position)1);
val3.style.left = StyleLength.op_Implicit(12f);
val3.style.right = StyleLength.op_Implicit(12f);
val3.style.top = StyleLength.op_Implicit(12f);
val3.style.height = StyleLength.op_Implicit(53f);
val3.style.backgroundColor = StyleColor.op_Implicit(HeaderBackground);
val2.Add(val3);
VisualElement val4 = new VisualElement
{
pickingMode = (PickingMode)1
};
val4.style.position = StyleEnum<Position>.op_Implicit((Position)1);
val4.style.left = StyleLength.op_Implicit(11f);
val4.style.right = StyleLength.op_Implicit(11f);
val4.style.top = StyleLength.op_Implicit(65f);
val4.style.height = StyleLength.op_Implicit(2f);
val4.style.backgroundColor = StyleColor.op_Implicit(FrameGold);
val2.Add(val4);
Label val5 = new Label("CONFIRM RING SELECTION");
((VisualElement)val5).name = "stonewards-ring-confirm-title";
((VisualElement)val5).pickingMode = (PickingMode)1;
((VisualElement)val5).style.position = StyleEnum<Position>.op_Implicit((Position)1);
((VisualElement)val5).style.left = StyleLength.op_Implicit(22f);
((VisualElement)val5).style.right = StyleLength.op_Implicit(22f);
((VisualElement)val5).style.top = StyleLength.op_Implicit(16f);
((VisualElement)val5).style.height = StyleLength.op_Implicit(44f);
((VisualElement)val5).style.fontSize = StyleLength.op_Implicit(25f);
((VisualElement)val5).style.unityFontStyleAndWeight = StyleEnum<FontStyle>.op_Implicit((FontStyle)1);
((VisualElement)val5).style.color = StyleColor.op_Implicit(new Color(1f, 0.88f, 0.66f, 1f));
((VisualElement)val5).style.unityTextAlign = StyleEnum<TextAnchor>.op_Implicit((TextAnchor)4);
val2.Add((VisualElement)(object)val5);
Label val6 = new Label("RING SELECTED");
((VisualElement)val6).name = "stonewards-ring-confirm-selected";
((VisualElement)val6).pickingMode = (PickingMode)1;
((VisualElement)val6).style.position = StyleEnum<Position>.op_Implicit((Position)1);
((VisualElement)val6).style.left = StyleLength.op_Implicit(28f);
((VisualElement)val6).style.right = StyleLength.op_Implicit(28f);
((VisualElement)val6).style.top = StyleLength.op_Implicit(81f);
((VisualElement)val6).style.height = StyleLength.op_Implicit(37f);
((VisualElement)val6).style.fontSize = StyleLength.op_Implicit(23f);
((VisualElement)val6).style.unityFontStyleAndWeight = StyleEnum<FontStyle>.op_Implicit((FontStyle)1);
((VisualElement)val6).style.color = StyleColor.op_Implicit(new Color(0.99f, 0.98f, 0.92f, 1f));
((VisualElement)val6).style.unityTextAlign = StyleEnum<TextAnchor>.op_Implicit((TextAnchor)4);
val2.Add((VisualElement)(object)val6);
Label val7 = new Label("CHOOSE ANOTHER RING OR CANCEL THIS PICK");
((VisualElement)val7).pickingMode = (PickingMode)1;
((VisualElement)val7).style.position = StyleEnum<Position>.op_Implicit((Position)1);
((VisualElement)val7).style.left = StyleLength.op_Implicit(25f);
((VisualElement)val7).style.right = StyleLength.op_Implicit(25f);
((VisualElement)val7).style.top = StyleLength.op_Implicit(124f);
((VisualElement)val7).style.height = StyleLength.op_Implicit(25f);
((VisualElement)val7).style.fontSize = StyleLength.op_Implicit(17f);
((VisualElement)val7).style.unityFontStyleAndWeight = StyleEnum<FontStyle>.op_Implicit((FontStyle)1);
((VisualElement)val7).style.color = StyleColor.op_Implicit(new Color(0.76f, 0.77f, 0.78f, 1f));
((VisualElement)val7).style.unityTextAlign = StyleEnum<TextAnchor>.op_Implicit((TextAnchor)4);
val2.Add((VisualElement)(object)val7);
VisualElement val8 = new VisualElement();
val8.style.position = StyleEnum<Position>.op_Implicit((Position)1);
val8.style.left = StyleLength.op_Implicit(14f);
val8.style.right = StyleLength.op_Implicit(14f);
val8.style.bottom = StyleLength.op_Implicit(15f);
val8.style.height = StyleLength.op_Implicit(53f);
val8.style.flexDirection = StyleEnum<FlexDirection>.op_Implicit((FlexDirection)2);
val8.style.alignItems = StyleEnum<Align>.op_Implicit((Align)2);
val8.style.justifyContent = StyleEnum<Justify>.op_Implicit((Justify)1);
val2.Add(val8);
Button val9 = CreateGameButton("CONFIRM", delegate
{
Confirm(choice.Menu);
}, _confirmFrame, _confirmHoverFrame);
Button val10 = CreateGameButton("CANCEL", Cancel, _cancelFrame, _cancelHoverFrame);
val8.Add((VisualElement)(object)val9);
val8.Add((VisualElement)(object)val10);
obj.Add(val);
choice.Panel = val;
choice.Description = val6;
}
}
private static Button CreateGameButton(string text, Action onClick, Texture2D normal, Texture2D hover)
{
//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_0027: Expected O, but got Unknown
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_011c: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: 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)
//IL_0166: Unknown result type (might be due to invalid IL or missing references)
//IL_017c: Unknown result type (might be due to invalid IL or missing references)
//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
Button button = new Button(onClick)
{
text = text
};
((VisualElement)button).RemoveFromClassList("unity-button");
((VisualElement)button).style.width = StyleLength.op_Implicit(216f);
((VisualElement)button).style.maxWidth = StyleLength.op_Implicit(Length.Percent(46f));
((VisualElement)button).style.height = StyleLength.op_Implicit(49f);
((VisualElement)button).style.marginLeft = StyleLength.op_Implicit(8f);
((VisualElement)button).style.marginRight = StyleLength.op_Implicit(8f);
((VisualElement)button).style.paddingLeft = StyleLength.op_Implicit(5f);
((VisualElement)button).style.paddingRight = StyleLength.op_Implicit(5f);
((VisualElement)button).style.paddingTop = StyleLength.op_Implicit(0f);
((VisualElement)button).style.paddingBottom = StyleLength.op_Implicit(0f);
((VisualElement)button).style.flexShrink = StyleFloat.op_Implicit(1f);
((VisualElement)button).style.fontSize = StyleLength.op_Implicit(22f);
((VisualElement)button).style.unityFontStyleAndWeight = StyleEnum<FontStyle>.op_Implicit((FontStyle)1);
((VisualElement)button).style.unityTextAlign = StyleEnum<TextAnchor>.op_Implicit((TextAnchor)4);
((VisualElement)button).style.color = StyleColor.op_Implicit(new Color(0.98f, 0.95f, 0.87f, 1f));
ApplyPixelFrame((VisualElement)(object)button, normal);
((CallbackEventHandler)button).RegisterCallback<PointerEnterEvent>((EventCallback<PointerEnterEvent>)delegate
{
//IL_0011: 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_003f: Unknown result type (might be due to invalid IL or missing references)
((VisualElement)button).style.backgroundImage = new StyleBackground(hover);
((VisualElement)button).style.color = StyleColor.op_Implicit(new Color(1f, 0.98f, 0.85f, 1f));
}, (TrickleDown)0);
((CallbackEventHandler)button).RegisterCallback<PointerLeaveEvent>((EventCallback<PointerLeaveEvent>)delegate
{
//IL_0011: 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_003f: Unknown result type (might be due to invalid IL or missing references)
((VisualElement)button).style.backgroundImage = new StyleBackground(normal);
((VisualElement)button).style.color = StyleColor.op_Implicit(new Color(0.98f, 0.95f, 0.87f, 1f));
}, (TrickleDown)0);
return button;
}
private static void ApplyPixelFrame(VisualElement element, Texture2D frame)
{
//IL_0006: 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_001c: 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_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: 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)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: 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)
element.style.backgroundColor = StyleColor.op_Implicit(Color.clear);
element.style.backgroundImage = new StyleBackground(frame);
element.style.unitySliceLeft = StyleInt.op_Implicit(12);
element.style.unitySliceRight = StyleInt.op_Implicit(12);
element.style.unitySliceTop = StyleInt.op_Implicit(12);
element.style.unitySliceBottom = StyleInt.op_Implicit(12);
element.style.borderTopWidth = StyleFloat.op_Implicit(0f);
element.style.borderBottomWidth = StyleFloat.op_Implicit(0f);
element.style.borderLeftWidth = StyleFloat.op_Implicit(0f);
element.style.borderRightWidth = StyleFloat.op_Implicit(0f);
element.style.borderTopLeftRadius = StyleLength.op_Implicit(0f);
element.style.borderTopRightRadius = StyleLength.op_Implicit(0f);
element.style.borderBottomLeftRadius = StyleLength.op_Implicit(0f);
element.style.borderBottomRightRadius = StyleLength.op_Implicit(0f);
}
private static void EnsureFrameTextures()
{
//IL_000e: 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_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_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_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)_windowFrame != (Object)null))
{
_windowFrame = CreateFrameTexture(WindowBackground, FrameGold, "UndoRingSelection_Window");
_confirmFrame = CreateFrameTexture(new Color(0.2f, 0.29f, 0.27f, 1f), FrameGold, "UndoRingSelection_Confirm");
_confirmHoverFrame = CreateFrameTexture(new Color(0.28f, 0.38f, 0.32f, 1f), FrameHoverGold, "UndoRingSelection_ConfirmHover");
_cancelFrame = CreateFrameTexture(new Color(0.28f, 0.23f, 0.27f, 1f), FrameGold, "UndoRingSelection_Cancel");
_cancelHoverFrame = CreateFrameTexture(new Color(0.38f, 0.28f, 0.33f, 1f), FrameHoverGold, "UndoRingSelection_CancelHover");
}
}
private static int StairInset(int distanceFromEdge)
{
if (distanceFromEdge < 2)
{
return 8;
}
if (distanceFromEdge < 4)
{
return 6;
}
if (distanceFromEdge < 6)
{
return 4;
}
if (distanceFromEdge < 8)
{
return 2;
}
return 0;
}
private static bool InsideStaircase(int x, int y)
{
if (x < 0 || y < 0 || x >= 32 || y >= 32)
{
return false;
}
int num = Mathf.Min(x, 31 - x);
int num2 = Mathf.Min(y, 31 - y);
if (num >= StairInset(num2))
{
return num2 >= StairInset(num);
}
return false;
}
private static Texture2D CreateFrameTexture(Color fill, Color edge, string name)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: 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_0096: Unknown result type (might be due to invalid IL or missing references)
Texture2D val = new Texture2D(32, 32, (TextureFormat)4, false);
((Object)val).name = name;
((Texture)val).filterMode = (FilterMode)0;
((Texture)val).wrapMode = (TextureWrapMode)1;
((Object)val).hideFlags = (HideFlags)61;
Color[] array = (Color[])(object)new Color[1024];
for (int i = 0; i < 32; i++)
{
for (int j = 0; j < 32; j++)
{
if (!InsideStaircase(j, i))
{
array[i * 32 + j] = Color.clear;
continue;
}
bool flag = InsideStaircase(j - 2, i) && InsideStaircase(j + 2, i) && InsideStaircase(j, i - 2) && InsideStaircase(j, i + 2);
array[i * 32 + j] = (flag ? fill : edge);
}
}
val.SetPixels(array);
val.Apply(false, true);
return val;
}
private static void DisposeFrameTextures()
{
Texture2D[] array = (Texture2D[])(object)new Texture2D[5] { _windowFrame, _confirmFrame, _confirmHoverFrame, _cancelFrame, _cancelHoverFrame };
foreach (Texture2D val in array)
{
if ((Object)(object)val != (Object)null)
{
Object.Destroy((Object)(object)val);
}
}
_windowFrame = null;
_confirmFrame = null;
_confirmHoverFrame = null;
_cancelFrame = null;
_cancelHoverFrame = null;
}
private static void Confirm(RogueLikeUpgradeMenu menu)
{
PendingChoice pending = _pending;
if (pending == null || pending.Menu != menu)
{
return;
}
try
{
_onUpgradeClicked.Invoke(menu, pending.Args);
((BaseUnityPlugin)_plugin).Logger.LogInfo((object)"Confirmed ring through native OnUpgradeClicked.");
Cancel();
}
catch (TargetInvocationException ex)
{
((BaseUnityPlugin)_plugin).Logger.LogError((object)("Vanilla ring selection threw: " + (ex.InnerException ?? ex)));
}
catch (Exception ex2)
{
((BaseUnityPlugin)_plugin).Logger.LogError((object)("Could not confirm selected ring: " + ex2));
}
}
private static void Cancel()
{
PendingChoice pending = _pending;
_pending = null;
if (pending?.Panel != null)
{
pending.Panel.RemoveFromHierarchy();
}
}
private static bool InterceptCard(object card)
{
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
if (_enabled == null || !_enabled.Value || card == null)
{
return true;
}
try
{
object obj = ReadMember(card, "_upgradeMenu");
RogueLikeUpgradeMenu val = (RogueLikeUpgradeMenu)((obj is RogueLikeUpgradeMenu) ? obj : null);
if ((Object)(object)val == (Object)null || !((BaseMenu)val).IsOpen || val.IsUpgradeSelected)
{
return true;
}
object obj2 = ReadMember(card, "isShowing");
bool flag = default(bool);
int num;
if (obj2 is bool)
{
flag = (bool)obj2;
num = 1;
}
else
{
num = 0;
}
if (((uint)num & (flag ? 1u : 0u)) != 0)
{
return true;
}
obj2 = ReadMember(card, "isHiding");
bool flag2 = default(bool);
int num2;
if (obj2 is bool)
{
flag2 = (bool)obj2;
num2 = 1;
}
else
{
num2 = 0;
}
if (((uint)num2 & (flag2 ? 1u : 0u)) != 0)
{
return true;
}
if (!(ReadMember(card, "DraftChoice") is UpgradeDraftChoice val2) || !((UpgradeDraftChoice)(ref val2)).IsValid)
{
return true;
}
return Intercept(val, new object[1] { val2 });
}
catch (Exception ex)
{
UndoRingSelectionPlugin plugin = _plugin;
if (plugin != null)
{
((BaseUnityPlugin)plugin).Logger.LogError((object)("Could not intercept native card click: " + ex));
}
return true;
}
}
private static string DescribeSelection(RogueLikeUpgradeMenu menu, object[] args)
{
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
if (args == null || args.Length == 0 || args[0] == null)
{
return "CURRENT CHOICE";
}
object obj = args[0];
string upgradeId = GetUpgradeId(obj);
int num = ((obj is int) ? ((int)obj) : (-1));
object? obj2 = AccessTools.Field(typeof(RogueLikeUpgradeMenu), "upgradePopupController")?.GetValue(menu);
UpgradePopupController val = (UpgradePopupController)((obj2 is UpgradePopupController) ? obj2 : null);
if (((val != null) ? val.UpgradeButtons : null) != null)
{
int num2 = 0;
foreach (UpgradeButton upgradeButton in val.UpgradeButtons)
{
if (upgradeButton == null)
{
num2++;
continue;
}
UpgradeDraftChoice draftChoice = upgradeButton.DraftChoice;
bool num3;
if (num < 0)
{
if (string.IsNullOrEmpty(upgradeId) || !((Object)(object)draftChoice.Upgrade != (Object)null))
{
goto IL_00f1;
}
num3 = string.Equals(((BaseUpgradeSO)draftChoice.Upgrade).ID, upgradeId, StringComparison.Ordinal);
}
else
{
num3 = num2 == num;
}
if (num3)
{
string text = FindNativeCardTitle(upgradeButton);
if (!string.IsNullOrWhiteSpace(text))
{
return TruncateTitle(text);
}
}
goto IL_00f1;
IL_00f1:
num2++;
}
}
object obj3 = ReadMember(obj, "Upgrade") ?? ReadMember(obj, "upgrade") ?? obj;
string[] array = new string[3] { "LocalizedName", "localizedName", "DisplayName" };
foreach (string name in array)
{
string text2 = ReadMember(obj3, name)?.ToString();
if (LooksLikeTitle(text2))
{
return TruncateTitle(text2);
}
}
array = new string[2] { "GetLocalizedName", "GetLocalizedTitle" };
foreach (string text3 in array)
{
try
{
string text4 = AccessTools.Method(obj3.GetType(), text3, Type.EmptyTypes, (Type[])null)?.Invoke(obj3, null)?.ToString();
if (LooksLikeTitle(text4))
{
return TruncateTitle(text4);
}
}
catch
{
}
}
string text5 = upgradeId ?? obj.ToString();
text5 = text5.Replace('_', ' ').Replace('-', ' ').Trim();
return TruncateTitle(CultureInfo.CurrentCulture.TextInfo.ToTitleCase(text5.ToLowerInvariant()));
}
private static string GetUpgradeId(object value)
{
if (value == null)
{
return null;
}
return ReadMember(ReadMember(value, "Upgrade") ?? ReadMember(value, "upgrade") ?? value, "ID")?.ToString();
}
private static string FindNativeCardTitle(object card)
{
if (card == null)
{
return null;
}
FieldInfo[] fields = card.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
FieldInfo[] array = fields;
foreach (FieldInfo fieldInfo in array)
{
if (typeof(Label).IsAssignableFrom(fieldInfo.FieldType) && (fieldInfo.Name.IndexOf("name", StringComparison.OrdinalIgnoreCase) >= 0 || fieldInfo.Name.IndexOf("title", StringComparison.OrdinalIgnoreCase) >= 0))
{
object? value = fieldInfo.GetValue(card);
object? obj = ((value is Label) ? value : null);
string text = CleanGameText((obj != null) ? ((TextElement)obj).text : null);
if (LooksLikeTitle(text))
{
return text;
}
}
}
array = fields;
foreach (FieldInfo fieldInfo2 in array)
{
if (typeof(VisualElement).IsAssignableFrom(fieldInfo2.FieldType))
{
object? value2 = fieldInfo2.GetValue(card);
string text2 = FindTitleInVisualTree((VisualElement)((value2 is VisualElement) ? value2 : null), 0);
if (LooksLikeTitle(text2))
{
return text2;
}
}
}
return null;
}
private static string FindTitleInVisualTree(VisualElement element, int depth)
{
if (element == null || depth > 12)
{
return null;
}
Label val = (Label)(object)((element is Label) ? element : null);
if (val != null)
{
string text = CleanGameText(((TextElement)val).text);
if (LooksLikeTitle(text))
{
return text;
}
}
for (int i = 0; i < element.childCount; i++)
{
string text2 = FindTitleInVisualTree(element[i], depth + 1);
if (LooksLikeTitle(text2))
{
return text2;
}
}
return null;
}
private static string CleanGameText(string value)
{
if (string.IsNullOrWhiteSpace(value))
{
return null;
}
return Regex.Replace(value, "<[^>]+>", "").Trim();
}
private static bool LooksLikeTitle(string value)
{
if (string.IsNullOrWhiteSpace(value))
{
return false;
}
value = CleanGameText(value);
if (!string.IsNullOrWhiteSpace(value) && value.Length <= 65)
{
switch (value)
{
default:
if (!value.Contains(":") && !value.Contains(">") && !value.Contains("%"))
{
if (value.Contains("_") || value == value.ToUpperInvariant())
{
return false;
}
return true;
}
break;
case "NEW":
case "Common":
case "Uncommon":
case "Rare":
case "Epic":
case "Legendary":
break;
}
}
return false;
}
private static string TruncateTitle(string title)
{
if (title.Length > 65)
{
return title.Substring(0, 62) + "...";
}
return title;
}
private static object ReadMember(object instance, string name)
{
if (instance == null)
{
return null;
}
Type type = instance.GetType();
try
{
return AccessTools.Field(type, name)?.GetValue(instance) ?? AccessTools.Property(type, name)?.GetValue(instance, null);
}
catch
{
return null;
}
}
}
}