using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using RetainItemsOnDeath.patches;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("RetainItemsOnDeath")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RetainItemsOnDeath")]
[assembly: AssemblyCopyright("Copyright © lisk8 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("73ba209f-b777-46ab-b9de-4072bb5f2438")]
[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 RetainItemsOnDeath
{
[BepInPlugin("RetainItemsOnDeath.lisk8", "Retain Items On Death", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
private void Awake()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"RetainItemsOnDeath loaded!");
Harmony.CreateAndPatchAll(typeof(PlayerStatusPatch), (string)null);
}
}
}
namespace RetainItemsOnDeath.patches
{
[HarmonyPatch(typeof(PlayerStatus), "PlayerDied")]
internal class PlayerStatusPatch
{
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
int num = -1;
int num2 = -1;
MethodInfo methodInfo = AccessTools.Method(typeof(Hotbar), "UpdateHotbar", (Type[])null, (Type[])null);
FieldInfo fieldInfo = AccessTools.Field(typeof(InventoryUI), "Instance");
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
for (int i = 0; i < list.Count; i++)
{
CodeInstruction val = list[i];
if (val.opcode == OpCodes.Ldsfld && val.operand == fieldInfo && num == -1)
{
num = i;
}
else if (val.opcode == OpCodes.Callvirt && val.operand == methodInfo)
{
num2 = i;
}
}
if (num > -1 && num2 > -1)
{
list.RemoveRange(num, num2 - num + 1);
int num3 = -1;
int num4 = -1;
MethodInfo methodInfo2 = AccessTools.Method(typeof(OtherInput), "ToggleInventory", (Type[])null, (Type[])null);
FieldInfo fieldInfo2 = AccessTools.Field(typeof(AchievementManager), "Instance");
for (int j = 0; j < list.Count; j++)
{
CodeInstruction val2 = list[j];
if (val2.opcode == OpCodes.Callvirt && val2.operand == methodInfo2)
{
num3 = j;
}
else if (val2.opcode == OpCodes.Ldsfld && val2.operand == fieldInfo2)
{
num4 = j;
}
}
if (num3 > -1 && num4 > -1)
{
list.RemoveRange(num3 + 2, num4 - num3 - 2);
list[num3 + 1].opcode = OpCodes.Nop;
return list.AsEnumerable();
}
throw new ArgumentException("Armor loop wasn't found!");
}
throw new ArgumentException("Items loop wasn't found!");
}
}
}