Decompiled source of BiggerPack v1.0.1

BiggerPack.dll

Decompiled 6 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Photon.Pun;
using Photon.Realtime;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using Zorro.Core;
using Zorro.Core.Serizalization;

[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("BiggerPack")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+426f294cd83fdffa209954308da2e2cccc8574e8")]
[assembly: AssemblyProduct("BiggerPack")]
[assembly: AssemblyTitle("BiggerPack")]
[assembly: AssemblyVersion("1.0.1.0")]
namespace BiggerPack;

[HarmonyPatch(/*Could not decode attribute arguments.*/)]
internal static class PackDataCtor
{
	private static void Postfix(BackpackData __instance)
	{
		__instance.itemSlots = (ItemSlot[])(object)new ItemSlot[8];
	}
}
[HarmonyPatch(typeof(BackpackData), "DeserializeValue")]
internal static class PackDataRead
{
	private static bool Prefix(BackpackData __instance, BinaryDeserializer deserializer)
	{
		//IL_0002: 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_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Expected O, but got Unknown
		//IL_004c: 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)
		InventorySyncData val = default(InventorySyncData);
		((InventorySyncData)(ref val)).Deserialize(deserializer);
		ItemSlot[] itemSlots = __instance.itemSlots;
		int num = ((val.slots != null) ? Math.Min(val.slots.Length, itemSlots.Length) : 0);
		Item val2 = default(Item);
		for (byte b = 0; b < itemSlots.Length; b++)
		{
			if (itemSlots[b] == null)
			{
				itemSlots[b] = new ItemSlot(b);
			}
			if (b < num)
			{
				itemSlots[b].SetItem(ItemDatabase.TryGetItem(val.slots[b].ItemID, ref val2) ? val2 : null, val.slots[b].Data);
			}
			else
			{
				itemSlots[b].SetItem((Item)null, (ItemInstanceData)null);
			}
		}
		return false;
	}
}
internal static class PackSize
{
	internal const int OldSlots = 4;

	internal const int NewSlots = 8;

	internal const int SlicesPerPage = 4;

	internal const int PageCount = 2;

	internal static readonly Vector3 ExtraSlotOffset = Vector3.zero;

	internal static bool IsPaged(BackpackType type, int slotCount, int dataLength)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Invalid comparison between Unknown and I4
		if ((int)type == 1 && slotCount == 8)
		{
			return dataLength == 8;
		}
		return false;
	}

	internal static int ScaleContents(int raw)
	{
		return (int)Math.Ceiling((double)raw * 4.0 / 8.0);
	}
}
[HarmonyPatch(typeof(BackpackVisuals), "RefreshVisuals")]
internal static class PackVisuals
{
	private static readonly HashSet<Type> loggedAdded = new HashSet<Type>();

	private static readonly HashSet<Type> loggedUnchanged = new HashSet<Type>();

	private static readonly FieldRef<BackpackVisuals, BackpackData> BackpackDataRef = AccessTools.FieldRefAccess<BackpackVisuals, BackpackData>("backpackData");

	internal static void EnsureSlots(BackpackVisuals visuals)
	{
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)visuals == (Object)null || visuals.backpackSlots == null || visuals.backpackSlots.Length == 8)
		{
			return;
		}
		Type type = ((object)visuals).GetType();
		int num = visuals.backpackSlots.Length;
		if (num < 4 || num > 8)
		{
			if (loggedUnchanged.Add(type))
			{
				Plugin.Log.LogInfo((object)$"Left backpack visuals with {visuals.backpackSlots.Length} slot anchors unchanged ({type.Name}).");
			}
			return;
		}
		Transform[] array = (Transform[])(object)new Transform[8];
		for (int i = 0; i < array.Length; i++)
		{
			if (i < num)
			{
				array[i] = visuals.backpackSlots[i];
				continue;
			}
			Transform val = visuals.backpackSlots[i - 4];
			Transform transform = new GameObject("BiggerPackSlot" + (i + 1)).transform;
			transform.SetParent(val.parent, false);
			transform.localPosition = val.localPosition + PackSize.ExtraSlotOffset;
			transform.localRotation = val.localRotation;
			transform.localScale = val.localScale;
			array[i] = transform;
		}
		visuals.backpackSlots = array;
		if (loggedAdded.Add(type))
		{
			Plugin.Log.LogInfo((object)$"Extended {type.Name} slot anchors from {num} to 8.");
		}
	}

	internal static int LoopCount(BackpackVisuals visuals)
	{
		return Math.Min(BackpackDataRef.Invoke(visuals).itemSlots.Length, (visuals.backpackSlots != null) ? visuals.backpackSlots.Length : 0);
	}

	private static void Prefix(BackpackVisuals __instance)
	{
		EnsureSlots(__instance);
	}

	private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: Expected O, but got Unknown
		List<CodeInstruction> list = instructions.ToList();
		List<(CodeInstruction, int)> list2 = (from pair in list.Select((CodeInstruction code, int index) => (code: code, index: index))
			where pair.code.opcode == OpCodes.Ldc_I4_4
			select pair).ToList();
		if (list2.Count != 1)
		{
			Plugin.PatchProblem = "anchor not found: RefreshVisuals ldc.i4.4 count " + list2.Count;
			return list;
		}
		int item = list2[0].Item2;
		list[item].opcode = OpCodes.Ldarg_0;
		list[item].operand = null;
		list.Insert(item + 1, new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(PackVisuals), "LoopCount", (Type[])null, (Type[])null)));
		return list;
	}
}
[HarmonyPatch(typeof(Item), "PutInBackpackRPC")]
internal static class PackVisualsRpc
{
	private static void Prefix(BackpackReference backpackReference)
	{
		PackVisuals.EnsureSlots(((BackpackReference)(ref backpackReference)).GetVisuals());
	}
}
[HarmonyPatch(typeof(CharacterAfflictions), "UpdateWeight")]
internal static class PackWeight
{
	private static bool scale;

	private static int raw;

	private static int given;

	internal static int LastRaw;

	internal static int LastScaled;

	private static void Prefix(CharacterAfflictions __instance)
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Invalid comparison between Unknown and I4
		BackpackSlot val = (((Object)(object)__instance.character != (Object)null && (Object)(object)__instance.character.player != (Object)null) ? __instance.character.player.backpackSlot : null);
		scale = val != null && (int)val.backpackType == 1;
		raw = 0;
		given = 0;
		LastRaw = 0;
		LastScaled = 0;
	}

	internal static int ContentWeight(Item prefab)
	{
		raw += prefab.CarryWeight;
		int num = (scale ? PackSize.ScaleContents(raw) : raw);
		int result = num - given;
		given = num;
		LastRaw = raw;
		LastScaled = given;
		return result;
	}

	private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		List<CodeInstruction> list = instructions.ToList();
		FieldInfo slotsField = AccessTools.Field(typeof(BackpackData), "itemSlots");
		MethodInfo weightGetter = AccessTools.PropertyGetter(typeof(Item), "CarryWeight");
		List<int> list2 = (from pair in list.Select((CodeInstruction code, int index) => (code: code, index: index))
			where CodeInstructionExtensions.LoadsField(pair.code, slotsField, false)
			select pair.index).ToList();
		int num = ((list2.Count == 2) ? list2[0] : (-1));
		int num2 = ((num < 0) ? (-1) : list.FindIndex(num, (CodeInstruction code) => CodeInstructionExtensions.Calls(code, weightGetter)));
		if (num2 < 0 || num2 > list2[1])
		{
			Plugin.PatchProblem = "anchor not found: UpdateWeight contents weight";
			return list;
		}
		list[num2].opcode = OpCodes.Call;
		list[num2].operand = AccessTools.Method(typeof(PackWeight), "ContentWeight", (Type[])null, (Type[])null);
		return list;
	}
}
[BepInPlugin("t0y9n.peak.biggerpack", "BiggerPack", "1.0.1")]
public sealed class Plugin : BaseUnityPlugin
{
	internal const string Guid = "t0y9n.peak.biggerpack";

	internal const string Version = "1.0.1";

	internal const string Protocol = "1.0.0";

	internal static ManualLogSource Log;

	internal static bool Active;

