using System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Core.Logging.Interpolation; using BepInEx.Logging; using BepInEx.Unity.IL2CPP; using Gear; using HarmonyLib; 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("CasualAmmo")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+09d2c2ea46df3a13308590212e56ee5e753f33be")] [assembly: AssemblyProduct("CasualAmmo")] [assembly: AssemblyTitle("CasualAmmo")] [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.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] [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; } } [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 CasualAmmo { [BepInPlugin("com.privatecoop.gtfo.casualammo", "Casual Ammo", "1.0.13")] public sealed class Plugin : BasePlugin { public const string PluginGuid = "com.privatecoop.gtfo.casualammo"; public const string PluginName = "Casual Ammo"; public const string PluginVersion = "1.0.13"; private static readonly Harmony Harmony = new Harmony("com.privatecoop.gtfo.casualammo"); internal static ManualLogSource Logger = null; internal static ConfigEntry EnableMod = null; internal static ConfigEntry RestoreMode = null; internal static ConfigEntry RestoreMultiplier = null; internal static ConfigEntry MunitionPackCharges = null; internal static ConfigEntry InfiniteReserveAmmo = null; internal static ConfigEntry PrivateLobbyWarning = null; internal static bool IsEnabled => EnableMod?.Value ?? false; internal static float DesiredPackPercent => Math.Clamp(MunitionPackCharges.Value, 0f, 100f); public override void Load() { Logger = ((BasePlugin)this).Log; BindConfig(); LogStartupConfiguration(); if (!EnableMod.Value) { Logger.LogInfo((object)"EnableMod is false; Casual Ammo patches were not applied."); return; } Harmony.PatchAll(typeof(Plugin).Assembly); Logger.LogInfo((object)"Harmony patches applied."); } public override bool Unload() { Harmony.UnpatchSelf(); return true; } private void BindConfig() { EnableMod = ((BasePlugin)this).Config.Bind("General", "EnableMod", true, "Enables or disables all Casual Ammo changes."); RestoreMode = ((BasePlugin)this).Config.Bind("Ammo Restore", "AmmoRestoreMode", AmmoRestoreMode.FullRestore, "FullRestore, Multiplier, or Disabled."); RestoreMultiplier = ((BasePlugin)this).Config.Bind("Ammo Restore", "RestoreMultiplier", 10f, "Multiplier applied to munitions pack ammo restore when AmmoRestoreMode is Multiplier."); MunitionPackCharges = ((BasePlugin)this).Config.Bind("Munitions Packs", "MunitionPackCharges", 999f, "Minimum ammo capacity shown/stored on weapon munitions packs."); InfiniteReserveAmmo = ((BasePlugin)this).Config.Bind("Reserve Ammo", "InfiniteReserveAmmo", false, "When enabled, weapon reserve ammo storage is refilled to a very high cap after setup."); PrivateLobbyWarning = ((BasePlugin)this).Config.Bind("Safety", "PrivateLobbyWarning", true, "Logs a private-lobby-only warning on startup."); } private static void LogStartupConfiguration() { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Expected O, but got Unknown //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Expected O, but got Unknown //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Expected O, but got Unknown //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Expected O, but got Unknown if (PrivateLobbyWarning.Value) { Logger.LogWarning((object)"Casual Ammo is intended for private cooperative lobbies only. Do not use it in public matchmaking."); } ManualLogSource logger = Logger; bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(12, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("EnableMod = "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(EnableMod.Value); } logger.LogInfo(val); ManualLogSource logger2 = Logger; val = new BepInExInfoLogInterpolatedStringHandler(18, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("AmmoRestoreMode = "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(RestoreMode.Value); } logger2.LogInfo(val); ManualLogSource logger3 = Logger; val = new BepInExInfoLogInterpolatedStringHandler(20, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("RestoreMultiplier = "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(RestoreMultiplier.Value); } logger3.LogInfo(val); ManualLogSource logger4 = Logger; val = new BepInExInfoLogInterpolatedStringHandler(49, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("MunitionPackCharges = "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(MunitionPackCharges.Value); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (resolved pack percent = "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(DesiredPackPercent); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")"); } logger4.LogInfo(val); ManualLogSource logger5 = Logger; val = new BepInExInfoLogInterpolatedStringHandler(22, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("InfiniteReserveAmmo = "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(InfiniteReserveAmmo.Value); } logger5.LogInfo(val); if (EnableMod.Value) { Logger.LogInfo((object)"Patch plan: PlayerAgent.GiveAmmoRel adjusts standard/special weapon ammo restore only; class/tool ammo is left unchanged."); Logger.LogInfo((object)"Patch plan: ResourcePackPickup.OnInteractionPickUp logs and tops up weapon munitions packs on pickup."); Logger.LogInfo((object)"Patch plan: ResourcePackPickup.UpdateAmmo keeps weapon munitions packs stocked."); Logger.LogInfo((object)"Patch plan: ResourcePackFirstPerson.OnWield/ApplyPack tops up the equipped weapon munitions pack."); Logger.LogInfo((object)"Patch plan: ResourcePackFirstPerson.ApplyPack is replaced for weapon munitions packs to grant ammo without consuming the pack."); Logger.LogInfo((object)"Patch plan: PUI_Inventory.SetSlotAmmo keeps the resource-pack HUD display at the configured pack percent only while a weapon munitions pack is equipped."); Logger.LogInfo((object)"Patch plan: PlayerAmmoStorage.UpdateAmmoInPack and InventorySlotAmmo.AddAmmo force positive standard/special weapon ammo additions to full."); Logger.LogInfo((object)"Patch plan: PlayerAmmoStorage.SetupAmmoType only changes reserves when InfiniteReserveAmmo is true."); } } internal static bool IsWeaponAmmoPack(ResourcePackPickup pack) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Invalid comparison between Unknown and I4 if ((Object)(object)pack != (Object)null) { return (int)pack.m_packType == 1; } return false; } internal static bool IsWeaponAmmo(AmmoType type) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 if ((int)type <= 1) { return true; } return false; } } public enum AmmoRestoreMode { FullRestore, Multiplier, Disabled } [HarmonyPatch(typeof(PlayerAgent), "GiveAmmoRel")] internal static class PlayerAgentGiveAmmoRelPatch { private static void Prefix(ref float ammoStandardRel, ref float ammoSpecialRel, ref float ammoClassRel) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Expected O, but got Unknown if (!Plugin.IsEnabled || Plugin.RestoreMode.Value == AmmoRestoreMode.Disabled) { return; } bool flag = default(bool); switch (Plugin.RestoreMode.Value) { case AmmoRestoreMode.FullRestore: { ManualLogSource logger2 = Plugin.Logger; BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(85, 3, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Casual Ammo GiveAmmoRel hook: restore standard/special "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ammoStandardRel, "0.###"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("/"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ammoSpecialRel, "0.###"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" -> 1/1; class/tool remains "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ammoClassRel, "0.###"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("."); } logger2.LogWarning(val); if (ammoStandardRel > 0f) { ammoStandardRel = 1f; } if (ammoSpecialRel > 0f) { ammoSpecialRel = 1f; } break; } case AmmoRestoreMode.Multiplier: { float num = Math.Max(0f, Plugin.RestoreMultiplier.Value); ManualLogSource logger = Plugin.Logger; BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(81, 4, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Casual Ammo GiveAmmoRel hook: restore standard/special "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ammoStandardRel, "0.###"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("/"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ammoSpecialRel, "0.###"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" x "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(num, "0.###"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("; class/tool remains "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ammoClassRel, "0.###"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("."); } logger.LogWarning(val); if (ammoStandardRel > 0f) { ammoStandardRel *= num; } if (ammoSpecialRel > 0f) { ammoSpecialRel *= num; } break; } } } } [HarmonyPatch] internal static class ResourcePackPickupOnInteractionPickUpPatch { private static MethodBase TargetMethod() { return AccessTools.Method(typeof(ResourcePackPickup), "OnInteractionPickUp", new Type[1] { typeof(PlayerAgent) }, (Type[])null); } private static void Prefix(ResourcePackPickup __instance, PlayerAgent player) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Expected O, but got Unknown //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: 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_0067: Invalid comparison between Unknown and I4 //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Expected O, but got Unknown //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Expected O, but got Unknown //IL_0129: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.IsEnabled || (Object)(object)__instance == (Object)null) { return; } eResourceContainerSpawnType packType = __instance.m_packType; float num = -1f; bool flag = default(bool); try { num = ((Item)__instance).Get_pItemData().custom.ammo; } catch (Exception ex) { ManualLogSource logger = Plugin.Logger; BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(68, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Ammo pack pickup detected, but current pack ammo could not be read: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ex.Message); } logger.LogWarning(val); } if ((int)packType == 1) { float num2 = Math.Max(num, Plugin.DesiredPackPercent); __instance.UpdateAmmo(num2); ManualLogSource logger2 = Plugin.Logger; BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(77, 3, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Casual Ammo pickup hook: weapon munitions pack picked up by "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(GetPlayerLabel(player)); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(". Pack ammo "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(num, "0.##"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" -> "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(num2, "0.##"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("."); } logger2.LogWarning(val); } else { ManualLogSource logger3 = Plugin.Logger; BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(78, 3, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Casual Ammo pickup hook: non-weapon resource pack picked up by "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted(GetPlayerLabel(player)); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(". Type="); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted(packType); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(", ammo="); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted(num, "0.##"); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("."); } logger3.LogInfo(val2); } } private static string GetPlayerLabel(PlayerAgent player) { if ((Object)(object)player == (Object)null) { return "unknown player"; } try { SNet_Player owner = player.Owner; return ((owner != null) ? owner.NickName : null) ?? "unknown player"; } catch { return "unknown player"; } } } [HarmonyPatch(typeof(ResourcePackFirstPerson), "OnWield")] internal static class ResourcePackFirstPersonOnWieldPatch { private static void Postfix(ResourcePackFirstPerson __instance) { ResourcePackHudState.UpdateEquippedPack(__instance); EquippedResourcePackAmmo.TryTopUp(__instance, "OnWield", forceWrite: true); } } [HarmonyPatch] internal static class ResourcePackFirstPersonApplyPackPatch { private static MethodBase TargetMethod() { return AccessTools.Method(typeof(ResourcePackFirstPerson), "ApplyPack", (Type[])null, (Type[])null); } private static bool Prefix(ResourcePackFirstPerson __instance) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Invalid comparison between Unknown and I4 EquippedResourcePackAmmo.TryTopUp(__instance, "ApplyPack prefix", forceWrite: true); if (!Plugin.IsEnabled || (Object)(object)__instance == (Object)null || (int)__instance.m_packType != 1) { return true; } iResourcePackReceiver val = __instance.m_actionReceiver ?? __instance.m_lastActionReceiver; if (val == null) { Plugin.Logger.LogWarning((object)"Casual Ammo non-consuming ApplyPack: no action receiver found; allowing original ApplyPack."); return true; } PlayerAgent owner = ((Item)__instance).Owner; Plugin.Logger.LogWarning((object)"Casual Ammo non-consuming ApplyPack: granting full standard/special ammo through the resource receiver and skipping original pack consumption."); val.GiveAmmoRel(owner, 1f, 1f, 0f); EquippedResourcePackAmmo.TryTopUp(__instance, "ApplyPack manual grant", forceWrite: true); return false; } private static void Postfix(ResourcePackFirstPerson __instance) { EquippedResourcePackAmmo.TryTopUp(__instance, "ApplyPack postfix", forceWrite: true); } } internal static class EquippedResourcePackAmmo { internal static void TryTopUp(ResourcePackFirstPerson pack, string reason, bool forceWrite = false) { //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Expected O, but got Unknown //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Invalid comparison between Unknown and I4 //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: 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_0045: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Expected O, but got Unknown if (!Plugin.IsEnabled || (Object)(object)pack == (Object)null || (int)pack.m_packType != 1) { return; } bool flag = default(bool); try { pItemData_Custom customData = ((Item)pack).GetCustomData(); float ammo = customData.ammo; float num = Math.Max(ammo, Plugin.DesiredPackPercent); if (forceWrite || num > ammo) { customData.ammo = num; ((Item)pack).SetCustomData(customData, true); } if (ammo < num) { ManualLogSource logger = Plugin.Logger; BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(67, 3, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Casual Ammo equipped pack hook ("); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(reason); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("): weapon munitions pack ammo "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ammo, "0.##"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" -> "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(num, "0.##"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("."); } logger.LogWarning(val); } } catch (Exception ex) { ManualLogSource logger2 = Plugin.Logger; BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(42, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Casual Ammo equipped pack hook ("); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(reason); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(") failed: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ex.Message); } logger2.LogWarning(val); } } } internal static class ResourcePackHudState { internal static bool EquippedPackIsWeaponAmmo { get; private set; } internal static void UpdateEquippedPack(ResourcePackFirstPerson pack) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Invalid comparison between Unknown and I4 EquippedPackIsWeaponAmmo = Plugin.IsEnabled && (Object)(object)pack != (Object)null && (int)pack.m_packType == 1; } } [HarmonyPatch(typeof(ResourcePackPickup), "UpdateAmmo")] internal static class ResourcePackPickupUpdateAmmoPatch { private static void Prefix(ResourcePackPickup __instance, ref float ammo) { if (Plugin.IsEnabled && Plugin.IsWeaponAmmoPack(__instance)) { ammo = Math.Max(ammo, Plugin.DesiredPackPercent); } } } [HarmonyPatch(typeof(PUI_Inventory), "SetSlotAmmo")] internal static class PuiInventorySetSlotAmmoPatch { private static void Prefix(InventorySlot slot, ref int clipAbs, ref int inPackAbs, ref float inPackRel) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Invalid comparison between Unknown and I4 if (Plugin.IsEnabled && (int)slot == 4 && ResourcePackHudState.EquippedPackIsWeaponAmmo) { float desiredPackPercent = Plugin.DesiredPackPercent; inPackAbs = Math.Max(inPackAbs, (int)Math.Round(desiredPackPercent)); inPackRel = Math.Max(inPackRel, desiredPackPercent / 100f); } } } [HarmonyPatch(typeof(PlayerAmmoStorage), "SetupAmmoType")] internal static class PlayerAmmoStorageSetupAmmoTypePatch { private const float ReserveCap = 999f; private static void Postfix(PlayerAmmoStorage __instance, AmmoType type) { //IL_0013: 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) if (Plugin.IsEnabled && Plugin.InfiniteReserveAmmo.Value && Plugin.IsWeaponAmmo(type)) { InventorySlotAmmo inventorySlotAmmo = __instance.GetInventorySlotAmmo(type); if (inventorySlotAmmo != null) { inventorySlotAmmo.AmmoMaxCap = Math.Max(inventorySlotAmmo.AmmoMaxCap, 999f); inventorySlotAmmo.AmmoInPack = inventorySlotAmmo.AmmoMaxCap; __instance.UpdateSlotAmmoUI(inventorySlotAmmo, 0); } } } } [HarmonyPatch(typeof(PlayerAmmoStorage), "UpdateAmmoInPack")] internal static class PlayerAmmoStorageUpdateAmmoInPackPatch { private static void Prefix(PlayerAmmoStorage __instance, AmmoType ammoType, ref float delta) { //IL_0000: 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_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected O, but got Unknown //IL_0039: Unknown result type (might be due to invalid IL or missing references) if (ShouldForceFull(ammoType, delta)) { float num = SafeGetAmmo(__instance, ammoType); delta = 1f; ManualLogSource logger = Plugin.Logger; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(97, 3, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Casual Ammo storage hook: UpdateAmmoInPack("); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ammoType); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(") positive delta detected. Before="); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(num, "0.###"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", forcing delta to "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(delta, "0.###"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("."); } logger.LogWarning(val); } } private static void Postfix(PlayerAmmoStorage __instance, AmmoType ammoType, float delta) { //IL_0000: 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) if (ShouldForceFull(ammoType, delta)) { ForceStorageFull(__instance, ammoType, "UpdateAmmoInPack"); } } private static bool ShouldForceFull(AmmoType ammoType, float delta) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) if (Plugin.IsEnabled && Plugin.RestoreMode.Value == AmmoRestoreMode.FullRestore && Plugin.IsWeaponAmmo(ammoType)) { return delta > 0f; } return false; } private static float SafeGetAmmo(PlayerAmmoStorage storage, AmmoType ammoType) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) try { return storage.GetAmmoInPack(ammoType); } catch { return -1f; } } internal static void ForceStorageFull(PlayerAmmoStorage storage, AmmoType ammoType, string reason) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Expected O, but got Unknown //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Expected O, but got Unknown //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) bool flag = default(bool); try { InventorySlotAmmo inventorySlotAmmo = storage.GetInventorySlotAmmo(ammoType); BepInExWarningLogInterpolatedStringHandler val; if (inventorySlotAmmo == null) { ManualLogSource logger = Plugin.Logger; val = new BepInExWarningLogInterpolatedStringHandler(53, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Casual Ammo storage hook ("); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(reason); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("): no slot ammo found for "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ammoType); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("."); } logger.LogWarning(val); return; } float ammoInPack = inventorySlotAmmo.AmmoInPack; inventorySlotAmmo.AmmoInPack = Math.Max(inventorySlotAmmo.AmmoInPack, inventorySlotAmmo.AmmoMaxCap); storage.UpdateSlotAmmoUI(inventorySlotAmmo, 0); ManualLogSource logger2 = Plugin.Logger; val = new BepInExWarningLogInterpolatedStringHandler(47, 5, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Casual Ammo storage hook ("); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(reason); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("): "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ammoType); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ammo "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ammoInPack, "0.###"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" -> "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(inventorySlotAmmo.AmmoInPack, "0.###"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" / cap "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(inventorySlotAmmo.AmmoMaxCap, "0.###"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("."); } logger2.LogWarning(val); } catch (Exception ex) { ManualLogSource logger3 = Plugin.Logger; BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(41, 3, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Casual Ammo storage hook ("); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(reason); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(") failed for "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ammoType); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ex.Message); } logger3.LogWarning(val); } } } [HarmonyPatch(typeof(InventorySlotAmmo), "AddAmmo")] internal static class InventorySlotAmmoAddAmmoPatch { private static void Postfix(InventorySlotAmmo __instance, float ammoAmount) { //IL_0017: 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_005a: Expected O, but got Unknown //IL_006d: Unknown result type (might be due to invalid IL or missing references) if (Plugin.IsEnabled && Plugin.RestoreMode.Value == AmmoRestoreMode.FullRestore && __instance != null && Plugin.IsWeaponAmmo(__instance.AmmoType) && !(ammoAmount <= 0f)) { float ammoInPack = __instance.AmmoInPack; __instance.AmmoInPack = Math.Max(__instance.AmmoInPack, __instance.AmmoMaxCap); ManualLogSource logger = Plugin.Logger; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(54, 5, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Casual Ammo slot hook: AddAmmo("); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(__instance.AmmoType); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ammoAmount, "0.###"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(") forced "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ammoInPack, "0.###"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" -> "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(__instance.AmmoInPack, "0.###"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" / cap "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(__instance.AmmoMaxCap, "0.###"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("."); } logger.LogWarning(val); } } } }