Decompiled source of Ammo Tin v1.0.0

AmmoTin.dll

Decompiled 4 hours ago
using System.Diagnostics;
using System.IO;
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 GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Unity.Netcode;
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("LethalCompanyAmmoTin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LethalCompanyAmmoTin")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("85d63194-36a9-4b57-9db1-9b88fba8b04e")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace LethalCompanyAmmoTin;

[BepInPlugin("htd.lethalcompany.ammotin", "Ammo Tin", "1.0.0.0")]
public class ModAmmoTinMain : BaseUnityPlugin
{
	[HarmonyPatch(typeof(ShotgunItem), "ReloadedGun")]
	private static class ShotgunItemReloadedGunPatches
	{
		private static void Postfix(ShotgunItem __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 && ((Object)((GrabbableObject)__instance).playerHeldBy.ItemSlots[i]).name.Replace("(Clone)", "") == "AmmoTin" && ((GrabbableObject)__instance).playerHeldBy.ItemSlots[i].insertedBattery.charge >= shotgunDrainCost)
				{
					Battery insertedBattery = ((GrabbableObject)__instance).playerHeldBy.ItemSlots[i].insertedBattery;
					insertedBattery.charge -= shotgunDrainCost;
					__result = true;
					__instance.ammoSlotToUse = 100;
					break;
				}
			}
		}
	}

	[HarmonyPatch(typeof(PlayerControllerB), "DestroyItemInSlot")]
	private static class PlayerControllerBDestroyItemInSlotPatches
	{
		private static bool Prefix(PlayerControllerB __instance, ref int itemSlot)
		{
			if (itemSlot == 100)
			{
				if ((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null || (Object)(object)NetworkManager.Singleton == (Object)null || NetworkManager.Singleton.ShutdownInProgress)
				{
					return true;
				}
				return false;
			}
			return true;
		}
	}

	public const string Version = "1.0.0.0";

	public const string ModName = "Ammo Tin";

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

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

	public static ManualLogSource Log;

	public static AssetBundle AmmoTinAssets;

	public static int maxShotgunReloads = 8;

	public static float shotgunDrainCost = 1f / (float)maxShotgunReloads;

	private void Awake()
	{
		string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		AmmoTinAssets = AssetBundle.LoadFromFile(Path.Combine(directoryName, "ammotin"));
		if ((Object)(object)AmmoTinAssets == (Object)null)
		{
			Log.LogError((object)"Failed to load custom assets.");
			return;
		}
		Item val = AmmoTinAssets.LoadAsset<Item>("Assets/Prefab/AmmoTin.asset");
		NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
		bool value = ((BaseUnityPlugin)this).Config.Bind<bool>("Scrap", "Allow Ammo Tin to be Scrap", false, "Setting this to true will add it to scrap lists for all moons.").Value;
		int value2 = ((BaseUnityPlugin)this).Config.Bind<int>("Scrap", "Ammo Tin Rarity", 5, "What Weighted Value does this have.").Value;
		int value3 = ((BaseUnityPlugin)this).Config.Bind<int>("Scrap", "Ammo Tin Min", 65, "Min Scrap value.").Value;
		int value4 = ((BaseUnityPlugin)this).Config.Bind<int>("Scrap", "Ammo Tin Max", 215, "Max Scrap value.").Value;
		if (value)
		{
			val.minValue = value3;
			val.maxValue = value4;
			Items.RegisterScrap(val, value2, (LevelTypes)(-1));
		}
		int value5 = ((BaseUnityPlugin)this).Config.Bind<int>("Shop", "Ammo Tin Price", 600, "Price of the Ammo Tin in the shop.").Value;
		int num = value5;
		TerminalNode val2 = AmmoTinAssets.LoadAsset<TerminalNode>("Assets/Terminal/WI.asset");
		Items.RegisterShopItem(val, (TerminalNode)null, (TerminalNode)null, val2, num);
		maxShotgunReloads = ((BaseUnityPlugin)this).Config.Bind<int>("Reloads", "Total Shotgun Reloads from Full Ammo Tin", 8, "If an Ammo Tin is full, this is the possible amount of reloads you can get.").Value;
		shotgunDrainCost = 1f / (float)maxShotgunReloads;
		_Harmony.PatchAll();
		((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
	}
}