using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using EquinoxsModUtils;
using FluffyUnderware.DevTools.Extensions;
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;
using VoidChests.Patches;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("VoidChests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("VoidChests")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("cbbf442e-9885-4b38-b9c9-9b306f6da3ac")]
[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 VoidChests
{
[BepInPlugin("com.equinox.VoidChests", "VoidChests", "1.0.0")]
public class VoidChestsPlugin : BaseUnityPlugin
{
private const string MyGUID = "com.equinox.VoidChests";
private const string PluginName = "VoidChests";
private const string VersionString = "1.0.0";
private static readonly Harmony Harmony = new Harmony("com.equinox.VoidChests");
public static ManualLogSource Log = new ManualLogSource("VoidChests");
private void Awake()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: VoidChests, VersionString: 1.0.0 is loading...");
Harmony.PatchAll();
Harmony.CreateAndPatchAll(typeof(InserterInstancePatch), (string)null);
Harmony.CreateAndPatchAll(typeof(InventoryNavigatorPatch), (string)null);
Harmony.CreateAndPatchAll(typeof(ChestDefinitionPatch), (string)null);
((BaseUnityPlugin)this).Logger.LogInfo((object)"PluginName: VoidChests, VersionString: 1.0.0 is loaded.");
Log = ((BaseUnityPlugin)this).Logger;
}
private void Update()
{
}
}
}
namespace VoidChests.Patches
{
internal class ChestDefinitionPatch
{
[HarmonyPatch(typeof(ChestDefinition), "InitInstance")]
[HarmonyPostfix]
private static void setLimit(ChestDefinition __instance, ref ChestInstance newInstance)
{
newInstance.restrictInputToSlots = 56;
}
}
public class InserterInstancePatch
{
[HarmonyPatch(typeof(InserterInstance), "Give")]
[HarmonyPostfix]
private static void VoidItems(InserterInstance __instance)
{
//IL_0001: 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)
//IL_000d: Invalid comparison between Unknown and I4
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: 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_002a: 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_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: 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_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: 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_0083: Unknown result type (might be due to invalid IL or missing references)
if ((int)__instance.giveResourceContainer.typeIndex != 3)
{
return;
}
GenericMachineInstanceRef val = __instance.giveResourceContainer.AsGeneric();
ChestInstance val2 = ((GenericMachineInstanceRef)(ref val)).Get<ChestInstance>();
if (val2.restrictInputToSlots == 0)
{
Inventory inventory = __instance.giveResourceContainer.GetInventory(0);
ResourceStack[] myStacks = inventory.myStacks;
foreach (ResourceStack val3 in myStacks)
{
((Inventory)(ref inventory)).RemoveResourcesFromSlot(ArrayExt.IndexOf<ResourceStack>(inventory.myStacks, val3), val3.count);
}
}
}
}
internal class InventoryNavigatorPatch
{
[HarmonyPatch(typeof(InventoryNavigator), "UpdateLimitedSlots")]
[HarmonyPostfix]
private static void allowZeroSlots(InventoryNavigator __instance, int limit)
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_009b: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: 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_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0218: Unknown result type (might be due to invalid IL or missing references)
//IL_022f: Unknown result type (might be due to invalid IL or missing references)
//IL_024b: Unknown result type (might be due to invalid IL or missing references)
//IL_0267: Unknown result type (might be due to invalid IL or missing references)
//IL_0283: Unknown result type (might be due to invalid IL or missing references)
//IL_029f: Unknown result type (might be due to invalid IL or missing references)
//IL_0146: Unknown result type (might be due to invalid IL or missing references)
//IL_0162: Unknown result type (might be due to invalid IL or missing references)
//IL_017e: Unknown result type (might be due to invalid IL or missing references)
//IL_019a: Unknown result type (might be due to invalid IL or missing references)
//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
//IL_01db: Unknown result type (might be due to invalid IL or missing references)
ModUtils.SetPrivateField<InventoryNavigator>("curLimit", __instance, (object)limit);
InventoryUI val = (InventoryUI)ModUtils.GetPrivateField<InventoryNavigator>("otherInventoryUI", __instance);
for (int i = 0; i < val.activeSlots.Count; i++)
{
val.activeSlots[i].SetSlotLimitMask(i >= limit);
}
if (!(bool)ModUtils.GetPrivateField<InventoryNavigator>("canUseSlotLimits", __instance))
{
FHG_Utils.ToggleActive(((Component)(Button)ModUtils.GetPrivateField<InventoryNavigator>("storageLimitClearButton", __instance)).gameObject, false);
FHG_Utils.ToggleActive(((Component)(Button)ModUtils.GetPrivateField<InventoryNavigator>("storageLimitSetButtonHilit", __instance)).gameObject, false);
FHG_Utils.ToggleActive(((Component)(Button)ModUtils.GetPrivateField<InventoryNavigator>("storageLimitSetButton", __instance)).gameObject, false);
FHG_Utils.ToggleActive(((Component)(Button)ModUtils.GetPrivateField<InventoryNavigator>("storageLimitCancelButton", __instance)).gameObject, false);
FHG_Utils.ToggleActive(((Component)(ButtonPromptUI)ModUtils.GetPrivateField<InventoryNavigator>("limitStorageBP", __instance)).gameObject, false);
FHG_Utils.ToggleActive(((Component)(ButtonPromptUI)ModUtils.GetPrivateField<InventoryNavigator>("clearLimitBP", __instance)).gameObject, false);
}
else if ((bool)ModUtils.GetPrivateField<InventoryNavigator>("settingLimit", __instance))
{
FHG_Utils.ToggleActive(((Component)(Button)ModUtils.GetPrivateField<InventoryNavigator>("storageLimitClearButton", __instance)).gameObject, false);
FHG_Utils.ToggleActive(((Component)(Button)ModUtils.GetPrivateField<InventoryNavigator>("storageLimitSetButtonHilit", __instance)).gameObject, true);
FHG_Utils.ToggleActive(((Component)(Button)ModUtils.GetPrivateField<InventoryNavigator>("storageLimitSetButton", __instance)).gameObject, false);
FHG_Utils.ToggleActive(((Component)(Button)ModUtils.GetPrivateField<InventoryNavigator>("storageLimitCancelButton", __instance)).gameObject, true);
val.Set(-1, false);
FHG_Utils.ToggleActive(((Component)(ButtonPromptUI)ModUtils.GetPrivateField<InventoryNavigator>("limitStorageBP", __instance)).gameObject, true);
FHG_Utils.ToggleActive(((Component)(ButtonPromptUI)ModUtils.GetPrivateField<InventoryNavigator>("clearLimitBP", __instance)).gameObject, true);
}
else
{
FHG_Utils.ToggleActive(((Component)(Button)ModUtils.GetPrivateField<InventoryNavigator>("storageLimitClearButton", __instance)).gameObject, true);
((Selectable)(Button)ModUtils.GetPrivateField<InventoryNavigator>("storageLimitClearButton", __instance)).interactable = true;
FHG_Utils.ToggleActive(((Component)(Button)ModUtils.GetPrivateField<InventoryNavigator>("storageLimitSetButton", __instance)).gameObject, true);
FHG_Utils.ToggleActive(((Component)(Button)ModUtils.GetPrivateField<InventoryNavigator>("storageLimitSetButtonHilit", __instance)).gameObject, false);
FHG_Utils.ToggleActive(((Component)(Button)ModUtils.GetPrivateField<InventoryNavigator>("storageLimitCancelButton", __instance)).gameObject, false);
FHG_Utils.ToggleActive(((Component)(ButtonPromptUI)ModUtils.GetPrivateField<InventoryNavigator>("limitStorageBP", __instance)).gameObject, true);
FHG_Utils.ToggleActive(((Component)(ButtonPromptUI)ModUtils.GetPrivateField<InventoryNavigator>("clearLimitBP", __instance)).gameObject, true);
}
}
[HarmonyPatch(typeof(InventoryNavigator), "StorageLimitClearCommand")]
[HarmonyPrefix]
private static bool clearLimit(InventoryNavigator __instance)
{
MethodInfo method = typeof(InventoryNavigator).GetMethod("UpdateLimitedSlots", BindingFlags.Instance | BindingFlags.NonPublic);
method.Invoke(__instance, new object[1] { 56 });
MethodInfo method2 = typeof(InventoryNavigator).GetMethod("StopSettingLimit", BindingFlags.Instance | BindingFlags.NonPublic);
method2.Invoke(__instance, new object[1] { true });
return false;
}
}
}