Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of BagOfHolding v1.0.1
BagOfHolding/bagofholding.dll
Decompiled 22 minutes ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using GameNetcodeStuff; using HarmonyLib; using LethalConfig; using LethalConfig.ConfigItems; using LethalConfig.ConfigItems.Options; using Microsoft.CodeAnalysis; using TMPro; using Unity.Collections; using Unity.Netcode; using UnityEngine; using UnityEngine.Animations.Rigging; using UnityEngine.Audio; using UnityEngine.Events; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; using UnityEngine.Networking; using UnityEngine.Rendering; using UnityEngine.Rendering.HighDefinition; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("BagOfHolding")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("BagOfHolding")] [assembly: AssemblyTitle("BagOfHolding")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace BagOfHolding { internal sealed class BagCharger : MonoBehaviour { private const float BagRescanInterval = 2f; private readonly List<BeltBagItem> bags = new List<BeltBagItem>(); private readonly Dictionary<GrabbableObject, float> pending = new Dictionary<GrabbableObject, float>(); private readonly HashSet<GrabbableObject> seenThisFrame = new HashSet<GrabbableObject>(); private readonly List<GrabbableObject> stale = new List<GrabbableObject>(); private float nextRescan; private void Update() { NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)singleton == (Object)null || !singleton.IsListening || !singleton.IsServer || !Plugin.PortableCharger.Value) { pending.Clear(); bags.Clear(); return; } if (Time.unscaledTime >= nextRescan) { nextRescan = Time.unscaledTime + 2f; bags.Clear(); bags.AddRange(Object.FindObjectsOfType<BeltBagItem>()); } float gained = Mathf.Round(Mathf.Clamp(Plugin.ChargeRate.Value, 0.1f, 10f) * 10f) / 10f * Time.deltaTime; seenThisFrame.Clear(); foreach (BeltBagItem bag in bags) { if ((Object)(object)bag == (Object)null || bag.objectsInBag == null) { continue; } foreach (GrabbableObject item in bag.objectsInBag) { if ((Object)(object)item != (Object)null && seenThisFrame.Add(item)) { Charge(item, gained); } } } stale.Clear(); foreach (GrabbableObject key in pending.Keys) { if (!seenThisFrame.Contains(key)) { stale.Add(key); } } foreach (GrabbableObject item2 in stale) { pending.Remove(item2); } } private void Charge(GrabbableObject item, float gained) { if ((Object)(object)item.itemProperties == (Object)null || !item.itemProperties.requiresBattery || item.insertedBattery == null || (Object)(object)((NetworkBehaviour)item).NetworkObject == (Object)null || !((NetworkBehaviour)item).NetworkObject.IsSpawned) { return; } int num = Mathf.FloorToInt(item.insertedBattery.charge * 100f + 0.001f); if (num >= 100) { pending.Remove(item); return; } pending.TryGetValue(item, out var value); value += gained; int num2 = Mathf.FloorToInt(value); if (num2 <= 0) { pending[item] = value; return; } pending[item] = value - (float)num2; item.SyncBatteryClientRpc(Mathf.Min(100, num + num2)); } } internal enum SwitchIntent { None, ScrollForward, ScrollBack, UtilitySlot } internal sealed class BagHands : MonoBehaviour { private sealed class Swap { public GrabbableObject Pulled; public BeltBagItem PulledFrom; public GrabbableObject Stashed; public BeltBagItem StashBag; } private const float StepTimeout = 3f; internal static BagHands? Instance; private Swap? swap; private bool busy; private float busySince; private const float BusyWatchdog = 15f; private bool lastGrabSucceeded; public GrabbableObject? HiddenItem => swap?.Stashed; private void Awake() { Instance = this; } private void Update() { if (busy && Time.realtimeSinceStartup - busySince > 15f) { Plugin.Log.LogWarning((object)"Belt bag action timed out; resetting."); ((MonoBehaviour)this).StopAllCoroutines(); busy = false; swap = null; } if (swap != null && !busy) { PlayerControllerB localPlayer = WheelController.LocalPlayer; if ((Object)(object)localPlayer == (Object)null || localPlayer.isPlayerDead || !localPlayer.isPlayerControlled) { swap = null; } else if ((Object)(object)swap.Stashed == (Object)null || (Object)(object)swap.StashBag == (Object)null || !GameAccess.InInventory(localPlayer, (GrabbableObject)(object)swap.StashBag) || !swap.StashBag.objectsInBag.Contains(swap.Stashed)) { swap = null; } else if ((Object)(object)swap.Pulled == (Object)null || !GameAccess.InInventory(localPlayer, swap.Pulled)) { ((MonoBehaviour)this).StartCoroutine(Run(RestoreStashed(localPlayer, SwitchIntent.None))); } else if ((Object)(object)localPlayer.currentlyHeldObjectServer != (Object)(object)swap.Pulled && !localPlayer.isGrabbingObjectAnimation) { swap = null; } } } public string? TakeOut(PlayerControllerB player, BagEntry entry) { if (busy) { return null; } BeltBagItem bag = entry.Bag; GrabbableObject item = entry.Item; if ((Object)(object)bag == (Object)null || (Object)(object)item == (Object)null || !bag.objectsInBag.Contains(item)) { return "That item is no longer in the bag."; } if (bag.tryingAddToBag) { return null; } string text = BagRetrieval.CannotGrab(player, item); if (text != null) { return text; } GrabbableObject currentlyHeldObjectServer = player.currentlyHeldObjectServer; if (swap != null && (Object)(object)currentlyHeldObjectServer != (Object)null && (Object)(object)currentlyHeldObjectServer == (Object)(object)swap.Pulled) { if (GameAccess.SlotAfterEmptyingHeld(player, item) == -1) { return "No free inventory slot."; } ((MonoBehaviour)this).StartCoroutine(Run(Exchange(player, entry))); return null; } if (!player.twoHanded && GameAccess.FirstEmptyItemSlot(player, item) != -1) { BagRetrieval.TakeOutAndGrab(player, bag, item); return null; } if (swap != null) { return "Put away the other item first."; } if ((Object)(object)currentlyHeldObjectServer == (Object)null) { return "No free inventory slot."; } if ((Object)(object)currentlyHeldObjectServer == (Object)(object)bag) { return "Inventory full. Switch off the bag first."; } if (BagRetrieval.CannotStore(currentlyHeldObjectServer, allowScrap: true) != null) { return "No free inventory slot."; } if (GameAccess.SlotAfterEmptyingHeld(player, item) == -1) { return "No free inventory slot."; } ((MonoBehaviour)this).StartCoroutine(Run(SwapIn(player, entry, currentlyHeldObjectServer))); return null; } public string? PutBack(PlayerControllerB player) { if (busy) { return null; } GrabbableObject currentlyHeldObjectServer = player.currentlyHeldObjectServer; if ((Object)(object)currentlyHeldObjectServer == (Object)null || currentlyHeldObjectServer is BeltBagItem) { return null; } if (player.isGrabbingObjectAnimation || GameAccess.ThrowingObject.Invoke(player) || player.activatingItem || player.inSpecialInteractAnimation) { return null; } if (swap != null && (Object)(object)currentlyHeldObjectServer == (Object)(object)swap.Pulled) { ((MonoBehaviour)this).StartCoroutine(Run(ReturnPulled(player, SwitchIntent.None))); return null; } string text = BagRetrieval.CannotStore(currentlyHeldObjectServer, allowScrap: false); if (text != null) { return text; } BeltBagItem val = BagRetrieval.BagFor(player, currentlyHeldObjectServer); if ((Object)(object)val == (Object)null) { return "Your belt bag is full."; } ((MonoBehaviour)this).StartCoroutine(Run(StoreHeld(player, currentlyHeldObjectServer, val))); return null; } public string? StoreInto(PlayerControllerB player, BeltBagItem bag) { if (busy) { return null; } GrabbableObject currentlyHeldObjectServer = player.currentlyHeldObjectServer; if ((Object)(object)currentlyHeldObjectServer == (Object)null || (Object)(object)bag == (Object)null) { return null; } if ((Object)(object)currentlyHeldObjectServer == (Object)(object)bag) { return "The bag can't go inside itself."; } if (player.isGrabbingObjectAnimation || GameAccess.ThrowingObject.Invoke(player) || player.activatingItem || player.inSpecialInteractAnimation) { return null; } if (swap != null && (Object)(object)currentlyHeldObjectServer == (Object)(object)swap.Pulled) { ((MonoBehaviour)this).StartCoroutine(Run(ReturnPulled(player, SwitchIntent.None))); return null; } string text = BagRetrieval.CannotStore(currentlyHeldObjectServer, allowScrap: false); if (text != null) { return text; } if (bag.objectsInBag.Count >= 15) { return "The bag is full."; } ((MonoBehaviour)this).StartCoroutine(Run(StoreHeld(player, currentlyHeldObjectServer, bag))); return null; } public bool InterceptSwitch(PlayerControllerB player, SwitchIntent intent) { if (busy) { return true; } if (swap == null || (Object)(object)player.currentlyHeldObjectServer != (Object)(object)swap.Pulled) { return false; } if (GameAccess.TimeSinceSwitchingSlots.Invoke(player) < 0.3f || player.isGrabbingObjectAnimation || GameAccess.ThrowingObject.Invoke(player) || player.activatingItem || player.inSpecialInteractAnimation || player.twoHanded || player.isTypingChat || player.quickMenuManager.isMenuOpen) { return false; } ((MonoBehaviour)this).StartCoroutine(Run(ReturnPulled(player, intent))); return true; } private IEnumerator Run(IEnumerator sequence) { busy = true; busySince = Time.realtimeSinceStartup; while (true) { bool flag; try { flag = sequence.MoveNext(); } catch (Exception arg) { Plugin.Log.LogError((object)$"Belt bag action failed: {arg}"); swap = null; flag = false; } if (!flag) { break; } yield return sequence.Current; } busy = false; } private IEnumerator SwapIn(PlayerControllerB player, BagEntry entry, GrabbableObject held) { yield return DropHeld(player); if (!CanStillTakeOut(player, entry)) { BagRetrieval.Grab(player, held); yield break; } BagRetrieval.TakeOutAndGrab(player, entry.Bag, entry.Item); swap = new Swap { Pulled = entry.Item, PulledFrom = entry.Bag, Stashed = held, StashBag = entry.Bag }; yield return Store(entry.Bag, held); yield return WaitForGrab(player, entry.Item); } private IEnumerator Exchange(PlayerControllerB player, BagEntry entry) { GrabbableObject old = swap.Pulled; yield return DropHeld(player); if (!CanStillTakeOut(player, entry)) { yield return Store(swap.PulledFrom, old); yield return RestoreStashed(player, SwitchIntent.None); yield break; } BagRetrieval.TakeOutAndGrab(player, entry.Bag, entry.Item); swap.Pulled = entry.Item; swap.PulledFrom = entry.Bag; yield return Store(entry.Bag, old); yield return WaitForGrab(player, entry.Item); } private IEnumerator ReturnPulled(PlayerControllerB player, SwitchIntent intent) { GrabbableObject pulled = swap.Pulled; yield return DropHeld(player); BeltBagItem val = (BeltBagItem)(((Object)(object)swap.PulledFrom != (Object)null && GameAccess.InInventory(player, (GrabbableObject)(object)swap.PulledFrom) && swap.PulledFrom.objectsInBag.Count < 15) ? ((object)swap.PulledFrom) : ((object)BagRetrieval.BagFor(player, pulled))); if ((Object)(object)val != (Object)null) { yield return Store(val, pulled); } yield return RestoreStashed(player, intent); } private IEnumerator RestoreStashed(PlayerControllerB player, SwitchIntent intent) { Swap s = swap; swap = null; if (s == null) { yield break; } yield return WaitUntilFree(player); if (!((Object)(object)s.StashBag == (Object)null) && s.StashBag.objectsInBag.Contains(s.Stashed) && GameAccess.InInventory(player, (GrabbableObject)(object)s.StashBag) && BagRetrieval.CannotGrab(player, s.Stashed) == null && GameAccess.FirstEmptyItemSlot(player, s.Stashed) != -1) { BagRetrieval.TakeOutAndGrab(player, s.StashBag, s.Stashed); yield return WaitForGrab(player, s.Stashed); if (intent != SwitchIntent.None && lastGrabSucceeded) { DoSwitch(player, intent); } } } private IEnumerator StoreHeld(PlayerControllerB player, GrabbableObject held, BeltBagItem bag) { yield return DropHeld(player); yield return Store(bag, held); } private static IEnumerator DropHeld(PlayerControllerB player) { yield return (object)new WaitForEndOfFrame(); player.DiscardHeldObject(false, (NetworkObject)null, default(Vector3), true); float until = Time.realtimeSinceStartup + 3f; while (GameAccess.ThrowingObject.Invoke(player) && Time.realtimeSinceStartup < until) { yield return null; } } private static IEnumerator Store(BeltBagItem bag, GrabbableObject item) { if ((Object)(object)bag == (Object)null || (Object)(object)item == (Object)null) { yield break; } float until = Time.realtimeSinceStartup + 3f; while (bag.tryingAddToBag && Time.realtimeSinceStartup < until) { yield return null; } if (!item.isHeld && !item.isHeldByEnemy && !bag.objectsInBag.Contains(item)) { bag.TryAddObjectToBag(item); until = Time.realtimeSinceStartup + 3f; while (bag.tryingAddToBag && Time.realtimeSinceStartup < until) { yield return null; } } } private IEnumerator WaitForGrab(PlayerControllerB player, GrabbableObject item) { lastGrabSucceeded = false; float until = Time.realtimeSinceStartup + 3f; while (Time.realtimeSinceStartup < until) { if ((Object)(object)player.currentlyHeldObjectServer == (Object)(object)item && !player.isGrabbingObjectAnimation) { lastGrabSucceeded = true; break; } if (!player.isGrabbingObjectAnimation && (Object)(object)GameAccess.CurrentlyGrabbing.Invoke(player) == (Object)null) { break; } yield return null; } } private static IEnumerator WaitUntilFree(PlayerControllerB player) { float until = Time.realtimeSinceStartup + 3f; while ((GameAccess.ThrowingObject.Invoke(player) || player.isGrabbingObjectAnimation) && Time.realtimeSinceStartup < until) { yield return null; } } private static bool CanStillTakeOut(PlayerControllerB player, BagEntry entry) { if ((Object)(object)entry.Bag != (Object)null && (Object)(object)entry.Item != (Object)null && entry.Bag.objectsInBag.Contains(entry.Item) && BagRetrieval.CannotGrab(player, entry.Item) == null) { return GameAccess.FirstEmptyItemSlot(player, entry.Item) != -1; } return false; } private static void DoSwitch(PlayerControllerB player, SwitchIntent intent) { if (player.twoHanded) { return; } player.playerBodyAnimator.SetBool("GrabValidated", false); if (intent == SwitchIntent.UtilitySlot) { int num = 50; if (player.currentItemSlot == 50) { num = GameAccess.FirstEmptyItemSlot(player, null); if (num == -1) { num = 0; } } GameAccess.SwitchToItemSlot(player, num, null); GameAccess.SwitchToSlotServerRpc(player, num); } else { bool arg = intent == SwitchIntent.ScrollForward; GameAccess.SwitchToItemSlot(player, GameAccess.NextItemSlot(player, arg), null); GameAccess.SwitchItemSlotsServerRpc(player, arg); } GrabbableObject currentlyHeldObjectServer = player.currentlyHeldObjectServer; if ((Object)(object)currentlyHeldObjectServer != (Object)null && (Object)(object)currentlyHeldObjectServer.itemProperties.grabSFX != (Object)null) { AudioSource component = ((Component)currentlyHeldObjectServer).gameObject.GetComponent<AudioSource>(); if (component != null) { component.PlayOneShot(currentlyHeldObjectServer.itemProperties.grabSFX, 0.6f); } } GameAccess.TimeSinceSwitchingSlots.Invoke(player) = 0f; } } internal readonly struct BagEntry { public readonly BeltBagItem Bag; public readonly GrabbableObject Item; public BagEntry(BeltBagItem bag, GrabbableObject item) { Bag = bag; Item = item; } } internal static class BagRetrieval { public const int BagCapacity = 15; private const int VanillaBlockedIdA = 123984; private const int VanillaBlockedIdB = 819501; public static void Collect(PlayerControllerB player, List<BagEntry> into, GrabbableObject? hidden) { into.Clear(); HashSet<BeltBagItem> seen = new HashSet<BeltBagItem>(); GrabbableObject currentlyHeldObjectServer = player.currentlyHeldObjectServer; AddBag((BeltBagItem?)(object)((currentlyHeldObjectServer is BeltBagItem) ? currentlyHeldObjectServer : null), seen, into, hidden); GrabbableObject itemOnlySlot = player.ItemOnlySlot; AddBag((BeltBagItem?)(object)((itemOnlySlot is BeltBagItem) ? itemOnlySlot : null), seen, into, hidden); GrabbableObject[] itemSlots = player.ItemSlots; foreach (GrabbableObject obj in itemSlots) { AddBag((BeltBagItem?)(object)((obj is BeltBagItem) ? obj : null), seen, into, hidden); } } public static bool HasBag(PlayerControllerB player) { if (player.ItemOnlySlot is BeltBagItem) { return true; } GrabbableObject[] itemSlots = player.ItemSlots; for (int i = 0; i < itemSlots.Length; i++) { if (itemSlots[i] is BeltBagItem) { return true; } } return false; } private static void AddBag(BeltBagItem? bag, HashSet<BeltBagItem> seen, List<BagEntry> into, GrabbableObject? hidden) { if ((Object)(object)bag == (Object)null || !seen.Add(bag) || bag.objectsInBag == null) { return; } foreach (GrabbableObject item in bag.objectsInBag) { if ((Object)(object)item != (Object)null && (Object)(object)item != (Object)(object)hidden) { into.Add(new BagEntry(bag, item)); } } } public static BeltBagItem? BagFor(PlayerControllerB player, GrabbableObject item) { GrabbableObject itemOnlySlot = player.ItemOnlySlot; BeltBagItem val = (BeltBagItem)(object)((itemOnlySlot is BeltBagItem) ? itemOnlySlot : null); if (val != null && (Object)(object)val != (Object)(object)item && val.objectsInBag.Count < 15) { return val; } GrabbableObject[] itemSlots = player.ItemSlots; foreach (GrabbableObject obj in itemSlots) { BeltBagItem val2 = (BeltBagItem)(object)((obj is BeltBagItem) ? obj : null); if (val2 != null && (Object)(object)val2 != (Object)(object)item && val2.objectsInBag.Count < 15) { return val2; } } return null; } public static string? CannotStore(GrabbableObject item, bool allowScrap) { Item itemProperties = item.itemProperties; if ((Object)(object)itemProperties == (Object)null) { return "That can't go in the bag."; } if (itemProperties.isScrap && !allowScrap && !BagStoragePatches.IsAllowedWeapon(item)) { return "Scrap doesn't fit in the belt bag."; } if (itemProperties.itemId == 123984 || itemProperties.itemId == 819501) { return ItemName(item) + " can't go in the bag."; } if (item.isHeldByEnemy) { return "That can't go in the bag."; } return null; } public static string? CannotGrab(PlayerControllerB player, GrabbableObject item) { if (player.isPlayerDead || !player.isPlayerControlled) { return "You can't do that right now."; } if (player.isGrabbingObjectAnimation || player.inSpecialInteractAnimation || player.isClimbingLadder || GameAccess.ThrowingObject.Invoke(player) || player.activatingItem) { return "You're busy."; } if (player.jetpackControls || player.disablingJetpackControls) { return "Not while flying."; } if (player.sinkingValue > 0.73f) { return "You're sinking!"; } if (!item.grabbable) { return ItemName(item) + " can't be picked up right now."; } NetworkObject networkObject = ((NetworkBehaviour)item).NetworkObject; if ((Object)(object)networkObject == (Object)null || !networkObject.IsSpawned) { return "That item isn't ready yet."; } return null; } public static void TakeOutAndGrab(PlayerControllerB player, BeltBagItem bag, GrabbableObject item) { int num = bag.objectsInBag.IndexOf(item); if (num >= 0) { bag.GrabItemInBag(); bag.RemoveObjectFromBag(num); Grab(player, item); } } public static void Grab(PlayerControllerB player, GrabbableObject item) { //IL_0116: Unknown result type (might be due to invalid IL or missing references) NetworkObject networkObject = ((NetworkBehaviour)item).NetworkObject; if (!((Object)(object)networkObject == (Object)null) && networkObject.IsSpawned) { GameAccess.CurrentlyGrabbing.Invoke(player) = item; GameAccess.GrabInvalidated.Invoke(player) = false; item.InteractItem(); Animator playerBodyAnimator = player.playerBodyAnimator; playerBodyAnimator.SetBool("GrabInvalidated", false); playerBodyAnimator.SetBool("GrabValidated", false); playerBodyAnimator.SetBool("cancelHolding", false); playerBodyAnimator.ResetTrigger("Throw"); GameAccess.SetSpecialGrabAnimationBool(player, arg2: true, null); player.isGrabbingObjectAnimation = true; ((Behaviour)player.cursorIcon).enabled = false; ((TMP_Text)player.cursorTip).text = ""; player.twoHanded = item.itemProperties.twoHanded; player.carryWeight = Mathf.Clamp(player.carryWeight + (item.itemProperties.weight - 1f), 1f, 10f); StartOfRound.Instance.SendChangedWeightEvent(); player.grabObjectAnimationTime = ((item.itemProperties.grabAnimationTime > 0f) ? item.itemProperties.grabAnimationTime : 0.4f); GameAccess.GrabObjectServerRpc(player, NetworkObjectReference.op_Implicit(networkObject)); Coroutine val = GameAccess.GrabCoroutine.Invoke(player); if (val != null) { ((MonoBehaviour)player).StopCoroutine(val); } GameAccess.GrabCoroutine.Invoke(player) = ((MonoBehaviour)player).StartCoroutine(GameAccess.GrabObject(player)); } } public static string ItemName(GrabbableObject item) { string text = (((Object)(object)item.itemProperties != (Object)null) ? item.itemProperties.itemName : null); if (!string.IsNullOrWhiteSpace(text)) { return text; } return ((Object)item).name; } } internal static class BagStoragePatches { private const float Reach = 4f; private const int ItemMask = 1073742144; public static bool IsAllowedWeapon(GrabbableObject item) { if (HostSync.Active && HostSync.Current.AllowWeapons) { if (!(item is KnifeItem) && !(item is ShotgunItem)) { return item is GunAmmo; } return true; } return false; } [HarmonyPrefix] [HarmonyPatch(typeof(BeltBagItem), "ItemInteractLeftRight")] private static bool ItemInteractLeftRight(BeltBagItem __instance, bool right) { //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) if (right || !HostSync.Active || !HostSync.Current.AllowWeapons || !((NetworkBehaviour)__instance).IsOwner) { return true; } PlayerControllerB playerHeldBy = ((GrabbableObject)__instance).playerHeldBy; if ((Object)(object)playerHeldBy == (Object)null || __instance.tryingAddToBag || __instance.objectsInBag.Count >= 15) { return true; } Transform transform = ((Component)playerHeldBy.gameplayCamera).transform; RaycastHit val = default(RaycastHit); if (!Physics.Raycast(transform.position, transform.forward, ref val, 4f, 1073742144, (QueryTriggerInteraction)1)) { return true; } GrabbableObject component = ((Component)((RaycastHit)(ref val)).collider).gameObject.GetComponent<GrabbableObject>(); if ((Object)(object)component == (Object)null || (Object)(object)component == (Object)(object)__instance || !IsAllowedWeapon(component) || component.isHeld || component.isHeldByEnemy) { return true; } __instance.TryAddObjectToBag(component); return false; } } internal sealed class BagWeights : MonoBehaviour { public const int VanillaBagPounds = 16; private const float PoundsPerUnit = 105f; private const float Epsilon = 0.0001f; private static float? vanillaWeight; private static readonly Dictionary<PlayerControllerB, float> contentsApplied = new Dictionary<PlayerControllerB, float>(); private static readonly HashSet<BeltBagItem> Visited = new HashSet<BeltBagItem>(); private Item? bagItem; public static void Forget(PlayerControllerB player) { if ((Object)(object)player != (Object)null && Mathf.Abs(player.carryWeight - 1f) < 0.0001f) { contentsApplied.Remove(player); } } public static void ForgetAll() { foreach (PlayerControllerB item in new List<PlayerControllerB>(contentsApplied.Keys)) { Forget(item); } } private void Update() { StartOfRound instance = StartOfRound.Instance; if ((Object)(object)instance == (Object)null || instance.allPlayerScripts == null) { contentsApplied.Clear(); bagItem = null; return; } if ((Object)(object)bagItem == (Object)null) { bagItem = FindBagItem(instance); } if ((Object)(object)bagItem != (Object)null) { ApplyBagWeight(instance, bagItem); } ApplyContentsWeight(instance); } private static Item? FindBagItem(StartOfRound round) { List<Item> list = (((Object)(object)round.allItemsList != (Object)null) ? round.allItemsList.itemsList : null); if (list == null) { return null; } foreach (Item item in list) { if (!((Object)(object)item == (Object)null) && !((Object)(object)item.spawnPrefab == (Object)null) && !((Object)(object)item.spawnPrefab.GetComponent<BeltBagItem>() == (Object)null)) { float valueOrDefault = vanillaWeight.GetValueOrDefault(); if (!vanillaWeight.HasValue) { valueOrDefault = item.weight; vanillaWeight = valueOrDefault; } return item; } } return null; } private static float DesiredBagWeight() { int bagPounds = HostSync.Current.BagPounds; if (vanillaWeight.HasValue && bagPounds == 16) { return vanillaWeight.Value; } return 1f + (float)bagPounds / 105f; } private static void ApplyBagWeight(StartOfRound round, Item bag) { float num = DesiredBagWeight(); float num2 = num - bag.weight; if (Mathf.Abs(num2) < 0.0001f) { return; } PlayerControllerB[] allPlayerScripts = round.allPlayerScripts; foreach (PlayerControllerB val in allPlayerScripts) { if ((Object)(object)val == (Object)null || val.isPlayerDead) { continue; } int num3 = 0; if ((Object)(object)val.ItemOnlySlot != (Object)null && (Object)(object)val.ItemOnlySlot.itemProperties == (Object)(object)bag) { num3++; } GrabbableObject[] itemSlots = val.ItemSlots; foreach (GrabbableObject val2 in itemSlots) { if ((Object)(object)val2 != (Object)null && (Object)(object)val2.itemProperties == (Object)(object)bag) { num3++; } } if (num3 > 0) { val.carryWeight = Mathf.Max(1f, val.carryWeight + num2 * (float)num3); } } bag.weight = num; round.SendChangedWeightEvent(); } private static void ApplyContentsWeight(StartOfRound round) { bool flag = false; PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null); PlayerControllerB[] allPlayerScripts = round.allPlayerScripts; foreach (PlayerControllerB val2 in allPlayerScripts) { if ((Object)(object)val2 == (Object)null) { continue; } contentsApplied.TryGetValue(val2, out var value); float num = ((val2.isPlayerDead || !val2.isPlayerControlled) ? 0f : ContentsWeight(val2)); float num2 = num - value; if (!(Mathf.Abs(num2) < 0.0001f)) { val2.carryWeight = Mathf.Max(1f, val2.carryWeight + num2); contentsApplied[val2] = num; if ((Object)(object)val2 == (Object)(object)val) { flag = true; } } } if (flag) { round.SendChangedWeightEvent(); } } private static float ContentsWeight(PlayerControllerB player) { SyncedSettings current = HostSync.Current; if (!current.CountContents) { return 0f; } float num = 1f - (float)current.ContentsReduction / 100f; if (num <= 0f) { return 0f; } HashSet<BeltBagItem> visited = Visited; visited.Clear(); GrabbableObject itemOnlySlot = player.ItemOnlySlot; float num2 = AddBag((BeltBagItem?)(object)((itemOnlySlot is BeltBagItem) ? itemOnlySlot : null), visited); GrabbableObject[] itemSlots = player.ItemSlots; foreach (GrabbableObject val in itemSlots) { num2 += AddBag((BeltBagItem?)(object)((val is BeltBagItem) ? val : null), visited); } return num2 * num; } private static float AddBag(BeltBagItem? bag, HashSet<BeltBagItem> visited) { if ((Object)(object)bag == (Object)null || !visited.Add(bag) || bag.objectsInBag == null) { return 0f; } float num = 0f; foreach (GrabbableObject item in bag.objectsInBag) { if (!((Object)(object)item == (Object)null) && !((Object)(object)item.itemProperties == (Object)null)) { num += Mathf.Max(0f, item.itemProperties.weight - 1f); BeltBagItem val = (BeltBagItem)(object)((item is BeltBagItem) ? item : null); if (val != null) { num += AddBag(val, visited); } } } return num; } } internal static class WeightPatches { [HarmonyPostfix] [HarmonyPatch(typeof(PlayerControllerB), "KillPlayer")] private static void KillPlayer(PlayerControllerB __instance) { BagWeights.Forget(__instance); } [HarmonyPostfix] [HarmonyPatch(typeof(PlayerControllerB), "DropAllHeldItems")] private static void DropAllHeldItems(PlayerControllerB __instance) { BagWeights.Forget(__instance); } [HarmonyPostfix] [HarmonyPatch(typeof(StartOfRound), "ReviveDeadPlayers")] private static void ReviveDeadPlayers() { BagWeights.ForgetAll(); } } internal sealed class BeerItem : GrabbableObject { private const uint PrefabHash = 2963652327u; private const int BeerItemId = 11576766; internal static GameObject? Prefab; internal static Item? Properties; private bool built; private const float HeldShiftRight = 0.055f; internal static void Register() { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown //IL_00c0: Unknown result type (might be due to invalid IL or missing references) NetworkManager singleton = NetworkManager.Singleton; if ((Object)(object)Prefab != (Object)null || (Object)(object)singleton == (Object)null) { return; } GameObject val = new GameObject("BagOfHoldingBeerPrefab") { hideFlags = (HideFlags)61 }; val.SetActive(false); Object.DontDestroyOnLoad((Object)(object)val); GameObject val2 = new GameObject("BagOfHoldingBeer"); val2.transform.SetParent(val.transform, false); int num = LayerMask.NameToLayer("Props"); val2.layer = ((num >= 0) ? num : 6); val2.tag = "PhysicsProp"; NetworkObject obj = val2.AddComponent<NetworkObject>(); AccessTools.Field(typeof(NetworkObject), "GlobalObjectIdHash").SetValue(obj, 2963652327u); val2.AddComponent<BoxCollider>().size = new Vector3(0.09f, 0.14f, 0.09f); val2.AddComponent<AudioSource>(); ((GrabbableObject)val2.AddComponent<BeerItem>()).grabbable = true; try { singleton.AddNetworkPrefab(val2); Prefab = val2; } catch (Exception ex) { Plugin.Log.LogWarning((object)("Couldn't register the beer item: " + ex.Message)); Object.Destroy((Object)(object)val); } } internal static void MakeProperties() { //IL_0159: 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) if ((Object)(object)Properties != (Object)null || (Object)(object)Prefab == (Object)null) { return; } List<Item> list = (((Object)(object)StartOfRound.Instance != (Object)null && (Object)(object)StartOfRound.Instance.allItemsList != (Object)null) ? StartOfRound.Instance.allItemsList.itemsList : null); Item val = list?.FirstOrDefault((Func<Item, bool>)((Item i) => (Object)(object)i != (Object)null && (Object)(object)i.spawnPrefab != (Object)null && (Object)(object)i.spawnPrefab.GetComponent<TetraChemicalItem>() != (Object)null)); if (!((Object)(object)val == (Object)null)) { Sprite val2 = MakeIcon() ?? ((IEnumerable<Item>)list).FirstOrDefault((Func<Item, bool>)((Item i) => (Object)(object)i != (Object)null && i.isScrap && (Object)(object)i.itemIcon != (Object)null))?.itemIcon; Item val3 = Object.Instantiate<Item>(val); ((Object)val3).name = "BagOfHoldingBeer"; val3.itemName = "Beer"; val3.itemId = 11576766; val3.spawnPrefab = Prefab; val3.isScrap = true; val3.creditsWorth = 0; val3.minValue = (val3.maxValue = 0); val3.weight = 1.02f; val3.requiresBattery = false; val3.isConductiveMetal = false; val3.twoHanded = false; val3.holdButtonUse = false; val3.syncUseFunction = false; val3.useAnim = ""; val3.itemSpawnsOnGround = false; val3.canBeGrabbedBeforeGameStart = true; val3.restingRotation = Vector3.zero; val3.verticalOffset = 0.0665f; val3.toolTips = new string[1] { "Drink : [LMB]" }; if ((Object)(object)val2 != (Object)null) { val3.itemIcon = val2; } val3.spawnPositionTypes = new List<ItemGroup>(); Properties = val3; ((GrabbableObject)Prefab.GetComponent<BeerItem>()).itemProperties = val3; CopyAudio(val.spawnPrefab.GetComponent<AudioSource>(), Prefab.GetComponent<AudioSource>()); } } private static Sprite? MakeIcon() { //IL_0042: 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) Texture2D val = PocketDimension.LoadEmbeddedImage("BagOfHolding.beericon.png"); if ((Object)(object)val == (Object)null) { return null; } ((Object)val).name = "BagOfHoldingBeerIcon"; ((Object)val).hideFlags = (HideFlags)61; Sprite obj = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f); ((Object)obj).name = "BagOfHoldingBeerIcon"; ((Object)obj).hideFlags = (HideFlags)61; return obj; } internal static void CopyAudio(AudioSource? from, AudioSource? to) { //IL_0034: 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: Invalid comparison between Unknown and I4 if ((Object)(object)to == (Object)null) { return; } to.playOnAwake = false; to.spatialBlend = 1f; if (!((Object)(object)from == (Object)null)) { to.outputAudioMixerGroup = from.outputAudioMixerGroup; to.rolloffMode = from.rolloffMode; if ((int)from.rolloffMode == 2) { to.SetCustomCurve((AudioSourceCurveType)0, from.GetCustomCurve((AudioSourceCurveType)0)); } to.minDistance = from.minDistance; to.maxDistance = from.maxDistance; to.dopplerLevel = from.dopplerLevel; to.spread = from.spread; to.volume = from.volume; to.priority = from.priority; } } public override void Start() { if ((Object)(object)Properties == (Object)null) { MakeProperties(); } if ((Object)(object)base.itemProperties == (Object)null && (Object)(object)Properties != (Object)null) { base.itemProperties = Properties; } if ((Object)(object)base.itemProperties == (Object)null) { Plugin.Log.LogWarning((object)"The beer has no item settings (no TZP-Inhalant found); removing it."); if (((NetworkBehaviour)this).IsServer) { ((NetworkBehaviour)this).NetworkObject.Despawn(true); } } else { BuildLooks(); ((GrabbableObject)this).Start(); ((GrabbableObject)this).SetScrapValue(0); } } private void BuildLooks() { //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005a: 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_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) if (!built && !((Object)(object)PocketDimension.Instance == (Object)null)) { built = true; GameObject val = PocketDimension.Instance.MakeBeerModel(((Component)this).gameObject, ((Component)this).gameObject.layer); base.mainObjectRenderer = val.GetComponentInChildren<MeshRenderer>(); int num = LayerMask.NameToLayer("ScanNode"); GameObject val2 = new GameObject("ScanNode") { layer = ((num >= 0) ? num : 22) }; val2.transform.SetParent(((Component)this).transform, false); BoxCollider obj = val2.AddComponent<BoxCollider>(); ((Collider)obj).isTrigger = true; obj.size = Vector3.one * 0.1f; ScanNodeProperties obj2 = val2.AddComponent<ScanNodeProperties>(); obj2.headerText = "Beer"; obj2.subText = "Value: $0"; obj2.nodeType = 2; obj2.minRange = 1; obj2.maxRange = 13; obj2.requiresLineOfSight = true; obj2.creatureScanID = -1; } } public override void LateUpdate() { //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) //IL_0079: 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_0083: 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_0095: 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_00a1: 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_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) ((GrabbableObject)this).LateUpdate(); PlayerControllerB playerHeldBy = base.playerHeldBy; if ((Object)(object)base.parentObject == (Object)null || (Object)(object)playerHeldBy == (Object)null || base.isPocketed || !base.isHeld) { return; } int num; Transform transform; if ((Object)(object)playerHeldBy == (Object)(object)WheelController.LocalPlayer) { num = (((Object)(object)playerHeldBy.gameplayCamera != (Object)null) ? 1 : 0); if (num != 0) { transform = ((Component)playerHeldBy.gameplayCamera).transform; goto IL_0067; } } else { num = 0; } transform = ((Component)playerHeldBy).transform; goto IL_0067; IL_0067: Transform val = transform; Vector3 val2 = Quaternion.AngleAxis(-12f, val.right) * val.up; ((Component)this).transform.rotation = Quaternion.FromToRotation(((Component)this).transform.up, val2) * ((Component)this).transform.rotation; if (num != 0) { Transform transform2 = ((Component)this).transform; transform2.position += val.right * 0.055f; } } public override void ItemActivate(bool used, bool buttonDown = true) { ((GrabbableObject)this).ItemActivate(used, buttonDown); if (buttonDown && (Object)(object)base.playerHeldBy != (Object)null && (Object)(object)base.playerHeldBy == (Object)(object)WheelController.LocalPlayer && (Object)(object)PocketDimension.Instance != (Object)null) { PocketDimension.Instance.DrinkBeer(this); } } } internal static class BeerItemPatches { [HarmonyPostfix] [HarmonyPatch(typeof(GameNetworkManager), "Start")] private static void RegisterPrefab() { BeerItem.Register(); } [HarmonyPostfix] [HarmonyPatch(typeof(StartOfRound), "Start")] private static void MakeProperties() { BeerItem.MakeProperties(); } } internal static class DropSoundPatches { private static readonly Dictionary<GrabbableObject, float> dropStarted = new Dictionary<GrabbableObject, float>(); [HarmonyPostfix] [HarmonyPatch(typeof(GrabbableObject), "PlayDropSFX")] private static void NoteDrop(GrabbableObject __instance) { if (!((Object)(object)__instance == (Object)null) && !((Object)(object)__instance.itemProperties == (Object)null) && !((Object)(object)__instance.itemProperties.dropSFX == (Object)null)) { if (dropStarted.Count > 64) { dropStarted.Clear(); } dropStarted[__instance] = Time.time; } } [HarmonyPrefix] [HarmonyPatch(typeof(BeltBagItem), "PutObjectInBagLocalClient")] private static void FinishDropSound(GrabbableObject gObject) { //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: 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_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Invalid comparison between Unknown and I4 //IL_01a6: Expected O, but got Unknown if ((Object)(object)gObject == (Object)null || !dropStarted.TryGetValue(gObject, out var value)) { return; } dropStarted.Remove(gObject); AudioClip val = (((Object)(object)gObject.itemProperties != (Object)null) ? gObject.itemProperties.dropSFX : null); AudioSource component = ((Component)gObject).GetComponent<AudioSource>(); if ((Object)(object)val == (Object)null || (Object)(object)component == (Object)null || !component.isPlaying) { return; } float num = (Time.time - value) * Mathf.Abs(component.pitch); if (!(num >= val.length - 0.02f)) { GameObject val2 = new GameObject("BagOfHolding.DropSound"); val2.transform.position = ((Component)gObject).transform.position; AudioSource val3 = val2.AddComponent<AudioSource>(); val3.outputAudioMixerGroup = component.outputAudioMixerGroup; val3.spatialBlend = component.spatialBlend; val3.rolloffMode = component.rolloffMode; if ((int)component.rolloffMode == 2) { val3.SetCustomCurve((AudioSourceCurveType)0, component.GetCustomCurve((AudioSourceCurveType)0)); } val3.minDistance = component.minDistance; val3.maxDistance = component.maxDistance; val3.dopplerLevel = component.dopplerLevel; val3.spread = component.spread; val3.priority = component.priority; val3.volume = component.volume; val3.pitch = component.pitch; val3.clip = val; val3.time = Mathf.Clamp(num, 0f, val.length - 0.02f); val3.Play(); component.Stop(); Object.Destroy((Object)val2, (val.length - num) / Mathf.Max(0.01f, Mathf.Abs(component.pitch)) + 0.1f); } } } internal static class GameAccess { public static readonly FieldRef<PlayerControllerB, GrabbableObject?> CurrentlyGrabbing = AccessTools.FieldRefAccess<PlayerControllerB, GrabbableObject>("currentlyGrabbingObject"); public static readonly FieldRef<PlayerControllerB, Coroutine?> GrabCoroutine = AccessTools.FieldRefAccess<PlayerControllerB, Coroutine>("grabObjectCoroutine"); public static readonly FieldRef<PlayerControllerB, bool> GrabInvalidated = AccessTools.FieldRefAccess<PlayerControllerB, bool>("grabInvalidated"); public static readonly FieldRef<PlayerControllerB, bool> ThrowingObject = AccessTools.FieldRefAccess<PlayerControllerB, bool>("throwingObject"); public static readonly FieldRef<PlayerControllerB, float> TimeSinceSwitchingSlots = AccessTools.FieldRefAccess<PlayerControllerB, float>("timeSinceSwitchingSlots"); public static readonly Func<PlayerControllerB, GrabbableObject?, int> FirstEmptyItemSlot = Bind<Func<PlayerControllerB, GrabbableObject, int>>("FirstEmptyItemSlot"); public static readonly Func<PlayerControllerB, bool, int> NextItemSlot = Bind<Func<PlayerControllerB, bool, int>>("NextItemSlot"); public static readonly Action<PlayerControllerB, int, GrabbableObject?> SwitchToItemSlot = Bind<Action<PlayerControllerB, int, GrabbableObject>>("SwitchToItemSlot"); public static readonly Action<PlayerControllerB, int> SwitchToSlotServerRpc = Bind<Action<PlayerControllerB, int>>("SwitchToSlotServerRpc"); public static readonly Action<PlayerControllerB, bool> SwitchItemSlotsServerRpc = Bind<Action<PlayerControllerB, bool>>("SwitchItemSlotsServerRpc"); public static readonly Func<PlayerControllerB, IEnumerator> GrabObject = Bind<Func<PlayerControllerB, IEnumerator>>("GrabObject"); public static readonly Action<PlayerControllerB, NetworkObjectReference> GrabObjectServerRpc = Bind<Action<PlayerControllerB, NetworkObjectReference>>("GrabObjectServerRpc"); public static readonly Action<PlayerControllerB, bool, GrabbableObject?> SetSpecialGrabAnimationBool = Bind<Action<PlayerControllerB, bool, GrabbableObject>>("SetSpecialGrabAnimationBool"); public const int UtilitySlot = 50; private static T Bind<T>(string method) where T : Delegate { return AccessTools.MethodDelegate<T>(AccessTools.Method(typeof(PlayerControllerB), method, (Type[])null, (Type[])null), (object)null, true); } public static bool InInventory(PlayerControllerB player, GrabbableObject item) { if ((Object)(object)player.ItemOnlySlot == (Object)(object)item) { return true; } GrabbableObject[] itemSlots = player.ItemSlots; for (int i = 0; i < itemSlots.Length; i++) { if ((Object)(object)itemSlots[i] == (Object)(object)item) { return true; } } return false; } public static GrabbableObject? Held(PlayerControllerB player) { if (player.currentItemSlot != 50) { if (player.currentItemSlot < 0 || player.currentItemSlot >= player.ItemSlots.Length) { return null; } return player.ItemSlots[player.currentItemSlot]; } return player.ItemOnlySlot; } public static int SlotAfterEmptyingHeld(PlayerControllerB player, GrabbableObject item) { bool num = (Object)(object)player.ItemOnlySlot == (Object)null || player.currentItemSlot == 50; Item itemProperties = item.itemProperties; if (num && !itemProperties.isScrap && !itemProperties.twoHanded && !itemProperties.disallowUtilitySlot) { return 50; } if (player.currentItemSlot != 50) { return player.currentItemSlot; } for (int i = 0; i < player.ItemSlots.Length; i++) { if ((Object)(object)player.ItemSlots[i] == (Object)null) { return i; } } return -1; } } internal readonly struct SyncedSettings { public readonly int BagPounds; public readonly bool CountContents; public readonly int ContentsReduction; public readonly bool AllowWeapons; public readonly bool PocketDimension; public readonly bool PortableCharger; public static readonly SyncedSettings Vanilla = new SyncedSettings(16, countContents: false, 50, allowWeapons: false, pocketDimension: false, portableCharger: false); public SyncedSettings(int bagPounds, bool countContents, int contentsReduction, bool allowWeapons, bool pocketDimension, bool portableCharger) { PortableCharger = portableCharger; PocketDimension = pocketDimension; BagPounds = Mathf.Clamp(bagPounds, 0, 100); CountContents = countContents; ContentsReduction = Mathf.Clamp(contentsReduction, 0, 100); AllowWeapons = allowWeapons; } public static SyncedSettings FromConfig() { return new SyncedSettings(Plugin.BagWeight.Value, Plugin.CountContentsWeight.Value, Plugin.ContentsWeightReduction.Value, Plugin.AllowWeapons.Value, Plugin.PocketDimension.Value, Plugin.PortableCharger.Value); } public bool Equals(SyncedSettings o) { if (BagPounds == o.BagPounds && CountContents == o.CountContents && ContentsReduction == o.ContentsReduction && AllowWeapons == o.AllowWeapons && PocketDimension == o.PocketDimension) { return PortableCharger == o.PortableCharger; } return false; } public override string ToString() { return string.Format("bag {0} lb, contents {1}, weapons {2}, pocket dimension {3}, portable charger {4}", BagPounds, CountContents ? $"counted at {100 - ContentsReduction}%" : "weightless", AllowWeapons ? "allowed" : "not allowed", PocketDimension ? "on" : "off", PortableCharger ? "on" : "off"); } } internal sealed class HostSync : MonoBehaviour { private enum State { Offline, Host, Waiting, Synced, HostMissing, HostMismatch } private const string Hello = "achachala.betterbeltbag.hello"; private const string Settings = "achachala.betterbeltbag.settings"; private const int Protocol = 6; private const int SettingsBytes = 12; private const float HelloInterval = 2f; private const float ClientGiveUpAfter = 10f; private const float HostWarnAfter = 15f; private static State state = State.Offline; private static SyncedSettings hostSettings = SyncedSettings.Vanilla; private NetworkManager? network; private bool attached; private float nextHello; private float connectedAt; private SyncedSettings? announced; private bool toldPlayer; private readonly Dictionary<ulong, float> joinTimes = new Dictionary<ulong, float>(); private readonly HashSet<ulong> confirmed = new HashSet<ulong>(); private readonly HashSet<ulong> warned = new HashSet<ulong>(); public static bool Active { get { State state = HostSync.state; if ((uint)state <= 1u || state == State.Synced) { return true; } return false; } } public static bool IsClient { get { State state = HostSync.state; if ((uint)(state - 2) <= 3u) { return true; } return false; } } public static SyncedSettings Current { get { switch (state) { case State.Offline: case State.Host: return SyncedSettings.FromConfig(); case State.Synced: return hostSettings; default: return SyncedSettings.Vanilla; } } } public static string? InactiveReason => state switch { State.Waiting => "Waiting for the host to confirm Bag of Holding.", State.HostMissing => "The host doesn't have Bag of Holding, so it's turned off in this lobby. Every player needs it.", State.HostMismatch => "The host has a different version of Bag of Holding, so it's turned off. Everyone needs the same version.", _ => null, }; private unsafe void Update() { //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) NetworkManager singleton = NetworkManager.Singleton; if (attached && ((Object)(object)singleton != (Object)(object)network || (Object)(object)singleton == (Object)null || !singleton.IsListening)) { Detach(); } if ((Object)(object)singleton == (Object)null || !singleton.IsListening || singleton.CustomMessagingManager == null) { return; } if (!attached) { Attach(singleton); } if (singleton.IsServer) { state = State.Host; SyncedSettings syncedSettings = SyncedSettings.FromConfig(); if (!announced.HasValue || !announced.Value.Equals(syncedSettings)) { announced = syncedSettings; foreach (ulong item in confirmed) { Send(item); } } WarnAboutUnmoddedPlayers(singleton); return; } if (state == State.Waiting && singleton.IsConnectedClient) { if (connectedAt <= 0f) { connectedAt = Time.unscaledTime; } if (Time.unscaledTime - connectedAt > 10f) { state = State.HostMissing; Plugin.Log.LogWarning((object)"The host did not answer; Bag of Holding is off in this lobby."); } else if (Time.unscaledTime >= nextHello) { nextHello = Time.unscaledTime + 2f; FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(4, (Allocator)2, -1); try { int num = 6; ((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives)); singleton.CustomMessagingManager.SendNamedMessage("achachala.betterbeltbag.hello", 0uL, val, (NetworkDelivery)3); } finally { ((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose(); } } } if (!toldPlayer && (state == State.HostMissing || state == State.HostMismatch) && (Object)(object)HUDManager.Instance != (Object)null && (Object)(object)GameNetworkManager.Instance != (Object)null && (Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null) { toldPlayer = true; HUDManager.Instance.DisplayTip("Bag of Holding", InactiveReason, true, false, "LC_Tip1"); } } private void Attach(NetworkManager current) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Expected O, but got Unknown network = current; current.CustomMessagingManager.RegisterNamedMessageHandler("achachala.betterbeltbag.hello", new HandleNamedMessageDelegate(ReceiveHello)); current.CustomMessagingManager.RegisterNamedMessageHandler("achachala.betterbeltbag.settings", new HandleNamedMessageDelegate(ReceiveSettings)); current.OnClientConnectedCallback += ClientConnected; current.OnClientDisconnectCallback += ClientDisconnected; attached = true; state = (current.IsServer ? State.Host : State.Waiting); nextHello = (connectedAt = 0f); announced = null; toldPlayer = false; if (!current.IsServer) { return; } foreach (ulong connectedClientsId in current.ConnectedClientsIds) { if (connectedClientsId != current.LocalClientId) { joinTimes[connectedClientsId] = Time.unscaledTime; } } } private void OnDestroy() { Detach(); } private void Detach() { if ((Object)(object)network != (Object)null) { network.OnClientConnectedCallback -= ClientConnected; network.OnClientDisconnectCallback -= ClientDisconnected; if (network.CustomMessagingManager != null) { network.CustomMessagingManager.UnregisterNamedMessageHandler("achachala.betterbeltbag.hello"); network.CustomMessagingManager.UnregisterNamedMessageHandler("achachala.betterbeltbag.settings"); } } network = null; attached = false; announced = null; joinTimes.Clear(); confirmed.Clear(); warned.Clear(); state = State.Offline; hostSettings = SyncedSettings.Vanilla; } private void ClientConnected(ulong client) { if ((Object)(object)network != (Object)null && network.IsServer && client != network.LocalClientId) { joinTimes[client] = Time.unscaledTime; } } private void ClientDisconnected(ulong client) { joinTimes.Remove(client); confirmed.Remove(client); warned.Remove(client); } private void WarnAboutUnmoddedPlayers(NetworkManager current) { foreach (KeyValuePair<ulong, float> joinTime in joinTimes) { ulong key = joinTime.Key; if (!confirmed.Contains(key) && !warned.Contains(key) && !(Time.unscaledTime - joinTime.Value < 15f) && current.ConnectedClients.ContainsKey(key)) { warned.Add(key); string text = PlayerName(key); Plugin.Log.LogWarning((object)string.Format("{0} (client {1}) doesn't have Bag of Holding {2}.", text, key, "1.0.0")); if ((Object)(object)HUDManager.Instance != (Object)null) { HUDManager.Instance.DisplayTip("Bag of Holding", text + " doesn't have Bag of Holding 1.0.0. Every player needs it for belt bags to work correctly.", true, false, "LC_Tip1"); } } } } private static string PlayerName(ulong client) { StartOfRound instance = StartOfRound.Instance; if ((Object)(object)instance != (Object)null && instance.allPlayerScripts != null) { PlayerControllerB[] allPlayerScripts = instance.allPlayerScripts; foreach (PlayerControllerB val in allPlayerScripts) { if ((Object)(object)val != (Object)null && val.actualClientId == client && !string.IsNullOrEmpty(val.playerUsername)) { return val.playerUsername; } } } return $"Player {client}"; } private unsafe void Send(ulong client) { //IL_0035: 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_004c: 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_0063: 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_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0080: 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_0097: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)network == (Object)null || network.CustomMessagingManager == null) { return; } SyncedSettings syncedSettings = SyncedSettings.FromConfig(); FastBufferWriter val = default(FastBufferWriter); ((FastBufferWriter)(ref val))..ctor(32, (Allocator)2, -1); try { int num = 6; ((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref syncedSettings.BagPounds, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref syncedSettings.CountContents, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref syncedSettings.ContentsReduction, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref syncedSettings.AllowWeapons, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref syncedSettings.PocketDimension, default(ForPrimitives)); ((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref syncedSettings.PortableCharger, default(ForPrimitives)); network.CustomMessagingManager.SendNamedMessage("achachala.betterbeltbag.settings", client, val, (NetworkDelivery)3); } finally { ((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose(); } } private void ReceiveHello(ulong sender, FastBufferReader reader) { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)network == (Object)null || !network.IsServer || !network.ConnectedClients.ContainsKey(sender) || !((FastBufferReader)(ref reader)).TryBeginRead(4)) { return; } int num = default(int); ((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives)); if (num == 6) { if (confirmed.Add(sender)) { Plugin.Log.LogInfo((object)(PlayerName(sender) + " has Bag of Holding.")); } } else { Plugin.Log.LogWarning((object)$"{PlayerName(sender)} has a different Bag of Holding version (protocol {num}, host {6})."); } Send(sender); } private void ReceiveSettings(ulong sender, FastBufferReader reader) { //IL_002f: 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_00a1: 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_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: 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_00cd: 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_00e0: 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_00f3: 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_0106: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)network == (Object)null || network.IsServer || sender != 0L || !((FastBufferReader)(ref reader)).TryBeginRead(4)) { return; } int num = default(int); ((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives)); if (num != 6) { if (state != State.HostMismatch) { Plugin.Log.LogWarning((object)$"Host has a different Bag of Holding version (protocol {num}, ours {6}); turning it off."); } state = State.HostMismatch; return; } if (!((FastBufferReader)(ref reader)).TryBeginRead(12)) { Plugin.Log.LogWarning((object)$"The host's belt bag settings message was too short ({((FastBufferReader)(ref reader)).Length} bytes); ignoring it."); return; } int bagPounds = default(int); ((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref bagPounds, default(ForPrimitives)); bool countContents = default(bool); ((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref countContents, default(ForPrimitives)); int contentsReduction = default(int); ((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref contentsReduction, default(ForPrimitives)); bool allowWeapons = default(bool); ((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref allowWeapons, default(ForPrimitives)); bool pocketDimension = default(bool); ((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref pocketDimension, default(ForPrimitives)); bool portableCharger = default(bool); ((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref portableCharger, default(ForPrimitives)); SyncedSettings syncedSettings = new SyncedSettings(bagPounds, countContents, contentsReduction, allowWeapons, pocketDimension, portableCharger); if (state != State.Synced || !hostSettings.Equals(syncedSettings)) { Plugin.Log.LogInfo((object)$"Using the host's belt bag settings: {syncedSettings}."); } hostSettings = syncedSettings; state = State.Synced; } } internal static class LethalConfigSupport { [CompilerGenerated] private static class <>O { public static CanModifyDelegate <0>__HostOnly; } [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static CanModifyDelegate <>9__1_0; public static CanModifyDelegate <>9__1_1; internal CanModifyResult <Register>b__1_0() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: 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_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) CanModifyResult val = HostOnly(); if (!CanModifyResult.op_Implicit(val)) { return val; } if (!Plugin.PortableCharger.Value) { return CanModifyResult.False("Turn on Portable charger (and save) to use this."); } return CanModifyResult.True(); } internal CanModifyResult <Register>b__1_1() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: 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_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) CanModifyResult val = HostOnly(); if (!CanModifyResult.op_Implicit(val)) { return val; } if (!Plugin.CountContentsWeight.Value) { return CanModifyResult.False("Turn on CountContentsWeight (and save) to use this."); } return CanModifyResult.True(); } } public const string Guid = "ainavt.lc.lethalconfig"; public static void Register() { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: 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_0041: Expected O, but got Unknown //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Expected O, but got Unknown //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: 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_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Expected O, but got Unknown //IL_007d: Expected O, but got Unknown //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Expected O, but got Unknown //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Expected O, but got Unknown //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Expected O, but got Unknown //IL_00a9: 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_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown //IL_00de: Expected O, but got Unknown //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Expected O, but got Unknown //IL_00e8: 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_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Expected O, but got Unknown //IL_011a: Expected O, but got Unknown //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Expected O, but got Unknown //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0129: 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_0137: Expected O, but got Unknown //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Expected O, but got Unknown //IL_013f: 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_0110: Expected O, but got Unknown //IL_0165: Expected O, but got Unknown //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Expected O, but got Unknown //IL_016f: 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_017b: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0155: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Expected O, but got Unknown //IL_01a1: Expected O, but got Unknown //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Expected O, but got Unknown //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Expected O, but got Unknown //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Expected O, but got Unknown //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Expected O, but got Unknown //IL_01f0: Expected O, but got Unknown //IL_01eb: Unknown result type (might be due to invalid IL or missing references) //IL_01f5: Expected O, but got Unknown //IL_01fb: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Expected O, but got Unknown //IL_020b: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Expected O, but got Unknown //IL_021b: Unknown result type (might be due to invalid IL or missing references) //IL_0225: Expected O, but got Unknown //IL_022b: Unknown result type (might be due to invalid IL or missing references) //IL_0235: Expected O, but got Unknown //IL_023b: Unknown result type (might be due to invalid IL or missing references) //IL_0245: Expected O, but got Unknown //IL_024b: Unknown result type (might be due to invalid IL or missing references) //IL_0255: Expected O, but got Unknown //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Expected O, but got Unknown LethalConfigManager.SetModDescription("Climb inside your belt bag, plus a quick item wheel and more belt bag options."); ConfigEntry<bool> pocketDimension = Plugin.PocketDimension; BoolCheckBoxOptions val = new BoolCheckBoxOptions { RequiresRestart = false }; object obj = <>O.<0>__HostOnly; if (obj == null) { CanModifyDelegate val2 = HostOnly; <>O.<0>__HostOnly = val2; obj = (object)val2; } ((BaseOptions)val).CanModifyCallback = (CanModifyDelegate)obj; LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(pocketDimension, val)); ConfigEntry<bool> portableCharger = Plugin.PortableCharger; BoolCheckBoxOptions val3 = new BoolCheckBoxOptions { RequiresRestart = false }; object obj2 = <>O.<0>__HostOnly; if (obj2 == null) { CanModifyDelegate val4 = HostOnly; <>O.<0>__HostOnly = val4; obj2 = (object)val4; } ((BaseOptions)val3).CanModifyCallback = (CanModifyDelegate)obj2; LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(portableCharger, val3)); ConfigEntry<float> chargeRate = Plugin.ChargeRate; FloatStepSliderOptions val5 = new FloatStepSliderOptions { RequiresRestart = false }; ((BaseRangeOptions<float>)val5).Min = 0.1f; ((BaseRangeOptions<float>)val5).Max = 10f; val5.Step = 0.1f; object obj3 = <>c.<>9__1_0; if (obj3 == null) { CanModifyDelegate val6 = delegate { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: 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_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) CanModifyResult val15 = HostOnly(); if (!CanModifyResult.op_Implicit(val15)) { return val15; } return (!Plugin.PortableCharger.Value) ? CanModifyResult.False("Turn on Portable charger (and save) to use this.") : CanModifyResult.True(); }; <>c.<>9__1_0 = val6; obj3 = (object)val6; } ((BaseOptions)val5).CanModifyCallback = (CanModifyDelegate)obj3; LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatStepSliderConfigItem(chargeRate, val5)); ConfigEntry<bool> allowWeapons = Plugin.AllowWeapons; BoolCheckBoxOptions val7 = new BoolCheckBoxOptions { RequiresRestart = false }; object obj4 = <>O.<0>__HostOnly; if (obj4 == null) { CanModifyDelegate val8 = HostOnly; <>O.<0>__HostOnly = val8; obj4 = (object)val8; } ((BaseOptions)val7).CanModifyCallback = (CanModifyDelegate)obj4; LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(allowWeapons, val7)); ConfigEntry<int> bagWeight = Plugin.BagWeight; IntSliderOptions val9 = new IntSliderOptions { RequiresRestart = false }; ((BaseRangeOptions<int>)val9).Min = 0; ((BaseRangeOptions<int>)val9).Max = 100; object obj5 = <>O.<0>__HostOnly; if (obj5 == null) { CanModifyDelegate val10 = HostOnly; <>O.<0>__HostOnly = val10; obj5 = (object)val10; } ((BaseOptions)val9).CanModifyCallback = (CanModifyDelegate)obj5; LethalConfigManager.AddConfigItem((BaseConfigItem)new IntSliderConfigItem(bagWeight, val9)); ConfigEntry<bool> countContentsWeight = Plugin.CountContentsWeight; BoolCheckBoxOptions val11 = new BoolCheckBoxOptions { RequiresRestart = false }; object obj6 = <>O.<0>__HostOnly; if (obj6 == null) { CanModifyDelegate val12 = HostOnly; <>O.<0>__HostOnly = val12; obj6 = (object)val12; } ((BaseOptions)val11).CanModifyCallback = (CanModifyDelegate)obj6; LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(countContentsWeight, val11)); ConfigEntry<int> contentsWeightReduction = Plugin.ContentsWeightReduction; IntSliderOptions val13 = new IntSliderOptions { RequiresRestart = false }; ((BaseRangeOptions<int>)val13).Min = 0; ((BaseRangeOptions<int>)val13).Max = 100; object obj7 = <>c.<>9__1_1; if (obj7 == null) { CanModifyDelegate val14 = delegate { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: 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_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) CanModifyResult val15 = HostOnly(); if (!CanModifyResult.op_Implicit(val15)) { return val15; } return (!Plugin.CountContentsWeight.Value) ? CanModifyResult.False("Turn on CountContentsWeight (and save) to use this.") : CanModifyResult.True(); }; <>c.<>9__1_1 = val14; obj7 = (object)val14; } ((BaseOptions)val13).CanModifyCallback = (CanModifyDelegate)obj7; LethalConfigManager.AddConfigItem((BaseConfigItem)new IntSliderConfigItem(contentsWeightReduction, val13)); LethalConfigManager.AddConfigItem((BaseConfigItem)new TextInputFieldConfigItem(Plugin.OpenBinding, false)); LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(Plugin.SelectOnRelease, false)); LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(Plugin.TapToPutBack, false)); LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatSliderConfigItem(Plugin.HoldTime, false)); LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(Plugin.CenterCursorOnOpen, false)); LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatSliderConfigItem(Plugin.WheelScale, false)); } private static CanModifyResult HostOnly() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) if (!HostSync.IsClient) { return CanModifyResult.True(); } return CanModifyResult.False("The host's settings are used in this lobby."); } } [HarmonyPatch(typeof(PlayerControllerB))] internal static class PlayerPatches { [HarmonyPostfix] [HarmonyPatch("CanUseItem")] private static void CanUseItem(PlayerControllerB __instance, ref bool __result) { if (Blocked(__instance)) { __result = false; } } [HarmonyPrefix] [HarmonyPatch("ActivateItem_performed")] private static bool ActivateItem(PlayerControllerB __instance) { return !Blocked(__instance); } [HarmonyPrefix] [HarmonyPatch("ItemSecondaryUse_performed")] private static bool ItemSecondaryUse(PlayerControllerB __instance) { return !Blocked(__instance); } [HarmonyPrefix] [HarmonyPatch("ItemTertiaryUse_performed")] private static bool ItemTertiaryUse(PlayerControllerB __instance) { return !Blocked(__instance); } [HarmonyPrefix] [HarmonyPatch("Interact_performed")] private static bool Interact(PlayerControllerB __instance) { return !Blocked(__instance); } [HarmonyPrefix] [HarmonyPatch("Discard_performed")] private static bool Discard(PlayerControllerB __instance) { if (!((Object)(object)__instance != (Object)(object)WheelController.LocalPlayer) && !((Object)(object)PocketDimension.Instance == (Object)null)) { return !PocketDimension.Instance.Drinking; } return true; } [HarmonyPrefix] [HarmonyPatch("ScrollMouse_performed")] private static bool ScrollMouse(PlayerControllerB __instance, CallbackContext context) { if (Blocked(__instance)) { return false; } if ((Object)(object)__instance != (Object)(object)WheelController.LocalPlayer || __instance.inTerminalMenu || (Object)(object)BagHands.Instance == (Object)null) { return true; } SwitchIntent intent = ((((CallbackContext)(ref context)).ReadValue<float>() > 0f) ? SwitchIntent.ScrollForward : SwitchIntent.ScrollBack); return !BagHands.Instance.InterceptSwitch(__instance, intent); } [HarmonyPrefix] [HarmonyPatch("UseUtilitySlot_performed")] private static bool UseUtilitySlot(PlayerControllerB __instance) { if (Blocked(__instance)) { return false; } if ((Object)(object)__instance != (Object)(object)WheelController.LocalPlayer || (Object)(object)BagHands.Instance == (Object)null) { return true; } return !BagHands.Instance.InterceptSwitch(__instance, SwitchIntent.UtilitySlot); } private static bool Blocked(PlayerControllerB player) { if ((Object)(object)player == (Object)(object)WheelController.LocalPlayer) { if (!WheelController.BlocksItemInput) { if ((Object)(object)PocketDimension.Instance != (Object)null) { return PocketDimension.Instance.Drinking; } return false; } return true; } return false; } } [BepInPlugin("achachala.betterbeltbag", "Bag of Holding", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class Plugin : BaseUnityPlugin { public const string Id = "achachala.betterbeltbag"; public const string Version = "1.0.0"; internal static ManualLogSource Log; internal static ConfigEntry<string> OpenBinding; internal static ConfigEntry<bool> SelectOnRelease; internal static ConfigEntry<bool> TapToPutBack; internal static ConfigEntry<float> HoldTime; internal static ConfigEntry<bool> CenterCursorOnOpen; internal static ConfigEntry<float> WheelScale; internal static ConfigEntry<int> BagWeight; internal static ConfigEntry<bool> CountContentsWeight; internal static ConfigEntry<int> ContentsWeightReduction; internal static ConfigEntry<bool> AllowWeapons; internal static ConfigEntry<bool> PortableCharger; internal static ConfigEntry<float> ChargeRate; internal static ConfigEntry<bool> PocketDimension; private void Awake() { //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Expected O, but got Unknown //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Expected O, but got Unknown //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Expected O, but got Unknown //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Expected O, but got Unknown //IL_021d: Unknown result type (might be due to invalid IL or missing references) //IL_0227: Expected O, but got Unknown //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_0236: Unknown result type (might be due to invalid IL or missing references) //IL_0246: Unknown result type (might be due to invalid IL or missing references) //IL_0256: Unknown result type (might be due to invalid IL or missing references) //IL_0266: 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_0286: Unknown result type (might be due to invalid IL or missing references) //IL_0296: Unknown result type (might be due to invalid IL or missing references) //IL_02ba: Unknown result type (might be due to invalid IL or missing references) //IL_02bf: Unknown result type (might be due to invalid IL or missing references) //IL_02c7: Unknown result type (might be due to invalid IL or missing references) //IL_02cd: Expected O, but got Unknown //IL_02cd: Unknown result type (might be due to invalid IL or missing references) //IL_02d4: Unknown result type (might be due to invalid IL or missing references) //IL_02db: Unknown result type (might be due to invalid IL or missing references) //IL_02e2: Unknown result type (might be due to invalid IL or missing references) //IL_02e9: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; PocketDimension = ((BaseUnityPlugin)this).Config.Bind<bool>("1. Pocket dimension", "Pocket dimension", true, "Okay hear me out. The belt bag can store an infinite number of items without making the bag any heavier...there HAS to be a pocket dimension in there. Just try sticking your leg inside and see if the rest follows. I'm sure nothing bad will happen. (Disabling this disables the belt bag pocket dimension from spawning at all)."); PortableCharger = ((BaseUnityPlugin)this).Config.Bind<bool>("2. Portable charger", "Portable charger", true, "Since the belt bag is an infinite storage space, you decided to stick a portable battery bank inside, because why not? Battery items inside a belt bag slowly charge. Host setting."); ChargeRate = ((BaseUnityPlugin)this).Config.Bind<float>("2. Portable charger", "Charge rate", 0.5f, new ConfigDescription("How much charge the portable charger adds each second, in percent of a full battery (0.1 to 10). Host setting.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 10f), Array.Empty<object>())); AllowWeapons = ((BaseUnityPlugin)this).Config.Bind<bool>("3. Storage", "AllowWeapons", true, "Let kitchen knives, shotguns and shotgun shells go in the belt bag. Host setting."); BagWeight = ((BaseUnityPlugin)this).Config.Bind<int>("4. Weight", "BagWeight", 16, new ConfigDescription("How heavy the empty belt bag is, in pounds. Vanilla is 16. Host setting.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())); CountContentsWeight = ((BaseUnityPlugin)this).Config.Bind<bool>("4. Weight", "CountContentsWeight", false, "Make items inside the bag count toward your weight. Normally they weigh nothing. Host setting."); ContentsWeightReduction = ((BaseUnityPlugin)this).Config.Bind<int>("4. Weight", "ContentsWeightReduction", 50, new ConfigDescription("How much lighter the bag makes the items inside it, in percent (0 = full weight, 100 = weightless). Only used when CountContentsWeight is on. Host setting.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())); OpenBinding = ((BaseUnityPlugin)this).Config.Bind<string>("5. Controls", "OpenWheelBinding", "<Keyboard>/c", "The key to hold to open the bag wheel. Examples: <Keyboard>/c, <Keyboard>/v, <Mouse>/middleButton, <Gamepad>/dpad/down."); SelectOnRelease = ((BaseUnityPlugin)this).Config.Bind<bool>("5. Controls", "SelectOnRelease", true, "Letting go of the key while pointing at an item also takes it out (clicking always works)."); TapToPutBack = ((BaseUnityPlugin)this).Config.Bind<bool>("5. Controls", "TapToPutBack", true, "Tap the key (instead of holding it) to put the item in your hand back in the bag."); HoldTime = ((BaseUnityPlugin)this).Config.Bind<float>("5. Controls", "HoldTime", 0.2f, new ConfigDescription("How long, in seconds, to hold the key before the wheel opens (when TapToPutBack is on).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 1f), Array.Empty<object>())); CenterCursorOnOpen = ((BaseUnityPlugin)this).Config.Bind<bool>("5. Controls", "CenterCursorOnOpen", true, "Put the mouse cursor in the middle of the screen each time the wheel opens."); WheelScale = ((BaseUnityPlugin)this).Config.Bind<float>("6. Display", "WheelScale", 1f, new ConfigDescription("Size of the wheel on screen.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 2f), Array.Empty<object>())); Harmony val = new Harmony("achachala.betterbeltbag"); val.PatchAll(typeof(PlayerPatches)); val.PatchAll(typeof(WeightPatches)); val.PatchAll(typeof(BagStoragePatches)); val.PatchAll(typeof(PocketDimensionPatches)); val.PatchAll(typeof(NoteItemPatches)); val.PatchAll(typeof(DropSoundPatches)); val.PatchAll(typeof(BeerItemPatches)); val.PatchAll(typeof(BeerBuff)); GameObject val2 = new GameObject("BagOfHolding") { hideFlags = (HideFlags)61 }; Object.DontDestroyOnLoad((Object)val2); val2.AddComponent<WheelController>(); val2.AddComponent<BagHands>(); val2.AddComponent<HostSync>(); val2.AddComponent<BagWeights>(); val2.AddComponent<BagCharger>(); val2.AddComponent<PocketDimension>(); if (Chainloader.PluginInfos.ContainsKey("ainavt.lc.lethalconfig")) { RegisterLethalConfig(); } Log.LogInfo((object)"Bag of Holding 1.0.0 loaded."); } [MethodImpl(MethodImplOptions.NoInlining)] private static void RegisterLethalConfig() { try { LethalConfigSupport.Register(); } catch (Exception ex) { Log.LogWarning((object)("Could not add LethalConfig menu entries: " + ex.Message)); } } } internal sealed class PocketDimension : MonoBehaviour { private sealed class Calendar { public Renderer[] Boxes; public GameObject[] Crosses; public TextMeshPro Title; public TextMeshPro Footer; public string Shown = ""; } private sealed class Chair { public Transform Root; public readonly List<Collider> Colliders = new List<Collider>(); } private sealed class BatteryBank { public GameObject Root; public Renderer[] Leds; public Light Glow; } private sealed class WallClock { public Transform Hour; public Transform Minute; } private sealed class WebBuilder { private readonly List<Vector3> vertices = new List<Vector3>(); private readonly List<Vector3> normals = new List<Vector3>(); private readonly List<int> triangles = new List<int>(); private readonly Vector3 facing; public WebBuilder(Vector3 facing) { //IL_0028: 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) this.facing = facing; } public void Thread(Vector3 p, Vector3 q, float sag) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: 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_0012: 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_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_002f: 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_003c: 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_0058: 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_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: 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) //IL_00a6: 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_009e: 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_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: 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_00e7: 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_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_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0108: 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_0118: Unknown result type (might be due to invalid IL or missing references) //IL_011a: 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) //IL_0132: 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_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_019e: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Unknown result type (might be due to invalid IL or missing references) float num = Vector3.Distance(p, q); Vector3 val = Vector3.down * 0.6f - facing * 0.4f; Vector3 val2 = ((Vector3)(ref val)).normalized * (sag * num); Vector3[] array = (Vector3[])(object)new Vector3[7]; for (int i = 0; i <= 6; i++) { float num2 = (float)i / 6f; array[i] = Vector3.Lerp(p, q, num2) + val2 * (4f * num2 * (1f - num2)); } for (int j = 0; j < 2; j++) { Vector3 val3 = ((j == 0) ? facing : (-facing)); int count = vertices.Count; for (int k = 0; k <= 6; k++) { Vector3 val4 = array[Mathf.Min(k + 1, 6)] - array[Mathf.Max(k - 1, 0)]; val = Vector3.Cross(facing, val4); Vector3 val5 = ((Vector3)(ref val)).normalized * 0.00125f; vertices.Add(array[k] - val5); vertices.Add(array[k] + val5); normals.Add(val3); normals.Add(val3); } for (int l = 0; l < 6; l++) { int num3 = count + l * 2; int num4 = num3 + 1; int num5 = num3 + 2; int num6 = num3 + 3; if (Vector3.Dot(Vector3.Cross(vertices[num4] - vertices[num3], vertices[num5] - vertices[num3]), val3) >= 0f) { triangles.AddRange(new int[6] { num3, num4, num5, num4, num6, num5 }); } else { triangles.AddRange(new int[6] { num3, num5, num4, num4, num5, num6 }); } } } } public Mesh Build() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: 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_0024: 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_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Expected O, but got Unknown Mesh val = new Mesh { name = "BagRoomCobweb", hideFlags = (HideFlags)61 }; val.SetVertices(vertices); val.SetNormals(normals); val.SetTriangles(triangles, 0); val.RecalculateBounds(); return val; } } private sealed class Lamp { public Light Light; public Renderer[] Glass; public readonly List<(Light Light, Renderer Glass)> Others = new List<(Light, Renderer)>(); public Transform? Lever; public Collider? Switch; public bool? Shown; } private sealed class Visit { public BeltBagItem? Bag; public Vector3 EntryPosition; public float EntryRotation; public bool EntryInFactory; public Vector3 BagPositionAtEntry; } private readonly struct CanKey { public readonly float Time; public readonly float Tilt; public readonly Vector3 Top; public CanKey(float time, float x, float y, float z, float tilt) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) Time = time; Top = new Vector3(x, y, z); Tilt = tilt; } } private sealed class Fridge { public Transform Door; public Light InsideLight; public GameObject TakenCan; public Vector3 Spot; public readonly List<Collider> Colliders = new List<Collider>(); public int Openers; public float Angle; } private sealed class Peephole { public Collider? Pull; public Transform? PullPiece; public GameObject? ClosedTeeth; public GameObject? Open; public Renderer? View; public Vector3 PullClosed; public Vector3 PullOpen; } private enum RoomMessage : byte { Table, Request, Full, WantTable, Radio, Light, Secret, Drink, Station, WantBeer, FridgeOpen, GiveBeer, NoBeer, Tape } private readonly struct SavedRoom { public readonly bool RadioOff; public readonly bool LampOff; public readonly bool SecretOpen; public readonly byte Station; public SavedRoom(bool radioOff, bool lampOff, bool secretOpen, byte station) { RadioOff = radioOff; LampOff = lampOff; SecretOpen = secretOpen; Station = station; } } private sealed class Secret { public GameObject Wall; public GameObject OpenWall; public GameObject Room; public bool? Shown; } private sealed class BagMotion { public bool Tracking; public Vector3 LastPosition; public Vector3 Velocity; public Vector3 Acceleration; public Vector2 Swing; public Vector2 SwingSpeed; public float Shake; public float NextJolt; } private sealed class Relayed { public Transform Transform; public Transform? Parent; public Vector3 Rest; public PlayerControllerB? Voice; public OccludeAudio? Occlude; public bool OldOverride; public float OldOverrideValue; public AudioLowPassFilter? Lowpass; public bool AddedLowpass; public bool OldLowpa