	internal static string PatchProblem;

	private static Harmony harmony;

	private static readonly (string, Type)[] PatchRows = new(string, Type)[13]
	{
		("data ctor", typeof(PackDataCtor)),
		("data read", typeof(PackDataRead)),
		("wheel open", typeof(WheelOpen)),
		("wheel init", typeof(WheelInit)),
		("wheel update", typeof(WheelUpdate)),
		("wheel hover", typeof(StashHover)),
		("wheel stash", typeof(StashAttempt)),
		("visuals refresh", typeof(PackVisuals)),
		("visuals rpc", typeof(PackVisualsRpc)),
		("weight", typeof(PackWeight)),
		("slice hover", typeof(SliceHover)),
		("slice dehover", typeof(SliceDehover)),
		("gamepad select", typeof(GamepadSelect))
	};

	private void Awake()
	{
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Expected O, but got Unknown
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Invalid comparison between Unknown and I4
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		if (!((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Give the normal backpack 8 slots on two wheel pages and count its contents at half weight. Read once at start; restart the game after changing it.").Value)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"BiggerPack 1.0.1 loaded. Enabled = false; nothing is patched.");
			return;
		}
		harmony = new Harmony("t0y9n.peak.biggerpack");
		(string, Type)[] patchRows = PatchRows;
		for (int i = 0; i < patchRows.Length; i++)
		{
			var (row, type) = patchRows[i];
			try
			{
				harmony.CreateClassProcessor(type).Patch();
			}
			catch (Exception ex)
			{
				TurnOff(row, ex.GetType().Name);
				return;
			}
			if (PatchProblem != null)
			{
				TurnOff(row, PatchProblem);
				return;
			}
		}
		Active = true;
		GameObject val = ((Component)this).gameObject;
		if ((((Object)val).hideFlags & 0x3D) == 61)
		{
			val = new GameObject("BiggerPack services");
			Object.DontDestroyOnLoad((Object)(object)val);
		}
		val.AddComponent<RoomCheck>();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"BiggerPack 1.0.1 loaded. Backpack slots: 8.");
	}

	internal static void TurnOff(string row, string reason)
	{
		harmony.UnpatchSelf();
		Active = false;
		Log.LogError((object)("BiggerPack is off: could not apply " + row + " (" + reason + "). The game runs unchanged."));
	}
}
internal sealed class RoomCheck : MonoBehaviour, IMatchmakingCallbacks
{
	internal const string PropertyKey = "t0y9n.biggerpack";

	private static bool Checked;

	private bool lateProblemHandled;

	private void OnEnable()
	{
		PhotonNetwork.AddCallbackTarget((object)this);
	}

	private void OnDisable()
	{
		PhotonNetwork.RemoveCallbackTarget((object)this);
	}

	private void Start()
	{
		if (Plugin.PatchProblem != null)
		{
			Plugin.TurnOff("late rebuild", Plugin.PatchProblem);
			return;
		}
		(string, MethodBase)[] array = new(string, MethodBase)[5]
		{
			("BackpackData.ctor", AccessTools.Constructor(typeof(BackpackData), Type.EmptyTypes, false)),
			("BackpackData.Init", AccessTools.Method(typeof(BackpackData), "Init", (Type[])null, (Type[])null)),
			("BackpackData.DeserializeValue", AccessTools.Method(typeof(BackpackData), "DeserializeValue", (Type[])null, (Type[])null)),
			("BackpackData.SerializeValue", AccessTools.Method(typeof(BackpackData), "SerializeValue", (Type[])null, (Type[])null)),
			("BackpackWheel.InitWheel", AccessTools.Method(typeof(BackpackWheel), "InitWheel", (Type[])null, (Type[])null))
		};
		for (int i = 0; i < array.Length; i++)
		{
			(string, MethodBase) tuple = array[i];
			string item = tuple.Item1;
			Patches patchInfo = Harmony.GetPatchInfo(tuple.Item2);
			if (patchInfo == null)
			{
				continue;
			}
			foreach (string owner in patchInfo.Owners)
			{
				if (owner != "t0y9n.peak.biggerpack")
				{
					Plugin.TurnOff(item, "also patched by " + owner);
					return;
				}
			}
		}
		Checked = true;
		if (PhotonNetwork.InRoom)
		{
			Announce();
		}
	}

