Decompiled source of AltMultiTool v1.5.3

AltMultiTool.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("AltMultiTool")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Alt + Left Click for Efficient Mining and Woodcutting")]
[assembly: AssemblyFileVersion("1.5.3.0")]
[assembly: AssemblyInformationalVersion("1.5.3")]
[assembly: AssemblyProduct("AltMultiTool")]
[assembly: AssemblyTitle("AltMultiTool")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.5.3.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 AltMultiTool
{
	[BepInPlugin("com.frogbaek.altmultitool", "Alt Multi Tool", "1.5.3")]
	public class AltMultiToolPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(MineRock5), "Damage")]
		private static class MineRock5_Patch
		{
			private static readonly MethodInfo DamageAreaMethod = AccessTools.Method(typeof(MineRock5), "DamageArea", (Type[])null, (Type[])null);

			private static readonly FieldInfo HitAreasField = AccessTools.Field(typeof(MineRock5), "m_hitAreas");

			private static readonly FieldInfo NViewField = AccessTools.Field(typeof(MineRock5), "m_nview");

			private static bool Prefix(MineRock5 __instance, ref HitData hit)
			{
				if (ShouldApplyOneHit((SkillType)12))
				{
					hit.m_damage.m_pickaxe = 9999f;
					object? value = NViewField.GetValue(__instance);
					ZNetView val = (ZNetView)((value is ZNetView) ? value : null);
					if ((Object)(object)val == (Object)null || !val.IsValid())
					{
						return true;
					}
					if (!(HitAreasField.GetValue(__instance) is IList list))
					{
						return true;
					}
					for (int i = 0; i < list.Count; i++)
					{
						if ((Object)(object)val == (Object)null)
						{
							break;
						}
						if (!val.IsValid())
						{
							break;
						}
						if (val.GetZDO() == null)
						{
							break;
						}
						try
						{
							if (!(val.GetZDO().GetFloat("Health" + i, 1f) <= 0f))
							{
								DamageAreaMethod.Invoke(__instance, new object[2] { i, hit });
							}
						}
						catch (Exception)
						{
						}
					}
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(MineRock), "Damage")]
		private static class MineRock_Patch
		{
			private static void Prefix(ref HitData hit)
			{
				if (ShouldApplyOneHit((SkillType)12))
				{
					hit.m_damage.m_pickaxe = 9999f;
				}
			}
		}

		[HarmonyPatch(typeof(TreeBase), "Damage")]
		private static class TreeBase_Patch
		{
			private static void Prefix(ref HitData hit)
			{
				if (ShouldApplyOneHit((SkillType)7))
				{
					hit.m_damage.m_chop = 9999f;
				}
			}
		}

		[HarmonyPatch(typeof(TreeLog), "Damage")]
		private static class TreeLog_Patch
		{
			private static void Prefix(ref HitData hit)
			{
				if (ShouldApplyOneHit((SkillType)7))
				{
					hit.m_damage.m_chop = 9999f;
				}
			}
		}

		[HarmonyPatch(typeof(Destructible), "Damage")]
		private static class Destructible_Patch
		{
			private static void Prefix(ref HitData hit)
			{
				if (ShouldApplyOneHit((SkillType)12))
				{
					hit.m_damage.m_pickaxe = 9999f;
				}
				else if (ShouldApplyOneHit((SkillType)7))
				{
					hit.m_damage.m_chop = 9999f;
				}
			}
		}

		private void Awake()
		{
			Harmony.CreateAndPatchAll(typeof(AltMultiToolPlugin).Assembly, (string)null);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"AltMultiTool v1.5.3 Loaded.");
		}

		private static bool ShouldApplyOneHit(SkillType requiredSkill)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			if (!Input.GetKey((KeyCode)308) && !Input.GetKey((KeyCode)307))
			{
				return false;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return false;
			}
			ItemData currentWeapon = ((Humanoid)localPlayer).GetCurrentWeapon();
			if (currentWeapon != null)
			{
				return currentWeapon.m_shared.m_skillType == requiredSkill;
			}
			return false;
		}
	}
}