using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using LevelGeneration;
using Microsoft.CodeAnalysis;
using Player;
using SNetwork;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("MaxConsumables")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MaxConsumables")]
[assembly: AssemblyTitle("MaxConsumables")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace MaxConsumables
{
[HarmonyPatch]
internal class Patch
{
private const float resourcePackMaxLimit = 900f;
public static float GetConsumableMaxCapacity(float originalMaxCapacity)
{
return originalMaxCapacity * 8f;
}
[HarmonyPatch(typeof(LG_PickupItem_Sync), "AttemptInteract")]
[HarmonyPrefix]
public static void AttemptInteract_Prefix(LG_PickupItem_Sync __instance, pPickupItemInteraction interaction)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
SNet_Player player = default(SNet_Player);
if (SNet.IsMaster && (int)interaction.type == 0 && ((pPlayer)(ref interaction.pPlayer)).TryGetPlayer(ref player))
{
InterceptInteraction(__instance.item, player);
}
}
private static void InterceptInteraction(Item item, SNet_Player player)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Invalid comparison between Unknown and I4
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Invalid comparison between Unknown and I4
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Invalid comparison between Unknown and I4
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Invalid comparison between Unknown and I4
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
InventorySlot slot = item.pItemData.slot;
PlayerBackpack val = default(PlayerBackpack);
BackpackItem val2 = default(BackpackItem);
if (((int)slot != 4 && (int)slot != 5) || !PlayerBackpackManager.TryGetBackpack(player, ref val) || !val.TryGetBackpackItem(slot, ref val2) || val2.Instance.pItemData.itemID_gearCRC != item.pItemData.itemID_gearCRC)
{
return;
}
float num = (((int)slot == 4) ? 900f : GetConsumableMaxCapacity(item.ItemDataBlock.ConsumableAmmoMax));
AmmoType val3 = (AmmoType)(((int)slot == 4) ? 3 : 5);
float ammoInPack = val.AmmoStorage.GetAmmoInPack(val3);
if (ammoInPack >= num)
{
return;
}
float num2 = item.pItemData.custom.ammo + ammoInPack;
pItemData_Custom customData = item.GetCustomData();
if (num2 > num)
{
customData.ammo = num;
ItemInLevel val4 = ((Il2CppObjectBase)item).TryCast<ItemInLevel>();
if (val4 != null && val4.GetSyncComponent() != null)
{
((Item)val4).SetCustomData(customData, true);
val.AmmoStorage.SetAmmo(val3, num2 - num);
}
return;
}
PlayerBackpackManager.MasterRemoveItem(val2.Instance, player);
customData.ammo = num2;
ItemInLevel obj = ((Il2CppObjectBase)item).TryCast<ItemInLevel>();
if (obj != null)
{
iPickupItemSync syncComponent = obj.GetSyncComponent();
if (syncComponent != null)
{
syncComponent.SetCustomData(customData, true);
}
}
}
[HarmonyPatch(typeof(PlayerAmmoStorage), "UpdateAmmoInPack")]
[HarmonyPrefix]
public static bool UpdateAmmoInPack_Override_Prefix(PlayerAmmoStorage __instance, AmmoType ammoType, float delta, ref float __result)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Invalid comparison between Unknown and I4
InventorySlotAmmo inventorySlotAmmo = __instance.GetInventorySlotAmmo(ammoType);
float num = (((int)ammoType == 3) ? 900f : GetConsumableMaxCapacity(inventorySlotAmmo.AmmoMaxCap));
float num3 = (inventorySlotAmmo.AmmoInPack = Mathf.Clamp(inventorySlotAmmo.AmmoInPack + delta, 0f, num));
inventorySlotAmmo.OnBulletsUpdateCallback?.Invoke(inventorySlotAmmo.BulletsInPack);
__instance.NeedsSync = true;
__instance.UpdateSlotAmmoUI(inventorySlotAmmo, 0);
__result = num3;
return false;
}
[HarmonyPatch(typeof(PlayerAmmoStorage), "UpdateBulletsInPack")]
[HarmonyPrefix]
public static bool UpdateBulletsInPack_Override_Prefix(PlayerAmmoStorage __instance, AmmoType ammoType, int bulletCount, ref float __result)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Invalid comparison between Unknown and I4
InventorySlotAmmo inventorySlotAmmo = __instance.GetInventorySlotAmmo(ammoType);
float num = (float)bulletCount * inventorySlotAmmo.CostOfBullet;
float num2 = (((int)ammoType == 3) ? 900f : GetConsumableMaxCapacity(inventorySlotAmmo.AmmoMaxCap));
float num4 = (inventorySlotAmmo.AmmoInPack = Mathf.Clamp(inventorySlotAmmo.AmmoInPack + num, 0f, num2));
inventorySlotAmmo.OnBulletsUpdateCallback?.Invoke(inventorySlotAmmo.BulletsInPack);
__instance.NeedsSync = true;
__instance.UpdateSlotAmmoUI(inventorySlotAmmo, 0);
__result = num4;
return false;
}
}
[BepInPlugin("INF.MaxConsumables", "MaxConsumables", "1.0.0")]
public class PlugIn : BasePlugin
{
public override void Load()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
new Harmony("INF.MaxConsumables").PatchAll();
((BasePlugin)this).Log.LogInfo((object)"[ INF.MaxConsumables -> Loaded ]");
}
}
}