using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Items;
using Items.Inventory;
using R3;
using TMPro;
using UI.SelectableWindow.Cell;
using UI.SelectableWindow.ISelectableWindows;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using Utility.StringFormatter;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace LwfPinnedSlots;
[BepInPlugin("kiyonakanata.lwfpinnedslots", "LWF Pinned Slots", "1.0.1")]
public sealed class PinnedSlotsPlugin : BaseUnityPlugin
{
internal const string PluginGuid = "kiyonakanata.lwfpinnedslots";
internal const string PluginName = "LWF Pinned Slots";
internal const string PluginVersion = "1.0.1";
internal const int SlotCount = 11;
internal static ManualLogSource Log;
internal static ConfigEntry<bool> Enabled;
internal static ConfigEntry<string>[] Slots;
internal static ConfigEntry<bool> ShowCounts;
internal static ConfigEntry<int> GhostBrightness;
internal static ConfigEntry<int> MarkerSize;
internal static ConfigEntry<string> MarkerColor;
internal static bool SuppressArrange;
private Harmony _harmony;
internal static readonly string[] ItemIds = new string[11]
{
"", "Wand", "Summon-Conveyor", "Summon-Conveyor2", "Summon-Splitter", "Summon-Splitter2", "Summon-Worker", "Summon-Transporter", "Summon-Crafter", "Summon-Smelter",
"Summon-Summoner"
};
private void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
try
{
Boot();
}
catch (Exception ex)
{
Log.LogWarning((object)("[boot] LWF Pinned Slots 1.0.1 disabled (the game version may have changed): " + ex));
((BaseUnityPlugin)this).Config.SettingChanged -= OnSettingChanged;
try
{
if (_harmony != null)
{
_harmony.UnpatchSelf();
}
}
catch (Exception ex2)
{
Log.LogWarning((object)("[boot] unpatch failed: " + ex2.Message));
}
((Behaviour)this).enabled = false;
}
}
private void Boot()
{
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Expected O, but got Unknown
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Expected O, but got Unknown
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_011f: Expected O, but got Unknown
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
//IL_016f: Expected O, but got Unknown
Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1. General", "Enabled", true, "");
string[] array = new string[11];
for (int i = 0; i < 11; i++)
{
array[i] = "";
}
Slots = new ConfigEntry<string>[11];
for (int j = 0; j < 11; j++)
{
Slots[j] = ((BaseUnityPlugin)this).Config.Bind<string>("2. Slots", "Slot " + (j + 1), array[j], new ConfigDescription("", (AcceptableValueBase)(object)new AcceptableValueList<string>(ItemIds), new object[0]));
}
ShowCounts = ((BaseUnityPlugin)this).Config.Bind<bool>("3. View", "Show 0 and 1 on pinned slots", true, "");
GhostBrightness = ((BaseUnityPlugin)this).Config.Bind<int>("3. View", "Empty pinned slot icon brightness (%)", 35, new ConfigDescription("", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), new object[0]));
MarkerSize = ((BaseUnityPlugin)this).Config.Bind<int>("3. View", "Pin marker size", 14, new ConfigDescription("", (AcceptableValueBase)(object)new AcceptableValueRange<int>(2, 64), new object[0]));
MarkerColor = ((BaseUnityPlugin)this).Config.Bind<string>("3. View", "Pin marker color", "#FFFFFF", "");
((BaseUnityPlugin)this).Config.SettingChanged += OnSettingChanged;
_harmony = new Harmony("kiyonakanata.lwfpinnedslots");
_harmony.PatchAll(typeof(PinnedSlotsPlugin).Assembly);
int num = 0;
foreach (MethodBase patchedMethod in _harmony.GetPatchedMethods())
{
_ = patchedMethod;
num++;
}
Log.LogInfo((object)("[boot] LWF Pinned Slots 1.0.1 patches=" + num));
SlotArranger.ArrangePlayerInventory();
SlotView.RefreshAll();
}
private void OnDestroy()
{
((BaseUnityPlugin)this).Config.SettingChanged -= OnSettingChanged;
SlotMouse.DetachAll();
if (_harmony != null)
{
_harmony.UnpatchSelf();
}
}
private void OnSettingChanged(object sender, SettingChangedEventArgs e)
{
if (!SuppressArrange)
{
SlotArranger.ArrangePlayerInventory();
SlotView.RefreshAll();
}
}
}
[HarmonyPatch(typeof(InventoryDepositor), "DepositInternal")]
internal static class DepositInternalPatch
{
private static void Postfix(InventoryDepositor __instance)
{
if (PinnedSlotsPlugin.Enabled.Value)
{
InventoryManager playerInventory = InventoryManager.playerInventory;
if (playerInventory != null && object.ReferenceEquals(playerInventory.GetDepositor(), __instance))
{
SlotArranger.Arrange(playerInventory);
}
}
}
}
internal static class SlotArranger
{
private const string NoneId = "None";
private static readonly FieldInfo CellValueChangedField = AccessTools.Field(typeof(InventoryDepositor), "_onCellValueChanged");
private static bool _busy;
internal static string OwnerOf(int index)
{
if (index < 0 || index >= 11 || PinnedSlotsPlugin.Slots == null)
{
return null;
}
for (int i = 0; i <= index; i++)
{
string value = PinnedSlotsPlugin.Slots[i].Value;
if (value == null)
{
continue;
}
value = value.Trim();
if (value.Length == 0 || value == "None")
{
continue;
}
bool flag = false;
for (int j = 0; j < i; j++)
{
string value2 = PinnedSlotsPlugin.Slots[j].Value;
if (value2 != null && value2.Trim() == value)
{
flag = true;
break;
}
}
if (i == index)
{
if (!flag)
{
return value;
}
return null;
}
}
return null;
}
internal static void ArrangePlayerInventory()
{
if (PinnedSlotsPlugin.Enabled != null && PinnedSlotsPlugin.Enabled.Value)
{
InventoryManager playerInventory = InventoryManager.playerInventory;
if (playerInventory != null)
{
Arrange(playerInventory);
}
}
}
internal static void Arrange(InventoryManager inv)
{
if (_busy)
{
return;
}
_busy = true;
try
{
ArrangeCore(inv.GetDB(), inv.GetDepositor());
SlotView.RefreshAll();
}
catch (Exception ex)
{
PinnedSlotsPlugin.Log.LogError((object)("[arrange] " + ex));
}
finally
{
_busy = false;
}
}
private static void ArrangeCore(InventoryDB db, InventoryDepositor depositor)
{
int num = db.cellIDEnd + 1;
string[] array = new string[num];
Dictionary<string, int> dictionary = new Dictionary<string, int>();
ReadPins(num, array, dictionary);
if (dictionary.Count == 0)
{
return;
}
int getCellCapacity = db.GetCellCapacity;
int num2 = num * 2 + 2;
for (int i = 0; i < num2; i++)
{
bool flag = false;
for (int j = 0; j < num; j++)
{
string text = db.ItemID(j);
int num3 = db.ItemCount(j);
if (num3 <= 0 || text == "None")
{
continue;
}
if (dictionary.TryGetValue(text, out var value))
{
if (value != j && MoveHome(db, depositor, j, value, text, num3, getCellCapacity))
{
flag = true;
}
}
else if (array[j] != null)
{
int num4 = FindFreeCell(db, array, num);
if (num4 >= 0)
{
Move(db, depositor, j, num4, text, num3);
flag = true;
}
}
}
if (!flag)
{
break;
}
}
}
private static void ReadPins(int cellCount, string[] owner, Dictionary<string, int> home)
{
int num = Math.Min(11, cellCount);
for (int i = 0; i < num; i++)
{
string value = PinnedSlotsPlugin.Slots[i].Value;
if (value != null)
{
value = value.Trim();
if (value.Length != 0 && !(value == "None") && !home.ContainsKey(value))
{
home[value] = i;
owner[i] = value;
}
}
}
}
private static int FindFreeCell(InventoryDB db, string[] owner, int cellCount)
{
for (int i = 0; i < cellCount; i++)
{
if (owner[i] == null && (db.ItemCount(i) <= 0 || !(db.ItemID(i) != "None")))
{
return i;
}
}
return -1;
}
private static bool MoveHome(InventoryDB db, InventoryDepositor depositor, int from, int to, string id, int count, int capacity)
{
string text = db.ItemID(to);
int num = db.ItemCount(to);
if (num <= 0 || text == "None")
{
Move(db, depositor, from, to, id, count);
return true;
}
if (text == id)
{
long num2 = (long)capacity - (long)num;
if (num2 <= 0)
{
return false;
}
int num3 = (int)Math.Min(num2, count);
int num4 = count - num3;
db.SetCellItem(to, id, num + num3);
db.SetCellItem(from, (num4 > 0) ? id : "None", num4);
Notify(depositor, to);
PinnedSlotsPlugin.Log.LogDebug((object)("[arrange] merge " + id + " x" + num3 + " cell " + from + " -> " + to));
return true;
}
db.SetCellItem(to, id, count);
db.SetCellItem(from, text, num);
Notify(depositor, to);
PinnedSlotsPlugin.Log.LogDebug((object)("[arrange] swap " + id + " cell " + from + " <-> " + text + " cell " + to));
return true;
}
private static void Move(InventoryDB db, InventoryDepositor depositor, int from, int to, string id, int count)
{
db.SetCellItem(to, id, count);
db.SetCellItem(from, "None", 0);
Notify(depositor, to);
PinnedSlotsPlugin.Log.LogDebug((object)("[arrange] move " + id + " x" + count + " cell " + from + " -> " + to));
}
private static void Notify(InventoryDepositor depositor, int cell)
{
if (!(CellValueChangedField == null) && CellValueChangedField.GetValue(depositor) is ReactiveProperty<int> val)
{
val.OnNext(cell);
}
}
}
internal static class SlotView
{
private const string NoneId = "None";
private static readonly FieldInfo SyncField = AccessTools.Field(typeof(InventoryManager), "_sync");
private static readonly HashSet<CellComponents> _ghosted = new HashSet<CellComponents>();
internal static void RefreshAll()
{
InventoryManager playerInventory = InventoryManager.playerInventory;
if (playerInventory == null || playerInventory.GetWindow() == null)
{
return;
}
try
{
List<CellComponents> cellComponentsList = ((WindowWithCells)playerInventory.GetWindow()).GetCellComponentsList();
InventoryDB dB = playerInventory.GetDB();
if (cellComponentsList == null)
{
return;
}
int num = Math.Min(cellComponentsList.Count, dB.cellIDEnd + 1);
for (int i = 0; i < num; i++)
{
if (!((Object)(object)cellComponentsList[i] == (Object)null))
{
string text = dB.ItemID(i);
int num2 = dB.ItemCount(i);
cellComponentsList[i].SetImageSprite(ItemParamGetter.GetSprite(text));
cellComponentsList[i].SetText((num2 <= 1) ? "" : NumberFormatter.Format(num2));
Decorate(cellComponentsList[i], i, text, num2);
}
}
}
catch (Exception ex)
{
PinnedSlotsPlugin.Log.LogError((object)("[view] " + ex));
}
}
internal static void Decorate(CellComponents cell, int index, string itemID, int count)
{
//IL_00c7: 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)
string text = ((PinnedSlotsPlugin.Enabled.Value && PinnedSlotsPlugin.ShowCounts.Value) ? SlotArranger.OwnerOf(index) : null);
bool flag = count <= 0 || itemID == "None";
SlotMouse.Ensure(cell, index, SlotArranger.OwnerOf(index) != null);
if (text != null && flag)
{
Sprite sprite = ItemParamGetter.GetSprite(text);
if ((Object)(object)sprite != (Object)null)
{
cell.SetImageSprite(sprite);
}
float num = (float)Mathf.Clamp(PinnedSlotsPlugin.GhostBrightness.Value, 0, 100) / 100f;
cell.SetImageColor(new Color(1f, 1f, 1f, num));
cell.SetText("0");
_ghosted.Add(cell);
}
else
{
if (_ghosted.Remove(cell))
{
cell.SetImageColor(Color.white);
}
if (text != null && count == 1 && itemID != "Wand")
{
cell.SetText("1");
}
}
}
internal static bool IsPlayerSync(object sync)
{
InventoryManager playerInventory = InventoryManager.playerInventory;
if (playerInventory == null || SyncField == null)
{
return false;
}
return object.ReferenceEquals(SyncField.GetValue(playerInventory), sync);
}
}
[HarmonyPatch(typeof(InventoryViewSynchronizer), "Sync", new Type[]
{
typeof(CellComponents),
typeof(string),
typeof(int)
})]
internal static class ViewSyncPatch
{
private static void Postfix(InventoryViewSynchronizer __instance, CellComponents cell, string itemID, int count)
{
try
{
if (!((Object)(object)cell == (Object)null) && SlotView.IsPlayerSync(__instance))
{
InventoryManager playerInventory = InventoryManager.playerInventory;
int num = ((WindowWithCells)playerInventory.GetWindow()).GetCellComponentsList()?.IndexOf(cell) ?? (-1);
if (num >= 0)
{
SlotView.Decorate(cell, num, itemID, count);
}
}
}
catch (Exception ex)
{
PinnedSlotsPlugin.Log.LogError((object)("[view] " + ex));
}
}
}
internal static class SlotEdit
{
private const string NoneId = "None";
internal static void SwapSeats(InventoryManager inv, int from, int to)
{
InventoryDB dB = inv.GetDB();
if (from != to && from >= 0 && to >= 0 && from <= dB.cellIDEnd && to <= dB.cellIDEnd)
{
string text = dB.ItemID(from);
int num = dB.ItemCount(from);
string text2 = dB.ItemID(to);
int num2 = dB.ItemCount(to);
string text3 = SlotValue(from);
string text4 = SlotValue(to);
PinnedSlotsPlugin.SuppressArrange = true;
try
{
dB.SetCellItem(to, text, num);
dB.SetCellItem(from, text2, num2);
SetSlot(from, text4);
SetSlot(to, text3);
}
finally
{
PinnedSlotsPlugin.SuppressArrange = false;
}
SlotArranger.Arrange(inv);
SlotView.RefreshAll();
PinnedSlotsPlugin.Log.LogInfo((object)("[edit] swap cell " + from + " <-> " + to + " (" + Show(text, text3) + " <-> " + Show(text2, text4) + ")"));
}
}
internal static void TogglePin(InventoryManager inv, int cell)
{
InventoryDB dB = inv.GetDB();
if (cell < 0 || cell > dB.cellIDEnd)
{
return;
}
string text = dB.ItemID(cell);
int num = dB.ItemCount(cell);
string text2 = SlotArranger.OwnerOf(cell);
PinnedSlotsPlugin.SuppressArrange = true;
try
{
if (text2 != null)
{
SetSlot(cell, "");
PinnedSlotsPlugin.Log.LogInfo((object)("[edit] unpin slot " + (cell + 1) + " (" + text2 + ")"));
}
else
{
if (num <= 0 || !(text != "None"))
{
return;
}
for (int i = 0; i < 11; i++)
{
if (i != cell && SlotValue(i) == text)
{
SetSlot(i, "");
}
}
SetSlot(cell, text);
PinnedSlotsPlugin.Log.LogInfo((object)("[edit] pin slot " + (cell + 1) + " = " + text));
}
}
finally
{
PinnedSlotsPlugin.SuppressArrange = false;
}
SlotArranger.Arrange(inv);
SlotView.RefreshAll();
}
private static string SlotValue(int i)
{
if (i < 0 || i >= 11)
{
return "";
}
string value = PinnedSlotsPlugin.Slots[i].Value;
if (value != null)
{
return value.Trim();
}
return "";
}
private static void SetSlot(int i, string value)
{
if (i >= 0 && i < 11 && PinnedSlotsPlugin.Slots[i].Value != value)
{
PinnedSlotsPlugin.Slots[i].Value = value;
}
}
private static string Show(string id, string owner)
{
return id + ((owner.Length > 0) ? ("@" + owner) : "");
}
}
internal static class SlotMouse
{
private const string MarkerName = "LwfPinnedSlots.Marker";
private const string MarkerSpriteName = "check_small_true";
private static Sprite _markerSprite;
private static Sprite FindMarkerSprite()
{
if ((Object)(object)_markerSprite != (Object)null)
{
return _markerSprite;
}
Sprite[] array = Resources.FindObjectsOfTypeAll<Sprite>();
for (int i = 0; i < array.Length; i++)
{
if ((Object)(object)array[i] != (Object)null && ((Object)array[i]).name == "check_small_true")
{
_markerSprite = array[i];
break;
}
}
if ((Object)(object)_markerSprite == (Object)null)
{
PinnedSlotsPlugin.Log.LogWarning((object)"[view] sprite not found: check_small_true");
}
return _markerSprite;
}
internal static void Ensure(CellComponents cell, int index, bool pinned)
{
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Expected O, but got Unknown
//IL_00c5: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_016b: Unknown result type (might be due to invalid IL or missing references)
//IL_0170: Unknown result type (might be due to invalid IL or missing references)
//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
//IL_021a: Unknown result type (might be due to invalid IL or missing references)
GameObject val = HostOf(cell);
if ((Object)(object)val == (Object)null)
{
return;
}
SlotCellHandle slotCellHandle = val.GetComponent<SlotCellHandle>();
if ((Object)(object)slotCellHandle == (Object)null)
{
slotCellHandle = val.AddComponent<SlotCellHandle>();
}
slotCellHandle.Index = index;
slotCellHandle.Cell = cell;
Transform val2 = MarkerParent(cell);
if ((Object)(object)val2 == (Object)null)
{
return;
}
Transform val3 = val2.Find("LwfPinnedSlots.Marker");
Image component;
if ((Object)(object)val3 == (Object)null)
{
GameObject val4 = new GameObject("LwfPinnedSlots.Marker", new Type[2]
{
typeof(RectTransform),
typeof(Image)
});
val4.transform.SetParent(val2, false);
component = val4.GetComponent<Image>();
((Graphic)component).raycastTarget = false;
RectTransform component2 = val4.GetComponent<RectTransform>();
component2.anchorMin = new Vector2(0f, 0f);
component2.anchorMax = new Vector2(0f, 0f);
component2.pivot = new Vector2(0.5f, 0.5f);
}
else
{
component = ((Component)val3).GetComponent<Image>();
}
float num = Mathf.Max(2, PinnedSlotsPlugin.MarkerSize.Value);
float num2 = 8.9f;
if ((Object)(object)cell.GetText() != (Object)null)
{
num2 = ((TMP_Text)cell.GetText()).rectTransform.anchoredPosition.y;
}
TextMeshProUGUI text = cell.GetText();
float num3 = 36f;
float num4 = 0f;
if ((Object)(object)text != (Object)null)
{
Rect rect = ((TMP_Text)text).rectTransform.rect;
float width = ((Rect)(ref rect)).width;
if (width > 0f)
{
num3 = width;
}
if (!string.IsNullOrEmpty(((TMP_Text)text).text))
{
num4 = ((TMP_Text)text).preferredWidth;
}
}
float num5 = num3 - num4 - 2f;
if (num5 < num)
{
num = num5;
}
bool flag = num >= 6f;
RectTransform rectTransform = ((Graphic)component).rectTransform;
rectTransform.sizeDelta = new Vector2(num, num);
rectTransform.anchoredPosition = new Vector2(4f + num * 0.5f, num2);
Sprite val5 = (component.sprite = FindMarkerSprite());
component.preserveAspect = (Object)(object)val5 != (Object)null;
((Graphic)component).color = MarkerColor();
((Component)component).gameObject.SetActive(pinned && flag && PinnedSlotsPlugin.Enabled.Value);
}
internal static void DetachAll()
{
InventoryManager playerInventory = InventoryManager.playerInventory;
if (playerInventory == null || playerInventory.GetWindow() == null)
{
return;
}
List<CellComponents> cellComponentsList = ((WindowWithCells)playerInventory.GetWindow()).GetCellComponentsList();
if (cellComponentsList == null)
{
return;
}
foreach (CellComponents item in cellComponentsList)
{
if ((Object)(object)item == (Object)null)
{
continue;
}
GameObject val = HostOf(item);
if ((Object)(object)val != (Object)null)
{
SlotCellHandle component = val.GetComponent<SlotCellHandle>();
if ((Object)(object)component != (Object)null)
{
Object.Destroy((Object)(object)component);
}
}
Transform val2 = MarkerParent(item);
if ((Object)(object)val2 != (Object)null)
{
Transform val3 = val2.Find("LwfPinnedSlots.Marker");
if ((Object)(object)val3 != (Object)null)
{
Object.Destroy((Object)(object)((Component)val3).gameObject);
}
}
}
SlotCellHandle.DestroyGhost();
}
private static Transform MarkerParent(CellComponents cell)
{
if ((Object)(object)cell.GetText() != (Object)null)
{
return ((TMP_Text)cell.GetText()).transform.parent;
}
if ((Object)(object)cell.GetImage() != (Object)null)
{
return ((Component)cell.GetImage()).transform.parent;
}
return null;
}
private static GameObject HostOf(CellComponents cell)
{
Button button = cell.GetButton();
if ((Object)(object)button != (Object)null)
{
return ((Component)button).gameObject;
}
return cell.GetGameObject();
}
private static Color MarkerColor()
{
//IL_0015: 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)
Color result = default(Color);
if (ColorUtility.TryParseHtmlString(PinnedSlotsPlugin.MarkerColor.Value, ref result))
{
return result;
}
return Color.white;
}
}
internal sealed class SlotCellHandle : MonoBehaviour, IPointerClickHandler, IBeginDragHandler, IDragHandler, IEndDragHandler, IDropHandler, IEventSystemHandler
{
private const string GhostName = "LwfPinnedSlots.Ghost";
private static GameObject _ghost;
internal int Index;
internal CellComponents Cell;
public void OnPointerClick(PointerEventData e)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Invalid comparison between Unknown and I4
if ((int)e.button == 1 && PinnedSlotsPlugin.Enabled.Value)
{
InventoryManager playerInventory = InventoryManager.playerInventory;
if (playerInventory != null)
{
SlotEdit.TogglePin(playerInventory, Index);
}
}
}
public void OnBeginDrag(PointerEventData e)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
if ((int)e.button != 0 || !PinnedSlotsPlugin.Enabled.Value)
{
return;
}
InventoryManager playerInventory = InventoryManager.playerInventory;
if (playerInventory != null)
{
InventoryDB dB = playerInventory.GetDB();
string text = dB.ItemID(Index);
string text2 = SlotArranger.OwnerOf(Index);
if ((dB.ItemCount(Index) > 0 && !(text == "None")) || text2 != null)
{
Sprite sprite = ItemParamGetter.GetSprite((dB.ItemCount(Index) > 0 && text != "None") ? text : text2);
MakeGhost(sprite, e);
}
}
}
public void OnDrag(PointerEventData e)
{
MoveGhost(e);
}
public void OnEndDrag(PointerEventData e)
{
DestroyGhost();
}
public void OnDrop(PointerEventData e)
{
if (!PinnedSlotsPlugin.Enabled.Value || (Object)(object)e.pointerDrag == (Object)null)
{
return;
}
SlotCellHandle component = e.pointerDrag.GetComponent<SlotCellHandle>();
if (!((Object)(object)component == (Object)null) && !((Object)(object)component == (Object)(object)this) && component.Index != Index)
{
InventoryManager playerInventory = InventoryManager.playerInventory;
if (playerInventory != null)
{
SlotEdit.SwapSeats(playerInventory, component.Index, Index);
}
}
}
private void MakeGhost(Sprite sprite, PointerEventData e)
{
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Expected O, but got Unknown
//IL_00cb: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
DestroyGhost();
Image val = (((Object)(object)Cell != (Object)null) ? Cell.GetImage() : null);
Canvas componentInParent = ((Component)this).GetComponentInParent<Canvas>();
if (!((Object)(object)val == (Object)null) && !((Object)(object)componentInParent == (Object)null))
{
componentInParent = componentInParent.rootCanvas;
_ghost = new GameObject("LwfPinnedSlots.Ghost", new Type[2]
{
typeof(RectTransform),
typeof(Image)
});
_ghost.transform.SetParent(((Component)componentInParent).transform, false);
_ghost.transform.SetAsLastSibling();
Image component = _ghost.GetComponent<Image>();
component.sprite = sprite;
((Graphic)component).raycastTarget = false;
((Graphic)component).color = new Color(1f, 1f, 1f, 0.8f);
RectTransform component2 = _ghost.GetComponent<RectTransform>();
Rect rect = ((Graphic)val).rectTransform.rect;
component2.sizeDelta = ((Rect)(ref rect)).size;
MoveGhost(e);
}
}
private static void MoveGhost(PointerEventData e)
{
//IL_002f: 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)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)_ghost == (Object)null)
{
return;
}
RectTransform component = _ghost.GetComponent<RectTransform>();
Canvas componentInParent = _ghost.GetComponentInParent<Canvas>();
if (!((Object)(object)componentInParent == (Object)null))
{
Camera val = (((int)componentInParent.renderMode == 0) ? null : componentInParent.worldCamera);
Transform transform = ((Component)componentInParent).transform;
Vector3 position = default(Vector3);
if (RectTransformUtility.ScreenPointToWorldPointInRectangle((RectTransform)(object)((transform is RectTransform) ? transform : null), e.position, val, ref position))
{
((Transform)component).position = position;
}
}
}
internal static void DestroyGhost()
{
if ((Object)(object)_ghost != (Object)null)
{
Object.Destroy((Object)(object)_ghost);
_ghost = null;
}
}
private void OnDisable()
{
DestroyGhost();
}
}