Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of HipWeapons v1.2.0
ValheimHipWeapons.dll
Decompiled 3 weeks agousing 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.2.0")] 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 DualOffsetTransform dualAxeJoint = new DualOffsetTransform("DualAxe"); private static DualOffsetTransform earlyAxesJoint = new DualOffsetTransform("EarlyAxes"); private static OffsetTransform clubsJoint = new OffsetTransform("Clubs"); private static ConfigEntry<bool> berserkirEditSFX; 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) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_01a8: 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)); dualAxeJoint.BindDual(((BaseUnityPlugin)this).Config, defualtEnabled: true, new Vector3(0f, 0.9f, 2.5f), new Vector3(0f, 10f, 20f), new Vector3(0f, 5.2f, 2.3f), new Vector3(10f, 10f, 190f)); berserkirEditSFX = ((BaseUnityPlugin)this).Config.Bind<bool>(dualAxeJoint.name, "_Edit SFX on Berserkir", true, "Removes cloud particles and duplicates the special effect"); earlyAxesJoint.BindDual(((BaseUnityPlugin)this).Config, defualtEnabled: true, new Vector3(2f, 0.4f, -0.3f), new Vector3(-30f, 85f, 180f), new Vector3(1f, -4.9f, 0f), new Vector3(-10f, 80f, 4f)); } private void OnDestroy() { harmony.UnpatchSelf(); } [HarmonyPrefix] [HarmonyPatch(typeof(VisEquipment), "AttachItem")] public static bool AttachItem(VisEquipment __instance, Transform ___m_backMelee, Transform ___m_backShield, Transform ___m_backTool, int itemHash, ref Transform joint, bool backAttach = false) { //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: 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_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Invalid comparison between Unknown and I4 //IL_01b6: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Invalid comparison between Unknown and I4 //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Invalid comparison between Unknown and I4 //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Invalid comparison between Unknown and I4 //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Invalid comparison between Unknown and I4 //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_0213: Invalid comparison between Unknown and I4 //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Invalid comparison between Unknown and I4 //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_023a: Unknown result type (might be due to invalid IL or missing references) //IL_01f9: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) try { if (__instance.m_isPlayer && backAttach && 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; ItemType val = (((int)component2.m_itemData.m_shared.m_attachOverride != 0) ? component2.m_itemData.m_shared.m_attachOverride : component2.m_itemData.m_shared.m_itemType); if ((Object)(object)joint == (Object)(object)___m_backMelee) { if ((int)val == 3) { if ((int)skillType == 1 && swordJoint.enabled) { joint = swordJoint.Set(__instance, ___m_backTool); logger.LogInfo((object)$"Attaching OneHandedWeapon {skillType} to sword joint for {component.GetPlayerName()}"); } else if ((int)skillType == 7 && axeJoint.enabled) { joint = axeJoint.Set(__instance, ___m_backTool); logger.LogInfo((object)$"Attaching OneHandedWeapon {skillType} to axe joint for {component.GetPlayerName()}"); } else if ((int)skillType == 3 && clubsJoint.enabled) { joint = clubsJoint.Set(__instance, ___m_backTool); logger.LogInfo((object)$"Attaching OneHandedWeapon {skillType} to clubs joint for {component.GetPlayerName()}"); } } } else if ((Object)(object)joint == (Object)(object)___m_backShield && (int)val == 5) { if ((int)skillType == 7 && earlyAxesJoint.enabled && ((Object)itemPrefab).name == "AxeEarly") { joint = earlyAxesJoint.Set(__instance, ___m_backTool); logger.LogInfo((object)$"Attaching OneHandedWeapon {skillType} to earlyAxes joint for {component.GetPlayerName()}"); } else if ((int)skillType == 7 && dualAxeJoint.enabled) { joint = dualAxeJoint.Set(__instance, ___m_backTool); logger.LogInfo((object)$"Attaching OneHandedWeapon {skillType} to dualAxe joint for {component.GetPlayerName()}"); } } } } catch (Exception ex) { logger.LogError((object)("Caught error: " + ex.ToString())); } return true; } [HarmonyPostfix] [HarmonyPatch(typeof(VisEquipment), "AttachItem")] public static void AttachItem_Postfix(VisEquipment __instance, ref GameObject __result, ref Transform joint) { //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Expected O, but got Unknown try { if (dualAxeJoint.enabled && (Object)(object)joint == (Object)(object)dualAxeJoint.GetJoint(__instance)) { MeshRenderer[] componentsInChildren = __result.GetComponentsInChildren<MeshRenderer>(false); if (componentsInChildren.Length <= 1) { return; } if (berserkirEditSFX.Value) { foreach (Transform item in __result.transform) { Transform val = item; if (((Object)val).name == "Clouds") { Object.Destroy((Object)(object)((Component)val).gameObject); } else if ((Object)(object)((Component)val).GetComponent<ParticleSystem>() != (Object)null) { Object.Instantiate<GameObject>(((Component)val).gameObject, val.parent, true).transform.SetParent(((Component)componentsInChildren[1]).transform, true); } } } dualAxeJoint.ApplySecond(__instance, __result); } else if (earlyAxesJoint.enabled && (Object)(object)joint == (Object)(object)earlyAxesJoint.GetJoint(__instance)) { earlyAxesJoint.ApplySecond(__instance, __result); } } catch (Exception ex) { logger.LogError((object)("Caught error: " + ex.ToString())); } } } public class DestroyOther : MonoBehaviour { public GameObject other; private void OnDestroy() { if (Object.op_Implicit((Object)(object)other)) { Object.Destroy((Object)(object)other); } } } public class OffsetTransform { protected class Pair { public Transform rot; public Transform pos; } public ConfigEntry<bool> configEnabled; public ConfigEntry<Vector3> configAngle; public ConfigEntry<Vector3> configOffset; protected Dictionary<VisEquipment, Pair> instances = new Dictionary<VisEquipment, Pair>(); protected string _name; public string name => _name; public bool enabled => configEnabled.Value; public OffsetTransform(string name) { _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; } protected 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); } } } protected virtual 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); } protected virtual 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; } } public class DualOffsetTransform : OffsetTransform { public ConfigEntry<Vector3> secondConfigAngle; public ConfigEntry<Vector3> secondConfigOffset; protected Dictionary<VisEquipment, Pair> secondInstances = new Dictionary<VisEquipment, Pair>(); public DualOffsetTransform(string name) : base(name) { } public void BindDual(ConfigFile Config, bool defualtEnabled, Vector3 defaultOffset, Vector3 defaultAngle, Vector3 secondDefaultOffset, Vector3 secondDefaultAngle) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0004: 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) Bind(Config, defualtEnabled, defaultOffset, defaultAngle); secondConfigOffset = Config.Bind<Vector3>(_name, _name + " Second Offset", secondDefaultOffset, ""); secondConfigAngle = Config.Bind<Vector3>(_name, _name + " Second Angle", secondDefaultAngle, ""); secondConfigOffset.SettingChanged += base.Config_SettingChanged; secondConfigAngle.SettingChanged += base.Config_SettingChanged; } private Pair CreateDual() { Pair pair = Create(); Transform pos = pair.pos; ((Object)pos).name = ((Object)pos).name + " (Second)"; Transform rot = pair.rot; ((Object)rot).name = ((Object)rot).name + " (Second)"; return pair; } protected override Transform Set(VisEquipment visEquip, Transform parent, Vector3 localPosition, Vector3 localEuler) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) Transform result = base.Set(visEquip, parent, localPosition, localEuler); if (!secondInstances.TryGetValue(visEquip, out var value)) { Pair pair = (secondInstances[visEquip] = CreateDual()); value = pair; } if (!Object.op_Implicit((Object)(object)value.rot) || !Object.op_Implicit((Object)(object)value.pos)) { Pair pair = (secondInstances[visEquip] = CreateDual()); value = pair; } value.rot.parent = parent; value.rot.localPosition = Vector3.zero; value.rot.localEulerAngles = secondConfigAngle.Value; value.rot.localScale = Vector3.one; value.pos.localPosition = secondConfigOffset.Value / 1000f; value.pos.localEulerAngles = Vector3.zero; value.pos.localScale = Vector3.one; return result; } public Transform GetSecondJoint(VisEquipment visEquip) { if (secondInstances.TryGetValue(visEquip, out var value)) { return value.pos; } return null; } public void ApplySecond(VisEquipment visEquip, GameObject weaponInstance) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: 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_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) MeshRenderer[] componentsInChildren = weaponInstance.GetComponentsInChildren<MeshRenderer>(false); if (componentsInChildren.Length > 1) { Transform transform = ((Component)componentsInChildren[1]).transform; Transform secondJoint = GetSecondJoint(visEquip); if ((Object)(object)secondJoint != (Object)null) { Vector3 localPosition = transform.localPosition; Quaternion localRotation = transform.localRotation; transform.SetParent(secondJoint, true); transform.localPosition = Vector3.Scale(localPosition, transform.localScale); transform.localRotation = localRotation; weaponInstance.AddComponent<DestroyOther>().other = ((Component)transform).gameObject; } } } }