	private void Update()
	{
		//IL_0031: 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_0042: Expected O, but got Unknown
		//IL_0049: Expected O, but got Unknown
		if (!lateProblemHandled && Checked && Plugin.Active && Plugin.PatchProblem != null)
		{
			lateProblemHandled = true;
			if (PhotonNetwork.InRoom)
			{
				Player localPlayer = PhotonNetwork.LocalPlayer;
				Hashtable val = new Hashtable();
				((Dictionary<object, object>)val).Add((object)"t0y9n.biggerpack", (object)null);
				localPlayer.SetCustomProperties(val, (Hashtable)null, (WebFlags)null);
			}
			Plugin.Log.LogError((object)("BiggerPack: another mod changed a patched method after start (" + Plugin.PatchProblem + "). Slots 5-8 are locked until the game restarts."));
		}
	}

	private static void Announce()
	{
		//IL_001b: 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_0030: Expected O, but got Unknown
		//IL_0037: Expected O, but got Unknown
		if (Checked && Plugin.Active && Plugin.PatchProblem == null)
		{
			Player localPlayer = PhotonNetwork.LocalPlayer;
			Hashtable val = new Hashtable();
			((Dictionary<object, object>)val).Add((object)"t0y9n.biggerpack", (object)"1.0.0");
			localPlayer.SetCustomProperties(val, (Hashtable)null, (WebFlags)null);
			Plugin.Log.LogInfo((object)"Announced BiggerPack 1.0.1 to the room.");
		}
	}

	internal static bool AllReady()
	{
		if (Plugin.PatchProblem != null)
		{
			return false;
		}
		if (PhotonNetwork.OfflineMode)
		{
			return true;
		}
		if (!PhotonNetwork.InRoom)
		{
			return false;
		}
		Player[] playerList = PhotonNetwork.PlayerList;
		for (int i = 0; i < playerList.Length; i++)
		{
			if (!((Dictionary<object, object>)(object)playerList[i].CustomProperties).TryGetValue((object)"t0y9n.biggerpack", out object value) || !(value is string text) || text != "1.0.0")
			{
				return false;
			}
		}
		return true;
	}

	public void OnJoinedRoom()
	{
		Announce();
	}

	public void OnFriendListUpdate(List<FriendInfo> friendList)
	{
	}

	public void OnCreatedRoom()
	{
	}

	public void OnCreateRoomFailed(short returnCode, string message)
	{
	}

	public void OnJoinRoomFailed(short returnCode, string message)
	{
	}

	public void OnJoinRandomFailed(short returnCode, string message)
	{
	}

	public void OnLeftRoom()
	{
	}
}
[HarmonyPatch(typeof(BackpackWheelSlice), "Hover")]
internal static class SliceHover
{
	internal static BackpackWheelSlice Current;

	internal static BackpackWheelSlice RefusedBy;

	internal static readonly FieldRef<BackpackWheelSlice, BackpackWheel> Wheel = AccessTools.FieldRefAccess<BackpackWheelSlice, BackpackWheel>("backpackWheel");

