using System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("KeepInventory")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("KeepInventory")] [assembly: AssemblyCopyright("Copyright © 2026")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("8f3c1a92-6e4b-4d71-9c18-b7e2a04f5d11")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace KeepInventory; [BepInPlugin("kvasir.keepinventory", "Keep Inventory", "1.0.0")] public class Plugin : BaseUnityPlugin { private void Awake() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown Harmony val = new Harmony("kvasir.keepinventory"); val.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"KeepInventory loaded!"); } } public static class ItemStash { private static readonly FieldInfo PlayerField = AccessTools.Field(typeof(PlayerDying), "_player"); private static readonly MethodInfo GetOpenSlotMethod = AccessTools.Method(typeof(PlayerInventory), "GetOpenSlot", (Type[])null, (Type[])null); public static Player GetPlayer(PlayerDying dying) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown return (Player)PlayerField.GetValue(dying); } public static void StashHeldItem(Player player) { //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) Item heldItem = player.Holding.HeldItem; if (Object.op_Implicit((Object)(object)heldItem) && !Object.op_Implicit((Object)(object)heldItem.DeadPlayer)) { if (TryPutInInventory(player, heldItem)) { heldItem.PutInInventory(); player.Hands.DropItem(true, heldItem); player.Holding.SetHeldItem((Item)null); } else if ((Object)(object)heldItem.Holder == (Object)(object)player) { heldItem.Drop(true, Vector3.zero, Vector3.zero); } } } private static bool TryPutInInventory(Player player, Item item) { if (player.Inventory.HasItemInInventory(item)) { return true; } if (player.Inventory.ServerTryStoreHeldItem(item)) { return true; } int num = (int)GetOpenSlotMethod.Invoke(player.Inventory, new object[1] { 0 }); if (num < 0) { return false; } Server.Instance.PutItemInInventory(player, item, (byte)num); return true; } } [HarmonyPatch(typeof(PlayerInventory), "ServerDropAll")] public static class KeepInventoryOnRespawnPatch { private static bool Prefix() { return false; } } [HarmonyPatch(typeof(PlayerDying), "ServerDie")] public static class KeepHeldItemOnServerDiePatch { private static void Prefix(PlayerDying __instance) { ItemStash.StashHeldItem(ItemStash.GetPlayer(__instance)); } } [HarmonyPatch(typeof(PlayerDying), "LocalDie")] public static class KeepHeldItemOnLocalDiePatch { private static void Prefix(PlayerDying __instance) { ItemStash.StashHeldItem(ItemStash.GetPlayer(__instance)); } }