using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Photon.Pun; using UnityEngine; using Zorro.Core; using Zorro.Core.Serizalization; [assembly: AssemblyTitle("BackpackCapacity")] [assembly: AssemblyProduct("com.github.hu1hu.BackpackCapacity")] [assembly: AssemblyInformationalVersion("1.0.4")] [assembly: AssemblyFileVersion("1.0.4.0")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCompany("com.github.hu1hu.BackpackCapacity")] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: CompilationRelaxations(8)] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.4.0")] [module: RefSafetyRules(11)] [module: UnverifiableCode] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] [Embedded] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte A_1) { NullableFlags = new byte[1] { A_1 }; } public NullableAttribute(byte[] A_1) { NullableFlags = A_1; } } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] [Embedded] [CompilerGenerated] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte A_1) { Flag = A_1; } } [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] [Embedded] [CompilerGenerated] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int A_1) { Version = A_1; } } } namespace BepInEx { [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] [Conditional("CodeGeneration")] internal sealed class BepInAutoPluginAttribute : Attribute { public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null) { } } } namespace BepInEx.Preloader.Core.Patching { [Conditional("CodeGeneration")] [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] internal sealed class PatcherAutoPluginAttribute : Attribute { public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null) { } } } namespace BackpackCapacity { [BepInPlugin("com.github.hu1hu.BackpackCapacity", "BackpackCapacity", "1.0.4")] public class BackpackCapacity : BaseUnityPlugin { private static Harmony? harmony; public static ManualLogSource? Log; private const string PLUGIN_GUID = "com.github.hu1hu.BackpackCapacity"; private const string PLUGIN_NAME = "BackpackCapacity"; private const string PLUGIN_VERSION = "1.0.4"; public static ConfigEntry? capacityConfig; public PhotonView? photonView; private void Awake() { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Expected O, but got Unknown capacityConfig = ((BaseUnityPlugin)this).Config.Bind("General", "Capacity", 6, "Maximum number of backpack slots"); Log = ((BaseUnityPlugin)this).Logger; photonView = ((Component)this).gameObject.AddComponent(); harmony = new Harmony("com.github.hu1hu.BackpackCapacity"); harmony.PatchAll(); } private void OnDestroy() { ManualLogSource? log = Log; if (log != null) { log.LogInfo((object)"插件 BackpackCapacity 已卸载"); } Harmony? obj = harmony; if (obj != null) { obj.UnpatchSelf(); } } } [HarmonyPatch(typeof(BackpackData))] public class BackpackDataPatches { [HarmonyPatch("Init")] [HarmonyPrefix] public static void InitPrefix(BackpackData __instance) { int num = Mathf.Clamp(BackpackCapacity.capacityConfig.Value, 1, 100); __instance.itemSlots = (ItemSlot[])(object)new ItemSlot[num]; } [HarmonyPatch("DeserializeValue")] [HarmonyPrefix] public static bool DesserializeValuePrefix(BackpackData __instance, BinaryDeserializer deserializer) { //IL_0002: 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_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Expected O, but got Unknown //IL_0055: Unknown result type (might be due to invalid IL or missing references) InventorySyncData val = default(InventorySyncData); ((InventorySyncData)(ref val)).Deserialize(deserializer); Item val2 = default(Item); for (byte b = 0; b < __instance.itemSlots.Length; b++) { if (__instance.itemSlots[b] == null) { __instance.itemSlots[b] = new ItemSlot(b); } __instance.itemSlots[b].SetItem(ItemDatabase.TryGetItem(val.slots[b].ItemID, ref val2) ? val2 : null, val.slots[b].Data); Debug.Log((object)$"Sync Back Inventory is setting slot: {b} to {__instance.itemSlots[b]}"); } return false; } } [HarmonyPatch(typeof(BackpackWheel))] public class BackpackWheelPatches { [HarmonyPatch("InitWheel")] [HarmonyPrefix] private static void InitWheelPrefix(BackpackWheel __instance, ref BackpackReference bp, ref int slotCount) { //IL_01a0: Unknown result type (might be due to invalid IL or missing references) //IL_01bb: Unknown result type (might be due to invalid IL or missing references) //IL_020d: Unknown result type (might be due to invalid IL or missing references) //IL_0237: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Expected O, but got Unknown int num = (slotCount = Mathf.Clamp(BackpackCapacity.capacityConfig.Value, 1, 100)); int num2 = num + 1; int num3 = __instance.slices.Length; ItemSlot[] itemSlots = ((BackpackReference)(ref bp)).GetData().itemSlots; if (num3 < num2) { BackpackWheelSlice val = __instance.slices[1]; BackpackWheelSlice[] slices = __instance.slices; List list = new List(slices.Length); list.AddRange(slices); List list2 = list; while (list2.Count < num2) { BackpackWheelSlice item = Object.Instantiate(val, ((Component)val).transform.parent); list2.Add(item); } __instance.slices = list2.ToArray(); } else if (num3 > num2) { for (int i = num2; i < num3; i++) { Object.Destroy((Object)(object)((Component)__instance.slices[i]).gameObject); } List list3 = new List(); list3.AddRange(__instance.slices.Take(num2)); __instance.slices = list3.ToArray(); } if (itemSlots.Length < num) { ItemSlot[] array = (ItemSlot[])(object)new ItemSlot[num]; for (int j = 0; j < itemSlots.Length; j++) { array[j] = itemSlots[j]; } for (int k = itemSlots.Length; k < num; k++) { array[k] = new ItemSlot((byte)k); } ((BackpackReference)(ref bp)).GetData().itemSlots = array; } else if (itemSlots.Length > num) { BackpackData data = ((BackpackReference)(ref bp)).GetData(); List list4 = new List(); list4.AddRange(itemSlots.Take(num)); data.itemSlots = list4.ToArray(); } int num4 = __instance.slices.Length; float num5 = (num4 - 4) * 26; Transform parent = ((Component)__instance.slices[0]).transform.parent; parent.position = new Vector3((float)Screen.width / 2f, (float)Screen.height / 2f, 0f); parent.rotation = Quaternion.Euler(0f, 0f, 0f); for (int l = 0; l < num4; l++) { BackpackWheelSlice val2 = __instance.slices[l]; float num6 = 360f / (float)num4 * (float)l + 158f; float num7 = (num6 + 112f) * (MathF.PI / 180f); ((Component)val2).transform.localRotation = Quaternion.Euler(0f, 0f, num6); ((Component)val2).transform.localPosition = new Vector3(Mathf.Cos(num7) * num5, Mathf.Sin(num7) * num5, 0f); } } } [HarmonyPatch(typeof(BackpackVisuals))] public class BackpackVisualsPatches { [HarmonyPrefix] [HarmonyPatch("RefreshVisuals")] public static bool RefreshVisualsPrefix(BackpackVisuals __instance) { //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: 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_00ec: 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_0192: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) BackpackData backpackData = __instance.GetBackpackData(); if (backpackData == null) { Debug.LogWarning((object)"BackpackData is null, cannot refresh visuals."); return true; } int num = backpackData.itemSlots.Length; if (__instance.backpackSlots.Length < num) { int num2 = Mathf.Max(__instance.backpackSlots.Length, num); Transform[] backpackSlots = __instance.backpackSlots; Transform[] array = (Transform[])(object)new Transform[num2]; for (int i = 0; i < backpackSlots.Length; i++) { array[i] = backpackSlots[i]; } for (int j = backpackSlots.Length; j < num2; j++) { array[j] = array[j % 4]; } __instance.backpackSlots = array; } for (byte b = 0; b < num; b++) { try { ItemSlot val = backpackData.itemSlots[b]; Optionable val2 = (((Object)(object)val.prefab == (Object)null) ? Optionable.None : Optionable.Some(val.prefab.itemID)); (GameObject, ushort) value; Optionable val3 = (__instance.visualItems.TryGetValue(b, out value) ? Optionable.Some(value.Item2) : Optionable.None); if (val2 != val3) { if (val2.IsSome && val3.IsSome) { ManualLogSource? log = BackpackCapacity.Log; if (log != null) { log.LogError((object)$"Item Visuals Mismatch at slot {b}!"); } } else if (val2.IsSome && val3.IsNone) { Debug.Log((object)$"Spawning Backpack Visual for slot {b}, itemID {val2.Value}"); GameObject val4 = null; try { val4 = PhotonNetwork.Instantiate("0_Items/" + val.GetPrefabName(), new Vector3(0f, -500f, 0f), Quaternion.identity, (byte)0, (object[])null); __instance.PutItemInBackpack(val4, b); val4.GetComponent().RPC("SetItemInstanceDataRPC", (RpcTarget)0, new object[1] { val.data }); __instance.visualItems.Add(b, (val4, val2.Value)); } catch (Exception arg) { ManualLogSource? log2 = BackpackCapacity.Log; if (log2 != null) { log2.LogError((object)$"Failed to spawn visual for slot {b}: {arg}"); } } } else if (val2.IsNone && val3.IsSome) { Debug.Log((object)$"Removing backpack visual for slot {b}, itemID {val3.Value}"); if (__instance.visualItems.TryGetValue(b, out (GameObject, ushort) value2) && (Object)(object)value2.Item1 != (Object)null) { try { PhotonNetwork.Destroy(value2.Item1.GetComponent()); } catch (Exception arg2) { ManualLogSource? log3 = BackpackCapacity.Log; if (log3 != null) { log3.LogError((object)$"Failed to destroy visual for slot {b}: {arg2}"); } } __instance.visualItems.Remove(b); } else { Debug.LogWarning((object)$"No valid visual object to remove for slot {b}"); } } } else if (val2.IsNone) { Debug.Log((object)$"Slot {b} is empty, no visual to spawn."); } } catch (Exception arg3) { ManualLogSource? log4 = BackpackCapacity.Log; if (log4 != null) { log4.LogError((object)$"Exception refreshing slot {b}: {arg3}"); } } } return false; } } public class CapacitySync : MonoBehaviour { public void Awake() { if (!PhotonNetwork.IsMasterClient) { return; } BackpackCapacity.capacityConfig.Value = Mathf.Clamp(BackpackCapacity.capacityConfig.Value, 1, 100); foreach (Character allCharacter in Character.AllCharacters) { ((MonoBehaviourPun)allCharacter).photonView.RPC("RPCA_SetCapacity", (RpcTarget)4, new object[1] { BackpackCapacity.capacityConfig.Value }); } } public void Update() { if (!Character.localCharacter.refs.afflictions.m_inAirport) { return; } if (Input.GetKeyDown((KeyCode)117)) { BackpackCapacity.capacityConfig.Value = Mathf.Clamp(BackpackCapacity.capacityConfig.Value + 1, 1, 100); if (PhotonNetwork.IsMasterClient) { foreach (Character allCharacter in Character.AllCharacters) { ((MonoBehaviourPun)allCharacter).photonView.RPC("RPCA_SetCapacity", (RpcTarget)4, new object[1] { BackpackCapacity.capacityConfig.Value }); } } } if (!Input.GetKeyUp((KeyCode)105)) { return; } BackpackCapacity.capacityConfig.Value = Mathf.Clamp(BackpackCapacity.capacityConfig.Value - 1, 1, 100); if (!PhotonNetwork.IsMasterClient) { return; } foreach (Character allCharacter2 in Character.AllCharacters) { ((MonoBehaviourPun)allCharacter2).photonView.RPC("RPCA_SetCapacity", (RpcTarget)4, new object[1] { BackpackCapacity.capacityConfig.Value }); } } [PunRPC] public void RPCA_SetCapacity(int newCapacity) { if (BackpackCapacity.capacityConfig != null) { BackpackCapacity.capacityConfig.Value = Mathf.Clamp(newCapacity, 1, 100); } } } [HarmonyPatch(typeof(Character), "Awake")] public class CharacterAwakePatch { public static void Postfix(Character __instance) { if (((MonoBehaviourPun)__instance).photonView.IsMine && (Object)(object)((Component)__instance).gameObject.GetComponent() == (Object)null) { ((Component)__instance).gameObject.AddComponent(); } } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }