using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Photon.Pun;
using Photon.Realtime;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.UI;
using Zorro.Core;
using Zorro.Core.Serizalization;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[BepInPlugin("databaze.peak.doubleup", "Double Up", "1.0.0")]
public class DoubleUp : BaseUnityPlugin
{
[HarmonyPatch(typeof(Player), "GetItemSlot")]
private static class GetItemSlotPatch
{
private static bool Prefix(Player __instance, byte __0, ref ItemSlot __result)
{
if (__0 != 4)
{
return true;
}
__result = (ItemSlot)(object)Fanny(__instance);
return false;
}
}
[HarmonyPatch(typeof(Player), "HasEmptySlot")]
private static class HasEmptySlotPatch
{
private static void Postfix(Player __instance, ushort __0, ref bool __result)
{
Item prefab = default(Item);
if (!__result && ItemDatabase.TryGetItem(__0, ref prefab) && IsFanny(prefab) && ((ItemSlot)Fanny(__instance)).IsEmpty())
{
__result = true;
}
}
}
[HarmonyPatch(typeof(Player), "AddItem")]
private static class AddItemPatch
{
private static bool Prefix(Player __instance, ushort __0, ItemInstanceData __1, ref ItemSlot __2, ref bool __result)
{
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Expected O, but got Unknown
Item val = default(Item);
if (!PhotonNetwork.IsMasterClient || !ItemDatabase.TryGetItem(__0, ref val) || !IsFanny(val))
{
return true;
}
BackpackSlot val2 = Fanny(__instance);
if (!((ItemSlot)val2).IsEmpty())
{
return true;
}
ItemInstanceData val3 = __1;
if (val3 == null)
{
val3 = new ItemInstanceData(Guid.NewGuid());
ItemInstanceDataHandler.AddInstanceData(val3);
}
val2.backpackType = (BackpackType)2;
((ItemSlot)val2).SetItem(val, val3);
__2 = (ItemSlot)(object)val2;
__result = true;
Log.LogDebug((object)("Fanny pack -> slot 5 for " + ((Object)__instance).name));
BroadcastInventory(__instance);
return false;
}
}
[HarmonyPatch(typeof(CharacterItems), "OnPickupAccepted")]
private static class OnPickupAcceptedPatch
{
private static bool Prefix(CharacterItems __instance, byte __0)
{
if (__0 != 4)
{
return true;
}
AccessTools.Method(typeof(CharacterItems), "RefreshAllCharacterCarryWeight", (Type[])null, (Type[])null).Invoke(__instance, null);
return false;
}
}
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
private static class SyncCtorPatch
{
private static void Postfix(ref InventorySyncData __instance, ItemSlot[] __0)
{
Player val = ((__0.Length > 0) ? __0[0].player : null);
if (!((Object)(object)val == (Object)null) && object.ReferenceEquals(__0, val.itemSlots))
{
syncOwners.Remove(__instance.slots);
syncOwners.Add(__instance.slots, val);
}
}
}
[HarmonyPatch(typeof(InventorySyncData), "Serialize")]
private static class SyncSerializePatch
{
private static void Postfix(ref InventorySyncData __instance, BinarySerializer __0)
{
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Expected O, but got Unknown
Player value;
BackpackSlot val = ((serializeDepth == 0 && __instance.slots != null && syncOwners.TryGetValue(__instance.slots, out value)) ? Fanny(value) : null);
if (val == null || ((ItemSlot)val).IsEmpty() || (Object)(object)((ItemSlot)val).prefab == (Object)null)
{
__0.WriteUshort(ushort.MaxValue);
return;
}
ItemInstanceData val2 = ((ItemSlot)val).data;
if (val2 == null)
{
val2 = new ItemInstanceData(Guid.NewGuid());
ItemInstanceDataHandler.AddInstanceData(val2);
}
__0.WriteUshort(((ItemSlot)val).prefab.itemID);
__0.WriteGuid(val2.guid);
serializeDepth++;
try
{
val2.Serialize(__0);
}
finally
{
serializeDepth--;
}
}
}
[HarmonyPatch(typeof(InventorySyncData), "Deserialize")]
private static class SyncDeserializePatch
{
private static void Postfix(BinaryDeserializer __0)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Expected O, but got Unknown
lastReadValid = false;
try
{
ushort num = __0.ReadUShort();
ItemInstanceData val = null;
if (num != ushort.MaxValue)
{
Guid guid = __0.ReadGuid();
if (!ItemInstanceDataHandler.TryGetInstanceData(guid, ref val))
{
val = new ItemInstanceData(guid);
ItemInstanceDataHandler.AddInstanceData(val);
}
val.Deserialize(__0);
}
lastReadId = num;
lastReadData = val;
lastReadValid = true;
}
catch (Exception ex)
{
Debug.LogWarning((object)("[DoubleUp] no fanny slot data in inventory sync: " + ex.Message));
}
}
}
[HarmonyPatch(typeof(Player), "SyncInventoryRPC")]
private static class SyncInventoryRpcPatch
{
private static void Prefix()
{
lastReadValid = false;
}
private static void Postfix(Player __instance, bool __1)
{
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
if (lastReadValid && (__1 || !PhotonNetwork.IsMasterClient))
{
lastReadValid = false;
BackpackSlot val = Fanny(__instance);
Item val2 = default(Item);
if (lastReadId != ushort.MaxValue && ItemDatabase.TryGetItem(lastReadId, ref val2))
{
val.backpackType = (BackpackType)2;
((ItemSlot)val).SetItem(val2, lastReadData);
}
else
{
((ItemSlot)val).EmptyOut();
}
Log.LogDebug((object)("Sync read: slot 5 " + (((ItemSlot)val).IsEmpty() ? "empty" : ("= " + ((Object)((ItemSlot)val).prefab).name)) + " for " + ((Object)__instance).name));
Character character = __instance.character;
if ((Object)(object)character != (Object)null)
{
AccessTools.Method(typeof(CharacterAfflictions), "UpdateWeight", (Type[])null, (Type[])null).Invoke(character.refs.afflictions, null);
}
}
}
}
[HarmonyPatch(typeof(CharacterAfflictions), "UpdateWeight")]
private static class UpdateWeightPatch
{
private static void Postfix(CharacterAfflictions __instance)
{
Character character = __instance.character;
Player val = (((Object)(object)character != (Object)null) ? character.player : null);
if ((Object)(object)val == (Object)null)
{
return;
}
float num = 0f;
ItemSlot[] itemSlots = val.itemSlots;
foreach (ItemSlot val2 in itemSlots)
{
if ((Object)(object)val2.prefab != (Object)null)
{
num += (float)val2.prefab.CarryWeight;
}
}
float value = PackWeightMultiplier.Value;
float value2 = ContentsWeightMultiplier.Value;
PackWeight(val.backpackSlot, out var contents, out var self);
PackWeight(Fanny(val), out var contents2, out var self2);
float num2 = 0f;
ItemSlot itemSlot = val.GetItemSlot((byte)250);
if (itemSlot != null && !itemSlot.IsEmpty())
{
num2 += (float)itemSlot.prefab.CarryWeight;
}
if ((Object)(object)character.data.carriedPlayer != (Object)null)
{
num2 += 8f;
}
foreach (StickyItemComponent aLL_STUCK_ITEM in StickyItemComponent.ALL_STUCK_ITEMS)
{
if ((Object)(object)aLL_STUCK_ITEM != (Object)null && (Object)(object)aLL_STUCK_ITEM.stuckToCharacter == (Object)(object)character)
{
num2 += (float)aLL_STUCK_ITEM.addWeightToStuckPlayer;
}
}
float num3 = num + value2 * (float)(contents + contents2) + value * (float)(self + self2) + num2;
__instance.SetStatus((STATUSTYPE)7, 0.025f * num3, true);
}
}
[HarmonyPatch(typeof(CharacterItems), "DoSwitching")]
private static class DoSwitchingPatch
{
private static readonly MethodInfo canDoInput = AccessTools.Method(typeof(Character), "CanDoInput", (Type[])null, (Type[])null);
private static bool Key5Pressed(Character c)
{
if (c.input.itemSwitchBlocked)
{
return false;
}
InputAction[] hotbarActions = CharacterInput.hotbarActions;
Keyboard current = Keyboard.current;
if (hotbarActions == null || hotbarActions.Length <= 4 || hotbarActions[4] == null || !hotbarActions[4].WasPressedThisFrame())
{
if (current != null)
{
return ((ButtonControl)current.digit5Key).wasPressedThisFrame;
}
return false;
}
return true;
}
private static void Postfix(CharacterItems __instance)
{
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
Character value = Traverse.Create((object)__instance).Field("character").GetValue<Character>();
if (!((Object)(object)value == (Object)null) && value.IsLocal && Key5Pressed(value))
{
CharacterData data = value.data;
if (data.fullyConscious && !data.isClimbing && !data.isRopeClimbing && !Object.op_Implicit((Object)(object)data.currentStickyItem) && (!((Object)(object)data.currentItem != (Object)null) || !(data.currentItem.progress > 0f)) && (bool)canDoInput.Invoke(value, null) && !Traverse.Create((object)__instance).Property("lockedFromSwitching", (object[])null).GetValue<bool>())
{
Optionable<byte> currentSelectedSlot = __instance.currentSelectedSlot;
bool flag = currentSelectedSlot.IsSome && currentSelectedSlot.Value == 4;
Log.LogDebug((object)(flag ? "Key 5: putting slot 5 away" : "Key 5: equipping slot 5"));
__instance.EquipSlot(flag ? Optionable<byte>.None : Optionable<byte>.Some((byte)4));
}
}
}
}
[HarmonyPatch(typeof(CharacterItems), "DropAllItems")]
private static class DropAllItemsPatch
{
private static void Prefix(CharacterItems __instance, bool __0)
{
//IL_0017: 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_0055: Unknown result type (might be due to invalid IL or missing references)
Character value = Traverse.Create((object)__instance).Field("character").GetValue<Character>();
Optionable<byte> currentSelectedSlot = __instance.currentSelectedSlot;
if (!__0 && !((Object)(object)value == (Object)null) && value.IsLocal && currentSelectedSlot.IsSome && currentSelectedSlot.Value == 4)
{
Log.LogDebug((object)"Passing out while holding the fanny pack: putting it away instead of dropping it");
__instance.EquipSlot(Optionable<byte>.None);
}
}
private static void Postfix(CharacterItems __instance, bool __0)
{
//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_005b: 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_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
Character value = Traverse.Create((object)__instance).Field("character").GetValue<Character>();
if (__0 && !((Object)(object)value == (Object)null) && value.IsLocal && !((Object)(object)value.player == (Object)null) && !((ItemSlot)Fanny(value.player)).IsEmpty())
{
Vector3 val = value.Center + Vector3.up * 1.5f;
Log.LogDebug((object)"Dropping slot 5 (drop all)");
Traverse.Create((object)__instance).Field("photonView").GetValue<PhotonView>()
.RPC("DropItemFromSlotRPC", (RpcTarget)0, new object[2]
{
(byte)4,
val
});
}
}
}
[HarmonyPatch(typeof(CharacterItems), "Update")]
private static class SpawnTestPacksPatch
{
private static void Postfix()
{
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: 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)
//IL_009b: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: 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)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: 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)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: 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_00e2: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: 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_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
Character localCharacter = Character.localCharacter;
if (!SpawnTestPacks.Value || (Object)(object)localCharacter == (Object)null || !PhotonNetwork.IsMasterClient)
{
return;
}
if ((Object)(object)localCharacter != (Object)(object)spawnTarget)
{
spawnTarget = localCharacter;
spawnAt = Time.time + 3f;
}
else if (!(spawnAt < 0f) && !(Time.time < spawnAt))
{
spawnAt = -1f;
Camera main = Camera.main;
Vector3 val = Vector3.ProjectOnPlane(((Object)(object)main != (Object)null) ? ((Component)main).transform.forward : ((Component)localCharacter).transform.forward, Vector3.up);
Vector3 normalized = ((Vector3)(ref val)).normalized;
Vector3 val2 = Vector3.Cross(Vector3.up, normalized);
Vector3 val3 = localCharacter.Center + normalized * 1.5f + Vector3.up * 0.5f;
try
{
PhotonNetwork.InstantiateItemRoom("Backpack", val3 - val2 * 0.5f, Quaternion.identity, true);
PhotonNetwork.InstantiateItemRoom("Fannypack", val3 + val2 * 0.5f, Quaternion.identity, true);
Log.LogDebug((object)("Spawned test backpack + fanny pack at " + val3));
}
catch (Exception ex)
{
Log.LogError((object)("Test pack spawn failed: " + ex));
}
}
}
}
[HarmonyPatch(typeof(InventoryItemUI), "SetItem")]
private static class GhostIconPatch
{
private static void Postfix(InventoryItemUI __instance, ItemSlot __0)
{
//IL_009f: 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)
GUIManager instance = GUIManager.instance;
if ((Object)(object)instance == (Object)null || (Object)(object)__instance == (Object)null)
{
return;
}
bool flag = (Object)(object)__instance == (Object)(object)fannyUI && (Object)(object)fannyUI != (Object)null;
if (!flag && (Object)(object)__instance != (Object)(object)instance.backpack)
{
return;
}
Character observedCharacter = Character.observedCharacter;
if ((Object)(object)observedCharacter == (Object)null)
{
return;
}
bool flag2 = (Object)(object)observedCharacter.data.carriedPlayer != (Object)null;
if (flag2 && !flag)
{
return;
}
RawImage icon = __instance.icon;
if (__0 != null && !__0.IsEmpty())
{
if (flag2)
{
icon.texture = (Texture)(object)__0.prefab.UIData.GetIcon();
((Graphic)icon).color = Color.white;
((Behaviour)icon).enabled = true;
}
return;
}
Texture val = (flag ? GhostIcon("Fannypack", ref fannyGhost) : GhostIcon("Backpack", ref backpackGhost));
if (!((Object)(object)val == (Object)null))
{
icon.texture = val;
((Graphic)icon).color = new Color(1f, 1f, 1f, 0.22f);
((Behaviour)icon).enabled = true;
}
}
}
[HarmonyPatch(typeof(GUIManager), "UpdateItems")]
private static class UpdateItemsPatch
{
private static void Postfix(GUIManager __instance)
{
Character observedCharacter = Character.observedCharacter;
if (!((Object)(object)observedCharacter == (Object)null) && !((Object)(object)__instance.backpack == (Object)null))
{
if ((Object)(object)fannyUI == (Object)null)
{
fannyUI = MakeFannyUI(__instance.backpack);
}
fannyUI.SetItem((ItemSlot)(object)(((Object)(object)observedCharacter.player != (Object)null) ? Fanny(observedCharacter.player) : null));
PlaceFannyUI(__instance);
}
}
}
[HarmonyPatch(typeof(InventoryItemUI), "SetSelected")]
private static class SetSelectedPatch
{
private static bool Prefix(InventoryItemUI __instance)
{
if (!((Object)(object)fannyUI == (Object)null))
{
return (Object)(object)__instance != (Object)(object)fannyUI;
}
return true;
}
}
[HarmonyPatch(typeof(GUIManager), "LateUpdate")]
private static class FannySelectionVisualPatch
{
private static void Postfix(GUIManager __instance)
{
//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_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Expected O, but got Unknown
//IL_00b2: 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)
if ((Object)(object)fannyUI == (Object)null || (Object)(object)sizedFanny != (Object)(object)fannyUI)
{
return;
}
Character observedCharacter = Character.observedCharacter;
if (!((Object)(object)observedCharacter == (Object)null) && !((Object)(object)observedCharacter.player == (Object)null))
{
Optionable<byte> currentSelectedSlot = observedCharacter.refs.items.currentSelectedSlot;
bool flag = currentSelectedSlot.IsSome && currentSelectedSlot.Value == 4 && !((ItemSlot)Fanny(observedCharacter.player)).IsEmpty();
fannyPop = Mathf.MoveTowards(fannyPop, flag ? 1f : 0f, Time.unscaledDeltaTime * 6f);
RectTransform val = (RectTransform)((Component)fannyUI).transform;
val.sizeDelta = slotBaseSize * Mathf.Lerp(1f, 1.2f, Mathf.SmoothStep(0f, 1f, fannyPop));
if ((Object)(object)fannyUI.fill != (Object)null)
{
((Behaviour)fannyUI.fill).enabled = flag;
}
if ((Object)(object)fannyUI.nameText != (Object)null)
{
((Behaviour)fannyUI.nameText).enabled = flag;
}
PlaceFannyUI(__instance);
}
}
}
[HarmonyPatch(typeof(CharacterItems), "EquipSlot")]
private static class NoEmptyPackSlotPatch
{
private static bool Prefix(CharacterItems __instance, ref Optionable<byte> __0)
{
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
if (!__0.IsSome || (__0.Value != 3 && __0.Value != 4))
{
return true;
}
Character value = Traverse.Create((object)__instance).Field("character").GetValue<Character>();
if ((Object)(object)value == (Object)null || !value.IsLocal || (Object)(object)value.player == (Object)null)
{
return true;
}
ItemSlot itemSlot = value.player.GetItemSlot(__0.Value);
if (itemSlot != null && !itemSlot.IsEmpty())
{
return true;
}
if (value.input.selectSlotForwardWasPressed)
{
__0 = Optionable<byte>.Some((byte)0);
return true;
}
if (value.input.selectSlotBackwardWasPressed)
{
__0 = Optionable<byte>.Some((byte)(value.player.itemSlots.Length - 1));
return true;
}
return false;
}
}
public const byte FannySlotId = 4;
private const ushort NoItem = ushort.MaxValue;
internal static ConfigEntry<float> PackWeightMultiplier;
internal static ConfigEntry<float> ContentsWeightMultiplier;
internal static ConfigEntry<bool> SpawnTestPacks;
internal static ConfigEntry<float> WheelHotbarOffset;
internal static ManualLogSource Log;
private static readonly ConditionalWeakTable<Player, BackpackSlot> fannySlots = new ConditionalWeakTable<Player, BackpackSlot>();
private static readonly MethodInfo toManagedArray = AccessTools.Method(AccessTools.TypeByName("Zorro.Core.Serizalization.IBinarySerializable"), "ToManagedArray", (Type[])null, (Type[])null).MakeGenericMethod(typeof(InventorySyncData));
private static readonly ConditionalWeakTable<object, Player> syncOwners = new ConditionalWeakTable<object, Player>();
private static ushort lastReadId = ushort.MaxValue;
private static ItemInstanceData lastReadData;
private static bool lastReadValid;
private static int serializeDepth;
private static Character spawnTarget;
private static float spawnAt;
private static InventoryItemUI fannyUI;
private static RectTransform shiftedLayout;
private static InventoryItemUI sizedFanny;
private static Vector2 slotBaseSize;
private static Vector2 restPos;
private static bool hasRestPos;
private static Texture backpackGhost;
private static Texture fannyGhost;
private static float fannyPop;
private void Awake()
{
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Expected O, but got Unknown
PackWeightMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "PackWeightMultiplier", 0.5f, "Weight multiplier for the worn bags themselves (1 = vanilla, 0 = weightless).");
ContentsWeightMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ContentsWeightMultiplier", 0.7f, "Weight multiplier for items stored inside a worn bag: 0.7 = each item is 30% lighter (1 = vanilla, 0 = weightless).");
WheelHotbarOffset = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "WheelHotbarOffset", 0f, "Extra distance (UI pixels) between the bag wheel and the hotbar shown under it. Negative moves it up.");
SpawnTestPacks = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "SpawnTestPacks", false, "Testing aid: spawn a backpack and a fanny pack in front of you each time you load into a level (host only).");
Log = ((BaseUnityPlugin)this).Logger;
new Harmony("databaze.peak.doubleup").PatchAll();
GameObject val = new GameObject("DoubleUp_BagPanel");
Object.DontDestroyOnLoad((Object)(object)val);
((Object)val).hideFlags = (HideFlags)61;
val.AddComponent<BagPanel>();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Double Up loaded");
}
public static BackpackSlot Fanny(Player p)
{
return fannySlots.GetValue(p, (Player _) => new BackpackSlot((byte)4));
}
private static bool IsFanny(Item prefab)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Invalid comparison between Unknown and I4
Backpack val = (Backpack)(object)((prefab is Backpack) ? prefab : null);
if ((Object)(object)val != (Object)null)
{
return (int)val.backpackType == 2;
}
return false;
}
internal static void BroadcastInventory(Player p)
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
InventorySyncData val = default(InventorySyncData);
((InventorySyncData)(ref val))..ctor(p.itemSlots, p.backpackSlot, p.tempFullSlot);
byte[] array = (byte[])toManagedArray.Invoke(null, new object[1] { val });
Traverse.Create((object)p).Field("view").GetValue<PhotonView>()
.RPC("SyncInventoryRPC", (RpcTarget)1, new object[2] { array, false });
}
private static void PackWeight(BackpackSlot slot, out int contents, out int self)
{
contents = 0;
self = 0;
BackpackData val = default(BackpackData);
if (slot == null || ((ItemSlot)slot).IsEmpty() || ((ItemSlot)slot).data == null || !((ItemSlot)slot).data.TryGetDataEntry<BackpackData>((DataEntryKey)7, ref val))
{
return;
}
ItemSlot[] itemSlots = val.itemSlots;
foreach (ItemSlot val2 in itemSlots)
{
if (!val2.IsEmpty())
{
contents += val2.prefab.CarryWeight;
}
}
Item val3 = default(Item);
if (ItemDatabase.TryGetItem(((ItemSlot)slot).GetPrefabName(), ref val3))
{
self = val3.CarryWeight;
}
}
private static InventoryItemUI MakeFannyUI(InventoryItemUI src)
{
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Invalid comparison between Unknown and I4
GameObject val = Object.Instantiate<GameObject>(((Component)src).gameObject, ((Component)src).transform.parent);
((Object)val).name = "DoubleUp_FannypackSlot";
val.transform.SetAsLastSibling();
LayoutElement val2 = val.GetComponent<LayoutElement>();
if ((Object)(object)val2 == (Object)null)
{
val2 = val.AddComponent<LayoutElement>();
}
val2.ignoreLayout = true;
InventoryItemUI[] componentsInChildren = val.GetComponentsInChildren<InventoryItemUI>(true);
foreach (InventoryItemUI val3 in componentsInChildren)
{
if ((Object)(object)((Component)val3).gameObject != (Object)(object)val)
{
Object.Destroy((Object)(object)((Component)val3).gameObject);
}
}
InputIcon[] componentsInChildren2 = val.GetComponentsInChildren<InputIcon>(true);
foreach (InputIcon val4 in componentsInChildren2)
{
if ((int)val4.action != 10)
{
continue;
}
TMP_Text component = ((Component)val4).GetComponent<TMP_Text>();
Object.DestroyImmediate((Object)(object)val4);
if (!((Object)(object)component == (Object)null))
{
string text = null;
try
{
text = SingletonAsset<InputSpriteData>.Instance.GetSpriteTagFromInputPathKeyboard("<Keyboard>/5");
}
catch (Exception)
{
}
component.text = ((string.IsNullOrEmpty(text) || text == "<sprite=124 tint=1>") ? "5" : text);
}
}
return val.GetComponent<InventoryItemUI>();
}
private static void PlaceFannyUI(GUIManager gui)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0168: Unknown result type (might be due to invalid IL or missing references)
//IL_016d: 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)
//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_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_019b: Unknown result type (might be due to invalid IL or missing references)
//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
//IL_0146: Unknown result type (might be due to invalid IL or missing references)
//IL_0152: Unknown result type (might be due to invalid IL or missing references)
//IL_0157: Unknown result type (might be due to invalid IL or missing references)
//IL_01be: Unknown result type (might be due to invalid IL or missing references)
RectTransform val = (RectTransform)((Component)gui.backpack).transform;
RectTransform val2 = (RectTransform)((Component)fannyUI).transform;
Transform parent = ((Transform)val).parent;
RectTransform val3 = (RectTransform)(object)((parent is RectTransform) ? parent : null);
HorizontalLayoutGroup val4 = (((Object)(object)val3 != (Object)null) ? ((Component)val3).GetComponent<HorizontalLayoutGroup>() : null);
float num = (((Object)(object)val4 != (Object)null) ? ((HorizontalOrVerticalLayoutGroup)val4).spacing : 10f);
if ((Object)(object)sizedFanny != (Object)(object)fannyUI)
{
slotBaseSize = Traverse.Create((object)gui.backpack).Field("startingSizeDelta").GetValue<Vector2>();
if (slotBaseSize.x < 1f)
{
Rect rect = val.rect;
slotBaseSize = ((Rect)(ref rect)).size;
}
val2.anchorMin = val.anchorMin;
val2.anchorMax = val.anchorMax;
val2.pivot = val.pivot;
((Transform)val2).localScale = ((Transform)val).localScale;
val2.sizeDelta = slotBaseSize;
Traverse.Create((object)fannyUI).Field("startingSizeDelta").SetValue((object)slotBaseSize);
sizedFanny = fannyUI;
hasRestPos = false;
}
float num2 = slotBaseSize.x + num;
if ((Object)(object)val3 != (Object)null && (Object)(object)shiftedLayout != (Object)(object)val3)
{
val3.anchoredPosition -= new Vector2(num2, 0f);
shiftedLayout = val3;
}
Rect rect2 = val.rect;
bool flag = Mathf.Abs(((Rect)(ref rect2)).width - slotBaseSize.x) < 0.5f;
if (flag || !hasRestPos)
{
restPos = val.anchoredPosition + new Vector2(num2, 0f);
hasRestPos = flag;
}
val2.anchoredPosition = restPos;
}
private static Texture GhostIcon(string prefabName, ref Texture cache)
{
Item val = default(Item);
if ((Object)(object)cache == (Object)null && ItemDatabase.TryGetItem(prefabName, ref val))
{
cache = (Texture)(object)val.UIData.GetIcon();
}
return cache;
}
}
public class BagPanel : MonoBehaviour
{
[HarmonyPatch(typeof(BackpackWheel), "Update")]
private static class WheelUpdatePatch
{
private static void Prefix(out bool __state)
{
__state = false;
Character localCharacter = Character.localCharacter;
if (IsOpen && !((Object)(object)localCharacter == (Object)null))
{
__state = localCharacter.input.interactIsPressed;
localCharacter.input.interactIsPressed = true;
}
}
private static void Postfix(bool __state)
{
Character localCharacter = Character.localCharacter;
if (IsOpen && (Object)(object)localCharacter != (Object)null)
{
localCharacter.input.interactIsPressed = __state;
}
}
}
[HarmonyPatch(typeof(GUIManager), "UpdateWindowStatus")]
private static class WindowStatusPatch
{
private static readonly MethodInfo setCursor = AccessTools.PropertySetter(typeof(GUIManager), "windowShowingCursor");
private static readonly MethodInfo setBlocking = AccessTools.PropertySetter(typeof(GUIManager), "windowBlockingInput");
private static void Postfix(GUIManager __instance)
{
if (IsOpen)
{
setCursor.Invoke(__instance, new object[1] { true });
setBlocking.Invoke(__instance, new object[1] { true });
}
}
}
[HarmonyPatch(typeof(CharacterInput), "Sample")]
private static class NoLookWhileOpenPatch
{
private static void Postfix(CharacterInput __instance)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
if (IsOpen)
{
__instance.lookInput = Vector2.zero;
}
}
}
private const byte SwapEventCode = 173;
private const byte DropLoc = byte.MaxValue;
private const float DragThreshold = 8f;
private const float HotbarScale = 1.4f;
private const float DropBoxSize = 2.6f;
public static bool IsOpen;
private static byte openPack;
private static int selected = -1;
private static BackpackReference openRef;
private static Backpack openBag;
private static InventoryItemUI[] hotbar;
private bool subscribed;
private static readonly Vector2[] iconPos = (Vector2[])(object)new Vector2[8];
private static readonly int[] iconSlot = new int[8];
private static int iconCount;
private static Vector2 wheelCenter;
private static float ringRadius;
private static int pressLoc = -1;
private static int dragFrom = -1;
private static Vector2 pressPos;
private static GameObject canvasGo;
private static Canvas canvas;
private static RectTransform hotbarRoot;
private static RawImage dragIcon;
private static float slotW;
private static float slotH;
private static RectTransform dropBox;
private static Image dropBoxBg;
private static readonly Color DropIdle = new Color(0.08f, 0.09f, 0.12f, 0.75f);
private static readonly Color DropArmed = new Color(0.55f, 0.18f, 0.15f, 0.85f);
private static readonly Color DropHover = new Color(0.85f, 0.3f, 0.22f, 0.95f);
private static readonly Vector3[] corners = (Vector3[])(object)new Vector3[4];
private static BackpackWheel Wheel
{
get
{
if (!((Object)(object)GUIManager.instance != (Object)null))
{
return null;
}
return GUIManager.instance.backpackWheel;
}
}
private static byte BagBase(byte packSlot)
{
return (byte)((packSlot == 3) ? 30u : 40u);
}
private static BackpackData GetBagData(ItemSlot packSlot, bool create)
{
if (packSlot == null || packSlot.IsEmpty() || packSlot.data == null)
{
return null;
}
BackpackData result = default(BackpackData);
if (packSlot.data.TryGetDataEntry<BackpackData>((DataEntryKey)7, ref result))
{
return result;
}
if (!create)
{
return null;
}
return packSlot.data.RegisterNewEntry<BackpackData>((DataEntryKey)7);
}
private static int BagCapacity(ItemSlot packSlot, BackpackData bd)
{
Item prefab = packSlot.prefab;
Backpack val = (Backpack)(object)((prefab is Backpack) ? prefab : null);
int val2 = (((Object)(object)val != (Object)null) ? val.slotCount : bd.itemSlots.Length);
return Math.Min(val2, bd.itemSlots.Length);
}
private static ItemSlot Resolve(Player p, byte loc, bool create, out bool inBag)
{
inBag = false;
if (loc < p.itemSlots.Length)
{
return p.itemSlots[loc];
}
byte b = (byte)((loc >= 40) ? 4 : ((loc >= 30) ? 3 : byte.MaxValue));
if (b == byte.MaxValue)
{
return null;
}
inBag = true;
ItemSlot itemSlot = p.GetItemSlot(b);
BackpackData bagData = GetBagData(itemSlot, create);
int num = loc - BagBase(b);
if (bagData == null || num >= BagCapacity(itemSlot, bagData))
{
return null;
}
return bagData.itemSlots[num];
}
private static bool AllowedInBag(ItemSlot s)
{
if (!s.IsEmpty())
{
if (s.prefab.UIData.canBackpack)
{
return !(s.prefab is Backpack);
}
return false;
}
return true;
}
private static void ApplySwap(Player p, byte a, byte b, Vector3 dropPos)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
if (b == byte.MaxValue)
{
ApplyDrop(p, a, dropPos);
return;
}
bool inBag;
ItemSlot val = Resolve(p, a, create: true, out inBag);
bool inBag2;
ItemSlot val2 = Resolve(p, b, create: true, out inBag2);
if (a == b || val == null || val2 == null || (val.IsEmpty() && val2.IsEmpty()) || (inBag2 && !AllowedInBag(val)) || (inBag && !AllowedInBag(val2)))
{
return;
}
Optionable<byte> currentSelectedSlot = p.character.refs.items.currentSelectedSlot;
if (!currentSelectedSlot.IsSome || ((inBag || currentSelectedSlot.Value != a) && (inBag2 || currentSelectedSlot.Value != b)))
{
Item prefab = val.prefab;
Item prefab2 = val2.prefab;
ItemInstanceData data = val.data;
ItemInstanceData data2 = val2.data;
if ((Object)(object)prefab2 != (Object)null)
{
val.SetItem(prefab2, data2);
}
else
{
val.EmptyOut();
}
if ((Object)(object)prefab != (Object)null)
{
val2.SetItem(prefab, data);
}
else
{
val2.EmptyOut();
}
RefreshAfterChange(p);
}
}
private static void ApplyDrop(Player p, byte from, Vector3 pos)
{
//IL_0039: 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_0063: 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)
bool inBag;
ItemSlot val = Resolve(p, from, create: false, out inBag);
if (val == null || val.IsEmpty() || !val.prefab.UIData.canDrop)
{
return;
}
Optionable<byte> currentSelectedSlot = p.character.refs.items.currentSelectedSlot;
if (inBag || !currentSelectedSlot.IsSome || currentSelectedSlot.Value != from)
{
if (PhotonNetwork.IsMasterClient)
{
PhotonView component = PhotonNetwork.InstantiateItemRoom(val.GetPrefabName(), pos, Quaternion.identity, true).GetComponent<PhotonView>();
component.RPC("SetItemInstanceDataRPC", (RpcTarget)0, new object[1] { val.data });
}
val.EmptyOut();
RefreshAfterChange(p);
}
}
private static void RefreshAfterChange(Player p)
{
//IL_0012: 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)
Character character = p.character;
Optionable<byte> currentSelectedSlot = character.refs.items.currentSelectedSlot;
Item currentItem = character.data.currentItem;
Backpack val = (Backpack)(object)((currentItem is Backpack) ? currentItem : null);
if ((Object)(object)val != (Object)null)
{
BackpackVisuals component = ((Component)val).GetComponent<BackpackVisuals>();
if ((Object)(object)component != (Object)null)
{
if (PhotonNetwork.IsMasterClient)
{
component.RefreshVisuals();
}
component.RefreshPocketBehaviors(p);
}
}
if (!((ItemSlot)p.backpackSlot).IsEmpty() && (!currentSelectedSlot.IsSome || currentSelectedSlot.Value != 3))
{
BackpackOnBackVisuals activeBackpackVisuals = character.refs.backpackHandler.activeBackpackVisuals;
if ((Object)(object)activeBackpackVisuals != (Object)null)
{
if (PhotonNetwork.IsMasterClient)
{
((BackpackVisuals)activeBackpackVisuals).RefreshVisuals();
}
((BackpackVisuals)activeBackpackVisuals).RefreshPocketBehaviors(p);
}
}
Traverse.Create((object)p).Field("itemsChangedAction").GetValue<Action<ItemSlot[]>>()?.Invoke(p.itemSlots);
if (character.IsLocal)
{
AccessTools.Method(typeof(CharacterAfflictions), "UpdateWeight", (Type[])null, (Type[])null).Invoke(character.refs.afflictions, null);
if (IsOpen)
{
RefreshWheel();
}
}
}
private static void RequestSwap(byte a, byte b)
{
//IL_0028: 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_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: 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_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_0042: 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)
//IL_004d: 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_0057: 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_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: 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_00a0: Expected O, but got Unknown
//IL_00a3: 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)
Character localCharacter = Character.localCharacter;
Camera main = Camera.main;
Vector3 val = Vector3.ProjectOnPlane(((Object)(object)main != (Object)null) ? ((Component)main).transform.forward : ((Component)localCharacter).transform.forward, Vector3.up);
Vector3 normalized = ((Vector3)(ref val)).normalized;
Vector3 val2 = localCharacter.Center + normalized * 0.8f + Vector3.up * 0.3f;
object[] obj = new object[3] { a, b, val2 };
RaiseEventOptions val3 = new RaiseEventOptions();
val3.Receivers = (ReceiverGroup)1;
PhotonNetwork.RaiseEvent((byte)173, (object)obj, val3, SendOptions.SendReliable);
}
private static void OnEvent(EventData e)
{
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
if (e.Code != 173 || !(e.CustomData is object[] array) || array.Length != 3 || !(array[0] is byte) || !(array[1] is byte) || !(array[2] is Vector3))
{
return;
}
foreach (Character allPlayerCharacter in PlayerHandler.GetAllPlayerCharacters())
{
if (!((Object)(object)allPlayerCharacter == (Object)null) && ((MonoBehaviourPun)allPlayerCharacter).photonView.Owner != null && ((MonoBehaviourPun)allPlayerCharacter).photonView.Owner.ActorNumber == e.Sender && !((Object)(object)allPlayerCharacter.player == (Object)null))
{
try
{
ApplySwap(allPlayerCharacter.player, (byte)array[0], (byte)array[1], (Vector3)array[2]);
break;
}
catch (Exception ex)
{
DoubleUp.Log.LogError((object)("Bag swap failed: " + ex));
break;
}
}
}
}
private void Update()
{
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
if (!subscribed && PhotonNetwork.NetworkingClient != null)
{
PhotonNetwork.NetworkingClient.EventReceived += OnEvent;
subscribed = true;
}
Character localCharacter = Character.localCharacter;
GUIManager instance = GUIManager.instance;
if ((Object)(object)localCharacter == (Object)null || (Object)(object)instance == (Object)null)
{
if (IsOpen)
{
Close();
}
return;
}
Item currentItem = localCharacter.data.currentItem;
Backpack val = (Backpack)(object)((currentItem is Backpack) ? currentItem : null);
Optionable<byte> currentSelectedSlot = localCharacter.refs.items.currentSelectedSlot;
bool flag = (Object)(object)val != (Object)null && currentSelectedSlot.IsSome && (currentSelectedSlot.Value == 3 || currentSelectedSlot.Value == 4);
Mouse current = Mouse.current;
Keyboard current2 = Keyboard.current;
if (IsOpen)
{
if ((Object)(object)Wheel == (Object)null || !((Component)Wheel).gameObject.activeSelf || !flag || (Object)(object)val != (Object)(object)openBag || (current2 != null && ((ButtonControl)current2.escapeKey).wasPressedThisFrame) || (current != null && current.rightButton.wasPressedThisFrame))
{
Close();
return;
}
UpdateHotbar(localCharacter.player);
if (current != null)
{
HandleMouse(current);
}
}
else if (flag && current != null && current.rightButton.wasPressedThisFrame && !instance.wheelActive && !GUIManager.InPauseMenu)
{
Open(val, currentSelectedSlot.Value);
}
}
private static void Open(Backpack bag, byte packSlot)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: 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_0039: Unknown result type (might be due to invalid IL or missing references)
openRef = BackpackReference.GetFromBackpackItem((Item)(object)bag);
openBag = bag;
openPack = packSlot;
selected = -1;
pressLoc = -1;
EndDrag();
GUIManager.instance.OpenBackpackWheel(openRef, bag.slotCount, bag.backpackType);
if (!((Object)(object)Wheel == (Object)null) && ((Component)Wheel).gameObject.activeSelf)
{
IsOpen = true;
try
{
EnsureHotbar();
canvasGo.SetActive(true);
}
catch (Exception ex)
{
DoubleUp.Log.LogError((object)("Wheel hotbar setup failed: " + ex));
}
RefreshWheel();
}
}
private static void Close()
{
IsOpen = false;
selected = -1;
pressLoc = -1;
EndDrag();
if ((Object)(object)canvasGo != (Object)null)
{
canvasGo.SetActive(false);
}
if ((Object)(object)Wheel != (Object)null && ((Component)Wheel).gameObject.activeSelf)
{
GUIManager.instance.CloseBackpackWheel();
}
}
private static void RefreshWheel()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: 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_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: 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)
BackpackWheel wheel = Wheel;
if ((Object)(object)wheel == (Object)null)
{
return;
}
Optionable<SliceData> chosenSlice = wheel.chosenSlice;
wheel.InitWheel(openRef, openBag.slotCount, openBag.backpackType);
wheel.chosenSlice = chosenSlice;
BackpackWheelSlice[] slices = wheel.slices;
foreach (BackpackWheelSlice val in slices)
{
if ((Object)(object)val != (Object)null && Traverse.Create((object)val).Property("isBackpackWear", (object[])null).GetValue<bool>())
{
((Component)val).gameObject.SetActive(false);
}
}
ItemSlot val2 = SlotAt(selected);
if (val2 != null && dragFrom < 0)
{
wheel.currentlyHeldItem.texture = (Texture)(object)val2.prefab.UIData.GetIcon();
((Graphic)wheel.currentlyHeldItem).color = Color.white;
((Behaviour)wheel.currentlyHeldItem).enabled = true;
}
else
{
((Behaviour)wheel.currentlyHeldItem).enabled = false;
}
}
private static ItemSlot SlotAt(int loc)
{
Character localCharacter = Character.localCharacter;
if (loc < 0 || (Object)(object)localCharacter == (Object)null || (Object)(object)localCharacter.player == (Object)null)
{
return null;
}
bool inBag;
ItemSlot val = Resolve(localCharacter.player, (byte)loc, create: false, out inBag);
if (val == null || val.IsEmpty())
{
return null;
}
return val;
}
private static int LocationUnderMouse()
{
if (OverDropBox())
{
return 255;
}
int num = HotbarUnderMouse();
if (num >= 0)
{
return num;
}
num = BagSlotNearMouse();
if (num < 0)
{
return HoveredBagSlot();
}
return num;
}
private static void MeasureWheel()
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_016d: Unknown result type (might be due to invalid IL or missing references)
//IL_0174: Unknown result type (might be due to invalid IL or missing references)
//IL_0179: Unknown result type (might be due to invalid IL or missing references)
//IL_0198: Unknown result type (might be due to invalid IL or missing references)
//IL_019d: Unknown result type (might be due to invalid IL or missing references)
//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: 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_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: 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_011b: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: Unknown result type (might be due to invalid IL or missing references)
//IL_013f: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_0142: 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)
iconCount = 0;
BackpackWheel wheel = Wheel;
if ((Object)(object)wheel == (Object)null)
{
return;
}
Canvas componentInParent = ((Component)wheel).GetComponentInParent<Canvas>();
Camera val = (((Object)(object)componentInParent != (Object)null && (int)componentInParent.renderMode != 0) ? componentInParent.worldCamera : null);
Vector2 val2 = Vector2.zero;
BackpackWheelSlice[] slices = wheel.slices;
foreach (BackpackWheelSlice val3 in slices)
{
if (iconCount == iconPos.Length)
{
break;
}
if (!((Object)(object)val3 == (Object)null) && ((Component)val3).gameObject.activeInHierarchy && !((Object)(object)val3.image == (Object)null) && !val3.stashSlice && !val3.jetpackFuelSlice && !val3.isBackpackWear)
{
((RectTransform)((Component)val3.image).transform).GetWorldCorners(corners);
Vector2 val4 = RectTransformUtility.WorldToScreenPoint(val, (corners[0] + corners[2]) * 0.5f);
iconPos[iconCount] = val4;
iconSlot[iconCount] = BagBase(openPack) + val3.backpackSlot;
val2 += val4;
iconCount++;
}
}
if (iconCount != 0)
{
wheelCenter = val2 / (float)iconCount;
float num = 0f;
for (int j = 0; j < iconCount; j++)
{
float num2 = num;
Vector2 val5 = iconPos[j] - wheelCenter;
num = num2 + ((Vector2)(ref val5)).magnitude;
}
ringRadius = ((iconCount > 1) ? (num / (float)iconCount) : (slotH * (((Object)(object)canvas != (Object)null) ? canvas.scaleFactor : 1f) * 1.5f));
}
}
private static int BagSlotNearMouse()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: 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_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: 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)
if (iconCount == 0 || Mouse.current == null)
{
return -1;
}
Vector2 val = ((InputControl<Vector2>)(object)((Pointer)Mouse.current).position).ReadValue();
int num = -1;
float num2 = float.MaxValue;
for (int i = 0; i < iconCount; i++)
{
Vector2 val2 = val - iconPos[i];
float magnitude = ((Vector2)(ref val2)).magnitude;
if (magnitude < num2)
{
num2 = magnitude;
num = i;
}
}
if (num < 0 || !(num2 < ringRadius * 0.9f))
{
return -1;
}
return iconSlot[num];
}
private static void HandleMouse(Mouse mouse)
{
//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_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: 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_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
Vector2 val = ((InputControl<Vector2>)(object)((Pointer)mouse).position).ReadValue();
if (mouse.leftButton.wasPressedThisFrame)
{
pressLoc = LocationUnderMouse();
pressPos = val;
}
if (mouse.leftButton.isPressed && dragFrom < 0 && pressLoc >= 0 && SlotAt(pressLoc) != null)
{
Vector2 val2 = val - pressPos;
if (((Vector2)(ref val2)).magnitude > 8f)
{
BeginDrag(pressLoc);
}
}
if (dragFrom >= 0)
{
MoveDragIcon(val);
}
if (!mouse.leftButton.wasReleasedThisFrame)
{
return;
}
int num = LocationUnderMouse();
if (dragFrom >= 0)
{
if (num >= 0 && num != dragFrom)
{
RequestSwap((byte)dragFrom, (byte)num);
}
EndDrag();
selected = -1;
}
else if (pressLoc >= 0 && num == pressLoc)
{
Click(pressLoc);
}
pressLoc = -1;
RefreshWheel();
}
private static void Click(int loc)
{
if (selected < 0)
{
if (SlotAt(loc) != null)
{
selected = loc;
}
}
else if (selected == loc)
{
selected = -1;
}
else
{
RequestSwap((byte)selected, (byte)loc);
selected = -1;
}
}
private static void BeginDrag(int loc)
{
dragFrom = loc;
selected = -1;
ItemSlot val = SlotAt(loc);
if ((Object)(object)dragIcon != (Object)null && val != null)
{
dragIcon.texture = (Texture)(object)val.prefab.UIData.GetIcon();
((Behaviour)dragIcon).enabled = true;
}
RefreshWheel();
}
private static void EndDrag()
{
dragFrom = -1;
if ((Object)(object)dragIcon != (Object)null)
{
((Behaviour)dragIcon).enabled = false;
}
}
private static void MoveDragIcon(Vector2 screenPos)
{
//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_0035: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)dragIcon == (Object)null) && !((Object)(object)canvas == (Object)null))
{
((RectTransform)((Component)dragIcon).transform).anchoredPosition = screenPos / canvas.scaleFactor;
}
}
private static int HoveredBagSlot()
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
BackpackWheel wheel = Wheel;
if ((Object)(object)wheel == (Object)null || !wheel.chosenSlice.IsSome)
{
return -1;
}
Traverse val = Traverse.Create((object)wheel.chosenSlice.Value);
if (val.Field("isBackpackWear").GetValue<bool>() || val.Field("isStashSlice").GetValue<bool>() || val.Field("isJetpackFuelSlice").GetValue<bool>())
{
return -1;
}
return BagBase(openPack) + val.Field("slotID").GetValue<byte>();
}
private static void EnsureHotbar()
{
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Expected O, but got Unknown
//IL_00c2: 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)
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_0122: Unknown result type (might be due to invalid IL or missing references)
//IL_0134: Unknown result type (might be due to invalid IL or missing references)
//IL_013a: Expected O, but got Unknown
//IL_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_0158: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: Unknown result type (might be due to invalid IL or missing references)
//IL_016c: Unknown result type (might be due to invalid IL or missing references)
//IL_0171: Unknown result type (might be due to invalid IL or missing references)
//IL_0189: Unknown result type (might be due to invalid IL or missing references)
//IL_018e: Unknown result type (might be due to invalid IL or missing references)
//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
//IL_01f4: Expected O, but got Unknown
//IL_0202: Unknown result type (might be due to invalid IL or missing references)
//IL_0207: Unknown result type (might be due to invalid IL or missing references)
//IL_0208: 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_0222: Unknown result type (might be due to invalid IL or missing references)
//IL_022e: Unknown result type (might be due to invalid IL or missing references)
//IL_0244: Unknown result type (might be due to invalid IL or missing references)
//IL_0276: Unknown result type (might be due to invalid IL or missing references)
//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
//IL_02cd: Expected O, but got Unknown
//IL_030d: Unknown result type (might be due to invalid IL or missing references)
//IL_0314: Expected O, but got Unknown
//IL_0318: Unknown result type (might be due to invalid IL or missing references)
//IL_031d: Unknown result type (might be due to invalid IL or missing references)
//IL_031e: Unknown result type (might be due to invalid IL or missing references)
//IL_0325: Unknown result type (might be due to invalid IL or missing references)
//IL_0338: Unknown result type (might be due to invalid IL or missing references)
//IL_0342: Unknown result type (might be due to invalid IL or missing references)
//IL_034c: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)canvasGo != (Object)null))
{
InventoryItemUI[] items = GUIManager.instance.items;
Canvas componentInParent = ((Component)items[0]).GetComponentInParent<Canvas>();
canvasGo = new GameObject("DoubleUp_WheelHotbarCanvas", new Type[2]
{
typeof(RectTransform),
typeof(Canvas)
});
canvas = canvasGo.GetComponent<Canvas>();
canvas.renderMode = (RenderMode)0;
canvas.sortingOrder = 1000;
canvas.scaleFactor = (((Object)(object)componentInParent != (Object)null) ? componentInParent.rootCanvas.scaleFactor : 1f);
hotbarRoot = new GameObject("Hotbar", new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>();
((Transform)hotbarRoot).SetParent(canvasGo.transform, false);
RectTransform obj = hotbarRoot;
Vector2 anchorMin = (hotbarRoot.anchorMax = Vector2.zero);
obj.anchorMin = anchorMin;
hotbarRoot.pivot = new Vector2(0.5f, 1f);
hotbarRoot.sizeDelta = Vector2.zero;
RectTransform val = (RectTransform)((Component)items[0]).transform;
Rect rect = val.rect;
float num;
if (!(((Rect)(ref rect)).width > 1f))
{
num = 80f;
}
else
{
Rect rect2 = val.rect;
num = ((Rect)(ref rect2)).width;
}
slotW = num;
Rect rect3 = val.rect;
float num2;
if (!(((Rect)(ref rect3)).height > 1f))
{
num2 = 80f;
}
else
{
Rect rect4 = val.rect;
num2 = ((Rect)(ref rect4)).height;
}
slotH = num2;
hotbar = (InventoryItemUI[])(object)new InventoryItemUI[items.Length];
for (int i = 0; i < items.Length; i++)
{
GameObject val2 = Object.Instantiate<GameObject>(((Component)items[i]).gameObject, (Transform)(object)hotbarRoot, false);
((Object)val2).name = "Slot" + (i + 1);
val2.SetActive(true);
RectTransform val3 = (RectTransform)val2.transform;
Vector2 anchorMin2 = (val3.anchorMax = new Vector2(0.5f, 0.5f));
val3.anchorMin = anchorMin2;
val3.pivot = new Vector2(0.5f, 1f);
((Transform)val3).localScale = Vector3.one;
val3.sizeDelta = new Vector2(slotW, slotH);
val3.anchoredPosition = new Vector2(((float)i - (float)(items.Length - 1) * 0.5f) * slotW * 1.25f * 1.4f, 0f);
hotbar[i] = val2.GetComponent<InventoryItemUI>();
}
GameObject val5 = new GameObject("DragIcon", new Type[2]
{
typeof(RectTransform),
typeof(RawImage)
});
val5.transform.SetParent(canvasGo.transform, false);
dragIcon = val5.GetComponent<RawImage>();
((Graphic)dragIcon).raycastTarget = false;
((Behaviour)dragIcon).enabled = false;
RectTransform val6 = (RectTransform)val5.transform;
Vector2 anchorMin3 = (val6.anchorMax = Vector2.zero);
val6.anchorMin = anchorMin3;
val6.sizeDelta = new Vector2(slotW, slotH) * 0.8f * 1.4f;
BuildDropBox(items[0]);
DoubleUp.Log.LogDebug((object)("Wheel hotbar built (slot " + slotW + "x" + slotH + ", scale " + canvas.scaleFactor + ")"));
}
}
private static void BuildDropBox(InventoryItemUI style)
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Expected O, but got Unknown
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Expected O, but got Unknown
//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_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: 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_009d: 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_00c1: 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_0107: Expected O, but got Unknown
//IL_011e: Unknown result type (might be due to invalid IL or missing references)
//IL_0124: Expected O, but got Unknown
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
//IL_013c: 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_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Unknown result type (might be due to invalid IL or missing references)
//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("DropBox", new Type[2]
{
typeof(RectTransform),
typeof(Image)
});
val.transform.SetParent(canvasGo.transform, false);
dropBox = (RectTransform)val.transform;
RectTransform obj = dropBox;
Vector2 anchorMin = (dropBox.anchorMax = Vector2.zero);
obj.anchorMin = anchorMin;
dropBox.pivot = new Vector2(0.5f, 0.5f);
dropBox.sizeDelta = new Vector2(slotW, slotH) * 2.6f;
dropBoxBg = val.GetComponent<Image>();
((Graphic)dropBoxBg).color = DropIdle;
((Graphic)dropBoxBg).raycastTarget = false;
GameObject val2 = new GameObject("Label", new Type[2]
{
typeof(RectTransform),
typeof(TextMeshProUGUI)
});
val2.transform.SetParent((Transform)(object)dropBox, false);
RectTransform val3 = (RectTransform)val2.transform;
val3.anchorMin = Vector2.zero;
val3.anchorMax = Vector2.one;
Vector2 offsetMin = (val3.offsetMax = Vector2.zero);
val3.offsetMin = offsetMin;
TextMeshProUGUI component = val2.GetComponent<TextMeshProUGUI>();
if ((Object)(object)style.nameText != (Object)null)
{
((TMP_Text)component).font = ((TMP_Text)style.nameText).font;
}
((TMP_Text)component).text = "DROP";
((TMP_Text)component).fontSize = slotH * 0.2f * 2.6f;
((TMP_Text)component).alignment = (TextAlignmentOptions)514;
((Graphic)component).color = new Color(1f, 1f, 1f, 0.85f);
((Graphic)component).raycastTarget = false;
}
private static void UpdateDropBox()
{
//IL_0062: 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_00a2: 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)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)dropBox == (Object)null))
{
float num = ((canvas.scaleFactor > 0f) ? canvas.scaleFactor : 1f);
dropBox.anchoredPosition = new Vector2((float)Screen.width * 0.03f + slotW * 2.6f * 0.5f * num, (float)Screen.height * 0.5f) / num;
bool flag = dragFrom >= 0 || selected >= 0;
((Graphic)dropBoxBg).color = ((flag && OverDropBox()) ? DropHover : (flag ? DropArmed : DropIdle));
}
}
private static bool OverDropBox()
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)dropBox != (Object)null && Mouse.current != null)
{
return RectTransformUtility.RectangleContainsScreenPoint(dropBox, ((InputControl<Vector2>)(object)((Pointer)Mouse.current).position).ReadValue(), (Camera)null);
}
return false;
}
private static void UpdateHotbar(Player p)
{
//IL_0043: 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_006e: Unknown result type (might be due to invalid IL or missing references)
if (hotbar != null && !((Object)(object)hotbarRoot == (Object)null))
{
PlaceUnderWheel();
UpdateDropBox();
for (int i = 0; i < hotbar.Length && i < p.itemSlots.Length; i++)
{
hotbar[i].SetItem(p.itemSlots[i]);
((Component)hotbar[i]).transform.localScale = Vector3.one * 1.4f * ((selected == i || dragFrom == i) ? 1.15f : 1f);
}
}
}
private static void PlaceUnderWheel()
{
//IL_006f: 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_0074: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
MeasureWheel();
float num = ((canvas.scaleFactor > 0f) ? canvas.scaleFactor : 1f);
Vector2 val = ((iconCount > 0) ? new Vector2(wheelCenter.x, wheelCenter.y - ringRadius * 1.4f) : new Vector2((float)Screen.width * 0.5f, (float)Screen.height * 0.3f));
val.y -= DoubleUp.WheelHotbarOffset.Value * num;
val.y = Mathf.Max(val.y, slotH * 1.1f * num);
hotbarRoot.anchoredPosition = val / num;
}
private static int HotbarUnderMouse()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: 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_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Expected O, but got Unknown
if (hotbar == null || Mouse.current == null)
{
return -1;
}
Vector2 val = ((InputControl<Vector2>)(object)((Pointer)Mouse.current).position).ReadValue();
for (int i = 0; i < hotbar.Length; i++)
{
if (RectTransformUtility.RectangleContainsScreenPoint((RectTransform)((Component)hotbar[i]).transform, val, (Camera)null))
{
return i;
}
}
return -1;
}
}