	private static void Postfix(BackpackWheelSlice __instance)
	{
		Current = __instance;
		BackpackWheel val = Wheel.Invoke(__instance);
		RefusedBy = (((Object)(object)val != (Object)null && ((TMP_Text)val.chosenItemText).text == "Slots 5-8 need BiggerPack on every player.") ? __instance : null);
	}
}
[HarmonyPatch(typeof(BackpackWheelSlice), "Dehover")]
internal static class SliceDehover
{
	private static void Postfix(BackpackWheelSlice __instance)
	{
		if ((Object)(object)SliceHover.Current == (Object)(object)__instance)
		{
			SliceHover.Current = null;
		}
		if ((Object)(object)SliceHover.RefusedBy == (Object)(object)__instance)
		{
			BackpackWheel val = SliceHover.Wheel.Invoke(__instance);
			if ((Object)(object)val != (Object)null && ((TMP_Text)val.chosenItemText).text == "Slots 5-8 need BiggerPack on every player.")
			{
				((TMP_Text)val.chosenItemText).text = "";
			}
			SliceHover.RefusedBy = null;
		}
	}
}
[HarmonyPatch(typeof(BackpackWheel), "TestSelectSliceGamepad")]
internal static class GamepadSelect
{
	private static void Postfix(BackpackWheel __instance, Vector2 gamepadVector)
	{
		if (!(((Vector2)(ref gamepadVector)).sqrMagnitude < 0.5f))
		{
			return;
		}
		if ((Object)(object)SliceHover.Current != (Object)null && (Object)(object)SliceHover.Wheel.Invoke(SliceHover.Current) == (Object)(object)__instance)
		{
			SliceHover.Current = null;
		}
		if ((Object)(object)SliceHover.RefusedBy != (Object)null && (Object)(object)SliceHover.Wheel.Invoke(SliceHover.RefusedBy) == (Object)(object)__instance)
		{
			if (((TMP_Text)__instance.chosenItemText).text == "Slots 5-8 need BiggerPack on every player.")
			{
				((TMP_Text)__instance.chosenItemText).text = "";
			}
			SliceHover.RefusedBy = null;
		}
	}
}
internal static class StashGate
{
	internal const string RefusedLine = "Slots 5-8 need BiggerPack on every player.";
}
[HarmonyPatch(typeof(BackpackWheel), "Hover")]
internal static class StashHover
{
	private static void Postfix(BackpackWheel __instance, SliceData sliceData)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: 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_0039: 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_0073: Unknown result type (might be due to invalid IL or missing references)
		if (!sliceData.isBackpackWear && !sliceData.isStashSlice && !sliceData.isJetpackFuelSlice && sliceData.slotID >= 4 && !RoomCheck.AllReady() && ((BackpackReference)(ref __instance.backpack)).GetData().itemSlots[sliceData.slotID].IsEmpty() && Object.op_Implicit((Object)(object)Character.localCharacter.data.currentItem))
		{
			((TMP_Text)__instance.chosenItemText).text = "Slots 5-8 need BiggerPack on every player.";
			__instance.chosenSlice = Optionable<SliceData>.None;
		}
	}
}
[HarmonyPatch(typeof(BackpackWheel), "TryStash")]
internal static class StashAttempt
{
	private static bool Prefix(BackpackWheel __instance, byte backpackSlotID)
	{
		if (backpackSlotID < 4)
		{
			return true;
		}
		if (!((BackpackReference)(ref __instance.backpack)).GetData().itemSlots[backpackSlotID].IsEmpty())
		{
			Plugin.Log.LogInfo((object)$"Stash into slot {backpackSlotID + 1} refused: the slot is not empty.");
			return false;
		}
		if (RoomCheck.AllReady())
		{
			return true;
		}
		Plugin.Log.LogInfo((object)$"Stash into slot {backpackSlotID + 1} refused: not every player in the room has BiggerPack.");
		return false;
	}
}
internal static class WheelPages
{
	internal static int Page;

	internal static bool Paged;

	internal static TextMeshProUGUI Label;

	internal static int SlotCount;

	internal static Button Next;

	internal static Button Prev;

	private static bool arrowsMissingLogged;

	internal static bool Opening;

