Decompiled source of InfiniteToolDurability v1.1.1

BepInEx/plugins/InfiniteToolDurability.dll

Decompiled a week ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("InfiniteToolDurability")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("InfiniteToolDurability")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("1a8e59b1-6fe8-4007-9642-0e7d28f62831")]
[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")]
[BepInPlugin("InfiniteToolDurability", "Infinite Tool Durability", "1.1.1")]
public class InfiniteToolDurability : BaseUnityPlugin
{
	public const string PluginGuid = "InfiniteToolDurability";

	public const string PluginName = "Infinite Tool Durability";

	public const string PluginVersion = "1.1.1";

	private void Awake()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		new Harmony("InfiniteToolDurability").PatchAll();
	}
}
[HarmonyPatch(typeof(ItemManager))]
internal static class ItemManager_DamageToolServerRpc_Patch
{
	private static IEnumerable<MethodBase> TargetMethods()
	{
		return (from m in AccessTools.GetDeclaredMethods(typeof(ItemManager))
			where m.Name == "DamageToolServerRpc"
			select m).Cast<MethodBase>();
	}

	private static bool Prefix()
	{
		return false;
	}
}
[HarmonyPatch(typeof(GunTool), "Selected")]
internal static class GunTool_Selected_Patch
{
	private static void Postfix(GunTool __instance)
	{
		if (__instance.clipSize > 0 && __instance.clipContent <= 0)
		{
			__instance.clipContent = __instance.clipSize;
		}
		if (__instance.disabledOnEmpty && !((Component)__instance).gameObject.activeSelf)
		{
			((Component)__instance).gameObject.SetActive(true);
		}
	}
}
[HarmonyPatch(typeof(GunTool), "Fire")]
internal static class GunTool_Fire_Patch
{
	private struct FireState
	{
		public int Clip;

		public uint ItemId;
	}

	private static void Prefix(GunTool __instance, out FireState __state)
	{
		if (__instance.clipSize > 0 && __instance.clipContent <= 0)
		{
			__instance.clipContent = __instance.clipSize;
		}
		__state = new FireState
		{
			Clip = __instance.clipContent,
			ItemId = PlayerInventory.Instance.selectedItemId
		};
	}

	private static void Postfix(GunTool __instance, FireState __state)
	{
		bool num = __instance.clipContent == __state.Clip - 1;
		__instance.clipContent = __state.Clip;
		if (num && __state.ItemId != 0)
		{
			PlayerInventory.Instance.inventory.AddItemChargeServerRpc(__state.ItemId, (ushort)1);
		}
	}
}
[HarmonyPatch(typeof(GunTool), "Reload")]
internal static class GunTool_Reload_Patch
{
	private static bool Prefix(GunTool __instance)
	{
		if (__instance.clipSize > 0)
		{
			__instance.clipContent = __instance.clipSize;
		}
		return false;
	}
}