Decompiled source of HipWeapons v1.1.1

ValheimHipWeapons.dll

Decompiled a day ago
using System;
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 BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ValheimHipSword")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ValheimHipSword")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("8372904f-d004-4941-803f-f2fddce7a69b")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ValheimHipSword;

[BepInPlugin("GemHunter1.HipWeapons", "HipWeapons", "1.1.1")]
public class HipWeaponsMod : BaseUnityPlugin
{
	private readonly Harmony harmony = new Harmony("GemHunter1.HipWeapons");

	public static ManualLogSource logger;

	private static OffsetTransform swordJoint = new OffsetTransform("Sword");

	private static OffsetTransform axeJoint = new OffsetTransform("Axe");

	private static OffsetTransform clubsJoint = new OffsetTransform("Clubs");

	private void Awake()
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		logger = ((BaseUnityPlugin)this).Logger;
		harmony.PatchAll(typeof(HipWeaponsMod));
		swordJoint.Bind(((BaseUnityPlugin)this).Config, defualtEnabled: true, new Vector3(0f, 0f, -2f), new Vector3(0f, 35f, 0f));
		axeJoint.Bind(((BaseUnityPlugin)this).Config, defualtEnabled: true, new Vector3(0f, 0f, -5f), new Vector3(0f, 210f, 0f));
		clubsJoint.Bind(((BaseUnityPlugin)this).Config, defualtEnabled: true, new Vector3(1f, 0f, -4f), new Vector3(0f, 210f, 0f));
	}

	private void OnDestroy()
	{
		harmony.UnpatchSelf();
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(VisEquipment), "AttachItem")]
	public static bool AttachItem(VisEquipment __instance, Transform ___m_backMelee, Transform ___m_backTool, int itemHash, int variant, ref Transform joint, bool enableEquipEffects = true, bool backAttach = false)
	{
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Invalid comparison between Unknown and I4
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Invalid comparison between Unknown and I4
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Invalid comparison between Unknown and I4
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Invalid comparison between Unknown and I4
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (__instance.m_isPlayer && backAttach && (Object)(object)joint == (Object)(object)___m_backMelee && Object.op_Implicit((Object)(object)___m_backTool))
			{
				Player component = ((Component)__instance).GetComponent<Player>();
				if (!Object.op_Implicit((Object)(object)component))
				{
					return true;
				}
				GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(itemHash);
				if (!Object.op_Implicit((Object)(object)itemPrefab))
				{
					return true;
				}
				ItemDrop component2 = itemPrefab.GetComponent<ItemDrop>();
				if (!Object.op_Implicit((Object)(object)component2) || component2.m_itemData == null || component2.m_itemData.m_shared == null)
				{
					return true;
				}
				SkillType skillType = component2.m_itemData.m_shared.m_skillType;
				if ((int)(((int)component2.m_itemData.m_shared.m_attachOverride != 0) ? component2.m_itemData.m_shared.m_attachOverride : component2.m_itemData.m_shared.m_itemType) == 3)
				{
					if ((int)skillType == 1 && swordJoint.enabled)
					{
						joint = swordJoint.Set(__instance, ___m_backTool);
						logger.LogDebug((object)$"Attaching OneHandedWeapon {skillType} to sword joint for {component.GetPlayerName()}");
					}
					else if ((int)skillType == 7 && axeJoint.enabled)
					{
						joint = axeJoint.Set(__instance, ___m_backTool);
						logger.LogDebug((object)$"Attaching OneHandedWeapon {skillType} to axe joint for {component.GetPlayerName()}");
					}
					else if ((int)skillType == 3 && clubsJoint.enabled)
					{
						joint = clubsJoint.Set(__instance, ___m_backTool);
						logger.LogDebug((object)$"Attaching OneHandedWeapon {skillType} to clubs joint for {component.GetPlayerName()}");
					}
				}
			}
		}
		catch (Exception ex)
		{
			logger.LogError((object)("Caught error: " + ex.ToString()));
		}
		return true;
	}
}
public class OffsetTransform
{
	private class Pair
	{
		public Transform rot;

		public Transform pos;
	}

	public ConfigEntry<bool> configEnabled;

	public ConfigEntry<Vector3> configAngle;

	public ConfigEntry<Vector3> configOffset;

	private Dictionary<VisEquipment, Pair> instances = new Dictionary<VisEquipment, Pair>();

	private string name;

	public bool enabled => configEnabled.Value;

	public OffsetTransform(string name)
	{
		this.name = name;
	}

	public void Bind(ConfigFile Config, bool defualtEnabled, Vector3 defaultOffset, Vector3 defaultAngle)
	{
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		configEnabled = Config.Bind<bool>(name, "_" + name + " Enabled", defualtEnabled, "");
		configOffset = Config.Bind<Vector3>(name, name + " Offset", defaultOffset, "");
		configAngle = Config.Bind<Vector3>(name, name + " Angle", defaultAngle, "");
		configOffset.SettingChanged += Config_SettingChanged;
		configAngle.SettingChanged += Config_SettingChanged;
	}

	private void Config_SettingChanged(object sender, EventArgs e)
	{
		foreach (KeyValuePair<VisEquipment, Pair> instance in instances)
		{
			if (Object.op_Implicit((Object)(object)instance.Key) && Object.op_Implicit((Object)(object)instance.Value.rot.parent))
			{
				Set(instance.Key, instance.Value.rot.parent);
			}
		}
	}

	private Pair Create()
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Expected O, but got Unknown
		Pair pair = new Pair();
		GameObject val = new GameObject(name + " Rotation");
		GameObject val2 = new GameObject(name + " Position");
		pair.rot = val.transform;
		pair.pos = val2.transform;
		pair.pos.parent = pair.rot;
		return pair;
	}

	public Transform Set(VisEquipment visEquip, Transform parent)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		return Set(visEquip, parent, configOffset.Value / 1000f, configAngle.Value);
	}

	public Transform Set(VisEquipment visEquip, Transform parent, Vector3 localPosition, Vector3 localEuler)
	{
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: 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_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: 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)
		if (!instances.TryGetValue(visEquip, out var value))
		{
			Pair pair = (instances[visEquip] = Create());
			value = pair;
		}
		if (!Object.op_Implicit((Object)(object)value.rot) || !Object.op_Implicit((Object)(object)value.pos))
		{
			Pair pair = (instances[visEquip] = Create());
			value = pair;
		}
		value.rot.parent = parent;
		value.rot.localPosition = Vector3.zero;
		value.rot.localEulerAngles = localEuler;
		value.rot.localScale = Vector3.one;
		value.pos.localPosition = localPosition;
		value.pos.localEulerAngles = Vector3.zero;
		value.pos.localScale = Vector3.one;
		return value.pos;
	}

	public Transform GetJoint(VisEquipment visEquip)
	{
		if (instances.TryGetValue(visEquip, out var value))
		{
			return value.pos;
		}
		return null;
	}
}