using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;
[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("DSPAutoRecycle")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DSPAutoRecycle")]
[assembly: AssemblyTitle("DSPAutoRecycle")]
[assembly: AssemblyVersion("1.0.0.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 DSPAutoRecycle
{
[BepInPlugin("dsp.autorecycle", "DSP Auto Recycle", "1.0.0")]
public class AutoRecyclePlugin : BaseUnityPlugin
{
public const string Guid = "dsp.autorecycle";
public const string Name = "DSP Auto Recycle";
public const string Version = "1.0.0";
internal static ManualLogSource Log;
internal static AutoRecyclePlugin Instance;
internal static ConfigEntry<bool> Enabled;
internal static ConfigEntry<string> TrashItemsEntry;
internal static readonly List<int> Items = new List<int>();
private static readonly HashSet<int> ItemSet = new HashSet<int>();
private void Awake()
{
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
Instance = this;
Log = ((BaseUnityPlugin)this).Logger;
Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "是否启用自动删除");
TrashItemsEntry = ((BaseUnityPlugin)this).Config.Bind<string>("General", "TrashItems", "", "自动删除的物品 ID(逗号分隔),由界面自动维护,一般不需要手动修改");
Load();
Log.LogInfo((object)$"自动回收已加载,当前删除列表:{DescribeItems()}");
try
{
new Harmony("dsp.autorecycle").PatchAll(typeof(AutoRecyclePlugin).Assembly);
}
catch (Exception ex)
{
Log.LogError((object)("Harmony 补丁失败:" + ex));
}
}
internal static bool IsTrash(int itemId)
{
if (Enabled.Value)
{
return ItemSet.Contains(itemId);
}
return false;
}
internal static bool Add(int itemId)
{
if (itemId <= 0 || ItemSet.Contains(itemId))
{
return false;
}
Items.Add(itemId);
ItemSet.Add(itemId);
Save();
Log.LogInfo((object)("加入自动删除列表:" + DescribeItem(itemId)));
return true;
}
internal static void Remove(int itemId)
{
if (ItemSet.Remove(itemId))
{
Items.Remove(itemId);
Save();
Log.LogInfo((object)("移出自动删除列表:" + DescribeItem(itemId)));
}
}
internal static void Clear()
{
if (Items.Count != 0)
{
Items.Clear();
ItemSet.Clear();
Save();
}
}
private static void Load()
{
string value = TrashItemsEntry.Value;
if (string.IsNullOrEmpty(value))
{
return;
}
string[] array = value.Split(new char[3] { ',', ';', ' ' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < array.Length; i++)
{
if (int.TryParse(array[i], out var result) && result > 0 && ItemSet.Add(result))
{
Items.Add(result);
}
}
}
private static void Save()
{
try
{
TrashItemsEntry.Value = string.Join(",", Items.Select((int i) => i.ToString()).ToArray());
AutoRecyclePlugin instance = Instance;
if (instance != null)
{
((BaseUnityPlugin)instance).Config.Save();
}
}
catch (Exception ex)
{
Log.LogWarning((object)("保存配置失败:" + ex.Message));
}
}
internal static string DescribeItem(int itemId)
{
ItemProto val = (((Object)(object)LDB.items != (Object)null) ? ((ProtoSet<ItemProto>)(object)LDB.items).Select(itemId) : null);
if (val == null)
{
return "ID " + itemId;
}
return $"{Localization.Translate(((Proto)val).Name)}(ID {itemId})";
}
internal static string DescribeItems()
{
if (Items.Count == 0)
{
return "空";
}
return string.Join(",", Items.Select(DescribeItem).ToArray());
}
}
[HarmonyPatch(typeof(Player), "TryAddItemToPackage")]
internal static class PatchTryAddItemToPackage
{
private static void Postfix(Player __instance, int __0, ref int __result)
{
if (__result <= 0 || __instance == null || !AutoRecyclePlugin.IsTrash(__0))
{
return;
}
try
{
int num2 = default(int);
int num = __instance.package.TakeItem(__0, __result, ref num2);
if (num > 0)
{
AutoRecyclePlugin.Log.LogDebug((object)$"自动删除 {__0} x{num}");
}
}
catch (Exception ex)
{
AutoRecyclePlugin.Log.LogWarning((object)("自动删除物品失败:" + ex.Message));
}
}
}
[HarmonyPatch(typeof(UIInventoryWindow), "_OnOpen")]
internal static class PatchInventoryOpen
{
private static void Postfix(UIInventoryWindow __instance)
{
try
{
TrashPanel.Ensure(__instance);
}
catch (Exception ex)
{
AutoRecyclePlugin.Log.LogError((object)("创建自动删除面板失败:" + ex));
}
}
}
[HarmonyPatch(typeof(UIInventoryWindow), "_OnFree")]
internal static class PatchInventoryFree
{
private static void Postfix()
{
TrashPanel.DestroyInstance();
}
}
[HarmonyPatch(typeof(UIStorageGrid), "OnContentMouseUp")]
internal static class PatchStorageGridMouseUp
{
private static bool Prefix(BaseEventData __0)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
try
{
PointerEventData val = (PointerEventData)(object)((__0 is PointerEventData) ? __0 : null);
if (val != null && (int)val.button != 0)
{
return true;
}
TrashPanel instance = TrashPanel.Instance;
if ((Object)(object)instance != (Object)null && instance.TryConsumeDrop())
{
return false;
}
}
catch
{
}
return true;
}
}
internal sealed class TrashPanel : MonoBehaviour
{
private const int Cols = 4;
private const float SlotSize = 48f;
private const float SlotGap = 2f;
private const float Pad = 7f;
private const float Width = 212f;
private const float GapToGrid = 27f;
private const float AlignOffsetY = 32f;
private static readonly Color BoxFill = new Color(0.055f, 0.075f, 0.105f, 0.97f);
private static readonly Color BoxBorder = new Color(0.3f, 0.5f, 0.6f, 0.55f);
private static readonly Color SlotFill = new Color(0.075f, 0.105f, 0.135f, 0.95f);
private static readonly Color SlotFillFilled = new Color(0.1f, 0.17f, 0.23f, 0.98f);
private static readonly Color SlotBorder = new Color(0.3f, 0.5f, 0.6f, 0.35f);
private static readonly Color SlotBorderFilled = new Color(0.45f, 0.75f, 0.9f, 0.55f);
private static readonly Color SlotBorderHover = new Color(0.55f, 0.85f, 1f, 0.95f);
private static readonly Color TextMain = new Color(0.92f, 0.96f, 1f, 0.95f);
private static readonly Color TextSub = new Color(0.62f, 0.74f, 0.8f, 0.78f);
private static readonly Color ButtonFill = new Color(0.1f, 0.16f, 0.21f, 0.95f);
private static readonly Color ButtonBorder = new Color(0.32f, 0.52f, 0.62f, 0.5f);
private static TrashPanel _instance;
private UIInventoryWindow _window;
private RectTransform _rt;
private RectTransform _content;
private readonly List<Image> _icons = new List<Image>();
private readonly List<Image> _fills = new List<Image>();
private readonly List<Image> _borders = new List<Image>();
private Text _infoText;
private Text _toggleText;
private Font _font;
private Sprite _uiSprite;
private Image _boxFill;
private Image _boxBorder;
private int _rows = 6;
private float _height = 416f;
private int _dropFrame = -1;
private int _page;
private bool _collapsed;
private readonly List<GameObject> _bodyObjects = new List<GameObject>();
private GameObject _toggleRoot;
private GameObject _titleRoot;
private Text _collapseText;
private bool _visible = true;
internal static TrashPanel Instance => _instance;
private int PageSize => _rows * 4;
private int PageCount
{
get
{
int pageSize = PageSize;
if (pageSize <= 0)
{
return 1;
}
return Mathf.Max(1, (AutoRecyclePlugin.Items.Count + pageSize - 1) / pageSize);
}
}
internal static void Ensure(UIInventoryWindow window)
{
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)_instance != (Object)null)
{
if ((Object)(object)_instance._window == (Object)(object)window)
{
_instance.Refresh();
return;
}
Object.Destroy((Object)(object)((Component)_instance).gameObject);
_instance = null;
}
if (!((Object)(object)window == (Object)null) && !((Object)(object)window.windowTrans == (Object)null))
{
Transform val = (Transform)(((Object)(object)((Transform)window.windowTrans).parent != (Object)null) ? ((object)((Transform)window.windowTrans).parent) : ((object)window.windowTrans));
GameObject val2 = new GameObject("AutoRecyclePanel", new Type[1] { typeof(RectTransform) });
val2.transform.SetParent(val, false);
val2.AddComponent<TrashPanel>().Init(window);
}
}
internal static void DestroyInstance()
{
if ((Object)(object)_instance != (Object)null)
{
Object.Destroy((Object)(object)((Component)_instance).gameObject);
_instance = null;
}
}
private void Init(UIInventoryWindow window)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Expected O, but got Unknown
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: 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_00af: 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)
//IL_00cc: 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)
_instance = this;
_window = window;
_rt = (RectTransform)((Component)this).transform;
_rt.anchorMin = new Vector2(0.5f, 0.5f);
_rt.anchorMax = new Vector2(0.5f, 0.5f);
_rt.pivot = new Vector2(0f, 1f);
CollectStyle();
ComputeSize();
Build();
Refresh();
FollowWindow();
((Transform)_rt).SetAsFirstSibling();
ManualLogSource log = AutoRecyclePlugin.Log;
Rect rect = _window.windowTrans.rect;
object arg = ((Rect)(ref rect)).width;
rect = _window.windowTrans.rect;
log.LogInfo((object)$"自动删除框已创建:窗口 {arg:0}x{((Rect)(ref rect)).height:0},框体位置 {_rt.anchoredPosition}");
}
private void CollectStyle()
{
try
{
if ((Object)(object)_window.titleText != (Object)null)
{
_font = _window.titleText.font;
}
if ((Object)(object)_window.inventory != (Object)null && (Object)(object)_window.inventory.bgImage != (Object)null)
{
_uiSprite = _window.inventory.bgImage.sprite;
}
}
catch
{
}
if ((Object)(object)_font == (Object)null)
{
try
{
_font = Resources.GetBuiltinResource<Font>("Arial.ttf");
}
catch
{
_font = null;
}
}
}
private void ComputeSize()
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
float num;
if (!((Object)(object)_window.windowTrans != (Object)null))
{
num = 552f;
}
else
{
Rect rect = _window.windowTrans.rect;
num = ((Rect)(ref rect)).height;
}
int num2 = Mathf.FloorToInt((num - 176f) / 50f);
_rows = Mathf.Clamp(num2, 3, 6);
_height = (float)_rows * 50f + 116f;
}
private void Update()
{
if ((Object)(object)_window == (Object)null)
{
Object.Destroy((Object)(object)((Component)this).gameObject);
_instance = null;
return;
}
bool flag;
try
{
flag = ((Component)_window).gameObject.activeInHierarchy && ((ManualBehaviour)_window).active;
}
catch
{
flag = ((Component)_window).gameObject.activeInHierarchy;
}
if (flag != _visible)
{
_visible = flag;
if ((Object)(object)_content != (Object)null)
{
((Component)_content).gameObject.SetActive(flag);
}
if (flag)
{
((Transform)_rt).SetAsFirstSibling();
}
}
if (flag)
{
FollowWindow();
}
PollDrop();
}
private void FollowWindow()
{
//IL_0020: 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_01ea: Unknown result type (might be due to invalid IL or missing references)
//IL_018a: Unknown result type (might be due to invalid IL or missing references)
//IL_018f: Unknown result type (might be due to invalid IL or missing references)
//IL_019c: Unknown result type (might be due to invalid IL or missing references)
//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
try
{
RectTransform windowTrans = _window.windowTrans;
if ((Object)(object)windowTrans == (Object)null)
{
return;
}
float num = ((Mathf.Abs(((Transform)_rt).lossyScale.x) < 0.0001f) ? 1f : Mathf.Abs(((Transform)_rt).lossyScale.x));
Vector3[] array = (Vector3[])(object)new Vector3[4];
windowTrans.GetWorldCorners(array);
float x = array[2].x;
float num2 = array[2].y - 34f * num;
try
{
if ((Object)(object)_window.inventory != (Object)null && (Object)(object)_window.inventory.rectTrans != (Object)null)
{
Vector3[] array2 = (Vector3[])(object)new Vector3[4];
_window.inventory.rectTrans.GetWorldCorners(array2);
x = array2[2].x;
num2 = array2[2].y;
}
}
catch
{
}
Vector3 val = default(Vector3);
((Vector3)(ref val))..ctor(x + 27f * num, num2 + 32f * num, array[2].z);
UIRoot instance = UIRoot.instance;
if ((Object)(object)instance != (Object)null && (Object)(object)instance.overlayCanvas != (Object)null)
{
Transform transform = ((Component)instance.overlayCanvas).transform;
RectTransform val2 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
if ((Object)(object)val2 != (Object)null)
{
Vector3[] array3 = (Vector3[])(object)new Vector3[4];
val2.GetWorldCorners(array3);
float num3 = array3[2].x - 4f * num;
Rect rect = _rt.rect;
float num4 = ((Rect)(ref rect)).width * num;
float num5 = val.x + num4;
if (num5 > num3)
{
float num6 = num5 - num3;
((Transform)windowTrans).position = ((Transform)windowTrans).position - new Vector3(num6, 0f, 0f);
val.x -= num6;
}
}
}
((Transform)_rt).position = val;
}
catch
{
}
}
private void Build()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: 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_0089: 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_00af: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_0101: Unknown result type (might be due to invalid IL or missing references)
//IL_0132: Unknown result type (might be due to invalid IL or missing references)
//IL_0141: Unknown result type (might be due to invalid IL or missing references)
//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
//IL_01e5: 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_0466: Unknown result type (might be due to invalid IL or missing references)
//IL_0475: Unknown result type (might be due to invalid IL or missing references)
//IL_0485: Unknown result type (might be due to invalid IL or missing references)
//IL_04ad: Unknown result type (might be due to invalid IL or missing references)
//IL_04bc: Unknown result type (might be due to invalid IL or missing references)
//IL_04f2: Unknown result type (might be due to invalid IL or missing references)
//IL_0501: Unknown result type (might be due to invalid IL or missing references)
//IL_053b: Unknown result type (might be due to invalid IL or missing references)
//IL_054a: Unknown result type (might be due to invalid IL or missing references)
//IL_057a: Unknown result type (might be due to invalid IL or missing references)
//IL_0589: Unknown result type (might be due to invalid IL or missing references)
//IL_05bf: Unknown result type (might be due to invalid IL or missing references)
//IL_05ce: Unknown result type (might be due to invalid IL or missing references)
//IL_028c: Unknown result type (might be due to invalid IL or missing references)
//IL_029b: Unknown result type (might be due to invalid IL or missing references)
//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
//IL_02da: Unknown result type (might be due to invalid IL or missing references)
//IL_02df: Unknown result type (might be due to invalid IL or missing references)
//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
//IL_030f: Unknown result type (might be due to invalid IL or missing references)
//IL_0328: Unknown result type (might be due to invalid IL or missing references)
//IL_0341: Unknown result type (might be due to invalid IL or missing references)
//IL_0346: Unknown result type (might be due to invalid IL or missing references)
//IL_0361: Unknown result type (might be due to invalid IL or missing references)
//IL_0376: Unknown result type (might be due to invalid IL or missing references)
_rt.sizeDelta = new Vector2(212f, _height);
_content = NewRect("Content", _rt, Vector2.zero, new Vector2(212f, _height));
Stretch(_content);
RectTransform val = NewRect("BoxBorder", _content, Vector2.zero, Vector2.zero);
Stretch(val);
_boxBorder = ((Component)val).gameObject.AddComponent<Image>();
((Graphic)_boxBorder).color = BoxBorder;
((Graphic)_boxBorder).raycastTarget = true;
RectTransform val2 = NewRect("BoxFill", _content, Vector2.zero, Vector2.zero);
Stretch(val2);
val2.offsetMin = new Vector2(1f, 1f);
val2.offsetMax = new Vector2(-1f, -1f);
_boxFill = ((Component)val2).gameObject.AddComponent<Image>();
((Graphic)_boxFill).color = BoxFill;
((Graphic)_boxFill).raycastTarget = true;
Button val3 = NewButton("Collapse", _content, "-", new Vector2(3f, -3f), new Vector2(20f, 20f), OnCollapseClicked, body: false);
_collapseText = ((Component)((Component)val3).transform.parent).GetComponentInChildren<Text>(true);
Text val4 = NewText("Title", _content, "自动删除", 15, (TextAnchor)3);
_titleRoot = ((Component)val4).gameObject;
SetRect(((Graphic)val4).rectTransform, new Vector2(26f, -5f), new Vector2(120f, 24f));
((Graphic)val4).color = TextMain;
Button val5 = NewButton("Toggle", _content, "启用", new Vector2(149f, -6f), new Vector2(56f, 22f), OnToggleClicked, body: false);
_toggleRoot = ((Component)((Component)val5).transform.parent).gameObject;
_toggleText = _toggleRoot.GetComponentInChildren<Text>(true);
for (int i = 0; i < _rows; i++)
{
for (int j = 0; j < 4; j++)
{
int index = i * 4 + j;
float num = 7f + (float)j * 50f;
float num2 = -32f - (float)i * 50f;
RectTransform val6 = NewRect("Slot" + index, _content, new Vector2(num, num2), new Vector2(48f, 48f));
_bodyObjects.Add(((Component)val6).gameObject);
Image val7 = AddImage(val6, SlotBorder);
Stretch(((Graphic)val7).rectTransform);
RectTransform obj = NewRect("Fill", val6, Vector2.zero, Vector2.zero);
Stretch(obj);
obj.offsetMin = new Vector2(1f, 1f);
obj.offsetMax = new Vector2(-1f, -1f);
Image val8 = ((Component)obj).gameObject.AddComponent<Image>();
((Graphic)val8).color = SlotFill;
((Graphic)val8).raycastTarget = true;
RectTransform obj2 = NewRect("Icon", val6, Vector2.zero, Vector2.zero);
Stretch(obj2);
obj2.offsetMin = new Vector2(6f, 6f);
obj2.offsetMax = new Vector2(-6f, -6f);
Image val9 = ((Component)obj2).gameObject.AddComponent<Image>();
val9.preserveAspect = true;
((Graphic)val9).raycastTarget = false;
((Behaviour)val9).enabled = false;
SlotInteraction slotInteraction = ((Component)obj).gameObject.AddComponent<SlotInteraction>();
slotInteraction.Panel = this;
slotInteraction.Index = index;
_borders.Add(val7);
_fills.Add(val8);
_icons.Add(val9);
}
}
float num3 = -32f - (float)_rows * 50f;
_infoText = NewText("Info", _content, "", 11, (TextAnchor)3);
_bodyObjects.Add(((Component)_infoText).gameObject);
SetRect(((Graphic)_infoText).rectTransform, new Vector2(7f, num3 - 2f), new Vector2(146f, 18f));
((Graphic)_infoText).color = TextSub;
NewButton("PrevPage", _content, "<", new Vector2(155f, num3 - 1f), new Vector2(22f, 18f), PrevPage);
NewButton("NextPage", _content, ">", new Vector2(181f, num3 - 1f), new Vector2(22f, 18f), NextPage);
float num4 = num3 - 24f;
NewButton("Add", _content, "+ 添加", new Vector2(7f, num4), new Vector2(112f, 26f), OnAddClicked);
NewButton("Clear", _content, "清空", new Vector2(125f, num4), new Vector2(80f, 26f), OnClearClicked);
NewButton("CleanNow", _content, "清理背包现有物品", new Vector2(7f, num4 - 30f), new Vector2(198f, 26f), OnCleanClicked);
((Component)_boxFill).gameObject.AddComponent<ScrollPager>().Panel = this;
}
private void PollDrop()
{
try
{
if (Input.GetMouseButtonUp(0))
{
TryConsumeDrop();
}
}
catch (Exception ex)
{
AutoRecyclePlugin.Log.LogWarning((object)("处理拖入物品失败:" + ex.Message));
}
}
internal bool TryConsumeDrop()
{
try
{
if (_dropFrame == Time.frameCount)
{
return true;
}
Player mainPlayer = GameMain.mainPlayer;
if (mainPlayer == null || mainPlayer.inhandItemCount <= 0 || mainPlayer.inhandItemId <= 0)
{
return false;
}
if (!IsMouseOverPanel())
{
return false;
}
_dropFrame = Time.frameCount;
AcceptDroppedItem(mainPlayer.inhandItemId);
ConsumeHandItem(mainPlayer);
return true;
}
catch (Exception ex)
{
AutoRecyclePlugin.Log.LogWarning((object)("处理拖入物品失败:" + ex.Message));
return false;
}
}
private bool IsMouseOverPanel()
{
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)_rt == (Object)null || !((Component)_rt).gameObject.activeInHierarchy)
{
return false;
}
if ((Object)(object)_window != (Object)null && !((ManualBehaviour)_window).active)
{
return false;
}
if (_collapsed)
{
return false;
}
Canvas componentInParent = ((Component)_rt).GetComponentInParent<Canvas>();
Camera val = (((Object)(object)componentInParent != (Object)null && (int)componentInParent.renderMode != 0) ? componentInParent.worldCamera : null);
return RectTransformUtility.RectangleContainsScreenPoint(_rt, Vector2.op_Implicit(Input.mousePosition), val);
}
private void ConsumeHandItem(Player player)
{
player.SetHandItemId_Unsafe(0);
player.SetHandItemCount_Unsafe(0);
player.SetHandItemInc_Unsafe(0);
}
private void AcceptDroppedItem(int itemId)
{
if (AutoRecyclePlugin.Add(itemId))
{
_page = Mathf.Max(0, (AutoRecyclePlugin.Items.Count - 1) / PageSize);
UIRealtimeTip.Popup("已加入自动删除:" + AutoRecyclePlugin.DescribeItem(itemId), false, 0);
}
else
{
UIRealtimeTip.Popup("已在自动删除列表中:" + AutoRecyclePlugin.DescribeItem(itemId), false, 0);
}
Refresh();
}
internal void OnSlotClicked(int slotIndex)
{
if (!HasHandItem())
{
int num = _page * PageSize + slotIndex;
if (num < AutoRecyclePlugin.Items.Count)
{
AutoRecyclePlugin.Remove(AutoRecyclePlugin.Items[num]);
Refresh();
}
else
{
OpenPicker();
}
}
}
internal void OnSlotHover(int slotIndex, bool enter)
{
//IL_0045: 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)
//IL_006f: 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_0061: Unknown result type (might be due to invalid IL or missing references)
if (slotIndex >= 0 && slotIndex < _fills.Count)
{
bool flag = _page * PageSize + slotIndex < AutoRecyclePlugin.Items.Count;
((Graphic)_fills[slotIndex]).color = (flag ? SlotFillFilled : SlotFill);
((Graphic)_borders[slotIndex]).color = (enter ? SlotBorderHover : (flag ? SlotBorderFilled : SlotBorder));
}
}
internal void PrevPage()
{
if (!HasHandItem() && _page > 0)
{
_page--;
Refresh();
}
}
internal void NextPage()
{
if (!HasHandItem() && _page < PageCount - 1)
{
_page++;
Refresh();
}
}
internal void ScrollPage(float delta)
{
if (!HasHandItem())
{
if (delta > 0f)
{
NextPage();
}
else if (delta < 0f)
{
PrevPage();
}
}
}
private void OnAddClicked()
{
if (!HasHandItem())
{
OpenPicker();
}
}
private void OnToggleClicked()
{
if (HasHandItem())
{
return;
}
AutoRecyclePlugin.Enabled.Value = !AutoRecyclePlugin.Enabled.Value;
try
{
AutoRecyclePlugin instance = AutoRecyclePlugin.Instance;
if (instance != null)
{
((BaseUnityPlugin)instance).Config.Save();
}
}
catch
{
}
AutoRecyclePlugin.Log.LogInfo((object)("自动删除:" + (AutoRecyclePlugin.Enabled.Value ? "已启用" : "已暂停")));
Refresh();
}
private void OnCollapseClicked()
{
if (!HasHandItem())
{
_collapsed = !_collapsed;
ApplyCollapsed();
}
}
private void ApplyCollapsed()
{
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
foreach (GameObject bodyObject in _bodyObjects)
{
if ((Object)(object)bodyObject != (Object)null)
{
bodyObject.SetActive(!_collapsed);
}
}
if ((Object)(object)_toggleRoot != (Object)null)
{
_toggleRoot.SetActive(!_collapsed);
}
if ((Object)(object)_titleRoot != (Object)null)
{
_titleRoot.SetActive(!_collapsed);
}
if ((Object)(object)_collapseText != (Object)null)
{
_collapseText.text = (_collapsed ? "+" : "-");
}
_rt.sizeDelta = (_collapsed ? new Vector2(26f, 26f) : new Vector2(212f, _height));
if (!_collapsed)
{
Refresh();
}
}
private void OnClearClicked()
{
if (!HasHandItem())
{
AutoRecyclePlugin.Clear();
Refresh();
}
}
private void OnCleanClicked()
{
if (!HasHandItem())
{
CleanInventory();
}
}
private static bool HasHandItem()
{
Player mainPlayer = GameMain.mainPlayer;
if (mainPlayer != null)
{
return mainPlayer.inhandItemCount > 0;
}
return false;
}
private void OpenPicker()
{
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
try
{
UIRoot instance = UIRoot.instance;
if (!((Object)(object)instance == (Object)null) && !((Object)(object)instance.uiGame == (Object)null) && !((Object)(object)instance.uiGame.itemPicker == (Object)null))
{
if (UIItemPicker.isOpened)
{
UIItemPicker.Close();
}
UIItemPicker.showAll = true;
UIItemPicker.Popup(_rt.anchoredPosition + new Vector2(224f, -40f), (Action<ItemProto>)OnItemPicked);
}
}
catch (Exception ex)
{
AutoRecyclePlugin.Log.LogError((object)("打开物品选择器失败:" + ex));
}
}
private void OnItemPicked(ItemProto item)
{
if (item != null)
{
AutoRecyclePlugin.Add(((Proto)item).ID);
_page = Mathf.Max(0, (AutoRecyclePlugin.Items.Count - 1) / PageSize);
Refresh();
}
}
private void CleanInventory()
{
try
{
Player val = ((_window.player != null) ? _window.player : GameMain.mainPlayer);
if (val == null || val.package == null)
{
return;
}
int num = 0;
int num2 = default(int);
foreach (int item in new List<int>(AutoRecyclePlugin.Items))
{
int itemCount = val.package.GetItemCount(item);
if (itemCount > 0)
{
num += val.package.TakeItem(item, itemCount, ref num2);
}
}
if (num > 0)
{
UIRealtimeTip.Popup($"已清理 {num} 个物品", false, 0);
}
}
catch (Exception ex)
{
AutoRecyclePlugin.Log.LogWarning((object)("清理背包失败:" + ex.Message));
}
}
internal void Refresh()
{
//IL_0120: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
int pageSize = PageSize;
int pageCount = PageCount;
if (_page < 0)
{
_page = 0;
}
if (_page > pageCount - 1)
{
_page = pageCount - 1;
}
int num = _page * pageSize;
for (int i = 0; i < _icons.Count; i++)
{
int num2 = num + i;
if (num2 < AutoRecyclePlugin.Items.Count)
{
int num3 = AutoRecyclePlugin.Items[num2];
ItemProto val = (((Object)(object)LDB.items != (Object)null) ? ((ProtoSet<ItemProto>)(object)LDB.items).Select(num3) : null);
Sprite val2 = ((val != null) ? val.iconSprite : null);
_icons[i].sprite = val2;
((Behaviour)_icons[i]).enabled = (Object)(object)val2 != (Object)null;
((Graphic)_fills[i]).color = SlotFillFilled;
((Graphic)_borders[i]).color = SlotBorderFilled;
}
else
{
_icons[i].sprite = null;
((Behaviour)_icons[i]).enabled = false;
((Graphic)_fills[i]).color = SlotFill;
((Graphic)_borders[i]).color = SlotBorder;
}
}
if ((Object)(object)_infoText != (Object)null)
{
if (pageCount > 1)
{
_infoText.text = $"第 {_page + 1}/{pageCount} 页 · 共 {AutoRecyclePlugin.Items.Count} 种";
}
else
{
_infoText.text = $"已选 {AutoRecyclePlugin.Items.Count} 种 · 拖入物品可加入";
}
}
if ((Object)(object)_toggleText != (Object)null)
{
_toggleText.text = (AutoRecyclePlugin.Enabled.Value ? "启用" : "暂停");
}
}
private static RectTransform NewRect(string name, RectTransform parent, Vector2 anchoredPos, Vector2 size)
{
//IL_0014: 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_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: 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_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Expected O, but got Unknown
//IL_0034: Expected O, but got Unknown
RectTransform val = (RectTransform)new GameObject(name, new Type[1] { typeof(RectTransform) }).transform;
((Transform)val).SetParent((Transform)(object)parent, false);
SetRect(val, anchoredPos, size);
return val;
}
private static void SetRect(RectTransform rt, Vector2 pos, Vector2 size)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: 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_0047: Unknown result type (might be due to invalid IL or missing references)
rt.anchorMin = new Vector2(0f, 1f);
rt.anchorMax = new Vector2(0f, 1f);
rt.pivot = new Vector2(0f, 1f);
rt.anchoredPosition = pos;
rt.sizeDelta = size;
}
private static void Stretch(RectTransform rt)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: 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)
rt.anchorMin = Vector2.zero;
rt.anchorMax = Vector2.one;
rt.offsetMin = Vector2.zero;
rt.offsetMax = Vector2.zero;
}
private static Image AddImage(RectTransform parent, Color color)
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("Image", new Type[2]
{
typeof(RectTransform),
typeof(Image)
});
((Transform)(RectTransform)val.transform).SetParent((Transform)(object)parent, false);
Image component = val.GetComponent<Image>();
((Graphic)component).color = color;
((Graphic)component).raycastTarget = false;
return component;
}
private Text NewText(string name, RectTransform parent, string content, int size, TextAnchor anchor)
{
//IL_0002: 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_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
Text obj = ((Component)NewRect(name, parent, Vector2.zero, new Vector2(100f, 20f))).gameObject.AddComponent<Text>();
obj.font = _font;
obj.fontSize = size;
obj.text = content;
((Graphic)obj).color = TextMain;
obj.alignment = anchor;
obj.horizontalOverflow = (HorizontalWrapMode)1;
obj.verticalOverflow = (VerticalWrapMode)1;
((Graphic)obj).raycastTarget = false;
return obj;
}
private Button NewButton(string name, RectTransform parent, string label, Vector2 pos, Vector2 size, Action onClick, bool body = true)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: 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_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: 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)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_0124: Unknown result type (might be due to invalid IL or missing references)
//IL_012f: Unknown result type (might be due to invalid IL or missing references)
//IL_0184: 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_0155: Expected O, but got Unknown
RectTransform val = NewRect(name, parent, pos, size);
if (body)
{
_bodyObjects.Add(((Component)val).gameObject);
}
RectTransform obj = NewRect("Border", val, Vector2.zero, Vector2.zero);
Stretch(obj);
Image obj2 = ((Component)obj).gameObject.AddComponent<Image>();
((Graphic)obj2).color = ButtonBorder;
((Graphic)obj2).raycastTarget = false;
RectTransform obj3 = NewRect("Fill", val, Vector2.zero, Vector2.zero);
Stretch(obj3);
obj3.offsetMin = new Vector2(1f, 1f);
obj3.offsetMax = new Vector2(-1f, -1f);
Image val2 = ((Component)obj3).gameObject.AddComponent<Image>();
((Graphic)val2).color = ButtonFill;
((Graphic)val2).raycastTarget = true;
Button val3 = ((Component)obj3).gameObject.AddComponent<Button>();
((Selectable)val3).targetGraphic = (Graphic)(object)val2;
ColorBlock colors = ((Selectable)val3).colors;
((ColorBlock)(ref colors)).normalColor = Color.white;
((ColorBlock)(ref colors)).highlightedColor = new Color(1.45f, 1.45f, 1.45f, 1f);
((ColorBlock)(ref colors)).pressedColor = new Color(0.8f, 0.8f, 0.8f, 1f);
((Selectable)val3).colors = colors;
if (onClick != null)
{
((UnityEvent)val3.onClick).AddListener((UnityAction)delegate
{
onClick();
});
}
Text obj4 = NewText("Label", val, label, 12, (TextAnchor)4);
Stretch(((Graphic)obj4).rectTransform);
((Graphic)obj4).color = new Color(0.85f, 0.93f, 0.98f, 0.95f);
return val3;
}
}
internal sealed class SlotInteraction : MonoBehaviour, IPointerClickHandler, IEventSystemHandler, IPointerEnterHandler, IPointerExitHandler, IScrollHandler
{
internal TrashPanel Panel;
internal int Index;
public void OnPointerClick(PointerEventData eventData)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
if ((int)eventData.button == 0)
{
Panel?.OnSlotClicked(Index);
}
}
public void OnPointerEnter(PointerEventData eventData)
{
Panel?.OnSlotHover(Index, enter: true);
}
public void OnPointerExit(PointerEventData eventData)
{
Panel?.OnSlotHover(Index, enter: false);
}
public void OnScroll(PointerEventData eventData)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
Panel?.ScrollPage(eventData.scrollDelta.y);
}
}
internal sealed class ScrollPager : MonoBehaviour, IScrollHandler, IEventSystemHandler
{
internal TrashPanel Panel;
public void OnScroll(PointerEventData eventData)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
Panel?.ScrollPage(eventData.scrollDelta.y);
}
}
}