using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Pigeon.Movement;
using TMPro;
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: 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 StackUpgrades
{
[BepInPlugin("com.coloron.stackupgrades", "Stack Upgrades", "1.0.0")]
[MycoMod(/*Could not decode attribute arguments.*/)]
public class StackUpgrades : BaseUnityPlugin
{
public static UpgradeID? ExpandedID = null;
public static Dictionary<UpgradeID, List<UpgradeInstance>> Stacks = new Dictionary<UpgradeID, List<UpgradeInstance>>();
public static MethodInfo SetupUpgradesMethod;
public static FieldInfo InSkinModeField;
public static MethodInfo SoundPostMethod;
private void Awake()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
Harmony val = new Harmony("com.coloron.stackupgrades");
val.PatchAll();
SetupUpgradesMethod = typeof(GearDetailsWindow).GetMethod("SetupUpgrades", BindingFlags.Instance | BindingFlags.NonPublic);
InSkinModeField = typeof(GearDetailsWindow).GetField("inSkinMode", BindingFlags.Instance | BindingFlags.NonPublic);
((BaseUnityPlugin)this).Logger.LogInfo((object)"Stack Upgrades v1.0.0 loaded");
}
public static void RefreshWindow(GearDetailsWindow window)
{
if (!((Object)(object)window == (Object)null) && !(SetupUpgradesMethod == null))
{
bool flag = (bool)InSkinModeField.GetValue(window);
SetupUpgradesMethod.Invoke(window, new object[3] { window.UpgradablePrefab, flag, true });
window.SetUpgradeListScroll(1f);
}
}
}
public static class SoundHelper
{
private static object _cachedSoundObj;
private static MethodInfo _cachedPost;
public static void PlaySoundByName(string fieldName)
{
if ((Object)(object)Global.Instance == (Object)null || (Object)(object)PlayerLook.Instance == (Object)null)
{
return;
}
try
{
if (_cachedPost == null)
{
_cachedSoundObj = typeof(Global).GetField(fieldName, BindingFlags.Instance | BindingFlags.Public)?.GetValue(Global.Instance);
_cachedPost = _cachedSoundObj?.GetType().GetMethod("Post", new Type[1] { typeof(GameObject) });
}
_cachedPost?.Invoke(_cachedSoundObj, new object[1] { ((Component)PlayerLook.Instance).gameObject });
}
catch
{
}
}
}
[HarmonyPatch(typeof(GearDetailsWindow), "SetupUpgrades")]
public static class Patch_SetupUpgrades
{
private static void Prefix()
{
StackUpgrades.Stacks.Clear();
}
}
[HarmonyPatch(typeof(GearDetailsWindow), "AddUpgrade")]
public static class Patch_AddUpgrade
{
[HarmonyPrefix]
private static bool Prefix(UpgradeInstance upgrade, ref int index)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: 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)
if ((Object)(object)((upgrade != null) ? upgrade.Upgrade : null) == (Object)null)
{
return true;
}
UpgradeID iD = upgrade.Upgrade.ID;
if (!StackUpgrades.Stacks.TryGetValue(iD, out var value))
{
value = new List<UpgradeInstance>();
StackUpgrades.Stacks[iD] = value;
}
value.Add(upgrade);
if (StackUpgrades.ExpandedID.HasValue)
{
return iD == StackUpgrades.ExpandedID.Value;
}
return value.Count == 1;
}
}
[HarmonyPatch(typeof(GearUpgradeUI), "SetUpgrade", new Type[]
{
typeof(UpgradeInstance),
typeof(bool)
})]
public static class Patch_SetUpgrade
{
[HarmonyPostfix]
private static void Postfix(GearUpgradeUI __instance, UpgradeInstance upgrade)
{
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Expected O, but got Unknown
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: 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_00cb: 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_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)((upgrade != null) ? upgrade.Upgrade : null) == (Object)null))
{
TextMeshProUGUI val = null;
Transform val2 = ((Component)__instance).transform.Find("ModStackCount");
if ((Object)(object)val2 == (Object)null)
{
GameObject val3 = new GameObject("ModStackCount");
val3.transform.SetParent(((Component)__instance).transform, false);
val = val3.AddComponent<TextMeshProUGUI>();
((TMP_Text)val).fontSize = 16f;
((TMP_Text)val).alignment = (TextAlignmentOptions)1028;
((Graphic)val).color = Color.yellow;
((Graphic)val).raycastTarget = false;
((TMP_Text)val).fontStyle = (FontStyles)1;
RectTransform component = val3.GetComponent<RectTransform>();
component.anchorMin = Vector2.zero;
component.anchorMax = Vector2.one;
component.offsetMin = new Vector2(0f, 5f);
component.offsetMax = new Vector2(-5f, 0f);
}
else
{
val = ((Component)val2).GetComponent<TextMeshProUGUI>();
}
List<UpgradeInstance> value;
if (StackUpgrades.ExpandedID.HasValue && StackUpgrades.ExpandedID.Value == upgrade.Upgrade.ID)
{
((Behaviour)val).enabled = false;
}
else if (StackUpgrades.Stacks.TryGetValue(upgrade.Upgrade.ID, out value) && value.Count > 1)
{
((Behaviour)val).enabled = true;
((TMP_Text)val).text = "x" + value.Count;
}
else
{
((Behaviour)val).enabled = false;
}
}
}
}
[HarmonyPatch(typeof(GearDetailsWindow), "OnClickUp")]
public static class Patch_OnClickUp
{
[HarmonyPrefix]
private static void Prefix(GearDetailsWindow __instance)
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Expected O, but got Unknown
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)GearDetailsWindow.SelectedUpgrade != (Object)null)
{
return;
}
GearUpgradeUI val = default(GearUpgradeUI);
bool flag = UIRaycaster.RaycastForComponent<GearUpgradeUI>(ref val);
UpgradeEquipCell val2 = default(UpgradeEquipCell);
bool flag2 = UIRaycaster.RaycastForNearest<UpgradeEquipCell>((RectTransform)((Component)__instance).transform, ref val2);
if (flag2 && !flag)
{
object? obj = typeof(GearDetailsWindow).GetField("equipSlots", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(__instance);
ModuleEquipSlots val3 = (ModuleEquipSlots)((obj is ModuleEquipSlots) ? obj : null);
if (!((Object)(object)val3 != (Object)null))
{
return;
}
Node val4 = val3.HexMap[val2.X, val2.Y];
if (val4.enabled && val4.upgrade != null)
{
UpgradeID iD = val4.upgrade.Upgrade.ID;
if (!StackUpgrades.ExpandedID.HasValue || StackUpgrades.ExpandedID.Value != iD)
{
StackUpgrades.ExpandedID = iD;
StackUpgrades.RefreshWindow(__instance);
SoundHelper.PlaySoundByName("GridHoverSound");
}
}
}
else if (!flag && !flag2 && StackUpgrades.ExpandedID.HasValue)
{
StackUpgrades.ExpandedID = null;
StackUpgrades.RefreshWindow(__instance);
SoundHelper.PlaySoundByName("GridHoverSound");
}
}
}
[HarmonyPatch(typeof(GearDetailsWindow), "SelectUpgrade")]
public static class Patch_SelectUpgrade
{
[HarmonyPrefix]
private static bool Prefix(GearDetailsWindow __instance, GearUpgradeUI upgrade)
{
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: 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_0097: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)upgrade == (Object)null || ((HoverInfoUpgrade)upgrade).Upgrade == null)
{
return true;
}
if (((HoverInfoUpgrade)upgrade).Upgrade.IsEquipped(__instance.UpgradablePrefab))
{
return true;
}
UpgradeID iD = ((HoverInfoUpgrade)upgrade).Upgrade.Upgrade.ID;
if ((!StackUpgrades.ExpandedID.HasValue || StackUpgrades.ExpandedID.Value != iD) && StackUpgrades.Stacks.TryGetValue(iD, out var value) && value.Count > 1)
{
StackUpgrades.ExpandedID = iD;
StackUpgrades.RefreshWindow(__instance);
SoundHelper.PlaySoundByName("GridHoverSound");
return false;
}
return true;
}
}
[HarmonyPatch(typeof(GearDetailsWindow), "OnCloseCallback")]
public static class Patch_OnClose
{
private static void Postfix()
{
StackUpgrades.ExpandedID = null;
}
}
}