using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("favoriteItems")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("favoriteItems Mod")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+2ec0f263e8e765217ce364d2adc4574ba2a0483a")]
[assembly: AssemblyProduct("favoriteItems")]
[assembly: AssemblyTitle("favoriteItems")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 favoriteItems
{
[BepInPlugin("com.grizzyggs.FavoriteItems", "Favorite Items", "0.1.1")]
public class Main : BaseUnityPlugin
{
[HarmonyPatch(typeof(Humanoid), "IsItemEquiped")]
public static class Inventory_MoveItem_Patch
{
[HarmonyPatch(typeof(Container), "StackAll")]
public static class Container_StackAll_Patch
{
[HarmonyPrefix]
public static void Prefix()
{
logger.LogDebug((object)"Quick stacking now");
IsQuickStacking = true;
}
[HarmonyPostfix]
public static void Postfix()
{
logger.LogDebug((object)"No longer quick stacking");
IsQuickStacking = false;
}
}
[HarmonyPrefix]
public static bool Prefix(Inventory __instance, ItemData item, ref bool __result)
{
if (!IsQuickStacking)
{
return true;
}
if (item.m_customData.ContainsKey(FavoriteKey))
{
logger.LogDebug((object)("Item blocked from quick stacking: " + item.m_shared.m_name));
__result = true;
return false;
}
logger.LogDebug((object)("Item allowed to quick stack: " + item.m_shared.m_name));
return true;
}
}
[HarmonyPatch(typeof(InventoryGrid), "UpdateGui")]
public static class InventoryGrid_Patch
{
public static void Postfix(InventoryGrid __instance, Player player, ItemData dragItem)
{
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Expected O, but got Unknown
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: Unknown result type (might be due to invalid IL or missing references)
//IL_015e: 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_018c: Unknown result type (might be due to invalid IL or missing references)
foreach (Element element in __instance.m_elements)
{
if (!element.m_used)
{
continue;
}
bool flag = __instance.m_inventory.GetItemAt(element.m_pos.x, element.m_pos.y)?.m_customData.ContainsKey(FavoriteKey) ?? false;
Transform val = element.m_go.transform.Find("FavoriteText");
if (flag)
{
TextMeshProUGUI val3;
if ((Object)(object)val == (Object)null)
{
GameObject val2 = new GameObject("FavoriteText", new Type[1] { typeof(RectTransform) });
val2.transform.SetParent(element.m_go.transform, false);
val3 = val2.AddComponent<TextMeshProUGUI>();
if ((Object)(object)element.m_amount != (Object)null)
{
((TMP_Text)val3).font = element.m_amount.font;
((TMP_Text)val3).fontSize = element.m_amount.fontSize;
}
((Graphic)val3).color = Color.yellow;
((TMP_Text)val3).alignment = (TextAlignmentOptions)1028;
RectTransform component = val2.GetComponent<RectTransform>();
component.anchorMin = new Vector2(1f, 0f);
component.anchorMax = new Vector2(1f, 0f);
component.pivot = new Vector2(1f, 0f);
component.anchoredPosition = new Vector2(-2f, 2f);
}
else
{
val3 = ((Component)val).GetComponent<TextMeshProUGUI>();
((Component)val).gameObject.SetActive(true);
}
((TMP_Text)val3).text = "★";
}
else if ((Object)(object)val != (Object)null)
{
((Component)val).gameObject.SetActive(false);
}
}
}
}
private const string pluginGUID = "com.grizzyggs.FavoriteItems";
private const string pluginName = "Favorite Items";
private const string pluginVersion = "0.1.1";
private readonly Harmony HarmonyInstance = new Harmony("com.grizzyggs.FavoriteItems");
public static ManualLogSource logger = Logger.CreateLogSource("Favorite Items");
public static bool IsQuickStacking = false;
public static string FavoriteKey = "favoriteItems_favorite";
public static ItemData CurrentHoveredItem = null;
private ConfigEntry<bool> modEnabled;
private static ConfigEntry<KeyCode> favoriteKey;
public void Awake()
{
modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable or disable the Favorite Items mod.");
favoriteKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Settings", "FavoriteHotkey", (KeyCode)308, "Hotkey to toggle favorite status on hovered item.");
if (!modEnabled.Value)
{
logger.LogInfo((object)"Favorite Items mod is disabled in config. Exiting.");
return;
}
logger.LogInfo((object)"Loaded Favorite Items with config file");
Assembly executingAssembly = Assembly.GetExecutingAssembly();
HarmonyInstance.PatchAll(executingAssembly);
}
private void FixedUpdate()
{
getHoveredItem();
}
private void Update()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
if (Input.GetKeyDown(favoriteKey.Value) && CurrentHoveredItem != null)
{
logger.LogDebug((object)$"Attempting to toggle favorite status on item: {CurrentHoveredItem}");
if (CurrentHoveredItem.m_customData.ContainsKey(FavoriteKey))
{
CurrentHoveredItem.m_customData.Remove(FavoriteKey);
((BaseUnityPlugin)this).Logger.LogInfo((object)("Unfavorited: " + CurrentHoveredItem.m_shared.m_name));
}
else
{
CurrentHoveredItem.m_customData[FavoriteKey] = "true";
((BaseUnityPlugin)this).Logger.LogInfo((object)("Favorited: " + CurrentHoveredItem.m_shared.m_name));
}
}
}
private void getHoveredItem()
{
if ((Object)(object)InventoryGui.instance == (Object)null)
{
logger.LogDebug((object)"inventory is null");
return;
}
InventoryGrid playerGrid = InventoryGui.instance.m_playerGrid;
if ((Object)(object)playerGrid == (Object)null)
{
logger.LogDebug((object)"playergrid is null");
return;
}
Element hoveredElement = playerGrid.GetHoveredElement();
if (hoveredElement != null)
{
ItemData val = (CurrentHoveredItem = playerGrid.m_inventory.GetItemAt(hoveredElement.m_pos.x, hoveredElement.m_pos.y));
logger.LogDebug((object)("hovereditem: " + val.m_shared.m_name));
}
else
{
logger.LogDebug((object)"hoveredelement is null");
}
}
}
}