Decompiled source of HammerFall v1.1.1

HammerFall.dll

Decompiled 2 months ago
using System.Collections.Generic;
using System.Diagnostics;
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.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("HammerFall")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("HP")]
[assembly: AssemblyProduct("HammerFall")]
[assembly: AssemblyCopyright("Copyright © HP 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ec7a6b85-18f8-4405-9aeb-d1d727e46f8f")]
[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")]
namespace HammerFall;

[BepInPlugin("youdied.hammerfall", "HammerFall", "1.1.1")]
public class HammerFallPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Character), "UpdateGroundContact")]
	private class FallDamagePatch
	{
		private static readonly FieldRef<Character, float> MaxAirAltitude = AccessTools.FieldRefAccess<Character, float>("m_maxAirAltitude");

		private static void Postfix(Character __instance)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
			{
				Player player = (Player)__instance;
				if (IsHoldingHammer(player) && IsNearWorkbench(player))
				{
					MaxAirAltitude.Invoke(__instance) = ((Component)__instance).transform.position.y;
				}
			}
		}
	}

	public const string ModId = "youdied.hammerfall";

	public const string ModName = "HammerFall";

	public const string ModVersion = "1.1.1";

	private void Awake()
	{
		Harmony.CreateAndPatchAll(typeof(FallDamagePatch), (string)null);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"HammerFall v1.1.1 loaded.");
	}

	private static bool IsHoldingHammer(Player player)
	{
		ItemData value = Traverse.Create((object)player).Field("m_rightItem").GetValue<ItemData>();
		if (value == null)
		{
			return false;
		}
		int result;
		if (!(value.m_shared.m_name == "$item_hammer"))
		{
			GameObject dropPrefab = value.m_dropPrefab;
			result = ((((dropPrefab != null) ? ((Object)dropPrefab).name : null) == "Hammer") ? 1 : 0);
		}
		else
		{
			result = 1;
		}
		return (byte)result != 0;
	}

	private static bool IsNearWorkbench(Player player)
	{
		//IL_0007: 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_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		Vector3 position = ((Component)player).transform.position;
		List<CraftingStation> value = Traverse.Create(typeof(CraftingStation)).Field("m_allStations").GetValue<List<CraftingStation>>();
		if (value == null)
		{
			return false;
		}
		foreach (CraftingStation item in value)
		{
			if (!((Object)(object)item == (Object)null) && item.m_name == "$piece_workbench")
			{
				Vector3 val = ((Component)item).transform.position - position;
				if (((Vector3)(ref val)).sqrMagnitude <= 10000f)
				{
					return true;
				}
			}
		}
		return false;
	}
}