using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using EpicLoot;
using HarmonyLib;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("InventoryWiperWithIndestructibleCheck")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("InventoryWiperWithIndestructibleCheck")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5172e328-2e2d-4f88-a013-19f0ec894454")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("com.yourname.indestructiblekeeper", "Indestructible Item Keeper", "1.7.0")]
public class IndestructibleItemKeeper : BaseUnityPlugin
{
[HarmonyPatch(typeof(Player), "OnDeath")]
public class OnDeathPatch
{
public static void Prefix(Player __instance)
{
Inventory inventory = ((Humanoid)__instance).GetInventory();
List<ItemData> list = inventory.GetAllItems().ToList();
string text = IndestructibleItemBehavior.Value.ToLowerInvariant();
if (text == "keep")
{
keptItems.Clear();
foreach (ItemData item in list)
{
MagicItem magicItem = ItemDataExtensions.GetMagicItem(item);
if (magicItem != null && magicItem.HasEffect(MagicEffectType.Indestructible))
{
keptItems.Add(item);
}
}
{
foreach (ItemData item2 in list)
{
inventory.RemoveItem(item2);
}
return;
}
}
foreach (ItemData item3 in list)
{
MagicItem magicItem2 = ItemDataExtensions.GetMagicItem(item3);
if (magicItem2 != null && magicItem2.HasEffect(MagicEffectType.Indestructible))
{
string text2 = text;
string text3 = text2;
if (!(text3 == "drop"))
{
if (!(text3 == "gravestone"))
{
((BaseUnityPlugin)Instance).Logger.LogWarning((object)("[IndestructibleItemKeeper] Unknown config value: '" + text + "', defaulting to Gravestone."));
}
}
else
{
((Humanoid)__instance).DropItem(inventory, item3, item3.m_stack);
inventory.RemoveItem(item3);
}
}
else
{
inventory.RemoveItem(item3);
}
}
}
}
[HarmonyPatch(typeof(Player), "Start")]
public class RespawnPatch
{
public static void Postfix(Player __instance)
{
if (!(IndestructibleItemBehavior.Value.ToLowerInvariant() == "keep"))
{
return;
}
Inventory inventory = ((Humanoid)__instance).GetInventory();
foreach (ItemData keptItem in keptItems)
{
inventory.AddItem(keptItem);
}
keptItems.Clear();
}
}
public static ConfigEntry<string> IndestructibleItemBehavior;
public static IndestructibleItemKeeper Instance;
private static List<ItemData> keptItems = new List<ItemData>();
private void Awake()
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Expected O, but got Unknown
Instance = this;
IndestructibleItemBehavior = ((BaseUnityPlugin)this).Config.Bind<string>("General", "IndestructibleItemAction", "Gravestone", new ConfigDescription("Choose what to do with Indestructible items on death: 'Gravestone', 'Drop', or 'Keep'.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[3] { "Gravestone", "Drop", "Keep" }), Array.Empty<object>()));
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
((BaseUnityPlugin)this).Logger.LogInfo((object)("[IndestructibleItemKeeper] Loaded. Current behavior: " + IndestructibleItemBehavior.Value));
}
}