	internal static string PageText(int page)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Invalid comparison between Unknown and I4
		return (((int)LocalizedText.CURRENT_LANGUAGE == 11) ? "ポケット " : "Pocket ") + (page + 1) + "/" + 2;
	}

	internal static int VisibleCount(ItemSlot[] slots)
	{
		return Math.Min(slots.Length, 4);
	}

	internal static int SliceIndex(int slotID)
	{
		return slotID % 4;
	}

	internal static void Turn(BackpackWheel wheel, int step)
	{
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)wheel == (Object)null || !((Component)wheel).gameObject.activeSelf || !Paged)
		{
			return;
		}
		int num = Mathf.Clamp(Page + step, 0, 1);
		if (num != Page)
		{
			Page = num;
			wheel.InitWheel(wheel.backpack, SlotCount, wheel.backpackType);
			BackpackWheelSlice current = SliceHover.Current;
			if ((Object)(object)current != (Object)null && (Object)(object)SliceHover.Wheel.Invoke(current) == (Object)(object)wheel && ((Component)current).gameObject.activeInHierarchy)
			{
				current.Hover();
			}
		}
	}

	internal static void ShowArrows(BackpackWheel wheel)
	{
		if ((Object)(object)wheel != (Object)null && (((Object)(object)Next != (Object)null && (Object)(object)((Component)Next).transform.parent != (Object)(object)((Component)wheel).transform) || ((Object)(object)Prev != (Object)null && (Object)(object)((Component)Prev).transform.parent != (Object)(object)((Component)wheel).transform)))
		{
			if ((Object)(object)Next != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)Next).gameObject);
			}
			if ((Object)(object)Prev != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)Prev).gameObject);
			}
			Next = (Prev = null);
		}
		if ((Object)(object)wheel != (Object)null && Paged && ((Object)(object)Next == (Object)null || (Object)(object)Prev == (Object)null))
		{
			MakeArrows(wheel);
		}
		if ((Object)(object)Next != (Object)null)
		{
			((Component)Next).gameObject.SetActive(Paged && Page + 1 < 2);
		}
		if ((Object)(object)Prev != (Object)null)
		{
			((Component)Prev).gameObject.SetActive(Paged && Page > 0);
		}
	}

	private static void MakeArrows(BackpackWheel wheel)
	{
		EmoteWheel val = (((Object)(object)GUIManager.instance != (Object)null && (Object)(object)GUIManager.instance.emoteWheel != (Object)null) ? GUIManager.instance.emoteWheel.GetComponentInChildren<EmoteWheel>(true) : null);
		if ((Object)(object)val == (Object)null || (Object)(object)val.nextButton == (Object)null || (Object)(object)val.prevButton == (Object)null)
		{
			if (!arrowsMissingLogged)
			{
				Plugin.Log.LogWarning((object)"BiggerPack: the emote wheel arrows were not found; pages turn with the gamepad only.");
			}
			arrowsMissingLogged = true;
			return;
		}
		if ((Object)(object)Next == (Object)null)
		{
			Next = CopyArrow(val, val.nextButton, wheel, 1);
		}
		if ((Object)(object)Prev == (Object)null)
		{
			Prev = CopyArrow(val, val.prevButton, wheel, -1);
		}
	}

	private static Button CopyArrow(EmoteWheel emote, Button source, BackpackWheel wheel, int step)
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Expected O, but got Unknown
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Expected O, but got Unknown
		//IL_006f: 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_007f: 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_0094: 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: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: 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)
		//IL_00e1: 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_00ee: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: 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_028a: Unknown result type (might be due to invalid IL or missing references)
		//IL_028f: Unknown result type (might be due to invalid IL or missing references)
		//IL_029f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e8: 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_01f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
		//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_020c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_022a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0235: Unknown result type (might be due to invalid IL or missing references)
		//IL_0243: Unknown result type (might be due to invalid IL or missing references)
		//IL_0248: Unknown result type (might be due to invalid IL or missing references)
		//IL_024c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0258: Unknown result type (might be due to invalid IL or missing references)
		//IL_025c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0268: Unknown result type (might be due to invalid IL or missing references)
		//IL_026c: Unknown result type (might be due to invalid IL or missing references)
		Button val = Object.Instantiate<Button>(source, ((Component)wheel).transform);
		((Object)val).name = ((step > 0) ? "BiggerPackNextPage" : "BiggerPackPrevPage");
		val.onClick = new ButtonClickedEvent();
		((UnityEvent)val.onClick).AddListener((UnityAction)delegate
		{
			Turn(wheel, step);
		});
		((Component)val).transform.localRotation = Quaternion.Inverse(((Component)emote).transform.rotation) * ((Component)source).transform.rotation;
		Vector3 lossyScale = ((Component)source).transform.lossyScale;
		Vector3 lossyScale2 = ((Component)emote).transform.lossyScale;
		Vector3 val2 = (Vector3)((lossyScale2.x != 0f && lossyScale2.y != 0f && lossyScale2.z != 0f) ? new Vector3(lossyScale.x / lossyScale2.x, lossyScale.y / lossyScale2.y, lossyScale.z / lossyScale2.z) : Vector3.one);
		Transform transform = ((Component)emote).transform;
		RectTransform val3 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
		Transform transform2 = ((Component)wheel).transform;
		RectTransform val4 = (RectTransform)(object)((transform2 is RectTransform) ? transform2 : null);
		Transform transform3 = ((Component)source).transform;
		RectTransform val5 = (RectTransform)(object)((transform3 is RectTransform) ? transform3 : null);
		Transform transform4 = ((Component)val).transform;
		RectTransform val6 = (RectTransform)(object)((transform4 is RectTransform) ? transform4 : null);
		float num;
		Rect rect;
		if (!((Object)(object)val3 != (Object)null))
		{
			num = 0f;
		}
		else
		{
			rect = val3.rect;
			float width = ((Rect)(ref rect)).width;
			rect = val3.rect;
			num = Mathf.Min(width, ((Rect)(ref rect)).height);
		}
		float num2 = num;
		float num3;
		if (!((Object)(object)val4 != (Object)null))
		{
			num3 = 0f;
		}
		else
		{
			rect = val4.rect;
			float width2 = ((Rect)(ref rect)).width;
			rect = val4.rect;
			num3 = Mathf.Min(width2, ((Rect)(ref rect)).height);
		}
		float num4 = num3;
		if ((Object)(object)val5 != (Object)null && (Object)(object)val6 != (Object)null && num2 > 0f && num4 > 0f)
		{
			float num5 = num4 / num2;
			Vector2 val7 = Vector2.op_Implicit(((Transform)val3).InverseTransformPoint(((Transform)val5).position));
			rect = val3.rect;
			Vector2 val8 = val7 - ((Rect)(ref rect)).center;
			Vector2 val9 = default(Vector2);
			((Vector2)(ref val9))..ctor(0.5f, 0.5f);
			val6.anchorMax = val9;
			val6.anchorMin = val9;
			val6.pivot = val5.pivot;
			rect = val5.rect;
			val6.sizeDelta = ((Rect)(ref rect)).size;
			val6.anchoredPosition = val8 * num5;
			((Transform)val6).localScale = val2 * num5;
		}
		else
		{
			((Component)val).transform.localPosition = ((Component)emote).transform.InverseTransformPoint(((Component)source).transform.position);
			((Component)val).transform.localScale = val2;
		}
		return val;
	}
}
[HarmonyPatch(typeof(GUIManager), "OpenBackpackWheel")]
internal static class WheelOpen
{
	private static void Prefix(ref int slotCount, BackpackType backpackType)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Invalid comparison between Unknown and I4
		WheelPages.Opening = true;
		if (Plugin.PatchProblem == null && (int)backpackType == 1 && slotCount == 4)
		{
			slotCount = 8;
		}
	}

	private static void Postfix()
	{
		WheelPages.Opening = false;
	}
}
[HarmonyPatch(typeof(BackpackWheel), "InitWheel")]
internal static class WheelInit
{
	private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		List<CodeInstruction> list = instructions.ToList();
		List<CodeInstruction> list2 = list.Where((CodeInstruction code) => code.opcode == OpCodes.Ldlen).ToList();
		if (list2.Count != 1)
		{
			Plugin.PatchProblem = "anchor not found: InitWheel ldlen count " + list2.Count;
			return list;
		}
		list2[0].opcode = OpCodes.Call;
		list2[0].operand = AccessTools.Method(typeof(WheelPages), "VisibleCount", (Type[])null, (Type[])null);
		return list;
	}

	private static void Prefix()
	{
		if (WheelPages.Opening)
		{
			WheelPages.Opening = false;
			SliceHover.Current = null;
			SliceHover.RefusedBy = null;
			WheelPages.Page = 0;
		}
	}

	private static void Postfix(BackpackWheel __instance, BackpackReference bp, int slotCount, BackpackType backpackType)
	{
		//IL_001a: 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_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: 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_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		WheelPages.SlotCount = slotCount;
		ItemSlot[] itemSlots = ((BackpackReference)(ref bp)).GetData().itemSlots;
		WheelPages.Paged = Plugin.PatchProblem == null && PackSize.IsPaged(backpackType, slotCount, itemSlots.Length);
		if (!WheelPages.Paged)
		{
			WheelPages.Page = 0;
		}
		if (WheelPages.Page == 1)
		{
			for (int i = 0; i < 4; i++)
			{
				byte b = (byte)(WheelPages.Page * 4 + i);
				BackpackWheelSlice val = __instance.slices[i + 1];
				bool flag = b < slotCount && b < itemSlots.Length;
				((Component)val).gameObject.SetActive(flag);
				if (flag)
				{
					val.InitItemSlot((bp, b), __instance);
				}
			}
		}
		if ((Object)(object)WheelPages.Label != (Object)null && (Object)(object)((TMP_Text)WheelPages.Label).transform.parent != (Object)(object)((TMP_Text)__instance.chosenItemText).transform.parent)
		{
			Object.Destroy((Object)(object)((Component)WheelPages.Label).gameObject);
			WheelPages.Label = null;
		}
		if ((Object)(object)WheelPages.Label == (Object)null)
		{
			WheelPages.Label = Object.Instantiate<TextMeshProUGUI>(__instance.chosenItemText, ((TMP_Text)__instance.chosenItemText).transform.parent);
			((Object)WheelPages.Label).name = "BiggerPackPageLabel";
			TextMeshProUGUI label = WheelPages.Label;
			((TMP_Text)label).fontSize = ((TMP_Text)label).fontSize * 0.6f;
			Vector2 anchoredPosition = ((TMP_Text)WheelPages.Label).rectTransform.anchoredPosition;
			ref float y = ref anchoredPosition.y;
			float num = y;
			Rect rect = ((TMP_Text)__instance.chosenItemText).rectTransform.rect;
			y = num - ((Rect)(ref rect)).height;
			((TMP_Text)WheelPages.Label).rectTransform.anchoredPosition = anchoredPosition;
		}
		((Component)WheelPages.Label).gameObject.SetActive(WheelPages.Paged);
		if (WheelPages.Paged)
		{
			((TMP_Text)WheelPages.Label).text = WheelPages.PageText(WheelPages.Page);
		}
		WheelPages.ShowArrows(__instance);
	}
}
[HarmonyPatch(typeof(BackpackWheel), "Update")]
internal static class WheelUpdate
{
	private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Expected O, but got Unknown
		List<CodeInstruction> list = instructions.ToList();
		FieldInfo field = AccessTools.Field(typeof(SliceData), "slotID");
		List<int> list2 = (from pair in list.Select((CodeInstruction code, int index) => (code: code, index: index))
			where CodeInstructionExtensions.LoadsField(pair.code, field, false)
			select pair.index).ToList();
		if (list2.Count != 2)
		{
			Plugin.PatchProblem = "anchor not found: Update slotID count " + list2.Count;
			return list;
		}
		for (int num = list2.Count - 1; num >= 0; num--)
		{
			list.Insert(list2[num] + 1, new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(WheelPages), "SliceIndex", (Type[])null, (Type[])null)));
		}
		return list;
	}

	private static bool Prefix(BackpackWheel __instance)
	{
		if (Plugin.PatchProblem == null || !WheelPages.Paged || !((Component)__instance).gameObject.activeSelf)
		{
			return true;
		}
		WheelPages.Paged = false;
		WheelPages.Page = 0;
		if ((Object)(object)WheelPages.Label != (Object)null)
		{
			((Component)WheelPages.Label).gameObject.SetActive(false);
		}
		WheelPages.ShowArrows(null);
		GUIManager.instance.CloseBackpackWheel();
		return false;
	}

	private static void Postfix(BackpackWheel __instance)
	{
		if (((Component)__instance).gameObject.activeSelf && WheelPages.Paged)
		{
			CharacterInput input = Character.localCharacter.input;
			int num = (input.selectSlotForwardWasPressed ? 1 : 0) - (input.selectSlotBackwardWasPressed ? 1 : 0);
			if (num != 0)
			{
				WheelPages.Turn(__instance, num);
			}
		}
	}
}