using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
[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("NestedContainers")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("NestedContainers")]
[assembly: AssemblyTitle("NestedContainers")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[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 NestedContainers
{
public static class PluginInfo
{
public const string PLUGIN_GUID = "com.ma_boi.nestedcontainers";
public const string PLUGIN_NAME = "NestedContainers";
public const string PLUGIN_VERSION = "1.0.1";
}
[BepInPlugin("com.ma_boi.nestedcontainers", "NestedContainers", "1.0.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Log;
private Harmony _harmony;
private void Awake()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
try
{
_harmony = new Harmony("com.ma_boi.nestedcontainers");
_harmony.PatchAll(typeof(Plugin).Assembly);
Log.LogInfo((object)"NestedContainers v1.0.1 loaded successfully.");
}
catch (Exception arg)
{
Log.LogError((object)string.Format("Failed to load {0}: {1}", "NestedContainers", arg));
}
}
private void OnDestroy()
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
}
[HarmonyPatch]
public static class ItemSlot_CanInsertItem_Patch
{
private static MethodBase TargetMethod()
{
Type type = AccessTools.TypeByName("ItemSlot");
if (type == null)
{
ManualLogSource log = Plugin.Log;
if (log != null)
{
log.LogWarning((object)"ItemSlot type not found – nesting patch disabled.");
}
return null;
}
MethodInfo methodInfo = new MethodInfo[5]
{
AccessTools.Method(type, "CanInsertItem", (Type[])null, (Type[])null),
AccessTools.Method(type, "CanInsert", (Type[])null, (Type[])null),
AccessTools.Method(type, "CanAcceptItem", (Type[])null, (Type[])null),
AccessTools.Method(type, "CanAccept", (Type[])null, (Type[])null),
AccessTools.Method(type, "AllowInsert", (Type[])null, (Type[])null)
}.FirstOrDefault((MethodInfo m) => m != null);
if (methodInfo == null)
{
methodInfo = type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((MethodInfo m) => m.Name.IndexOf("Insert", StringComparison.OrdinalIgnoreCase) >= 0 || m.Name.IndexOf("Accept", StringComparison.OrdinalIgnoreCase) >= 0);
}
if (methodInfo == null)
{
ManualLogSource log2 = Plugin.Log;
if (log2 != null)
{
log2.LogWarning((object)"No suitable CanInsert* method found on ItemSlot.");
}
}
else
{
ManualLogSource log3 = Plugin.Log;
if (log3 != null)
{
log3.LogInfo((object)("Patching ItemSlot." + methodInfo.Name));
}
}
return methodInfo;
}
private static bool Prefix(object __instance, object __0, ref bool __result)
{
try
{
if (__0 == null)
{
return true;
}
string itemIdentifier = GetItemIdentifier(__0);
if (string.IsNullOrEmpty(itemIdentifier))
{
return true;
}
itemIdentifier = itemIdentifier.ToLowerInvariant();
if (itemIdentifier.Contains("backpack") || itemIdentifier.Contains("fanny") || itemIdentifier.Contains("jetpack") || itemIdentifier.Contains("fannypack") || itemIdentifier.Contains("pack"))
{
__result = true;
return false;
}
}
catch (Exception ex)
{
ManualLogSource log = Plugin.Log;
if (log != null)
{
log.LogWarning((object)("NestedContainers prefix error: " + ex.Message));
}
}
return true;
}
private static string GetItemIdentifier(object item)
{
if (item == null)
{
return null;
}
Type type = item.GetType();
PropertyInfo propertyInfo = type.GetProperty("name") ?? type.GetProperty("Name");
if (propertyInfo != null)
{
string text = propertyInfo.GetValue(item) as string;
if (!string.IsNullOrEmpty(text))
{
return text;
}
}
string[] array = new string[6] { "typeID", "TypeID", "itemID", "ItemID", "id", "ID" };
foreach (string name in array)
{
MemberInfo memberInfo = (MemberInfo)(((object)type.GetProperty(name)) ?? ((object)type.GetField(name)));
if (memberInfo is PropertyInfo propertyInfo2)
{
string text2 = propertyInfo2.GetValue(item)?.ToString();
if (!string.IsNullOrEmpty(text2))
{
return text2;
}
}
else if (memberInfo is FieldInfo fieldInfo)
{
string text3 = fieldInfo.GetValue(item)?.ToString();
if (!string.IsNullOrEmpty(text3))
{
return text3;
}
}
}
MemberInfo memberInfo2 = (MemberInfo)(((object)type.GetProperty("prefab")) ?? ((object)type.GetField("prefab")));
if (memberInfo2 != null)
{
object obj = ((memberInfo2 is PropertyInfo propertyInfo3) ? propertyInfo3.GetValue(item) : ((FieldInfo)memberInfo2).GetValue(item));
if (obj != null)
{
string text4 = (obj.GetType().GetProperty("name")?.GetValue(obj) as string) ?? obj.ToString();
if (!string.IsNullOrEmpty(text4))
{
return text4;
}
}
}
return item.ToString();
}
}
}