Decompiled source of Ammo Tin Piggy Compat v1.0.1

AmmoTinPVCom.dll

Decompiled 2 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using PiggyVarietyMod.Patches;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LethalCompanyAmmoTinPiggyVarietyCompat")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LethalCompanyAmmoTinPiggyVarietyCompat")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("dfc547b3-8844-42f7-aeba-ed1788a8bbc7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace LethalCompanyAmmoTinPiggyVarietyCompat;

[HarmonyPatch(typeof(M4Item))]
public class M4ItemPatches
{
	[HarmonyPatch("ReloadedGun")]
	[HarmonyPostfix]
	public static void Postfix(M4Item __instance, ref bool __result)
	{
		if (__result)
		{
			return;
		}
		for (int i = 0; i < ((GrabbableObject)__instance).playerHeldBy.ItemSlots.Length; i++)
		{
			if ((Object)(object)((GrabbableObject)__instance).playerHeldBy.ItemSlots[i] != (Object)null && ((GrabbableObject)__instance).playerHeldBy.ItemSlots[i].itemProperties.itemName == "Ammo Tin" && ((GrabbableObject)__instance).playerHeldBy.ItemSlots[i].insertedBattery.charge >= ModAmmoTinPVComMain.m4DrainCost)
			{
				Battery insertedBattery = ((GrabbableObject)__instance).playerHeldBy.ItemSlots[i].insertedBattery;
				insertedBattery.charge -= ModAmmoTinPVComMain.m4DrainCost;
				__result = true;
				__instance.ammoSlotToUse = 100;
				break;
			}
		}
	}
}
[BepInPlugin("htd.lethalcompany.ammotinPVCom", "Ammo Tin Piggys Variety Compatability", "1.0.1")]
public class ModAmmoTinPVComMain : BaseUnityPlugin
{
	public const string Version = "1.0.1";

	public const string ModName = "Ammo Tin Piggys Variety Compatability";

	public const string GUID = "htd.lethalcompany.ammotinPVCom";

	private Harmony _Harmony = new Harmony("htd.lethalcompany.ammotinPVCom");

	public static ManualLogSource Log;

	public static int maxM4Reloads = 2;

	public static float m4DrainCost = 1f / (float)maxM4Reloads;

	public static int maxRevolverReloads = 12;

	public static float revolverDrainCost = 1f / (float)maxRevolverReloads;

	private void Awake()
	{
		maxM4Reloads = ((BaseUnityPlugin)this).Config.Bind<int>("Reloads", "Total M4(Rifle) Reloads from Full Ammo Tin", 2, "If an Ammo Tin is full, this is the possible amount of reloads you can get.").Value;
		m4DrainCost = 1f / (float)maxM4Reloads;
		maxRevolverReloads = ((BaseUnityPlugin)this).Config.Bind<int>("Reloads", "Total Revolver Reloads from Full Ammo Tin", 12, "If an Ammo Tin is full, this is the possible amount of reloads you can get.").Value;
		revolverDrainCost = 1f / (float)maxRevolverReloads;
		_Harmony.PatchAll();
		((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
	}
}
[HarmonyPatch(typeof(RevolverItem))]
public class RevolverItemPatches
{
	[HarmonyPatch("ReloadedGun")]
	[HarmonyPostfix]
	public static void Postfix(RevolverItem __instance, ref bool __result)
	{
		if (__result)
		{
			return;
		}
		for (int i = 0; i < ((GrabbableObject)__instance).playerHeldBy.ItemSlots.Length; i++)
		{
			if ((Object)(object)((GrabbableObject)__instance).playerHeldBy.ItemSlots[i] != (Object)null && ((GrabbableObject)__instance).playerHeldBy.ItemSlots[i].itemProperties.itemName == "Ammo Tin" && ((GrabbableObject)__instance).playerHeldBy.ItemSlots[i].insertedBattery.charge >= ModAmmoTinPVComMain.revolverDrainCost)
			{
				Battery insertedBattery = ((GrabbableObject)__instance).playerHeldBy.ItemSlots[i].insertedBattery;
				insertedBattery.charge -= ModAmmoTinPVComMain.revolverDrainCost;
				__result = true;
				__instance.ammoSlotToUse = 100;
				break;
			}
		}
	}
}