Decompiled source of DoorPull v0.1.1

DoorPull.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
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("DoorPull")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DoorPull")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("FE8B42E3-7082-4DFF-A5CC-6B62B0315ACA")]
[assembly: AssemblyFileVersion("0.1.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.1.0")]
[module: UnverifiableCode]
namespace DoorPull;

public static class BepInExExtensions
{
	public static bool IsKeyDown(this KeyboardShortcut shortcut)
	{
		//IL_0003: 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)
		return (int)((KeyboardShortcut)(ref shortcut)).MainKey != 0 && Input.GetKeyDown(((KeyboardShortcut)(ref shortcut)).MainKey) && ((KeyboardShortcut)(ref shortcut)).Modifiers.All((Func<KeyCode, bool>)Input.GetKey);
	}

	public static bool IsKeyPressed(this KeyboardShortcut shortcut)
	{
		//IL_0003: 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)
		return (int)((KeyboardShortcut)(ref shortcut)).MainKey != 0 && Input.GetKey(((KeyboardShortcut)(ref shortcut)).MainKey) && ((KeyboardShortcut)(ref shortcut)).Modifiers.All((Func<KeyCode, bool>)Input.GetKey);
	}
}
[HarmonyPatch]
public class Patches
{
	private static float lastDoorInteractTime;

	[HarmonyPatch(typeof(Door), "GetHoverText")]
	[HarmonyPostfix]
	public static void GetHoverText(Door __instance, ref string __result)
	{
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		if (__instance.m_nview.IsValid() && (!__instance.m_canNotBeClosed || __instance.CanInteract()) && (!__instance.m_checkGuardStone || PrivateArea.CheckAccess(((Component)__instance).transform.position, 0f, false, false)) && __instance.CanInteract())
		{
			string text = ((__instance.m_nview.GetZDO().GetInt(ZDOVars.s_state, 0) != 0 && !__instance.m_invertedOpenClosedText) ? "$piece_door_close" : "Pull $piece_door_open");
			string obj = __result;
			Localization instance = Localization.instance;
			KeyboardShortcut value = Plugin.PullKey.Value;
			__result = obj + instance.Localize("\n[<color=yellow><b>" + ((KeyboardShortcut)(ref value)).Serialize() + "</b></color>] " + text);
		}
	}

	[HarmonyPatch(typeof(Door), "Interact")]
	[HarmonyTranspiler]
	public static IEnumerable<CodeInstruction> InteractTranspiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0025: 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)
		//IL_0046: Expected O, but got Unknown
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Expected O, but got Unknown
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Expected O, but got Unknown
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Expected O, but got Unknown
		MethodInfo openCall = AccessTools.Method(typeof(Door), "Open", (Type[])null, (Type[])null);
		return new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => CodeInstructionExtensions.Calls(i, openCall)), (string)null)
		}).Insert((CodeInstruction[])(object)new CodeInstruction[3]
		{
			new CodeInstruction(OpCodes.Ldarg_0, (object)null),
			new CodeInstruction(OpCodes.Ldarg_1, (object)null),
			new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Patches), "GetPullDirection", (Type[])null, (Type[])null))
		}).InstructionEnumeration();
	}

	[HarmonyPatch(typeof(Player), "Update")]
	[HarmonyPostfix]
	public static void UpdatePostfix(Player __instance)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)__instance.m_hovering) && Plugin.PullKey.Value.IsKeyPressed() && ((Character)__instance).TakeInput() && !((double)(Time.time - lastDoorInteractTime) < 0.2) && Object.op_Implicit((Object)(object)__instance.m_hovering.GetComponentInParent<Door>()))
		{
			__instance.Interact(__instance.m_hovering, false, true);
		}
	}

	private static Vector3 GetPullDirection(Vector3 originalDirection, Door door, Humanoid character)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		lastDoorInteractTime = Time.time;
		if (!Plugin.PullKey.Value.IsKeyPressed())
		{
			return originalDirection;
		}
		Vector3 val = ((Component)door).transform.position - ((Component)character).transform.position;
		return ((Vector3)(ref val)).normalized;
	}
}
[BepInPlugin("com.maxsch.valheim.DoorPull", "DoorPull", "0.1.1")]
public class Plugin : BaseUnityPlugin
{
	public const string ModName = "DoorPull";

	public const string ModGuid = "com.maxsch.valheim.DoorPull";

	public const string ModVersion = "0.1.1";

	private Harmony harmony;

	public static Plugin Instance { get; private set; }

	public static ConfigEntry<KeyboardShortcut> PullKey { get; private set; }

	private void Awake()
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Expected O, but got Unknown
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		Instance = this;
		harmony = new Harmony("com.maxsch.valheim.DoorPull");
		harmony.PatchAll();
		PullKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "Pull Key", new KeyboardShortcut((KeyCode)101, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), (ConfigDescription)null);
	}
}